function clean_params($params) { foreach ($params as $key => $value) { if (is_array($value)) { $params[$key] = clean_params($value); } else { $params[$key] = quote_smart(trim($value)); } } return $params; }
/** * Output a slideshow feed as a template * * @param array $params * @return string */ function smarty_slideshow($params) { global $PIVOTX, $slideshow_config; static $slideshowcount = 0; $js_insert = <<<EOF <script type="text/javascript"> jQuery(window).bind("load", function(){ jQuery("div#pivotx-slideshow-%count%").slideView(%parms%); setTimeout('slideNext_%count%()', %timeout%); }); function slideNext_%count%() { if( typeof slideNext_%count%.currentslide == 'undefined' ) { slideNext_%count%.currentslide = 0; } var slidewidth = jQuery("div#pivotx-slideshow-%count%").find("li").find("img").width(); var amountofslides = %amount% - 1; if (amountofslides > slideNext_%count%.currentslide) { slideNext_%count%.currentslide++; } else { slideNext_%count%.currentslide = 0; } var xpos = (-slidewidth * slideNext_%count%.currentslide); jQuery("div#pivotx-slideshow-%count%").find("ul").animate({ left: xpos}, 1200, "easeInOutExpo"); setTimeout('slideNext_%count%()', %timeout%); } </script> EOF; $params = clean_params($params); foreach (array('timeout', 'folder', 'width', 'height', 'limit', 'orderby', 'popup', 'recursion', 'nicenamewithdirs', 'iptcindex', 'iptcencoding') as $key) { if (isset($params[$key])) { ${$key} = $params[$key]; } else { ${$key} = getDefault($PIVOTX['config']->get('slideshow_' . $key), $slideshow_config['slideshow_' . $key]); } } $imagefolder = addTrailingSlash($PIVOTX['paths']['upload_base_path'] . $folder); $ok_extensions = explode(",", "jpg,jpeg,png,gif"); if (!file_exists($imagefolder) || !is_dir($imagefolder)) { debug("Image folder {$imagefolder} does not exist."); echo "Image folder {$imagefolder} does not exist."; return ""; } else { if (!is_readable($imagefolder)) { debug("Image folder {$imagefolder} is not readable."); echo "Image folder {$imagefolder} is not readable."; return ""; } } $images = array(); $key = ""; if ($recursion == 'no') { $dirs = array($imagefolder); } else { $dirs = slideshowGetDirs($imagefolder, $recursion); if ($recursion == 'all') { array_unshift($dirs, $imagefolder); } } foreach ($dirs as $folder) { $dir = dir($folder); while (false !== ($entry = $dir->read())) { if (in_array(strtolower(getExtension($entry)), $ok_extensions)) { if (strpos($entry, ".thumb.") > 0) { continue; } $entry = $folder . $entry; if ($orderby == 'date_asc' || $orderby == 'date_desc') { $key = filemtime($entry) . rand(10000, 99999); $images[$key] = $entry; } else { $images[] = $entry; } } } $dir->close(); } if ($orderby == 'date_asc') { ksort($images); } else { if ($orderby == 'date_desc') { ksort($images); $images = array_reverse($images); } else { if ($orderby == 'alphabet') { natcasesort($images); } else { shuffle($images); } } } // Cut it to the desired length.. $images = array_slice($images, 0, $limit); // Built the parms $tooltip = getDefault($PIVOTX['config']->get('slideshow_tooltip'), $slideshow_config['slideshow_tooltip']); $ttopacity = getDefault($PIVOTX['config']->get('slideshow_ttopacity'), $slideshow_config['slideshow_ttopacity']); $uibefore = getDefault($PIVOTX['config']->get('slideshow_uibefore'), $slideshow_config['slideshow_uibefore']); $zc = getDefault($PIVOTX['config']->get('slideshow_zc'), $slideshow_config['slideshow_zc']); $zcimg = ''; if (isset($zc)) { $zcimg = '&zc=' . $zc; } if ($tooltip == 1) { $parms = "{toolTip: true"; } else { $parms = "{toolTip: false"; } $parms .= ", ttOpacity: " . $ttopacity; if ($uibefore == 1) { $parms .= ", uiBefore: true}"; } else { $parms .= ", uiBefore: false}"; } $js_insert = str_replace('%timeout%', $timeout, $js_insert); $js_insert = str_replace('%count%', $slideshowcount, $js_insert); $js_insert = str_replace('%amount%', count($images), $js_insert); $js_insert = str_replace('%parms%', $parms, $js_insert); $PIVOTX['extensions']->addHook('after_parse', 'insert_before_close_head', $js_insert); // If a specific popup type is selected execute the callback. if ($popup != 'no') { $callback = $popup . "IncludeCallback"; if (function_exists($callback)) { $PIVOTX['extensions']->addHook('after_parse', 'callback', $callback); } else { debug("There is no function '{$callback}' - the popups won't work."); } } $output = "\n<div id=\"pivotx-slideshow-{$slideshowcount}\" class=\"svw\">\n<ul>\n"; foreach ($images as $image) { $file = $image; $image = str_replace($PIVOTX['paths']['upload_base_path'], '', $image); $image = str_replace(DIRECTORY_SEPARATOR, '/', $image); $nicefilename = formatFilename($image, $nicenamewithdirs); $title = false; if ($iptcindex) { getimagesize($file, $iptc); if (is_array($iptc) && $iptc['APP13']) { $iptc = iptcparse($iptc['APP13']); $title = $iptc[$iptcindex][0]; if ($iptcencoding) { $title = iconv($iptcencoding, 'UTF-8', $title); } $title = cleanAttributes($title); } } if (!$title) { $title = $nicefilename; } $line = "<li>\n"; if ($popup != 'no') { $line .= sprintf("<a href=\"%s%s\" class=\"{$popup}\" rel=\"slideshow\" title=\"%s\">\n", $PIVOTX['paths']['upload_base_url'], $image, $title); } $line .= sprintf("<img src=\"%sincludes/timthumb.php?src=%s&w=%s&h=%s%s\" " . "alt=\"%s\" width=\"%s\" height=\"%s\" />\n", $PIVOTX['paths']['pivotx_url'], rawurlencode($image), $width, $height, $zcimg, $title, $width, $height); if ($popup != 'no') { $line .= "</a>"; } $line .= "</li>\n"; $output .= $line; } $output .= "</ul>\n</div>\n"; $slideshowcount++; return $output; }