source: branches/2.4/index.php @ 24070

Last change on this file since 24070 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
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}
42if ($page['start']>0 && $page['start']>=count($page['items']))
43{
44  page_not_found('', duplicate_index_url(array('start'=>0)));
45}
46
47trigger_action('loc_begin_index');
48
49//---------------------------------------------- change of image display order
50if (isset($_GET['image_order']))
51{
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  }
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}
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}
75//-------------------------------------------------------------- initialization
76
77$page['navigation_bar'] = array();
78if (count($page['items']) > $page['nb_image_page'])
79{
80  $page['navigation_bar'] = create_navigation_bar(
81    duplicate_index_url(array(), array('start')),
82    count($page['items']),
83    $page['start'],
84    $page['nb_image_page'],
85    true
86    );
87}
88
89// caddie filling :-)
90if (isset($_GET['caddie']))
91{
92  fill_caddie($page['items']);
93  redirect(duplicate_index_url());
94}
95
96if (isset($page['is_homepage']) and $page['is_homepage'])
97{
98  $canonical_url = get_gallery_home_url();
99}
100else
101{
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));
108}
109$template->assign('U_CANONICAL', $canonical_url);
110
111//----------------------------------------------------- template initialization
112//
113// Start output of page
114//
115$title = $page['title'];
116$page['body_id'] = 'theCategoryPage';
117
118$template->set_filenames( array('index'=>'index.tpl') );
119//-------------------------------------------------------------- category title
120$template_title = $page['title'];
121if (count($page['items']) > 0)
122{
123  $template_title.= ' ['.count($page['items']).']';
124}
125$template->assign('TITLE', $template_title);
126
127if (isset($page['flat']) or isset($page['chronology_field']))
128{
129  $template->assign(
130    'U_MODE_NORMAL',
131    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
132    );
133}
134
135if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
136{
137  $template->assign(
138    'U_MODE_FLAT',
139    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
140    );
141}
142
143if (!isset($page['chronology_field']))
144{
145  $chronology_params =
146      array(
147          'chronology_field' => 'created',
148          'chronology_style' => 'monthly',
149          'chronology_view' => 'list',
150      );
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  }
166}
167else
168{
169  if ($page['chronology_field'] == 'created')
170  {
171    $chronology_field = 'posted';
172  }
173  else
174  {
175    $chronology_field = 'created';
176  }
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  }
188}
189
190if ('search' == $page['section'])
191{
192  $template->assign(
193    'U_SEARCH_RULES',
194    get_root_url().'search_rules.php?search_id='.$page['search']
195    );
196}
197
198if (isset($page['category']) and is_admin())
199{
200  $template->assign(
201    'U_EDIT',
202    get_root_url().'admin.php?page=album-'.$page['category']['id']
203    );
204}
205
206if (is_admin() and !empty($page['items']))
207{
208  $template->assign(
209    'U_CADDIE',
210     add_url_params(duplicate_index_url(), array('caddie'=>1) )
211    );
212}
213
214if ( $page['section']=='search' and $page['start']==0 and
215    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
216{
217  $template->assign('QUERY_SEARCH',
218    htmlspecialchars($page['qsearch_details']['q']) );
219
220  $cats = array_merge(
221      (array)@$page['qsearch_details']['matching_cats_no_images'],
222      (array)@$page['qsearch_details']['matching_cats'] );
223  if (count($cats))
224  {
225    usort($cats, 'name_compare');
226    $hints = array();
227    foreach ( $cats as $cat )
228    {
229      $hints[] = get_cat_display_name( array($cat), '', false );
230    }
231    $template->assign( 'category_search_results', $hints);
232  }
233
234  $tags = (array)@$page['qsearch_details']['matching_tags'];
235  if (count($tags))
236  {
237    usort($tags, 'name_compare');
238    $hints = array();
239    foreach ( $tags as $tag )
240    {
241      $hints[] =
242        '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
243        .trigger_event('render_tag_name', $tag['name'])
244        .'</a>';
245    }
246    $template->assign( 'tag_search_results', $hints);
247  }
248}
249
250// navigation bar
251$template->assign( 'navbar', $page['navigation_bar'] );
252
253if ( $conf['index_sort_order_input']
254    and count($page['items']) > 0
255    and $page['section'] != 'most_visited'
256    and $page['section'] != 'best_rated')
257{
258  // image order
259  $order_idx = pwg_get_session_var( 'image_order', 0 );
260
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)
266  {
267    if ($order[2])
268    {
269      $template->append(
270        'image_orders',
271        array(
272          'DISPLAY' => $order[0],
273          'URL' => $url.$order_id,
274          'SELECTED' => ($order_idx == $order_id ? true:false),
275          )
276        );
277    }
278  }
279}
280
281// category comment
282if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
283{
284  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
285}
286
287// include menubar
288include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
289
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
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');
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  }
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  }
338  elseif ($conf['index_slideshow_icon'])
339  {
340    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
341  }
342}
343
344include(PHPWG_ROOT_PATH.'include/page_header.php');
345trigger_action('loc_end_index');
346include(PHPWG_ROOT_PATH.'include/page_messages.php');
347$template->pparse('index');
348//------------------------------------------------------------ log informations
349pwg_log();
350include(PHPWG_ROOT_PATH.'include/page_tail.php');
351?>
Note: See TracBrowser for help on using the repository browser.