source: branches/2.4/index.php @ 27569

Last change on this file since 27569 was 18668, checked in by rvelices, 12 years ago

merge -r18667 from trunk - improved page title when viewing tags, fix canonical url on index page if the webmaster changes the default number of thumbnails per page

  • Property svn:eol-style set to LF
File size: 10.2 KB
RevLine 
[2]1<?php
[351]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[351]4// +-----------------------------------------------------------------------+
[12908]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2342]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
[351]8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
[352]11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
[351]22// +-----------------------------------------------------------------------+
[2]23
[352]24//--------------------------------------------------------------------- include
[364]25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1084]27include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
[1072]28
[8401]29// Check Access and exit when user status is not ok
30check_status(ACCESS_GUEST);
31
32if (!isset($page['start']))
33{
34  $page['start'] = 0;
35}
36
37// access authorization check
38if (isset($page['category']))
39{
40  check_restrictions($page['category']['id']);
41}
[13872]42if ($page['start']>0 && $page['start']>=count($page['items']))
43{
44  page_not_found('', duplicate_index_url(array('start'=>0)));
45}
[8401]46
[1604]47trigger_action('loc_begin_index');
48
[1059]49//---------------------------------------------- change of image display order
[1036]50if (isset($_GET['image_order']))
[614]51{
[1623]52  if ( (int)$_GET['image_order'] > 0)
53  {
54    pwg_set_session_var('image_order', (int)$_GET['image_order']);
55  }
56  else
57  {
58    pwg_unset_session_var('image_order');
59  }
[1036]60  redirect(
[1503]61    duplicate_index_url(
[1084]62      array(),        // nothing to redefine
63      array('start')  // changing display order goes back to section first page
[1082]64      )
[1036]65    );
[614]66}
[12908]67if (isset($_GET['display']))
68{
69  $page['meta_robots']['noindex']=1;
70  if (array_key_exists($_GET['display'], ImageStdParams::get_defined_type_map()))
71  {
72    pwg_set_session_var('index_deriv', $_GET['display']);
73  }
74}
[2]75//-------------------------------------------------------------- initialization
[345]76
[3172]77$page['navigation_bar'] = array();
[8432]78if (count($page['items']) > $page['nb_image_page'])
[1036]79{
80  $page['navigation_bar'] = create_navigation_bar(
[1503]81    duplicate_index_url(array(), array('start')),
[1820]82    count($page['items']),
[1036]83    $page['start'],
[3117]84    $page['nb_image_page'],
[1084]85    true
[1036]86    );
87}
88
[755]89// caddie filling :-)
90if (isset($_GET['caddie']))
91{
[1036]92  fill_caddie($page['items']);
[2114]93  redirect(duplicate_index_url());
[755]94}
95
[13458]96if (isset($page['is_homepage']) and $page['is_homepage'])
97{
98  $canonical_url = get_gallery_home_url();
99}
100else
101{
[18668]102  $start = $page['nb_image_page'] * round($page['start'] / $page['nb_image_page']);
103  if ($start>0 && $start >= count($page['items']) )
104  {
105    $start -= $page['nb_image_page'];
106  }
107  $canonical_url = duplicate_index_url(array('start' => $start));
[13458]108}
109$template->assign('U_CANONICAL', $canonical_url);
[13062]110
[2]111//----------------------------------------------------- template initialization
[345]112//
113// Start output of page
114//
115$title = $page['title'];
[850]116$page['body_id'] = 'theCategoryPage';
[345]117
[1109]118$template->set_filenames( array('index'=>'index.tpl') );
[351]119//-------------------------------------------------------------- category title
[1120]120$template_title = $page['title'];
[2218]121if (count($page['items']) > 0)
[428]122{
[1820]123  $template_title.= ' ['.count($page['items']).']';
[428]124}
[2231]125$template->assign('TITLE', $template_title);
[2]126
[1800]127if (isset($page['flat']) or isset($page['chronology_field']))
[1648]128{
[2231]129  $template->assign(
130    'U_MODE_NORMAL',
131    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
[1648]132    );
133}
134
[5293]135if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
[1651]136{
[2231]137  $template->assign(
138    'U_MODE_FLAT',
139    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
[1651]140    );
141}
142
[1090]143if (!isset($page['chronology_field']))
[1047]144{
[1090]145  $chronology_params =
146      array(
147          'chronology_field' => 'created',
148          'chronology_style' => 'monthly',
149          'chronology_view' => 'list',
150      );
[5293]151  if ($conf['index_created_date_icon'])
152  {
153    $template->assign(
154      'U_MODE_CREATED',
155      duplicate_index_url( $chronology_params, array('start', 'flat') )
156      );
157  }
158  if ($conf['index_posted_date_icon'])
159  {
160    $chronology_params['chronology_field'] = 'posted';
161    $template->assign(
162      'U_MODE_POSTED',
163      duplicate_index_url( $chronology_params, array('start', 'flat') )
164      );
165  }
[1047]166}
[1050]167else
168{
[1090]169  if ($page['chronology_field'] == 'created')
[1059]170  {
[1090]171    $chronology_field = 'posted';
[1059]172  }
173  else
174  {
[1090]175    $chronology_field = 'created';
[1059]176  }
[5293]177  if ($conf['index_'.$chronology_field.'_date_icon'])
178  {
179    $url = duplicate_index_url(
180              array('chronology_field'=>$chronology_field ),
181              array('chronology_date', 'start', 'flat')
182            );
183    $template->assign(
184        'U_MODE_'.strtoupper($chronology_field),
185        $url
186      );
187  }
[1050]188}
[1047]189
[1082]190if ('search' == $page['section'])
[1015]191{
[2231]192  $template->assign(
193    'U_SEARCH_RULES',
194    get_root_url().'search_rules.php?search_id='.$page['search']
[1015]195    );
196}
[797]197
[1082]198if (isset($page['category']) and is_admin())
[834]199{
[2231]200  $template->assign(
201    'U_EDIT',
[13025]202    get_root_url().'admin.php?page=album-'.$page['category']['id']
[834]203    );
204}
205
[2218]206if (is_admin() and !empty($page['items']))
[1092]207{
[2231]208  $template->assign(
209    'U_CADDIE',
210     add_url_params(duplicate_index_url(), array('caddie'=>1) )
[2135]211    );
212}
213
214if ( $page['section']=='search' and $page['start']==0 and
215    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
216{
[2231]217  $template->assign('QUERY_SEARCH',
[2135]218    htmlspecialchars($page['qsearch_details']['q']) );
219
[2138]220  $cats = array_merge(
[2135]221      (array)@$page['qsearch_details']['matching_cats_no_images'],
222      (array)@$page['qsearch_details']['matching_cats'] );
[2138]223  if (count($cats))
[2135]224  {
[2138]225    usort($cats, 'name_compare');
[2135]226    $hints = array();
[2138]227    foreach ( $cats as $cat )
[2135]228    {
[2770]229      $hints[] = get_cat_display_name( array($cat), '', false );
[2135]230    }
[2231]231    $template->assign( 'category_search_results', $hints);
[1092]232  }
233
[2138]234  $tags = (array)@$page['qsearch_details']['matching_tags'];
[2135]235  if (count($tags))
[1537]236  {
[2135]237    usort($tags, 'name_compare');
238    $hints = array();
239    foreach ( $tags as $tag )
[1537]240    {
[2135]241      $hints[] =
242        '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
[12553]243        .trigger_event('render_tag_name', $tag['name'])
[2135]244        .'</a>';
245    }
[2231]246    $template->assign( 'tag_search_results', $hints);
[1537]247  }
248}
249
[1047]250// navigation bar
[3172]251$template->assign( 'navbar', $page['navigation_bar'] );
[1051]252
[5293]253if ( $conf['index_sort_order_input']
254    and count($page['items']) > 0
[1082]255    and $page['section'] != 'most_visited'
256    and $page['section'] != 'best_rated')
[1051]257{
258  // image order
[1623]259  $order_idx = pwg_get_session_var( 'image_order', 0 );
[1051]260
[3146]261  $url = add_url_params(
262          duplicate_index_url(),
263          array('image_order' => '')
264        );
265  foreach (get_category_preferred_image_orders() as $order_id => $order)
[1051]266  {
[2517]267    if ($order[2])
[1051]268    {
[2231]269      $template->append(
270        'image_orders',
[1082]271        array(
[2517]272          'DISPLAY' => $order[0],
[3146]273          'URL' => $url.$order_id,
[2517]274          'SELECTED' => ($order_idx == $order_id ? true:false),
[1082]275          )
276        );
[1051]277    }
278  }
279}
280
[1604]281// category comment
[8401]282if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
[2]283{
[2231]284  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
[2]285}
[2586]286
287// include menubar
288include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
289
[8463]290if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 )
291{// count_categories might be computed by menubar - if the case unassign flat link if no sub albums
292        $template->clear_assign('U_MODE_FLAT');
293}
294
[2586]295//------------------------------------------------------ main part : thumbnails
296if ( 0==$page['start']
297    and !isset($page['flat'])
298    and !isset($page['chronology_field'])
299    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
300    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
301  )
302{
303  include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
304}
305if ( !empty($page['items']) )
306{
307  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
[16988]308  $url = add_url_params(
309          duplicate_index_url(),
310          array('display' => '')
311        );
312  $selected_type = $template->get_template_vars('derivative_params')->type;
313  $template->clear_assign( 'derivative_params' );
314  $type_map = ImageStdParams::get_defined_type_map();
315  unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
316  foreach($type_map as $params)
317  {
318    $template->append(
319      'image_derivatives',
320      array(
321        'DISPLAY' => l10n($params->type),
322        'URL' => $url.$params->type,
323        'SELECTED' => ($params->type == $selected_type ? true:false),
324        )
325      );
326  }
[2586]327}
328//------------------------------------------------------- category informations
329
330// slideshow
331// execute after init thumbs in order to have all picture informations
332if (!empty($page['cat_slideshow_url']))
333{
334  if (isset($_GET['slideshow']))
335  {
336    redirect($page['cat_slideshow_url']);
337  }
[5293]338  elseif ($conf['index_slideshow_icon'])
[2586]339  {
340    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
341  }
342}
343
[1655]344include(PHPWG_ROOT_PATH.'include/page_header.php');
[1604]345trigger_action('loc_end_index');
[15578]346include(PHPWG_ROOT_PATH.'include/page_messages.php');
[2231]347$template->pparse('index');
[2699]348//------------------------------------------------------------ log informations
349pwg_log();
[369]350include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]351?>
Note: See TracBrowser for help on using the repository browser.