'Google Appliance Settings',
'description' => 'Configuration for the Google Appliance search',
'page callback' => 'drupal_get_form',
'page arguments' => array('google_appliance_admin_settings'),
'access arguments' => array('administer search'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_block().
*/
function google_appliance_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks['recommended_links']['info'] = t("Recommended Links");
$blocks['recommended_links']['title'] = t('Recommended Links');
$blocks['recommended_links']['pages'] = '*search/google_appliance*';
$blocks['recommended_links']['visibility'] = 1;
return $blocks;
break;
case 'view':
switch ($delta) {
case 'recommended_links':
if ($result =& google_appliance_static_response_cache()) {
$matches = $result->getKeyMatches();
if (!$matches) {
return;
}
$links = array();
foreach ($matches as $link => $title) {
$links[] = l($title, $link);
}
if (count($links)) {
$block['content'] = theme('item_list', $links);
}
else {
return FALSE;
}
}
break;
}
return $block;
break;
}
}
function google_appliance_admin_settings() {
$form = array();
// initial required config fields
$form['config_init'] = array(
'#title' => t("Initial Configuration"),
'#type' => 'fieldset',
);
$form['config_init']['google_appliance_name'] = array(
'#type' => 'textfield',
'#size' => 30,
'#title' => t("Search Name"),
'#description' => t('The name of this search, to appear as sub-navigation on the search page.'),
'#default_value' => variable_get('google_appliance_name', 'Google Appliance'),
'#required' => TRUE,
);
$form['config_init']['google_appliance_host_name'] = array(
'#type' => 'textfield',
'#size' => 50,
'#title' => t("Host Name"),
'#description' => t('Your Google Search Appliance host name or IP address (with http:// or https://), which were assigned when the appliance was set up.
You do not need to include "/search" at the end, or a trailing slash, but you should include a port number if needed.
Example: http://mygooglebox.com'),
'#default_value' => variable_get('google_appliance_host_name', ''),
'#required' => TRUE,
);
$form['config_init']['google_appliance_collection'] = array(
'#type' => 'textfield',
'#size' => 20,
'#title' => t("Collection"),
'#description' => t('The name of the collection of indexed content to search.'),
'#default_value' => variable_get('google_appliance_collection', ''),
'#required' => TRUE,
);
$form['config_init']['google_appliance_client'] = array(
'#type' => 'textfield',
'#size' => 20,
'#title' => t("Client"),
'#description' => t('The name of a valid front-end, defined when you set up the appliance.'),
'#default_value' => variable_get('google_appliance_client', ''),
'#required' => TRUE,
);
$form['config_init']['google_appliance_cache_timeout'] = array(
'#type' => 'textfield',
'#size' => 20,
'#title' => t("Cache Timeout"),
'#description' => t('If you wish to use caching of results (to reduce load on mini, enter a timeout here'),
'#default_value' => variable_get('google_appliance_cache_timeout', ''),
);
$form['config_init']['google_debug'] = array(
'#type' => 'textfield',
'#size' => 20,
'#title' => t("Debug Level"),
'#description' => t('1 = watchdog, 2 = dpr(needs devel module), 3 = more dpr\'s'),
'#default_value' => variable_get('google_debug', ''),
);
$form['config_init']['google_appliance_limit_per_page'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t("Number of results per page"),
'#description' => t('If you enter 0, it will return the max allowed by the appliance (100)'),
'#default_value' => variable_get('google_appliance_limit_per_page', 10),
);
// error message config
$form['config_messages'] = array(
'#title' => t("Error Messages"),
'#type' => 'fieldset',
'#collapsible' => TRUE,
);
$form['config_messages']['google_appliance_errorcode_1'] = array(
'#title' => t("No results found"),
'#type' => 'textfield',
'#size' => 100,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('If there are no results for the search criteria.'),
'#default_value' => variable_get('google_appliance_errorcode_1', 'No results were found that matched your criteria. Please try broadening your search.'),
);
$form['config_messages']['google_appliance_errorcode_2'] = array(
'#title' => t("More than 1,000 results"),
'#type' => 'textfield',
'#size' => 100,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('If there are more than 1,000 results for the search criteria.'),
'#default_value' => variable_get('google_appliance_errorcode_2', 'Sorry, but our search does not return more than 1,000 records, please refine your criteria.'),
);
$form['config_messages']['google_appliance_errorcode_neg_99'] = array(
'#title' => t("Cannot perform search"),
'#type' => 'textfield',
'#size' => 100,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('If the search cannot perform due to a query error.'),
'#default_value' => variable_get('google_appliance_errorcode_neg_99', 'We apologize, but your search cannot be completed at this time, please try again later.'),
);
$form['config_messages']['google_appliance_errorcode_neg_100'] = array(
'#title' => t("Cannot connect to Google Appliance"),
'#type' => 'textfield',
'#size' => 100,
'#maxlength' => 255,
'#required' => TRUE,
'#description' => t('If the search cannot connect to the Google Appliance server.'),
'#default_value' => variable_get('google_appliance_errorcode_neg_100','We apologize, but the connection to our search engine appears to be down at the moment, please try again later.'),
);
$form['config_search_block']['google_appliance_control_search'] = array(
'#type' => 'checkbox',
'#title' => t('Default Search Handler.'),
'#description' => t('Allows the GSA to be the default search handler for the search block'),
'#default_value' => variable_get('google_appliance_control_search',false),
);
return system_settings_form($form);
}
/**
* Implementation of hook_search().
*
* @param string $op
* Operation - name, reset, search, status
* @param string $keys
* Keyword string sent to the search
* @return
* Array of search results (each is an assoc. array) that can be fed to a theme function
*/
function google_appliance_search($op = 'search', $keys = NULL) {
switch ($op) {
case 'name':
return t(variable_get('google_appliance_name', "Google Appliance"));
break;
case 'search':
global $pager_page_array, $pager_total, $pager_total_items;
$page = isset($_GET['page']) ? $_GET['page'] : '';
// Convert comma-separated $page to an array, used by other functions.
$pager_page_array = explode(',', $page);
// $element indicates which of the pagers active this pager is working from. $limit indicates how many per page.
$element = 0;
$limit = variable_get('google_appliance_limit_per_page', 10);
$dir = drupal_get_path('module', 'google_appliance');
include_once $dir . '/DrupalGoogleMini.php';
$google_debug = variable_get('google_debug',0);
if ($google_debug >= 2 ) {
$gm = new DrupalGoogleMini(TRUE, 'dpr');
}
elseif ($google_debug == 1) {
$gm = new DrupalGoogleMini(TRUE);
}
else {
$gm = new DrupalGoogleMini(FALSE);
}
/**
* If you have many searches for the same content
* You can use this setting to keep the GSA from getting hit too often
*
*/
if ($cache = variable_get('google_appliance_cache_timeout', 0) ) {
cache_clear_all(NULL, 'cache_google');
$gm->cache = TRUE;
}
// initialize search object
try {
$gm->setOutputEncoding('utf8');
$gm->setInputEncoding('utf8');
$gm->setMetaDataRequested('*');
// get configuration from settings page
$_tmp_host = variable_get('google_appliance_host_name', FALSE);
if (!$_tmp_host) {
drupal_set_message(t('No host name has been configured for the search appliance. Please enter it on the Google Appliance settings page', array('@admin-url' => url("admin/settings/search/google_appliance"))), 'error');
return FALSE;
}
$gm->baseUrl = $_tmp_host . "/search";
$gm->collection = variable_get('google_appliance_collection', '');
$gm->setQueryPart('client', variable_get('google_appliance_client', ''));
$gm->setPageAndResultsPerPage($page, $limit);
// set search parameters
$gm->setKeywords($keys);
if (module_exists('i18n')) {
if ($lang = i18n_get_lang()) {
$gm->setLanguageFilter(array($lang));
}
}
}
catch (GoogleMiniCriteriaException $e) {
$code = $e->getCode();
if ($message = variable_get('google_appliance_errorcode_' . $code, '')) {
$user_message = $message;
}
else {
$user_message = GoogleMiniException::getUserMessage($code);
}
$error_message = $e->getMessage();
if ($code > 0) {
$output .= "