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
»
General Discussions
»
modxcms.com Discussions and Suggestions
»
Snippet return for directory contents
Pages: [
1
]
Go Down
« Previous topic
Next topic »
Print
Author
Topic: Snippet return for directory contents (Read 2862 times)
0 Members and 1 Guest are viewing this topic.
pleth
Member
Posts: 86
Snippet return for directory contents
«
on:
May 14, 2008, 08:51 PM »
Lately I have used jCarousel and Modx for a site with a photo gallery and it works quite well. Since it works with a simple unordered list on the gallery page I got to thinking that it would be nice to have a snippet that could return the contents of an assets directory in that list item format.
It seems this would create a gallery within Modx that the CMS user could manage by simply uploading to/deleting from a specified directory. Has anyone done anything like this?
Logged
Greg
BobRay
Coding Team
Posts: 3,173
Re: Snippet return for directory contents
«
Reply #1 on:
May 14, 2008, 10:47 PM »
I've done something similar (if I'm understanding you). It's a fairly simple process.
I've adapted some code I had laying around. This is very quick and dirty code and untested, but should get you started.
Code:
<?php
// Shows all files in the directory,
$newline
=
"<br/>"
;
$dir
=
$modx
->
config
[
'base_path'
].
'assets/yourfiles'
;
// 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"
)) {
// skip self, parent, and ftp log
$dir_array
[] =
$filename
;
// add the filename to the array
}
}
closedir
(
$dh
);
// close directory
}
natsort
(
$dir_array
);
// sort in ascending order -- delete if you don't need them sorted.
// $dir_array = array_reverse($dir_array, false); // reverse array (descending) if needed.
$n
=
count
(
$dir_array
);
// total number of files -- might want this for something
$output
=
""
;
$output
.=
"<ul>"
foreach (
$dir_array
as
$value
) {
// iterate through array of filenames.
$output
.=
'<li>'
.
$value
.
'</li>'
;
}
$output
.=
'</ul>'
;
}
return
$output
;
?>
BTW, you might look at the MaxiGallery snippet if you haven't already. It does all this for you and makes for much easier and more full-featured gallery management by the users (e.g. picture order, uploading and deleting, titles, descriptions, dropshadows, masks, slideshow, etc).
Hope this helps,
Bob
Logged
MODx info for newbies:
http://bobsguides.com/MODx.html
powersitedesign
New Member
Posts: 1
Re: Snippet return for directory contents
«
Reply #2 on:
May 15, 2008, 11:10 AM »
Hey BobRay -
I am working w/ Greg on this and we think we almost have it. The only thing we want to do now is to exclude the .thumb_ file prefix so the thumbnails don't show, do you have any suggestions for that?
We tried this,
if (($filename != ".") && ($filename != "..") && ($filename !=
"WS_FTP.LOG") && (!preg_match('/^\.*thumb_$/', $filename ) ) { // skip
self, parent, and ftp log and thumb prefix
and it didn't seem to exclude them,
thanks for your help in advance.
Cotton Rohrscheib, Partner
Pleth Networks, LLC
http://www.pleth.com
Logged
ganeshXL
Testers
Posts: 1,923
true is true
Re: Snippet return for directory contents
«
Reply #3 on:
May 15, 2008, 12:49 PM »
using strstr or stristr would be easier...
http://ch2.php.net/stristr
Logged
http://www.screengang.com/
ˇ
http://www.online-marketing-consulting.ch/
ˇ
http://www.dnik.ch/
ˇ
http://www.flickr.com/photos/dnik/
smashingred
Marketing & Design Team
Posts: 1,294
HTML, CSS, Marketing, Design, and more...
Re: Snippet return for directory contents
«
Reply #4 on:
May 15, 2008, 02:16 PM »
I think that @pleth has it working now. He found me on
twitter
and I gave him the correct pattern to add to BobRay's post.
I changed the following:
Code:
if (($filename != ".") && ($filename != "..") && ($filename != "WS_FTP.LOG")) { // skip self, parent, and ftp log
to
Code:
if (($filename != ".") && ($filename != "..") && ($filename != "WS_FTP.LOG") && (!preg_match('/^.thumb_/', $filename))) { // skip self, parent, and ftp log
And it works.
The pattern just checks to see if the filename starts with .thumb_ and if it does skip it.
Logged
Jay Gilmore
SmashingRed Web & Marketing
Follow me on
Twitter
Configs
Local: MAMP 1.7.2 Mac OS 10.5, Apache 2.0.59, PHP 5.2.6, MySQL 5.0.41
Remote: Linux, Apache 1.3.41, PHP 5.2.5, MySQL 5.0.51a-community
MODx For Newbies
About MODx (read For Optimal Results)
Installation and Configuration
Beginners Guide to MODx
About MODx and More
What's Coming Next
Just because it's possible to build a dropdown menu doesn't mean you should.
pleth
Member
Posts: 86
Re: Snippet return for directory contents
«
Reply #5 on:
May 15, 2008, 02:36 PM »
Thanks guys, we appreciate the help.
Logged
Greg
pleth
Member
Posts: 86
Re: Snippet return for directory contents
«
Reply #6 on:
May 16, 2008, 11:07 AM »
Just thought I would post this to let you know where we ended up on this. I realize there are other solutions available and am planning on diving into MaxiGallery next but this solution proved sufficient as well as a good exercise. Maybe this will be useful to someone as I think it could be applied to other types of documents. Once again, thanks.
Code:
<?php
/* -------------------------------------------------------------
:: Snippet: Returns Directory Contents
----------------------------------------------------------------
Short Description:
Returns Directory Contents, excludes self, parent, ftp log and thumbnail with prefix (.thumb_)
Date:
05/16/2008
----------------------------------------------------------------
:: Example Call
----------------------------------------------------------------
[!directory? &Location=`yourdirectory`!]
A call that describes the directory inside of assets/images/ that you want called in.
------------------------------------------------------------- */
// Shows all files in the directory (assumes you are in assets/images/),
$newline
=
''
;
$dir
=
$modx
->
config
[
'(site_url)'
].
'assets/images/'
.
$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
$dir_array
[] =
$filename
;
// add the filename to the array
}
}
closedir
(
$dh
);
// close directory
}
natsort
(
$dir_array
);
// sort in ascending order -- delete if you don't need them sorted.
// $dir_array = array_reverse($dir_array, false); // reverse array (descending) if needed.
$n
=
count
(
$dir_array
);
// total number of files -- might want this for something
$output
=
''
;
$output
.=
'<ul id="mycarousel" class="jcarousel-skin-tango">'
;
foreach (
$dir_array
as
$value
) {
// iterate through array of filenames.
$output
.=
'<li><img src="'
.
$dir
.
''
.
$value
.
'" /></li>'
;
}
$output
.=
'</ul>'
;
}
return
$output
;
?>
Logged
Greg
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ışı