Changeset 1036 for trunk/picture.php
- Timestamp:
- Feb 12, 2006, 10:52:16 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r1029 r1036 31 31 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 32 32 //-------------------------------------------------- access authorization check 33 check_cat_id( $_GET['cat'] ); 34 35 if (!isset($page['cat'])) 36 { 37 die($lang['access_forbiden']); 38 } 39 40 check_login_authorization(); 41 if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) 42 { 43 check_restrictions( $page['cat'] ); 44 } 33 if (isset($page['cat']) and is_numeric($page['cat'])) 34 { 35 check_restrictions($page['cat']); 36 } 37 //-------------------------------------------------------------- initialization 38 include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); 39 40 // if this image_id doesn't correspond to this category, an error message is 41 // displayed, and execution is stopped 42 if (!in_array($_GET['image_id'], $page['items'])) 43 { 44 echo ' 45 <div style="text-align:center;">'.$lang['access_forbiden'].'<br /> 46 <a href="'.PHPWG_ROOT_PATH.'category.php'.'">'.$lang['thumbnails'].'</a> 47 </div>'; 48 exit(); 49 } 50 51 $page['rank_of'] = array_flip($page['items']); 52 53 // caching first_rank, last_rank, current_rank in the displayed 54 // section. This should also help in readability. 55 $page['first_rank'] = 0; 56 $page['last_rank'] = count($page['items']) - 1; 57 $page['current_rank'] = $page['rank_of'][ $_GET['image_id'] ]; 58 59 // caching current item : readability purpose 60 $page['current_item'] = $_GET['image_id']; 61 62 if ($page['current_rank'] != $page['first_rank']) 63 { 64 // "go to first picture of this section" link is displayed only if the 65 // displayed item is not the first. 66 $template->assign_block_vars( 67 'first', 68 array( 69 'U_IMG' => 70 PHPWG_ROOT_PATH.'picture.php'. 71 get_query_string_diff( 72 array('image_id', 'add_fav', 'slideshow', 'rate') 73 ). 74 '&image_id='.$page['items'][ $page['first_rank'] ], 75 ) 76 ); 77 78 // caching previous item : readability purpose 79 $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ]; 80 } 81 82 if ($page['current_rank'] != $page['last_rank']) 83 { 84 // "go to last picture of this section" link is displayed only if the 85 // displayed item is not the last. 86 $template->assign_block_vars( 87 'last', 88 array( 89 'U_IMG' => 90 PHPWG_ROOT_PATH.'picture.php'. 91 get_query_string_diff( 92 array('image_id', 'add_fav', 'slideshow', 'rate') 93 ). 94 '&image_id='.$page['items'][ $page['last_rank'] ], 95 ) 96 ); 97 98 // caching next item : readability purpose 99 $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ]; 100 } 101 45 102 //---------------------------------------- incrementation of the number of hits 46 103 if ( count(array_intersect( … … 56 113 @pwg_query( $query ); 57 114 } 58 //-------------------------------------------------------------- initialization 59 initialize_category( 'picture' ); 60 // retrieving the number of the picture in its category (in order) 61 $query = ' 62 SELECT DISTINCT(id) 63 FROM '.IMAGES_TABLE.' 64 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 65 '.$page['where'].' 66 '.$conf['order_by'].' 67 ;'; 68 $result = pwg_query( $query ); 69 $page['num'] = 0; 70 $belongs = false; 71 while ($row = mysql_fetch_array($result)) 72 { 73 if ($row['id'] == $_GET['image_id']) 74 { 75 $belongs = true; 76 break; 77 } 78 if ($page['num']==0) 79 { 80 $url_first_last = PHPWG_ROOT_PATH.'picture.php'; 81 $url_first_last.= get_query_string_diff(array('image_id','add_fav', 82 'slideshow','rate')); 83 $url_first_last.= '&image_id='; 84 $template->assign_block_vars( 85 'first', 86 array( 87 'U_IMG' => $url_first_last . $row['id'], 88 )); 89 } 90 $page['num']++; 91 } 92 if ($page['cat_nb_images']>0 and $page['num'] < $page['cat_nb_images'] - 1) 93 { 94 mysql_data_seek($result, $page['cat_nb_images'] - 1); 95 $row = mysql_fetch_array($result); 96 $url_first_last = PHPWG_ROOT_PATH.'picture.php'; 97 $url_first_last.= get_query_string_diff(array('image_id','add_fav', 98 'slideshow','rate')); 99 $url_first_last.= '&image_id='; 100 $template->assign_block_vars( 101 'last', 102 array( 103 'U_IMG' => $url_first_last . $row['id'], 104 )); 105 } 106 107 // if this image_id doesn't correspond to this category, an error message is 108 // displayed, and execution is stopped 109 if (!$belongs) 110 { 111 echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; 112 echo '<a href="'.PHPWG_ROOT_PATH.'category.php'.'">'; 113 echo $lang['thumbnails'].'</a></div>'; 114 exit(); 115 } 115 116 116 //-------------------------------------------------------------- representative 117 117 if ('admin' == $user['status'] and isset($_GET['representative'])) … … 162 162 $picture = array(); 163 163 164 if ($page['num'] == 0) 165 { 166 $has_prev = false; 167 } 168 else 169 { 170 $has_prev = true; 171 } 172 173 if ($page['num'] == $page['cat_nb_images'] - 1) 174 { 175 $has_next = false; 176 } 177 else 178 { 179 $has_next = true; 164 $ids = array($_GET['image_id']); 165 if (isset($page['previous_item'])) 166 { 167 array_push($ids, $page['previous_item']); 168 } 169 if (isset($page['next_item'])) 170 { 171 array_push($ids, $page['next_item']); 180 172 } 181 173 182 174 $query = ' 183 SELECT DISTINCT(i.id), i.* 184 FROM '.IMAGES_TABLE.' AS i 185 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id 186 '.$page['where'].' 187 '.$conf['order_by'].' 188 '; 189 190 if ( !$has_prev ) 191 { 192 $query.= ' LIMIT 0,2'; 193 } 194 else 195 { 196 $query.= ' LIMIT '.($page['num'] - 1).',3'; 197 } 198 $query.= ';'; 199 200 $result = pwg_query( $query ); 201 $indexes = array('prev', 'current', 'next'); 202 203 foreach (array('prev', 'current', 'next') as $i) 204 { 205 if ($i == 'prev' and !$has_prev) 206 { 207 continue; 208 } 209 if ($i == 'next' and !$has_next) 210 { 211 break; 212 } 213 214 $row = mysql_fetch_array($result); 175 SELECT * 176 FROM '.IMAGES_TABLE.' 177 WHERE id IN ('.implode(',', $ids).') 178 ;'; 179 180 $result = pwg_query($query); 181 182 while ($row = mysql_fetch_array($result)) 183 { 184 if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) 185 { 186 $i = 'prev'; 187 } 188 else if (isset($page['next_item']) and $row['id'] == $page['next_item']) 189 { 190 $i = 'next'; 191 } 192 else 193 { 194 $i = 'current'; 195 } 196 215 197 foreach (array_keys($row) as $key) 216 198 { … … 235 217 if (isset($row['representative_ext']) and $row['representative_ext'] != '') 236 218 { 237 $picture[$i]['src'] = $cat_directory.'/pwg_representative/'; 238 $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext']; 219 $picture[$i]['src'] = 220 $cat_directory.'/pwg_representative/' 221 .$file_wo_ext.'.'.$row['representative_ext']; 239 222 } 240 223 else … … 275 258 } 276 259 277 $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php';278 $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav',279 'slideshow','rate'));280 $picture[$i]['url'].='&image_id='.$row['id'];260 $picture[$i]['url'] = 261 PHPWG_ROOT_PATH.'picture.php' 262 .get_query_string_diff(array('image_id', 'add_fav', 'slideshow', 'rate')) 263 .'&image_id='.$row['id']; 281 264 } 282 265 283 266 $url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat']; 284 $url_up_start = floor( $page['num'] / $user['nb_image_page'] ); 267 268 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] ); 285 269 $url_up_start *= $user['nb_image_page']; 286 270 if ($url_up_start>0) … … 298 282 } 299 283 300 $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; 301 $url_admin.= '&cat_id='.$page['cat']; 302 $url_admin.= '&image_id='.$_GET['image_id']; 303 304 $url_slide = $picture['current']['url']; 305 $url_slide.= '&slideshow='.$conf['slideshow_period']; 284 $url_admin = 285 PHPWG_ROOT_PATH.'admin.php?page=picture_modify' 286 .'&cat_id='.$page['cat'] 287 .'&image_id='.$_GET['image_id']; 288 289 $url_slide = 290 $picture['current']['url'].'&slideshow='.$conf['slideshow_period']; 306 291 307 292 //----------------------------------------------------------- rate registration … … 485 470 { 486 471 $title_img = replace_space(get_cat_display_name($page['cat_name'])); 487 $n = $page[' num'] + 1;472 $n = $page['current_rank'] + 1; 488 473 $title_nb = $n.'/'.$page['cat_nb_images']; 489 474 } … … 527 512 528 513 $page['body_id'] = 'thePicturePage'; 529 //------------------------------------------------------- -navigation management530 if ( $has_prev)514 //------------------------------------------------------- navigation management 515 if (isset($page['previous_item'])) 531 516 { 532 517 $template->assign_block_vars( … … 537 522 'U_IMG' => $picture['prev']['url'], 538 523 'U_IMG_SRC' => $picture['prev']['src'] 539 )); 540 } 541 542 if ($has_next) 524 ) 525 ); 526 } 527 528 if (isset($page['next_item'])) 543 529 { 544 530 $template->assign_block_vars( … … 549 535 'U_IMG' => $picture['next']['url'], 550 536 'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload 551 )); 537 ) 538 ); 552 539 } 553 540
Note: See TracChangeset
for help on using the changeset viewer.