Example #1
0
 /**
  * Parse the search string to find pubdate keyword and the search related
  * to it.
  * The search is the first word following the keyword.
  *
  * @param string $input
  * @return string
  */
 private function parsePubdateSearch($input)
 {
     if (preg_match('/pubdate:(?P<search>[^\\s]*)/', $input, $matches)) {
         list($this->min_pubdate, $this->max_pubdate) = parseDateInterval($matches['search']);
         return str_replace($matches[0], '', $input);
     }
     return $input;
 }
Example #2
0
 private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0)
 {
     if (!$state) {
         $state = FreshRSS_Entry::STATE_ALL;
     }
     $where = '';
     $joinFeed = false;
     $values = array();
     switch ($type) {
         case 'a':
             $where .= 'f.priority > 0 ';
             $joinFeed = true;
             break;
         case 's':
             //Deprecated: use $state instead
             $where .= 'e1.is_favorite=1 ';
             break;
         case 'c':
             $where .= 'f.category=? ';
             $values[] = intval($id);
             $joinFeed = true;
             break;
         case 'f':
             $where .= 'e1.id_feed=? ';
             $values[] = intval($id);
             break;
         case 'A':
             $where .= '1 ';
             break;
         default:
             throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!');
     }
     if ($state & FreshRSS_Entry::STATE_NOT_READ) {
         if (!($state & FreshRSS_Entry::STATE_READ)) {
             $where .= 'AND e1.is_read=0 ';
         }
     } elseif ($state & FreshRSS_Entry::STATE_READ) {
         $where .= 'AND e1.is_read=1 ';
     }
     if ($state & FreshRSS_Entry::STATE_FAVORITE) {
         if (!($state & FreshRSS_Entry::STATE_NOT_FAVORITE)) {
             $where .= 'AND e1.is_favorite=1 ';
         }
     } elseif ($state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
         $where .= 'AND e1.is_favorite=0 ';
     }
     switch ($order) {
         case 'DESC':
         case 'ASC':
             break;
         default:
             throw new FreshRSS_EntriesGetter_Exception('Bad order in Entry->listByType: [' . $order . ']!');
     }
     /*if ($firstId === '' && parent::$sharedDbType === 'mysql') {
     			$firstId = $order === 'DESC' ? '9000000000'. '000000' : '0';	//MySQL optimization. TODO: check if this is needed again, after the filtering for old articles has been removed in 0.9-dev
     		}*/
     if ($firstId !== '') {
         $where .= 'AND e1.id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
     }
     if ($date_min > 0) {
         $where .= 'AND e1.id >= ' . $date_min . '000000 ';
     }
     $search = '';
     if ($filter !== '') {
         require_once LIB_PATH . '/lib_date.php';
         $filter = trim($filter);
         $filter = addcslashes($filter, '\\%_');
         $terms = array_unique(explode(' ', $filter));
         //sort($terms);	//Put #tags first	//TODO: Put the cheapest filters first
         foreach ($terms as $word) {
             $word = trim($word);
             if (stripos($word, 'intitle:') === 0) {
                 $word = substr($word, strlen('intitle:'));
                 $search .= 'AND e1.title LIKE ? ';
                 $values[] = '%' . $word . '%';
             } elseif (stripos($word, 'inurl:') === 0) {
                 $word = substr($word, strlen('inurl:'));
                 $search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? ';
                 $values[] = '%' . $word . '%';
             } elseif (stripos($word, 'author:') === 0) {
                 $word = substr($word, strlen('author:'));
                 $search .= 'AND e1.author LIKE ? ';
                 $values[] = '%' . $word . '%';
             } elseif (stripos($word, 'date:') === 0) {
                 $word = substr($word, strlen('date:'));
                 list($minDate, $maxDate) = parseDateInterval($word);
                 if ($minDate) {
                     $search .= 'AND e1.id >= ' . $minDate . '000000 ';
                 }
                 if ($maxDate) {
                     $search .= 'AND e1.id <= ' . $maxDate . '000000 ';
                 }
             } elseif (stripos($word, 'pubdate:') === 0) {
                 $word = substr($word, strlen('pubdate:'));
                 list($minDate, $maxDate) = parseDateInterval($word);
                 if ($minDate) {
                     $search .= 'AND e1.date >= ' . $minDate . ' ';
                 }
                 if ($maxDate) {
                     $search .= 'AND e1.date <= ' . $maxDate . ' ';
                 }
             } else {
                 if ($word[0] === '#' && isset($word[1])) {
                     $search .= 'AND e1.tags LIKE ? ';
                     $values[] = '%' . $word . '%';
                 } else {
                     $search .= 'AND ' . $this->sqlconcat('e1.title', $this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ' LIKE ? ';
                     $values[] = '%' . $word . '%';
                 }
             }
         }
     }
     return array($values, 'SELECT e1.id FROM `' . $this->prefix . 'entry` e1 ' . ($joinFeed ? 'INNER JOIN `' . $this->prefix . 'feed` f ON e1.id_feed=f.id ' : '') . 'WHERE ' . $where . $search . 'ORDER BY e1.id ' . $order . ($limit > 0 ? ' LIMIT ' . $limit : ''));
     //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
 }