function children_id_to_array_2(&$child_array, $table, $parent) { // a cleaner version of children_id_to_array // retrieve all children of $parent $sql = 'SELECT category__auto_id FROM ' . $table . ' WHERE category_parent="' . $parent . '" and category__auto_id <> 0;'; $result = mysql_query($sql); // for each child... while ($row = mysql_fetch_array($result)) { $child_array[] = $row['category__auto_id']; // call this function again to display this child's children children_id_to_array_2($child_array, $table, $row['category__auto_id']); } }
function doSearch() { global $db, $main_smarty; $search_clause = $this->get_search_clause(); // set smarty variables if (isset($this->searchTerm)) { $main_smarty->assign('search', $this->searchTerm); $main_smarty->assign('searchtext', htmlspecialchars($this->searchTerm)); } else { $main_smarty->assign('searchtext', ''); } $from_where = "FROM " . $this->searchTable . " WHERE "; if ($this->filterToStatus == 'all') { $from_where .= " link_status!='discard' "; } if ($this->filterToStatus == 'queued') { $from_where .= " link_status='queued' "; } if ($this->filterToStatus == 'discard') { $from_where .= " link_status='discard' "; } if ($this->filterToStatus == 'published') { $from_where .= " link_status='published' "; } if ($this->filterToStatus == 'popular') { $from_where .= " link_status='published' "; } if ($this->filterToTimeFrame == 'today') { $tsdt = date('Ymd000000', strtotime("now")); $fsdt = date('Ymd235959', strtotime("now")); $from_where .= " AND (link_published_date >= {$tsdt} AND link_published_date <= {$fsdt}) "; } if ($this->filterToTimeFrame == 'yesterday') { $tsdt = date('Ymd000000', strtotime("-1 day")); $fsdt = date('Ymd235959', strtotime("-1 day")); $from_where .= " AND (link_published_date >= {$tsdt} AND link_published_date <= {$fsdt}) "; } if ($this->filterToTimeFrame == 'week') { $wknum = date('w', strtotime("now")); if ($wknum > 0) { $tsdt = date('Ymd000000', strtotime("-{$wknum} day")); $fsdt = date('Ymd235959', strtotime("now")); } else { $tsdt = date('Ymd000000', strtotime("now")); $fsdt = date('Ymd235959', strtotime("now")); } $from_where .= " AND (link_published_date >= {$tsdt} AND link_published_date <= {$fsdt}) "; } if ($this->filterToTimeFrame == 'month') { $tsdt = date('Ym01000000', strtotime("now")); $fsdt = date('Ym31235959', strtotime("now")); $from_where .= " AND (link_published_date >= {$tsdt} AND link_published_date <= {$fsdt}) "; } if ($this->filterToTimeFrame == 'year') { $tsdt = date('Y0101000000', strtotime("now")); $fsdt = date('Y1231235959', strtotime("now")); $from_where .= " AND (link_published_date >= {$tsdt} AND link_published_date <= {$fsdt}) "; } // get links newer than $newerthan if (isset($this->newerthan)) { $from_where = $from_where . "AND UNIX_TIMESTAMP(link_date) > " . $this->newerthan; $from_text = PLIGG_Visual_Search_WithinTheLast . intval((time() - $this->newerthan) / 86400) . PLIGG_Visual_Search_Days; } else { $from_datetime = ""; $from_text = ""; } //should we filter to just this category? if (isset($this->category)) { $catId = $db->get_var("SELECT category_id from " . table_categories . " where category_name = '" . $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_2($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 . ")"; } } if (isset($this->orderBy)) { $this->orderBy = "ORDER BY " . $this->orderBy; } if ($this->searchTerm == "") { // like when on the index or upcoming pages. $this->sql = "SELECT DISTINCT link_id {$from_where} {$search_clause} {$this->orderBy} LIMIT {$this->offset},{$this->pagesize}"; } else { $this->sql = "SELECT link_id, link_date, link_published_date {$from_where} {$search_clause} "; } $this->countsql = "SELECT count(*) {$from_where} {$search_clause} {$this->orderBy}"; return; }