1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | /** |
---|
25 | * This file is included by the main page to show thumbnails for a category |
---|
26 | * that have only subcategories or to show recent categories |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | if ($page['section']=='recent_cats') |
---|
31 | { |
---|
32 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
33 | $query = ' |
---|
34 | SELECT |
---|
35 | c.*, nb_images, date_last, max_date_last, count_images, count_categories |
---|
36 | FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
37 | ON id = cat_id and user_id = '.$user['id'].' |
---|
38 | WHERE date_last >= SUBDATE( |
---|
39 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY |
---|
40 | ) |
---|
41 | '.get_sql_condition_FandF |
---|
42 | ( |
---|
43 | array |
---|
44 | ( |
---|
45 | 'visible_categories' => 'id', |
---|
46 | ), |
---|
47 | 'AND' |
---|
48 | ).' |
---|
49 | ;'; |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
54 | $query = ' |
---|
55 | SELECT |
---|
56 | c.*, nb_images, date_last, max_date_last, count_images, count_categories |
---|
57 | FROM '.CATEGORIES_TABLE.' c INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
58 | ON id = cat_id and user_id = '.$user['id'].' |
---|
59 | WHERE id_uppercat '. |
---|
60 | (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).' |
---|
61 | '.get_sql_condition_FandF |
---|
62 | ( |
---|
63 | array |
---|
64 | ( |
---|
65 | 'visible_categories' => 'id', |
---|
66 | ), |
---|
67 | 'AND' |
---|
68 | ).' |
---|
69 | ORDER BY rank |
---|
70 | ;'; |
---|
71 | } |
---|
72 | |
---|
73 | $result = pwg_query($query); |
---|
74 | $categories = array(); |
---|
75 | $category_ids = array(); |
---|
76 | $image_ids = array(); |
---|
77 | |
---|
78 | while ($row = mysql_fetch_assoc($result)) |
---|
79 | { |
---|
80 | $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last']; |
---|
81 | |
---|
82 | if (isset($row['representative_picture_id']) |
---|
83 | and is_numeric($row['representative_picture_id'])) |
---|
84 | { // if a representative picture is set, it has priority |
---|
85 | $image_id = $row['representative_picture_id']; |
---|
86 | } |
---|
87 | else if ($conf['allow_random_representative']) |
---|
88 | {// searching a random representant among elements in sub-categories |
---|
89 | if ($row['count_images']>0) |
---|
90 | { |
---|
91 | $query = ' |
---|
92 | SELECT image_id |
---|
93 | FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
94 | ON ic.category_id = c.id'; |
---|
95 | $query.= ' |
---|
96 | WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')' |
---|
97 | .get_sql_condition_FandF |
---|
98 | ( |
---|
99 | array |
---|
100 | ( |
---|
101 | 'forbidden_categories' => 'c.id', |
---|
102 | 'visible_categories' => 'c.id', |
---|
103 | 'visible_images' => 'image_id' |
---|
104 | ), |
---|
105 | "\n AND" |
---|
106 | ).' |
---|
107 | ORDER BY RAND() |
---|
108 | LIMIT 0,1 |
---|
109 | ;'; |
---|
110 | $subresult = pwg_query($query); |
---|
111 | if (mysql_num_rows($subresult) > 0) |
---|
112 | { |
---|
113 | list($image_id) = mysql_fetch_row($subresult); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | else |
---|
118 | { // searching a random representant among representant of sub-categories |
---|
119 | if ($row['count_categories']>0 and $row['count_images']>0) |
---|
120 | { |
---|
121 | $query = ' |
---|
122 | SELECT representative_picture_id |
---|
123 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
124 | ON id = cat_id and user_id = '.$user['id'].' |
---|
125 | WHERE uppercats LIKE \''.$row['uppercats'].',%\' |
---|
126 | AND representative_picture_id IS NOT NULL' |
---|
127 | .get_sql_condition_FandF |
---|
128 | ( |
---|
129 | array |
---|
130 | ( |
---|
131 | 'visible_categories' => 'id', |
---|
132 | ), |
---|
133 | "\n AND" |
---|
134 | ).' |
---|
135 | ORDER BY RAND() |
---|
136 | LIMIT 0,1 |
---|
137 | ;'; |
---|
138 | $subresult = pwg_query($query); |
---|
139 | if (mysql_num_rows($subresult) > 0) |
---|
140 | { |
---|
141 | list($image_id) = mysql_fetch_row($subresult); |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | if (isset($image_id)) |
---|
147 | { |
---|
148 | $row['representative_picture_id'] = $image_id; |
---|
149 | array_push($image_ids, $image_id); |
---|
150 | array_push($categories, $row); |
---|
151 | array_push($category_ids, $row['id']); |
---|
152 | } |
---|
153 | unset($image_id); |
---|
154 | } |
---|
155 | |
---|
156 | if ($conf['display_fromto']) |
---|
157 | { |
---|
158 | $dates_of_category = array(); |
---|
159 | if (count($category_ids) > 0) |
---|
160 | { |
---|
161 | $query = ' |
---|
162 | SELECT |
---|
163 | category_id, |
---|
164 | MIN(date_creation) AS date_creation_min, |
---|
165 | MAX(date_creation) AS date_creation_max |
---|
166 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
167 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
168 | WHERE category_id IN ('.implode(',', $category_ids).') |
---|
169 | '.get_sql_condition_FandF |
---|
170 | ( |
---|
171 | array |
---|
172 | ( |
---|
173 | 'visible_categories' => 'category_id', |
---|
174 | 'visible_images' => 'id' |
---|
175 | ), |
---|
176 | 'AND' |
---|
177 | ).' |
---|
178 | GROUP BY category_id |
---|
179 | ;'; |
---|
180 | $result = pwg_query($query); |
---|
181 | while ($row = mysql_fetch_array($result)) |
---|
182 | { |
---|
183 | $dates_of_category[ $row['category_id'] ] = array( |
---|
184 | 'from' => $row['date_creation_min'], |
---|
185 | 'to' => $row['date_creation_max'], |
---|
186 | ); |
---|
187 | } |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | if ($page['section']=='recent_cats') |
---|
192 | { |
---|
193 | usort($categories, 'global_rank_compare'); |
---|
194 | } |
---|
195 | if (count($categories) > 0) |
---|
196 | { |
---|
197 | $thumbnail_src_of = array(); |
---|
198 | |
---|
199 | $query = ' |
---|
200 | SELECT id, path, tn_ext |
---|
201 | FROM '.IMAGES_TABLE.' |
---|
202 | WHERE id IN ('.implode(',', $image_ids).') |
---|
203 | ;'; |
---|
204 | $result = pwg_query($query); |
---|
205 | while ($row = mysql_fetch_assoc($result)) |
---|
206 | { |
---|
207 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | if (count($categories) > 0) |
---|
212 | { |
---|
213 | // Update filtered data |
---|
214 | if (function_exists('update_cats_with_filtered_data')) |
---|
215 | { |
---|
216 | update_cats_with_filtered_data($categories); |
---|
217 | } |
---|
218 | |
---|
219 | $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl'); |
---|
220 | |
---|
221 | trigger_action('loc_begin_index_category_thumbnails', $categories); |
---|
222 | |
---|
223 | $tpl_thumbnails_var = array(); |
---|
224 | |
---|
225 | foreach ($categories as $category) |
---|
226 | { |
---|
227 | $category['name'] = trigger_event( |
---|
228 | 'render_category_name', |
---|
229 | $category['name'], |
---|
230 | 'subcatify_category_name' |
---|
231 | ); |
---|
232 | |
---|
233 | if ($page['section']=='recent_cats') |
---|
234 | { |
---|
235 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | $name = $category['name']; |
---|
240 | } |
---|
241 | |
---|
242 | $tpl_var = |
---|
243 | array( |
---|
244 | 'ID' => $category['id'], |
---|
245 | 'TN_SRC' => $thumbnail_src_of[$category['representative_picture_id']], |
---|
246 | 'TN_ALT' => strip_tags($category['name']), |
---|
247 | 'icon_ts' => get_icon($category['max_date_last'], $category['is_child_date_last']), |
---|
248 | |
---|
249 | 'URL' => make_index_url( |
---|
250 | array( |
---|
251 | 'category' => $category |
---|
252 | ) |
---|
253 | ), |
---|
254 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
255 | ( |
---|
256 | $category['nb_images'], |
---|
257 | $category['count_images'], |
---|
258 | $category['count_categories'], |
---|
259 | true, |
---|
260 | '<br>' |
---|
261 | ), |
---|
262 | 'DESCRIPTION' => |
---|
263 | trigger_event('render_category_literal_description', |
---|
264 | trigger_event('render_category_description', |
---|
265 | @$category['comment'], |
---|
266 | 'subcatify_category_description')), |
---|
267 | 'NAME' => $name, |
---|
268 | ); |
---|
269 | |
---|
270 | if ($conf['display_fromto']) |
---|
271 | { |
---|
272 | if (isset($dates_of_category[ $category['id'] ])) |
---|
273 | { |
---|
274 | $from = $dates_of_category[ $category['id'] ]['from']; |
---|
275 | $to = $dates_of_category[ $category['id'] ]['to']; |
---|
276 | |
---|
277 | if (!empty($from)) |
---|
278 | { |
---|
279 | $info = ''; |
---|
280 | |
---|
281 | if ($from == $to) |
---|
282 | { |
---|
283 | $info = format_date($from); |
---|
284 | } |
---|
285 | else |
---|
286 | { |
---|
287 | $info = sprintf( |
---|
288 | l10n('from %s to %s'), |
---|
289 | format_date($from), |
---|
290 | format_date($to) |
---|
291 | ); |
---|
292 | } |
---|
293 | $tpl_var['INFO_DATES'] = $info; |
---|
294 | } |
---|
295 | } |
---|
296 | }//fromto |
---|
297 | |
---|
298 | $tpl_thumbnails_var[] = $tpl_var; |
---|
299 | } |
---|
300 | |
---|
301 | $tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories); |
---|
302 | $template->assign( 'category_thumbnails', $tpl_thumbnails_var); |
---|
303 | |
---|
304 | $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails'); |
---|
305 | } |
---|
306 | pwg_debug('end include/category_cats.inc.php'); |
---|
307 | ?> |
---|