Changeset 368


Ignore:
Timestamp:
Feb 21, 2004, 12:02:06 PM (20 years ago)
Author:
gweltas
Message:

Template migration

Location:
trunk
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/picture.php

    r364 r368  
    4242//-------------------------------------------------------------- initialization
    4343initialize_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
    5945// if this image_id doesn't correspond to this category, an error message is
    6046// displayed, and execution is stopped
    61 if ( mysql_num_rows( $result ) == 0 )
     47if ( 0 )
    6248{
    6349  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
     
    6652  exit();
    6753}
    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
    7555// retrieving the number of the picture in its category (in order)
    7656$query = 'SELECT DISTINCT(id)';
     
    8464$page['num'] = 0;
    8565$row = mysql_fetch_array( $result );
    86 while ( $row['id'] != $page['id'] )
     66while ( $row['id'] != $_GET['image_id'] )
    8767{
    8868  $page['num']++;
    8969  $row = mysql_fetch_array( $result );
    9070}
     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
     84if ( $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
     95if ($prev <0)
     96  $query.= ' LIMIT 0,2';
     97else
     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');
     105for ($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'].= '&amp;cat='.$page['cat'];
     133  if ( isset( $_GET['expand'] ) )
     134    $picture[$j]['url'].= '&amp;expand='.$_GET['expand'];
     135  if ( $page['cat'] == 'search' )
     136  {
     137    $picture[$j]['url'].= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
     138  }
     139}
     140
     141$url_home = './category.php?cat='.$page['cat'].'&amp;';
     142$url_home.= 'num='.$page['num'];
     143if (isset($_GET['expand']))
     144        $url_home.='&amp;expand='.$_GET['expand'];
     145if ( $page['cat'] == 'search' )
     146{
     147  $url_home.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
     148}
     149
     150$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify&amp;cat_id='.$page['cat'];
     151$url_admin.= '&amp;image_id='.$_GET['image_id'];
     152 
    91153//--------------------------------------------------------- favorite management
    92154if ( isset( $_GET['add_fav'] ) )
    93155{
     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 
    94160  if ( $_GET['add_fav'] == 1 )
    95161  {
    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 )
    120169    {
    121170      // there is no favorite picture anymore
    122171      // we redirect the user to the category page
    123       $url = add_session_id( 'category.php' );
     172      $url = add_session_id( $url_home );
    124173      header( 'Request-URI: '.$url );
    125174      header( 'Content-Location: '.$url ); 
     
    127176      exit();
    128177    }
    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'].'&amp;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.= '&amp;cat='.$page['cat'];
    199   if ( isset( $_GET['expand'] ) )
    200     $next_url_link.= '&amp;expand='.$_GET['expand'];
    201   if ( $page['cat'] == 'search' )
    202   {
    203     $next_url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
    204   }
    205 }
    206 //----------------------------------------------------- template initialization
     178        else if ( $prev < 0 )
     179        {
     180          $url = add_session_id( str_replace('&amp;','&',$picture['next']['url']), true);
     181        }
     182        else
     183        {
     184          $url = add_session_id( str_replace('&amp;','&',$picture['prev']['url']), true);
     185        }
     186        header( 'Request-URI: '.$url );
     187        header( 'Content-Location: '.$url ); 
     188        header( 'Location: '.$url );
     189        exit();
     190  }
     191}
     192
    207193//
    208194// Start output of page
    209195//
    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'];
    216198$refresh = 0;
    217 if ( isset( $_GET['slideshow'] ) && isset($next_url_link))
     199if ( isset( $_GET['slideshow'] ) && $next)
    218200{
    219201        $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.= '&amp;cat='.$page['cat'];
    240   $url.= '&amp;expand='.$_GET['expand'];
    241   if ( $page['cat'] == 'search' )
    242   {
    243     $url.= '&amp;search='.$_GET['search'];
    244     $url.= '&amp;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.= '&amp;cat='.$page['cat'];
    258         if (isset($_GET['expand']))
    259             $url.= '&amp;expand='.$_GET['expand'];
    260     if ( $page['cat'] == 'search' )
    261     {
    262       $url.= '&amp;search='.$_GET['search'];
    263       $url.= '&amp;mode='.$_GET['mode'];
    264     }
    265     $url.= '&amp;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'].'&amp;cat='.$page['cat'];
    308   if ( isset( $_GET['expand'] ) ) $url_link.= '&amp;expand='.$_GET['expand'];
    309   if ( $page['cat'] == 'search' )
    310   {
    311     $url_link.= '&amp;search='.$_GET['search'].'&amp;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'];
     206if (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}
     214else if ( $page['cat'] == 'search' )
     215{
     216  $title_img = replace_search( $title_img, $_GET['search'] );
     217}
    364218
    365219// calculation of width and height
    366 if ( $page['width'] == "" )
     220if ( empty($picture['current']['width']))
    367221{
    368222  $taille_image = @getimagesize( $lien_image );
     
    372226else
    373227{
    374   $original_width = $page['width'];
    375   $original_height = $page['height'];
     228  $original_width = $picture['current']['width'];
     229  $original_height = $picture['current']['height'];
    376230}
    377231
    378232$picture_size = get_picture_size( $original_width, $original_height,
    379233                                  $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'].'&amp;';
    384 $url_link.= 'num='.$page['num'];
    385 if (isset($_GET['expand']))
    386         $url_link.='&amp;expand='.$_GET['expand'];
    387 if ( $page['cat'] == 'search' )
    388 {
    389   $url_link.= "&amp;search=".$_GET['search'].'&amp;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                                 
     235include('include/page_header.php');
     236$template->set_filenames(array('picture'=>'picture.tpl'));
     237initialize_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( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
     271  )
     272);
     273
     274//-------------------------------------------------------- slideshow management
     275if ( 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}
     283else
     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'].'&amp;slideshow='.$option)
     291          ));
     292  }
     293}
     294
     295if ($prev>=0) $template->assign_block_vars('previous', array());
     296if ($next) $template->assign_block_vars('next', array());
     297
    409298//--------------------------------------------------------- picture information
    410299// 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' );
     300if ( !empty($picture['current']['author']) )
     301{
     302  $template->assign_block_vars('info_line', array(
     303          'INFO'=>$lang['author'],
     304          'VALUE'=>$picture['current']['author']
     305          ));
    417306}
    418307// 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' );
     308if ( !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          ));
    426314}
    427315// 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          ));
    434320// 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'].'">';
     321if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] )
     322{
     323  $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">';
    440324  $content.= $original_width.'*'.$original_height.'</a> ]';
    441   $vtp->setVar( $handle, 'info_line.content', $content );
    442325}
    443326else
    444327{
    445328  $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          ));
    449334// 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
     340if ( empty($picture['current']['filesize']))
     341{
     342  $poids = floor ( filesize( $picture['current']['url'] ) / 1024 );
    456343}
    457344else
    458345{
    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          ));
    475353// 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'] );
     354if ( !empty($picture['current']['keywords']))
     355{
     356  $keywords = explode( ',', $picture['current']['keywords'] );
    481357  $content = '';
    482358  $url = './category.php?cat=search';
     
    488364    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
    489365  }
    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    ));
    492370}
    493371// 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
    498377//------------------------------------------------------- favorite manipulation
    499378if ( !$user['is_the_guest'] )
     
    501380  // verify if the picture is already in the favorite of the user
    502381  $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'];
    504383  $query.= ' AND user_id = '.$user['id'].';';
    505384  $result = mysql_query( $query );
     
    507386  if (!$row['nb_fav'])
    508387  {
    509     $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
     388    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
    510389    if (isset($_GET['expand']))
    511390      $url.= '&amp;expand='.$_GET['expand'];
     
    515394      $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    516395    }
    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    ));
    524402  }
    525403  else
    526404  {
    527     $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
     405    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
    528406    $url.= '&amp;expand='.$_GET['expand'].'&amp;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    ));
    536413  }
    537414}
     
    539416if ( $user['status'] == 'admin' )
    540417{
    541   $vtp->addSession( $handle, 'modification' );
    542   $url = './admin/admin.php?page=picture_modify&amp;cat_id='.$page['cat'];
    543   $url.= '&amp;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
    563421//---------------------------------------------------- users's comments display
    564422if ( $conf['show_comments'] )
    565423{
    566   $vtp->addSession( $handle, 'comments' );
    567424  // comment registeration
    568   if ( isset( $_POST['content'] ) and $_POST['content'] != '' )
     425  if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
    569426  {
    570427    $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'];
    574429    // if a guest try to use the name of an already existing user, he must
    575430    // be rejected
    576     if ( isset( $author ) and $author != $user['username'] )
     431    if ( $author != $user['username'] )
    577432    {
    578433      $query = 'SELECT COUNT(*) AS user_exists';
     
    583438      if ( $row['user_exists'] == 1 )
    584439      {
    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']));
    589441        $register_comment = false;
    590442      }
     
    600452      $query.= ';';
    601453      if ( mysql_num_rows( mysql_query( $query ) ) == 0
    602            or $conf['anti-flood_time'] == 0 )
     454           || $conf['anti-flood_time'] == 0 )
    603455      {
    604456        $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'];
    610460        $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
    611         if ( !$conf['comments_validation'] or $user['status'] == 'admin' )
     461        if ( !$conf['comments_validation'] || $user['status'] == 'admin' )
    612462          $query.= ",'true'";
    613463        else
     
    616466        mysql_query( $query );
    617467        // information message
    618         $vtp->addSession( $handle, 'information' );
    619468        $message = $lang['comment_added'];
    620469        if ( $conf['comments_validation'] and $user['status'] != 'admin' )
     
    622471          $message.= '<br />'.$lang['comment_to_validate'];
    623472        }
    624         $vtp->setVar( $handle, 'information.content', $message );
    625         $vtp->closeSession( $handle, 'information' );
     473        $template->assign_block_vars('information', array('INFORMATION'=>$message));
    626474        // notification to the administrators
    627475        if ( $conf['mail_notification'] )
     
    629477          $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' );
    630478          $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']);
    634480        }
    635481      }
     
    637483      {
    638484        // 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']));
    643486      }
    644487    }
     
    646489  // comment deletion
    647490  if ( isset( $_GET['del'] )
    648        and is_numeric( $_GET['del'] )
    649        and $user['status'] == 'admin' )
     491       && is_numeric( $_GET['del'] )
     492       && $user['status'] == 'admin' )
    650493  {
    651494    $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';';
     
    654497  // number of comment for this picture
    655498  $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'];
    657500  $query.= " AND validated = 'true'";
    658501  $query.= ';';
    659502  $row = mysql_fetch_array( mysql_query( $query ) );
    660   $page['nb_comments'] = $row['nb_comments'];
     503 
    661504  // navigation bar creation
    662   $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
     505  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
    663506  if (isset($_GET['expand']))
    664507        $url.= '&amp;expand='.$_GET['expand'];
     
    677520    $page['start'] = $_GET['start'];
    678521  }
    679   $page['navigation_bar'] = create_navigation_bar( $url, $page['nb_comments'],
     522  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
    680523                                                   $page['start'],
    681524                                                   $conf['nb_comment_page'],
    682525                                                   '' );
    683   // sending vars for display
    684   $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']));
    686529
    687530  $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'];
    689532  $query.= " AND validated = 'true'";
    690533  $query.= ' ORDER BY date ASC';
     
    694537  while ( $row = mysql_fetch_array( $result ) )
    695538  {
    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 ) );
    702539    $content = nl2br( $row['content'] );
    703540
     
    716553    $replacement = '<span style="font-style:italic;">\1</span>';
    717554    $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       
    720562    if ( $user['status'] == 'admin' )
    721563    {
    722       $vtp->addSession( $handle, 'delete' );
    723       $vtp->setVar( $handle, 'delete.link',
    724                     add_session_id( $url.'&amp;del='.$row['id'] ) );
    725       $vtp->closeSession( $handle, 'delete' );
     564          $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'] )));
    726565    }
    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( '&', '&amp;', $_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());
    737571    // display author field if the user is not logged in
    738572    if ( !$user['is_the_guest'] )
    739573    {
    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());
    744579    }
    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  }
    753581}
    754582//------------------------------------------------------------ log informations
    755 pwg_log( 'picture', $intitule_cat, $page['file'] );
     583pwg_log( 'picture', $title_img, $picture['current']['file'] );
    756584mysql_close();
    757 //----------------------------------------------------------- html code display
    758 $code = $vtp->Display( $handle, 0 );
    759 echo $code;
    760 
     585
     586$template->pparse('picture');
    761587include('include/page_tail.php');
    762588?>
Note: See TracChangeset for help on using the changeset viewer.