Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

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