source: trunk/category.php @ 1029

Last change on this file since 1029 was 1029, checked in by rvelices, 18 years ago
  • remake of Remote sites and Synchronize:
    • synchronization for remote and local sites are done by the same code
    • remote sites can update metadata now (not before) - bug 279
    • fixes bug 82: has_high column
  • improve feature 280: user sort by filename
  • fix path to template mimetypes icons
  • bug 284: session cookie lifetime, deletion on logout and corrected issue

when db upgrades were missing

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