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-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2005-01-16 17:27:34 +0000 (Sun, 16 Jan 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 697 $ |
---|
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 category.php to show thumbnails for the category |
---|
30 | * calendar |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | // years of image availability |
---|
35 | $query = ' |
---|
36 | SELECT YEAR('.$conf['calendar_datefield'].') AS year, COUNT(id) AS count |
---|
37 | FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.' |
---|
38 | '.$page['where'].' |
---|
39 | AND id = image_id |
---|
40 | GROUP BY year |
---|
41 | ;'; |
---|
42 | $result = pwg_query($query); |
---|
43 | $calendar_years = array(); |
---|
44 | while ($row = mysql_fetch_array($result)) |
---|
45 | { |
---|
46 | $calendar_years[$row['year']] = $row['count']; |
---|
47 | } |
---|
48 | |
---|
49 | // if the year requested is not among the available years, we unset the |
---|
50 | // variable |
---|
51 | if (isset($page['calendar_year']) |
---|
52 | and !isset($calendar_years[$page['calendar_year']])) |
---|
53 | { |
---|
54 | unset($page['calendar_year']); |
---|
55 | } |
---|
56 | |
---|
57 | // years navigation bar creation |
---|
58 | $years_nav_bar = ''; |
---|
59 | foreach ($calendar_years as $calendar_year => $nb_picture_year) |
---|
60 | { |
---|
61 | if (isset($page['calendar_year']) |
---|
62 | and $calendar_year == $page['calendar_year']) |
---|
63 | { |
---|
64 | $years_nav_bar.= ' <span class="dateSelected">'.$calendar_year.'</span>'; |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | $url = PHPWG_ROOT_PATH.'category.php?cat=calendar'; |
---|
69 | $url.= '&year='.$calendar_year; |
---|
70 | $url = add_session_id($url); |
---|
71 | $years_nav_bar.= ' <a href="'.$url.'">'.$calendar_year.'</a>'; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | $template->assign_block_vars( |
---|
76 | 'calendar', |
---|
77 | array('YEARS_NAV_BAR' => $years_nav_bar) |
---|
78 | ); |
---|
79 | |
---|
80 | // months are calculated (to know which months are available, and how many |
---|
81 | // pictures per month we can find) only if a year is requested. |
---|
82 | if (isset($page['calendar_year'])) |
---|
83 | { |
---|
84 | // creation of hash associating the number of the month in the year with |
---|
85 | // the number of picture for this month : $calendar_months |
---|
86 | $query = ' |
---|
87 | SELECT DISTINCT(MONTH('.$conf['calendar_datefield'].')) AS month |
---|
88 | , COUNT(id) AS count |
---|
89 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
90 | '.$page['where'].' |
---|
91 | AND '.$conf['calendar_datefield'].' |
---|
92 | BETWEEN \''.$page['calendar_year'].'-1-1\' |
---|
93 | AND \''.$page['calendar_year'].'-12-31\' |
---|
94 | GROUP BY MONTH('.$conf['calendar_datefield'].') |
---|
95 | ;'; |
---|
96 | $result = pwg_query($query); |
---|
97 | $calendar_months = array(); |
---|
98 | while ($row = mysql_fetch_array($result)) |
---|
99 | { |
---|
100 | $calendar_months[$row['month']] = $row['count']; |
---|
101 | } |
---|
102 | |
---|
103 | // if a month is requested and is not among the available months, we unset |
---|
104 | // the requested month |
---|
105 | if (isset($page['calendar_month']) |
---|
106 | and !isset($calendar_months[$page['calendar_month']])) |
---|
107 | { |
---|
108 | unset($page['calendar_month']); |
---|
109 | } |
---|
110 | |
---|
111 | // months navigation bar creation |
---|
112 | $months_nav_bar = ''; |
---|
113 | foreach ($calendar_months as $calendar_month => $nb_picture_month) |
---|
114 | { |
---|
115 | if (isset($page['calendar_month']) |
---|
116 | and $calendar_month == $page['calendar_month']) |
---|
117 | { |
---|
118 | $months_nav_bar.= ' <span class="dateSelected">'; |
---|
119 | $months_nav_bar.= $lang['month'][(int)$calendar_month]; |
---|
120 | $months_nav_bar.= '</span>'; |
---|
121 | } |
---|
122 | else |
---|
123 | { |
---|
124 | $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&month='; |
---|
125 | $url.= $page['calendar_year'].'.'.sprintf('%02s', $calendar_month); |
---|
126 | $months_nav_bar.= ' '; |
---|
127 | $months_nav_bar.= '<a href="'.add_session_id($url).'">'; |
---|
128 | $months_nav_bar.= $lang['month'][(int)$calendar_month]; |
---|
129 | $months_nav_bar.= '</a>'; |
---|
130 | } |
---|
131 | } |
---|
132 | $template->assign_block_vars( |
---|
133 | 'calendar', |
---|
134 | array('MONTHS_NAV_BAR' => $months_nav_bar)); |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * 4 sub-cases are possibles for the calendar category : |
---|
139 | * |
---|
140 | * 1. show years if no year is requested |
---|
141 | * 2. show months of the requested year if no month is requested |
---|
142 | * 3. show days of the {year,month} requested if no day requested |
---|
143 | * 4. show categories of the requested day (+ a special category gathering |
---|
144 | * all categories) |
---|
145 | */ |
---|
146 | |
---|
147 | if (!isset($page['calendar_year'])) |
---|
148 | { |
---|
149 | $nb_pics = count($calendar_years); |
---|
150 | } |
---|
151 | elseif (!isset($page['calendar_month'])) |
---|
152 | { |
---|
153 | $nb_pics = count($calendar_months); |
---|
154 | } |
---|
155 | elseif (!isset($page['calendar_day'])) |
---|
156 | { |
---|
157 | // creation of hash associating the number of the day in the month with |
---|
158 | // the number of picture for this day : $calendar_days |
---|
159 | $query = ' |
---|
160 | SELECT DISTINCT('.$conf['calendar_datefield'].') AS day, COUNT(id) AS count |
---|
161 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
162 | '.$page['where'].' |
---|
163 | AND '.$conf['calendar_datefield'].' |
---|
164 | BETWEEN \''.$page['calendar_year'].'-'.$page['calendar_month'].'-1\' |
---|
165 | AND \''.$page['calendar_year'].'-'.$page['calendar_month'].'-31\' |
---|
166 | GROUP BY day |
---|
167 | ;'; |
---|
168 | $result = pwg_query($query); |
---|
169 | $calendar_days = array(); |
---|
170 | while ($row = mysql_fetch_array($result)) |
---|
171 | { |
---|
172 | $calendar_days[$row['day']] = $row['count']; |
---|
173 | } |
---|
174 | $nb_pics = count($calendar_days); |
---|
175 | } |
---|
176 | elseif (isset($page['calendar_day'])) |
---|
177 | { |
---|
178 | // $page['calendar_date'] is the concatenation of year-month-day. simplier |
---|
179 | // to use in SQ queries |
---|
180 | $page['calendar_date'] = $page['calendar_year']; |
---|
181 | $page['calendar_date'].= '-'.$page['calendar_month']; |
---|
182 | $page['calendar_date'].= '-'.$page['calendar_day']; |
---|
183 | |
---|
184 | $query = ' |
---|
185 | SELECT category_id AS category, COUNT(id) AS count |
---|
186 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
187 | '.$page['where'].' |
---|
188 | AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\' |
---|
189 | GROUP BY category_id |
---|
190 | ;'; |
---|
191 | $result = pwg_query($query); |
---|
192 | $calendar_categories = array(); |
---|
193 | // special category 0 : gathering all available categories (0 cannot be a |
---|
194 | // oregular category identifier) |
---|
195 | $calendar_categories[0] = 0; |
---|
196 | while ($row = mysql_fetch_array($result)) |
---|
197 | { |
---|
198 | $calendar_categories[$row['category']] = $row['count']; |
---|
199 | } |
---|
200 | // update the total number of pictures for this day |
---|
201 | $calendar_categories[0] = array_sum($calendar_categories); |
---|
202 | |
---|
203 | $nb_pics = count($calendar_categories); |
---|
204 | } |
---|
205 | |
---|
206 | // template thumbnail initialization |
---|
207 | if ($nb_pics > 0) |
---|
208 | { |
---|
209 | $template->assign_block_vars('thumbnails', array()); |
---|
210 | // first line |
---|
211 | $template->assign_block_vars('thumbnails.line', array()); |
---|
212 | // current row displayed |
---|
213 | $row_number = 0; |
---|
214 | } |
---|
215 | |
---|
216 | if (!isset($page['calendar_year'])) |
---|
217 | { |
---|
218 | // for each month of this year, display a random picture |
---|
219 | foreach ($calendar_years as $calendar_year => $nb_pics) |
---|
220 | { |
---|
221 | $query = ' |
---|
222 | SELECT file,tn_ext,'.$conf['calendar_datefield'].',path |
---|
223 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
224 | '.$page['where'].' |
---|
225 | AND '.$conf['calendar_datefield'].' |
---|
226 | BETWEEN \''.$calendar_year.'-1-1\' |
---|
227 | AND \''.$calendar_year.'-12-31\' |
---|
228 | ORDER BY RAND() |
---|
229 | LIMIT 0,1 |
---|
230 | ;'; |
---|
231 | $row = mysql_fetch_array(pwg_query($query)); |
---|
232 | |
---|
233 | $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
234 | |
---|
235 | $name = $calendar_year.' ('.$nb_pics.')'; |
---|
236 | |
---|
237 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
238 | |
---|
239 | $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar'; |
---|
240 | $url_link.= '&year='.$calendar_year; |
---|
241 | |
---|
242 | $template->assign_block_vars( |
---|
243 | 'thumbnails.line.thumbnail', |
---|
244 | array( |
---|
245 | 'IMAGE'=>$thumbnail_src, |
---|
246 | 'IMAGE_ALT'=>$row['file'], |
---|
247 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
248 | 'IMAGE_NAME'=>$name, |
---|
249 | |
---|
250 | 'U_IMG_LINK'=>add_session_id($url_link) |
---|
251 | ) |
---|
252 | ); |
---|
253 | |
---|
254 | // create a new line ? |
---|
255 | if (++$row_number == $user['nb_image_line']) |
---|
256 | { |
---|
257 | $template->assign_block_vars('thumbnails.line', array()); |
---|
258 | $row_number = 0; |
---|
259 | } |
---|
260 | } |
---|
261 | } |
---|
262 | elseif (!isset($page['calendar_month'])) |
---|
263 | { |
---|
264 | // for each month of this year, display a random picture |
---|
265 | foreach ($calendar_months as $calendar_month => $nb_pics) |
---|
266 | { |
---|
267 | $query = ' |
---|
268 | SELECT file,tn_ext,'.$conf['calendar_datefield'].',path |
---|
269 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
270 | '.$page['where'].' |
---|
271 | AND '.$conf['calendar_datefield'].' |
---|
272 | BETWEEN \''.$page['calendar_year'].'-'.$calendar_month.'-1\' |
---|
273 | AND \''.$page['calendar_year'].'-'.$calendar_month.'-31\' |
---|
274 | ORDER BY RAND() |
---|
275 | LIMIT 0,1 |
---|
276 | ;'; |
---|
277 | $row = mysql_fetch_array(pwg_query($query)); |
---|
278 | |
---|
279 | $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
280 | |
---|
281 | $name = $lang['month'][$calendar_month]; |
---|
282 | $name.= ' '.$page['calendar_year']; |
---|
283 | $name.= ' ('.$nb_pics.')'; |
---|
284 | |
---|
285 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
286 | |
---|
287 | $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar'; |
---|
288 | $url_link.= '&month='.$page['calendar_year'].'.'; |
---|
289 | if ($calendar_month < 10) |
---|
290 | { |
---|
291 | // adding leading zero |
---|
292 | $url_link.= '0'; |
---|
293 | } |
---|
294 | $url_link.= $calendar_month; |
---|
295 | |
---|
296 | $template->assign_block_vars( |
---|
297 | 'thumbnails.line.thumbnail', |
---|
298 | array( |
---|
299 | 'IMAGE'=>$thumbnail_src, |
---|
300 | 'IMAGE_ALT'=>$row['file'], |
---|
301 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
302 | 'IMAGE_NAME'=>$name, |
---|
303 | |
---|
304 | 'U_IMG_LINK'=>add_session_id($url_link) |
---|
305 | ) |
---|
306 | ); |
---|
307 | |
---|
308 | // create a new line ? |
---|
309 | if (++$row_number == $user['nb_image_line']) |
---|
310 | { |
---|
311 | $template->assign_block_vars('thumbnails.line', array()); |
---|
312 | $row_number = 0; |
---|
313 | } |
---|
314 | } |
---|
315 | } |
---|
316 | elseif (!isset($page['calendar_day'])) |
---|
317 | { |
---|
318 | // for each day of the requested month, display a random picture |
---|
319 | foreach ($calendar_days as $calendar_day => $nb_pics) |
---|
320 | { |
---|
321 | $query = ' |
---|
322 | SELECT file,tn_ext,'.$conf['calendar_datefield'].',path |
---|
323 | , DAYOFWEEK(\''.$calendar_day.'\') AS dow |
---|
324 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id |
---|
325 | '.$page['where'].' |
---|
326 | AND '.$conf['calendar_datefield'].' = \''.$calendar_day.'\' |
---|
327 | ORDER BY RAND() |
---|
328 | LIMIT 0,1 |
---|
329 | ;'; |
---|
330 | $row = mysql_fetch_array(pwg_query($query)); |
---|
331 | |
---|
332 | $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
333 | |
---|
334 | list($year,$month,$day) = explode('-', $calendar_day); |
---|
335 | $name = $lang['day'][$row['dow']-1]; |
---|
336 | $name.= ' '.$day; |
---|
337 | $name.= ' ('.$nb_pics.')'; |
---|
338 | |
---|
339 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
340 | |
---|
341 | $url_link = PHPWG_ROOT_PATH.'category.php'; |
---|
342 | $url_link.= '?cat=calendar&day='.str_replace('-', '.', $calendar_day); |
---|
343 | |
---|
344 | $template->assign_block_vars( |
---|
345 | 'thumbnails.line.thumbnail', |
---|
346 | array( |
---|
347 | 'IMAGE'=>$thumbnail_src, |
---|
348 | 'IMAGE_ALT'=>$row['file'], |
---|
349 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
350 | 'IMAGE_NAME'=>$name, |
---|
351 | |
---|
352 | 'U_IMG_LINK'=>add_session_id($url_link) |
---|
353 | ) |
---|
354 | ); |
---|
355 | |
---|
356 | // create a new line ? |
---|
357 | if (++$row_number == $user['nb_image_line']) |
---|
358 | { |
---|
359 | $template->assign_block_vars('thumbnails.line', array()); |
---|
360 | $row_number = 0; |
---|
361 | } |
---|
362 | } |
---|
363 | } |
---|
364 | elseif (isset($page['calendar_day'])) |
---|
365 | { |
---|
366 | $old_level_separator = $conf['level_separator']; |
---|
367 | $conf['level_separator'] = '<br />'; |
---|
368 | // for each category of this day, display a random picture |
---|
369 | foreach ($calendar_categories as $calendar_category => $nb_pics) |
---|
370 | { |
---|
371 | if ($calendar_category == 0) |
---|
372 | { |
---|
373 | $name = '[all]'; |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | $cat_infos = get_cat_info( $calendar_category ); |
---|
378 | |
---|
379 | $name = get_cat_display_name($cat_infos['name'],'',false); |
---|
380 | $name = '['.$name.']'; |
---|
381 | } |
---|
382 | $name.= ' ('.$nb_pics.')'; |
---|
383 | |
---|
384 | $query = ' |
---|
385 | SELECT file,tn_ext,'.$conf['calendar_datefield'].',path |
---|
386 | FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.' |
---|
387 | '.$page['where'].' |
---|
388 | AND '.$conf['calendar_datefield'].' = \''.$page['calendar_date'].'\''; |
---|
389 | if ($calendar_category != 0) |
---|
390 | { |
---|
391 | $query.= ' |
---|
392 | AND category_id = '.$calendar_category; |
---|
393 | } |
---|
394 | $query.= ' |
---|
395 | AND id = image_id |
---|
396 | ORDER BY RAND() |
---|
397 | LIMIT 0,1 |
---|
398 | ;'; |
---|
399 | $row = mysql_fetch_array(pwg_query($query)); |
---|
400 | |
---|
401 | $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
402 | |
---|
403 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
404 | |
---|
405 | $url_link = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
406 | $url_link.= '&search='.$conf['calendar_datefield'].':'.$_GET['day']; |
---|
407 | if ($calendar_category != 0) |
---|
408 | { |
---|
409 | $url_link.= ';cat:'.$calendar_category.'|AND'; |
---|
410 | } |
---|
411 | |
---|
412 | $template->assign_block_vars( |
---|
413 | 'thumbnails.line.thumbnail', |
---|
414 | array( |
---|
415 | 'IMAGE'=>$thumbnail_src, |
---|
416 | 'IMAGE_ALT'=>$row['file'], |
---|
417 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
418 | 'IMAGE_NAME'=>$name, |
---|
419 | |
---|
420 | 'U_IMG_LINK'=>add_session_id($url_link) |
---|
421 | ) |
---|
422 | ); |
---|
423 | $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array()); |
---|
424 | |
---|
425 | // create a new line ? |
---|
426 | if (++$row_number == $user['nb_image_line']) |
---|
427 | { |
---|
428 | $template->assign_block_vars('thumbnails.line', array()); |
---|
429 | $row_number = 0; |
---|
430 | } |
---|
431 | } |
---|
432 | $conf['level_separator'] = $old_level_separator; |
---|
433 | } |
---|
434 | ?> |
---|