Topic: [HACK] search within categories
Name: search within categories
Author: NyNe
CuteNews Compatibility: 1.3.6 - 1.4.1 (incompatibility in higher versions due to multiple categories)
Description: adds an option in the advanced search where you can select a single category
Instructions:
open search.php
find TWICE:
"user",
add after BOTH:
"category",
find:
// Show Search Form
add above:
// Define Categories
$cat_lines = file("$cutepath/data/category.db.php");
foreach($cat_lines as $single_line){
$cat_arr = explode("|", $single_line);
$cat[$cat_arr[0]] = $cat_arr[1];
$cat_icon[$cat_arr[0]]=$cat_arr[2];
}
find:
<tr>
<td width="100%" align="right">Author <input type=text value="$user" name=user size="24">
</tr>
add below:
<!-- search cats -->
HTML;
if(count($cat_lines) > 0){
echo"<tr>
<td width=\"100%\" align=\"right\">
Category
<select name=category>\n
<option value=\"\" selected>- All -</option>\n";
foreach($cat_lines as $single_line){
$cat_arr = explode("|", $single_line);
if (strlen($cat_arr[1]) > 17) { $cat_arr['disp'] = substr($cat_arr[1], 0, 17 - 3) . '...'; }
else { $cat_arr['disp'] = $cat_arr[1]; }
echo"<option value=\"$cat_arr[0]\">$cat_arr[disp]</option>\n";
}
echo"</select></tr>";
}
echo <<<HTML
<!-- search cats -->
find:
$found = 0;
add below:
$fcat = FALSE;
find:
if($story and (@preg_match("/$story/i", "$news_db_arr[4]") or @preg_match("/$story/i", "$news_db_arr[3]"))){ $fstory = TRUE;}
add below:
if($category == $news_db_arr[6]){ $fcat = TRUE;}
find:
if($user and $fuser) { $fuser = TRUE; }elseif(!$user) { $fuser = TRUE; }else{ $fuser = FALSE; }
add below:
if($category and $fcat) { $fcat = TRUE; }elseif(!$category) { $fcat = TRUE; }else{ $fcat = FALSE; }
find:
$fdate and $ftitle and $fuser and $fstory
add after:
and $fcat
find:
if($local_id == $news_id){
////////// Showing Result
echo"
[b][url=]$item_arr[2][/url][/b] (". date("d F, Y", $item_arr[0]) .")";
////////// End Showing Result
}
replace with:
// search cats
if($category == $item_arr[6] || $fcat == TRUE || !isset($category)){
if($local_id == $news_id){ echo"
[b][url=]$item_arr[2][/url][/b] (". date("d F, Y", $item_arr[0]) .")"; }
}
// show cats