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