summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-22 13:35:30 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-22 13:35:30 +0200
commitb446a510ebacddd1437d907e795c83b3d05a9b98 (patch)
treece5f131b80b1ed69b969e1d0451264c3a95f06cb
parentfcae4157539306e90299e7f0e90740320a2833d7 (diff)
Finish to update context object
See See https://github.com/marienfressinaud/FreshRSS/issues/634
-rwxr-xr-xapp/Controllers/indexController.php82
-rw-r--r--app/Models/Context.php6
-rw-r--r--app/views/index/normal.phtml8
3 files changed, 32 insertions, 64 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 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.php
index 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.phtml
index 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><?php
foreach ($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"><?php
echo _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"><?php
echo _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"><?php
echo _t('before_yesterday');
?><span class="name"><?php echo $this->currentName; ?></span><?php