Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.237
diff -u -u -p -r1.237 locale.module
--- modules/locale/locale.module 5 Feb 2009 00:32:46 -0000 1.237
+++ modules/locale/locale.module 7 Feb 2009 14:40:51 -0000
@@ -613,3 +613,34 @@ function theme_locale_translation_filter
$output .= '
' . drupal_render($form['buttons']) . '
';
return $output;
}
+
+/**
+ * Implementation of hook_searchform.
+ */
+function locale_searchform() {
+ // Languages:
+ $language_options = array();
+ foreach (language_list('language') as $key => $object) {
+ $language_options[$key] = $object->name;
+ }
+ if (count($language_options) > 1) {
+ $form['language'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Languages'),
+ '#prefix' => '',
+ '#suffix' => '
',
+ '#options' => $language_options,
+ '#weight' => 5,
+ );
+ return $form;
+ }
+}
+
+/**
+ * Implementation of hook_searchkeys.
+ */
+function locale_searchkeys() {
+ return array(
+ 'language' => array('where' => "n.language = '%s'"),
+ );
+}
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.1023
diff -u -u -p -r1.1023 node.module
--- modules/node/node.module 6 Feb 2009 16:25:08 -0000 1.1023
+++ modules/node/node.module 7 Feb 2009 14:40:52 -0000
@@ -1437,35 +1437,20 @@ function node_search($op = 'search', $ke
$arguments1 = array();
$conditions1 = 'n.status = 1';
- if ($type = search_query_extract($keys, 'type')) {
- $types = array();
- foreach (explode(',', $type) as $t) {
- $types[] = "n.type = '%s'";
- $arguments1[] = $t;
+ // Extract the keywords from the query and add sql to the clauses.
+ foreach (module_invoke_all('searchkeys') as $term => $options) {
+ if ($type = search_query_extract($keys, $term)) {
+ $types = array();
+ foreach (explode(',', $type) as $t) {
+ $types[] = $options['where'];
+ $arguments1[] = $t;
+ }
+ $conditions1 .= ' AND (' . implode(' OR ', $types) . ')';
+ if (isset($options['join'])) {
+ $joins .= ' ' . $options['join'];
+ }
+ $keys = search_query_insert($keys, $term);
}
- $conditions1 .= ' AND (' . implode(' OR ', $types) . ')';
- $keys = search_query_insert($keys, 'type');
- }
-
- if ($term = search_query_extract($keys, 'term')) {
- $terms = array();
- foreach (explode(',', $term) as $c) {
- $terms[] = "tn.tid = %d";
- $arguments1[] = $c;
- }
- $conditions1 .= ' AND (' . implode(' OR ', $terms) . ')';
- $join1 .= ' INNER JOIN {taxonomy_term_node} tn ON n.vid = tn.vid';
- $keys = search_query_insert($keys, 'term');
- }
-
- if ($languages = search_query_extract($keys, 'language')) {
- $terms = array();
- foreach (explode(',', $languages) as $l) {
- $terms[] = "n.language = '%s'";
- $arguments1[] = $l;
- }
- $conditions1 .= ' AND (' . implode(' OR ', $terms) . ')';
- $keys = search_query_insert($keys, 'language');
}
// Get the ranking expressions.
@@ -2144,50 +2129,8 @@ function node_form_search_form_alter(&$f
'#maxlength' => 255,
);
- // Taxonomy box:
- if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
- $form['advanced']['term'] = array(
- '#type' => 'select',
- '#title' => t('Only in the term(s)'),
- '#prefix' => '',
- '#size' => 10,
- '#suffix' => '
',
- '#options' => $taxonomy,
- '#multiple' => TRUE,
- );
- }
-
- // Node types:
- $types = array_map('check_plain', node_get_types('names'));
- $form['advanced']['type'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Only of the type(s)'),
- '#prefix' => '',
- '#suffix' => '
',
- '#options' => $types,
- );
- $form['advanced']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Advanced search'),
- '#prefix' => '',
- '#suffix' => '
',
- );
-
- // Languages:
- $language_options = array();
- foreach (language_list('language') as $key => $object) {
- $language_options[$key] = $object->name;
- }
- if (count($language_options) > 1) {
- $form['advanced']['language'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Languages'),
- '#prefix' => '',
- '#suffix' => '
',
- '#options' => $language_options,
- );
- }
-
+ $form['advanced'] += module_invoke_all('searchform');
+
$form['#validate'][] = 'node_search_validate';
}
}
@@ -2200,20 +2143,15 @@ function node_search_validate($form, &$f
$keys = $form_state['values']['processed_keys'];
// Insert extra restrictions into the search keywords string.
- if (isset($form_state['values']['type']) && is_array($form_state['values']['type'])) {
- // Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
- $form_state['values']['type'] = array_filter($form_state['values']['type']);
- if (count($form_state['values']['type'])) {
- $keys = search_query_insert($keys, 'type', implode(',', array_keys($form_state['values']['type'])));
+ foreach (module_invoke_all('searchkeys') as $term => $options) {
+ if (isset($form_state['values'][$term]) && is_array($form_state['values'][$term])) {
+ // Retrieve selected types - Forms API sets the value of unselected checkboxes to 0.
+ $form_state['values'][$term] = array_filter($form_state['values'][$term]);
+ if (count($form_state['values'][$term])) {
+ $keys = search_query_insert($keys, $term, implode(',', array_keys($form_state['values'][$term])));
+ }
}
}
-
- if (isset($form_state['values']['term']) && is_array($form_state['values']['term'])) {
- $keys = search_query_insert($keys, 'term', implode(',', $form_state['values']['term']));
- }
- if (isset($form_state['values']['language']) && is_array($form_state['values']['language'])) {
- $keys = search_query_insert($keys, 'language', implode(',', array_filter($form_state['values']['language'])));
- }
if ($form_state['values']['or'] != '') {
if (preg_match_all('/ ("[^"]+"|[^" ]+)/i', ' ' . $form_state['values']['or'], $matches)) {
$keys .= ' ' . implode(' OR ', $matches[1]);
@@ -3157,3 +3095,28 @@ function node_elements() {
function theme_node_links($element) {
return theme('links', $element['#value'], array('class' => 'links inline'));
}
+
+/**
+ * Implementation of hook_searchform.
+ */
+function node_searchform() {
+ // Node types:
+ $types = array_map('check_plain', node_get_types('names'));
+ $form['type'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Only of the type(s)'),
+ '#prefix' => '',
+ '#suffix' => '
',
+ '#options' => $types,
+ );
+ return $form;
+}
+
+/**
+ * Implementation of hook_searchkeys.
+ */
+function node_searchkeys() {
+ return array(
+ 'type' => array('where' => "n.type = '%s'"),
+ );
+}
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.460
diff -u -u -p -r1.460 taxonomy.module
--- modules/taxonomy/taxonomy.module 6 Feb 2009 16:25:09 -0000 1.460
+++ modules/taxonomy/taxonomy.module 7 Feb 2009 14:40:52 -0000
@@ -1480,3 +1480,32 @@ function taxonomy_hook_info() {
),
);
}
+
+/**
+ * Implementation of hook_searchform.
+ */
+function taxonomy_searchform() {
+ // Taxonomy box:
+ if ($taxonomy = taxonomy_form_all(1)) {
+ $form['category'] = array(
+ '#type' => 'select',
+ '#title' => t('Only in the category(s)'),
+ '#prefix' => '',
+ '#size' => 10,
+ '#suffix' => '
',
+ '#options' => $taxonomy,
+ '#multiple' => TRUE,
+ );
+ return $form;
+ }
+}
+
+/**
+ * Implementation of hook_searchformkeys.
+ */
+function taxonomy_searchkeys() {
+ return array(
+ 'category' => array('where' => "tn.cid = '%s'", 'join' => 'INNER JOIN {term_node} tn ON n.vid = tn.vid'),
+ );
+}
+