source: trunk/index.php @ 13777

Revision 13458, 9.8 KB checked in by plg, 8 years ago (diff)

feature 2368: better canonical URL for homepage

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
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  |
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.                                                                  |
22// +-----------------------------------------------------------------------+
23
24//--------------------------------------------------------------------- include
25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
27include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
28
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}
42
43trigger_action('loc_begin_index');
44
45//---------------------------------------------- change of image display order
46if (isset($_GET['image_order']))
47{
48  if ( (int)$_GET['image_order'] > 0)
49  {
50    pwg_set_session_var('image_order', (int)$_GET['image_order']);
51  }
52  else
53  {
54    pwg_unset_session_var('image_order');
55  }
56  redirect(
57    duplicate_index_url(
58      array(),        // nothing to redefine
59      array('start')  // changing display order goes back to section first page
60      )
61    );
62}
63if (isset($_GET['display']))
64{
65  $page['meta_robots']['noindex']=1;
66  if (array_key_exists($_GET['display'], ImageStdParams::get_defined_type_map()))
67  {
68    pwg_set_session_var('index_deriv', $_GET['display']);
69  }
70}
71//-------------------------------------------------------------- initialization
72
73$page['navigation_bar'] = array();
74if (count($page['items']) > $page['nb_image_page'])
75{
76  $page['navigation_bar'] = create_navigation_bar(
77    duplicate_index_url(array(), array('start')),
78    count($page['items']),
79    $page['start'],
80    $page['nb_image_page'],
81    true
82    );
83}
84
85// caddie filling :-)
86if (isset($_GET['caddie']))
87{
88  fill_caddie($page['items']);
89  redirect(duplicate_index_url());
90}
91
92if (isset($page['is_homepage']) and $page['is_homepage'])
93{
94  $canonical_url = get_gallery_home_url();
95}
96else
97{
98  $canonical_url = duplicate_index_url();
99}
100$template->assign('U_CANONICAL', $canonical_url);
101
102//----------------------------------------------------- template initialization
103//
104// Start output of page
105//
106$title = $page['title'];
107$page['body_id'] = 'theCategoryPage';
108
109$template->set_filenames( array('index'=>'index.tpl') );
110//-------------------------------------------------------------- category title
111$template_title = $page['title'];
112if (count($page['items']) > 0)
113{
114  $template_title.= ' ['.count($page['items']).']';
115}
116$template->assign('TITLE', $template_title);
117
118if (isset($page['flat']) or isset($page['chronology_field']))
119{
120  $template->assign(
121    'U_MODE_NORMAL',
122    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
123    );
124}
125
126if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
127{
128  $template->assign(
129    'U_MODE_FLAT',
130    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
131    );
132}
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  if ($conf['index_created_date_icon'])
143  {
144    $template->assign(
145      'U_MODE_CREATED',
146      duplicate_index_url( $chronology_params, array('start', 'flat') )
147      );
148  }
149  if ($conf['index_posted_date_icon'])
150  {
151    $chronology_params['chronology_field'] = 'posted';
152    $template->assign(
153      'U_MODE_POSTED',
154      duplicate_index_url( $chronology_params, array('start', 'flat') )
155      );
156  }
157}
158else
159{
160  if ($page['chronology_field'] == 'created')
161  {
162    $chronology_field = 'posted';
163  }
164  else
165  {
166    $chronology_field = 'created';
167  }
168  if ($conf['index_'.$chronology_field.'_date_icon'])
169  {
170    $url = duplicate_index_url(
171              array('chronology_field'=>$chronology_field ),
172              array('chronology_date', 'start', 'flat')
173            );
174    $template->assign(
175        'U_MODE_'.strtoupper($chronology_field),
176        $url
177      );
178  }
179}
180
181if ('search' == $page['section'])
182{
183  $template->assign(
184    'U_SEARCH_RULES',
185    get_root_url().'search_rules.php?search_id='.$page['search']
186    );
187}
188
189if (isset($page['category']) and is_admin())
190{
191  $template->assign(
192    'U_EDIT',
193    get_root_url().'admin.php?page=album-'.$page['category']['id']
194    );
195}
196
197if (is_admin() and !empty($page['items']))
198{
199  $template->assign(
200    'U_CADDIE',
201     add_url_params(duplicate_index_url(), array('caddie'=>1) )
202    );
203}
204
205if ( $page['section']=='search' and $page['start']==0 and
206    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
207{
208  $template->assign('QUERY_SEARCH',
209    htmlspecialchars($page['qsearch_details']['q']) );
210
211  $cats = array_merge(
212      (array)@$page['qsearch_details']['matching_cats_no_images'],
213      (array)@$page['qsearch_details']['matching_cats'] );
214  if (count($cats))
215  {
216    usort($cats, 'name_compare');
217    $hints = array();
218    foreach ( $cats as $cat )
219    {
220      $hints[] = get_cat_display_name( array($cat), '', false );
221    }
222    $template->assign( 'category_search_results', $hints);
223  }
224
225  $tags = (array)@$page['qsearch_details']['matching_tags'];
226  if (count($tags))
227  {
228    usort($tags, 'name_compare');
229    $hints = array();
230    foreach ( $tags as $tag )
231    {
232      $hints[] =
233        '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
234        .trigger_event('render_tag_name', $tag['name'])
235        .'</a>';
236    }
237    $template->assign( 'tag_search_results', $hints);
238  }
239}
240
241// navigation bar
242$template->assign( 'navbar', $page['navigation_bar'] );
243
244if ( $conf['index_sort_order_input']
245    and count($page['items']) > 0
246    and $page['section'] != 'most_visited'
247    and $page['section'] != 'best_rated')
248{
249  // image order
250  $order_idx = pwg_get_session_var( 'image_order', 0 );
251
252  $url = add_url_params(
253          duplicate_index_url(),
254          array('image_order' => '')
255        );
256  foreach (get_category_preferred_image_orders() as $order_id => $order)
257  {
258    if ($order[2])
259    {
260      $template->append(
261        'image_orders',
262        array(
263          'DISPLAY' => $order[0],
264          'URL' => $url.$order_id,
265          'SELECTED' => ($order_idx == $order_id ? true:false),
266          )
267        );
268    }
269  }
270}
271
272if ( count($page['items']) > 0 )
273{
274  $url = add_url_params(
275          duplicate_index_url(),
276          array('display' => '')
277        );
278  $selected_type = pwg_get_session_var('index_deriv', IMG_THUMB);
279  $type_map = ImageStdParams::get_defined_type_map();
280  unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
281  foreach($type_map as $params)
282  {
283    $template->append(
284      'image_derivatives',
285      array(
286        'DISPLAY' => l10n($params->type),
287        'URL' => $url.$params->type,
288        'SELECTED' => ($params->type == $selected_type ? true:false),
289        )
290      );
291  }
292}
293
294// category comment
295if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
296{
297  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
298}
299
300// include menubar
301include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
302
303if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 )
304{// count_categories might be computed by menubar - if the case unassign flat link if no sub albums
305        $template->clear_assign('U_MODE_FLAT');
306}
307
308//------------------------------------------------------ main part : thumbnails
309if ( 0==$page['start']
310    and !isset($page['flat'])
311    and !isset($page['chronology_field'])
312    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
313    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
314  )
315{
316  include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
317}
318if ( !empty($page['items']) )
319{
320  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
321}
322//------------------------------------------------------- category informations
323
324// slideshow
325// execute after init thumbs in order to have all picture informations
326if (!empty($page['cat_slideshow_url']))
327{
328  if (isset($_GET['slideshow']))
329  {
330    redirect($page['cat_slideshow_url']);
331  }
332  elseif ($conf['index_slideshow_icon'])
333  {
334    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
335  }
336}
337
338include(PHPWG_ROOT_PATH.'include/page_header.php');
339trigger_action('loc_end_index');
340$template->pparse('index');
341//------------------------------------------------------------ log informations
342pwg_log();
343include(PHPWG_ROOT_PATH.'include/page_tail.php');
344?>
Note: See TracBrowser for help on using the repository browser.