Changeset 16


Ignore:
Timestamp:
May 21, 2003, 11:45:46 PM (21 years ago)
Author:
z0rglub
Message:

* empty log message *

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/category.php

    r14 r16  
    5353{
    5454  $page['tab_expand'] = array();
    55   $query = 'select id';
    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;';
    5858  $result = mysql_query( $query );
    5959  $i = 0;
     
    124124  $vtp->setVar( $handle, 'favorites.url', $url );
    125125  // searching the number of favorite picture
    126   $query = 'select count(*) as count';
    127   $query.= ' from '.PREFIX_TABLE.'favorites';
    128   $query.= ' where user_id = '.$user['id'].';';
     126  $query = 'SELECT COUNT(*) AS count';
     127  $query.= ' FROM '.PREFIX_TABLE.'favorites';
     128  $query.= ' WHERE user_id = '.$user['id'].';';
    129129  $result = mysql_query( $query );
    130130  $row = mysql_fetch_array( $result );
     
    238238  }
    239239 
    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';
    243242  $query.= $page['where'];
    244243  $query.= $conf['order_by'];
    245   $query.= ' limit '.$page['start'].','.$page['nb_image_page'];
     244  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
    246245  $query.= ';';
    247246  $result = mysql_query( $query );
     
    249248  $vtp->addSession( $handle, 'thumbnails' );
    250249  $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
    253251  $i = 1;
    254252  while ( $row = mysql_fetch_array( $result ) )
     
    263261      $cat_directory = $array_cat_directories[$row['cat_id']];
    264262    }
    265     // filename without extension
    266     $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) );
     263    $file = get_filename_wo_extension( $row['file'] );
    267264    // name of the picture
    268265    if ( $row['name'] != '' )
     
    283280    $thumbnail_url.= $file.'.'.$row['tn_ext'];
    284281    // 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 );
    301286    }
    302287    else
    303288    {
    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     else
    314     {
    315289      $poids = $row['filesize'];
    316290    }
    317     $thumbnail_title .= "\n".$lang['filesize'].' : '.$poids.' KB';
     291    $thumbnail_title .= ' : '.$poids.' KB';
    318292    // url link on picture.php page
    319293    $url_link = './picture.php?cat='.$page['cat'];
     
    338312    {
    339313      $vtp->addSession( $handle, 'nb_comments' );
    340       $query = 'select count(*) as nb_comments';
    341       $query.= ' from '.PREFIX_TABLE.'comments';
    342       $query.= ' where image_id = '.$row['id'];
     314      $query = 'SELECT COUNT(*) AS nb_comments';
     315      $query.= ' FROM '.PREFIX_TABLE.'comments';
     316      $query.= ' WHERE image_id = '.$row['id'];
    343317      $query.= ';';
    344318      $row = mysql_fetch_array( mysql_query( $query ) );
     
    371345{
    372346  $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'] );
    379350  $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'] );
    384353    $cat_directory = $result['dir'];
    385354
    386355    $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'];
    390359    }
    391360    else
    392361    {
    393       $name.= $cat_row['dir'];
     362      $name.= $subcat['dir'];
    394363    }
    395364    $name.= '</span> ]';
    396365    $name = replace_space( $name );
    397366   
    398     $query = 'select file,tn_ext';
    399     $query.= ' from '.PREFIX_TABLE.'images';
    400     $query.= ' where cat_id = '.$cat_row['id'];
    401     $query.= ' order by rand()';
    402     $query.= ' limit 0,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';
    403372    $query.= ';';
    404373    $image_result = mysql_query( $query );
     
    417386    $thumbnail_title = '';
    418387
    419     $url_link = './category.php?cat='.$cat_row['id'];
     388    $url_link = './category.php?cat='.$subcat['id'];
    420389    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
    421390    {
     
    433402    $vtp->setVar( $handle, 'thumbnail.name', $name );
    434403
    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 );
    437406    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
    438407
  • trunk/include/functions_category.inc.php

    r13 r16  
    378378      $page['cat_site_id']   = $result['site_id'];
    379379      $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' );
    380       $page['where'] = ' where cat_id = '.$page['cat'];
     380      $page['where'] = ' WHERE cat_id = '.$page['cat'];
    381381    }
    382382    else
     
    392392          $page['title'].= $_GET['search']."</span>";
    393393        }
    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';
     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';
    400400        $query.= $page['where'];
    401401        $query.= ';';
     
    409409
    410410        $page['where'] = ', '.PREFIX_TABLE.'favorites';
    411         $page['where'].= ' where user_id = '.$user['id'];
    412         $page['where'].= ' and image_id = id';
     411        $page['where'].= ' WHERE user_id = '.$user['id'];
     412        $page['where'].= ' AND image_id = id';
    413413     
    414         $query = 'select count(*) as nb_total_images';
    415         $query.= ' from '.PREFIX_TABLE.'favorites';
    416         $query.= ' where user_id = '.$user['id'];
     414        $query = 'SELECT COUNT(*) AS nb_total_images';
     415        $query.= ' FROM '.PREFIX_TABLE.'favorites';
     416        $query.= ' WHERE user_id = '.$user['id'];
    417417        $query.= ';';
    418418      }
     
    424424        // today - $conf['periode_courte']
    425425        $date = time() - 60*60*24*$user['short_period'];
    426         $page['where'] = " where date_available > '";
     426        $page['where'] = " WHERE date_available > '";
    427427        $page['where'].= date( 'Y-m-d', $date )."'";
    428428
    429         $query = 'select count(*) as nb_total_images';
    430         $query.= ' from '.PREFIX_TABLE.'images';
     429        $query = 'SELECT COUNT(*) AS nb_total_images';
     430        $query.= ' FROM '.PREFIX_TABLE.'images';
    431431        $query.= $page['where'];
    432432        $query.= ';';
     
    436436      {
    437437        $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
    438         $page['where'] = ' where cat_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';
    440440        $page['cat_nb_images'] = $conf['top_number'];
    441441        if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
     
    456456      {
    457457        // 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;
    465461        }
    466462      }
     
    478474  }
    479475}
     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;
     501function 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.
     548function 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}
    480581?>
  • trunk/include/functions_user.inc.php

    r14 r16  
    225225{
    226226  // 1. getting the ids of the restricted categories
    227   $query = 'select cat_id';
    228   $query.= ' from '.PREFIX_TABLE.'restrictions';
    229   $query.= ' where user_id = '.$user_id;
     227  $query = 'SELECT cat_id';
     228  $query.= ' FROM '.PREFIX_TABLE.'restrictions';
     229  $query.= ' WHERE user_id = '.$user_id;
    230230  $query.= ';';
    231231  $result = mysql_query( $query );
    232   $i = 0;
     232
    233233  $restriction = array();
    234234  while ( $row = mysql_fetch_array( $result ) )
    235235  {
    236     $restriction[$i++] = $row['cat_id'];
     236    array_push( $restriction, $row['cat_id'] );
    237237  }
    238238  if ( $check_invisible )
    239239  {
    240240    // 2. adding to the restricted categories, the invisible ones
    241     if ( $user_status != "admin" )
    242     {
    243       $query = 'select id';
    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';";
    246246      $result = mysql_query( $query );
    247247      while ( $row = mysql_fetch_array( $result ) )
    248248      {
    249         $restriction[$i++] = $row['id'];
     249        array_push( $restriction, $row['id'] );
    250250      }
    251251    }
Note: See TracChangeset for help on using the changeset viewer.