/** * Constructor * Sets up private search variables * * @author Tony Bibbs, tony AT geeklog DOT net */ public function __construct() { global $_CONF, $_TABLES; // Set search criteria if (isset($_GET['query'])) { $query = COM_stripslashes($_GET['query']); $query = GLText::remove4byteUtf8Chars($query); $this->_query = strip_tags($query); } if (isset($_GET['topic'])) { // see if topic exists $tid = COM_applyFilter($_GET['topic']); // If it exists and user has access to it, it will return itself else an empty string $tid = DB_getItem($_TABLES['topics'], 'tid', "tid = '{$tid}'" . COM_getPermSQL('AND', 0, 2)); $this->_topic = $tid; } else { if ($_CONF['search_use_topic']) { $last_topic = SESS_getVariable('topic'); if ($last_topic != '') { $this->_topic = $last_topic; } } } if (isset($_GET['datestart'])) { $this->_dateStart = COM_applyFilter($_GET['datestart']); } if (isset($_GET['dateend'])) { $this->_dateEnd = COM_applyFilter($_GET['dateend']); } if (isset($_GET['author'])) { $this->_author = COM_applyFilter($_GET['author']); // In case we got a username instead of uid, convert it. This should // make custom themes for search page easier. if (!is_numeric($this->_author) && !preg_match('/^([0-9]+)$/', $this->_author) && $this->_author != '') { $this->_author = DB_getItem($_TABLES['users'], 'uid', 'username=\'' . DB_escapeString($this->_author) . '\''); } if ($this->_author < 1) { $this->_author = ''; } } $this->_type = isset($_GET['type']) ? COM_applyFilter($_GET['type']) : 'all'; $this->_keyType = isset($_GET['keyType']) ? COM_applyFilter($_GET['keyType']) : $_CONF['search_def_keytype']; $this->_titlesOnly = isset($_GET['title']) ? true : false; }
/** * Figure out the current topic for a plugin. If permissions or language wrong * will find default else end with a '' topic (which is all). Needs to be run * on page that is affected by the topic after lib-common.php so it can grab * topic in url if need be. Also if pass blank $type and $id then return just last topic * * @param string $type Type of object to find topic access about. * @param string/array $id ID of object * @return void * */ function TOPIC_getTopic($type = '', $id = '') { global $_TABLES, $topic; $find_another = false; $found = false; // Double check $topic = COM_applyFilter($topic); if ($topic == TOPIC_ALL_OPTION) { $topic = ''; // Do not use 'all' option. Nothing is the same thing } // See if user has access to view topic if ($topic != '') { $test_topic = DB_getItem($_TABLES['topics'], 'tid', "tid = '{$topic}' " . COM_getPermSQL('AND')); if (strtolower($topic) != strtolower($test_topic)) { $topic = ''; } else { // Make it equal to the db version since case maybe different $topic = $test_topic; } } // Check and return Previous topic if ($topic == '') { // Blank could mean all topics or that we do not know topic // retrieve previous topic $last_topic = SESS_getVariable('topic'); } else { $last_topic = $topic; } // *********************************** // Special Cases if ($type == '') { // used by search, submit, etc to find last topic $topic = $last_topic; $found = true; } elseif ($type == 'comment') { if ($id != '') { // Find comment objects topic $sql = "SELECT type, sid\n FROM {$_TABLES['comments']}\n WHERE cid = '{$id}'"; $result = DB_query($sql); $nrows = DB_numRows($result); if ($nrows > 0) { $A = DB_fetchArray($result); // Found comment object so now reset type and id variables $type = $A['type']; $id = $A['sid']; } else { // Could not find comment so set topic to nothing (all) $topic = ''; $found = true; } } else { // If no id then probably a submit form $topic = $last_topic; $found = true; } } // *********************************** if (!$found) { if ($last_topic != '') { // see if object belongs to topic or any child inherited topics $tid_list = TOPIC_getChildList($last_topic); $sql = "SELECT ta.tid\n FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta\n WHERE t.tid = ta.tid\n AND ta.type = '{$type}' AND ta.id = '{$id}'\n AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$last_topic}')))\n " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't') . " ORDER BY tdefault DESC, tid ASC"; // Order by default first and then tid alphabetically since no defined sort order of topics. This needs to be the same as when topics are displayed (index.php) $result = DB_query($sql); $nrows = DB_numRows($result); if ($nrows > 0) { $A = DB_fetchArray($result); $topic = $A['tid']; // Default topic if returned else first topic in order by tid // Need to check if topic assignment exists for last topic if so make that the topic instead while ($A = DB_fetchArray($result)) { if ($last_topic == $A['tid']) { $topic = $A['tid']; } } } else { $find_another = true; } } else { $find_another = true; } if ($find_another) { // Find another topic to set, most likely default $sql = "SELECT ta.*\n FROM {$_TABLES['topics']} t, {$_TABLES['topic_assignments']} ta\n WHERE t.tid = ta.tid\n AND ta.type = '{$type}' AND ta.id = '{$id}'\n " . COM_getLangSQL('tid', 'AND', 't') . COM_getPermSQL('AND', 0, 2, 't') . "\n ORDER by ta.tdefault DESC"; $result = DB_query($sql); $nrows = DB_numRows($result); if ($nrows > 0) { $A = DB_fetchArray($result); $topic = $A['tid']; } else { $topic = ''; } } } }