source: trunk/search.php @ 1677

Last change on this file since 1677 was 1677, checked in by rub, 17 years ago

Feature Issue ID 0000601: Filter all public pages with only recent elements

It's a finalized version.
Obsolete code of draft are removed.

You can filter categories and images with recent date period on your screen selection.
In the future, filter could be easy done on other type data (plugin?)

You can flat categories and sub-categories with a recent date period of your choice.

Next, perhaps, a panel to choice recent date for the 2 features.

On draft, there have problem with MySql 5, be careful!

Css problem not resolved:

  • Menu "Categories" is bad centered
  • Icon on dark too on the top
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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-12-21 21:38:20 +0000 (Thu, 21 Dec 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1677 $
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';
176
177$template->set_filenames( array('search'=>'search.tpl') );
178
179$template->assign_vars(
180  array(
181    'TODAY_DAY' => date('d', time()),
182    'TODAY_MONTH' => date('m', time()),
183    'TODAY_YEAR' => date('Y', time()),
184    'S_SEARCH_ACTION' => 'search.php',
185    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
186    'U_HOME' => make_index_url(),
187    )
188  );
189
190$available_tags = get_available_tags();
191
192if (count($available_tags) > 0)
193{
194  usort( $available_tags, 'name_compare');
195
196  $template->assign_block_vars('tags', array());
197 
198  $template->assign_vars(
199    array(
200      'TAG_SELECTION' => get_html_tag_selection(
201        $available_tags,
202        'tags',
203        isset($_POST['tags']) ? $_POST['tags'] : array()
204        ),
205      )
206    );
207}
208
209//------------------------------------------------------------- categories form
210$query = '
211SELECT name,id,date_last,nb_images,global_rank,uppercats
212  FROM '.CATEGORIES_TABLE.'
213'.get_sql_condition_FandF
214  (
215    array
216      (
217        'forbidden_categories' => 'id',
218        'visible_categories' => 'id'
219      ),
220    'WHERE'
221  ).'
222;';
223
224$selecteds = array();
225display_select_cat_wrapper($query, $selecteds, 'category_option', false);
226
227//-------------------------------------------------------------- errors display
228if (sizeof($errors) != 0)
229{
230  $template->assign_block_vars('errors',array());
231  foreach ($errors as $error)
232  {
233    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
234  }
235}
236//------------------------------------------------------------ log informations
237pwg_log( 'search', $title );
238include(PHPWG_ROOT_PATH.'include/page_header.php');
239$template->parse('search');
240include(PHPWG_ROOT_PATH.'include/page_tail.php');
241?>
Note: See TracBrowser for help on using the repository browser.