source: branches/branch-1_6/search.php @ 1230

Last change on this file since 1230 was 1125, checked in by rvelices, 19 years ago

image sort order for tags

very minor code and language simplifications and corrections

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