You are here

function _zopim_active in Zopim Live Chat 8

Check if Zopim Chat widget should be active for the current URL.

Return value

boolean TRUE if it should be active for the current page, otherwise FALSE.

1 call to _zopim_active()
zopim_page_attachments in ./zopim.module
Implements hook_page_attachments().

File

./zopim.module, line 65

Code

function _zopim_active() {

  // Make it possible deactivate Zopim Chat with
  // parameter ?zopim=no in the url.
  if (isset($_GET['zopim']) && $_GET['zopim'] == 'no') {
    return FALSE;
  }

  // Assume there are not matches until one is found.
  $page_match = FALSE;

  // Convert path to lowercase. This allows comparison of the same path
  // with different case. Ex: /Page, /page, /PAGE.
  $config = \Drupal::config('zopim.settings');
  $pages = Unicode::strtolower(_zopim_array_to_string($config
    ->get('pages')));

  // Compare the lowercase path alias (if any) and internal path.
  $path = \Drupal::service('path.current')
    ->getPath();
  $current_language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $path_alias = Unicode::strtolower(\Drupal::service('path.alias_storage')
    ->lookupPathAlias($path, $current_language));
  $page_match = \Drupal::service('path.matcher')
    ->matchPath($path_alias, $pages);
  if ($path_alias != $path) {
    $page_match = $page_match || \Drupal::service('path.matcher')
      ->matchPath($path, $pages);
  }
  $page_match = $config
    ->get('visibility') == ZOPIM_BLACKLIST_MODE ? !$page_match : $page_match;
  return $page_match;
}