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. ...@@ -4,15 +4,17 @@ search_config is used to configure the advanced search form.
Installation Installation
------------ ------------
1. Copy entire search_config directory to the module directory of your Drupal 1. Copy entire search_config directory to the module directory of your Drupal
installation installation
2. Enable the search_config module on the admin modules page 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. "Advanced search form configuration" collapsed fieldset.
General Information General Information
------------------- -------------------
This module started out as a simple means of configuring the *display* of the 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 advance search form. A few features have been added since thanks to the
contributions of others. contributions of others.
...@@ -42,3 +44,23 @@ form globally or on role by role basis: ...@@ -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. 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$ ; $Id$
name = Search config name = Search config
description = Configure display of the advanced search form description = Configure display of the advanced search form
dependencies = search dependencies[] = search
core = 6.x
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* @author Nesta Campbell <nesta.campbell@gmail.com> * @author Nesta Campbell <nesta.campbell@gmail.com>
* @todo Look at multiple hierarchy taxonomies * @todo Look at multiple hierarchy taxonomies
* *
*/ */
/** /**
...@@ -22,64 +22,73 @@ function search_config_perm() { ...@@ -22,64 +22,73 @@ function search_config_perm() {
/** /**
* Implementation of hook_form_alter() * Implementation of hook_form_alter()
*/ */
function search_config_form_alter($form_id, &$form) { function search_config_form_alter(&$form, &$form_state, $form_id) {
// Present the user with the appropriate search results tab as defined by // 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") // variable "search_config_default_search" (labeled "Default Search")
// in the "Advanced search settings" fieldset in admin/settings/search // in the "Advanced search settings" fieldset in admin/settings/search
if ($form_id == 'search_theme_form') { if ($form_id == 'search_theme_form') {
$form['#submit'] = array(); $form['#submit'] = array('search_config_form_submit');
$form['#submit']['search_form_submit'] = array();
$form['module']['#value'] = variable_get('search_config_default_search', 'node'); $form['module']['#value'] = variable_get('search_config_default_search', 'node');
$form['module']['#type'] = 'hidden'; $form['module']['#type'] = 'value';
$form['processed_keys'] = $form['search_theme_form_keys']; $form['processed_keys'] = $form['search_theme_form_keys'];
$form['processed_keys']['#weight'] = -1; $form['processed_keys']['#weight'] = -1;
unset($form['search_theme_form_keys']); unset($form['search_theme_form_keys']);
} }
if ($form_id == 'search_form') { if ($form_id == 'search_form') {
if (arg(1) == 'node') { $default_search = variable_get('search_config_default_search', 'node');
// Keywords // Keywords
if (user_access('use keyword search')) { if (user_access('use keyword search')) {
if (variable_get('search_config_disable_or', 0)) { if (variable_get('search_config_disable_or', 0)) {
unset($form['advanced']['keywords']['or']); 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']);
}
} }
// Remove all the keyword search fields if (variable_get('search_config_disable_phrase', 0)) {
else { unset($form['advanced']['keywords']['phrase']);
unset($form['advanced']['keywords']);
} }
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 // Node types
// We will need to rebuild the checkboxes for the node types // We will need to rebuild the checkboxes for the node types
$remove = variable_get('search_config_disable_type', array()); $remove = variable_get('search_config_disable_type', array());
if ($remove['all'] || !user_access('search by node type')) { if ($remove['all'] || !user_access('search by node type')) {
unset($form['advanced']['type']); unset($form['advanced']['type']);
} }
else { else {
$types = node_get_types('names'); $types = node_get_types('names');
foreach ($types as $module => $type) { foreach ($types as $module => $type) {
if ($remove[$module]) { if ($remove[$module]) {
unset($types[$module]); unset($types[$module]);
}
} }
else {
// Rebuild form item -- copied from node.module $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) { if (count($types) == 1) {
$type_keys = array_keys($types); $type_keys = array_keys($types);
$form['advanced']['type'] = array( $form['advanced']['type'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#default_value' => $type_keys[0], '#default_value' => $type_keys[0],
); );
} }
else { else {
$form['advanced']['type'] = array( $form['advanced']['type'] = array(
'#type' => 'checkboxes', '#type' => 'checkboxes',
...@@ -90,66 +99,78 @@ function search_config_form_alter($form_id, &$form) { ...@@ -90,66 +99,78 @@ function search_config_form_alter($form_id, &$form) {
); );
} }
} }
}
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
// Taxonomy // Taxonomy
if (variable_get('search_config_disable_category_all', 0) || !user_access('search by category')) { if (variable_get('search_config_disable_category_all', 0) || !user_access('search by category')) {
unset($form['advanced']['category']); unset($form['advanced']['category']);
} }
else { else {
$terms = variable_get('search_config_disable_category', array()); $terms = variable_get('search_config_disable_category', array());
if (module_exists('og_vocab')) { if (module_exists('og_vocab')) {
$groupnode = og_get_group_context(); $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"; $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); $result = db_query($sql, $groupnode->nid);
while ($row = db_fetch_object($result)) { while ($row = db_fetch_object($result)) {
$terms[$row->tid] = $row->tid; $terms[$row->tid] = $row->tid;
}
} }
}
// FIXME: What about multiple hierarchy categories? // FIXME: What about multiple hierarchy categories?
foreach ($taxonomy as $vocab => $term) { foreach ($taxonomy as $vocab => $term) {
foreach ($term as $k => $v) { foreach ($term as $k => $v) {
if(in_array($k, $terms)) { if(in_array($k, $terms)) {
unset($taxonomy[$vocab][$k]); unset($taxonomy[$vocab][$k]);
}
}
// Remove empty vocabs
if (count($taxonomy[$vocab]) == 0) {
unset($taxonomy[$vocab]);
} }
} }
// Remove empty vocabs
if (count($taxonomy) == 0) { if (count($taxonomy[$vocab]) == 0) {
unset($form['advanced']['category']); unset($taxonomy[$vocab]);
}
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,
);
} }
} }
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() * Implementation of hook_search()
*/ */
function search_config_search($op) { function search_config_search($op) {
switch ($op) { switch ($op) {
case 'admin': case 'admin':
$form['search_config'] = array( $form['search_config'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Advanced search configuration'), '#title' => t('Advanced search configuration'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
...@@ -158,10 +179,10 @@ function search_config_search($op) { ...@@ -158,10 +179,10 @@ function search_config_search($op) {
// Search results default tab // 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'); $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)); $searches = drupal_map_assoc(module_implements('search', false, false));
unset ($searches['search_config']); unset ($searches['search_config']);
$form['search_config']['search_config_default_search'] = array( $form['search_config']['search_config_default_search'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('Default Search'), '#title' => t('Default Search'),
...@@ -170,7 +191,7 @@ function search_config_search($op) { ...@@ -170,7 +191,7 @@ function search_config_search($op) {
'#default_value' => variable_get('search_config_default_search', 'node'), '#default_value' => variable_get('search_config_default_search', 'node'),
'#description' => t($description) '#description' => t($description)
); );
// Keyword boxes: // Keyword boxes:
$form['search_config']['keywords'] = array( $form['search_config']['keywords'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
...@@ -179,25 +200,25 @@ function search_config_search($op) { ...@@ -179,25 +200,25 @@ function search_config_search($op) {
'#collapsed' => TRUE , '#collapsed' => TRUE ,
'#description' => t('Configuration for which keyword search fields should not be displayed.') '#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', '#type' => 'checkbox',
'#title' => t('Containing any of the words'), '#title' => t('Containing any of the words'),
'#default_value' => variable_get('search_config_disable_or', 0) '#default_value' => variable_get('search_config_disable_or', 0)
); );
$form['search_config']['keywords']['search_config_disable_phrase'] = array( $form['search_config']['keywords']['search_config_disable_phrase'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Containing the phrase'), '#title' => t('Containing the phrase'),
'#default_value' => variable_get('search_config_disable_phrase', 0) '#default_value' => variable_get('search_config_disable_phrase', 0)
); );
$form['search_config']['keywords']['search_config_disable_negative'] = array( $form['search_config']['keywords']['search_config_disable_negative'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Containing none of the words'), '#title' => t('Containing none of the words'),
'#default_value' => variable_get('search_config_disable_negative', 0) '#default_value' => variable_get('search_config_disable_negative', 0)
); );
// Taxonomy box // Taxonomy box
if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
$form['search_config']['category'] = array( $form['search_config']['category'] = array(
...@@ -225,7 +246,7 @@ function search_config_search($op) { ...@@ -225,7 +246,7 @@ function search_config_search($op) {
); );
} }
// Node types // Node types
$types = node_get_types('names'); $types = node_get_types('names');
$types = array_merge(array('all' => 'Disable all'), $types); $types = array_merge(array('all' => 'Disable all'), $types);
...@@ -234,9 +255,8 @@ function search_config_search($op) { ...@@ -234,9 +255,8 @@ function search_config_search($op) {
'#title' => t('Node types'), '#title' => t('Node types'),
'#collapsible' => TRUE, '#collapsible' => TRUE,
'#collapsed' => TRUE , '#collapsed' => TRUE ,
'#validate' => array('search_config_validate' => array())
); );
$form['search_config']['type']['form'] = array( $form['search_config']['type']['form'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Search Form'), '#title' => t('Search Form'),
...@@ -244,12 +264,12 @@ function search_config_search($op) { ...@@ -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.') '#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', '#type' => 'checkboxes',
'#options' => $types, '#options' => $types,
'#default_value' => variable_get('search_config_disable_type', array()) '#default_value' => variable_get('search_config_disable_type', array())
); );
$form['search_config']['type']['index'] = array( $form['search_config']['type']['index'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Search Index'), '#title' => t('Search Index'),
...@@ -271,60 +291,59 @@ function search_config_search($op) { ...@@ -271,60 +291,59 @@ function search_config_search($op) {
} }
} }
function search_config_validate($form_values) { function search_config_validate($form, &$form_state) {
if ($form_values['#post']['form_id'] == 'search_admin_settings' && $form_values['#post']['op'] == 'Save configuration') { if ($form_state['values']['form_id'] == 'search_admin_settings' && $form_state['values']['op'] == t('Save configuration')) {
$post_values = $form_values['#post']; $post_values = $form_state['values'];
$node_types = node_get_types('names'); $node_types = node_get_types('names');
if (!isset($post_values['search_config_disable_index_type'])) { if (!isset($post_values['search_config_disable_index_type'])) {
return; 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'])) { if (!isset($post_values['search_config_disable_type'])) {
$post_values['search_config_disable_type'] = array(); $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)) { 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.')); 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; return;
} }
$type_diff = array_diff($index_types, $form_types); $type_diff = array_diff($index_types, $form_types);
if (count($type_diff)) { if (count($type_diff)) {
$node_errors = array(); $node_errors = array();
foreach ($type_diff as $type) { foreach ($type_diff as $type) {
$node_errors[] = $node_types[$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)))); 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() { function search_config_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
// This hook is only called when the search module is enabled if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
// The function_exists check can be removed, but there is no harm in leaving it in $excluded_types = array_filter(variable_get('search_config_disable_index_type', array()));
if (function_exists('search_wipe')) { if (!empty($excluded_types)) {
$types = node_get_types('names'); $where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
$remove = variable_get('search_config_disable_index_type', array()); return array('where' => $where);
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');
}
}
} }
} }
} }
# $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"