function _authcache_blocks in Authenticated User Page Caching (Authcache) 6
Same name and namespace in other branches
- 7 ajax/authcache.php \_authcache_blocks()
Render blocks. Grab from cache if available.
Parameters
<array> $blocks: [block id] => [block cache id]
See also
File
- ajax/
authcache.php, line 243 - Authcache Ajax Callback (authcache.php)
Code
function _authcache_blocks($blocks) {
global $user, $theme_key;
$return = array();
foreach ($blocks as $block_id => $block_cid) {
// If block cache is per user, then specify current user id.
$block_cid = preg_replace('/:u.[0-9]+/', ":u.{$user->uid}", $block_cid);
// Validate user roles with block visibility roles.
// (In case someone is trying to hack into viewing certain blocks.)
if (strpos($block_cid, ':r.') !== FALSE) {
$matches = array();
preg_match('/:r.([0-9,]+)/', $block_cid, $matches);
if (isset($matches[1])) {
// Cache id is built using exact user roles, so a direct comparison works. @see _block_get_cache_id().
if ($matches[1] != implode(',', array_keys($user->roles))) {
continue;
}
}
}
// Check cache_block bin first
if ($block_cached = cache_get($block_cid, 'cache_block')) {
if (variable_get('authcache_debug_all', FALSE)) {
$block_cached->data['content'] .= '<!-- block cached -->';
}
$block_view = $block_cached->data;
}
else {
// Full bootstrap required for correct theming.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
init_theme();
$id = explode('-', $block_id, 2);
$block_view = module_invoke($id[0], 'block', 'view', $id[1]);
}
$return[$block_id] = $block_view;
}
return $return;
}