I have a snippet that recursively searchs through a director for images and displays them, this works fine when using the default media source e.g.
echo scanDirectoryImages(client/client-gallery);
But I cant seem to get it to work with the dropbox media source. I searched the forums and there seems to be several old posts that dont have conclusive answers.
$mediasource = $modx->getObject('modMediaSource',array('Dropbox' => $source ));
echo scanDirectoryImages($mediasource);
/**
* Recursively search through directory for images and display them
*
* @param array $exts
* @param string $directory
* @return string
*/
function scanDirectoryImages($directory, array $exts = array('jpeg', 'jpg', 'gif', 'png'))
{
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
$html = '';
if (
is_readable($directory)
&& (file_exists($directory) || is_dir($directory))
) {
$directoryList = opendir($directory);
while($file = readdir($directoryList)) {
if ($file != '.' && $file != '..') {
$path = $directory . '/' . $file;
if (is_readable($path)) {
if (is_dir($path)) {
return scanDirectoryImages($path, $exts);
}
if (
is_file($path)
&& in_array(end(explode('.', end(explode('/', $path)))), $exts)
) {
$html .=
'<div class="gallery">
<a href="[[+imageURL:pthumb]]" title="[[+imageAlt]]">
<img src="[[pThumb? &input=`' . $path . '` &options=`&w=300&h=300&zc=1&q=95`]]" alt="">
</a>
<div class="desc"></div>
</div>';
}
}
}
}
closedir($directoryList);
}
return $html;
}