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

Last change on this file since 12414 was 12414, checked in by plg, 13 years ago

bug fixed: correctly sort by date availability, id is not reliable

File size: 3.9 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  date_available DESC, 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  date_available DESC, 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  trigger_action('loc_begin_index_thumbnails', $pictures);
81  $block['thumbnails'] = array();
82
83  foreach ($pictures as $row)
84  {
85    // link on picture.php page
86    $url = duplicate_picture_url(
87          array(
88            'image_id' => $row['id'],
89            'image_file' => $row['file']
90          ),
91          array('start')
92        );
93    $url = add_url_params($url, array('pwgs_re' => implode(',',$selection)));
94
95    $tpl_var =
96      array(
97        'ID'        => $row['id'],
98        'TN_SRC'    => get_thumbnail_url($row),
99        'TN_ALT'    => $row['file'],
100        'TN_TITLE'  => get_thumbnail_title($row),
101        'ICON_TS'   => get_icon($row['date_available']),
102        'URL'       => $url,
103
104     /* Fields for template-extension usage */
105        'FILE_PATH' => $row['path'],
106        'FILE_POSTED' => $row['date_available'],
107        'FILE_CREATED' => $row['date_creation'],
108        'FILE_DESC' => $row['comment'],
109        'FILE_AUTHOR' => $row['author'],
110        'FILE_HIT' => $row['hit'],
111        'FILE_SIZE' => $row['filesize'],
112        'FILE_WIDTH' => $row['width'],
113        'FILE_HEIGHT' => $row['height'],
114        'FILE_METADATE' => $row['date_metadata_update'],
115        'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
116                  true:false, /* lack of include/functions_picture.inc.php */
117      );
118
119    if ($user['show_nb_hits'])
120    {
121      $tpl_var['NB_HITS'] = $row['hit'];
122    }
123
124    if (isset($row['name']) and $row['name'] != '')
125    {
126      $name = $row['name'];
127    }
128    else
129    {
130      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
131    }
132
133    $tpl_var['NAME'] = $name;
134
135    if ( isset($nb_comments_of) )
136    {
137      $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
138    }
139
140    $block['thumbnails'][] = $tpl_var;
141  }
142
143  $block['thumbnails'] = trigger_event('loc_end_index_thumbnails', $block['thumbnails'], $pictures);
144
145  $block['TEMPLATE'] = 'stuffs_thumbnails.tpl';
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.