source: trunk/category.php @ 606

Last change on this file since 606 was 605, checked in by plg, 19 years ago

category random replaced by a more generic category : list. You give a list
of element identifiers and it creates a page virtual temporary
category. random.php generates a randomized list of element id visible to
the user (according to permissions) and redirects to category.php.

Major problem : elements order is in id ascending order, I don't know how to
change order when having id1,id2,id3 and id2,id3,id1 (the display order is
the same)

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