| 1 | <?php |
|---|
| 2 | // +-----------------------------------------------------------------------+ |
|---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
|---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
|---|
| 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
|---|
| 6 | // +-----------------------------------------------------------------------+ |
|---|
| 7 | // | branch : BSF (Best So Far) |
|---|
| 8 | // | file : $Id$ |
|---|
| 9 | // | last update : $Date$ |
|---|
| 10 | // | last modifier : $Author$ |
|---|
| 11 | // | revision : $Revision$ |
|---|
| 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 | define('PHPWG_ROOT_PATH','./'); |
|---|
| 29 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
|---|
| 30 | include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); |
|---|
| 31 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
|---|
| 32 | |
|---|
| 33 | // Check Access and exit when user status is not ok |
|---|
| 34 | check_status(ACCESS_GUEST); |
|---|
| 35 | |
|---|
| 36 | // access authorization check |
|---|
| 37 | if (isset($page['category'])) |
|---|
| 38 | { |
|---|
| 39 | check_restrictions($page['category']); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | // if this image_id doesn't correspond to this category, an error message is |
|---|
| 43 | // displayed, and execution is stopped |
|---|
| 44 | if (!in_array($page['image_id'], $page['items'])) |
|---|
| 45 | { |
|---|
| 46 | page_not_found( |
|---|
| 47 | 'The requested image does not belong to this image set', |
|---|
| 48 | duplicate_index_url() |
|---|
| 49 | ); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | // add default event handler for rendering element content |
|---|
| 53 | add_event_handler( |
|---|
| 54 | 'render_element_content', |
|---|
| 55 | 'default_picture_content', |
|---|
| 56 | EVENT_HANDLER_PRIORITY_NEUTRAL, |
|---|
| 57 | 2 |
|---|
| 58 | ); |
|---|
| 59 | trigger_action('loc_begin_picture'); |
|---|
| 60 | |
|---|
| 61 | // this is the default handler that generates the display for the element |
|---|
| 62 | function default_picture_content($content, $element_info) |
|---|
| 63 | { |
|---|
| 64 | if ( !empty($content) ) |
|---|
| 65 | {// someone hooked us - so we skip; |
|---|
| 66 | return $content; |
|---|
| 67 | } |
|---|
| 68 | if (!isset($element_info['image_url'])) |
|---|
| 69 | { // nothing to do |
|---|
| 70 | return $content; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | global $user; |
|---|
| 74 | |
|---|
| 75 | $my_template = new Template( |
|---|
| 76 | PHPWG_ROOT_PATH.'template/'.$user['template'], |
|---|
| 77 | $user['theme'] |
|---|
| 78 | ); |
|---|
| 79 | $my_template->set_filenames( |
|---|
| 80 | array('default_content'=>'picture_content.tpl') |
|---|
| 81 | ); |
|---|
| 82 | |
|---|
| 83 | if (isset($element_info['high_url'])) |
|---|
| 84 | { |
|---|
| 85 | $uuid = uniqid(rand()); |
|---|
| 86 | $my_template->assign_block_vars( |
|---|
| 87 | 'high', |
|---|
| 88 | array( |
|---|
| 89 | 'U_HIGH' => $element_info['high_url'], |
|---|
| 90 | 'UUID' => $uuid, |
|---|
| 91 | ) |
|---|
| 92 | ); |
|---|
| 93 | } |
|---|
| 94 | $my_template->assign_vars( array( |
|---|
| 95 | 'SRC_IMG' => $element_info['image_url'], |
|---|
| 96 | 'ALT_IMG' => $element_info['file'], |
|---|
| 97 | 'WIDTH_IMG' => @$element_info['scaled_width'], |
|---|
| 98 | 'HEIGHT_IMG' => @$element_info['scaled_height'], |
|---|
| 99 | ) |
|---|
| 100 | ); |
|---|
| 101 | return $my_template->parse( 'default_content', true); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | // +-----------------------------------------------------------------------+ |
|---|
| 105 | // | initialization | |
|---|
| 106 | // +-----------------------------------------------------------------------+ |
|---|
| 107 | |
|---|
| 108 | $page['rank_of'] = array_flip($page['items']); |
|---|
| 109 | |
|---|
| 110 | // caching first_rank, last_rank, current_rank in the displayed |
|---|
| 111 | // section. This should also help in readability. |
|---|
| 112 | $page['first_rank'] = 0; |
|---|
| 113 | $page['last_rank'] = count($page['items']) - 1; |
|---|
| 114 | $page['current_rank'] = $page['rank_of'][ $page['image_id'] ]; |
|---|
| 115 | |
|---|
| 116 | // caching current item : readability purpose |
|---|
| 117 | $page['current_item'] = $page['image_id']; |
|---|
| 118 | |
|---|
| 119 | if ($page['current_rank'] != $page['first_rank']) |
|---|
| 120 | { |
|---|
| 121 | // caching first & previous item : readability purpose |
|---|
| 122 | $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ]; |
|---|
| 123 | $page['first_item'] = $page['items'][ $page['first_rank'] ]; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | if ($page['current_rank'] != $page['last_rank']) |
|---|
| 127 | { |
|---|
| 128 | // caching next & last item : readability purpose |
|---|
| 129 | $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ]; |
|---|
| 130 | $page['last_item'] = $page['items'][ $page['last_rank'] ]; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | $url_up = duplicate_index_url( |
|---|
| 134 | array( |
|---|
| 135 | 'start' => |
|---|
| 136 | floor($page['current_rank'] / $user['nb_image_page']) |
|---|
| 137 | * $user['nb_image_page'] |
|---|
| 138 | ), |
|---|
| 139 | array( |
|---|
| 140 | 'start', |
|---|
| 141 | ) |
|---|
| 142 | ); |
|---|
| 143 | |
|---|
| 144 | $url_self = duplicate_picture_url(); |
|---|
| 145 | |
|---|
| 146 | // +-----------------------------------------------------------------------+ |
|---|
| 147 | // | actions | |
|---|
| 148 | // +-----------------------------------------------------------------------+ |
|---|
| 149 | |
|---|
| 150 | /** |
|---|
| 151 | * Actions are favorite adding, user comment deletion, setting the picture |
|---|
| 152 | * as representative of the current category... |
|---|
| 153 | * |
|---|
| 154 | * Actions finish by a redirection |
|---|
| 155 | */ |
|---|
| 156 | |
|---|
| 157 | if (isset($_GET['action'])) |
|---|
| 158 | { |
|---|
| 159 | switch ($_GET['action']) |
|---|
| 160 | { |
|---|
| 161 | case 'add_to_favorites' : |
|---|
| 162 | { |
|---|
| 163 | $query = ' |
|---|
| 164 | INSERT INTO '.FAVORITES_TABLE.' |
|---|
| 165 | (image_id,user_id) |
|---|
| 166 | VALUES |
|---|
| 167 | ('.$page['image_id'].','.$user['id'].') |
|---|
| 168 | ;'; |
|---|
| 169 | pwg_query($query); |
|---|
| 170 | |
|---|
| 171 | redirect($url_self); |
|---|
| 172 | |
|---|
| 173 | break; |
|---|
| 174 | } |
|---|
| 175 | case 'remove_from_favorites' : |
|---|
| 176 | { |
|---|
| 177 | $query = ' |
|---|
| 178 | DELETE FROM '.FAVORITES_TABLE.' |
|---|
| 179 | WHERE user_id = '.$user['id'].' |
|---|
| 180 | AND image_id = '.$page['image_id'].' |
|---|
| 181 | ;'; |
|---|
| 182 | pwg_query($query); |
|---|
| 183 | |
|---|
| 184 | if ('favorites' == $page['section']) |
|---|
| 185 | { |
|---|
| 186 | redirect($url_up); |
|---|
| 187 | } |
|---|
| 188 | else |
|---|
| 189 | { |
|---|
| 190 | redirect($url_self); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | break; |
|---|
| 194 | } |
|---|
| 195 | case 'set_as_representative' : |
|---|
| 196 | { |
|---|
| 197 | if (is_admin() and !is_adviser() and isset($page['category'])) |
|---|
| 198 | { |
|---|
| 199 | $query = ' |
|---|
| 200 | UPDATE '.CATEGORIES_TABLE.' |
|---|
| 201 | SET representative_picture_id = '.$page['image_id'].' |
|---|
| 202 | WHERE id = '.$page['category'].' |
|---|
| 203 | ;'; |
|---|
| 204 | pwg_query($query); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | redirect($url_self); |
|---|
| 208 | |
|---|
| 209 | break; |
|---|
| 210 | } |
|---|
| 211 | case 'toggle_metadata' : |
|---|
| 212 | { |
|---|
| 213 | break; |
|---|
| 214 | } |
|---|
| 215 | case 'add_to_caddie' : |
|---|
| 216 | { |
|---|
| 217 | fill_caddie(array($page['image_id'])); |
|---|
| 218 | redirect($url_self); |
|---|
| 219 | break; |
|---|
| 220 | } |
|---|
| 221 | case 'rate' : |
|---|
| 222 | { |
|---|
| 223 | include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); |
|---|
| 224 | rate_picture( |
|---|
| 225 | $page['image_id'], |
|---|
| 226 | isset($_POST['rate']) ? $_POST['rate'] : $_GET['rate'] |
|---|
| 227 | ); |
|---|
| 228 | redirect($url_self); |
|---|
| 229 | } |
|---|
| 230 | case 'delete_comment' : |
|---|
| 231 | { |
|---|
| 232 | if (isset($_GET['comment_to_delete']) |
|---|
| 233 | and is_numeric($_GET['comment_to_delete']) |
|---|
| 234 | and is_admin() and !is_adviser() ) |
|---|
| 235 | { |
|---|
| 236 | $query = ' |
|---|
| 237 | DELETE FROM '.COMMENTS_TABLE.' |
|---|
| 238 | WHERE id = '.$_GET['comment_to_delete'].' |
|---|
| 239 | ;'; |
|---|
| 240 | pwg_query( $query ); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | redirect($url_self); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | // incrementation of the number of hits, we do this only if no action |
|---|
| 249 | $query = ' |
|---|
| 250 | UPDATE |
|---|
| 251 | '.IMAGES_TABLE.' |
|---|
| 252 | SET hit = hit+1 |
|---|
| 253 | WHERE id = '.$page['image_id'].' |
|---|
| 254 | ;'; |
|---|
| 255 | pwg_query($query); |
|---|
| 256 | |
|---|
| 257 | //---------------------------------------------------------- related categories |
|---|
| 258 | $query = ' |
|---|
| 259 | SELECT category_id,uppercats,commentable,global_rank |
|---|
| 260 | FROM '.IMAGE_CATEGORY_TABLE.' |
|---|
| 261 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
|---|
| 262 | WHERE image_id = '.$page['image_id'].' |
|---|
| 263 | '.get_sql_condition_FandF |
|---|
| 264 | ( |
|---|
| 265 | array |
|---|
| 266 | ( |
|---|
| 267 | 'forbidden_categories' => 'category_id', |
|---|
| 268 | 'visible_categories' => 'category_id' |
|---|
| 269 | ), |
|---|
| 270 | 'AND' |
|---|
| 271 | ).' |
|---|
| 272 | ;'; |
|---|
| 273 | $result = pwg_query($query); |
|---|
| 274 | $related_categories = array(); |
|---|
| 275 | while ($row = mysql_fetch_array($result)) |
|---|
| 276 | { |
|---|
| 277 | array_push($related_categories, $row); |
|---|
| 278 | } |
|---|
| 279 | usort($related_categories, 'global_rank_compare'); |
|---|
| 280 | //-------------------------first, prev, current, next & last picture management |
|---|
| 281 | $picture = array(); |
|---|
| 282 | |
|---|
| 283 | $ids = array($page['image_id']); |
|---|
| 284 | if (isset($page['previous_item'])) |
|---|
| 285 | { |
|---|
| 286 | array_push($ids, $page['previous_item']); |
|---|
| 287 | array_push($ids, $page['first_item']); |
|---|
| 288 | } |
|---|
| 289 | if (isset($page['next_item'])) |
|---|
| 290 | { |
|---|
| 291 | array_push($ids, $page['next_item']); |
|---|
| 292 | array_push($ids, $page['last_item']); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | $query = ' |
|---|
| 296 | SELECT * |
|---|
| 297 | FROM '.IMAGES_TABLE.' |
|---|
| 298 | WHERE id IN ('.implode(',', $ids).') |
|---|
| 299 | ;'; |
|---|
| 300 | |
|---|
| 301 | $result = pwg_query($query); |
|---|
| 302 | |
|---|
| 303 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 304 | { |
|---|
| 305 | if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) |
|---|
| 306 | { |
|---|
| 307 | $i = 'previous'; |
|---|
| 308 | } |
|---|
| 309 | else if (isset($page['next_item']) and $row['id'] == $page['next_item']) |
|---|
| 310 | { |
|---|
| 311 | $i = 'next'; |
|---|
| 312 | } |
|---|
| 313 | else if (isset($page['first_item']) and $row['id'] == $page['first_item']) |
|---|
| 314 | { |
|---|
| 315 | $i = 'first'; |
|---|
| 316 | } |
|---|
| 317 | else if (isset($page['last_item']) and $row['id'] == $page['last_item']) |
|---|
| 318 | { |
|---|
| 319 | $i = 'last'; |
|---|
| 320 | } |
|---|
| 321 | else |
|---|
| 322 | { |
|---|
| 323 | $i = 'current'; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | $picture[$i] = $row; |
|---|
| 327 | |
|---|
| 328 | $picture[$i]['is_picture'] = false; |
|---|
| 329 | if (in_array(get_extension($row['file']), $conf['picture_ext'])) |
|---|
| 330 | { |
|---|
| 331 | $picture[$i]['is_picture'] = true; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | // ------ build element_path and element_url |
|---|
| 335 | $picture[$i]['element_path'] = get_element_path($picture[$i]); |
|---|
| 336 | $picture[$i]['element_url'] = get_element_url($picture[$i]); |
|---|
| 337 | |
|---|
| 338 | // ------ build image_path and image_url |
|---|
| 339 | if ($i=='current' or $i=='next') |
|---|
| 340 | { |
|---|
| 341 | $picture[$i]['image_path'] = get_image_path( $picture[$i] ); |
|---|
| 342 | $picture[$i]['image_url'] = get_image_url( $picture[$i] ); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | if ($i=='current') |
|---|
| 346 | { |
|---|
| 347 | if ( $picture[$i]['is_picture'] ) |
|---|
| 348 | { |
|---|
| 349 | if ( $user['enabled_high']=='true' ) |
|---|
| 350 | { |
|---|
| 351 | $hi_url=get_high_url($picture[$i]); |
|---|
| 352 | if ( !empty($hi_url) ) |
|---|
| 353 | { |
|---|
| 354 | $picture[$i]['high_url'] = $hi_url; |
|---|
| 355 | $picture[$i]['download_url'] = get_download_url('h',$picture[$i]); |
|---|
| 356 | } |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | else |
|---|
| 360 | { // not a pic - need download link |
|---|
| 361 | $picture[$i]['download_url'] = get_download_url('e',$picture[$i]); |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | $picture[$i]['thumbnail'] = get_thumbnail_url($row); |
|---|
| 366 | |
|---|
| 367 | if ( !empty( $row['name'] ) ) |
|---|
| 368 | { |
|---|
| 369 | $picture[$i]['name'] = $row['name']; |
|---|
| 370 | } |
|---|
| 371 | else |
|---|
| 372 | { |
|---|
| 373 | $file_wo_ext = get_filename_wo_extension($row['file']); |
|---|
| 374 | $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | $picture[$i]['url'] = duplicate_picture_url( |
|---|
| 378 | array( |
|---|
| 379 | 'image_id' => $row['id'], |
|---|
| 380 | 'image_file' => $row['file'], |
|---|
| 381 | ), |
|---|
| 382 | array( |
|---|
| 383 | 'start', |
|---|
| 384 | ) |
|---|
| 385 | ); |
|---|
| 386 | |
|---|
| 387 | if ('previous'==$i and $page['previous_item']==$page['first_item']) |
|---|
| 388 | { |
|---|
| 389 | $picture['first'] = $picture[$i]; |
|---|
| 390 | } |
|---|
| 391 | if ('next'==$i and $page['next_item']==$page['last_item']) |
|---|
| 392 | { |
|---|
| 393 | $picture['last'] = $picture[$i]; |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | // calculation of width and height for the current picture |
|---|
| 398 | if (empty($picture['current']['width'])) |
|---|
| 399 | { |
|---|
| 400 | $taille_image = @getimagesize($picture['current']['image_path']); |
|---|
| 401 | if ($taille_image!==false) |
|---|
| 402 | { |
|---|
| 403 | $picture['current']['width'] = $taille_image[0]; |
|---|
| 404 | $picture['current']['height']= $taille_image[1]; |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | if (!empty($picture['current']['width'])) |
|---|
| 409 | { |
|---|
| 410 | list( |
|---|
| 411 | $picture['current']['scaled_width'], |
|---|
| 412 | $picture['current']['scaled_height'] |
|---|
| 413 | ) = get_picture_size( |
|---|
| 414 | $picture['current']['width'], |
|---|
| 415 | $picture['current']['height'], |
|---|
| 416 | @$user['maxwidth'], |
|---|
| 417 | @$user['maxheight'] |
|---|
| 418 | ); |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | $url_admin = |
|---|
| 422 | get_root_url().'admin.php?page=picture_modify' |
|---|
| 423 | .'&cat_id='.(isset($page['category']) ? $page['category'] : '') |
|---|
| 424 | .'&image_id='.$page['image_id'] |
|---|
| 425 | ; |
|---|
| 426 | |
|---|
| 427 | $url_slide = add_url_params( |
|---|
| 428 | $picture['current']['url'], |
|---|
| 429 | array( 'slideshow'=>$conf['slideshow_period'] ) |
|---|
| 430 | ); |
|---|
| 431 | |
|---|
| 432 | $title = $picture['current']['name']; |
|---|
| 433 | $refresh = 0; |
|---|
| 434 | if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) ) |
|---|
| 435 | { |
|---|
| 436 | // $redirect_msg, $refresh, $url_link and $title are required for creating |
|---|
| 437 | // an automated refresh page in header.tpl |
|---|
| 438 | $refresh= $_GET['slideshow']; |
|---|
| 439 | $url_link = add_url_params( |
|---|
| 440 | $picture['next']['url'], |
|---|
| 441 | array('slideshow'=>$refresh) |
|---|
| 442 | ); |
|---|
| 443 | $redirect_msg = nl2br(l10n('redirect_msg')); |
|---|
| 444 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | $title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images']; |
|---|
| 448 | |
|---|
| 449 | // metadata |
|---|
| 450 | $url_metadata = duplicate_picture_url(); |
|---|
| 451 | |
|---|
| 452 | // do we have a plugin that can show metadata for something else than images? |
|---|
| 453 | $metadata_showable = trigger_event( |
|---|
| 454 | 'get_element_metadata_available', |
|---|
| 455 | ( |
|---|
| 456 | ($conf['show_exif'] or $conf['show_iptc']) |
|---|
| 457 | and isset($picture['current']['image_path']) |
|---|
| 458 | ), |
|---|
| 459 | $picture['current']['path'] |
|---|
| 460 | ); |
|---|
| 461 | |
|---|
| 462 | if ($metadata_showable) |
|---|
| 463 | { |
|---|
| 464 | if ( !isset($_GET['metadata']) ) |
|---|
| 465 | { |
|---|
| 466 | $url_metadata = add_url_params( $url_metadata, array('metadata'=>null) ); |
|---|
| 467 | } |
|---|
| 468 | else |
|---|
| 469 | { |
|---|
| 470 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
|---|
| 471 | } |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | $page['body_id'] = 'thePicturePage'; |
|---|
| 475 | |
|---|
| 476 | //------------------------------------------------------------ light slideshow |
|---|
| 477 | // Warning !!! Warning !!! Warning !!! |
|---|
| 478 | // Notice for plugins writers check if you have to act on the active template |
|---|
| 479 | // like this if ( $page['slideshow'] ) { return false; } |
|---|
| 480 | // |
|---|
| 481 | if ( isset($_GET['slideshow']) and $conf['light_slideshow'] ) |
|---|
| 482 | { |
|---|
| 483 | $page['display_tpl'] = 'slideshow.tpl'; |
|---|
| 484 | $page['slideshow'] = true; |
|---|
| 485 | unset($picture['current']['high_url']); |
|---|
| 486 | } |
|---|
| 487 | else { |
|---|
| 488 | $page['display_tpl'] = 'picture.tpl'; |
|---|
| 489 | $page['slideshow'] = false; |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | // maybe someone wants a special display (call it before page_header so that |
|---|
| 493 | // they can add stylesheets) |
|---|
| 494 | $element_content = trigger_event( |
|---|
| 495 | 'render_element_content', |
|---|
| 496 | '', |
|---|
| 497 | $picture['current'] |
|---|
| 498 | ); |
|---|
| 499 | |
|---|
| 500 | if (isset($picture['next']['image_url']) |
|---|
| 501 | and isset($picture['next']['is_picture'])) |
|---|
| 502 | { |
|---|
| 503 | $template->assign_block_vars( |
|---|
| 504 | 'prefetch', |
|---|
| 505 | array ( |
|---|
| 506 | 'URL' => $picture['next']['image_url'] |
|---|
| 507 | ) |
|---|
| 508 | ); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | $template->set_filenames(array( 'picture' => $page['display_tpl'] )); |
|---|
| 512 | |
|---|
| 513 | //------------------------------------------------------- navigation management |
|---|
| 514 | foreach (array('first','previous','next','last') as $which_image) |
|---|
| 515 | { |
|---|
| 516 | if (isset($picture[$which_image])) |
|---|
| 517 | { |
|---|
| 518 | $template->assign_block_vars( |
|---|
| 519 | $which_image, |
|---|
| 520 | array( |
|---|
| 521 | 'TITLE_IMG' => $picture[$which_image]['name'], |
|---|
| 522 | 'IMG' => $picture[$which_image]['thumbnail'], |
|---|
| 523 | 'U_IMG' => $picture[$which_image]['url'], |
|---|
| 524 | ) |
|---|
| 525 | ); |
|---|
| 526 | } |
|---|
| 527 | else |
|---|
| 528 | { |
|---|
| 529 | $template->assign_block_vars( |
|---|
| 530 | $which_image.'_unactive', |
|---|
| 531 | array() |
|---|
| 532 | ); |
|---|
| 533 | } |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | $template->assign_vars( |
|---|
| 537 | array( |
|---|
| 538 | 'SECTION_TITLE' => $page['title'], |
|---|
| 539 | 'PICTURE_TITLE' => $picture['current']['name'], |
|---|
| 540 | 'PHOTO' => $title_nb, |
|---|
| 541 | 'TITLE' => $picture['current']['name'], |
|---|
| 542 | 'ELEMENT_CONTENT' => $element_content, |
|---|
| 543 | |
|---|
| 544 | 'LEVEL_SEPARATOR' => $conf['level_separator'], |
|---|
| 545 | |
|---|
| 546 | 'U_HOME' => make_index_url(), |
|---|
| 547 | 'U_UP' => $url_up, |
|---|
| 548 | 'U_METADATA' => $url_metadata, |
|---|
| 549 | 'U_ADMIN' => $url_admin, |
|---|
| 550 | 'U_SLIDESHOW'=> $url_slide, |
|---|
| 551 | 'U_ADD_COMMENT' => $url_self, |
|---|
| 552 | ) |
|---|
| 553 | ); |
|---|
| 554 | |
|---|
| 555 | if ($conf['show_picture_name_on_title']) |
|---|
| 556 | { |
|---|
| 557 | $template->assign_block_vars('title', array()); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | //------------------------------------------------------- upper menu management |
|---|
| 561 | |
|---|
| 562 | // download link |
|---|
| 563 | if ( isset($picture['current']['download_url']) ) |
|---|
| 564 | { |
|---|
| 565 | $template->assign_block_vars( |
|---|
| 566 | 'download', |
|---|
| 567 | array( |
|---|
| 568 | 'U_DOWNLOAD' => $picture['current']['download_url'] |
|---|
| 569 | ) |
|---|
| 570 | ); |
|---|
| 571 | } |
|---|
| 572 | |
|---|
| 573 | // button to set the current picture as representative |
|---|
| 574 | if (is_admin() and isset($page['category'])) |
|---|
| 575 | { |
|---|
| 576 | $template->assign_block_vars( |
|---|
| 577 | 'representative', |
|---|
| 578 | array( |
|---|
| 579 | 'URL' => add_url_params($url_self, |
|---|
| 580 | array('action'=>'set_as_representative') |
|---|
| 581 | ) |
|---|
| 582 | ) |
|---|
| 583 | ); |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | // caddie button |
|---|
| 587 | if (is_admin()) |
|---|
| 588 | { |
|---|
| 589 | $template->assign_block_vars( |
|---|
| 590 | 'caddie', |
|---|
| 591 | array( |
|---|
| 592 | 'URL' => add_url_params($url_self, |
|---|
| 593 | array('action'=>'add_to_caddie') |
|---|
| 594 | ) |
|---|
| 595 | ) |
|---|
| 596 | ); |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | // favorite manipulation |
|---|
| 600 | if (!$user['is_the_guest']) |
|---|
| 601 | { |
|---|
| 602 | // verify if the picture is already in the favorite of the user |
|---|
| 603 | $query = ' |
|---|
| 604 | SELECT COUNT(*) AS nb_fav |
|---|
| 605 | FROM '.FAVORITES_TABLE.' |
|---|
| 606 | WHERE image_id = '.$page['image_id'].' |
|---|
| 607 | AND user_id = '.$user['id'].' |
|---|
| 608 | ;'; |
|---|
| 609 | $result = pwg_query($query); |
|---|
| 610 | $row = mysql_fetch_array($result); |
|---|
| 611 | |
|---|
| 612 | if ($row['nb_fav'] == 0) |
|---|
| 613 | { |
|---|
| 614 | $template->assign_block_vars( |
|---|
| 615 | 'favorite', |
|---|
| 616 | array( |
|---|
| 617 | 'FAVORITE_IMG' => get_root_url().get_themeconf('icon_dir').'/favorite.png', |
|---|
| 618 | 'FAVORITE_HINT' => $lang['add_favorites_hint'], |
|---|
| 619 | 'FAVORITE_ALT' => $lang['add_favorites_alt'], |
|---|
| 620 | 'U_FAVORITE' => add_url_params( |
|---|
| 621 | $url_self, |
|---|
| 622 | array('action'=>'add_to_favorites') |
|---|
| 623 | ), |
|---|
| 624 | ) |
|---|
| 625 | ); |
|---|
| 626 | } |
|---|
| 627 | else |
|---|
| 628 | { |
|---|
| 629 | $template->assign_block_vars( |
|---|
| 630 | 'favorite', |
|---|
| 631 | array( |
|---|
| 632 | 'FAVORITE_IMG' => get_root_url().get_themeconf('icon_dir').'/del_favorite.png', |
|---|
| 633 | 'FAVORITE_HINT' => $lang['del_favorites_hint'], |
|---|
| 634 | 'FAVORITE_ALT' => $lang['del_favorites_alt'], |
|---|
| 635 | 'U_FAVORITE' => add_url_params( |
|---|
| 636 | $url_self, |
|---|
| 637 | array('action'=>'remove_from_favorites') |
|---|
| 638 | ) |
|---|
| 639 | ) |
|---|
| 640 | ); |
|---|
| 641 | } |
|---|
| 642 | } |
|---|
| 643 | //------------------------------------ admin link for information modifications |
|---|
| 644 | if ( is_admin() ) |
|---|
| 645 | { |
|---|
| 646 | $template->assign_block_vars('admin', array()); |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | //--------------------------------------------------------- picture information |
|---|
| 650 | $header_infos = array(); //for html header use |
|---|
| 651 | // legend |
|---|
| 652 | if (isset($picture['current']['comment']) |
|---|
| 653 | and !empty($picture['current']['comment'])) |
|---|
| 654 | { |
|---|
| 655 | $template->assign_block_vars( |
|---|
| 656 | 'legend', |
|---|
| 657 | array( |
|---|
| 658 | 'COMMENT_IMG' => nl2br($picture['current']['comment']) |
|---|
| 659 | )); |
|---|
| 660 | $header_infos['COMMENT'] = strip_tags($picture['current']['comment']); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | $infos = array(); |
|---|
| 664 | |
|---|
| 665 | // author |
|---|
| 666 | if (!empty($picture['current']['author'])) |
|---|
| 667 | { |
|---|
| 668 | $infos['INFO_AUTHOR'] = |
|---|
| 669 | // FIXME because of search engine partial rewrite, giving the author |
|---|
| 670 | // name threw GET is not supported anymore. This feature should come |
|---|
| 671 | // back later, with a better design |
|---|
| 672 | // '<a href="'. |
|---|
| 673 | // PHPWG_ROOT_PATH.'category.php?cat=search'. |
|---|
| 674 | // '&search=author:'.$picture['current']['author'] |
|---|
| 675 | // .'">'.$picture['current']['author'].'</a>'; |
|---|
| 676 | $picture['current']['author']; |
|---|
| 677 | $header_infos['INFO_AUTHOR'] = $picture['current']['author']; |
|---|
| 678 | } |
|---|
| 679 | else |
|---|
| 680 | { |
|---|
| 681 | $infos['INFO_AUTHOR'] = l10n('N/A'); |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | // creation date |
|---|
| 685 | if (!empty($picture['current']['date_creation'])) |
|---|
| 686 | { |
|---|
| 687 | $val = format_date($picture['current']['date_creation']); |
|---|
| 688 | $url = make_index_url( |
|---|
| 689 | array( |
|---|
| 690 | 'chronology_field'=>'created', |
|---|
| 691 | 'chronology_style'=>'monthly', |
|---|
| 692 | 'chronology_view'=>'list', |
|---|
| 693 | 'chronology_date' => explode('-', $picture['current']['date_creation']) |
|---|
| 694 | ) |
|---|
| 695 | ); |
|---|
| 696 | $infos['INFO_CREATION_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
|---|
| 697 | } |
|---|
| 698 | else |
|---|
| 699 | { |
|---|
| 700 | $infos['INFO_CREATION_DATE'] = l10n('N/A'); |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | // date of availability |
|---|
| 704 | $val = format_date($picture['current']['date_available'], 'mysql_datetime'); |
|---|
| 705 | $url = make_index_url( |
|---|
| 706 | array( |
|---|
| 707 | 'chronology_field'=>'posted', |
|---|
| 708 | 'chronology_style'=>'monthly', |
|---|
| 709 | 'chronology_view'=>'list', |
|---|
| 710 | 'chronology_date'=>explode('-', substr($picture['current']['date_available'],0,10)) |
|---|
| 711 | ) |
|---|
| 712 | ); |
|---|
| 713 | $infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
|---|
| 714 | |
|---|
| 715 | // size in pixels |
|---|
| 716 | if ($picture['current']['is_picture'] and isset($picture['current']['width']) ) |
|---|
| 717 | { |
|---|
| 718 | if ($picture['current']['scaled_width'] !== $picture['current']['width'] ) |
|---|
| 719 | { |
|---|
| 720 | $infos['INFO_DIMENSIONS'] = |
|---|
| 721 | '<a href="'.$picture['current']['image_url'].'" title="'. |
|---|
| 722 | l10n('Original dimensions').'">'. |
|---|
| 723 | $picture['current']['width'].'*'.$picture['current']['height'].'</a>'; |
|---|
| 724 | } |
|---|
| 725 | else |
|---|
| 726 | { |
|---|
| 727 | $infos['INFO_DIMENSIONS'] = |
|---|
| 728 | $picture['current']['width'].'*'.$picture['current']['height']; |
|---|
| 729 | } |
|---|
| 730 | } |
|---|
| 731 | else |
|---|
| 732 | { |
|---|
| 733 | $infos['INFO_DIMENSIONS'] = l10n('N/A'); |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | // filesize |
|---|
| 737 | if (!empty($picture['current']['filesize'])) |
|---|
| 738 | { |
|---|
| 739 | $infos['INFO_FILESIZE'] = |
|---|
| 740 | sprintf(l10n('%d Kb'), $picture['current']['filesize']); |
|---|
| 741 | } |
|---|
| 742 | else |
|---|
| 743 | { |
|---|
| 744 | $infos['INFO_FILESIZE'] = l10n('N/A'); |
|---|
| 745 | } |
|---|
| 746 | |
|---|
| 747 | // number of visits |
|---|
| 748 | $infos['INFO_VISITS'] = $picture['current']['hit']; |
|---|
| 749 | |
|---|
| 750 | // file |
|---|
| 751 | $infos['INFO_FILE'] = $picture['current']['file']; |
|---|
| 752 | |
|---|
| 753 | // tags |
|---|
| 754 | $query = ' |
|---|
| 755 | SELECT id, name, url_name |
|---|
| 756 | FROM '.IMAGE_TAG_TABLE.' |
|---|
| 757 | INNER JOIN '.TAGS_TABLE.' ON tag_id = id |
|---|
| 758 | WHERE image_id = '.$page['image_id'].' |
|---|
| 759 | ;'; |
|---|
| 760 | $result = pwg_query($query); |
|---|
| 761 | |
|---|
| 762 | if (mysql_num_rows($result) > 0) |
|---|
| 763 | { |
|---|
| 764 | $tags = array(); |
|---|
| 765 | $tag_names = array(); |
|---|
| 766 | |
|---|
| 767 | while ($row = mysql_fetch_array($result)) |
|---|
| 768 | { |
|---|
| 769 | array_push( |
|---|
| 770 | $tags, |
|---|
| 771 | '<a href="' |
|---|
| 772 | .make_index_url( |
|---|
| 773 | array( |
|---|
| 774 | 'tags' => array( |
|---|
| 775 | array( |
|---|
| 776 | 'id' => $row['id'], |
|---|
| 777 | 'url_name' => $row['url_name'], |
|---|
| 778 | ), |
|---|
| 779 | ) |
|---|
| 780 | ) |
|---|
| 781 | ) |
|---|
| 782 | .'">'.$row['name'].'</a>' |
|---|
| 783 | ); |
|---|
| 784 | array_push( $tag_names, $row['name'] ); |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | $infos['INFO_TAGS'] = implode(', ', $tags); |
|---|
| 788 | $header_infos['INFO_TAGS'] = implode(', ', $tag_names); |
|---|
| 789 | } |
|---|
| 790 | else |
|---|
| 791 | { |
|---|
| 792 | $infos['INFO_TAGS'] = l10n('N/A'); |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | $template->assign_vars($infos); |
|---|
| 796 | |
|---|
| 797 | // related categories |
|---|
| 798 | foreach ($related_categories as $category) |
|---|
| 799 | { |
|---|
| 800 | $template->assign_block_vars( |
|---|
| 801 | 'category', |
|---|
| 802 | array( |
|---|
| 803 | 'LINE' => count($related_categories) > 3 |
|---|
| 804 | ? get_cat_display_name_cache($category['uppercats']) |
|---|
| 805 | : get_cat_display_name_from_id($category['category_id']) |
|---|
| 806 | ) |
|---|
| 807 | ); |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | //slideshow end |
|---|
| 811 | if (isset($_GET['slideshow'])) |
|---|
| 812 | { |
|---|
| 813 | if (!is_numeric($_GET['slideshow'])) |
|---|
| 814 | { |
|---|
| 815 | $_GET['slideshow'] = $conf['slideshow_period']; |
|---|
| 816 | } |
|---|
| 817 | |
|---|
| 818 | $template->assign_block_vars( |
|---|
| 819 | 'stop_slideshow', |
|---|
| 820 | array( |
|---|
| 821 | 'U_SLIDESHOW' => $picture['current']['url'], |
|---|
| 822 | ) |
|---|
| 823 | ); |
|---|
| 824 | } |
|---|
| 825 | |
|---|
| 826 | // +-----------------------------------------------------------------------+ |
|---|
| 827 | // | sub pages | |
|---|
| 828 | // +-----------------------------------------------------------------------+ |
|---|
| 829 | |
|---|
| 830 | include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php'); |
|---|
| 831 | include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php'); |
|---|
| 832 | if ($metadata_showable and isset($_GET['metadata'])) |
|---|
| 833 | { |
|---|
| 834 | include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php'); |
|---|
| 835 | } |
|---|
| 836 | //------------------------------------------------------------ log informations |
|---|
| 837 | pwg_log($picture['current']['id']); |
|---|
| 838 | |
|---|
| 839 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
|---|
| 840 | $template->parse('picture'); |
|---|
| 841 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
|---|
| 842 | ?> |
|---|