Ignore:
Timestamp:
Mar 11, 2008, 3:04:27 AM (16 years ago)
Author:
rvelices
Message:
  • remove $confsubcatify (it was my reqquest to Pierrick when plugins were not available; now it can be done through plugin)
  • optimization when show_nb_comments true (1 sql query per page instead of 1 query per element)
  • some cleanup & more standard trigger names
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_default.inc.php

    r2234 r2274  
    5959}
    6060
    61 // template thumbnail initialization
    62 $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
    6361if (count($pictures) > 0)
    6462{
     
    7977    );
    8078
    81     $template->clear_assign('thumbnails'); // category_default reuse them
     79  if ($user['show_nb_comments'])
     80  {
     81    $query = '
     82SELECT image_id, COUNT(*) AS nb_comments
     83  FROM '.COMMENTS_TABLE.'
     84  WHERE validated = \'true\'
     85    AND image_id IN ('.implode(',', $selection).')
     86  GROUP BY image_id
     87;';
     88    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
     89  }
    8290}
     91
     92// template thumbnail initialization
     93$template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',));
    8394
    8495trigger_action('loc_begin_index_thumbnails', $pictures);
     
    99110  $tpl_var =
    100111    array(
    101       'IMAGE'              => $thumbnail_url,
    102       'IMAGE_ALT'          => $row['file'],
    103       'IMAGE_TITLE'        => get_thumbnail_title($row),
    104       'IMAGE_TS'           => get_icon($row['date_available']),
    105 
    106       'U_IMG_LINK'         => $url,
    107 
    108       'CLASS'              => 'thumbElmt',
     112      'ID'            => $row['id'],
     113      'IMAGE'         => $thumbnail_url,
     114      'IMAGE_ALT'     => $row['file'],
     115      'IMAGE_TITLE'   => get_thumbnail_title($row),
     116      'IMAGE_TS'      => get_icon($row['date_available']),
     117      'U_IMG_LINK'    => $url,
    109118    );
    110119
    111120  if ($user['show_nb_hits'])
    112121  {
    113     $tpl_var['nb_hits'] =
    114       array(
    115       'HITS'=> $row['hit'],
    116       'CLASS'=> set_span_class($row['hit']),
    117       );
     122    $tpl_var['NB_HITS'] = $row['hit'];
    118123  }
    119124
     
    149154  }
    150155
    151   if ($user['show_nb_comments'])
     156  if ( isset($nb_comments_of) )
    152157  {
    153     $query = '
    154 SELECT COUNT(*) AS nb_comments
    155   FROM '.COMMENTS_TABLE.'
    156   WHERE image_id = '.$row['id'].'
    157     AND validated = \'true\'
    158 ;';
    159     list($row['nb_comments']) = mysql_fetch_array(pwg_query($query));
    160     $tpl_var['nb_comments'] =
    161       array(
    162         'NB_COMMENTS'=> $row['nb_comments'],
    163         'CLASS'=> set_span_class($row['nb_comments']),
    164       );
     158    $row['nb_comments'] = isset($nb_comments_of[$row['id']])
     159        ? (int)$nb_comments_of[$row['id']] : 0;
     160    $tpl_var['NB_COMMENTS'] = $row['nb_comments'];
    165161  }
    166162
     163  //plugins need to add/modify sth in this loop ?
     164  $tpl_var = trigger_event('loc_index_thumbnail', $tpl_var, $row);
     165
    167166  $template->append('thumbnails', $tpl_var);
    168 
    169   //plugins need to add/modify sth in this loop ?
    170   trigger_action('loc_index_thumbnail', $row, 'thumbnails' );
    171167}
    172168
    173169trigger_action('loc_end_index_thumbnails', $pictures);
    174 $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
     170$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
    175171
    176172pwg_debug('end include/category_default.inc.php');
Note: See TracChangeset for help on using the changeset viewer.