Changeset 368
- Timestamp:
- Feb 21, 2004, 12:02:06 PM (20 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/picture.php
r364 r368 42 42 //-------------------------------------------------------------- initialization 43 43 initialize_category( 'picture' ); 44 //------------------------------------- main picture information initialization 45 $infos = array( 'id','date_available','comment','hit','keywords','author' 46 ,'name','file','date_creation','filesize','width','height' 47 ,'storage_category_id' ); 48 49 $query = 'SELECT '.implode( ',', $infos ); 50 if ( is_numeric( $page['cat'] ) ) $query.= ',category_id'; 51 $query.= ' FROM '.IMAGES_TABLE; 52 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 53 $query.= ' ON id = ic.image_id'; 54 $query.= $page['where']; 55 $query.= ' AND id = '.$_GET['image_id']; 56 $query.= $conf['order_by']; 57 $query.= ';'; 58 $result = mysql_query( $query ); 44 59 45 // if this image_id doesn't correspond to this category, an error message is 60 46 // displayed, and execution is stopped 61 if ( mysql_num_rows( $result ) ==0 )47 if ( 0 ) 62 48 { 63 49 echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; … … 66 52 exit(); 67 53 } 68 $row = mysql_fetch_array( $result ); 69 70 foreach ( $infos as $info ) { 71 if ( isset( $row[$info] ) ) $page[$info] = $row[$info]; 72 else $page[$info] = ''; 73 } 74 if ( is_numeric( $page['cat'] ) ) $page['category_id'] = $row['category_id']; 54 75 55 // retrieving the number of the picture in its category (in order) 76 56 $query = 'SELECT DISTINCT(id)'; … … 84 64 $page['num'] = 0; 85 65 $row = mysql_fetch_array( $result ); 86 while ( $row['id'] != $ page['id'] )66 while ( $row['id'] != $_GET['image_id'] ) 87 67 { 88 68 $page['num']++; 89 69 $row = mysql_fetch_array( $result ); 90 70 } 71 72 //---------------------------------------- prev, current & next picture management 73 $picture=array(); 74 $picture['prev']['name']=''; 75 $picture['next']['name']=''; 76 $picture['prev']['thumbnail']=''; 77 $picture['next']['thumbnail']=''; 78 $picture['prev']['url']=''; 79 $picture['next']['url']=''; 80 81 $next = $page['num'] + 1; 82 $prev = $page['num'] - 1; 83 84 if ( $page['num'] == $page['cat_nb_images']-1) 85 { 86 $next = 0; 87 } 88 89 $query = 'SELECT * FROM '.IMAGES_TABLE; 90 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 91 $query.= ' ON id=ic.image_id'; 92 $query.= $page['where']; 93 $query.= $conf['order_by']; 94 95 if ($prev <0) 96 $query.= ' LIMIT 0,2'; 97 else 98 $query.= ' LIMIT '.$prev.',3'; 99 100 $query.= ';'; 101 102 $result = mysql_query( $query ); 103 $nb_row = mysql_num_rows($result); 104 $index = array('prev','current','next'); 105 for ($i=0; $i<$nb_row;$i++) 106 { 107 $j=($prev<0)?$index[$i+1]:$index[$i]; 108 $row = mysql_fetch_array($result); 109 $picture[$j] = $row; 110 111 if ( !isset($array_cat_directories[$row['storage_category_id']])) 112 { 113 $array_cat_directories[$row['storage_category_id']] = 114 get_complete_dir( $row['storage_category_id'] ); 115 } 116 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 117 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); 118 $picture[$j]['src'] = $cat_directory.$row['file']; 119 $picture[$j]['thumbnail'] = $cat_directory.'thumbnail/'; 120 $picture[$j]['thumbnail'].= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 121 122 if (!empty($row['name'])) 123 { 124 $picture[$j]['name'] = $row['name']; 125 } 126 else 127 { 128 $picture[$j]['name'] = str_replace( "_", " ",$file); 129 } 130 131 $picture[$j]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; 132 $picture[$j]['url'].= '&cat='.$page['cat']; 133 if ( isset( $_GET['expand'] ) ) 134 $picture[$j]['url'].= '&expand='.$_GET['expand']; 135 if ( $page['cat'] == 'search' ) 136 { 137 $picture[$j]['url'].= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 138 } 139 } 140 141 $url_home = './category.php?cat='.$page['cat'].'&'; 142 $url_home.= 'num='.$page['num']; 143 if (isset($_GET['expand'])) 144 $url_home.='&expand='.$_GET['expand']; 145 if ( $page['cat'] == 'search' ) 146 { 147 $url_home.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 148 } 149 150 $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify&cat_id='.$page['cat']; 151 $url_admin.= '&image_id='.$_GET['image_id']; 152 91 153 //--------------------------------------------------------- favorite management 92 154 if ( isset( $_GET['add_fav'] ) ) 93 155 { 156 $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id']; 157 $query.= ' AND image_id = '.$picture['current']['id'].';'; 158 $result = mysql_query( $query ); 159 94 160 if ( $_GET['add_fav'] == 1 ) 95 161 { 96 // verify if the picture is already in the favorite of the user 97 $query = 'SELECT COUNT(*) AS nb_fav'; 98 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$page['id']; 99 $query.= ' AND user_id = '.$user['id']; 100 $query.= ';'; 101 $result = mysql_query( $query ); 102 $row = mysql_fetch_array( $result ); 103 if ( $row['nb_fav'] == 0 ) 104 { 105 $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES'; 106 $query.= ' ('.$page['id'].','.$user['id'].')'; 107 $query.= ';'; 108 $result = mysql_query( $query ); 109 } 110 } 111 if ( $_GET['add_fav'] == 0 ) 112 { 113 $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id']; 114 $query.= ' AND image_id = '.$page['id']; 115 $query.= ';'; 116 $result = mysql_query( $query ); 117 118 $page['cat_nb_images'] = $page['cat_nb_images'] - 1; 119 if ( $page['cat_nb_images'] <= 0 ) 162 $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES'; 163 $query.= ' ('.$picture['current']['id'].','.$user['id'].');'; 164 $result = mysql_query( $query ); 165 } 166 if ( !$_GET['add_fav'] && $page['cat']=='fav') 167 { 168 if ( $prev < 0 && $nb_row==1 ) 120 169 { 121 170 // there is no favorite picture anymore 122 171 // we redirect the user to the category page 123 $url = add_session_id( 'category.php');172 $url = add_session_id( $url_home ); 124 173 header( 'Request-URI: '.$url ); 125 174 header( 'Content-Location: '.$url ); … … 127 176 exit(); 128 177 } 129 // redirection of the user to the picture.php page 130 // with the right picture 131 $page['num'] = $page['num'] - 1; 132 if ( $page['num'] == -1 ) 133 { 134 $page['num'] = 0; 135 } 136 $query = 'SELECT id'; 137 $query.= ' FROM '.IMAGES_TABLE; 138 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 139 $query.= ' ON id = ic.image_id'; 140 $query.= $page['where']; 141 $query.= $conf['order_by']; 142 $query.= ' LIMIT '.$page['num'].',1'; 143 $query.= ';'; 144 $result = mysql_query( $query ); 145 $row = mysql_fetch_array( $result ); 146 $redirect = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; 147 $redirect.= '&expand='.$_GET['expand']; 148 if ( $page['cat'] == 'search' ) 149 { 150 $redirect.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 151 } 152 $url = add_session_id( $redirect, true ); 153 header( 'Request-URI: '.$url ); 154 header( 'Content-Location: '.$url ); 155 header( 'Location: '.$url ); 156 exit(); 157 } 158 } 159 160 //---------------------------------------------- next picture thumbnail display 161 $next = 0; 162 if ( $page['num'] < $page['cat_nb_images']-1 ) 163 { 164 $next = $page['num'] + 1; 165 $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; 166 $query.= ' FROM '.IMAGES_TABLE; 167 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 168 $query.= ' ON id=ic.image_id'; 169 $query.= $page['where']; 170 $query.= $conf['order_by']; 171 $query.= ' LIMIT '.$next.',1'; 172 $query.= ';'; 173 $result = mysql_query( $query ); 174 $row = mysql_fetch_array( $result ); 175 176 if ( !isset($array_cat_directories[$row['storage_category_id']])) 177 { 178 $array_cat_directories[$row['storage_category_id']] = 179 get_complete_dir( $row['storage_category_id'] ); 180 } 181 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 182 183 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); 184 $next_lien_thumbnail = $cat_directory.'thumbnail/'; 185 $next_lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 186 187 if ( isset( $row['name'] ) and $row['name'] != '' ) 188 { 189 $next_alt_thumbnail = $row['name']; 190 } 191 else 192 { 193 $next_alt_thumbnail = $file; 194 } 195 $next_title = $lang['next_image']." : ".$next_alt_thumbnail; 196 197 $next_url_link = './picture.php?image_id='.$row['id']; 198 $next_url_link.= '&cat='.$page['cat']; 199 if ( isset( $_GET['expand'] ) ) 200 $next_url_link.= '&expand='.$_GET['expand']; 201 if ( $page['cat'] == 'search' ) 202 { 203 $next_url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 204 } 205 } 206 //----------------------------------------------------- template initialization 178 else if ( $prev < 0 ) 179 { 180 $url = add_session_id( str_replace('&','&',$picture['next']['url']), true); 181 } 182 else 183 { 184 $url = add_session_id( str_replace('&','&',$picture['prev']['url']), true); 185 } 186 header( 'Request-URI: '.$url ); 187 header( 'Content-Location: '.$url ); 188 header( 'Location: '.$url ); 189 exit(); 190 } 191 } 192 207 193 // 208 194 // Start output of page 209 195 // 210 //------------------------------------------------------------------ page title 211 $title = $page['name']; 212 if ( $title == '') 213 { 214 $title = str_replace("_"," ",get_filename_wo_extension($page['file'])); 215 } 196 197 $title = $picture['current']['name']; 216 198 $refresh = 0; 217 if ( isset( $_GET['slideshow'] ) && isset($next_url_link))199 if ( isset( $_GET['slideshow'] ) && $next) 218 200 { 219 201 $refresh= $_GET['slideshow']; 220 $url_link = $next_url_link; 221 } 222 include('include/page_header.php'); 223 224 $handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' ); 225 initialize_template(); 226 227 $tpl = array( 'back','submit','comments_title','comments_del','delete', 228 'comments_add','author','slideshow','slideshow_stop', 229 'period_seconds' ); 230 templatize_array( $tpl, 'lang', $handle ); 231 //-------------------------------------------------------- slideshow management 232 if ( isset( $_GET['slideshow'] ) ) 233 { 234 if ( !is_numeric( $_GET['slideshow'] ) ) 235 $_GET['slideshow'] = $conf['slideshow_period'][0]; 236 $vtp->addSession( $handle, 'stop_slideshow' ); 237 $url = './picture.php'; 238 $url.= '?image_id='.$page['id']; 239 $url.= '&cat='.$page['cat']; 240 $url.= '&expand='.$_GET['expand']; 241 if ( $page['cat'] == 'search' ) 242 { 243 $url.= '&search='.$_GET['search']; 244 $url.= '&mode='.$_GET['mode']; 245 } 246 $vtp->setVar( $handle, 'stop_slideshow.url', add_session_id( $url ) ); 247 $vtp->closeSession( $handle, 'stop_slideshow' ); 248 } 249 else 250 { 251 $vtp->addSession( $handle, 'start_slideshow' ); 252 foreach ( $conf['slideshow_period'] as $option ) { 253 $vtp->addSession( $handle, 'second' ); 254 $vtp->setVar( $handle, 'second.option', $option ); 255 $url = './picture.php'; 256 $url.= '?image_id='.$page['id']; 257 $url.= '&cat='.$page['cat']; 258 if (isset($_GET['expand'])) 259 $url.= '&expand='.$_GET['expand']; 260 if ( $page['cat'] == 'search' ) 261 { 262 $url.= '&search='.$_GET['search']; 263 $url.= '&mode='.$_GET['mode']; 264 } 265 $url.= '&slideshow='.$option; 266 $vtp->setVar( $handle, 'second.url', add_session_id( $url ) ); 267 $vtp->closeSession( $handle, 'second' ); 268 } 269 $vtp->closeSession( $handle, 'start_slideshow' ); 270 } 271 272 //-------------------------------------------------- previous picture thumbnail 273 if ( $page['num'] >= 1 ) 274 { 275 $prev = $page['num'] - 1; 276 $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; 277 $query.= ' FROM '.IMAGES_TABLE; 278 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; 279 $query.= ' ON id=ic.image_id'; 280 $query.= $page['where']; 281 $query.= $conf['order_by']; 282 $query.= ' LIMIT '.$prev.',1'; 283 $query.= ';'; 284 $result = mysql_query( $query ); 285 $row = mysql_fetch_array( $result ); 286 287 if ( !isset($array_cat_directories[$row['storage_category_id']]) ) 288 { 289 $array_cat_directories[$row['storage_category_id']] = 290 get_complete_dir( $row['storage_category_id'] ); 291 } 292 $cat_directory = $array_cat_directories[$row['storage_category_id']]; 293 294 $file = substr( $row['file'], 0, strrpos ( $row['file'], '.' ) ); 295 $lien_thumbnail = $cat_directory.'thumbnail/'; 296 $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; 297 298 $prev_title = $lang['previous_image'].' : '; 299 300 if ( isset( $row['name'] ) and $row['name'] != '' ) 301 $alt_thumbnail = $row['name']; 302 else 303 $alt_thumbnail = $file; 304 305 $prev_title.= $alt_thumbnail; 306 307 $url_link = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; 308 if ( isset( $_GET['expand'] ) ) $url_link.= '&expand='.$_GET['expand']; 309 if ( $page['cat'] == 'search' ) 310 { 311 $url_link.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 312 } 313 // sending vars for display 314 $vtp->addSession( $handle, 'previous' ); 315 $vtp->setGlobalVar( $handle, 'previous.url', add_session_id( $url_link ) ); 316 $vtp->setGlobalVar( $handle, 'previous.title', $prev_title ); 317 $vtp->setGlobalVar( $handle, 'previous.src', $lien_thumbnail ); 318 $vtp->setGlobalVar( $handle, 'previous.alt', $alt_thumbnail ); 319 $vtp->closeSession( $handle, 'previous' ); 320 } 321 else 322 { 323 $vtp->addSession( $handle, 'previous_empty' ); 324 $vtp->closeSession( $handle, 'previous_empty' ); 325 } 326 //-------------------------------------------------------- main picture display 327 if ( is_numeric( $page['cat'] ) ) 328 { 329 $intitule_cat = get_cat_display_name( $page['cat_name'], " - ", 330 "font-style:italic;" ); 331 } 332 else 333 { 334 $intitule_cat = $page['title']; 335 } 336 337 if ( !isset($array_cat_directories[$page['storage_category_id']]) ) 338 { 339 $array_cat_directories[$page['storage_category_id']] = 340 get_complete_dir( $page['storage_category_id'] ); 341 } 342 $cat_directory = $array_cat_directories[$page['storage_category_id']]; 343 344 $n = $page['num'] + 1; 345 $intitule_titre = replace_space( $intitule_cat." - " ).$n.'/'; 346 $intitule_titre.= $page['cat_nb_images']."<br />"; 347 if ( $page['name'] != "" ) 348 { 349 $intitule_file = $page['name']; 350 } 351 else 352 { 353 $intitule_file = str_replace( "_", " ", 354 substr( $page['file'], 0, 355 strrpos ( $page['file'], ".") ) ); 356 } 357 if ( $page['cat'] == 'search' ) 358 { 359 $intitule_file = replace_search( $intitule_file, $_GET['search'] ); 360 } 361 $vtp->setGlobalVar( $handle, 'title', $intitule_titre.$intitule_file ); 362 363 $lien_image = $cat_directory.$page['file']; 202 $url_link = $picture['next']['url']; 203 } 204 205 $title_img = $picture['current']['name']; 206 if (is_numeric( $page['cat'] )) 207 { 208 $title_img = get_cat_display_name( $page['cat_name'], " - ","font-style:italic;" ); 209 $n = $page['num'] + 1; 210 $title_img = replace_space( $title_img." - " ).$n.'/'; 211 $title_img.= $page['cat_nb_images']."<br />"; 212 $title_img.= $picture['current']['name']; 213 } 214 else if ( $page['cat'] == 'search' ) 215 { 216 $title_img = replace_search( $title_img, $_GET['search'] ); 217 } 364 218 365 219 // calculation of width and height 366 if ( $page['width'] == "")220 if ( empty($picture['current']['width'])) 367 221 { 368 222 $taille_image = @getimagesize( $lien_image ); … … 372 226 else 373 227 { 374 $original_width = $p age['width'];375 $original_height = $p age['height'];228 $original_width = $picture['current']['width']; 229 $original_height = $picture['current']['height']; 376 230 } 377 231 378 232 $picture_size = get_picture_size( $original_width, $original_height, 379 233 $user['maxwidth'], $user['maxheight'] ); 380 $final_width = $picture_size[0]; 381 $final_height = $picture_size[1]; 382 383 $url_link = './category.php?cat='.$page['cat'].'&'; 384 $url_link.= 'num='.$page['num']; 385 if (isset($_GET['expand'])) 386 $url_link.='&expand='.$_GET['expand']; 387 if ( $page['cat'] == 'search' ) 388 { 389 $url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; 390 } 391 $vtp->setGlobalVar( $handle, 'picture_link', add_session_id( $url_link ) ); 392 $vtp->setGlobalVar( $handle, 'picture_width', $final_width ); 393 $vtp->setGlobalVar( $handle, 'picture_height', $final_height ); 394 $vtp->setGlobalVar( $handle, 'picture_src', $lien_image ); 395 $vtp->setGlobalVar( $handle, 'picture_alt', $page['file'] ); 396 397 if ( $page['comment'] != '' ) 398 { 399 if ( $page['cat'] == 'search' ) 400 { 401 $picture_comment = replace_search( $page['comment'], $_GET['search'] ); 402 $vtp->setGlobalVar( $handle, 'picture_comment', $picture_comment ); 403 } 404 else 405 { 406 $vtp->setGlobalVar( $handle, 'picture_comment', $page['comment'] ); 407 } 408 } 234 235 include('include/page_header.php'); 236 $template->set_filenames(array('picture'=>'picture.tpl')); 237 initialize_template(); 238 239 $template->assign_vars(array( 240 'TITLE' => $title_img, 241 'PREV_TITLE_IMG' => $picture['prev']['name'], 242 'NEXT_TITLE_IMG' => $picture['next']['name'], 243 'PREV_IMG' => $picture['prev']['thumbnail'], 244 'NEXT_IMG' => $picture['next']['thumbnail'], 245 'SRC_IMG' => $picture['current']['src'], 246 'ALT_IMG' => $picture['current']['file'], 247 'WIDTH_IMG' => $picture_size[0], 248 'HEIGHT_IMG' => $picture_size[1], 249 'COMMENT_IMG' => $picture['current']['comment'], 250 251 'L_SLIDESHOW' => $lang['slideshow'], 252 'L_TIME' => $lang['period_seconds'], 253 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], 254 'L_PREV_IMG' =>$lang['previous_image'].' : ', 255 'L_ADMIN' =>$lang['link_info_image'], 256 'L_BACK' =>$lang['back'], 257 'L_COMMENT_TITLE' =>$lang['comments_title'], 258 'L_ADD_COMMENT' =>$lang['comments_add'], 259 'L_DELETE_COMMENT' =>$lang['comments_del'], 260 'L_DELETE' =>$lang['delete'], 261 'L_SUBMIT' =>$lang['submit'], 262 'L_AUTHOR' =>$lang['author'], 263 264 'T_DEL_IMG' =>'./template/'.$user['template'].'/theme/delete.gif', 265 266 'U_PREV_IMG' => add_session_id($picture['prev']['url']), 267 'U_NEXT_IMG' => add_session_id($picture['next']['url']), 268 'U_HOME' => add_session_id($url_home), 269 'U_ADMIN' => add_session_id($url_admin), 270 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) 271 ) 272 ); 273 274 //-------------------------------------------------------- slideshow management 275 if ( isset( $_GET['slideshow'] ) ) 276 { 277 if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0]; 278 279 $template->assign_block_vars('stop_slideshow', array( 280 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) 281 )); 282 } 283 else 284 { 285 $template->assign_block_vars('start_slideshow', array()); 286 foreach ( $conf['slideshow_period'] as $option ) 287 { 288 $template->assign_block_vars('start_slideshow.second', array( 289 'SLIDESHOW_SPEED'=>$option, 290 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&slideshow='.$option) 291 )); 292 } 293 } 294 295 if ($prev>=0) $template->assign_block_vars('previous', array()); 296 if ($next) $template->assign_block_vars('next', array()); 297 409 298 //--------------------------------------------------------- picture information 410 299 // author 411 if ( $page['author'] != "")412 { 413 $ vtp->addSession( $handle, 'info_line' );414 $vtp->setVar( $handle, 'info_line.name', $lang['author'].' : ' ); 415 $vtp->setVar( $handle, 'info_line.content', $page['author'] ); 416 $vtp->closeSession( $handle, 'info_line');300 if ( !empty($picture['current']['author']) ) 301 { 302 $template->assign_block_vars('info_line', array( 303 'INFO'=>$lang['author'], 304 'VALUE'=>$picture['current']['author'] 305 )); 417 306 } 418 307 // creation date 419 if ( $page['date_creation'] != "" ) 420 { 421 $vtp->addSession( $handle, 'info_line' ); 422 $vtp->setVar( $handle, 'info_line.name', $lang['creation_date'].' : ' ); 423 $vtp->setVar( $handle, 'info_line.content', 424 format_date( $page['date_creation'] ) ); 425 $vtp->closeSession( $handle, 'info_line' ); 308 if ( !empty($picture['current']['date_creation']) ) 309 { 310 $template->assign_block_vars('info_line', array( 311 'INFO'=>$lang['creation_date'], 312 'VALUE'=>format_date( $picture['current']['date_creation'] ) 313 )); 426 314 } 427 315 // date of availability 428 $vtp->addSession( $handle, 'info_line' ); 429 $vtp->setVar( $handle, 'info_line.name', $lang['registration_date'].' : ' ); 430 list( $year,$month,$day ) = explode( '-', $page['date_available'] ); 431 $vtp->setVar( $handle, 'info_line.content', 432 format_date( $page['date_available'] ) ); 433 $vtp->closeSession( $handle, 'info_line' ); 316 $template->assign_block_vars('info_line', array( 317 'INFO'=>$lang['registration_date'], 318 'VALUE'=>format_date( $picture['current']['date_available'] ) 319 )); 434 320 // size in pixels 435 $vtp->addSession( $handle, 'info_line' ); 436 $vtp->setVar( $handle, 'info_line.name', $lang['size'].' : ' ); 437 if ( $original_width != $final_width or $original_height != $final_height ) 438 { 439 $content = '[ <a href="'.$lien_image.'" title="'.$lang['true_size'].'">'; 321 if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] ) 322 { 323 $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">'; 440 324 $content.= $original_width.'*'.$original_height.'</a> ]'; 441 $vtp->setVar( $handle, 'info_line.content', $content );442 325 } 443 326 else 444 327 { 445 328 $content = $original_width.'*'.$original_height; 446 $vtp->setVar( $handle, 'info_line.content', $content ); 447 } 448 $vtp->closeSession( $handle, 'info_line' ); 329 } 330 $template->assign_block_vars('info_line', array( 331 'INFO'=>$lang['size'], 332 'VALUE'=>$content 333 )); 449 334 // file 450 $vtp->addSession( $handle, 'info_line' ); 451 $vtp->setVar( $handle, 'info_line.name', $lang['file'].' : ' ); 452 if ( $page['cat'] == 'search' ) 453 { 454 $content = replace_search( $page['file'], $_GET['search'] ); 455 $vtp->setVar( $handle, 'info_line.content', $content ); 335 $template->assign_block_vars('info_line', array( 336 'INFO'=>$lang['file'], 337 'VALUE'=>$picture['current']['file'] 338 )); 339 // filesize 340 if ( empty($picture['current']['filesize'])) 341 { 342 $poids = floor ( filesize( $picture['current']['url'] ) / 1024 ); 456 343 } 457 344 else 458 345 { 459 $vtp->setVar( $handle, 'info_line.content', $page['file'] ); 460 } 461 $vtp->closeSession( $handle, 'info_line' ); 462 // filesize 463 if ( $page['filesize'] == "" ) 464 { 465 $poids = floor ( filesize( $lien_image ) / 1024 ); 466 } 467 else 468 { 469 $poids = $page['filesize']; 470 } 471 $vtp->addSession( $handle, 'info_line' ); 472 $vtp->setVar( $handle, 'info_line.name', $lang['filesize'].' : ' ); 473 $vtp->setVar( $handle, 'info_line.content', $poids.' KB' ); 474 $vtp->closeSession( $handle, 'info_line' ); 346 $poids = $picture['current']['filesize']; 347 } 348 349 $template->assign_block_vars('info_line', array( 350 'INFO'=>$lang['filesize'], 351 'VALUE'=>$poids.' KB' 352 )); 475 353 // keywords 476 if ( $page['keywords'] != '' ) 477 { 478 $vtp->addSession( $handle, 'info_line' ); 479 $vtp->setVar( $handle, 'info_line.name', $lang['keywords'].' : ' ); 480 $keywords = explode( ',', $page['keywords'] ); 354 if ( !empty($picture['current']['keywords'])) 355 { 356 $keywords = explode( ',', $picture['current']['keywords'] ); 481 357 $content = ''; 482 358 $url = './category.php?cat=search'; … … 488 364 $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; 489 365 } 490 $vtp->setVar( $handle, 'info_line.content', $content ); 491 $vtp->closeSession( $handle, 'info_line' ); 366 $template->assign_block_vars('info_line', array( 367 'INFO'=>$lang['keywords'], 368 'VALUE'=>$content 369 )); 492 370 } 493 371 // number of visits 494 $vtp->addSession( $handle, 'info_line' ); 495 $vtp->setVar( $handle, 'info_line.name', $lang['visited'].' : ' ); 496 $vtp->setVar( $handle, 'info_line.content', $page['hit'].' '.$lang['times'] ); 497 $vtp->closeSession( $handle, 'info_line' ); 372 $template->assign_block_vars('info_line', array( 373 'INFO'=>$lang['visited'], 374 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] 375 )); 376 498 377 //------------------------------------------------------- favorite manipulation 499 378 if ( !$user['is_the_guest'] ) … … 501 380 // verify if the picture is already in the favorite of the user 502 381 $query = 'SELECT COUNT(*) AS nb_fav'; 503 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$ page['id'];382 $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; 504 383 $query.= ' AND user_id = '.$user['id'].';'; 505 384 $result = mysql_query( $query ); … … 507 386 if (!$row['nb_fav']) 508 387 { 509 $url = './picture.php?cat='.$page['cat'].'&image_id='.$ page['id'];388 $url = './picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; 510 389 if (isset($_GET['expand'])) 511 390 $url.= '&expand='.$_GET['expand']; … … 515 394 $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; 516 395 } 517 $vtp->addSession( $handle, 'favorite' ); 518 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 519 $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] ); 520 $vtp->setVar( $handle, 'favorite.src', 521 './template/'.$user['template'].'/theme/favorite.gif' ); 522 $vtp->setVar($handle,'favorite.alt','[ '.$lang['add_favorites_alt'].' ]'); 523 $vtp->closeSession( $handle, 'favorite' ); 396 $template->assign_block_vars('favorite', array( 397 'FAVORITE_IMG' => './template/'.$user['template'].'/theme/favorite.gif', 398 'FAVORITE_HINT' =>$lang['add_favorites_hint'], 399 'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]', 400 'U_FAVORITE'=> add_session_id( $url ) 401 )); 524 402 } 525 403 else 526 404 { 527 $url = './picture.php?cat='.$page['cat'].'&image_id='.$ page['id'];405 $url = './picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; 528 406 $url.= '&expand='.$_GET['expand'].'&add_fav=0'; 529 $vtp->addSession( $handle, 'favorite' ); 530 $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); 531 $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] ); 532 $vtp->setVar( $handle, 'favorite.src', 533 './template/'.$user['template'].'/theme/del_favorite.gif' ); 534 $vtp->setVar($handle,'favorite.alt','[ '.$lang['del_favorites_alt'].' ]'); 535 $vtp->closeSession( $handle, 'favorite' ); 407 $template->assign_block_vars('favorite', array( 408 'FAVORITE_IMG' => './template/'.$user['template'].'/theme/del_favorite.gif', 409 'FAVORITE_HINT' =>$lang['del_favorites_hint'], 410 'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]', 411 'U_FAVORITE'=> add_session_id( $url ) 412 )); 536 413 } 537 414 } … … 539 416 if ( $user['status'] == 'admin' ) 540 417 { 541 $vtp->addSession( $handle, 'modification' ); 542 $url = './admin/admin.php?page=picture_modify&cat_id='.$page['cat']; 543 $url.= '&image_id='.$page['id']; 544 $vtp->setVar( $handle, 'modification.link', add_session_id( $url ) ); 545 $vtp->setVar( $handle, 'modification.name', $lang['link_info_image'] ); 546 } 547 548 if ( $next ) 549 { 550 // sending vars for display 551 $vtp->addSession( $handle, 'next' ); 552 $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $next_url_link ) ); 553 $vtp->setGlobalVar( $handle, 'next.title', $next_title ); 554 $vtp->setGlobalVar( $handle, 'next.src', $next_lien_thumbnail ); 555 $vtp->setGlobalVar( $handle, 'next.alt', $next_alt_thumbnail ); 556 $vtp->closeSession( $handle, 'next' ); 557 } 558 else 559 { 560 $vtp->addSession( $handle, 'next_empty' ); 561 $vtp->closeSession( $handle, 'next_empty' ); 562 } 418 $template->assign_block_vars('modification', array()); 419 } 420 563 421 //---------------------------------------------------- users's comments display 564 422 if ( $conf['show_comments'] ) 565 423 { 566 $vtp->addSession( $handle, 'comments' );567 424 // comment registeration 568 if ( isset( $_POST['content'] ) and $_POST['content'] != '')425 if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) 569 426 { 570 427 $register_comment = true; 571 572 if ( !$user['is_the_guest'] ) $author = $user['username']; 573 if ( $_POST['author'] != '' ) $author = $_POST['author']; 428 $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; 574 429 // if a guest try to use the name of an already existing user, he must 575 430 // be rejected 576 if ( isset( $author ) and$author != $user['username'] )431 if ( $author != $user['username'] ) 577 432 { 578 433 $query = 'SELECT COUNT(*) AS user_exists'; … … 583 438 if ( $row['user_exists'] == 1 ) 584 439 { 585 $vtp->addSession( $handle, 'information' ); 586 $message = $lang['comment_user_exists']; 587 $vtp->setVar( $handle, 'information.content', $message ); 588 $vtp->closeSession( $handle, 'information' ); 440 $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_user_exists'])); 589 441 $register_comment = false; 590 442 } … … 600 452 $query.= ';'; 601 453 if ( mysql_num_rows( mysql_query( $query ) ) == 0 602 or$conf['anti-flood_time'] == 0 )454 || $conf['anti-flood_time'] == 0 ) 603 455 { 604 456 $query = 'INSERT INTO '.COMMENTS_TABLE; 605 $query.= ' (author,date,image_id,content,validated) VALUES'; 606 $query.= ' ('; 607 if ( !isset( $author ) ) $query.= 'NULL'; 608 else $query.= "'".$author."'"; 609 $query.= ','.time().','.$page['id']; 457 $query.= ' (author,date,image_id,content,validated) VALUES ('; 458 $query.= "'".$author."'"; 459 $query.= ','.time().','.$_GET['image_id']; 610 460 $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; 611 if ( !$conf['comments_validation'] or$user['status'] == 'admin' )461 if ( !$conf['comments_validation'] || $user['status'] == 'admin' ) 612 462 $query.= ",'true'"; 613 463 else … … 616 466 mysql_query( $query ); 617 467 // information message 618 $vtp->addSession( $handle, 'information' );619 468 $message = $lang['comment_added']; 620 469 if ( $conf['comments_validation'] and $user['status'] != 'admin' ) … … 622 471 $message.= '<br />'.$lang['comment_to_validate']; 623 472 } 624 $vtp->setVar( $handle, 'information.content', $message ); 625 $vtp->closeSession( $handle, 'information' ); 473 $template->assign_block_vars('information', array('INFORMATION'=>$message)); 626 474 // notification to the administrators 627 475 if ( $conf['mail_notification'] ) … … 629 477 $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); 630 478 $cat_name = strip_tags( $cat_name ); 631 if ( $page['name'] == '' ) $picture = $page['file']; 632 else $picture = $page['name']; 633 notify( 'comment', $cat_name.' > '.$picture ); 479 notify( 'comment', $cat_name.' > '.$picture['current']['name']); 634 480 } 635 481 } … … 637 483 { 638 484 // information message 639 $vtp->addSession( $handle, 'information' ); 640 $message = $lang['comment_anti-flood']; 641 $vtp->setVar( $handle, 'information.content', $message ); 642 $vtp->closeSession( $handle, 'information' ); 485 $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_anti-flood'])); 643 486 } 644 487 } … … 646 489 // comment deletion 647 490 if ( isset( $_GET['del'] ) 648 andis_numeric( $_GET['del'] )649 and$user['status'] == 'admin' )491 && is_numeric( $_GET['del'] ) 492 && $user['status'] == 'admin' ) 650 493 { 651 494 $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';'; … … 654 497 // number of comment for this picture 655 498 $query = 'SELECT COUNT(*) AS nb_comments'; 656 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$ page['id'];499 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 657 500 $query.= " AND validated = 'true'"; 658 501 $query.= ';'; 659 502 $row = mysql_fetch_array( mysql_query( $query ) ); 660 $page['nb_comments'] = $row['nb_comments'];503 661 504 // navigation bar creation 662 $url = './picture.php?cat='.$page['cat'].'&image_id='.$ page['id'];505 $url = './picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; 663 506 if (isset($_GET['expand'])) 664 507 $url.= '&expand='.$_GET['expand']; … … 677 520 $page['start'] = $_GET['start']; 678 521 } 679 $page['navigation_bar'] = create_navigation_bar( $url, $ page['nb_comments'],522 $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], 680 523 $page['start'], 681 524 $conf['nb_comment_page'], 682 525 '' ); 683 // sending vars for display684 $vtp->setGlobalVar( $handle, 'navigation_bar', $page['navigation_bar'] );685 $vtp->setGlobalVar( $handle, 'nb_comments', $page['nb_comments']);526 $template->assign_block_vars('comments', array( 527 'NB_COMMENT'=>$row['nb_comments'], 528 'NAV_BAR'=>$page['navigation_bar'])); 686 529 687 530 $query = 'SELECT id,author,date,image_id,content'; 688 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$ page['id'];531 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 689 532 $query.= " AND validated = 'true'"; 690 533 $query.= ' ORDER BY date ASC'; … … 694 537 while ( $row = mysql_fetch_array( $result ) ) 695 538 { 696 $vtp->addSession( $handle, 'comment' );697 $author = $row['author'];698 if ( $row['author'] == '' ) $author = $lang['guest'];699 $vtp->setVar( $handle, 'comment.author', $author );700 $vtp->setVar( $handle, 'comment.date',701 format_date( $row['date'], 'unix', true ) );702 539 $content = nl2br( $row['content'] ); 703 540 … … 716 553 $replacement = '<span style="font-style:italic;">\1</span>'; 717 554 $content = preg_replace( $pattern, $replacement, $content ); 718 719 $vtp->setVar( $handle, 'comment.content', $content ); 555 556 $template->assign_block_vars('comments.comment', array( 557 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], 558 'COMMENT_DATE'=>format_date( $row['date'], 'unix', true ), 559 'COMMENT'=>$content 560 )); 561 720 562 if ( $user['status'] == 'admin' ) 721 563 { 722 $vtp->addSession( $handle, 'delete' ); 723 $vtp->setVar( $handle, 'delete.link', 724 add_session_id( $url.'&del='.$row['id'] ) ); 725 $vtp->closeSession( $handle, 'delete' ); 564 $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id'] ))); 726 565 } 727 $vtp->closeSession( $handle, 'comment' ); 728 } 729 730 if ( !$user['is_the_guest'] 731 or ( $user['is_the_guest'] and $conf['comments_forall'] ) ) 732 { 733 $vtp->addSession( $handle, 'add_comment' ); 734 // form action 735 $action = str_replace( '&', '&', $_SERVER['REQUEST_URI'] ); 736 $vtp->setGlobalVar( $handle, 'form_action', $action ); 566 } 567 568 if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) ) 569 { 570 $template->assign_block_vars('comments.add_comment', array()); 737 571 // display author field if the user is not logged in 738 572 if ( !$user['is_the_guest'] ) 739 573 { 740 $vtp->addSession( $handle, 'author_known' ); 741 if (isset($user['pseudo'])) 742 $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] ); 743 $vtp->closeSession( $handle, 'author_known' ); 574 $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username'])); 575 } 576 else 577 { 578 $template->assign_block_vars('comments.add_comment.author_field', array()); 744 579 } 745 else 746 { 747 $vtp->addSession( $handle, 'author_field' ); 748 $vtp->closeSession( $handle, 'author_field' ); 749 } 750 $vtp->closeSession( $handle, 'add_comment' ); 751 } 752 $vtp->closeSession( $handle, 'comments' ); 580 } 753 581 } 754 582 //------------------------------------------------------------ log informations 755 pwg_log( 'picture', $ intitule_cat, $page['file'] );583 pwg_log( 'picture', $title_img, $picture['current']['file'] ); 756 584 mysql_close(); 757 //----------------------------------------------------------- html code display 758 $code = $vtp->Display( $handle, 0 ); 759 echo $code; 760 585 586 $template->pparse('picture'); 761 587 include('include/page_tail.php'); 762 588 ?>
Note: See TracChangeset
for help on using the changeset viewer.