source: branches/1.7/search_rules.php @ 26010

Last change on this file since 26010 was 2137, checked in by rvelices, 17 years ago
  • fix plugin menu link broken with xamp (realpath behaves differently) (merge from trunk to branch 1_7)
  • added some meta_robots (noindex and nofollow) on popuphelp, search_rules and search seaction (googlebot gets crazy)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: search_rules.php 2137 2007-10-16 01:45:26Z rvelices $
8// | last update   : $Date: 2007-10-16 01:45:26 +0000 (Tue, 16 Oct 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2137 $
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// +-----------------------------------------------------------------------+
26
27/**
28 * returns language value 'included' or 'excluded' depending on boolean
29 * value. This function is useful only to make duplicate code shorter
30 *
31 * @param bool is_included
32 * @return string
33 */
34function inc_exc_str($is_included)
35{
36  return $is_included ? l10n('included') : l10n('excluded');
37}
38
39// +-----------------------------------------------------------------------+
40// |                           initialization                              |
41// +-----------------------------------------------------------------------+
42
43define('PHPWG_ROOT_PATH','./');
44include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
45check_status(ACCESS_NONE);
46include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' );
47
48$page['body_id'] = 'thePopuphelpPage';
49$title = l10n('PhpWebGallery Help');
50$page['page_banner'] = '<h1>'.$title.'</h1>';
51$page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
52include(PHPWG_ROOT_PATH.'include/page_header.php');
53
54$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
55
56// +-----------------------------------------------------------------------+
57// |                        Textual rules creation                         |
58// +-----------------------------------------------------------------------+
59
60// Rules are stored in database, serialized in an array. This array must be
61// transformed into a list of textual rules.
62
63$search = get_search_array($_GET['search_id']);
64
65if (isset($search['q']))
66{
67  $template->assign_block_vars(
68    'words',
69    array(
70      'CONTENT' => $search['q']
71        )
72    );
73}
74else
75{
76  $template->assign_vars(
77    array(
78      'INTRODUCTION'
79        => 'OR' == $search['mode']
80        ? l10n('At least one listed rule must be satisfied.')
81        : l10n('Each listed rule must be satisfied.'),
82      )
83    );
84}
85
86if (isset($search['fields']['allwords']))
87{
88  $template->assign_block_vars(
89    'words',
90    array(
91      'CONTENT' => sprintf(
92        l10n('searched words : %s'),
93        join(', ', $search['fields']['allwords']['words'])
94        )
95      )
96    );
97}
98
99if (isset($search['fields']['tags']))
100{
101  $template->assign_block_vars(
102    'tags',
103    array(
104      'LIST_INTRO' => ($search['fields']['tags']['mode'] == 'AND')
105        ? l10n('All tags must match')
106        : l10n('At least one tag must match')
107      )
108    );
109
110  $query = '
111SELECT name
112  FROM '.TAGS_TABLE.'
113  WHERE id IN ('.implode(',', $search['fields']['tags']['words']).')
114;';
115  $result = pwg_query($query);
116  while ($row = mysql_fetch_array($result))
117  {
118    $template->assign_block_vars(
119      'tags.tag',
120      array(
121        'NAME' => $row['name'],
122        )
123      );
124  }
125}
126
127if (isset($search['fields']['author']))
128{
129  $template->assign_block_vars(
130    'words',
131    array(
132      'CONTENT' => sprintf(
133          l10n('author(s) : %s'),
134          join(', ', $search['fields']['author']['words'])
135        )
136      )
137    );
138}
139
140if (isset($search['fields']['cat']))
141{
142  if ($search['fields']['cat']['sub_inc'])
143  {
144    // searching all the categories id of sub-categories
145    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
146  }
147  else
148  {
149    $cat_ids = $search['fields']['cat']['words'];
150  }
151
152  $template->assign_block_vars(
153    'categories',
154    array(
155      'LIST_INTRO' => l10n('Categories'),
156      )
157    );
158
159  $query = '
160SELECT id, uppercats, global_rank
161  FROM '.CATEGORIES_TABLE.'
162  WHERE id IN ('.
163    implode(',', $cat_ids).
164    ')
165;';
166  $result = pwg_query($query);
167
168  $categories = array();
169  if (!empty($result))
170  {
171    while ($row = mysql_fetch_array($result))
172    {
173      array_push($categories, $row);
174    }
175  }
176  usort($categories, 'global_rank_compare');
177
178  foreach ($categories as $category)
179  {
180    $template->assign_block_vars(
181      'categories.category',
182      array(
183        'NAME' => get_cat_display_name_cache(
184          $category['uppercats'],
185          null,                      // no url on category names
186          false                    // no blank replacement
187          )
188        )
189      );
190  }
191}
192
193foreach (array('date_available', 'date_creation') as $datefield)
194{
195  if ('date_available' == $datefield)
196  {
197    $lang_items = array(
198      'date'   => 'became available on %s',
199      'period' => 'became available between %s (%s) and %s (%s)',
200      'after'  => 'became available after %s (%s)',
201      'before' => 'became available before %s (%s)',
202      );
203  }
204  elseif ('date_creation' == $datefield)
205  {
206    $lang_items = array(
207      'date'   => 'created on %s',
208      'period' => 'created between %s (%s) and %s (%s)',
209      'after'  => 'created after %s (%s)',
210      'before' => 'created before %s (%s)',
211      );
212  }
213
214  $keys = array(
215    'date'   => $datefield,
216    'after'  => $datefield.'-after',
217    'before' => $datefield.'-before',
218    );
219
220  if (isset($search['fields'][ $keys['date'] ]))
221  {
222    $template->assign_block_vars(
223      $datefield,
224      array(
225        'CONTENT' => sprintf(
226          l10n($lang_items['date']),
227          format_date($search['fields'][ $keys['date'] ])
228          ),
229        )
230      );
231  }
232  elseif (isset($search['fields'][ $keys['before'] ])
233          and isset($search['fields'][ $keys['after'] ]))
234  {
235    $template->assign_block_vars(
236      $datefield,
237      array(
238        'CONTENT' => sprintf(
239          l10n($lang_items['period']),
240
241          format_date($search['fields'][ $keys['after'] ]['date']),
242          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
243
244          format_date($search['fields'][ $keys['before'] ]['date']),
245          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
246          ),
247        )
248      );
249  }
250  elseif (isset($search['fields'][ $keys['before'] ]))
251  {
252    $template->assign_block_vars(
253      $datefield,
254      array(
255        'CONTENT' => sprintf(
256          l10n($lang_items['before']),
257
258          format_date($search['fields'][ $keys['before'] ]['date']),
259          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
260          ),
261        )
262      );
263  }
264  elseif (isset($search['fields'][ $keys['after'] ]))
265  {
266    $template->assign_block_vars(
267      $datefield,
268      array(
269        'CONTENT' => sprintf(
270          l10n($lang_items['after']),
271
272          format_date($search['fields'][ $keys['after'] ]['date']),
273          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
274          )
275        )
276      );
277  }
278}
279
280// +-----------------------------------------------------------------------+
281// |                           html code display                           |
282// +-----------------------------------------------------------------------+
283
284$template->parse('search_rules');
285include(PHPWG_ROOT_PATH.'include/page_tail.php');
286?>
Note: See TracBrowser for help on using the repository browser.