Changeset 16
- Timestamp:
- May 21, 2003, 11:45:46 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/category.php
r14 r16 53 53 { 54 54 $page['tab_expand'] = array(); 55 $query = ' selectid';56 $query.= ' from'.PREFIX_TABLE.'categories';57 $query.= ' where id_uppercat is null;';55 $query = 'SELECT id'; 56 $query.= ' FROM '.PREFIX_TABLE.'categories'; 57 $query.= ' WHERE id_uppercat IS NULL;'; 58 58 $result = mysql_query( $query ); 59 59 $i = 0; … … 124 124 $vtp->setVar( $handle, 'favorites.url', $url ); 125 125 // searching the number of favorite picture 126 $query = ' select count(*) ascount';127 $query.= ' from'.PREFIX_TABLE.'favorites';128 $query.= ' whereuser_id = '.$user['id'].';';126 $query = 'SELECT COUNT(*) AS count'; 127 $query.= ' FROM '.PREFIX_TABLE.'favorites'; 128 $query.= ' WHERE user_id = '.$user['id'].';'; 129 129 $result = mysql_query( $query ); 130 130 $row = mysql_fetch_array( $result ); … … 238 238 } 239 239 240 $query = 'select id,file,date_available,comment,'; 241 $query.= ' author,tn_ext,name,filesize,width,height,cat_id'; 242 $query.= ' from '.PREFIX_TABLE.'images'; 240 $query = 'SELECT id,file,date_available,tn_ext,name,filesize,cat_id'; 241 $query.= ' FROM '.PREFIX_TABLE.'images'; 243 242 $query.= $page['where']; 244 243 $query.= $conf['order_by']; 245 $query.= ' limit'.$page['start'].','.$page['nb_image_page'];244 $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; 246 245 $query.= ';'; 247 246 $result = mysql_query( $query ); … … 249 248 $vtp->addSession( $handle, 'thumbnails' ); 250 249 $vtp->addSession( $handle, 'line' ); 251 // compteur d'itération pour aller à la ligne 252 // toutes les "$nb_image_ligne" images 250 // iteration counter to use a new <tr> every "$nb_image_line" pictures 253 251 $i = 1; 254 252 while ( $row = mysql_fetch_array( $result ) ) … … 263 261 $cat_directory = $array_cat_directories[$row['cat_id']]; 264 262 } 265 // filename without extension 266 $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) ); 263 $file = get_filename_wo_extension( $row['file'] ); 267 264 // name of the picture 268 265 if ( $row['name'] != '' ) … … 283 280 $thumbnail_url.= $file.'.'.$row['tn_ext']; 284 281 // message in title for the thumbnail 285 $tab_date = explode( '-', $row['date_available'] ); 286 $thumbnail_title = $lang['registration_date']; 287 $thumbnail_title.= ' '.$tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0]; 288 if ( $row['comment'] != '' ) 289 { 290 $thumbnail_title .= "\n".$lang['comment'].' : '.$row['comment']; 291 } 292 if ( $row['author'] != '' ) 293 { 294 $thumbnail_title .= "\n".$lang['author'].' : '.$row['author']; 295 } 296 if ( $row['width'] == '' ) 297 { 298 $taille_image = @getimagesize( $lien_image ); 299 $width = $taille_image[0]; 300 $height = $taille_image[1]; 282 $thumbnail_title = $row['file']; 283 if ( $row['filesize'] == '' ) 284 { 285 $poids = floor( filesize( $lien_image ) / 1024 ); 301 286 } 302 287 else 303 288 { 304 $width = $row['width'];305 $height = $row['height'];306 }307 $thumbnail_title .= "\n".$lang['size'].' : '.$width.'*'.$height;308 $thumbnail_title .= "\n".$lang['file'].' : '.$row['file'];309 if ( $row['filesize'] == '' )310 {311 $poids = floor( filesize( $lien_image ) / 1024 );312 }313 else314 {315 289 $poids = $row['filesize']; 316 290 } 317 $thumbnail_title .= "\n".$lang['filesize'].' : '.$poids.' KB';291 $thumbnail_title .= ' : '.$poids.' KB'; 318 292 // url link on picture.php page 319 293 $url_link = './picture.php?cat='.$page['cat']; … … 338 312 { 339 313 $vtp->addSession( $handle, 'nb_comments' ); 340 $query = ' select count(*) asnb_comments';341 $query.= ' from'.PREFIX_TABLE.'comments';342 $query.= ' whereimage_id = '.$row['id'];314 $query = 'SELECT COUNT(*) AS nb_comments'; 315 $query.= ' FROM '.PREFIX_TABLE.'comments'; 316 $query.= ' WHERE image_id = '.$row['id']; 343 317 $query.= ';'; 344 318 $row = mysql_fetch_array( mysql_query( $query ) ); … … 371 345 { 372 346 $vtp->addSession( $handle, 'thumbnails' ); 373 374 $query = 'select id,name,dir,date_dernier'; 375 $query.= ' from '.PREFIX_TABLE.'categories'; 376 $query.= ' where id_uppercat = '.$page['cat']; 377 $query.= ' order by rank;'; 378 $cat_result = mysql_query( $query ); 347 $vtp->addSession( $handle, 'line' ); 348 349 $subcats = get_non_empty_sub_cat_ids( $page['cat'] ); 379 350 $i = 1; 380 $vtp->addSession( $handle, 'line' ); 381 while ( $cat_row = mysql_fetch_array( $cat_result ) ) 382 { 383 $result = get_cat_info( $cat_row['id'] ); 351 foreach ( $subcats as $subcat) { 352 $result = get_cat_info( $subcat['non_empty_cat'] ); 384 353 $cat_directory = $result['dir']; 385 354 386 355 $name = '[ <span style="font-weight:bold;">'; 387 if ( $ cat_row['name'] != '' )388 { 389 $name.= $ cat_row['name'];356 if ( $subcat['name'] != '' ) 357 { 358 $name.= $subcat['name']; 390 359 } 391 360 else 392 361 { 393 $name.= $ cat_row['dir'];362 $name.= $subcat['dir']; 394 363 } 395 364 $name.= '</span> ]'; 396 365 $name = replace_space( $name ); 397 366 398 $query = ' selectfile,tn_ext';399 $query.= ' from'.PREFIX_TABLE.'images';400 $query.= ' where cat_id = '.$cat_row['id'];401 $query.= ' order by rand()';402 $query.= ' limit0,1';367 $query = 'SELECT file,tn_ext'; 368 $query.= ' FROM '.PREFIX_TABLE.'images'; 369 $query.= ' WHERE cat_id = '.$subcat['non_empty_cat']; 370 $query.= ' ORDER BY RAND()'; 371 $query.= ' LIMIT 0,1'; 403 372 $query.= ';'; 404 373 $image_result = mysql_query( $query ); … … 417 386 $thumbnail_title = ''; 418 387 419 $url_link = './category.php?cat='.$ cat_row['id'];388 $url_link = './category.php?cat='.$subcat['id']; 420 389 if ( !in_array( $page['cat'], $page['tab_expand'] ) ) 421 390 { … … 433 402 $vtp->setVar( $handle, 'thumbnail.name', $name ); 434 403 435 $date = explode( '-', $cat_row['date_dernier'] );436 $date = mktime( 0, 0, 0, $ date[1], $date[2], $date[0]);404 list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] ); 405 $date = mktime( 0, 0, 0, $month, $day, $year ); 437 406 $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) ); 438 407 -
trunk/include/functions_category.inc.php
r13 r16 378 378 $page['cat_site_id'] = $result['site_id']; 379 379 $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' ); 380 $page['where'] = ' wherecat_id = '.$page['cat'];380 $page['where'] = ' WHERE cat_id = '.$page['cat']; 381 381 } 382 382 else … … 392 392 $page['title'].= $_GET['search']."</span>"; 393 393 } 394 $page['where'] = " where ( file like'%".$_GET['search']."%'";395 $page['where'].= " or name like'%".$_GET['search']."%'";396 $page['where'].= " or comment like'%".$_GET['search']."%' )";397 398 $query = ' select count(*) asnb_total_images';399 $query.= ' from'.PREFIX_TABLE.'images';394 $page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'"; 395 $page['where'].= " OR name LIKE '%".$_GET['search']."%'"; 396 $page['where'].= " OR comment LIKE '%".$_GET['search']."%' )"; 397 398 $query = 'SELECT COUNT(*) AS nb_total_images'; 399 $query.= ' FROM '.PREFIX_TABLE.'images'; 400 400 $query.= $page['where']; 401 401 $query.= ';'; … … 409 409 410 410 $page['where'] = ', '.PREFIX_TABLE.'favorites'; 411 $page['where'].= ' whereuser_id = '.$user['id'];412 $page['where'].= ' andimage_id = id';411 $page['where'].= ' WHERE user_id = '.$user['id']; 412 $page['where'].= ' AND image_id = id'; 413 413 414 $query = ' select count(*) asnb_total_images';415 $query.= ' from'.PREFIX_TABLE.'favorites';416 $query.= ' whereuser_id = '.$user['id'];414 $query = 'SELECT COUNT(*) AS nb_total_images'; 415 $query.= ' FROM '.PREFIX_TABLE.'favorites'; 416 $query.= ' WHERE user_id = '.$user['id']; 417 417 $query.= ';'; 418 418 } … … 424 424 // today - $conf['periode_courte'] 425 425 $date = time() - 60*60*24*$user['short_period']; 426 $page['where'] = " wheredate_available > '";426 $page['where'] = " WHERE date_available > '"; 427 427 $page['where'].= date( 'Y-m-d', $date )."'"; 428 428 429 $query = ' select count(*) asnb_total_images';430 $query.= ' from'.PREFIX_TABLE.'images';429 $query = 'SELECT COUNT(*) AS nb_total_images'; 430 $query.= ' FROM '.PREFIX_TABLE.'images'; 431 431 $query.= $page['where']; 432 432 $query.= ';'; … … 436 436 { 437 437 $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat']; 438 $page['where'] = ' wherecat_id != -1';439 $conf['order_by'] = ' order by hit desc, file asc';438 $page['where'] = ' WHERE cat_id != -1'; 439 $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; 440 440 $page['cat_nb_images'] = $conf['top_number']; 441 441 if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] ) … … 456 456 { 457 457 // we must not show pictures of a forbidden category 458 $restricted_cat = get_all_restrictions( $user['id'], $user['status'] ); 459 if ( sizeof( $restricted_cat ) > 0 ) 460 { 461 for ( $i = 0; $i < sizeof( $restricted_cat ); $i++ ) 462 { 463 $page['where'].= ' and cat_id != '.$restricted_cat[$i]; 464 } 458 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 459 foreach ( $restricted_cats as $restricted_cat ) { 460 $page['where'].= ' AND cat_id != '.$restricted_cat; 465 461 } 466 462 } … … 478 474 } 479 475 } 476 477 // get_non_empty_sub_cat_ids returns an array composing of the infos of the 478 // direct sub-categories of the given uppercat id. Each of these infos is 479 // associated to the first found non empty category id. eg : 480 // 481 // - catname [cat_id] 482 // - cat1 [1] -> given uppercat 483 // - cat1.1 [2] (empty) 484 // - cat1.1.1 [5] (empty) 485 // - cat1.1.2 [6] 486 // - cat1.2 [3] 487 // - cat1.3 [4] 488 // 489 // get_non_empty_sub_cat_ids will return : 490 // $cats[0]['id'] = 2; 491 // $cats[0]['name'] = ''; 492 // $cats[0]['dir'] = 'cat1'; 493 // $cats[0]['date_dernier'] = '2003-05-17'; 494 // $cats[0]['non_empty_cat'] = 6; 495 // 496 // $cats[1]['id'] = 3; 497 // $cats[1]['non_empty_cat'] = 3; 498 // 499 // $cats[1]['id'] = 4; 500 // $cats[1]['non_empty_cat'] = 4; 501 function get_non_empty_sub_cat_ids( $id_uppercat ) 502 { 503 global $user; 504 505 $cats = array(); 506 507 $query = 'SELECT id,name,dir,date_dernier,nb_images'; 508 $query.= ' FROM '.PREFIX_TABLE.'categories'; 509 $query.= ' WHERE id_uppercat = '.$id_uppercat; 510 // we must not show pictures of a forbidden category 511 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 512 foreach ( $restricted_cats as $restricted_cat ) { 513 $query.= ' AND id != '.$restricted_cat; 514 } 515 $query.= ' ORDER BY rank'; 516 $query.= ';'; 517 518 $result = mysql_query( $query ); 519 while ( $row = mysql_fetch_array( $result ) ) 520 { 521 if ( $row['nb_images'] == 0 ) 522 { 523 $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ); 524 } 525 else 526 { 527 $non_empty_cat = $row['id']; 528 } 529 // only categories with findable picture in any of its subcats is 530 // represented. 531 if ( $non_empty_cat != false ) 532 { 533 $temp_cat = array( 534 'id' => $row['id'], 535 'name' => $row['name'], 536 'dir' => $row['dir'], 537 'date_dernier' => $row['date_dernier'], 538 'non_empty_cat' => $non_empty_cat ); 539 array_push( $cats, $temp_cat ); 540 } 541 } 542 return $cats; 543 } 544 545 // get_first_non_empty_cat_id returns the id of the first non empty 546 // sub-category to the given uppercat. If no picture is found in any 547 // subcategory, false is returned. 548 function get_first_non_empty_cat_id( $id_uppercat ) 549 { 550 global $user; 551 552 $query = 'SELECT id,nb_images'; 553 $query.= ' FROM '.PREFIX_TABLE.'categories'; 554 $query.= ' WHERE id_uppercat = '.$id_uppercat; 555 // we must not show pictures of a forbidden category 556 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); 557 foreach ( $restricted_cats as $restricted_cat ) { 558 $query.= ' AND id != '.$restricted_cat; 559 } 560 $query.= ' ORDER BY RAND()'; 561 $query.= ';'; 562 $result = mysql_query( $query ); 563 while ( $row = mysql_fetch_array( $result ) ) 564 { 565 if ( $row['nb_images'] > 0 ) 566 { 567 return $row['id']; 568 } 569 } 570 $result = mysql_query( $query ); 571 while ( $row = mysql_fetch_array( $result ) ) 572 { 573 // recursive call 574 if ( $subcat = get_first_non_empty_cat_id( $row['id'] ) ) 575 { 576 return $subcat; 577 } 578 } 579 return false; 580 } 480 581 ?> -
trunk/include/functions_user.inc.php
r14 r16 225 225 { 226 226 // 1. getting the ids of the restricted categories 227 $query = ' selectcat_id';228 $query.= ' from'.PREFIX_TABLE.'restrictions';229 $query.= ' whereuser_id = '.$user_id;227 $query = 'SELECT cat_id'; 228 $query.= ' FROM '.PREFIX_TABLE.'restrictions'; 229 $query.= ' WHERE user_id = '.$user_id; 230 230 $query.= ';'; 231 231 $result = mysql_query( $query ); 232 $i = 0; 232 233 233 $restriction = array(); 234 234 while ( $row = mysql_fetch_array( $result ) ) 235 235 { 236 $restriction[$i++] = $row['cat_id'];236 array_push( $restriction, $row['cat_id'] ); 237 237 } 238 238 if ( $check_invisible ) 239 239 { 240 240 // 2. adding to the restricted categories, the invisible ones 241 if ( $user_status != "admin")242 { 243 $query = ' selectid';244 $query.= ' from'.PREFIX_TABLE.'categories';245 $query.= " where status='invisible';";241 if ( $user_status != 'admin' ) 242 { 243 $query = 'SELECT id'; 244 $query.= ' FROM '.PREFIX_TABLE.'categories'; 245 $query.= " WHERE status = 'invisible';"; 246 246 $result = mysql_query( $query ); 247 247 while ( $row = mysql_fetch_array( $result ) ) 248 248 { 249 $restriction[$i++] = $row['id'];249 array_push( $restriction, $row['id'] ); 250 250 } 251 251 }
Note: See TracChangeset
for help on using the changeset viewer.