You are here

function _linkchecker_link_block_ids in Link checker 6.2

Same name and namespace in other branches
  1. 7 linkchecker.module \_linkchecker_link_block_ids()

Returns IDs of blocks that contain a link which the current user is allowed to view.

Parameters

$link: An object representing the link to check.

Return value

An array of custom block IDs that contain the provided link and that the current user is allowed to view.

2 calls to _linkchecker_link_block_ids()
_linkchecker_link_access in ./linkchecker.module
Determines if the current user has access to view a link.
_linkchecker_report_page in includes/linkchecker.pages.inc

File

./linkchecker.module, line 310
This module periodically check links in given node types, blocks, cck fields, etc.

Code

function _linkchecker_link_block_ids($link) {

  // Exit if blocks are disabled.
  if (!variable_get('linkchecker_scan_blocks', 0)) {
    return array();
  }

  // Get the initial list of block IDs.
  $boxes = db_query('SELECT bid FROM {linkchecker_boxes} WHERE lid = %d', $link->lid);
  $bids = array();
  while ($box = db_fetch_object($boxes)) {
    $bids[] = $box->bid;
  }

  // If the user can administer blocks, they're able to see all block content.
  if (user_access('administer blocks')) {
    return $bids;
  }

  // Otherwise, only return blocks that this user (or anonymous users) have
  // access to.
  global $user;
  $rids = array_keys($user->roles);
  $rids[] = DRUPAL_ANONYMOUS_RID;
  $allowed_boxes = db_query("SELECT DISTINCT b.delta\n    FROM {blocks} b\n    LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta\n    WHERE b.module = 'block'\n    AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL)", $rids);
  $allowed_bids = array();
  while ($allowed_box = db_fetch_object($allowed_boxes)) {
    $allowed_bids[] = $allowed_box->delta;
  }
  return array_intersect($bids, $allowed_bids);
}