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

Last change on this file since 1110 was 1092, checked in by rvelices, 18 years ago

URL rewriting: capable of fully working with urls without ?

URL rewriting: works with image file instead of image id (change
make_picture_url to generate urls with file name instead of image id)

URL rewriting: completely works with category/best_rated and
picture/best_rated/534 (change 'category.php?' to 'category' in make_index_url
and 'picture.php?' to 'picture' in make_picture_url to see it)

fix: picture category display in upper bar

fix: function rate_picture variables and use of the new user type

fix: caddie icon appears now on category page

fix: admin element_set sql query was using storage_category_id column
(column has moved to #image_categories)

fix: replaced some old $_GET[xxx] with $page[xxx]

fix: pictures have metadata url (use ? parameter - might change later)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
RevLine 
[476]1<?php
2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[476]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[476]8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-22 01:01:47 +0000 (Wed, 22 Mar 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1092 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
[1040]28function get_icon($date)
[476]29{
[1040]30  global $page, $user, $conf, $lang;
[476]31
[1040]32  if (empty($date))
[492]33  {
[1040]34    $date = 'NULL';
[492]35  }
36
[1040]37  if (isset($page['get_icon_cache'][$date]))
38  {
39    return $page['get_icon_cache'][$date];
40  }
41
42  if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $matches))
43  {
44    // date can be empty, no icon to display
45    $page['get_icon_cache'][$date] = '';
46    return $page['get_icon_cache'][$date];
47  }
[1090]48
[1040]49  list($devnull, $year, $month, $day) = $matches;
[476]50  $unixtime = mktime( 0, 0, 0, $month, $day, $year );
[1040]51
52  if ($unixtime === false  // PHP 5.1.0 and above
53      or $unixtime === -1) // PHP prior to 5.1.0
54  {
55    $page['get_icon_cache'][$date] = '';
56    return $page['get_icon_cache'][$date];
57  }
[1090]58
[476]59  $diff = time() - $unixtime;
60  $day_in_seconds = 24*60*60;
61  $output = '';
62  $title = $lang['recent_image'].'&nbsp;';
63  if ( $diff < $user['recent_period'] * $day_in_seconds )
64  {
[960]65    $icon_url = get_themeconf('icon_dir').'/recent.png';
[476]66    $title .= $user['recent_period'];
67    $title .=  '&nbsp;'.$lang['days'];
68    $size = getimagesize( $icon_url );
[1092]69    $icon_url = get_root_url().$icon_url;
[948]70    $output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;';
71    $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
[476]72  }
[1040]73
74  $page['get_icon_cache'][$date] = $output;
75
76  return $page['get_icon_cache'][$date];
[476]77}
78
[1084]79function create_navigation_bar(
80  $url, $nb_element, $start, $nb_element_page, $clean_url = false
81  )
[476]82{
[643]83  global $lang, $conf;
84
85  $pages_around = $conf['paginate_pages_around'];
[1084]86  $start_str = $clean_url ? '/start-' : '&amp;start=';
[1090]87
[644]88  $navbar = '';
[1090]89
[643]90  // current page detection
91  if (!isset($start)
92      or !is_numeric($start)
93      or (is_numeric($start) and $start < 0))
[476]94  {
95    $start = 0;
96  }
[1090]97
[643]98  // navigation bar useful only if more than one page to display !
99  if ($nb_element > $nb_element_page)
[476]100  {
[644]101    // current page and last page
[643]102    $cur_page = ceil($start / $nb_element_page) + 1;
103    $maximum = ceil($nb_element / $nb_element_page);
104
105    // link to first page ?
106    if ($cur_page != 1)
107    {
[1084]108      $navbar.=
109        '<a href="'.$url.'" rel="start">'
110        .$lang['first_page']
111        .'</a>';
[643]112    }
113    else
114    {
[644]115      $navbar.= $lang['first_page'];
[643]116    }
[644]117    $navbar.= ' | ';
[643]118    // link on previous page ?
[1084]119    if ($start != 0)
[476]120    {
121      $previous = $start - $nb_element_page;
[1090]122
[1084]123      $navbar.=
124        '<a href="'
125        .$url.($previous > 0 ? $start_str.$previous : '')
126        .'" rel="prev">'
127        .$lang['previous_page']
128        .'</a>';
[476]129    }
[643]130    else
[476]131    {
[644]132      $navbar.= $lang['previous_page'];
[643]133    }
[1031]134    $navbar.= ' |';
[643]135
136    if ($cur_page > $pages_around + 1)
137    {
[1084]138      $navbar.= '&nbsp;<a href="'.$url.'">1</a>';
[1090]139
[678]140      if ($cur_page > $pages_around + 2)
141      {
142        $navbar.= ' ...';
143      }
[643]144    }
[1090]145
[643]146    // inspired from punbb source code
147    for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1;
148         $i < $stop;
149         $i++)
150    {
151      if ($i < 1 or $i > $maximum)
[476]152      {
[643]153        continue;
[476]154      }
[643]155      else if ($i != $cur_page)
156      {
157        $temp_start = ($i - 1) * $nb_element_page;
[1090]158
[1084]159        $navbar.=
160          '&nbsp;'
161          .'<a href="'.$url
162          .($temp_start > 0 ? $start_str.$temp_start : '')
163          .'">'
164          .$i
165          .'</a>';
[643]166      }
[476]167      else
168      {
[1084]169        $navbar.=
170          '&nbsp;'
171          .'<span class="pageNumberSelected">'
172          .$i
173          .'</span>';
[476]174      }
175    }
[643]176
177    if ($cur_page < ($maximum - $pages_around))
178    {
179      $temp_start = ($maximum - 1) * $nb_element_page;
[1090]180
[678]181      if ($cur_page < ($maximum - $pages_around - 1))
182      {
183        $navbar.= ' ...';
184      }
[1090]185
[1084]186      $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>';
[643]187    }
[1090]188
[644]189    $navbar.= ' | ';
[643]190    // link on next page ?
[1084]191    if ($nb_element > $nb_element_page
192        and $start + $nb_element_page < $nb_element)
[476]193    {
194      $next = $start + $nb_element_page;
[1090]195
[1084]196      $navbar.=
197        '<a href="'.$url.$start_str.$next.'" rel="next">'
198        .$lang['next_page']
199        .'</a>';
[476]200    }
[643]201    else
202    {
[644]203      $navbar.= $lang['next_page'];
[643]204    }
[1090]205
[647]206    $navbar.= ' | ';
[643]207    // link to last page ?
208    if ($cur_page != $maximum)
209    {
210      $temp_start = ($maximum - 1) * $nb_element_page;
[1090]211
[1084]212      $navbar.=
213        '<a href="'.$url.$start_str.$temp_start.'" rel="last">'
214        .$lang['last_page']
215        .'</a>';
[643]216    }
217    else
218    {
[644]219      $navbar.= $lang['last_page'];
[643]220    }
[476]221  }
[644]222  return $navbar;
[476]223}
224
225//
226// Pick a language, any language ...
227//
228function language_select($default, $select_name = "language")
229{
[512]230  $available_lang = get_languages();
[476]231
[817]232  $lang_select = '<select name="' . $select_name . '">';
[528]233  foreach ($available_lang as $code => $displayname)
[476]234  {
235    $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
236    $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
237  }
238  $lang_select .= '</select>';
239
240  return $lang_select;
241}
242
[572]243/**
244 * returns the list of categories as a HTML string
245 *
246 * categories string returned contains categories as given in the input
247 * array $cat_informations. $cat_informations array must be an association
[1092]248 * of {category_id => category_name}. If url input parameter is null,
[572]249 * returns only the categories name without links.
250 *
251 * @param array cat_informations
252 * @param string url
253 * @param boolean replace_space
254 * @return string
255 */
[569]256function get_cat_display_name($cat_informations,
[1092]257                              $url = '',
[569]258                              $replace_space = true)
[476]259{
[642]260  global $conf;
[1090]261
[476]262  $output = '';
[569]263  $is_first = true;
264  foreach ($cat_informations as $id => $name)
[476]265  {
[569]266    if ($is_first)
267    {
268      $is_first = false;
269    }
270    else
271    {
[642]272      $output.= $conf['level_separator'];
[569]273    }
274
[1092]275    if ( !isset($url) )
[569]276    {
277      $output.= $name;
278    }
[1092]279    elseif ($url == '')
280    {
281      $output.= '<a class=""';
282      $output.= ' href="'.make_index_url( array('category'=>$id) ).'">';
283      $output.= $name.'</a>';
284    }
[569]285    else
286    {
[825]287      $output.= '<a class=""';
[1004]288      $output.= ' href="'.PHPWG_ROOT_PATH.$url.$id.'">';
[825]289      $output.= $name.'</a>';
[569]290    }
[476]291  }
[569]292  if ($replace_space)
293  {
294    return replace_space($output);
295  }
296  else
297  {
298    return $output;
299  }
[476]300}
301
302/**
[610]303 * returns the list of categories as a HTML string, with cache of names
304 *
305 * categories string returned contains categories as given in the input
306 * array $cat_informations. $uppercats is the list of category ids to
307 * display in the right order. If url input parameter is empty, returns only
308 * the categories name without links.
309 *
310 * @param string uppercats
311 * @param string url
312 * @param boolean replace_space
313 * @return string
314 */
315function get_cat_display_name_cache($uppercats,
[1092]316                                    $url = '',
[610]317                                    $replace_space = true)
318{
[642]319  global $cat_names, $conf;
[610]320
321  if (!isset($cat_names))
322  {
323    $query = '
324SELECT id,name
325  FROM '.CATEGORIES_TABLE.'
326;';
327    $result = pwg_query($query);
328    while ($row = mysql_fetch_array($result))
329    {
330      $cat_names[$row['id']] = $row['name'];
331    }
332  }
[1090]333
[610]334  $output = '';
335  $is_first = true;
336  foreach (explode(',', $uppercats) as $category_id)
337  {
338    $name = $cat_names[$category_id];
[1090]339
[610]340    if ($is_first)
341    {
342      $is_first = false;
343    }
344    else
345    {
[642]346      $output.= $conf['level_separator'];
[610]347    }
348
[1092]349    if ( !isset($url) )
[610]350    {
351      $output.= $name;
352    }
[1092]353    elseif ($url == '')
354    {
355      $output.= '
356<a class=""
357   href="'.make_index_url( array('category'=>$category_id) ).'">'.$name.'</a>';
358    }
[610]359    else
360    {
361      $output.= '
362<a class=""
[1004]363   href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$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,
[614]381 * used keys are : id, name, nb_images, date_last
[476]382 *
[614]383 * @param array categories
[476]384 * @return string
385 */
[614]386function get_html_menu_category($categories)
[476]387{
388  global $page, $lang;
389
[614]390  $ref_level = 0;
[976]391  $level = 0;
[876]392  $menu = '';
[1036]393
394  // $page_cat value remains 0 for special sections
[1031]395  $page_cat = 0;
[1082]396  if (isset($page['category']))
[1031]397  {
[1082]398    $page_cat = $page['category'];
[1031]399  }
[1090]400
[614]401  foreach ($categories as $category)
402  {
[876]403    $level = substr_count($category['global_rank'], '.') + 1;
[614]404    if ($level > $ref_level)
405    {
[941]406      $menu.= "\n<ul>";
[614]407    }
[876]408    else if ($level == $ref_level)
409    {
[941]410      $menu.= "\n</li>";
[876]411    }
[614]412    else if ($level < $ref_level)
413    {
[645]414      // we may have to close more than one level at the same time...
[876]415      $menu.= "\n</li>";
[941]416      $menu.= str_repeat("\n</ul></li>",($ref_level-$level));
[614]417    }
418    $ref_level = $level;
[850]419
[941]420    $menu.= "\n\n".'<li';
[1031]421    if ($category['id'] == $page_cat)
[614]422    {
[850]423      $menu.= ' class="selected"';
[614]424    }
[850]425    $menu.= '>';
[1090]426
[1082]427    $url = make_index_url(array('category' => $category['id']));
[1090]428
[1031]429    $menu.= "\n".'<a href="'.$url.'"';
[1036]430    if ($page_cat != 0
431        and $category['id'] == $page['cat_id_uppercat'])
[1031]432    {
433      $menu.= ' rel="up"';
434    }
435    $menu.= '>'.$category['name'].'</a>';
[476]436
[614]437    if ($category['nb_images'] > 0)
438    {
[941]439      $menu.= "\n".'<span class="menuInfoCat"';
[831]440      $menu.= ' title="'.$category['nb_images'];
441      $menu.= ' '.$lang['images_available'].'">';
442      $menu.= '['.$category['nb_images'].']';
443      $menu.= '</span>';
444      $menu.= get_icon($category['date_last']);
[614]445    }
[476]446  }
[941]447
448  $menu.= str_repeat("\n</li></ul>",($level));
[1090]449
[476]450  return $menu;
451}
[579]452
453/**
454 * returns HTMLized comment contents retrieved from database
455 *
456 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
457 * italic, *word* becomes bolded
458 *
459 * @param string content
460 * @return string
461 */
462function parse_comment_content($content)
463{
[1031]464  $pattern = '/(https?:\/\/\S*)/';
465  $replacement = '<a href="$1" rel="nofollow">$1</a>';
466  $content = preg_replace($pattern, $replacement, $content);
467
[579]468  $content = nl2br($content);
[1090]469
[579]470  // replace _word_ by an underlined word
[1030]471  $pattern = '/\b_(\S*)_\b/';
472  $replacement = '<span style="text-decoration:underline;">$1</span>';
[579]473  $content = preg_replace($pattern, $replacement, $content);
[1090]474
[579]475  // replace *word* by a bolded word
[1030]476  $pattern = '/\b\*(\S*)\*\b/';
477  $replacement = '<span style="font-weight:bold;">$1</span>';
[579]478  $content = preg_replace($pattern, $replacement, $content);
[1090]479
[579]480  // replace /word/ by an italic word
[1031]481  $pattern = "/\/(\S*)\/(\s)/";
482  $replacement = '<span style="font-style:italic;">$1$2</span>';
483  $content = preg_replace($pattern, $replacement, $content);
[579]484
[1031]485  $content = '<div>'.$content.'</div>';
[579]486  return $content;
487}
[817]488
489function get_cat_display_name_from_id($cat_id,
[1092]490                                      $url = '',
[817]491                                      $replace_space = true)
492{
493  $cat_info = get_cat_info($cat_id);
[825]494  return get_cat_display_name($cat_info['name'], $url, $replace_space);
[817]495}
[476]496?>
Note: See TracBrowser for help on using the repository browser.