source: trunk/category.php @ 1035

Last change on this file since 1035 was 1031, checked in by rvelices, 18 years ago

feature 77: standard navigation link - finalized

3 small fixes: simplified code (unnecessary $pagetab_expand),
urls in comments (at end of line nl2br issue+regex+html 4 validated) and
$pagewhere correction for most_visited

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