source: extensions/MostCommented/most_commented.php @ 7235

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

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

File size: 1.8 KB
Line 
1<?php
2
3load_language('plugin.lang', MOSTCOMMENTED_PATH);
4
5global $page, $conf;
6
7$page['section'] = 'most_commented';
8
9$forbidden = get_sql_condition_FandF (
10                        array ('forbidden_categories' => 'category_id',
11                                 'visible_categories' => 'category_id',
12                                 'visible_images' => 'image_id'), '', true);
13
14$query = 'SELECT DISTINCT image_id
15    FROM ' . IMAGE_CATEGORY_TABLE . '
16    WHERE ' .  $forbidden . ';';
17
18$img = array_from_query($query, 'image_id');
19
20if (empty($img)) $img = array(0);
21
22$query = 'SELECT img.id, COUNT(*)
23  FROM ' . IMAGES_TABLE . ' AS img
24  INNER JOIN ' . COMMENTS_TABLE . ' AS com
25  ON com.image_id = img.id
26  AND com.validated = "true"
27  WHERE img.id IN (' . implode(',', $img) . ')
28  GROUP BY img.id
29  ORDER BY 2 DESC, img.hit DESC
30  LIMIT 0, ' . $conf['top_number'] . ';';
31
32$page = array_merge($page,
33    array('title' => '<a href="' . duplicate_index_url() . '">'
34         . $conf['top_number'] . ' ' . l10n('most_commented_cat') . '</a>',
35        'items' => array_from_query($query, 'id')));
36
37
38add_event_handler('loc_end_index_thumbnails', 'add_mostcommented_nb_comments');
39
40function add_mostcommented_nb_comments($tpl_thumbnails_var)
41{
42  global $template, $user;
43
44  // Suppression de l'ordre de trie
45  $template->clear_assign('image_orders');
46
47  // Affichage du nombre de commentaires si désactivé pour l'utilisateur
48  if (!$user['show_nb_comments'])
49  {
50    foreach ($tpl_thumbnails_var as $key => $row)
51    {
52      $query = 'SELECT COUNT(*) AS nb_comments
53        FROM '.COMMENTS_TABLE.'
54        WHERE image_id = '.$row['ID'].'
55        AND validated = "true";';
56
57      list($nb_comments) = mysql_fetch_array(pwg_query($query));
58
59      $tpl_thumbnails_var[$key]['NAME'] = '(' . $nb_comments . ') ' . $tpl_thumbnails_var[$key]['NAME'];
60    }
61  }
62
63  return $tpl_thumbnails_var;
64}
65?>
Note: See TracBrowser for help on using the repository browser.