You are here

adsense_cse.results.inc in Google AdSense integration 7

Same filename and directory in other branches
  1. 5.3 cse/adsense_cse.results.inc
  2. 6 cse/adsense_cse.results.inc

Displays the page containing the results of the Adsense for Search box.

File

cse/adsense_cse.results.inc
View source
<?php

/**
 * @file
 * Displays the page containing the results of the Adsense for Search box.
 */

/**
 * Creates the CSE search results page for site-embedded search results.
 *
 * @return string
 *   JavaScript that embeds the Google results
 */
function _adsense_cse_results() {
  global $base_url;

  // Log the search keys:
  watchdog('AdSense search', 'Search keywords: %keywords', array(
    '%keywords' => urldecode(check_plain($_GET['as_q'])),
  ));
  $script = $base_url . '/' . drupal_get_path('module', 'adsense_cse') . '/adsense_cse.results.js';

  // Output search results.
  $width = variable_get('adsense_cse_frame_width', ADSENSE_CSE_FRAME_WIDTH_DEFAULT);
  $country = variable_get('adsense_cse_country', ADSENSE_CSE_COUNTRY_DEFAULT);
  if (variable_get('adsense_test_mode', ADSENSE_TEST_MODE_DEFAULT)) {
    $output = theme('adsense_placeholder', array(
      'text' => "Results<br />width = {$width}<br />country = {$country}",
      'width' => $width,
      'height' => 100,
    ));
  }
  else {
    $output = <<<CSE_RESULTS_TXT
<div id="cse-search-results"></div>
<script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = {<span class="php-variable">$width</span>};
  var googleSearchDomain = "{<span class="php-variable">$country</span>}";
  var googleSearchPath = "/cse";
  var googleSearchQueryString = "as_q";
</script>
<script type="text/javascript" src="{<span class="php-variable">$script</span>}"></script>
CSE_RESULTS_TXT;

    // @codingStandardsIgnoreStart Drupal.WhiteSpace.ScopeIndent.IncorrectExact
    // <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    // @codingStandardsIgnoreEnd
    // Remove empty lines.
    $output = str_replace("\n\n", "\n", $output);
  }
  return $output;
}

Functions

Namesort descending Description
_adsense_cse_results Creates the CSE search results page for site-embedded search results.