source: extensions/PWG_Stuffs/modules/Recent/main.inc.php @ 9369

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

Plugins can add their own modules.

File size: 4.1 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $page, $user, $conf, $template;
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 ='
27SELECT 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.date_available >= SUBDATE(
32      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
33
34if (isset($page['category']))
35{
36  $query .= '
37        AND ( c.uppercats LIKE \''.$page['category']['uppercats'].',%\' OR c.id = '.$page['category']['id'].' )
38  ';
39}
40
41$query .= '
42    '.$forbidden.'
43    ORDER BY i.id DESC
44    LIMIT 0, '.$datas['nb_images'].'
45  ;';
46
47$pictures = array();
48$selection = array_from_query($query, 'id');
49 
50if (count($selection) > 0)
51{
52  $query = '
53SELECT *
54  FROM '.IMAGES_TABLE.'
55  WHERE id IN ('.implode(',', $selection).')
56  ORDER BY id DESC
57;';
58  $result = pwg_query($query);
59  while ($row = mysql_fetch_assoc($result))
60  {
61    array_push($pictures, $row);
62  }
63}
64
65if (count($pictures) > 0)
66{
67  if ($user['show_nb_comments'])
68  {
69    $query = '
70SELECT image_id, COUNT(*) AS nb_comments
71  FROM '.COMMENTS_TABLE.'
72  WHERE validated = \'true\'
73    AND image_id IN ('.implode(',', $selection).')
74  GROUP BY image_id
75;';
76    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
77  }
78
79  // template thumbnail initialization
80  $template->set_filenames( array( 'pwgs_recent' => 'thumbnails.tpl',));
81
82  trigger_action('loc_begin_index_thumbnails', $pictures);
83  $tpl_thumbnails_var = array();
84
85  foreach ($pictures as $row)
86  {
87    // link on picture.php page
88    $url = duplicate_picture_url(
89          array(
90            'image_id' => $row['id'],
91            'image_file' => $row['file']
92          ),
93          array('start')
94        );
95    $url = add_url_params($url, array('pwgs_re' => implode(',',$selection)));
96
97    $tpl_var =
98      array(
99        'ID'        => $row['id'],
100        'TN_SRC'    => get_thumbnail_url($row),
101        'TN_ALT'    => $row['file'],
102        'TN_TITLE'  => get_thumbnail_title($row),
103        'ICON_TS'   => get_icon($row['date_available']),
104        'URL'       => $url,
105
106     /* Fields for template-extension usage */
107        'FILE_PATH' => $row['path'],
108        'FILE_POSTED' => $row['date_available'],
109        'FILE_CREATED' => $row['date_creation'],
110        'FILE_DESC' => $row['comment'],
111        'FILE_AUTHOR' => $row['author'],
112        'FILE_HIT' => $row['hit'],
113        'FILE_SIZE' => $row['filesize'],
114        'FILE_WIDTH' => $row['width'],
115        'FILE_HEIGHT' => $row['height'],
116        'FILE_METADATE' => $row['date_metadata_update'],
117        'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
118                  true:false, /* lack of include/functions_picture.inc.php */
119      );
120
121    if ($user['show_nb_hits'])
122    {
123      $tpl_var['NB_HITS'] = $row['hit'];
124    }
125
126    if ($conf['show_thumbnail_caption'])
127    {// name of the picture
128      if (isset($row['name']) and $row['name'] != '')
129      {
130        $name = $row['name'];
131      }
132      else
133      {
134        $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
135      }
136
137      $tpl_var['NAME'] = $name;
138    }
139
140    if ( isset($nb_comments_of) )
141    {
142      $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
143    }
144
145    $tpl_thumbnails_var[] = $tpl_var;
146  }
147
148  $tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
149  $template->assign('thumbnails', $tpl_thumbnails_var);
150
151  $block['CONTENT'] = $template->parse('pwgs_recent', true);
152  $block['TEMPLATE'] = 'stuffs_recent.tpl';
153}
154
155?>
Note: See TracBrowser for help on using the repository browser.