I have some code to get it to work, but of course there need to have some tweaks between All and frontpage/upcoming. This is because frontpage/upcoming means filtering will be applied (if category is not specified) but when All is selected, it really mean all without filtering.
Anyway, this is the changes I made based on cookie as I haven't done the user profile setting that you have mentioned
In libs/search.php, I changed from
PHP Code:
//$catId = $db->get_var("SELECT category_id from " . table_categories . " where category_name = '" . $this->category . "';");
$catId = get_category_id($this->category);
if(isset($catId)){
$child_cats = '';
// do we also search the subcategories?
if($this->search_subcats == true){
$child_array = '';
// get a list of all children and put them in $child_array.
children_id_to_array($child_array, table_categories, $catId);
if ($child_array != '') {
// build the sql
foreach($child_array as $child_cat_id) {
$child_cat_sql .= ' OR `link_category` = ' . $child_cat_id . ' ';
}
}
}
$from_where .= " AND (link_category=$catId " . $child_cat_sql . ")";
and added an else block
PHP Code:
//$catId = $db->get_var("SELECT category_id from " . table_categories . " where category_name = '" . $this->category . "';");
$catId = get_category_id($this->category);
if(isset($catId)){
$child_cats = '';
// do we also search the subcategories?
if($this->search_subcats == true){
$child_array = '';
// get a list of all children and put them in $child_array.
children_id_to_array($child_array, table_categories, $catId);
if ($child_array != '') {
// build the sql
foreach($child_array as $child_cat_id) {
$child_cat_sql .= ' OR `link_category` = ' . $child_cat_id . ' ';
}
}
}
$from_where .= " AND (link_category=$catId " . $child_cat_sql . ")";
} else {
if ($_COOKIE['TestCookie'] != "" ) {
//echo '<br>TestCookie' . $_COOKIE['TestCookie'] . '<br>';
$child_array = '';
children_id_to_array_with_filter($child_array, table_categories, 0, ';' . $_COOKIE['TestCookie'] );
if ($child_array != '') {
// build the sql
$counter = 0;
foreach($child_array as $child_cat_id) {
if ($counter > 0) {
$child_cat_sql .= ' OR `link_category` = ' . $child_cat_id . ' ';
} else {
$child_cat_sql .= '`link_category` = ' . $child_cat_id . ' ';
}
$counter = $counter + 1;
}
$from_where .= " AND (" . $child_cat_sql . ")";
}
}
}
As you see, the filter is based on a cookie named TestCookie. ie the value set to 1;3;5 means that category 1,3,5 and its descendants will be filtered.
I also added one method to dbtree.php
PHP Code:
function children_id_to_array_with_filter(&$child_array, $table, $parent, $filter) {
global $db;
// retrieve all children of $parent
$sql = 'SELECT category__auto_id FROM '.$table.' WHERE category_parent="'.$parent.'" and category__auto_id <> 0;';
$result = $db->get_results($sql);
if($result){
foreach ($result as $row){
//echo $filter . ' , '. $row->category__auto_id . ',' . stripos($filter,';'.$row->category__auto_id . ';') . '<br>';
if (!(strpos($filter,';'.$row->category__auto_id . ';'))) {
//echo 'matched <br>';
$child_array[] = $row->category__auto_id;
// call this function again to display this child's children
children_id_to_array_with_filter($child_array, $table, $row->category__auto_id, $filter);
}
}
}
}
For testing purpose right now, I made a test.php to set the filter
PHP Code:
<html>
<body>
<?php
echo "old value " . $_COOKIE['TestCookie'] . "<br>";
if($_GET['filter'] == "")
#
{
echo "test cookie = " . $_COOKIE['TestCookie'] . "<br>";
echo "a" . stripos($_COOKIE['TestCookie'], ';1;'). "<br>";
#
} else if ($_GET['filter'] == "e") {
echo "You did not enter a name.";
setcookie("TestCookie", "", time()-3600); /* expire it */
} else {
echo "You entered a name." . $_GET['filter']. "<br>";
if ($_COOKIE['TestCookie'] != "") {
setcookie("TestCookie", $_COOKIE['TestCookie'] . $_GET['filter'] . ';'); /* expire it */
} else {
setcookie("TestCookie", ';' . $_GET['filter'] . ';') ; /* expire it */
}
echo "new value " . $_COOKIE['TestCookie'] . "<br>";
}
echo "<br>" ;
?>
</body>
</html>
I put it to the root and
http://<your host>/test.php to see the filter
http://<your host>/test.php?filter=1 to add filter category 1
http://<your host>/test.php?filter=e to erase the cookie.
Can anyone gives me the UI? I am really bad at UI setup and I can finish the rest and post it here.