You are here

function _adsense_cse_get_searchbox in Google AdSense integration 5.3

Same name and namespace in other branches
  1. 6 cse/adsense_cse.module \_adsense_cse_get_searchbox()
  2. 7 cse/adsense_cse.module \_adsense_cse_get_searchbox()

Generates the CSE search box

Parameters

$slot: Slot Id for the AdSense for Search

Return value

HTML with the search input form

1 call to _adsense_cse_get_searchbox()
adsense_display in ./adsense.module
Generates the Google AdSense Ad

File

cse/adsense_cse.module, line 141
Displays Google AdSense ads on Drupal pages

Code

function _adsense_cse_get_searchbox($client, $slot = NULL) {
  global $base_url;
  $branding = variable_get('adsense_cse_logo', ADSENSE_CSE_LOGO_DEFAULT);
  $box_background_color = variable_get('adsense_cse_color_box_background', ADSENSE_CSE_COLOR_BOX_BACKGROUND_DEFAULT);
  $ad_location = variable_get('adsense_cse_ad_location', ADSENSE_CSE_AD_LOCATION_DEFAULT);
  $encoding = variable_get('adsense_cse_encoding', ADSENSE_CSE_ENCODING_DEFAULT);
  $textbox_length = variable_get('adsense_cse_textbox_length', ADSENSE_CSE_TEXTBOX_LENGTH_DEFAULT);
  $language = variable_get('adsense_cse_language', ADSENSE_CSE_LANGUAGE_DEFAULT);
  $search = t('Search');
  $custom_search = t('Custom Search');
  if (variable_get('clean_url', 0)) {
    $results_path = url(ADSENSE_CSE_RESULTS_PATH, array(
      'absolute' => TRUE,
    ));
    $hidden_q_field = '';
  }
  else {
    $results_path = $base_url;
    $hidden_q_field = '<input type="hidden" name="q" value="." />';
  }
  if ($box_background_color == '000000') {
    $box_text_color = 'FFFFFF';
  }
  else {
    $box_text_color = '000000';
  }
  switch ($ad_location) {
    case 'adsense_cse_loc_top_right':
      $forid = 10;
      break;
    case 'adsense_cse_loc_top_bottom':
      $forid = 11;
      break;
    case 'adsense_cse_loc_right':
      $forid = 9;
      break;
  }
  if ($branding == 'adsense_cse_branding_watermark') {

    // Since we use as_q, Google's Javascript can't be used, so we use a modified local copy
    $script = $base_url . '/' . drupal_get_path('module', 'adsense_cse') . '/adsense_cse.js';

    // If there is a watermark, the indentation of the code makes it impossible to re-use the same text
    $output = <<<CSE_TXT1
<script type="text/javascript"><!--
drupal_adsense_cse_lang = '{<span class="php-variable">$language</span>}';
//-->
</script>
<form action="{<span class="php-variable">$results_path</span>}" id="cse-search-box">
  <div>{<span class="php-variable">$hidden_q_field</span>}
    <input type="hidden" name="cx" value="partner-{<span class="php-variable">$client</span>}:{<span class="php-variable">$slot</span>}" />
    <input type="hidden" name="cof" value="FORID:{<span class="php-variable">$forid</span>}" />
    <input type="hidden" name="ie" value="{<span class="php-variable">$encoding</span>}" />
    <input type="text" name="as_q" size="{<span class="php-variable">$textbox_length</span>}" />
    <input type="submit" name="sa" value="{<span class="php-variable">$search</span>}" />
  </div>
</form>
<script type="text/javascript" src="{<span class="php-variable">$script</span>}"></script>
CSE_TXT1;

    //<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en"></script>
  }
  else {
    if ($branding == 'adsense_cse_branding_right') {
      $class = 'cse-branding-right';
    }
    else {
      $class = 'cse-branding-bottom';
    }
    $output = <<<CSE_TXT2
<style type="text/css">
@import url(http://www.google.com/cse/api/branding.css);
</style>
<div class="{<span class="php-variable">$class</span>}" style="background-color:#{<span class="php-variable">$box_background_color</span>};color:#{<span class="php-variable">$box_text_color</span>}">
  <div class="cse-branding-form">
    <form action="{<span class="php-variable">$results_path</span>}" id="cse-search-box">
      <div>{<span class="php-variable">$hidden_q_field</span>}
        <input type="hidden" name="cx" value="partner-{<span class="php-variable">$client</span>}:{<span class="php-variable">$slot</span>}" />
        <input type="hidden" name="cof" value="FORID:{<span class="php-variable">$forid</span>}" />
        <input type="hidden" name="ie" value="{<span class="php-variable">$encoding</span>}" />
        <input type="text" name="as_q" size="{<span class="php-variable">$textbox_length</span>}" />
        <input type="submit" name="sa" value="{<span class="php-variable">$search</span>}" />
      </div>
    </form>
  </div>
  <div class="cse-branding-logo">
    <img src="http://www.google.com/images/poweredby_transparent/poweredby_{<span class="php-variable">$box_background_color</span>}.gif" alt="Google" />
  </div>
  <div class="cse-branding-text">
    {<span class="php-variable">$custom_search</span>}
  </div>
</div>
CSE_TXT2;
  }
  return $output;
}