From 3411ec84f694c92d71f331a213c522e24448ee41 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 13 Feb 2006 22:15:56 +0000 Subject: 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 --- include/functions_html.inc.php | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'include/functions_html.inc.php') 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 = '(!)'; } - return $output; + + $page['get_icon_cache'][$date] = $output; + + return $page['get_icon_cache'][$date]; } function create_navigation_bar($url, $nb_element, $start, -- cgit v1.2.3