'google_appliance',
'callback' => 'google_appliance_search',
'type' => MENU_CALLBACK,
'access' => true,
);
$items[] = array (
'path' => 'google_appliance_feeder',
'callback' => 'google_apppliance_feeder',
'type' => MENU_CALLBACK,
'access' => true,
);
$items[] = array(
'path' => 'admin/settings/google_appliance',
'title' => t('Google Appliance Settings'),
'description' => t('Configuration for the Google Appliance search'),
'callback' => 'drupal_get_form',
'callback arguments' => array('google_appliance_admin_settings'),
'access' => user_access('administer search'),
'type' => MENU_NORMAL_ITEM,
);
} else {
_google_appliance_add_meta_tags();
}
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', ''),
);
// 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.'),
);
// optional metadata configuration
/*
$form["config_metadata"] = array(
"#title" => t("Metadata Configuration"),
"#type" => "fieldset",
"#collapsible" => true,
);
*/
// last but not least, submit
$form["submit"] = array(
"#type" => "submit",
"#value" => t("Save Settings"),
);
return $form;
}
/**
* Validation function, though it's actually getting overridden by the #required fields...
*
*/
function google_appliance_admin_settings_validate($form_id, $form) {
if (empty($form['google_appliance_host_name'])) {
form_set_error('google_appliance_host_name', t('Please enter your host name or IP address.'));
}
if (empty($form['google_appliance_collection'])) {
form_set_error('google_appliance_collection', t('Please enter the name of the collection you want to search.'));
}
if (empty($form['google_appliance_client'])) {
form_set_error('google_appliance_client', t('Please enter name of the client frontend you are searching.'));
}
if (empty($form['google_appliance_name'])) {
form_set_error('google_appliance_name', t('Please enter the name of this search, to appear as sub-navigation on the search page.'));
}
}
/**
* Submits the admin settings form and saves all the variables.
*/
function google_appliance_admin_settings_submit($form_id, $form) {
variable_set('google_appliance_host_name', check_plain($form['google_appliance_host_name']));
variable_set('google_appliance_collection', check_plain($form['google_appliance_collection']));
variable_set('google_appliance_client', check_plain($form['google_appliance_client']));
variable_set('google_appliance_name', check_plain($form['google_appliance_name']));
variable_set('google_appliance_cache_timeout', check_plain($form['google_appliance_cache_timeout']));
variable_set('google_debug', check_plain($form['google_debug']));
// don't run check_plain on these because they can have HTML
variable_set('google_appliance_errorcode_1', $form['google_appliance_errorcode_1']);
variable_set('google_appliance_errorcode_2', $form['google_appliance_errorcode_2']);
variable_set('google_appliance_errorcode_neg_99', $form['google_appliance_errorcode_neg_99']);
variable_set('google_appliance_errorcode_neg_100', $form['google_appliance_errorcode_neg_100']);
drupal_set_message(t('Your settings have been saved.'));
}
/**
* Invokes the google_appliance_appconfig hook to add tags to nodes
* for indexing metadata by the google crawler.
*
*/
function _google_appliance_add_meta_tags() {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
theme('add_google_appliance_meta_tags', $node);
}
}
function google_appliance_feeder() {
//not sure if this is appropriate as everything should be findable via the main site, but this basically just creates a listing of all nodes.
$result = db_query('SELECT * from {node} WHERE status = 1');
print '';
print '