source: branches/branch-1_5/include/category_calendar.inc.php @ 1003

Last change on this file since 1003 was 1003, checked in by nikrou, 18 years ago

Improve security of sessions:

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