source: extensions/PWG_Stuffs/modules/MostVisited/main.inc.php @ 3609

Last change on this file since 3609 was 3609, checked in by patdenice, 15 years ago

Convert all php and tpl files in Unix format for my plugins.

File size: 4.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $page, $user, $conf, $template, $pwg_event_handlers, $yop;
6
7if (script_basename() == 'picture'
8  or ($datas['cat_display'] == 'wo_thumb' and !empty($page['items']))
9  or ($datas['cat_display'] == 'w_thumb' and empty($page['items']) and isset($page['category']))
10  or ($datas['cat_display'] == 'selected_cats' and isset($page['category']) and !in_array($page['category']['id'], $datas['cat_selection'])))
11{
12  return false;
13}
14
15$forbidden = get_sql_condition_FandF
16  (
17    array
18      (
19        'forbidden_categories' => 'ic.category_id',
20        'visible_categories' => 'ic.category_id',
21        'visible_images' => 'i.id'
22      ),
23    'AND'
24  );
25
26$query = '
27  SELECT DISTINCT (i.id)
28    FROM '.IMAGES_TABLE.' as i
29      INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
30      INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id
31    WHERE i.hit > 0';
32
33if (isset($page['category']))
34{
35  $query .= '
36        AND ( c.uppercats LIKE \''.$page['category']['uppercats'].',%\' OR c.id = '.$page['category']['id'].' )
37  ';
38}
39
40$query .= '
41      '.$forbidden.'
42      ORDER BY i.hit DESC, i.file ASC
43    LIMIT 0, '.$datas['nb_images'].'
44  ;';
45
46$pictures = array();
47$selection = array_from_query($query, 'id');
48 
49if (count($selection) > 0)
50{
51  $rank_of = array_flip($selection);
52
53  $query = '
54SELECT *
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
70if (count($pictures) > 0)
71{
72  if ($user['show_nb_comments'])
73  {
74    $query = '
75SELECT 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  $template->set_filenames( array( 'pwgs_most_visited' => 'thumbnails.tpl',));
86
87  trigger_action('loc_begin_index_thumbnails', $pictures);
88  $tpl_thumbnails_var = array();
89
90  foreach ($pictures as $row)
91  {
92    // link on picture.php page
93    $url = duplicate_picture_url(
94          array(
95            'image_id' => $row['id'],
96            'image_file' => $row['file']
97          ),
98          array('start')
99        );
100    $url = add_url_params($url, array('pwgs_mv' => implode(',',$selection)));
101
102    $tpl_var =
103      array(
104        'ID'        => $row['id'],
105        'TN_SRC'    => get_thumbnail_url($row),
106        'TN_ALT'    => $row['file'],
107        'TN_TITLE'  => get_thumbnail_title($row),
108        'ICON_TS'   => get_icon($row['date_available']),
109        'URL'       => $url,
110
111     /* Fields for template-extension usage */
112        'FILE_PATH' => $row['path'],
113        'FILE_POSTED' => $row['date_available'],
114        'FILE_CREATED' => $row['date_creation'],
115        'FILE_DESC' => $row['comment'],
116        'FILE_AUTHOR' => $row['author'],
117        'FILE_HIT' => $row['hit'],
118        'FILE_SIZE' => $row['filesize'],
119        'FILE_WIDTH' => $row['width'],
120        'FILE_HEIGHT' => $row['height'],
121        'FILE_METADATE' => $row['date_metadata_update'],
122        'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
123                  true:false, /* lack of include/functions_picture.inc.php */
124      );
125
126    if ($user['show_nb_hits'])
127    {
128      $tpl_var['NB_HITS'] = $row['hit'];
129    }
130
131    if ($conf['show_thumbnail_caption'])
132    {// name of the picture
133      if (isset($row['name']) and $row['name'] != '')
134      {
135        $name = $row['name'];
136      }
137      else
138      {
139        $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
140      }
141
142      if ( !$user['show_nb_hits'])
143      {
144        $name = '('.$row['hit'].') '.$name;
145      }
146
147      $tpl_var['NAME'] = $name;
148    }
149
150    if ( isset($nb_comments_of) )
151    {
152      $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
153    }
154
155    $tpl_thumbnails_var[] = $tpl_var;
156  }
157
158  $tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
159  $template->assign('thumbnails', $tpl_thumbnails_var);
160
161  $block['CONTENT'] = $template->parse('pwgs_most_visited', true);
162}
163else
164{
165  return false;
166}
167
168?>
Note: See TracBrowser for help on using the repository browser.