You are here

function _zopim_visibility_pages in Zopim Live Chat 7

Same name and namespace in other branches
  1. 6.2 zopim.module \_zopim_visibility_pages()
  2. 6 zopim.module \_zopim_visibility_pages()

Utility function to determing visibility. Based on visibility setting this function returns TRUE if Zopim code should be added to the current page and otherwise FALSE.

@staticvar boolean $page_match whether page is visible (true) or not (false).

Return value

boolean a decision on visibility, true/false

1 call to _zopim_visibility_pages()
zopim_page_alter in ./zopim.module
Implementation of hook_page_alter().

File

./zopim.module, line 121

Code

function _zopim_visibility_pages() {
  static $page_match;

  // Cache visibility setting in hook_init for hook_footer.
  if (!isset($page_match)) {
    $visibility = variable_get('zopim_visibility', 0);
    $pages = variable_get('zopim_pages', '');

    // Match path if necessary.
    if (!empty($pages)) {
      if ($visibility < 2) {
        $path = drupal_get_path_alias($_GET['q']);

        // Compare with the internal and path alias (if any).
        $page_match = drupal_match_path($path, $pages);
        if ($path != $_GET['q']) {
          $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
        }

        // When $visibility has a value of 0, the block is displayed on
        // all pages except those listed in $pages. When set to 1, it
        // is displayed only on those pages listed in $pages.
        $page_match = !($visibility xor $page_match);
      }
      elseif (module_exists('php')) {
        $page_match = php_eval($pages);
      }
    }
    else {
      $page_match = TRUE;
    }
  }
  return $page_match;
}