<?
define("IN_SEARCH",1);
include "includes/inc.php";
$baseUrl='search.php?';
require_once("header.php");
$input[s]=intval($input[s]);
if(!in_array($input[in],array('i','g'))) $input[in]='i';
if(strlen($input[text])<3)
{
die($input[text]);
}
# escape the text
$input[text] = $db->getEscaped($input[text]);
/**
* Search in galleries
*/
if($input[in]=='g')
{
$per_num=10;
$search_cond = "g.name like '%$input[text]%' or g.descr like '%$input[text]%'";
# get searched galleries
$TotalSearched = GetGalleryNums($search_cond);
# list the gallery by pages
$orderby='totals';
$rows = ListGallery(array('','','',$search_cond),$orderby,$user_id,$per_num,1,$input[s]);
$template->set_filenames(array(
'listings' => 'dir.listings.html',
));
if($rows)
foreach($rows as $row)
{
$i++;
if($i%2)$row['class']='tdrow1';else $row['class']='tdrow2';
$row[gallery_dir]=$row[galleryname];
$row[domain]=$user->servers[$row[server_id]][domain];
$urls=getUrl($row,$GalleryViewScript);
extract($urls);
$row[user] = $input[user];
$row[galleryurl]=$galleryurl;
$row[thumburl]=$thumburl;
$row[totalsize]=convertsize($row[totalsize]);
$template->assign_block_vars('listing', $row);
}
if($rows) $template->assign_var_from_handle('inc_gallery_listings','listings');
}
/**
* Search in images
*/
if($input[in]=='i')
{
$per_num=30;
$search_cond = "i.name like '%$input[text]%' or i.tags like '%,$input[text],%'";
// append the synonyms
$db->setQuery("select tag_name from tags where tag_synonym like '%,$input[text],%'");
$db->query();
$tag_rows = $db->loadRowList();
foreach($tag_rows as $tag_row)
{
$search_cond .= " or i.tags like '%,$tag_row[tag_name],%'";
}
$search_cond = '('.$search_cond.')';
# get nums of images
$TotalSearched = GetImageNums($search_cond);
# list the images by condition
$info=array('searchimg','inc_search_image_list','SearchImage',$search_cond);
$orderby='i.views';
ListImages($info,$orderby,$per_num,4,$input[s]);
}
# build page links for multiple pages
$cur_page=$input[s]/$per_num;
$info=array( 'total' =>$TotalSearched,
'page' =>$per_num,
'cur_page' =>$cur_page,
'baseUrl' =>$baseUrl."&text=".$input[text],
);
$pageLinks=buildPageLinks($info);
if($page<0) $page=0;
if($page>0) $template->assign_block_vars('pre_link',array('s'=>($page-$per_num)));
if($page+$showimages<$totals) $template->assign_block_vars('next_link',array('s'=>($page+$per_num)));
# assign some global vars
$template->assign_vars(array('pageLinks'=>$pageLinks,'TotalSearched'=>$TotalSearched,'search_text'=>$input[text]));
# parsing templates
if($input[in]=='i')
{
$template->set_filenames(array(
'body' => 'img.search.html'
));
$template->pparse('body');
include "footer.php";
}
if($input[in]=='g')
{
$template->set_filenames(array(
'body' => 'dir.search.html'
));
$template->pparse('body');
include "gallery_footer.php";
}
?>