Skip to content

Commit

Permalink
Merge pull request #191 from gareththered/master
Browse files Browse the repository at this point in the history
Pass a list of files to be displayed to the Gallery and Slideshow.
  • Loading branch information
jbroadway committed May 22, 2013
2 parents f922154 + cc28b1b commit 05d99ba
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 39 deletions.
65 changes: 49 additions & 16 deletions apps/filemanager/handlers/gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,64 @@
*
* The `foldername` is a folder of images inside `/files/` or the directory set
* by the 'filemanager_path' option in your config file.
*
* Alternatively, it can be used via:
*
* {! filemanager/gallery?files=filelist !}
*
* The `filelist` is a list of images inside `/files/` or the directory set
* by the `filemanager_path` option in your config file.
* `filelist` can either be an array or a string with each file path delimited
* by `|`.
*/

require_once ('apps/filemanager/lib/Functions.php');

$root = trim (conf ('Paths','filemanager_path'), '/') . '/';

if (isset ($data['path'])) {
$path = trim ($data['path'], '/');
} elseif (isset ($_GET['path'])) {
$path = trim ($_GET['path'], '/');
} else {
return;
}
if (isset ($data['path']) or isset ($_GET['path'])) {

if (strpos ($path, '..') !== false) {
return;
}
if (isset ($data['path'])) {
$path = trim ($data['path'], '/');
} elseif (isset ($_GET['path'])) {
$path = trim ($_GET['path'], '/');
}

if (! @is_dir ($root . $path)) {
return;
}
if (strpos ($path, '..') !== false) {
return;
}

// fetch the files
$files = glob ($root . $path . '/*.{jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG}', GLOB_BRACE);
$files = is_array ($files) ? $files : array ();
if ( ! @is_dir ($root . $path)) {
return;
}

// fetch the files
$files = glob ($root . $path . '/*.{jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG}', GLOB_BRACE);
$files = is_array ($files) ? $files : array ();
} elseif (isset ($data['files']) or isset ($_GET['files'])) {

if (isset ($data['files'])) {
$files_arg = $data['files'];
} elseif (isset ($_GET['files'])) {
$files_arg = $_GET['files'];
}

if (is_string ($files_arg)) {
$files = explode ('|', $files_arg);
} elseif (is_array ($files_arg)) {
$files = $files_arg;
} else {
return;
}

$files = array_map (
function($var) use ($root) {
return ($root . trim ($var, '/'));
}
, $files);
} else {
return;
}

// sorting order
if ($data['order'] === 'desc') {
Expand Down
84 changes: 61 additions & 23 deletions apps/filemanager/handlers/slideshow.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,77 @@
*
* The `foldername` is a folder of images inside `/files/` or the directory set
* by the 'filemanager_path' option in your config file.
*
* * Alternatively, it can be used via:
*
* {! filemanager/slideshow?files=filelist&name=idsuffix !}
*
* The `filelist` is a list of images inside `/files/` or the directory set
* by the `filemanager_path` option in your config file.
* `filelist` can either be an array or a string with each file path delimited
* by `|`.
* `idsuffix` will be appended to the CSS id of the slideshow.
*/
$root = trim (conf ('Paths', 'filemanager_path'), '/') . '/';

$root = trim (conf ('Paths','filemanager_path'), '/') . '/';
if (isset ($data['path']) or isset ($_GET['path'])) {

if (isset ($data['path'])) {
$path = trim ($data['path'], '/');
} elseif (isset ($_GET['path'])) {
$path = trim ($_GET['path'], '/');
} else {
return;
}
if (isset ($data['path'])) {
$path = trim ($data['path'], '/');
} elseif (isset ($_GET['path'])) {
$path = trim ($_GET['path'], '/');
}

if (strpos ($path, '..') !== false) {
return;
}
if (strpos ($path, '..') !== false) {
return;
}

if (! @is_dir ($root . $path)) {
return;
}
if ( ! @is_dir ($root . $path)) {
return;
}

$name = str_replace ('/', '-', $path);
$name = str_replace ('/', '-', $path);

$files = glob ($root . $path . '/*.{jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG}', GLOB_BRACE);
$files = is_array ($files) ? $files : array ();
$files = glob ($root . $path . '/*.{jpg,jpeg,gif,png,JPG,JPEG,GIF,PNG}', GLOB_BRACE);
$files = is_array ($files) ? $files : array ();
} elseif (isset ($data['files']) or isset ($_GET['files'])) {

if (isset ($data['files'])) {
$files_arg = $data['files'];
} elseif (isset ($_GET['files'])) {
$files_arg = $_GET['files'];
}

if (is_string ($files_arg)) {
$files = explode ('|', $files_arg);
} elseif (is_array ($files_arg)) {
$files = $files_arg;
} else {
return;
}

$files = array_map (
function($var) use ($root) {
return ($root . trim ($var, '/'));
}
, $files);

if (isset ($data['name'])) {
$name = $data['name'];
} elseif (isset ($_GET['name'])) {
$name = $_GET['name'];
}
} else {
return;
}

// rewrite if proxy is set
if ($appconf['General']['proxy_handler']) {
foreach ($files as $k => $file) {
$files[$k] = str_replace ('files/', 'filemanager/proxy/', $file);
}
foreach ($files as $k => $file) {
$files[$k] = str_replace ('files/', 'filemanager/proxy/', $file);
}
}

$page->add_script ('/apps/filemanager/js/jquery.cycle.all.min.js');
echo $tpl->render ('filemanager/slideshow', array ('files' => $files, 'name' => $name));

$page -> add_script ('/apps/filemanager/js/jquery.cycle.all.min.js');
echo $tpl -> render ('filemanager/slideshow', array ('files' => $files, 'name' => $name));
?>

0 comments on commit 05d99ba

Please sign in to comment.