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

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

improvement: got rid of num= _GET param in category.php (use only start=) so
that links to category for search engines are the same as in category
pagination

feature 77: standard navigation link : HTML Link types

improvement: add go to first and last image buttons in picture page

improvement: do not increase image hit in picture.php when rating, adding to
favorites, caddie, ...

improvement: show number of hits in most_visited (as best_rated shows the rate)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-01-27 01:11:43 +0000 (Fri, 27 Jan 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1014 $
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
28function get_icon( $date )
29{
30  global $user, $conf, $lang;
31
32  if (!preg_match('/\d{4}-\d{2}-\d{2}/', $date))
33  {
34    return '';
35  }
36
37  list( $year,$month,$day ) = explode( '-', $date );
38  $unixtime = mktime( 0, 0, 0, $month, $day, $year );
39 
40  $diff = time() - $unixtime;
41  $day_in_seconds = 24*60*60;
42  $output = '';
43  $title = $lang['recent_image'].'&nbsp;';
44  if ( $diff < $user['recent_period'] * $day_in_seconds )
45  {
46    $icon_url = get_themeconf('icon_dir').'/recent.png';
47    $title .= $user['recent_period'];
48    $title .=  '&nbsp;'.$lang['days'];
49    $size = getimagesize( $icon_url );
50    $output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;';
51    $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />';
52  }
53  return $output;
54}
55
56function create_navigation_bar($url, $nb_element, $start,
57                               $nb_element_page, $link_class)
58{
59  global $lang, $conf;
60
61  $pages_around = $conf['paginate_pages_around'];
62 
63  $navbar = '';
64 
65  // current page detection
66  if (!isset($start)
67      or !is_numeric($start)
68      or (is_numeric($start) and $start < 0))
69  {
70    $start = 0;
71  }
72 
73  // navigation bar useful only if more than one page to display !
74  if ($nb_element > $nb_element_page)
75  {
76    // current page and last page
77    $cur_page = ceil($start / $nb_element_page) + 1;
78    $maximum = ceil($nb_element / $nb_element_page);
79
80    // link to first page ?
81    if ($cur_page != 1)
82    {
83      $navbar.= '<a href="';
84      $navbar.= $url.'&amp;start=0';
85      $navbar.= '" class="'.$link_class.'" rel="start">'.$lang['first_page'];
86      $navbar.= '</a>';
87    }
88    else
89    {
90      $navbar.= $lang['first_page'];
91    }
92    $navbar.= ' | ';
93    // link on previous page ?
94    if ( $start != 0 )
95    {
96      $previous = $start - $nb_element_page;
97      $navbar.= '<a href="';
98      $navbar.= $url.'&amp;start='.$previous;
99      $navbar.= '" class="'.$link_class.'" rel="prev">'.$lang['previous_page'];
100      $navbar.= '</a>';
101    }
102    else
103    {
104      $navbar.= $lang['previous_page'];
105    }
106    $navbar.= ' | ';
107
108    if ($cur_page > $pages_around + 1)
109    {
110      $navbar.= '&nbsp;<a href="';
111      $navbar.= $url.'&amp;start=0';
112      $navbar.= '" class="'.$link_class.'">1</a>';
113      if ($cur_page > $pages_around + 2)
114      {
115        $navbar.= ' ...';
116      }
117    }
118   
119    // inspired from punbb source code
120    for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1;
121         $i < $stop;
122         $i++)
123    {
124      if ($i < 1 or $i > $maximum)
125      {
126        continue;
127      }
128      else if ($i != $cur_page)
129      {
130        $temp_start = ($i - 1) * $nb_element_page;
131        $navbar.= '&nbsp;<a href="';
132        $navbar.= $url.'&amp;start='.$temp_start;
133        $navbar.= '" class="'.$link_class.'"';
134        if ($i == $cur_page - 1)
135        {
136          $navbar.= ' rel="prev"';
137        }
138        if ($i == $cur_page + 1)
139        {
140          $navbar.= ' rel="next"';
141        }
142        $navbar.='>'.$i.'</a>';
143      }
144      else
145      {
146        $navbar.= '&nbsp;<span class="pageNumberSelected">';
147        $navbar.= $i.'</span>';
148      }
149    }
150
151    if ($cur_page < ($maximum - $pages_around))
152    {
153      $temp_start = ($maximum - 1) * $nb_element_page;
154      if ($cur_page < ($maximum - $pages_around - 1))
155      {
156        $navbar.= ' ...';
157      }
158      $navbar.= ' <a href="';
159      $navbar.= $url.'&amp;start='.$temp_start;
160      $navbar.= '" class="'.$link_class.'">'.$maximum.'</a>';
161    }
162   
163    $navbar.= ' | ';
164    // link on next page ?
165    if ( $nb_element > $nb_element_page
166         && $start + $nb_element_page < $nb_element )
167    {
168      $next = $start + $nb_element_page;
169      $navbar.= '<a href="';
170      $navbar.= $url.'&amp;start='.$next;
171      $navbar.= '" class="'.$link_class.'" rel="next">'.$lang['next_page'].'</a>';
172    }
173    else
174    {
175      $navbar.= $lang['next_page'];
176    }
177   
178    $navbar.= ' | ';
179    // link to last page ?
180    if ($cur_page != $maximum)
181    {
182      $temp_start = ($maximum - 1) * $nb_element_page;
183      $navbar.= '<a href="';
184      $navbar.= $url.'&amp;start='.$temp_start;
185      $navbar.= '" class="'.$link_class.'">'.$lang['last_page'];
186      $navbar.= '</a>';
187    }
188    else
189    {
190      $navbar.= $lang['last_page'];
191    }
192  }
193  return $navbar;
194}
195
196//
197// Pick a language, any language ...
198//
199function language_select($default, $select_name = "language")
200{
201  $available_lang = get_languages();
202
203  $lang_select = '<select name="' . $select_name . '">';
204  foreach ($available_lang as $code => $displayname)
205  {
206    $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
207    $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
208  }
209  $lang_select .= '</select>';
210
211  return $lang_select;
212}
213
214/**
215 * returns the list of categories as a HTML string
216 *
217 * categories string returned contains categories as given in the input
218 * array $cat_informations. $cat_informations array must be an association
219 * of {category_id => category_name}. If url input parameter is empty,
220 * returns only the categories name without links.
221 *
222 * @param array cat_informations
223 * @param string url
224 * @param boolean replace_space
225 * @return string
226 */
227function get_cat_display_name($cat_informations,
228                              $url = 'category.php?cat=',
229                              $replace_space = true)
230{
231  global $conf;
232 
233  $output = '';
234  $is_first = true;
235  foreach ($cat_informations as $id => $name)
236  {
237    if ($is_first)
238    {
239      $is_first = false;
240    }
241    else
242    {
243      $output.= $conf['level_separator'];
244    }
245
246    if ($url == '')
247    {
248      $output.= $name;
249    }
250    else
251    {
252      $output.= '<a class=""';
253      $output.= ' href="'.PHPWG_ROOT_PATH.$url.$id.'">';
254      $output.= $name.'</a>';
255    }
256  }
257  if ($replace_space)
258  {
259    return replace_space($output);
260  }
261  else
262  {
263    return $output;
264  }
265}
266
267/**
268 * returns the list of categories as a HTML string, with cache of names
269 *
270 * categories string returned contains categories as given in the input
271 * array $cat_informations. $uppercats is the list of category ids to
272 * display in the right order. If url input parameter is empty, returns only
273 * the categories name without links.
274 *
275 * @param string uppercats
276 * @param string url
277 * @param boolean replace_space
278 * @return string
279 */
280function get_cat_display_name_cache($uppercats,
281                                    $url = 'category.php?cat=',
282                                    $replace_space = true)
283{
284  global $cat_names, $conf;
285
286  if (!isset($cat_names))
287  {
288    $query = '
289SELECT id,name
290  FROM '.CATEGORIES_TABLE.'
291;';
292    $result = pwg_query($query);
293    while ($row = mysql_fetch_array($result))
294    {
295      $cat_names[$row['id']] = $row['name'];
296    }
297  }
298 
299  $output = '';
300  $is_first = true;
301  foreach (explode(',', $uppercats) as $category_id)
302  {
303    $name = $cat_names[$category_id];
304   
305    if ($is_first)
306    {
307      $is_first = false;
308    }
309    else
310    {
311      $output.= $conf['level_separator'];
312    }
313
314    if ($url == '')
315    {
316      $output.= $name;
317    }
318    else
319    {
320      $output.= '
321<a class=""
322   href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$name.'</a>';
323    }
324  }
325  if ($replace_space)
326  {
327    return replace_space($output);
328  }
329  else
330  {
331    return $output;
332  }
333}
334
335/**
336 * returns the HTML code for a category item in the menu (for category.php)
337 *
338 * HTML code generated uses logical list tags ul and each category is an
339 * item li. The paramter given is the category informations as an array,
340 * used keys are : id, name, nb_images, date_last
341 *
342 * @param array categories
343 * @return string
344 */
345function get_html_menu_category($categories)
346{
347  global $page, $lang;
348
349  $ref_level = 0;
350  $level = 0;
351  $menu = '';
352 
353  foreach ($categories as $category)
354  {
355    $level = substr_count($category['global_rank'], '.') + 1;
356    if ($level > $ref_level)
357    {
358      $menu.= "\n<ul>";
359    }
360    else if ($level == $ref_level)
361    {
362      $menu.= "\n</li>";
363    }
364    else if ($level < $ref_level)
365    {
366      // we may have to close more than one level at the same time...
367      $menu.= "\n</li>";
368      $menu.= str_repeat("\n</ul></li>",($ref_level-$level));
369    }
370    $ref_level = $level;
371
372    $menu.= "\n\n".'<li';
373    if (isset($page['cat'])
374        and is_numeric($page['cat'])
375        and $category['id'] == $page['cat'])
376    {
377      $menu.= ' class="selected"';
378    }
379    $menu.= '>';
380 
381    $url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id'];
382    $menu.= "\n".'<a href="'.$url.'">'.$category['name'].'</a>';
383
384    if ($category['nb_images'] > 0)
385    {
386      $menu.= "\n".'<span class="menuInfoCat"';
387      $menu.= ' title="'.$category['nb_images'];
388      $menu.= ' '.$lang['images_available'].'">';
389      $menu.= '['.$category['nb_images'].']';
390      $menu.= '</span>';
391      $menu.= get_icon($category['date_last']);
392    }
393  }
394
395  $menu.= str_repeat("\n</li></ul>",($level));
396 
397  return $menu;
398}
399
400/**
401 * returns HTMLized comment contents retrieved from database
402 *
403 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
404 * italic, *word* becomes bolded
405 *
406 * @param string content
407 * @return string
408 */
409function parse_comment_content($content)
410{
411  $content = nl2br($content);
412 
413  // replace _word_ by an underlined word
414  $pattern = '/_([^\s]*)_/';
415  $replacement = '<span style="text-decoration:underline;">\1</span>';
416  $content = preg_replace($pattern, $replacement, $content);
417 
418  // replace *word* by a bolded word
419  $pattern = '/\*([^\s]*)\*/';
420  $replacement = '<span style="font-weight:bold;">\1</span>';
421  $content = preg_replace($pattern, $replacement, $content);
422 
423  // replace /word/ by an italic word
424  $pattern = '/\/([^\s]*)\//';
425  $replacement = '<span style="font-style:italic;">\1</span>';
426  $content = preg_replace($pattern, $replacement, $content);
427
428  return $content;
429}
430
431function get_cat_display_name_from_id($cat_id,
432                                      $url = 'category.php?cat=',
433                                      $replace_space = true)
434{
435  $cat_info = get_cat_info($cat_id);
436  return get_cat_display_name($cat_info['name'], $url, $replace_space);
437}
438?>
Note: See TracBrowser for help on using the repository browser.