source: trunk/index.php @ 13088

Last change on this file since 13088 was 13062, checked in by plg, 9 years ago

feature 2368: also add canonical URL on index page.

  • Property svn:eol-style set to LF
File size: 9.6 KB
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
92$template->assign('U_CANONICAL', duplicate_index_url());
93
94//----------------------------------------------------- template initialization
95//
96// Start output of page
97//
98$title = $page['title'];
99$page['body_id'] = 'theCategoryPage';
100
101$template->set_filenames( array('index'=>'index.tpl') );
102//-------------------------------------------------------------- category title
103$template_title = $page['title'];
104if (count($page['items']) > 0)
105{
106  $template_title.= ' ['.count($page['items']).']';
107}
108$template->assign('TITLE', $template_title);
109
110if (isset($page['flat']) or isset($page['chronology_field']))
111{
112  $template->assign(
113    'U_MODE_NORMAL',
114    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
115    );
116}
117
118if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
119{
120  $template->assign(
121    'U_MODE_FLAT',
122    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
123    );
124}
125
126if (!isset($page['chronology_field']))
127{
128  $chronology_params =
129      array(
130          'chronology_field' => 'created',
131          'chronology_style' => 'monthly',
132          'chronology_view' => 'list',
133      );
134  if ($conf['index_created_date_icon'])
135  {
136    $template->assign(
137      'U_MODE_CREATED',
138      duplicate_index_url( $chronology_params, array('start', 'flat') )
139      );
140  }
141  if ($conf['index_posted_date_icon'])
142  {
143    $chronology_params['chronology_field'] = 'posted';
144    $template->assign(
145      'U_MODE_POSTED',
146      duplicate_index_url( $chronology_params, array('start', 'flat') )
147      );
148  }
149}
150else
151{
152  if ($page['chronology_field'] == 'created')
153  {
154    $chronology_field = 'posted';
155  }
156  else
157  {
158    $chronology_field = 'created';
159  }
160  if ($conf['index_'.$chronology_field.'_date_icon'])
161  {
162    $url = duplicate_index_url(
163              array('chronology_field'=>$chronology_field ),
164              array('chronology_date', 'start', 'flat')
165            );
166    $template->assign(
167        'U_MODE_'.strtoupper($chronology_field),
168        $url
169      );
170  }
171}
172
173if ('search' == $page['section'])
174{
175  $template->assign(
176    'U_SEARCH_RULES',
177    get_root_url().'search_rules.php?search_id='.$page['search']
178    );
179}
180
181if (isset($page['category']) and is_admin())
182{
183  $template->assign(
184    'U_EDIT',
185    get_root_url().'admin.php?page=album-'.$page['category']['id']
186    );
187}
188
189if (is_admin() and !empty($page['items']))
190{
191  $template->assign(
192    'U_CADDIE',
193     add_url_params(duplicate_index_url(), array('caddie'=>1) )
194    );
195}
196
197if ( $page['section']=='search' and $page['start']==0 and
198    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
199{
200  $template->assign('QUERY_SEARCH',
201    htmlspecialchars($page['qsearch_details']['q']) );
202
203  $cats = array_merge(
204      (array)@$page['qsearch_details']['matching_cats_no_images'],
205      (array)@$page['qsearch_details']['matching_cats'] );
206  if (count($cats))
207  {
208    usort($cats, 'name_compare');
209    $hints = array();
210    foreach ( $cats as $cat )
211    {
212      $hints[] = get_cat_display_name( array($cat), '', false );
213    }
214    $template->assign( 'category_search_results', $hints);
215  }
216
217  $tags = (array)@$page['qsearch_details']['matching_tags'];
218  if (count($tags))
219  {
220    usort($tags, 'name_compare');
221    $hints = array();
222    foreach ( $tags as $tag )
223    {
224      $hints[] =
225        '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
226        .trigger_event('render_tag_name', $tag['name'])
227        .'</a>';
228    }
229    $template->assign( 'tag_search_results', $hints);
230  }
231}
232
233// navigation bar
234$template->assign( 'navbar', $page['navigation_bar'] );
235
236if ( $conf['index_sort_order_input']
237    and count($page['items']) > 0
238    and $page['section'] != 'most_visited'
239    and $page['section'] != 'best_rated')
240{
241  // image order
242  $order_idx = pwg_get_session_var( 'image_order', 0 );
243
244  $url = add_url_params(
245          duplicate_index_url(),
246          array('image_order' => '')
247        );
248  foreach (get_category_preferred_image_orders() as $order_id => $order)
249  {
250    if ($order[2])
251    {
252      $template->append(
253        'image_orders',
254        array(
255          'DISPLAY' => $order[0],
256          'URL' => $url.$order_id,
257          'SELECTED' => ($order_idx == $order_id ? true:false),
258          )
259        );
260    }
261  }
262}
263
264if ( count($page['items']) > 0 )
265{
266  $url = add_url_params(
267          duplicate_index_url(),
268          array('display' => '')
269        );
270  $selected_type = pwg_get_session_var('index_deriv', IMG_THUMB);
271  $type_map = ImageStdParams::get_defined_type_map();
272  unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
273  foreach($type_map as $params)
274  {
275    $template->append(
276      'image_derivatives',
277      array(
278        'DISPLAY' => l10n($params->type),
279        'URL' => $url.$params->type,
280        'SELECTED' => ($params->type == $selected_type ? true:false),
281        )
282      );
283  }
284}
285
286// category comment
287if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
288{
289  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
290}
291
292// include menubar
293include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
294
295if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 )
296{// count_categories might be computed by menubar - if the case unassign flat link if no sub albums
297        $template->clear_assign('U_MODE_FLAT');
298}
299
300//------------------------------------------------------ main part : thumbnails
301if ( 0==$page['start']
302    and !isset($page['flat'])
303    and !isset($page['chronology_field'])
304    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
305    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
306  )
307{
308  include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
309}
310if ( !empty($page['items']) )
311{
312  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
313}
314//------------------------------------------------------- category informations
315
316// slideshow
317// execute after init thumbs in order to have all picture informations
318if (!empty($page['cat_slideshow_url']))
319{
320  if (isset($_GET['slideshow']))
321  {
322    redirect($page['cat_slideshow_url']);
323  }
324  elseif ($conf['index_slideshow_icon'])
325  {
326    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
327  }
328}
329
330include(PHPWG_ROOT_PATH.'include/page_header.php');
331trigger_action('loc_end_index');
332$template->pparse('index');
333//------------------------------------------------------------ log informations
334pwg_log();
335include(PHPWG_ROOT_PATH.'include/page_tail.php');
336?>
Note: See TracBrowser for help on using the repository browser.