Skip to content

Commit

Permalink
merge -r1038:1039 from branches/branch-1_5 into trunk (bug 269 fixed)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
plegall committed Feb 13, 2006
1 parent 1e904ae commit 3411ec8
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions include/functions_html.inc.php
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 3411ec8

Please sign in to comment.