You are here

function google_cse_sitesearch_form in Google Custom Search Engine 6

Same name and namespace in other branches
  1. 7 google_cse.module \google_cse_sitesearch_form()
  2. 7.2 google_cse.module \google_cse_sitesearch_form()

Returns SiteSearch options form item.

2 calls to google_cse_sitesearch_form()
google_cse_searchbox_form_builder in ./google_cse.module
Form builder for the searchbox forms.
google_form_alter in ./google.module
Implementation of hook_form_alter().

File

./google_cse.module, line 204
Display a Google Custom Search Engine on your site.

Code

function google_cse_sitesearch_form(&$form) {
  if ($sites = preg_split('/[\\n\\r]+/', variable_get('google_cse_sitesearch', ''), -1, PREG_SPLIT_NO_EMPTY)) {
    $type = count($sites) > 1 ? 'select' : 'radios';
    foreach ($sites as $site) {
      $site = preg_split('/[\\s]+/', trim($site), 2, PREG_SPLIT_NO_EMPTY);
      if ($type == 'radios') {

        // Unlike select options, we need to HTML-escape radios options (both return values and display values).
        $options[check_plain($site[0])] = isset($site[1]) ? check_plain($site[1]) : t('Search %sitesearch', array(
          '%sitesearch' => $site[0],
        ));
      }
      else {

        // Select options will be HTML-escaped for us.
        $options[$site[0]] = isset($site[1]) ? $site[1] : t('Search !sitesearch', array(
          '!sitesearch' => $site[0],
        ));
      }
    }
    $form['sitesearch'] = array(
      '#type' => $type,
      '#options' => array(
        '' => ($var = variable_get('google_cse_sitesearch_option', '')) ? $type == 'radios' ? check_plain($var) : $var : t('Search the web'),
      ) + $options,
      '#default_value' => google_cse_sitesearch_default(),
    );
    if ($type == 'select' && isset($form['sa'])) {
      $form['sa']['#weight'] = 10;
    }
  }
}