source: trunk/index.php @ 1119

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

improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.

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