aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-26 22:20:24 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-26 22:20:24 +0100
commit43fd0a543900866f4feaf0713e1726b98a60b22d (patch)
tree9250fccea119e9fc224d293df86bdd7df0348aa8 /app
parent2c57e7254d613683ec20076d37b33ea2a7dd2d83 (diff)
Mise à jour de f.url en base de données lorsque SimplePie découvre que l'adresse a changé
Et correction problème favicon lorsque l'adresse du flux a changé du point de vue de SimplePie. Plus petites optimisations.
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/entryController.php2
-rwxr-xr-xapp/Controllers/feedController.php27
-rw-r--r--app/Models/Feed.php18
3 files changed, 23 insertions, 24 deletions
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index 1c3c56c4d..26f3422ca 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -131,7 +131,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
$nb = $feedDAO->cleanOldEntries($feed->id(), $date_min, $feedHistory);
if ($nb > 0) {
$nbTotal += $nb;
- Minz_Log::record($nb . ' old entries cleaned in feed ' . $feed->id(), Minz_Log::DEBUG);
+ Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
$feedDAO->updateLastUpdate($feed->id());
}
}
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index dc8a854a9..ca230232f 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -20,15 +20,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$this->catDAO->checkDefault ();
}
- private static function entryDateComparer($e1, $e2) {
- $d1 = $e1->date(true);
- $d2 = $e2->date(true);
- if ($d1 === $d2) {
- return 0;
- }
- return ($d1 < $d2) ? -1 : 1;
- }
-
public function addAction () {
@set_time_limit(300);
@@ -55,7 +46,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
$feed->_httpAuth ($httpAuth);
- $feed->load ();
+ $feed->load(true);
$feedDAO = new FreshRSS_FeedDAO ();
$values = array (
@@ -91,8 +82,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0;
$entryDAO = new FreshRSS_EntryDAO ();
- $entries = $feed->entries ();
- usort($entries, 'self::entryDateComparer');
+ $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order
// on calcule la date des articles les plus anciens qu'on accepte
$nb_month_old = $this->view->conf->oldEntries ();
@@ -199,10 +189,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$flux_update = 0;
foreach ($feeds as $feed) {
try {
- $feed->load ();
- $feed->faviconPrepare();
- $entries = $feed->entries ();
- usort($entries, 'self::entryDateComparer');
+ $url = $feed->url();
+ $feed->load(false);
+ $entries = array_reverse($feed->entries()); //We want chronological order and SimplePie uses reverse order
$is_read = $this->view->conf->markUponReception() === 'yes' ? 1 : 0;
@@ -231,7 +220,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if (($feedHistory >= 0) && (rand(0, 30) === 1)) {
$nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10));
if ($nb > 0) {
- Minz_Log::record ($nb . ' old entries cleaned in feed ' . $feed->id (), Minz_Log::DEBUG);
+ Minz_Log::record ($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG);
}
}
@@ -239,6 +228,10 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feedDAO->updateLastUpdate ($feed->id ());
$feedDAO->commit ();
$flux_update++;
+ if ($feed->url() !== $url) { //URL has changed (auto-discovery)
+ $feedDAO->updateFeed($feed->id(), array('url' => $feed->url()));
+ }
+ $feed->faviconPrepare();
} catch (FreshRSS_Feed_Exception $e) {
Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);
$feedDAO->updateLastUpdate ($feed->id (), 1);
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 4f90b9872..0f467f776 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -16,6 +16,7 @@ class FreshRSS_Feed extends Minz_Model {
private $httpAuth = '';
private $error = false;
private $keep_history = -2;
+ private $hash = null;
public function __construct ($url, $validate=true) {
if ($validate) {
@@ -30,7 +31,10 @@ class FreshRSS_Feed extends Minz_Model {
}
public function hash() {
- return hash('crc32b', Minz_Configuration::salt() . $this->url);
+ if ($this->hash === null) {
+ $this->hash = hash('crc32b', Minz_Configuration::salt() . $this->url);
+ }
+ return $this->hash;
}
public function url () {
@@ -184,7 +188,7 @@ class FreshRSS_Feed extends Minz_Model {
$this->nbEntries = intval($value);
}
- public function load () {
+ public function load ($loadDetails = false) {
if (!is_null ($this->url)) {
if (CACHE_PATH === false) {
throw new Minz_FileNotExistException (
@@ -256,11 +260,13 @@ class FreshRSS_Feed extends Minz_Model {
$this->_url ($subscribe_url);
}
- $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8');
- $this->_name (!is_null ($title) ? $title : $this->url);
+ if ($loadDetails) {
+ $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8');
+ $this->_name (!is_null ($title) ? $title : $this->url);
- $this->_website(html_only_entity_decode($feed->get_link()));
- $this->_description(html_only_entity_decode($feed->get_description()));
+ $this->_website(html_only_entity_decode($feed->get_link()));
+ $this->_description(html_only_entity_decode($feed->get_description()));
+ }
// et on charge les articles du flux
$this->loadEntries ($feed);