<?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;
?>
<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>
Main folder: Publications
Subfolders: Publications->Newspapers; Publications->Magazines
Subfolder lvl.2: Publications->Magazines->SpecialEditions
<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>