aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-02-13 22:15:56 +0000
committerplegall <plg@piwigo.org>2006-02-13 22:15:56 +0000
commit3411ec84f694c92d71f331a213c522e24448ee41 (patch)
tree982f3e516928fa0c55066ef57855e033cda0ec22
parent1e904aeca42262a56761ec43c0c458a8bc30b80e (diff)
merge -r1038:1039 from branches/branch-1_5 into trunk (bug 269 fixed)
improvement: use a cache on get_icon function since it's often used with the same argument on a page generation. git-svn-id: http://piwigo.org/svn/trunk@1040 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions_html.inc.php34
1 files changed, 28 insertions, 6 deletions
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index e23a2e3b2..d6bcdaf63 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -25,17 +25,36 @@
// | USA. |
// +-----------------------------------------------------------------------+
-function get_icon( $date )
+function get_icon($date)
{
- global $user, $conf, $lang;
+ global $page, $user, $conf, $lang;
- if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date))
+ if (empty($date))
{
- return '';
+ $date = 'NULL';
}
- list( $year,$month,$day ) = explode( '-', $date );
+ if (isset($page['get_icon_cache'][$date]))
+ {
+ return $page['get_icon_cache'][$date];
+ }
+
+ if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $matches))
+ {
+ // date can be empty, no icon to display
+ $page['get_icon_cache'][$date] = '';
+ return $page['get_icon_cache'][$date];
+ }
+
+ list($devnull, $year, $month, $day) = $matches;
$unixtime = mktime( 0, 0, 0, $month, $day, $year );
+
+ if ($unixtime === false // PHP 5.1.0 and above
+ or $unixtime === -1) // PHP prior to 5.1.0
+ {
+ $page['get_icon_cache'][$date] = '';
+ return $page['get_icon_cache'][$date];
+ }
$diff = time() - $unixtime;
$day_in_seconds = 24*60*60;
@@ -50,7 +69,10 @@ function get_icon( $date )
$output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;';
$output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
}
- return $output;
+
+ $page['get_icon_cache'][$date] = $output;
+
+ return $page['get_icon_cache'][$date];
}
function create_navigation_bar($url, $nb_element, $start,