Changeset 2274


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
Location:
trunk
Files:
4 edited

Legend:

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

    r2234 r2274  
    216216  }
    217217
     218  $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
     219
    218220  trigger_action('loc_begin_index_category_thumbnails', $categories);
    219   if ($conf['subcatify'])
    220   {
    221     $template->set_filename('mainpage_categories', 'mainpage_categories.tpl');
    222 
    223     foreach ($categories as $category)
    224     {
    225       if ($page['section']=='recent_cats')
    226       {
    227         $name = get_cat_display_name_cache($category['uppercats'], null, false);
    228       }
    229       else
    230       {
    231         $name = $category['name'];
    232       }
    233 
    234       $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
    235 
    236       $tpl_var =
     221
     222  foreach ($categories as $category)
     223  {
     224    if ($page['section']=='recent_cats')
     225    {
     226      $name = get_cat_display_name_cache($category['uppercats'], null, false);
     227    }
     228    else
     229    {
     230      $name = $category['name'];
     231    }
     232
     233    $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
     234
     235    $tpl_var =
    237236        array(
    238237          'ID'    => $category['id'],
     
    260259                'subcatify_category_description')),
    261260          'NAME'  => $name,
    262           );
    263 
    264       if ($conf['display_fromto'])
     261        );
     262
     263    if ($conf['display_fromto'])
     264    {
     265      if (isset($dates_of_category[ $category['id'] ]))
    265266      {
    266         if (isset($dates_of_category[ $category['id'] ]))
     267        $from = $dates_of_category[ $category['id'] ]['from'];
     268        $to   = $dates_of_category[ $category['id'] ]['to'];
     269
     270        if (!empty($from))
    267271        {
    268           $from = $dates_of_category[ $category['id'] ]['from'];
    269           $to   = $dates_of_category[ $category['id'] ]['to'];
    270 
    271           if (!empty($from))
     272          $info = '';
     273
     274          if ($from == $to)
    272275          {
    273             $info = '';
    274 
    275             if ($from == $to)
    276             {
    277               $info = format_date($from);
    278             }
    279             else
    280             {
    281               $info = sprintf(
    282                 l10n('from %s to %s'),
    283                 format_date($from),
    284                 format_date($to)
    285                 );
    286             }
    287             $tpl_var['INFO_DATES'] = $info;
     276            $info = format_date($from);
    288277          }
     278          else
     279          {
     280            $info = sprintf(
     281              l10n('from %s to %s'),
     282              format_date($from),
     283              format_date($to)
     284              );
     285          }
     286          $tpl_var['INFO_DATES'] = $info;
    289287        }
    290       }//fromto
    291 
    292       $template->append( 'category_thumbnails', $tpl_var);
    293 
    294 
    295       //plugins need to add/modify sth in this loop ?
    296       trigger_action('loc_index_category_thumbnail',
    297         $category, 'categories.category' );
    298     }
    299 
    300     $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
    301   }
    302   else
    303   {
    304     $template->set_filename( 'thumbnails', 'thumbnails.tpl');
    305 
    306     if ($page['section']=='recent_cats')
    307     {
    308       $old_level_separator = $conf['level_separator'];
    309       $conf['level_separator'] = '<br />';
    310     }
    311 
    312     foreach ($categories as $category)
    313     {
    314       $tpl_var =
    315         array(
    316           'IMAGE'       => $thumbnail_src_of[ $category['representative_picture_id'] ],
    317           'IMAGE_ALT'   => $category['name'],
    318           'IMAGE_TITLE' => get_display_images_count
    319                                   (
    320                                     $category['nb_images'],
    321                                     $category['count_images'],
    322                                     $category['count_categories'],
    323                                     true,
    324                                     ' / '
    325                                   ),
    326 
    327           'U_IMG_LINK'  => make_index_url(
    328             array(
    329               'category' => $category
    330               )
    331             ),
    332           'CLASS'       => 'thumbCat',
    333           );
    334       if ($page['section']=='recent_cats')
    335       {
    336         $name = get_cat_display_name_cache($category['uppercats'], null, false);
    337288      }
    338       else
    339       {
    340         $name = $category['name'];
    341         $tpl_var['IMAGE_TS'] = get_icon($category['max_date_last'], $category['is_child_date_last']);
    342       }
    343       $tpl_var['CATEGORY_NAME']=$name;
    344 
    345       $template->append('thumbnails', $tpl_var);
    346 
    347       //plugins need to add/modify sth in this loop ?
    348       trigger_action('loc_index_category_thumbnail',
    349         $category, 'thumbnails' );
    350 
    351     }
    352 
    353     if ( isset($old_level_separator) )
    354     {
    355       $conf['level_separator']=$old_level_separator;
    356     }
    357 
    358     $template->assign_var_from_handle('CATEGORIES', 'thumbnails');
    359   }
     289    }//fromto
     290
     291    //plugins need to add/modify sth in this loop ?
     292    $tpl_var = trigger_event('loc_index_category_thumbnail',
     293                  $tpl_var, $category );
     294
     295    $template->append( 'category_thumbnails', $tpl_var);
     296  }
     297
    360298  trigger_action('loc_end_index_category_thumbnails', $categories);
     299  $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
    361300}
    362301?>
  • 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');
  • trunk/include/config_default.inc.php

    r2218 r2274  
    222222// name ?
    223223$conf['show_picture_name_on_title'] = true;
    224 
    225 // subcatify: display thumbnails representing a category a different way
    226 // than thumbnails representing a picture.
    227 $conf['subcatify'] = true;
    228224
    229225// display_fromto: in subcatify mode, display the date creation bounds of a
  • trunk/template/yoga/thumbnails.tpl

    r2234 r2274  
    44<ul class="thumbnails">
    55{foreach from=$thumbnails item=thumbnail}
    6         <li class="{$thumbnail.CLASS}">
     6        <li>
    77        <span class="wrap1">
    88                <span class="wrap2">
    99                <a href="{$thumbnail.U_IMG_LINK}">
    10                         <img class="thumbnail" src="{$thumbnail.IMAGE}"
    11                 alt="{$thumbnail.IMAGE_ALT}"
    12                 title="{$thumbnail.IMAGE_TITLE}">
     10                        <img class="thumbnail" src="{$thumbnail.IMAGE}" alt="{$thumbnail.IMAGE_ALT}" title="{$thumbnail.IMAGE_TITLE}" />
    1311                </a>
    1412                </span>
     
    1614
    1715                {if !empty($thumbnail.ELEMENT_NAME)}{$thumbnail.ELEMENT_NAME}{/if}
    18                 {if !empty($thumbnail.CATEGORY_NAME)}{$thumbnail.CATEGORY_NAME}{/if}
    1916                {if !empty($thumbnail.IMAGE_TS)}{$thumbnail.IMAGE_TS}{/if}
    20                
    21                 {if !empty($thumbnail.nb_comments)}
    22                 <span class="{$thumbnail.nb_comments.CLASS} nb-comments">
     17
     18                {if isset($thumbnail.NB_COMMENTS)}
     19                <span class="{if 0==$thumbnail.NB_COMMENTS}zero {/if}nb-comments">
    2320                <br />
    24                 {$pwg->l10n_dec('%d comment', '%d comments',$thumbnail.nb_comments.NB_COMMENTS)}
     21                {$pwg->l10n_dec('%d comment', '%d comments',$thumbnail.NB_COMMENTS)}
    2522                </span>
    2623                {/if}
    27                
    28                 {if !empty($thumbnail.nb_hits)}
    29                 <span class="{$thumbnail.nb_hits.CLASS} nb-hits">
     24
     25                {if isset($thumbnail.NB_HITS)}
     26                <span class="{if 0==$thumbnail.NB_HITS}zero {/if}nb-hits">
    3027                <br />
    31                 {$pwg->l10n_dec('%d hit', '%d hits',$thumbnail.nb_hits.HITS)}
     28                {$pwg->l10n_dec('%d hit', '%d hits',$thumbnail.NB_HITS)}
    3229                </span>
    3330                {/if}
Note: See TracChangeset for help on using the changeset viewer.