You are here

function drupalchat_verify_access in DrupalChat 7.2

Same name and namespace in other branches
  1. 6.2 drupalchat.module \drupalchat_verify_access()
  2. 7 drupalchat.module \drupalchat_verify_access()
2 calls to drupalchat_verify_access()
drupalchat_init in ./drupalchat.module
@todo Please document this function.
drupalchat_page_alter in ./drupalchat.module

File

./drupalchat.module, line 44
Module code for DrupalChat.

Code

function drupalchat_verify_access() {
  global $user;

  // Match path if necessary.
  $page_match = FALSE;
  if (check_plain(variable_get('drupalchat_path_pages', NULL))) {

    // Convert path to lowercase. This allows comparison of the same path
    // with different case. Ex: /Page, /page, /PAGE.
    $pages = drupal_strtolower(check_plain(variable_get('drupalchat_path_pages', NULL)));
    if (check_plain(variable_get('drupalchat_path_visibility', BLOCK_VISIBILITY_NOTLISTED)) < BLOCK_VISIBILITY_PHP) {

      // Convert the Drupal path to lowercase
      $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

      // Compare the lowercase internal and lowercase 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 $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
      // the block is displayed on all pages except those listed in $block->pages.
      // When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
      // pages listed in $block->pages.
      $page_match = !(check_plain(variable_get('drupalchat_path_visibility', BLOCK_VISIBILITY_NOTLISTED)) xor $page_match);
    }
    elseif (module_exists('php')) {
      $page_match = php_eval(check_plain(variable_get('drupalchat_path_pages', NULL)));
    }
    else {
      $page_match = FALSE;
    }
  }
  else {
    $page_match = TRUE;
  }
  $final = FALSE;
  $final = (check_plain(variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH)) == DRUPALCHAT_REL_AUTH && $user->uid == 0 || $user->uid > 0) && $page_match && user_access('access drupalchat');
  if (check_plain(variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX)) != DRUPALCHAT_COMMERCIAL) {
    $final = $final && _drupalchat_get_sid() != -1;
  }
  return $final;
}