Changeset 465
- Timestamp:
- Aug 5, 2004, 7:31:36 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r454 r465 43 43 //-------------------------------------------------------------- initialization 44 44 initialize_category( 'picture' ); 45 46 // if this image_id doesn't correspond to this category, an error message is47 // displayed, and execution is stopped48 if ( 0 )49 {50 echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';51 echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';52 echo $lang['thumbnails'].'</a></div>';53 exit();54 }55 56 45 // retrieving the number of the picture in its category (in order) 57 46 $query = ' … … 64 53 $result = mysql_query( $query ); 65 54 $page['num'] = 0; 66 $row = mysql_fetch_array( $result ); 67 while ( $row['id'] != $_GET['image_id'] ) 68 { 55 $belongs = false; 56 while ($row = mysql_fetch_array($result)) 57 { 58 if ($row['id'] == $_GET['image_id']) 59 { 60 $belongs = true; 61 break; 62 } 69 63 $page['num']++; 70 $row = mysql_fetch_array( $result ); 71 } 72 64 } 65 // if this image_id doesn't correspond to this category, an error message is 66 // displayed, and execution is stopped 67 if (!$belongs) 68 { 69 echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; 70 echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">'; 71 echo $lang['thumbnails'].'</a></div>'; 72 exit(); 73 } 73 74 //------------------------------------- prev, current & next picture management 74 75 $picture = array(); 75 $picture['prev']['name'] = ''; 76 $picture['next']['name'] = ''; 77 $picture['prev']['thumbnail'] = ''; 78 $picture['next']['thumbnail'] = ''; 79 $picture['prev']['url'] = ''; 80 $picture['next']['url'] = ''; 81 82 $next = $page['num'] + 1; 83 $prev = $page['num'] - 1; 84 85 if ( $page['num'] == $page['cat_nb_images'] - 1 ) 86 { 87 $next = 0; 76 77 if ($page['num'] == 0) 78 { 79 $has_prev = false; 80 } 81 else 82 { 83 $has_prev = true; 84 } 85 86 if ($page['num'] == $page['cat_nb_images'] - 1) 87 { 88 $has_next = false; 89 } 90 else 91 { 92 $has_next = true; 88 93 } 89 94 … … 96 101 '; 97 102 98 if ( $prev < 0)103 if ( !$has_prev ) 99 104 { 100 105 $query.= ' LIMIT 0,2'; … … 102 107 else 103 108 { 104 $query.= ' LIMIT '. $prev.',3';109 $query.= ' LIMIT '.($page['num'] - 1).',3'; 105 110 } 106 111 $query.= ';'; 107 112 108 113 $result = mysql_query( $query ); 109 $nb_row = mysql_num_rows( $result ); 110 $index = array('prev','current','next'); 111 112 for ( $i = 0; $i < $nb_row; $i++ ) 113 { 114 $j=($prev<0)?$index[$i+1]:$index[$i]; 114 $indexes = array('prev', 'current', 'next'); 115 116 foreach (array('prev', 'current', 'next') as $i) 117 { 118 if ($i == 'prev' and !$has_prev) 119 { 120 continue; 121 } 122 if ($i == 'next' and !$has_next) 123 { 124 break; 125 } 126 115 127 $row = mysql_fetch_array($result); 116 $picture[$j] = $row; 128 foreach (array_keys($row) as $key) 129 { 130 if (!is_numeric($key)) 131 { 132 $picture[$i][$key] = $row[$key]; 133 } 134 } 135 136 $picture[$i]['is_picture'] = false; 137 if (in_array(get_extension($row['file']), $conf['picture_ext'])) 138 { 139 $picture[$i]['is_picture'] = true; 140 } 117 141 118 142 if ( !isset($array_cat_directories[$row['storage_category_id']])) … … 122 146 } 123 147 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 124 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); 125 126 $picture[$j]['src'] = $cat_directory.$row['file']; 127 128 $picture[$j]['thumbnail'] = $cat_directory.'thumbnail/'; 129 $picture[$j]['thumbnail'].= $conf['prefix_thumbnail'].$file; 130 $picture[$j]['thumbnail'].= '.'.$row['tn_ext']; 148 $file_wo_ext = get_filename_wo_extension($row['file']); 149 150 $icon = './template/'.$user['template'].'/mimetypes/'; 151 $icon.= strtolower(get_extension($row['file'])).'.png'; 152 153 if (isset($row['representative_ext']) and $row['representative_ext'] =! '') 154 { 155 $picture[$i]['src'] = $cat_directory.'representative/'; 156 $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext']; 157 } 158 else 159 { 160 $picture[$i]['src'] = $icon; 161 } 162 // special case for picture files 163 if ($picture[$i]['is_picture']) 164 { 165 $picture[$i]['src'] = $cat_directory.$row['file']; 166 } 167 168 // if picture is not a file, we need the download link 169 if (!$picture[$i]['is_picture']) 170 { 171 $picture[$i]['download'] = $cat_directory.$row['file']; 172 } 173 174 if (isset($row['tn_ext']) and $row['tn_ext'] != '') 175 { 176 $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/'; 177 $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext; 178 $picture[$i]['thumbnail'].= '.'.$row['tn_ext']; 179 } 180 else 181 { 182 $picture[$i]['thumbnail'] = $icon; 183 } 131 184 132 185 if ( !empty( $row['name'] ) ) 133 186 { 134 $picture[$ j]['name'] = $row['name'];187 $picture[$i]['name'] = $row['name']; 135 188 } 136 189 else 137 190 { 138 $picture[$ j]['name'] = str_replace( '_', ' ', $file);139 } 140 141 $picture[$ j]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];142 $picture[$ j]['url'].= '&cat='.$page['cat'];191 $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); 192 } 193 194 $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; 195 $picture[$i]['url'].= '&cat='.$page['cat']; 143 196 if ( $page['cat'] == 'search' ) 144 197 { 145 $picture[$ j]['url'].= '&search='.$_GET['search'];198 $picture[$i]['url'].= '&search='.$_GET['search']; 146 199 } 147 200 } … … 177 230 if ( !$_GET['add_fav'] and $page['cat'] == 'fav' ) 178 231 { 179 if ( $prev < 0 and $nb_row == 1)232 if (!$has_prev and $mysql_num_rows == 1) 180 233 { 181 234 // there is no favorite picture anymore we redirect the user to the … … 184 237 redirect( $url ); 185 238 } 186 else if ( $prev < 0)239 else if (!$has_prev) 187 240 { 188 241 $url = str_replace( '&', '&', $picture['next']['url'] ); … … 333 386 'PHOTO' => $title_nb, 334 387 'TITLE' => $picture['current']['name'], 335 'PREV_TITLE_IMG' => $picture['prev']['name'],336 'NEXT_TITLE_IMG' => $picture['next']['name'],337 'PREV_IMG' => $picture['prev']['thumbnail'],338 'NEXT_IMG' => $picture['next']['thumbnail'],339 388 'SRC_IMG' => $picture['current']['src'], 340 389 'ALT_IMG' => $picture['current']['file'], 341 390 'WIDTH_IMG' => $picture_size[0], 342 391 'HEIGHT_IMG' => $picture_size[1], 343 'COMMENT_IMG' => $picture['current']['comment'],344 392 345 393 'L_SLIDESHOW' => $lang['slideshow'], … … 356 404 'L_AUTHOR' =>$lang['author'], 357 405 'L_COMMENT' =>$lang['comment'], 406 'L_DOWNLOAD' => $lang['download'], 407 'L_DOWNLOAD_HINT' => $lang['download_hint'], 358 408 359 409 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', 360 410 361 'U_PREV_IMG' => add_session_id($picture['prev']['url']),362 'U_NEXT_IMG' => add_session_id($picture['next']['url']),363 411 'U_HOME' => add_session_id($url_home), 364 412 'U_ADMIN' => add_session_id($url_admin), … … 388 436 } 389 437 390 if ($prev>=0) $template->assign_block_vars('previous', array()); 391 if ($next) $template->assign_block_vars('next', array()); 438 if ($has_prev) 439 { 440 $template->assign_block_vars( 441 'previous', 442 array( 443 'TITLE_IMG' => $picture['prev']['name'], 444 'IMG' => $picture['prev']['thumbnail'], 445 'U_IMG' => add_session_id($picture['prev']['url']) 446 )); 447 } 448 449 if ($has_next) 450 { 451 $template->assign_block_vars( 452 'next', 453 array( 454 'TITLE_IMG' => $picture['next']['name'], 455 'IMG' => $picture['next']['thumbnail'], 456 'U_IMG' => add_session_id($picture['next']['url']) 457 )); 458 } 392 459 393 460 //--------------------------------------------------------- picture information 394 461 // legend 395 if ( !empty($picture['current']['comment']) ) 396 { 397 $template->assign_block_vars('legend', array()); 462 if (isset($picture['current']['comment']) 463 and !empty($picture['current']['comment'])) 464 { 465 $template->assign_block_vars( 466 'legend', 467 array( 468 'COMMENT_IMG' => $picture['current']['comment'] 469 )); 470 } 471 // download link if file is not a picture 472 if (!$picture['current']['is_picture']) 473 { 474 $template->assign_block_vars( 475 'download', 476 array( 477 'U_DOWNLOAD' => $picture['current']['download'] 478 )); 398 479 } 399 480 … … 401 482 if ( !empty($picture['current']['author']) ) 402 483 { 403 $template->assign_block_vars('info_line', array( 404 'INFO'=>$lang['author'], 405 'VALUE'=>$picture['current']['author'] 406 )); 484 $template->assign_block_vars( 485 'info_line', 486 array( 487 'INFO'=>$lang['author'], 488 'VALUE'=>$picture['current']['author'] 489 )); 407 490 } 408 491 // creation date … … 420 503 )); 421 504 // size in pixels 422 if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] ) 423 { 424 $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">'; 425 $content.= $original_width.'*'.$original_height.'</a> ]'; 426 } 427 else 428 { 429 $content = $original_width.'*'.$original_height; 430 } 431 $template->assign_block_vars('info_line', array( 432 'INFO'=>$lang['size'], 433 'VALUE'=>$content 434 )); 505 if ($picture['current']['is_picture']) 506 { 507 if ($original_width != $picture_size[0] 508 or $original_height != $picture_size[1]) 509 { 510 $content = '[ <a href="'.$picture['current']['url'].'" '; 511 $content.= ' title="'.$lang['true_size'].'">'; 512 $content.= $original_width.'*'.$original_height.'</a> ]'; 513 } 514 else 515 { 516 $content = $original_width.'*'.$original_height; 517 } 518 $template->assign_block_vars( 519 'info_line', 520 array( 521 'INFO'=>$lang['size'], 522 'VALUE'=>$content 523 )); 524 } 435 525 // file 436 526 $template->assign_block_vars('info_line', array(
Note: See TracChangeset
for help on using the changeset viewer.