You are here

function livechat_check_visibility in LiveChat 7

Same name and namespace in other branches
  1. 8 livechat.module \livechat_check_visibility()
  2. 8.2 livechat.module \livechat_check_visibility()

Checks whether LiveChat should be visible on a path, according to settings.

1 call to livechat_check_visibility()
livechat_preprocess_html in ./livechat.module
Implements hook_preprocess_HOOK().

File

./livechat.module, line 154
LiveChat module.

Code

function livechat_check_visibility($path = NULL) {

  // Default to the current path.
  if (!isset($path)) {
    $path = current_path();
  }

  // Visibility settings.
  $visibility = variable_get('livechat_visibility', LIVECHAT_VISIBILITY_NOTLISTED);
  $pages = drupal_strtolower(variable_get('livechat_pages', LIVECHAT_VISIBILITY_DEFAULT_PAGES));

  // If $visibility is set to LIVECHAT_VISIBILITY_NOTLISTED and the setting for
  // excluding system paths is enabled, add system paths to the list of pages.
  $exclude_system_paths = variable_get('livechat_exclude_system_paths', 1);
  if ($visibility == LIVECHAT_VISIBILITY_NOTLISTED && $exclude_system_paths) {
    $pages .= "\n" . LIVECHAT_VISIBILITY_SYSTEM_PATHS;
  }

  // Get the path alias as lowercase.
  $expanded_path = drupal_strtolower(drupal_get_path_alias($path));

  // Compare the lowercase internal and lowercase path alias (if any).
  $page_match = drupal_match_path($expanded_path, $pages);
  if ($expanded_path != $path) {
    $page_match = $page_match || drupal_match_path($path, $pages);
  }

  // When $visibility has a value of 0 (LIVECHAT_VISIBILITY_NOTLISTED), the
  // widget should be displayed on all pages except those listed. When set to 1
  // (LIVECHAT_VISIBILITY_LISTED), it should only be displayed on listed pages.
  return !($visibility xor $page_match);
}