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
This commit is contained in:
plegall
2006-02-13 22:15:56 +00:00
parent 1e904aeca4
commit 3411ec84f6
+28 -6
View File
@@ -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,