source: trunk/search_rules.php @ 1015

Revision 1015, 7.3 KB checked in by plg, 14 years ago (diff)

Search engine redesign, second part :

improvement: in category.php, an icon opening a popup display the list of
search rules.

modification: function get_search_array is responsible of search rules
retrieving from database. This function is called from get_sql_search_clause
and from search_rules.php

modification: ability to search multiple authors. Warning: this version of
search tool can't search author names including any blank space.

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: 2005-09-27 23:57:14 +0200 (mar, 27 sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 879 $
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/**
29 * returns language value 'included' or 'excluded' depending on boolean
30 * value. This function is useful only to make duplicate code shorter
31 *
32 * @param bool is_included
33 * @return string
34 */
35function inc_exc_str($is_included)
36{
37  return $is_included ? l10n('included') : l10n('excluded');
38}
39
40// +-----------------------------------------------------------------------+
41// |                           initialization                              |
42// +-----------------------------------------------------------------------+
43
44define('PHPWG_ROOT_PATH','./');
45include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
46
47$page['body_id'] = 'thePopuphelpPage';
48$page['gallery_title'] = $title = l10n('PhpWebGallery Help');
49include(PHPWG_ROOT_PATH.'include/page_header.php');
50
51$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
52
53// +-----------------------------------------------------------------------+
54// |                        Textual rules creation                         |
55// +-----------------------------------------------------------------------+
56
57// Rules are stored in database, serialized in an array. This array must be
58// transformed into a list of textual rules.
59
60$search = get_search_array($_GET['search_id']);
61
62$template->assign_vars(
63  array(
64    'INTRODUCTION'
65      => 'OR' == $search['mode']
66      ? l10n('At least one listed rule must be satisfied.')
67      : l10n('Each listed rule must be satisfied.'),
68    )
69  );
70
71if (isset($search['fields']['allwords']))
72{
73  $template->assign_block_vars(
74    'words',
75    array(
76      'CONTENT' => sprintf(
77        l10n('searched words : %s'),
78        join(', ', $search['fields']['allwords']['words'])
79        )
80      )
81    );
82}
83
84if (isset($search['fields']['author']))
85{
86  $template->assign_block_vars(
87    'words',
88    array(
89      'CONTENT' => sprintf(
90          l10n('author(s) : %s'),
91          join(', ', $search['fields']['author']['words'])
92        )
93      )
94    );
95}
96
97if (isset($search['fields']['cat']))
98{
99  if ($search['fields']['cat']['sub_inc'])
100  {
101    // searching all the categories id of sub-categories
102    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
103  }
104  else
105  {
106    $cat_ids = $search['fields']['cat']['words'];
107  }
108
109  $template->assign_block_vars(
110    'categories',
111    array(
112      'LIST_INTRO' => l10n('categories'),
113      )
114    );
115
116  $query = '
117SELECT id, uppercats, global_rank
118  FROM '.CATEGORIES_TABLE.'
119  WHERE id IN ('.
120    implode(',', $cat_ids).
121    ')
122;';
123  $result = pwg_query($query);
124
125  $categories = array();
126  if (!empty($result))
127  {
128    while ($row = mysql_fetch_array($result))
129    {
130      array_push($categories, $row);
131    }
132  }
133  usort($categories, 'global_rank_compare');
134
135  foreach ($categories as $category)
136  {
137    $template->assign_block_vars(
138      'categories.category',
139      array(
140        'NAME' => get_cat_display_name_cache(
141          $category['uppercats'],
142          '',                      // no url on category names
143          false                    // no blank replacement
144          )
145        )
146      );
147  }
148}
149
150foreach (array('date_available', 'date_creation') as $datefield)
151{
152  if ('date_available' == $datefield)
153  {
154    $lang_items = array(
155      'date'   => 'became available on %s',
156      'period' => 'became available between %s (%s) and %s (%s)',
157      'after'  => 'became available after %s (%s)',
158      'before' => 'became available before %s (%s)',
159      );
160  }
161  elseif ('date_creation' == $datefield)
162  {
163    $lang_items = array(
164      'date'   => 'created on %s',
165      'period' => 'created between %s (%s) and %s (%s)',
166      'after'  => 'created after %s (%s)',
167      'before' => 'created before %s (%s)',
168      );
169  }
170
171  $keys = array(
172    'date'   => $datefield,
173    'after'  => $datefield.'-after',
174    'before' => $datefield.'-before',
175    );
176
177  if (isset($search['fields'][ $keys['date'] ]))
178  {
179    $template->assign_block_vars(
180      $datefield,
181      array(
182        'CONTENT' => sprintf(
183          l10n($lang_items['date']),
184          format_date($search['fields'][ $keys['date'] ])
185          ),
186        )
187      );
188  }
189  elseif (isset($search['fields'][ $keys['before'] ])
190          and isset($search['fields'][ $keys['after'] ]))
191  {
192    $template->assign_block_vars(
193      $datefield,
194      array(
195        'CONTENT' => sprintf(
196          l10n($lang_items['period']),
197         
198          format_date($search['fields'][ $keys['after'] ]['date']),
199          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
200
201          format_date($search['fields'][ $keys['before'] ]['date']),
202          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
203          ),
204        )
205      );
206  }
207  elseif (isset($search['fields'][ $keys['before'] ]))
208  {
209    $template->assign_block_vars(
210      $datefield,
211      array(
212        'CONTENT' => sprintf(
213          l10n($lang_items['before']),
214         
215          format_date($search['fields'][ $keys['before'] ]['date']),
216          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
217          ),
218        )
219      );
220  }
221  elseif (isset($search['fields'][ $keys['after'] ]))
222  {
223    $template->assign_block_vars(
224      $datefield,
225      array(
226        'CONTENT' => sprintf(
227          l10n($lang_items['after']),
228         
229          format_date($search['fields'][ $keys['after'] ]['date']),
230          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
231          )
232        )
233      );
234  }
235}
236
237// +-----------------------------------------------------------------------+
238// |                           html code display                           |
239// +-----------------------------------------------------------------------+
240
241$template->parse('search_rules');
242include(PHPWG_ROOT_PATH.'include/page_tail.php');
243?>
Note: See TracBrowser for help on using the repository browser.