function asb_slideshow_build_template($args) { extract($args); global ${$template_var}, $mybb, $templates; $shuffle = $settings['shuffle'] ? 'true' : 'false'; $folder = $settings['folder']; $rate = (int) $settings['rate'] ? (int) $settings['rate'] : 10; $fade_rate = (double) $settings['fade_rate'] ? (double) $settings['fade_rate'] : 1; $filenames = asb_get_folder_images($folder, '', $settings['recursive']); if (!$filenames) { ${$template_var} = <<<EOF \t\t<tr> \t\t\t<td class="trow1">{$lang->asb_slideshow_no_images}</td> \t\t</tr> EOF; return false; } if ($settings['footer_text'] && $settings['footer_url']) { eval("\$footer = \"" . $templates->get('asb_slideshow_footer') . "\";"); } $width = $width * 0.9; eval("\$\$template_var = \"" . $templates->get('asb_slideshow') . "\";"); return true; }
/** * asb_get_folder_images() * * build a list of all the images stored in a particular folder on the server * * @param - $folder - (string) the unqualified folder name from the root * @param - $subfolder - (string) (for recursion) the current subfolder * @param - $recursive - (bool) determines where to recurse into subfolders * @return: (string) a comma-separated, single-quoted list of file names */ function asb_get_folder_images($folder, $subfolder = '', $recursive = false) { // bad folder, get out if (!$folder || !is_dir(MYBB_ROOT . $folder)) { return false; } // make sure the subfolder has a directory separator if ($subfolder && substr($subfolder, strlen($subfolder) - 1, 1) != '/') { $subfolder .= '/'; } // cycle through all the files/folders and produce a list $sep = ''; foreach (new DirectoryIterator(MYBB_ROOT . $folder) as $file) { // skip navigation folders if ($file->isDot()) { continue; } if ($file->isDir()) { // no recursion, just skip this if (!$recursive) { continue; } // get the files from this directory $sub_files = asb_get_folder_images($folder . '/' . $file->getFilename(), $subfolder . $file->getFilename(), $recursive); if ($sub_files) { $filenames .= "{$sep}{$sub_files}"; $sep = ','; } continue; } // only certain extensions allowed $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION); if (!in_array($extension, array('gif', 'png', 'jpg', 'jpeg'))) { continue; } $filenames .= "{$sep}'{$subfolder}{$file->getFilename()}'"; $sep = ','; } return $filenames; }