Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
function plogger_init_search($arr) {
$terms = explode(" ",$arr['searchterms']);
$from = 0;
$limit = 20;
if (isset($arr['from']) && $arr['from'] > 0) {
$from = $arr['from'];
}
// enforce hard-coded max limit
if (isset($arr['limit']) && $arr['limit'] > 0 && $arr['limit'] <= 100) {
$limit = $arr['limit'];
}
$query = " FROM `".TABLE_PREFIX."pictures` p LEFT JOIN `".TABLE_PREFIX."comments` c
ON p.`id` = c.`parent_id` ";
if ((count($terms) != 1) || ($terms[0] != '')){
$query .= " WHERE ( ";
foreach ($terms as $term) {
$term = mysql_real_escape_string($term);
$multi_term = explode("+",$term);
if (count($multi_term)>1) {
$path = implode("%' AND `path` LIKE '%",$multi_term);
$description = implode("%' AND `description` LIKE '%",$multi_term);
$comment = implode("%' AND `comment` LIKE '%",$multi_term);
$caption = implode("%' AND `caption` LIKE '%",$multi_term);
} else {
$path = $description = $comment = $caption = $term;
}
$query .= "
`path` LIKE '%$path%' OR
`description` LIKE '%$description%' OR
`comment` LIKE '%$comment%' OR
`caption` LIKE '%$caption%' OR ";
}
$query = substr($query, 0, strlen($query) - 3) .") ";
} else {
// no search terms? no results either
$query .= " WHERE 1 = 0";
}
$sort_fields = array('date_submitted','id');
$sortby = 'date_submitted';
if (isset($arr['sortby']) && in_array($arr['sortby'],$sort_fields)) {
$sortby = $arr['sortby'];
}
$sortdir = ' DESC';
if (isset($arr['sortdir']) && 'asc' == $arr['sortdir']) {
$sortdir = ' ASC';
}
$result = run_query("SELECT COUNT(DISTINCT p.`id`) AS cnt " . $query);
$row = mysql_fetch_assoc($result);
$GLOBALS["total_pictures"] = $row["cnt"];
// and I need sort order here as well
// from and limit too
$result = run_query("SELECT `caption`,`path`,p.`id`,c.`comment`,
UNIX_TIMESTAMP(`date_submitted`) AS `unix_date_submitted` ".$query .
" GROUP BY p.`id` ORDER BY `$sortby` $sortdir LIMIT $from,$limit");
$GLOBALS["available_pictures"] = mysql_num_rows($result);
$GLOBALS["picture_counter"] = 0;
$GLOBALS["picture_dbh"] = $result;
}
1 to 10 of 10