Changeset 579


Ignore:
Timestamp:
Oct 23, 2004, 7:56:46 PM (19 years ago)
Author:
z0rglub
Message:
  • refactoring of comments.php
  • creation of function get_thumbnail_src used everywhere a thumbnail must be displayed
  • creation of function parse_comment_content (used in comments.php and picture.php)
  • concerning undefined index on arrays retrieved in database, instead of testing possibly unset values, use of @ operator (smarter...)
  • add pre tag in default.css stylesheet for debugging purpose (need to have left aligned text)
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/infos_images.php

    r577 r579  
    320320  while ($row = mysql_fetch_array($result))
    321321  {
    322     if (!isset($array_cat_directories[$row['storage_category_id']]))
    323     {
    324       $array_cat_directories[$row['storage_category_id']] =
    325         get_complete_dir($row['storage_category_id']);
    326     }
    327 
    328     // thumbnail url
    329     if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    330     {
    331       $thumbnail_url = $array_cat_directories[$row['storage_category_id']];
    332       $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
    333       $thumbnail_url.= get_filename_wo_extension($row['file']);
    334       $thumbnail_url.= '.'.$row['tn_ext'];
    335     }
    336     else
    337     {
    338       $thumbnail_url = PHPWG_ROOT_PATH;
    339       $thumbnail_url = 'template/'.$user['template'].'/mimetypes/';
    340       $thumbnail_url.= strtolower(get_extension($row['file'])).'.png';
    341     }
    342 
    343     // some fields are nullable in the images table
    344     $nullables = array('name','author','keywords','date_creation','comment');
    345     foreach ($nullables as $field)
    346     {
    347       if (isset($row[$field]))
    348       {
    349         $$field = $row[$field];
    350       }
    351       else
    352       {
    353         $$field = '';
    354       }
    355     }
     322    $thumbnail_url = get_thumbnail_src($row['file'],
     323                                       $row['storage_category_id'],
     324                                       @$row['tn_ext']);
    356325
    357326    $template->assign_block_vars(
     
    363332        'FILENAME_IMG'=>$row['file'],
    364333        'DEFAULTNAME_IMG'=>get_filename_wo_extension($row['file']),
    365         'NAME_IMG'=>$name,
    366         'DATE_IMG'=>date_convert_back($date_creation),
    367         'AUTHOR_IMG'=>$author,
    368         'KEYWORDS_IMG'=>$keywords,
    369         'COMMENT_IMG'=>$comment
     334        'NAME_IMG'=>@$row['name'],
     335        'DATE_IMG'=>date_convert_back(@$row['date_creation']),
     336        'AUTHOR_IMG'=>@$row['author'],
     337        'KEYWORDS_IMG'=>@$row['keywords'],
     338        'COMMENT_IMG'=>@$row['comment']
    370339       ));
    371340  }
  • trunk/admin/picture_modify.php

    r577 r579  
    188188$row = mysql_fetch_array(mysql_query($query));
    189189
    190 // some fields are nullable in the images table
    191 $nullables = array('name','author','keywords','date_creation','comment',
    192                    'width','height');
    193 foreach ($nullables as $field)
    194 {
    195   if (!isset($row[$field]))
    196   {
    197     $row[$field] = '';
    198   }
    199 }
    200 
    201190if (empty($row['name']))
    202191{
     
    211200$dir_path = get_cat_display_name($current_category['name'], '->', '');
    212201
    213 // thumbnail url
    214 if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    215 {
    216   $thumbnail_url = get_complete_dir($row['storage_category_id']);
    217   $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
    218   $thumbnail_url.= get_filename_wo_extension($row['file']);
    219   $thumbnail_url.= '.'.$row['tn_ext'];
    220 }
    221 else
    222 {
    223   $thumbnail_url = PHPWG_ROOT_PATH;
    224   $thumbnail_url = 'template/'.$user['template'].'/mimetypes/';
    225   $thumbnail_url.= strtolower(get_extension($row['file'])).'.png';
    226 }
     202$thumbnail_url = get_thumbnail_src($row['file'],
     203                                   $row['storage_category_id'],
     204                                   @$row['tn_ext']);
    227205
    228206$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
    229207$url_img .= '&cat='.$row['storage_category_id'];
    230208$date = isset($_POST['date_creation']) && empty($errors)
    231           ?$_POST['date_creation']:date_convert_back($row['date_creation']);
     209          ?$_POST['date_creation']:date_convert_back(@$row['date_creation']);
    232210
    233211// retrieving all the linked categories
     
    258236  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
    259237  'FILE_IMG'=>$row['file'],
    260   'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'],
    261   'SIZE_IMG'=>$row['width'].' * '.$row['height'],
    262   'FILESIZE_IMG'=>$row['filesize'].' KB',
     238  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'],
     239  'SIZE_IMG'=>@$row['width'].' * '.@$row['height'],
     240  'FILESIZE_IMG'=>@$row['filesize'].' KB',
    263241  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
    264   'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'],
     242  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'],
    265243  'CREATION_DATE_IMG'=>$date,
    266   'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'],
    267   'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'],
     244  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'],
     245  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'],
    268246  'ASSOCIATED_CATEGORIES'=>$categories,
    269247 
  • trunk/comments.php

    r527 r579  
    2626// +-----------------------------------------------------------------------+
    2727
    28 //----------------------------------------------------------- include
     28// +-----------------------------------------------------------------------+
     29// |                           initialization                              |
     30// +-----------------------------------------------------------------------+
    2931if (!defined('IN_ADMIN'))
    3032{
    3133  define('PHPWG_ROOT_PATH','./');
    32   include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
    33 }
    34 
    35 //--------------------------------------------------- number of days to display
    36 if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
    37 else                               define( 'MAX_DAYS', 0 );
    38 //----------------------------------------- non specific section initialization
    39 $array_cat_directories = array();
    40 $array_cat_names       = array();
    41 $array_cat_site_id     = array();
    42 
    43 // comment deletion
    44 if ( isset( $_POST['delete'] ) )
    45 {
    46   $mod_sql='';
    47   while( list($id, $row_id) = @each($_POST['comment_id']) )
    48   {
    49         $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id;
    50   }
    51   $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id IN ('.$mod_sql.');';
    52   mysql_query( $query );
    53 }
    54 
    55 //--------------------------------------------------------- comments validation
    56 if ( isset( $_POST['validate'] ) )
    57 {
    58   $mod_sql='';
    59   while( list($id, $row_id) = @each($_POST['comment_id']) )
    60   {
    61         $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id;
    62   }
    63   $query = 'UPDATE '.COMMENTS_TABLE;
    64   $query.= " SET validated = 'true'";
    65   $query.=' WHERE id IN ('.$mod_sql.');';
    66   mysql_query( $query );
    67 }
    68 //------------------------------------------------------- last comments display
    69 
    70 //
    71 // Start output of page
    72 //
     34  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
     35}
     36
     37if (isset($_GET['last_days']))
     38{
     39  define('MAX_DAYS', $_GET['last_days']);
     40}
     41else
     42{
     43  define('MAX_DAYS', 0);
     44}
     45$array_cat_names = array();
     46// +-----------------------------------------------------------------------+
     47// |                         comments management                           |
     48// +-----------------------------------------------------------------------+
     49// comments deletion
     50if (isset($_POST['delete']) and count($_POST['comment_id']) > 0)
     51{
     52  $query = '
     53DELETE FROM '.COMMENTS_TABLE.'
     54  WHERE id IN ('.implode(',', $_POST['comment_id']).')
     55;';
     56  mysql_query($query);
     57}
     58// comments validation
     59if (isset($_POST['validate']) and count($_POST['comment_id']) > 0)
     60{
     61  $query = '
     62UPDATE '.COMMENTS_TABLE.'
     63  SET validated = \'true\'
     64  WHERE id IN ('.implode(',', $_POST['comment_id']).')
     65;';
     66  mysql_query($query);
     67}
     68// +-----------------------------------------------------------------------+
     69// |                       page header and options                         |
     70// +-----------------------------------------------------------------------+
    7371if (!defined('IN_ADMIN'))
    7472{
     
    7775}
    7876
    79 $template->set_filenames( array('comments'=>'comments.tpl') );
    80 $template->assign_vars(array(
    81   'L_COMMENT_TITLE' => $title,
    82   'L_COMMENT_STATS' => $lang['stats_last_days'],
    83   'L_COMMENT_RETURN' => $lang['return_main_page'],
    84   'L_DELETE' =>$lang['delete'],
    85   'L_VALIDATE'=>$lang['submit'],
    86  
    87   'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif',
    88  
    89   'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' )
    90   )
    91 );
    92 
    93 foreach ( $conf['last_days'] as $option ) {
     77$template->set_filenames(array('comments'=>'comments.tpl'));
     78$template->assign_vars(
     79  array(
     80    'L_COMMENT_TITLE' => $title,
     81    'L_COMMENT_STATS' => $lang['stats_last_days'],
     82    'L_COMMENT_RETURN' => $lang['return_main_page'],
     83    'L_DELETE' =>$lang['delete'],
     84    'L_VALIDATE'=>$lang['submit'],
     85   
     86    'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php')
     87    )
     88  );
     89
     90foreach ($conf['last_days'] as $option)
     91{
    9492  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
    95   if (defined('IN_ADMIN')) $url.= '&page=comments';
     93  if (defined('IN_ADMIN'))
     94  {
     95    $url.= '&page=comments';
     96  }
    9697  $template->assign_block_vars(
    9798    'last_day_option',
    9899    array(
    99100      'OPTION'=>$option,
    100       'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
    101       'U_OPTION'=>add_session_id( $url )
     101      'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''),
     102      'U_OPTION'=>add_session_id($url)
    102103      )
    103104    );
    104105}
    105 
     106// +-----------------------------------------------------------------------+
     107// |                        last comments display                          |
     108// +-----------------------------------------------------------------------+
    106109// 1. retrieving picture ids which have comments recently added
    107 $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
    108 list($year,$month,$day) = explode( '-', $date);
    109 $maxtime = mktime( 0,0,0,$month,$day,$year );
    110 $query = 'SELECT DISTINCT(ic.image_id) as image_id,';
    111 $query.= '(ic.category_id) as category_id';
    112 $query.= ' FROM '.COMMENTS_TABLE.' AS c';
    113 $query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic';
    114 $query.= ' WHERE c.image_id = ic.image_id';
    115 $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')';
    116 if ( $user['status'] != 'admin' )
    117 {
    118   $query.= " AND validated = 'true'";
     110$maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day'));
     111
     112$query = '
     113SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id
     114  FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic
     115  WHERE c.image_id = ic.image_id
     116    AND date >= \''.$maxdate.'\'';
     117if ($user['status'] != 'admin')
     118{
     119  $query.= "
     120    AND validated = 'true'";
    119121  // we must not show pictures of a forbidden category
    120   if ( $user['forbidden_categories'] != '' )
    121   {
    122     $query.= ' AND category_id NOT IN ';
    123     $query.= '('.$user['forbidden_categories'].')';
    124   }
    125 }
    126 $query.= ' ORDER BY ic.image_id DESC';
    127 $query.= ';';
    128 $result = mysql_query( $query );
    129 if ( $user['status'] == 'admin' )
     122  if ($user['forbidden_categories'] != '')
     123  {
     124    $query.= '
     125    AND category_id NOT IN ('.$user['forbidden_categories'].')';
     126  }
     127}
     128$query.= '
     129  ORDER BY ic.image_id DESC
     130;';
     131$result = mysql_query($query);
     132if ($user['status'] == 'admin')
    130133{
    131134  $template->assign_block_vars('validation', array());
    132135}
    133 while ( $row = mysql_fetch_array( $result ) )
    134   {
    135     $category_id=$row['category_id'];
    136 
    137     // for each picture, getting informations for displaying thumbnail and
    138     // link to the full size picture
    139     $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
    140     $query.= ' FROM '.IMAGES_TABLE;
    141     $query.= ' WHERE id = '.$row['image_id'];
    142     $query.= ';';
    143     $subresult = mysql_query( $query );
    144     $subrow = mysql_fetch_array( $subresult );
    145 
    146     if ( !isset($array_cat_directories[$subrow['cat_id']]) )
     136while ($row = mysql_fetch_array($result))
     137{
     138  $category_id = $row['category_id'];
     139 
     140  // for each picture, getting informations for displaying thumbnail and
     141  // link to the full size picture
     142  $query = '
     143SELECT name,file,storage_category_id as cat_id,tn_ext
     144  FROM '.IMAGES_TABLE.'
     145  WHERE id = '.$row['image_id'].'
     146;';
     147  $subresult = mysql_query($query);
     148  $subrow = mysql_fetch_array($subresult);
     149
     150  if (!isset($array_cat_names[$subrow['cat_id']]))
     151  {
     152    $cat_result = get_cat_info($subrow['cat_id']);
     153    $array_cat_names[$subrow['cat_id']] =
     154      get_cat_display_name($cat_result['name'], ' > ', '');
     155  }
     156 
     157  // name of the picture
     158  $name = $array_cat_names[$category_id].' > ';
     159  if (!empty($subrow['name']))
     160  {
     161    $name.= $subrow['name'];
     162  }
     163  else
     164  {
     165    $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file']));
     166  }
     167  $name.= ' [ '.$subrow['file'].' ]';
     168  // source of the thumbnail picture
     169  $thumbnail_src = get_thumbnail_src($subrow['file'],
     170                                     $subrow['cat_id'],
     171                                     @$subrow['tn_ext']);
     172  // link to the full size picture
     173  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
     174  $url.= '&image_id='.$row['image_id'];
     175   
     176  $template->assign_block_vars(
     177    'picture',
     178    array(
     179      'TITLE_IMG'=>$name,
     180      'I_THUMB'=>$thumbnail_src,
     181      'U_THUMB'=>add_session_id($url)
     182      ));
     183   
     184  // for each picture, retrieving all comments
     185  $query = '
     186SELECT *
     187  FROM '.COMMENTS_TABLE.'
     188  WHERE image_id = '.$row['image_id'].'
     189    AND date >= \''.$maxdate.'\'';
     190  if ($user['status'] != 'admin')
     191  {
     192    $query.= '
     193    AND validated = \'true\'';
     194  }
     195  $query.= '
     196  ORDER BY date DESC
     197;';
     198  $handleresult = mysql_query($query);
     199  while ($subrow = mysql_fetch_array($handleresult))
     200  {
     201    $author = $subrow['author'];
     202    if (empty($subrow['author']))
    147203    {
    148       $array_cat_directories[$subrow['cat_id']] =
    149         get_complete_dir( $subrow['cat_id'] );
    150       $cat_result = get_cat_info( $subrow['cat_id'] );
    151       $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
    152       $array_cat_names[$subrow['cat_id']] =
    153         get_cat_display_name( $cat_result['name'], ' > ', '' );
     204      $author = $lang['guest'];
    154205    }
    155206
    156     $file = get_filename_wo_extension( $subrow['file'] );
    157     // name of the picture
    158     $name = $array_cat_names[$category_id].' > ';
    159     if (!empty($subrow['name'])) $name.= $subrow['name'];
    160     else                         $name.= str_replace( '_', ' ', $file );
    161     $name.= ' [ '.$subrow['file'].' ]';
    162     // source of the thumbnail picture
    163     if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '')
     207    $template->assign_block_vars(
     208      'picture.comment',
     209      array(
     210        'COMMENT_AUTHOR'=>$author,
     211        'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true),
     212        'COMMENT'=>parse_comment_content($subrow['content']),
     213        ));
     214   
     215    if ($user['status'] == 'admin')
    164216    {
    165       $src = $array_cat_directories[$subrow['cat_id']];
    166       $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
    167       $src.= $file.'.'.$subrow['tn_ext'];
     217      $template->assign_block_vars(
     218        'picture.comment.validation',
     219        array(
     220          'ID'=> $subrow['id'],
     221          'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
     222          ));
    168223    }
    169     else
    170     {
    171       $src = './template/'.$user['template'].'/mimetypes/';
    172       $src.= strtolower(get_extension($subrow['file'])).'.png';
    173     }
    174    
    175     // link to the full size picture
    176     $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
    177     $url.= '&image_id='.$row['image_id'];
    178    
    179     $template->assign_block_vars(
    180       'picture',
    181       array(
    182         'TITLE_IMG'=>$name,
    183         'I_THUMB'=>$src,
    184         'U_THUMB'=>add_session_id( $url )
    185         ));
    186    
    187     // for each picture, retrieving all comments
    188     $query = 'SELECT * FROM '.COMMENTS_TABLE;
    189     $query.= ' WHERE image_id = '.$row['image_id'];
    190     $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')';
    191     if ( $user['status'] != 'admin' )
    192     {
    193       $query.= " AND validated = 'true'";
    194     }
    195     $query.= ' ORDER BY date DESC';
    196     $query.= ';';
    197     $handleresult = mysql_query( $query );
    198     while ( $subrow = mysql_fetch_array( $handleresult ) )
    199     {
    200       $author = $subrow['author'];
    201       if ( empty($subrow['author'] )) $author = $lang['guest'];
    202       $content = nl2br( $subrow['content'] );
    203      
    204       // replace _word_ by an underlined word
    205       $pattern = '/_([^\s]*)_/';
    206       $replacement = '<span style="text-decoration:underline;">\1</span>';
    207       $content = preg_replace( $pattern, $replacement, $content );
    208      
    209       // replace *word* by a bolded word
    210       $pattern = '/\*([^\s]*)\*/';
    211       $replacement = '<span style="font-weight:bold;">\1</span>';
    212       $content = preg_replace( $pattern, $replacement, $content );
    213 
    214       // replace /word/ by an italic word
    215       $pattern = '/\/([^\s]*)\//';
    216       $replacement = '<span style="font-style:italic;">\1</span>';
    217       $content = preg_replace( $pattern, $replacement, $content );
    218       $template->assign_block_vars(
    219         'picture.comment',array(
    220           'COMMENT_AUTHOR'=>$author,
    221           'COMMENT_DATE'=>format_date( $subrow['date'],'mysql_datetime',true ),
    222           'COMMENT'=>$content,
    223           ));
    224       if ( $user['status'] == 'admin' )
    225       {
    226         $template->assign_block_vars(
    227           'picture.comment.validation', array(
    228             'ID'=> $subrow['id'],
    229             'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
    230             ));
    231       }
    232     }
    233   }
    234 //----------------------------------------------------------- html code display
     224  }
     225}
     226// +-----------------------------------------------------------------------+
     227// |                           html code display                           |
     228// +-----------------------------------------------------------------------+
    235229if (defined('IN_ADMIN'))
    236230{
  • trunk/include/category_calendar.inc.php

    r514 r579  
    230230    $row = mysql_fetch_array(mysql_query($query));
    231231   
    232     $file = get_filename_wo_extension($row['file']);
    233    
    234     // creating links for thumbnail and associated category
    235     if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    236     {
    237       $thumbnail_link = get_complete_dir($row['storage_category_id']);
    238       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    239       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    240     }
    241     else
    242     {
    243       $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    244       $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
    245     }
     232    $thumbnail_src = get_thumbnail_src($row['file'],
     233                                       $row['storage_category_id'],
     234                                       @$row['tn_ext']);
    246235   
    247236    $name = $calendar_year.' ('.$nb_pics.')';
     
    255244      'thumbnails.line.thumbnail',
    256245      array(
    257         'IMAGE'=>$thumbnail_link,
     246        'IMAGE'=>$thumbnail_src,
    258247        'IMAGE_ALT'=>$row['file'],
    259248        'IMAGE_TITLE'=>$thumbnail_title,
     
    289278    $row = mysql_fetch_array(mysql_query($query));
    290279   
    291     $file = get_filename_wo_extension($row['file']);
    292 
    293     // creating links for thumbnail and associated category
    294     if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    295     {
    296       $thumbnail_link = get_complete_dir($row['storage_category_id']);
    297       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    298       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    299     }
    300     else
    301     {
    302       $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    303       $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
    304     }
    305      
     280    $thumbnail_src = get_thumbnail_src($row['file'],
     281                                       $row['storage_category_id'],
     282                                       @$row['tn_ext']);
     283   
    306284    $name = $lang['month'][$calendar_month];
    307285    $name.= ' '.$page['calendar_year'];
     
    322300      'thumbnails.line.thumbnail',
    323301      array(
    324         'IMAGE'=>$thumbnail_link,
     302        'IMAGE'=>$thumbnail_src,
    325303        'IMAGE_ALT'=>$row['file'],
    326304        'IMAGE_TITLE'=>$thumbnail_title,
     
    355333    $row = mysql_fetch_array(mysql_query($query));
    356334   
    357     $file = get_filename_wo_extension($row['file']);
    358    
    359     // creating links for thumbnail and associated category
    360     if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    361     {
    362       $thumbnail_link = get_complete_dir($row['storage_category_id']);
    363       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    364       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    365     }
    366     else
    367     {
    368       $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    369       $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
    370     }
     335    $thumbnail_src = get_thumbnail_src($row['file'],
     336                                       $row['storage_category_id'],
     337                                       @$row['tn_ext']);
    371338
    372339    list($year,$month,$day) = explode('-', $calendar_day);
     
    384351      'thumbnails.line.thumbnail',
    385352      array(
    386         'IMAGE'=>$thumbnail_link,
     353        'IMAGE'=>$thumbnail_src,
    387354        'IMAGE_ALT'=>$row['file'],
    388355        'IMAGE_TITLE'=>$thumbnail_title,
     
    435402    $row = mysql_fetch_array(mysql_query($query));
    436403   
    437     $file = get_filename_wo_extension($row['file']);
    438    
    439     // creating links for thumbnail and associated category
    440     if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    441     {
    442       $thumbnail_link = get_complete_dir($row['storage_category_id']);
    443       $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    444       $thumbnail_link.= $file.'.'.$row['tn_ext'];
    445     }
    446     else
    447     {
    448       $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    449       $thumbnail_link.= strtolower(get_extension($row['file'])).'.png';
    450     }
     404    $thumbnail_src = get_thumbnail_src($row['file'],
     405                                       $row['storage_category_id'],
     406                                       @$row['tn_ext']);
    451407   
    452408    $thumbnail_title = $lang['calendar_picture_hint'].$name;
     
    462418      'thumbnails.line.thumbnail',
    463419      array(
    464         'IMAGE'=>$thumbnail_link,
     420        'IMAGE'=>$thumbnail_src,
    465421        'IMAGE_ALT'=>$row['file'],
    466422        'IMAGE_TITLE'=>$thumbnail_title,
  • trunk/include/category_default.inc.php

    r578 r579  
    6262while ($row = mysql_fetch_array($result))
    6363{
    64   // retrieving the storage dir of the picture
    65   if (!isset($array_cat_directories[$row['storage_category_id']]))
    66   {
    67     $array_cat_directories[$row['storage_category_id']] =
    68       get_complete_dir($row['storage_category_id']);
    69   }
    70   $cat_directory = $array_cat_directories[$row['storage_category_id']];
    71 
    72   $file = get_filename_wo_extension($row['file']);
    7364  // name of the picture
    7465  if (isset($row['name']) and $row['name'] != '')
     
    7869  else
    7970  {
    80     $name = str_replace('_', ' ', $file);
     71    $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
    8172  }
    8273  if ($page['cat'] == 'best_rated')
     
    8980    $name = replace_search($name, $_GET['search']);
    9081  }
    91   // thumbnail url
    92   if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    93   {
    94     $thumbnail_url = $cat_directory;
    95     $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
    96     $thumbnail_url.= $file.'.'.$row['tn_ext'];
    97   }
    98   else
    99   {
    100     $thumbnail_url = PHPWG_ROOT_PATH;
    101     $thumbnail_url.= 'template/'.$user['template'].'/mimetypes/';
    102     $thumbnail_url.= strtolower(get_extension($row['file'])).'.png';
    103   }
     82 
     83  $thumbnail_url = get_thumbnail_src($row['file'],
     84                                     $row['storage_category_id'],
     85                                     @$row['tn_ext']);
    10486 
    10587  // message in title for the thumbnail
  • trunk/include/category_recent_cats.inc.php

    r470 r579  
    7878  $subrow = mysql_fetch_array( mysql_query( $query ) );
    7979
    80   $file = get_filename_wo_extension( $subrow['file'] );
    81    
    82   // creating links for thumbnail and associated category
    83   if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '')
    84   {
    85     $thumbnail_link = get_complete_dir($subrow['storage_category_id']);
    86     $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    87     $thumbnail_link.= $file.'.'.$subrow['tn_ext'];
    88   }
    89   else
    90   {
    91     $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    92     $thumbnail_link.= strtolower(get_extension($subrow['file'])).'.png';
    93   }
     80  $thumbnail_src = get_thumbnail_src($subrow['file'],
     81                                     $subrow['storage_category_id'],
     82                                     @$subrow['tn_ext']);
    9483 
    9584  $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
     
    9887    'thumbnails.line.thumbnail',
    9988    array(
    100       'IMAGE'                   => $thumbnail_link,
     89      'IMAGE'                   => $thumbnail_src,
    10190      'IMAGE_ALT'               => $subrow['file'],
    10291      'IMAGE_TITLE'             => $lang['hint_category'],
  • trunk/include/category_subcats.inc.php

    r470 r579  
    8787  $image_row    = mysql_fetch_array($image_result);
    8888
    89   $file = get_filename_wo_extension($image_row['file']);
    90 
    91   // creating links for thumbnail and associated category
    92   if (isset($image_row['tn_ext']) and $image_row['tn_ext'] != '')
    93   {
    94     $thumbnail_link = get_complete_dir($image_row['storage_category_id']);
    95     $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
    96     $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
    97   }
    98   else
    99   {
    100     $thumbnail_link = './template/'.$user['template'].'/mimetypes/';
    101     $thumbnail_link.= strtolower(get_extension($image_row['file'])).'.png';
    102   }
     89  $thumbnail_link = get_thumbnail_src($image_row['file'],
     90                                      $image_row['storage_category_id'],
     91                                      @$image_row['tn_ext']);
    10392
    10493  $thumbnail_title = $lang['hint_category'];
  • trunk/include/functions.inc.php

    r537 r579  
    547547  return get_dirs(PHPWG_ROOT_PATH.'template');
    548548}
     549
     550/**
     551 * returns thumbnail filepath (or distant URL if thumbnail is remote) for a
     552 * given element
     553 *
     554 * this function could have taken only the element id as parameter but to
     555 * optimize database access we directly ask file, storage category
     556 * identifier and extension since when this function is called,
     557 * PhpWebGallery should have all these infos. No need to retrieve them
     558 * another time in the database.
     559 *
     560 * the returned string can represente the filepath of the thumbnail or the
     561 * filepath to the corresponding icon for non picture elements
     562 *
     563 * complete directories are cached to be used more than once during a page
     564 * generation (many thumbnails of the same category on the same page)
     565 *
     566 * @param string file
     567 * @param int storage_category_id
     568 * @param string tn_ext
     569 * @return string
     570 */
     571function get_thumbnail_src($file, $storage_category_id, $tn_ext = '')
     572{
     573  global $conf, $user, $array_cat_directories;
     574 
     575  if (!isset($array_cat_directories[$storage_category_id]))
     576  {
     577    $array_cat_directories[$storage_category_id] =
     578      get_complete_dir($storage_category_id);
     579  }
     580 
     581  if ($tn_ext != '')
     582  {
     583    $src = $array_cat_directories[$storage_category_id];
     584    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
     585    $src.= get_filename_wo_extension($file);
     586    $src.= '.'.$tn_ext;
     587  }
     588  else
     589  {
     590    $src = PHPWG_ROOT_PATH;
     591    $src.= 'template/'.$user['template'].'/mimetypes/';
     592    $src.= strtolower(get_extension($file)).'.png';
     593  }
     594
     595  return $src;
     596}
    549597?>
  • trunk/include/functions_category.inc.php

    r510 r579  
    346346function get_complete_dir( $category_id )
    347347{
    348   return get_site_url( $category_id ).get_local_dir( $category_id );
     348  return get_site_url($category_id).get_local_dir($category_id);
    349349}
    350350
     
    384384    $database_dirs[$row['id']] = $row['dir'];
    385385  }
    386   foreach ( $upper_array as $id ) {
     386  foreach ($upper_array as $id)
     387  {
    387388    $local_dir.= $database_dirs[$id].'/';
    388389  }
     
    393394// retrieving the site url : "http://domain.com/gallery/" or
    394395// simply "./galleries/"
    395 function get_site_url( $category_id )
     396function get_site_url($category_id)
    396397{
    397398  global $page;
    398399
    399   $query = 'SELECT galleries_url';
    400   $query.= ' FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c';
    401   $query.= ' WHERE s.id = c.site_id';
    402   $query.= ' AND c.id = '.$category_id;
    403   $query.= ';';
    404   $row = mysql_fetch_array( mysql_query( $query ) );
     400  $query = '
     401SELECT galleries_url
     402  FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c
     403  WHERE s.id = c.site_id
     404    AND c.id = '.$category_id.'
     405;';
     406  $row = mysql_fetch_array(mysql_query($query));
    405407  return $row['galleries_url'];
    406408}
  • trunk/include/functions_html.inc.php

    r572 r579  
    270270  return $menu;
    271271}
     272
     273/**
     274 * returns HTMLized comment contents retrieved from database
     275 *
     276 * newlines becomes br tags, _word_ becomes underline, /word/ becomes
     277 * italic, *word* becomes bolded
     278 *
     279 * @param string content
     280 * @return string
     281 */
     282function parse_comment_content($content)
     283{
     284  $content = nl2br($content);
     285 
     286  // replace _word_ by an underlined word
     287  $pattern = '/_([^\s]*)_/';
     288  $replacement = '<span style="text-decoration:underline;">\1</span>';
     289  $content = preg_replace($pattern, $replacement, $content);
     290 
     291  // replace *word* by a bolded word
     292  $pattern = '/\*([^\s]*)\*/';
     293  $replacement = '<span style="font-weight:bold;">\1</span>';
     294  $content = preg_replace($pattern, $replacement, $content);
     295 
     296  // replace /word/ by an italic word
     297  $pattern = '/\/([^\s]*)\//';
     298  $replacement = '<span style="font-style:italic;">\1</span>';
     299  $content = preg_replace($pattern, $replacement, $content);
     300
     301  return $content;
     302}
    272303?>
  • trunk/picture.php

    r576 r579  
    182182  }
    183183
    184   if (isset($row['tn_ext']) and $row['tn_ext'] != '')
    185   {
    186     $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/';
    187     $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext;
    188     $picture[$i]['thumbnail'].= '.'.$row['tn_ext'];
    189   }
    190   else
    191   {
    192     $picture[$i]['thumbnail'] = $icon;
    193   }
     184  $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'],
     185                                                $row['storage_category_id'],
     186                                                @$row['tn_ext']);
    194187 
    195188  if ( !empty( $row['name'] ) )
     
    962955  while ( $row = mysql_fetch_array( $result ) )
    963956  {
    964     $content = nl2br( $row['content'] );
    965 
    966     // replace _word_ by an underlined word
    967     $pattern = '/_([^\s]*)_/';
    968     $replacement = '<span style="text-decoration:underline;">\1</span>';
    969     $content = preg_replace( $pattern, $replacement, $content );
    970 
    971     // replace *word* by a bolded word
    972     $pattern = '/\*([^\s]*)\*/';
    973     $replacement = '<span style="font-weight:bold;">\1</span>';
    974     $content = preg_replace( $pattern, $replacement, $content );
    975 
    976     // replace /word/ by an italic word
    977     $pattern = '/\/([^\s]*)\//';
    978     $replacement = '<span style="font-style:italic;">\1</span>';
    979     $content = preg_replace( $pattern, $replacement, $content );
    980        
    981     $template->assign_block_vars('comments.comment', array(
    982     'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
    983     'COMMENT_DATE'=>format_date( $row['date'], 'mysql_datetime', true ),
    984         'COMMENT'=>$content
     957    $template->assign_block_vars(
     958      'comments.comment',
     959      array(
     960        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
     961        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
     962        'COMMENT'=>parse_comment_content($row['content'])
    985963        ));
    986964       
    987965    if ( $user['status'] == 'admin' )
    988966    {
    989           $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'] )));
    990     }
    991   }
    992 
    993   if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) )
     967      $template->assign_block_vars(
     968        'comments.comment.delete',
     969        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
     970          ));
     971    }
     972  }
     973
     974  if (!$user['is_the_guest']
     975      or ($user['is_the_guest'] and $conf['comments_forall']))
    994976  {
    995977    $template->assign_block_vars('comments.add_comment', array());
    996978    // display author field if the user is not logged in
    997     if ( !$user['is_the_guest'] )
    998     {
    999       $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username']));
    1000         }
     979    if (!$user['is_the_guest'])
     980    {
     981      $template->assign_block_vars(
     982        'comments.add_comment.author_known',
     983        array('KNOWN_AUTHOR'=>$user['username'])
     984        );
     985    }
    1001986    else
    1002987    {
    1003       $template->assign_block_vars('comments.add_comment.author_field', array());
     988      $template->assign_block_vars(
     989        'comments.add_comment.author_field', array()
     990        );
    1004991    }
    1005992  }
  • trunk/template/default/default.css

    r554 r579  
    421421  text-align:center;
    422422}
     423
     424/* for debugging purpose */
     425pre {
     426  text-align:left;
     427}
Note: See TracChangeset for help on using the changeset viewer.