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