|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Implementation of Roblib search for searching several targets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_menu().
|
|
|
|
*/
|
|
|
|
function roblib_search_menu() {
|
|
|
|
|
|
|
|
$items['admin/roblib_search'] = array(
|
|
|
|
'title' => 'Roblib search',
|
|
|
|
'description' => 'Configure global Roblib search settings.',
|
|
|
|
'access arguments' => array('administer site configuration'),
|
|
|
|
'type' => MENU_NORMAL_ITEM,
|
|
|
|
);
|
|
|
|
$items['admin/roblib_search/configure'] = array(
|
|
|
|
'title' => 'Global Configuration',
|
|
|
|
'description' => 'Configure global Roblib search settings.',
|
|
|
|
'access arguments' => array('administer site configuration'),
|
|
|
|
'page callback' => 'drupal_get_form',
|
|
|
|
'page arguments' => array('roblib_search_config_form'),
|
|
|
|
'type' => MENU_NORMAL_ITEM,
|
|
|
|
);
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function roblib_search_config_form($form, &$form_state) {
|
|
|
|
|
|
|
|
$form['roblib_search_panel_page'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('Path to the roblib search panel page'),
|
|
|
|
'#default_value' => variable_get('roblib_search_panel_page', '/roblib/panel'),
|
|
|
|
'#description' => t('The Path to the Roblib Search Panel, for example /roblib/panel'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
return system_settings_form($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_admin_paths().
|
|
|
|
*/
|
|
|
|
function roblib_search_admin_paths() {
|
|
|
|
$paths = array(
|
|
|
|
'admin/roblib/search' => TRUE,
|
|
|
|
);
|
|
|
|
return $paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_permission().
|
|
|
|
*/
|
|
|
|
function roblib_search_permission() {
|
|
|
|
return array(
|
|
|
|
'search roblib' => array(
|
|
|
|
'title' => t('Search all configured targets'),
|
|
|
|
'description' => t('Search all Roblib configured targets. This permission exposes the search blocks and allows you to see search results.'),
|
|
|
|
),
|
|
|
|
'administer roblib search' => array(
|
|
|
|
'title' => t('Administer Roblib Search'),
|
|
|
|
'description' => t('Administer settings for the Roblib search client.'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function roblib_search_block_info() {
|
|
|
|
|
|
|
|
$blocks['roblib_search_form'] = array(
|
|
|
|
'info' => t('Roblib Global Search Form'),
|
|
|
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
|
|
|
);
|
|
|
|
$blocks['roblib_search_other'] = array(
|
|
|
|
'info' => t('Roblib Search Other Sources'),
|
|
|
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function roblib_search_theme() {
|
|
|
|
// set path
|
|
|
|
$path = drupal_get_path('module', 'roblib_search');
|
|
|
|
$file = 'theme.inc';
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'roblib_search_other_sources' => array(
|
|
|
|
'path' => $path . '/theme',
|
|
|
|
'file' => $file,
|
|
|
|
'template' => 'roblib-search-other-sources',
|
|
|
|
'variables' => array('results' => NULL),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_preprocess_panels_pane(&$variables, $hook){
|
|
|
|
switch ($variables['pane']->subtype) {
|
|
|
|
case 'roblib_search-roblib_search_other':
|
|
|
|
$variables['title_prefix'] = '<div class="roblib-search-header roblib-search-other-sources-header">';
|
|
|
|
$variables['title_suffix'] = '</div>';
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_init() {
|
|
|
|
// Make qtip available for all targets js.
|
|
|
|
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/jquery.qtip.min.js');
|
|
|
|
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/imagesloaded.pkg.min.js');
|
|
|
|
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/roblib_search.js');
|
|
|
|
drupal_add_css(drupal_get_path('module', 'roblib_search') . '/css/jquery.qtip.min.css');
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_block_view($delta = '') {
|
|
|
|
switch ($delta) {
|
|
|
|
case 'roblib_search_form':
|
|
|
|
$block['subject'] = t('Bento Search');
|
|
|
|
$block['content'] = drupal_get_form('roblib_search_simple_form');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'roblib_search_other':
|
|
|
|
$block['subject'] = t('Other Sources');
|
|
|
|
$block['content'] = theme('roblib_search_other_sources', array('results' => NULL));
|
|
|
|
}
|
|
|
|
return $block;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Roblib search simple search form submit.
|
|
|
|
*
|
|
|
|
* @param array $form
|
|
|
|
* @param array $form_state
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function roblib_search_simple_form_submit($form, &$form_state) {
|
|
|
|
global $base_url;
|
|
|
|
$form_state['rebuild'] = TRUE;
|
|
|
|
$search_string = $form_state['values']['roblib_search_simple_search_query'];
|
|
|
|
$search_string = filter_xss($search_string);
|
|
|
|
roblib_search_log_query($search_string);
|
|
|
|
$redirect_url = variable_get('roblib_search_panel_page', 'roblib/panel');
|
|
|
|
$redirect_url = $base_url . '/' . $redirect_url;
|
|
|
|
drupal_goto($redirect_url, array('query' => array('roblib_query' => $search_string)));
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_log_query($search_string) {
|
|
|
|
$eid = db_insert('roblib_search_log')
|
|
|
|
->fields(array(
|
|
|
|
'query' => $search_string,
|
|
|
|
'searched_date' => format_date(time(), 'custom', 'Y-m-d H:i:s'),
|
|
|
|
'ipaddress' => ip_address(),
|
|
|
|
))
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Roblib search simple search form
|
|
|
|
*
|
|
|
|
* @param array $form
|
|
|
|
* @param array $form_state
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function roblib_search_simple_form($form, &$form_state) {
|
|
|
|
if (isset($_GET['roblib_query'])) {
|
|
|
|
$query = $_GET['roblib_query'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$query = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$form['simple'] = array(
|
|
|
|
'#type' => 'container',
|
|
|
|
'#attributes' => array(
|
|
|
|
'class' => array(
|
|
|
|
'container-inline'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$form['simple']["roblib_search_simple_search_query"] = array(
|
|
|
|
'#size' => '15',
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => '',
|
|
|
|
'#default_value' => $query,
|
|
|
|
);
|
|
|
|
$form['simple']['submit'] = array(
|
|
|
|
'#type' => 'submit',
|
|
|
|
'#value' => t('search')
|
|
|
|
);
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*
|
|
|
|
* @param type $path
|
|
|
|
* @param type $arg
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
function roblib_search_help($path, $arg) {
|
|
|
|
switch ($path) {
|
|
|
|
case 'admin/help#roblib_search':
|
|
|
|
return t(
|
|
|
|
'<p>
|
|
|
|
The Roblib Search is a module to allow searching across multiple targets.
|
|
|
|
This module does not know how to retrieve results but fires hooks that other
|
|
|
|
modules can implement to gather and display results.
|
|
|
|
</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|