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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $Id: category_cats.inc.php 1722 2007-01-15 00:09:14Z rub $ |
---|
9 | // | last update : $Date: 2007-01-15 00:09:14 +0000 (Mon, 15 Jan 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1722 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | /** |
---|
29 | * This file is included by the main page to show thumbnails for a category |
---|
30 | * that have only subcategories or to show recent categories |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | if ($page['section']=='recent_cats') |
---|
35 | { |
---|
36 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
37 | $query = ' |
---|
38 | SELECT |
---|
39 | id,name, representative_picture_id, comment, nb_images, uppercats, |
---|
40 | date_last, max_date_last, count_images, count_categories, global_rank |
---|
41 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
42 | ON id = cat_id and user_id = '.$user['id'].' |
---|
43 | WHERE date_last > SUBDATE( |
---|
44 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY |
---|
45 | ) |
---|
46 | '.get_sql_condition_FandF |
---|
47 | ( |
---|
48 | array |
---|
49 | ( |
---|
50 | 'visible_categories' => 'id', |
---|
51 | ), |
---|
52 | 'AND' |
---|
53 | ).' |
---|
54 | ;'; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
59 | $query = ' |
---|
60 | SELECT |
---|
61 | id,name, representative_picture_id, comment, nb_images, |
---|
62 | date_last, max_date_last, count_images, count_categories |
---|
63 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
64 | ON id = cat_id and user_id = '.$user['id'].' |
---|
65 | WHERE id_uppercat '. |
---|
66 | (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).' |
---|
67 | '.get_sql_condition_FandF |
---|
68 | ( |
---|
69 | array |
---|
70 | ( |
---|
71 | 'visible_categories' => 'id', |
---|
72 | ), |
---|
73 | 'AND' |
---|
74 | ).' |
---|
75 | ORDER BY rank |
---|
76 | ;'; |
---|
77 | } |
---|
78 | |
---|
79 | $result = pwg_query($query); |
---|
80 | $categories = 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 | } |
---|
151 | unset($image_id); |
---|
152 | } |
---|
153 | |
---|
154 | if ($page['section']=='recent_cats') |
---|
155 | { |
---|
156 | usort($categories, 'global_rank_compare'); |
---|
157 | } |
---|
158 | if (count($categories) > 0) |
---|
159 | { |
---|
160 | $thumbnail_src_of = array(); |
---|
161 | |
---|
162 | $query = ' |
---|
163 | SELECT id, path, tn_ext |
---|
164 | FROM '.IMAGES_TABLE.' |
---|
165 | WHERE id IN ('.implode(',', $image_ids).') |
---|
166 | ;'; |
---|
167 | $result = pwg_query($query); |
---|
168 | while ($row = mysql_fetch_assoc($result)) |
---|
169 | { |
---|
170 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | if (count($categories) > 0) |
---|
175 | { |
---|
176 | // Update filtered data |
---|
177 | if (function_exists('update_cats_with_filtered_data')) |
---|
178 | { |
---|
179 | update_cats_with_filtered_data($categories); |
---|
180 | } |
---|
181 | |
---|
182 | if ($conf['subcatify']) |
---|
183 | { |
---|
184 | $template->set_filenames( |
---|
185 | array( |
---|
186 | 'mainpage_categories' => 'mainpage_categories.tpl', |
---|
187 | ) |
---|
188 | ); |
---|
189 | |
---|
190 | foreach ($categories as $category) |
---|
191 | { |
---|
192 | $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>'); |
---|
193 | if ($page['section']=='recent_cats') |
---|
194 | { |
---|
195 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | $name = $category['name']; |
---|
200 | } |
---|
201 | |
---|
202 | $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']); |
---|
203 | |
---|
204 | $template->assign_block_vars( |
---|
205 | 'categories.category', |
---|
206 | array( |
---|
207 | 'SRC' => $thumbnail_src_of[$category['representative_picture_id']], |
---|
208 | 'ALT' => $category['name'], |
---|
209 | 'TITLE' => $lang['hint_category'], |
---|
210 | 'ICON' => $icon_ts, |
---|
211 | |
---|
212 | 'URL' => make_index_url( |
---|
213 | array( |
---|
214 | 'category' => $category['id'], |
---|
215 | 'cat_name' => $category['name'], |
---|
216 | ) |
---|
217 | ), |
---|
218 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
219 | ( |
---|
220 | $category['nb_images'], |
---|
221 | $category['count_images'], |
---|
222 | $category['count_categories'] |
---|
223 | ), |
---|
224 | 'DESCRIPTION' => @$comment, |
---|
225 | 'NAME' => $name, |
---|
226 | ) |
---|
227 | ); |
---|
228 | } |
---|
229 | |
---|
230 | $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories'); |
---|
231 | } |
---|
232 | else |
---|
233 | { |
---|
234 | $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',)); |
---|
235 | // first line |
---|
236 | $template->assign_block_vars('thumbnails.line', array()); |
---|
237 | // current row displayed |
---|
238 | $row_number = 0; |
---|
239 | |
---|
240 | if ($page['section']=='recent_cats') |
---|
241 | { |
---|
242 | $old_level_separator = $conf['level_separator']; |
---|
243 | $conf['level_separator'] = '<br />'; |
---|
244 | } |
---|
245 | |
---|
246 | foreach ($categories as $category) |
---|
247 | { |
---|
248 | $template->assign_block_vars( |
---|
249 | 'thumbnails.line.thumbnail', |
---|
250 | array( |
---|
251 | 'IMAGE' => $thumbnail_src_of[ $category['representative_picture_id'] ], |
---|
252 | 'IMAGE_ALT' => $category['name'], |
---|
253 | 'IMAGE_TITLE' => $lang['hint_category'], |
---|
254 | |
---|
255 | 'U_IMG_LINK' => make_index_url( |
---|
256 | array( |
---|
257 | 'category' => $category['id'], |
---|
258 | 'cat_name' => $category['name'], |
---|
259 | ) |
---|
260 | ), |
---|
261 | 'CLASS' => 'thumbCat', |
---|
262 | ) |
---|
263 | ); |
---|
264 | if ($page['section']=='recent_cats') |
---|
265 | { |
---|
266 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
267 | } |
---|
268 | else |
---|
269 | { |
---|
270 | $name = $category['name']; |
---|
271 | $template->merge_block_vars( |
---|
272 | 'thumbnails.line.thumbnail', |
---|
273 | array( |
---|
274 | 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']), |
---|
275 | ) |
---|
276 | ); |
---|
277 | } |
---|
278 | $template->assign_block_vars( |
---|
279 | 'thumbnails.line.thumbnail.category_name', |
---|
280 | array( |
---|
281 | 'NAME' => $name |
---|
282 | ) |
---|
283 | ); |
---|
284 | |
---|
285 | // create a new line ? |
---|
286 | if (++$row_number == $user['nb_image_line']) |
---|
287 | { |
---|
288 | $template->assign_block_vars('thumbnails.line', array()); |
---|
289 | $row_number = 0; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | if ( isset($old_level_separator) ) |
---|
294 | { |
---|
295 | $conf['level_separator']=$old_level_separator; |
---|
296 | } |
---|
297 | |
---|
298 | $template->assign_var_from_handle('THUMBNAILS', 'thumbnails'); |
---|
299 | } |
---|
300 | } |
---|
301 | ?> |
---|