A free, self-hostable news aggregator…
Finish to update context object
Marien Fressinaudb446a510ebac
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.phpindex f163da53d..be85aa68d 100755--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@ -17,70 +17,13 @@ class FreshRSS_index_Controller extends Minz_ActionController {return;- // On récupère les différents éléments de filtrage- $this->view->state = Minz_Request::param('state', FreshRSS_Context::$conf->default_view);- $state_param = Minz_Request::param('state', null);- $filter = Minz_Request::param('search', '');- $this->view->order = $order = Minz_Request::param('order', FreshRSS_Context::$conf->sort_order);- $nb = Minz_Request::param('nb', FreshRSS_Context::$conf->posts_per_page);- $first = Minz_Request::param('next', '');-- $ajax_request = Minz_Request::param('ajax', false);- if ($output === 'reader') {- $nb = max(1, round($nb / 2));- }-- if ($this->view->state === FreshRSS_Entry::STATE_NOT_READ) { //Any unread article in this category at all?- switch ($getType) {- case 'a':- $hasUnread = $this->view->nb_not_read > 0;- break;- case 's':- // This is deprecated. The favorite button does not exist anymore- $hasUnread = $this->view->nb_favorites['unread'] > 0;- break;- case 'c':- $hasUnread = (!isset($this->view->cat_aside[$getId]) ||- $this->view->cat_aside[$getId]->nbNotRead() > 0);- break;- case 'f':- $myFeed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId);- $hasUnread = ($myFeed === null) || ($myFeed->nbNotRead() > 0);- break;- default:- $hasUnread = true;- break;- }- if (!$hasUnread && ($state_param === null)) {- $this->view->state = FreshRSS_Entry::STATE_ALL;- }- }-- $this->view->today = @strtotime('today');-try {$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb + 1, $first, $filter);- // Si on a récupéré aucun article "non lus"- // on essaye de récupérer tous les articles- if ($this->view->state === FreshRSS_Entry::STATE_NOT_READ && empty($entries) && ($state_param === null) && ($filter == '')) {- Minz_Log::debug('Conflicting information about nbNotRead!');- $feedDAO = FreshRSS_Factory::createFeedDao();- try {- $feedDAO->updateCachedValues();- } catch (Exception $ex) {- Minz_Log::notice('Failed to automatically correct nbNotRead! ' + $ex->getMessage());- }- $this->view->state = FreshRSS_Entry::STATE_ALL;- $entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb, $first, $filter);- }- Minz_Request::_param('state', $this->view->state);-- if (count($entries) <= $nb) {- $this->view->nextId = '';- } else { //We have more elements for pagination- $lastEntry = array_pop($entries);- $this->view->nextId = $lastEntry->id();+ if (count($entries) > $nb) {+ // We have more elements for pagination+ $last_entry = array_pop($entries);+ FreshRSS_Context::$next_id = $last_entry->id();}$this->view->entries = $entries;@@ -168,6 +111,23 @@ class FreshRSS_index_Controller extends Minz_ActionController {*/private function updateContext() {FreshRSS_Context::_get(Minz_Request::param('get', 'a'));++ FreshRSS_Context::$state |= Minz_Request::param(+ 'state', FreshRSS_Context::$conf->default_view+ );+ if (FreshRSS_Context::$state & FreshRSS_Entry::STATE_NOT_READ &&+ FreshRSS_Context::$get_unread <= 0) {+ FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ;+ }++ FreshRSS_Context::$search = Minz_Request::param('search', '');+ FreshRSS_Context::$order = Minz_Request::param(+ 'order', FreshRSS_Context::$conf->sort_order+ );+ FreshRSS_Context::$number = Minz_Request::param(+ 'nb', FreshRSS_Context::$conf->posts_per_page+ );+ FreshRSS_Context::$first_id = Minz_Request::param('next', '');}/**diff --git a/app/Models/Context.php b/app/Models/Context.phpindex 7138fd638..31ac60207 100644--- a/app/Models/Context.php+++ b/app/Models/Context.php@@ -26,6 +26,9 @@ class FreshRSS_Context {);public static $get_unread = 0;public static $order = 'DESC';+ public static $number = 0;+ public static $search = '';+ public static $first_id = 0;public static function init() {// Init configuration.@@ -80,6 +83,9 @@ class FreshRSS_Context {self::$current_get['starred'] = true;self::$name = _t('your_favorites');self::$get_unread = self::$total_starred['unread'];++ // Update state if favorite is not yet enabled.+ self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE;break;case 'f':self::$current_get['feed'] = $id;diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtmlindex 6333d63db..c39dba0a9 100644--- a/app/views/index/normal.phtml+++ b/app/views/index/normal.phtml@@ -26,6 +26,8 @@ if (!empty($this->entries)) {$bottomline_link = FreshRSS_Context::$conf->bottomline_link;$content_width = FreshRSS_Context::$conf->content_width;++ $today = @strtotime('today');?><div id="stream" class="normal<?php echo $hidePosts ? ' hide_posts' : ''; ?>"><?php@@ -33,7 +35,7 @@ if (!empty($this->entries)) {<a href="<?php echo Minz_Url::display($this->url); ?>"><?php echo _t('new_article'); ?></a></div><?phpforeach ($this->entries as $item) {- if ($display_today && $item->isDay(FreshRSS_Days::TODAY, $this->today)) {+ if ($display_today && $item->isDay(FreshRSS_Days::TODAY, $today)) {?><div class="day" id="day_today"><?phpecho _t('today');?><span class="date"> — <?php echo timestamptodate(time(), false); ?></span><?php@@ -41,7 +43,7 @@ if (!empty($this->entries)) {?></div><?php$display_today = false;}- if ($display_yesterday && $item->isDay(FreshRSS_Days::YESTERDAY, $this->today)) {+ if ($display_yesterday && $item->isDay(FreshRSS_Days::YESTERDAY, $today)) {?><div class="day" id="day_yesterday"><?phpecho _t('yesterday');?><span class="date"> — <?php echo timestamptodate(time() - 86400, false); ?></span><?php@@ -49,7 +51,7 @@ if (!empty($this->entries)) {?></div><?php$display_yesterday = false;}- if ($display_others && $item->isDay(FreshRSS_Days::BEFORE_YESTERDAY, $this->today)) {+ if ($display_others && $item->isDay(FreshRSS_Days::BEFORE_YESTERDAY, $today)) {?><div class="day" id="day_before_yesterday"><?phpecho _t('before_yesterday');?><span class="name"><?php echo $this->currentName; ?></span><?php