Changeset 1082 for trunk/picture.php
- Timestamp:
- Mar 15, 2006, 11:44:35 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r1078 r1082 26 26 // +-----------------------------------------------------------------------+ 27 27 28 $rate_items = array(0,1,2,3,4,5);29 //--------------------------------------------------------------------- include30 28 define('PHPWG_ROOT_PATH','./'); 31 29 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 32 33 // +-----------------------------------------------------------------------+ 34 // | Check Access and exit when user status is not ok | 35 // +-----------------------------------------------------------------------+ 30 include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); 31 32 // Check Access and exit when user status is not ok 36 33 check_status(ACCESS_GUEST); 37 34 38 include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); 39 //-------------------------------------------------- access authorization check 40 if (isset($page['cat']) and is_numeric($page['cat'])) 41 { 42 check_restrictions($page['cat']); 43 } 44 //-------------------------------------------------------------- initialization 35 // access authorization check 36 if (isset($page['category'])) 37 { 38 check_restrictions($page['category']); 39 } 40 45 41 // if this image_id doesn't correspond to this category, an error message is 46 42 // displayed, and execution is stopped 47 if (!in_array($ _GET['image_id'], $page['items']))48 { 49 echo '50 <div style="text-align:center;">'.$lang['access_forbiden'].'<br /> 51 <a href="'.PHPWG_ROOT_PATH.'category.php'.'">'.$lang['thumbnails'].'</a> 52 </div>'; 53 exit(); 54 } 43 if (!in_array($page['image_id'], $page['items'])) 44 { 45 die('Fatal: this picture does not belong to this section'); 46 } 47 48 // +-----------------------------------------------------------------------+ 49 // | initialization | 50 // +-----------------------------------------------------------------------+ 55 51 56 52 $page['rank_of'] = array_flip($page['items']); … … 60 56 $page['first_rank'] = 0; 61 57 $page['last_rank'] = count($page['items']) - 1; 62 $page['current_rank'] = $page['rank_of'][ $ _GET['image_id'] ];58 $page['current_rank'] = $page['rank_of'][ $page['image_id'] ]; 63 59 64 60 // caching current item : readability purpose 65 $page['current_item'] = $ _GET['image_id'];61 $page['current_item'] = $page['image_id']; 66 62 67 63 if ($page['current_rank'] != $page['first_rank']) … … 72 68 'first', 73 69 array( 74 'U_IMG' => 75 PHPWG_ROOT_PATH.'picture.php'. 76 get_query_string_diff( 77 array('image_id', 'add_fav', 'slideshow') 78 ). 79 '&image_id='.$page['items'][ $page['first_rank'] ], 70 'U_IMG' => duplicate_picture_URL( 71 // redefinitions 72 array( 73 'image_id' => $page['items'][ $page['first_rank'] ], 74 ), 75 // removes 76 array() 77 ) 80 78 ) 81 79 ); … … 92 90 'last', 93 91 array( 94 'U_IMG' => 95 PHPWG_ROOT_PATH.'picture.php'. 96 get_query_string_diff( 97 array('image_id', 'add_fav', 'slideshow') 98 ). 99 '&image_id='.$page['items'][ $page['last_rank'] ], 92 'U_IMG' => duplicate_picture_URL( 93 // redefinitions 94 array( 95 'image_id' => $page['items'][ $page['last_rank'] ], 96 ), 97 // removes 98 array() 99 ) 100 100 ) 101 101 ); … … 105 105 } 106 106 107 //---------------------------------------- incrementation of the number of hits 108 if ( count(array_intersect( 109 array_keys($_GET), 110 array('add_fav', 'caddie', 'rate', 'representative', 'del') ) 111 )==0 ) 112 { 113 $query = ' 114 UPDATE '.IMAGES_TABLE.' 115 SET hit = hit+1 116 WHERE id = '.$_GET['image_id'].' 117 ;'; 118 @pwg_query( $query ); 119 } 120 121 //-------------------------------------------------------------- representative 122 if (is_admin() and isset($_GET['representative'])) 123 { 124 $query = ' 107 $url_up = duplicate_index_URL( 108 array( 109 'start' => 110 floor($page['current_rank'] / $user['nb_image_page']) 111 * $user['nb_image_page'] 112 ), 113 array( 114 'start', 115 ) 116 ); 117 118 $url_self = duplicate_picture_URL(); 119 120 // +-----------------------------------------------------------------------+ 121 // | actions | 122 // +-----------------------------------------------------------------------+ 123 124 /** 125 * Actions are favorite adding, user comment deletion, setting the picture 126 * as representative of the current category... 127 * 128 * Actions finish by a redirection 129 */ 130 131 if (isset($_GET['action'])) 132 { 133 switch ($_GET['action']) 134 { 135 case 'add_to_favorites' : 136 { 137 $query = ' 138 INSERT INTO '.FAVORITES_TABLE.' 139 (image_id,user_id) 140 VALUES 141 ('.$page['image_id'].','.$user['id'].') 142 ;'; 143 pwg_query($query); 144 145 redirect($url_self); 146 147 break; 148 } 149 case 'remove_from_favorites' : 150 { 151 $query = ' 152 DELETE FROM '.FAVORITES_TABLE.' 153 WHERE user_id = '.$user['id'].' 154 AND image_id = '.$page['image_id'].' 155 ;'; 156 pwg_query($query); 157 158 if ('favorites' == $page['section']) 159 { 160 redirect($url_up); 161 } 162 else 163 { 164 redirect($url_self); 165 } 166 167 break; 168 } 169 case 'set_as_representative' : 170 { 171 if (is_admin() and isset($page['category'])) 172 { 173 $query = ' 125 174 UPDATE '.CATEGORIES_TABLE.' 126 SET representative_picture_id = '.$_GET['image_id'].' 127 WHERE id = '.$page['cat'].' 128 ;'; 129 pwg_query($query); 130 131 $url = 132 PHPWG_ROOT_PATH 133 .'picture.php' 134 .get_query_string_diff(array('representative')); 135 redirect($url); 136 } 137 138 //-------------------------------------------------------------- caddie filling 139 140 if (isset($_GET['caddie'])) 141 { 142 fill_caddie(array($_GET['image_id'])); 143 144 $url = 145 PHPWG_ROOT_PATH 146 .'picture.php' 147 .get_query_string_diff(array('caddie')); 148 redirect($url); 149 } 150 151 152 //----------------------------------------------------------- rate registration 153 if (isset($_GET['rate']) 154 and $conf['rate'] 155 and ( !$user['is_the_guest'] or $conf['rate_anonymous'] ) 156 and in_array($_GET['rate'], $rate_items)) 157 { 158 if ($user['is_the_guest']) 159 { 160 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 161 if ( count($ip_components)>3 ) 175 SET representative_picture_id = '.$page['image_id'].' 176 WHERE id = '.$page['category'].' 177 ;'; 178 pwg_query($query); 179 } 180 181 redirect($url_self); 182 183 break; 184 } 185 case 'toggle_metadata' : 162 186 { 163 array_pop($ip_components);187 break; 164 188 } 165 $anonymous_id = implode ('.', $ip_components); 166 167 if ( isset($_COOKIE['pwg_anonymous_rater']) ) 189 case 'add_to_caddie' : 168 190 { 169 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'] ) 170 { // client has changed his IP adress or he's trying to fool us 171 $query = ' 191 fill_caddie(array($page['image_id'])); 192 redirect($url_self); 193 break; 194 } 195 case 'rate' : 196 { 197 if (isset($_GET['rate']) 198 and $conf['rate'] 199 and (!$user['is_the_guest'] or $conf['rate_anonymous']) 200 and in_array($_GET['rate'], $rate_items)) 201 { 202 if ($user['is_the_guest']) 203 { 204 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 205 if (count($ip_components) > 3) 206 { 207 array_pop($ip_components); 208 } 209 $anonymous_id = implode ('.', $ip_components); 210 211 if (isset($_COOKIE['pwg_anonymous_rater'])) 212 { 213 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) 214 { // client has changed his IP adress or he's trying to fool us 215 $query = ' 172 216 SELECT element_id FROM '. RATE_TABLE . ' 173 217 WHERE user_id=' . $user['id'] . ' 174 218 AND anonymous_id=\'' . $anonymous_id . '\''; 175 $result = pwg_query($query); 176 $already_there = array(); 177 while ( $row = mysql_fetch_array($result) ) 219 $result = pwg_query($query); 220 $already_there = array(); 221 while ($row = mysql_fetch_array($result)) 222 { 223 array_push($already_there, $row['element_id']); 224 } 225 226 if (count($already_there) > 0) 227 { 228 $query = ' 229 DELETE 230 FROM '.RATE_TABLE.' 231 WHERE user_id = '.$user['id'].' 232 AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\' 233 AND element_id NOT IN ('.implode(',', $already_there).') 234 ;'; 235 pwg_query($query); 236 } 237 238 $query = ' 239 UPDATE 240 '.RATE_TABLE.' 241 SET anonymous_id = \'' .$anonymous_id.'\' 242 WHERE user_id = '.$user['id'].' 243 AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' 244 ;'; 245 pwg_query($query); 246 247 setcookie( 248 'pwg_anonymous_rater', 249 $anonymous_id, 250 strtotime('+10 years'), 251 cookie_path() 252 ); 253 } 254 } 255 else 256 { 257 setcookie( 258 'pwg_anonymous_rater', 259 $anonymous_id, 260 strtotime('+10 years'), 261 cookie_path() 262 ); 263 } 264 } 265 266 $query = ' 267 DELETE 268 FROM '.RATE_TABLE.' 269 WHERE element_id = '.$page['image_id'] . ' 270 AND user_id = '.$user['id'].' 271 '; 272 if (isset($anonymous_id)) 178 273 { 179 array_push( $already_there, $row['element_id'] );274 $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; 180 275 } 181 182 if ( count($already_there)>0 ) 183 { 184 $query = ' 185 DELETE FROM '. RATE_TABLE . ' 186 WHERE user_id=' . $user['id'] . ' 187 AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\' 188 AND element_id NOT IN (' . implode(',',$already_there) . ')'; 189 pwg_query($query); 190 } 191 276 pwg_query($query); 192 277 $query = ' 193 UPDATE '. RATE_TABLE . ' 194 SET anonymous_id=\'' . $anonymous_id . '\' 195 WHERE user_id=' . $user['id'] . ' 196 AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\''; 197 pwg_query($query); 198 199 setcookie('pwg_anonymous_rater', $anonymous_id, 200 strtotime('+10 years'), cookie_path() ); 201 } 202 } 203 else 204 { 205 setcookie('pwg_anonymous_rater', $anonymous_id, 206 strtotime('+10 years'), cookie_path() ); 207 } 208 } 209 210 $query = ' 211 DELETE FROM '.RATE_TABLE.' 212 WHERE element_id = '.$_GET['image_id'] . ' 213 AND user_id = '.$user['id'] 214 ; 215 if (isset($anonymous_id)) 216 { 217 $query.= ' AND anonymous_id=\'' . $anonymous_id .'\''; 218 } 219 pwg_query($query); 220 $query = ' 221 INSERT INTO '.RATE_TABLE.' 278 INSERT 279 INTO '.RATE_TABLE.' 222 280 (user_id,anonymous_id,element_id,rate,date) 223 281 VALUES 224 ('.$user['id'].','.(isset($anonymous_id)?'\''.$anonymous_id.'\'':"''").','. 225 $_GET['image_id'].','.$_GET['rate'].',NOW()) 226 ;'; 227 pwg_query($query); 228 229 // update of images.average_rate field 230 $query = ' 282 (' 283 .$user['id'].',' 284 .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' 285 .$page['image_id'].',' 286 .$_GET['rate'] 287 .',NOW()) 288 ;'; 289 pwg_query($query); 290 291 // update of images.average_rate field 292 $query = ' 231 293 SELECT ROUND(AVG(rate),2) AS average_rate 232 294 FROM '.RATE_TABLE.' 233 WHERE element_id = '.$ _GET['image_id'].'234 ;'; 235 $row = mysql_fetch_array(pwg_query($query));236 $query = '295 WHERE element_id = '.$page['image_id'].' 296 ;'; 297 $row = mysql_fetch_array(pwg_query($query)); 298 $query = ' 237 299 UPDATE '.IMAGES_TABLE.' 238 300 SET average_rate = '.$row['average_rate'].' 239 WHERE id = '.$_GET['image_id'].' 240 ;'; 241 pwg_query($query); 242 $url = 243 PHPWG_ROOT_PATH 244 .'picture.php' 245 .get_query_string_diff(array('rate')); 246 redirect($url); 247 } 248 301 WHERE id = '.$page['image_id'].' 302 ;'; 303 pwg_query($query); 304 } 305 306 redirect($url_self); 307 } 308 case 'delete_comment' : 309 { 310 if (isset($_GET['comment_to_delete']) 311 and is_numeric($_GET['comment_to_delete']) 312 and is_admin()) 313 { 314 $query = ' 315 DELETE FROM '.COMMENTS_TABLE.' 316 WHERE id = '.$_GET['comment_to_delete'].' 317 ;'; 318 pwg_query( $query ); 319 } 320 321 redirect($url_self); 322 } 323 } 324 } 325 326 // incrementation of the number of hits, we do this only if no action 327 $query = ' 328 UPDATE 329 '.IMAGES_TABLE.' 330 SET hit = hit+1 331 WHERE id = '.$page['image_id'].' 332 ;'; 333 pwg_query($query); 249 334 250 335 //---------------------------------------------------------- related categories … … 253 338 FROM '.IMAGE_CATEGORY_TABLE.' 254 339 INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id 255 WHERE image_id = '.$ _GET['image_id'].'340 WHERE image_id = '.$page['image_id'].' 256 341 AND category_id NOT IN ('.$user['forbidden_categories'].') 257 342 ;'; … … 266 351 $picture = array(); 267 352 268 $ids = array($ _GET['image_id']);353 $ids = array($page['image_id']); 269 354 if (isset($page['previous_item'])) 270 355 { … … 362 447 } 363 448 364 $picture[$i]['url'] = 365 PHPWG_ROOT_PATH.'picture.php' 366 .get_query_string_diff(array('image_id', 'add_fav', 'slideshow')) 367 .'&image_id='.$row['id']; 368 } 369 370 $url_up = PHPWG_ROOT_PATH.'category.php?'; 371 if ( isset($page['cat']) ) 372 { 373 $url_up .= 'cat='.$page['cat']; 374 } 375 elseif ( isset($_GET['calendar']) ) 376 { 377 $url_up .= 'calendar='.$_GET['calendar']; 378 } 379 380 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] ); 381 $url_up_start *= $user['nb_image_page']; 382 if ($url_up_start>0) 383 { 384 $url_up .= '&start='.$url_up_start; 385 } 386 387 if ( isset($page['cat']) ) 388 { 389 if ( $page['cat'] == 'search' ) 390 { 391 $url_up.= '&search='.$_GET['search']; 392 } 393 if ( $page['cat'] == 'list' ) 394 { 395 $url_up.= '&list='.$_GET['list']; 396 } 449 $picture[$i]['url'] = duplicate_picture_URL( 450 array( 451 'image_id' => $row['id'], 452 ), 453 array( 454 'start', 455 ) 456 ); 397 457 } 398 458 399 459 $url_admin = 400 460 PHPWG_ROOT_PATH.'admin.php?page=picture_modify' 401 .'&cat_id='. ( isset($page['cat']) ? $page['cat'] : '' ) 402 .'&image_id='.$_GET['image_id']; 461 .'&cat_id='.(isset($page['category']) ? $page['category'] : '') 462 .'&image_id='.$page['image_id'] 463 ; 403 464 404 465 $url_slide = 405 $picture['current']['url'].'&slideshow='.$conf['slideshow_period']; 406 407 //--------------------------------------------------------- favorite management 408 if ( isset( $_GET['add_fav'] ) ) 409 { 410 $query = 'DELETE FROM '.FAVORITES_TABLE; 411 $query.= ' WHERE user_id = '.$user['id']; 412 $query.= ' AND image_id = '.$picture['current']['id']; 413 $query.= ';'; 414 $result = pwg_query( $query ); 415 416 if ( $_GET['add_fav'] == 1 ) 417 { 418 $query = 'INSERT INTO '.FAVORITES_TABLE; 419 $query.= ' (image_id,user_id) VALUES'; 420 $query.= ' ('.$picture['current']['id'].','.$user['id'].')'; 421 $query.= ';'; 422 $result = pwg_query( $query ); 423 } 424 if ( !$_GET['add_fav'] and isset($page['cat']) and 'fav'==$page['cat'] ) 425 { 426 if (!isset($page['previous_item']) and !isset($page['next_item'])) 427 { 428 // there is no favorite picture anymore we redirect the user to the 429 // category page 430 redirect($url_up); 431 } 432 else if (!isset($page['previous_item'])) 433 { 434 $url = str_replace( '&', '&', $picture['next']['url'] ); 435 redirect( $url ); 436 } 437 else 438 { 439 $url = str_replace('&', '&', $picture['prev']['url'] ); 440 redirect( $url ); 441 } 442 redirect( $url ); 443 } 444 } 445 446 //------------------------------------------------------ comment registeration 447 if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) 448 { 449 $register_comment = true; 450 $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; 451 // if a guest try to use the name of an already existing user, he must be 452 // rejected 453 if ( $author != $user['username'] ) 454 { 455 $query = 'SELECT COUNT(*) AS user_exists'; 456 $query.= ' FROM '.USERS_TABLE; 457 $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'"; 458 $query.= ';'; 459 $row = mysql_fetch_array( pwg_query( $query ) ); 460 if ( $row['user_exists'] == 1 ) 461 { 462 $template->assign_block_vars( 463 'information', 464 array('INFORMATION'=>$lang['comment_user_exists'])); 465 $register_comment = false; 466 } 467 } 468 469 if ( $register_comment ) 470 { 471 // anti-flood system 472 $reference_date = time() - $conf['anti-flood_time']; 473 $query = 'SELECT id FROM '.COMMENTS_TABLE; 474 $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; 475 $query.= " AND author = '".$author."'"; 476 $query.= ';'; 477 if ( mysql_num_rows( pwg_query( $query ) ) == 0 478 or $conf['anti-flood_time'] == 0 ) 479 { 480 list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); 481 482 $data = array(); 483 $data{'author'} = $author; 484 $data{'date'} = $dbnow; 485 $data{'image_id'} = $_GET['image_id']; 486 $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES); 487 488 if (!$conf['comments_validation'] or is_admin()) 489 { 490 $data{'validated'} = 'true'; 491 $data{'validation_date'} = $dbnow; 492 } 493 else 494 { 495 $data{'validated'} = 'false'; 496 } 497 498 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 499 $fields = array('author', 'date', 'image_id', 'content', 'validated', 500 'validation_date'); 501 mass_inserts(COMMENTS_TABLE, $fields, array($data)); 502 503 // information message 504 $message = $lang['comment_added']; 505 506 if (!$conf['comments_validation'] or is_admin()) 507 508 if ( $conf['comments_validation'] and !is_admin() ) 509 { 510 $message.= '<br />'.$lang['comment_to_validate']; 511 } 512 $template->assign_block_vars('information', 513 array('INFORMATION'=>$message)); 514 } 515 else 516 { 517 // information message 518 $template->assign_block_vars( 519 'information', 520 array('INFORMATION'=>$lang['comment_anti-flood'])); 521 } 522 } 523 } 524 // comment deletion 525 if ( isset( $_GET['del'] ) 526 and is_numeric( $_GET['del'] ) 527 and is_admin() ) 528 { 529 $query = 'DELETE FROM '.COMMENTS_TABLE; 530 $query.= ' WHERE id = '.$_GET['del']; 531 $query.= ';'; 532 pwg_query( $query ); 533 } 534 535 // 536 // Start output of page 537 // 466 $picture['current']['url'] 467 .'&slideshow='.$conf['slideshow_period'] 468 ; 538 469 539 470 $title = $picture['current']['name']; … … 572 503 } 573 504 574 $picture_size = get_picture_size($original_width, $original_height, 575 @$user['maxwidth'], @$user['maxheight']); 505 $picture_size = get_picture_size( 506 $original_width, 507 $original_height, 508 @$user['maxwidth'], 509 @$user['maxheight'] 510 ); 576 511 577 512 // metadata … … 585 520 } 586 521 587 $url_metadata = PHPWG_ROOT_PATH.'picture.php'; 588 $url_metadata .= get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata')); 589 if ($metadata_showable and !isset($_GET['show_metadata'])) 590 { 591 $url_metadata.= '&show_metadata=1'; 592 } 522 // $url_metadata = PHPWG_ROOT_PATH.'picture.php'; 523 // $url_metadata .= get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata')); 524 // if ($metadata_showable and !isset($_GET['show_metadata'])) 525 // { 526 // $url_metadata.= '&show_metadata=1'; 527 // } 528 529 // TODO: rewrite metadata display to toggle on/off user_infos.show_metadata 530 $url_metadata = duplicate_picture_URL(); 593 531 594 532 $page['body_id'] = 'thePicturePage'; … … 623 561 $template->set_filenames(array('picture'=>'picture.tpl')); 624 562 625 $template->assign_vars(array( 626 'CATEGORY' => $title_img, 627 'PHOTO' => $title_nb, 628 'TITLE' => $picture['current']['name'], 629 'SRC_IMG' => $picture['current']['src'], 630 'ALT_IMG' => $picture['current']['file'], 631 'WIDTH_IMG' => $picture_size[0], 632 'HEIGHT_IMG' => $picture_size[1], 633 634 'LEVEL_SEPARATOR' => $conf['level_separator'], 635 636 'L_HOME' => $lang['home'], 637 'L_SLIDESHOW' => $lang['slideshow'], 638 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], 639 'L_PREV_IMG' =>$lang['previous_page'].' : ', 640 'L_NEXT_IMG' =>$lang['next_page'].' : ', 641 'L_ADMIN' =>$lang['link_info_image'], 642 'L_COMMENT_TITLE' =>$lang['comments_title'], 643 'L_ADD_COMMENT' =>$lang['comments_add'], 644 'L_DELETE_COMMENT' =>$lang['comments_del'], 645 'L_DELETE' =>$lang['delete'], 646 'L_SUBMIT' =>$lang['submit'], 647 'L_AUTHOR' => $lang['upload_author'], 648 'L_COMMENT' =>$lang['comment'], 649 'L_DOWNLOAD' => $lang['download'], 650 'L_DOWNLOAD_HINT' => $lang['download_hint'], 651 'L_PICTURE_METADATA' => $lang['picture_show_metadata'], 652 'L_PICTURE_HIGH' => $lang['picture_high'], 653 'L_UP_HINT' => $lang['home_hint'], 654 'L_UP_ALT' => $lang['home'], 655 656 'U_HOME' => (PHPWG_ROOT_PATH.'category.php'), 657 'U_UP' => $url_up, 658 'U_METADATA' => $url_metadata, 659 'U_ADMIN' => $url_admin, 660 'U_SLIDESHOW'=> $url_slide, 661 'U_ADD_COMMENT' => str_replace( '&', '&', $_SERVER['REQUEST_URI'] ) 662 ) 663 ); 563 $template->assign_vars( 564 array( 565 'CATEGORY' => $title_img, 566 'PHOTO' => $title_nb, 567 'TITLE' => $picture['current']['name'], 568 'SRC_IMG' => $picture['current']['src'], 569 'ALT_IMG' => $picture['current']['file'], 570 'WIDTH_IMG' => $picture_size[0], 571 'HEIGHT_IMG' => $picture_size[1], 572 573 'LEVEL_SEPARATOR' => $conf['level_separator'], 574 575 'L_HOME' => $lang['home'], 576 'L_SLIDESHOW' => $lang['slideshow'], 577 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], 578 'L_PREV_IMG' =>$lang['previous_page'].' : ', 579 'L_NEXT_IMG' =>$lang['next_page'].' : ', 580 'L_ADMIN' =>$lang['link_info_image'], 581 'L_COMMENT_TITLE' =>$lang['comments_title'], 582 'L_ADD_COMMENT' =>$lang['comments_add'], 583 'L_DELETE_COMMENT' =>$lang['comments_del'], 584 'L_DELETE' =>$lang['delete'], 585 'L_SUBMIT' =>$lang['submit'], 586 'L_AUTHOR' => $lang['upload_author'], 587 'L_COMMENT' =>$lang['comment'], 588 'L_DOWNLOAD' => $lang['download'], 589 'L_DOWNLOAD_HINT' => $lang['download_hint'], 590 'L_PICTURE_METADATA' => $lang['picture_show_metadata'], 591 'L_PICTURE_HIGH' => $lang['picture_high'], 592 'L_UP_HINT' => $lang['home_hint'], 593 'L_UP_ALT' => $lang['home'], 594 595 'U_HOME' => make_index_URL(), 596 'U_UP' => $url_up, 597 'U_METADATA' => $url_metadata, 598 'U_ADMIN' => $url_admin, 599 'U_SLIDESHOW'=> $url_slide, 600 'U_ADD_COMMENT' => $url_self, 601 ) 602 ); 664 603 665 604 if ($conf['show_picture_name_on_title']) … … 669 608 670 609 //------------------------------------------------------- upper menu management 610 671 611 // download link if file is not a picture 672 612 if (!$picture['current']['is_picture']) … … 674 614 $template->assign_block_vars( 675 615 'download', 676 array('U_DOWNLOAD' => $picture['current']['download'])); 677 } 616 array( 617 'U_DOWNLOAD' => $picture['current']['download'] 618 ) 619 ); 620 } 621 678 622 // display a high quality link if present 679 623 if (isset($picture['current']['high'])) 680 624 { 681 625 $uuid = uniqid(rand()); 682 $template->assign_block_vars('high', array( 683 'U_HIGH' => $picture['current']['high'], 684 'UUID'=>$uuid 685 )); 626 627 $template->assign_block_vars( 628 'high', 629 array( 630 'U_HIGH' => $picture['current']['high'], 631 'UUID' => $uuid, 632 ) 633 ); 634 686 635 $template->assign_block_vars( 687 636 'download', 688 array('U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn=' 689 .$picture['current']['high'] 690 ) 691 ); 692 } 637 array( 638 'U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn=' 639 .$picture['current']['high'] 640 ) 641 ); 642 } 643 693 644 // button to set the current picture as representative 694 if (is_admin() and 695 isset($page['cat']) and is_numeric($page['cat'])) 645 if (is_admin() and isset($page['category'])) 696 646 { 697 647 $template->assign_block_vars( 698 648 'representative', 699 649 array( 700 'URL' => 701 PHPWG_ROOT_PATH.'picture.php' 702 .get_query_string_diff(array('add_fav')) 703 .'&representative=1' 704 ) 705 ); 706 } 707 650 'URL' => $url_self.'&action=set_as_representative' 651 ) 652 ); 653 } 654 655 // caddie button 708 656 if (is_admin()) 709 657 { … … 711 659 'caddie', 712 660 array( 713 'URL' => 714 PHPWG_ROOT_PATH.'picture.php' 715 .get_query_string_diff(array('add_fav')).'&caddie=1') 716 ); 717 } 718 719 //------------------------------------------------------- favorite manipulation 720 if ( !$user['is_the_guest'] ) 661 'URL' => $url_self.'&action=add_to_caddie' 662 ) 663 ); 664 } 665 666 // favorite manipulation 667 if (!$user['is_the_guest']) 721 668 { 722 669 // verify if the picture is already in the favorite of the user 723 $query = 'SELECT COUNT(*) AS nb_fav'; 724 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; 725 $query.= ' AND user_id = '.$user['id'].';'; 726 $result = pwg_query( $query ); 727 $row = mysql_fetch_array( $result ); 728 if (!$row['nb_fav']) 729 { 730 $url = PHPWG_ROOT_PATH.'picture.php'; 731 $url.= get_query_string_diff(array('add_fav')); 732 $url.= '&add_fav=1'; 670 $query = ' 671 SELECT COUNT(*) AS nb_fav 672 FROM '.FAVORITES_TABLE.' 673 WHERE image_id = '.$page['image_id'].' 674 AND user_id = '.$user['id'].' 675 ;'; 676 $result = pwg_query($query); 677 $row = mysql_fetch_array($result); 678 679 if ($row['nb_fav'] == 0) 680 { 681 $url = $url_self.'&action=add_to_favorites'; 733 682 734 683 $template->assign_block_vars( 735 684 'favorite', 736 685 array( 737 'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png', 738 'FAVORITE_HINT' =>$lang['add_favorites_hint'], 739 'FAVORITE_ALT' =>$lang['add_favorites_alt'], 740 'U_FAVORITE' => $url 741 )); 686 'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png', 687 'FAVORITE_HINT' => $lang['add_favorites_hint'], 688 'FAVORITE_ALT' => $lang['add_favorites_alt'], 689 'U_FAVORITE' => $url_self.'&action=add_to_favorites', 690 ) 691 ); 742 692 } 743 693 else 744 694 { 745 $url = PHPWG_ROOT_PATH.'picture.php';746 $url.= get_query_string_diff(array('add_fav'));747 $url.= '&add_fav=0';748 749 695 $template->assign_block_vars( 750 696 'favorite', 751 697 array( 752 'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png', 753 'FAVORITE_HINT' =>$lang['del_favorites_hint'], 754 'FAVORITE_ALT' =>$lang['del_favorites_alt'], 755 'U_FAVORITE'=> $url 756 )); 698 'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png', 699 'FAVORITE_HINT' => $lang['del_favorites_hint'], 700 'FAVORITE_ALT' => $lang['del_favorites_alt'], 701 'U_FAVORITE' => $url_self.'&action=remove_from_favorites', 702 ) 703 ); 757 704 } 758 705 } … … 888 835 } 889 836 890 //------------------------------------------------------------------- metadata891 if ($metadata_showable and isset($_GET['show_metadata']))892 {893 include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');894 $template->assign_block_vars('metadata', array());895 if ($conf['show_exif'])896 {897 if (!function_exists('read_exif_data'))898 {899 die('Exif extension not available, admin should disable exif display');900 }901 902 if ($exif = @read_exif_data($picture['current']['src']))903 {904 $template->assign_block_vars(905 'metadata.headline',906 array('TITLE' => 'EXIF Metadata')907 );908 909 foreach ($conf['show_exif_fields'] as $field)910 {911 if (strpos($field, ';') === false)912 {913 if (isset($exif[$field]))914 {915 $key = $field;916 if (isset($lang['exif_field_'.$field]))917 {918 $key = $lang['exif_field_'.$field];919 }920 921 $template->assign_block_vars(922 'metadata.line',923 array(924 'KEY' => $key,925 'VALUE' => $exif[$field]926 )927 );928 }929 }930 else931 {932 $tokens = explode(';', $field);933 if (isset($exif[$tokens[0]][$tokens[1]]))934 {935 $key = $tokens[1];936 if (isset($lang['exif_field_'.$tokens[1]]))937 {938 $key = $lang['exif_field_'.$tokens[1]];939 }940 941 $template->assign_block_vars(942 'metadata.line',943 array(944 'KEY' => $key,945 'VALUE' => $exif[$tokens[0]][$tokens[1]]946 )947 );948 }949 }950 }951 }952 }953 if ($conf['show_iptc'])954 {955 $iptc = get_iptc_data($picture['current']['src'],956 $conf['show_iptc_mapping']);957 958 if (count($iptc) > 0)959 {960 $template->assign_block_vars(961 'metadata.headline',962 array('TITLE' => 'IPTC Metadata')963 );964 }965 966 foreach ($iptc as $field => $value)967 {968 $key = $field;969 if (isset($lang[$field]))970 {971 $key = $lang[$field];972 }973 974 $template->assign_block_vars(975 'metadata.line',976 array(977 'KEY' => $key,978 'VALUE' => $value979 )980 );981 }982 }983 }984 837 //slideshow end 985 if ( isset( $_GET['slideshow'] ) ) 986 { 987 if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period']; 988 989 $template->assign_block_vars('stop_slideshow', array( 990 'U_SLIDESHOW'=>$picture['current']['url'] 991 )); 992 } 993 994 //------------------------------------------------------------------- rating 995 if ($conf['rate']) 996 { 997 $query = ' 998 SELECT COUNT(rate) AS count 999 , ROUND(AVG(rate),2) AS average 1000 , ROUND(STD(rate),2) AS STD 1001 FROM '.RATE_TABLE.' 1002 WHERE element_id = '.$picture['current']['id'].' 1003 ;'; 1004 $row = mysql_fetch_array(pwg_query($query)); 1005 if ($row['count'] == 0) 1006 { 1007 $value = $lang['no_rate']; 1008 } 1009 else 1010 { 1011 $value = sprintf( 1012 l10n('%.2f (rated %d times, standard deviation = %.2f)'), 1013 $row['average'], 1014 $row['count'], 1015 $row['STD'] 1016 ); 1017 } 1018 1019 if ($conf['rate_anonymous'] or !$user['is_the_guest']) 1020 { 1021 if ($row['count']>0) 1022 { 1023 $query = 'SELECT rate 1024 FROM '.RATE_TABLE.' 1025 WHERE element_id = '.$_GET['image_id'] . ' 1026 AND user_id = '.$user['id'] ; 1027 1028 if ($user['is_the_guest']) 1029 { 1030 $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); 1031 if ( count($ip_components)>3 ) 1032 { 1033 array_pop($ip_components); 1034 } 1035 $anonymous_id = implode ('.', $ip_components); 1036 $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; 1037 } 1038 1039 $result = pwg_query($query); 1040 if (mysql_num_rows($result) > 0) 1041 { 1042 $row = mysql_fetch_array($result); 1043 $sentence = $lang['already_rated']; 1044 $sentence.= ' ('.$row['rate'].'). '; 1045 $sentence.= $lang['update_rate']; 1046 } 1047 else 1048 { 1049 $sentence = $lang['never_rated'].'. '.$lang['Rate']; 1050 } 1051 } 1052 else 1053 { 1054 $sentence = $lang['never_rated'].'. '.$lang['Rate']; 1055 } 1056 $template->assign_block_vars( 1057 'rate', 1058 array( 1059 'CONTENT' => $value, 1060 'SENTENCE' => $sentence 1061 )); 1062 1063 $template->assign_block_vars('info_rate', array('CONTENT' => $value)); 1064 1065 $template->assign_vars( 1066 array( 1067 'INFO_RATE' => $value 1068 ) 1069 ); 1070 1071 foreach ($rate_items as $num => $mark) 1072 { 1073 if ($num > 0) 1074 { 1075 $separator = '|'; 1076 } 1077 else 1078 { 1079 $separator = ''; 1080 } 1081 1082 $url = PHPWG_ROOT_PATH.'picture.php'; 1083 $url.= get_query_string_diff(array('add_fav')); 1084 $url.= '&rate='.$mark; 1085 1086 $template->assign_block_vars( 1087 'rate.rate_option', 1088 array( 1089 'OPTION' => $mark, 1090 'URL' => $url, 1091 'SEPARATOR' => $separator 1092 )); 1093 } 1094 } 1095 } 1096 1097 //---------------------------------------------------- users's comments display 1098 1099 // the picture is commentable if it belongs at least to one category which 1100 // is commentable 1101 $page['show_comments'] = false; 1102 foreach ($related_categories as $category) 1103 { 1104 if ($category['commentable'] == 'true') 1105 { 1106 $page['show_comments'] = true; 1107 } 1108 } 1109 1110 if ($page['show_comments']) 1111 { 1112 // number of comment for this picture 1113 $query = 'SELECT COUNT(*) AS nb_comments'; 1114 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 1115 $query.= " AND validated = 'true'"; 1116 $query.= ';'; 1117 $row = mysql_fetch_array( pwg_query( $query ) ); 1118 1119 // navigation bar creation 1120 $url = PHPWG_ROOT_PATH.'picture.php'; 1121 $url.= get_query_string_diff(array('add_fav','start')); 1122 1123 if (!isset( $_GET['start'] ) 1124 or !is_numeric( $_GET['start'] ) 1125 or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) 1126 { 1127 $page['start'] = 0; 1128 } 1129 else 1130 { 1131 $page['start'] = $_GET['start']; 1132 } 1133 $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], 1134 $page['start'], 1135 $conf['nb_comment_page'], 1136 '' ); 1137 $template->assign_block_vars('comments', array( 1138 'NB_COMMENT'=>$row['nb_comments'], 1139 'NAV_BAR'=>$page['navigation_bar'])); 1140 1141 if ($row['nb_comments']>0) 1142 { 1143 $query = 'SELECT id,author,date,image_id,content'; 1144 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 1145 $query.= " AND validated = 'true'"; 1146 $query.= ' ORDER BY date ASC'; 1147 $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; 1148 $result = pwg_query( $query ); 1149 1150 while ( $row = mysql_fetch_array( $result ) ) 1151 { 1152 $template->assign_block_vars( 1153 'comments.comment', 1154 array( 1155 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], 1156 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), 1157 'COMMENT'=>parse_comment_content($row['content']) 1158 )); 1159 1160 if ( is_admin() ) 1161 { 1162 $template->assign_block_vars( 1163 'comments.comment.delete', 1164 array('U_COMMENT_DELETE'=> $url.'&del='.$row['id'] 1165 )); 1166 } 1167 } 1168 } 1169 1170 if (!$user['is_the_guest'] 1171 or ($user['is_the_guest'] and $conf['comments_forall'])) 1172 { 1173 $template->assign_block_vars('comments.add_comment', array()); 1174 // display author field if the user is not logged in 1175 if (!$user['is_the_guest']) 1176 { 1177 $template->assign_block_vars( 1178 'comments.add_comment.author_known', 1179 array('KNOWN_AUTHOR'=>$user['username']) 1180 ); 1181 } 1182 else 1183 { 1184 $template->assign_block_vars( 1185 'comments.add_comment.author_field', array() 1186 ); 1187 } 1188 } 1189 } 838 if (isset($_GET['slideshow'])) 839 { 840 if (!is_numeric($_GET['slideshow'])) 841 { 842 $_GET['slideshow'] = $conf['slideshow_period']; 843 } 844 845 $template->assign_block_vars( 846 'stop_slideshow', 847 array( 848 'U_SLIDESHOW' => $picture['current']['url'], 849 ) 850 ); 851 } 852 853 // +-----------------------------------------------------------------------+ 854 // | sub pages | 855 // +-----------------------------------------------------------------------+ 856 857 include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php'); 858 include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php'); 859 include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php'); 860 1190 861 //------------------------------------------------------------ log informations 1191 862 pwg_log( 'picture', $title_img, $picture['current']['file'] );
Note: See TracChangeset
for help on using the changeset viewer.