You are here

freelinking_search.inc in Freelinking 6.3

Same filename and directory in other branches
  1. 7.3 plugins/freelinking_search.inc

File

plugins/freelinking_search.inc
View source
<?php

/**
 * Search Plugin for Freelinking
 *
 * @file
 * Provides Internal & Google search plugins.
 */
$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') {

      // send back an error message.
      return array(
        'failover' => 'error',
        'message' => t('Search Unavailable'),
      );
    }
    else {

      // specify a plugin for next effort
      $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;
}

/**
 * Settings callback for Search plugin
 */
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;
}

/**
 * Replacement callback for Google plugin
 */
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;
}

Functions

Namesort descending Description
freelinking_google_callback Replacement callback for Google plugin
freelinking_search_callback
freelinking_search_settings Settings callback for Search plugin