A free, self-hostable news aggregator…
PHP : performances fonction isDay
Alexandre Alapetite847de9b3292a
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.phpindex cc474302e..22c5683ea 100755--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@ -125,6 +125,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {}$today = @strtotime('today');+ $this->view->today = $today;// on calcule la date des articles les plus anciens qu'on affiche$nb_month_old = $this->view->conf->oldEntries ();diff --git a/app/Models/Entry.php b/app/Models/Entry.phpindex ba0fb48f4..983f94727 100644--- a/app/Models/Entry.php+++ b/app/Models/Entry.php@@ -134,21 +134,20 @@ class FreshRSS_Entry extends Minz_Model {$this->tags = $value;}- public function isDay ($day) {+ public function isDay ($day, $today) {$date = $this->dateAdded(true);- $today = @strtotime('today');- $yesterday = $today - 86400;-- if ($day === FreshRSS_Days::TODAY &&- $date >= $today && $date < $today + 86400) {- return true;- } elseif ($day === FreshRSS_Days::YESTERDAY &&- $date >= $yesterday && $date < $yesterday + 86400) {- return true;- } elseif ($day === FreshRSS_Days::BEFORE_YESTERDAY && $date < $yesterday) {- return true;- } else {- return false;+ switch ($day) {+ case FreshRSS_Days::TODAY:+ $tomorrow = $today + 86400;+ return $date >= $today && $date < $tomorrow;+ case FreshRSS_Days::YESTERDAY:+ $yesterday = $today - 86400;+ return $date >= $yesterday && $date < $today;+ case FreshRSS_Days::BEFORE_YESTERDAY:+ $yesterday = $today - 86400;+ return $date < $yesterday;+ default:+ return false;}}diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtmlindex 92a987aed..045f391f9 100644--- a/app/layout/nav_menu.phtml+++ b/app/layout/nav_menu.phtml@@ -72,7 +72,7 @@<li class="item"><a href="<?php echo $markReadUrl; ?>"><?php echo $string_mark; ?></a></li><li class="separator"></li><?php- $today = @strtotime('today');+ $today = $this->today;$one_week = $today - 604800;?><li class="item"><a href="<?php echo _url ('entry', 'read', 'is_read', 1, 'get', $get, 'idMax', $today . '000000'); ?>"><?php echo Minz_Translate::t ('before_one_day'); ?></a></li>diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtmlindex 094017957..d5328651d 100644--- a/app/views/helpers/view/normal_view.phtml+++ b/app/views/helpers/view/normal_view.phtml@@ -21,24 +21,25 @@ if (!empty($this->entries)) {$facebook = $this->conf->sharing ('facebook');$email = $this->conf->sharing ('email');$print = $this->conf->sharing ('print');+ $today = $this->today;?><?php foreach ($this->entries as $item) { ?>- <?php if ($display_today && $item->isDay (FreshRSS_Days::TODAY)) { ?>+ <?php if ($display_today && $item->isDay (FreshRSS_Days::TODAY, $today)) { ?><div class="day" id="day_today"><?php echo Minz_Translate::t ('today'); ?><span class="date"> - <?php echo timestamptodate (time (), false); ?></span><span class="name"><?php echo $this->currentName; ?></span></div><?php $display_today = false; } ?>- <?php if ($display_yesterday && $item->isDay (FreshRSS_Days::YESTERDAY)) { ?>+ <?php if ($display_yesterday && $item->isDay (FreshRSS_Days::YESTERDAY, $today)) { ?><div class="day" id="day_yesterday"><?php echo Minz_Translate::t ('yesterday'); ?><span class="date"> - <?php echo timestamptodate (time () - 86400, false); ?></span><span class="name"><?php echo $this->currentName; ?></span></div><?php $display_yesterday = false; } ?>- <?php if ($display_others && $item->isDay (FreshRSS_Days::BEFORE_YESTERDAY)) { ?>+ <?php if ($display_others && $item->isDay (FreshRSS_Days::BEFORE_YESTERDAY, $today)) { ?><div class="day" id="day_before_yesterday"><?php echo Minz_Translate::t ('before_yesterday'); ?><span class="name"><?php echo $this->currentName; ?></span>