View source
<?php
$freelinking['search'] = array(
'indicator' => '/search/',
'translate' => array(
' ' => '+',
),
'callback' => 'freelinking_search_callback',
'tip' => t('Run a local search for the specified terms.'),
);
$freelinking['google'] = array(
'indicator' => '/google/',
'translate' => array(
' ' => '+',
),
'callback' => 'freelinking_google_callback',
'tip' => t('Search google for the specified terms.'),
);
function freelinking_search_callback($target, $plugin) {
global $base_url;
$link = array();
$failover = variable_get('freelinking_search_failover', 'error');
if (!module_exists('search')) {
if ($failover == 'error') {
return array(
'failover' => 'error',
'message' => t('Search Unavailable'),
);
}
else {
$target['other']['site'] = $base_url;
return array(
'failover' => $failover,
'target' => $target,
);
}
}
$link[0] = $target['text'] ? $target['text'] : $target['dest'];
$link[1] = 'search/node/' . $target['dest'];
$link[2]['attributes']['title'] = t('Search this site for content like "%dest"', array(
'%dest' => $target['dest'],
));
return $link;
}
function freelinking_search_settings() {
$form['freelinking_search_failover'] = array(
'#type' => 'select',
'#title' => t('Failover Option'),
'#default_value' => variable_get('freelinking_search_failover', 'error'),
'#options' => array(
'error' => t('Error Message'),
'google' => 'Google',
),
'#description' => t('If Search is disabled or inaccessible do something else.'),
);
return $form;
}
function freelinking_google_callback($target, $plugin) {
global $language;
if (!$language) {
$lang = 'en';
}
else {
$lang = $language->language;
}
if ($target['text']) {
$title = $target['text'];
}
else {
$title = 'Google Search "' . $target['dest'] . '"';
}
$link = array(
check_plain($title),
'http://www.google.com/search',
array(
'query' => array(
'q' => check_url($target['dest']),
'hl' => $lang,
),
'external' => TRUE,
'attributes' => array(
'title' => t('Search Google for content like "%dest"', array(
'%dest' => $target['dest'],
)),
),
),
);
if (isset($target['other']['site'])) {
$link[2]['query']['as_sitesearch'] = urlencode($target['other']['site']);
}
return $link;
}