aboutsummaryrefslogtreecommitdiffstats
path: root/search_rules.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-01-27 22:40:51 +0000
committerplegall <plg@piwigo.org>2006-01-27 22:40:51 +0000
commit61668e4cf7627f3f2d56d92c6e80ff72b38965fa (patch)
tree052c70867a98c6fb8a0e8d721c0e317e2e0d68ad /search_rules.php
parenta8fd5ee6cf5cf061ed0ff789d6030290b3418be5 (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. git-svn-id: http://piwigo.org/svn/trunk@1015 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'search_rules.php')
-rw-r--r--search_rules.php243
1 files changed, 243 insertions, 0 deletions
diff --git a/search_rules.php b/search_rules.php
new file mode 100644
index 000000000..68407fb29
--- /dev/null
+++ b/search_rules.php
@@ -0,0 +1,243 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2005-09-27 23:57:14 +0200 (mar, 27 sep 2005) $
+// | last modifier : $Author: plg $
+// | revision : $Revision: 879 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+/**
+ * returns language value 'included' or 'excluded' depending on boolean
+ * value. This function is useful only to make duplicate code shorter
+ *
+ * @param bool is_included
+ * @return string
+ */
+function inc_exc_str($is_included)
+{
+ return $is_included ? l10n('included') : l10n('excluded');
+}
+
+// +-----------------------------------------------------------------------+
+// | initialization |
+// +-----------------------------------------------------------------------+
+
+define('PHPWG_ROOT_PATH','./');
+include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
+
+$page['body_id'] = 'thePopuphelpPage';
+$page['gallery_title'] = $title = l10n('PhpWebGallery Help');
+include(PHPWG_ROOT_PATH.'include/page_header.php');
+
+$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
+
+// +-----------------------------------------------------------------------+
+// | Textual rules creation |
+// +-----------------------------------------------------------------------+
+
+// Rules are stored in database, serialized in an array. This array must be
+// transformed into a list of textual rules.
+
+$search = get_search_array($_GET['search_id']);
+
+$template->assign_vars(
+ array(
+ 'INTRODUCTION'
+ => 'OR' == $search['mode']
+ ? l10n('At least one listed rule must be satisfied.')
+ : l10n('Each listed rule must be satisfied.'),
+ )
+ );
+
+if (isset($search['fields']['allwords']))
+{
+ $template->assign_block_vars(
+ 'words',
+ array(
+ 'CONTENT' => sprintf(
+ l10n('searched words : %s'),
+ join(', ', $search['fields']['allwords']['words'])
+ )
+ )
+ );
+}
+
+if (isset($search['fields']['author']))
+{
+ $template->assign_block_vars(
+ 'words',
+ array(
+ 'CONTENT' => sprintf(
+ l10n('author(s) : %s'),
+ join(', ', $search['fields']['author']['words'])
+ )
+ )
+ );
+}
+
+if (isset($search['fields']['cat']))
+{
+ if ($search['fields']['cat']['sub_inc'])
+ {
+ // searching all the categories id of sub-categories
+ $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
+ }
+ else
+ {
+ $cat_ids = $search['fields']['cat']['words'];
+ }
+
+ $template->assign_block_vars(
+ 'categories',
+ array(
+ 'LIST_INTRO' => l10n('categories'),
+ )
+ );
+
+ $query = '
+SELECT id, uppercats, global_rank
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.
+ implode(',', $cat_ids).
+ ')
+;';
+ $result = pwg_query($query);
+
+ $categories = array();
+ if (!empty($result))
+ {
+ while ($row = mysql_fetch_array($result))
+ {
+ array_push($categories, $row);
+ }
+ }
+ usort($categories, 'global_rank_compare');
+
+ foreach ($categories as $category)
+ {
+ $template->assign_block_vars(
+ 'categories.category',
+ array(
+ 'NAME' => get_cat_display_name_cache(
+ $category['uppercats'],
+ '', // no url on category names
+ false // no blank replacement
+ )
+ )
+ );
+ }
+}
+
+foreach (array('date_available', 'date_creation') as $datefield)
+{
+ if ('date_available' == $datefield)
+ {
+ $lang_items = array(
+ 'date' => 'became available on %s',
+ 'period' => 'became available between %s (%s) and %s (%s)',
+ 'after' => 'became available after %s (%s)',
+ 'before' => 'became available before %s (%s)',
+ );
+ }
+ elseif ('date_creation' == $datefield)
+ {
+ $lang_items = array(
+ 'date' => 'created on %s',
+ 'period' => 'created between %s (%s) and %s (%s)',
+ 'after' => 'created after %s (%s)',
+ 'before' => 'created before %s (%s)',
+ );
+ }
+
+ $keys = array(
+ 'date' => $datefield,
+ 'after' => $datefield.'-after',
+ 'before' => $datefield.'-before',
+ );
+
+ if (isset($search['fields'][ $keys['date'] ]))
+ {
+ $template->assign_block_vars(
+ $datefield,
+ array(
+ 'CONTENT' => sprintf(
+ l10n($lang_items['date']),
+ format_date($search['fields'][ $keys['date'] ])
+ ),
+ )
+ );
+ }
+ elseif (isset($search['fields'][ $keys['before'] ])
+ and isset($search['fields'][ $keys['after'] ]))
+ {
+ $template->assign_block_vars(
+ $datefield,
+ array(
+ 'CONTENT' => sprintf(
+ l10n($lang_items['period']),
+
+ format_date($search['fields'][ $keys['after'] ]['date']),
+ inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
+
+ format_date($search['fields'][ $keys['before'] ]['date']),
+ inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
+ ),
+ )
+ );
+ }
+ elseif (isset($search['fields'][ $keys['before'] ]))
+ {
+ $template->assign_block_vars(
+ $datefield,
+ array(
+ 'CONTENT' => sprintf(
+ l10n($lang_items['before']),
+
+ format_date($search['fields'][ $keys['before'] ]['date']),
+ inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
+ ),
+ )
+ );
+ }
+ elseif (isset($search['fields'][ $keys['after'] ]))
+ {
+ $template->assign_block_vars(
+ $datefield,
+ array(
+ 'CONTENT' => sprintf(
+ l10n($lang_items['after']),
+
+ format_date($search['fields'][ $keys['after'] ]['date']),
+ inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
+ )
+ )
+ );
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | html code display |
+// +-----------------------------------------------------------------------+
+
+$template->parse('search_rules');
+include(PHPWG_ROOT_PATH.'include/page_tail.php');
+?> \ No newline at end of file