function _linkchecker_link_block_ids in Link checker 7
Same name and namespace in other branches
- 6.2 linkchecker.module \_linkchecker_link_block_ids()
Returns IDs of blocks that contain a link which the current user is allowed to view.
Parameters
object $link: An object representing the link to check.
Return value
array 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 ./
linkchecker.pages.inc - Builds the HTML report page table with pager.
File
- ./
linkchecker.module, line 413 - This module periodically check links in given node types, blocks 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.
$bids = db_query('SELECT bid FROM {linkchecker_block_custom} WHERE lid = :lid', array(
':lid' => $link->lid,
))
->fetchCol();
// 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;
$query = db_select('block', 'b');
$query
->leftJoin('block_role', 'r', 'b.module = r.module AND b.delta = r.delta');
$query
->condition('b.module', 'block');
$query
->condition(db_or()
->condition('r.rid', $rids, 'IN')
->isNull('r.rid'));
$query
->fields('b', array(
'delta',
));
$query
->distinct();
$allowed_bids = $query
->execute()
->fetchCol();
return array_intersect($bids, $allowed_bids);
}