source: trunk/index.php @ 22033

Last change on this file since 22033 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
RevLine 
[2]1<?php
[351]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[351]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2342]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
[351]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  |
[352]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.                                                                  |
[351]22// +-----------------------------------------------------------------------+
[2]23
[352]24//--------------------------------------------------------------------- include
[364]25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1084]27include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
[1072]28
[8401]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}
[13872]38if ($page['start']>0 && $page['start']>=count($page['items']))
39{
40  page_not_found('', duplicate_index_url(array('start'=>0)));
41}
[8401]42
[1604]43trigger_action('loc_begin_index');
44
[1059]45//---------------------------------------------- change of image display order
[1036]46if (isset($_GET['image_order']))
[614]47{
[1623]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  }
[1036]56  redirect(
[1503]57    duplicate_index_url(
[1084]58      array(),        // nothing to redefine
59      array('start')  // changing display order goes back to section first page
[1082]60      )
[1036]61    );
[614]62}
[12908]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}
[2]71//-------------------------------------------------------------- initialization
[345]72
[18165]73// navigation bar
[3172]74$page['navigation_bar'] = array();
[8432]75if (count($page['items']) > $page['nb_image_page'])
[1036]76{
77  $page['navigation_bar'] = create_navigation_bar(
[1503]78    duplicate_index_url(array(), array('start')),
[1820]79    count($page['items']),
[1036]80    $page['start'],
[3117]81    $page['nb_image_page'],
[18165]82    true, 'start'
[1036]83    );
84}
85
[18462]86$template->assign('thumb_navbar', $page['navigation_bar'] );
[18165]87
[755]88// caddie filling :-)
89if (isset($_GET['caddie']))
90{
[1036]91  fill_caddie($page['items']);
[2114]92  redirect(duplicate_index_url());
[755]93}
94
[13458]95if (isset($page['is_homepage']) and $page['is_homepage'])
96{
97  $canonical_url = get_gallery_home_url();
98}
99else
100{
[18667]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));
[13458]107}
108$template->assign('U_CANONICAL', $canonical_url);
[13062]109
[2]110//----------------------------------------------------- template initialization
[345]111//
112// Start output of page
113//
114$title = $page['title'];
[850]115$page['body_id'] = 'theCategoryPage';
[345]116
[1109]117$template->set_filenames( array('index'=>'index.tpl') );
[351]118//-------------------------------------------------------------- category title
[18637]119$template_title = $page['section_title'];
[2218]120if (count($page['items']) > 0)
[428]121{
[1820]122  $template_title.= ' ['.count($page['items']).']';
[428]123}
[2231]124$template->assign('TITLE', $template_title);
[2]125
[1800]126if (isset($page['flat']) or isset($page['chronology_field']))
[1648]127{
[2231]128  $template->assign(
129    'U_MODE_NORMAL',
130    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
[1648]131    );
132}
133
[5293]134if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
[1651]135{
[2231]136  $template->assign(
137    'U_MODE_FLAT',
138    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
[1651]139    );
140}
141
[1090]142if (!isset($page['chronology_field']))
[1047]143{
[1090]144  $chronology_params =
145      array(
146          'chronology_field' => 'created',
147          'chronology_style' => 'monthly',
148          'chronology_view' => 'list',
149      );
[5293]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  }
[1047]165}
[1050]166else
167{
[1090]168  if ($page['chronology_field'] == 'created')
[1059]169  {
[1090]170    $chronology_field = 'posted';
[1059]171  }
172  else
173  {
[1090]174    $chronology_field = 'created';
[1059]175  }
[5293]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  }
[1050]187}
[1047]188
[1082]189if ('search' == $page['section'])
[1015]190{
[2231]191  $template->assign(
192    'U_SEARCH_RULES',
193    get_root_url().'search_rules.php?search_id='.$page['search']
[1015]194    );
195}
[797]196
[1082]197if (isset($page['category']) and is_admin())
[834]198{
[2231]199  $template->assign(
200    'U_EDIT',
[13025]201    get_root_url().'admin.php?page=album-'.$page['category']['id']
[834]202    );
203}
204
[2218]205if (is_admin() and !empty($page['items']))
[1092]206{
[2231]207  $template->assign(
208    'U_CADDIE',
209     add_url_params(duplicate_index_url(), array('caddie'=>1) )
[2135]210    );
211}
212
213if ( $page['section']=='search' and $page['start']==0 and
214    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
215{
[2231]216  $template->assign('QUERY_SEARCH',
[2135]217    htmlspecialchars($page['qsearch_details']['q']) );
218
[2138]219  $cats = array_merge(
[2135]220      (array)@$page['qsearch_details']['matching_cats_no_images'],
221      (array)@$page['qsearch_details']['matching_cats'] );
[2138]222  if (count($cats))
[2135]223  {
[2138]224    usort($cats, 'name_compare');
[2135]225    $hints = array();
[2138]226    foreach ( $cats as $cat )
[2135]227    {
[2770]228      $hints[] = get_cat_display_name( array($cat), '', false );
[2135]229    }
[2231]230    $template->assign( 'category_search_results', $hints);
[1092]231  }
232
[2138]233  $tags = (array)@$page['qsearch_details']['matching_tags'];
[18636]234  foreach ( $tags as $tag )
[1537]235  {
[18636]236    $tag['URL'] = make_index_url(array('tags'=>array($tag)));
237    $template->append( 'tag_search_results', $tag);
[1537]238  }
239}
240
[1051]241
[5293]242if ( $conf['index_sort_order_input']
243    and count($page['items']) > 0
[1082]244    and $page['section'] != 'most_visited'
245    and $page['section'] != 'best_rated')
[1051]246{
247  // image order
[1623]248  $order_idx = pwg_get_session_var( 'image_order', 0 );
[1051]249
[3146]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)
[1051]255  {
[2517]256    if ($order[2])
[1051]257    {
[2231]258      $template->append(
259        'image_orders',
[1082]260        array(
[2517]261          'DISPLAY' => $order[0],
[3146]262          'URL' => $url.$order_id,
[2517]263          'SELECTED' => ($order_idx == $order_id ? true:false),
[1082]264          )
265        );
[1051]266    }
267  }
268}
269
[1604]270// category comment
[8401]271if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
[2]272{
[2231]273  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
[2]274}
[2586]275
276// include menubar
277include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
278
[8463]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
[2586]284//------------------------------------------------------ main part : thumbnails
[18462]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)
[2586]291{
292  include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
293}
[18462]294
[2586]295if ( !empty($page['items']) )
296{
297  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
[16987]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  }
[2586]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  }
[5293]328  elseif ($conf['index_slideshow_icon'])
[2586]329  {
330    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
331  }
332}
333
[1655]334include(PHPWG_ROOT_PATH.'include/page_header.php');
[1604]335trigger_action('loc_end_index');
[20609]336flush_page_messages();
[18760]337$template->parse_index_buttons();
[2231]338$template->pparse('index');
[2699]339//------------------------------------------------------------ log informations
340pwg_log();
[369]341include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]342?>
Note: See TracBrowser for help on using the repository browser.