authcache_panels.module in Authenticated User Page Caching (Authcache) 7.2
Authcache support for Panels.
File
modules/authcache_panels/authcache_panels.moduleView source
<?php
/**
* @file
* Authcache support for Panels.
*/
/**
* Return TRUE when a valid authcache configuration exists for the given pane.
*/
function authcache_panels_pane_fragment_enabled($pane) {
$config = _authcache_panels_pane_get_options($pane);
$fragment_id = authcache_panels_pane_fragment_id($pane);
return !empty($config['status']) && $fragment_id;
}
/**
* Return fragment renderer for the given panel pane.
*/
function authcache_panels_pane_fragment($pane) {
$config = _authcache_panels_pane_get_options($pane);
$granularity = authcache_p13n_config_cache_granularity($config);
return array(
'fragment' => array(
'#class' => 'AuthcachePanelsPaneFragment',
),
'bootstrap phase' => DRUPAL_BOOTSTRAP_FULL,
'cache maxage' => authcache_p13n_config_cache_maxage($config),
'cache granularity' => $granularity,
'admin name' => t('Pane at position %position on panel %panel', array(
'%position' => $pane->position,
'%panel' => $pane->panel,
)),
'admin clients' => $config['clients'],
'panels pane id' => $pane->pid,
);
}
/**
* Implements hook_ctools_plugin_directory().
*/
function authcache_panels_ctools_plugin_directory($module, $plugin) {
if ($module === 'panels') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_panels_pane_content_alter().
*/
function authcache_panels_panels_pane_content_alter($content, $pane, $args, $context, $renderer, $display) {
if ($content && authcache_page_is_cacheable() && authcache_panels_pane_fragment_enabled($pane)) {
$config = _authcache_panels_pane_get_options($pane);
$fragment = array(
'#theme' => 'authcache_p13n_fragment',
'#fragment' => authcache_panels_pane_fragment_id($pane),
'#clients' => $config['clients'],
'#fallback' => $config['fallback'],
);
if (!is_array($content->content)) {
$markup = !empty($content->content) ? $content->content : '';
$content->content = array(
'#markup' => $markup,
);
}
authcache_p13n_attach($content->content, $fragment);
}
}
/**
* Implements hook_panels_display_save().
*/
function authcache_panels_panels_display_save($display) {
authcache_p13n_request_router_rebuild();
}
/**
* Return options for the given pane.
*/
function _authcache_panels_pane_get_options($pane) {
if (!empty($pane->cache) && $pane->cache['method'] === 'authcache_panels') {
$settings = array();
if (!empty($pane->cache['settings']['authcache'])) {
$settings = $pane->cache['settings']['authcache'];
}
return $settings + authcache_p13n_config_defaults();
}
return FALSE;
}
/**
* Return a fragment id for the given pane.
*/
function authcache_panels_pane_fragment_id($pane) {
if (!empty($pane->cache) && $pane->cache['method'] === 'authcache_panels') {
return 'panels/' . str_replace('_', '-', $pane->cache['settings']['machine_name']);
}
return FALSE;
}
/**
* Given a pane, generate an initial machine name.
*/
function authcache_panels_pane_machine_name_generate($display, $pid) {
ctools_include('content');
$suffix = '';
for ($attempt = 0; $attempt < 100; $attempt++) {
$pane = $display->content[$pid];
$content_type = ctools_get_content_type($pane->type);
$title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $display->context);
if (!$title) {
$title = t('Deleted/missing content type @type', array(
'@type' => $pane->type,
));
}
if ($attempt > 0) {
$suffix = '-' . $attempt;
}
$machine_name = preg_replace('/[^a-z0-9-]+/', '_', strtolower($title));
$machine_name = substr($machine_name, 0, 64 - strlen($suffix)) . $suffix;
if (!authcache_panels_pane_machine_name_exists($machine_name)) {
return $machine_name;
}
}
}
/**
* Return TRUE if the given machine name exists.
*/
function authcache_panels_pane_machine_name_exists($machine_name) {
return authcache_p13n_request_exists('frag/panels/' . str_replace('_', '-', $machine_name));
}
Functions
Name | Description |
---|---|
authcache_panels_ctools_plugin_directory | Implements hook_ctools_plugin_directory(). |
authcache_panels_panels_display_save | Implements hook_panels_display_save(). |
authcache_panels_panels_pane_content_alter | Implements hook_panels_pane_content_alter(). |
authcache_panels_pane_fragment | Return fragment renderer for the given panel pane. |
authcache_panels_pane_fragment_enabled | Return TRUE when a valid authcache configuration exists for the given pane. |
authcache_panels_pane_fragment_id | Return a fragment id for the given pane. |
authcache_panels_pane_machine_name_exists | Return TRUE if the given machine name exists. |
authcache_panels_pane_machine_name_generate | Given a pane, generate an initial machine name. |
_authcache_panels_pane_get_options | Return options for the given pane. |