[1036] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1125] | 5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1036] | 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
[1113] | 8 | // | file : $Id: section_init.inc.php 1681 2006-12-27 20:26:36Z rub $ |
---|
[1092] | 9 | // | last update : $Date: 2006-12-27 20:26:36 +0000 (Wed, 27 Dec 2006) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
| 11 | // | revision : $Revision: 1681 $ |
---|
[1036] | 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 | /** |
---|
| 29 | * This included page checks section related parameter and provides |
---|
| 30 | * following informations: |
---|
| 31 | * |
---|
| 32 | * - $page['title'] |
---|
| 33 | * |
---|
| 34 | * - $page['items']: ordered list of items to display |
---|
| 35 | * |
---|
| 36 | * - $page['cat_nb_images']: number of items in the section (should be equal |
---|
| 37 | * to count($page['items'])) |
---|
| 38 | * |
---|
| 39 | * - $page['thumbnails_include']: include page managing thumbnails to |
---|
| 40 | * display |
---|
| 41 | */ |
---|
| 42 | |
---|
[1090] | 43 | // "index.php?/category/12-foo/start-24&action=fill_caddie" or |
---|
| 44 | // "index.php/category/12-foo/start-24&action=fill_caddie" |
---|
| 45 | // must return : |
---|
[1082] | 46 | // |
---|
| 47 | // array( |
---|
| 48 | // 'section' => 'categories', |
---|
| 49 | // 'category' => 12, |
---|
| 50 | // 'start' => 24 |
---|
| 51 | // 'action' => 'fill_caddie' |
---|
| 52 | // ); |
---|
[1036] | 53 | |
---|
[1082] | 54 | $page['section'] = 'categories'; |
---|
| 55 | |
---|
[1306] | 56 | // some ISPs set PATH_INFO to empty string or to SCRIPT_FILENAME while in the |
---|
| 57 | // default apache implementation it is not set |
---|
| 58 | if ( $conf['question_mark_in_urls']==false and |
---|
| 59 | isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) |
---|
[1036] | 60 | { |
---|
[1090] | 61 | $rewritten = $_SERVER["PATH_INFO"]; |
---|
| 62 | $rewritten = str_replace('//', '/', $rewritten); |
---|
| 63 | $path_count = count( explode('/', $rewritten) ); |
---|
| 64 | $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1); |
---|
| 65 | } |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | $rewritten = ''; |
---|
| 69 | foreach (array_keys($_GET) as $keynum => $key) |
---|
[1036] | 70 | { |
---|
[1090] | 71 | $rewritten = $key; |
---|
| 72 | break; |
---|
| 73 | } |
---|
| 74 | $page['root_path'] = PHPWG_ROOT_PATH; |
---|
| 75 | } |
---|
[1131] | 76 | |
---|
[1090] | 77 | // deleting first "/" if displayed |
---|
| 78 | $tokens = explode( |
---|
| 79 | '/', |
---|
| 80 | preg_replace('#^/#', '', $rewritten) |
---|
| 81 | ); |
---|
| 82 | // $tokens = array( |
---|
| 83 | // 0 => category, |
---|
| 84 | // 1 => 12-foo, |
---|
| 85 | // 2 => start-24 |
---|
| 86 | // ); |
---|
[1082] | 87 | |
---|
[1090] | 88 | $next_token = 0; |
---|
[1094] | 89 | if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php') |
---|
[1109] | 90 | { // the first token must be the identifier for the picture |
---|
| 91 | if ( isset($_GET['image_id']) |
---|
| 92 | and isset($_GET['cat']) and is_numeric($_GET['cat']) ) |
---|
| 93 | {// url compatibility with versions below 1.6 |
---|
| 94 | $url = make_picture_url( array( |
---|
| 95 | 'section' => 'categories', |
---|
| 96 | 'category' => $_GET['cat'], |
---|
| 97 | 'image_id' => $_GET['image_id'] |
---|
| 98 | ) ); |
---|
| 99 | redirect($url); |
---|
| 100 | } |
---|
| 101 | $token = $tokens[$next_token]; |
---|
| 102 | $next_token++; |
---|
[1092] | 103 | if ( is_numeric($token) ) |
---|
[1090] | 104 | { |
---|
[1092] | 105 | $page['image_id'] = $token; |
---|
[1090] | 106 | } |
---|
[1092] | 107 | else |
---|
| 108 | { |
---|
[1109] | 109 | preg_match('/^(\d+-)?(.*)?$/', $token, $matches); |
---|
[1094] | 110 | if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) ) |
---|
[1092] | 111 | { |
---|
| 112 | $page['image_id'] = $matches[1]; |
---|
[1109] | 113 | if ( !empty($matches[2]) ) |
---|
[1092] | 114 | { |
---|
[1109] | 115 | $page['image_file'] = $matches[2]; |
---|
[1092] | 116 | } |
---|
[1094] | 117 | |
---|
[1092] | 118 | } |
---|
| 119 | else |
---|
| 120 | { |
---|
[1109] | 121 | if ( !empty($matches[2]) ) |
---|
[1092] | 122 | { |
---|
[1109] | 123 | $page['image_file'] = $matches[2]; |
---|
[1092] | 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | die('Fatal: picture identifier is missing'); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | } |
---|
[1090] | 131 | } |
---|
[1086] | 132 | |
---|
[1109] | 133 | if (0 === strpos($tokens[$next_token], 'categor')) |
---|
[1090] | 134 | { |
---|
| 135 | $page['section'] = 'categories'; |
---|
| 136 | $next_token++; |
---|
[1086] | 137 | |
---|
[1090] | 138 | if (isset($tokens[$next_token]) |
---|
| 139 | and preg_match('/^(\d+)/', $tokens[$next_token], $matches)) |
---|
| 140 | { |
---|
| 141 | $page['category'] = $matches[1]; |
---|
| 142 | $next_token++; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | else if (0 === strpos($tokens[$next_token], 'tag')) |
---|
| 146 | { |
---|
| 147 | $page['section'] = 'tags'; |
---|
| 148 | $page['tags'] = array(); |
---|
[1086] | 149 | |
---|
[1090] | 150 | $next_token++; |
---|
[1119] | 151 | $i = $next_token; |
---|
[1086] | 152 | |
---|
[1131] | 153 | $requested_tag_ids = array(); |
---|
| 154 | $requested_tag_url_names = array(); |
---|
| 155 | |
---|
[1119] | 156 | while (isset($tokens[$i])) |
---|
[1090] | 157 | { |
---|
[1131] | 158 | if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) ) |
---|
| 159 | break; |
---|
| 160 | |
---|
| 161 | if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) ) |
---|
[1082] | 162 | { |
---|
[1131] | 163 | array_push($requested_tag_ids, $matches[1]); |
---|
[1082] | 164 | } |
---|
[1131] | 165 | else |
---|
| 166 | { |
---|
| 167 | array_push($requested_tag_url_names, "'".$tokens[$i]."'"); |
---|
| 168 | } |
---|
[1119] | 169 | $i++; |
---|
[1090] | 170 | } |
---|
[1131] | 171 | $next_token = $i; |
---|
[1086] | 172 | |
---|
[1131] | 173 | if ( empty($requested_tag_ids) && empty($requested_tag_url_names) ) |
---|
| 174 | { |
---|
| 175 | die('Fatal: at least one tag required'); |
---|
| 176 | } |
---|
| 177 | // tag infos |
---|
| 178 | $query = ' |
---|
| 179 | SELECT name, url_name, id |
---|
| 180 | FROM '.TAGS_TABLE.' |
---|
| 181 | WHERE '; |
---|
| 182 | if ( !empty($requested_tag_ids) ) |
---|
| 183 | { |
---|
| 184 | $query.= 'id IN ('.implode(',', $requested_tag_ids ).')'; |
---|
| 185 | } |
---|
| 186 | if ( !empty($requested_tag_url_names) ) |
---|
| 187 | { |
---|
| 188 | if ( !empty($requested_tag_ids) ) |
---|
| 189 | { |
---|
| 190 | $query.= ' OR '; |
---|
| 191 | } |
---|
| 192 | $query.= 'url_name IN ('.implode(',', $requested_tag_url_names ).')'; |
---|
| 193 | } |
---|
| 194 | $result = pwg_query($query); |
---|
| 195 | $tag_infos = array(); |
---|
[1606] | 196 | while ($row = mysql_fetch_assoc($result)) |
---|
[1131] | 197 | { |
---|
| 198 | $tag_infos[ $row['id'] ] = $row; |
---|
| 199 | array_push($page['tags'], $row );//we loose given tag order; is it important? |
---|
| 200 | } |
---|
| 201 | if ( empty($page['tags']) ) |
---|
| 202 | { |
---|
[1288] | 203 | page_not_found('Requested tag does not exist', get_root_url().'tags.php' ); |
---|
[1131] | 204 | } |
---|
[1090] | 205 | } |
---|
| 206 | else if (0 === strpos($tokens[$next_token], 'fav')) |
---|
| 207 | { |
---|
| 208 | $page['section'] = 'favorites'; |
---|
| 209 | $next_token++; |
---|
| 210 | } |
---|
| 211 | else if ('most_visited' == $tokens[$next_token]) |
---|
| 212 | { |
---|
| 213 | $page['section'] = 'most_visited'; |
---|
| 214 | $next_token++; |
---|
| 215 | } |
---|
| 216 | else if ('best_rated' == $tokens[$next_token]) |
---|
| 217 | { |
---|
| 218 | $page['section'] = 'best_rated'; |
---|
| 219 | $next_token++; |
---|
| 220 | } |
---|
| 221 | else if ('recent_pics' == $tokens[$next_token]) |
---|
| 222 | { |
---|
| 223 | $page['section'] = 'recent_pics'; |
---|
| 224 | $next_token++; |
---|
| 225 | } |
---|
| 226 | else if ('recent_cats' == $tokens[$next_token]) |
---|
| 227 | { |
---|
| 228 | $page['section'] = 'recent_cats'; |
---|
| 229 | $next_token++; |
---|
| 230 | } |
---|
| 231 | else if ('search' == $tokens[$next_token]) |
---|
| 232 | { |
---|
| 233 | $page['section'] = 'search'; |
---|
| 234 | $next_token++; |
---|
[1086] | 235 | |
---|
[1090] | 236 | preg_match('/(\d+)/', $tokens[$next_token], $matches); |
---|
| 237 | if (!isset($matches[1])) |
---|
| 238 | { |
---|
| 239 | die('Fatal: search identifier is missing'); |
---|
| 240 | } |
---|
| 241 | $page['search'] = $matches[1]; |
---|
| 242 | $next_token++; |
---|
| 243 | } |
---|
| 244 | else if ('list' == $tokens[$next_token]) |
---|
| 245 | { |
---|
| 246 | $page['section'] = 'list'; |
---|
| 247 | $next_token++; |
---|
[1082] | 248 | |
---|
[1090] | 249 | $page['list'] = array(); |
---|
[1681] | 250 | |
---|
| 251 | // No pictures |
---|
| 252 | if (empty($tokens[$next_token])) |
---|
[1090] | 253 | { |
---|
[1681] | 254 | // Add dummy element list |
---|
| 255 | array_push($page['list'], -1); |
---|
[1090] | 256 | } |
---|
[1681] | 257 | // With pictures list |
---|
| 258 | else |
---|
[1090] | 259 | { |
---|
[1681] | 260 | if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token])) |
---|
| 261 | { |
---|
| 262 | die('wrong format on list GET parameter'); |
---|
| 263 | } |
---|
| 264 | foreach (explode(',', $tokens[$next_token]) as $image_id) |
---|
| 265 | { |
---|
| 266 | array_push($page['list'], $image_id); |
---|
| 267 | } |
---|
[1090] | 268 | } |
---|
| 269 | $next_token++; |
---|
| 270 | } |
---|
| 271 | |
---|
[1119] | 272 | $i = $next_token; |
---|
| 273 | |
---|
| 274 | while (isset($tokens[$i])) |
---|
[1090] | 275 | { |
---|
| 276 | if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) |
---|
| 277 | { |
---|
| 278 | $page['start'] = $matches[1]; |
---|
| 279 | } |
---|
| 280 | |
---|
[1677] | 281 | if (preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches)) |
---|
| 282 | { |
---|
| 283 | // indicate a special list of images |
---|
| 284 | $page['flat_recent_cat'] = $matches[1]; |
---|
| 285 | } |
---|
| 286 | |
---|
[1131] | 287 | if (preg_match('/^(posted|created)/', $tokens[$i] )) |
---|
[1090] | 288 | { |
---|
| 289 | $chronology_tokens = explode('-', $tokens[$i] ); |
---|
[1119] | 290 | |
---|
[1090] | 291 | $page['chronology_field'] = $chronology_tokens[0]; |
---|
[1119] | 292 | |
---|
[1090] | 293 | array_shift($chronology_tokens); |
---|
| 294 | $page['chronology_style'] = $chronology_tokens[0]; |
---|
[1119] | 295 | |
---|
[1090] | 296 | array_shift($chronology_tokens); |
---|
| 297 | if ( count($chronology_tokens)>0 ) |
---|
| 298 | { |
---|
| 299 | if ('list'==$chronology_tokens[0] or |
---|
| 300 | 'calendar'==$chronology_tokens[0]) |
---|
[1082] | 301 | { |
---|
[1090] | 302 | $page['chronology_view'] = $chronology_tokens[0]; |
---|
[1086] | 303 | array_shift($chronology_tokens); |
---|
[1082] | 304 | } |
---|
[1090] | 305 | $page['chronology_date'] = $chronology_tokens; |
---|
[1082] | 306 | } |
---|
[1036] | 307 | } |
---|
[1119] | 308 | |
---|
| 309 | $i++; |
---|
[1036] | 310 | } |
---|
| 311 | |
---|
[1090] | 312 | |
---|
[1047] | 313 | // $page['nb_image_page'] is the number of picture to display on this page |
---|
| 314 | // By default, it is the same as the $user['nb_image_page'] |
---|
| 315 | $page['nb_image_page'] = $user['nb_image_page']; |
---|
[1036] | 316 | |
---|
[1623] | 317 | if (pwg_get_session_var('image_order',0) > 0) |
---|
[1051] | 318 | { |
---|
| 319 | $orders = get_category_preferred_image_orders(); |
---|
| 320 | |
---|
| 321 | $conf['order_by'] = str_replace( |
---|
| 322 | 'ORDER BY ', |
---|
[1623] | 323 | 'ORDER BY '.$orders[ pwg_get_session_var('image_order',0) ][1].',', |
---|
[1051] | 324 | $conf['order_by'] |
---|
| 325 | ); |
---|
| 326 | $page['super_order_by'] = true; |
---|
| 327 | } |
---|
| 328 | |
---|
[1036] | 329 | // +-----------------------------------------------------------------------+ |
---|
| 330 | // | category | |
---|
| 331 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 332 | if ('categories' == $page['section']) |
---|
| 333 | { |
---|
| 334 | if (isset($page['category'])) |
---|
[1036] | 335 | { |
---|
[1082] | 336 | $result = get_cat_info($page['category']); |
---|
[1288] | 337 | if (empty($result)) |
---|
| 338 | { |
---|
| 339 | page_not_found('Requested category does not exist' ); |
---|
| 340 | } |
---|
[1086] | 341 | |
---|
[1036] | 342 | $page = array_merge( |
---|
| 343 | $page, |
---|
| 344 | array( |
---|
[1677] | 345 | 'comment' => $result['comment'], |
---|
| 346 | 'cat_dir' => $result['dir'], |
---|
| 347 | 'cat_name' => $result['name'], |
---|
| 348 | 'cat_site_id' => $result['site_id'], |
---|
| 349 | 'cat_uploadable' => $result['uploadable'], |
---|
| 350 | 'cat_commentable' => $result['commentable'], |
---|
| 351 | 'cat_id_uppercat' => $result['id_uppercat'], |
---|
| 352 | 'uppercats' => $result['uppercats'], |
---|
| 353 | 'title' => |
---|
| 354 | get_cat_display_name($result['name'], '', false), |
---|
| 355 | 'thumbnails_include' => |
---|
| 356 | (($result['nb_images'] > 0) or (isset($page['flat_recent_cat']))) |
---|
| 357 | ? 'include/category_default.inc.php' |
---|
| 358 | : 'include/category_cats.inc.php' |
---|
[1051] | 359 | ) |
---|
| 360 | ); |
---|
[1677] | 361 | } |
---|
| 362 | else |
---|
| 363 | { |
---|
| 364 | $page['title'] = $lang['no_category']; |
---|
| 365 | $page['thumbnails_include'] = |
---|
| 366 | (isset($page['flat_recent_cat'])) |
---|
| 367 | ? 'include/category_default.inc.php' |
---|
| 368 | : 'include/category_cats.inc.php'; |
---|
| 369 | } |
---|
[1086] | 370 | |
---|
[1677] | 371 | if (isset($page['flat_recent_cat'])) |
---|
| 372 | { |
---|
| 373 | $page['title'] = $lang['recent_pics_cat'].' : '.$page['title'] ; |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | if |
---|
| 377 | ( |
---|
| 378 | (!isset($page['chronology_field'])) and |
---|
| 379 | ( |
---|
| 380 | (isset($page['category'])) or |
---|
| 381 | (isset($page['flat_recent_cat'])) |
---|
| 382 | ) |
---|
| 383 | ) |
---|
| 384 | { |
---|
| 385 | if ( !empty($result['image_order']) and !isset($page['super_order_by']) ) |
---|
[1051] | 386 | { |
---|
[1677] | 387 | $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order']; |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | if (isset($page['flat_recent_cat'])) |
---|
| 391 | { |
---|
| 392 | // flat recent categories mode |
---|
| 393 | $query = ' |
---|
| 394 | SELECT |
---|
| 395 | DISTINCT(ic.image_id) |
---|
| 396 | FROM '.IMAGES_TABLE.' AS i |
---|
| 397 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
| 398 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
| 399 | WHERE |
---|
| 400 | date_available > SUBDATE( |
---|
| 401 | CURRENT_DATE,INTERVAL '.$page['flat_recent_cat'].' DAY)'. |
---|
| 402 | (isset($page['category']) ? ' |
---|
| 403 | AND uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '' ).' |
---|
| 404 | '.get_sql_condition_FandF |
---|
| 405 | ( |
---|
| 406 | array |
---|
| 407 | ( |
---|
| 408 | 'forbidden_categories' => 'category_id', |
---|
| 409 | 'visible_categories' => 'category_id', |
---|
| 410 | 'visible_images' => 'image_id' |
---|
| 411 | ), |
---|
| 412 | 'AND' |
---|
| 413 | ).' |
---|
| 414 | ;'; |
---|
| 415 | |
---|
| 416 | $where_sql = array_from_query($query, 'image_id'); |
---|
| 417 | if (!empty($where_sql)) |
---|
[1500] | 418 | { |
---|
[1677] | 419 | $where_sql = 'image_id in ('.implode(',', $where_sql).')'; |
---|
[1500] | 420 | } |
---|
[1677] | 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | // Normal mode |
---|
| 425 | $where_sql = 'category_id = '.$page['category']; |
---|
| 426 | } |
---|
[1500] | 427 | |
---|
[1677] | 428 | if (!empty($where_sql)) |
---|
| 429 | { |
---|
| 430 | // Main query |
---|
[1051] | 431 | $query = ' |
---|
| 432 | SELECT image_id |
---|
| 433 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 434 | INNER JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
[1677] | 435 | WHERE |
---|
| 436 | '.$where_sql.' |
---|
| 437 | '.get_sql_condition_FandF |
---|
| 438 | ( |
---|
| 439 | array |
---|
| 440 | ( |
---|
| 441 | 'forbidden_categories' => 'category_id', |
---|
| 442 | 'visible_categories' => 'category_id', |
---|
| 443 | 'visible_images' => 'image_id' |
---|
| 444 | ), |
---|
| 445 | 'AND' |
---|
| 446 | ).' |
---|
[1051] | 447 | '.$conf['order_by'].' |
---|
| 448 | ;'; |
---|
[1677] | 449 | |
---|
[1051] | 450 | $page['items'] = array_from_query($query, 'image_id'); |
---|
[1677] | 451 | } |
---|
| 452 | else |
---|
| 453 | { |
---|
| 454 | $page['items'] = array(); |
---|
| 455 | } |
---|
| 456 | } //otherwise the calendar will requery all subitems |
---|
[1082] | 457 | } |
---|
| 458 | // special sections |
---|
| 459 | else |
---|
| 460 | { |
---|
[1677] | 461 | $forbidden = |
---|
| 462 | get_sql_condition_FandF |
---|
| 463 | ( |
---|
| 464 | array |
---|
| 465 | ( |
---|
| 466 | 'forbidden_categories' => 'category_id', |
---|
| 467 | 'visible_categories' => 'category_id', |
---|
| 468 | 'visible_images' => 'image_id' |
---|
| 469 | ), |
---|
| 470 | 'AND' |
---|
| 471 | ); |
---|
| 472 | |
---|
[1036] | 473 | // +-----------------------------------------------------------------------+ |
---|
[1119] | 474 | // | tags section | |
---|
| 475 | // +-----------------------------------------------------------------------+ |
---|
| 476 | if ($page['section'] == 'tags') |
---|
| 477 | { |
---|
| 478 | $page['tag_ids'] = array(); |
---|
| 479 | foreach ($page['tags'] as $tag) |
---|
| 480 | { |
---|
| 481 | array_push($page['tag_ids'], $tag['id']); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | $items = get_image_ids_for_tags($page['tag_ids']); |
---|
| 485 | |
---|
| 486 | // permissions depends on category, so to only keep images that are |
---|
| 487 | // reachable to the connected user, we need to check category |
---|
| 488 | // associations |
---|
[1131] | 489 | if (!empty($items) ) |
---|
[1119] | 490 | { |
---|
| 491 | $query = ' |
---|
| 492 | SELECT image_id |
---|
[1125] | 493 | FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
[1119] | 494 | WHERE image_id IN ('.implode(',', $items).') |
---|
[1677] | 495 | '.$forbidden. |
---|
[1125] | 496 | $conf['order_by'].' |
---|
[1119] | 497 | ;'; |
---|
| 498 | $items = array_unique( |
---|
| 499 | array_from_query($query, 'image_id') |
---|
| 500 | ); |
---|
| 501 | } |
---|
| 502 | |
---|
[1606] | 503 | $title = get_tags_content_title(); |
---|
[1119] | 504 | |
---|
| 505 | $page = array_merge( |
---|
| 506 | $page, |
---|
| 507 | array( |
---|
| 508 | 'title' => $title, |
---|
| 509 | 'items' => array_values($items), |
---|
| 510 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 511 | ) |
---|
| 512 | ); |
---|
| 513 | } |
---|
| 514 | // +-----------------------------------------------------------------------+ |
---|
[1036] | 515 | // | search section | |
---|
| 516 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 517 | if ($page['section'] == 'search') |
---|
| 518 | { |
---|
[1113] | 519 | include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); |
---|
[1119] | 520 | |
---|
[1537] | 521 | $search_result = get_search_results($page['search']); |
---|
| 522 | if ( !empty($search_result['items']) and !isset($search_result['as_is']) ) |
---|
[1120] | 523 | { |
---|
| 524 | $query = ' |
---|
[1036] | 525 | SELECT DISTINCT(id) |
---|
| 526 | FROM '.IMAGES_TABLE.' |
---|
| 527 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
[1537] | 528 | WHERE id IN ('.implode(',', $search_result['items']).') |
---|
[1677] | 529 | '.$forbidden.' |
---|
[1036] | 530 | '.$conf['order_by'].' |
---|
[1120] | 531 | ;'; |
---|
| 532 | $page['items'] = array_from_query($query, 'id'); |
---|
| 533 | } |
---|
| 534 | else |
---|
| 535 | { |
---|
[1537] | 536 | $page['items'] = $search_result['items']; |
---|
[1120] | 537 | } |
---|
[1036] | 538 | |
---|
[1082] | 539 | $page = array_merge( |
---|
| 540 | $page, |
---|
| 541 | array( |
---|
| 542 | 'title' => $lang['search_result'], |
---|
| 543 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 544 | ) |
---|
| 545 | ); |
---|
| 546 | } |
---|
[1036] | 547 | // +-----------------------------------------------------------------------+ |
---|
| 548 | // | favorite section | |
---|
| 549 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 550 | else if ($page['section'] == 'favorites') |
---|
| 551 | { |
---|
| 552 | check_user_favorites(); |
---|
[1036] | 553 | |
---|
[1082] | 554 | $query = ' |
---|
[1036] | 555 | SELECT image_id |
---|
| 556 | FROM '.FAVORITES_TABLE.' |
---|
| 557 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
| 558 | WHERE user_id = '.$user['id'].' |
---|
[1677] | 559 | '.get_sql_condition_FandF |
---|
| 560 | ( |
---|
| 561 | array |
---|
| 562 | ( |
---|
| 563 | 'visible_images' => 'image_id' |
---|
| 564 | ), |
---|
| 565 | 'AND' |
---|
| 566 | ).' |
---|
[1036] | 567 | '.$conf['order_by'].' |
---|
| 568 | ;'; |
---|
| 569 | |
---|
[1082] | 570 | $page = array_merge( |
---|
| 571 | $page, |
---|
| 572 | array( |
---|
| 573 | 'title' => $lang['favorites'], |
---|
| 574 | 'items' => array_from_query($query, 'image_id'), |
---|
| 575 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 576 | ) |
---|
| 577 | ); |
---|
| 578 | } |
---|
[1036] | 579 | // +-----------------------------------------------------------------------+ |
---|
| 580 | // | recent pictures section | |
---|
| 581 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 582 | else if ($page['section'] == 'recent_pics') |
---|
| 583 | { |
---|
| 584 | $query = ' |
---|
[1036] | 585 | SELECT DISTINCT(id) |
---|
| 586 | FROM '.IMAGES_TABLE.' |
---|
| 587 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
| 588 | WHERE date_available > \''. |
---|
[1082] | 589 | date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' |
---|
[1677] | 590 | '.$forbidden.' |
---|
[1036] | 591 | '.$conf['order_by'].' |
---|
| 592 | ;'; |
---|
| 593 | |
---|
[1082] | 594 | $page = array_merge( |
---|
| 595 | $page, |
---|
| 596 | array( |
---|
[1373] | 597 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
| 598 | .$lang['recent_pics_cat'].'</a>', |
---|
[1082] | 599 | 'items' => array_from_query($query, 'id'), |
---|
| 600 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 601 | ) |
---|
| 602 | ); |
---|
| 603 | } |
---|
[1036] | 604 | // +-----------------------------------------------------------------------+ |
---|
| 605 | // | recently updated categories section | |
---|
| 606 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 607 | else if ($page['section'] == 'recent_cats') |
---|
| 608 | { |
---|
| 609 | $page = array_merge( |
---|
| 610 | $page, |
---|
| 611 | array( |
---|
| 612 | 'title' => $lang['recent_cats_cat'], |
---|
[1597] | 613 | 'thumbnails_include' => 'include/category_cats.inc.php', |
---|
[1082] | 614 | ) |
---|
| 615 | ); |
---|
| 616 | } |
---|
[1036] | 617 | // +-----------------------------------------------------------------------+ |
---|
| 618 | // | most visited section | |
---|
| 619 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 620 | else if ($page['section'] == 'most_visited') |
---|
| 621 | { |
---|
| 622 | $page['super_order_by'] = true; |
---|
| 623 | $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; |
---|
| 624 | $query = ' |
---|
[1036] | 625 | SELECT DISTINCT(id) |
---|
| 626 | FROM '.IMAGES_TABLE.' |
---|
| 627 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
| 628 | WHERE hit > 0 |
---|
[1677] | 629 | '.$forbidden.' |
---|
[1082] | 630 | '.$conf['order_by'].' |
---|
[1036] | 631 | LIMIT 0, '.$conf['top_number'].' |
---|
| 632 | ;'; |
---|
[1086] | 633 | |
---|
[1082] | 634 | $page = array_merge( |
---|
| 635 | $page, |
---|
| 636 | array( |
---|
[1373] | 637 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
| 638 | .$conf['top_number'].' '.$lang['most_visited_cat'].'</a>', |
---|
[1082] | 639 | 'items' => array_from_query($query, 'id'), |
---|
| 640 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 641 | ) |
---|
| 642 | ); |
---|
| 643 | } |
---|
[1036] | 644 | // +-----------------------------------------------------------------------+ |
---|
| 645 | // | best rated section | |
---|
| 646 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 647 | else if ($page['section'] == 'best_rated') |
---|
| 648 | { |
---|
| 649 | $page['super_order_by'] = true; |
---|
| 650 | $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; |
---|
[1086] | 651 | |
---|
[1082] | 652 | $query =' |
---|
[1036] | 653 | SELECT DISTINCT(id) |
---|
| 654 | FROM '.IMAGES_TABLE.' |
---|
| 655 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
| 656 | WHERE average_rate IS NOT NULL |
---|
[1677] | 657 | '.$forbidden.' |
---|
[1082] | 658 | '.$conf['order_by'].' |
---|
[1036] | 659 | LIMIT 0, '.$conf['top_number'].' |
---|
| 660 | ;'; |
---|
[1082] | 661 | $page = array_merge( |
---|
| 662 | $page, |
---|
| 663 | array( |
---|
[1373] | 664 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
| 665 | .$conf['top_number'].' '.$lang['best_rated_cat'].'</a>', |
---|
[1082] | 666 | 'items' => array_from_query($query, 'id'), |
---|
| 667 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 668 | ) |
---|
| 669 | ); |
---|
| 670 | } |
---|
[1036] | 671 | // +-----------------------------------------------------------------------+ |
---|
| 672 | // | list section | |
---|
| 673 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 674 | else if ($page['section'] == 'list') |
---|
| 675 | { |
---|
| 676 | $query =' |
---|
[1036] | 677 | SELECT DISTINCT(id) |
---|
| 678 | FROM '.IMAGES_TABLE.' |
---|
| 679 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
[1082] | 680 | WHERE image_id IN ('.implode(',', $page['list']).') |
---|
[1677] | 681 | '.$forbidden.' |
---|
[1036] | 682 | '.$conf['order_by'].' |
---|
| 683 | ;'; |
---|
[1086] | 684 | |
---|
[1082] | 685 | $page = array_merge( |
---|
| 686 | $page, |
---|
| 687 | array( |
---|
[1373] | 688 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
| 689 | .$lang['random_cat'].'</a>', |
---|
[1082] | 690 | 'items' => array_from_query($query, 'id'), |
---|
| 691 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
| 692 | ) |
---|
| 693 | ); |
---|
[1036] | 694 | } |
---|
| 695 | } |
---|
[1082] | 696 | |
---|
[1036] | 697 | // +-----------------------------------------------------------------------+ |
---|
[1082] | 698 | // | chronology | |
---|
[1036] | 699 | // +-----------------------------------------------------------------------+ |
---|
[1047] | 700 | |
---|
[1090] | 701 | if (isset($page['chronology_field'])) |
---|
[1047] | 702 | { |
---|
| 703 | include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); |
---|
| 704 | initialize_calendar(); |
---|
| 705 | } |
---|
| 706 | |
---|
[1125] | 707 | $page['cat_nb_images'] = isset($page['items']) ? count($page['items']) : 0; |
---|
| 708 | |
---|
[1094] | 709 | if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php' |
---|
[1092] | 710 | and !isset($page['image_id']) ) |
---|
| 711 | { |
---|
[1094] | 712 | if ( !empty($page['items']) ) |
---|
| 713 | { |
---|
| 714 | $query = ' |
---|
[1092] | 715 | SELECT id,file |
---|
| 716 | FROM '.IMAGES_TABLE .' |
---|
| 717 | WHERE id IN ('.implode(',',$page['items']).') |
---|
| 718 | AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"' |
---|
| 719 | ; |
---|
[1094] | 720 | $result = pwg_query($query); |
---|
| 721 | if (mysql_num_rows($result)>0) |
---|
| 722 | { |
---|
| 723 | list($page['image_id'], $page['image_file']) = mysql_fetch_row($result); |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | if ( !isset($page['image_id']) ) |
---|
[1092] | 727 | { |
---|
[1094] | 728 | $page['image_id'] = -1; // will fail in picture.php |
---|
[1092] | 729 | } |
---|
| 730 | } |
---|
[1604] | 731 | |
---|
| 732 | trigger_action('loc_end_section_init'); |
---|
[1036] | 733 | ?> |
---|