aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-16 00:54:13 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-16 00:54:13 +0100
commit847de9b3292ad854b281d7e12cc36ac93e745139 (patch)
tree65ce480d622fd983d36df9d6a60e0249de053a1a /app
parent529d6bcd15f7351cb7bdcf2f74c6a44930b0de55 (diff)
PHP : performances fonction isDay
Amélioration des performances de Entry->isDay()
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/indexController.php1
-rw-r--r--app/Models/Entry.php27
-rw-r--r--app/layout/nav_menu.phtml2
-rw-r--r--app/views/helpers/view/normal_view.phtml7
4 files changed, 19 insertions, 18 deletions
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 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.php
index 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.phtml
index 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.phtml
index 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>