source: trunk/include/functions.inc.php @ 4966

Last change on this file since 4966 was 4966, checked in by plg, 14 years ago

merge r4965 from branch 2.0 to trunk

bug 1047 fixed: avoid warnings when the creation date is 0000-00-00 (which
happens when date_creation comes from corrupted EXIF)

bug 859 fixed: at display time only. Piwigo still inserts wrong date in the
database, to be fixed later.

File size: 40.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24include_once( PHPWG_ROOT_PATH .'include/functions_user.inc.php' );
25include_once( PHPWG_ROOT_PATH .'include/functions_cookie.inc.php' );
26include_once( PHPWG_ROOT_PATH .'include/functions_session.inc.php' );
27include_once( PHPWG_ROOT_PATH .'include/functions_category.inc.php' );
28include_once( PHPWG_ROOT_PATH .'include/functions_xml.inc.php' );
29include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' );
30include_once( PHPWG_ROOT_PATH .'include/functions_tag.inc.php' );
31include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
32include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
33
34//----------------------------------------------------------- generic functions
35function get_extra_fields($order_by_fields) 
36{
37  $fields = str_ireplace(array(' order by ', ' desc', ' asc'), 
38                         array('', '', ''),
39                         $order_by_fields
40                         );
41  if (!empty($fields))
42  {
43    $fields = ','.$fields;
44  }
45  return $fields;
46}
47
48// The function get_moment returns a float value coresponding to the number
49// of seconds since the unix epoch (1st January 1970) and the microseconds
50// are precised : e.g. 1052343429.89276600
51function get_moment()
52{
53  $t1 = explode( ' ', microtime() );
54  $t2 = explode( '.', $t1[0] );
55  $t2 = $t1[1].'.'.$t2[1];
56  return $t2;
57}
58
59// The function get_elapsed_time returns the number of seconds (with 3
60// decimals precision) between the start time and the end time given.
61function get_elapsed_time( $start, $end )
62{
63  return number_format( $end - $start, 3, '.', ' ').' s';
64}
65
66// - The replace_space function replaces space and '-' characters
67//   by their HTML equivalent  &nbsb; and &minus;
68// - The function does not replace characters in HTML tags
69// - This function was created because IE5 does not respect the
70//   CSS "white-space: nowrap;" property unless space and minus
71//   characters are replaced like this function does.
72// - Example :
73//                 <div class="foo">My friend</div>
74//               ( 01234567891111111111222222222233 )
75//               (           0123456789012345678901 )
76// becomes :
77//             <div class="foo">My&nbsp;friend</div>
78function replace_space( $string )
79{
80  //return $string;
81  $return_string = '';
82  // $remaining is the rest of the string where to replace spaces characters
83  $remaining = $string;
84  // $start represents the position of the next '<' character
85  // $end   represents the position of the next '>' character
86  ; // -> 0
87  $end   = strpos ( $remaining, '>' ); // -> 16
88  // as long as a '<' and his friend '>' are found, we loop
89  while ( ($start=strpos( $remaining, '<' )) !==false
90        and ($end=strpos( $remaining, '>' )) !== false )
91  {
92    // $treatment is the part of the string to treat
93    // In the first loop of our example, this variable is empty, but in the
94    // second loop, it equals 'My friend'
95    $treatment = substr ( $remaining, 0, $start );
96    // Replacement of ' ' by his equivalent '&nbsp;'
97    $treatment = str_replace( ' ', '&nbsp;', $treatment );
98    $treatment = str_replace( '-', '&minus;', $treatment );
99    // composing the string to return by adding the treated string and the
100    // following HTML tag -> 'My&nbsp;friend</div>'
101    $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
102    // the remaining string is deplaced to the part after the '>' of this
103    // loop
104    $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
105  }
106  $treatment = str_replace( ' ', '&nbsp;', $remaining );
107  $treatment = str_replace( '-', '&minus;', $treatment );
108  $return_string.= $treatment;
109
110  return $return_string;
111}
112
113// get_extension returns the part of the string after the last "."
114function get_extension( $filename )
115{
116  return substr( strrchr( $filename, '.' ), 1, strlen ( $filename ) );
117}
118
119// get_filename_wo_extension returns the part of the string before the last
120// ".".
121// get_filename_wo_extension( 'test.tar.gz' ) -> 'test.tar'
122function get_filename_wo_extension( $filename )
123{
124  $pos = strrpos( $filename, '.' );
125  return ($pos===false) ? $filename : substr( $filename, 0, $pos);
126}
127
128/**
129 * returns an array contening sub-directories, excluding ".svn"
130 *
131 * @param string $dir
132 * @return array
133 */
134function get_dirs($directory)
135{
136  $sub_dirs = array();
137  if ($opendir = opendir($directory))
138  {
139    while ($file = readdir($opendir))
140    {
141      if ($file != '.'
142          and $file != '..'
143          and is_dir($directory.'/'.$file)
144          and $file != '.svn')
145      {
146        array_push($sub_dirs, $file);
147      }
148    }
149    closedir($opendir);
150  }
151  return $sub_dirs;
152}
153
154define('MKGETDIR_NONE', 0);
155define('MKGETDIR_RECURSIVE', 1);
156define('MKGETDIR_DIE_ON_ERROR', 2);
157define('MKGETDIR_PROTECT_INDEX', 4);
158define('MKGETDIR_PROTECT_HTACCESS', 8);
159define('MKGETDIR_DEFAULT', 7);
160/**
161 * creates directory if not exists; ensures that directory is writable
162 * @param:
163 *  string $dir
164 *  int $flags combination of MKGETDIR_xxx
165 * @return bool false on error else true
166 */
167function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
168{
169  if ( !is_dir($dir) )
170  {
171    $umask = umask(0);
172    $mkd = @mkdir($dir, 0755, ($flags&MKGETDIR_RECURSIVE) ? true:false );
173    umask($umask);
174    if ($mkd==false)
175    {
176      !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
177      return false;
178    }
179    if( $flags&MKGETDIR_PROTECT_HTACCESS )
180    {
181      $file = $dir.'/.htaccess';
182      file_exists($file) or @file_put_contents( $file, 'deny from all' );
183    }
184    if( $flags&MKGETDIR_PROTECT_INDEX )
185    {
186      $file = $dir.'/index.htm';
187      file_exists($file) or @file_put_contents( $file, 'Not allowed!' );
188    }
189  }
190  if ( !is_writable($dir) )
191  {
192    !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
193    return false;
194  }
195  return true;
196}
197
198/**
199 * returns thumbnail directory name of input diretoty name
200 * make thumbnail directory is necessary
201 * set error messages on array messages
202 *
203 * @param:
204 *  string $dirname
205 *  arrayy $errors
206 * @return bool false on error else string directory name
207 */
208function mkget_thumbnail_dir($dirname, &$errors)
209{
210  global $conf;
211
212  $tndir = $dirname.'/'.$conf['dir_thumbnail'];
213  if (! mkgetdir($tndir, MKGETDIR_NONE) )
214  {
215    array_push($errors,
216          '['.$dirname.'] : '.l10n('no_write_access'));
217    return false;
218  }
219  return $tndir;
220}
221
222/* Returns true if the string appears to be encoded in UTF-8. (from wordpress)
223 * @param string Str
224 */
225function seems_utf8($Str) { # by bmorel at ssi dot fr
226  for ($i=0; $i<strlen($Str); $i++) {
227    if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
228    elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
229    elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
230    elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
231    elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
232    elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
233    else return false; # Does not match any model
234    for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
235      if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
236      return false;
237    }
238  }
239  return true;
240}
241
242/* Remove accents from a UTF-8 or ISO-859-1 string (from wordpress)
243 * @param string sstring - an UTF-8 or ISO-8859-1 string
244 */
245function remove_accents($string)
246{
247  if ( !preg_match('/[\x80-\xff]/', $string) )
248    return $string;
249
250  if (seems_utf8($string)) {
251    $chars = array(
252    // Decompositions for Latin-1 Supplement
253    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
254    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
255    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
256    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
257    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
258    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
259    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
260    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
261    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
262    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
263    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
264    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
265    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
266    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
267    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
268    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
269    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
270    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
271    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
272    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
273    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
274    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
275    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
276    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
277    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
278    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
279    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
280    chr(195).chr(191) => 'y',
281    // Decompositions for Latin Extended-A
282    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
283    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
284    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
285    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
286    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
287    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
288    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
289    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
290    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
291    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
292    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
293    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
294    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
295    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
296    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
297    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
298    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
299    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
300    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
301    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
302    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
303    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
304    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
305    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
306    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
307    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
308    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
309    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
310    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
311    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
312    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
313    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
314    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
315    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
316    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
317    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
318    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
319    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
320    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
321    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
322    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
323    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
324    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
325    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
326    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
327    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
328    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
329    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
330    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
331    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
332    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
333    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
334    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
335    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
336    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
337    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
338    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
339    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
340    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
341    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
342    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
343    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
344    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
345    chr(197).chr(190) => 'z', chr(197).chr(191) => 's',
346    // Euro Sign
347    chr(226).chr(130).chr(172) => 'E',
348    // GBP (Pound) Sign
349    chr(194).chr(163) => '');
350
351    $string = strtr($string, $chars);
352  } else {
353    // Assume ISO-8859-1 if not UTF-8
354    $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
355      .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
356      .chr(195).chr(196).chr(197).chr(199).chr(200).chr(201).chr(202)
357      .chr(203).chr(204).chr(205).chr(206).chr(207).chr(209).chr(210)
358      .chr(211).chr(212).chr(213).chr(214).chr(216).chr(217).chr(218)
359      .chr(219).chr(220).chr(221).chr(224).chr(225).chr(226).chr(227)
360      .chr(228).chr(229).chr(231).chr(232).chr(233).chr(234).chr(235)
361      .chr(236).chr(237).chr(238).chr(239).chr(241).chr(242).chr(243)
362      .chr(244).chr(245).chr(246).chr(248).chr(249).chr(250).chr(251)
363      .chr(252).chr(253).chr(255);
364
365    $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
366
367    $string = strtr($string, $chars['in'], $chars['out']);
368    $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
369    $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
370    $string = str_replace($double_chars['in'], $double_chars['out'], $string);
371  }
372
373  return $string;
374}
375
376/**
377 * simplify a string to insert it into an URL
378 *
379 * @param string
380 * @return string
381 */
382function str2url($str)
383{
384  $str = remove_accents($str);
385  $str = preg_replace('/[^a-z0-9_\s\'\:\/\[\],-]/','',strtolower($str));
386  $str = preg_replace('/[\s\'\:\/\[\],-]+/',' ',trim($str));
387  $res = str_replace(' ','_',$str);
388
389  return $res;
390}
391
392//-------------------------------------------- Piwigo specific functions
393
394/**
395 * returns an array with a list of {language_code => language_name}
396 *
397 * @returns array
398 */
399function get_languages($target_charset = null)
400{
401  if ( empty($target_charset) )
402  {
403    $target_charset = get_pwg_charset();
404  }
405  $target_charset = strtolower($target_charset);
406
407  $dir = opendir(PHPWG_ROOT_PATH.'language');
408  $languages = array();
409
410  while ($file = readdir($dir))
411  {
412    $path = PHPWG_ROOT_PATH.'language/'.$file;
413    if (!is_link($path) and file_exists($path.'/iso.txt'))
414    {
415      list($language_name) = @file($path.'/iso.txt');
416
417      $langdef = explode('.',$file);
418      if (count($langdef)>1) // (langCode,encoding)
419      {
420        $langdef[1] = strtolower($langdef[1]);
421
422        if (
423          $target_charset==$langdef[1]
424         or
425          ($target_charset=='utf-8' and $langdef[1]=='iso-8859-1')
426         or
427          ($target_charset=='iso-8859-1' and
428          in_array( substr($langdef[0],2), array('en','fr','de','es','it','nl')))
429        )
430        {
431          $language_name = convert_charset($language_name,
432              $langdef[1], $target_charset);
433          $languages[ $langdef[0] ] = $language_name;
434        }
435        else
436          continue; // the language encoding is not compatible with our charset
437      }
438      else
439      { // UTF-8
440        $language_name = convert_charset($language_name,
441              'utf-8', $target_charset);
442        $languages[$file] = $language_name;
443      }
444    }
445  }
446  closedir($dir);
447  @asort($languages);
448
449  return $languages;
450}
451
452function pwg_log($image_id = null, $image_type = null)
453{
454  global $conf, $user, $page;
455
456  $do_log = $conf['log'];
457  if (is_admin())
458  {
459    $do_log = $conf['history_admin'];
460  }
461  if (is_a_guest())
462  {
463    $do_log = $conf['history_guest'];
464  }
465
466  $do_log = trigger_event('pwg_log_allowed', $do_log, $image_id, $image_type);
467
468  if (!$do_log)
469  {
470    return false;
471  }
472
473  $tags_string = null;
474  if ('tags'==@$page['section'])
475  {
476    $tags_string = implode(',', $page['tag_ids']);
477  }
478
479  $query = '
480INSERT INTO '.HISTORY_TABLE.'
481  (
482    date,
483    time,
484    user_id,
485    IP,
486    section,
487    category_id,
488    image_id,
489    image_type,
490    tag_ids
491  )
492  VALUES
493  (
494    CURRENT_DATE,
495    CURRENT_TIME,
496    '.$user['id'].',
497    \''.$_SERVER['REMOTE_ADDR'].'\',
498    '.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').',
499    '.(isset($page['category']['id']) ? $page['category']['id'] : 'NULL').',
500    '.(isset($image_id) ? $image_id : 'NULL').',
501    '.(isset($image_type) ? "'".$image_type."'" : 'NULL').',
502    '.(isset($tags_string) ? "'".$tags_string."'" : 'NULL').'
503  )
504;';
505  pwg_query($query);
506
507  return true;
508}
509
510// format_date returns a formatted date for display. The date given in
511// argument must be an american format (2003-09-15). By option, you can show the time.
512// The output is internationalized.
513//
514// format_date( "2003-09-15", true ) -> "Monday 15 September 2003 21:52"
515function format_date($date, $show_time = false)
516{
517  global $lang;
518
519  if (strpos($date, '0') == 0)
520  {
521    return l10n('N/A');
522  }
523
524  $ymdhms = array();
525  $tok = strtok( $date, '- :');
526  while ($tok !== false)
527  {
528    $ymdhms[] = $tok;
529    $tok = strtok('- :');
530  }
531
532  if ( count($ymdhms)<3 )
533  {
534    return false;
535  }
536
537  $formated_date = '';
538  // before 1970, Microsoft Windows can't mktime
539  if ($ymdhms[0] >= 1970)
540  {
541    // we ask midday because Windows think it's prior to midnight with a
542    // zero and refuse to work
543    $formated_date.= $lang['day'][date('w', mktime(12,0,0,$ymdhms[1],$ymdhms[2],$ymdhms[0]))];
544  }
545  $formated_date.= ' '.$ymdhms[2];
546  $formated_date.= ' '.$lang['month'][(int)$ymdhms[1]];
547  $formated_date.= ' '.$ymdhms[0];
548  if ($show_time and count($ymdhms)>=5 )
549  {
550    $formated_date.= ' '.$ymdhms[3].':'.$ymdhms[4];
551  }
552  return $formated_date;
553}
554
555function pwg_debug( $string )
556{
557  global $debug,$t2,$page;
558
559  $now = explode( ' ', microtime() );
560  $now2 = explode( '.', $now[0] );
561  $now2 = $now[1].'.'.$now2[1];
562  $time = number_format( $now2 - $t2, 3, '.', ' ').' s';
563  $debug .= '<p>';
564  $debug.= '['.$time.', ';
565  $debug.= $page['count_queries'].' queries] : '.$string;
566  $debug.= "</p>\n";
567}
568
569/**
570 * Redirects to the given URL (HTTP method)
571 *
572 * Note : once this function called, the execution doesn't go further
573 * (presence of an exit() instruction.
574 *
575 * @param string $url
576 * @return void
577 */
578function redirect_http( $url )
579{
580  if (ob_get_length () !== FALSE)
581  {
582    ob_clean();
583  }
584  // default url is on html format
585  $url = html_entity_decode($url);
586  header('Request-URI: '.$url);
587  header('Content-Location: '.$url);
588  header('Location: '.$url);
589  exit();
590}
591
592/**
593 * Redirects to the given URL (HTML method)
594 *
595 * Note : once this function called, the execution doesn't go further
596 * (presence of an exit() instruction.
597 *
598 * @param string $url
599 * @param string $title_msg
600 * @param integer $refreh_time
601 * @return void
602 */
603function redirect_html( $url , $msg = '', $refresh_time = 0)
604{
605  global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;
606
607  if (!isset($lang_info))
608  {
609    $user = build_user( $conf['guest_id'], true);
610    load_language('common.lang');
611    trigger_action('loading_lang');
612    load_language('local.lang', '', array('no_fallback'=>true) );
613    list($tmpl, $thm) = explode('/', get_default_template());
614    $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm);
615  }
616  else
617  {
618    $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']);
619  }
620
621  if (empty($msg))
622  {
623    $msg = nl2br(l10n('redirect_msg'));
624  }
625
626  $refresh = $refresh_time;
627  $url_link = $url;
628  $title = 'redirection';
629
630  $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) );
631
632  include( PHPWG_ROOT_PATH.'include/page_header.php' );
633
634  $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) );
635  $template->assign('REDIRECT_MSG', $msg);
636
637  $template->parse('redirect');
638
639  include( PHPWG_ROOT_PATH.'include/page_tail.php' );
640
641  exit();
642}
643
644/**
645 * Redirects to the given URL (Switch to HTTP method or HTML method)
646 *
647 * Note : once this function called, the execution doesn't go further
648 * (presence of an exit() instruction.
649 *
650 * @param string $url
651 * @param string $title_msg
652 * @param integer $refreh_time
653 * @return void
654 */
655function redirect( $url , $msg = '', $refresh_time = 0)
656{
657  global $conf;
658
659  // with RefeshTime <> 0, only html must be used
660  if ($conf['default_redirect_method']=='http'
661      and $refresh_time==0
662      and !headers_sent()
663    )
664  {
665    redirect_http($url);
666  }
667  else
668  {
669    redirect_html($url, $msg, $refresh_time);
670  }
671}
672
673/**
674 * returns $_SERVER['QUERY_STRING'] whitout keys given in parameters
675 *
676 * @param array $rejects
677 * @param boolean $escape - if true escape & to &amp; (for html)
678 * @returns string
679 */
680function get_query_string_diff($rejects=array(), $escape=true)
681{
682  $query_string = '';
683
684  $str = $_SERVER['QUERY_STRING'];
685  parse_str($str, $vars);
686
687  $is_first = true;
688  foreach ($vars as $key => $value)
689  {
690    if (!in_array($key, $rejects))
691    {
692      $query_string.= $is_first ? '?' : ($escape ? '&amp;' : '&' );
693      $is_first = false;
694      $query_string.= $key.'='.$value;
695    }
696  }
697
698  return $query_string;
699}
700
701function url_is_remote($url)
702{
703  if ( strncmp($url, 'http://', 7)==0
704    or strncmp($url, 'https://', 8)==0 )
705  {
706    return true;
707  }
708  return false;
709}
710
711/**
712 * returns available template/theme
713 */
714function get_pwg_themes()
715{
716  global $conf;
717  $themes = array();
718
719  $template_dir = PHPWG_ROOT_PATH.'template';
720
721  foreach (get_dirs($template_dir) as $template)
722  {
723    foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme)
724    {
725      if ( ($template.'/'.$theme) != $conf['admin_layout'] )
726      array_push($themes, $template.'/'.$theme);
727    }
728  }
729
730  return $themes;
731}
732
733/* Returns the PATH to the thumbnail to be displayed. If the element does not
734 * have a thumbnail, the default mime image path is returned. The PATH can be
735 * used in the php script, but not sent to the browser.
736 * @param array element_info assoc array containing element info from db
737 * at least 'path', 'tn_ext' and 'id' should be present
738 */
739function get_thumbnail_path($element_info)
740{
741  $path = get_thumbnail_location($element_info);
742  if ( !url_is_remote($path) )
743  {
744    $path = PHPWG_ROOT_PATH.$path;
745  }
746  return $path;
747}
748
749/* Returns the URL of the thumbnail to be displayed. If the element does not
750 * have a thumbnail, the default mime image url is returned. The URL can be
751 * sent to the browser, but not used in the php script.
752 * @param array element_info assoc array containing element info from db
753 * at least 'path', 'tn_ext' and 'id' should be present
754 */
755function get_thumbnail_url($element_info)
756{
757  $path = get_thumbnail_location($element_info);
758  if ( !url_is_remote($path) )
759  {
760    $path = embellish_url(get_root_url().$path);
761  }
762
763  // plugins want another url ?
764  $path = trigger_event('get_thumbnail_url', $path, $element_info);
765  return $path;
766}
767
768/* returns the relative path of the thumnail with regards to to the root
769of piwigo (not the current page!).This function is not intended to be
770called directly from code.*/
771function get_thumbnail_location($element_info)
772{
773  global $conf;
774  if ( !empty( $element_info['tn_ext'] ) )
775  {
776    $path = substr_replace(
777      get_filename_wo_extension($element_info['path']),
778      '/'.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'],
779      strrpos($element_info['path'],'/'),
780      1
781      );
782    $path.= '.'.$element_info['tn_ext'];
783  }
784  else
785  {
786    $path = get_themeconf('mime_icon_dir')
787        .strtolower(get_extension($element_info['path'])).'.png';
788  }
789
790  // plugins want another location ?
791  $path = trigger_event( 'get_thumbnail_location', $path, $element_info);
792  return $path;
793}
794
795/* returns the title of the thumnail */
796function get_thumbnail_title($element_info)
797{
798  // message in title for the thumbnail
799  if (isset($element_info['file']))
800  {
801    $thumbnail_title = $element_info['file'];
802  }
803  else
804  {
805    $thumbnail_title = '';
806  }
807
808  if (!empty($element_info['filesize']))
809  {
810    $thumbnail_title .= ' : '.sprintf(l10n('%d Kb'), $element_info['filesize']);
811  }
812
813  return $thumbnail_title;
814}
815
816/**
817 * fill the current user caddie with given elements, if not already in
818 * caddie
819 *
820 * @param array elements_id
821 */
822function fill_caddie($elements_id)
823{
824  global $user;
825
826  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
827
828  $query = '
829SELECT element_id
830  FROM '.CADDIE_TABLE.'
831  WHERE user_id = '.$user['id'].'
832;';
833  $in_caddie = array_from_query($query, 'element_id');
834
835  $caddiables = array_diff($elements_id, $in_caddie);
836
837  $datas = array();
838
839  foreach ($caddiables as $caddiable)
840  {
841    array_push($datas, array('element_id' => $caddiable,
842                             'user_id' => $user['id']));
843  }
844
845  if (count($caddiables) > 0)
846  {
847    mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
848  }
849}
850
851/**
852 * returns the element name from its filename
853 *
854 * @param string filename
855 * @return string name
856 */
857function get_name_from_file($filename)
858{
859  return str_replace('_',' ',get_filename_wo_extension($filename));
860}
861
862/**
863 * returns the corresponding value from $lang if existing. Else, the key is
864 * returned
865 *
866 * @param string key
867 * @return string
868 */
869function l10n($key)
870{
871  global $lang, $conf;
872
873  if ($conf['debug_l10n'] and !isset($lang[$key]) and !empty($key))
874  {
875    trigger_error('[l10n] language key "'.$key.'" is not defined', E_USER_WARNING);
876  }
877
878  return isset($lang[$key]) ? $lang[$key] : $key;
879}
880
881/**
882 * returns the prinft value for strings including %d
883 * return is concorded with decimal value (singular, plural)
884 *
885 * @param singular string key
886 * @param plural string key
887 * @param decimal value
888 * @return string
889 */
890function l10n_dec($singular_fmt_key, $plural_fmt_key, $decimal)
891{
892  global $lang_info;
893
894  return
895    sprintf(
896      l10n((
897        (($decimal > 1) or ($decimal == 0 and $lang_info['zero_plural']))
898          ? $plural_fmt_key
899          : $singular_fmt_key
900        )), $decimal);
901}
902/*
903 * returns a single element to use with l10n_args
904 *
905 * @param string key: translation key
906 * @param array/string/../number args:
907 *   arguments to use on sprintf($key, args)
908 *   if args is a array, each values are used on sprintf
909 * @return string
910 */
911function get_l10n_args($key, $args)
912{
913  if (is_array($args))
914  {
915    $key_arg = array_merge(array($key), $args);
916  }
917  else
918  {
919    $key_arg = array($key,  $args);
920  }
921  return array('key_args' => $key_arg);
922}
923
924/*
925 * returns a string with formated with l10n_args elements
926 *
927 * @param element/array $key_args: element or array of l10n_args elements
928 * @param $sep: if $key_args is array,
929 *   separator is used when translated l10n_args elements are concated
930 * @return string
931 */
932function l10n_args($key_args, $sep = "\n")
933{
934  if (is_array($key_args))
935  {
936    foreach ($key_args as $key => $element)
937    {
938      if (isset($result))
939      {
940        $result .= $sep;
941      }
942      else
943      {
944        $result = '';
945      }
946
947      if ($key === 'key_args')
948      {
949        array_unshift($element, l10n(array_shift($element)));
950        $result .= call_user_func_array('sprintf', $element);
951      }
952      else
953      {
954        $result .= l10n_args($element, $sep);
955      }
956    }
957  }
958  else
959  {
960    fatal_error('l10n_args: Invalid arguments');
961  }
962
963  return $result;
964}
965
966/**
967 * returns the corresponding value from $themeconf if existing. Else, the
968 * key is returned
969 *
970 * @param string key
971 * @return string
972 */
973function get_themeconf($key)
974{
975  global $template;
976
977  return $template->get_themeconf($key);
978}
979
980/**
981 * Returns webmaster mail address depending on $conf['webmaster_id']
982 *
983 * @return string
984 */
985function get_webmaster_mail_address()
986{
987  global $conf;
988
989  $query = '
990SELECT '.$conf['user_fields']['email'].'
991  FROM '.USERS_TABLE.'
992  WHERE '.$conf['user_fields']['id'].' = '.$conf['webmaster_id'].'
993;';
994  list($email) = pwg_db_fetch_row(pwg_query($query));
995
996  return $email;
997}
998
999/**
1000 * Add configuration parameters from database to global $conf array
1001 *
1002 * @return void
1003 */
1004function load_conf_from_db($condition = '')
1005{
1006  global $conf;
1007
1008  $query = '
1009SELECT param, value
1010 FROM '.CONFIG_TABLE.'
1011 '.(!empty($condition) ? 'WHERE '.$condition : '').'
1012;';
1013  $result = pwg_query($query);
1014
1015  if ((pwg_db_num_rows($result) == 0) and !empty($condition))
1016  {
1017    fatal_error('No configuration data');
1018  }
1019
1020  while ($row = pwg_db_fetch_assoc($result))
1021  {
1022    $conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : '';
1023
1024    // If the field is true or false, the variable is transformed into a
1025    // boolean value.
1026    if ($conf[$row['param']] == 'true' or $conf[$row['param']] == 'false')
1027    {
1028      $conf[ $row['param'] ] = get_boolean($conf[ $row['param'] ]);
1029    }
1030  }
1031}
1032
1033/**
1034 * Prepends and appends a string at each value of the given array.
1035 *
1036 * @param array
1037 * @param string prefix to each array values
1038 * @param string suffix to each array values
1039 */
1040function prepend_append_array_items($array, $prepend_str, $append_str)
1041{
1042  array_walk(
1043    $array,
1044    create_function('&$s', '$s = "'.$prepend_str.'".$s."'.$append_str.'";')
1045    );
1046
1047  return $array;
1048}
1049
1050/**
1051 * creates an hashed based on a query, this function is a very common
1052 * pattern used here. Among the selected columns fetched, choose one to be
1053 * the key, another one to be the value.
1054 *
1055 * @param string $query
1056 * @param string $keyname
1057 * @param string $valuename
1058 * @return array
1059 */
1060function simple_hash_from_query($query, $keyname, $valuename)
1061{
1062  $array = array();
1063
1064  $result = pwg_query($query);
1065  while ($row = pwg_db_fetch_assoc($result))
1066  {
1067    $array[ $row[$keyname] ] = $row[$valuename];
1068  }
1069
1070  return $array;
1071}
1072
1073/**
1074 * creates an hashed based on a query, this function is a very common
1075 * pattern used here. The key is given as parameter, the value is an associative
1076 * array.
1077 *
1078 * @param string $query
1079 * @param string $keyname
1080 * @return array
1081 */
1082function hash_from_query($query, $keyname)
1083{
1084  $array = array();
1085  $result = pwg_query($query);
1086  while ($row = pwg_db_fetch_assoc($result))
1087  {
1088    $array[ $row[$keyname] ] = $row;
1089  }
1090  return $array;
1091}
1092
1093/**
1094 * Return basename of the current script
1095 * Lower case convertion is applied on return value
1096 * Return value is without file extention ".php"
1097 *
1098 * @param void
1099 *
1100 * @return script basename
1101 */
1102function script_basename()
1103{
1104  global $conf;
1105
1106  foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value)
1107  {
1108    if (!empty($_SERVER[$value]))
1109    {
1110      $filename = strtolower($_SERVER[$value]);
1111      if ($conf['php_extension_in_urls'] and get_extension($filename)!=='php')
1112        continue;
1113      $basename = basename($filename, '.php');
1114      if (!empty($basename))
1115      {
1116        return $basename;
1117      }
1118    }
1119  }
1120  return '';
1121}
1122
1123/**
1124 * Return value for the current page define on $conf['filter_pages']
1125 * Îf value is not defined, default value are returned
1126 *
1127 * @param value name
1128 *
1129 * @return filter page value
1130 */
1131function get_filter_page_value($value_name)
1132{
1133  global $conf;
1134
1135  $page_name = script_basename();
1136
1137  if (isset($conf['filter_pages'][$page_name][$value_name]))
1138  {
1139    return $conf['filter_pages'][$page_name][$value_name];
1140  }
1141  else if (isset($conf['filter_pages']['default'][$value_name]))
1142  {
1143    return $conf['filter_pages']['default'][$value_name];
1144  }
1145  else
1146  {
1147    return null;
1148  }
1149}
1150
1151/**
1152 * returns the character set of data sent to browsers / received from forms
1153 */
1154function get_pwg_charset()
1155{
1156  defined('PWG_CHARSET') or fatal_error('PWG_CHARSET undefined');
1157  return PWG_CHARSET;
1158}
1159
1160/**
1161 * includes a language file or returns the content of a language file
1162 * availability of the file
1163 *
1164 * in descending order of preference:
1165 *   param language, user language, default language
1166 * Piwigo default language.
1167 *
1168 * @param string filename
1169 * @param string dirname
1170 * @param mixed options can contain
1171 *     language - language to load (if empty uses user language)
1172 *     return - if true the file content is returned otherwise the file is evaluated as php
1173 *     target_charset -
1174 *     no_fallback - the language must be respected
1175 * @return boolean success status or a string if options['return'] is true
1176 */
1177function load_language($filename, $dirname = '',
1178    $options = array() )
1179{
1180  global $user;
1181
1182  if (! @$options['return'] )
1183  {
1184    $filename .= '.php'; //MAYBE to do .. load .po and .mo localization files
1185  }
1186  if (empty($dirname))
1187  {
1188    $dirname = PHPWG_ROOT_PATH;
1189  }
1190  $dirname .= 'language/';
1191
1192  $languages = array();
1193  if ( !empty($options['language']) )
1194  {
1195    $languages[] = $options['language'];
1196  }
1197  if ( !empty($user['language']) )
1198  {
1199    $languages[] = $user['language'];
1200  }
1201  if ( ! @$options['no_fallback'] )
1202  {
1203    if ( defined('PHPWG_INSTALLED') )
1204    {
1205      $languages[] = get_default_language();
1206    }
1207    $languages[] = PHPWG_DEFAULT_LANGUAGE;
1208  }
1209
1210  $languages = array_unique($languages);
1211
1212  if ( empty($options['target_charset']) )
1213  {
1214    $target_charset = get_pwg_charset();
1215  }
1216  else
1217  {
1218    $target_charset = $options['target_charset'];
1219  }
1220  $target_charset = strtolower($target_charset);
1221  $source_charset = '';
1222  $source_file    = '';
1223  foreach ($languages as $language)
1224  {
1225    $dir = $dirname.$language;
1226
1227    if ($target_charset!='utf-8')
1228    {
1229      // exact charset match - no conversion required
1230      $f = $dir.'.'.$target_charset.'/'.$filename;
1231      if (file_exists($f))
1232      {
1233        $source_file = $f;
1234        break;
1235      }
1236    }
1237
1238    // UTF-8 ?
1239    $f = $dir.'/'.$filename;
1240    if (file_exists($f))
1241    {
1242      $source_charset = 'utf-8';
1243      $source_file = $f;
1244      break;
1245    }
1246  }
1247
1248  if ( !empty($source_file) )
1249  {
1250    if (! @$options['return'] )
1251    {
1252      @include($source_file);
1253      $load_lang = @$lang;
1254      $load_lang_info = @$lang_info;
1255
1256      global $lang, $lang_info;
1257      if ( !isset($lang) ) $lang=array();
1258      if ( !isset($lang_info) ) $lang_info=array();
1259
1260      if ( !empty($source_charset) and $source_charset!=$target_charset)
1261      {
1262        if ( is_array($load_lang) )
1263        {
1264          foreach ($load_lang as $k => $v)
1265          {
1266            if ( is_array($v) )
1267            {
1268              $func = create_function('$v', 'return convert_charset($v, "'.$source_charset.'","'.$target_charset.'");' );
1269              $lang[$k] = array_map($func, $v);
1270            }
1271            else
1272              $lang[$k] = convert_charset($v, $source_charset, $target_charset);
1273          }
1274        }
1275        if ( is_array($load_lang_info) )
1276        {
1277          foreach ($load_lang_info as $k => $v)
1278          {
1279            $lang_info[$k] = convert_charset($v, $source_charset, $target_charset);
1280          }
1281        }
1282      }
1283      else
1284      {
1285        $lang = array_merge( $lang, (array)$load_lang );
1286        $lang_info = array_merge( $lang_info, (array)$load_lang_info );
1287      }
1288      return true;
1289    }
1290    else
1291    {
1292      $content = @file_get_contents($source_file);
1293      if ( !empty($source_charset) and $source_charset!=$target_charset)
1294      {
1295        $content = convert_charset($content, $source_charset, $target_charset);
1296      }
1297      return $content;
1298    }
1299  }
1300  return false;
1301}
1302
1303/**
1304 * converts a string from a character set to another character set
1305 * @param string str the string to be converted
1306 * @param string source_charset the character set in which the string is encoded
1307 * @param string dest_charset the destination character set
1308 */
1309function convert_charset($str, $source_charset, $dest_charset)
1310{
1311  if ($source_charset==$dest_charset)
1312    return $str;
1313  if ($source_charset=='iso-8859-1' and $dest_charset=='utf-8')
1314  {
1315    return utf8_encode($str);
1316  }
1317  if ($source_charset=='utf-8' and $dest_charset=='iso-8859-1')
1318  {
1319    return utf8_decode($str);
1320  }
1321  if (function_exists('iconv'))
1322  {
1323    return iconv($source_charset, $dest_charset, $str);
1324  }
1325  if (function_exists('mb_convert_encoding'))
1326  {
1327    return mb_convert_encoding( $str, $dest_charset, $source_charset );
1328  }
1329  return $str; //???
1330}
1331
1332/**
1333 * makes sure a index.htm protects the directory from browser file listing
1334 *
1335 * @param string dir directory
1336 */
1337function secure_directory($dir)
1338{
1339  $file = $dir.'/index.htm';
1340  if (!file_exists($file))
1341  {
1342    @file_put_contents($file, 'Not allowed!');
1343  }
1344}
1345
1346/**
1347 * returns a "secret key" that is to be sent back when a user enters a comment
1348 *
1349 * @param int image_id
1350 */
1351function get_comment_post_key($image_id)
1352{
1353  global $conf;
1354
1355  $time = time();
1356
1357  return sprintf(
1358    '%s:%s',
1359    $time,
1360    hash_hmac(
1361      'md5',
1362      $time.':'.$image_id,
1363      $conf['secret_key']
1364      )
1365    );
1366}
1367
1368/**
1369 * return an array which will be sent to template to display navigation bar
1370 */
1371function create_navigation_bar($url, $nb_element, $start, $nb_element_page, $clean_url = false)
1372{
1373  global $conf;
1374
1375  $navbar = array();
1376  $pages_around = $conf['paginate_pages_around'];
1377  $start_str = $clean_url ? '/start-' : (strpos($url, '?')===false ? '?':'&amp;').'start=';
1378
1379  if (!isset($start) or !is_numeric($start) or (is_numeric($start) and $start < 0))
1380  {
1381    $start = 0;
1382  }
1383
1384  // navigation bar useful only if more than one page to display !
1385  if ($nb_element > $nb_element_page)
1386  {
1387    $cur_page = ceil($start / $nb_element_page) + 1;
1388    $maximum = ceil($nb_element / $nb_element_page);
1389    $previous = $start - $nb_element_page;
1390    $next = $start + $nb_element_page;
1391    $last = ($maximum - 1) * $nb_element_page;
1392
1393    $navbar['CURRENT_PAGE'] = $cur_page;
1394
1395    // link to first page and previous page?
1396    if ($cur_page != 1)
1397    {
1398      $navbar['URL_FIRST'] = $url;
1399      $navbar['URL_PREV'] = $url.($previous > 0 ? $start_str.$previous : '');
1400    }
1401    // link on next page and last page?
1402    if ($cur_page != $maximum)
1403    {
1404      $navbar['URL_NEXT'] = $url.$start_str.$next;
1405      $navbar['URL_LAST'] = $url.$start_str.$last;
1406    }
1407
1408    // pages to display
1409    $navbar['pages'] = array();
1410    $navbar['pages'][1] = $url;
1411    $navbar['pages'][$maximum] = $url.$start_str.$last;
1412
1413    for ($i = max($cur_page - $pages_around , 2), $stop = min($cur_page + $pages_around + 1, $maximum);
1414         $i < $stop; $i++)
1415    {
1416      $navbar['pages'][$i] = $url.$start_str.(($i - 1) * $nb_element_page);
1417    }
1418    ksort($navbar['pages']);
1419  }
1420  return $navbar;
1421}
1422
1423/**
1424 * return an array which will be sent to template to display recent icon
1425 */
1426function get_icon($date, $is_child_date = false)
1427{
1428  global $cache, $user;
1429
1430  if (empty($date))
1431  {
1432    return false;
1433  }
1434
1435  if (!isset($cache['get_icon']['title']))
1436  {
1437    $cache['get_icon']['title'] = sprintf(
1438      l10n('elements posted during the last %d days'),
1439      $user['recent_period']
1440      );
1441  }
1442
1443  $icon = array(
1444    'TITLE' => $cache['get_icon']['title'],
1445    'IS_CHILD_DATE' => $is_child_date,
1446    );
1447
1448  if (isset($cache['get_icon'][$date]))
1449  {
1450    return $cache['get_icon'][$date] ? $icon : array();
1451  }
1452
1453  if (!isset($cache['get_icon']['sql_recent_date']))
1454  {
1455    // Use MySql date in order to standardize all recent "actions/queries"
1456    $cache['get_icon']['sql_recent_date'] = pwg_db_get_recent_period($user['recent_period']);
1457  }
1458
1459  $cache['get_icon'][$date] = $date > $cache['get_icon']['sql_recent_date'];
1460
1461  return $cache['get_icon'][$date] ? $icon : array();
1462}
1463?>
Note: See TracBrowser for help on using the repository browser.