Changeset 1040 for trunk


Ignore:
Timestamp:
Feb 13, 2006, 11:15:56 PM (18 years ago)
Author:
plg
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_html.inc.php

    r1036 r1040  
    2626// +-----------------------------------------------------------------------+
    2727
    28 function get_icon( $date )
    29 {
    30   global $user, $conf, $lang;
    31 
    32   if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date))
    33   {
    34     return '';
    35   }
    36 
    37   list( $year,$month,$day ) = explode( '-', $date );
     28function get_icon($date)
     29{
     30  global $page, $user, $conf, $lang;
     31
     32  if (empty($date))
     33  {
     34    $date = 'NULL';
     35  }
     36
     37  if (isset($page['get_icon_cache'][$date]))
     38  {
     39    return $page['get_icon_cache'][$date];
     40  }
     41
     42  if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $matches))
     43  {
     44    // date can be empty, no icon to display
     45    $page['get_icon_cache'][$date] = '';
     46    return $page['get_icon_cache'][$date];
     47  }
     48 
     49  list($devnull, $year, $month, $day) = $matches;
    3850  $unixtime = mktime( 0, 0, 0, $month, $day, $year );
     51
     52  if ($unixtime === false  // PHP 5.1.0 and above
     53      or $unixtime === -1) // PHP prior to 5.1.0
     54  {
     55    $page['get_icon_cache'][$date] = '';
     56    return $page['get_icon_cache'][$date];
     57  }
    3958 
    4059  $diff = time() - $unixtime;
     
    5170    $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
    5271  }
    53   return $output;
     72
     73  $page['get_icon_cache'][$date] = $output;
     74
     75  return $page['get_icon_cache'][$date];
    5476}
    5577
Note: See TracChangeset for help on using the changeset viewer.