phpFileTree v0.0.1
A snippet recursively listing all included directories and files within a specific directory.
Attention: WORK IN PROGRESS!
A year ago "pleth" posted a neat snippet that creates "unordered lists based on documents in a given directory"
(
http://modxcms.com/forums/index.php/topic,30700.msg186267/topicseen.html#msg186267).
Among other things, this could be useful for
- building javascript image galleries,
- for generating a mediaplayer playlist,
- listing pdf documents in a directory.
- ...
After pondering about the opportunities such a script can offer, I though it would be a good idea to power this idea a bit up...
In the past I have used "PHP File Tree" by Cory S.N. LaViska (
http://abeautifulsite.net/notebook/21) for similar tasks. Go and check it out to see what can be achieved with it. Especially have a look at those demo pages:
http://abeautifulsite.net/notebook_files/21/demo/demo_classic.php and
http://abeautifulsite.net/notebook_files/21/demo/demo_jquery.php
Because Cory doesn’t mind sharing his humble work with other people...
...you can use it however you want with or without attribution, so long as you understand and accept that it is offered as-is, with no warranty whatsoever. Also, we obviously won’t be able to provide support for it.
Thanks Cory!
During this weekend I’ve frankensteined Cory’s script and added some additional limbs and organs. You can find it attached to this post.
Attention: You are free to use this snippet in every way you like but like Cory I’m offering it as it is and there is no warranty for it too . If you want to make use of it, do it. But please BE CAREFUL about what kind of information you are offering to the public.
Usage:
1. Snippet call:
----------------
[!phpFileTree? &directory=`images` &return_link=`[link]` &addFile=`jpg,png,gif` &removeFile=`png` &ignore=`thumb` !]
2. Parameters:
--------------
&directory=`images`
The directory you want to start your journey from. For security reasons, the assets directory is hardwired into the snippet.
&return_link=`[link]`
Control how the URL to a resource will look like. [link] will just create an ordinary link to each file.
&addFile=`jpg,png,gif`
If not empty INCLUDE only files with the listed extensions. Just use a comma to separate multiple filetypes. Just add the extensions, don’t use a "." in front.
&removeFile=`png`
Same as above, but If not empty, EXCLUDE only files with a certain extension.
&ignore=`thumb`
Remove files from list that contain a specific string within their filenames. To remove all thumb_*.* from your list, just add thumb to this parameter.
Note: For more information have a look at the comments inside the snippet.
3. Tips and Tricks
------------------
- Until I have added some templating functionality (can I hear someone volunteering for this task?) you have to change parts of the snippet’s php code. If you don’t know how to do this post your question and I will try to help you.
- Controlling depth of list. Right now there is no way to prevent the snippet from going all the way down to the bottom of a directory. If this is a problem for you, you have to point it to a folder that only has the included directories you want to list.
ToDo (in no particular order):
------------------------------
- Remove inline styling for debugging the snippet.
- Clean up messy code.
- Add some security features to prevent (accidental) abuse.
- Add some generic filetypes (Example: &addFile=`images` could automatically add "jpg,png,tiff,jpeg" )
- Create a mechanism for templating the list generation (outer,inner).
- Add a variable to control the depth of the recursive search
- Add parameters to remove specific directories from your result.
- Sorting the results should also be possible.
- ...
Have fun.
pepebe
P.S. I’ll appreciate any advice, support or feedback for this script. I can imagine many uses for this snippet and overwhelming public demand might even move me to develop it into a fullscale plugin...