source: extensions/PWG_Stuffs/trunk/modules/FeaturedPhotos/main.inc.php @ 12401

Last change on this file since 12401 was 12401, checked in by patdenice, 13 years ago

Best rated module is now compatible with piwigo 2.3

File size: 3.4 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $page, $user, $conf, $template;
6
7$forbidden = get_sql_condition_FandF
8  (
9    array
10      (
11        'forbidden_categories' => 'ic.category_id',
12        'visible_categories' => 'ic.category_id',
13        'visible_images' => 'i.id'
14      ),
15    'AND'
16  );
17 
18$query ='
19SELECT DISTINCT(i.id)
20  FROM '.IMAGES_TABLE.' AS i
21    INNER JOIN '.FAVORITES_TABLE.' AS f       ON f.image_id = i.id
22    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
23    INNER JOIN '.CATEGORIES_TABLE.' AS c      ON ic.category_id = c.id
24      WHERE f.user_id = '.$conf['webmaster_id'].'
25       '.$forbidden.';';
26
27$pictures = array();
28$selection = array_from_query($query, 'id');
29
30if (count($selection) > 0)
31{
32  $rank_of = array_flip($selection);
33
34  $query = '
35SELECT *
36  FROM '.IMAGES_TABLE.'
37  WHERE id IN ('.implode(',', $selection).')
38;';
39  $result = pwg_query($query);
40  while ($row = mysql_fetch_assoc($result))
41  {
42    $row['rank'] = $rank_of[ $row['id'] ];
43
44    array_push($pictures, $row);
45  }
46
47  usort($pictures, 'rank_compare');
48  unset($rank_of);
49}
50
51if (count($pictures) > 0)
52{
53  if ($user['show_nb_comments'])
54  {
55    $query = '
56SELECT image_id, COUNT(*) AS nb_comments
57  FROM '.COMMENTS_TABLE.'
58  WHERE validated = \'true\'
59    AND image_id IN ('.implode(',', $selection).')
60  GROUP BY image_id
61;';
62    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
63  }
64
65  // template thumbnail initialization
66  trigger_action('loc_begin_index_thumbnails', $pictures);
67  $block['thumbnails'] = array();
68
69  foreach ($pictures as $row)
70  {
71    // link on picture.php page
72    $url = duplicate_picture_url(
73          array(
74            'image_id' => $row['id'],
75            'image_file' => $row['file']
76          ),
77          array('start')
78        );
79    $url = add_url_params($url, array('pwgs_ra' => implode(',',$selection)));
80
81    $tpl_var =
82      array(
83        'ID'        => $row['id'],
84        'TN_SRC'    => get_thumbnail_url($row),
85        'TN_ALT'    => $row['file'],
86        'TN_TITLE'  => get_thumbnail_title($row),
87        'ICON_TS'   => get_icon($row['date_available']),
88        'URL'       => $url,
89
90     /* Fields for template-extension usage */
91        'FILE_PATH' => $row['path'],
92        'FILE_POSTED' => $row['date_available'],
93        'FILE_CREATED' => $row['date_creation'],
94        'FILE_DESC' => $row['comment'],
95        'FILE_AUTHOR' => $row['author'],
96        'FILE_HIT' => $row['hit'],
97        'FILE_SIZE' => $row['filesize'],
98        'FILE_WIDTH' => $row['width'],
99        'FILE_HEIGHT' => $row['height'],
100        'FILE_METADATE' => $row['date_metadata_update'],
101        'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
102                  true:false, /* lack of include/functions_picture.inc.php */
103      );
104
105    if ($user['show_nb_hits'])
106    {
107      $tpl_var['NB_HITS'] = $row['hit'];
108    }
109
110    if (isset($row['name']) and $row['name'] != '')
111    {
112      $name = $row['name'];
113    }
114    else
115    {
116      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
117    }
118
119    $tpl_var['NAME'] = $name;
120
121    if ( isset($nb_comments_of) )
122    {
123      $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
124    }
125
126    $block['thumbnails'][] = $tpl_var;
127  }
128
129  $block['thumbnails'] = trigger_event('loc_end_index_thumbnails', $block['thumbnails'], $pictures);
130
131  $block['TEMPLATE'] = 'stuffs_thumbnails.tpl';
132}
133
134?>
Note: See TracBrowser for help on using the repository browser.