Example #1
0
 protected function buildWhere()
 {
     $db = JFactory::getDBO();
     $querystrings = array();
     foreach ($this->getSearchWords() as $searchword) {
         $searchword = $db->escape(JString::trim($searchword));
         if (empty($searchword)) {
             continue;
         }
         $not = '';
         $operator = ' OR ';
         if (substr($searchword, 0, 1) == '-' && strlen($searchword) > 1) {
             $not = 'NOT';
             $operator = 'AND';
             $searchword = JString::substr($searchword, 1);
         }
         if (!$this->getState('query.titleonly')) {
             $querystrings[] = "(t.message {$not} LIKE '%{$searchword}%' {$operator} m.subject {$not} LIKE '%{$searchword}%')";
         } else {
             $querystrings[] = "(m.subject {$not} LIKE '%{$searchword}%')";
         }
     }
     //User searching
     $username = $this->getState('query.searchuser');
     if ($username) {
         if ($this->getState('query.exactname') == '1') {
             $querystrings[] = "m.name LIKE '" . $db->escape($username) . "'";
         } else {
             $querystrings[] = "m.name LIKE '%" . $db->escape($username) . "%'";
         }
     }
     $time = 0;
     switch ($this->getState('query.searchdate')) {
         case 'lastvisit':
             $time = KunenaFactory::GetSession()->lasttime;
             break;
         case 'all':
             break;
         case '1':
         case '7':
         case '14':
         case '30':
         case '90':
         case '180':
         case '365':
             $time = time() - 86400 * intval($this->getState('query.searchdate'));
             //24*3600
             break;
         default:
             $time = time() - 86400 * 365;
     }
     if ($time) {
         if ($this->getState('query.beforeafter') == 'after') {
             $querystrings[] = "m.time > '{$time}'";
         } else {
             $querystrings[] = "m.time <= '{$time}'";
         }
     }
     $topic_id = $this->getState('query.topic_id');
     if ($topic_id) {
         $querystrings[] = "m.id = '{$topic_id}'";
     }
     return implode(' AND ', $querystrings);
 }