From 6c8b36f04ea1bc2c022c331bb0980b6c9dccb83c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 5 Oct 2014 15:55:20 +0200 Subject: Let's begin the big refactoring! Minz_Translate::t\s? replaces by _t See https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/Controllers/errorController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/Controllers/errorController.php') diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 922650b3d..64a5c06fd 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -24,11 +24,11 @@ class FreshRSS_error_Controller extends Minz_ActionController { if ($this->view->errorMessage == '') { switch(Minz_Request::param('code')) { case 403: - $this->view->errorMessage = Minz_Translate::t('forbidden_access'); + $this->view->errorMessage = _t('forbidden_access'); break; case 404: default: - $this->view->errorMessage = Minz_Translate::t('page_not_found'); + $this->view->errorMessage = _t('page_not_found'); break; } } -- cgit v1.2.3 From 9a0d01be0cb627b30424e9f938face34c6c3814d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 5 Oct 2014 18:24:28 +0200 Subject: Coding style Remove spaces before parenthesis. See https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/Controllers/entryController.php | 78 +++++------ app/Controllers/errorController.php | 28 ++-- app/Controllers/feedController.php | 184 +++++++++++++------------ app/Controllers/indexController.php | 229 ++++++++++++++++--------------- app/Controllers/javascriptController.php | 6 +- app/Controllers/statsController.php | 2 +- 6 files changed, 269 insertions(+), 258 deletions(-) (limited to 'app/Controllers/errorController.php') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index 048ac1c69..ec90666ed 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -1,47 +1,47 @@ view->loginOk) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (_t('access_denied'))) + array('error' => array(_t('access_denied'))) ); } - $this->params = array (); + $this->params = array(); $output = Minz_Request::param('output', ''); if (($output != '') && ($this->view->conf->view_mode !== $output)) { $this->params['output'] = $output; } $this->redirect = false; - $ajax = Minz_Request::param ('ajax'); + $ajax = Minz_Request::param('ajax'); if ($ajax) { - $this->view->_useLayout (false); + $this->view->_useLayout(false); } } - public function lastAction () { - $ajax = Minz_Request::param ('ajax'); + public function lastAction() { + $ajax = Minz_Request::param('ajax'); if (!$ajax && $this->redirect) { - Minz_Request::forward (array ( + Minz_Request::forward(array( 'c' => 'index', 'a' => 'index', 'params' => $this->params ), true); } else { - Minz_Request::_param ('ajax'); + Minz_Request::_param('ajax'); } } - public function readAction () { + public function readAction() { $this->redirect = true; - $id = Minz_Request::param ('id'); - $get = Minz_Request::param ('get'); - $nextGet = Minz_Request::param ('nextGet', $get); - $idMax = Minz_Request::param ('idMax', 0); + $id = Minz_Request::param('id'); + $get = Minz_Request::param('get'); + $nextGet = Minz_Request::param('nextGet', $get); + $idMax = Minz_Request::param('idMax', 0); $entryDAO = FreshRSS_Factory::createEntryDao(); if ($id == false) { @@ -50,47 +50,47 @@ class FreshRSS_entry_Controller extends Minz_ActionController { } if (!$get) { - $entryDAO->markReadEntries ($idMax); + $entryDAO->markReadEntries($idMax); } else { $typeGet = $get[0]; - $get = substr ($get, 2); - switch ($typeGet) { - case 'c': - $entryDAO->markReadCat ($get, $idMax); - break; - case 'f': - $entryDAO->markReadFeed ($get, $idMax); - break; - case 's': - $entryDAO->markReadEntries ($idMax, true); - break; - case 'a': - $entryDAO->markReadEntries ($idMax); - break; + $get = substr($get, 2); + switch($typeGet) { + case 'c': + $entryDAO->markReadCat($get, $idMax); + break; + case 'f': + $entryDAO->markReadFeed($get, $idMax); + break; + case 's': + $entryDAO->markReadEntries($idMax, true); + break; + case 'a': + $entryDAO->markReadEntries($idMax); + break; } if ($nextGet !== 'a') { $this->params['get'] = $nextGet; } } - $notif = array ( + $notif = array( 'type' => 'good', 'content' => _t('feeds_marked_read') ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } else { - $is_read = (bool)(Minz_Request::param ('is_read', true)); - $entryDAO->markRead ($id, $is_read); + $is_read = (bool)(Minz_Request::param('is_read', true)); + $entryDAO->markRead($id, $is_read); } } - public function bookmarkAction () { + public function bookmarkAction() { $this->redirect = true; - $id = Minz_Request::param ('id'); + $id = Minz_Request::param('id'); if ($id) { $entryDAO = FreshRSS_Factory::createEntryDao(); - $entryDAO->markFavorite ($id, (bool)(Minz_Request::param ('is_favorite', true))); + $entryDAO->markFavorite($id, (bool)(Minz_Request::param('is_favorite', true))); } } @@ -109,11 +109,11 @@ class FreshRSS_entry_Controller extends Minz_ActionController { invalidateHttpCache(); - $notif = array ( + $notif = array( 'type' => 'good', 'content' => _t('optimization_complete') ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } Minz_Request::forward(array( diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 64a5c06fd..36312b56c 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -3,20 +3,20 @@ class FreshRSS_error_Controller extends Minz_ActionController { public function indexAction() { switch (Minz_Request::param('code')) { - case 403: - $this->view->code = 'Error 403 - Forbidden'; - break; - case 404: - $this->view->code = 'Error 404 - Not found'; - break; - case 500: - $this->view->code = 'Error 500 - Internal Server Error'; - break; - case 503: - $this->view->code = 'Error 503 - Service Unavailable'; - break; - default: - $this->view->code = 'Error 404 - Not found'; + case 403: + $this->view->code = 'Error 403 - Forbidden'; + break; + case 404: + $this->view->code = 'Error 404 - Not found'; + break; + case 500: + $this->view->code = 'Error 500 - Internal Server Error'; + break; + case 503: + $this->view->code = 'Error 503 - Service Unavailable'; + break; + default: + $this->view->code = 'Error 404 - Not found'; } $errors = Minz_Request::param('logs', array()); diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 029f9fa68..93a8d7c2e 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -1,27 +1,27 @@ view->loginOk) { // Token is useful in the case that anonymous refresh is forbidden // and CRON task cannot be used with php command so the user can // set a CRON task to refresh his feeds by using token inside url $token = $this->view->conf->token; - $token_param = Minz_Request::param ('token', ''); + $token_param = Minz_Request::param('token', ''); $token_is_ok = ($token != '' && $token == $token_param); - $action = Minz_Request::actionName (); + $action = Minz_Request::actionName(); if (!(($token_is_ok || Minz_Configuration::allowAnonymousRefresh()) && $action === 'actualize') ) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (_t('access_denied'))) + array('error' => array(_t('access_denied'))) ); } } } - public function addAction () { + public function addAction() { $url = Minz_Request::param('url_rss', false); if ($url === false) { @@ -32,16 +32,16 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } $feedDAO = FreshRSS_Factory::createFeedDao(); - $this->catDAO = new FreshRSS_CategoryDAO (); - $this->catDAO->checkDefault (); + $this->catDAO = new FreshRSS_CategoryDAO(); + $this->catDAO->checkDefault(); if (Minz_Request::isPost()) { @set_time_limit(300); - $cat = Minz_Request::param ('category', false); + $cat = Minz_Request::param('category', false); if ($cat === 'nc') { - $new_cat = Minz_Request::param ('new_category'); + $new_cat = Minz_Request::param('new_category'); if (empty($new_cat['name'])) { $cat = false; } else { @@ -49,55 +49,55 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } if ($cat === false) { - $def_cat = $this->catDAO->getDefault (); - $cat = $def_cat->id (); + $def_cat = $this->catDAO->getDefault(); + $cat = $def_cat->id(); } - $user = Minz_Request::param ('http_user'); - $pass = Minz_Request::param ('http_pass'); - $params = array (); + $user = Minz_Request::param('http_user'); + $pass = Minz_Request::param('http_pass'); + $params = array(); $transactionStarted = false; try { - $feed = new FreshRSS_Feed ($url); - $feed->_category ($cat); + $feed = new FreshRSS_Feed($url); + $feed->_category($cat); $httpAuth = ''; if ($user != '' || $pass != '') { $httpAuth = $user . ':' . $pass; } - $feed->_httpAuth ($httpAuth); + $feed->_httpAuth($httpAuth); $feed->load(true); - $values = array ( - 'url' => $feed->url (), - 'category' => $feed->category (), - 'name' => $feed->name (), - 'website' => $feed->website (), - 'description' => $feed->description (), - 'lastUpdate' => time (), - 'httpAuth' => $feed->httpAuth (), + $values = array( + 'url' => $feed->url(), + 'category' => $feed->category(), + 'name' => $feed->name(), + 'website' => $feed->website(), + 'description' => $feed->description(), + 'lastUpdate' => time(), + 'httpAuth' => $feed->httpAuth(), ); - if ($feedDAO->searchByUrl ($values['url'])) { + if ($feedDAO->searchByUrl($values['url'])) { // on est déjà abonné à ce flux - $notif = array ( + $notif = array( 'type' => 'bad', - 'content' => _t('already_subscribed', $feed->name ()) + 'content' => _t('already_subscribed', $feed->name()) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } else { - $id = $feedDAO->addFeed ($values); + $id = $feedDAO->addFeed($values); if (!$id) { // problème au niveau de la base de données - $notif = array ( + $notif = array( 'type' => 'bad', - 'content' => _t('feed_not_added', $feed->name ()) + 'content' => _t('feed_not_added', $feed->name()) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } else { - $feed->_id ($id); + $feed->_id($id); $feed->faviconPrepare(); $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; @@ -107,7 +107,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = $this->view->conf->old_entries; - $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + $date_min = time() - (3600 * 24 * 30 * $nb_month_old); //MySQL: http://docs.oracle.com/cd/E17952_01/refman-5.5-en/optimizing-innodb-transaction-management.html //SQLite: http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite @@ -129,44 +129,50 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $transactionStarted = false; // ok, ajout terminé - $notif = array ( + $notif = array( 'type' => 'good', - 'content' => _t('feed_added', $feed->name ()) + 'content' => _t('feed_added', $feed->name()) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); // permet de rediriger vers la page de conf du flux - $params['id'] = $feed->id (); + $params['id'] = $feed->id(); } } } catch (FreshRSS_BadUrl_Exception $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); - $notif = array ( + Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + $notif = array( 'type' => 'bad', 'content' => _t('invalid_url', $url) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } catch (FreshRSS_Feed_Exception $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::WARNING); - $notif = array ( + Minz_Log::record($e->getMessage(), Minz_Log::WARNING); + $notif = array( 'type' => 'bad', - 'content' => _t('internal_problem_feed', Minz_Url::display(array('a' => 'logs'))) + 'content' => _t('internal_problem_feed', + Minz_Url::display(array('a' => 'logs'))) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } catch (Minz_FileNotExistException $e) { // Répertoire de cache n'existe pas - Minz_Log::record ($e->getMessage (), Minz_Log::ERROR); - $notif = array ( + Minz_Log::record($e->getMessage(), Minz_Log::ERROR); + $notif = array( 'type' => 'bad', - 'content' => _t('internal_problem_feed', Minz_Url::display(array('a' => 'logs'))) + 'content' => _t('internal_problem_feed', + Minz_Url::display(array('a' => 'logs'))) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); } if ($transactionStarted) { - $feedDAO->rollBack (); + $feedDAO->rollBack(); } - Minz_Request::forward (array ('c' => 'subscription', 'a' => 'index', 'params' => $params), true); + Minz_Request::forward(array( + 'c' => 'subscription', + 'a' => 'index', + 'params' => $params + ), true); } else { // GET request so we must ask confirmation to user @@ -201,41 +207,43 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - public function truncateAction () { - if (Minz_Request::isPost ()) { - $id = Minz_Request::param ('id'); + public function truncateAction() { + if (Minz_Request::isPost()) { + $id = Minz_Request::param('id'); $feedDAO = FreshRSS_Factory::createFeedDao(); $n = $feedDAO->truncate($id); $notif = array( 'type' => $n === false ? 'bad' : 'good', 'content' => _t('n_entries_deleted', $n) ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); invalidateHttpCache(); - Minz_Request::forward (array ('c' => 'subscription', - 'a' => 'index', - 'params' => array('id' => $id)), true); + Minz_Request::forward(array( + 'c' => 'subscription', + 'a' => 'index', + 'params' => array('id' => $id) + ), true); } } - public function actualizeAction () { + public function actualizeAction() { @set_time_limit(300); $feedDAO = FreshRSS_Factory::createFeedDao(); $entryDAO = FreshRSS_Factory::createEntryDao(); Minz_Session::_param('actualize_feeds', false); - $id = Minz_Request::param ('id'); - $force = Minz_Request::param ('force', false); + $id = Minz_Request::param('id'); + $force = Minz_Request::param('force', false); // on créé la liste des flux à mettre à actualiser // si on veut mettre un flux à jour spécifiquement, on le met // dans la liste, mais seul (permet d'automatiser le traitement) - $feeds = array (); + $feeds = array(); if ($id) { - $feed = $feedDAO->searchById ($id); + $feed = $feedDAO->searchById($id); if ($feed) { - $feeds = array ($feed); + $feeds = array($feed); } } else { $feeds = $feedDAO->listFeedsOrderUpdate($this->view->conf->ttl_default); @@ -243,7 +251,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { // on calcule la date des articles les plus anciens qu'on accepte $nb_month_old = max($this->view->conf->old_entries, 1); - $date_min = time () - (3600 * 24 * 30 * $nb_month_old); + $date_min = time() - (3600 * 24 * 30 * $nb_month_old); $i = 0; $flux_update = 0; @@ -263,7 +271,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if (count($entries) > 0) { //For this feed, check last n entry GUIDs already in database - $existingGuids = array_fill_keys ($entryDAO->listLastGuidsByFeed ($feed->id (), count($entries) + 10), 1); + $existingGuids = array_fill_keys( + $entryDAO->listLastGuidsByFeed($feed->id(), + count($entries) + 10), 1); $useDeclaredDate = empty($existingGuids); if ($feedHistory == -2) { //default @@ -295,14 +305,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if (!$hasTransaction) { $feedDAO->beginTransaction(); } - $nb = $feedDAO->cleanOldEntries ($feed->id (), $date_min, max($feedHistory, count($entries) + 10)); + $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->url() . ']', Minz_Log::DEBUG); + Minz_Log::record($nb . ' old entries cleaned in feed [' . $feed->url() . ']', Minz_Log::DEBUG); } } // on indique que le flux vient d'être mis à jour en BDD - $feedDAO->updateLastUpdate ($feed->id (), 0, $hasTransaction); + $feedDAO->updateLastUpdate($feed->id(), 0, $hasTransaction); if ($hasTransaction) { $feedDAO->commit(); } @@ -312,8 +322,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $feedDAO->updateFeed($feed->id(), array('url' => $feed->url())); } } catch (FreshRSS_Feed_Exception $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); - $feedDAO->updateLastUpdate ($feed->id (), 1); + Minz_Log::record($e->getMessage(), Minz_Log::NOTICE); + $feedDAO->updateLastUpdate($feed->id(), 1); } $feed->faviconPrepare(); @@ -328,23 +338,23 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } - $url = array (); + $url = array(); if ($flux_update === 1) { // on a mis un seul flux à jour - $feed = reset ($feeds); - $notif = array ( + $feed = reset($feeds); + $notif = array( 'type' => 'good', - 'content' => _t('feed_actualized', $feed->name ()) + 'content' => _t('feed_actualized', $feed->name()) ); } elseif ($flux_update > 1) { // plusieurs flux on été mis à jour - $notif = array ( + $notif = array( 'type' => 'good', 'content' => _t('n_feeds_actualized', $flux_update) ); } else { // aucun flux n'a été mis à jour, oups - $notif = array ( + $notif = array( 'type' => 'good', 'content' => _t('no_feed_to_refresh') ); @@ -353,26 +363,26 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ($i === 1) { // Si on a voulu mettre à jour qu'un flux // on filtre l'affichage par ce flux - $feed = reset ($feeds); - $url['params'] = array ('get' => 'f_' . $feed->id ()); + $feed = reset($feeds); + $url['params'] = array('get' => 'f_' . $feed->id()); } - if (Minz_Request::param ('ajax', 0) === 0) { - Minz_Session::_param ('notification', $notif); - Minz_Request::forward ($url, true); + if (Minz_Request::param('ajax', 0) === 0) { + Minz_Session::_param('notification', $notif); + Minz_Request::forward($url, true); } else { // Une requête Ajax met un seul flux à jour. // Comme en principe plusieurs requêtes ont lieu, // on indique que "plusieurs flux ont été mis à jour". // Cela permet d'avoir une notification plus proche du // ressenti utilisateur - $notif = array ( + $notif = array( 'type' => 'good', 'content' => _t('feeds_actualized') ); - Minz_Session::_param ('notification', $notif); + Minz_Session::_param('notification', $notif); // et on désactive le layout car ne sert à rien - $this->view->_useLayout (false); + $this->view->_useLayout(false); } } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 346739523..73638acb3 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -3,18 +3,18 @@ class FreshRSS_index_Controller extends Minz_ActionController { private $nb_not_read_cat = 0; - public function indexAction () { - $output = Minz_Request::param ('output'); + public function indexAction() { + $output = Minz_Request::param('output'); $token = $this->view->conf->token; // check if user is logged in if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous()) { - $token_param = Minz_Request::param ('token', ''); + $token_param = Minz_Request::param('token', ''); $token_is_ok = ($token != '' && $token === $token_param); if ($output === 'rss' && !$token_is_ok) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (_t('access_denied'))) + array('error' => array(_t('access_denied'))) ); return; } elseif ($output !== 'rss') { @@ -25,12 +25,12 @@ class FreshRSS_index_Controller extends Minz_ActionController { } } - $params = Minz_Request::params (); - if (isset ($params['search'])) { - $params['search'] = urlencode ($params['search']); + $params = Minz_Request::params(); + if (isset($params['search'])) { + $params['search'] = urlencode($params['search']); } - $this->view->url = array ( + $this->view->url = array( 'c' => 'index', 'a' => 'index', 'params' => $params @@ -38,31 +38,31 @@ class FreshRSS_index_Controller extends Minz_ActionController { if ($output === 'rss') { // no layout for RSS output - $this->view->_useLayout (false); + $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'))); + Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } $catDAO = new FreshRSS_CategoryDAO(); $entryDAO = FreshRSS_Factory::createEntryDao(); - $this->view->cat_aside = $catDAO->listCategories (); - $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); + $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 = ''; $this->view->get_c = ''; $this->view->get_f = ''; - $get = Minz_Request::param ('get', 'a'); + $get = Minz_Request::param('get', 'a'); $getType = $get[0]; - $getId = substr ($get, 2); - if (!$this->checkAndProcessType ($getType, $getId)) { - Minz_Log::record ('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG); - Minz_Error::error ( + $getId = substr($get, 2); + if (!$this->checkAndProcessType($getType, $getId)) { + Minz_Log::record('Not found [' . $getType . '][' . $getId . ']', Minz_Log::DEBUG); + Minz_Error::error( 404, - array ('error' => array (_t('page_not_found'))) + array('error' => array(_t('page_not_found'))) ); return; } @@ -77,11 +77,11 @@ class FreshRSS_index_Controller extends Minz_ActionController { // On récupère les différents éléments de filtrage $this->view->state = Minz_Request::param('state', $this->view->conf->default_view); - $state_param = Minz_Request::param ('state', null); - $filter = Minz_Request::param ('search', ''); - $this->view->order = $order = Minz_Request::param ('order', $this->view->conf->sort_order); - $nb = Minz_Request::param ('nb', $this->view->conf->posts_per_page); - $first = Minz_Request::param ('next', ''); + $state_param = Minz_Request::param('state', null); + $filter = Minz_Request::param('search', ''); + $this->view->order = $order = Minz_Request::param('order', $this->view->conf->sort_order); + $nb = Minz_Request::param('nb', $this->view->conf->posts_per_page); + $first = Minz_Request::param('next', ''); $ajax_request = Minz_Request::param('ajax', false); if ($output === 'reader') { @@ -90,23 +90,24 @@ class FreshRSS_index_Controller extends Minz_ActionController { 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; + 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; @@ -142,10 +143,10 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->entries = $entries; } catch (FreshRSS_EntriesGetter_Exception $e) { - Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE); - Minz_Error::error ( + Minz_Log::record($e->getMessage(), Minz_Log::NOTICE); + Minz_Error::error( 404, - array ('error' => array (_t('page_not_found'))) + array('error' => array(_t('page_not_found'))) ); } } @@ -155,98 +156,98 @@ class FreshRSS_index_Controller extends Minz_ActionController { * + Initialise correctement les variables de vue get_c et get_f * + Met à jour la variable $this->nb_not_read_cat */ - private function checkAndProcessType ($getType, $getId) { - switch ($getType) { - case 'a': - $this->view->currentName = _t('your_rss_feeds'); - $this->nb_not_read_cat = $this->view->nb_not_read; - $this->view->get_c = $getType; + private function checkAndProcessType($getType, $getId) { + switch($getType) { + case 'a': + $this->view->currentName = _t('your_rss_feeds'); + $this->nb_not_read_cat = $this->view->nb_not_read; + $this->view->get_c = $getType; + return true; + case 's': + $this->view->currentName = _t('your_favorites'); + $this->nb_not_read_cat = $this->view->nb_favorites['unread']; + $this->view->get_c = $getType; + return true; + case 'c': + $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null; + if ($cat === null) { + $catDAO = new FreshRSS_CategoryDAO(); + $cat = $catDAO->searchById($getId); + } + if ($cat) { + $this->view->currentName = $cat->name(); + $this->nb_not_read_cat = $cat->nbNotRead(); + $this->view->get_c = $getId; return true; - case 's': - $this->view->currentName = _t('your_favorites'); - $this->nb_not_read_cat = $this->view->nb_favorites['unread']; - $this->view->get_c = $getType; + } else { + return false; + } + case 'f': + $feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId); + if (empty($feed)) { + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feed = $feedDAO->searchById($getId); + } + if ($feed) { + $this->view->currentName = $feed->name(); + $this->nb_not_read_cat = $feed->nbNotRead(); + $this->view->get_f = $getId; + $this->view->get_c = $feed->category(); return true; - case 'c': - $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null; - if ($cat === null) { - $catDAO = new FreshRSS_CategoryDAO(); - $cat = $catDAO->searchById($getId); - } - if ($cat) { - $this->view->currentName = $cat->name (); - $this->nb_not_read_cat = $cat->nbNotRead (); - $this->view->get_c = $getId; - return true; - } else { - return false; - } - case 'f': - $feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId); - if (empty($feed)) { - $feedDAO = FreshRSS_Factory::createFeedDao(); - $feed = $feedDAO->searchById($getId); - } - if ($feed) { - $this->view->currentName = $feed->name (); - $this->nb_not_read_cat = $feed->nbNotRead (); - $this->view->get_f = $getId; - $this->view->get_c = $feed->category (); - return true; - } else { - return false; - } - default: + } else { return false; + } + default: + return false; } } - public function aboutAction () { - Minz_View::prependTitle (_t('about') . ' · '); + public function aboutAction() { + Minz_View::prependTitle(_t('about') . ' · '); } - public function logsAction () { + public function logsAction() { if (!$this->view->loginOk) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (_t('access_denied'))) + array('error' => array(_t('access_denied'))) ); } - Minz_View::prependTitle (_t('logs') . ' · '); + Minz_View::prependTitle(_t('logs') . ' · '); - if (Minz_Request::isPost ()) { + if (Minz_Request::isPost()) { FreshRSS_LogDAO::truncate(); } $logs = FreshRSS_LogDAO::lines(); //TODO: ask only the necessary lines //gestion pagination - $page = Minz_Request::param ('page', 1); - $this->view->logsPaginator = new Minz_Paginator ($logs); - $this->view->logsPaginator->_nbItemsPerPage (50); - $this->view->logsPaginator->_currentPage ($page); + $page = Minz_Request::param('page', 1); + $this->view->logsPaginator = new Minz_Paginator($logs); + $this->view->logsPaginator->_nbItemsPerPage(50); + $this->view->logsPaginator->_currentPage($page); } - public function loginAction () { - $this->view->_useLayout (false); + public function loginAction() { + $this->view->_useLayout(false); $url = 'https://verifier.login.persona.org/verify'; - $assert = Minz_Request::param ('assertion'); + $assert = Minz_Request::param('assertion'); $params = 'assertion=' . $assert . '&audience=' . - urlencode (Minz_Url::display (null, 'php', true)); - $ch = curl_init (); - $options = array ( + urlencode(Minz_Url::display(null, 'php', true)); + $ch = curl_init(); + $options = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params ); - curl_setopt_array ($ch, $options); - $result = curl_exec ($ch); - curl_close ($ch); + curl_setopt_array($ch, $options); + $result = curl_exec($ch); + curl_close($ch); - $res = json_decode ($result, true); + $res = json_decode($result, true); $loginOk = false; $reason = ''; @@ -273,21 +274,21 @@ class FreshRSS_index_Controller extends Minz_ActionController { } if ($loginOk) { Minz_Session::_param('currentUser', $currentUser); - Minz_Session::_param ('mail', $email); + Minz_Session::_param('mail', $email); $this->view->loginOk = true; invalidateHttpCache(); } else { - $res = array (); + $res = array(); $res['status'] = 'failure'; $res['reason'] = $reason == '' ? _t('invalid_login') : $reason; - Minz_Log::record ('Persona: ' . $res['reason'], Minz_Log::WARNING); + Minz_Log::record('Persona: ' . $res['reason'], Minz_Log::WARNING); } header('Content-Type: application/json; charset=UTF-8'); - $this->view->res = json_encode ($res); + $this->view->res = json_encode($res); } - public function logoutAction () { + public function logoutAction() { $this->view->_useLayout(false); invalidateHttpCache(); Minz_Session::_param('currentUser'); @@ -330,7 +331,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { } } - public function formLoginAction () { + public function formLoginAction() { if ($this->view->loginOk) { Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true); } @@ -401,15 +402,15 @@ class FreshRSS_index_Controller extends Minz_ActionController { } Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true); } elseif (!Minz_Configuration::canLogIn()) { - Minz_Error::error ( + Minz_Error::error( 403, - array ('error' => array (_t('access_denied'))) + array('error' => array(_t('access_denied'))) ); } invalidateHttpCache(); } - public function formLogoutAction () { + public function formLogoutAction() { $this->view->_useLayout(false); invalidateHttpCache(); Minz_Session::_param('currentUser'); diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index 67148350f..2a0dbd3d9 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -1,11 +1,11 @@ view->_useLayout (false); + public function firstAction() { + $this->view->_useLayout(false); } - public function actualizeAction () { + public function actualizeAction() { header('Content-Type: text/javascript; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); $this->view->feeds = $feedDAO->listFeedsOrderUpdate($this->view->conf->ttl_default); diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 4adb5e75d..99c57c809 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -99,7 +99,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController { $categoryDAO = new FreshRSS_CategoryDAO(); $feedDAO = FreshRSS_Factory::createFeedDao(); Minz_View::appendScript(Minz_Url::display('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js'))); - $id = Minz_Request::param ('id', null); + $id = Minz_Request::param('id', null); $this->view->categories = $categoryDAO->listCategories(); $this->view->feed = $feedDAO->searchById($id); $this->view->days = $statsDAO->getDays(); -- cgit v1.2.3 From f5a95d383c056fddd86e34024cba3444b527730d Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 5 Oct 2014 21:16:06 +0200 Subject: Coding style errorController --- app/Controllers/errorController.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'app/Controllers/errorController.php') diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 36312b56c..bb3431c2b 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -23,13 +23,13 @@ class FreshRSS_error_Controller extends Minz_ActionController { $this->view->errorMessage = trim(implode($errors)); if ($this->view->errorMessage == '') { switch(Minz_Request::param('code')) { - case 403: - $this->view->errorMessage = _t('forbidden_access'); - break; - case 404: - default: - $this->view->errorMessage = _t('page_not_found'); - break; + case 403: + $this->view->errorMessage = _t('forbidden_access'); + break; + case 404: + default: + $this->view->errorMessage = _t('page_not_found'); + break; } } -- cgit v1.2.3 From 34151ea1ae2107d4b5d96cefe8f4b2dc1ae3b70f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 6 Oct 2014 13:12:36 +0200 Subject: Add comments in error and importExport controllers See https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/Controllers/errorController.php | 17 +++- app/Controllers/importExportController.php | 149 ++++++++++++++++++++++++----- 2 files changed, 140 insertions(+), 26 deletions(-) (limited to 'app/Controllers/errorController.php') diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index bb3431c2b..76ab930e0 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -1,8 +1,21 @@ view->code = 'Error 403 - Forbidden'; break; @@ -22,7 +35,7 @@ class FreshRSS_error_Controller extends Minz_ActionController { $errors = Minz_Request::param('logs', array()); $this->view->errorMessage = trim(implode($errors)); if ($this->view->errorMessage == '') { - switch(Minz_Request::param('code')) { + switch($code_int) { case 403: $this->view->errorMessage = _t('forbidden_access'); break; diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index f329766b8..57759f277 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -1,6 +1,14 @@ view->loginOk) { Minz_Error::error( @@ -16,13 +24,23 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->feedDAO = FreshRSS_Factory::createFeedDao(); } + /** + * This action displays the main page for import / export system. + */ public function indexAction() { - $this->view->categories = $this->catDAO->listCategories(); $this->view->feeds = $this->feedDAO->listFeeds(); - Minz_View::prependTitle(_t('import_export') . ' · '); } + /** + * This action handles import action. + * + * It must be reached by a POST request. + * + * Parameter is: + * - file (default: nothing!) + * Available file types are: zip, json or xml. + */ public function importAction() { if (!Minz_Request::isPost()) { Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); @@ -92,10 +110,10 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $error = $this->importOpml($opml_file); } foreach ($list_files['json_starred'] as $article_file) { - $error = $this->importArticles($article_file, true); + $error = $this->importJson($article_file, true); } foreach ($list_files['json_feed'] as $article_file) { - $error = $this->importArticles($article_file); + $error = $this->importJson($article_file); } // And finally, we get import status and redirect to the home page @@ -105,11 +123,15 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { Minz_Request::good($content_notif); } + /** + * This method tries to guess the file type based on its name. + * + * Itis a *very* basic guess file type function. Only based on filename. + * That's could be improved but should be enough for what we have to do. + * + * @todo move into lib_rss.php + */ private function guessFileType($filename) { - // A *very* basic guess file type function. Only based on filename - // That's could be improved but should be enough, at least for a first - // implementation. - if (substr_compare($filename, '.zip', -4) === 0) { return 'zip'; } elseif (substr_compare($filename, '.opml', -5) === 0 || @@ -125,6 +147,12 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } } + /** + * This method parses and imports an OPML file. + * + * @param string $opml_file the OPML file content. + * @return boolean true if an error occured, false else. + */ private function importOpml($opml_file) { $opml_array = array(); try { @@ -139,13 +167,22 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $this->addOpmlElements($opml_array['body']); } + /** + * This method imports an OPML file based on its body. + * + * @param array $opml_elements an OPML element (body or outline). + * @param string $parent_cat the name of the parent category. + * @return boolean true if an error occured, false else. + */ private function addOpmlElements($opml_elements, $parent_cat = null) { $error = false; foreach ($opml_elements as $elt) { $res = false; if (isset($elt['xmlUrl'])) { + // If xmlUrl exists, it means it is a feed $res = $this->addFeedOpml($elt, $parent_cat); } else { + // No xmlUrl? It should be a category! $res = $this->addCategoryOpml($elt, $parent_cat); } @@ -158,6 +195,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $error; } + /** + * This method imports an OPML feed element. + * + * @param array $feed_elt an OPML element (must be a feed element). + * @param string $parent_cat the name of the parent category. + * @return boolean true if an error occured, false else. + */ private function addFeedOpml($feed_elt, $parent_cat) { if (is_null($parent_cat)) { // This feed has no parent category so we get the default one @@ -165,8 +209,9 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } $cat = $this->catDAO->searchByName($parent_cat); - if (!$cat) { + // If there is not $cat, it means parent category does not exist in + // database. It should not happened! return true; } @@ -203,6 +248,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $error; } + /** + * This method imports an OPML category element. + * + * @param array $cat_elt an OPML element (must be a category element). + * @param string $parent_cat the name of the parent category. + * @return boolean true if an error occured, false else. + */ private function addCategoryOpml($cat_elt, $parent_cat) { // Create a new Category object $cat = new FreshRSS_Category(Minz_Helper::htmlspecialchars_utf8($cat_elt['text'])); @@ -223,7 +275,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $error; } - private function importArticles($article_file, $starred = false) { + /** + * This method import a JSON-based file (Google Reader format). + * + * @param string $article_file the JSON file content. + * @param boolean $starred true if articles from the file must be starred. + * @return boolean true if an error occured, false else. + */ + private function importJson($article_file, $starred = false) { $article_object = json_decode($article_file, true); if (is_null($article_object)) { Minz_Log::warning('Try to import a non-JSON file'); @@ -232,16 +291,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $is_read = $this->view->conf->mark_when['reception'] ? 1 : 0; - $google_compliant = ( - strpos($article_object['id'], 'com.google') !== false - ); + $google_compliant = strpos($article_object['id'], 'com.google') !== false; $error = false; $article_to_feed = array(); // First, we check feeds of articles are in DB (and add them if needed). foreach ($article_object['items'] as $item) { - $feed = $this->addFeedArticles($item['origin'], $google_compliant); + $feed = $this->addFeedJson($item['origin'], $google_compliant); if (is_null($feed)) { $error = true; } else { @@ -254,6 +311,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->entryDAO->beginTransaction(); foreach ($article_object['items'] as $item) { if (!isset($article_to_feed[$item['id']])) { + // Related feed does not exist for this entry, do nothing. continue; } @@ -263,6 +321,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { 'summary' : 'content'; $tags = $item['categories']; if ($google_compliant) { + // Remove tags containing "/state/com.google" which are useless. $tags = array_filter($tags, function($var) { return strpos($var, '/state/com.google') === false; }); @@ -288,7 +347,15 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $error; } - private function addFeedArticles($origin, $google_compliant) { + /** + * This method import a JSON-based feed (Google Reader format). + * + * @param array $origin represents a feed. + * @param boolean $google_compliant takes care of some specific values if true. + * @return FreshRSS_Feed if feed is in database at the end of the process, + * else null. + */ + private function addFeedJson($origin, $google_compliant) { $default_cat = $this->catDAO->getDefault(); $return = null; @@ -298,14 +365,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $website = $origin['htmlUrl']; try { - // Create a Feed object and add it in DB + // Create a Feed object and add it in database. $feed = new FreshRSS_Feed($url); $feed->_category($default_cat->id()); $feed->_name($name); $feed->_website($website); // addFeedObject checks if feed is already in DB so nothing else to - // check here + // check here. $id = $this->feedDAO->addFeedObject($feed); if ($id !== false) { @@ -319,6 +386,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $return; } + /** + * This action handles export action. + * + * This action must be reached by a POST request. + * + * Parameters are: + * - export_opml (default: false) + * - export_starred (default: false) + * - export_feeds (default: array()) a list of feed ids + */ public function exportAction() { if (!Minz_Request::isPost()) { Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); @@ -336,7 +413,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { } if ($export_starred) { - $export_files['starred.json'] = $this->generateArticles('starred'); + $export_files['starred.json'] = $this->generateEntries('starred'); } foreach ($export_feeds as $feed_id) { @@ -344,9 +421,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { if ($feed) { $filename = 'feed_' . $feed->category() . '_' . $feed->id() . '.json'; - $export_files[$filename] = $this->generateArticles( - 'feed', $feed - ); + $export_files[$filename] = $this->generateEntries('feed', $feed); } } @@ -366,10 +441,16 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $type = $this->guessFileType($filename); $this->exportFile('freshrss_' . $filename, $export_files[$filename], $type); } else { + // Nothing to do... Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true); } } + /** + * This method returns the OPML file based on user subscriptions. + * + * @return string the OPML file content. + */ private function generateOpml() { $list = array(); foreach ($this->catDAO->listCategories() as $key => $cat) { @@ -381,7 +462,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $this->view->helperToString('export/opml'); } - private function generateArticles($type, $feed = NULL) { + /** + * This method returns a JSON file content. + * + * @param string $type must be "starred" or "feed" + * @param FreshRSS_Feed $feed feed of which we want to get entries. + * @return string the JSON file content. + */ + private function generateEntries($type, $feed = NULL) { $this->view->categories = $this->catDAO->listCategories(); if ($type == 'starred') { @@ -389,8 +477,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { $this->view->type = 'starred'; $unread_fav = $this->entryDAO->countUnreadReadFavorites(); $this->view->entries = $this->entryDAO->listWhere( - 's', '', FreshRSS_Entry::STATE_ALL, 'ASC', - $unread_fav['all'] + 's', '', FreshRSS_Entry::STATE_ALL, 'ASC', $unread_fav['all'] ); } elseif ($type == 'feed' && !is_null($feed)) { $this->view->list_title = _t('feed_list', $feed->name()); @@ -405,6 +492,12 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { return $this->view->helperToString('export/articles'); } + /** + * This method zips a list of files and returns it by HTTP. + * + * @param array $files list of files where key is filename and value the content. + * @throws Exception if Zip extension is not loaded. + */ private function exportZip($files) { if (!extension_loaded('zip')) { throw new Exception(); @@ -428,6 +521,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController { unlink($zip_file); } + /** + * This method returns a single file (OPML or JSON) by HTTP. + * + * @param string $filename + * @param string $content + * @param string $type the file type (opml, json_feed or json_starred). + * If equals to unknown, nothing happens. + */ private function exportFile($filename, $content, $type) { if ($type === 'unknown') { return; -- cgit v1.2.3 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 +++++++++++++++----- app/layout/nav_menu.phtml | 2 +- app/views/helpers/view/global_view.phtml | 53 -------------------------------- app/views/index/global.phtml | 46 +++++++++++++++++++++++++++ app/views/index/index.phtml | 2 -- lib/lib_rss.php | 4 +++ p/scripts/global_view.js | 3 +- 8 files changed, 79 insertions(+), 66 deletions(-) delete mode 100644 app/views/helpers/view/global_view.phtml create mode 100644 app/views/index/global.phtml (limited to 'app/Controllers/errorController.php') 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') . ' · '); diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index bb9468ab1..1a26422df 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -240,7 +240,7 @@ - + diff --git a/app/views/helpers/view/global_view.phtml b/app/views/helpers/view/global_view.phtml deleted file mode 100644 index ae8af820d..000000000 --- a/app/views/helpers/view/global_view.phtml +++ /dev/null @@ -1,53 +0,0 @@ -partial('nav_menu'); ?> - -entries)) { ?> -
- 'index', 'a' => 'index', 'params' => array()); - if (FreshRSS_Context::$conf->view_mode !== 'normal') { - $arUrl['params']['output'] = 'normal'; - } - $p = Minz_Request::param('state', ''); - if (($p != '') && (FreshRSS_Context::$conf->default_view !== $p)) { - $arUrl['params']['state'] = $p; - } - - foreach ($this->cat_aside as $cat) { - $feeds = $cat->feeds(); - if (!empty($feeds)) { -?> -
- - -
- -
- -
-
display_posts ? '' : ' class="hide_posts"'; ?>> - -
- - -
-

-

-
- diff --git a/app/views/index/global.phtml b/app/views/index/global.phtml new file mode 100644 index 000000000..a72e431df --- /dev/null +++ b/app/views/index/global.phtml @@ -0,0 +1,46 @@ +partial('nav_menu'); ?> + +
+ 'index', + 'a' => 'index', + 'params' => array( + 'state' => FreshRSS_Context::$state + ) + ); + + foreach ($this->categories as $cat) { + $feeds = $cat->feeds(); + $url_base['params']['get'] = 'c_' . $cat->id(); + + if (!empty($feeds)) { +?> +
+ + +
    + nbNotRead(); + $error = $feed->inError() ? 'error ' : ''; + $empty = $feed->nbEntries() === 0 ? 'empty ' : ''; + $url_base['params']['get'] = 'f_' . $feed->id(); + ?> +
  • + ✇ + name(); ?> +
  • + +
+
+ +
+ +
+
display_posts ? '' : ' class="hide_posts"'; ?>> + +
diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index a59063557..8b93461dd 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -7,8 +7,6 @@ if (FreshRSS_Auth::hasAccess() || Minz_Configuration::allowAnonymous()) { $this->renderHelper('view/normal_view'); } elseif ($output === 'reader') { $this->renderHelper('view/reader_view'); - } elseif ($output === 'global') { - $this->renderHelper('view/global_view'); } elseif ($output === 'rss') { $this->renderHelper('view/rss_view'); } else { diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 9abdf18ce..80eb206d2 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -60,6 +60,10 @@ function formatNumber($n, $precision = 0) { return str_replace(' ', ' ', //Espace insécable //TODO: remplacer par une espace _fine_ insécable number_format($n, $precision, '.', ' ')); //number_format does not seem to be Unicode-compatible } +function format_number($n, $precision = 0) { + // TODO: coding style, prefer THIS function. Remove formatNumber. + return formatNumber($n, $precision); +} function formatBytes($bytes, $precision = 2, $system = 'IEC') { if ($system === 'IEC') { diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js index 6e1f61066..8c2e6c1a2 100644 --- a/p/scripts/global_view.js +++ b/p/scripts/global_view.js @@ -50,7 +50,8 @@ function init_close_panel() { } function init_global_view() { - $("#stream .box-category a").click(function () { + // TODO: should be based on generic classes. + $(".box a").click(function () { var link = $(this).attr("href"); load_panel(link); -- cgit v1.2.3