source: trunk/index.php @ 12908

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

feature 2548 multisize - ability to choose displayed size on index page
-added some logs on i.php (configurable) to measure the perf

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