A free, self-hostable news aggregator…
Refactor and formatting
Alexis Degrugillier60fe99344e1d
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.phpindex cbc67cac3..fb5609cb4 100644--- a/app/Controllers/statsController.php+++ b/app/Controllers/statsController.php@@ -2,70 +2,66 @@class FreshRSS_stats_Controller extends Minz_ActionController {- public function mainAction() {- $this->initAction();-- $statsDAO = new FreshRSS_StatsDAO ();+ public function indexAction() {+ $statsDAO = new FreshRSS_StatsDAO ();Minz_View::appendScript (Minz_Url::display ('/scripts/flotr2.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/flotr2.min.js')));$this->view->repartition = $statsDAO->calculateEntryRepartition();$this->view->count = ($statsDAO->calculateEntryCount());$this->view->feedByCategory = $statsDAO->calculateFeedByCategory();$this->view->entryByCategory = $statsDAO->calculateEntryByCategory();$this->view->topFeed = $statsDAO->calculateTopFeed();- }-- public function idleAction() {- $this->initAction();+ }- $statsDAO = new FreshRSS_StatsDAO ();- $feeds = $statsDAO->calculateFeedLastDate();- $idleFeeds = array();- $now = new \DateTime();- $feedDate = clone $now;- $lastWeek = clone $now;- $lastWeek->modify('-1 week');- $lastMonth = clone $now;- $lastMonth->modify('-1 month');- $last3Month = clone $now;- $last3Month->modify('-3 month');- $last6Month = clone $now;- $last6Month->modify('-6 month');- $lastYear = clone $now;- $lastYear->modify('-1 year');+ public function idleAction() {+ $statsDAO = new FreshRSS_StatsDAO ();+ $feeds = $statsDAO->calculateFeedLastDate();+ $idleFeeds = array();+ $now = new \DateTime();+ $feedDate = clone $now;+ $lastWeek = clone $now;+ $lastWeek->modify('-1 week');+ $lastMonth = clone $now;+ $lastMonth->modify('-1 month');+ $last3Month = clone $now;+ $last3Month->modify('-3 month');+ $last6Month = clone $now;+ $last6Month->modify('-6 month');+ $lastYear = clone $now;+ $lastYear->modify('-1 year');- foreach ($feeds as $feed) {- $feedDate->setTimestamp($feed['last_date']);- if ($feedDate >= $lastWeek) {- continue;- }- if ($feedDate < $lastWeek) {- $idleFeeds['last_week'][] = $feed['name'];- }- if ($feedDate < $lastMonth) {- $idleFeeds['last_month'][] = $feed['name'];- }- if ($feedDate < $last3Month) {- $idleFeeds['last_3_month'][] = $feed['name'];- }- if ($feedDate < $last6Month) {- $idleFeeds['last_6_month'][] = $feed['name'];- }- if ($feedDate < $lastYear) {- $idleFeeds['last_year'][] = $feed['name'];- }- }+ foreach ($feeds as $feed) {+ $feedDate->setTimestamp($feed['last_date']);+ if ($feedDate >= $lastWeek) {+ continue;+ }+ if ($feedDate < $lastWeek) {+ $idleFeeds['last_week'][] = $feed['name'];+ }+ if ($feedDate < $lastMonth) {+ $idleFeeds['last_month'][] = $feed['name'];+ }+ if ($feedDate < $last3Month) {+ $idleFeeds['last_3_month'][] = $feed['name'];+ }+ if ($feedDate < $last6Month) {+ $idleFeeds['last_6_month'][] = $feed['name'];+ }+ if ($feedDate < $lastYear) {+ $idleFeeds['last_year'][] = $feed['name'];+ }+ }- $this->view->idleFeeds = array_reverse($idleFeeds);- }+ $this->view->idleFeeds = array_reverse($idleFeeds);+ }- private function initAction() {+ public function firstAction() {if (!$this->view->loginOk) {- Minz_Error::error(- 403, array('error' => array(Minz_Translate::t('access_denied')))- );- }+ Minz_Error::error(+ 403, array('error' => array(Minz_Translate::t('access_denied')))+ );+ }- Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');+ Minz_View::prependTitle(Minz_Translate::t('stats') . ' · ');}}diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.phpindex f9f4740fd..eafe86407 100644--- a/app/Models/StatsDAO.php+++ b/app/Models/StatsDAO.php@@ -180,14 +180,14 @@ SQL;$stm->execute();return $stm->fetchAll(PDO::FETCH_ASSOC);}-- /**- * Calculates the last publication date for each feed- *- * @return array- */- public function calculateFeedLastDate() {- $sql = <<<SQL++ /**+ * Calculates the last publication date for each feed+ *+ * @return array+ */+ public function calculateFeedLastDate() {+ $sql = <<<SQLSELECT MAX(f.name) AS name, MAX(date) AS last_dateFROM {$this->prefix}feed AS f,@@ -196,10 +196,10 @@ WHERE f.id = e.id_feedGROUP BY f.idORDER BY nameSQL;- $stm = $this->bd->prepare($sql);- $stm->execute();- return $stm->fetchAll(PDO::FETCH_ASSOC);- }+ $stm = $this->bd->prepare($sql);+ $stm->execute();+ return $stm->fetchAll(PDO::FETCH_ASSOC);+ }private function convertToSerie($data) {$serie = array();diff --git a/app/i18n/en.php b/app/i18n/en.phpindex 8d5f305c0..19cf4a06d 100644--- a/app/i18n/en.php+++ b/app/i18n/en.php@@ -46,14 +46,14 @@ return array ('no_query_filter' => 'No filter','about' => 'About','stats' => 'Statistics',- 'stats_idle' => 'Idle feeds',- 'stats_main' => 'Main statistics',+ 'stats_idle' => 'Idle feeds',+ 'stats_main' => 'Main statistics',- 'last_week' => 'Last week',- 'last_month' => 'Last month',- 'last_3_month' => 'Last three months',- 'last_6_month' => 'Last six months',- 'last_year' => 'Last year',+ 'last_week' => 'Last week',+ 'last_month' => 'Last month',+ 'last_3_month' => 'Last three months',+ 'last_6_month' => 'Last six months',+ 'last_year' => 'Last year','your_rss_feeds' => 'Your RSS feeds','add_rss_feed' => 'Add a RSS feed',diff --git a/app/i18n/fr.php b/app/i18n/fr.phpindex 3441425df..54fe55ea0 100644--- a/app/i18n/fr.php+++ b/app/i18n/fr.php@@ -46,14 +46,14 @@ return array ('no_query_filter' => 'Aucun filtre appliqué','about' => 'À propos','stats' => 'Statistiques',- 'stats_idle' => 'Flux inactifs',- 'stats_main' => 'Statistiques principales',+ 'stats_idle' => 'Flux inactifs',+ 'stats_main' => 'Statistiques principales',- 'last_week' => 'La dernière semaine',- 'last_month' => 'Le dernier mois',- 'last_3_month' => 'Les derniers trois mois',- 'last_6_month' => 'Les derniers six mois',- 'last_year' => 'La dernière année',+ 'last_week' => 'La dernière semaine',+ 'last_month' => 'Le dernier mois',+ 'last_3_month' => 'Les derniers trois mois',+ 'last_6_month' => 'Les derniers six mois',+ 'last_year' => 'La dernière année','your_rss_feeds' => 'Vos flux RSS','add_rss_feed' => 'Ajouter un flux RSS',diff --git a/app/layout/aside_stats.phtml b/app/layout/aside_stats.phtmlindex bc1e85592..32a3f5dee 100644--- a/app/layout/aside_stats.phtml+++ b/app/layout/aside_stats.phtml@@ -1,7 +1,7 @@<ul class="nav nav-list aside"><li class="nav-header"><?php echo Minz_Translate::t ('stats'); ?></li>- <li class="item<?php echo Minz_Request::actionName () == 'main' ? ' active' : ''; ?>">- <a href="<?php echo _url ('stats', 'main'); ?>"><?php echo Minz_Translate::t ('stats_main'); ?></a>+ <li class="item<?php echo Minz_Request::actionName () == 'index' ? ' active' : ''; ?>">+ <a href="<?php echo _url ('stats', 'index'); ?>"><?php echo Minz_Translate::t ('stats_main'); ?></a></li><li class="item<?php echo Minz_Request::actionName () == 'idle' ? ' active' : ''; ?>"><a href="<?php echo _url ('stats', 'idle'); ?>"><?php echo Minz_Translate::t ('stats_idle'); ?></a>diff --git a/app/layout/header.phtml b/app/layout/header.phtmlindex 3be3e496d..46e248ac8 100644--- a/app/layout/header.phtml+++ b/app/layout/header.phtml@@ -76,7 +76,7 @@ if (Minz_Configuration::canLogIn()) {<li class="separator"></li><li class="item"><a href="<?php echo _url ('configure', 'users'); ?>"><?php echo Minz_Translate::t ('users'); ?></a></li><li class="separator"></li>- <li class="item"><a href="<?php echo _url ('stats', 'main'); ?>"><?php echo Minz_Translate::t ('stats'); ?></a></li>+ <li class="item"><a href="<?php echo _url ('stats', 'index'); ?>"><?php echo Minz_Translate::t ('stats'); ?></a></li><li class="item"><a href="<?php echo _url ('index', 'logs'); ?>"><?php echo Minz_Translate::t ('logs'); ?></a></li><li class="item"><a href="<?php echo _url ('index', 'about'); ?>"><?php echo Minz_Translate::t ('about'); ?></a></li><?phpdiff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtmlindex 26806bb0e..3ea70624a 100644--- a/app/views/stats/idle.phtml+++ b/app/views/stats/idle.phtml@@ -1,19 +1,19 @@<?php $this->partial('aside_stats'); ?><div class="post content">- <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Minz_Translate::t ('back_to_rss_feeds'); ?></a>-- <h1><?php echo Minz_Translate::t ('stats_idle'); ?></h1>-- <?php foreach ($this->idleFeeds as $period => $feeds){ ?>- <div class="stat">- <h2><?php echo Minz_Translate::t ($period); ?></h2>+ <a href="<?php echo _url ('index', 'index'); ?>"><?php echo _t ('back_to_rss_feeds'); ?></a>++ <h1><?php echo _t ('stats_idle'); ?></h1>++ <?php foreach ($this->idleFeeds as $period => $feeds){ ?>+ <div class="stat">+ <h2><?php echo _t ($period); ?></h2>- <ul>- <?php foreach ($feeds as $feed){ ?>- <li><?php echo $feed; ?></li>+ <ul>+ <?php foreach ($feeds as $feed){ ?>+ <li><?php echo $feed; ?></li><?php } ?>- </ul>- </div>+ </ul>+ </div><?php } ?></div>diff --git a/app/views/stats/main.phtml b/app/views/stats/index.phtmlsimilarity index 76%rename from app/views/stats/main.phtmlrename to app/views/stats/index.phtmlindex fe372e221..a48181fe4 100644--- a/app/views/stats/main.phtml+++ b/app/views/stats/index.phtml@@ -1,38 +1,38 @@<?php $this->partial('aside_stats'); ?><div class="post content">- <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Minz_Translate::t ('back_to_rss_feeds'); ?></a>-- <h1><?php echo Minz_Translate::t ('stats_main'); ?></h1>+ <a href="<?php echo _url ('index', 'index'); ?>"><?php echo _t ('back_to_rss_feeds'); ?></a>++ <h1><?php echo _t ('stats_main'); ?></h1>- <div class="stat">- <h2><?php echo Minz_Translate::t ('stats_entry_repartition'); ?></h2>+ <div class="stat">+ <h2><?php echo _t ('stats_entry_repartition'); ?></h2><table><thead><tr><th> </th>- <th><?php echo Minz_Translate::t ('main_stream'); ?></th>- <th><?php echo Minz_Translate::t ('all_feeds'); ?></th>+ <th><?php echo _t ('main_stream'); ?></th>+ <th><?php echo _t ('all_feeds'); ?></th></tr></thead><tbody><tr>- <th><?php echo Minz_Translate::t ('status_total'); ?></th>+ <th><?php echo _t ('status_total'); ?></th><td class="numeric"><?php echo formatNumber($this->repartition['main_stream']['total']); ?></td><td class="numeric"><?php echo formatNumber($this->repartition['all_feeds']['total']); ?></td></tr><tr>- <th><?php echo Minz_Translate::t ('status_read'); ?></th>+ <th><?php echo _t ('status_read'); ?></th><td class="numeric"><?php echo formatNumber($this->repartition['main_stream']['read']); ?></td><td class="numeric"><?php echo formatNumber($this->repartition['all_feeds']['read']); ?></td></tr><tr>- <th><?php echo Minz_Translate::t ('status_unread'); ?></th>+ <th><?php echo _t ('status_unread'); ?></th><td class="numeric"><?php echo formatNumber($this->repartition['main_stream']['unread']); ?></td><td class="numeric"><?php echo formatNumber($this->repartition['all_feeds']['unread']); ?></td></tr><tr>- <th><?php echo Minz_Translate::t ('status_favorites'); ?></th>+ <th><?php echo _t ('status_favorites'); ?></th><td class="numeric"><?php echo formatNumber($this->repartition['main_stream']['favorite']); ?></td><td class="numeric"><?php echo formatNumber($this->repartition['all_feeds']['favorite']); ?></td></tr>@@ -41,30 +41,30 @@</div><div class="stat">- <h2><?php echo Minz_Translate::t ('stats_entry_per_day'); ?></h2>+ <h2><?php echo _t ('stats_entry_per_day'); ?></h2><div id="statsEntryPerDay" style="height: 300px"></div></div><div class="stat">- <h2><?php echo Minz_Translate::t ('stats_feed_per_category'); ?></h2>+ <h2><?php echo _t ('stats_feed_per_category'); ?></h2><div id="statsFeedPerCategory" style="height: 300px"></div><div id="statsFeedPerCategoryLegend"></div></div><div class="stat">- <h2><?php echo Minz_Translate::t ('stats_entry_per_category'); ?></h2>+ <h2><?php echo _t ('stats_entry_per_category'); ?></h2><div id="statsEntryPerCategory" style="height: 300px"></div><div id="statsEntryPerCategoryLegend"></div></div><div class="stat">- <h2><?php echo Minz_Translate::t ('stats_top_feed'); ?></h2>+ <h2><?php echo _t ('stats_top_feed'); ?></h2><table><thead><tr>- <th><?php echo Minz_Translate::t ('feed'); ?></th>- <th><?php echo Minz_Translate::t ('category'); ?></th>- <th><?php echo Minz_Translate::t ('stats_entry_count'); ?></th>+ <th><?php echo _t ('feed'); ?></th>+ <th><?php echo _t ('category'); ?></th>+ <th><?php echo _t ('stats_entry_count'); ?></th></tr></thead><tbody>