Changeset 441 for trunk/category.php


Ignore:
Timestamp:
Jun 25, 2004, 10:29:51 PM (20 years ago)
Author:
z0rglub
Message:

thumbnails display moved to included files include/category_*.inc.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/category.php

    r436 r441  
    270270));
    271271
    272 //------------------------------------------------------------------ thumbnails
    273 if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 )
    274 {
    275   $array_cat_directories = array();
    276  
    277   $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
    278   $query.= ',storage_category_id';
    279   $query.= ' FROM '.IMAGES_TABLE.' AS i';
    280   $query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id';
    281   $query.= $page['where'];
    282   $query.= $conf['order_by'];
    283   $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
    284   $query.= ';';
    285   $result = mysql_query( $query );
    286 
    287   $template->assign_block_vars('thumbnails', array());
    288 
    289   // iteration counter to use a new <tr> every "$nb_image_line" pictures
    290   $cell_number = 0;
    291   // iteration counter to be sure not to create too much lines in the table
    292   $line_number = 0;
    293 
    294   $row_number  = 1;
    295   $line_opened = false;
    296   $displayed_pics = 0;
    297  
    298   while ( $row = mysql_fetch_array( $result ) )
    299   {
    300     // retrieving the storage dir of the picture
    301     if ( !isset($array_cat_directories[$row['storage_category_id']]))
    302     {
    303       $array_cat_directories[$row['storage_category_id']] =
    304         get_complete_dir( $row['storage_category_id'] );
    305     }
    306     $cat_directory = $array_cat_directories[$row['storage_category_id']];
    307 
    308     $file = get_filename_wo_extension( $row['file'] );
    309     // name of the picture
    310     if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name'];
    311     else $name = str_replace( '_', ' ', $file );
    312 
    313     if ( $page['cat'] == 'search' )
    314     {
    315       $name = replace_search( $name, $_GET['search'] );
    316     }
    317     // thumbnail url
    318     $thumbnail_url = $cat_directory;
    319     $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
    320     $thumbnail_url.= $file.'.'.$row['tn_ext'];
    321     // message in title for the thumbnail
    322     $thumbnail_title = $row['file'];
    323     if ( $row['filesize'] == '' )
    324       $poids = floor( filesize( $cat_directory.$row['file'] ) / 1024 );
    325     else
    326       $poids = $row['filesize'];
    327     $thumbnail_title .= ' : '.$poids.' KB';
    328     // url link on picture.php page
    329     $url_link = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'];
    330     $url_link.= '&amp;image_id='.$row['id'];
    331     if ( $page['cat'] == 'search' )
    332     {
    333       $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    334     }
    335     // create a new line ?
    336     if ( (!$line_opened or $row_number++ == $user['nb_image_line'] )
    337          and $displayed_pics++ < mysql_num_rows( $result ) )
    338     {
    339       $template->assign_block_vars('thumbnails.line', array());
    340       $row_number = 1;
    341       $line_opened = true;
    342     }
    343    
    344     $template->assign_block_vars(
    345       'thumbnails.line.thumbnail',
    346       array(
    347         'IMAGE'=>$thumbnail_url,
    348         'IMAGE_ALT'=>$row['file'],
    349         'IMAGE_TITLE'=>$thumbnail_title,
    350         'IMAGE_NAME'=>$name,
    351         'IMAGE_TS'=>get_icon( $row['date_available'] ),
    352        
    353         'U_IMG_LINK'=>add_session_id( $url_link )
    354         ));
    355    
    356     if ( $conf['show_comments'] and $user['show_nb_comments'] )
    357     {
    358       $query = 'SELECT COUNT(*) AS nb_comments';
    359       $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id'];
    360       $query.= " AND validated = 'true'";
    361       $query.= ';';
    362       $row = mysql_fetch_array( mysql_query( $query ) );
    363       $template->assign_block_vars(
    364         'thumbnails.line.thumbnail.nb_comments',
    365         array('NB_COMMENTS'=>$row['nb_comments']) );
    366     }
    367   }
    368 }
    369 //-------------------------------------------------------------------- calendar
    370 elseif ( isset( $page['cat'] ) and $page['cat'] == 'calendar' )
    371 {
    372   // years of image availability
    373   $query = 'SELECT DISTINCT(YEAR(date_available)) AS year';
    374   $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    375   $query.= $page['where'];
    376   $query.= ' AND id = image_id';
    377   $query.= ' ORDER BY year';
    378   $query.= ';';
    379   $result = mysql_query( $query );
    380   $calendar_years = array();
    381   while ( $row = mysql_fetch_array( $result ) )
    382   {
    383     array_push( $calendar_years, $row['year'] );
    384   }
    385 
    386   if ( !isset( $page['calendar_year'] )
    387        or !in_array( $page['calendar_year'], $calendar_years ) )
    388   {
    389     $page['calendar_year'] = max( $calendar_years );
    390   }
    391 
    392   // years navigation bar creation
    393   $years_nav_bar = '';
    394   foreach ( $calendar_years as $calendar_year ) {
    395     if ( $calendar_year == $page['calendar_year'] )
    396     {
    397       $years_nav_bar.= ' <span class="selected">';
    398       $years_nav_bar.= $calendar_year;
    399       $years_nav_bar.= '</span>';
    400     }
    401     else
    402     {
    403       $url = PHPWG_ROOT_PATH.'category.php?cat=calendar';
    404       $url.= '&amp;year='.$calendar_year;
    405       $years_nav_bar.= ' ';
    406       $years_nav_bar.= '<a href="'.add_session_id( $url ).'">';
    407       $years_nav_bar.= $calendar_year;
    408       $years_nav_bar.= '</a>';
    409     }
    410   }
    411   $template->assign_block_vars(
    412     'calendar',
    413     array( 'YEARS_NAV_BAR' => $years_nav_bar )
    414     );
    415  
    416   $query = 'SELECT DISTINCT(MONTH(date_available)) AS month';
    417   $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    418   $query.= $page['where'];
    419   $query.= ' AND id = image_id';
    420   $query.= ' AND YEAR(date_available) = '.$page['calendar_year'];
    421   $query.= ' ORDER BY month';
    422   $query.= ';';
    423   $result = mysql_query( $query );
    424   $calendar_months = array();
    425   while ( $row = mysql_fetch_array( $result ) )
    426   {
    427     array_push( $calendar_months, $row['month'] );
    428   }
    429 
    430   // months navigation bar creation
    431   $months_nav_bar = '';
    432   foreach ( $calendar_months as $calendar_month ) {
    433     if ( isset( $page['calendar_month'] )
    434          and $calendar_month == $page['calendar_month'] )
    435     {
    436       $months_nav_bar.= ' <span class="selected">';
    437       $months_nav_bar.= $lang['month'][(int)$calendar_month];
    438       $months_nav_bar.= '</span>';
    439     }
    440     else
    441     {
    442       $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&amp;month=';
    443       $url.= $page['calendar_year'].'.';
    444       if ( $calendar_month < 10 )
    445       {
    446         // adding leading zero
    447         $url.= '0';
    448       }
    449       $url.= $calendar_month;
    450       $months_nav_bar.= ' ';
    451       $months_nav_bar.= '<a href="'.add_session_id( $url ).'">';
    452       $months_nav_bar.= $lang['month'][(int)$calendar_month];
    453       $months_nav_bar.= '</a>';
    454     }
    455   }
    456   $template->assign_block_vars(
    457     'calendar',
    458     array( 'MONTHS_NAV_BAR' => $months_nav_bar )
    459     );
    460 
    461   $row_number  = 1;
    462   $line_opened = false;
    463   $displayed_pics = 0;
    464   $template->assign_block_vars('thumbnails', array());
    465  
    466   if ( !isset( $page['calendar_month'] ) )
    467   {
    468     // for each month of this year, display a random picture
    469     foreach ( $calendar_months as $calendar_month ) {
    470       $query = 'SELECT COUNT(id) AS nb_picture_month';
    471       $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    472       $query.= $page['where'];
    473       $query.= ' AND YEAR(date_available) = '.$page['calendar_year'];
    474       $query.= ' AND MONTH(date_available) = '.$calendar_month;
    475       $query.= ' AND id = image_id';
    476       $query.= ';';
    477       $row = mysql_fetch_array( mysql_query( $query ) );
    478       $nb_picture_month = $row['nb_picture_month'];
    479 
    480       $query = 'SELECT file,tn_ext,date_available,storage_category_id';
    481       $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    482       $query.= $page['where'];
    483       $query.= ' AND YEAR(date_available) = '.$page['calendar_year'];
    484       $query.= ' AND MONTH(date_available) = '.$calendar_month;
    485       $query.= ' AND id = image_id';
    486       $query.= ' ORDER BY RAND()';
    487       $query.= ' LIMIT 0,1';
    488       $query.= ';';
    489       $row = mysql_fetch_array( mysql_query( $query ) );
    490      
    491       $file = get_filename_wo_extension( $row['file'] );
    492      
    493       // creating links for thumbnail and associated category
    494       $thumbnail_link = get_complete_dir( $row['storage_category_id'] );
    495       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    496       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    497      
    498       $name = $lang['month'][$calendar_month];
    499       $name.= ' '.$page['calendar_year'];
    500       $name.= ' ['.$nb_picture_month.']';
    501 
    502       $thumbnail_title = $lang['calendar_picture_hint'].$name;
    503      
    504       $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar';
    505       $url_link.= '&amp;month='.$page['calendar_year'].'.';
    506       if ( $calendar_month < 10 )
    507       {
    508         // adding leading zero
    509         $url_link.= '0';
    510       }
    511       $url_link.= $calendar_month;
    512      
    513       // create a new line ?
    514       if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] )
    515            and $displayed_pics++ < count( $calendar_months ) )
    516       {
    517         $template->assign_block_vars('thumbnails.line', array());
    518         $row_number = 1;
    519         $line_opened = true;
    520       }
    521 
    522       $template->assign_block_vars(
    523         'thumbnails.line.thumbnail',
    524         array(
    525           'IMAGE'=>$thumbnail_link,
    526           'IMAGE_ALT'=>$row['file'],
    527           'IMAGE_TITLE'=>$thumbnail_title,
    528           'IMAGE_NAME'=>$name,
    529          
    530           'U_IMG_LINK'=>add_session_id( $url_link )
    531           )
    532         );
    533     }
    534   }
    535   else
    536   {
    537     $query = 'SELECT DISTINCT(date_available) AS day';
    538     $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    539     $query.= $page['where'];
    540     $query.= ' AND id = image_id';
    541     $query.= ' AND YEAR(date_available) = '.$page['calendar_year'];
    542     $query.= ' AND MONTH(date_available) = '.$page['calendar_month'];
    543     $query.= ' ORDER BY day';
    544     $query.= ';';
    545     $result = mysql_query( $query );
    546     $calendar_days = array();
    547     while ( $row = mysql_fetch_array( $result ) )
    548     {
    549       array_push( $calendar_days, $row['day'] );
    550     }
    551     // for each month of this year, display a random picture
    552     foreach ( $calendar_days as $calendar_day ) {
    553       $query = 'SELECT COUNT(id) AS nb_picture_day';
    554       $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    555       $query.= $page['where'];
    556       $query.= " AND date_available = '".$calendar_day."'";
    557       $query.= ' AND id = image_id';
    558       $query.= ';';
    559       $row = mysql_fetch_array( mysql_query( $query ) );
    560       $nb_picture_day = $row['nb_picture_day'];
    561      
    562       $query = 'SELECT file,tn_ext,date_available,storage_category_id';
    563       $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    564       $query.= $page['where'];
    565       $query.= " AND date_available = '".$calendar_day."'";
    566       $query.= ' AND id = image_id';
    567       $query.= ' ORDER BY RAND()';
    568       $query.= ' LIMIT 0,1';
    569       $query.= ';';
    570       $row = mysql_fetch_array( mysql_query( $query ) );
    571 
    572       $file = get_filename_wo_extension( $row['file'] );
    573      
    574       // creating links for thumbnail and associated category
    575       $thumbnail_link = get_complete_dir( $row['storage_category_id'] );
    576       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    577       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    578 
    579       list($year,$month,$day) = explode( '-', $calendar_day );
    580       $unixdate = mktime(0,0,0,$month,$day,$year);
    581       $name = $lang['day'][date( "w", $unixdate )];
    582       $name.= ' '.$day;
    583       $name.= ' ['.$nb_picture_day.']';
    584      
    585       $thumbnail_title = $lang['calendar_picture_hint'].$name;
    586 
    587       $url_link = PHPWG_ROOT_PATH.'category.php?cat=search';
    588      
    589       // create a new line ?
    590       if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] )
    591            and $displayed_pics++ <= count( $calendar_months ) )
    592       {
    593         $template->assign_block_vars('thumbnails.line', array());
    594         $row_number = 1;
    595         $line_opened = true;
    596       }
    597 
    598       $template->assign_block_vars(
    599         'thumbnails.line.thumbnail',
    600         array(
    601           'IMAGE'=>$thumbnail_link,
    602           'IMAGE_ALT'=>$row['file'],
    603           'IMAGE_TITLE'=>$thumbnail_title,
    604           'IMAGE_NAME'=>$name,
    605          
    606           'U_IMG_LINK'=>add_session_id( $url_link )
    607           )
    608         );
    609     }
    610   }
    611 }
    612 //------------------------------------------------- recently updated categories
    613 elseif ( isset( $page['cat'] ) and $page['cat'] == 'recent_cats' )
    614 {
    615   // retrieving categories recently update, ie containing pictures added
    616   // recently. The calculated table field categories.date_last will be
    617   // easier to use
    618   $query = 'SELECT id AS category_id';
    619   $query.= ' FROM '.CATEGORIES_TABLE;
    620   $query.= ' WHERE date_last > ';
    621   $query.= '   SUBDATE(CURRENT_DATE,INTERVAL '.$user['short_period'].' DAY)';
    622   if ( $user['forbidden_categories'] != '' )
    623   {
    624     $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
    625   }
    626   $query.= ';';
    627   $result = mysql_query( $query );
    628 
    629   $row_number  = 1;
    630   $line_opened = false;
    631   $displayed_pics = 0;
    632   $cat_nb_images = mysql_num_rows( $result );
    633   $template->assign_block_vars('thumbnails', array());
    634  
    635   // for each category, we have to search a recent picture to display and
    636   // the name to display
    637   while ( $row = mysql_fetch_array( $result ) )
    638   {
    639     $cat_infos = get_cat_info( $row['category_id'] );
    640     $name = '['.get_cat_display_name($cat_infos['name'],'<br />','',false).']';
    641    
    642     $query = 'SELECT id,file,tn_ext,storage_category_id';
    643     $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    644     $query.= ' WHERE category_id = '.$row['category_id'];
    645     $query.= ' AND date_available > ';
    646     $query.= '   SUBDATE(CURRENT_DATE,INTERVAL '.$user['short_period'].' DAY)';
    647     $query.= ' AND id = image_id';
    648     $query.= ' ORDER BY RAND()';
    649     $query.= ' LIMIT 0,1';
    650     $query.= ';';
    651     $subrow = mysql_fetch_array( mysql_query( $query ) );
    652 
    653     $file = get_filename_wo_extension( $subrow['file'] );
    654    
    655     // creating links for thumbnail and associated category
    656     $thumbnail_link = get_complete_dir( $subrow['storage_category_id'] );
    657     $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    658     $thumbnail_link.= $file.'.'.$subrow['tn_ext'];
    659    
    660     $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
    661    
    662     // create a new line ?
    663     if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] )
    664          and $displayed_pics++ < $cat_nb_images )
    665     {
    666       $template->assign_block_vars('thumbnails.line', array());
    667       $row_number = 1;
    668       $line_opened = true;
    669     }
    670    
    671     $template->assign_block_vars(
    672       'thumbnails.line.thumbnail',
    673       array(
    674         'IMAGE' => $thumbnail_link,
    675         'IMAGE_ALT' => $subrow['file'],
    676         'IMAGE_TITLE' => $lang['hint_category'],
    677         'IMAGE_NAME' => $name,
    678        
    679         'U_IMG_LINK'=>add_session_id( $url_link )
    680         )
    681       );   
    682   }
    683 }
    684 //-------------------------------------------------------------- empty category
     272//------------------------------------------------------ main part : thumbnails
     273if (isset($page['cat']) and $page['cat_nb_images'] != 0)
     274{
     275  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
     276}
     277elseif (isset($page['cat']) and $page['cat'] == 'calendar')
     278{
     279  include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php');
     280}
     281elseif (isset($page['cat']) and $page['cat'] == 'recent_cats')
     282{
     283  include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php');
     284}
    685285else
    686286{
    687   $subcats=array();
    688   if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] );
    689   else                     $subcats = get_non_empty_subcat_ids( '' );
    690   $cell_number = 0;
    691   $i = 0;
    692  
    693   $template->assign_block_vars('thumbnails', array());
    694  
    695   foreach ( $subcats as $subcat_id => $non_empty_id )
    696   {
    697     $name = '<img src="'.$user['lien_collapsed'].'" style="border:none;"';
    698     $name.= ' alt="&gt;"/> ';
    699     $name.= '[ <span style="font-weight:bold;">';
    700     $name.= $page['plain_structure'][$subcat_id]['name'];
    701     $name.= '</span> ]';
    702 
    703     // searching the representative picture of the category
    704     $query = 'SELECT representative_picture_id';
    705     $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id;
    706     $query.= ';';
    707     $row = mysql_fetch_array( mysql_query( $query ) );
    708    
    709     $query = 'SELECT file,tn_ext,storage_category_id';
    710     $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    711     $query.= ' WHERE category_id = '.$non_empty_id;
    712     $query.= ' AND id = image_id';
    713     // if the category has a representative picture, this is its thumbnail
    714     // that will be displayed !
    715     if ( isset( $row['representative_picture_id'] ) )
    716       $query.= ' AND id = '.$row['representative_picture_id'];
    717     else
    718       $query.= ' ORDER BY RAND()';
    719     $query.= ' LIMIT 0,1';
    720     $query.= ';';
    721     $image_result = mysql_query( $query );
    722     $image_row    = mysql_fetch_array( $image_result );
    723 
    724     $file = get_filename_wo_extension( $image_row['file'] );
    725 
    726     // creating links for thumbnail and associated category
    727     $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] );
    728     $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    729     $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
    730 
    731     $thumbnail_title = $lang['hint_category'];
    732 
    733     $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$subcat_id;
    734 
    735     $date = $page['plain_structure'][$subcat_id]['date_last'];
    736 
    737     // sending vars to display
    738     if (!$cell_number && $i < count( $subcats ))
    739     {
    740       $template->assign_block_vars('thumbnails.line', array());
    741       $cell_number = 0;
    742       $i++;
    743     }
    744     if ( $cell_number++ == $user['nb_image_line'] -1 )
    745     {
    746       $cell_number = 0;
    747     }
    748    
    749     $template->assign_block_vars(
    750       'thumbnails.line.thumbnail',
    751       array(
    752         'IMAGE'=>$thumbnail_link,
    753         'IMAGE_ALT'=>$image_row['file'],
    754         'IMAGE_TITLE'=>$thumbnail_title,
    755         'IMAGE_NAME'=>$name,
    756         'IMAGE_TS'=>get_icon( $date ),
    757        
    758         'U_IMG_LINK'=>add_session_id( $url_link )
    759         )
    760       );
    761   }
     287  include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php');
    762288}
    763289//------------------------------------------------------- category informations
Note: See TracChangeset for help on using the changeset viewer.