From 61668e4cf7627f3f2d56d92c6e80ff72b38965fa Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 27 Jan 2006 22:40:51 +0000 Subject: 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 --- category.php | 10 ++ include/functions.inc.php | 32 ++-- language/en_UK.iso-8859-1/common.lang.php | 30 +++- language/fr_FR.iso-8859-1/common.lang.php | 19 ++- search.php | 6 +- search_rules.php | 243 ++++++++++++++++++++++++++++++ template/yoga/category.tpl | 14 +- template/yoga/icon/search_rules.png | Bin 0 -> 1509 bytes template/yoga/search_rules.tpl | 44 ++++++ 9 files changed, 373 insertions(+), 25 deletions(-) create mode 100644 search_rules.php create mode 100644 template/yoga/icon/search_rules.png create mode 100644 template/yoga/search_rules.tpl diff --git a/category.php b/category.php index 6a0b7a651..5889f505c 100644 --- a/category.php +++ b/category.php @@ -165,6 +165,16 @@ $template->assign_vars( 'U_PROFILE'=> PHPWG_ROOT_PATH.'profile.php' ) ); + +if (isset($page['cat']) and 'search' == $page['cat']) +{ + $template->assign_block_vars( + 'search_rules', + array( + 'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$_GET['search'], + ) + ); +} //-------------------------------------------------------------- external links if (count($conf['links']) > 0) { diff --git a/include/functions.inc.php b/include/functions.inc.php index 9586dfc7f..511da391a 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -773,15 +773,13 @@ function prepend_append_array_items($array, $prepend_str, $append_str) } /** - * returns the SQL clause from a search identifier - * - * Search rules are stored in search table as a serialized array. This array - * need to be transformed into an SQL clause to be used in queries. + * returns search rules stored into a serialized array in "search" + * table. Each search rules set is numericaly identified. * * @param int search_id - * @return string + * @return array */ -function get_sql_search_clause($search_id) +function get_search_array($search_id) { if (!is_numeric($search_id)) { @@ -791,16 +789,26 @@ function get_sql_search_clause($search_id) $query = ' SELECT rules FROM '.SEARCH_TABLE.' - WHERE id = '.$_GET['search'].' + WHERE id = '.$search_id.' ;'; list($serialized_rules) = mysql_fetch_row(pwg_query($query)); - $search = unserialize($serialized_rules); - -// echo '
';
-//   print_r($search);
-//   echo '
'; + return unserialize($serialized_rules); +} +/** + * returns the SQL clause from a search identifier + * + * Search rules are stored in search table as a serialized array. This array + * need to be transformed into an SQL clause to be used in queries. + * + * @param int search_id + * @return string + */ +function get_sql_search_clause($search_id) +{ + $search = get_search_array($search_id); + // SQL where clauses are stored in $clauses array during query // construction $clauses = array(); diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php index c82eb63c0..94f37d00c 100644 --- a/language/en_UK.iso-8859-1/common.lang.php +++ b/language/en_UK.iso-8859-1/common.lang.php @@ -41,21 +41,22 @@ $lang['%d new elements'] = '%d new elements'; $lang['%d new users'] = '%d new users'; $lang['%d waiting elements'] = '%d waiting elements'; $lang['About'] = 'About'; +$lang['At least one listed rule must be satisfied.'] = 'At least one listed rule must be satisfied.'; $lang['Author'] = 'Author'; $lang['Average rate'] = 'Average rate'; $lang['Categories'] = 'Categories'; $lang['Category'] = 'Category'; $lang['Close this window'] = 'Close this window'; $lang['Confirm Password'] = 'Confirm Password'; -$lang['Connection'] = 'Connection'; -$lang['Quick connect'] = 'Quick connect'; $lang['Connection settings'] = 'Connection settings'; +$lang['Connection'] = 'Connection'; $lang['Contact webmaster'] = 'Contact webmaster'; $lang['Create a new account'] = 'Create a new account'; $lang['Created on'] = 'Created on'; $lang['Current password is wrong'] = 'Current password is wrong'; $lang['Dimensions'] = 'Dimensions'; $lang['Display'] = 'Display'; +$lang['Each listed rule must be satisfied.'] = 'Each listed rule must be satisfied.'; $lang['Email address is missing'] = 'Email address is missing'; $lang['Email address'] = 'Email address'; $lang['Enter your personnal informations'] = 'Enter your personnal informations'; @@ -85,12 +86,14 @@ $lang['Password forgotten'] = 'Password forgotten'; $lang['Password'] = 'Password'; $lang['PhpWebGallery Help'] = 'PhpWebGallery Help'; $lang['Profile'] = 'Profile'; +$lang['Quick connect'] = 'Quick connect'; $lang['RSS feed'] = 'RSS feed'; $lang['Register'] = 'Register'; $lang['Registered on'] = 'Registered on'; $lang['Registration'] = 'Registration'; $lang['Reset'] = 'Reset'; $lang['Retrieve password'] = 'Retrieve password'; +$lang['Search rules'] = 'Search rules'; $lang['Search'] = 'Search'; $lang['Send new password'] = 'Send new password'; $lang['Since'] = 'Since'; @@ -108,9 +111,16 @@ $lang['add to caddie'] = 'add to caddie'; $lang['add_favorites_alt'] = 'Add to favorites'; $lang['add_favorites_hint'] = 'Add this picture to your favorites'; $lang['admin'] = 'Administration'; +$lang['all'] = 'all'; $lang['all_categories'] = 'all categories'; $lang['already_rated'] = 'You\'ve already rated this item'; +$lang['ascending'] = 'ascending'; +$lang['author(s) : %s'] = 'author(s) : %s'; $lang['auto_expand'] = 'Expand all categories'; +$lang['became available after %s (%s)'] = 'became available after %s (%s)'; +$lang['became available before %s (%s)'] = 'became available before %s (%s)'; +$lang['became available between %s (%s) and %s (%s)'] = 'became available between %s (%s) and %s (%s)'; +$lang['became available on %s'] = 'became available on %s'; $lang['best_rated_cat'] = 'best rated'; $lang['best_rated_cat_hint'] = 'displays best rated items'; $lang['caddie'] = 'caddie'; @@ -118,6 +128,7 @@ $lang['calendar'] = 'Calendar'; $lang['calendar_hint'] = 'displays each day with pictures, month per month'; $lang['calendar_picture_hint'] = 'displays pictures added on '; $lang['categories'] = 'Categories'; +$lang['comment date'] = 'comment date'; $lang['comment'] = 'Comment'; $lang['comment_added'] = 'Your comment has been registered'; $lang['comment_anti-flood'] = 'Anti-flood system : please wait for a moment before trying to post another comment'; @@ -128,6 +139,10 @@ $lang['comments_add'] = 'Add a comment'; $lang['comments_del'] = 'delete this comment'; $lang['comments_title'] = 'Comments from the users of the site'; $lang['confirm_password_hint'] = 'You only have to confirm your new password if you wish to change it.'; +$lang['created after %s (%s)'] = 'created after %s (%s)'; +$lang['created before %s (%s)'] = 'created before %s (%s)'; +$lang['created between %s (%s) and %s (%s)'] = 'created between %s (%s) and %s (%s)'; +$lang['created on %s'] = 'created on %s'; $lang['customize'] = 'Customize'; $lang['customize_page_title'] = 'Your Gallery Customization '; $lang['customize_title'] = 'Customization'; @@ -142,11 +157,13 @@ $lang['days'] = 'days'; $lang['del_favorites_alt'] = 'Delete from favorites'; $lang['del_favorites_hint'] = 'Delete this picture from your favorites'; $lang['delete'] = 'Delete'; +$lang['descending'] = 'descending'; $lang['download'] = 'download'; $lang['download_hint'] = 'download this file'; $lang['edit category informations'] = 'edit category informations'; $lang['edit'] = 'edit'; $lang['err_date'] = 'wrong date'; +$lang['excluded'] = 'excluded'; $lang['favorite_cat'] = 'My favorites'; $lang['favorite_cat_hint'] = 'display my favorites pictures'; $lang['favorites'] = 'Favorites'; @@ -168,6 +185,7 @@ $lang['ident_register'] = 'Register'; $lang['ident_title'] = 'ident_title'; $lang['identification'] = 'Identification'; $lang['images_available'] = 'images in this category'; +$lang['included'] = 'included'; $lang['invalid_pwd'] = 'Invalid password!'; $lang['language']='Language'; $lang['last %d days'] = 'last %d days'; @@ -210,6 +228,7 @@ $lang['password updated'] = 'password updated'; $lang['password'] = 'Password'; $lang['password_hint'] = 'You only have to give your password if you wish to change your e-mail'; $lang['periods_error'] = 'Recent period must be a positive integer value'; +$lang['picture'] = 'picture'; $lang['picture_high'] = 'Click on the picture to see it in high definition'; $lang['picture_show_metadata'] = 'Show file metadata'; $lang['powered_by'] = 'Powered by'; @@ -258,6 +277,7 @@ $lang['search_result'] = 'Search results'; $lang['search_sort'] = 'Sort results by'; $lang['search_subcats_included'] = 'Search in subcategroies'; $lang['search_title'] = 'Search'; +$lang['searched words : %s'] = 'searched words : %s'; $lang['send_mail'] = 'Contact'; $lang['set as category representative'] = 'set as category representative'; $lang['show_nb_comments'] = 'Show number of comments'; @@ -299,10 +319,4 @@ $lang['upload_username'] = 'Username'; $lang['useful when password forgotten'] = 'useful when password forgotten'; $lang['w_month'] = 'Month'; $lang['yes'] = 'Yes'; - -$lang['descending'] = 'descending'; -$lang['all'] = 'all'; -$lang['ascending'] = 'ascending'; -$lang['comment date'] = 'comment date'; -$lang['picture'] = 'picture'; ?> diff --git a/language/fr_FR.iso-8859-1/common.lang.php b/language/fr_FR.iso-8859-1/common.lang.php index 53f5a3129..9b2b07702 100644 --- a/language/fr_FR.iso-8859-1/common.lang.php +++ b/language/fr_FR.iso-8859-1/common.lang.php @@ -40,21 +40,22 @@ $lang['%d new comments'] = '%d nouveaux commentaires utilisateur'; $lang['%d new elements'] = '%d nouveaux éléments'; $lang['%d new users'] = '%d nouveaux utilisateurs'; $lang['About'] = 'À propos'; +$lang['At least one listed rule must be satisfied.'] = 'Au moins un des critères doit être satisfait.'; $lang['Author'] = 'Auteur'; $lang['Average rate'] = 'Note moyenne'; $lang['Categories'] = 'Catégories'; $lang['Category'] = 'Catégorie'; $lang['Close this window'] = 'Fermer cette fenêtre'; $lang['Confirm Password'] = 'Confirmer le mot de passe'; -$lang['Connection'] = 'Connexion'; -$lang['Quick connect'] = 'Connexion rapide'; $lang['Connection settings'] = 'Paramètres de connexion'; +$lang['Connection'] = 'Connexion'; $lang['Contact webmaster'] = 'Contacter le webmestre'; $lang['Create a new account'] = 'Créer un nouveau compte'; $lang['Created on'] = 'Créée le'; $lang['Current password is wrong'] = 'Erreur sur le mot de passe actuel'; $lang['Dimensions'] = 'Dimensions'; $lang['Display'] = 'Affichage'; +$lang['Each listed rule must be satisfied.'] = 'Chaque critère doit être satisfait'; $lang['Email address is missing'] = 'L\'adresse e-mail manque'; $lang['Email address'] = 'Adresse e-mail'; $lang['Enter your personnal informations'] = 'Entrer vos informations personnelles'; @@ -84,12 +85,14 @@ $lang['Password forgotten'] = 'Mot de passe oubli $lang['Password'] = 'Mot de passe'; $lang['PhpWebGallery Help'] = 'Aide de PhpWebGallery'; $lang['Profile'] = 'Profil'; +$lang['Quick connect'] = 'Connexion rapide'; $lang['RSS feed'] = 'flux RSS'; $lang['Register'] = 'S\'enregistrer'; $lang['Registered on'] = 'Enregistrée le'; $lang['Registration'] = 'Enregistrement'; $lang['Reset'] = 'Annuler'; $lang['Retrieve password'] = 'Récupérer un mot de passe'; +$lang['Search rules'] = 'Critères de recherche'; $lang['Search'] = 'Rechercher'; $lang['Send new password'] = 'Envoyer le nouveau mot de passe'; $lang['Since'] = 'Depuis'; @@ -111,7 +114,12 @@ $lang['all'] = 'tout'; $lang['all_categories'] = 'toutes les catégories'; $lang['already_rated'] = 'Vous avez déjà voté pour cette image'; $lang['ascending'] = 'croissant'; +$lang['author(s) : %s'] = 'auteur(s) : %s'; $lang['auto_expand'] = 'Développer toutes les catégories'; +$lang['became available after %s (%s)'] = 'mis à disposition après le %s (%s)'; +$lang['became available before %s (%s)'] = 'mis à disposition avant le %s (%s)'; +$lang['became available between %s (%s) and %s (%s)'] = 'mis à disposition entre le %s (%s) et le %s (%s)'; +$lang['became available on %s'] = 'mis à disposition le %s'; $lang['best_rated_cat'] = 'Mieux notées'; $lang['best_rated_cat_hint'] = 'affiche les images les mieux notées'; $lang['caddie'] = 'Panier'; @@ -130,6 +138,10 @@ $lang['comments_add'] = 'Ajouter un commentaire'; $lang['comments_del'] = 'Supprimer ce commentaire'; $lang['comments_title'] = 'Commentaires des utilisateurs'; $lang['confirm_password_hint'] = 'Vous n\'avez à confirmer votre mot de passe que si vous désirez en changer.'; +$lang['created after %s (%s)'] = 'créée après le %s (%s)'; +$lang['created before %s (%s)'] = 'créée avant le %s (%s)'; +$lang['created between %s (%s) and %s (%s)'] = 'créée entre le %s (%s) et le %s (%s)'; +$lang['created on %s'] = 'créée le %s'; $lang['customize'] = 'Personnaliser'; $lang['customize_page_title'] = 'Personnalisation de votre affichage '; $lang['customize_title'] = 'Personnaliser'; @@ -150,6 +162,7 @@ $lang['download_hint'] = 't $lang['edit category informations'] = 'éditer les informations de cette catégorie'; $lang['edit'] = 'éditer'; $lang['err_date'] = 'date erronée'; +$lang['excluded'] = 'exclus'; $lang['favorite_cat'] = 'Mes favorites'; $lang['favorite_cat_hint'] = 'afficher mes images favorites'; $lang['favorites'] = 'Favoris'; @@ -171,6 +184,7 @@ $lang['ident_register'] = 'S\'enregistrer'; $lang['ident_title'] = 'Identification (FIXME)'; $lang['identification'] = 'Identification'; $lang['images_available'] = 'images dans cette catégorie'; +$lang['included'] = 'inclus'; $lang['invalid_pwd'] = 'Mot de passe invalide !'; $lang['language'] = 'Langue'; $lang['last %d days'] = '%d derniers jours'; @@ -262,6 +276,7 @@ $lang['search_result'] = 'R $lang['search_sort'] = 'Trier les résultats de recherche selon'; $lang['search_subcats_included'] = 'Rechercher dans les sous-catégories'; $lang['search_title'] = 'Recherche'; +$lang['searched words : %s'] = 'mots recherchés : %s'; $lang['send_mail'] = 'Contacter'; $lang['set as category representative'] = 'élire comme représentant de cette catégorie'; $lang['show_nb_comments'] = 'Montrer le nombre de commentaires'; diff --git a/search.php b/search.php index 6567f3fa8..28796535d 100644 --- a/search.php +++ b/search.php @@ -64,7 +64,11 @@ if (isset($_POST['submit'])) if ($_POST['search_author']) { $search['fields']['author'] = array( - 'words' => array($_POST['search_author']), + 'words' => preg_split( + '/\s+/', + $_POST['search_author'] + ), + 'mode' => 'OR', ); } 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 @@ +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 diff --git a/template/yoga/category.tpl b/template/yoga/category.tpl index 40391a923..1f9e50c66 100644 --- a/template/yoga/category.tpl +++ b/template/yoga/category.tpl @@ -107,15 +107,25 @@
-

{TITLE}

-
+ +

{TITLE}

+ + + diff --git a/template/yoga/icon/search_rules.png b/template/yoga/icon/search_rules.png new file mode 100644 index 000000000..300186647 Binary files /dev/null and b/template/yoga/icon/search_rules.png differ diff --git a/template/yoga/search_rules.tpl b/template/yoga/search_rules.tpl new file mode 100644 index 000000000..aac2586fe --- /dev/null +++ b/template/yoga/search_rules.tpl @@ -0,0 +1,44 @@ +
+

{lang:Search rules}

+ +

{INTRODUCTION}

+ + + +
+ +

+ + close + +

-- cgit v1.2.3