source: trunk/include/section_init.inc.php @ 1051

Last change on this file since 1051 was 1051, checked in by rvelices, 19 years ago

new calendar completely integrated

File size: 11.1 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-27 02:11:43 +0100 (ven, 27 jan 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1014 $
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 included page checks section related parameter and provides
30 * following informations:
31 *
32 * - $page['title']
33 *
34 * - $page['items']: ordered list of items to display
35 *
36 * - $page['cat_nb_images']: number of items in the section (should be equal
37 * to count($page['items']))
38 *
39 * - $page['thumbnails_include']: include page managing thumbnails to
40 * display
41 */
42
43unset($page['cat']);
44
45if (isset($_GET['cat']))
46{
47  if (is_numeric($_GET['cat']))
48  {
49    $page['cat'] = $_GET['cat'];
50  }
51  else if ($_GET['cat'] == 'fav'
52           or $_GET['cat'] == 'most_visited'
53           or $_GET['cat'] == 'best_rated'
54           or $_GET['cat'] == 'recent_pics'
55           or $_GET['cat'] == 'recent_cats')
56  {
57    $page['cat'] = $_GET['cat'];
58  }
59  else if ($_GET['cat'] == 'search')
60  {
61    if (!isset($_GET['search']))
62    {
63      die('search GET parameter is missing');
64    }
65    else if (!is_numeric($_GET['search']))
66    {
67      die('wrong format on search GET parameter');
68    }
69    else
70    {
71      $page['cat'] = 'search';
72    }
73  }
74  else if ($_GET['cat'] == 'list')
75  {
76    if (!isset($_GET['list']))
77    {
78      die('list GET parameter is missing');
79    }
80    else if (!preg_match('/^\d+(,\d+)*$/', $_GET['list']))
81    {
82      die('wrong format on list GET parameter');
83    }
84    else
85    {
86      $page['cat'] = 'list';
87    }
88  }
89  else
90  {
91    die('unknown cat GET parameter value');
92  }
93}
94
95// $page['nb_image_page'] is the number of picture to display on this page
96// By default, it is the same as the $user['nb_image_page']
97$page['nb_image_page'] = $user['nb_image_page'];
98
99if (isset($_COOKIE['pwg_image_order'])
100    and is_numeric($_COOKIE['pwg_image_order'])
101    and $_COOKIE['pwg_image_order'] > 0)
102{
103  $orders = get_category_preferred_image_orders();
104
105  $conf['order_by'] = str_replace(
106    'ORDER BY ',
107    'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',', 
108    $conf['order_by']
109    );
110  $page['super_order_by'] = true;
111}
112
113if (isset($page['cat']))
114{
115 
116// +-----------------------------------------------------------------------+
117// |                              category                                 |
118// +-----------------------------------------------------------------------+
119  if (is_numeric($page['cat']))
120  {
121    $result = get_cat_info($page['cat']);
122
123    $page = array_merge(
124      $page,
125      array(
126        'comment'          => $result['comment'],
127        'cat_dir'          => $result['dir'],
128        'cat_name'         => $result['name'],
129        'cat_nb_images'    => $result['nb_images'],
130        'cat_site_id'      => $result['site_id'],
131        'cat_uploadable'   => $result['uploadable'],
132        'cat_commentable'  => $result['commentable'],
133        'cat_id_uppercat'  => $result['id_uppercat'],
134        'uppercats'        => $result['uppercats'],
135
136        'title' => get_cat_display_name($result['name'], '', false),
137        )
138      );
139    if ( !isset($_GET['calendar']) )
140    {
141      $query = '
142SELECT image_id
143  FROM '.IMAGE_CATEGORY_TABLE.'
144    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
145  WHERE category_id = '.$page['cat'].'
146  '.$conf['order_by'].'
147;';
148      $page['items'] = array_from_query($query, 'image_id');
149      $page['thumbnails_include'] =
150          $result['nb_images'] > 0
151          ? 'include/category_default.inc.php'
152          : 'include/category_subcats.inc.php';
153    }//otherwise the calendar will requery all subitems
154  }
155  // special section
156  else
157  {
158    if (!empty($user['forbidden_categories']))
159    {
160      $forbidden =
161        ' category_id NOT IN ('.$user['forbidden_categories'].')';
162    }
163    else
164    {
165      $forbidden = ' 1=1';
166    }
167         
168// +-----------------------------------------------------------------------+
169// |                           search section                              |
170// +-----------------------------------------------------------------------+
171    if ( $page['cat'] == 'search' )
172    {
173      $query = '
174SELECT DISTINCT(id)
175  FROM '.IMAGES_TABLE.'
176    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
177  WHERE '.get_sql_search_clause($_GET['search']).'
178    AND '.$forbidden.'
179  '.$conf['order_by'].'
180;';
181
182      $page = array_merge(
183        $page,
184        array(
185          'title' => $lang['search_result'],
186          'items' => array_from_query($query, 'id'),
187          'thumbnails_include' => 'include/category_default.inc.php',
188          )
189        );
190    }
191// +-----------------------------------------------------------------------+
192// |                           favorite section                            |
193// +-----------------------------------------------------------------------+
194    else if ($page['cat'] == 'fav')
195    {
196      check_user_favorites();
197
198      $query = '
199SELECT image_id
200  FROM '.FAVORITES_TABLE.'
201    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
202  WHERE user_id = '.$user['id'].'
203  '.$conf['order_by'].'
204;';
205
206      $page = array_merge(
207        $page,
208        array(
209          'title' => $lang['favorites'],
210          'items' => array_from_query($query, 'image_id'),
211          'thumbnails_include' => 'include/category_default.inc.php',
212          )
213        );
214    }
215// +-----------------------------------------------------------------------+
216// |                       recent pictures section                         |
217// +-----------------------------------------------------------------------+
218    else if ($page['cat'] == 'recent_pics')
219    {
220      $query = '
221SELECT DISTINCT(id)
222  FROM '.IMAGES_TABLE.'
223    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
224  WHERE date_available > \''.
225        date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\'
226    AND '.$forbidden.'
227  '.$conf['order_by'].'
228;';
229
230      $page = array_merge(
231        $page,
232        array(
233          'title' => $lang['recent_pics_cat'],
234          'items' => array_from_query($query, 'id'),
235          'thumbnails_include' => 'include/category_default.inc.php',
236          )
237        );
238    }
239// +-----------------------------------------------------------------------+
240// |                 recently updated categories section                   |
241// +-----------------------------------------------------------------------+
242    else if ($page['cat'] == 'recent_cats')
243    {
244      $page = array_merge(
245        $page,
246        array(
247          'title' => $lang['recent_cats_cat'],
248          'cat_nb_images' => 0,
249          'thumbnails_include' => 'include/category_recent_cats.inc.php',
250          )
251        );
252    }
253// +-----------------------------------------------------------------------+
254// |                        most visited section                           |
255// +-----------------------------------------------------------------------+
256    else if ($page['cat'] == 'most_visited')
257    {
258      $page['super_order_by'] = true;
259      $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
260      $query = '
261SELECT DISTINCT(id)
262  FROM '.IMAGES_TABLE.'
263    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
264  WHERE hit > 0
265    AND '.$forbidden.
266  $conf['order_by'].'
267  LIMIT 0, '.$conf['top_number'].'
268;';
269
270      $page = array_merge(
271        $page,
272        array(
273          'title' => $conf['top_number'].' '.$lang['most_visited_cat'],
274          'items' => array_from_query($query, 'id'),
275          'thumbnails_include' => 'include/category_default.inc.php',
276          )
277        );
278    }
279// +-----------------------------------------------------------------------+
280// |                          best rated section                           |
281// +-----------------------------------------------------------------------+
282    else if ($page['cat'] == 'best_rated')
283    {
284      $page['super_order_by'] = true;
285      $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
286
287      $query ='
288SELECT DISTINCT(id)
289  FROM '.IMAGES_TABLE.'
290    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
291  WHERE average_rate IS NOT NULL
292    AND '.$forbidden.
293  $conf['order_by'].'
294  LIMIT 0, '.$conf['top_number'].'
295;';
296      $page = array_merge(
297        $page,
298        array(
299          'title' => $conf['top_number'].' '.$lang['best_rated_cat'],
300          'items' => array_from_query($query, 'id'),
301          'thumbnails_include' => 'include/category_default.inc.php',
302          )
303        );
304    }
305// +-----------------------------------------------------------------------+
306// |                             list section                              |
307// +-----------------------------------------------------------------------+
308    else if ($page['cat'] == 'list')
309    {
310      $query ='
311SELECT DISTINCT(id)
312  FROM '.IMAGES_TABLE.'
313    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
314  WHERE image_id IN ('.$_GET['list'].')
315    AND '.$forbidden.'
316  '.$conf['order_by'].'
317;';
318      $page = array_merge(
319        $page,
320        array(
321          'title' => $lang['random_cat'],
322          'items' => array_from_query($query, 'id'),
323          'thumbnails_include' => 'include/category_default.inc.php',
324          )
325        );
326    }
327
328    if (!isset($page['cat_nb_images']))
329    {
330      $page['cat_nb_images'] = count($page['items']);
331    }
332  }
333}
334// +-----------------------------------------------------------------------+
335// |                            root category                              |
336// +-----------------------------------------------------------------------+
337else
338{
339  $page['title'] = $lang['no_category'];
340  $page['thumbnails_include'] = 'include/category_subcats.inc.php';
341}
342
343if ( isset($_GET['calendar']) )
344{
345  include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' );
346  initialize_calendar();
347}
348
349?>
Note: See TracBrowser for help on using the repository browser.