[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 | // | last update : $Date: 2006-12-07 23:21:54 +0000 (Thu, 07 Dec 2006) $ |
---|
| 9 | // | last modifier : $Author: rvelices $ |
---|
| 10 | // | revision : $Revision: 1641 $ |
---|
| 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
---|
| 14 | // | the Free Software Foundation | |
---|
| 15 | // | | |
---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 19 | // | General Public License for more details. | |
---|
| 20 | // | | |
---|
| 21 | // | You should have received a copy of the GNU General Public License | |
---|
| 22 | // | along with this program; if not, write to the Free Software | |
---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 24 | // | USA. | |
---|
| 25 | // +-----------------------------------------------------------------------+ |
---|
| 26 | |
---|
[1624] | 27 | function get_icon($date, $is_child_date = false) |
---|
[476] | 28 | { |
---|
[1641] | 29 | global $page, $user, $lang; |
---|
[476] | 30 | |
---|
[1040] | 31 | if (empty($date)) |
---|
[492] | 32 | { |
---|
[1641] | 33 | return ''; |
---|
[492] | 34 | } |
---|
| 35 | |
---|
[1641] | 36 | if (isset($page['get_icon_cache'][$date])) |
---|
[1040] | 37 | { |
---|
[1641] | 38 | if (! $page['get_icon_cache'][$date] ) |
---|
| 39 | return ''; |
---|
| 40 | return $page['get_icon_cache']['_icons_'][$is_child_date]; |
---|
[1040] | 41 | } |
---|
| 42 | |
---|
| 43 | if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $matches)) |
---|
[1641] | 44 | {// date can be empty, no icon to display |
---|
| 45 | $page['get_icon_cache'][$date] = false; |
---|
| 46 | return ''; |
---|
[1040] | 47 | } |
---|
[1090] | 48 | |
---|
[1040] | 49 | list($devnull, $year, $month, $day) = $matches; |
---|
[476] | 50 | $unixtime = mktime( 0, 0, 0, $month, $day, $year ); |
---|
[1040] | 51 | if ($unixtime === false // PHP 5.1.0 and above |
---|
| 52 | or $unixtime === -1) // PHP prior to 5.1.0 |
---|
| 53 | { |
---|
[1641] | 54 | $page['get_icon_cache'][$date] = false; |
---|
| 55 | return ''; |
---|
[1040] | 56 | } |
---|
[1090] | 57 | |
---|
[476] | 58 | $diff = time() - $unixtime; |
---|
| 59 | $day_in_seconds = 24*60*60; |
---|
[1641] | 60 | $page['get_icon_cache'][$date] = false; |
---|
[476] | 61 | if ( $diff < $user['recent_period'] * $day_in_seconds ) |
---|
| 62 | { |
---|
[1641] | 63 | if ( !isset($page['get_icon_cache']['_icons_'] ) ) |
---|
| 64 | { |
---|
| 65 | $icons = array(false => 'recent', true => 'recent_by_child' ); |
---|
| 66 | $title = $lang['recent_image'].' '.$user['recent_period'] |
---|
| 67 | .' '.$lang['days']; |
---|
| 68 | foreach ($icons as $key => $icon) |
---|
| 69 | { |
---|
| 70 | $icon_url = get_themeconf('icon_dir').'/'.$icon.'.png'; |
---|
| 71 | $size = getimagesize( PHPWG_ROOT_PATH.$icon_url ); |
---|
| 72 | $icon_url = get_root_url().$icon_url; |
---|
| 73 | $output = '<img title="'.$title.'" src="'.$icon_url.'" class="icon" style="border:0;'; |
---|
| 74 | $output.= 'height:'.$size[1].'px;width:'.$size[0].'px" alt="(!)" />'; |
---|
| 75 | $page['get_icon_cache']['_icons_'][$key] = $output; |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | $page['get_icon_cache'][$date] = true; |
---|
[476] | 79 | } |
---|
[1641] | 80 | if (! $page['get_icon_cache'][$date] ) |
---|
| 81 | return ''; |
---|
| 82 | return $page['get_icon_cache']['_icons_'][$is_child_date]; |
---|
| 83 | } |
---|
[1040] | 84 | |
---|
| 85 | |
---|
[1084] | 86 | function create_navigation_bar( |
---|
| 87 | $url, $nb_element, $start, $nb_element_page, $clean_url = false |
---|
| 88 | ) |
---|
[476] | 89 | { |
---|
[643] | 90 | global $lang, $conf; |
---|
| 91 | |
---|
| 92 | $pages_around = $conf['paginate_pages_around']; |
---|
[1563] | 93 | $start_str = $clean_url ? '/start-' : |
---|
| 94 | ( ( strstr($url, '?')===false ? '?':'&') . 'start=' ); |
---|
[1090] | 95 | |
---|
[644] | 96 | $navbar = ''; |
---|
[1090] | 97 | |
---|
[643] | 98 | // current page detection |
---|
| 99 | if (!isset($start) |
---|
| 100 | or !is_numeric($start) |
---|
| 101 | or (is_numeric($start) and $start < 0)) |
---|
[476] | 102 | { |
---|
| 103 | $start = 0; |
---|
| 104 | } |
---|
[1090] | 105 | |
---|
[643] | 106 | // navigation bar useful only if more than one page to display ! |
---|
| 107 | if ($nb_element > $nb_element_page) |
---|
[476] | 108 | { |
---|
[644] | 109 | // current page and last page |
---|
[643] | 110 | $cur_page = ceil($start / $nb_element_page) + 1; |
---|
| 111 | $maximum = ceil($nb_element / $nb_element_page); |
---|
| 112 | |
---|
| 113 | // link to first page ? |
---|
| 114 | if ($cur_page != 1) |
---|
| 115 | { |
---|
[1084] | 116 | $navbar.= |
---|
| 117 | '<a href="'.$url.'" rel="start">' |
---|
| 118 | .$lang['first_page'] |
---|
| 119 | .'</a>'; |
---|
[643] | 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
[644] | 123 | $navbar.= $lang['first_page']; |
---|
[643] | 124 | } |
---|
[644] | 125 | $navbar.= ' | '; |
---|
[643] | 126 | // link on previous page ? |
---|
[1084] | 127 | if ($start != 0) |
---|
[476] | 128 | { |
---|
| 129 | $previous = $start - $nb_element_page; |
---|
[1090] | 130 | |
---|
[1084] | 131 | $navbar.= |
---|
| 132 | '<a href="' |
---|
| 133 | .$url.($previous > 0 ? $start_str.$previous : '') |
---|
| 134 | .'" rel="prev">' |
---|
| 135 | .$lang['previous_page'] |
---|
| 136 | .'</a>'; |
---|
[476] | 137 | } |
---|
[643] | 138 | else |
---|
[476] | 139 | { |
---|
[644] | 140 | $navbar.= $lang['previous_page']; |
---|
[643] | 141 | } |
---|
[1031] | 142 | $navbar.= ' |'; |
---|
[643] | 143 | |
---|
| 144 | if ($cur_page > $pages_around + 1) |
---|
| 145 | { |
---|
[1084] | 146 | $navbar.= ' <a href="'.$url.'">1</a>'; |
---|
[1090] | 147 | |
---|
[678] | 148 | if ($cur_page > $pages_around + 2) |
---|
| 149 | { |
---|
| 150 | $navbar.= ' ...'; |
---|
| 151 | } |
---|
[643] | 152 | } |
---|
[1090] | 153 | |
---|
[643] | 154 | // inspired from punbb source code |
---|
| 155 | for ($i = $cur_page - $pages_around, $stop = $cur_page + $pages_around + 1; |
---|
| 156 | $i < $stop; |
---|
| 157 | $i++) |
---|
| 158 | { |
---|
| 159 | if ($i < 1 or $i > $maximum) |
---|
[476] | 160 | { |
---|
[643] | 161 | continue; |
---|
[476] | 162 | } |
---|
[643] | 163 | else if ($i != $cur_page) |
---|
| 164 | { |
---|
| 165 | $temp_start = ($i - 1) * $nb_element_page; |
---|
[1090] | 166 | |
---|
[1084] | 167 | $navbar.= |
---|
| 168 | ' ' |
---|
| 169 | .'<a href="'.$url |
---|
| 170 | .($temp_start > 0 ? $start_str.$temp_start : '') |
---|
| 171 | .'">' |
---|
| 172 | .$i |
---|
| 173 | .'</a>'; |
---|
[643] | 174 | } |
---|
[476] | 175 | else |
---|
| 176 | { |
---|
[1084] | 177 | $navbar.= |
---|
| 178 | ' ' |
---|
| 179 | .'<span class="pageNumberSelected">' |
---|
| 180 | .$i |
---|
| 181 | .'</span>'; |
---|
[476] | 182 | } |
---|
| 183 | } |
---|
[643] | 184 | |
---|
| 185 | if ($cur_page < ($maximum - $pages_around)) |
---|
| 186 | { |
---|
| 187 | $temp_start = ($maximum - 1) * $nb_element_page; |
---|
[1090] | 188 | |
---|
[678] | 189 | if ($cur_page < ($maximum - $pages_around - 1)) |
---|
| 190 | { |
---|
| 191 | $navbar.= ' ...'; |
---|
| 192 | } |
---|
[1090] | 193 | |
---|
[1084] | 194 | $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>'; |
---|
[643] | 195 | } |
---|
[1090] | 196 | |
---|
[644] | 197 | $navbar.= ' | '; |
---|
[643] | 198 | // link on next page ? |
---|
[1084] | 199 | if ($nb_element > $nb_element_page |
---|
| 200 | and $start + $nb_element_page < $nb_element) |
---|
[476] | 201 | { |
---|
| 202 | $next = $start + $nb_element_page; |
---|
[1090] | 203 | |
---|
[1084] | 204 | $navbar.= |
---|
| 205 | '<a href="'.$url.$start_str.$next.'" rel="next">' |
---|
| 206 | .$lang['next_page'] |
---|
| 207 | .'</a>'; |
---|
[476] | 208 | } |
---|
[643] | 209 | else |
---|
| 210 | { |
---|
[644] | 211 | $navbar.= $lang['next_page']; |
---|
[643] | 212 | } |
---|
[1090] | 213 | |
---|
[647] | 214 | $navbar.= ' | '; |
---|
[643] | 215 | // link to last page ? |
---|
| 216 | if ($cur_page != $maximum) |
---|
| 217 | { |
---|
| 218 | $temp_start = ($maximum - 1) * $nb_element_page; |
---|
[1090] | 219 | |
---|
[1084] | 220 | $navbar.= |
---|
| 221 | '<a href="'.$url.$start_str.$temp_start.'" rel="last">' |
---|
| 222 | .$lang['last_page'] |
---|
| 223 | .'</a>'; |
---|
[643] | 224 | } |
---|
| 225 | else |
---|
| 226 | { |
---|
[644] | 227 | $navbar.= $lang['last_page']; |
---|
[643] | 228 | } |
---|
[476] | 229 | } |
---|
[644] | 230 | return $navbar; |
---|
[476] | 231 | } |
---|
| 232 | |
---|
| 233 | // |
---|
| 234 | // Pick a language, any language ... |
---|
| 235 | // |
---|
| 236 | function language_select($default, $select_name = "language") |
---|
| 237 | { |
---|
[512] | 238 | $available_lang = get_languages(); |
---|
[476] | 239 | |
---|
[817] | 240 | $lang_select = '<select name="' . $select_name . '">'; |
---|
[528] | 241 | foreach ($available_lang as $code => $displayname) |
---|
[476] | 242 | { |
---|
| 243 | $selected = ( strtolower($default) == strtolower($code) ) ? ' selected="selected"' : ''; |
---|
| 244 | $lang_select .= '<option value="' . $code . '"' . $selected . '>' . ucwords($displayname) . '</option>'; |
---|
| 245 | } |
---|
| 246 | $lang_select .= '</select>'; |
---|
| 247 | |
---|
| 248 | return $lang_select; |
---|
| 249 | } |
---|
| 250 | |
---|
[572] | 251 | /** |
---|
| 252 | * returns the list of categories as a HTML string |
---|
| 253 | * |
---|
| 254 | * categories string returned contains categories as given in the input |
---|
| 255 | * array $cat_informations. $cat_informations array must be an association |
---|
[1092] | 256 | * of {category_id => category_name}. If url input parameter is null, |
---|
[572] | 257 | * returns only the categories name without links. |
---|
| 258 | * |
---|
| 259 | * @param array cat_informations |
---|
| 260 | * @param string url |
---|
| 261 | * @param boolean replace_space |
---|
| 262 | * @return string |
---|
| 263 | */ |
---|
[569] | 264 | function get_cat_display_name($cat_informations, |
---|
[1092] | 265 | $url = '', |
---|
[569] | 266 | $replace_space = true) |
---|
[476] | 267 | { |
---|
[642] | 268 | global $conf; |
---|
[1090] | 269 | |
---|
[476] | 270 | $output = ''; |
---|
[569] | 271 | $is_first = true; |
---|
| 272 | foreach ($cat_informations as $id => $name) |
---|
[476] | 273 | { |
---|
[569] | 274 | if ($is_first) |
---|
| 275 | { |
---|
| 276 | $is_first = false; |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
[642] | 280 | $output.= $conf['level_separator']; |
---|
[569] | 281 | } |
---|
| 282 | |
---|
[1092] | 283 | if ( !isset($url) ) |
---|
[569] | 284 | { |
---|
| 285 | $output.= $name; |
---|
| 286 | } |
---|
[1092] | 287 | elseif ($url == '') |
---|
| 288 | { |
---|
| 289 | $output.= '<a class=""'; |
---|
[1131] | 290 | $output.= ' href="' |
---|
| 291 | .make_index_url( |
---|
| 292 | array( |
---|
| 293 | 'category'=>$id, |
---|
| 294 | 'cat_name'=>$name |
---|
| 295 | ) |
---|
| 296 | ) |
---|
| 297 | .'">'; |
---|
[1092] | 298 | $output.= $name.'</a>'; |
---|
| 299 | } |
---|
[569] | 300 | else |
---|
| 301 | { |
---|
[825] | 302 | $output.= '<a class=""'; |
---|
[1004] | 303 | $output.= ' href="'.PHPWG_ROOT_PATH.$url.$id.'">'; |
---|
[825] | 304 | $output.= $name.'</a>'; |
---|
[569] | 305 | } |
---|
[476] | 306 | } |
---|
[569] | 307 | if ($replace_space) |
---|
| 308 | { |
---|
| 309 | return replace_space($output); |
---|
| 310 | } |
---|
| 311 | else |
---|
| 312 | { |
---|
| 313 | return $output; |
---|
| 314 | } |
---|
[476] | 315 | } |
---|
| 316 | |
---|
| 317 | /** |
---|
[610] | 318 | * returns the list of categories as a HTML string, with cache of names |
---|
| 319 | * |
---|
| 320 | * categories string returned contains categories as given in the input |
---|
| 321 | * array $cat_informations. $uppercats is the list of category ids to |
---|
| 322 | * display in the right order. If url input parameter is empty, returns only |
---|
| 323 | * the categories name without links. |
---|
| 324 | * |
---|
| 325 | * @param string uppercats |
---|
| 326 | * @param string url |
---|
| 327 | * @param boolean replace_space |
---|
| 328 | * @return string |
---|
| 329 | */ |
---|
| 330 | function get_cat_display_name_cache($uppercats, |
---|
[1092] | 331 | $url = '', |
---|
[610] | 332 | $replace_space = true) |
---|
| 333 | { |
---|
[642] | 334 | global $cat_names, $conf; |
---|
[610] | 335 | |
---|
| 336 | if (!isset($cat_names)) |
---|
| 337 | { |
---|
| 338 | $query = ' |
---|
| 339 | SELECT id,name |
---|
| 340 | FROM '.CATEGORIES_TABLE.' |
---|
| 341 | ;'; |
---|
| 342 | $result = pwg_query($query); |
---|
| 343 | while ($row = mysql_fetch_array($result)) |
---|
| 344 | { |
---|
| 345 | $cat_names[$row['id']] = $row['name']; |
---|
| 346 | } |
---|
| 347 | } |
---|
[1090] | 348 | |
---|
[610] | 349 | $output = ''; |
---|
| 350 | $is_first = true; |
---|
| 351 | foreach (explode(',', $uppercats) as $category_id) |
---|
| 352 | { |
---|
| 353 | $name = $cat_names[$category_id]; |
---|
[1090] | 354 | |
---|
[610] | 355 | if ($is_first) |
---|
| 356 | { |
---|
| 357 | $is_first = false; |
---|
| 358 | } |
---|
| 359 | else |
---|
| 360 | { |
---|
[642] | 361 | $output.= $conf['level_separator']; |
---|
[610] | 362 | } |
---|
| 363 | |
---|
[1092] | 364 | if ( !isset($url) ) |
---|
[610] | 365 | { |
---|
| 366 | $output.= $name; |
---|
| 367 | } |
---|
[1092] | 368 | elseif ($url == '') |
---|
| 369 | { |
---|
| 370 | $output.= ' |
---|
| 371 | <a class="" |
---|
[1131] | 372 | href="' |
---|
| 373 | .make_index_url( |
---|
| 374 | array( |
---|
| 375 | 'category'=>$category_id, |
---|
| 376 | 'cat_name'=>$name |
---|
| 377 | ) |
---|
| 378 | ) |
---|
| 379 | .'">'.$name.'</a>'; |
---|
[1092] | 380 | } |
---|
[610] | 381 | else |
---|
| 382 | { |
---|
| 383 | $output.= ' |
---|
| 384 | <a class="" |
---|
[1004] | 385 | href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$name.'</a>'; |
---|
[610] | 386 | } |
---|
| 387 | } |
---|
| 388 | if ($replace_space) |
---|
| 389 | { |
---|
| 390 | return replace_space($output); |
---|
| 391 | } |
---|
| 392 | else |
---|
| 393 | { |
---|
| 394 | return $output; |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | /** |
---|
[1082] | 399 | * returns the HTML code for a category item in the menu (for the main page) |
---|
[476] | 400 | * |
---|
| 401 | * HTML code generated uses logical list tags ul and each category is an |
---|
| 402 | * item li. The paramter given is the category informations as an array, |
---|
[1641] | 403 | * used keys are : id, name, nb_images, max_date_last, date_last |
---|
[1624] | 404 | * count_images, count_categories |
---|
[476] | 405 | * |
---|
[614] | 406 | * @param array categories |
---|
[476] | 407 | * @return string |
---|
| 408 | */ |
---|
[614] | 409 | function get_html_menu_category($categories) |
---|
[476] | 410 | { |
---|
| 411 | global $page, $lang; |
---|
| 412 | |
---|
[614] | 413 | $ref_level = 0; |
---|
[976] | 414 | $level = 0; |
---|
[876] | 415 | $menu = ''; |
---|
[1036] | 416 | |
---|
| 417 | // $page_cat value remains 0 for special sections |
---|
[1031] | 418 | $page_cat = 0; |
---|
[1082] | 419 | if (isset($page['category'])) |
---|
[1031] | 420 | { |
---|
[1082] | 421 | $page_cat = $page['category']; |
---|
[1031] | 422 | } |
---|
[1090] | 423 | |
---|
[614] | 424 | foreach ($categories as $category) |
---|
| 425 | { |
---|
[876] | 426 | $level = substr_count($category['global_rank'], '.') + 1; |
---|
[614] | 427 | if ($level > $ref_level) |
---|
| 428 | { |
---|
[941] | 429 | $menu.= "\n<ul>"; |
---|
[614] | 430 | } |
---|
[876] | 431 | else if ($level == $ref_level) |
---|
| 432 | { |
---|
[941] | 433 | $menu.= "\n</li>"; |
---|
[876] | 434 | } |
---|
[614] | 435 | else if ($level < $ref_level) |
---|
| 436 | { |
---|
[645] | 437 | // we may have to close more than one level at the same time... |
---|
[876] | 438 | $menu.= "\n</li>"; |
---|
[941] | 439 | $menu.= str_repeat("\n</ul></li>",($ref_level-$level)); |
---|
[614] | 440 | } |
---|
| 441 | $ref_level = $level; |
---|
[850] | 442 | |
---|
[941] | 443 | $menu.= "\n\n".'<li'; |
---|
[1031] | 444 | if ($category['id'] == $page_cat) |
---|
[614] | 445 | { |
---|
[850] | 446 | $menu.= ' class="selected"'; |
---|
[614] | 447 | } |
---|
[850] | 448 | $menu.= '>'; |
---|
[1090] | 449 | |
---|
[1131] | 450 | $url = make_index_url( |
---|
| 451 | array( |
---|
| 452 | 'category'=>$category['id'], |
---|
| 453 | 'cat_name'=>$category['name'] |
---|
| 454 | ) |
---|
| 455 | ); |
---|
[1090] | 456 | |
---|
[1031] | 457 | $menu.= "\n".'<a href="'.$url.'"'; |
---|
[1036] | 458 | if ($page_cat != 0 |
---|
| 459 | and $category['id'] == $page['cat_id_uppercat']) |
---|
[1031] | 460 | { |
---|
| 461 | $menu.= ' rel="up"'; |
---|
| 462 | } |
---|
[1290] | 463 | $menu.= '>'.$category['name'].'</a>'; |
---|
[476] | 464 | |
---|
[1624] | 465 | // Count of category is main |
---|
| 466 | // if not picture on categorie, test on sub-categories |
---|
| 467 | if (($category['nb_images'] > 0) or ($category['count_images'] > 0)) |
---|
[614] | 468 | { |
---|
[1624] | 469 | $menu.= "\n".'<span class="'; |
---|
| 470 | $menu.= ($category['nb_images'] > 0 ? "menuInfoCat" |
---|
| 471 | : "menuInfoCatByChild").'"'; |
---|
| 472 | $menu.= ' title="'; |
---|
| 473 | $menu.= ' '.get_display_images_count |
---|
| 474 | ( |
---|
| 475 | $category['nb_images'], |
---|
| 476 | $category['count_images'], |
---|
| 477 | $category['count_categories'], |
---|
| 478 | false |
---|
| 479 | ).'">'; |
---|
| 480 | $menu.= '['.($category['nb_images'] > 0 ? $category['nb_images'] |
---|
| 481 | : $category['count_images']).']'; |
---|
[831] | 482 | $menu.= '</span>'; |
---|
[614] | 483 | } |
---|
[1641] | 484 | $child_date_last = isset($category['date_last']) |
---|
| 485 | and $category['max_date_last']>$category['date_last'] ; |
---|
| 486 | $menu.= get_icon($category['max_date_last'], $child_date_last); |
---|
[476] | 487 | } |
---|
[941] | 488 | |
---|
| 489 | $menu.= str_repeat("\n</li></ul>",($level)); |
---|
[1090] | 490 | |
---|
[476] | 491 | return $menu; |
---|
| 492 | } |
---|
[579] | 493 | |
---|
| 494 | /** |
---|
| 495 | * returns HTMLized comment contents retrieved from database |
---|
| 496 | * |
---|
| 497 | * newlines becomes br tags, _word_ becomes underline, /word/ becomes |
---|
| 498 | * italic, *word* becomes bolded |
---|
| 499 | * |
---|
| 500 | * @param string content |
---|
| 501 | * @return string |
---|
| 502 | */ |
---|
| 503 | function parse_comment_content($content) |
---|
| 504 | { |
---|
[1031] | 505 | $pattern = '/(https?:\/\/\S*)/'; |
---|
| 506 | $replacement = '<a href="$1" rel="nofollow">$1</a>'; |
---|
| 507 | $content = preg_replace($pattern, $replacement, $content); |
---|
| 508 | |
---|
[579] | 509 | $content = nl2br($content); |
---|
[1090] | 510 | |
---|
[579] | 511 | // replace _word_ by an underlined word |
---|
[1030] | 512 | $pattern = '/\b_(\S*)_\b/'; |
---|
| 513 | $replacement = '<span style="text-decoration:underline;">$1</span>'; |
---|
[579] | 514 | $content = preg_replace($pattern, $replacement, $content); |
---|
[1090] | 515 | |
---|
[579] | 516 | // replace *word* by a bolded word |
---|
[1030] | 517 | $pattern = '/\b\*(\S*)\*\b/'; |
---|
| 518 | $replacement = '<span style="font-weight:bold;">$1</span>'; |
---|
[579] | 519 | $content = preg_replace($pattern, $replacement, $content); |
---|
[1090] | 520 | |
---|
[579] | 521 | // replace /word/ by an italic word |
---|
[1031] | 522 | $pattern = "/\/(\S*)\/(\s)/"; |
---|
| 523 | $replacement = '<span style="font-style:italic;">$1$2</span>'; |
---|
| 524 | $content = preg_replace($pattern, $replacement, $content); |
---|
[579] | 525 | |
---|
[1272] | 526 | $content = '<div>'.$content.'</div>'; |
---|
[579] | 527 | return $content; |
---|
| 528 | } |
---|
[817] | 529 | |
---|
| 530 | function get_cat_display_name_from_id($cat_id, |
---|
[1092] | 531 | $url = '', |
---|
[817] | 532 | $replace_space = true) |
---|
| 533 | { |
---|
| 534 | $cat_info = get_cat_info($cat_id); |
---|
[825] | 535 | return get_cat_display_name($cat_info['name'], $url, $replace_space); |
---|
[817] | 536 | } |
---|
[1113] | 537 | |
---|
| 538 | /** |
---|
[1119] | 539 | * Returns an HTML list of tags. It can be a multi select field or a list of |
---|
| 540 | * checkboxes. |
---|
| 541 | * |
---|
| 542 | * @param string HTML field name |
---|
| 543 | * @param array selected tag ids |
---|
| 544 | * @return array |
---|
| 545 | */ |
---|
| 546 | function get_html_tag_selection( |
---|
| 547 | $tags, |
---|
| 548 | $fieldname, |
---|
| 549 | $selecteds = array(), |
---|
| 550 | $forbidden_categories = null |
---|
| 551 | ) |
---|
| 552 | { |
---|
| 553 | global $conf; |
---|
[1131] | 554 | |
---|
[1201] | 555 | if (count ($tags) == 0 ) |
---|
| 556 | { |
---|
| 557 | return ''; |
---|
| 558 | } |
---|
[1119] | 559 | $output = '<ul class="tagSelection">'; |
---|
| 560 | foreach ($tags as $tag) |
---|
| 561 | { |
---|
| 562 | $output.= |
---|
| 563 | '<li>' |
---|
| 564 | .'<label>' |
---|
| 565 | .'<input type="checkbox" name="'.$fieldname.'[]"' |
---|
| 566 | .' value="'.$tag['tag_id'].'"' |
---|
| 567 | ; |
---|
| 568 | |
---|
| 569 | if (in_array($tag['tag_id'], $selecteds)) |
---|
| 570 | { |
---|
| 571 | $output.= ' checked="checked"'; |
---|
| 572 | } |
---|
[1131] | 573 | |
---|
[1119] | 574 | $output.= |
---|
| 575 | ' />' |
---|
[1290] | 576 | .' '. $tag['name'] |
---|
[1119] | 577 | .'</label>' |
---|
| 578 | .'</li>' |
---|
| 579 | ."\n" |
---|
| 580 | ; |
---|
| 581 | } |
---|
| 582 | $output.= '</ul>'; |
---|
| 583 | |
---|
| 584 | return $output; |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | function name_compare($a, $b) |
---|
| 588 | { |
---|
[1310] | 589 | return strcmp(strtolower($a['name']), strtolower($b['name'])); |
---|
[1119] | 590 | } |
---|
| 591 | |
---|
| 592 | /** |
---|
[1113] | 593 | * exits the current script (either exit or redirect) |
---|
| 594 | */ |
---|
| 595 | function access_denied() |
---|
| 596 | { |
---|
| 597 | global $user, $lang; |
---|
| 598 | |
---|
| 599 | $login_url = |
---|
| 600 | get_root_url().'identification.php?redirect=' |
---|
| 601 | .urlencode(urlencode($_SERVER['REQUEST_URI'])); |
---|
| 602 | |
---|
| 603 | if ( isset($user['is_the_guest']) and !$user['is_the_guest'] ) |
---|
| 604 | { |
---|
| 605 | echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; |
---|
| 606 | echo '<a href="'.get_root_url().'identification.php">'.$lang['identification'].'</a> '; |
---|
| 607 | echo '<a href="'.make_index_url().'">'.$lang['home'].'</a></div>'; |
---|
| 608 | exit(); |
---|
| 609 | } |
---|
| 610 | else |
---|
| 611 | { |
---|
| 612 | header('HTTP/1.1 401 Authorization required'); |
---|
| 613 | header('Status: 401 Authorization required'); |
---|
| 614 | redirect($login_url); |
---|
| 615 | } |
---|
| 616 | } |
---|
[1288] | 617 | |
---|
| 618 | /** |
---|
| 619 | * exits the current script with 404 code when a page cannot be found |
---|
| 620 | * @param string msg a message to display |
---|
| 621 | * @param string alternate_url redirect to this url |
---|
| 622 | */ |
---|
| 623 | function page_not_found($msg, $alternate_url=null) |
---|
| 624 | { |
---|
| 625 | header('HTTP/1.1 404 Not found'); |
---|
| 626 | header('Status: 404 Not found'); |
---|
| 627 | if ($alternate_url==null) |
---|
| 628 | $alternate_url = make_index_url(); |
---|
| 629 | redirect( $alternate_url, |
---|
| 630 | '<div style="text-align:left; margin-left:5em;margin-bottom:5em;"> |
---|
| 631 | <h1 style="text-align:left; font-size:36px;">Page not found</h1><br/>' |
---|
| 632 | .$msg.'</div>', |
---|
| 633 | 5 ); |
---|
| 634 | } |
---|
[1606] | 635 | |
---|
| 636 | /* returns the title to be displayed above thumbnails on tag page |
---|
| 637 | */ |
---|
| 638 | function get_tags_content_title() |
---|
| 639 | { |
---|
| 640 | global $page; |
---|
| 641 | $title = count($page['tags']) > 1 ? l10n('Tags') : l10n('Tag'); |
---|
| 642 | $title.= ' '; |
---|
| 643 | |
---|
| 644 | for ($i=0; $i<count($page['tags']); $i++) |
---|
| 645 | { |
---|
| 646 | $title.= $i>0 ? ' + ' : ''; |
---|
| 647 | |
---|
| 648 | $title.= |
---|
| 649 | '<a href="' |
---|
| 650 | .make_index_url( |
---|
| 651 | array( |
---|
| 652 | 'tags' => array( $page['tags'][$i] ) |
---|
| 653 | ) |
---|
| 654 | ) |
---|
| 655 | .'" title="' |
---|
| 656 | .l10n('See pictures linked to this tag only') |
---|
| 657 | .'">' |
---|
| 658 | .$page['tags'][$i]['name'] |
---|
| 659 | .'</a>'; |
---|
| 660 | |
---|
| 661 | if ( count($page['tags'])>2 ) |
---|
| 662 | { |
---|
| 663 | $other_tags = $page['tags']; |
---|
| 664 | unset ( $other_tags[$i] ); |
---|
| 665 | $title.= |
---|
| 666 | '<a href="' |
---|
| 667 | .make_index_url( |
---|
| 668 | array( |
---|
| 669 | 'tags' => $other_tags |
---|
| 670 | ) |
---|
| 671 | ) |
---|
| 672 | .'" style="border:none;" title="' |
---|
| 673 | .l10n('remove this tag') |
---|
| 674 | .'"><img src="' |
---|
| 675 | .get_root_url().get_themeconf('icon_dir').'/remove_s.png' |
---|
| 676 | .'" alt="x" style="vertical-align:bottom;" class="button"/>' |
---|
| 677 | .'</a>'; |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | } |
---|
| 681 | return $title; |
---|
| 682 | } |
---|
[1119] | 683 | ?> |
---|