[1036] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1703] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1036] | 6 | // +-----------------------------------------------------------------------+ |
---|
[1113] | 7 | // | file : $Id: section_init.inc.php 2201 2008-01-30 22:07:07Z rub $ |
---|
[1092] | 8 | // | last update : $Date: 2008-01-30 22:07:07 +0000 (Wed, 30 Jan 2008) $ |
---|
| 9 | // | last modifier : $Author: rub $ |
---|
| 10 | // | revision : $Revision: 2201 $ |
---|
[1036] | 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 | |
---|
| 27 | /** |
---|
| 28 | * This included page checks section related parameter and provides |
---|
| 29 | * following informations: |
---|
| 30 | * |
---|
| 31 | * - $page['title'] |
---|
| 32 | * |
---|
| 33 | * - $page['items']: ordered list of items to display |
---|
| 34 | * |
---|
| 35 | */ |
---|
| 36 | |
---|
[1861] | 37 | // "index.php?/category/12-foo/start-24" or |
---|
| 38 | // "index.php/category/12-foo/start-24" |
---|
[1090] | 39 | // must return : |
---|
[1082] | 40 | // |
---|
| 41 | // array( |
---|
| 42 | // 'section' => 'categories', |
---|
[1861] | 43 | // 'category' => array('id'=>12, ...), |
---|
[1082] | 44 | // 'start' => 24 |
---|
| 45 | // ); |
---|
[1036] | 46 | |
---|
[1820] | 47 | $page['items'] = array(); |
---|
| 48 | |
---|
[1306] | 49 | // some ISPs set PATH_INFO to empty string or to SCRIPT_FILENAME while in the |
---|
| 50 | // default apache implementation it is not set |
---|
| 51 | if ( $conf['question_mark_in_urls']==false and |
---|
| 52 | isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) |
---|
[1036] | 53 | { |
---|
[1090] | 54 | $rewritten = $_SERVER["PATH_INFO"]; |
---|
| 55 | $rewritten = str_replace('//', '/', $rewritten); |
---|
| 56 | $path_count = count( explode('/', $rewritten) ); |
---|
| 57 | $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | $rewritten = ''; |
---|
| 62 | foreach (array_keys($_GET) as $keynum => $key) |
---|
[1036] | 63 | { |
---|
[1090] | 64 | $rewritten = $key; |
---|
| 65 | break; |
---|
| 66 | } |
---|
| 67 | $page['root_path'] = PHPWG_ROOT_PATH; |
---|
| 68 | } |
---|
[1131] | 69 | |
---|
[1090] | 70 | // deleting first "/" if displayed |
---|
| 71 | $tokens = explode( |
---|
| 72 | '/', |
---|
| 73 | preg_replace('#^/#', '', $rewritten) |
---|
| 74 | ); |
---|
| 75 | // $tokens = array( |
---|
| 76 | // 0 => category, |
---|
| 77 | // 1 => 12-foo, |
---|
| 78 | // 2 => start-24 |
---|
| 79 | // ); |
---|
[1082] | 80 | |
---|
[1090] | 81 | $next_token = 0; |
---|
[1690] | 82 | if (script_basename() == 'picture') // basename without file extention |
---|
[1109] | 83 | { // the first token must be the identifier for the picture |
---|
| 84 | if ( isset($_GET['image_id']) |
---|
| 85 | and isset($_GET['cat']) and is_numeric($_GET['cat']) ) |
---|
| 86 | {// url compatibility with versions below 1.6 |
---|
| 87 | $url = make_picture_url( array( |
---|
| 88 | 'section' => 'categories', |
---|
[1861] | 89 | 'category' => get_cat_info($_GET['cat']), |
---|
[1109] | 90 | 'image_id' => $_GET['image_id'] |
---|
| 91 | ) ); |
---|
| 92 | redirect($url); |
---|
| 93 | } |
---|
| 94 | $token = $tokens[$next_token]; |
---|
| 95 | $next_token++; |
---|
[1092] | 96 | if ( is_numeric($token) ) |
---|
[1090] | 97 | { |
---|
[1092] | 98 | $page['image_id'] = $token; |
---|
[1090] | 99 | } |
---|
[1092] | 100 | else |
---|
| 101 | { |
---|
[1109] | 102 | preg_match('/^(\d+-)?(.*)?$/', $token, $matches); |
---|
[1094] | 103 | if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) ) |
---|
[1092] | 104 | { |
---|
| 105 | $page['image_id'] = $matches[1]; |
---|
[1109] | 106 | if ( !empty($matches[2]) ) |
---|
[1092] | 107 | { |
---|
[1109] | 108 | $page['image_file'] = $matches[2]; |
---|
[1092] | 109 | } |
---|
| 110 | } |
---|
| 111 | else |
---|
| 112 | { |
---|
[1109] | 113 | if ( !empty($matches[2]) ) |
---|
[1092] | 114 | { |
---|
[1109] | 115 | $page['image_file'] = $matches[2]; |
---|
[1092] | 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
[1852] | 119 | bad_request('picture identifier is missing'); |
---|
[1092] | 120 | } |
---|
| 121 | } |
---|
| 122 | } |
---|
[1090] | 123 | } |
---|
[1086] | 124 | |
---|
[1980] | 125 | $page = array_merge( $page, parse_section_url( $tokens, $next_token) ); |
---|
| 126 | if ( !isset($page['section']) ) |
---|
[1090] | 127 | { |
---|
| 128 | $page['section'] = 'categories'; |
---|
[1086] | 129 | |
---|
[1792] | 130 | switch (script_basename()) |
---|
[1788] | 131 | { |
---|
[1792] | 132 | case 'picture': |
---|
| 133 | break; |
---|
| 134 | case 'index': |
---|
| 135 | { |
---|
| 136 | // No section defined, go to selected url |
---|
| 137 | if (!empty($conf['random_index_redirect']) and empty($tokens[$next_token]) ) |
---|
[1788] | 138 | { |
---|
[1792] | 139 | $random_index_redirect = array(); |
---|
| 140 | foreach ($conf['random_index_redirect'] as $random_url => $random_url_condition) |
---|
| 141 | { |
---|
| 142 | if (empty($random_url_condition) or eval($random_url_condition)) |
---|
| 143 | { |
---|
| 144 | $random_index_redirect[] = $random_url; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | if (!empty($random_index_redirect)) |
---|
| 148 | { |
---|
| 149 | redirect($random_index_redirect[mt_rand(0, count($random_index_redirect)-1)]); |
---|
| 150 | } |
---|
[1788] | 151 | } |
---|
[1792] | 152 | break; |
---|
[1788] | 153 | } |
---|
[1880] | 154 | default: |
---|
| 155 | trigger_error('script_basename "'.script_basename().'" unknown', |
---|
| 156 | E_USER_WARNING); |
---|
[1788] | 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
[1119] | 160 | |
---|
[1980] | 161 | $page = array_merge( $page, parse_well_known_params_url( $tokens, $next_token) ); |
---|
[1090] | 162 | |
---|
[1980] | 163 | |
---|
| 164 | if ( script_basename()=='picture' and 'categories'==$page['section'] and |
---|
[1996] | 165 | !isset($page['category']) and !isset($page['chronology_field']) ) |
---|
[1980] | 166 | { //access a picture only by id, file or id-file without given section |
---|
| 167 | $page['flat']=true; |
---|
[1036] | 168 | } |
---|
| 169 | |
---|
[1047] | 170 | // $page['nb_image_page'] is the number of picture to display on this page |
---|
| 171 | // By default, it is the same as the $user['nb_image_page'] |
---|
| 172 | $page['nb_image_page'] = $user['nb_image_page']; |
---|
[1036] | 173 | |
---|
[1623] | 174 | if (pwg_get_session_var('image_order',0) > 0) |
---|
[1051] | 175 | { |
---|
| 176 | $orders = get_category_preferred_image_orders(); |
---|
| 177 | |
---|
| 178 | $conf['order_by'] = str_replace( |
---|
| 179 | 'ORDER BY ', |
---|
[1623] | 180 | 'ORDER BY '.$orders[ pwg_get_session_var('image_order',0) ][1].',', |
---|
[1051] | 181 | $conf['order_by'] |
---|
| 182 | ); |
---|
| 183 | $page['super_order_by'] = true; |
---|
| 184 | } |
---|
| 185 | |
---|
[1711] | 186 | $forbidden = get_sql_condition_FandF( |
---|
| 187 | array |
---|
| 188 | ( |
---|
| 189 | 'forbidden_categories' => 'category_id', |
---|
| 190 | 'visible_categories' => 'category_id', |
---|
[1820] | 191 | 'visible_images' => 'id' |
---|
[1711] | 192 | ), |
---|
| 193 | 'AND' |
---|
| 194 | ); |
---|
| 195 | |
---|
[1036] | 196 | // +-----------------------------------------------------------------------+ |
---|
| 197 | // | category | |
---|
| 198 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 199 | if ('categories' == $page['section']) |
---|
| 200 | { |
---|
| 201 | if (isset($page['category'])) |
---|
[1036] | 202 | { |
---|
| 203 | $page = array_merge( |
---|
| 204 | $page, |
---|
| 205 | array( |
---|
[2117] | 206 | 'comment' => |
---|
| 207 | trigger_event( |
---|
| 208 | 'render_category_description', |
---|
[2175] | 209 | $page['category']['comment'], |
---|
| 210 | 'main_page_category_description' |
---|
[2117] | 211 | ), |
---|
[1703] | 212 | 'title' => |
---|
[1980] | 213 | get_cat_display_name($page['category']['upper_names'], '', false), |
---|
[1051] | 214 | ) |
---|
| 215 | ); |
---|
[1677] | 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
[2201] | 219 | $page['title'] = l10n('no_category'); |
---|
[1677] | 220 | } |
---|
[1086] | 221 | |
---|
[1703] | 222 | if |
---|
[1677] | 223 | ( |
---|
| 224 | (!isset($page['chronology_field'])) and |
---|
| 225 | ( |
---|
[1703] | 226 | (isset($page['category'])) or |
---|
[1800] | 227 | (isset($page['flat'])) |
---|
[1677] | 228 | ) |
---|
| 229 | ) |
---|
| 230 | { |
---|
[1983] | 231 | if ( !empty($page['category']['image_order']) and !isset($page['super_order_by']) ) |
---|
[1051] | 232 | { |
---|
[1983] | 233 | $conf[ 'order_by' ] = ' ORDER BY '.$page['category']['image_order']; |
---|
[1677] | 234 | } |
---|
| 235 | |
---|
[1800] | 236 | if (isset($page['flat'])) |
---|
[1820] | 237 | {// flat categories mode |
---|
| 238 | if ( isset($page['category']) ) |
---|
[1500] | 239 | { |
---|
[1861] | 240 | $subcat_ids = get_subcat_ids( array($page['category']['id']) ); |
---|
[1820] | 241 | $where_sql = 'category_id IN ('.implode(',',$subcat_ids).')'; |
---|
[1500] | 242 | } |
---|
[1820] | 243 | else |
---|
| 244 | { |
---|
| 245 | $where_sql = '1=1'; |
---|
| 246 | } |
---|
[1677] | 247 | } |
---|
| 248 | else |
---|
[1820] | 249 | {// Normal mode |
---|
[1861] | 250 | $where_sql = 'category_id = '.$page['category']['id']; |
---|
[1677] | 251 | } |
---|
[1500] | 252 | |
---|
[1820] | 253 | // Main query |
---|
| 254 | $query = ' |
---|
[1711] | 255 | SELECT DISTINCT(image_id) |
---|
[1051] | 256 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 257 | INNER JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
[1677] | 258 | WHERE |
---|
| 259 | '.$where_sql.' |
---|
[1711] | 260 | '.$forbidden.' |
---|
[1051] | 261 | '.$conf['order_by'].' |
---|
| 262 | ;'; |
---|
[1677] | 263 | |
---|
[1820] | 264 | $page['items'] = array_from_query($query, 'image_id'); |
---|
[1677] | 265 | } //otherwise the calendar will requery all subitems |
---|
[1082] | 266 | } |
---|
| 267 | // special sections |
---|
| 268 | else |
---|
| 269 | { |
---|
[1036] | 270 | // +-----------------------------------------------------------------------+ |
---|
[1119] | 271 | // | tags section | |
---|
| 272 | // +-----------------------------------------------------------------------+ |
---|
| 273 | if ($page['section'] == 'tags') |
---|
| 274 | { |
---|
| 275 | $page['tag_ids'] = array(); |
---|
| 276 | foreach ($page['tags'] as $tag) |
---|
| 277 | { |
---|
| 278 | array_push($page['tag_ids'], $tag['id']); |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | $items = get_image_ids_for_tags($page['tag_ids']); |
---|
| 282 | |
---|
| 283 | // permissions depends on category, so to only keep images that are |
---|
| 284 | // reachable to the connected user, we need to check category |
---|
| 285 | // associations |
---|
[1131] | 286 | if (!empty($items) ) |
---|
[1119] | 287 | { |
---|
| 288 | $query = ' |
---|
| 289 | SELECT image_id |
---|
[1125] | 290 | FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
[1119] | 291 | WHERE image_id IN ('.implode(',', $items).') |
---|
[1677] | 292 | '.$forbidden. |
---|
[1125] | 293 | $conf['order_by'].' |
---|
[1119] | 294 | ;'; |
---|
| 295 | $items = array_unique( |
---|
| 296 | array_from_query($query, 'image_id') |
---|
| 297 | ); |
---|
| 298 | } |
---|
| 299 | |
---|
[1606] | 300 | $title = get_tags_content_title(); |
---|
[1119] | 301 | |
---|
| 302 | $page = array_merge( |
---|
| 303 | $page, |
---|
| 304 | array( |
---|
| 305 | 'title' => $title, |
---|
| 306 | 'items' => array_values($items), |
---|
| 307 | ) |
---|
| 308 | ); |
---|
| 309 | } |
---|
| 310 | // +-----------------------------------------------------------------------+ |
---|
[1036] | 311 | // | search section | |
---|
| 312 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 313 | if ($page['section'] == 'search') |
---|
| 314 | { |
---|
[1113] | 315 | include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); |
---|
[1119] | 316 | |
---|
[1537] | 317 | $search_result = get_search_results($page['search']); |
---|
| 318 | if ( !empty($search_result['items']) and !isset($search_result['as_is']) ) |
---|
[1120] | 319 | { |
---|
| 320 | $query = ' |
---|
[1036] | 321 | SELECT DISTINCT(id) |
---|
| 322 | FROM '.IMAGES_TABLE.' |
---|
| 323 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
[1537] | 324 | WHERE id IN ('.implode(',', $search_result['items']).') |
---|
[1677] | 325 | '.$forbidden.' |
---|
[1036] | 326 | '.$conf['order_by'].' |
---|
[1120] | 327 | ;'; |
---|
| 328 | $page['items'] = array_from_query($query, 'id'); |
---|
| 329 | } |
---|
| 330 | else |
---|
| 331 | { |
---|
[1537] | 332 | $page['items'] = $search_result['items']; |
---|
[2135] | 333 | if ( isset($search_result['qs']) ) |
---|
| 334 | {//save the details of the query search |
---|
| 335 | $page['qsearch_details'] = $search_result['qs']; |
---|
| 336 | } |
---|
[1120] | 337 | } |
---|
[1036] | 338 | |
---|
[1082] | 339 | $page = array_merge( |
---|
| 340 | $page, |
---|
| 341 | array( |
---|
[2117] | 342 | 'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
[2201] | 343 | .l10n('search_result').'</a>', |
---|
[1082] | 344 | ) |
---|
| 345 | ); |
---|
| 346 | } |
---|
[1036] | 347 | // +-----------------------------------------------------------------------+ |
---|
| 348 | // | favorite section | |
---|
| 349 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 350 | else if ($page['section'] == 'favorites') |
---|
| 351 | { |
---|
| 352 | check_user_favorites(); |
---|
[1036] | 353 | |
---|
[1082] | 354 | $query = ' |
---|
[1036] | 355 | SELECT image_id |
---|
| 356 | FROM '.FAVORITES_TABLE.' |
---|
| 357 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
| 358 | WHERE user_id = '.$user['id'].' |
---|
[1677] | 359 | '.get_sql_condition_FandF |
---|
| 360 | ( |
---|
| 361 | array |
---|
| 362 | ( |
---|
| 363 | 'visible_images' => 'image_id' |
---|
| 364 | ), |
---|
| 365 | 'AND' |
---|
| 366 | ).' |
---|
[1036] | 367 | '.$conf['order_by'].' |
---|
| 368 | ;'; |
---|
| 369 | |
---|
[1082] | 370 | $page = array_merge( |
---|
| 371 | $page, |
---|
| 372 | array( |
---|
[2201] | 373 | 'title' => l10n('favorites'), |
---|
[1082] | 374 | 'items' => array_from_query($query, 'image_id'), |
---|
| 375 | ) |
---|
| 376 | ); |
---|
| 377 | } |
---|
[1036] | 378 | // +-----------------------------------------------------------------------+ |
---|
| 379 | // | recent pictures section | |
---|
| 380 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 381 | else if ($page['section'] == 'recent_pics') |
---|
| 382 | { |
---|
| 383 | $query = ' |
---|
[1036] | 384 | SELECT DISTINCT(id) |
---|
| 385 | FROM '.IMAGES_TABLE.' |
---|
| 386 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
[1876] | 387 | WHERE |
---|
| 388 | date_available >= SUBDATE( |
---|
| 389 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY) |
---|
[1677] | 390 | '.$forbidden.' |
---|
[1036] | 391 | '.$conf['order_by'].' |
---|
| 392 | ;'; |
---|
| 393 | |
---|
[1082] | 394 | $page = array_merge( |
---|
| 395 | $page, |
---|
| 396 | array( |
---|
[2117] | 397 | 'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
[2201] | 398 | .l10n('recent_pics_cat').'</a>', |
---|
[1082] | 399 | 'items' => array_from_query($query, 'id'), |
---|
| 400 | ) |
---|
| 401 | ); |
---|
| 402 | } |
---|
[1036] | 403 | // +-----------------------------------------------------------------------+ |
---|
| 404 | // | recently updated categories section | |
---|
| 405 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 406 | else if ($page['section'] == 'recent_cats') |
---|
| 407 | { |
---|
| 408 | $page = array_merge( |
---|
| 409 | $page, |
---|
| 410 | array( |
---|
[2201] | 411 | 'title' => l10n('recent_cats_cat'), |
---|
[1082] | 412 | ) |
---|
| 413 | ); |
---|
| 414 | } |
---|
[1036] | 415 | // +-----------------------------------------------------------------------+ |
---|
| 416 | // | most visited section | |
---|
| 417 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 418 | else if ($page['section'] == 'most_visited') |
---|
| 419 | { |
---|
| 420 | $page['super_order_by'] = true; |
---|
| 421 | $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; |
---|
| 422 | $query = ' |
---|
[1036] | 423 | SELECT DISTINCT(id) |
---|
| 424 | FROM '.IMAGES_TABLE.' |
---|
| 425 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
| 426 | WHERE hit > 0 |
---|
[1677] | 427 | '.$forbidden.' |
---|
[1082] | 428 | '.$conf['order_by'].' |
---|
[1036] | 429 | LIMIT 0, '.$conf['top_number'].' |
---|
| 430 | ;'; |
---|
[1086] | 431 | |
---|
[1082] | 432 | $page = array_merge( |
---|
| 433 | $page, |
---|
| 434 | array( |
---|
[2117] | 435 | 'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
[2201] | 436 | .$conf['top_number'].' '.l10n('most_visited_cat').'</a>', |
---|
[1082] | 437 | 'items' => array_from_query($query, 'id'), |
---|
| 438 | ) |
---|
| 439 | ); |
---|
| 440 | } |
---|
[1036] | 441 | // +-----------------------------------------------------------------------+ |
---|
| 442 | // | best rated section | |
---|
| 443 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 444 | else if ($page['section'] == 'best_rated') |
---|
| 445 | { |
---|
| 446 | $page['super_order_by'] = true; |
---|
| 447 | $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; |
---|
[1086] | 448 | |
---|
[1082] | 449 | $query =' |
---|
[1036] | 450 | SELECT DISTINCT(id) |
---|
| 451 | FROM '.IMAGES_TABLE.' |
---|
| 452 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
| 453 | WHERE average_rate IS NOT NULL |
---|
[1677] | 454 | '.$forbidden.' |
---|
[1082] | 455 | '.$conf['order_by'].' |
---|
[1036] | 456 | LIMIT 0, '.$conf['top_number'].' |
---|
| 457 | ;'; |
---|
[1082] | 458 | $page = array_merge( |
---|
| 459 | $page, |
---|
| 460 | array( |
---|
[2117] | 461 | 'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
[2201] | 462 | .$conf['top_number'].' '.l10n('best_rated_cat').'</a>', |
---|
[1082] | 463 | 'items' => array_from_query($query, 'id'), |
---|
| 464 | ) |
---|
| 465 | ); |
---|
| 466 | } |
---|
[1036] | 467 | // +-----------------------------------------------------------------------+ |
---|
| 468 | // | list section | |
---|
| 469 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 470 | else if ($page['section'] == 'list') |
---|
| 471 | { |
---|
| 472 | $query =' |
---|
[1036] | 473 | SELECT DISTINCT(id) |
---|
| 474 | FROM '.IMAGES_TABLE.' |
---|
| 475 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
[1082] | 476 | WHERE image_id IN ('.implode(',', $page['list']).') |
---|
[1677] | 477 | '.$forbidden.' |
---|
[1036] | 478 | '.$conf['order_by'].' |
---|
| 479 | ;'; |
---|
[1086] | 480 | |
---|
[1082] | 481 | $page = array_merge( |
---|
| 482 | $page, |
---|
| 483 | array( |
---|
[2117] | 484 | 'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
[2201] | 485 | .l10n('random_cat').'</a>', |
---|
[1082] | 486 | 'items' => array_from_query($query, 'id'), |
---|
| 487 | ) |
---|
| 488 | ); |
---|
[1036] | 489 | } |
---|
| 490 | } |
---|
[1082] | 491 | |
---|
[1036] | 492 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 493 | // | chronology | |
---|
[1036] | 494 | // +-----------------------------------------------------------------------+ |
---|
[1047] | 495 | |
---|
[1090] | 496 | if (isset($page['chronology_field'])) |
---|
[1047] | 497 | { |
---|
| 498 | include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); |
---|
| 499 | initialize_calendar(); |
---|
| 500 | } |
---|
| 501 | |
---|
[1690] | 502 | if (script_basename() == 'picture' |
---|
[1092] | 503 | and !isset($page['image_id']) ) |
---|
| 504 | { |
---|
[1094] | 505 | if ( !empty($page['items']) ) |
---|
| 506 | { |
---|
| 507 | $query = ' |
---|
[1092] | 508 | SELECT id,file |
---|
| 509 | FROM '.IMAGES_TABLE .' |
---|
| 510 | WHERE id IN ('.implode(',',$page['items']).') |
---|
| 511 | AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"' |
---|
| 512 | ; |
---|
[1094] | 513 | $result = pwg_query($query); |
---|
| 514 | if (mysql_num_rows($result)>0) |
---|
| 515 | { |
---|
| 516 | list($page['image_id'], $page['image_file']) = mysql_fetch_row($result); |
---|
| 517 | } |
---|
| 518 | } |
---|
| 519 | if ( !isset($page['image_id']) ) |
---|
[1092] | 520 | { |
---|
[1094] | 521 | $page['image_id'] = -1; // will fail in picture.php |
---|
[1092] | 522 | } |
---|
| 523 | } |
---|
[1604] | 524 | |
---|
[1703] | 525 | // add meta robots noindex, nofollow to avoid unnecesary robot crawls |
---|
| 526 | $page['meta_robots']=array(); |
---|
[2135] | 527 | if ( isset($page['chronology_field']) |
---|
| 528 | or ( isset($page['flat']) and isset($page['category']) ) |
---|
[1703] | 529 | or 'list'==$page['section'] or 'recent_pics'==$page['section'] ) |
---|
| 530 | { |
---|
| 531 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
| 532 | } |
---|
| 533 | elseif ('tags' == $page['section']) |
---|
| 534 | { |
---|
| 535 | if ( count($page['tag_ids'])>1 ) |
---|
| 536 | { |
---|
| 537 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
| 538 | } |
---|
| 539 | } |
---|
| 540 | elseif ('recent_cats'==$page['section']) |
---|
| 541 | { |
---|
[2138] | 542 | $page['meta_robots']['noindex']=1; |
---|
| 543 | } |
---|
| 544 | elseif ('search'==$page['section']) |
---|
| 545 | { |
---|
[1703] | 546 | $page['meta_robots']['nofollow']=1; |
---|
| 547 | } |
---|
| 548 | if ( $filter['enabled'] ) |
---|
| 549 | { |
---|
| 550 | $page['meta_robots']['noindex']=1; |
---|
| 551 | } |
---|
| 552 | |
---|
[1866] | 553 | // see if we need a redirect because of a permalink |
---|
| 554 | if ( 'categories'==$page['section'] and isset($page['category']) ) |
---|
| 555 | { |
---|
| 556 | $need_redirect=false; |
---|
| 557 | if ( empty($page['category']['permalink']) ) |
---|
| 558 | { |
---|
| 559 | if ( $conf['category_url_style'] == 'id-name' and |
---|
| 560 | @$page['hit_by']['cat_url_name'] !== str2url($page['category']['name']) ) |
---|
| 561 | { |
---|
| 562 | $need_redirect=true; |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | else |
---|
| 566 | { |
---|
| 567 | if ( $page['category']['permalink'] !== @$page['hit_by']['cat_permalink'] ) |
---|
| 568 | { |
---|
| 569 | $need_redirect=true; |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | if ($need_redirect) |
---|
| 574 | { |
---|
| 575 | $redirect_url = ( script_basename()=='picture' |
---|
| 576 | ? duplicate_picture_url() |
---|
| 577 | : duplicate_index_url() |
---|
| 578 | ); |
---|
| 579 | if (!headers_sent()) |
---|
| 580 | { // this is a permanent redirection |
---|
[1950] | 581 | set_status_header(301); |
---|
[1866] | 582 | redirect_http( $redirect_url ); |
---|
| 583 | } |
---|
| 584 | redirect( $redirect_url ); |
---|
| 585 | } |
---|
| 586 | unset( $need_redirect, $page['hit_by'] ); |
---|
| 587 | } |
---|
| 588 | |
---|
[1604] | 589 | trigger_action('loc_end_section_init'); |
---|
[1036] | 590 | ?> |
---|