source: trunk/category.php @ 1043

Last change on this file since 1043 was 1036, checked in by plg, 18 years ago

improvement: $pagewhere string replaced by $pageitems.
$pagewhere was an SQL clause used to retrieve pictures in #images
table. $pageitems is the list of picture ids of the current section.

improvement: function initialize_category replaced by dedicated included PHP
script include/section_init.inc.php. Code was refactored to improve
readibility and maintenability. $pagenavigation_bar is now build in
category.php instead of initialize_category function. Function check_cat_id
was also replaced by a piece of code in the new file. The file to include to
display thumbnails from category.php is now set in section_init.inc.php
instead of calculated in category.php.

bug fix: the test for rel="up" link for standard HTML navigation links in
category menu was not working with non numeric categories, such as
"favorites".

improvement: function check_login_authorization removed because useless but
in profile.php.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.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-02-12 21:52:16 +0000 (Sun, 12 Feb 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1036 $
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//--------------------------------------------------------------------- include
29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
31//---------------------------------------------------------------------- logout
32if ( isset( $_GET['act'] )
33     and $_GET['act'] == 'logout'
34     and isset( $_COOKIE[session_name()] ) )
35{
36  // cookie deletion if exists
37  $_SESSION = array();
38  session_unset();
39  session_destroy();
40  setcookie(session_name(),'',0, cookie_path() );
41  $url = 'category.php';
42  redirect( $url );
43}
44//---------------------------------------------- change of image display order
45if (isset($_GET['image_order']))
46{
47  setcookie(
48    'pwg_image_order', 
49    $_GET['image_order'] > 0 ? $_GET['image_order'] : '',
50    0
51    );
52 
53  redirect(
54    PHPWG_ROOT_PATH
55    .'category.php'
56    .get_query_string_diff(array('image_order'))
57    );
58}
59//-------------------------------------------------------------- initialization
60// detection of the start picture to display
61if ( !isset( $_GET['start'] )
62     or !is_numeric( $_GET['start'] )
63     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
64{
65  $page['start'] = 0;
66}
67else
68{
69  $page['start'] = $_GET['start'];
70}
71
72include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
73
74// access authorization check
75if (isset($page['cat']) and is_numeric($page['cat']))
76{
77  check_restrictions($page['cat']);
78}
79
80if (isset($page['cat'])
81    and $page['cat_nb_images'] > $user['nb_image_page'])
82{
83  // $nav_url is used to create the navigation bar
84  $nav_url = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
85
86  switch ($page['cat'])
87  {
88    case 'search':
89    {
90      $nav_url.= '&amp;search='.$_GET['search'];
91      break;
92    }
93    case 'list':
94    {
95      $nav_url.= '&amp;list='.$_GET['list'];
96      break;
97    }
98  }
99 
100  $page['navigation_bar'] = create_navigation_bar(
101    $nav_url,
102    $page['cat_nb_images'],
103    $page['start'],
104    $user['nb_image_page'],
105    'back'
106    );
107}
108else
109{
110  $page['navigation_bar'] = '';
111}
112
113// caddie filling :-)
114if (isset($_GET['caddie']))
115{
116  fill_caddie($page['items']);
117}
118
119//----------------------------------------------------- template initialization
120//
121// Start output of page
122//
123$title = $page['title'];
124$page['body_id'] = 'theCategoryPage';
125include(PHPWG_ROOT_PATH.'include/page_header.php');
126
127$template->set_filenames( array('category'=>'category.tpl') );
128//-------------------------------------------------------------- category title
129if (isset($page['cat']) and is_numeric($page['cat']))
130{
131  $template_title = get_cat_display_name($page['cat_name'],
132                                         'category.php?cat=',
133                                         false);
134}
135else
136{
137  $template_title = $page['title'];
138}
139
140if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 )
141{
142  $template_title.= ' ['.$page['cat_nb_images'].']';
143}
144
145$icon_recent = get_icon(date('Y-m-d'));
146
147$template->assign_vars(
148  array(
149  'NB_PICTURE' => count_user_total_images(),
150  'TITLE' => $template_title,
151  'USERNAME' => $user['username'],
152  'TOP_NUMBER'=>$conf['top_number'],
153  'MENU_CATEGORIES_CONTENT'=>get_categories_menu(),
154
155  'L_CATEGORIES' => $lang['categories'],
156  'L_HINT_CATEGORY' => $lang['hint_category'],
157  'L_SUBCAT' => $lang['sub-cat'],
158  'L_IMG_AVAILABLE' => $lang['images_available'],
159  'L_TOTAL' => $lang['total'],
160  'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
161  'L_SUMMARY' => $lang['title_menu'],
162  'L_UPLOAD' => $lang['upload_picture'],
163  'L_COMMENT' => $lang['comments'],
164  'L_IDENTIFY' => $lang['identification'],
165  'L_PASSWORD' => $lang['password'],
166  'L_HELLO' => $lang['hello'],
167  'L_REGISTER' => $lang['ident_register'],
168  'L_LOGOUT' => $lang['logout'],
169  'L_ADMIN' => $lang['admin'],
170  'L_ADMIN_HINT' => $lang['hint_admin'],
171  'L_PROFILE' => $lang['customize'],
172  'L_PROFILE_HINT' => $lang['hint_customize'],
173  'L_REMEMBER_ME' => $lang['remember_me'],
174 
175  'F_IDENTIFY' => PHPWG_ROOT_PATH.'identification.php',
176  'T_RECENT' => $icon_recent,
177
178  'U_HOME' => PHPWG_ROOT_PATH.'category.php',
179  'U_REGISTER' => PHPWG_ROOT_PATH.'register.php',
180  'U_LOST_PASSWORD' => PHPWG_ROOT_PATH.'password.php',
181  'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
182  'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
183  'U_PROFILE'=> PHPWG_ROOT_PATH.'profile.php'
184  )
185);
186
187if (isset($page['cat']) and 'search' == $page['cat'])
188{
189  $template->assign_block_vars(
190    'search_rules',
191    array(
192      'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$_GET['search'],
193      )
194    );
195}
196//-------------------------------------------------------------- external links
197if (count($conf['links']) > 0)
198{
199  $template->assign_block_vars('links', array());
200
201  foreach ($conf['links'] as $url => $label)
202  {
203    $template->assign_block_vars(
204      'links.link',
205      array(
206        'URL' => $url,
207        'LABEL' => $label
208        ));
209  }
210}
211//---------------------------------------------------------- special categories
212// favorites categories
213if ( !$user['is_the_guest'] )
214{
215  $template->assign_block_vars('username', array());
216
217  $template->assign_block_vars(
218    'special_cat',
219    array(
220      'URL' => PHPWG_ROOT_PATH.'category.php?cat=fav',
221      'TITLE' => $lang['favorite_cat_hint'],
222      'NAME' => $lang['favorite_cat']
223      ));
224}
225// most visited
226$template->assign_block_vars(
227  'special_cat',
228  array(
229    'URL' => PHPWG_ROOT_PATH.'category.php?cat=most_visited',
230    'TITLE' => $lang['most_visited_cat_hint'],
231    'NAME' => $lang['most_visited_cat']
232    ));
233// best rated
234if ($conf['rate'])
235{
236  $template->assign_block_vars(
237    'special_cat',
238    array(
239      'URL' => PHPWG_ROOT_PATH.'category.php?cat=best_rated',
240      'TITLE' => $lang['best_rated_cat_hint'],
241      'NAME' => $lang['best_rated_cat']
242      )
243    );
244}
245// random
246$template->assign_block_vars(
247  'special_cat',
248  array(
249    'URL' => PHPWG_ROOT_PATH.'random.php',
250    'TITLE' => $lang['random_cat_hint'],
251    'NAME' => $lang['random_cat']
252    ));
253// recent pics
254$template->assign_block_vars(
255  'special_cat',
256  array(
257    'URL' => PHPWG_ROOT_PATH.'category.php?cat=recent_pics',
258    'TITLE' => $lang['recent_pics_cat_hint'],
259    'NAME' => $lang['recent_pics_cat']
260    ));
261// recent cats
262$template->assign_block_vars(
263  'special_cat',
264  array(
265    'URL' => PHPWG_ROOT_PATH.'category.php?cat=recent_cats',
266    'TITLE' => $lang['recent_cats_cat_hint'],
267    'NAME' => $lang['recent_cats_cat']
268    ));
269// calendar
270$template->assign_block_vars(
271  'special_cat',
272  array(
273    'URL' => PHPWG_ROOT_PATH.'category.php?cat=calendar',
274    'TITLE' => $lang['calendar_hint'],
275    'NAME' => $lang['calendar']
276    ));
277//--------------------------------------------------------------------- summary
278
279if ($user['is_the_guest'])
280{
281  $template->assign_block_vars('register', array());
282  $template->assign_block_vars('login', array());
283 
284  $template->assign_block_vars('quickconnect', array());
285  if ($conf['authorize_remembering'])
286  {
287    $template->assign_block_vars('quickconnect.remember_me', array());
288  }
289}
290else
291{
292  $template->assign_block_vars('hello', array());
293  $template->assign_block_vars('profile', array());
294
295  // the logout link has no meaning with Apache authentication : it is not
296  // possible to logout with this kind of authentication.
297  if (!$conf['apache_authentication'])
298  {
299    $template->assign_block_vars('logout', array());
300  }
301
302  if ('admin' == $user['status'])
303  {
304    $template->assign_block_vars('admin', array());
305  }
306}
307
308// search link
309$template->assign_block_vars('summary', array(
310'TITLE'=>$lang['hint_search'],
311'NAME'=>$lang['search'],
312'U_SUMMARY'=> 'search.php',
313'REL'=> 'rel="search"'
314));
315
316// comments link
317$template->assign_block_vars('summary', array(
318'TITLE'=>$lang['hint_comments'],
319'NAME'=>$lang['comments'],
320'U_SUMMARY'=> 'comments.php',
321));
322
323// about link
324$template->assign_block_vars('summary', array(
325'TITLE'=>$lang['about_page_title'],
326'NAME'=>$lang['About'],
327'U_SUMMARY'=> 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) 
328));
329
330// notification
331$template->assign_block_vars(
332  'summary',
333  array(
334    'TITLE'=>l10n('notification'),
335    'NAME'=>l10n('Notification'),
336    'U_SUMMARY'=> PHPWG_ROOT_PATH.'notification.php',
337    'REL'=> 'rel="nofollow"'
338));
339
340if (isset($page['cat'])
341    and is_numeric($page['cat'])
342    and 'admin' == $user['status'])
343{
344  $template->assign_block_vars(
345    'edit',
346    array(
347      'URL' =>
348          PHPWG_ROOT_PATH.'admin.php?page=cat_modify'
349          .'&amp;cat_id='.$page['cat']
350      )
351    );
352}
353
354//------------------------------------------------------ main part : thumbnails
355include(PHPWG_ROOT_PATH.$page['thumbnails_include']);
356//------------------------------------------------------- category informations
357if ( isset ( $page['cat'] ) )
358{
359  // upload a picture in the category
360  if (is_numeric($page['cat'])
361      and $page['cat_site_id'] == 1
362      and $page['cat_dir'] != ''
363      and $page['cat_uploadable'])
364  {
365    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
366    $template->assign_block_vars(
367      'upload',
368      array('U_UPLOAD'=> $url )
369      );
370  }
371
372  if ( $page['navigation_bar'] != ''
373       or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
374  {
375    $template->assign_block_vars('cat_infos',array());
376  }
377 
378  // navigation bar
379  if ( $page['navigation_bar'] != '' )
380  { 
381    $template->assign_block_vars(
382      'cat_infos.navigation',
383      array('NAV_BAR' => $page['navigation_bar'])
384      );
385  }
386  // category comment
387  if ( isset( $page['comment'] ) and $page['comment'] != '' )
388  {
389    $template->assign_block_vars(
390      'cat_infos.comment',
391      array('COMMENTS' => $page['comment'])
392      );
393  }
394  if ($page['cat_nb_images']>0 and 
395       $page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
396  {
397    // image order
398    $template->assign_block_vars( 'preferred_image_order', array() );
399 
400    $order_idx = isset($_COOKIE['pwg_image_order']) ? 
401                     $_COOKIE['pwg_image_order'] : 0;
402
403    $orders = get_category_preferred_image_orders();
404    for ( $i = 0; $i < count($orders); $i++)
405    {
406      if ($orders[$i][2])
407      {
408        $url = PHPWG_ROOT_PATH.'category.php'
409                 .get_query_string_diff(array('image_order'));
410        $url .= '&amp;image_order='.$i;
411        $template->assign_block_vars( 'preferred_image_order.order', array(
412          'DISPLAY' => $orders[$i][0],
413          'URL' => $url,
414          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : '' ),
415          ) );
416      }
417    }
418  }
419}
420//------------------------------------------------------------ log informations
421pwg_log( 'category', $page['title'] );
422
423$template->parse('category');
424include(PHPWG_ROOT_PATH.'include/page_tail.php');
425?>
Note: See TracBrowser for help on using the repository browser.