Changeset 345 for trunk/picture.php
- Timestamp:
- Feb 2, 2004, 1:55:18 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r183 r345 17 17 * * 18 18 ***************************************************************************/ 19 20 19 // this page shows the image full size 21 //----------------------------------------------------------- personnal include 22 include_once( './include/init.inc.php' ); 20 //----------------------------------------------------------- include 21 $phpwg_root_path = './'; 22 include_once( $phpwg_root_path.'common.php' ); 23 23 //-------------------------------------------------- access authorization check 24 24 check_cat_id( $_GET['cat'] ); 25 25 check_login_authorization(); 26 $page['plain_structure'] = get_plain_structure();27 26 if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) 28 27 { … … 30 29 } 31 30 //---------------------------------------- incrementation of the number of hits 32 $query = 'UPDATE '.PREFIX_TABLE.'images'; 33 $query.= ' SET hit=hit+1'; 31 $query = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1'; 34 32 $query.= ' WHERE id='.$_GET['image_id']; 35 33 $query.= ';'; … … 38 36 initialize_category( 'picture' ); 39 37 //------------------------------------- main picture information initialization 40 $ query = 'SELECT id,date_available,comment,hit,keywords';41 $query.= ',author,name,file,date_creation,filesize,width,height'; 42 $query.= ',storage_category_id';43 if ( is_numeric( $page['cat'] ) ) 44 { 45 46 } 47 $query.= ' FROM '.PREFIX_TABLE.'images';48 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS icON id = ic.image_id';38 $infos = array( 'id','date_available','comment','hit','keywords','author' 39 ,'name','file','date_creation','filesize','width','height' 40 ,'storage_category_id' ); 41 42 $query = 'SELECT '.implode( ',', $infos ); 43 if ( is_numeric( $page['cat'] ) ) $query.= ',category_id'; 44 $query.= ' FROM '.IMAGES_TABLE; 45 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 46 $query.= ' ON id = ic.image_id'; 49 47 $query.= $page['where']; 50 48 $query.= ' AND id = '.$_GET['image_id']; … … 62 60 } 63 61 $row = mysql_fetch_array( $result ); 64 $page['id'] = $row['id']; 65 $page['file'] = $row['file']; 66 $page['name'] = $row['name']; 67 $page['date_available'] = $row['date_available']; 68 $page['comment'] = $row['comment']; 69 $page['hit'] = $row['hit']; 70 $page['author'] = $row['author']; 71 $page['date_creation'] = $row['date_creation']; 72 $page['filesize'] = $row['filesize']; 73 $page['width'] = $row['width']; 74 $page['height'] = $row['height']; 75 $page['category_id'] = $row['category_id']; 76 $page['keywords'] = $row['keywords']; 77 $page['storage_category_id'] = $row['storage_category_id']; 62 63 foreach ( $infos as $info ) { 64 if ( isset( $row[$info] ) ) $page[$info] = $row[$info]; 65 else $page[$info] = ''; 66 } 67 if ( is_numeric( $page['cat'] ) ) $page['category_id'] = $row['category_id']; 78 68 // retrieving the number of the picture in its category (in order) 79 69 $query = 'SELECT DISTINCT(id)'; 80 $query.= ' FROM '.PREFIX_TABLE.'images'; 81 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id'; 70 $query.= ' FROM '.IMAGES_TABLE; 71 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 72 $query.= ' ON id = ic.image_id'; 82 73 $query.= $page['where']; 83 74 $query.= $conf['order_by']; … … 98 89 // verify if the picture is already in the favorite of the user 99 90 $query = 'SELECT COUNT(*) AS nb_fav'; 100 $query.= ' FROM '.PREFIX_TABLE.'favorites'; 101 $query.= ' WHERE image_id = '.$page['id']; 91 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$page['id']; 102 92 $query.= ' AND user_id = '.$user['id']; 103 93 $query.= ';'; … … 106 96 if ( $row['nb_fav'] == 0 ) 107 97 { 108 $query = 'INSERT INTO '.PREFIX_TABLE.'favorites'; 109 $query.= ' (image_id,user_id) VALUES'; 98 $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES'; 110 99 $query.= ' ('.$page['id'].','.$user['id'].')'; 111 100 $query.= ';'; … … 115 104 if ( $_GET['add_fav'] == 0 ) 116 105 { 117 $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; 118 $query.= ' WHERE user_id = '.$user['id']; 106 $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id']; 119 107 $query.= ' AND image_id = '.$page['id']; 120 108 $query.= ';'; … … 140 128 } 141 129 $query = 'SELECT id'; 142 $query.= ' FROM '.PREFIX_TABLE.'images';143 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_categoryAS ic';130 $query.= ' FROM '.IMAGES_TABLE; 131 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 144 132 $query.= ' ON id = ic.image_id'; 145 133 $query.= $page['where']; … … 162 150 } 163 151 } 152 153 //---------------------------------------------- next picture thumbnail display 154 $next = 0; 155 if ( $page['num'] < $page['cat_nb_images']-1 ) 156 { 157 $next = $page['num'] + 1; 158 $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; 159 $query.= ' FROM '.IMAGES_TABLE; 160 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 161 $query.= ' ON id=ic.image_id'; 162 $query.= $page['where']; 163 $query.= $conf['order_by']; 164 $query.= ' LIMIT '.$next.',1'; 165 $query.= ';'; 166 $result = mysql_query( $query ); 167 $row = mysql_fetch_array( $result ); 168 169 if ( !isset($array_cat_directories[$row['storage_category_id']])) 170 { 171 $array_cat_directories[$row['storage_category_id']] = 172 get_complete_dir( $row['storage_category_id'] ); 173 } 174 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 175 176 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); 177 $next_lien_thumbnail = $cat_directory.'thumbnail/'; 178 $next_lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 179 180 if ( isset( $row['name'] ) and $row['name'] != '' ) 181 { 182 $next_alt_thumbnail = $row['name']; 183 } 184 else 185 { 186 $next_alt_thumbnail = $file; 187 } 188 $next_title = $lang['next_image']." : ".$next_alt_thumbnail; 189 190 $next_url_link = './picture.php?image_id='.$row['id']; 191 $next_url_link.= '&cat='.$page['cat']; 192 if ( isset( $_GET['expand'] ) ) 193 $next_url_link.= '&expand='.$_GET['expand']; 194 if ( $page['cat'] == 'search' ) 195 { 196 $next_url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 197 } 198 } 164 199 //----------------------------------------------------- template initialization 165 $vtp = new VTemplate; 200 // 201 // Start output of page 202 // 203 //------------------------------------------------------------------ page title 204 $title = $page['name']; 205 if ( $title == '') 206 { 207 $title = str_replace("_"," ",get_filename_wo_extension($page['file'])); 208 } 209 $refresh = 0; 210 if ( isset( $_GET['slideshow'] ) && isset($next_url_link)) 211 { 212 $refresh= $_GET['slideshow']; 213 $url_link = $next_url_link; 214 } 215 include('include/page_header.php'); 216 166 217 $handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' ); 167 218 initialize_template(); … … 171 222 'period_seconds' ); 172 223 templatize_array( $tpl, 'lang', $handle ); 173 $vtp->setGlobalVar( $handle, 'user_template', $user['template'] );174 $vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] );175 224 //-------------------------------------------------------- slideshow management 176 225 if ( isset( $_GET['slideshow'] ) ) … … 200 249 $url.= '?image_id='.$page['id']; 201 250 $url.= '&cat='.$page['cat']; 202 $url.= '&expand='.$_GET['expand']; 251 if (isset($_GET['expand'])) 252 $url.= '&expand='.$_GET['expand']; 203 253 if ( $page['cat'] == 'search' ) 204 254 { … … 212 262 $vtp->closeSession( $handle, 'start_slideshow' ); 213 263 } 214 //------------------------------------------------------------------ page title 215 if ( $page['name'] != '' ) 216 { 217 $vtp->setGlobalVar( $handle, 'page_title', $page['name'] ); 218 } 219 else 220 { 221 $page_title = str_replace("_"," ",get_filename_wo_extension($page['file'])); 222 $vtp->setGlobalVar( $handle, 'page_title', $page_title ); 223 } 264 224 265 //-------------------------------------------------- previous picture thumbnail 225 266 if ( $page['num'] >= 1 ) … … 227 268 $prev = $page['num'] - 1; 228 269 $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; 229 $query.= ' FROM '.PREFIX_TABLE.'images'; 230 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id'; 270 $query.= ' FROM '.IMAGES_TABLE; 271 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 272 $query.= ' ON id=ic.image_id'; 231 273 $query.= $page['where']; 232 274 $query.= $conf['order_by']; … … 236 278 $row = mysql_fetch_array( $result ); 237 279 238 if ( $array_cat_directories[$row['storage_category_id']] == '')280 if ( !isset($array_cat_directories[$row['storage_category_id']]) ) 239 281 { 240 282 $array_cat_directories[$row['storage_category_id']] = … … 244 286 245 287 $file = substr( $row['file'], 0, strrpos ( $row['file'], '.' ) ); 246 $lien_thumbnail = $cat_directory.' /thumbnail/';288 $lien_thumbnail = $cat_directory.'thumbnail/'; 247 289 $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 248 290 249 291 $prev_title = $lang['previous_image'].' : '; 250 $alt_thumbnaill = ''; 251 if ( $row['name'] != '' ) $alt_thumbnail = $row['name']; 252 else $alt_thumbnail = $file; 292 293 if ( isset( $row['name'] ) and $row['name'] != '' ) 294 $alt_thumbnail = $row['name']; 295 else 296 $alt_thumbnail = $file; 297 253 298 $prev_title.= $alt_thumbnail; 254 299 255 300 $url_link = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; 256 $url_link.= '&expand='.$_GET['expand'];301 if ( isset( $_GET['expand'] ) ) $url_link.= '&expand='.$_GET['expand']; 257 302 if ( $page['cat'] == 'search' ) 258 303 { … … 283 328 } 284 329 285 if ( $array_cat_directories[$page['storage_category_id']] == '')330 if ( !isset($array_cat_directories[$page['storage_category_id']]) ) 286 331 { 287 332 $array_cat_directories[$page['storage_category_id']] = … … 291 336 292 337 $n = $page['num'] + 1; 293 $intitule_titre = replace_space( $intitule_cat." - " ).$n.'/' .338 $intitule_titre = replace_space( $intitule_cat." - " ).$n.'/'; 294 339 $intitule_titre.= $page['cat_nb_images']."<br />"; 295 340 if ( $page['name'] != "" ) … … 330 375 331 376 $url_link = './category.php?cat='.$page['cat'].'&'; 332 $url_link.= 'num='.$page['num'].'&expand='.$_GET['expand']; 377 $url_link.= 'num='.$page['num']; 378 if (isset($_GET['expand'])) 379 $url_link.='&expand='.$_GET['expand']; 333 380 if ( $page['cat'] == 'search' ) 334 381 { … … 338 385 $vtp->setGlobalVar( $handle, 'picture_width', $final_width ); 339 386 $vtp->setGlobalVar( $handle, 'picture_height', $final_height ); 340 $vtp->setGlobalVar( $handle, 'picture_border_color', $user['couleur_text'] );341 387 $vtp->setGlobalVar( $handle, 'picture_src', $lien_image ); 342 388 $vtp->setGlobalVar( $handle, 'picture_alt', $page['file'] ); … … 427 473 $keywords = explode( ',', $page['keywords'] ); 428 474 $content = ''; 429 $url = './category.php?cat=search&expand='.$_GET['expand']; 475 $url = './category.php?cat=search'; 476 if ( isset( $_GET['expand'] ) ) $url.= '&expand='.$_GET['expand']; 430 477 $url.= '&mode=OR&search='; 431 478 foreach ( $keywords as $i => $keyword ) { … … 443 490 $vtp->closeSession( $handle, 'info_line' ); 444 491 //------------------------------------------------------- favorite manipulation 445 if ( $page['cat'] != 'fav' and !$user['is_the_guest'] ) 446 { 447 $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; 448 $url.= '&expand='.$_GET['expand'].'&add_fav=1'; 449 if ( $page['cat'] == 'search' ) 450 { 451 $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 452 } 453 $vtp->addSession( $handle, 'favorite' ); 454 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 455 $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] ); 456 $vtp->setVar( $handle, 'favorite.src', 457 './template/'.$user['template'].'/theme/favorite.gif' ); 458 $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['add_favorites_alt'].' ]' ); 459 $vtp->closeSession( $handle, 'favorite' ); 460 } 461 if ( $page['cat'] == 'fav' ) 462 { 463 $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; 464 $url.= '&expand='.$_GET['expand'].'&add_fav=0'; 465 $vtp->addSession( $handle, 'favorite' ); 466 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 467 $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] ); 468 $vtp->setVar( $handle, 'favorite.src', 469 './template/'.$user['template'].'/theme/del_favorite.gif' ); 470 $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['del_favorites_alt'].' ]' ); 471 $vtp->closeSession( $handle, 'favorite' ); 492 if ( !$user['is_the_guest'] ) 493 { 494 // verify if the picture is already in the favorite of the user 495 $query = 'SELECT COUNT(*) AS nb_fav'; 496 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$page['id']; 497 $query.= ' AND user_id = '.$user['id'].';'; 498 $result = mysql_query( $query ); 499 $row = mysql_fetch_array( $result ); 500 if (!$row['nb_fav']) 501 { 502 $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; 503 if (isset($_GET['expand'])) 504 $url.= '&expand='.$_GET['expand']; 505 $url.='&add_fav=1'; 506 if ( $page['cat'] == 'search' ) 507 { 508 $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 509 } 510 $vtp->addSession( $handle, 'favorite' ); 511 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 512 $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] ); 513 $vtp->setVar( $handle, 'favorite.src', 514 './template/'.$user['template'].'/theme/favorite.gif' ); 515 $vtp->setVar($handle,'favorite.alt','[ '.$lang['add_favorites_alt'].' ]'); 516 $vtp->closeSession( $handle, 'favorite' ); 517 } 518 else 519 { 520 $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; 521 $url.= '&expand='.$_GET['expand'].'&add_fav=0'; 522 $vtp->addSession( $handle, 'favorite' ); 523 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 524 $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] ); 525 $vtp->setVar( $handle, 'favorite.src', 526 './template/'.$user['template'].'/theme/del_favorite.gif' ); 527 $vtp->setVar($handle,'favorite.alt','[ '.$lang['del_favorites_alt'].' ]'); 528 $vtp->closeSession( $handle, 'favorite' ); 529 } 472 530 } 473 531 //------------------------------------ admin link for information modifications … … 480 538 $vtp->setVar( $handle, 'modification.name', $lang['link_info_image'] ); 481 539 } 482 //---------------------------------------------- next picture thumbnail display 483 if ( $page['num'] < $page['cat_nb_images']-1 ) 484 { 485 $next = $page['num'] + 1; 486 $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; 487 $query.= ' FROM '.PREFIX_TABLE.'images'; 488 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id'; 489 $query.= $page['where']; 490 $query.= $conf['order_by']; 491 $query.= ' LIMIT '.$next.',1'; 492 $query.= ';'; 493 $result = mysql_query( $query ); 494 $row = mysql_fetch_array( $result ); 495 496 if ( $array_cat_directories[$row['storage_category_id']] == '' ) 497 { 498 $array_cat_directories[$row['storage_category_id']] = 499 get_complete_dir( $row['storage_category_id'] ); 500 } 501 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 502 503 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); 504 $lien_thumbnail = $cat_directory.'thumbnail/'; 505 $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 506 507 if ( $row['name'] != "" ) 508 { 509 $alt_thumbnail = $row['name']; 510 } 511 else 512 { 513 $alt_thumbnail = $file; 514 } 515 $next_title = $lang['next_image']." : ".$alt_thumbnail; 516 517 $url_link = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; 518 $url_link.= '&expand='.$_GET['expand']; 519 if ( $page['cat'] == 'search' ) 520 { 521 $url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 522 } 540 541 if ( $next ) 542 { 523 543 // sending vars for display 524 544 $vtp->addSession( $handle, 'next' ); 525 $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $ url_link ) );545 $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $next_url_link ) ); 526 546 $vtp->setGlobalVar( $handle, 'next.title', $next_title ); 527 $vtp->setGlobalVar( $handle, 'next.src', $ lien_thumbnail );528 $vtp->setGlobalVar( $handle, 'next.alt', $ alt_thumbnail );547 $vtp->setGlobalVar( $handle, 'next.src', $next_lien_thumbnail ); 548 $vtp->setGlobalVar( $handle, 'next.alt', $next_alt_thumbnail ); 529 549 $vtp->closeSession( $handle, 'next' ); 530 // slideshow 531 if ( isset( $_GET['slideshow'] ) ) 532 { 533 $vtp->addSession( $handle, 'refresh' ); 534 $vtp->setVar( $handle, 'refresh.time', $_GET['slideshow'] ); 535 $url = $url_link.'&slideshow='.$_GET['slideshow']; 536 $vtp->setVar( $handle, 'refresh.url', add_session_id( $url ) ); 537 $vtp->closeSession( $handle, 'refresh' ); 538 } 539 } 540 else 541 { 542 $vtp->addSession( $handle, 'previous_empty' ); 543 $vtp->closeSession( $handle, 'previous_empty' ); 550 } 551 else 552 { 553 $vtp->addSession( $handle, 'next_empty' ); 554 $vtp->closeSession( $handle, 'next_empty' ); 544 555 } 545 556 //---------------------------------------------------- users's comments display … … 577 588 // anti-flood system 578 589 $reference_date = time() - $conf['anti-flood_time']; 579 $query = 'SELECT id'; 580 $query.= ' FROM '.PREFIX_TABLE.'comments'; 590 $query = 'SELECT id FROM '.COMMENTS_TABLE; 581 591 $query.= ' WHERE date > '.$reference_date; 582 592 $query.= " AND author = '".$author."'"; … … 585 595 or $conf['anti-flood_time'] == 0 ) 586 596 { 587 $query = 'INSERT INTO '. PREFIX_TABLE.'comments';597 $query = 'INSERT INTO '.COMMENTS_TABLE; 588 598 $query.= ' (author,date,image_id,content,validated) VALUES'; 589 599 $query.= ' ('; … … 632 642 and $user['status'] == 'admin' ) 633 643 { 634 $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; 635 $query.= ' WHERE id = '.$_GET['del'].';'; 644 $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';'; 636 645 mysql_query( $query ); 637 646 } 638 647 // number of comment for this picture 639 648 $query = 'SELECT COUNT(*) AS nb_comments'; 640 $query.= ' FROM '.PREFIX_TABLE.'comments'; 641 $query.= ' WHERE image_id = '.$page['id']; 649 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['id']; 642 650 $query.= " AND validated = 'true'"; 643 651 $query.= ';'; … … 646 654 // navigation bar creation 647 655 $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; 648 $url.= '&expand='.$_GET['expand']; 656 if (isset($_GET['expand'])) 657 $url.= '&expand='.$_GET['expand']; 649 658 if ( $page['cat'] == 'search' ) 650 659 { … … 670 679 671 680 $query = 'SELECT id,author,date,image_id,content'; 672 $query.= ' FROM '.PREFIX_TABLE.'comments'; 673 $query.= ' WHERE image_id = '.$page['id']; 681 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['id']; 674 682 $query.= " AND validated = 'true'"; 675 683 $query.= ' ORDER BY date ASC'; … … 724 732 { 725 733 $vtp->addSession( $handle, 'author_known' ); 726 $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] ); 734 if (isset($user['pseudo'])) 735 $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] ); 727 736 $vtp->closeSession( $handle, 'author_known' ); 728 737 } … … 742 751 $code = $vtp->Display( $handle, 0 ); 743 752 echo $code; 753 754 include('include/page_tail.php'); 744 755 ?>
Note: See TracChangeset
for help on using the changeset viewer.