source: branches/2.5/index.php @ 21186

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

replaced page_messages.php with a function to call

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