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