<?php
include('include/autoloader.php');
$smarty->assign('is_search',1);
$ur = explode('?',curPageURL());
if (count($ur) != 0) {
if (isset($ur[1])) {
parse_str($ur[1],$q);	
}
}
if (isset($q['query']) AND !empty($q['query'])) {
$search_q = make_safe(xss_clean(htmlspecialchars($q['query'],ENT_QUOTES)));
$smarty->assign('query',$search_q);	
if ($options['theme_pagination_load'] == 'normal') {
$page = 1;
if (isset($options['theme_search_media_number'])) {
	$size = $options['theme_search_media_number'];
} else {
	$size = 24;
}
if (isset($q['page'])){ $page = (int) $q['page']; }
$sqls = "SELECT * FROM media WHERE published='1' AND deleted='0' AND (title LIKE '%$search_q%' OR tags LIKE '%$search_q%')";
$query = $mysqli->query($sqls);
$total_records = $query->num_rows;
$smarty->assign('total_records',$total_records);
if ($total_records > 0) {
$pagination = new Pagination();
$pagination->setLink("./search/?query=$search_q&page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
$get = "SELECT * FROM media WHERE published='1' AND deleted='0' AND (title LIKE '%$search_q%' OR tags LIKE '%$search_q%') ORDER BY id DESC ".$pagination->getLimitSql();
$qu = $mysqli->query($get);
while ($row = $qu->fetch_assoc()) {
	$media[] = $row;
}
$smarty->assign('media',$media);
$smarty->assign('pagi',$pagination->create_links());
}
}
} else {
$search_q = '';
$smarty->assign('query','');		
}
$smarty->assign('seo_title',$language['search_for'].' '.$search_q.' - '.$options['general_seo_title']);
$smarty->assign('seo_keywords',$options['general_seo_keywords']);
$smarty->assign('seo_description',$options['general_seo_description']);
$smarty->display('search.html');	
?>