source: trunk/index.php @ 1123

Last change on this file since 1123 was 1123, checked in by plg, 18 years ago

bug fixed: about.php was not starting with get_root_url()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-04-04 23:08:08 +0000 (Tue, 04 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1123 $
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, ini_get('session.cookie_path') );
48  redirect( make_index_url() );
49}
50
51//---------------------------------------------- change of image display order
52if (isset($_GET['image_order']))
53{
54  setcookie(
55    'pwg_image_order',
56    $_GET['image_order'] > 0 ? $_GET['image_order'] : '',
57    0, cookie_path()
58    );
59
60  redirect(
61    duplicate_index_URL(
62      array(),        // nothing to redefine
63      array('start')  // changing display order goes back to section first page
64      )
65    );
66}
67//-------------------------------------------------------------- initialization
68// detection of the start picture to display
69if (!isset($page['start']))
70{
71  $page['start'] = 0;
72}
73
74// access authorization check
75if (isset($page['category']))
76{
77  check_restrictions($page['category']);
78}
79
80if (isset($page['cat_nb_images'])
81    and $page['cat_nb_images'] > $user['nb_image_page'])
82{
83  $page['navigation_bar'] = create_navigation_bar(
84    duplicate_index_URL(array(), array('start')),
85    $page['cat_nb_images'],
86    $page['start'],
87    $user['nb_image_page'],
88    true
89    );
90}
91else
92{
93  $page['navigation_bar'] = '';
94}
95
96// caddie filling :-)
97if (isset($_GET['caddie']))
98{
99  fill_caddie($page['items']);
100  // redirect();
101}
102
103//----------------------------------------------------- template initialization
104//
105// Start output of page
106//
107$title = $page['title'];
108$page['body_id'] = 'theCategoryPage';
109include(PHPWG_ROOT_PATH.'include/page_header.php');
110
111$template->set_filenames( array('index'=>'index.tpl') );
112//-------------------------------------------------------------- category title
113$template_title = $page['title'];
114if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0)
115{
116  $template_title.= ' ['.$page['cat_nb_images'].']';
117}
118
119$icon_recent = get_icon(date('Y-m-d'));
120
121if (!isset($page['chronology_field']))
122{
123  $chronology_params =
124      array(
125          'chronology_field' => 'created',
126          'chronology_style' => 'monthly',
127          'chronology_view' => 'list',
128      );
129  $template->assign_block_vars(
130    'mode_created',
131    array(
132      'URL' => duplicate_index_URL( $chronology_params, array('start') )
133      )
134    );
135
136  $chronology_params['chronology_field'] = 'posted';
137  $template->assign_block_vars(
138    'mode_posted',
139    array(
140      'URL' => duplicate_index_URL( $chronology_params, array('start') )
141      )
142    );
143}
144else
145{
146  $template->assign_block_vars(
147    'mode_normal',
148    array(
149      'URL' => duplicate_index_URL( array(), array('chronology_field','start') )
150      )
151    );
152
153  if ($page['chronology_field'] == 'created')
154  {
155    $chronology_field = 'posted';
156  }
157  else
158  {
159    $chronology_field = 'created';
160  }
161  $url = duplicate_index_URL(
162            array('chronology_field'=>$chronology_field ),
163            array('chronology_date', 'start')
164          );
165  $template->assign_block_vars(
166    'mode_'.$chronology_field,
167    array('URL' => $url )
168    );
169}
170
171$template->assign_vars(
172  array(
173    'NB_PICTURE' => $user['nb_total_images'],
174    'TITLE' => $template_title,
175    'USERNAME' => $user['username'],
176    'TOP_NUMBER' => $conf['top_number'],
177    'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
178
179    'F_IDENTIFY' => get_root_url().'identification.php',
180    'T_RECENT' => $icon_recent,
181
182    'U_HOME' => make_index_URL(),
183    'U_REGISTER' => get_root_url().'register.php',
184    'U_LOST_PASSWORD' => get_root_url().'password.php',
185    'U_LOGOUT' => add_url_params(make_index_URL(), array('act'=>'logout') ),
186    'U_ADMIN'=> get_root_url().'admin.php',
187    'U_PROFILE'=> get_root_url().'profile.php',
188    )
189  );
190
191if ('search' == $page['section'])
192{
193  $template->assign_block_vars(
194    'search_rules',
195    array(
196      'URL' => get_root_url().'search_rules.php?search_id='.$page['search'],
197      )
198    );
199}
200//-------------------------------------------------------------- external links
201if (count($conf['links']) > 0)
202{
203  $template->assign_block_vars('links', array());
204
205  foreach ($conf['links'] as $url => $label)
206  {
207    $template->assign_block_vars(
208      'links.link',
209      array(
210        'URL' => $url,
211        'LABEL' => $label
212        )
213      );
214  }
215}
216//------------------------------------------------------------------------ tags
217if ('tags' == $page['section'])
218{
219  $template->assign_block_vars('tags', array());
220
221  // display tags associated to currently tagged items, less current tags
222  $tags = array();
223
224  if ( !empty($page['items']) )
225  {
226    $query = '
227SELECT tag_id, name, url_name, count(*) counter
228  FROM '.IMAGE_TAG_TABLE.'
229    INNER JOIN '.TAGS_TABLE.' ON tag_id = id
230  WHERE image_id IN ('.implode(',', $items).')
231    AND tag_id NOT IN ('.implode(',', $page['tag_ids']).')
232  GROUP BY tag_id
233  ORDER BY name ASC
234;';
235    $result = pwg_query($query);
236    while($row = mysql_fetch_array($result))
237    {
238      array_push($tags, $row);
239    }
240  }
241
242  $tags = add_level_to_tags($tags);
243
244  foreach ($tags as $tag)
245  {
246    $template->assign_block_vars(
247      'tags.tag',
248      array(
249        'URL_ADD' => make_index_URL(
250          array(
251            'tags' => array_merge(
252              $page['tags'],
253              array(
254                array(
255                  'id' => $tag['tag_id'],
256                  'url_name' => $tag['url_name'],
257                  ),
258                )
259              )
260            )
261          ),
262
263        'URL' => make_index_URL(
264          array(
265            'tags' => array(
266              array(
267                'id' => $tag['tag_id'],
268                'url_name' => $tag['url_name'],
269                ),
270              )
271            )
272          ),
273
274        'NAME' => $tag['name'],
275
276        'TITLE' => l10n('See pictures linked to this tag only'),
277
278        'TITLE_ADD' => sprintf(
279          l10n('%d pictures are also linked to current tags'),
280          $tag['counter']
281          ),
282
283        'CLASS' => 'tagLevel'.$tag['level']
284        )
285      );
286  }
287}
288//---------------------------------------------------------- special categories
289// favorites categories
290if ( !$user['is_the_guest'] )
291{
292  $template->assign_block_vars('username', array());
293
294  $template->assign_block_vars(
295    'special_cat',
296    array(
297      'URL' => make_index_URL(array('section' => 'favorites')),
298      'TITLE' => $lang['favorite_cat_hint'],
299      'NAME' => $lang['favorite_cat']
300      ));
301}
302// most visited
303$template->assign_block_vars(
304  'special_cat',
305  array(
306    'URL' => make_index_URL(array('section' => 'most_visited')),
307    'TITLE' => $lang['most_visited_cat_hint'],
308    'NAME' => $lang['most_visited_cat']
309    ));
310// best rated
311if ($conf['rate'])
312{
313  $template->assign_block_vars(
314    'special_cat',
315    array(
316      'URL' => make_index_URL(array('section' => 'best_rated')),
317      'TITLE' => $lang['best_rated_cat_hint'],
318      'NAME' => $lang['best_rated_cat']
319      )
320    );
321}
322// random
323$template->assign_block_vars(
324  'special_cat',
325  array(
326    'URL' => get_root_url().'random.php',
327    'TITLE' => $lang['random_cat_hint'],
328    'NAME' => $lang['random_cat']
329    ));
330// recent pics
331$template->assign_block_vars(
332  'special_cat',
333  array(
334    'URL' => make_index_URL(array('section' => 'recent_pics')),
335    'TITLE' => $lang['recent_pics_cat_hint'],
336    'NAME' => $lang['recent_pics_cat']
337    ));
338// recent cats
339$template->assign_block_vars(
340  'special_cat',
341  array(
342    'URL' => make_index_URL(array('section' => 'recent_cats')),
343    'TITLE' => $lang['recent_cats_cat_hint'],
344    'NAME' => $lang['recent_cats_cat']
345    ));
346
347// calendar
348$template->assign_block_vars(
349  'special_cat',
350  array(
351    'URL' =>
352      make_index_URL(
353        array(
354          'chronology_field' => ($conf['calendar_datefield']=='date_available'
355                                  ? 'posted' : 'created'),
356           'chronology_style'=> 'monthly',
357           'chronology_view' => 'calendar'
358        )
359      ),
360    'TITLE' => $lang['calendar_hint'],
361    'NAME' => $lang['calendar']
362    )
363  );
364//--------------------------------------------------------------------- summary
365
366if ($user['is_the_guest'])
367{
368  $template->assign_block_vars('register', array());
369  $template->assign_block_vars('login', array());
370
371  $template->assign_block_vars('quickconnect', array());
372  if ($conf['authorize_remembering'])
373  {
374    $template->assign_block_vars('quickconnect.remember_me', array());
375  }
376}
377else
378{
379  $template->assign_block_vars('hello', array());
380
381  if (is_autorize_status(ACCESS_CLASSIC))
382  {
383    $template->assign_block_vars('profile', array());
384  }
385
386  // the logout link has no meaning with Apache authentication : it is not
387  // possible to logout with this kind of authentication.
388  if (!$conf['apache_authentication'])
389  {
390    $template->assign_block_vars('logout', array());
391  }
392
393  if (is_admin())
394  {
395    $template->assign_block_vars('admin', array());
396  }
397}
398
399// tags link
400$template->assign_block_vars(
401  'summary',
402  array(
403    'TITLE' => l10n('See available tags'),
404    'NAME' => l10n('Tags'),
405    'U_SUMMARY'=> get_root_url().'tags.php',
406    )
407  );
408
409// search link
410$template->assign_block_vars(
411  'summary',
412  array(
413    'TITLE'=>$lang['hint_search'],
414    'NAME'=>$lang['search'],
415    'U_SUMMARY'=> get_root_url().'search.php',
416    'REL'=> 'rel="search"'
417    )
418  );
419
420// comments link
421$template->assign_block_vars(
422  'summary',
423  array(
424    'TITLE'=>$lang['hint_comments'],
425    'NAME'=>$lang['comments'],
426    'U_SUMMARY'=> get_root_url().'comments.php',
427    )
428  );
429
430// about link
431$template->assign_block_vars(
432  'summary',
433  array(
434    'TITLE'     => $lang['about_page_title'],
435    'NAME'      => $lang['About'],
436    'U_SUMMARY' => get_root_url().'about.php',
437    )
438  );
439
440// notification
441$template->assign_block_vars(
442  'summary',
443  array(
444    'TITLE'=>l10n('notification'),
445    'NAME'=>l10n('Notification'),
446    'U_SUMMARY'=> get_root_url().'notification.php',
447    'REL'=> 'rel="nofollow"'
448    )
449  );
450
451if (isset($page['category']) and is_admin())
452{
453  $template->assign_block_vars(
454    'edit',
455    array(
456      'URL' =>
457        get_root_url().'admin.php?page=cat_modify'
458        .'&amp;cat_id='.$page['category']
459      )
460    );
461}
462
463if (is_admin() and !empty($page['items']) )
464{
465    $template->assign_block_vars(
466      'caddie',
467      array(
468        'URL' =>
469          add_url_params(duplicate_index_url(), array('caddie'=>1) )
470        )
471      );
472  }
473
474//------------------------------------------------------ main part : thumbnails
475if (isset($page['thumbnails_include']))
476{
477  include(PHPWG_ROOT_PATH.$page['thumbnails_include']);
478}
479//------------------------------------------------------- category informations
480if (
481  $page['navigation_bar'] != ''
482  or (isset($page['comment']) and $page['comment'] != '')
483  )
484{
485  $template->assign_block_vars('cat_infos',array());
486}
487// navigation bar
488if ($page['navigation_bar'] != '')
489{
490  $template->assign_block_vars(
491    'cat_infos.navigation',
492    array(
493      'NAV_BAR' => $page['navigation_bar'],
494      )
495    );
496}
497
498if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0
499    and $page['section'] != 'most_visited'
500    and $page['section'] != 'best_rated')
501{
502  // image order
503  $template->assign_block_vars( 'preferred_image_order', array() );
504
505  $order_idx = isset($_COOKIE['pwg_image_order'])
506    ? $_COOKIE['pwg_image_order']
507    : 0
508    ;
509
510  $orders = get_category_preferred_image_orders();
511  for ($i = 0; $i < count($orders); $i++)
512  {
513    if ($orders[$i][2])
514    {
515      $template->assign_block_vars(
516        'preferred_image_order.order',
517        array(
518          'DISPLAY' => $orders[$i][0],
519          'URL' => add_url_params( duplicate_index_URL(), array('image_order'=>$i) ),
520          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : ''),
521          )
522        );
523    }
524  }
525}
526
527if (isset($page['category']))
528{
529  // upload a picture in the category
530  if ($page['cat_uploadable'])
531  {
532    $url = get_root_url().'upload.php?cat='.$page['category'];
533    $template->assign_block_vars(
534      'upload',
535      array(
536        'U_UPLOAD'=> $url
537        )
538      );
539  }
540
541  // category comment
542  if (isset($page['comment']) and $page['comment'] != '')
543  {
544    $template->assign_block_vars(
545      'cat_infos.comment',
546      array(
547        'COMMENTS' => $page['comment']
548        )
549      );
550  }
551}
552//------------------------------------------------------------ log informations
553pwg_log('category', $page['title']);
554
555$template->parse('index');
556include(PHPWG_ROOT_PATH.'include/page_tail.php');
557?>
Note: See TracBrowser for help on using the repository browser.