source: trunk/search.php @ 1082

Last change on this file since 1082 was 1082, checked in by plg, 18 years ago

new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and
make_picture_url build these new URLs. Functions duplicate_picture_url and
duplicate_index_url provide shortcuts to URL creation. The current main page
page is still category.php but this can be modified easily in make_index_url
function. In this first version, no backward compatibility. Calendar
definition in URL must be discussed with rvelices.

improvement: picture.php redesigned. First actions like "set as
representative" or "delete a comment" which all lead to a redirection. Then
the page (the big mess) and includes of new sub pages to manage specific
parts of the page (metadata, user comments, rates).

new: with the cleaner URL comes a new terminology. $pagecat doesn't
exist anymore. $pagesection is among 'categories', 'tags' (TODO),
'list', 'most_seen'... And sub parameters are set : $pagecategory if
$pagesection is "categories". See URL analyse in
include/section_init.inc.php for details.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-15 22:44:35 +0000 (Wed, 15 Mar 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1082 $
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 ($_POST['search_author'])
69  {
70    $search['fields']['author'] = array(
71      'words' => preg_split(
72        '/\s+/',
73        $_POST['search_author']
74        ),
75      'mode' => 'OR',
76      );
77  }
78
79  if (isset($_POST['cat']))
80  {
81    $search['fields']['cat'] = array(
82      'words'   => $_POST['cat'],
83      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
84      );
85  }
86
87  // dates
88  $type_date = $_POST['date_type'];
89
90  if (!empty($_POST['start_year']))
91  {
92    $search['fields'][$type_date.'-after'] = array(
93      'date' => join(
94        '-',
95        array(
96          $_POST['start_year'],
97          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
98          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
99          )
100        ),
101      'inc' => true,
102      );
103  }
104
105  if (!empty($_POST['end_year']))
106  {
107    $search['fields'][$type_date.'-before'] = array(
108      'date' => join(
109        '-',
110        array(
111          $_POST['end_year'],
112          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
113          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
114          )
115        ),
116      'inc' => true,
117      );
118  }
119
120  if (!empty($search))
121  {
122    // default search mode : each clause must be respected
123    $search['mode'] = 'AND';
124
125    // register search rules in database, then they will be available on
126    // thumbnails page and picture page.
127    $query ='
128INSERT INTO '.SEARCH_TABLE.'
129  (rules)
130  VALUES
131  (\''.serialize($search).'\')
132;';
133    pwg_query($query);
134
135    $search_id = mysql_insert_id();
136  }
137  else
138  {
139    array_push($errors, $lang['search_one_clause_at_least']);
140  }
141}
142//----------------------------------------------------------------- redirection
143if (isset($_POST['submit']) and count($errors) == 0)
144{
145  redirect(
146    make_index_url(
147      array(
148        'section' => 'search',
149        'search'  => $search_id,
150        )
151      )
152    );
153}
154//----------------------------------------------------- template initialization
155
156// start date
157get_day_list('start_day', @$_POST['start_day']);
158get_month_list('start_month', @$_POST['start_month']);
159// end date
160get_day_list('end_day', @$_POST['end_day']);
161get_month_list('end_month', @$_POST['end_month']);
162
163//
164// Start output of page
165//
166$title= $lang['search_title'];
167$page['body_id'] = 'theSearchPage';
168include(PHPWG_ROOT_PATH.'include/page_header.php');
169
170$template->set_filenames( array('search'=>'search.tpl') );
171$template->assign_vars(array(
172  'L_SEARCH_TITLE' => $lang['search_title'],
173  'L_SEARCH_OPTIONS' => $lang['search_options'],
174  'L_RETURN' => $lang['home'],
175  'L_SUBMIT' => $lang['submit'],
176  'L_RESET' => $lang['reset'],
177  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
178  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
179  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
180  'L_SEARCH_AUTHOR'=>$lang['search_author'],
181  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
182  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
183  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
184  'L_YES' => $lang['yes'],
185  'L_NO' => $lang['no'],
186  'L_SEARCH_DATE' => $lang['search_date'],
187  'L_TODAY' => $lang['today'],
188  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
189  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
190  'L_DAYS'=>$lang['days'],
191  'L_MONTH'=>$lang['w_month'],
192  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
193  'L_RESULT_SORT'=>$lang['search_sort'],
194  'L_SORT_ASCENDING'=>$lang['search_ascending'],
195  'L_SORT_DESCENDING'=>$lang['search_descending'],
196
197  'TODAY_DAY' => date('d', time()),
198  'TODAY_MONTH' => date('m', time()),
199  'TODAY_YEAR' => date('Y', time()),
200  'S_SEARCH_ACTION' => 'search.php',
201  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
202  'U_HOME' => make_index_url(),
203  )
204);
205
206//------------------------------------------------------------- categories form
207$query = '
208SELECT name,id,date_last,nb_images,global_rank,uppercats
209  FROM '.CATEGORIES_TABLE;
210if ($user['forbidden_categories'] != '')
211{
212  $query.= '
213  WHERE id NOT IN ('.$user['forbidden_categories'].')';
214}
215$query.= '
216;';
217
218$selecteds = array();
219display_select_cat_wrapper($query, $selecteds, 'category_option', false);
220
221//-------------------------------------------------------------- errors display
222if (sizeof($errors) != 0)
223{
224  $template->assign_block_vars('errors',array());
225  foreach ($errors as $error)
226  {
227    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
228  }
229}
230//------------------------------------------------------------ log informations
231pwg_log( 'search', $title );
232$template->parse('search');
233include(PHPWG_ROOT_PATH.'include/page_tail.php');
234?>
Note: See TracBrowser for help on using the repository browser.