Commit 492887f6 authored by Joseph Yanick's avatar Joseph Yanick
Browse files

Merged updates from 6.x-1.x branch back to HEAD

parent f6d9b0ad
......@@ -4,15 +4,17 @@ search_config is used to configure the advanced search form.
Installation
------------
1. Copy entire search_config directory to the module directory of your Drupal
installation
2. Enable the search_config module on the admin modules page
3. Go to administer » settings » search, you should now see a
3. Go to administer » Search Configuration, you should now see a
"Advanced search form configuration" collapsed fieldset.
General Information
-------------------
This module started out as a simple means of configuring the *display* of the
advance search form. A few features have been added since thanks to the
contributions of others.
......@@ -42,3 +44,23 @@ form globally or on role by role basis:
Some of what this module does can also be achieved by theming the form.
Removing nodes from the search index
------------------------------------
A feature offered by this module is to stop the indexing of specific node types.
There is no easy way to do this is Drupal. Items can be removed from the search
index though and this was the original method that was used. This worked by
deleting values of the selected type from the search index using the
search_wipe function in hook_update_index. This proved problematic, especially
in cases where search_config was installed on a site with a lot of content. No
throttling was enabled in the hook and this caused cron to crash. It also
posed the problem of search_config playing catch-up in removing the items from
the index since there was no way to prevent them from getting there in the
first place. I gave up on this approach.
Items are no longer removed from the index but instead hook_db_rewrite_sql is
used to prevent select content types from showing up in search results. This
is a ugly and hack but it provides the desired result. If you want to help solve
this issue of preventing indexing of content plese see this issue:
http://drupal.org/node/111744
; $Id$
name = Search config
description = Configure display of the advanced search form
dependencies = search
dependencies[] = search
core = 6.x
......@@ -7,7 +7,7 @@
*
* @author Nesta Campbell <nesta.campbell@gmail.com>
* @todo Look at multiple hierarchy taxonomies
*
*
*/
/**
......@@ -22,64 +22,73 @@ function search_config_perm() {
/**
* Implementation of hook_form_alter()
*/
function search_config_form_alter($form_id, &$form) {
// Present the user with the appropriate search results tab as defined by
function search_config_form_alter(&$form, &$form_state, $form_id) {
// Add validation function to search administration form
if ($form_id == 'search_admin_settings') {
$form['#validate'][] = 'search_config_validate';
}
// Present the user with the appropriate search results tab as defined by
// variable "search_config_default_search" (labeled "Default Search")
// in the "Advanced search settings" fieldset in admin/settings/search
if ($form_id == 'search_theme_form') {
$form['#submit'] = array();
$form['#submit']['search_form_submit'] = array();
$form['#submit'] = array('search_config_form_submit');
$form['module']['#value'] = variable_get('search_config_default_search', 'node');
$form['module']['#type'] = 'hidden';
$form['processed_keys'] = $form['search_theme_form_keys'];
$form['processed_keys']['#weight'] = -1;
$form['module']['#type'] = 'value';
$form['processed_keys'] = $form['search_theme_form_keys'];
$form['processed_keys']['#weight'] = -1;
unset($form['search_theme_form_keys']);
}
if ($form_id == 'search_form') {
if (arg(1) == 'node') {
// Keywords
if (user_access('use keyword search')) {
if (variable_get('search_config_disable_or', 0)) {
unset($form['advanced']['keywords']['or']);
}
if (variable_get('search_config_disable_phrase', 0)) {
unset($form['advanced']['keywords']['phrase']);
}
if (variable_get('search_config_disable_negative', 0)) {
unset($form['advanced']['keywords']['negative']);
}
$default_search = variable_get('search_config_default_search', 'node');
// Keywords
if (user_access('use keyword search')) {
if (variable_get('search_config_disable_or', 0)) {
unset($form['advanced']['keywords']['or']);
}
// Remove all the keyword search fields
else {
unset($form['advanced']['keywords']);
if (variable_get('search_config_disable_phrase', 0)) {
unset($form['advanced']['keywords']['phrase']);
}
if (variable_get('search_config_disable_negative', 0)) {
unset($form['advanced']['keywords']['negative']);
}
}
// Remove all the keyword search fields
else {
unset($form['advanced']['keywords']);
}
// Node types
// We will need to rebuild the checkboxes for the node types
$remove = variable_get('search_config_disable_type', array());
// Node types
// We will need to rebuild the checkboxes for the node types
$remove = variable_get('search_config_disable_type', array());
if ($remove['all'] || !user_access('search by node type')) {
unset($form['advanced']['type']);
}
else {
$types = node_get_types('names');
foreach ($types as $module => $type) {
if ($remove[$module]) {
unset($types[$module]);
}
if ($remove['all'] || !user_access('search by node type')) {
unset($form['advanced']['type']);
}
else {
$types = node_get_types('names');
foreach ($types as $module => $type) {
if ($remove[$module]) {
unset($types[$module]);
}
// Rebuild form item -- copied from node.module
else {
$types[$module] = t($type);
}
}
// Rebuild form item -- copied from node.module, but only if advanced
// fieldset exists.
if (!empty($form['advanced'])) {
if (count($types) == 1) {
$type_keys = array_keys($types);
$form['advanced']['type'] = array(
'#type' => 'hidden',
'#default_value' => $type_keys[0],
);
}
}
else {
$form['advanced']['type'] = array(
'#type' => 'checkboxes',
......@@ -90,66 +99,78 @@ function search_config_form_alter($form_id, &$form) {
);
}
}
}
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
// Taxonomy
if (variable_get('search_config_disable_category_all', 0) || !user_access('search by category')) {
unset($form['advanced']['category']);
}
else {
$terms = variable_get('search_config_disable_category', array());
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
// Taxonomy
if (variable_get('search_config_disable_category_all', 0) || !user_access('search by category')) {
unset($form['advanced']['category']);
}
else {
$terms = variable_get('search_config_disable_category', array());
if (module_exists('og_vocab')) {
$groupnode = og_get_group_context();
$sql = "SELECT t.tid FROM {vocabulary} v, {term_data} t LEFT JOIN {og_vocab} ov ON v.vid = ov.vid WHERE (v.module = 'og_vocab' AND ov.nid != %d) AND t.vid=v.vid";
$result = db_query($sql, $groupnode->nid);
if (module_exists('og_vocab')) {
$groupnode = og_get_group_context();
$sql = "SELECT t.tid FROM ({vocabulary} v, {term_data} t) LEFT JOIN {og_vocab} ov ON v.vid = ov.vid WHERE (v.module = 'og_vocab' AND ov.nid != %d) AND t.vid=v.vid";
$result = db_query($sql, $groupnode->nid);
while ($row = db_fetch_object($result)) {
$terms[$row->tid] = $row->tid;
}
while ($row = db_fetch_object($result)) {
$terms[$row->tid] = $row->tid;
}
}
// FIXME: What about multiple hierarchy categories?
foreach ($taxonomy as $vocab => $term) {
foreach ($term as $k => $v) {
if(in_array($k, $terms)) {
unset($taxonomy[$vocab][$k]);
}
}
// Remove empty vocabs
if (count($taxonomy[$vocab]) == 0) {
unset($taxonomy[$vocab]);
// FIXME: What about multiple hierarchy categories?
foreach ($taxonomy as $vocab => $term) {
foreach ($term as $k => $v) {
if(in_array($k, $terms)) {
unset($taxonomy[$vocab][$k]);
}
}
if (count($taxonomy) == 0) {
unset($form['advanced']['category']);
}
else {
// Taxonomy box:
$form['advanced']['category'] = array(
'#type' => 'select',
'#title' => t('Only in the category(s)'),
'#prefix' => '<div class="criterion">',
'#size' => 10,
'#suffix' => '</div>',
'#options' => $taxonomy,
'#multiple' => TRUE,
);
// Remove empty vocabs
if (count($taxonomy[$vocab]) == 0) {
unset($taxonomy[$vocab]);
}
}
if (count($taxonomy) == 0) {
unset($form['advanced']['category']);
}
else {
// Taxonomy box:
$form['advanced']['category'] = array(
'#type' => 'select',
'#title' => t('Only in the category(s)'),
'#prefix' => '<div class="criterion">',
'#size' => 10,
'#suffix' => '</div>',
'#options' => $taxonomy,
'#multiple' => TRUE,
);
}
}
}
}
}
/**
* Process a block search form submission.
*
* Taken from the core search module. It allows the search block to work
* with other default search types than node.
*/
function search_config_form_submit($form, &$form_state) {
$form_id = $form['form_id']['#value'];
$type = $form['module']['#value'];
$form_state['redirect'] = 'search/'. $type .'/'. trim($form_state['values'][$form_id]);
}
/**
* Implementation of hook_search()
*/
function search_config_search($op) {
switch ($op) {
case 'admin':
$form['search_config'] = array(
$form['search_config'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced search configuration'),
'#collapsible' => TRUE,
......@@ -158,10 +179,10 @@ function search_config_search($op) {
// Search results default tab
$description = t('Which tab on the search results will be presented by default. The standard Drupal installation defaults to node_search ("Content" tab). This option allows you to default to the "User" tab or any other tab from contributed search modules, e.g. Apachesolr which implements a tab called "Search" to display its results');
$searches = drupal_map_assoc(module_implements('search', false, false));
unset ($searches['search_config']);
$form['search_config']['search_config_default_search'] = array(
'#type' => 'radios',
'#title' => t('Default Search'),
......@@ -170,7 +191,7 @@ function search_config_search($op) {
'#default_value' => variable_get('search_config_default_search', 'node'),
'#description' => t($description)
);
// Keyword boxes:
$form['search_config']['keywords'] = array(
'#type' => 'fieldset',
......@@ -179,25 +200,25 @@ function search_config_search($op) {
'#collapsed' => TRUE ,
'#description' => t('Configuration for which keyword search fields should not be displayed.')
);
$form['search_config']['keywords']['search_config_disable_or'] = array(
$form['search_config']['keywords']['search_config_disable_or'] = array(
'#type' => 'checkbox',
'#title' => t('Containing any of the words'),
'#default_value' => variable_get('search_config_disable_or', 0)
);
$form['search_config']['keywords']['search_config_disable_phrase'] = array(
'#type' => 'checkbox',
'#title' => t('Containing the phrase'),
'#default_value' => variable_get('search_config_disable_phrase', 0)
);
$form['search_config']['keywords']['search_config_disable_negative'] = array(
'#type' => 'checkbox',
'#title' => t('Containing none of the words'),
'#default_value' => variable_get('search_config_disable_negative', 0)
);
// Taxonomy box
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$form['search_config']['category'] = array(
......@@ -225,7 +246,7 @@ function search_config_search($op) {
);
}
// Node types
// Node types
$types = node_get_types('names');
$types = array_merge(array('all' => 'Disable all'), $types);
......@@ -234,9 +255,8 @@ function search_config_search($op) {
'#title' => t('Node types'),
'#collapsible' => TRUE,
'#collapsed' => TRUE ,
'#validate' => array('search_config_validate' => array())
);
$form['search_config']['type']['form'] = array(
'#type' => 'fieldset',
'#title' => t('Search Form'),
......@@ -244,12 +264,12 @@ function search_config_search($op) {
'#description' => t('Node types that users shouldn\'t be allowed to search by using the the advanced search form.')
);
$form['search_config']['type']['search_config_disable_type'] = array(
$form['search_config']['type']['form']['search_config_disable_type'] = array(
'#type' => 'checkboxes',
'#options' => $types,
'#default_value' => variable_get('search_config_disable_type', array())
);
$form['search_config']['type']['index'] = array(
'#type' => 'fieldset',
'#title' => t('Search Index'),
......@@ -271,60 +291,59 @@ function search_config_search($op) {
}
}
function search_config_validate($form_values) {
if ($form_values['#post']['form_id'] == 'search_admin_settings' && $form_values['#post']['op'] == 'Save configuration') {
$post_values = $form_values['#post'];
function search_config_validate($form, &$form_state) {
if ($form_state['values']['form_id'] == 'search_admin_settings' && $form_state['values']['op'] == t('Save configuration')) {
$post_values = $form_state['values'];
$node_types = node_get_types('names');
if (!isset($post_values['search_config_disable_index_type'])) {
return;
}
$index_types = $post_values['search_config_disable_index_type'];
$index_types = array_filter($post_values['search_config_disable_index_type']);
if (!isset($post_values['search_config_disable_type'])) {
$post_values['search_config_disable_type'] = array();
}
$form_types = $post_values['search_config_disable_type'];
$form_types = array_filter($post_values['search_config_disable_type']);
if (count($index_types) != 0 && count($index_types) == count($node_types)) {
form_set_error('search_config_disable_index_type', t('You can not set all node types to be not indexed by the search module. Disable the search module if that is what you want.'));
}
if (isset($post_values['search_config_disable_type']['all'])) {
if ($form_types['all']) {
return;
}
$type_diff = array_diff($index_types, $form_types);
if (count($type_diff)) {
$node_errors = array();
foreach ($type_diff as $type) {
$node_errors[] = $node_types[$type];
}
form_set_error('search_config_disable_type', t('Search index node types do not match form node types. Please check the setting for %nodes.', array('%nodes' => implode(', ', $node_errors))));
}
}
}
/**
* Implementation of hook_update_index()
* Rewrite the search query to exclude selected node types.
*
* I feel dirty; This is such a hack.
* @see http://www.lullabot.com/articles/hiding-content-drupals-search-system
* @see http://drupal.org/node/111744 if you want to help get something
* sensible into core.
*/
function search_config_update_index() {
// This hook is only called when the search module is enabled
// The function_exists check can be removed, but there is no harm in leaving it in
if (function_exists('search_wipe')) {
$types = node_get_types('names');
$remove = variable_get('search_config_disable_index_type', array());
foreach ($remove as $type => $value) {
if (isset($types[$type]) && $value === $type) {
$result = db_query("SELECT n.nid FROM {node} n INNER JOIN {search_dataset} s ON n.nid=s.sid WHERE n.type = '%s'", $type);
while ($data = db_fetch_object($result)) {
search_wipe($data->nid, 'node');
}
}
function search_config_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
$excluded_types = array_filter(variable_get('search_config_disable_index_type', array()));
if (!empty($excluded_types)) {
$where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
return array('where' => $where);
}
}
}
# $Id$
#
# LANGUAGE translation of search_config module
msgid ""
msgstr ""
"Project-Id-Version: search_config (6.x-1.5)\n"
"POT-Creation-Date: 2009-11-06 01:46+0100\n"
"PO-Revision-Date: 2009-11-12 11:51+0100\n"
"Last-Translator: Simon Georges <simon.georges@alumni.enseeiht.fr>\n"
"Language-Team: Capgemini Drupal Factory <drupal-factory@capgemini.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: search_config.module:85
msgid "Only of the type(s)"
msgstr "Du ou des types"
#: search_config.module:131
msgid "Only in the category(s)"
msgstr "Dans la ou les catégories"
#: search_config.module:164
msgid "Advanced search configuration"
msgstr "Configuration de la recherche avancée"
#: search_config.module:170
msgid "Which tab on the search results will be presented by default. The standard Drupal installation defaults to node_search (\"Content\" tab). This option allows you to default to the \"User\" tab or any other tab from contributed search modules, e.g. Apachesolr which implements a tab called \"Search\" to display its results"
msgstr "Quel onglet des résultats de la recherche sera affiché par défaut. L'installation Drupal standard met par défaut à node_search (onglet \"Contenu\"). Cette option vous permet de choisir par défaut l'onglet \"Utilisateur\" ou n'importe quel onglet d'un module de recherche, par exemple Apachesolr qui implémente un onlet \"Search\" pour afficher ses résultats"
#: search_config.module:177
msgid "Default Search"
msgstr "Recherche par défaut"
#: search_config.module:187
msgid "Keywords"
msgstr "Mots-clés"
#: search_config.module:190
msgid "Configuration for which keyword search fields should not be displayed."
msgstr "Configuration pour laquelle les champs de recherche par mot-clé ne doivent pas être affichés."
#: search_config.module:195
msgid "Containing any of the words"
msgstr "Contenant l'un des mots"
#: search_config.module:201
msgid "Containing the phrase"
msgstr "Contenant l'expression entière"
#: search_config.module:207
msgid "Containing none of the words"
msgstr "Ne contenant pas les mots"
#: search_config.module:215;229
msgid "Categories"
msgstr "Catégories"
#: search_config.module:218
msgid "Categories to display"
msgstr "Catégories à afficher"
#: search_config.module:223
msgid "Disable category search"
msgstr "Désactiver la recherche de catégories"
#: search_config.module:234
msgid "Disable searching by the selected categories"
msgstr "Désactiver la recherche par les catégories sélectionnées"
#: search_config.module:244
msgid "Node types"
msgstr "Type de noeuds"
#: search_config.module:251
msgid "Search Form"
msgstr "Formulaire de recherche"
#: search_config.module:253
msgid "Node types that users shouldn't be allowed to search by using the the advanced search form."
msgstr "Types de noeud que les utilisateurs ne doivent pas être autorisés à chercher en utilisant la recherche avancée."
#: search_config.module:264
msgid "Search Index"
msgstr "Index de recherche"
#: search_config.module:266
msgid "Node types that should not be index by the search module. Any node type set to not be indexed will also be removed from the search form. If you select all available node types to not be index then the search module will be rendered unusable as no nodes will be indexed."
msgstr "Types de noeud qui ne doivent pas être indexés par le module search. Les types de noeud à ne pas indexer seront aussi retirés du formulaire de recherche. Si vous sélectionnez tous les types de noeud à ne pas indexer, alors le module search sera inutilisable car aucun noeud ne sera indexé."
#: search_config.module:302
msgid "You can not set all node types to be not indexed by the search module. Disable the search module if that is what you want."
msgstr "Vous devez choisir au moins un type de noeud à indexer par le module search. Sinon désactivez le module search."
#: search_config.module:318
msgid "Search index node types do not match form node types. Please check the setting for %nodes."
msgstr "La recherche de types de noeud à indexer ne trouve pas de types de noeud. Veuillez vérifier le paramètrage pour %nodes."
#: search_config.module:19
msgid "search by node type"
msgstr "recherche par type de noeud"
#: search_config.module:19
msgid "search by category"
msgstr "recherche par catégorie"
#: search_config.module:19
msgid "use keyword search"
msgstr "utiliser la recherche par mot-clé"
#: search_config.info:0
msgid "Search config"
msgstr "Configuration de la recherche"
#: search_config.info:0
msgid "Configure display of the advanced search form"
msgstr "Configurer l'affichage du formulaire de recherche avancée"
# Hungarian translation of Search config (6.x-1.5)
# Copyright (c) 2010 by the Hungarian translation team
#
msgid ""
msgstr ""
"Project-Id-Version: Search config (6.x-1.5)\n"
"POT-Creation-Date: 2010-01-22 16:53+0000\n"
"PO-Revision-Date: 2010-01-15 12:29+0000\n"
"Language-Team: Hungarian\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
msgid "Categories"
msgstr "Kategóriák"
msgid "Keywords"
msgstr "Kulcsszavak"
msgid "Node types"
msgstr "Tartalomtípusok"
msgid "Search Index"
msgstr "Keresés index"
msgid "Containing any of the words"
msgstr "Tartalmazza ezen szavak bármelyikét"
msgid "Containing the phrase"
msgstr "Tartalmazza pontosan ezt a kifejezést"
msgid "Containing none of the words"
msgstr "Ne tartalmazza ezeket a szavakat"
msgid "Only in the category(s)"
msgstr "Csak az ilyen kategóriában"
msgid "Only of the type(s)"
msgstr "Csak az ilyen tartalmakban"
msgid "Advanced search configuration"
msgstr "Haladó keresés beállításai"
msgid ""
"Which tab on the search results will be presented by default. The "
"standard Drupal installation defaults to node_search (\"Content\" "
"tab). This option allows you to default to the \"User\" tab or any "
"other tab from contributed search modules, e.g. Apachesolr which "
"implements a tab called \"Search\" to display its results"
msgstr ""
"Az alapértelmezés szerinti menüfül, melyen a keresési találatok "
"megjelennek. A szokásos Drupal telepítési alapbeállítás a "
"tartalom („Tartalom” menüfül). Ezzel a beállítással az "
"alapértelmezés szerinri értékeket lehet átállítani a "
"„Felhasználó”, vagy bármely olyan menüfülre, amelyet egy "
"másik, a közösség által fejlesztett modul, például az "
"<em>Apachesolr</em> biztosít."
msgid "Default Search"
msgstr "Alapértelmezés szerinti keresés"
msgid "Configuration for which keyword search fields should not be displayed."
msgstr "Kulcsszó keresés mezők elrejtésének beállításai"
msgid "Categories to display"
msgstr "Megjelenítendő kategóriák"
msgid "Disable category search"
msgstr "A kategória keresés kikapcsolása"