<?php
$temp = explode("?", $_SERVER['REQUEST_URI']);
//filter by gallery categories
$filter = explode("filter=", $_SERVER['REQUEST_URI']);
$filter = (int)$filter[1];
//master filter passed from gallery include mod
if($gobalFilter)
{
$filter = (int)$gobalFilter;
}
//go to first gallery if there is only one, but only if gallery setting is yes
$show_gallery_cats_onload = settings('show_gallery_cats_onload');
if($filter == 0 && $show_gallery_cats_onload['show_gallery_cats_onload'] == 'n')
{
$q = $mysql->query("ID", $mysql->perfix."gallery_cats", "password = '' ORDER BY `order` LIMIT 1");
$check = $mysql->num_rows($q);
if($check == 1)
{
$filter = $mysql->get_array($q);
$filter = ((int)$filter['ID'] > 0) ? $filter['ID'] : 0;
}
}
//if filter isnt set, show categories
if($filter == 0)
{
$catquery = $mysql->query("ID,name,password", $mysql->perfix."gallery_cats", "1 ORDER BY `order`");
while($cats = $mysql->get_array($catquery))
{
//first image from the category
$img = $mysql->get_array($mysql->query("thumb", $mysql->perfix."gallery", "cat = {$cats['ID']} ORDER BY `order` ASC LIMIT 1"));
//if the category is password protected and user hasn't logged in, show the lock image
if(!empty($cats['password']))
{
if(!isset($_COOKIE['gallery'.$filter]))
{
$img['thumb'] = 'lock.jpg';
}
}
//image table
$img = '<a href="'.$temp[0].'?filter='.$cats['ID'].'"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.$img['thumb'].'\')" border="0" alt="'.stripslashes($cats['name']).'" /></a>';
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th>'.$img.'</th><tr><td>'.stripslashes($cats['name']).'</td></tr></table>';
}
}
//category jump menu
if($filter > 0)
{
$catquery = $mysql->query("ID,name", $mysql->perfix."gallery_cats", "1 ORDER BY `order`");
$temp = explode("?", $_SERVER['REQUEST_URI']);	
//categories link list
if($mysql->num_rows($catquery) <= 10)
{
$array['images'] = '<a name="gall"></a><p>Gallery Categories:';
while($cats = $mysql->get_array($catquery))
{
if(!empty($cats['password']))
{
if(isset($_COOKIE['gallery'.$cats['ID']]))
{
$array['images'] .= '<a href="/'.$url['pid'].'/'.seo_str($cats['name']).'?filter='.$cats['ID'].'#gall">'.stripslashes($cats['name']).'</a>|';
}
else
{
$array['images'] .= '<a href="javascript:;" onclick="window.open(\'/inc/gallery/login.php?cat='.$cats['ID'].'\',\'\',\'status=yes,scrollbars=yes,resizable=yes,width=400,height=150\');">'.stripslashes($cats['name']).'</a>|';
}	
}
else
{
$array['images'] .= '<a href="/'.$url['pid'].'/'.seo_str($cats['name']).'?filter='.$cats['ID'].'#gall">'.stripslashes($cats['name']).'</a>|';
}
}
$array['images'] = substr($array['images'], 0, -1);
$array['images'] .= '</p>';
}
else//categories dropdown menu
{
$array['images'] = '<a name="gall"></a><p>Gallery Categories: <select name="j" onchange="window.location=this.value;">';
while($cats = $mysql->get_array($catquery))
{
$link = '/'.$url['pid'].'/'.seo_str($cats['name']).'/?filter='.$cats['ID'].'#gall';
if(!empty($cats['password']))
{
if(!isset($_COOKIE['gallery'.$cats['ID']]))
{
$link = '/inc/gallery/login.php?cat='.$cats['ID'].'#gall';
}
}
$selected = ($filter == $cats['ID']) ? ' selected' : '';
$array['images'] .= '<option value="'.$link.'"'.$selected.'>'.stripslashes($cats['name']).'</option>';
}
$array['images'] .= '</select></p>';
}
//pics
$query = $mysql->query("ID,caption,thumb,large,link", $mysql->perfix."gallery", "cat = $filter ORDER BY `order` ASC");
while($data1 = $mysql->get_array($query))
{
$protected = $mysql->get_array($mysql->query("password", $mysql->perfix."gallery_cats", "ID = $filter LIMIT 1"));
if(!empty($protected['password']))
{
if(isset($_COOKIE['gallery'.$filter]))
{
$class = (empty($data1['link'])) ? 'lightbox' : '';
$link = (empty($data1['link'])) ? '/inc/gallery/large/'.stripslashes($data1['large']) : $data['link'];
$blank = (empty($data1['link'])) ? '' : ' target="_blank"';
$img = '<a href="'.$link.'" class="'.$class.'"'.$blank.' title="'.stripslashes($data1['caption']).'"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.stripslashes($data1['thumb']).'\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a>';
}
else
{
$img = '<a href="javascript:;" onclick="window.open(\'/inc/gallery/login.php?cat='.$filter.'\',\'\',\'status=yes,scrollbars=yes,resizable=yes,width=400,height=150\');">
<img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/lock.jpg\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a>';
}
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th>'.$img.'</th><tr><td>'.stripslashes($data1['caption']).'</td></tr></table>';
}
else
{
$class = (empty($data1['link'])) ? 'lightbox' : '';
$link = (empty($data1['link'])) ? '/inc/gallery/large/'.stripslashes($data1['large']) : $data1['link'];
$blank = (empty($data1['link'])) ? '' : ' target="_blank"';
$array['images'] .= '<table border="0" cellspacing="0" cellpadding="0"><tr><th><a href="'.$link.'"'.$blank.' class="'.$class.'" title="'.stripslashes($data1['caption']).'"><img src="/inc/gallery/images/clear.gif" style="background-image: url(\'/inc/gallery/thumbs/'.stripslashes($data1['thumb']).'\')" border="0" alt="'.stripslashes($data1['caption']).'" /></a></th><tr><td>'.stripslashes($data1['caption']).'</td></tr></table>';
}
}
}
if($gobalFilter)
{
echo '<div id="gallery">'.$array['images'].'</div>'."<script>
jQuery('.lightbox').magnificPopup({
type: 'image',
gallery:{enabled:true}
});</script>";
}
else
{
$mainhtml .= '<div id="gallery">'.$array['images'].'</div>';
$mainhtml .= "<script>
jQuery('.lightbox').magnificPopup({
type: 'image',
gallery:{enabled:true}
});</script>";
}
//place css and js in the head
$code = '<link rel="stylesheet" href="/inc/gallery/src/lightbox.css" type="text/css" media="screen" />';
if(!strstr($mainhtml, '/jquery/'))
{
$code .= '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>';
}
$code .= '<script src="/inc/gallery/src/lightbox.js"></script>';
$mainhtml = str_replace("</head>", $code.'</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/gallery_lightbox.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/gallery_lightbox.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/gallery_lightbox.css" /></head>', $mainhtml);
}
//end
?>