View source
<?php
function esi_panels__esi_pane_prepare($component_key) {
list($theme, $did, $pid) = explode(':', $component_key);
$args = array_slice(func_get_args(), 1);
$cache_mode = array_pop($args);
$url = array_pop($args);
if ($did) {
$display = panels_load_display($did);
$pane = $display->content[$pid];
}
else {
ctools_include('export');
$panelizer_defaults = ctools_export_load_object('panelizer_defaults');
foreach ($panelizer_defaults as $name => $panelizer_default) {
if (!empty($panelizer_default->display->content)) {
$panes = array_keys($panelizer_default->display->content);
if (in_array($pid, $panes)) {
$display = $panelizer_default->display;
$pane = $panelizer_default->display->content[$pid];
break;
}
}
}
}
$pane->esi_meta = array(
'display_contexts' => array(),
);
if (!empty($pane->configuration['context'])) {
$task_name = array_shift($args);
list($task, $subtask) = _esi_panels__get_task_identifier($task_name);
$pane->esi_meta['task'] = $task;
$pane->esi_meta['subtask'] = $subtask;
}
$pane->esi_meta += array(
'display' => $display,
'theme' => $theme,
'display_args' => $args,
'url' => base64_decode($url),
);
esi_panels__restore_context($pane);
return $pane;
}
function esi_panels__restore_context(&$pane) {
global $theme;
$theme = $pane->esi_meta['theme'];
$_GET['q'] = $pane->esi_meta['url'];
$_SERVER['REQUEST_URI'] = $pane->esi_meta['url'];
drupal_static_reset('drupal_get_destination');
if (!empty($pane->configuration['context'])) {
ctools_include('context');
ctools_include('context-task-handler');
$task = page_manager_get_task($pane->esi_meta['task']);
$subtask = empty($pane->esi_meta['subtask']) ? '' : page_manager_get_task_subtask($task, $pane->esi_meta['subtask']);
$base_context_arguments = esi_panels__get_base_context_arguments($pane->esi_meta['task'], $pane->esi_meta['subtask'], $pane->esi_meta['display_args']);
$base_contexts = ctools_context_handler_get_task_contexts($task, $subtask, $base_context_arguments);
$contexts = array();
$handlers = page_manager_load_sorted_handlers($task, $subtask ? $subtask['name'] : '', TRUE);
$id = ctools_context_handler_get_render_handler($task, $subtask, $handlers, $base_contexts, $pane->esi_meta['display_args']);
if ($id) {
$handler = $handlers[$id];
$contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
}
$pane->esi_meta['display_contexts'] = $contexts;
}
}
function esi_panels__esi_pane_render($pane) {
ctools_include('content');
$content_type = ctools_get_content_type($pane->type);
$content = ctools_content_render($pane->type, $pane->subtype, $pane->configuration, array(), $pane->esi_meta['display_args'], $pane->esi_meta['display_contexts']);
if (empty($content)) {
return '';
}
foreach (module_implements('panels_pane_content_alter') as $module) {
$function = $module . '_panels_pane_content_alter';
$function($content, $pane, $pane->esi_meta['display_args'], $pane->esi_meta['display_contexts']);
}
esi_panels_set_http_headers($pane);
if (!empty($pane->css['css_id'])) {
$content->css_id = check_plain($pane->css['css_id']);
}
if (!empty($pane->css['css_class'])) {
$content->css_class = check_plain($pane->css['css_class']);
}
if (!empty($content->content)) {
if (!empty($pane->style['style'])) {
$style = panels_get_style($pane->style['style']);
if (isset($style) && isset($style['render pane'])) {
$output = theme($style['render pane'], array(
'content' => $content,
'pane' => $pane,
'display' => $this->display,
'style' => $style,
'settings' => $pane->style['settings'],
));
if (isset($output)) {
return $output;
}
}
}
return theme('panels_pane', array(
'content' => $content,
'pane' => $pane,
'display' => $pane->esi_meta['display'],
));
}
}
function esi_panels_set_http_headers($pane) {
$headers = array();
if (isset($pane->cache['settings'])) {
if ($ttl = $pane->cache['settings']['esi_ttl']) {
$headers[] = array(
'Cache-Control',
"private, max-age={$ttl}",
);
}
}
drupal_alter('esi_panels_cache_headers', $headers, $pane);
foreach ($headers as $header) {
drupal_add_http_header($header[0], $header[1]);
}
}
function esi_panels__esi_pane_flush() {
}