source: branches/2.0/search.php @ 12971

Last change on this file since 12971 was 5003, checked in by plg, 15 years ago

improvement: avoid the use of @ instead of a real test

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[3046]5// | Copyright(C) 2008-2009 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
[455]33//------------------------------------------------------------------ form check
34$errors = array();
35$search = array();
36if (isset($_POST['submit']))
[2]37{
[4752]38  foreach ($_POST as $post_key => $post_value)
39  {
40    if (!is_array($post_value))
41    {
42      $_POST[$post_key] = mysql_real_escape_string($post_value);
43    }
44  } 
45 
[634]46  if (isset($_POST['search_allwords'])
47      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]48  {
[634]49    $drop_char_match = array(
50      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
51      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
52    $drop_char_replace = array(
53      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
54      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]55
[634]56    // Split words
[1008]57    $search['fields']['allwords'] = array(
58      'words' => array_unique(
59        preg_split(
60          '/\s+/',
61          str_replace(
62            $drop_char_match,
63            $drop_char_replace,
64            $_POST['search_allwords']
65            )
66          )
67        ),
68      'mode' => $_POST['mode'],
69      );
[455]70  }
[1059]71
[1119]72  if (isset($_POST['tags']))
73  {
[5003]74    check_input_parameter('tags', $_POST, true, PATTERN_ID);
[4752]75   
[1119]76    $search['fields']['tags'] = array(
77      'words' => $_POST['tags'],
78      'mode'  => $_POST['tag_mode'],
79      );
80  }
[1125]81
[621]82  if ($_POST['search_author'])
[455]83  {
[1008]84    $search['fields']['author'] = array(
[1015]85      'words' => preg_split(
86        '/\s+/',
87        $_POST['search_author']
88        ),
89      'mode' => 'OR',
[1008]90      );
[17]91  }
[1059]92
[621]93  if (isset($_POST['cat']))
[2]94  {
[5003]95    check_input_parameter('cat', $_POST, true, PATTERN_ID);
[4752]96   
[1008]97    $search['fields']['cat'] = array(
98      'words'   => $_POST['cat'],
99      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
100      );
[2]101  }
[634]102
103  // dates
104  $type_date = $_POST['date_type'];
[1059]105
[621]106  if (!empty($_POST['start_year']))
[634]107  {
[1008]108    $search['fields'][$type_date.'-after'] = array(
109      'date' => join(
110        '-',
111        array(
112          $_POST['start_year'],
113          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
114          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
115          )
116        ),
117      'inc' => true,
118      );
[634]119  }
[621]120
[634]121  if (!empty($_POST['end_year']))
[621]122  {
[1008]123    $search['fields'][$type_date.'-before'] = array(
124      'date' => join(
125        '-',
126        array(
127          $_POST['end_year'],
128          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
129          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
130          )
131        ),
132      'inc' => true,
133      );
[621]134  }
[1059]135
[621]136  if (!empty($search))
137  {
[1008]138    // default search mode : each clause must be respected
139    $search['mode'] = 'AND';
140
141    // register search rules in database, then they will be available on
142    // thumbnails page and picture page.
143    $query ='
144INSERT INTO '.SEARCH_TABLE.'
[1816]145  (rules, last_seen)
[1008]146  VALUES
[1816]147  (\''.serialize($search).'\', NOW())
[1008]148;';
149    pwg_query($query);
150
151    $search_id = mysql_insert_id();
[455]152  }
[621]153  else
[455]154  {
[2014]155    array_push($errors, l10n('search_one_clause_at_least'));
[455]156  }
[2]157}
[455]158//----------------------------------------------------------------- redirection
159if (isset($_POST['submit']) and count($errors) == 0)
160{
[1082]161  redirect(
162    make_index_url(
163      array(
164        'section' => 'search',
165        'search'  => $search_id,
166        )
167      )
168    );
[455]169}
[2]170//----------------------------------------------------- template initialization
[621]171
[345]172//
173// Start output of page
174//
[2014]175$title= l10n('search_title');
[850]176$page['body_id'] = 'theSearchPage';
[345]177
[2223]178$template->set_filename('search' ,'search.tpl' );
[1125]179
[2223]180$month_list = $lang['month'];
181$month_list[0]='------------';
182ksort($month_list);
183
184$template->assign(
[1314]185  array(
[2223]186    'F_SEARCH_ACTION' => 'search.php',
[1314]187    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
[2324]188
[2223]189    'month_list' => $month_list,
190    'START_DAY_SELECTED' => @$_POST['start_day'],
191    'START_MONTH_SELECTED' => @$_POST['start_month'],
192    'END_DAY_SELECTED' => @$_POST['end_day'],
193    'END_MONTH_SELECTED' => @$_POST['end_month'],
[1314]194    )
195  );
196
[1677]197$available_tags = get_available_tags();
[1125]198
[1314]199if (count($available_tags) > 0)
200{
[2409]201  usort( $available_tags, 'tag_alpha_compare');
[1119]202
[2223]203  $template->assign(
204    'TAG_SELECTION',
205    get_html_tag_selection(
[1314]206        $available_tags,
207        'tags',
208        isset($_POST['tags']) ? $_POST['tags'] : array()
[2223]209        )
[1314]210    );
211}
[355]212
[455]213//------------------------------------------------------------- categories form
[614]214$query = '
[2324]215SELECT id,name,global_rank,uppercats
[1677]216  FROM '.CATEGORIES_TABLE.'
217'.get_sql_condition_FandF
218  (
219    array
220      (
221        'forbidden_categories' => 'id',
222        'visible_categories' => 'id'
223      ),
224    'WHERE'
225  ).'
[614]226;';
[2223]227display_select_cat_wrapper($query, array(), 'category_options', false);
[621]228
[2]229//-------------------------------------------------------------- errors display
[455]230if (sizeof($errors) != 0)
[2]231{
[2223]232  $template->assign('errors', $errors);
[2]233}
234//------------------------------------------------------------ log informations
[1627]235include(PHPWG_ROOT_PATH.'include/page_header.php');
[2223]236$template->pparse('search');
[369]237include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]238?>
Note: See TracBrowser for help on using the repository browser.