source: trunk/index.php @ 1145

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

merge r1144 from branch-1_6 into trunk

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