aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Category.php14
-rw-r--r--app/Models/CategoryDAO.php13
-rw-r--r--app/Models/Configuration.php2
-rw-r--r--app/Models/Feed.php38
-rw-r--r--app/Models/FeedDAO.php31
5 files changed, 59 insertions, 39 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 8e1e44ef8..328bae799 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -3,14 +3,12 @@
class FreshRSS_Category extends Minz_Model {
private $id = 0;
private $name;
- private $color;
private $nbFeed = -1;
private $nbNotRead = -1;
private $feeds = null;
- public function __construct ($name = '', $color = '#0062BE', $feeds = null) {
+ public function __construct ($name = '', $feeds = null) {
$this->_name ($name);
- $this->_color ($color);
if (isset ($feeds)) {
$this->_feeds ($feeds);
$this->nbFeed = 0;
@@ -28,9 +26,6 @@ class FreshRSS_Category extends Minz_Model {
public function name () {
return $this->name;
}
- public function color () {
- return $this->color;
- }
public function nbFeed () {
if ($this->nbFeed < 0) {
$catDAO = new FreshRSS_CategoryDAO ();
@@ -68,13 +63,6 @@ class FreshRSS_Category extends Minz_Model {
public function _name ($value) {
$this->name = $value;
}
- public function _color ($value) {
- if (preg_match ('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
- $this->color = $value;
- } else {
- $this->color = '#0062BE';
- }
- }
public function _feeds ($values) {
if (!is_array ($values)) {
$values = array ($values);
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index 1cc616ac0..5355228a5 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -2,12 +2,11 @@
class FreshRSS_CategoryDAO extends Minz_ModelPdo {
public function addCategory ($valuesTmp) {
- $sql = 'INSERT INTO `' . $this->prefix . 'category` (name, color) VALUES(?, ?)';
+ $sql = 'INSERT INTO `' . $this->prefix . 'category` (name) VALUES(?)';
$stm = $this->bd->prepare ($sql);
$values = array (
substr($valuesTmp['name'], 0, 255),
- substr($valuesTmp['color'], 0, 7),
);
if ($stm && $stm->execute ($values)) {
@@ -20,12 +19,11 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
}
public function updateCategory ($id, $valuesTmp) {
- $sql = 'UPDATE `' . $this->prefix . 'category` SET name=?, color=? WHERE id=?';
+ $sql = 'UPDATE `' . $this->prefix . 'category` SET name=? WHERE id=?';
$stm = $this->bd->prepare ($sql);
$values = array (
$valuesTmp['name'],
- $valuesTmp['color'],
$id
);
@@ -89,7 +87,6 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
public function listCategories ($prePopulateFeeds = true, $details = false) {
if ($prePopulateFeeds) {
$sql = 'SELECT c.id AS c_id, c.name AS c_name, '
- . ($details ? 'c.color AS c_color, ' : '')
. ($details ? 'f.* ' : 'f.id, f.name, f.url, f.website, f.priority, f.error, f.cache_nbEntries, f.cache_nbUnreads ')
. 'FROM `' . $this->prefix . 'category` c '
. 'LEFT OUTER JOIN `' . $this->prefix . 'feed` f ON f.category = c.id '
@@ -130,7 +127,6 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
$values = array (
'id' => $cat->id (),
'name' => $cat->name (),
- 'color' => $cat->color ()
);
$this->addCategory ($values);
@@ -203,7 +199,6 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
// End of the current category, we add it to the $list
$cat = new FreshRSS_Category (
$previousLine['c_name'],
- isset($previousLine['c_color']) ? $previousLine['c_color'] : '',
FreshRSS_FeedDAO::daoToFeed ($feedsDao, $previousLine['c_id'])
);
$cat->_id ($previousLine['c_id']);
@@ -220,7 +215,6 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
if ($previousLine != null) {
$cat = new FreshRSS_Category (
$previousLine['c_name'],
- isset($previousLine['c_color']) ? $previousLine['c_color'] : '',
FreshRSS_FeedDAO::daoToFeed ($feedsDao, $previousLine['c_id'])
);
$cat->_id ($previousLine['c_id']);
@@ -239,8 +233,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
foreach ($listDAO as $key => $dao) {
$cat = new FreshRSS_Category (
- $dao['name'],
- $dao['color']
+ $dao['name']
);
$cat->_id ($dao['id']);
$list[$key] = $cat;
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php
index 2a7fe95aa..2b719c370 100644
--- a/app/Models/Configuration.php
+++ b/app/Models/Configuration.php
@@ -32,6 +32,8 @@ class FreshRSS_Configuration {
'go_website' => 'space',
'next_entry' => 'j',
'prev_entry' => 'k',
+ 'first_entry' => 'home',
+ 'last_entry' => 'end',
'collapse_entry' => 'c',
'load_more' => 'm',
'auto_share' => 's',
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 22c019080..73f9c32fb 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -193,10 +193,10 @@ class FreshRSS_Feed extends Minz_Model {
}
$feed = customSimplePie();
$feed->set_feed_url ($url);
- $feed->init ();
+ $mtime = $feed->init();
- if ($feed->error ()) {
- throw new FreshRSS_Feed_Exception ($feed->error . ' [' . $url . ']');
+ if ((!$mtime) || $feed->error()) {
+ throw new FreshRSS_Feed_Exception ($feed->error() . ' [' . $url . ']');
}
// si on a utilisé l'auto-discover, notre url va avoir changé
@@ -217,11 +217,20 @@ class FreshRSS_Feed extends Minz_Model {
$this->_description(html_only_entity_decode($feed->get_description()));
}
- // et on charge les articles du flux
- $this->loadEntries ($feed);
+ if (($mtime === true) || ($mtime > $this->lastUpdate)) {
+ syslog(LOG_DEBUG, 'FreshRSS no cache ' . $mtime . ' > ' . $this->lastUpdate . ' for ' . $subscribe_url);
+ $this->loadEntries($feed); // et on charge les articles du flux
+ } else {
+ syslog(LOG_DEBUG, 'FreshRSS use cache for ' . $subscribe_url);
+ $this->entries = array();
+ }
+
+ $feed->__destruct(); //http://simplepie.org/wiki/faq/i_m_getting_memory_leaks
+ unset($feed);
}
}
}
+
private function loadEntries ($feed) {
$entries = array ();
@@ -267,8 +276,27 @@ class FreshRSS_Feed extends Minz_Model {
$entry->loadCompleteContent($this->pathEntries());
$entries[] = $entry;
+ unset($item);
}
$this->entries = $entries;
}
+
+ function lock() {
+ $lock = TMP_PATH . '/' . md5(Minz_Configuration::salt() . $this->url) . '.freshrss.lock';
+ if (file_exists($lock) && ((time() - @filemtime($lock)) > 3600)) {
+ @unlink($lock);
+ }
+ if (($handle = @fopen($lock, 'x')) === false) {
+ return false;
+ }
+ //register_shutdown_function('unlink', $lock);
+ @fclose($handle);
+ return true;
+ }
+
+ function unlock() {
+ $lock = TMP_PATH . '/' . md5(Minz_Configuration::salt() . $this->url) . '.freshrss.lock';
+ @unlink($lock);
+ }
}
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index e102da4ec..7ebe68d2b 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -52,21 +52,27 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
- public function updateLastUpdate ($id, $inError = 0) {
- $sql = 'UPDATE `' . $this->prefix . 'feed` f ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
- . 'SET f.cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=f.id),'
- . 'f.cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=f.id AND e2.is_read=0),'
- . 'lastUpdate=?, error=? '
- . 'WHERE f.id=?';
-
- $stm = $this->bd->prepare ($sql);
+ public function updateLastUpdate ($id, $inError = 0, $updateCache = true) {
+ if ($updateCache) {
+ $sql = 'UPDATE `' . $this->prefix . 'feed` f ' //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE
+ . 'SET f.cache_nbEntries=(SELECT COUNT(e1.id) FROM `' . $this->prefix . 'entry` e1 WHERE e1.id_feed=f.id),'
+ . 'f.cache_nbUnreads=(SELECT COUNT(e2.id) FROM `' . $this->prefix . 'entry` e2 WHERE e2.id_feed=f.id AND e2.is_read=0),'
+ . 'lastUpdate=?, error=? '
+ . 'WHERE f.id=?';
+ } else {
+ $sql = 'UPDATE `' . $this->prefix . 'feed` f '
+ . 'SET lastUpdate=?, error=? '
+ . 'WHERE f.id=?';
+ }
$values = array (
- time (),
+ time(),
$inError,
$id,
);
+ $stm = $this->bd->prepare ($sql);
+
if ($stm && $stm->execute ($values)) {
return $stm->rowCount();
} else {
@@ -192,8 +198,11 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
return self::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
}
- public function listFeedsOrderUpdate () {
- $sql = 'SELECT id, name, url, pathEntries, httpAuth, keep_history FROM `' . $this->prefix . 'feed` ORDER BY lastUpdate';
+ public function listFeedsOrderUpdate ($cacheDuration = 1500) {
+ $sql = 'SELECT id, name, url, lastUpdate, pathEntries, httpAuth, keep_history '
+ . 'FROM `' . $this->prefix . 'feed` '
+ . 'WHERE lastUpdate < ' . (time() - intval($cacheDuration))
+ . ' ORDER BY lastUpdate';
$stm = $this->bd->prepare ($sql);
$stm->execute ();