source: branches/branch-1_7/search.php @ 3035

Last change on this file since 3035 was 2015, checked in by rub, 18 years ago

Replace some $lang by l10n

Merge BSF 2013:2014 into branch-1_7

  • 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// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[1903]5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
[354]6// +-----------------------------------------------------------------------+
[2015]7// | file          : $Id: search.php 2015 2007-05-15 20:26:56Z rub $
[354]8// | last update   : $Date: 2007-05-15 20:26:56 +0000 (Tue, 15 May 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2015 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
[2]26
[455]27//--------------------------------------------------------------------- include
[364]28define('PHPWG_ROOT_PATH','./');
29include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1072]30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_GUEST);
35
[455]36//------------------------------------------------------------------ form check
37$errors = array();
38$search = array();
39if (isset($_POST['submit']))
[2]40{
[634]41  if (isset($_POST['search_allwords'])
42      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]43  {
[634]44    $drop_char_match = array(
45      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
46      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
47    $drop_char_replace = array(
48      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
49      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]50
[634]51    // Split words
[1008]52    $search['fields']['allwords'] = array(
53      'words' => array_unique(
54        preg_split(
55          '/\s+/',
56          str_replace(
57            $drop_char_match,
58            $drop_char_replace,
59            $_POST['search_allwords']
60            )
61          )
62        ),
63      'mode' => $_POST['mode'],
64      );
[455]65  }
[1059]66
[1119]67  if (isset($_POST['tags']))
68  {
69    $search['fields']['tags'] = array(
70      'words' => $_POST['tags'],
71      'mode'  => $_POST['tag_mode'],
72      );
73  }
[1125]74
[621]75  if ($_POST['search_author'])
[455]76  {
[1008]77    $search['fields']['author'] = array(
[1015]78      'words' => preg_split(
79        '/\s+/',
80        $_POST['search_author']
81        ),
82      'mode' => 'OR',
[1008]83      );
[17]84  }
[1059]85
[621]86  if (isset($_POST['cat']))
[2]87  {
[1008]88    $search['fields']['cat'] = array(
89      'words'   => $_POST['cat'],
90      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
91      );
[2]92  }
[634]93
94  // dates
95  $type_date = $_POST['date_type'];
[1059]96
[621]97  if (!empty($_POST['start_year']))
[634]98  {
[1008]99    $search['fields'][$type_date.'-after'] = array(
100      'date' => join(
101        '-',
102        array(
103          $_POST['start_year'],
104          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
105          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
106          )
107        ),
108      'inc' => true,
109      );
[634]110  }
[621]111
[634]112  if (!empty($_POST['end_year']))
[621]113  {
[1008]114    $search['fields'][$type_date.'-before'] = array(
115      'date' => join(
116        '-',
117        array(
118          $_POST['end_year'],
119          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
120          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
121          )
122        ),
123      'inc' => true,
124      );
[621]125  }
[1059]126
[621]127  if (!empty($search))
128  {
[1008]129    // default search mode : each clause must be respected
130    $search['mode'] = 'AND';
131
132    // register search rules in database, then they will be available on
133    // thumbnails page and picture page.
134    $query ='
135INSERT INTO '.SEARCH_TABLE.'
[1816]136  (rules, last_seen)
[1008]137  VALUES
[1816]138  (\''.serialize($search).'\', NOW())
[1008]139;';
140    pwg_query($query);
141
142    $search_id = mysql_insert_id();
[455]143  }
[621]144  else
[455]145  {
[2015]146    array_push($errors, l10n('search_one_clause_at_least'));
[455]147  }
[2]148}
[455]149//----------------------------------------------------------------- redirection
150if (isset($_POST['submit']) and count($errors) == 0)
151{
[1082]152  redirect(
153    make_index_url(
154      array(
155        'section' => 'search',
156        'search'  => $search_id,
157        )
158      )
159    );
[455]160}
[2]161//----------------------------------------------------- template initialization
[621]162
[634]163// start date
164get_day_list('start_day', @$_POST['start_day']);
165get_month_list('start_month', @$_POST['start_month']);
166// end date
167get_day_list('end_day', @$_POST['end_day']);
168get_month_list('end_month', @$_POST['end_month']);
[621]169
[345]170//
171// Start output of page
172//
[2015]173$title= l10n('search_title');
[850]174$page['body_id'] = 'theSearchPage';
[345]175
[355]176$template->set_filenames( array('search'=>'search.tpl') );
[1125]177
[1314]178$template->assign_vars(
179  array(
180    'TODAY_DAY' => date('d', time()),
181    'TODAY_MONTH' => date('m', time()),
182    'TODAY_YEAR' => date('Y', time()),
183    'S_SEARCH_ACTION' => 'search.php',
184    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
185    'U_HOME' => make_index_url(),
186    )
187  );
188
[1677]189$available_tags = get_available_tags();
[1125]190
[1314]191if (count($available_tags) > 0)
192{
193  usort( $available_tags, 'name_compare');
[1119]194
[1314]195  $template->assign_block_vars('tags', array());
196 
197  $template->assign_vars(
198    array(
199      'TAG_SELECTION' => get_html_tag_selection(
200        $available_tags,
201        'tags',
202        isset($_POST['tags']) ? $_POST['tags'] : array()
203        ),
204      )
205    );
206}
[355]207
[455]208//------------------------------------------------------------- categories form
[614]209$query = '
210SELECT name,id,date_last,nb_images,global_rank,uppercats
[1677]211  FROM '.CATEGORIES_TABLE.'
212'.get_sql_condition_FandF
213  (
214    array
215      (
216        'forbidden_categories' => 'id',
217        'visible_categories' => 'id'
218      ),
219    'WHERE'
220  ).'
[614]221;';
[621]222
[455]223$selecteds = array();
[614]224display_select_cat_wrapper($query, $selecteds, 'category_option', false);
[455]225
[2]226//-------------------------------------------------------------- errors display
[455]227if (sizeof($errors) != 0)
[2]228{
[355]229  $template->assign_block_vars('errors',array());
[455]230  foreach ($errors as $error)
[2]231  {
[455]232    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
[2]233  }
234}
235//------------------------------------------------------------ log informations
[1627]236include(PHPWG_ROOT_PATH.'include/page_header.php');
[688]237$template->parse('search');
[369]238include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]239?>
Note: See TracBrowser for help on using the repository browser.