source: trunk/include/functions_html.inc.php @ 2945

Last change on this file since 2945 was 2884, checked in by patdenice, 16 years ago
  • Replace some mysql_query by pwg_query function.
  • Add home button after upgrade.php.
  • Add utf8 charset for access denied message.
  • Replace some #content by .content in css files.
  • Fix menubar blocks borders with IE.
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 21.5 KB
RevLine 
[476]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// +-----------------------------------------------------------------------+
[476]23
[1624]24function get_icon($date, $is_child_date = false)
[476]25{
[2265]26  global $page, $user;
[476]27
[1040]28  if (empty($date))
[492]29  {
[1641]30    return '';
[492]31  }
[2290]32
[1641]33  if (isset($page['get_icon_cache'][$date]))
[1040]34  {
[1641]35    if (! $page['get_icon_cache'][$date] )
36      return '';
37    return $page['get_icon_cache']['_icons_'][$is_child_date];
[1040]38  }
39
[2182]40  if (!isset($page['get_icon_cache']['sql_recent_date']))
[1040]41  {
[1876]42    // Use MySql date in order to standardize all recent "actions/queries"
[2182]43    list($page['get_icon_cache']['sql_recent_date']) =
44      mysql_fetch_array(pwg_query('select SUBDATE(
45      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'));
[1876]46  }
47
[1641]48  $page['get_icon_cache'][$date] = false;
[2182]49  if ( $date > $page['get_icon_cache']['sql_recent_date'] )
[476]50  {
[1641]51    if ( !isset($page['get_icon_cache']['_icons_'] ) )
52    {
53      $icons = array(false => 'recent', true => 'recent_by_child' );
[2265]54      $title = sprintf(
55        l10n('elements posted during the last %d days'),
56        $user['recent_period']
57        );
[1641]58      foreach ($icons as $key => $icon)
59      {
60        $icon_url = get_themeconf('icon_dir').'/'.$icon.'.png';
61        $size = getimagesize( PHPWG_ROOT_PATH.$icon_url );
62        $icon_url = get_root_url().$icon_url;
63        $output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;';
64        $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
65        $page['get_icon_cache']['_icons_'][$key] = $output;
66      }
67    }
68    $page['get_icon_cache'][$date] = true;
[476]69  }
[2182]70
[1641]71  if (! $page['get_icon_cache'][$date] )
72    return '';
73  return $page['get_icon_cache']['_icons_'][$is_child_date];
74}
[1040]75
[1084]76function create_navigation_bar(
77  $url, $nb_element, $start, $nb_element_page, $clean_url = false
78  )
[476]79{
[2265]80  global $conf;
[643]81
82  $pages_around = $conf['paginate_pages_around'];
[1563]83  $start_str = $clean_url ? '/start-' :
[2773]84    ( ( strpos($url, '?')===false ? '?':'&amp;') . 'start=' );
[1090]85
[644]86  $navbar = '';
[1090]87
[643]88  // current page detection
89  if (!isset($start)
90      or !is_numeric($start)
91      or (is_numeric($start) and $start < 0))
[476]92  {
93    $start = 0;
94  }
[1090]95
[643]96  // navigation bar useful only if more than one page to display !
97  if ($nb_element > $nb_element_page)
[476]98  {
[644]99    // current page and last page
[643]100    $cur_page = ceil($start / $nb_element_page) + 1;
101    $maximum = ceil($nb_element / $nb_element_page);
102
103    // link to first page ?
104    if ($cur_page != 1)
105    {
[1084]106      $navbar.=
[2353]107        '<a href="'.$url.'" rel="first">'
[2201]108        .l10n('first_page')
[1084]109        .'</a>';
[643]110    }
111    else
112    {
[2201]113      $navbar.= l10n('first_page');
[643]114    }
[644]115    $navbar.= ' | ';
[643]116    // link on previous page ?
[1084]117    if ($start != 0)
[476]118    {
119      $previous = $start - $nb_element_page;
[1090]120
[1084]121      $navbar.=
122        '<a href="'
123        .$url.($previous > 0 ? $start_str.$previous : '')
124        .'" rel="prev">'
[2201]125        .l10n('previous_page')
[1084]126        .'</a>';
[476]127    }
[643]128    else
[476]129    {
[2201]130      $navbar.= l10n('previous_page');
[643]131    }
[1031]132    $navbar.= ' |';
[643]133
134    if ($cur_page > $pages_around + 1)
135    {
[1084]136      $navbar.= '&nbsp;<a href="'.$url.'">1</a>';
[1090]137
[678]138      if ($cur_page > $pages_around + 2)
139      {
140        $navbar.= ' ...';
141      }
[643]142    }
[1090]143
[643]144    // inspired from punbb source code
145    for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1;
146         $i < $stop;
147         $i++)
148    {
149      if ($i < 1 or $i > $maximum)
[476]150      {
[643]151        continue;
[476]152      }
[643]153      else if ($i != $cur_page)
154      {
155        $temp_start = ($i - 1) * $nb_element_page;
[1090]156
[1084]157        $navbar.=
158          '&nbsp;'
159          .'<a href="'.$url
160          .($temp_start > 0 ? $start_str.$temp_start : '')
161          .'">'
162          .$i
163          .'</a>';
[643]164      }
[476]165      else
166      {
[1084]167        $navbar.=
168          '&nbsp;'
169          .'<span class="pageNumberSelected">'
170          .$i
171          .'</span>';
[476]172      }
173    }
[643]174
175    if ($cur_page < ($maximum - $pages_around))
176    {
177      $temp_start = ($maximum - 1) * $nb_element_page;
[1090]178
[678]179      if ($cur_page < ($maximum - $pages_around - 1))
180      {
181        $navbar.= ' ...';
182      }
[1090]183
[1084]184      $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>';
[643]185    }
[1090]186
[644]187    $navbar.= ' | ';
[643]188    // link on next page ?
[1084]189    if ($nb_element > $nb_element_page
190        and $start + $nb_element_page < $nb_element)
[476]191    {
192      $next = $start + $nb_element_page;
[1090]193
[1084]194      $navbar.=
195        '<a href="'.$url.$start_str.$next.'" rel="next">'
[2201]196        .l10n('next_page')
[1084]197        .'</a>';
[476]198    }
[643]199    else
200    {
[2201]201      $navbar.= l10n('next_page');
[643]202    }
[1090]203
[647]204    $navbar.= ' | ';
[643]205    // link to last page ?
206    if ($cur_page != $maximum)
207    {
208      $temp_start = ($maximum - 1) * $nb_element_page;
[1090]209
[1084]210      $navbar.=
211        '<a href="'.$url.$start_str.$temp_start.'" rel="last">'
[2201]212        .l10n('last_page')
[1084]213        .'</a>';
[643]214    }
215    else
216    {
[2201]217      $navbar.= l10n('last_page');
[643]218    }
[476]219  }
[644]220  return $navbar;
[476]221}
222
[572]223/**
224 * returns the list of categories as a HTML string
225 *
226 * categories string returned contains categories as given in the input
[1866]227 * array $cat_informations. $cat_informations array must be an array
228 * of array( id=>?, name=>?, permalink=>?). If url input parameter is null,
[572]229 * returns only the categories name without links.
230 *
231 * @param array cat_informations
232 * @param string url
233 * @param boolean replace_space
234 * @return string
235 */
[569]236function get_cat_display_name($cat_informations,
[1092]237                              $url = '',
[569]238                              $replace_space = true)
[476]239{
[642]240  global $conf;
[1090]241
[476]242  $output = '';
[569]243  $is_first = true;
[1866]244  foreach ($cat_informations as $cat)
[476]245  {
[1861]246    is_array($cat) or trigger_error(
[1866]247        'get_cat_display_name wrong type for category ', E_USER_WARNING
[1861]248      );
[2433]249
250    $cat['name'] = trigger_event(
251      'render_category_name',
252      $cat['name'],
253      'get_cat_display_name'
254      );
255
[569]256    if ($is_first)
257    {
258      $is_first = false;
259    }
260    else
261    {
[642]262      $output.= $conf['level_separator'];
[569]263    }
264
[1092]265    if ( !isset($url) )
[569]266    {
[1861]267      $output.= $cat['name'];
[569]268    }
[1092]269    elseif ($url == '')
270    {
[1789]271      $output.= '<a href="'
[1748]272            .make_index_url(
[1131]273                array(
[1861]274                  'category' => $cat,
[1748]275                  )
[1131]276              )
277            .'">';
[1861]278      $output.= $cat['name'].'</a>';
[1092]279    }
[569]280    else
281    {
[1866]282      $output.= '<a href="'.PHPWG_ROOT_PATH.$url.$cat['id'].'">';
[1861]283      $output.= $cat['name'].'</a>';
[569]284    }
[476]285  }
[569]286  if ($replace_space)
287  {
288    return replace_space($output);
289  }
290  else
291  {
292    return $output;
293  }
[476]294}
295
296/**
[610]297 * returns the list of categories as a HTML string, with cache of names
298 *
299 * categories string returned contains categories as given in the input
300 * array $cat_informations. $uppercats is the list of category ids to
301 * display in the right order. If url input parameter is empty, returns only
302 * the categories name without links.
303 *
304 * @param string uppercats
305 * @param string url
306 * @param boolean replace_space
307 * @return string
308 */
309function get_cat_display_name_cache($uppercats,
[1092]310                                    $url = '',
[610]311                                    $replace_space = true)
312{
[1861]313  global $cache, $conf;
[610]314
[1861]315  if (!isset($cache['cat_names']))
[610]316  {
317    $query = '
[1866]318SELECT id, name, permalink
[610]319  FROM '.CATEGORIES_TABLE.'
320;';
[1866]321    $cache['cat_names'] = hash_from_query($query, 'id');
[610]322  }
[1090]323
[610]324  $output = '';
325  $is_first = true;
326  foreach (explode(',', $uppercats) as $category_id)
327  {
[1861]328    $cat = $cache['cat_names'][$category_id];
[1090]329
[2433]330    $cat['name'] = trigger_event(
331      'render_category_name',
332      $cat['name'],
333      'get_cat_display_name_cache'
334      );
335
[610]336    if ($is_first)
337    {
338      $is_first = false;
339    }
340    else
341    {
[642]342      $output.= $conf['level_separator'];
[610]343    }
344
[1092]345    if ( !isset($url) )
[610]346    {
[1861]347      $output.= $cat['name'];
[610]348    }
[1092]349    elseif ($url == '')
350    {
351      $output.= '
[1789]352<a href="'
[1131]353      .make_index_url(
354          array(
[1861]355            'category' => $cat,
[1131]356            )
357        )
[1861]358      .'">'.$cat['name'].'</a>';
[1092]359    }
[610]360    else
361    {
362      $output.= '
[1861]363<a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$cat['name'].'</a>';
[610]364    }
365  }
366  if ($replace_space)
367  {
368    return replace_space($output);
369  }
370  else
371  {
372    return $output;
373  }
374}
375
376/**
[1082]377 * returns the HTML code for a category item in the menu (for the main page)
[476]378 *
379 * HTML code generated uses logical list tags ul and each category is an
380 * item li. The paramter given is the category informations as an array,
[1641]381 * used keys are : id, name, nb_images, max_date_last, date_last
[1624]382 * count_images, count_categories
[476]383 *
[614]384 * @param array categories
[476]385 * @return string
386 */
[1861]387function get_html_menu_category($categories, $selected_category)
[476]388{
[614]389  $ref_level = 0;
[976]390  $level = 0;
[1036]391
[2070]392  $menu = trigger_event('get_html_menu_category', '',
393            $categories, $selected_category);
394  if (strlen($menu))
395  {
396    return $menu;
397  }
398
[614]399  foreach ($categories as $category)
400  {
[876]401    $level = substr_count($category['global_rank'], '.') + 1;
[614]402    if ($level > $ref_level)
403    {
[941]404      $menu.= "\n<ul>";
[614]405    }
[876]406    else if ($level == $ref_level)
407    {
[941]408      $menu.= "\n</li>";
[876]409    }
[614]410    else if ($level < $ref_level)
411    {
[645]412      // we may have to close more than one level at the same time...
[876]413      $menu.= "\n</li>";
[941]414      $menu.= str_repeat("\n</ul></li>",($ref_level-$level));
[614]415    }
416    $ref_level = $level;
[850]417
[941]418    $menu.= "\n\n".'<li';
[1861]419    if ($category['id'] == @$selected_category['id'])
[614]420    {
[850]421      $menu.= ' class="selected"';
[614]422    }
[850]423    $menu.= '>';
[1090]424
[1131]425    $url = make_index_url(
426            array(
[1861]427              'category' => $category
[1131]428              )
429            );
[1090]430
[1884]431    $title = get_display_images_count
432                (
433                  $category['nb_images'],
434                  $category['count_images'],
435                  $category['count_categories'],
436                  false,
437                  ' / '
438                );
439
[2070]440    $menu.= '<a href="'.$url.'"';
[1861]441    if ($selected_category!=null
442        and $category['id'] == $selected_category['id_uppercat'])
[1031]443    {
444      $menu.= ' rel="up"';
445    }
[2433]446    $menu.= ' title="'.$title.'">';
447    $menu.= trigger_event(
448      'render_category_name',
449      $category['name'],
450      'get_html_menu_category'
451      );
452    $menu.= '</a>';
[476]453
[1840]454    if ( $category['count_images']>0 )
455    {// at least one direct or indirect image
[1624]456      $menu.= "\n".'<span class="';
[1840]457      // at least one image in this category -> class menuInfoCat
[2117]458      $menu.= ($category['nb_images'] > 0 ? "menuInfoCat"
[1624]459                                          : "menuInfoCatByChild").'"';
[1884]460      $menu.= ' title=" '.$title.'">';
[1840]461      // show total number of images
462      $menu.= '['.$category['count_images'].']';
[831]463      $menu.= '</span>';
[614]464    }
[1643]465    $child_date_last = @$category['max_date_last']> @$category['date_last'];
[1641]466    $menu.= get_icon($category['max_date_last'], $child_date_last);
[476]467  }
[941]468
469  $menu.= str_repeat("\n</li></ul>",($level));
[1090]470
[476]471  return $menu;
472}
[579]473
474/**
475 * returns HTMLized comment contents retrieved from database
476 *
477 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
478 * italic, *word* becomes bolded
479 *
480 * @param string content
481 * @return string
482 */
483function parse_comment_content($content)
484{
[1031]485  $pattern = '/(https?:\/\/\S*)/';
486  $replacement = '<a href="$1" rel="nofollow">$1</a>';
487  $content = preg_replace($pattern, $replacement, $content);
488
[579]489  $content = nl2br($content);
[1090]490
[579]491  // replace _word_ by an underlined word
[1030]492  $pattern = '/\b_(\S*)_\b/';
493  $replacement = '<span style="text-decoration:underline;">$1</span>';
[579]494  $content = preg_replace($pattern, $replacement, $content);
[1090]495
[579]496  // replace *word* by a bolded word
[1030]497  $pattern = '/\b\*(\S*)\*\b/';
498  $replacement = '<span style="font-weight:bold;">$1</span>';
[579]499  $content = preg_replace($pattern, $replacement, $content);
[1090]500
[579]501  // replace /word/ by an italic word
[1031]502  $pattern = "/\/(\S*)\/(\s)/";
503  $replacement = '<span style="font-style:italic;">$1$2</span>';
504  $content = preg_replace($pattern, $replacement, $content);
[579]505
[1272]506  $content = '<div>'.$content.'</div>';
[579]507  return $content;
508}
[817]509
510function get_cat_display_name_from_id($cat_id,
[1092]511                                      $url = '',
[817]512                                      $replace_space = true)
513{
514  $cat_info = get_cat_info($cat_id);
[1861]515  return get_cat_display_name($cat_info['upper_names'], $url, $replace_space);
[817]516}
[1113]517
518/**
[1119]519 * Returns an HTML list of tags. It can be a multi select field or a list of
520 * checkboxes.
521 *
522 * @param string HTML field name
523 * @param array selected tag ids
524 * @return array
525 */
526function get_html_tag_selection(
527  $tags,
528  $fieldname,
529  $selecteds = array(),
530  $forbidden_categories = null
531  )
532{
533  global $conf;
[1131]534
[1201]535  if (count ($tags) == 0 )
536  {
537    return '';
538  }
[1119]539  $output = '<ul class="tagSelection">';
540  foreach ($tags as $tag)
541  {
542    $output.=
543      '<li>'
544      .'<label>'
545      .'<input type="checkbox" name="'.$fieldname.'[]"'
[1815]546      .' value="'.$tag['id'].'"'
[1119]547      ;
548
[1815]549    if (in_array($tag['id'], $selecteds))
[1119]550    {
551      $output.= ' checked="checked"';
552    }
[1131]553
[1119]554    $output.=
555      ' />'
[1290]556      .' '. $tag['name']
[1119]557      .'</label>'
558      .'</li>'
559      ."\n"
560      ;
561  }
562  $output.= '</ul>';
563
564  return $output;
565}
566
567function name_compare($a, $b)
568{
[1310]569  return strcmp(strtolower($a['name']), strtolower($b['name']));
[1119]570}
571
[2409]572function tag_alpha_compare($a, $b)
573{
574  return strcmp(strtolower($a['url_name']), strtolower($b['url_name']));
575}
576
[1119]577/**
[1113]578 * exits the current script (either exit or redirect)
579 */
580function access_denied()
581{
[2265]582  global $user;
[1113]583
584  $login_url =
585      get_root_url().'identification.php?redirect='
586      .urlencode(urlencode($_SERVER['REQUEST_URI']));
587
[2543]588  set_status_header(401);
[2029]589  if ( isset($user) and !is_a_guest() )
[1113]590  {
[2884]591    echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
[2201]592    echo '<div style="text-align:center;">'.l10n('access_forbiden').'<br />';
593    echo '<a href="'.get_root_url().'identification.php">'.l10n('identification').'</a>&nbsp;';
594    echo '<a href="'.make_index_url().'">'.l10n('home').'</a></div>';
[2543]595    echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size
[1113]596    exit();
597  }
598  else
599  {
[1649]600    redirect_html($login_url);
[1113]601  }
602}
[1288]603
604/**
[1652]605 * exits the current script with 403 code
606 * @param string msg a message to display
607 * @param string alternate_url redirect to this url
608 */
609function page_forbidden($msg, $alternate_url=null)
610{
611  set_status_header(403);
612  if ($alternate_url==null)
613    $alternate_url = make_index_url();
614  redirect_html( $alternate_url,
615    '<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
616<h1 style="text-align:left; font-size:36px;">Forbidden</h1><br/>'
617.$msg.'</div>',
618    5 );
619}
620
621/**
[1852]622 * exits the current script with 400 code
623 * @param string msg a message to display
624 * @param string alternate_url redirect to this url
625 */
626function bad_request($msg, $alternate_url=null)
627{
628  set_status_header(400);
629  if ($alternate_url==null)
630    $alternate_url = make_index_url();
631  redirect_html( $alternate_url,
632    '<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
633<h1 style="text-align:left; font-size:36px;">Bad request</h1><br/>'
634.$msg.'</div>',
635    5 );
636}
637
638/**
[1288]639 * exits the current script with 404 code when a page cannot be found
640 * @param string msg a message to display
641 * @param string alternate_url redirect to this url
642 */
643function page_not_found($msg, $alternate_url=null)
644{
[1643]645  set_status_header(404);
[1288]646  if ($alternate_url==null)
647    $alternate_url = make_index_url();
[1649]648  redirect_html( $alternate_url,
[1288]649    '<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
650<h1 style="text-align:left; font-size:36px;">Page not found</h1><br/>'
651.$msg.'</div>',
652    5 );
653}
[1606]654
[2502]655/**
656 * exits the current script with 500 http code
657 * this method can be called at any time (does not use template/language/user etc...)
658 * @param string msg a message to display
659 */
660function fatal_error($msg)
661{
662  $btrace_msg = '';
663  if (function_exists('debug_backtrace'))
664  {
665    $bt = debug_backtrace();
666    for ($i=1; $i<count($bt); $i++)
667    {
668      $class = isset($bt[$i]['class']) ? (@$bt[$i]['class'].'::') : '';
669      $btrace_msg .= "#$i\t".$class.@$bt[$i]['function'].' '.@$bt[$i]['file']."(".@$bt[$i]['line'].")\n";
670    }
671    $btrace_msg = trim($btrace_msg);
672    $msg .= "\n";
673  }
674
[2747]675  $display = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
676<h1>Piwigo encountered a non recoverable error</h1>
[2502]677<pre style='font-size:larger;background:white;color:red;padding:1em;margin:0;clear:both;display:block;width:auto;height:auto;overflow:auto'>
678<b>$msg</b>
679$btrace_msg
680</pre>\n";
681
682  @set_status_header(500);
[2543]683  echo $display.str_repeat( ' ', 300); //IE6 doesn't error output if below a size
[2502]684
685  if ( function_exists('ini_set') )
686  {// if possible turn off error display (we display it)
687    ini_set('display_errors', false);
688  }
689  error_reporting( E_ALL );
690  trigger_error( strip_tags($msg).$btrace_msg, E_USER_ERROR );
691  die(0); // just in case
692}
693
[1606]694/* returns the title to be displayed above thumbnails on tag page
695 */
696function get_tags_content_title()
697{
698  global $page;
699  $title = count($page['tags']) > 1 ? l10n('Tags') : l10n('Tag');
700  $title.= ' ';
701
702  for ($i=0; $i<count($page['tags']); $i++)
703  {
704    $title.= $i>0 ? ' + ' : '';
705
706    $title.=
707      '<a href="'
708      .make_index_url(
709        array(
710          'tags' => array( $page['tags'][$i] )
711          )
712        )
713      .'" title="'
[2265]714      .l10n('See elements linked to this tag only')
[1606]715      .'">'
716      .$page['tags'][$i]['name']
717      .'</a>';
718
719    if ( count($page['tags'])>2 )
720    {
721      $other_tags = $page['tags'];
722      unset ( $other_tags[$i] );
723      $title.=
724        '<a href="'
725        .make_index_url(
726          array(
727            'tags' => $other_tags
728            )
729          )
730        .'" style="border:none;" title="'
731        .l10n('remove this tag')
732        .'"><img src="'
733        .get_root_url().get_themeconf('icon_dir').'/remove_s.png'
734        .'" alt="x" style="vertical-align:bottom;" class="button"/>'
735        .'</a>';
736    }
737
738  }
739  return $title;
740}
[1643]741
742/**
743  Sets the http status header (200,401,...)
744 */
745function set_status_header($code, $text='')
746{
747  if (empty($text))
748  {
749    switch ($code)
750    {
751      case 200: $text='OK';break;
752      case 301: $text='Moved permanently';break;
753      case 302: $text='Moved temporarily';break;
754      case 304: $text='Not modified';break;
755      case 400: $text='Bad request';break;
756      case 401: $text='Authorization required';break;
757      case 403: $text='Forbidden';break;
758      case 404: $text='Not found';break;
[2053]759      case 500: $text='Server error';break;
[2543]760      case 501: $text='Not implemented';break;
[2053]761      case 503: $text='Service unavailable';break;
[1643]762    }
763  }
[2053]764        $protocol = $_SERVER["SERVER_PROTOCOL"];
765        if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
766                $protocol = 'HTTP/1.0';
767
768        if ( version_compare( phpversion(), '4.3.0', '>=' ) )
769  {
770                header( "$protocol $code $text", true, $code );
771        }
772  else
773  {
774                header( "$protocol $code $text" );
775        }
[1744]776  trigger_action('set_status_header', $code, $text);
[1643]777}
[1769]778
[2117]779/** returns the category comment for rendering in html.
780 * this is an event handler. don't call directly
781 */
782function render_category_description($desc)
783{
784  global $conf;
[2773]785  if ( !$conf['allow_html_descriptions'] )
[2117]786  {
787    $desc = nl2br($desc);
788  }
789  return $desc;
790}
791
792/** returns the category comment for rendering in html textual mode (subcatify)
793 * this is an event handler. don't call directly
794 */
795function render_category_literal_description($desc)
796{
797  return strip_tags($desc, '<span><p><a><br><b><i><small><big><strong><em>');
798}
[2349]799
[2409]800/** returns the argument_ids array with new sequenced keys based on related
[2349]801 * names. Sequence is not case sensitive.
802 * Warning: By definition, this function breaks original keys
803 */
804function order_by_name($element_ids,$name)
805{
806  $ordered_element_ids = array();
807  foreach ($element_ids as $k_id => $element_id)
808  {
809    $key = strtolower($name[$element_id]) .'-'. $name[$element_id] .'-'. $k_id;
810    $ordered_element_ids[$key] = $element_id;
811  }
812  ksort($ordered_element_ids);
813  return $ordered_element_ids;
814}
815
[2488]816/*event handler for menu*/
817function register_default_menubar_blocks( $menu_ref_arr )
818{
819  $menu = & $menu_ref_arr[0];
820  if ($menu->get_id() != 'menubar')
821    return;
822  $menu->register_block( new RegisteredBlock( 'mbLinks', 'Links', 'piwigo'));
823  $menu->register_block( new RegisteredBlock( 'mbCategories', 'Categories', 'piwigo'));
824  $menu->register_block( new RegisteredBlock( 'mbTags', 'Related tags', 'piwigo'));
825  $menu->register_block( new RegisteredBlock( 'mbSpecials', 'special_categories', 'piwigo'));
826  $menu->register_block( new RegisteredBlock( 'mbMenu', 'title_menu', 'piwigo'));
827  $menu->register_block( new RegisteredBlock( 'mbIdentification', 'identification', 'piwigo') );
828}
829
[2773]830?>
Note: See TracBrowser for help on using the repository browser.