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

Last change on this file since 642 was 642, checked in by plg, 19 years ago
  • in admin menu, status option for categories is not "permissions" but "private or public" choice = different language item
  • get_cat_display_name changed : use $conflevel_separator to unify presentation
  • default values for category properties commentable, uploadable, status and visible (set in include/config.inc.php) used for category creation (admin/update, admin/remote_site, admin/cat_list)
  • use mass_inserts in admin/update for inserting new categories
  • only one query for counting the number of sub categories in admin/cat_list
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 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-12 21:06:39 +0000 (Sun, 12 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 642 $
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;
61  $navigation_bar = "";
62  // 0. détection de la page en cours
63  if( !isset( $start )
64      || !is_numeric( $start )
65      || ( is_numeric( $start ) && $start < 0 ) )
66  {
67    $start = 0;
68  }
69  // on n'affiche la bare de navigation que si on plus de 1 page
70  if ( $nb_element > $nb_element_page )
71  {
72    // 1.une page précédente ?
73    if ( $start != 0 )
74    {
75      $previous = $start - $nb_element_page;
76      $navigation_bar.= '<a href="';
77      $navigation_bar.= add_session_id( $url.'&amp;start='.$previous );
78      $navigation_bar.= '" class="'.$link_class.'">'.$lang['previous_page'];
79      $navigation_bar.= '</a>';
80      $navigation_bar.= ' | ';
81    }
82    // 2.liste des numéros de page
83    $maximum = ceil ( $nb_element / $nb_element_page );
84    for ( $i = 1; $i <= $maximum; $i++ )
85    {
86      $temp_start = ( $i - 1 ) * $nb_element_page;
87      if ( $temp_start == $start )
88      {
89        $navigation_bar.= ' <span class="pageNumberSelected">'.$i.'</span> ';
90      }
91      else
92      {
93        $navigation_bar.= ' <a href="';
94        $navigation_bar.= add_session_id( $url.'&amp;start='.$temp_start );
95        $navigation_bar.= '" class="'.$link_class.'">'.$i.'</a> ';
96      }
97    }
98    // 3.une page suivante ?
99    if ( $nb_element > $nb_element_page
100         && $start + $nb_element_page < $nb_element )
101    {
102      $next = $start + $nb_element_page;
103      $navigation_bar.= ' | <a href="';
104      $navigation_bar.= add_session_id( $url.'&amp;start='.$next );
105      $navigation_bar.= '" class="'.$link_class.'">'.$lang['next_page'].'</a>';
106    }
107  }
108  return $navigation_bar;
109}
110
111//
112// Pick a language, any language ...
113//
114function language_select($default, $select_name = "language")
115{
116  $available_lang = get_languages();
117
118  $lang_select = '<select name="' . $select_name . '" onchange="this.form.submit()">';
119  foreach ($available_lang as $code => $displayname)
120  {
121    $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : '';
122    $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>';
123  }
124  $lang_select .= '</select>';
125
126  return $lang_select;
127}
128
129//
130// Pick a template/theme combo,
131//
132function style_select($default_style, $select_name = "style")
133{
134  $templates = get_templates();
135
136  $style_selected = '<select name="' . $select_name . '" >';
137  foreach ($templates as $template)
138  {
139    $selected = ( $template == $default_style ) ? ' selected="selected"' : '';
140    $style_selected.= '<option value="'.$template.'"'.$selected.'>';
141    $style_selected.= $template.'</option>';
142  }
143  $style_selected .= '</select>';
144  return $style_selected;
145}
146
147/**
148 * returns the list of categories as a HTML string
149 *
150 * categories string returned contains categories as given in the input
151 * array $cat_informations. $cat_informations array must be an association
152 * of {category_id => category_name}. If url input parameter is empty,
153 * returns only the categories name without links.
154 *
155 * @param array cat_informations
156 * @param string separator
157 * @param string url
158 * @param boolean replace_space
159 * @return string
160 */
161function get_cat_display_name($cat_informations,
162                              $url = 'category.php?cat=',
163                              $replace_space = true)
164{
165  global $conf;
166 
167  $output = '';
168  $is_first = true;
169  foreach ($cat_informations as $id => $name)
170  {
171    if ($is_first)
172    {
173      $is_first = false;
174    }
175    else
176    {
177      $output.= $conf['level_separator'];
178    }
179
180    if ($url == '')
181    {
182      $output.= $name;
183    }
184    else
185    {
186      $output.= '
187<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.$url.$id).'">'.$name.'</a>';
188    }
189  }
190  if ($replace_space)
191  {
192    return replace_space($output);
193  }
194  else
195  {
196    return $output;
197  }
198}
199
200/**
201 * returns the list of categories as a HTML string, with cache of names
202 *
203 * categories string returned contains categories as given in the input
204 * array $cat_informations. $uppercats is the list of category ids to
205 * display in the right order. If url input parameter is empty, returns only
206 * the categories name without links.
207 *
208 * @param string uppercats
209 * @param string url
210 * @param boolean replace_space
211 * @return string
212 */
213function get_cat_display_name_cache($uppercats,
214                                    $url = 'category.php?cat=',
215                                    $replace_space = true)
216{
217  global $cat_names, $conf;
218
219  if (!isset($cat_names))
220  {
221    $query = '
222SELECT id,name
223  FROM '.CATEGORIES_TABLE.'
224;';
225    $result = pwg_query($query);
226    while ($row = mysql_fetch_array($result))
227    {
228      $cat_names[$row['id']] = $row['name'];
229    }
230  }
231 
232  $output = '';
233  $is_first = true;
234  foreach (explode(',', $uppercats) as $category_id)
235  {
236    $name = $cat_names[$category_id];
237   
238    if ($is_first)
239    {
240      $is_first = false;
241    }
242    else
243    {
244      $output.= $conf['level_separator'];
245    }
246
247    if ($url == '')
248    {
249      $output.= $name;
250    }
251    else
252    {
253      $output.= '
254<a class=""
255   href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_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 HTML code for a category item in the menu (for category.php)
270 *
271 * HTML code generated uses logical list tags ul and each category is an
272 * item li. The paramter given is the category informations as an array,
273 * used keys are : id, name, nb_images, date_last
274 *
275 * @param array categories
276 * @return string
277 */
278function get_html_menu_category($categories)
279{
280  global $page, $lang;
281
282  $ref_level = 0;
283  $menu = '
284             <ul class="menu">';
285 
286  foreach ($categories as $category)
287  {
288    $level = substr_count($category['global_rank'], '.');
289    if ($level > $ref_level)
290    {
291      $menu.= '
292             <ul class="menu">';
293    }
294    else if ($level < $ref_level)
295    {
296      $menu.= '
297             </ul>';
298    }
299    $ref_level = $level;
300   
301    $menu.= '
302
303           <li>';
304 
305    $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']);
306
307    $class = '';
308    if (isset($page['cat'])
309        and is_numeric($page['cat'])
310        and $category['id'] == $page['cat'])
311    {
312      $class = 'menuCategorySelected';
313    }
314    else
315    {
316      $class = 'menuCategoryNotSelected';
317    }
318
319    $menu.= '
320           <a href="'.$url.'"
321              title="'.$lang['hint_category'].'"
322              class="'.$class.'">
323             '.$category['name'].'
324           </a>';
325
326    if ($category['nb_images'] > 0)
327    {
328      $menu.= '
329             <span class="menuInfoCat"
330                   title="'.$category['nb_images'].'
331                          '.$lang['images_available'].'">
332             ['.$category['nb_images'].']
333             </span>
334             '.get_icon($category['date_last']);
335    }
336
337    $menu.= '</li>';
338  }
339 
340  $menu.= '
341             </ul>';
342 
343  return $menu;
344}
345
346/**
347 * returns HTMLized comment contents retrieved from database
348 *
349 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
350 * italic, *word* becomes bolded
351 *
352 * @param string content
353 * @return string
354 */
355function parse_comment_content($content)
356{
357  $content = nl2br($content);
358 
359  // replace _word_ by an underlined word
360  $pattern = '/_([^\s]*)_/';
361  $replacement = '<span style="text-decoration:underline;">\1</span>';
362  $content = preg_replace($pattern, $replacement, $content);
363 
364  // replace *word* by a bolded word
365  $pattern = '/\*([^\s]*)\*/';
366  $replacement = '<span style="font-weight:bold;">\1</span>';
367  $content = preg_replace($pattern, $replacement, $content);
368 
369  // replace /word/ by an italic word
370  $pattern = '/\/([^\s]*)\//';
371  $replacement = '<span style="font-style:italic;">\1</span>';
372  $content = preg_replace($pattern, $replacement, $content);
373
374  return $content;
375}
376?>
Note: See TracBrowser for help on using the repository browser.