source: trunk/index.php @ 28230

Last change on this file since 28230 was 28128, checked in by rvelices, 10 years ago

bug 3056: quick search - fix warning; better management of variants and short words

  • Property svn:eol-style set to LF
File size: 11.6 KB
RevLine 
[2]1<?php
[351]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[351]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 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}
[23396]71
[2]72//-------------------------------------------------------------- initialization
[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
[27884]88if ( $page['section']=='search' and isset($page['qsearch_details']) )
89{
90  $template->assign('QUERY_SEARCH', htmlspecialchars($page['qsearch_details']['q']) );
91}
92
[755]93// caddie filling :-)
94if (isset($_GET['caddie']))
95{
[1036]96  fill_caddie($page['items']);
[2114]97  redirect(duplicate_index_url());
[755]98}
99
[13458]100if (isset($page['is_homepage']) and $page['is_homepage'])
101{
102  $canonical_url = get_gallery_home_url();
103}
104else
105{
[18667]106  $start = $page['nb_image_page'] * round($page['start'] / $page['nb_image_page']);
107  if ($start>0 && $start >= count($page['items']) )
108  {
109    $start -= $page['nb_image_page'];
110  }
111  $canonical_url = duplicate_index_url(array('start' => $start));
[13458]112}
113$template->assign('U_CANONICAL', $canonical_url);
[13062]114
[23396]115//-------------------------------------------------------------- page title
[345]116$title = $page['title'];
[18637]117$template_title = $page['section_title'];
[2218]118if (count($page['items']) > 0)
[428]119{
[1820]120  $template_title.= ' ['.count($page['items']).']';
[428]121}
[2231]122$template->assign('TITLE', $template_title);
[2]123
[23396]124//-------------------------------------------------------------- menubar
125include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
[1648]126
[23399]127$template->set_filename('index', 'index.tpl');
[23396]128
129// +-----------------------------------------------------------------------+
130// |  index page (categories, thumbnails, search, calendar, random, etc.)  |
131// +-----------------------------------------------------------------------+
132if ( empty($page['is_external']) or !$page['is_external'] )
[1651]133{
[23396]134  //----------------------------------------------------- template initialization
135  $page['body_id'] = 'theCategoryPage';
136 
137  if (isset($page['flat']) or isset($page['chronology_field']))
[5293]138  {
139    $template->assign(
[23396]140      'U_MODE_NORMAL',
141      duplicate_index_url( array(), array('chronology_field', 'start', 'flat') )
[5293]142      );
143  }
[23396]144
145  if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section'])
[5293]146  {
147    $template->assign(
[23396]148      'U_MODE_FLAT',
149      duplicate_index_url(array('flat' => ''), array('start', 'chronology_field'))
[5293]150      );
151  }
[23396]152
153  if (!isset($page['chronology_field']))
[1059]154  {
[23396]155    $chronology_params = array(
156      'chronology_field' => 'created',
157      'chronology_style' => 'monthly',
158      'chronology_view' => 'list',
159      );
160    if ($conf['index_created_date_icon'])
161    {
162      $template->assign(
163        'U_MODE_CREATED',
164        duplicate_index_url( $chronology_params, array('start', 'flat') )
165        );
166    }
167    if ($conf['index_posted_date_icon'])
168    {
169      $chronology_params['chronology_field'] = 'posted';
170      $template->assign(
171        'U_MODE_POSTED',
172        duplicate_index_url( $chronology_params, array('start', 'flat') )
173        );
174    }
[1059]175  }
176  else
177  {
[23396]178    if ($page['chronology_field'] == 'created')
179    {
180      $chronology_field = 'posted';
181    }
182    else
183    {
184      $chronology_field = 'created';
185    }
186    if ($conf['index_'.$chronology_field.'_date_icon'])
187    {
188      $url = duplicate_index_url(
189                array('chronology_field'=>$chronology_field ),
190                array('chronology_date', 'start', 'flat')
191              );
192      $template->assign(
193          'U_MODE_'.strtoupper($chronology_field),
194          $url
195        );
196    }
[1059]197  }
[23396]198
199  if ('search' == $page['section'])
[5293]200  {
201    $template->assign(
[23396]202      'U_SEARCH_RULES',
203      get_root_url().'search_rules.php?search_id='.$page['search']
[5293]204      );
205  }
[1047]206
[23396]207  if (isset($page['category']) and is_admin())
208  {
209    $template->assign(
210      'U_EDIT',
211      get_root_url().'admin.php?page=album-'.$page['category']['id']
212      );
213  }
[797]214
[23396]215  if (is_admin() and !empty($page['items']))
216  {
217    $template->assign(
218      'U_CADDIE',
219       add_url_params(duplicate_index_url(), array('caddie'=>1) )
220      );
221  }
[834]222
[23396]223  if ( $page['section']=='search' and $page['start']==0 and
224      !isset($page['chronology_field']) and isset($page['qsearch_details']) )
225  {
226    $cats = array_merge(
227        (array)@$page['qsearch_details']['matching_cats_no_images'],
228        (array)@$page['qsearch_details']['matching_cats'] );
229    if (count($cats))
230    {
231      usort($cats, 'name_compare');
232      $hints = array();
233      foreach ( $cats as $cat )
234      {
[25425]235        $hints[] = get_cat_display_name( array($cat), '' );
[23396]236      }
237      $template->assign( 'category_search_results', $hints);
238    }
[2135]239
[23396]240    $tags = (array)@$page['qsearch_details']['matching_tags'];
241    foreach ( $tags as $tag )
242    {
243      $tag['URL'] = make_index_url(array('tags'=>array($tag)));
244      $template->append( 'tag_search_results', $tag);
245    }
[27882]246   
247    if (empty($page['items']))
248    {
[28128]249      $template->append( 'no_search_results', htmlspecialchars($page['qsearch_details']['q']));
[27882]250    }
251    elseif (!empty($page['qsearch_details']['unmatched_terms']))
252    {
253      $template->assign( 'no_search_results', $page['qsearch_details']['unmatched_terms']);
254    }
[23396]255  }
256
[23533]257  // image order
[23396]258  if ( $conf['index_sort_order_input']
259      and count($page['items']) > 0
260      and $page['section'] != 'most_visited'
261      and $page['section'] != 'best_rated')
[2135]262  {
[23533]263    $preferred_image_orders = get_category_preferred_image_orders();
[23396]264    $order_idx = pwg_get_session_var( 'image_order', 0 );
[23533]265   
266    // get first order field and direction
267    $first_order = substr($conf['order_by'], 9);
268    if (($pos = strpos($first_order, ',')) !== false)
269    {
270      $first_order = substr($first_order, 0, $pos);
271    }
272    $first_order = trim($first_order);
273   
[23396]274    $url = add_url_params(
275            duplicate_index_url(),
276            array('image_order' => '')
277          );
[23533]278    $tpl_orders = array();
279    $order_selected = false;
280   
281    foreach ($preferred_image_orders as $order_id => $order)
[2135]282    {
[23396]283      if ($order[2])
284      {
[23533]285        // force select if the field is the first field of order_by
286        if (!$order_selected && $order[1]==$first_order)
287        {
288          $order_idx = $order_id;
289          $order_selected = true;
290        }
291       
292        $tpl_orders[ $order_id ] = array(
293          'DISPLAY' => $order[0],
294          'URL' => $url.$order_id,
295          'SELECTED' => $order_idx==$order_id,
[23396]296          );
297      }
[2135]298    }
[23533]299   
300    $tpl_orders[0]['SELECTED'] = !$order_selected; // unselect "Default" if another one is selected
301    $template->assign('image_orders', $tpl_orders);
[1092]302  }
303
[23396]304  // category comment
305  if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) )
[1537]306  {
[23396]307    $template->assign('CONTENT_DESCRIPTION', $page['comment'] );
[1537]308  }
309
[23396]310  if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 )
311  {// count_categories might be computed by menubar - if the case unassign flat link if no sub albums
312    $template->clear_assign('U_MODE_FLAT');
313  }
[1051]314
[23396]315  //------------------------------------------------------ main part : thumbnails
316  if ( 0==$page['start']
317    and !isset($page['flat'])
318    and !isset($page['chronology_field'])
319    and ('recent_cats'==$page['section'] or 'categories'==$page['section'])
320    and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 )
321  )
322  {
323    include(PHPWG_ROOT_PATH.'include/category_cats.inc.php');
324  }
[1051]325
[23396]326  if ( !empty($page['items']) )
[1051]327  {
[23396]328    include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
329    $url = add_url_params(
330            duplicate_index_url(),
331            array('display' => '')
332          );
333   
334    $selected_type = $template->get_template_vars('derivative_params')->type;
335    $template->clear_assign( 'derivative_params' );
336    $type_map = ImageStdParams::get_defined_type_map();
337    unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]);
338   
339    foreach($type_map as $params)
[1051]340    {
[2231]341      $template->append(
[23396]342        'image_derivatives',
[1082]343        array(
[23396]344          'DISPLAY' => l10n($params->type),
345          'URL' => $url.$params->type,
346          'SELECTED' => ($params->type == $selected_type ? true:false),
[1082]347          )
348        );
[1051]349    }
350  }
351
[23396]352  // slideshow
353  // execute after init thumbs in order to have all picture informations
354  if (!empty($page['cat_slideshow_url']))
[16987]355  {
[23396]356    if (isset($_GET['slideshow']))
357    {
358      redirect($page['cat_slideshow_url']);
359    }
360    elseif ($conf['index_slideshow_icon'])
361    {
362      $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']);
363    }
[16987]364  }
[2586]365}
366
[23396]367//------------------------------------------------------------ end
[1655]368include(PHPWG_ROOT_PATH.'include/page_header.php');
[1604]369trigger_action('loc_end_index');
[20609]370flush_page_messages();
[18760]371$template->parse_index_buttons();
[2231]372$template->pparse('index');
[23396]373
[2699]374//------------------------------------------------------------ log informations
375pwg_log();
[369]376include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]377?>
Note: See TracBrowser for help on using the repository browser.