Changeset 26 for trunk/category.php


Ignore:
Timestamp:
Jul 21, 2003, 9:47:14 PM (21 years ago)
Author:
z0rglub
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/category.php

    r20 r26  
    2121//----------------------------------------------------------- personnal include
    2222include_once( './include/init.inc.php' );
     23$output.= 'after init.inc.php : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    2324//-------------------------------------------------- access authorization check
     25// creating the plain structure : array of all the available categories and
     26// their relative informations, see the definition of the function
     27// get_plain_structure for further details.
     28$page['plain_structure'] = get_plain_structure();
     29
    2430check_cat_id( $_GET['cat'] );
    2531check_login_authorization();
     
    3541if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
    3642{
    37   $j = 0;
    38   $tab_expand = explode( ",", $_GET['expand'] );
    39   $size = sizeof( $tab_expand );
    40   for ( $i = 0; $i < $size; $i++ )
    41   {
    42     if ( is_numeric( $tab_expand[$i] ) )
    43     {
    44       $page['tab_expand'][$j++] = $tab_expand[$i];
    45     }
     43  $tab_expand = explode( ',', $_GET['expand'] );
     44  foreach ( $tab_expand as $id ) {
     45    if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
    4646  }
    4747  $page['expand'] = implode( ',', $page['tab_expand'] );
     
    5050// The $page['expand'] equals 'all' and
    5151// $page['tab_expand'] contains all the authorized cat ids
    52 if ( $user['expand'] == 'true' or $_GET['expand'] == 'all' )
     52if ( $user['expand'] or $_GET['expand'] == 'all' )
    5353{
    5454  $page['tab_expand'] = array();
    55   $query = 'SELECT id';
    56   $query.= ' FROM '.PREFIX_TABLE.'categories';
    57   $query.= ' WHERE id_uppercat IS NULL;';
    58   $result = mysql_query( $query );
    59   $i = 0;
    60   while ( $row = mysql_fetch_array( $result ) )
    61   {
    62     $page['tab_expand'][$i++] = $row['id'];
    63   }
    6455  $page['expand'] = 'all';
    6556}
     
    8475  $page['start']*= $user['nb_image_page'];
    8576}
     77// creating the structure of the categories (useful for displaying the menu)
     78$page['structure'] = create_structure( '', $user['restrictions'] );
     79$page['structure'] = update_structure( $page['structure'] );
    8680initialize_category();
     81$output.= 'before template init : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    8782//----------------------------------------------------- template initialization
    8883$vtp = new VTemplate;
    8984$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
    9085initialize_template();
    91 
    92 $tpl = array( 'categories','hint_category','sub-cat','images_available',
    93               'total','title_menu','nb_image_category','send_mail',
    94               'title_send_mail','generation_time','upload_name',
    95               'connected_user','recent_image','days','generation_time',
    96               'favorite_cat_hint','favorite_cat','stats',
    97               'most_visited_cat_hint','most_visited_cat','recent_cat',
    98               'recent_cat_hint' );
     86$output.= 'before lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
     87$tpl = array(
     88  'categories','hint_category','sub-cat','images_available','total',
     89  'title_menu','nb_image_category','send_mail','title_send_mail',
     90  'generation_time','connected_user','recent_image','days','generation_time',
     91  'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint',
     92  'most_visited_cat','recent_cat','recent_cat_hint','upload_picture' );
    9993templatize_array( $tpl, 'lang', $handle );
     94$output.= 'after lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    10095
    10196$tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
    10297templatize_array( $tpl, 'conf', $handle );
     98$output.= 'after conf array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    10399
    104100$tpl = array( 'short_period','long_period','lien_collapsed', 'username' );
     
    112108$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
    113109$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
    114 $nb_total_pictures = get_total_image( "", $user['restrictions'] );
     110$nb_total_pictures = count_images( $page['structure'] );
    115111$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
    116112//------------------------------------------------------------- categories menu
     113$output.= 'before menu : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    117114// normal categories
    118 display_cat( '', '&nbsp;', $user['restrictions'], $page['tab_expand'] );
     115foreach ( $page['structure'] as $category ) {
     116  // display category is a function relative to the template
     117  display_category( $category, '&nbsp;', $handle );
     118}
     119$output.= 'after menu : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    119120// favorites cat
    120121if ( !$user['is_the_guest'] )
    121122{
    122123  $vtp->addSession( $handle, 'favorites' );
    123   $url = add_session_id('./category.php?cat=fav&amp;expand='.$page['expand'] );
    124   $vtp->setVar( $handle, 'favorites.url', $url );
     124  $url = './category.php?cat=fav&amp;expand='.$page['expand'];
     125  $vtp->setVar( $handle, 'favorites.url', add_session_id( $url ) );
    125126  // searching the number of favorite picture
    126127  $query = 'SELECT COUNT(*) AS count';
     
    133134}
    134135// most visited pictures category
    135 $url = add_session_id( './category.php?cat=most_visited'.
    136                        '&amp;expand='.$page['expand'] );
    137 $vtp->setGlobalVar( $handle, 'most_visited_url', $url );
     136$url = './category.php?cat=most_visited&amp;expand='.$page['expand'];
     137$vtp->setGlobalVar( $handle, 'most_visited_url', add_session_id( $url ) );
    138138// recent pictures
    139 $url = add_session_id( './category.php?cat=recent'.
    140                        '&amp;expand='.$page['expand'] );
    141 $vtp->setGlobalVar( $handle, 'recent_url', $url );
     139$url = './category.php?cat=recent&amp;expand='.$page['expand'];
     140$vtp->setGlobalVar( $handle, 'recent_url', add_session_id( $url ) );
    142141//--------------------------------------------------------------------- summary
    143142$vtp->addSession( $handle, 'summary' );
     
    146145{
    147146  $vtp->setVar( $handle, 'summary.title', '' );
    148   $vtp->setVar( $handle, 'summary.name',
    149                 replace_space( $lang['change_login'] ) );
     147  $vtp->setVar( $handle, 'summary.name',replace_space($lang['change_login']));
    150148}
    151149else
    152150{
    153151  $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] );
    154   $vtp->setVar( $handle, 'summary.name',
    155                 replace_space( $lang['login'] ) );
     152  $vtp->setVar( $handle, 'summary.name',  replace_space( $lang['login'] ) );
    156153}
    157154$vtp->closeSession( $handle, 'summary' );
     
    186183// about link
    187184$vtp->addSession( $handle, 'summary' );
    188 $vtp->setVar( $handle, 'summary.url',
    189               add_session_id( './about.php?'.$_SERVER['QUERY_STRING'] ) );
     185$vtp->setVar( $handle, 'summary.url', './about.php?'.
     186              str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) );
    190187$vtp->setVar( $handle, 'summary.title', $lang['hint_about'] );
    191188$vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) );
     
    227224}
    228225//------------------------------------------------------------------ thumbnails
     226$output.= 'before thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    229227if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
    230228{
     
    318316      $query.= ' FROM '.PREFIX_TABLE.'comments';
    319317      $query.= ' WHERE image_id = '.$row['id'];
     318      $query.= " AND validated = 'true'";
    320319      $query.= ';';
    321320      $row = mysql_fetch_array( mysql_query( $query ) );
     
    342341  $vtp->closeSession( $handle, 'thumbnails' );
    343342}
    344 elseif ( isset( $page['cat'] )
    345          and is_numeric( $page['cat'] )
    346          and $page['cat_nb_images'] == 0 )
     343//-------------------------------------------------------------- empty category
     344elseif ( ( isset( $page['cat'] )
     345           and is_numeric( $page['cat'] )
     346           and $page['cat_nb_images'] == 0 )
     347         or $_GET['cat'] == '' )
    347348{
    348349  $vtp->addSession( $handle, 'thumbnails' );
    349350  $vtp->addSession( $handle, 'line' );
    350351
    351   $subcats = get_non_empty_sub_cat_ids( $page['cat'] );
     352  $subcats = get_non_empty_subcat_ids( $page['cat'] );
    352353  $cell_number = 1;
    353   foreach ( $subcats as $id => $subcat ) {
    354     $result = get_cat_info( $subcat['non_empty_cat'] );
    355     $cat_directory = $result['dir'];
    356 
    357     $name = '[ <span style="font-weight:bold;">';
    358     if ( $subcat['name'] != '' )
    359     {
    360       $name.= $subcat['name'];
    361     }
    362     else
    363     {
    364       $name.= $subcat['dir'];
    365     }
     354  $i = 0;
     355  foreach ( $subcats as $subcat_id => $non_empty_id ) {
     356    $subcat_infos    = get_cat_info( $subcat_id );
     357    $non_empty_infos = get_cat_info( $non_empty_id );
     358
     359    $name ='[ <span style="font-weight:bold;">';
     360    $name.= $subcat_infos['name'][0];
    366361    $name.= '</span> ]';
    367     $name = replace_space( $name );
    368362   
    369363    $query = 'SELECT file,tn_ext';
    370364    $query.= ' FROM '.PREFIX_TABLE.'images';
    371     $query.= ' WHERE cat_id = '.$subcat['non_empty_cat'];
     365    $query.= ' WHERE cat_id = '.$non_empty_id;
    372366    $query.= ' ORDER BY RAND()';
    373367    $query.= ' LIMIT 0,1';
    374368    $query.= ';';
    375369    $image_result = mysql_query( $query );
    376     $image_row = mysql_fetch_array( $image_result );
     370    $image_row    = mysql_fetch_array( $image_result );
    377371
    378372    $file = get_filename_wo_extension( $image_row['file'] );
    379373
    380374    // creating links for thumbnail and associated category
    381     $lien_image = $cat_directory;
    382     $lien_thumbnail = $lien_image;
    383     $lien_thumbnail.= 'thumbnail/'.$conf['prefix_thumbnail'];
    384     $lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
    385     $lien_image.= $image_row['file'];
     375    $thumbnail_link = $non_empty_infos['dir'];
     376    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
     377    $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
    386378
    387379    $thumbnail_title = $lang['hint_category'];
    388380
    389     $url_link = './category.php?cat='.$subcat['id'];
     381    $url_link = './category.php?cat='.$subcat_id;
    390382    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
    391383    {
     
    394386    }
    395387    $url_link.= '&amp;expand='.$page['expand'];
    396     list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
     388    list( $year,$month,$day ) = explode( '-', $subcat_infos['date_last'] );
    397389    $date = mktime( 0, 0, 0, $month, $day, $year );
    398390
     
    400392    $vtp->addSession( $handle, 'thumbnail' );
    401393    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
    402     $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail );
     394    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_link );
    403395    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
    404396    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
     
    412404      $cell_number = 1;
    413405      // we open a new line if the subcat was not the last one
    414       if ( $id < count( $subcats ) - 1 )
     406      if ( $i++ < count( $subcats ) - 1 )
    415407      {
    416408        $vtp->addSession( $handle, 'line' );
     
    418410    }
    419411  }
    420   if ( $id < count( $subcats ) - 1 )
     412  if ( $i < count( $subcats ) - 1 )
    421413  {
    422414    $vtp->closeSession( $handle, 'line' );
     
    424416  $vtp->closeSession( $handle, 'thumbnails' );
    425417}
     418$output.= 'after thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    426419//------------------------------------------------------- category informations
    427420if ( isset ( $page['cat'] ) )
     
    470463//----------------------------------------------------------- html code display
    471464$code = $vtp->Display( $handle, 0 );
     465echo $output;
    472466echo $code;
    473467?>
Note: See TracChangeset for help on using the changeset viewer.