You are here

function om_maximenu_blocks_visibility in OM Maximenu 6

Same name and namespace in other branches
  1. 8 inc/om_maximenu.render.inc \om_maximenu_blocks_visibility()
  2. 7 inc/om_maximenu.render.inc \om_maximenu_blocks_visibility()

OM Maximenu content block visibility check

1 call to om_maximenu_blocks_visibility()
om_maximenu_init in inc/om_maximenu.render.inc
Implementation of hook_init().

File

inc/om_maximenu.render.inc, line 300
OM Maximenu Render

Code

function om_maximenu_blocks_visibility() {
  global $user;

  // $theme_key is not processed on hook_init()
  $theme_key = variable_get('theme_default', 'garland');
  $visible_blocks = array();
  $blocks = array();
  if (!count($blocks)) {
    $rids = array_keys($user->roles);
    $result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array(
      $theme_key,
    ), $rids));
    while ($block = db_fetch_object($result)) {

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

      // Match path if necessary
      if ($block->pages) {
        if ($block->visibility < 2) {
          $path = drupal_get_path_alias($_GET['q']);

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

          // 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.
          $page_match = !($block->visibility xor $page_match);
        }
        else {
          $page_match = drupal_eval($block->pages);
        }
      }
      else {
        $page_match = TRUE;
      }
      $block->enabled = $enabled;
      $block->page_match = $page_match;
      if ($page_match) {
        $visible_blocks[] = $block->module . '__' . $block->delta;
      }
    }
  }
  return $visible_blocks;
}