<?php
//returns html for a nivo slideShow
function nivoSlideShow($id)
{
global $mysql;
$captions = array();
$setting = $mysql->get_array($mysql->query("show_width", "fs_slideshows", "ID = '$id' LIMIT 1"));
$html = ($setting['show_width'] > 0) ? '<div style="max-width:'.$setting['show_width'].'px;">' : '';
$html .= '<div class="theme-default controlnav-thumbs">';
$html .= '<div id="slider'.$id.'" class="nivoSlider">';
$query = $mysql->query("ID,image,caption,url,thumb", "fs_slideshows_images", "show_id = '$id' ORDER BY `order` ASC");
while($d = $mysql->get_array($query))
{
$cap = (!empty($d['caption'])) ? ' title="#caption'.$d['ID'].'"' : '';
$html .= (!empty($d['url'])) ? '<a href="'.$d['url'].'">' : '';
$html .= '<img src="/inc/slideshow/'.$d['image'].'" alt=""'.$cap.' rel="/inc/slideshow/'.$d['thumb'].'" />';
$html .= (!empty($d['url'])) ? '</a>' : '';
$captions[$d['ID']] = stripslashes($d['caption']);
}
$html .= '</div>';
foreach($captions as $id => $text)
{
$html .= (!empty($text)) ? '<div id="caption'.$id.'" class="nivo-html-caption">'.$text.'</div>' : '';
}
$html .= '</div>';
$html .= ($setting['show_width'] > 0) ? '</div>' : '';
return $html;
}
//returns html for superSize slide show
function superSizedSlideShow($id)
{
global $mysql;
$s = $mysql->get_array($mysql->query("effect,speed,show_nextprev", "fs_slideshows", "ID = '$id' LIMIT 1"));
$html = '<div id="supersized-wrap">';
if($s['show_nextprev'] == 'y')
{
$html .= '<!--Arrow Navigation--><a id="prevslide" class="load-item"></a><a id="nextslide" class="load-item"></a>';
}
$html .= '<div id="slidecaption"></div></div>
<script>
jQuery(function($){
$.supersized({
autoplay:1,					
slide_interval:'.($s['speed']*1000).',
transition:\''.$s['effect'].'\',
transition_speed:700,
keyboard_nav:1,
slides:[';
$query = $mysql->query("ID,image,caption,url", "fs_slideshows_images", "show_id = '$id' ORDER BY `order` ASC");
while($d = $mysql->get_array($query))
{
$html .= "{image:'/inc/slideshow/{$d['image']}', title:\"".addslashes($d['caption'])."\", url:'{$d['url']}'},";
}
$html = substr($html, 0, -1);
$html .= ']});});</script>';
return $html;
}
//checks which slideshow it is 
function slideShow($id)
{
global $mysql;
$type = $mysql->get_array($mysql->query("slider", "fs_slideshows", "ID = '$id' LIMIT 1"));
if($type['slider'] == 'superSize')
{
return superSizedSlideShow($id);
}
else
{
return nivoSlideShow($id);
}
}
//check for slideshows, replaces images with show code
$sliderCount = array('superSize' => 0, 'nivo' => 0);
if(strstr($mainhtml, 'class="slideShow"') || strstr($mainhtml, 'class=slideShow'))
{
$slidersFound = array();
preg_match_all('/<img[^>]+>/i', $mainhtml, $allImages);
if(is_array($allImages[0]))
{
foreach($allImages[0] as $key => $image)
{
list($junk, $id) = explode("?id=", $image);
preg_match("(^[0-9]+)", $id, $ID);
$id = (int)$ID[0];
if($id > 0 && strstr($image, 'slideShow'))
{
$show_content = slideShow($id);
$isNivo = $mysql->num_rows($mysql->query("slider", "fs_slideshows", "slider = 'nivo' AND ID = '$id' LIMIT 1"));
if($isNivo)
{
$sliderCount['nivo']++;
$mainhtml = str_replace($image, $show_content, $mainhtml);
}
else//supersize, place the slideshow wrap just before content div
{
$sliderCount['superSize']++;
$mainhtml = str_replace($image, '', $mainhtml);
$mainhtml = str_replace('<div id="content">', $show_content.'<div id="content">', $mainhtml);
}
$slidersFound[] = $id;
}
}
}
//add jquery if it isnt already loaded
if(!strstr($mainhtml, '/jquery/'))
{
$mainhtml = str_replace("</head>", '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script></head>', $mainhtml);
}
//build slider window load code and css
$loadCode = '';
$css = '';
if($sliderCount['nivo'] > 0)
{
foreach($slidersFound as $key => $id)
{
$setting = $mysql->get_array($mysql->query("effect,speed,show_nextprev,show_dots,show_width,show_height,show_thumbs", "fs_slideshows", "ID = '$id' LIMIT 1"));
$numImgs = $mysql->num_rows($mysql->query("ID", "fs_slideshows_images", "show_id = '$id'")); 
if($setting['show_thumbs'] == 'y')
{
$css .= '#slider'.$id.' .nivoSlider{margin-bottom:150px;}/*Tweak this to push content down */';
}
$show_nextprev = ($setting['show_nextprev'] == 'y') ? 'true' : 'false';
$show_dots = ($setting['show_dots'] == 'y' || $setting['show_dots'] == 't') ? 'true' : 'false';
$show_thumbs = ($setting['show_thumbs'] == 'y') ? 'true' : 'false';
$loadCode .= 'jQuery(window).load(function(){jQuery(\'#slider'.$id.'\').nivoSlider({
effect:\''.$setting['effect'].'\',
pauseTime:'.($setting['speed']*1000).',
directionNav:'.$show_nextprev.',
directionNavHide:true,
controlNav:'.$show_dots.',
controlNavThumbs:'.$show_thumbs.',
controlNavThumbsFromRel:'.$show_thumbs.'
});});
';
}
}
//call nivo slider
if($sliderCount['nivo'] > 0)
{
$mainhtml = str_replace("</head>", '<script src="/inc/slideshow/slider/jquery.nivo.slider.pack.js"></script><script type="text/javascript">'.$loadCode.'</script><link rel="stylesheet" href="/inc/slideshow/slider/nivo-slider.css" type="text/css" media="screen" /><link rel="stylesheet" href="/inc/slideshow/slider/default.css" type="text/css" media="screen" /><style type="text/css">.nivoSlider img{position:absolute;top:0px;left:0px;display:none;}.nivoSlider a{border:0;display:block;}'.$css.'</style></head>', $mainhtml);
}
if($sliderCount['superSize'] > 0)
{
$mainhtml = str_replace("</head>", '
<link rel="stylesheet" href="/inc/slideshow/superSize/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="/inc/slideshow/superSize/shutter.css" type="text/css" media="screen" />
<script src="/inc/slideshow/superSize/easing.js"></script>
<script src="/inc/slideshow/superSize/supersized.js"></script>
<script src="/inc/slideshow/superSize/shutter.js"></script>
</head>', $mainhtml);
}
//include this add-ons's overwrite css file from the template being used, if there is one
$t = settings('template');
if(file_exists('templates/'.$t['template'].'/addons/slideshow.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/slideshow.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/slideshow.css" /></head>', $mainhtml);
}
//
}
/****/
//check for gallery cateogries, replace images with gallery function call
if(strstr($mainhtml, 'class="galleryCategory"') || strstr($mainhtml, 'class=galleryCategory'))
{
$allImages = array();
$categoriesFound = array();
preg_match_all('/<img[^>]+>/i', $mainhtml, $allImages);
if(is_array($allImages[0]))
{
foreach($allImages[0] as $key => $image)
{
list($junk, $id) = explode("?id=", $image);
preg_match("(^[0-9]+)", $id, $ID);
$id = (int)$ID[0];
if($id > 0 && strstr($image, 'galleryCategory'))
{
$style = settings('gallery_style');
$galleryStyle = ($style['gallery_style'] == 'Slideshow') ? 'Slideshow' : 'LightBox';
$gobalFilter = $id;
ob_start();
include(fileInclude('inc/gallery/'.$galleryStyle.'.php'));
$show_content = ob_get_contents();
ob_end_clean();
$mainhtml = str_replace($image, $show_content, $mainhtml);
}
}
}
$mainhtml = str_replace("</head>", '<style>#gallery p{display:none;}</style></head>', $mainhtml);
}
?>