@ -437,7 +437,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $priorityMin
* @param integer $priorityMin
* @return integer affected rows
* @return integer affected rows
*/
*/
public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filter = null, $state = 0) {
public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0) {
FreshRSS_UserDAO::touch();
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
$idMax = time() . '000000';
@ -454,7 +454,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
}
$values = array($idMax);
$values = array($idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters , $state);
$stm = $this->bd->prepare($sql . $search);
$stm = $this->bd->prepare($sql . $search);
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
@ -480,7 +480,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @param integer $idMax fail safe article ID
* @return integer affected rows
* @return integer affected rows
*/
*/
public function markReadCat($id, $idMax = 0, $filter = null, $state = 0) {
public function markReadCat($id, $idMax = 0, $filters = null, $state = 0) {
FreshRSS_UserDAO::touch();
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
$idMax = time() . '000000';
@ -492,7 +492,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
. 'WHERE f.category=? AND e.is_read=0 AND e.id < = ?';
. 'WHERE f.category=? AND e.is_read=0 AND e.id < = ?';
$values = array($id, $idMax);
$values = array($id, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters , $state);
$stm = $this->bd->prepare($sql . $search);
$stm = $this->bd->prepare($sql . $search);
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
@ -518,7 +518,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @param integer $idMax fail safe article ID
* @return integer affected rows
* @return integer affected rows
*/
*/
public function markReadFeed($id_feed, $idMax = 0, $filter = null, $state = 0) {
public function markReadFeed($id_feed, $idMax = 0, $filters = null, $state = 0) {
FreshRSS_UserDAO::touch();
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
$idMax = time() . '000000';
@ -531,7 +531,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
. 'WHERE id_feed=? AND is_read=0 AND id < = ?';
. 'WHERE id_feed=? AND is_read=0 AND id < = ?';
$values = array($id_feed, $idMax);
$values = array($id_feed, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('', $filter, $state);
list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters , $state);
$stm = $this->bd->prepare($sql . $search);
$stm = $this->bd->prepare($sql . $search);
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
if (!($stm & & $stm->execute(array_merge($values, $searchValues)))) {
@ -625,7 +625,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return 'CONCAT(' . $s1 . ',' . $s2 . ')'; //MySQL
return 'CONCAT(' . $s1 . ',' . $s2 . ')'; //MySQL
}
}
protected function sqlListEntriesWhere($alias = '', $filter = null, $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $firstId = '', $date_min = 0) {
protected function sqlListEntriesWhere($alias = '', $filters = null, $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $firstId = '', $date_min = 0) {
$search = ' ';
$search = ' ';
$values = array();
$values = array();
if ($state & FreshRSS_Entry::STATE_NOT_READ) {
if ($state & FreshRSS_Entry::STATE_NOT_READ) {
@ -650,10 +650,6 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
default:
default:
throw new FreshRSS_EntriesGetter_Exception('Bad order in Entry->listByType: [' . $order . ']!');
throw new FreshRSS_EntriesGetter_Exception('Bad order in Entry->listByType: [' . $order . ']!');
}
}
/*if ($firstId === '' & & parent::$sharedDbType === 'mysql') {
//MySQL optimization. TODO: check if this is needed again, after the filtering for old articles has been removed in 0.9-dev
$firstId = $order === 'DESC' ? '9000000000'. '000000' : '0';
}*/
if ($firstId !== '') {
if ($firstId !== '') {
$search .= 'AND ' . $alias . 'id ' . ($order === 'DESC' ? '< =' : '>=') . ' ? ';
$search .= 'AND ' . $alias . 'id ' . ($order === 'DESC' ? '< =' : '>=') . ' ? ';
$values[] = $firstId;
$values[] = $firstId;
@ -662,91 +658,111 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$search .= 'AND ' . $alias . 'id >= ? ';
$search .= 'AND ' . $alias . 'id >= ? ';
$values[] = $date_min . '000000';
$values[] = $date_min . '000000';
}
}
if ($filter) {
if ($filters & & count($filters->searches()) > 0) {
if ($filter->getMinDate()) {
$isOpen = false;
$search .= 'AND ' . $alias . 'id >= ? ';
foreach ($filters->searches() as $filter) {
$values[] = "{$filter->getMinDate()}000000";
if ($filter == null) {
}
continue;
if ($filter->getMaxDate()) {
}
$search .= 'AND ' . $alias . 'id < = ? ';
$sub_search = '';
$values[] = "{$filter->getMaxDate()}000000";
if ($filter->getMinDate()) {
}
$sub_search .= 'AND ' . $alias . 'id >= ? ';
if ($filter->getMinPubdate()) {
$values[] = "{$filter->getMinDate()}000000";
$search .= 'AND ' . $alias . 'date >= ? ';
}
$values[] = $filter->getMinPubdate();
if ($filter->getMaxDate()) {
}
$sub_search .= 'AND ' . $alias . 'id < = ? ';
if ($filter->getMaxPubdate()) {
$values[] = "{$filter->getMaxDate()}000000";
$search .= 'AND ' . $alias . 'date < = ? ';
}
$values[] = $filter->getMaxPubdate();
if ($filter->getMinPubdate()) {
}
$sub_search .= 'AND ' . $alias . 'date >= ? ';
$values[] = $filter->getMinPubdate();
}
if ($filter->getMaxPubdate()) {
$sub_search .= 'AND ' . $alias . 'date < = ? ';
$values[] = $filter->getMaxPubdate();
}
if ($filter->getAuthor()) {
if ($filter->getAuthor()) {
foreach ($filter->getAuthor() as $author) {
foreach ($filter->getAuthor() as $author) {
$search .= 'AND ' . $alias . 'author LIKE ? ';
$sub_search .= 'AND ' . $alias . 'author LIKE ? ';
$values[] = "%{$author}%";
$values[] = "%{$author}%";
}
}
}
}
if ($filter->getIntitle()) {
if ($filter->getIntitle() ) {
foreach ($filter->getIntitle() as $title ) {
foreach ($filter->getIntitle() as $title) {
$sub_search .= 'AND ' . $alias . 'title LIKE ? ';
$search .= 'AND ' . $alias . 'title LIKE ? ' ;
$values[] = "%{$title}%" ;
$values[] = "%{$title }%";
}
}
}
}
if ($filter->getTags()) {
if ($filter->getTags() ) {
foreach ($filter->getTags() as $tag ) {
foreach ($filter->getTags() as $tag) {
$sub_search .= 'AND ' . $alias . 'tags LIKE ? ';
$search .= 'AND ' . $alias . 'tags LIKE ? ' ;
$values[] = "%{$tag}%" ;
$values[] = "%{$tag }%";
}
}
}
}
if ($filter->getInurl()) {
if ($filter->getInurl() ) {
foreach ($filter->getInurl() as $url ) {
foreach ($filter->getInurl() as $url) {
$sub_search .= 'AND CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ? ';
$search .= 'AND CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ? ' ;
$values[] = "%{$url}%" ;
$values[] = "%{$url }%";
}
}
}
}
if ($filter->getNotAuthor()) {
if ($filter->getNotAuthor()) {
foreach ($filter->getNotAuthor() as $author) {
foreach ($filter->getNotAuthor() as $author) {
$search .= 'AND (NOT ' . $alias . 'author LIKE ?) ';
$sub_search .= 'AND (NOT ' . $alias . 'author LIKE ?) ';
$values[] = "%{$author}%";
$values[] = "%{$author}%";
}
}
}
}
if ($filter->getNotIntitle()) {
if ($filter->getNotIntitle() ) {
foreach ($filter->getNotIntitle() as $title ) {
foreach ($filter->getNotIntitle() as $title) {
$sub_search .= 'AND (NOT ' . $alias . 'title LIKE ?) ';
$search .= 'AND (NOT ' . $alias . 'title LIKE ?) ' ;
$values[] = "%{$title}%" ;
$values[] = "%{$title }%";
}
}
}
}
if ($filter->getNotTags()) {
if ($filter->getNotTags() ) {
foreach ($filter->getNotTags() as $tag ) {
foreach ($filter->getNotTags() as $tag) {
$sub_search .= 'AND (NOT ' . $alias . 'tags LIKE ?) ';
$search .= 'AND (NOT ' . $alias . 'tags LIKE ?) ' ;
$values[] = "%{$tag}%" ;
$values[] = "%{$tag }%";
}
}
}
}
if ($filter->getNotInurl()) {
if ($filter->getNotInurl() ) {
foreach ($filter->getNotInurl() as $url ) {
foreach ($filter->getNotInurl() as $url) {
$sub_search .= 'AND (NOT CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ?) ';
$search .= 'AND (NOT CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ?) ' ;
$values[] = "%{$url}%" ;
$values[] = "%{$url }%";
}
}
}
}
if ($filter->getSearch()) {
if ($filter->getSearch()) {
foreach ($filter->getSearch() as $search_value) {
foreach ($filter->getSearch() as $search_value) {
$search .= 'AND ' . $this->sqlconcat($alias . 'title', $this->isCompressed() ? 'UNCOMPRESS(' . $alias . 'content_bin)' : '' . $alias . 'content') . ' LIKE ? ';
$sub_search .= 'AND ' . $this->sqlconcat($alias . 'title', $this->isCompressed() ? 'UNCOMPRESS(' . $alias . 'content_bin)' : '' . $alias . 'content') . ' LIKE ? ';
$values[] = "%{$search_value}%";
$values[] = "%{$search_value}%";
}
}
}
}
if ($filter->getNotSearch()) {
if ($filter->getNotSearch() ) {
foreach ($filter->getNotSearch() as $search_value ) {
foreach ($filter->getNotSearch() as $search_value) {
$sub_search .= 'AND (NOT ' . $this->sqlconcat($alias . 'title', $this->isCompressed() ? 'UNCOMPRESS(' . $alias . 'content_bin)' : '' . $alias . 'content') . ' LIKE ?) ';
$search .= 'AND (NOT ' . $this->sqlconcat($alias . 'title', $this->isCompressed() ? 'UNCOMPRESS(' . $alias . 'content_bin)' : '' . $alias . 'content') . ' LIKE ?) ' ;
$values[] = "%{$search_value}%" ;
$values[] = "%{$search_value }%";
}
}
}
if ($sub_search != '') {
if ($isOpen) {
$search .= 'OR ';
} else {
$search .= 'AND (';
$isOpen = true;
}
$search .= '(' . substr($sub_search, 4) . ') ';
}
}
if ($isOpen) {
$search .= ') ';
}
}
}
}
return array($values, $search);
return array($values, $search);
}
}
private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null , $date_min = 0) {
if (!$state) {
if (!$state) {
$state = FreshRSS_Entry::STATE_ALL;
$state = FreshRSS_Entry::STATE_ALL;
}
}
@ -777,7 +793,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!');
throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!');
}
}
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state, $order, $firstId, $date_min);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters , $state, $order, $firstId, $date_min);
return array(array_merge($values, $searchValues),
return array(array_merge($values, $searchValues),
'SELECT e.id FROM `' . $this->prefix . 'entry` e '
'SELECT e.id FROM `' . $this->prefix . 'entry` e '
@ -788,8 +804,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
. ($limit > 0 ? ' LIMIT ' . $limit : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
. ($limit > 0 ? ' LIMIT ' . $limit : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
}
}
public function listWhereRaw($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '' , $date_min = 0) {
public function listWhereRaw($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null , $date_min = 0) {
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters , $date_min);
$sql = 'SELECT e0.id, e0.guid, e0.title, e0.author, '
$sql = 'SELECT e0.id, e0.guid, e0.title, e0.author, '
. ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
. ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
@ -805,8 +821,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return $stm;
return $stm;
}
}
public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '' , $date_min = 0) {
public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null , $date_min = 0) {
$stm = $this->listWhereRaw($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
$stm = $this->listWhereRaw($type, $id, $state, $order, $limit, $firstId, $filters , $date_min);
return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC));
return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC));
}
}
@ -827,8 +843,8 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC));
return self::daoToEntries($stm->fetchAll(PDO::FETCH_ASSOC));
}
}
public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '' , $date_min = 0) { //For API
public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filters = null , $date_min = 0) { //For API
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filters , $date_min);
$stm = $this->bd->prepare($sql);
$stm = $this->bd->prepare($sql);
$stm->execute($values);
$stm->execute($values);