source: trunk/index.php @ 23396

Last change on this file since 23396 was 23396, checked in by mistic100, 11 years ago

feature:2832 Provide better integration of plugins adding a all new section
see future version of skeleton/trunk for usage

  • Property svn:eol-style set to LF
File size: 10.9 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
72//-------------------------------------------------------------- initialization
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//-------------------------------------------------------------- page title
111$title = $page['title'];
112$template_title = $page['section_title'];
113if (count($page['items']) > 0)
114{
115  $template_title.= ' ['.count($page['items']).']';
116}
117$template->assign('TITLE', $template_title);
118
119//-------------------------------------------------------------- menubar
120include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
121
122
123// +-----------------------------------------------------------------------+
124// |  index page (categories, thumbnails, search, calendar, random, etc.)  |
125// +-----------------------------------------------------------------------+
126if ( empty($page['is_external']) or !$page['is_external'] )
127{
128  //----------------------------------------------------- template initialization
129  $page['body_id'] = 'theCategoryPage';
130
131  $template->set_filename('index', 'index.tpl');
132 
133  if (isset($page['flat']) or isset($page['chronology_field']))
134  {
135    $template->assign(
136      'U_MODE_NORMAL',
137      duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
138      );
139  }
140
141  if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
142  {
143    $template->assign(
144      'U_MODE_FLAT',
145      duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
146      );
147  }
148
149  if (!isset($page['chronology_field']))
150  {
151    $chronology_params = array(
152      'chronology_field' => 'created',
153      'chronology_style' => 'monthly',
154      'chronology_view' => 'list',
155      );
156    if ($conf['index_created_date_icon'])
157    {
158      $template->assign(
159        'U_MODE_CREATED',
160        duplicate_index_url( $chronology_params, array('start', 'flat') )
161        );
162    }
163    if ($conf['index_posted_date_icon'])
164    {
165      $chronology_params['chronology_field'] = 'posted';
166      $template->assign(
167        'U_MODE_POSTED',
168        duplicate_index_url( $chronology_params, array('start', 'flat') )
169        );
170    }
171  }
172  else
173  {
174    if ($page['chronology_field'] == 'created')
175    {
176      $chronology_field = 'posted';
177    }
178    else
179    {
180      $chronology_field = 'created';
181    }
182    if ($conf['index_'.$chronology_field.'_date_icon'])
183    {
184      $url = duplicate_index_url(
185                array('chronology_field'=>$chronology_field ),
186                array('chronology_date', 'start', 'flat')
187              );
188      $template->assign(
189          'U_MODE_'.strtoupper($chronology_field),
190          $url
191        );
192    }
193  }
194
195  if ('search' == $page['section'])
196  {
197    $template->assign(
198      'U_SEARCH_RULES',
199      get_root_url().'search_rules.php?search_id='.$page['search']
200      );
201  }
202
203  if (isset($page['category']) and is_admin())
204  {
205    $template->assign(
206      'U_EDIT',
207      get_root_url().'admin.php?page=album-'.$page['category']['id']
208      );
209  }
210
211  if (is_admin() and !empty($page['items']))
212  {
213    $template->assign(
214      'U_CADDIE',
215       add_url_params(duplicate_index_url(), array('caddie'=>1) )
216      );
217  }
218
219  if ( $page['section']=='search' and $page['start']==0 and
220      !isset($page['chronology_field']) and isset($page['qsearch_details']) )
221  {
222    $template->assign('QUERY_SEARCH',
223      htmlspecialchars($page['qsearch_details']['q']) );
224
225    $cats = array_merge(
226        (array)@$page['qsearch_details']['matching_cats_no_images'],
227        (array)@$page['qsearch_details']['matching_cats'] );
228    if (count($cats))
229    {
230      usort($cats, 'name_compare');
231      $hints = array();
232      foreach ( $cats as $cat )
233      {
234        $hints[] = get_cat_display_name( array($cat), '', false );
235      }
236      $template->assign( 'category_search_results', $hints);
237    }
238
239    $tags = (array)@$page['qsearch_details']['matching_tags'];
240    foreach ( $tags as $tag )
241    {
242      $tag['URL'] = make_index_url(array('tags'=>array($tag)));
243      $template->append( 'tag_search_results', $tag);
244    }
245  }
246
247
248  if ( $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
277  if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
278  {
279    $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
280  }
281
282  if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 )
283  {// count_categories might be computed by menubar - if the case unassign flat link if no sub albums
284    $template->clear_assign('U_MODE_FLAT');
285  }
286
287  //------------------------------------------------------ main part : thumbnails
288  if ( 0==$page['start']
289    and !isset($page['flat'])
290    and !isset($page['chronology_field'])
291    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
292    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
293  )
294  {
295    include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
296  }
297
298  if ( !empty($page['items']) )
299  {
300    include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
301    $url = add_url_params(
302            duplicate_index_url(),
303            array('display' => '')
304          );
305   
306    $selected_type = $template->get_template_vars('derivative_params')->type;
307    $template->clear_assign( 'derivative_params' );
308    $type_map = ImageStdParams::get_defined_type_map();
309    unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
310   
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
324  // slideshow
325  // execute after init thumbs in order to have all picture informations
326  if (!empty($page['cat_slideshow_url']))
327  {
328    if (isset($_GET['slideshow']))
329    {
330      redirect($page['cat_slideshow_url']);
331    }
332    elseif ($conf['index_slideshow_icon'])
333    {
334      $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
335    }
336  }
337}
338// +-----------------------------------------------------------------------+
339// |  other pages (added by plugins)                                       |
340// +-----------------------------------------------------------------------+
341else
342{
343  $template->set_filename('index', 'common_page.tpl');
344}
345
346//------------------------------------------------------------ end
347include(PHPWG_ROOT_PATH.'include/page_header.php');
348trigger_action('loc_end_index');
349flush_page_messages();
350$template->parse_index_buttons();
351$template->pparse('index');
352
353//------------------------------------------------------------ log informations
354pwg_log();
355include(PHPWG_ROOT_PATH.'include/page_tail.php');
356?>
Note: See TracBrowser for help on using the repository browser.