Changeset 465


Ignore:
Timestamp:
Aug 5, 2004, 7:31:36 PM (20 years ago)
Author:
z0rglub
Message:
  • non picture files management
  • refactoring
  • test of "is the picture belonging to this category" comes back
  • recoding a bit the new system of $picture array with prev, current, next (more readable, I couldn't read the old one)
  • template vars for previous and next elements are now in the corresponding block, not in the global template vars
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/picture.php

    r454 r465  
    4343//-------------------------------------------------------------- initialization
    4444initialize_category( 'picture' );
    45 
    46 // if this image_id doesn't correspond to this category, an error message is
    47 // displayed, and execution is stopped
    48 if ( 0 )
    49 {
    50   echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
    51   echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';
    52   echo $lang['thumbnails'].'</a></div>';
    53   exit();
    54 }
    55 
    5645// retrieving the number of the picture in its category (in order)
    5746$query = '
     
    6453$result = mysql_query( $query );
    6554$page['num'] = 0;
    66 $row = mysql_fetch_array( $result );
    67 while ( $row['id'] != $_GET['image_id'] )
    68 {
     55$belongs = false;
     56while ($row = mysql_fetch_array($result))
     57{
     58  if ($row['id'] == $_GET['image_id'])
     59  {
     60    $belongs = true;
     61    break;
     62  }
    6963  $page['num']++;
    70   $row = mysql_fetch_array( $result );
    71 }
    72 
     64}
     65// if this image_id doesn't correspond to this category, an error message is
     66// displayed, and execution is stopped
     67if (!$belongs)
     68{
     69  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
     70  echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';
     71  echo $lang['thumbnails'].'</a></div>';
     72  exit();
     73}
    7374//------------------------------------- prev, current & next picture management
    7475$picture = array();
    75 $picture['prev']['name'] = '';
    76 $picture['next']['name'] = '';
    77 $picture['prev']['thumbnail'] = '';
    78 $picture['next']['thumbnail'] = '';
    79 $picture['prev']['url'] = '';
    80 $picture['next']['url'] = '';
    81 
    82 $next = $page['num'] + 1;
    83 $prev = $page['num'] - 1;
    84 
    85 if ( $page['num'] == $page['cat_nb_images'] - 1 )
    86 {
    87   $next = 0;
     76
     77if ($page['num'] == 0)
     78{
     79  $has_prev = false;
     80}
     81else
     82{
     83  $has_prev = true;
     84}
     85
     86if ($page['num'] == $page['cat_nb_images'] - 1)
     87{
     88  $has_next = false;
     89}
     90else
     91{
     92  $has_next = true;
    8893}
    8994
     
    96101  ';
    97102
    98 if ( $prev < 0 )
     103if ( !$has_prev )
    99104{
    100105  $query.= ' LIMIT 0,2';
     
    102107else
    103108{
    104   $query.= ' LIMIT '.$prev.',3';
     109  $query.= ' LIMIT '.($page['num'] - 1).',3';
    105110}
    106111$query.= ';';
    107112
    108113$result = mysql_query( $query );
    109 $nb_row = mysql_num_rows( $result );
    110 $index = array('prev','current','next');
    111 
    112 for ( $i = 0; $i < $nb_row; $i++ )
    113 {
    114   $j=($prev<0)?$index[$i+1]:$index[$i];
     114$indexes = array('prev', 'current', 'next');
     115
     116foreach (array('prev', 'current', 'next') as $i)
     117{
     118  if ($i == 'prev' and !$has_prev)
     119  {
     120    continue;
     121  }
     122  if ($i == 'next' and !$has_next)
     123  {
     124    break;
     125  }
     126
    115127  $row = mysql_fetch_array($result);
    116   $picture[$j] = $row;
     128  foreach (array_keys($row) as $key)
     129  {
     130    if (!is_numeric($key))
     131    {
     132      $picture[$i][$key] = $row[$key];
     133    }
     134  }
     135
     136  $picture[$i]['is_picture'] = false;
     137  if (in_array(get_extension($row['file']), $conf['picture_ext']))
     138  {
     139    $picture[$i]['is_picture'] = true;
     140  }
    117141 
    118142  if ( !isset($array_cat_directories[$row['storage_category_id']]))
     
    122146  }
    123147  $cat_directory = $array_cat_directories[$row['storage_category_id']];
    124   $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
    125 
    126   $picture[$j]['src'] = $cat_directory.$row['file'];
    127 
    128   $picture[$j]['thumbnail'] = $cat_directory.'thumbnail/';
    129   $picture[$j]['thumbnail'].= $conf['prefix_thumbnail'].$file;
    130   $picture[$j]['thumbnail'].= '.'.$row['tn_ext'];
     148  $file_wo_ext = get_filename_wo_extension($row['file']);
     149
     150  $icon = './template/'.$user['template'].'/mimetypes/';
     151  $icon.= strtolower(get_extension($row['file'])).'.png';
     152
     153  if (isset($row['representative_ext']) and $row['representative_ext'] =! '')
     154  {
     155    $picture[$i]['src'] = $cat_directory.'representative/';
     156    $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext'];
     157  }
     158  else
     159  {
     160    $picture[$i]['src'] = $icon;
     161  }
     162  // special case for picture files
     163  if ($picture[$i]['is_picture'])
     164  {
     165    $picture[$i]['src'] = $cat_directory.$row['file'];
     166  }
     167
     168  // if picture is not a file, we need the download link
     169  if (!$picture[$i]['is_picture'])
     170  {
     171    $picture[$i]['download'] = $cat_directory.$row['file'];
     172  }
     173
     174  if (isset($row['tn_ext']) and $row['tn_ext'] != '')
     175  {
     176    $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/';
     177    $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext;
     178    $picture[$i]['thumbnail'].= '.'.$row['tn_ext'];
     179  }
     180  else
     181  {
     182    $picture[$i]['thumbnail'] = $icon;
     183  }
    131184 
    132185  if ( !empty( $row['name'] ) )
    133186  {
    134     $picture[$j]['name'] = $row['name'];
     187    $picture[$i]['name'] = $row['name'];
    135188  }
    136189  else
    137190  {
    138     $picture[$j]['name'] = str_replace( '_', ' ', $file );
    139   }
    140 
    141   $picture[$j]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];
    142   $picture[$j]['url'].= '&amp;cat='.$page['cat'];
     191    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
     192  }
     193
     194  $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];
     195  $picture[$i]['url'].= '&amp;cat='.$page['cat'];
    143196  if ( $page['cat'] == 'search' )
    144197  {
    145     $picture[$j]['url'].= '&amp;search='.$_GET['search'];
     198    $picture[$i]['url'].= '&amp;search='.$_GET['search'];
    146199  }
    147200}
     
    177230  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
    178231  {
    179     if ( $prev < 0 and $nb_row == 1 )
     232    if (!$has_prev and $mysql_num_rows == 1)
    180233    {
    181234      // there is no favorite picture anymore we redirect the user to the
     
    184237      redirect( $url );
    185238    }
    186     else if ( $prev < 0 )
     239    else if (!$has_prev)
    187240    {
    188241      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
     
    333386  'PHOTO' => $title_nb,
    334387  'TITLE' => $picture['current']['name'],
    335   'PREV_TITLE_IMG' => $picture['prev']['name'],
    336   'NEXT_TITLE_IMG' => $picture['next']['name'],
    337   'PREV_IMG' => $picture['prev']['thumbnail'],
    338   'NEXT_IMG' => $picture['next']['thumbnail'],
    339388  'SRC_IMG' => $picture['current']['src'],
    340389  'ALT_IMG' => $picture['current']['file'],
    341390  'WIDTH_IMG' => $picture_size[0],
    342391  'HEIGHT_IMG' => $picture_size[1],
    343   'COMMENT_IMG' => $picture['current']['comment'],
    344392
    345393  'L_SLIDESHOW' => $lang['slideshow'],
     
    356404  'L_AUTHOR' =>$lang['author'],
    357405  'L_COMMENT' =>$lang['comment'],
     406  'L_DOWNLOAD' => $lang['download'],
     407  'L_DOWNLOAD_HINT' => $lang['download_hint'],
    358408 
    359409  'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif',
    360410 
    361   'U_PREV_IMG' => add_session_id($picture['prev']['url']),
    362   'U_NEXT_IMG' => add_session_id($picture['next']['url']),
    363411  'U_HOME' => add_session_id($url_home),
    364412  'U_ADMIN' => add_session_id($url_admin),
     
    388436}
    389437
    390 if ($prev>=0) $template->assign_block_vars('previous', array());
    391 if ($next) $template->assign_block_vars('next', array());
     438if ($has_prev)
     439{
     440  $template->assign_block_vars(
     441    'previous',
     442    array(
     443      'TITLE_IMG' => $picture['prev']['name'],
     444      'IMG' => $picture['prev']['thumbnail'],
     445      'U_IMG' => add_session_id($picture['prev']['url'])
     446      ));
     447}
     448
     449if ($has_next)
     450{
     451  $template->assign_block_vars(
     452    'next',
     453    array(
     454      'TITLE_IMG' => $picture['next']['name'],
     455      'IMG' => $picture['next']['thumbnail'],
     456      'U_IMG' => add_session_id($picture['next']['url'])
     457      ));
     458}
    392459
    393460//--------------------------------------------------------- picture information
    394461// legend
    395 if ( !empty($picture['current']['comment']) )
    396 {
    397   $template->assign_block_vars('legend', array());
     462if (isset($picture['current']['comment'])
     463    and !empty($picture['current']['comment']))
     464{
     465  $template->assign_block_vars(
     466    'legend',
     467    array(
     468        'COMMENT_IMG' => $picture['current']['comment']
     469      ));
     470}
     471// download link if file is not a picture
     472if (!$picture['current']['is_picture'])
     473{
     474  $template->assign_block_vars(
     475    'download',
     476    array(
     477        'U_DOWNLOAD' => $picture['current']['download']
     478      ));
    398479}
    399480
     
    401482if ( !empty($picture['current']['author']) )
    402483{
    403   $template->assign_block_vars('info_line', array(
    404           'INFO'=>$lang['author'],
    405           'VALUE'=>$picture['current']['author']
    406           ));
     484  $template->assign_block_vars(
     485    'info_line',
     486    array(
     487      'INFO'=>$lang['author'],
     488      'VALUE'=>$picture['current']['author']
     489      ));
    407490}
    408491// creation date
     
    420503          ));
    421504// size in pixels
    422 if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] )
    423 {
    424   $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">';
    425   $content.= $original_width.'*'.$original_height.'</a> ]';
    426 }
    427 else
    428 {
    429   $content = $original_width.'*'.$original_height;
    430 }
    431 $template->assign_block_vars('info_line', array(
    432           'INFO'=>$lang['size'],
    433           'VALUE'=>$content
    434           ));
     505if ($picture['current']['is_picture'])
     506{
     507  if ($original_width != $picture_size[0]
     508      or $original_height != $picture_size[1])
     509  {
     510    $content = '[ <a href="'.$picture['current']['url'].'" ';
     511    $content.= ' title="'.$lang['true_size'].'">';
     512    $content.= $original_width.'*'.$original_height.'</a> ]';
     513  }
     514  else
     515  {
     516    $content = $original_width.'*'.$original_height;
     517  }
     518  $template->assign_block_vars(
     519    'info_line',
     520    array(
     521      'INFO'=>$lang['size'],
     522      'VALUE'=>$content
     523      ));
     524}
    435525// file
    436526$template->assign_block_vars('info_line', array(
Note: See TracChangeset for help on using the changeset viewer.