source: trunk/category.php @ 554

Last change on this file since 554 was 541, checked in by z0rglub, 20 years ago
  • deletion of session_time and session_id_size as config parameter
  • new feature : "remember me" creates a long time cookie
  • possibility to set the default authentication method to URI or cookie
  • really technical parameters (session identifier size, session duration) are set in the config file and not in database + configuration.php
  • 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// |                             category.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-10-02 23:12:50 +0000 (Sat, 02 Oct 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 541 $
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.'category.php?cat=random'),
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}
243
244// search link
245$template->assign_block_vars('summary', array(
246'TITLE'=>$lang['hint_search'],
247'NAME'=>$lang['search'],
248'U_SUMMARY'=>add_session_id( 'search.php' ),
249));
250
251// comments link
252$template->assign_block_vars('summary', array(
253'TITLE'=>$lang['hint_comments'],
254'NAME'=>$lang['comments'],
255'U_SUMMARY'=>add_session_id( 'comments.php' ),
256));
257
258// about link
259$template->assign_block_vars('summary', array(
260'TITLE'=>$lang['hint_about'],
261'NAME'=>$lang['about'],
262'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) )
263));
264
265//------------------------------------------------------ main part : thumbnails
266if (isset($page['cat'])
267    and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0)
268         or in_array($page['cat'],
269                     array('search'
270                           ,'most_visited'
271                           ,'recent_pics'
272                           ,'best_rated'
273                           ,'random'
274                       ))))
275{
276  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
277}
278elseif (isset($page['cat']) and $page['cat'] == 'calendar')
279{
280  include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php');
281}
282elseif (isset($page['cat']) and $page['cat'] == 'recent_cats')
283{
284  include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php');
285}
286else
287{
288  include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php');
289}
290//------------------------------------------------------- category informations
291if ( isset ( $page['cat'] ) )
292{
293  // upload a picture in the category
294  if ( is_numeric( $page['cat'] )
295       and $page['cat_site_id'] == 1
296       and $conf['upload_available']
297       and $page['cat_uploadable'] )
298  {
299    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
300    $template->assign_block_vars(
301      'upload',
302      array('U_UPLOAD'=>add_session_id( $url ))
303      );
304  }
305
306  if ( $page['navigation_bar'] != ''
307       or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
308  {
309    $template->assign_block_vars('cat_infos',array());
310  }
311 
312  // navigation bar
313  if ( $page['navigation_bar'] != '' )
314  { 
315    $template->assign_block_vars(
316      'cat_infos.navigation',
317      array('NAV_BAR' => $page['navigation_bar'])
318      );
319  }
320  // category comment
321  if ( isset( $page['comment'] ) and $page['comment'] != '' )
322  {
323    $template->assign_block_vars(
324      'cat_infos.comment',
325      array('COMMENTS' => $page['comment'])
326      );
327  }
328}
329//------------------------------------------------------------ log informations
330pwg_log( 'category', $page['title'] );
331mysql_close();
332
333$template->pparse('category');
334include(PHPWG_ROOT_PATH.'include/page_tail.php');
335?>
Note: See TracBrowser for help on using the repository browser.