aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-02-28 12:33:15 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-02-28 12:33:15 +0100
commitcdd653ce5305f043ee1db970c25303676c9f35c0 (patch)
tree01a4c25e7e22b30b2099cf84b2031bad2f9a9566 /app/Models
parentc59a702c32752493e8b3b73acf635ecb473b4d7e (diff)
parente897afa7ccb2c625705bce25c003d9cf37179227 (diff)
Merge branch 'aledeg-change-filter' into dev
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Context.php2
-rw-r--r--app/Models/EntryDAO.php84
-rw-r--r--app/Models/Search.php8
3 files changed, 46 insertions, 48 deletions
diff --git a/app/Models/Context.php b/app/Models/Context.php
index f00bb1e97..dbdbfaa69 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -30,7 +30,7 @@ class FreshRSS_Context {
public static $state = 0;
public static $order = 'DESC';
public static $number = 0;
- public static $search = '';
+ public static $search;
public static $first_id = '';
public static $next_id = '';
public static $id_max = '';
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 61beeea13..d2a8e0fd9 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -441,54 +441,46 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
$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 .'%';
- }
+ if ($filter !== null) {
+ if ($filter->getIntitle()) {
+ $search .= 'AND e1.title LIKE ? ';
+ $values[] = "%{$filter->getIntitle()}%";
+ }
+ if ($filter->getInurl()) {
+ $search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? ';
+ $values[] = "%{$filter->getInurl()}%";
+ }
+ if ($filter->getAuthor()) {
+ $search .= 'AND e1.author LIKE ? ';
+ $values[] = "%{$filter->getAuthor()}%";
+ }
+ if ($filter->getMinDate()) {
+ $search .= 'AND e1.id >= ? ';
+ $values[] = "{$filter->getMinDate()}000000";
+ }
+ if ($filter->getMaxDate()) {
+ $search .= 'AND e1.id <= ?';
+ $values[] = "{$filter->getMaxDate()}000000";
+ }
+ if ($filter->getMinPubdate()) {
+ $search .= 'AND e1.date >= ? ';
+ $values[] = $filter->getMinPubdate();
+ }
+ if ($filter->getMaxPubdate()) {
+ $search .= 'AND e1.date <= ? ';
+ $values[] = $filter->getMaxPubdate();
+ }
+ if ($filter->getTags()) {
+ $tags = $filter->getTags();
+ foreach ($tags as $tag) {
+ $search .= 'AND e1.tags LIKE ? ';
+ $values[] = "%{$tag}%";
}
}
+ if ($filter->getSearch()) {
+ $search .= 'AND ' . $this->sqlconcat('e1.title', $this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ' LIKE ? ';
+ $values[] = "%{$filter->getSearch()}%";
+ }
}
return array($values,
diff --git a/app/Models/Search.php b/app/Models/Search.php
index ef8fc883d..84688be2e 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -1,5 +1,7 @@
<?php
+require_once(LIB_PATH . '/lib_date.php');
+
/**
* Contains a search from the search form.
*
@@ -9,7 +11,7 @@
class FreshRSS_Search {
// This contains the user input string
- private $raw_input;
+ private $raw_input = '';
// The following properties are extracted from the raw input
private $intitle;
private $min_date;
@@ -34,6 +36,10 @@ class FreshRSS_Search {
$input = $this->parseTagsSeach($input);
$this->search = $this->cleanSearch($input);
}
+
+ public function __toString() {
+ return $this->getRawInput();
+ }
public function getRawInput() {
return $this->raw_input;