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