diff options
author | Dries Buytaert <dries@buytaert.net> | 2004-12-31 09:30:12 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2004-12-31 09:30:12 +0000 |
commit | 1dbe0dc2ee80fc8d67e42785b12203513dc11820 (patch) | |
tree | ff4db2592bb43981e685a92dbf075a7095d63793 | |
parent | 828be2ad6198538def4eb3da0ce03a34961a38e9 (diff) | |
download | brdo-1dbe0dc2ee80fc8d67e42785b12203513dc11820.tar.gz brdo-1dbe0dc2ee80fc8d67e42785b12203513dc11820.tar.bz2 |
- Patch #14917 by UnConeD/Steven:
1) The different types of search, which used to be radio button options in the search form, are now subtabs of "search" (default "search/node"). This seems better from a UI point of view, but also has another advantage: modules which implement a custom search form (flexinode, project) can add it as a subtab of search. This means that all search forms will be located in the same place, and also without needing an extra api call to search.module.
2) The current code was a bit hackish, as the indexing of comments along with nodes was hardcoded in node.module. Instead, I created a nodeapi operation "update index" which allows modules to add more data for a node that is being indexed. Comments are now indexed using this mechanism and from comment.module, which is a lot cleaner.
3) The search results format was also hardcoded to include "N comments". I replaced this with a nodeapi operation "search result" and moved the comment code to comment.module where it belongs. This op is quite useful, as for example I also modified upload.module to add "N attachments" to a search result if any are present.
-rw-r--r-- | modules/comment.module | 10 | ||||
-rw-r--r-- | modules/comment/comment.module | 10 | ||||
-rw-r--r-- | modules/node.module | 14 | ||||
-rw-r--r-- | modules/node/node.module | 14 | ||||
-rw-r--r-- | modules/search.module | 46 | ||||
-rw-r--r-- | modules/search/search.module | 46 | ||||
-rw-r--r-- | modules/upload.module | 2 | ||||
-rw-r--r-- | modules/upload/upload.module | 2 |
8 files changed, 78 insertions, 66 deletions
diff --git a/modules/comment.module b/modules/comment.module index f0f164a3f..6a3b8cee5 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -261,6 +261,16 @@ function comment_nodeapi(&$node, $op, $arg = 0) { db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); break; + case 'update index': + $text = ''; + $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = 0', $node->nid); + while ($comment = db_fetch_object($comments)) { + $text .= '<h2>'. $comment->subject .'</h2>'. check_output($comment->comment, $comment->format); + } + return $text; + case 'search result': + $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid)); + return format_plural($comments, '1 comment', '%count comments'); } } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index f0f164a3f..6a3b8cee5 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -261,6 +261,16 @@ function comment_nodeapi(&$node, $op, $arg = 0) { db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid); db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); break; + case 'update index': + $text = ''; + $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = 0', $node->nid); + while ($comment = db_fetch_object($comments)) { + $text .= '<h2>'. $comment->subject .'</h2>'. check_output($comment->comment, $comment->format); + } + return $text; + case 'search result': + $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid)); + return format_plural($comments, '1 comment', '%count comments'); } } diff --git a/modules/node.module b/modules/node.module index 224c4c9a1..21655e1ef 100644 --- a/modules/node.module +++ b/modules/node.module @@ -582,13 +582,13 @@ function node_search($op = 'search', $keys = null) { $results = array(); foreach ($find as $item) { $node = node_load(array('nid' => $item)); - $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $item)); + $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), 'type' => node_invoke($node, 'node_name'), 'title' => $node->title, 'user' => format_name($node), 'date' => $node->changed, - 'extra' => format_plural($comments, '1 comment', '%count comments'), + 'extra' => $extra, 'snippet' => search_excerpt($keys, check_output($node->body, $node->format))); } return $results; @@ -1588,12 +1588,10 @@ function node_update_index() { $text = '<h1>'. drupal_specialchars($node->title) .'</h1>'. $node->body; - // Fetch comments - if (module_exist('comment')) { - $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = 0', $node->nid); - while ($comment = db_fetch_object($comments)) { - $text .= '<h2>'. $comment->subject .'</h2>'. check_output($comment->comment, $comment->format); - } + // Fetch extra data normally not visible + $extra = node_invoke_nodeapi($node, 'update index'); + foreach ($extra as $t) { + $text .= $t; } // Update index diff --git a/modules/node/node.module b/modules/node/node.module index 224c4c9a1..21655e1ef 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -582,13 +582,13 @@ function node_search($op = 'search', $keys = null) { $results = array(); foreach ($find as $item) { $node = node_load(array('nid' => $item)); - $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $item)); + $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), 'type' => node_invoke($node, 'node_name'), 'title' => $node->title, 'user' => format_name($node), 'date' => $node->changed, - 'extra' => format_plural($comments, '1 comment', '%count comments'), + 'extra' => $extra, 'snippet' => search_excerpt($keys, check_output($node->body, $node->format))); } return $results; @@ -1588,12 +1588,10 @@ function node_update_index() { $text = '<h1>'. drupal_specialchars($node->title) .'</h1>'. $node->body; - // Fetch comments - if (module_exist('comment')) { - $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = 0', $node->nid); - while ($comment = db_fetch_object($comments)) { - $text .= '<h2>'. $comment->subject .'</h2>'. check_output($comment->comment, $comment->format); - } + // Fetch extra data normally not visible + $extra = node_invoke_nodeapi($node, 'update index'); + foreach ($extra as $t) { + $text .= $t; } // Update index diff --git a/modules/search.module b/modules/search.module index fe70f94ba..9c812402b 100644 --- a/modules/search.module +++ b/modules/search.module @@ -74,12 +74,20 @@ function search_menu($may_cache) { $items = array(); if ($may_cache) { - $items[] = array('path' => 'search', 'title' => t('search'), + $items[] = array('path' => 'search', 'title' => t('search for'), 'callback' => 'search_view', 'access' => user_access('search content'), 'type' => MENU_SUGGESTED_ITEM); - $items[] = array('path' => 'search/search', 'title' => t('search'), - 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); + + foreach (module_list() as $name) { + if (module_hook($name, 'search')) { + $items[] = array('path' => 'search/'. $name, 'title' => module_invoke($name, 'search', 'name'), + 'callback' => 'search_view', + 'access' => user_access('search content'), + 'type' => $name == 'node' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK); + } + } + $items[] = array('path' => 'admin/settings/search', 'title' => t('search'), 'callback' => 'search_admin', 'type' => MENU_NORMAL_ITEM, @@ -465,7 +473,7 @@ function do_search($keys, $type, $join = '', $where = '1') { */ function search_view() { $keys = isset($_GET['keys']) ? $_GET['keys'] : $_POST['edit']['keys']; - $type = isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node'); + $type = arg(1) ? arg(1) : (isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node')); if (user_access('search content')) { // Only perform search if there is non-whitespace search term: @@ -538,6 +546,9 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { if (!$action) { $action = url('search'); } + if (!$type) { + $type = 'node'; + } $output = ' <div class="search-form">'; $box = '<div class="container-inline">'; @@ -545,24 +556,7 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { $box .= form_submit(t('Search'));; $box .= '</div>'; $output .= form_item(t('Enter your keywords'), $box); - - if ($options) { - $output .= '<div class="container-inline">'. t('Search for') .': '; - - if (!isset($edit['type'])) { - $edit['type'] = $type; - } - - foreach (module_list() as $name) { - if (module_hook($name, 'search')) { - $output .= form_radio(module_invoke($name, 'search', 'name'), 'type', $name, $edit['type'] == $name); - } - } - $output .= '</div>'; - } - else if ($type) { - $output .= form_hidden('type', $type); - } + $output .= form_hidden('type', $type); $output .= '</div>'; return form($output, 'post', $action); @@ -712,7 +706,9 @@ function _search_excerpt_replace($text) { * * @param $item * A single search result as returned by hook_search(). The result should be - * an array with keys "count", "link", "title", "user", "date", and "keywords". + * an array with keys "link", "title", "type", "user", "date", and "snippet". + * Optionally, "extra" can be an array of extra info to show along with the + * result. * @param $type * The type of item found, such as "user" or "comment". */ @@ -732,8 +728,8 @@ function theme_search_item($item, $type) { if ($item['date']) { $info[] = format_date($item['date'], 'small'); } - if (isset($item['extra'])) { - $info[] = $item['extra']; + if (is_array($item['extra'])) { + $info = array_merge($info, $item['extra']); } $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] . '</p>' : '') . '<p class="search-info">' . implode(' - ', $info) .'</p></dd>'; } diff --git a/modules/search/search.module b/modules/search/search.module index fe70f94ba..9c812402b 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -74,12 +74,20 @@ function search_menu($may_cache) { $items = array(); if ($may_cache) { - $items[] = array('path' => 'search', 'title' => t('search'), + $items[] = array('path' => 'search', 'title' => t('search for'), 'callback' => 'search_view', 'access' => user_access('search content'), 'type' => MENU_SUGGESTED_ITEM); - $items[] = array('path' => 'search/search', 'title' => t('search'), - 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); + + foreach (module_list() as $name) { + if (module_hook($name, 'search')) { + $items[] = array('path' => 'search/'. $name, 'title' => module_invoke($name, 'search', 'name'), + 'callback' => 'search_view', + 'access' => user_access('search content'), + 'type' => $name == 'node' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK); + } + } + $items[] = array('path' => 'admin/settings/search', 'title' => t('search'), 'callback' => 'search_admin', 'type' => MENU_NORMAL_ITEM, @@ -465,7 +473,7 @@ function do_search($keys, $type, $join = '', $where = '1') { */ function search_view() { $keys = isset($_GET['keys']) ? $_GET['keys'] : $_POST['edit']['keys']; - $type = isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node'); + $type = arg(1) ? arg(1) : (isset($_GET['type']) ? $_GET['type'] : ($_POST['edit']['type'] ? $_POST['edit']['type'] : 'node')); if (user_access('search content')) { // Only perform search if there is non-whitespace search term: @@ -538,6 +546,9 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { if (!$action) { $action = url('search'); } + if (!$type) { + $type = 'node'; + } $output = ' <div class="search-form">'; $box = '<div class="container-inline">'; @@ -545,24 +556,7 @@ function search_form($action = '', $keys = '', $type = null, $options = FALSE) { $box .= form_submit(t('Search'));; $box .= '</div>'; $output .= form_item(t('Enter your keywords'), $box); - - if ($options) { - $output .= '<div class="container-inline">'. t('Search for') .': '; - - if (!isset($edit['type'])) { - $edit['type'] = $type; - } - - foreach (module_list() as $name) { - if (module_hook($name, 'search')) { - $output .= form_radio(module_invoke($name, 'search', 'name'), 'type', $name, $edit['type'] == $name); - } - } - $output .= '</div>'; - } - else if ($type) { - $output .= form_hidden('type', $type); - } + $output .= form_hidden('type', $type); $output .= '</div>'; return form($output, 'post', $action); @@ -712,7 +706,9 @@ function _search_excerpt_replace($text) { * * @param $item * A single search result as returned by hook_search(). The result should be - * an array with keys "count", "link", "title", "user", "date", and "keywords". + * an array with keys "link", "title", "type", "user", "date", and "snippet". + * Optionally, "extra" can be an array of extra info to show along with the + * result. * @param $type * The type of item found, such as "user" or "comment". */ @@ -732,8 +728,8 @@ function theme_search_item($item, $type) { if ($item['date']) { $info[] = format_date($item['date'], 'small'); } - if (isset($item['extra'])) { - $info[] = $item['extra']; + if (is_array($item['extra'])) { + $info = array_merge($info, $item['extra']); } $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] . '</p>' : '') . '<p class="search-info">' . implode(' - ', $info) .'</p></dd>'; } diff --git a/modules/upload.module b/modules/upload.module index c770719cd..06ccde3fc 100644 --- a/modules/upload.module +++ b/modules/upload.module @@ -257,6 +257,8 @@ function upload_nodeapi(&$node, $op, $arg) { case 'delete': upload_delete($node); break; + case 'search result': + return $node->files ? format_plural(count($node->files), '1 attachment', '%count attachments') : null; } return $output; diff --git a/modules/upload/upload.module b/modules/upload/upload.module index c770719cd..06ccde3fc 100644 --- a/modules/upload/upload.module +++ b/modules/upload/upload.module @@ -257,6 +257,8 @@ function upload_nodeapi(&$node, $op, $arg) { case 'delete': upload_delete($node); break; + case 'search result': + return $node->files ? format_plural(count($node->files), '1 attachment', '%count attachments') : null; } return $output; |