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

Last change on this file since 675 was 675, checked in by plg, 19 years ago

all headers adapted to new year 2005, happy new year

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