MODx Community Forums
The MODx Blog
Donations
Feedburner Feeds
Documentation
Bugs & Requests
The Wiki
download MODx
plugins, modules, snippets
online demo
Jul 04, 2009, 04:53 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search via SMF
or Google:
modx forums
all of modxcms.com
web
MODxCMS.com
Forums
Help
Login
Register
News
:Donate to MODx:
Donations
MODx Community Forums
»
Development & Coding
»
Module, Plugin & Snippet Creation and Modification
»
Document Manager Snippet
Pages: [
1
]
Go Down
« Previous topic
Next topic »
Print
Author
Topic: Document Manager Snippet (Read 1322 times)
0 Members and 1 Guest are viewing this topic.
pleth
Member
Posts: 86
Document Manager Snippet
«
on:
Nov 18, 2008, 10:20 AM »
Just wanted to share a snippet I have been using to return unordered lists based on documents in a given directory. With a couple of modifications it has been coming in handy for several instances. I had actually
used a variation of this previously
to populate an unordered list styled for a photogallery.
Anyway, the advantage has been that is simplifies updating of lists (meeting minutes, newsletters, etc..) for the end user. They just need to upload a new document into the appropriate directory. Hope it is useful for someone.
Code:
<?php
/* -------------------------------------------------------------
:: Snippet: Returns Directory Contents (Document Manager)
----------------------------------------------------------------
Short Description:
Returns Directory Contents (Documents)
Date:
11/18/2008
----------------------------------------------------------------
:: Example Call
----------------------------------------------------------------
[!documentMan? &Location=`FileName` &docSort=`sort`!]
- A call that describes the directory inside of assets/files/ that you want called in.
- docSort, use 'sort' for alphanumeric sorting or 'rsort' for reverse alphanumeric sorting.
------------------------------------------------------------- */
// Shows all files in the directory (assumes you are in assets/files/),
$newline
=
''
;
$dir
=
$modx
->
config
[
'(site_url)'
].
'assets/files/'
.
$Location
.
'/'
;
// set path to files
$dir_array
= array();
// main array - contains all file names in directory
// open directory and parse file list
if (
is_dir
(
$dir
)) {
if (
$dh
=
opendir
(
$dir
)) {
// iterate over file list to create full directory array
while ((
$filename
=
readdir
(
$dh
)) !==
false
) {
if ((
$filename
!=
"."
) && (
$filename
!=
".."
) && (
$filename
!=
"WS_FTP.LOG"
) && (!
preg_match
(
'/^.thumb_/'
,
$filename
))) {
// skip self, parent, and ftp log and thumb prefix if returning images
$dir_array
[] =
$filename
;
// add the filename to the array
}
}
closedir
(
$dh
);
// close directory
}
$docSort
(
$dir_array
,
SORT_STRING
);
// sorting.
$n
=
count
(
$dir_array
);
// total number of files -- might want this for something
$output
=
''
;
$output
.=
'<h3>'
.
$Location
.
','
.
$n
.
' Documents</h3>'
;
$output
.=
'<ul>'
;
foreach (
$dir_array
as
$value
) {
// iterate through array of filenames.
$output
.=
'<li><a href="'
.
$dir
.
''
.
$value
.
'">'
.
$value
.
'</a></li>'
;
}
$output
.=
'</ul>'
;
}
return
$output
;
?>
Logged
Greg
Everett
Committed to MODx
Posts: 566
Re: Document Manager Snippet
«
Reply #1 on:
Jan 01, 2009, 11:53 PM »
Thanks for sharing!
Logged
cbaone
Committed to MODx
Posts: 530
Utah Web Design
Re: Document Manager Snippet
«
Reply #2 on:
Jan 08, 2009, 02:26 PM »
If I understand correctly this could be modified to create a list of documents for download too, right? I'm currently integrating FileDownloadPE to allow users access to a document download page where there will be several PDFs available for download. Could a modified version of this be used to list the documents in an unordered list?
Logged
The ModX has you...
Utah Web Design
pleth
Member
Posts: 86
Re: Document Manager Snippet
«
Reply #3 on:
Jan 08, 2009, 04:26 PM »
I believe the answer is yes. I use it to return the contents of directories for list of PDFs or lists of images. It just takes the weight off of having to create the code by hand. As far as I can tell it can return the contents of any directory.
The code above creates an unordered list, but I have also modified it to populate lists of images in javascript photogalleries like jCarousel. That way the end user (or developer) only has to upload the new images into a directory and the rest is taken care of by the snippet.
I created a post here about it if it helps:
http://www.gregorysmart.com/2008/11/18/documentman-modx-document-management-snippet/
Logged
Greg
cbaone
Committed to MODx
Posts: 530
Utah Web Design
Re: Document Manager Snippet
«
Reply #4 on:
Jan 09, 2009, 04:08 AM »
Great, thanks! I'll take a look at the link.
Logged
The ModX has you...
Utah Web Design
Darkelve
Full Member
Posts: 119
Re: Document Manager Snippet
«
Reply #5 on:
Mar 06, 2009, 09:29 AM »
What if I want to 'nest'... I want each new subfolder to be a new nested list, with the name of the subfolder as the 'heading'.
Logged
pleth
Member
Posts: 86
Re: Document Manager Snippet
«
Reply #6 on:
Mar 06, 2009, 09:44 AM »
I am using this in several places to call in multiple directories. Now, I am not a PHP programmer and I know some of this could be improved by a good PHP person with a more elegant approach, but so far this has worked great for me. The code below is an example I use in combination with a javascript photo gallery. Each snippet call builds a list of documents (images) that are then associated with a link in the unordered list. By only having the snippet build the lists I feel I have retained a lot of flexibility. Each of the &Location calls is just a directory in assets/images/. I don't have to code my lists by hand anymore, just add the new items to one of the directories. I am not sure if this helps with the "nested" portion of your question, but I hope it helps.
Code:
<ul>
[!documentMan? &Location=`gallery-022709` &gNumb=`4` &docSort=`sort`!]
<li><a href="javascript:void(viewer4.show(0))">February 21, 2009 ADDY Awards</a></li>
<!-- divider -->
[!documentMan? &Location=`gallery-010809` &gNumb=`3` &docSort=`sort`!]
<li><a href="javascript:void(viewer3.show(0))">January 1, 2009 Speaker Luncheon</a></li>
<!-- divider -->
[!documentMan? &Location=`gallery-110608` &gNumb=`2` &docSort=`sort`!]
<li><a href="javascript:void(viewer2.show(0))">November 6, 2008 Speaker Luncheon</a></li>
<!-- divider -->
[!documentMan? &Location=`gallery-090408` &gNumb=`1` &docSort=`sort`!]
<li><a href="javascript:void(viewer1.show(0))">September 4, 2008 Speaker Luncheon</a></li>
<!-- divider -->
</ul>
Here are a couple of posts that might help too.
http://www.gregorysmart.com/2009/02/27/modx-documentman-and-jquery-portfolio/
http://www.gregorysmart.com/2008/11/18/documentman-modx-document-management-snippet/
Logged
Greg
Darkelve
Full Member
Posts: 119
Re: Document Manager Snippet
«
Reply #7 on:
Mar 09, 2009, 02:22 AM »
Pleth, your suggestion is very useful, but what I want is to somehow 'recursively' list all documents... in a way that I can have a 'main' folder that has documents in it -or is empty- and subfolders that have documetns in them -or are empty. Then it would show the files if there are any, and any files in the subfolders as nested lists. Also it would be nice if one could specify the maximum 'depth' the list should be.
I'd try it myself, but my knowledge of PHP is at 'newbie' level... x)
So in the following example, with the folder structure in the quote and a DocMan/snippet call, it would output the code for the list below.
Quote
Main folder: Publications
Subfolders: Publications->Newspapers; Publications->Magazines
Subfolder lvl.2: Publications->Magazines->SpecialEditions
Code:
<h2>Publications</h2>
<ul>
<li>Newspapers
<ul>
<li><a href="gg-1.pdf">The grand gazette Issue 1</a></li>
<li><a href="gg-2.pdf">The grand gazette Issue 2</a></li>
<li><a href="gg-3.pdf">The grand gazette Issue 3</a></li>
</ul>
</li>
<li>Magazines
<ul>
<li><a href="bm-1.pdf">Best Mag In The World Issue 1</a></li>
<li><a href="bm-2.pdf">Best Mag In The World Issue 2</a></li>
<li>Special Editions
<ul><li><a href="bm-spsp.pdf">Best Mag In The World Spring Special</li></ul>
</li>
</ul>
</li>
</ul>
«
Last Edit: Mar 09, 2009, 02:53 AM by Darkelve
»
Logged
Pages: [
1
]
Go Up
Print
« Previous topic
Next topic »
Jump to:
Please select a destination:
-----------------------------
Announcements
-----------------------------
=> Important News
=> Security Notices
-----------------------------
Commercial Support
-----------------------------
=> [CS] About Commercial Support
-----------------------------
Development & Coding
-----------------------------
=> Commercial Inquiries & Bounties
=> Core Code
===> MODx Next
===> xPDO
=> Module, Plugin & Snippet Creation and Modification
=> In Development
=> Templates
-----------------------------
Add-ons, Extensions & Elements
-----------------------------
=> Module, Plugin & Snippet Usage
=> General Repository Items Support
=> Navigation & Tagging/Taxonomy
===> Wayfinder & DropMenu
=> Creating & Repurposing Content
===> Ditto
===> Jot
===> Front-end Document Management
=> Users, Authentication & Personalization
===> WebloginPE
===> WebLogin, WebSignup and WebChangePwd
=> Rich Text Editors & File Browser
===> TinyMCE
===> FCKeditor
===> MCPuck File Browser
=> Forms, Form Processing & Anti-Spam
===> eForm
=> Search
===> AjaxSearch
=> E-business
=> Polls, Calendars, Address Book and Community
=> Third-party integrations
=> Images, Videos & Podcasts
===> MaxiGallery
=> Manager, Parser & the Core
===> Backup & Versioning
===> Doc Finder
===> ManagerManager
===> PHx
=> Templates
-----------------------------
Support
-----------------------------
=> Release Support
===> 0.9.6.3
===> 0.9.6.2
===> 0.9.6.1
===> 0.9.6
===> 0.9.5 and earlier
=> General Support
===> MODx 101
===> E-Commerce, E-Marketing, Analytics & SEO
===> Hosting Experiences
===> IIS / Windows Hosting Issues
=> Documentation, Tips & Tricks
===> Documentation Suggestions & Corrections
-----------------------------
General Discussions
-----------------------------
=> General MODx Discussions
=> Webworker Lounge
=> Wishlist
=> You and Your Sites
=> modxcms.com Discussions and Suggestions
=> Off-topic
-----------------------------
International Support & Translations
-----------------------------
=> Internationalization
=> Bulgarian
===> Поддръжка
=====> Често задавани въпроси
=====> Инсталация
=====> Модули, Плъгини, Снипети и код
=====> Дизайн и Шаблони
===> Документация, Ръководства и Превод
=====> Документация
=====> Ръководства
=====> Превод
===> Общество
=====> Съобщения
=====> Представете се
=====> Представете сайта си
=====> Дискусии извън MODx
=> Chinese
=> Czech
===> Oznámení
=====> Důleitá oznámení/novinky
=====> Bezpečnost
===> Komunita
=====> Oznámení
=====> Představte se, prosím
=====> Ukázky práce
=====> Různé aneb cokoli co se jinam nehodí
===> Podpora
=====> FAQ (často kladené otázky)
=====> Instalace
=====> Moduly, pluginy, "snippets & code" (ablony zdrojových kódů)
=====> Design & ablony
===> Dokumentace, tutoriály (návody) a překlady
=====> Dokumentace
=====> Tutoriály (návody)
=====> Překlady (lokalizace)
=> Dutch
===> Ondersteuning
=====> Veel gestelde vragen
=====> Modules, Plugins, Snippets & Code
=====> Design & Templates
===> Documentatie, Tutorials en Vertalingen
=====> Documentatie
=====> Tutorials
=====> Vertalingen
===> Community
=====> Aankondigingen
=====> Stel jezelf voor
=====> Site Showcase
=====> De stamkroeg
=> Filipino
===> Suporta
=====> Kadalasang tanong
=====> Instalasyon
=====> Moduler, Maidadagdag, Karagdagang mga Code
=====> Desenyo at Templates
===> Dokumentasyon, Mga Turo, Mga Salin
=====> Dokumentasyon
=====> Mga Turo
=====> Mga Salin
===> Kumunidad
=====> Anunsyo
=====> Ipakilala ang sarili
=====> Ang Galing ng pinoy
=====> Tsismisan atbp
=> Finnish
===> Tuki
=====> UKK
=====> Asennus
=====> Moduulit, liitännäiset, koodinpätkät
=====> Ulkoasu/Sivustopohjat
===> Dokumentaatio, oppaat ja käännökset
=====> Dokumentaatio
=====> Käännökset
=====> Oppaat
===> Yhteisö
=====> Tiedotteet
=====> Esittele itsesi
=====> MODx sivustosi
=====> Kahvihuone
=> French
===> Support
=====> FAQ
=====> Installation
=====> Module, plugin, snippets
=====> Design/Templates
===> Documentation, Tutoriels et Traductions
=====> Documentation
=====> Traduction
=====> Tutoriels
===> Communauté
=====> Annonces
=====> Présentez vous
=====> Vos sites
=====> Le Bistrot Français
=> German
===> Support (de)
=====> FAQ (de)
=====> Installation (de)
=====> Module, Plugins, Snippets & Code (de)
=====> Design & Templates (de)
===> Dokumentation, Tutorials und Übersetzung
=====> Dokumentation
=====> Tutorials (de)
=====> Übersetzung
===> Community (de)
=====> Ankündigungen
=====> Stellt Euch vor
=====> Beispielseiten
=====> Off Topic / Verschiedenes
=> Hebrew
===> הכרזה
=====> חדשות חשובות
=====> אבטחה
===> תמיכה
=====> התקנה
=====> תיעוד, מדריכים ותרגומים
=====> עיצוב ותבניות
=====> שאלות נפוצות
===> תיעוד, מדריכים ותרגומים
=====> תיעוד
=====> מדריכים
=====> תרגומים
===> קהילה
=====> הודעות
=====> הצג את עצמך
=====> אתרים לדוגמא
=====> כללי
=> Irish
=> Italian
===> Supporto
=====> FAQ
=====> Installazione
=====> Moduli, Plugin, Snippet e altro codice
=====> Web Design e Template
===> Documentazione, Tutorial e Traduzione
=====> Documentazione
=====> Tutorial
=====> Traduzione
===> Comunitŕ
=====> Annunci
=====> Presentazioni
=====> Siti in vetrina
=====> Chiacchiere in libertŕ
=> Japanese
===> サポート
=====> 良くある質問
=====> インストール
=====> モジュール・プラグイン・スニペット・本体
=====> デザインやテンプレート
===> マニュアル・テュートリアル・翻訳
=====> マニュアル
=====> 事例集、テュートリアル
=====> 日本語化
===> コミュニティ
=====> お知らせ
=====> MODxサイト展示場
=====> 自己紹介
=====> 雑談
=====> 国産リソース
=> Persian - فارسي
===> پشتيباني
=====> راهنما
=====> نصب
=====> ماژول , پلاگین ها , کد ها و جزییات
=====> طراحی و قالب ها
===> مستند سازی , آموزش ها و ترجمه ها
=====> مستند سازی
=====> آموزش ها
=====> ترجمه ها
===> انجمن ها
=====> اخبار
=====> معرفی کردن خود
=====> نمایش دادن سایت ها
=====> بحث های عمومی و سایر موضوعات
=> Polish
===> Wsparcie
=====> FAQ
=====> Instalacja
=====> Moduły, pluginy, snipety i kod
=====> Wygląd i szablony
===> Dokumentacja, tutoriale i tłumaczenie
=====> Dokumentacja
=====> Tutoriale
=====> Tłumaczenie
===> Społeczność
=====> Ogłoszenia
=====> Przedstaw się
=====> Twój serwis WWW
=====> Hyde Park
=> Portuguese
===> Suporte
=====> FAQ - Dúvidas Frequentes
=====> Instalaçăo
=====> Módulos, Plugins, Snippets e Código
=====> Design e Templates
===> Documentaçăo, Guias e Traduçőes
=====> Documentaçăo
=====> Guias
=====> Traduçőes
===> Comunidade
=====> Anúncios
=====> Apresente-se!
=====> Bar da esquina (fora de tópico)
=====> Portfólio de Sites
=> Russian
===> Поддержка
=====> ЧАВО (FAQ)
=====> Установка
=====> Модули, плагины, сниппеты и код
=====> Дизайны и шаблоны
===> Документация, Уроки, Перевод
=====> Документация
=====> Уроки
=====> Перевод
===> Сообщество
=====> Объявления
=====> Представьтесь публике
=====> Галерея сайтов
=====> Диван
=> Scandanavian
===> Support
=====> Frĺgor och svar
=====> Installation
=====> Moduler, plugins, snippets och kod
=====> Design & sidmallar
===> Dokumentation, guider och översättningar
=====> Dokumentation
=====> Guider
=====> Översättningar
===> Webbgemenskap
=====> Meddelanden
=====> Presentera dig själv
=====> Visa upp dina webbsidor
=====> Ordet fritt
=> Slovak
=> Spanish
===> Soporte
=====> FAQ
=====> Instalación
=====> Modulos, Plugins, Snippets & Código
=====> Diseńo y plantillas
===> Documentación, Tutoriales y Traducciones
=====> Documentatción
=====> Tutoriales
=====> Traducciones
===> Comunidad
=====> Anuncios
=====> Presentaciones personales
=====> Muestra de sitios
=====> El Café
=> Swedish
=> TÜRKÇE (Turkish)
===> Destek
=====> SSS
=====> Kurulum
=====> Modüller, Pluginler, Snippetlar & Kodlar
=====> Dizayn & Temalar
===> Belgeleme, Eğitmenler ve Çeviri
=====> Belgeleme
=====> Eğitmenler
=====> Çeviri
===> Topluluk
=====> Duyurular
=====> Kendinizi Tanıtın
=====> Site Vitrini
=====> Konu Dışı