source: extensions/PWG_Stuffs/modules/Recent/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;
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    '. str_replace('ORDER BY ', 'ORDER BY date_available DESC, ', $conf['order_by']).'
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  $rank_of = array_flip($selection);
53
54  $query = '
55SELECT *
56  FROM '.IMAGES_TABLE.'
57  WHERE id IN ('.implode(',', $selection).')
58;';
59  $result = pwg_query($query);
60  while ($row = mysql_fetch_assoc($result))
61  {
62    $row['rank'] = $rank_of[ $row['id'] ];
63
64    array_push($pictures, $row);
65  }
66
67  usort($pictures, 'rank_compare');
68  unset($rank_of);
69}
70
71if (count($pictures) > 0)
72{
73  if ($user['show_nb_comments'])
74  {
75    $query = '
76SELECT image_id, COUNT(*) AS nb_comments
77  FROM '.COMMENTS_TABLE.'
78  WHERE validated = \'true\'
79    AND image_id IN ('.implode(',', $selection).')
80  GROUP BY image_id
81;';
82    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
83  }
84
85  // template thumbnail initialization
86  $template->set_filenames( array( 'pwgs_recent' => 'thumbnails.tpl',));
87
88  trigger_action('loc_begin_index_thumbnails', $pictures);
89  $tpl_thumbnails_var = array();
90
91  foreach ($pictures as $row)
92  {
93    // link on picture.php page
94    $url = duplicate_picture_url(
95          array(
96            'image_id' => $row['id'],
97            'image_file' => $row['file']
98          ),
99          array('start')
100        );
101    $url = add_url_params($url, array('pwgs_re' => implode(',',$selection)));
102
103    $tpl_var =
104      array(
105        'ID'        => $row['id'],
106        'TN_SRC'    => get_thumbnail_url($row),
107        'TN_ALT'    => $row['file'],
108        'TN_TITLE'  => get_thumbnail_title($row),
109        'ICON_TS'   => get_icon($row['date_available']),
110        'URL'       => $url,
111
112     /* Fields for template-extension usage */
113        'FILE_PATH' => $row['path'],
114        'FILE_POSTED' => $row['date_available'],
115        'FILE_CREATED' => $row['date_creation'],
116        'FILE_DESC' => $row['comment'],
117        'FILE_AUTHOR' => $row['author'],
118        'FILE_HIT' => $row['hit'],
119        'FILE_SIZE' => $row['filesize'],
120        'FILE_WIDTH' => $row['width'],
121        'FILE_HEIGHT' => $row['height'],
122        'FILE_METADATE' => $row['date_metadata_update'],
123        'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
124                  true:false, /* lack of include/functions_picture.inc.php */
125      );
126
127    if ($user['show_nb_hits'])
128    {
129      $tpl_var['NB_HITS'] = $row['hit'];
130    }
131
132    if ($conf['show_thumbnail_caption'])
133    {// name of the picture
134      if (isset($row['name']) and $row['name'] != '')
135      {
136        $name = $row['name'];
137      }
138      else
139      {
140        $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
141      }
142
143      $tpl_var['NAME'] = $name;
144    }
145
146    if ( isset($nb_comments_of) )
147    {
148      $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
149    }
150
151    $tpl_thumbnails_var[] = $tpl_var;
152  }
153
154  $tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
155  $template->assign('thumbnails', $tpl_thumbnails_var);
156
157  $block['CONTENT'] = $template->parse('pwgs_recent', true);
158}
159else
160{
161  return false;
162}
163
164?>
Note: See TracBrowser for help on using the repository browser.