aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-08-20 12:22:56 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-08-20 12:22:56 +0200
commit2af3abc89e56af75c38caf5e8071b3cd09bedba8 (patch)
treedc7e1cb7a31c039ec451d7788ae9d73bc336a6ee /app
parente315192c4b3df89dddb1ac37c6c7a01531d7952f (diff)
parentf9359cd406bafdbb1ffaa8bad8a5810a02efc820 (diff)
Merge branch 'FreshRSS/dev' into PostgreSQL
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/entryController.php19
-rw-r--r--app/Models/ConfigurationSetter.php7
-rw-r--r--app/Models/EntryDAO.php150
-rw-r--r--app/Models/EntryDAOSQLite.php18
-rw-r--r--app/layout/layout.phtml15
-rw-r--r--app/layout/nav_menu.phtml4
-rwxr-xr-xapp/views/helpers/pagination.phtml2
7 files changed, 124 insertions, 91 deletions
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index bff1073ef..c40588105 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -40,6 +40,17 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$get = Minz_Request::param('get');
$next_get = Minz_Request::param('nextGet', $get);
$id_max = Minz_Request::param('idMax', 0);
+ FreshRSS_Context::$search = new FreshRSS_Search(Minz_Request::param('search', ''));
+
+ FreshRSS_Context::$state = Minz_Request::param('state', 0);
+ if (FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_FAVORITE)) {
+ FreshRSS_Context::$state = FreshRSS_Entry::STATE_FAVORITE;
+ } elseif (FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_NOT_FAVORITE)) {
+ FreshRSS_Context::$state = FreshRSS_Entry::STATE_NOT_FAVORITE;
+ } else {
+ FreshRSS_Context::$state = 0;
+ }
+
$params = array();
$entryDAO = FreshRSS_Factory::createEntryDao();
@@ -58,16 +69,16 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$get = substr($get, 2);
switch($type_get) {
case 'c':
- $entryDAO->markReadCat($get, $id_max);
+ $entryDAO->markReadCat($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state);
break;
case 'f':
- $entryDAO->markReadFeed($get, $id_max);
+ $entryDAO->markReadFeed($get, $id_max, FreshRSS_Context::$search, FreshRSS_Context::$state);
break;
case 's':
- $entryDAO->markReadEntries($id_max, true);
+ $entryDAO->markReadEntries($id_max, true, 0, FreshRSS_Context::$search);
break;
case 'a':
- $entryDAO->markReadEntries($id_max);
+ $entryDAO->markReadEntries($id_max, false, 0, FreshRSS_Context::$search, FreshRSS_Context::$state);
break;
}
diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php
index 988e83356..046f54955 100644
--- a/app/Models/ConfigurationSetter.php
+++ b/app/Models/ConfigurationSetter.php
@@ -129,12 +129,7 @@ class FreshRSS_ConfigurationSetter {
// Verify URL and add default value when needed
if (isset($value['url'])) {
- $is_url = (
- filter_var($value['url'], FILTER_VALIDATE_URL) ||
- (version_compare(PHP_VERSION, '5.3.3', '<') &&
- (strpos($value, '-') > 0) &&
- ($value === filter_var($value, FILTER_SANITIZE_URL)))
- ); //PHP bug #51192
+ $is_url = filter_var($value['url'], FILTER_VALIDATE_URL);
if (!$is_url) {
continue;
}
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index ba52d3f15..3a1dc1ba5 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -344,7 +344,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $priorityMin
* @return integer affected rows
*/
- public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0) {
+ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filter = null, $state = 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadEntries(0) is deprecated!');
@@ -359,8 +359,11 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$sql .= ' AND f.priority > ' . intval($priorityMin);
}
$values = array($idMax);
- $stm = $this->bd->prepare($sql);
- if (!($stm && $stm->execute($values))) {
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state);
+
+ $stm = $this->bd->prepare($sql . $search);
+ if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
$info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::error('SQL error markReadEntries: ' . $info[2]);
return false;
@@ -383,7 +386,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadCat($id, $idMax = 0) {
+ public function markReadCat($id, $idMax = 0, $filter = null, $state = 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadCat(0) is deprecated!');
@@ -393,8 +396,11 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
. 'SET e.is_read=1 '
. 'WHERE f.category=? AND e.is_read=0 AND e.id <= ?';
$values = array($id, $idMax);
- $stm = $this->bd->prepare($sql);
- if (!($stm && $stm->execute($values))) {
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state);
+
+ $stm = $this->bd->prepare($sql . $search);
+ if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
$info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::error('SQL error markReadCat: ' . $info[2]);
return false;
@@ -417,19 +423,22 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadFeed($id_feed, $idMax = 0) {
+ public function markReadFeed($id_feed, $idMax = 0, $filter = null, $state = 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadFeed(0) is deprecated!');
}
$this->bd->beginTransaction();
- $sql = 'UPDATE `' . $this->prefix . 'entry` '
- . 'SET is_read=1 '
- . 'WHERE id_feed=? AND is_read=0 AND id <= ?';
+ $sql = 'UPDATE `' . $this->prefix . 'entry` e '
+ . 'SET e.is_read=1 '
+ . 'WHERE e.id_feed=? AND e.is_read=0 AND e.id <= ?';
$values = array($id_feed, $idMax);
- $stm = $this->bd->prepare($sql);
- if (!($stm && $stm->execute($values))) {
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state);
+
+ $stm = $this->bd->prepare($sql . $search);
+ if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
$info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::error('SQL error markReadFeed: ' . $info[2]);
$this->bd->rollBack();
@@ -493,52 +502,24 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return 'CONCAT(' . $s1 . ',' . $s2 . ')'; //MySQL
}
- 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;
+ protected function sqlListEntriesWhere($alias = '', $filter = null, $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $firstId = '', $date_min = 0) {
+ $search = ' ';
$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 ';
+ $search .= 'AND ' . $alias . 'is_read=0 ';
}
}
elseif ($state & FreshRSS_Entry::STATE_READ) {
- $where .= 'AND e1.is_read=1 ';
+ $search .= 'AND ' . $alias . 'is_read=1 ';
}
if ($state & FreshRSS_Entry::STATE_FAVORITE) {
if (!($state & FreshRSS_Entry::STATE_NOT_FAVORITE)) {
- $where .= 'AND e1.is_favorite=1 ';
+ $search .= 'AND ' . $alias . 'is_favorite=1 ';
}
}
elseif ($state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
- $where .= 'AND e1.is_favorite=0 ';
+ $search .= 'AND ' . $alias . 'is_favorite=0 ';
}
switch ($order) {
@@ -552,76 +533,111 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$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 . ' ';
+ $search .= 'AND ' . $alias . 'id ' . ($order === 'DESC' ? '<=' : '>=') . $firstId . ' ';
}
if ($date_min > 0) {
- $where .= 'AND e1.id >= ' . $date_min . '000000 ';
+ $search .= 'AND ' . $alias . 'id >= ' . $date_min . '000000 ';
}
- $search = '';
if ($filter) {
if ($filter->getIntitle()) {
- $search .= 'AND e1.title LIKE ? ';
+ $search .= 'AND ' . $alias . 'title LIKE ? ';
$values[] = "%{$filter->getIntitle()}%";
}
if ($filter->getInurl()) {
- $search .= 'AND CONCAT(e1.link, e1.guid) LIKE ? ';
+ $search .= 'AND CONCAT(' . $alias . 'link, ' . $alias . 'guid) LIKE ? ';
$values[] = "%{$filter->getInurl()}%";
}
if ($filter->getAuthor()) {
- $search .= 'AND e1.author LIKE ? ';
+ $search .= 'AND ' . $alias . 'author LIKE ? ';
$values[] = "%{$filter->getAuthor()}%";
}
if ($filter->getMinDate()) {
- $search .= 'AND e1.id >= ? ';
+ $search .= 'AND ' . $alias . 'id >= ? ';
$values[] = "{$filter->getMinDate()}000000";
}
if ($filter->getMaxDate()) {
- $search .= 'AND e1.id <= ? ';
+ $search .= 'AND ' . $alias . 'id <= ? ';
$values[] = "{$filter->getMaxDate()}000000";
}
if ($filter->getMinPubdate()) {
- $search .= 'AND e1.date >= ? ';
+ $search .= 'AND ' . $alias . 'date >= ? ';
$values[] = $filter->getMinPubdate();
}
if ($filter->getMaxPubdate()) {
- $search .= 'AND e1.date <= ? ';
+ $search .= 'AND ' . $alias . 'date <= ? ';
$values[] = $filter->getMaxPubdate();
}
if ($filter->getTags()) {
$tags = $filter->getTags();
foreach ($tags as $tag) {
- $search .= 'AND e1.tags LIKE ? ';
+ $search .= 'AND ' . $alias . 'tags LIKE ? ';
$values[] = "%{$tag}%";
}
}
if ($filter->getSearch()) {
$search_values = $filter->getSearch();
foreach ($search_values as $search_value) {
- $search .= 'AND ' . $this->sqlconcat('e1.title', $this->isCompressed() ? 'UNCOMPRESS(content_bin)' : 'content') . ' LIKE ? ';
+ $search .= 'AND ' . $this->sqlconcat($alias . 'title', $this->isCompressed() ? 'UNCOMPRESS(' . $alias . 'content_bin)' : '' . $alias . 'content') . ' LIKE ? ';
$values[] = "%{$search_value}%";
}
}
}
- return array($values,
- 'SELECT e1.id FROM `' . $this->prefix . 'entry` e1 '
- . ($joinFeed ? 'INNER JOIN `' . $this->prefix . 'feed` f ON e1.id_feed=f.id ' : '')
+ return array($values, $search);
+ }
+
+ 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 .= 'e.is_favorite=1 ';
+ break;
+ case 'c':
+ $where .= 'f.category=? ';
+ $values[] = intval($id);
+ $joinFeed = true;
+ break;
+ case 'f':
+ $where .= 'e.id_feed=? ';
+ $values[] = intval($id);
+ break;
+ case 'A':
+ $where .= '1 ';
+ break;
+ default:
+ throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!');
+ }
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filter, $state, $order, $firstId, $date_min);
+
+ return array(array_merge($values, $searchValues),
+ 'SELECT e.id FROM `' . $this->prefix . 'entry` e '
+ . ($joinFeed ? 'INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed=f.id ' : '')
. 'WHERE ' . $where
. $search
- . 'ORDER BY e1.id ' . $order
+ . 'ORDER BY e.id ' . $order
. ($limit > 0 ? ' LIMIT ' . $limit : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
}
public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0) {
list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min);
- $sql = 'SELECT e.id, e.guid, e.title, e.author, '
+ $sql = 'SELECT e0.id, e0.guid, e0.title, e0.author, '
. ($this->isCompressed() ? 'UNCOMPRESS(content_bin) AS content' : 'content')
- . ', e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags '
- . 'FROM `' . $this->prefix . 'entry` e '
+ . ', e0.link, e0.date, e0.is_read, e0.is_favorite, e0.id_feed, e0.tags '
+ . 'FROM `' . $this->prefix . 'entry` e0 '
. 'INNER JOIN ('
. $sql
- . ') e2 ON e2.id=e.id '
- . 'ORDER BY e.id ' . $order;
+ . ') e2 ON e2.id=e0.id '
+ . 'ORDER BY e0.id ' . $order;
$stm = $this->bd->prepare($sql);
$stm->execute($values);
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 19b97fd3a..dad34a93d 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -119,7 +119,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
* @param integer $priorityMin
* @return integer affected rows
*/
- public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0) {
+ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filter = null, $state = 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadEntries(0) is deprecated!');
@@ -132,8 +132,11 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
$sql .= ' AND id_feed IN (SELECT f.id FROM `' . $this->prefix . 'feed` f WHERE f.priority > ' . intval($priorityMin) . ')';
}
$values = array($idMax);
- $stm = $this->bd->prepare($sql);
- if (!($stm && $stm->execute($values))) {
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('', $filter, $state);
+
+ $stm = $this->bd->prepare($sql . $search);
+ if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
$info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::error('SQL error markReadEntries: ' . $info[2]);
return false;
@@ -156,7 +159,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadCat($id, $idMax = 0) {
+ public function markReadCat($id, $idMax = 0, $filter = null, $state = 0) {
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadCat(0) is deprecated!');
@@ -167,8 +170,11 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
. 'WHERE is_read=0 AND id <= ? AND '
. 'id_feed IN (SELECT f.id FROM `' . $this->prefix . 'feed` f WHERE f.category=?)';
$values = array($idMax, $id);
- $stm = $this->bd->prepare($sql);
- if (!($stm && $stm->execute($values))) {
+
+ list($searchValues, $search) = $this->sqlListEntriesWhere('', $filter, $state);
+
+ $stm = $this->bd->prepare($sql . $search);
+ if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
$info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo();
Minz_Log::error('SQL error markReadCat: ' . $info[2]);
return false;
diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml
index 189d93fbe..4d9ad5458 100644
--- a/app/layout/layout.phtml
+++ b/app/layout/layout.phtml
@@ -11,16 +11,19 @@
<?php echo self::headScript(); ?>
<link rel="shortcut icon" id="favicon" type="image/x-icon" sizes="16x16 64x64" href="<?php echo Minz_Url::display('/favicon.ico'); ?>" />
<link rel="icon msapplication-TileImage apple-touch-icon" type="image/png" sizes="256x256" href="<?php echo Minz_Url::display('/themes/icons/favicon-256.png'); ?>" />
- <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('starred', true); ?>">
- <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('non-starred', true); ?>">
- <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('read', true); ?>">
- <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('unread', true); ?>">
- <link rel="apple-touch-icon" href="<?php echo Minz_Url::display('/themes/icons/apple-touch-icon.png'); ?>">
+ <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('starred', true); ?>" />
+ <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('non-starred', true); ?>" />
+ <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('read', true); ?>" />
+ <link rel="prefetch" href="<?php echo FreshRSS_Themes::icon('unread', true); ?>" />
+ <link rel="apple-touch-icon" href="<?php echo Minz_Url::display('/themes/icons/apple-touch-icon.png'); ?>" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="<?php echo FreshRSS_Context::$system_conf->title; ?>">
<meta name="msapplication-TileColor" content="#FFF" />
+<?php if (!FreshRSS_Context::$system_conf->allow_referrer) { ?>
+ <meta name="referrer" content="never" />
<?php
+ }
flush();
if (isset($this->callbackBeforeContent)) {
call_user_func($this->callbackBeforeContent, $this);
@@ -41,8 +44,6 @@
$url_rss['a'] = 'rss';
?>
<link rel="alternate" type="application/rss+xml" title="<?php echo $this->rss_title; ?>" href="<?php echo Minz_Url::display($url_rss); ?>" />
-<?php } if (!FreshRSS_Context::$system_conf->allow_referrer) { ?>
- <meta name="referrer" content="never" />
<?php } if (FreshRSS_Context::$system_conf->allow_robots) { ?>
<meta name="description" content="<?php echo htmlspecialchars(FreshRSS_Context::$name . ' | ' . FreshRSS_Context::$description, ENT_COMPAT, 'UTF-8'); ?>" />
<?php } else { ?>
diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml
index 17655acbf..23255f04f 100644
--- a/app/layout/nav_menu.phtml
+++ b/app/layout/nav_menu.phtml
@@ -22,7 +22,7 @@
?>
<a id="toggle-<?php echo $state_str; ?>"
class="btn <?php echo $state_enabled ? 'active' : ''; ?>"
- aria-checked="<?php echo $state_enabled ? 'true' : 'false'; ?>"
+ role="checkbox" aria-checked="<?php echo $state_enabled ? 'true' : 'false'; ?>"
title="<?php echo _t('index.menu.' . $state_str); ?>"
href="<?php echo Minz_Url::display($url_state); ?>"><?php echo _i($state_str); ?></a>
<?php } ?>
@@ -75,6 +75,8 @@
'get' => $get,
'nextGet' => FreshRSS_Context::$next_get,
'idMax' => FreshRSS_Context::$id_max,
+ 'search' => FreshRSS_Context::$search,
+ 'state' => FreshRSS_Context::$state,
)
);
?>
diff --git a/app/views/helpers/pagination.phtml b/app/views/helpers/pagination.phtml
index 23c45114d..20957fc67 100755
--- a/app/views/helpers/pagination.phtml
+++ b/app/views/helpers/pagination.phtml
@@ -10,6 +10,8 @@
'get' => FreshRSS_Context::currentGet(),
'nextGet' => FreshRSS_Context::$next_get,
'idMax' => FreshRSS_Context::$id_max,
+ 'search' => FreshRSS_Context::$search,
+ 'state' => FreshRSS_Context::$state,
)
);
?>