source: trunk/search.php @ 28744

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

feature 3094: redesign of search form

  • fix comments page filter form (css changes affected also that .filter form - simplified also css rules)
  • better query for author list (using id for visible_images instead of image_id field)
  • don't show author list if there is only one author
  • Property svn:eol-style set to LF
File size: 7.8 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2]23
[455]24//--------------------------------------------------------------------- include
[364]25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1072]27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_GUEST);
32
[28587]33trigger_notify('loc_begin_search');
[18063]34
[455]35//------------------------------------------------------------------ form check
36$search = array();
37if (isset($_POST['submit']))
[2]38{
[4753]39  foreach ($_POST as $post_key => $post_value)
40  {
41    if (!is_array($post_value))
42    {
[6518]43      $_POST[$post_key] = pwg_db_real_escape_string($post_value);
[4753]44    }
45  } 
46 
[634]47  if (isset($_POST['search_allwords'])
48      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]49  {
[26825]50    check_input_parameter('mode', $_POST, false, '/^(OR|AND)$/');
[28709]51
52    $fields = array_intersect($_POST['fields'], array('name', 'comment', 'file'));
[26825]53   
[634]54    $drop_char_match = array(
55      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
56      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
57    $drop_char_replace = array(
58      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
59      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]60
[634]61    // Split words
[1008]62    $search['fields']['allwords'] = array(
63      'words' => array_unique(
64        preg_split(
65          '/\s+/',
66          str_replace(
67            $drop_char_match,
68            $drop_char_replace,
69            $_POST['search_allwords']
70            )
71          )
72        ),
73      'mode' => $_POST['mode'],
[28709]74      'fields' => $fields,
[1008]75      );
[455]76  }
[1059]77
[1119]78  if (isset($_POST['tags']))
79  {
[5195]80    check_input_parameter('tags', $_POST, true, PATTERN_ID);
[26825]81    check_input_parameter('tag_mode', $_POST, false, '/^(OR|AND)$/');
[4753]82   
[1119]83    $search['fields']['tags'] = array(
84      'words' => $_POST['tags'],
85      'mode'  => $_POST['tag_mode'],
86      );
87  }
[1125]88
[28707]89  if (isset($_POST['authors']) and is_array($_POST['authors']) and count($_POST['authors']) > 0)
[455]90  {
[28707]91    $authors = array();
92
93    foreach ($_POST['authors'] as $author)
94    {
95      $authors[] = strip_tags($author);
96    }
97   
[1008]98    $search['fields']['author'] = array(
[28707]99      'words' => $authors,
[1015]100      'mode' => 'OR',
[1008]101      );
[17]102  }
[1059]103
[621]104  if (isset($_POST['cat']))
[2]105  {
[5195]106    check_input_parameter('cat', $_POST, true, PATTERN_ID);
[4753]107   
[1008]108    $search['fields']['cat'] = array(
109      'words'   => $_POST['cat'],
110      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
111      );
[2]112  }
[634]113
114  // dates
115  $type_date = $_POST['date_type'];
[1059]116
[621]117  if (!empty($_POST['start_year']))
[634]118  {
[1008]119    $search['fields'][$type_date.'-after'] = array(
[6518]120      'date' => sprintf(
[25005]121        '%d-%02d-%02d',
122        $_POST['start_year'],
123        $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
124        $_POST['start_day']   != 0 ? $_POST['start_day']   : '01'
[1008]125        ),
126      'inc' => true,
127      );
[634]128  }
[621]129
[634]130  if (!empty($_POST['end_year']))
[621]131  {
[1008]132    $search['fields'][$type_date.'-before'] = array(
[6518]133      'date' => sprintf(
[25005]134        '%d-%02d-%02d',
135        $_POST['end_year'],
136        $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
137        $_POST['end_day']   != 0 ? $_POST['end_day']   : '31'
[6518]138      ),
[1008]139      'inc' => true,
140      );
[621]141  }
[1059]142
[621]143  if (!empty($search))
144  {
[1008]145    // default search mode : each clause must be respected
146    $search['mode'] = 'AND';
147
148    // register search rules in database, then they will be available on
149    // thumbnails page and picture page.
150    $query ='
151INSERT INTO '.SEARCH_TABLE.'
[1816]152  (rules, last_seen)
[1008]153  VALUES
[1816]154  (\''.serialize($search).'\', NOW())
[1008]155;';
156    pwg_query($query);
157
[4892]158    $search_id = pwg_db_insert_id(SEARCH_TABLE);
[455]159  }
[621]160  else
[455]161  {
[25018]162    $page['errors'][] = l10n('Empty query. No criteria has been entered.');
[455]163  }
[2]164}
[455]165//----------------------------------------------------------------- redirection
[12764]166if (isset($_POST['submit']) and count($page['errors']) == 0)
[455]167{
[1082]168  redirect(
169    make_index_url(
170      array(
171        'section' => 'search',
172        'search'  => $search_id,
173        )
174      )
175    );
[455]176}
[2]177//----------------------------------------------------- template initialization
[621]178
[345]179//
180// Start output of page
181//
[5021]182$title= l10n('Search');
[850]183$page['body_id'] = 'theSearchPage';
[345]184
[2223]185$template->set_filename('search' ,'search.tpl' );
[1125]186
[2223]187$month_list = $lang['month'];
188$month_list[0]='------------';
189ksort($month_list);
190
191$template->assign(
[1314]192  array(
[2223]193    'F_SEARCH_ACTION' => 'search.php',
[1314]194    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
[2324]195
[2223]196    'month_list' => $month_list,
197    'START_DAY_SELECTED' => @$_POST['start_day'],
198    'START_MONTH_SELECTED' => @$_POST['start_month'],
199    'END_DAY_SELECTED' => @$_POST['end_day'],
200    'END_MONTH_SELECTED' => @$_POST['end_month'],
[1314]201    )
202  );
203
[1677]204$available_tags = get_available_tags();
[1125]205
[1314]206if (count($available_tags) > 0)
207{
[2409]208  usort( $available_tags, 'tag_alpha_compare');
[1119]209
[28708]210  $template->assign('TAGS', $available_tags);
[1314]211}
[355]212
[28707]213// authors
214$query = '
215SELECT
216    author,
217    COUNT(*) AS counter
218  FROM '.IMAGES_TABLE.' AS i
219    JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id
220  '.get_sql_condition_FandF(
221    array(
222      'forbidden_categories' => 'category_id',
223      'visible_categories' => 'category_id',
[28744]224      'visible_images' => 'id'
[28707]225      ),
226    ' WHERE '
227    ).'
228    AND author IS NOT NULL
229  GROUP BY author
230  ORDER BY author
231;';
232$authors = query2array($query);
233
234$template->assign('AUTHORS', $authors);
235
[455]236//------------------------------------------------------------- categories form
[614]237$query = '
[2324]238SELECT id,name,global_rank,uppercats
[1677]239  FROM '.CATEGORIES_TABLE.'
240'.get_sql_condition_FandF
241  (
242    array
243      (
244        'forbidden_categories' => 'id',
245        'visible_categories' => 'id'
246      ),
247    'WHERE'
248  ).'
[614]249;';
[28710]250display_select_cat_wrapper($query, array(), 'category_options', true);
[621]251
[10812]252// include menubar
253$themeconf = $template->get_template_vars('themeconf');
[10824]254if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on']))
[10812]255{
256  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
257}
258
259//------------------------------------------------------------ html code display
[1627]260include(PHPWG_ROOT_PATH.'include/page_header.php');
[28587]261trigger_notify('loc_end_search');
[20609]262flush_page_messages();
[2223]263$template->pparse('search');
[369]264include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]265?>
Note: See TracBrowser for help on using the repository browser.