From 8a7bab3a55442f85553ab1d897084e89c10f7e05 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 20 Oct 2014 19:35:22 +0200 Subject: Refactoring of indexController Global view has been moved to a different action (all is not working) See https://github.com/marienfressinaud/FreshRSS/issues/634 and https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/Controllers/errorController.php | 2 +- app/Controllers/indexController.php | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 76ab930e0..6c080bea8 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -37,7 +37,7 @@ class FreshRSS_error_Controller extends Minz_ActionController { if ($this->view->errorMessage == '') { switch($code_int) { case 403: - $this->view->errorMessage = _t('forbidden_access'); + $this->view->errorMessage = _t('access_denied'); break; case 404: default: diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index f994e257c..e1ce71b28 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -1,5 +1,8 @@ array(_t('access_denied'))) - ); + Minz_Error::error(403); return; } elseif ($output !== 'rss') { // "hard" redirection is not required, just ask dispatcher to @@ -201,17 +201,34 @@ class FreshRSS_index_Controller extends Minz_ActionController { return false; } } + + /** + * This action displays the global view of FreshRSS. + */ + public function globalAction() { + if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) { + Minz_Error::error(403); + } + + Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); + + $catDAO = new FreshRSS_CategoryDAO(); + $this->view->categories = $catDAO->listCategories(); + } + /** + * This action displays the about page of FreshRSS. + */ public function aboutAction() { Minz_View::prependTitle(_t('about') . ' · '); } + /** + * This action displays logs of FreshRSS for the current user. + */ public function logsAction() { if (!FreshRSS_Auth::hasAccess()) { - Minz_Error::error( - 403, - array('error' => array(_t('access_denied'))) - ); + Minz_Error::error(403); } Minz_View::prependTitle(_t('logs') . ' · '); -- cgit v1.2.3 From 80cffa6de51771cd80995fb1c4f1e04ee868eb45 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 21 Oct 2014 16:46:36 +0200 Subject: Views are in dedicated actions + improve Context - Seperate normal, global and rss outputs in dedicated actions (NOT WORKING YET!) - Rewrite aside_flux and nav_menu to use Context object - Improve Context object See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/indexController.php | 97 ++++++++------- app/FreshRSS.php | 10 -- app/Models/Context.php | 65 +++++++++- app/layout/aside_flux.phtml | 103 ++++++---------- app/layout/nav_menu.phtml | 205 +++++++------------------------ app/views/helpers/view/normal_view.phtml | 191 ---------------------------- app/views/helpers/view/rss_view.phtml | 29 ----- app/views/index/global.phtml | 4 +- app/views/index/normal.phtml | 191 ++++++++++++++++++++++++++++ app/views/index/rss.phtml | 29 +++++ lib/Minz/Request.php | 7 ++ 11 files changed, 425 insertions(+), 506 deletions(-) delete mode 100644 app/views/helpers/view/normal_view.phtml delete mode 100755 app/views/helpers/view/rss_view.phtml create mode 100644 app/views/index/normal.phtml create mode 100755 app/views/index/rss.phtml (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index e1ce71b28..d348ea1d0 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -7,47 +7,17 @@ class FreshRSS_index_Controller extends Minz_ActionController { private $nb_not_read_cat = 0; public function indexAction() { - $output = Minz_Request::param('output'); - $token = FreshRSS_Context::$conf->token; - - // check if user is logged in - if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) { - $token_param = Minz_Request::param('token', ''); - $token_is_ok = ($token != '' && $token === $token_param); - if ($output === 'rss' && !$token_is_ok) { - Minz_Error::error(403); - return; - } elseif ($output !== 'rss') { - // "hard" redirection is not required, just ask dispatcher to - // forward to the login form without 302 redirection - Minz_Request::forward(array('c' => 'auth', 'a' => 'login')); - return; - } - } + // TODO: update the context with information from request. + // TODO: then, in dedicated action, get corresponding entries - $params = Minz_Request::params(); - if (isset($params['search'])) { - $params['search'] = urlencode($params['search']); - } - - $this->view->url = array( + $prefered_output = FreshRSS_Context::$conf->view_mode; + Minz_Request::forward(array( 'c' => 'index', - 'a' => 'index', - 'params' => $params - ); + 'a' => $prefered_output + )); - if ($output === 'rss') { - // no layout for RSS output - $this->view->_useLayout(false); - header('Content-Type: application/rss+xml; charset=utf-8'); - } elseif ($output === 'global') { - Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); - } + return; - $catDAO = new FreshRSS_CategoryDAO(); - $entryDAO = FreshRSS_Factory::createEntryDao(); - - $this->view->cat_aside = $catDAO->listCategories(); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites(); $this->view->nb_not_read = FreshRSS_CategoryDAO::CountUnreads($this->view->cat_aside, 1); $this->view->currentName = ''; @@ -60,10 +30,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $getId = substr($get, 2); if (!$this->checkAndProcessType($getType, $getId)) { Minz_Log::debug('Not found [' . $getType . '][' . $getId . ']'); - Minz_Error::error( - 404, - array('error' => array(_t('page_not_found'))) - ); + Minz_Error::error(404); return; } @@ -144,10 +111,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->entries = $entries; } catch (FreshRSS_EntriesGetter_Exception $e) { Minz_Log::notice($e->getMessage()); - Minz_Error::error( - 404, - array('error' => array(_t('page_not_found'))) - ); + Minz_Error::error(404); } } @@ -202,20 +166,59 @@ class FreshRSS_index_Controller extends Minz_ActionController { } } + /** + * This action displays the normal view of FreshRSS. + */ + public function normalAction() { + if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) { + Minz_Request::forward(array('c' => 'auth', 'a' => 'login')); + return; + } + + $catDAO = new FreshRSS_CategoryDAO(); + $entryDAO = FreshRSS_Factory::createEntryDao(); + + $this->view->categories = $catDAO->listCategories(); + + } + /** * This action displays the global view of FreshRSS. */ public function globalAction() { if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) { - Minz_Error::error(403); + Minz_Request::forward(array('c' => 'auth', 'a' => 'login')); + return; } Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); $catDAO = new FreshRSS_CategoryDAO(); $this->view->categories = $catDAO->listCategories(); + + Minz_View::prependTitle(_t('gen.title.global_view') . ' · '); } - + + /** + * This action displays the RSS feed of FreshRSS. + */ + public function rssAction() { + $token = FreshRSS_Context::$conf->token; + $token_param = Minz_Request::param('token', ''); + $token_is_ok = ($token != '' && $token === $token_param); + + // Check if user has access. + if (!FreshRSS_Auth::hasAccess() && + !Minz_Configuration::allowAnonymous() && + !$token_is_ok) { + Minz_Error::error(403); + } + + // No layout for RSS output. + $this->view->_useLayout(false); + header('Content-Type: application/rss+xml; charset=utf-8'); + } + /** * This action displays the about page of FreshRSS. */ diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 752b14e31..b997433bf 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -26,21 +26,11 @@ class FreshRSS extends Minz_FrontController { // Load context and configuration. FreshRSS_Context::init(); - $this->loadParamsView(); $this->loadStylesAndScripts(); $this->loadNotifications(); $this->loadExtensions(); } - private function loadParamsView() { - // TODO: outputs should be different actions. - $output = Minz_Request::param('output', ''); - if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) { - $output = FreshRSS_Context::$conf->view_mode; - Minz_Request::_param('output', $output); - } - } - private function loadStylesAndScripts() { $theme = FreshRSS_Themes::load(FreshRSS_Context::$conf->theme); if ($theme) { diff --git a/app/Models/Context.php b/app/Models/Context.php index d984fece7..b85179652 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -6,7 +6,22 @@ */ class FreshRSS_Context { public static $conf = null; + + public static $total_unread = 0; + public static $total_starred = array( + 'all' => 0, + 'read' => 0, + 'unread' => 0, + ); + public static $state = 0; + public static $current_get = array( + 'all' => false, + 'starred' => false, + 'feed' => false, + 'category' => false, + ); + public static $order = 'DESC'; public static function init() { // Init configuration. @@ -23,10 +38,56 @@ class FreshRSS_Context { Minz_Translate::init(); // Get the current state. - self::$state = self::$conf->default_view; + // self::$state = self::$conf->default_view; } - public static function stateEnabled($state) { + public static function isStateEnabled($state) { return self::$state & $state; } + + public static function getRevertState($state) { + if (self::$state & $state) { + return self::$state & ~$state; + } else { + return self::$state | $state; + } + } + + public static function currentGet() { + if (self::$current_get['all']) { + return 'a'; + } elseif (self::$current_get['starred']) { + return 's'; + } elseif (self::$current_get['feed']) { + return 'f_' . self::$current_get['feed']; + } elseif (self::$current_get['category']) { + return 'c_' . self::$current_get['category']; + } + } + + public static function isCurrentGet($get) { + $type = $get[0]; + $id = substr($get, 2); + + switch($type) { + case 'a': + return self::$current_get['all']; + case 's': + return self::$current_get['starred']; + case 'f': + return self::$current_get['feed'] === $id; + case 'c': + return self::$current_get['category'] === $id; + default: + return false; + } + } + + public static function nextStep() { + // TODO: fix this method. + return array( + 'get' => 'a', + 'idMax' => (time() - 1) . '000000' + ); + } } diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 114ccbf56..e572e9d48 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -1,82 +1,53 @@ -
+
-
    - - + +
    + + +
    + + + + + -
  • -
    - - -
    +
      +
    • + +
    • + +
    • +
    • - -
    • - 'index', 'a' => 'index', 'params' => array()); - if (FreshRSS_Context::$conf->view_mode !== Minz_Request::param('output', 'normal')) { - $arUrl['params']['output'] = 'normal'; - } + foreach ($this->categories as $cat) { + $feeds = $cat->feeds(); + if (!empty($feeds)) { ?> -
    • - -
    • +
    • + name(); ?> -
    • - +
    • - cat_aside as $cat) { - $feeds = $cat->feeds(); - if (!empty($feeds)) { - $c_active = false; - $c_show = false; - if ($this->get_c == $cat->id()) { - $c_active = true; - if (!FreshRSS_Context::$conf->display_categories || $this->get_f) { - $c_show = true; - } } - ?>
    • >
        id(); - $nbEntries = $feed->nbEntries(); - $f_active = ($this->get_f == $feed_id); - ?>
      • ✇ name(); ?>
    • + ?>
    -
nextId)) { + if (FreshRSS_Context::$next_id !== '') { $params = Minz_Request::params(); - $params['next'] = $this->nextId; + $params['next'] = FreshRSS_Context::$next_id; $params['ajax'] = 1; ?> diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index c39dba0a9..36adef2f2 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -32,14 +32,14 @@ if (!empty($this->entries)) {
- +
entries as $item) { if ($display_today && $item->isDay(FreshRSS_Days::TODAY, $today)) { ?>
currentName; ?>
entries)) { ?>
currentName; ?>
isDay(FreshRSS_Days::BEFORE_YESTERDAY, $today)) { ?>
currentName; ?>
Date: Wed, 22 Oct 2014 17:57:22 +0200 Subject: Fix a set of TODO and bugs - Context object raises correct Exception if get is invalid - RSS feed is well-indicated on the home page - State is better calculated - Add some comments See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/indexController.php | 39 +++++++++++++++++++++++++------------ app/Exceptions/ContextException.php | 10 ++++++++++ app/Models/Context.php | 16 ++++++--------- app/layout/layout.phtml | 17 ++++++++-------- 4 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 app/Exceptions/ContextException.php (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index d711997be..f9af2d0bb 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -5,10 +5,10 @@ */ class FreshRSS_index_Controller extends Minz_ActionController { + /** + * This action only redirect on the default view mode (normal or global) + */ public function indexAction() { - // TODO: update the context with information from request. - // TODO: then, in dedicated action, get corresponding entries - $prefered_output = FreshRSS_Context::$conf->view_mode; Minz_Request::forward(array( 'c' => 'index', @@ -27,12 +27,12 @@ class FreshRSS_index_Controller extends Minz_ActionController { try { $this->updateContext(); - } catch (Minz_Exception $e) { + } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } try { - $entries = $this->listByContext(); + $entries = $this->listEntriesByContext(); if (count($entries) > FreshRSS_Context::$number) { // We have more elements for pagination @@ -48,6 +48,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->categories = FreshRSS_Context::$categories; + $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title(); $title = FreshRSS_Context::$name; if (FreshRSS_Context::$get_unread > 0) { $title = '(' . FreshRSS_Context::$get_unread . ') · ' . $title; @@ -68,12 +69,13 @@ class FreshRSS_index_Controller extends Minz_ActionController { try { $this->updateContext(); - } catch (Minz_Exception $e) { + } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } $this->view->categories = FreshRSS_Context::$categories; + $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title(); Minz_View::prependTitle(_t('gen.title.global_view') . ' · '); } @@ -94,12 +96,12 @@ class FreshRSS_index_Controller extends Minz_ActionController { try { $this->updateContext(); - } catch (Minz_Exception $e) { + } catch (FreshRSS_Context_Exception $e) { Minz_Error::error(404); } try { - $this->view->entries = $this->listByContext(); + $this->view->entries = $this->listEntriesByContext(); } catch (FreshRSS_EntriesGetter_Exception $e) { Minz_Log::notice($e->getMessage()); Minz_Error::error(404); @@ -113,15 +115,25 @@ class FreshRSS_index_Controller extends Minz_ActionController { /** * This action updates the Context object by using request parameters. + * + * Parameters are: + * - state (default: conf->default_view) + * - search (default: empty string) + * - order (default: conf->sort_order) + * - nb (default: conf->posts_per_page) + * - next (default: empty string) */ private function updateContext() { FreshRSS_Context::_get(Minz_Request::param('get', 'a')); - FreshRSS_Context::$state |= Minz_Request::param( + // TODO: change default_view by default_state. + 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) { + $state_forced_by_user = Minz_Request::param('state', false) !== false; + if (FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_NOT_READ) && + FreshRSS_Context::$get_unread <= 0 && + !$state_forced_by_user) { FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ; } @@ -135,7 +147,10 @@ class FreshRSS_index_Controller extends Minz_ActionController { FreshRSS_Context::$first_id = Minz_Request::param('next', ''); } - private function listByContext() { + /** + * This method returns a list of entries based on the Context object. + */ + private function listEntriesByContext() { $entryDAO = FreshRSS_Factory::createEntryDao(); $get = FreshRSS_Context::currentGet(true); diff --git a/app/Exceptions/ContextException.php b/app/Exceptions/ContextException.php new file mode 100644 index 000000000..357751b7c --- /dev/null +++ b/app/Exceptions/ContextException.php @@ -0,0 +1,10 @@ + 0, ); - public static $state = 0; + public static $get_unread = 0; public static $current_get = array( 'all' => false, 'starred' => false, 'feed' => false, 'category' => false, ); - public static $get_unread = 0; + + public static $state = 0; public static $order = 'DESC'; public static $number = 0; public static $search = ''; @@ -48,8 +49,6 @@ class FreshRSS_Context { $catDAO = new FreshRSS_CategoryDAO(); $entryDAO = FreshRSS_Factory::createEntryDao(); - // Get the current state. - // self::$state = self::$conf->default_view; self::$categories = $catDAO->listCategories(); // Update number of read / unread variables. @@ -97,8 +96,7 @@ class FreshRSS_Context { $feed = $feedDAO->searchById($id); if (!$feed) { - // TODO: raise an exception - return false; + throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); } } @@ -112,8 +110,7 @@ class FreshRSS_Context { $cat = $catDAO->searchById($id); if (!$cat) { - // TODO: raise an exception - return false; + throw new FreshRSS_Context_Exception('Invalid category: ' . $id); } } else { $cat = self::$categories[$id]; @@ -123,8 +120,7 @@ class FreshRSS_Context { self::$get_unread = $cat->nbNotRead(); break; default: - // TODO: raise an exception! - return false; + throw new FreshRSS_Context_Exception('Invalid getter: ' . $get); } } diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index 2b38df4a1..1827d6c26 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -10,21 +10,22 @@ renderHelper('javascript_vars'); ?> //]]> - + url)) { - $rss_url = $this->url; - $rss_url['params']['output'] = 'rss'; + if (isset($this->rss_title)) { + $url_rss = $url_base; + $url_rss['a'] = 'rss'; ?> - + -- cgit v1.2.3 From 9551145200b61717fdeb11007e1da541ddf93f0f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 22 Oct 2014 18:21:36 +0200 Subject: Better view mode - Seperate view mode from default state in conf - Load read articles if no unread articles only if view is adaptive See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/configureController.php | 2 +- app/Controllers/indexController.php | 6 +++--- app/Models/Configuration.php | 21 +++++++++++++-------- app/views/configure/reading.phtml | 6 +++--- 4 files changed, 20 insertions(+), 15 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 8a9dcdc62..9a7870000 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -104,7 +104,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { if (Minz_Request::isPost()) { FreshRSS_Context::$conf->_posts_per_page(Minz_Request::param('posts_per_page', 10)); FreshRSS_Context::$conf->_view_mode(Minz_Request::param('view_mode', 'normal')); - FreshRSS_Context::$conf->_default_view((int)Minz_Request::param('default_view', FreshRSS_Entry::STATE_ALL)); + FreshRSS_Context::$conf->_default_view(Minz_Request::param('default_view', 'adaptive')); FreshRSS_Context::$conf->_auto_load_more(Minz_Request::param('auto_load_more', false)); FreshRSS_Context::$conf->_display_posts(Minz_Request::param('display_posts', false)); FreshRSS_Context::$conf->_display_categories(Minz_Request::param('display_categories', false)); diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index f9af2d0bb..2dd4c3068 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -126,13 +126,13 @@ class FreshRSS_index_Controller extends Minz_ActionController { private function updateContext() { FreshRSS_Context::_get(Minz_Request::param('get', 'a')); - // TODO: change default_view by default_state. FreshRSS_Context::$state = Minz_Request::param( - 'state', FreshRSS_Context::$conf->default_view + 'state', FreshRSS_Context::$conf->default_state ); $state_forced_by_user = Minz_Request::param('state', false) !== false; - if (FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_NOT_READ) && + if (FreshRSS_Context::$conf->default_view === 'adaptive' && FreshRSS_Context::$get_unread <= 0 && + !FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_READ) && !$state_forced_by_user) { FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ; } diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 2f208e509..53f136513 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -14,7 +14,8 @@ class FreshRSS_Configuration { 'apiPasswordHash' => '', //CRYPT_BLOWFISH 'posts_per_page' => 20, 'view_mode' => 'normal', - 'default_view' => FreshRSS_Entry::STATE_NOT_READ, + 'default_view' => 'adaptive', + 'default_state' => FreshRSS_Entry::STATE_NOT_READ, 'auto_load_more' => true, 'display_posts' => false, 'display_categories' => false, @@ -153,18 +154,22 @@ class FreshRSS_Configuration { } public function _default_view($value) { switch ($value) { - case FreshRSS_Entry::STATE_ALL: - // left blank on purpose - case FreshRSS_Entry::STATE_NOT_READ: - // left blank on purpose - case FreshRSS_Entry::STATE_STRICT + FreshRSS_Entry::STATE_NOT_READ: + case 'all': $this->data['default_view'] = $value; + $this->data['default_state'] = (FreshRSS_Entry::STATE_READ + + FreshRSS_Entry::STATE_NOT_READ); break; + case 'adaptive': + case 'unread': default: - $this->data['default_view'] = FreshRSS_Entry::STATE_ALL; - break; + $this->data['default_view'] = $value; + $this->data['default_state'] = FreshRSS_Entry::STATE_NOT_READ; } } + public function _default_state($value) { + $this->data['default_state'] = (int)$value; + } + public function _display_posts($value) { $this->data['display_posts'] = ((bool)$value) && $value !== 'no'; } diff --git a/app/views/configure/reading.phtml b/app/views/configure/reading.phtml index ef775b4b1..b8f673466 100644 --- a/app/views/configure/reading.phtml +++ b/app/views/configure/reading.phtml @@ -39,9 +39,9 @@
-- cgit v1.2.3 From 8a6ad05ebacb6bf6c0f6afd0afe54a29a0a18ee9 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 22 Oct 2014 18:33:46 +0200 Subject: Remove STATE_STRICT See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/configureController.php | 3 --- app/Models/Entry.php | 3 +-- app/Models/EntryDAO.php | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 9a7870000..cafd0e8a8 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -338,9 +338,6 @@ class FreshRSS_configure_Controller extends Minz_ActionController { unset($query[$key]); } } - if (!empty($query['state']) && $query['state'] & FreshRSS_Entry::STATE_STRICT) { - $query['state'] -= FreshRSS_Entry::STATE_STRICT; - } $queries[] = $query; FreshRSS_Context::$conf->_queries($queries); FreshRSS_Context::$conf->save(); diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ee94d1110..346c98a92 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -1,12 +1,11 @@ Date: Wed, 22 Oct 2014 19:19:15 +0200 Subject: nextGet and idMax are coming back. See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/entryController.php | 14 ++----- app/Controllers/indexController.php | 15 +++++++- app/Models/Context.php | 73 ++++++++++++++++++++++++++++++++----- app/layout/nav_menu.phtml | 5 +-- 4 files changed, 82 insertions(+), 25 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 449029648..d11f3a520 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -17,14 +17,6 @@ class FreshRSS_entry_Controller extends Minz_ActionController { ); } - // Keep parameter information (output) to do a correct redirection at - // the end. - $this->params = array(); - $output = Minz_Request::param('output', ''); - if ($output != '' && FreshRSS_Context::$conf->view_mode !== $output) { - $this->params['output'] = $output; - } - // If ajax request, we do not print layout $this->ajax = Minz_Request::param('ajax'); if ($this->ajax) { @@ -53,6 +45,7 @@ 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); + $params = array(); $entryDAO = FreshRSS_Factory::createEntryDao(); if ($id === false) { @@ -86,7 +79,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { // Redirect to the correct page (category, feed or starred) // Not "a" because it is the default value if nothing is // given. - $this->params['get'] = $next_get; + $params['get'] = $next_get; } } } else { @@ -98,7 +91,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { Minz_Request::good(_t('feeds_marked_read'), array( 'c' => 'index', 'a' => 'index', - 'params' => $this->params, + 'params' => $params, ), true); } } @@ -123,7 +116,6 @@ class FreshRSS_entry_Controller extends Minz_ActionController { Minz_Request::forward(array( 'c' => 'index', 'a' => 'index', - 'params' => $this->params, ), true); } } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 2dd4c3068..80675b3a6 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -34,12 +34,25 @@ class FreshRSS_index_Controller extends Minz_ActionController { try { $entries = $this->listEntriesByContext(); - if (count($entries) > FreshRSS_Context::$number) { + $nb_entries = count($entries); + if ($nb_entries > FreshRSS_Context::$number) { // We have more elements for pagination $last_entry = array_pop($entries); FreshRSS_Context::$next_id = $last_entry->id(); } + $first_entry = $nb_entries > 0 ? $entries[0] : null; + FreshRSS_Context::$id_max = $first_entry === null ? + (time() - 1) . '000000' : + $first_entry->id(); + if (FreshRSS_Context::$order === 'ASC') { + // In this case we do not know but we guess id_max + $id_max = (time() - 1) . '000000'; + if (strcmp($id_max, FreshRSS_Context::$id_max) > 0) { + FreshRSS_Context::$id_max = $id_max; + } + } + $this->view->entries = $entries; } catch (FreshRSS_EntriesGetter_Exception $e) { Minz_Log::notice($e->getMessage()); diff --git a/app/Models/Context.php b/app/Models/Context.php index 3b3c8673d..3d184dcaa 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -24,6 +24,7 @@ class FreshRSS_Context { 'feed' => false, 'category' => false, ); + public static $next_get = 'a'; public static $state = 0; public static $order = 'DESC'; @@ -31,6 +32,7 @@ class FreshRSS_Context { public static $search = ''; public static $first_id = ''; public static $next_id = ''; + public static $id_max = ''; public static function init() { // Init configuration. @@ -84,8 +86,6 @@ class FreshRSS_Context { self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; break; case 'f': - self::$current_get['feed'] = $id; - $feed = FreshRSS_CategoryDAO::findFeed(self::$categories, $id); if ($feed === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -96,6 +96,8 @@ class FreshRSS_Context { } } + self::$current_get['feed'] = $id; + self::$current_get['category'] = $feed->category(); self::$name = $feed->name(); self::$get_unread = $feed->nbNotRead(); break; @@ -118,6 +120,8 @@ class FreshRSS_Context { default: throw new FreshRSS_Context_Exception('Invalid getter: ' . $get); } + + self::_nextGet(); } public static function currentGet($array = false) { @@ -150,19 +154,68 @@ class FreshRSS_Context { case 's': return self::$current_get['starred']; case 'f': - return self::$current_get['feed'] === $id; + return self::$current_get['feed'] == $id; case 'c': - return self::$current_get['category'] === $id; + return self::$current_get['category'] == $id; default: return false; } } - public static function nextStep() { - // TODO: fix this method. - return array( - 'get' => 'a', - 'idMax' => (time() - 1) . '000000' - ); + public static function _nextGet() { + $get = self::currentGet(); + self::$next_get = $get; + + if (self::$conf->onread_jump_next && strlen($get) > 2) { + $another_unread_id = ''; + $found_current_get = false; + switch ($get[0]) { + case 'f': + foreach (self::$categories as $cat) { + if ($cat->id() != self::$current_get['category']) { + continue; + } + + foreach ($cat->feeds() as $feed) { + if ($feed->id() == self::$current_get['feed']) { + $found_current_get = true; + continue; + } + + if ($feed->nbNotRead() > 0) { + $another_unread_id = $feed->id(); + if ($found_current_get) { + break; + } + } + } + break; + } + + self::$next_get['get'] = empty($another_unread_id) ? + 'c_' . self::$current_get['category'] : + 'f_' . $another_unread_id; + break; + case 'c': + foreach (self::$categories as $cat) { + if ($cat->id() == self::$current_get['category']) { + $found_current_get = true; + continue; + } + + if ($cat->nbNotRead() > 0) { + $another_unread_id = $cat->id(); + if ($found_current_get) { + break; + } + } + } + + self::$next_get['get'] = empty($another_unread_id) ? + 'a' : + 'c_' . $another_unread_id; + break; + } + } } } diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 440e4d0b6..2c9f8724d 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -61,7 +61,6 @@ 'read', 'params' => array( 'get' => $get, - 'nextGet' => $next_step['get'], - 'idMax' => $next_step['idMax'] + 'nextGet' => FreshRSS_Context::$next_get, + 'idMax' => FreshRSS_Context::$id_max, ) ); ?> -- cgit v1.2.3 From 1efbf6fb86dfe4ff549ce1b7884db17dfbf5554f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 22 Oct 2014 20:05:00 +0200 Subject: Add comments to Context object. See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/indexController.php | 7 ++ app/Models/Context.php | 135 ++++++++++++++++++++++++------------ 2 files changed, 98 insertions(+), 44 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 80675b3a6..ed5b58b45 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -137,6 +137,13 @@ class FreshRSS_index_Controller extends Minz_ActionController { * - next (default: empty string) */ private function updateContext() { + // Update number of read / unread variables. + $entryDAO = FreshRSS_Factory::createEntryDao(); + FreshRSS_Context::$total_starred = $entryDAO->countUnreadReadFavorites(); + FreshRSS_Context::$total_unread = FreshRSS_CategoryDAO::CountUnreads( + FreshRSS_Context::$categories, 1 + ); + FreshRSS_Context::_get(Minz_Request::param('get', 'a')); FreshRSS_Context::$state = Minz_Request::param( diff --git a/app/Models/Context.php b/app/Models/Context.php index d4aeee7ac..36c4087eb 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -34,6 +34,11 @@ class FreshRSS_Context { public static $next_id = ''; public static $id_max = ''; + /** + * Initialize the context. + * + * Set the correct $conf and $categories variables. + */ public static function init() { // Init configuration. $current_user = Minz_Session::param('currentUser'); @@ -45,19 +50,19 @@ class FreshRSS_Context { } $catDAO = new FreshRSS_CategoryDAO(); - $entryDAO = FreshRSS_Factory::createEntryDao(); - self::$categories = $catDAO->listCategories(); - - // Update number of read / unread variables. - self::$total_starred = $entryDAO->countUnreadReadFavorites(); - self::$total_unread = FreshRSS_CategoryDAO::CountUnreads(self::$categories, 1); } + /** + * Returns if the current state includes $state parameter. + */ public static function isStateEnabled($state) { return self::$state & $state; } + /** + * Returns the current state with or without $state parameter. + */ public static function getRevertState($state) { if (self::$state & $state) { return self::$state & ~$state; @@ -66,6 +71,65 @@ class FreshRSS_Context { } } + /** + * Return the current get as a string or an array. + * + * If $array is true, the first item of the returned value is 'f' or 'c' and + * the second is the id. + */ + public static function currentGet($array = false) { + if (self::$current_get['all']) { + return 'a'; + } elseif (self::$current_get['starred']) { + return 's'; + } elseif (self::$current_get['feed']) { + if ($array) { + return array('f', self::$current_get['feed']); + } else { + return 'f_' . self::$current_get['feed']; + } + } elseif (self::$current_get['category']) { + if ($array) { + return array('c', self::$current_get['category']); + } else { + return 'c_' . self::$current_get['category']; + } + } + } + + /** + * Return true if $get parameter correspond to the $current_get attribute. + */ + public static function isCurrentGet($get) { + $type = $get[0]; + $id = substr($get, 2); + + switch($type) { + case 'a': + return self::$current_get['all']; + case 's': + return self::$current_get['starred']; + case 'f': + return self::$current_get['feed'] == $id; + case 'c': + return self::$current_get['category'] == $id; + default: + return false; + } + } + + /** + * Set the current $get attribute. + * + * Valid $get parameter are: + * - a + * - s + * - f_ + * - c_ + * + * $name and $get_unread attributes are also updated as $next_get + * Raise an exception if id or $get is invalid. + */ public static function _get($get) { $type = $get[0]; $id = substr($get, 2); @@ -86,6 +150,7 @@ class FreshRSS_Context { self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; break; case 'f': + // We try to find the corresponding feed. $feed = FreshRSS_CategoryDAO::findFeed(self::$categories, $id); if ($feed === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -102,6 +167,7 @@ class FreshRSS_Context { self::$get_unread = $feed->nbNotRead(); break; case 'c': + // We try to find the corresponding category. self::$current_get['category'] = $id; if (!isset(self::$categories[$id])) { $catDAO = new FreshRSS_CategoryDAO(); @@ -124,46 +190,12 @@ class FreshRSS_Context { self::_nextGet(); } - public static function currentGet($array = false) { - if (self::$current_get['all']) { - return 'a'; - } elseif (self::$current_get['starred']) { - return 's'; - } elseif (self::$current_get['feed']) { - if ($array) { - return array('f', self::$current_get['feed']); - } else { - return 'f_' . self::$current_get['feed']; - } - } elseif (self::$current_get['category']) { - if ($array) { - return array('c', self::$current_get['category']); - } else { - return 'c_' . self::$current_get['category']; - } - } - } - - public static function isCurrentGet($get) { - $type = $get[0]; - $id = substr($get, 2); - - switch($type) { - case 'a': - return self::$current_get['all']; - case 's': - return self::$current_get['starred']; - case 'f': - return self::$current_get['feed'] == $id; - case 'c': - return self::$current_get['category'] == $id; - default: - return false; - } - } - + /** + * Set the value of $next_get attribute. + */ public static function _nextGet() { $get = self::currentGet(); + // By default, $next_get == $get self::$next_get = $get; if (self::$conf->onread_jump_next && strlen($get) > 2) { @@ -171,13 +203,18 @@ class FreshRSS_Context { $found_current_get = false; switch ($get[0]) { case 'f': + // We search the next feed with at least one unread article in + // same category as the currend feed. foreach (self::$categories as $cat) { if ($cat->id() != self::$current_get['category']) { + // We look into the category of the current feed! continue; } foreach ($cat->feeds() as $feed) { if ($feed->id() == self::$current_get['feed']) { + // Here is our current feed! Fine, the next one will + // be a potential candidate. $found_current_get = true; continue; } @@ -185,6 +222,9 @@ class FreshRSS_Context { if ($feed->nbNotRead() > 0) { $another_unread_id = $feed->id(); if ($found_current_get) { + // We have found our current feed and now we + // have an feed with unread articles. Leave the + // loop! break; } } @@ -192,13 +232,17 @@ class FreshRSS_Context { break; } + // If no feed have been found, next_get is the current category. self::$next_get = empty($another_unread_id) ? 'c_' . self::$current_get['category'] : 'f_' . $another_unread_id; break; case 'c': + // We search the next category with at least one unread article. foreach (self::$categories as $cat) { if ($cat->id() == self::$current_get['category']) { + // Here is our current category! Next one could be our + // champion if it has unread articles. $found_current_get = true; continue; } @@ -206,11 +250,14 @@ class FreshRSS_Context { if ($cat->nbNotRead() > 0) { $another_unread_id = $cat->id(); if ($found_current_get) { + // Unread articles and the current category has + // already been found? Leave the loop! break; } } } + // No unread category? The main stream will be our destination! self::$next_get = empty($another_unread_id) ? 'a' : 'c_' . $another_unread_id; -- cgit v1.2.3 From 0d6993fe08cf57121eadb2aa0e4208420756165a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 24 Oct 2014 12:51:17 +0200 Subject: Reader view comes back! See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/indexController.php | 9 +++++++ app/layout/nav_menu.phtml | 5 ++++ app/views/helpers/view/reader_view.phtml | 44 -------------------------------- app/views/index/reader.phtml | 44 ++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 44 deletions(-) delete mode 100644 app/views/helpers/view/reader_view.phtml create mode 100644 app/views/index/reader.phtml (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index ed5b58b45..8bc23fb70 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -69,6 +69,15 @@ class FreshRSS_index_Controller extends Minz_ActionController { Minz_View::prependTitle($title . ' · '); } + /** + * This action displays the reader view of FreshRSS. + * + * @todo: change this view into specific CSS rules? + */ + public function readerAction() { + $this->normalAction(); + } + /** * This action displays the global view of FreshRSS. */ diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index 6f555c3d0..075f84ca6 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -133,6 +133,11 @@ + + + + + diff --git a/app/views/helpers/view/reader_view.phtml b/app/views/helpers/view/reader_view.phtml deleted file mode 100644 index 821a50f7f..000000000 --- a/app/views/helpers/view/reader_view.phtml +++ /dev/null @@ -1,44 +0,0 @@ -partial('nav_menu'); - -if (!empty($this->entries)) { - $lazyload = FreshRSS_Context::$conf->lazyload; - $content_width = FreshRSS_Context::$conf->content_width; -?> - -
- entries as $item) { ?> - -
-
-
- cat_aside, $item->feed()); //We most likely already have the feed object in cache - if (empty($feed)) $feed = $item->feed(true); - ?> - - ✇ name(); ?> - -

title(); ?>

- -
author(); - echo $author != '' ? _t('by_author', $author) . ' — ' : '', - $item->date(); - ?>
- - content(); ?> -
-
-
- - - renderHelper('pagination'); ?> -
- - -
-

-

-
- diff --git a/app/views/index/reader.phtml b/app/views/index/reader.phtml new file mode 100644 index 000000000..f07868488 --- /dev/null +++ b/app/views/index/reader.phtml @@ -0,0 +1,44 @@ +partial('nav_menu'); + +if (!empty($this->entries)) { + $lazyload = FreshRSS_Context::$conf->lazyload; + $content_width = FreshRSS_Context::$conf->content_width; +?> + +
+ entries as $item) { ?> + +
+
+
+ categories, $item->feed()); //We most likely already have the feed object in cache + if (empty($feed)) $feed = $item->feed(true); + ?> + + ✇ name(); ?> + +

title(); ?>

+ +
author(); + echo $author != '' ? _t('by_author', $author) . ' — ' : '', + $item->date(); + ?>
+ + content(); ?> +
+
+
+ + + renderHelper('pagination'); ?> +
+ + +
+

+

+
+ -- cgit v1.2.3 From 83d95ca4b894a84de467a97c7f413c1d04c43631 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 24 Oct 2014 15:11:02 +0200 Subject: Fix titles for normal and global views See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/Controllers/indexController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 8bc23fb70..1cf618f7f 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -64,7 +64,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title(); $title = FreshRSS_Context::$name; if (FreshRSS_Context::$get_unread > 0) { - $title = '(' . FreshRSS_Context::$get_unread . ') · ' . $title; + $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title; } Minz_View::prependTitle($title . ' · '); } @@ -98,7 +98,11 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->categories = FreshRSS_Context::$categories; $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title(); - Minz_View::prependTitle(_t('gen.title.global_view') . ' · '); + $title = _t('gen.title.global_view'); + if (FreshRSS_Context::$get_unread > 0) { + $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title; + } + Minz_View::prependTitle($title . ' · '); } /** -- cgit v1.2.3