Ignore:
Timestamp:
Oct 15, 2011, 5:16:32 PM (13 years ago)
Author:
patdenice
Message:

Use category_default.inc.php to generate template output for thumbnalis blocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PWG_Stuffs/trunk/modules/MostVisited/main.inc.php

    r12401 r12450  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 global $page, $user, $conf, $template, $pwg_event_handlers, $yop;
     5global $page, $user, $conf, $template;
     6
     7$page_save = $page;
     8$tpl_save = $template->get_template_vars('THUMBNAILS');
    69
    710if (script_basename() == 'picture'
     
    4447  ;';
    4548
    46 $pictures = array();
    47 $selection = array_from_query($query, 'id');
    48  
    49 if (count($selection) > 0)
     49$page['items'] = array_from_query($query, 'id');
     50$page['start'] = 0;
     51$page['nb_image_page'] = $datas['nb_images'];
     52$page['section'] = 'most_visited';
     53
     54include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
     55
     56if (!empty($tpl_thumbnails_var))
    5057{
    51   $rank_of = array_flip($selection);
    52 
    53   $query = '
    54 SELECT *
    55   FROM '.IMAGES_TABLE.'
    56   WHERE id IN ('.implode(',', $selection).')
    57 ;';
    58   $result = pwg_query($query);
    59   while ($row = mysql_fetch_assoc($result))
    60   {
    61     $row['rank'] = $rank_of[ $row['id'] ];
    62 
    63     array_push($pictures, $row);
    64   }
    65 
    66   usort($pictures, 'rank_compare');
    67   unset($rank_of);
    68 }
    69 
    70 if (count($pictures) > 0)
    71 {
    72   if ($user['show_nb_comments'])
    73   {
    74     $query = '
    75 SELECT image_id, COUNT(*) AS nb_comments
    76   FROM '.COMMENTS_TABLE.'
    77   WHERE validated = \'true\'
    78     AND image_id IN ('.implode(',', $selection).')
    79   GROUP BY image_id
    80 ;';
    81     $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
    82   }
    83 
    84   // template thumbnail initialization
    85   trigger_action('loc_begin_index_thumbnails', $pictures);
    86   $block['thumbnails'] = array();
    87 
    88   foreach ($pictures as $row)
    89   {
    90     // link on picture.php page
    91     $url = duplicate_picture_url(
    92           array(
    93             'image_id' => $row['id'],
    94             'image_file' => $row['file']
    95           ),
    96           array('start')
    97         );
    98     $url = add_url_params($url, array('pwgs_mv' => implode(',',$selection)));
    99 
    100     $tpl_var =
    101       array(
    102         'ID'        => $row['id'],
    103         'TN_SRC'    => get_thumbnail_url($row),
    104         'TN_ALT'    => $row['file'],
    105         'TN_TITLE'  => get_thumbnail_title($row),
    106         'ICON_TS'   => get_icon($row['date_available']),
    107         'URL'       => $url,
    108 
    109      /* Fields for template-extension usage */
    110         'FILE_PATH' => $row['path'],
    111         'FILE_POSTED' => $row['date_available'],
    112         'FILE_CREATED' => $row['date_creation'],
    113         'FILE_DESC' => $row['comment'],
    114         'FILE_AUTHOR' => $row['author'],
    115         'FILE_HIT' => $row['hit'],
    116         'FILE_SIZE' => $row['filesize'],
    117         'FILE_WIDTH' => $row['width'],
    118         'FILE_HEIGHT' => $row['height'],
    119         'FILE_METADATE' => $row['date_metadata_update'],
    120         'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
    121                   true:false, /* lack of include/functions_picture.inc.php */
    122       );
    123 
    124     if ($user['show_nb_hits'])
    125     {
    126       $tpl_var['NB_HITS'] = $row['hit'];
    127     }
    128 
    129     if (isset($row['name']) and $row['name'] != '')
    130     {
    131       $name = $row['name'];
    132     }
    133     else
    134     {
    135       $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
    136     }
    137 
    138     if ( !$user['show_nb_hits'])
    139     {
    140       $name = '('.$row['hit'].') '.$name;
    141     }
    142 
    143     $tpl_var['NAME'] = $name;
    144 
    145     if ( isset($nb_comments_of) )
    146     {
    147       $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
    148     }
    149 
    150     $block['thumbnails'][] = $tpl_var;
    151   }
    152 
    153   $block['thumbnails'] = trigger_event('loc_end_index_thumbnails', $block['thumbnails'], $pictures);
    154 
     58  $block['thumbnails'] = $tpl_thumbnails_var;
    15559  $block['TEMPLATE'] = 'stuffs_thumbnails.tpl';
    15660}
    15761
     62$page = $page_save;
     63$template->assign('THUMBNAILS', $tpl_save);
     64
    15865?>
Note: See TracChangeset for help on using the changeset viewer.