finder_search.module in Finder 7
Same filename and directory in other branches
The finder search module.
File
modules/finder_search/finder_search.moduleView source
<?php
// $Id: finder_search.module,v 1.1.2.56 2011/02/12 06:55:19 danielb Exp $
/**
* @file
* The finder search module.
*/
/**
* Implements hook_theme().
*
* @see hook_theme()
*/
function finder_search_theme() {
return array(
'finder_search_results' => array(
'variables' => array(
'results' => NULL,
'finder' => NULL,
'form_state' => NULL,
'no_results' => NULL,
),
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see hook_form_FORM_ID_alter()
*/
function finder_search_form_finder_admin_edit_alter(&$form, $form_state) {
$finder =& $form_state['storage']['finder'];
$form['settings']['advanced']['search'] = array(
'#type' => 'radios',
'#title' => t('Use search module'),
'#default_value' => isset($finder->settings['advanced']['search']) ? $finder->settings['advanced']['search'] : 0,
'#weight' => 50,
'#options' => array(
0 => t('Do not use search module.'),
1 => t('Attempt to fetch results from a content search when finder results are empty.'),
),
);
$form['settings']['advanced']['search_tab'] = array(
'#type' => 'textfield',
'#title' => t('Search module tab'),
'#default_value' => isset($finder->settings['advanced']['search_tab']) ? $finder->settings['advanced']['search_tab'] : 'node',
'#required' => TRUE,
'#weight' => 55,
'#description' => t('Which tab to use in the search module. Default is <em>node</em>.'),
);
}
/**
* Implements hook_theme_registry_alter().
*
* @see hook_theme_registry_alter()
*/
function finder_search_theme_registry_alter(&$theme_registry) {
global $theme_info;
$theme_funcs = variable_get('finder_search_finder_results_theme', array());
// This is to fix upgrade from <= 6.x-1.5 to 6.x-1.7
if (!is_array($theme_funcs)) {
$theme_funcs = array();
}
$theme_funcs[$theme_info->name] = $theme_registry['finder_results']['function'];
variable_set('finder_search_finder_results_theme', $theme_funcs);
$theme_registry['finder_results']['function'] = 'finder_search_preprocess_finder_results';
}
/**
* Intervene before theme function.
*
* Kind of like a template preprocess, except not for a template.
*
* @see finder_search_theme_registry_alter()
*/
function finder_search_preprocess_finder_results($variables) {
extract($variables);
global $theme_info;
$theme_funcs = variable_get('finder_search_finder_results_theme', array());
$theme_func = !empty($theme_funcs[$theme_info->name]) ? $theme_funcs[$theme_info->name] : 'theme_finder_results';
if (isset($finder->settings['advanced']['search']) && $finder->settings['advanced']['search'] && empty($results)) {
$keys = array();
foreach ($keywords as $finder_element_id => $finder_element_keywords) {
foreach ((array) $finder_element_keywords as $keyword) {
$keys[] = $keyword;
}
}
$results_array = finder_search_get_result(implode(' ', $keys), $finder->settings['advanced']['search_tab']);
$results = theme('finder_search_results', array(
'results' => $results_array,
'finder' => $finder,
'form_state' => $form_state,
'no_results' => $no_results,
));
// search module has it's own pager
$pager = 0;
}
return $theme_func(array(
'results' => $results,
'finder' => $finder,
'keywords' => $keywords,
'pager' => $pager,
'params' => $params,
'form_state' => $form_state,
'no_results' => $no_results,
));
}
/**
* Get results array from search module.
*/
function finder_search_get_result($keys = NULL, $type = 'node') {
if (isset($keys)) {
if (module_hook($type, 'search')) {
return module_invoke($type, 'search', 'search', $keys);
}
}
}
/**
* Get themed version of search results.
*
* @param $results
* An array of result objects.
* @return
* Themed output from search module's hooks.
*/
function finder_search_get_themed_results($results) {
$output = '';
if (isset($results) && is_array($results) && count($results)) {
if (module_hook($type, 'search_page')) {
$output .= module_invoke($type, 'search_page', $results);
}
else {
$output .= theme('search_results', $results, $type);
}
}
return $output;
}
/**
* Theme search results for finder.
*
* @param $results
* An array of result objects.
* @param $finder
* The finder object.
* @param $form_state
* The Forms API form state.
* @param $no_results
* The output to show when there are no results.
*/
function theme_finder_search_results($variables) {
extract($variables);
$output = '';
if ($results) {
$output .= finder_search_get_themed_results($results);
}
else {
$output .= $no_results;
}
return $output;
}
// to do:
// - ability to exclude certain fields/elements from being included in the search keywords
Functions
Name | Description |
---|---|
finder_search_form_finder_admin_edit_alter | Implements hook_form_FORM_ID_alter(). |
finder_search_get_result | Get results array from search module. |
finder_search_get_themed_results | Get themed version of search results. |
finder_search_preprocess_finder_results | Intervene before theme function. |
finder_search_theme | Implements hook_theme(). |
finder_search_theme_registry_alter | Implements hook_theme_registry_alter(). |
theme_finder_search_results | Theme search results for finder. |