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

Last change on this file since 5100 was 5100, checked in by vdigital, 14 years ago

Fix: failed to open dir on default template

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