source: trunk/index.php @ 18055

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

refactor code when selected derivative on index page is changed by a plugin ...

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