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

Last change on this file since 647 was 647, checked in by plg, 19 years ago
  • bug fixed : in admin/cat_list, next_rank cant' be calculted and query to count sub-categories per sub-categories became false if no sub-categories
  • virtual association come back in admin/infos_images (not only in admin/picture_modify)
  • check_favorites function in admin section becomes check_user_favorites in public section : favorites are checked when user tries to display his favorites. Function was optimized.
  • in function update_category, wrap of long queries due to many categories to update at the same time
  • typo fixed in description of paginate_pages_around configuration parameter
  • bug fixed in new navigation bar : no separation pipe was displayed between next and last when the page displayed was the last
  • sessions.expiration changed of type from int to datetime (a lot easier to read)
  • sessions.ip removed : IP address is no longer used to verify session
  • typo fixed in language/en_UK.iso-8859-1/admin.lang.php on editcat_lock_info language item
  • 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-18 22:05:30 +0000 (Sat, 18 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 647 $
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 separator
226 * @param string url
227 * @param boolean replace_space
228 * @return string
229 */
230function get_cat_display_name($cat_informations,
231                              $url = 'category.php?cat=',
232                              $replace_space = true)
233{
234  global $conf;
235 
236  $output = '';
237  $is_first = true;
238  foreach ($cat_informations as $id => $name)
239  {
240    if ($is_first)
241    {
242      $is_first = false;
243    }
244    else
245    {
246      $output.= $conf['level_separator'];
247    }
248
249    if ($url == '')
250    {
251      $output.= $name;
252    }
253    else
254    {
255      $output.= '
256<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name.'</a>';
257    }
258  }
259  if ($replace_space)
260  {
261    return replace_space($output);
262  }
263  else
264  {
265    return $output;
266  }
267}
268
269/**
270 * returns the list of categories as a HTML string, with cache of names
271 *
272 * categories string returned contains categories as given in the input
273 * array $cat_informations. $uppercats is the list of category ids to
274 * display in the right order. If url input parameter is empty, returns only
275 * the categories name without links.
276 *
277 * @param string uppercats
278 * @param string url
279 * @param boolean replace_space
280 * @return string
281 */
282function get_cat_display_name_cache($uppercats,
283                                    $url = 'category.php?cat=',
284                                    $replace_space = true)
285{
286  global $cat_names, $conf;
287
288  if (!isset($cat_names))
289  {
290    $query = '
291SELECT id,name
292  FROM '.CATEGORIES_TABLE.'
293;';
294    $result = pwg_query($query);
295    while ($row = mysql_fetch_array($result))
296    {
297      $cat_names[$row['id']] = $row['name'];
298    }
299  }
300 
301  $output = '';
302  $is_first = true;
303  foreach (explode(',', $uppercats) as $category_id)
304  {
305    $name = $cat_names[$category_id];
306   
307    if ($is_first)
308    {
309      $is_first = false;
310    }
311    else
312    {
313      $output.= $conf['level_separator'];
314    }
315
316    if ($url == '')
317    {
318      $output.= $name;
319    }
320    else
321    {
322      $output.= '
323<a class=""
324   href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>';
325    }
326  }
327  if ($replace_space)
328  {
329    return replace_space($output);
330  }
331  else
332  {
333    return $output;
334  }
335}
336
337/**
338 * returns the HTML code for a category item in the menu (for category.php)
339 *
340 * HTML code generated uses logical list tags ul and each category is an
341 * item li. The paramter given is the category informations as an array,
342 * used keys are : id, name, nb_images, date_last
343 *
344 * @param array categories
345 * @return string
346 */
347function get_html_menu_category($categories)
348{
349  global $page, $lang;
350
351  $ref_level = 0;
352  $menu = '
353             <ul class="menu">';
354 
355  foreach ($categories as $category)
356  {
357    $level = substr_count($category['global_rank'], '.');
358    if ($level > $ref_level)
359    {
360      $menu.= '
361             <ul class="menu">';
362    }
363    else if ($level < $ref_level)
364    {
365      // we may have to close more than one level at the same time...
366      $menu.= str_repeat("\n</ul>",($ref_level-$level));
367    }
368    $ref_level = $level;
369   
370    $menu.= '
371
372           <li>';
373 
374    $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']);
375
376    $class = '';
377    if (isset($page['cat'])
378        and is_numeric($page['cat'])
379        and $category['id'] == $page['cat'])
380    {
381      $class = 'menuCategorySelected';
382    }
383    else
384    {
385      $class = 'menuCategoryNotSelected';
386    }
387
388    $menu.= '
389           <a href="'.$url.'"
390              title="'.$lang['hint_category'].'"
391              class="'.$class.'">
392             '.$category['name'].'
393           </a>';
394
395    if ($category['nb_images'] > 0)
396    {
397      $menu.= '
398             <span class="menuInfoCat"
399                   title="'.$category['nb_images'].'
400                          '.$lang['images_available'].'">
401             ['.$category['nb_images'].']
402             </span>
403             '.get_icon($category['date_last']);
404    }
405
406    $menu.= '</li>';
407  }
408 
409  $menu.= '
410             </ul>';
411 
412  return $menu;
413}
414
415/**
416 * returns HTMLized comment contents retrieved from database
417 *
418 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
419 * italic, *word* becomes bolded
420 *
421 * @param string content
422 * @return string
423 */
424function parse_comment_content($content)
425{
426  $content = nl2br($content);
427 
428  // replace _word_ by an underlined word
429  $pattern = '/_([^\s]*)_/';
430  $replacement = '<span style="text-decoration:underline;">\1</span>';
431  $content = preg_replace($pattern, $replacement, $content);
432 
433  // replace *word* by a bolded word
434  $pattern = '/\*([^\s]*)\*/';
435  $replacement = '<span style="font-weight:bold;">\1</span>';
436  $content = preg_replace($pattern, $replacement, $content);
437 
438  // replace /word/ by an italic word
439  $pattern = '/\/([^\s]*)\//';
440  $replacement = '<span style="font-style:italic;">\1</span>';
441  $content = preg_replace($pattern, $replacement, $content);
442
443  return $content;
444}
445?>
Note: See TracBrowser for help on using the repository browser.