source: trunk/category.php @ 614

Last change on this file since 614 was 614, checked in by plg, 19 years ago
  • global categories' options : instead of N horizontal tabs on a single page, N options in the left menu (but the same backend)
  • categories.global_rank : new calculated field. It gives a global rank of the category among all others (updated during ordering)
  • category.php page : menu is generated faster thanks to categories.global_rank, recursivity becomes useless :-)
  • new function to display select box with a set of categories : display_select_cat_wrapper
  • cat_options : instead of using 1 multiselect for true/false items, using 1 multiselect for true, and another one for false. The form provides buttons with arrows to switch categories from one multiselect to another
  • deletion of obsolete function display_categories (working with the old template system)
  • deletion of obsolete functions get_user_plain_structure, create_user_structure, get_user_subcat_ids, update_structure, count_images : useless thanks to global_rank
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-23 22:31:24 +0000 (Tue, 23 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 614 $
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['id'] ) )
35{
36  // cookie deletion if exists
37  setcookie( 'id', '', 0, cookie_path() );
38  $url = 'category.php';
39  redirect( $url );
40}
41//-------------------------------------------------- access authorization check
42if (isset($_GET['cat']))
43{
44  check_cat_id($_GET['cat']);
45}
46check_login_authorization();
47if (isset($page['cat']) and is_numeric($page['cat']))
48{
49  check_restrictions($page['cat']);
50}
51//-------------------------------------------------------------- initialization
52// detection of the start picture to display
53if ( !isset( $_GET['start'] )
54     or !is_numeric( $_GET['start'] )
55     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
56{
57  $page['start'] = 0;
58}
59else
60{
61  $page['start'] = $_GET['start'];
62}
63
64// Sometimes, a "num" is provided in the URL. It is the number
65// of the picture to show. This picture must be in the thumbnails page.
66// We have to find the right $page['start'] that show the num picture
67// in this category
68if ( isset( $_GET['num'] )
69     and is_numeric( $_GET['num'] )
70     and $_GET['num'] >= 0 )
71{
72  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
73  $page['start']*= $user['nb_image_page'];
74}
75
76initialize_category();
77
78// creation of the array containing the cat ids to expand in the menu
79// $page['tab_expand'] contains an array with the category ids
80// $page['expand'] contains the string to display in URL with comma
81$page['tab_expand'] = array();
82if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
83{
84  // the category displayed (in the URL cat=23) must be seen in the menu ->
85  // parent categories must be expanded
86  $uppercats = explode( ',', $page['uppercats'] );
87  foreach ( $uppercats as $uppercat ) {
88    array_push( $page['tab_expand'], $uppercat );
89  }
90}
91// in case of expanding all authorized cats $page['tab_expand'] is empty
92if ( $user['expand'] )
93{
94  $page['tab_expand'] = array();
95}
96//----------------------------------------------------- template initialization
97//
98// Start output of page
99//
100$title = $page['title'];
101include(PHPWG_ROOT_PATH.'include/page_header.php');
102
103$template->set_filenames( array('category'=>'category.tpl') );
104//-------------------------------------------------------------- category title
105if ( !isset( $page['title'] ) )
106{
107  $page['title'] = $lang['no_category'];
108}
109$template_title = $page['title'];
110if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 )
111{
112  $template_title.= ' ['.$page['cat_nb_images'].']';
113}
114
115$icon_recent = get_icon(date('Y-m-d'));
116
117$template->assign_vars(array(
118  'NB_PICTURE' => count_user_total_images(),
119  'TITLE' => $template_title,
120  'USERNAME' => $user['username'],
121  'TOP_NUMBER'=>$conf['top_number'],
122  'MENU_CATEGORIES_CONTENT'=>get_categories_menu(),
123
124  'L_CATEGORIES' => $lang['categories'],
125  'L_HINT_CATEGORY' => $lang['hint_category'],
126  'L_SUBCAT' => $lang['sub-cat'],
127  'L_IMG_AVAILABLE' => $lang['images_available'],
128  'L_TOTAL' => $lang['total'],
129  'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
130  'L_SUMMARY' => $lang['title_menu'],
131  'L_UPLOAD' => $lang['upload_picture'],
132  'L_COMMENT' => $lang['comments'],
133  'L_IDENTIFY' => $lang['ident_title'],
134  'L_SUBMIT' => $lang['menu_login'],
135  'L_USERNAME' => $lang['login'],
136  'L_PASSWORD' => $lang['password'],
137  'L_HELLO' => $lang['hello'],
138  'L_LOGOUT' => $lang['logout'],
139  'L_ADMIN' => $lang['admin'],
140  'L_ADMIN_HINT' => $lang['hint_admin'],
141  'L_PROFILE' => $lang['customize'],
142  'L_PROFILE_HINT' => $lang['hint_customize'],
143  'L_REMEMBER_ME' => $lang['remember_me'],
144 
145  'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ),
146  'T_RECENT' => $icon_recent,
147
148  'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ),
149  'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
150  'U_ADMIN'=>add_session_id( PHPWG_ROOT_PATH.'admin.php' ),
151  'U_PROFILE'=>add_session_id(PHPWG_ROOT_PATH.'profile.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ))
152  )
153);
154//---------------------------------------------------------- special categories
155// favorites categories
156if ( !$user['is_the_guest'] )
157{
158  $template->assign_block_vars('username', array());
159
160  $template->assign_block_vars(
161    'special_cat',
162    array(
163      'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=fav'),
164      'TITLE' => $lang['favorite_cat_hint'],
165      'NAME' => $lang['favorite_cat']
166      ));
167}
168// most visited
169$template->assign_block_vars(
170  'special_cat',
171  array(
172    'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=most_visited'),
173    'TITLE' => $lang['most_visited_cat_hint'],
174    'NAME' => $conf['top_number'].' '.$lang['most_visited_cat']
175    ));
176// best rated
177$template->assign_block_vars(
178  'special_cat',
179  array(
180    'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=best_rated'),
181    'TITLE' => $lang['best_rated_cat_hint'],
182    'NAME' => $conf['top_number'].' '.$lang['best_rated_cat']
183    ));
184// random
185$template->assign_block_vars(
186  'special_cat',
187  array(
188    'URL' => add_session_id(PHPWG_ROOT_PATH.'random.php'),
189    'TITLE' => $lang['random_cat_hint'],
190    'NAME' => $lang['random_cat']
191    ));
192// recent pics
193$template->assign_block_vars(
194  'special_cat',
195  array(
196    'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=recent_pics'),
197    'TITLE' => $lang['recent_pics_cat_hint'],
198    'NAME' => $lang['recent_pics_cat']
199    ));
200// recent cats
201$template->assign_block_vars(
202  'special_cat',
203  array(
204    'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=recent_cats'),
205    'TITLE' => $lang['recent_cats_cat_hint'],
206    'NAME' => $lang['recent_cats_cat']
207    ));
208// calendar
209$template->assign_block_vars(
210  'special_cat',
211  array(
212    'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=calendar'),
213    'TITLE' => $lang['calendar_hint'],
214    'NAME' => $lang['calendar']
215    ));
216//--------------------------------------------------------------------- summary
217
218if ( !$user['is_the_guest'] )
219{
220  $template->assign_block_vars('logout',array());
221  // administration link
222  if ( $user['status'] == 'admin' )
223  {
224    $template->assign_block_vars('logout.admin', array());
225  }
226}
227else
228{
229  $template->assign_block_vars('login',array());
230  if ($conf['authorize_remembering'])
231  {
232    $template->assign_block_vars('login.remember_me',array());
233  }
234}
235
236// search link
237$template->assign_block_vars('summary', array(
238'TITLE'=>$lang['hint_search'],
239'NAME'=>$lang['search'],
240'U_SUMMARY'=>add_session_id( 'search.php' ),
241));
242
243// comments link
244$template->assign_block_vars('summary', array(
245'TITLE'=>$lang['hint_comments'],
246'NAME'=>$lang['comments'],
247'U_SUMMARY'=>add_session_id( 'comments.php' ),
248));
249
250// about link
251$template->assign_block_vars('summary', array(
252'TITLE'=>$lang['hint_about'],
253'NAME'=>$lang['about'],
254'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) )
255));
256
257//------------------------------------------------------ main part : thumbnails
258if (isset($page['cat'])
259    and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0)
260         or in_array($page['cat'],
261                     array('search'
262                           ,'most_visited'
263                           ,'recent_pics'
264                           ,'best_rated'
265                           ,'list'
266                       ))))
267{
268  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
269}
270elseif (isset($page['cat']) and $page['cat'] == 'calendar')
271{
272  include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php');
273}
274elseif (isset($page['cat']) and $page['cat'] == 'recent_cats')
275{
276  include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php');
277}
278else
279{
280  include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php');
281}
282//------------------------------------------------------- category informations
283if ( isset ( $page['cat'] ) )
284{
285  // upload a picture in the category
286  if (is_numeric($page['cat'])
287      and $page['cat_site_id'] == 1
288      and $page['cat_dir'] != ''
289      and $page['cat_uploadable'])
290  {
291    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
292    $template->assign_block_vars(
293      'upload',
294      array('U_UPLOAD'=>add_session_id( $url ))
295      );
296  }
297
298  if ( $page['navigation_bar'] != ''
299       or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
300  {
301    $template->assign_block_vars('cat_infos',array());
302  }
303 
304  // navigation bar
305  if ( $page['navigation_bar'] != '' )
306  { 
307    $template->assign_block_vars(
308      'cat_infos.navigation',
309      array('NAV_BAR' => $page['navigation_bar'])
310      );
311  }
312  // category comment
313  if ( isset( $page['comment'] ) and $page['comment'] != '' )
314  {
315    $template->assign_block_vars(
316      'cat_infos.comment',
317      array('COMMENTS' => $page['comment'])
318      );
319  }
320}
321//------------------------------------------------------------ log informations
322pwg_log( 'category', $page['title'] );
323mysql_close();
324
325$template->pparse('category');
326include(PHPWG_ROOT_PATH.'include/page_tail.php');
327?>
Note: See TracBrowser for help on using the repository browser.