function context_reaction_block::render_ajax in Context 6.3
Same name and namespace in other branches
- 6 plugins/context_reaction_block.inc \context_reaction_block::render_ajax()
- 7.3 plugins/context_reaction_block.inc \context_reaction_block::render_ajax()
Block renderer for AJAX requests. Triggered when $_GET['context_block'] is set. See ->execute() for how this is called.
1 call to context_reaction_block::render_ajax()
- context_reaction_block::execute in plugins/
context_reaction_block.inc - Execute.
File
- plugins/
context_reaction_block.inc, line 513
Class
- context_reaction_block
- Expose blocks as context reactions.
Code
function render_ajax($param) {
// Besure the page isn't a 404 or 403.
$headers = drupal_set_header();
// Support for Pressflow drupal_set_header.
if (!is_array($headers)) {
$headers = explode("\n", $headers);
}
foreach ($headers as $header) {
if (strpos($header, "404 Not Found") !== FALSE || strpos($header, "403 Forbidden") !== FALSE) {
return;
}
}
// Set the header right away. This will inform any players in the stack
// that we are in the middle of responding to an AJAX request.
drupal_set_header('Content-Type: text/javascript; charset=utf-8');
if (strpos($param, ',') !== FALSE) {
list($bid, $context) = explode(',', $param);
list($module, $delta) = explode('-', $bid, 2);
// Check token to make sure user has access to block.
if (!(user_access('context ajax block access') || $this
->context_block_ajax_rendering_allowed($bid))) {
echo drupal_to_js(array(
'status' => 0,
));
exit;
}
// Ensure $bid is valid.
$info = $this
->get_blocks();
if (isset($info[$bid])) {
$block = $info[$bid];
$block->context = $context;
$block->region = '';
$block = $this
->build_block($block);
if (empty($block->content)) {
$block->content = "<div class='context-block-empty'>" . t('This block appears empty when displayed on this page.') . "</div>";
}
$css = array();
// On behalf of panels we try to load some css, but we don't support
// panels inside panels currently.
if ($block->module == 'panels_mini') {
$panel = panels_mini_load($block->delta);
$layout = panels_get_layout($panel->display->layout);
if (!empty($layout['css'])) {
if (file_exists(path_to_theme() . '/' . $layout['css'])) {
$css[] = path_to_theme() . '/' . $layout['css'];
}
else {
$css[] = $layout['path'] . '/' . $layout['css'];
}
}
}
echo drupal_to_js(array(
'status' => 1,
'block' => theme('context_block_editable_block', $block),
'css' => $css,
));
exit;
}
}
echo drupal_to_js(array(
'status' => 0,
));
exit;
}