source: trunk/category.php @ 1090

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

URL rewriting: fix some old links, calendar simplification and prepare code
for urls without ? (added functions get_root_url and add_url_param)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-21 01:27:21 +0000 (Tue, 21 Mar 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1090 $
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' );
31include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_GUEST);
37
38//---------------------------------------------------------------------- logout
39if ( isset( $_GET['act'] )
40     and $_GET['act'] == 'logout'
41     and isset( $_COOKIE[session_name()] ) )
42{
43  // cookie deletion if exists
44  $_SESSION = array();
45  session_unset();
46  session_destroy();
47  setcookie(session_name(),'',0, cookie_path() );
48  $url = 'category.php';
49  redirect( $url );
50}
51
52//---------------------------------------------- change of image display order
53if (isset($_GET['image_order']))
54{
55  setcookie(
56    'pwg_image_order',
57    $_GET['image_order'] > 0 ? $_GET['image_order'] : '',
58    0
59    );
60
61  redirect(
62    duplicate_index_URL(
63      array(),        // nothing to redefine
64      array('start')  // changing display order goes back to section first page
65      )
66    );
67}
68//-------------------------------------------------------------- initialization
69// detection of the start picture to display
70if (!isset($page['start']))
71{
72  $page['start'] = 0;
73}
74
75// access authorization check
76if (isset($page['category']))
77{
78  check_restrictions($page['category']);
79}
80
81if (isset($page['cat_nb_images'])
82    and $page['cat_nb_images'] > $user['nb_image_page'])
83{
84  $page['navigation_bar'] = create_navigation_bar(
85    duplicate_index_URL(array(), array('start')),
86    $page['cat_nb_images'],
87    $page['start'],
88    $user['nb_image_page'],
89    true
90    );
91}
92else
93{
94  $page['navigation_bar'] = '';
95}
96
97// caddie filling :-)
98if (isset($_GET['caddie']))
99{
100  fill_caddie($page['items']);
101  // redirect();
102}
103
104//----------------------------------------------------- template initialization
105//
106// Start output of page
107//
108$title = $page['title'];
109$page['body_id'] = 'theCategoryPage';
110include(PHPWG_ROOT_PATH.'include/page_header.php');
111
112$template->set_filenames( array('category'=>'category.tpl') );
113//-------------------------------------------------------------- category title
114if (isset($page['category']))
115{
116  $template_title = get_cat_display_name(
117    $page['cat_name'],
118    'category.php?/category/',
119    false
120    );
121}
122else
123{
124  $template_title = $page['title'];
125}
126
127if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0)
128{
129  $template_title.= ' ['.$page['cat_nb_images'].']';
130}
131
132$icon_recent = get_icon(date('Y-m-d'));
133
134if (!isset($page['chronology_field']))
135{
136  $chronology_params =
137      array(
138          'chronology_field' => 'created',
139          'chronology_style' => 'monthly',
140          'chronology_view' => 'list',
141      );
142  $template->assign_block_vars(
143    'mode_created',
144    array(
145      'URL' => duplicate_index_URL( $chronology_params, array('start') )
146      )
147    );
148
149  $chronology_params['chronology_field'] = 'posted';
150  $template->assign_block_vars(
151    'mode_posted',
152    array(
153      'URL' => duplicate_index_URL( $chronology_params, array('start') )
154      )
155    );
156}
157else
158{
159  $template->assign_block_vars(
160    'mode_normal',
161    array(
162      'URL' => duplicate_index_URL( array(), array('chronology_field','start') )
163      )
164    );
165
166  if ($page['chronology_field'] == 'created')
167  {
168    $chronology_field = 'posted';
169  }
170  else
171  {
172    $chronology_field = 'created';
173  }
174  $url = duplicate_index_URL(
175            array('chronology_field'=>$chronology_field ),
176            array('chronology_date', 'start')
177          );
178  $template->assign_block_vars(
179    'mode_'.$chronology_field,
180    array('URL' => $url )
181    );
182}
183
184$template->assign_vars(
185  array(
186    'NB_PICTURE' => $user['nb_total_images'],
187    'TITLE' => $template_title,
188    'USERNAME' => $user['username'],
189    'TOP_NUMBER' => $conf['top_number'],
190    'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
191
192    'F_IDENTIFY' => get_root_url().'identification.php',
193    'T_RECENT' => $icon_recent,
194
195    'U_HOME' => make_index_URL(),
196    'U_REGISTER' => get_root_url().'register.php',
197    'U_LOST_PASSWORD' => get_root_url().'password.php',
198    'U_LOGOUT' => add_url_param(make_index_URL(), 'act=logout'),
199    'U_ADMIN'=> get_root_url().'admin.php',
200    'U_PROFILE'=> get_root_url().'profile.php',
201    )
202  );
203
204if ('search' == $page['section'])
205{
206  $template->assign_block_vars(
207    'search_rules',
208    array(
209      'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$page['search'],
210      )
211    );
212}
213//-------------------------------------------------------------- external links
214if (count($conf['links']) > 0)
215{
216  $template->assign_block_vars('links', array());
217
218  foreach ($conf['links'] as $url => $label)
219  {
220    $template->assign_block_vars(
221      'links.link',
222      array(
223        'URL' => $url,
224        'LABEL' => $label
225        )
226      );
227  }
228}
229//---------------------------------------------------------- special categories
230// favorites categories
231if ( !$user['is_the_guest'] )
232{
233  $template->assign_block_vars('username', array());
234
235  $template->assign_block_vars(
236    'special_cat',
237    array(
238      'URL' => make_index_URL(array('section' => 'favorites')),
239      'TITLE' => $lang['favorite_cat_hint'],
240      'NAME' => $lang['favorite_cat']
241      ));
242}
243// most visited
244$template->assign_block_vars(
245  'special_cat',
246  array(
247    'URL' => make_index_URL(array('section' => 'most_visited')),
248    'TITLE' => $lang['most_visited_cat_hint'],
249    'NAME' => $lang['most_visited_cat']
250    ));
251// best rated
252if ($conf['rate'])
253{
254  $template->assign_block_vars(
255    'special_cat',
256    array(
257      'URL' => make_index_URL(array('section' => 'best_rated')),
258      'TITLE' => $lang['best_rated_cat_hint'],
259      'NAME' => $lang['best_rated_cat']
260      )
261    );
262}
263// random
264$template->assign_block_vars(
265  'special_cat',
266  array(
267    'URL' => PHPWG_ROOT_PATH.'random.php',
268    'TITLE' => $lang['random_cat_hint'],
269    'NAME' => $lang['random_cat']
270    ));
271// recent pics
272$template->assign_block_vars(
273  'special_cat',
274  array(
275    'URL' => make_index_URL(array('section' => 'recent_pics')),
276    'TITLE' => $lang['recent_pics_cat_hint'],
277    'NAME' => $lang['recent_pics_cat']
278    ));
279// recent cats
280$template->assign_block_vars(
281  'special_cat',
282  array(
283    'URL' => make_index_URL(array('section' => 'recent_cats')),
284    'TITLE' => $lang['recent_cats_cat_hint'],
285    'NAME' => $lang['recent_cats_cat']
286    ));
287
288// calendar
289$template->assign_block_vars(
290  'special_cat',
291  array(
292    'URL' =>
293      make_index_URL(
294        array(
295          'chronology_field' => ($conf['calendar_datefield']=='date_available'
296                                  ? 'posted' : 'created'),
297           'chronology_style'=> 'monthly',
298           'chronology_view' => 'calendar'
299        )
300      ),
301    'TITLE' => $lang['calendar_hint'],
302    'NAME' => $lang['calendar']
303    )
304  );
305//--------------------------------------------------------------------- summary
306
307if ($user['is_the_guest'])
308{
309  $template->assign_block_vars('register', array());
310  $template->assign_block_vars('login', array());
311
312  $template->assign_block_vars('quickconnect', array());
313  if ($conf['authorize_remembering'])
314  {
315    $template->assign_block_vars('quickconnect.remember_me', array());
316  }
317}
318else
319{
320  $template->assign_block_vars('hello', array());
321
322  if (is_autorize_status(ACCESS_CLASSIC))
323  {
324    $template->assign_block_vars('profile', array());
325  }
326
327  // the logout link has no meaning with Apache authentication : it is not
328  // possible to logout with this kind of authentication.
329  if (!$conf['apache_authentication'])
330  {
331    $template->assign_block_vars('logout', array());
332  }
333
334  if (is_admin())
335  {
336    $template->assign_block_vars('admin', array());
337  }
338}
339
340// search link
341$template->assign_block_vars(
342  'summary',
343  array(
344    'TITLE'=>$lang['hint_search'],
345    'NAME'=>$lang['search'],
346    'U_SUMMARY'=> get_root_url().'search.php',
347    'REL'=> 'rel="search"'
348    )
349  );
350
351// comments link
352$template->assign_block_vars(
353  'summary',
354  array(
355    'TITLE'=>$lang['hint_comments'],
356    'NAME'=>$lang['comments'],
357    'U_SUMMARY'=> get_root_url().'comments.php',
358    )
359  );
360
361// about link
362$template->assign_block_vars(
363  'summary',
364  array(
365    'TITLE'     => $lang['about_page_title'],
366    'NAME'      => $lang['About'],
367    'U_SUMMARY' => 'about.php?'.str_replace(
368      '&',
369      '&amp;',
370      $_SERVER['QUERY_STRING']
371      )
372    )
373  );
374
375// notification
376$template->assign_block_vars(
377  'summary',
378  array(
379    'TITLE'=>l10n('notification'),
380    'NAME'=>l10n('Notification'),
381    'U_SUMMARY'=> get_root_url().'notification.php',
382    'REL'=> 'rel="nofollow"'
383    )
384  );
385
386if (isset($page['category']) and is_admin())
387{
388  $template->assign_block_vars(
389    'edit',
390    array(
391      'URL' =>
392        get_root_url().'admin.php?page=cat_modify'
393        .'&amp;cat_id='.$page['category']
394      )
395    );
396}
397
398//------------------------------------------------------ main part : thumbnails
399if (isset($page['thumbnails_include']))
400{
401  include(PHPWG_ROOT_PATH.$page['thumbnails_include']);
402}
403//------------------------------------------------------- category informations
404if (
405  $page['navigation_bar'] != ''
406  or (isset($page['comment']) and $page['comment'] != '')
407  )
408{
409  $template->assign_block_vars('cat_infos',array());
410}
411// navigation bar
412if ($page['navigation_bar'] != '')
413{
414  $template->assign_block_vars(
415    'cat_infos.navigation',
416    array(
417      'NAV_BAR' => $page['navigation_bar'],
418      )
419    );
420}
421
422if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0
423    and $page['section'] != 'most_visited'
424    and $page['section'] != 'best_rated')
425{
426  // image order
427  $template->assign_block_vars( 'preferred_image_order', array() );
428
429  $order_idx = isset($_COOKIE['pwg_image_order'])
430    ? $_COOKIE['pwg_image_order']
431    : 0
432    ;
433
434  $orders = get_category_preferred_image_orders();
435  for ($i = 0; $i < count($orders); $i++)
436  {
437    if ($orders[$i][2])
438    {
439      $template->assign_block_vars(
440        'preferred_image_order.order',
441        array(
442          'DISPLAY' => $orders[$i][0],
443          'URL' => add_url_param( duplicate_index_URL(), 'image_order='.$i ),
444          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : ''),
445          )
446        );
447    }
448  }
449}
450
451if (isset($page['category']))
452{
453  // upload a picture in the category
454  if ($page['cat_uploadable'])
455  {
456    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['category'];
457    $template->assign_block_vars(
458      'upload',
459      array(
460        'U_UPLOAD'=> $url
461        )
462      );
463  }
464
465  // category comment
466  if (isset($page['comment']) and $page['comment'] != '')
467  {
468    $template->assign_block_vars(
469      'cat_infos.comment',
470      array(
471        'COMMENTS' => $page['comment']
472        )
473      );
474  }
475}
476//------------------------------------------------------------ log informations
477pwg_log('category', $page['title']);
478
479$template->parse('category');
480include(PHPWG_ROOT_PATH.'include/page_tail.php');
481?>
Note: See TracBrowser for help on using the repository browser.