source: branches/2.0/index.php @ 4213

Last change on this file since 4213 was 3147, checked in by rvelices, 15 years ago

merge 3145-3146 from trunk
Last (I hope) paranoic optims ...

  • move get_uysername and get_groupname from public to admin/functions.inc.php
  • optim in index.php
  • tags.tpl does not need smarty modifier included
  • move func get_comment_post_key from functions_comment to functions (avoid extra inclusion every time on picture page)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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
29trigger_action('loc_begin_index');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_GUEST);
35
36//---------------------------------------------- change of image display order
37if (isset($_GET['image_order']))
38{
39  if ( (int)$_GET['image_order'] > 0)
40  {
41    pwg_set_session_var('image_order', (int)$_GET['image_order']);
42  }
43  else
44  {
45    pwg_unset_session_var('image_order');
46  }
47  redirect(
48    duplicate_index_url(
49      array(),        // nothing to redefine
50      array('start')  // changing display order goes back to section first page
51      )
52    );
53}
54//-------------------------------------------------------------- initialization
55// detection of the start picture to display
56if (!isset($page['start']))
57{
58  $page['start'] = 0;
59}
60
61// access authorization check
62if (isset($page['category']))
63{
64  check_restrictions($page['category']['id']);
65}
66
67if (count($page['items']) > $user['nb_image_page'])
68{
69  $page['navigation_bar'] = create_navigation_bar(
70    duplicate_index_url(array(), array('start')),
71    count($page['items']),
72    $page['start'],
73    $page['nb_image_page'],
74    true
75    );
76}
77else
78{
79  $page['navigation_bar'] = '';
80}
81
82// caddie filling :-)
83if (isset($_GET['caddie']))
84{
85  fill_caddie($page['items']);
86  redirect(duplicate_index_url());
87}
88
89//----------------------------------------------------- template initialization
90//
91// Start output of page
92//
93$title = $page['title'];
94$page['body_id'] = 'theCategoryPage';
95
96$template->set_filenames( array('index'=>'index.tpl') );
97//-------------------------------------------------------------- category title
98$template_title = $page['title'];
99if (count($page['items']) > 0)
100{
101  $template_title.= ' ['.count($page['items']).']';
102}
103$template->assign('TITLE', $template_title);
104
105if (isset($page['flat']) or isset($page['chronology_field']))
106{
107  $template->assign(
108    'U_MODE_NORMAL',
109    duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
110    );
111}
112
113if (!isset($page['flat']) and 'categories' == $page['section'])
114{
115  $template->assign(
116    'U_MODE_FLAT',
117    duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
118    );
119}
120
121if (!isset($page['chronology_field']))
122{
123  $chronology_params =
124      array(
125          'chronology_field' => 'created',
126          'chronology_style' => 'monthly',
127          'chronology_view' => 'list',
128      );
129  $template->assign(
130    'U_MODE_CREATED',
131    duplicate_index_url( $chronology_params, array('start', 'flat') )
132    );
133
134  $chronology_params['chronology_field'] = 'posted';
135  $template->assign(
136    'U_MODE_POSTED',
137    duplicate_index_url( $chronology_params, array('start', 'flat') )
138    );
139}
140else
141{
142  if ($page['chronology_field'] == 'created')
143  {
144    $chronology_field = 'posted';
145  }
146  else
147  {
148    $chronology_field = 'created';
149  }
150  $url = duplicate_index_url(
151            array('chronology_field'=>$chronology_field ),
152            array('chronology_date', 'start', 'flat')
153          );
154  $template->assign(
155      'U_MODE_'.strtoupper($chronology_field),
156      $url
157    );
158}
159
160if ('search' == $page['section'])
161{
162  $template->assign(
163    'U_SEARCH_RULES',
164    get_root_url().'search_rules.php?search_id='.$page['search']
165    );
166}
167
168if (isset($page['category']) and is_admin())
169{
170  $template->assign(
171    'U_EDIT',
172     get_root_url().'admin.php?page=cat_modify'
173        .'&amp;cat_id='.$page['category']['id']
174    );
175}
176
177if (is_admin() and !empty($page['items']))
178{
179  $template->assign(
180    'U_CADDIE',
181     add_url_params(duplicate_index_url(), array('caddie'=>1) )
182    );
183}
184
185if ( $page['section']=='search' and $page['start']==0 and
186    !isset($page['chronology_field']) and isset($page['qsearch_details']) )
187{
188  $template->assign('QUERY_SEARCH',
189    htmlspecialchars($page['qsearch_details']['q']) );
190
191  $cats = array_merge(
192      (array)@$page['qsearch_details']['matching_cats_no_images'],
193      (array)@$page['qsearch_details']['matching_cats'] );
194  if (count($cats))
195  {
196    usort($cats, 'name_compare');
197    $hints = array();
198    foreach ( $cats as $cat )
199    {
200      $hints[] = get_cat_display_name( array($cat), '', false );
201    }
202    $template->assign( 'category_search_results', $hints);
203  }
204
205  $tags = (array)@$page['qsearch_details']['matching_tags'];
206  if (count($tags))
207  {
208    usort($tags, 'name_compare');
209    $hints = array();
210    foreach ( $tags as $tag )
211    {
212      $hints[] =
213        '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
214        .$tag['name']
215        .'</a>';
216    }
217    $template->assign( 'tag_search_results', $hints);
218  }
219}
220
221// navigation bar
222$template->assign( 'NAV_BAR', $page['navigation_bar'] );
223
224if ( count($page['items']) > 0
225    and $page['section'] != 'most_visited'
226    and $page['section'] != 'best_rated')
227{
228  // image order
229  $order_idx = pwg_get_session_var( 'image_order', 0 );
230
231  $url = add_url_params(
232          duplicate_index_url(),
233          array('image_order' => '')
234        );
235  foreach (get_category_preferred_image_orders() as $order_id => $order)
236  {
237    if ($order[2])
238    {
239      $template->append(
240        'image_orders',
241        array(
242          'DISPLAY' => $order[0],
243          'URL' => $url.$order_id,
244          'SELECTED' => ($order_idx == $order_id ? true:false),
245          )
246        );
247    }
248  }
249}
250
251// category comment
252if (isset($page['comment']) and $page['comment'] != '')
253{
254  $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
255}
256
257// include menubar
258include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
259
260//------------------------------------------------------ main part : thumbnails
261if ( 0==$page['start']
262    and !isset($page['flat'])
263    and !isset($page['chronology_field'])
264    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
265    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
266  )
267{
268  include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
269}
270if ( !empty($page['items']) )
271{
272  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
273}
274//------------------------------------------------------- category informations
275
276// slideshow
277// execute after init thumbs in order to have all picture informations
278if (!empty($page['cat_slideshow_url']))
279{
280  if (isset($_GET['slideshow']))
281  {
282    redirect($page['cat_slideshow_url']);
283  }
284  else
285  {
286    $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
287  }
288}
289
290include(PHPWG_ROOT_PATH.'include/page_header.php');
291trigger_action('loc_end_index');
292$template->pparse('index');
293//------------------------------------------------------------ log informations
294pwg_log();
295include(PHPWG_ROOT_PATH.'include/page_tail.php');
296?>
Note: See TracBrowser for help on using the repository browser.