You are here

function _adsense_page_match in Google AdSense integration 5

Same name and namespace in other branches
  1. 5.3 adsense.module \_adsense_page_match()
  2. 5.2 adsense.module \_adsense_page_match()
  3. 6 adsense.module \_adsense_page_match()
  4. 7 adsense.module \_adsense_page_match()

Determine if AdSense has permission to be used on the current page.

Return value

TRUE if can render, FALSE if not allowed.

1 call to _adsense_page_match()
adsense_display in ./adsense.module

File

./adsense.module, line 1268

Code

function _adsense_page_match() {
  $page_match = FALSE;
  $visibility = (int) variable_get(ADSENSE_VISIBILITY, '0');
  $pages = variable_get(ADSENSE_ACCESS_PAGES, '');
  if ($pages) {

    // Specific pages are configured
    $path = drupal_get_path_alias($_GET['q']);
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . variable_get('site_frontpage', 'node') . '\\2',
    ), preg_quote($pages, '/')) . ')$/';
    $page_match = !($visibility xor preg_match($regexp, $path));
  }
  else {

    // No pages are configured
    if ($visibility === 0) {

      // We are set to "Show on every pages except..."
      $page_match = TRUE;
    }
  }

  // Do not show ads on secure pages.
  // This is for two reasons:
  // Google would most probably not have indexed secure pages
  // and it also prevents warnings about mixed-content
  // Thanks to Brad Konia http://drupal.org/node/29585
  // Should be restricted when running on Apache only
  if (function_exists('apache_get_version')) {
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
      $page_match = FALSE;
    }
  }
  return $page_match;
}