You are here

function _context_ui_block_visibility in Context 5

1 call to _context_ui_block_visibility()
context_ui_block_list in context_ui/context_ui.module
An alternative version of block_list() that provides any context_ui enabled blocks.

File

context_ui/context_ui.module, line 640

Code

function _context_ui_block_visibility($op, $block) {
  switch ($op) {
    case 'user':
      global $user;

      // Use the user's block visibility setting, if necessary
      if ($block->custom != 0) {
        if ($user->uid && isset($user->block[$block->module][$block->delta])) {
          return $user->block[$block->module][$block->delta];
        }
        else {
          return $block->custom == 1;
        }
      }
      return true;
    case 'page':

      // Match path if necessary
      if ($block->pages) {
        if ($block->visibility < 2) {
          $path = drupal_get_path_alias($_GET['q']);
          $regexp = '/^(' . preg_replace(array(
            '/(\\r\\n?|\\n)/',
            '/\\\\\\*/',
            '/(^|\\|)\\\\<front\\\\>($|\\|)/',
          ), array(
            '|',
            '.*',
            '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
          ), preg_quote($block->pages, '/')) . ')$/';

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

          // When $block->visibility has a value of 0, the block is displayed on
          // all pages except those listed in $block->pages. When set to 1, it
          // is displayed only on those pages listed in $block->pages.
          return !($block->visibility xor $page_match);
        }
        else {
          return drupal_eval($block->pages);
        }
      }
      return true;
    case 'throttle':
      if (!($block->throttle && module_invoke('throttle', 'status') > 0)) {
        return true;
      }
      return false;
  }
}