| 1 |
<?php
|
| 2 |
// $Id: faceted_search_ui.inc,v 1.3 2008/08/26 04:28:10 davidlesieur Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provides classes needed by the Faceted Search UI module, and that are
|
| 7 |
* sometimes extended by other modules.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Base class for display styles.
|
| 12 |
*/
|
| 13 |
class faceted_search_ui_style {
|
| 14 |
/**
|
| 15 |
* Return the number of nodes per page.
|
| 16 |
*/
|
| 17 |
function get_limit() {
|
| 18 |
return variable_get('default_nodes_main', 10);
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Provides the 'extracts' display style for search results.
|
| 24 |
*/
|
| 25 |
class faceted_search_ui_extract_style extends faceted_search_ui_style {
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Return the name of this style.
|
| 29 |
*/
|
| 30 |
function get_label() {
|
| 31 |
return t('Extracts');
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* Format the search results to display node extracts showing relevant
|
| 36 |
* keywords.
|
| 37 |
*/
|
| 38 |
function format_results($search) {
|
| 39 |
drupal_add_css(drupal_get_path('module', 'search') .'/search.css');
|
| 40 |
|
| 41 |
$found_items = $search->load_results($this->get_limit());
|
| 42 |
|
| 43 |
// Taken from node_search() (node.module 1.764) - BEGIN
|
| 44 |
$results = array();
|
| 45 |
foreach ($found_items as $item) {
|
| 46 |
// Build the node body.
|
| 47 |
$node = node_load($item->nid);
|
| 48 |
$node->build_mode = NODE_BUILD_SEARCH_RESULT;
|
| 49 |
$node = node_build_content($node, FALSE, FALSE);
|
| 50 |
$node->body = drupal_render($node->content);
|
| 51 |
|
| 52 |
// Fetch comments for snippet
|
| 53 |
$node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
|
| 54 |
// Fetch terms for snippet
|
| 55 |
$node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
|
| 56 |
|
| 57 |
$extra = node_invoke_nodeapi($node, 'search result');
|
| 58 |
$results[] = array(
|
| 59 |
'link' => url('node/'. $item->nid, array('absolute' => TRUE)),
|
| 60 |
'type' => check_plain(node_get_types('name', $node)),
|
| 61 |
'title' => $node->title,
|
| 62 |
'user' => theme('username', $node),
|
| 63 |
'date' => $node->changed,
|
| 64 |
'node' => $node,
|
| 65 |
'extra' => $extra,
|
| 66 |
'score' => $item->score,
|
| 67 |
'snippet' => search_excerpt(implode(' ', $search->get_keywords()), $node->body),
|
| 68 |
);
|
| 69 |
}
|
| 70 |
// Taken from node_search() - END
|
| 71 |
|
| 72 |
return theme('faceted_search_ui_search_page', $results, 'node');
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* Provides the 'teasers' display style for search results.
|
| 78 |
*/
|
| 79 |
class faceted_search_ui_teaser_style extends faceted_search_ui_style {
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Return the name of this style.
|
| 83 |
*/
|
| 84 |
function get_label() {
|
| 85 |
return t('Teasers');
|
| 86 |
}
|
| 87 |
|
| 88 |
/**
|
| 89 |
* Format the search results to display node teasers.
|
| 90 |
*/
|
| 91 |
function format_results($search) {
|
| 92 |
$limit = $this->get_limit();
|
| 93 |
$found_items = $search->load_results($limit);
|
| 94 |
|
| 95 |
foreach ($found_items as $item) {
|
| 96 |
$output .= node_view(node_load($item->nid), TRUE);
|
| 97 |
}
|
| 98 |
return $output . theme('pager', NULL, $limit);
|
| 99 |
}
|
| 100 |
}
|