View source
<?php
define('PANELS_REQUIRED_CTOOLS_API', '2.0.9');
define('PANELS_VERSION', '7.x-3.8');
define('PANELS_TITLE_FIXED', 0);
define('PANELS_TITLE_NONE', 1);
define('PANELS_TITLE_PANE', 2);
function panels_api_version() {
return array(
3,
1,
);
}
function panels_theme() {
if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
return array();
}
$theme = array();
$theme['panels_layout_link'] = array(
'variables' => array(
'title' => NULL,
'id' => NULL,
'image' => NULL,
'link' => NULL,
'class' => NULL,
'options' => NULL,
),
);
$theme['panels_layout_icon'] = array(
'variables' => array(
'id' => NULL,
'image' => NULL,
'title' => NULL,
),
);
$theme['panels_pane'] = array(
'variables' => array(
'content' => array(),
'pane' => array(),
'display' => array(),
),
'path' => drupal_get_path('module', 'panels') . '/templates',
'template' => 'panels-pane',
);
$theme['panels_common_content_list'] = array(
'variables' => array(
'display' => NULL,
),
'file' => 'includes/common.inc',
);
$theme['panels_render_display_form'] = array(
'render element' => 'element',
);
$theme['panels_dashboard'] = array(
'variables' => array(),
'path' => drupal_get_path('module', 'panels') . '/templates',
'file' => '../includes/callbacks.inc',
'template' => 'panels-dashboard',
);
$theme['panels_dashboard_link'] = array(
'variables' => array(
'link' => array(),
),
'path' => drupal_get_path('module', 'panels') . '/templates',
'file' => '../includes/callbacks.inc',
'template' => 'panels-dashboard-link',
);
$theme['panels_dashboard_block'] = array(
'variables' => array(
'block' => array(),
),
'path' => drupal_get_path('module', 'panels') . '/templates',
'file' => '../includes/callbacks.inc',
'template' => 'panels-dashboard-block',
);
$theme['panels_add_content_modal'] = array(
'variables' => array(
'renderer' => NULL,
'categories' => array(),
'region' => NULL,
'category' => NULL,
'column_count' => 2,
),
'path' => drupal_get_path('module', 'panels') . '/templates',
'file' => '../includes/add-content.inc',
'template' => 'panels-add-content-modal',
);
$theme['panels_add_content_link'] = array(
'variables' => array(
'renderer' => NULL,
'region' => NULL,
'content_type' => NULL,
),
'path' => drupal_get_path('module', 'panels') . '/templates',
'file' => '../includes/add-content.inc',
'template' => 'panels-add-content-link',
);
ctools_include('plugins', 'panels');
$layouts = panels_get_layouts();
foreach ($layouts as $name => $data) {
foreach (array(
'theme',
'admin theme',
) as $callback) {
if (!empty($data[$callback])) {
$theme[$data[$callback]] = array(
'variables' => array(
'css_id' => NULL,
'content' => NULL,
'settings' => NULL,
'display' => NULL,
'layout' => NULL,
'renderer' => NULL,
),
'path' => $data['path'],
'file' => $data['file'],
);
if (!function_exists("theme_{$data['theme']}")) {
$theme[$data[$callback]]['template'] = str_replace('_', '-', $data[$callback]);
$theme[$data[$callback]]['file'] = $data['file'];
}
}
}
}
$styles = panels_get_styles();
foreach ($styles as $name => $data) {
if (!empty($data['render pane'])) {
$theme[$data['render pane']] = array(
'variables' => array(
'content' => NULL,
'pane' => NULL,
'display' => NULL,
'style' => NULL,
'settings' => NULL,
),
'path' => $data['path'],
'file' => $data['file'],
);
}
if (!empty($data['render region'])) {
$theme[$data['render region']] = array(
'variables' => array(
'display' => NULL,
'owner_id' => NULL,
'panes' => NULL,
'settings' => NULL,
'region_id' => NULL,
'style' => NULL,
),
'path' => $data['path'],
'file' => $data['file'],
);
}
if (!empty($data['hook theme'])) {
if (is_array($data['hook theme'])) {
$theme += $data['hook theme'];
}
elseif (function_exists($data['hook theme'])) {
$data['hook theme']($theme, $data);
}
}
}
return $theme;
}
function panels_menu() {
if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
return array();
}
$items = array();
$items['panels/ajax'] = array(
'access arguments' => array(
'access content',
),
'page callback' => 'panels_ajax_router',
'theme callback' => 'ajax_base_page_theme',
'delivery callback' => 'ajax_deliver',
'type' => MENU_CALLBACK,
);
$admin_base = array(
'file' => 'includes/callbacks.inc',
'access arguments' => array(
'use panels dashboard',
),
);
$items['admin/structure/panels'] = array(
'title' => 'Panels',
'page callback' => 'panels_admin_page',
'description' => 'Get a bird\'s eye view of items related to Panels.',
) + $admin_base;
$items['admin/structure/panels/dashboard'] = array(
'title' => 'Dashboard',
'page callback' => 'panels_admin_page',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
) + $admin_base;
$items['admin/structure/panels/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'panels_admin_settings_page',
),
'type' => MENU_LOCAL_TASK,
) + $admin_base;
$items['admin/structure/panels/settings/general'] = array(
'title' => 'General',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'panels_admin_settings_page',
),
'access arguments' => array(
'administer page manager',
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
) + $admin_base;
if (module_exists('page_manager')) {
$items['admin/structure/panels/settings/panel-page'] = array(
'title' => 'Panel pages',
'page callback' => 'panels_admin_panel_context_page',
'type' => MENU_LOCAL_TASK,
'weight' => -10,
) + $admin_base;
}
ctools_include('plugins', 'panels');
$layouts = panels_get_layouts();
foreach ($layouts as $name => $data) {
if (!empty($data['hook menu'])) {
if (is_array($data['hook menu'])) {
$items += $data['hook menu'];
}
elseif (function_exists($data['hook menu'])) {
$data['hook menu']($items, $data);
}
}
}
return $items;
}
function panels_edit_cache_load($cache_key) {
ctools_include('display-edit', 'panels');
ctools_include('plugins', 'panels');
ctools_include('ajax');
ctools_include('modal');
ctools_include('context');
return panels_edit_cache_get($cache_key);
}
function panels_init() {
if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
if (user_access('administer site configuration')) {
drupal_set_message(t('Panels is enabled but CTools is out of date. All Panels modules are disabled until CTools is updated. See the status page for more information.'), 'error');
}
return;
}
ctools_add_css('panels', 'panels');
}
function panels_permission() {
return array(
'use panels dashboard' => array(
'title' => t("Use Panels Dashboard"),
'description' => t('Allows a user to access the <a href="@url">Panels Dashboard</a>.', array(
'@url' => url('admin/structure/panels'),
)),
),
'view pane admin links' => array(
'title' => t("View administrative links on Panel panes"),
'description' => "",
),
'administer pane access' => array(
'title' => t("Configure access settings on Panel panes"),
'description' => t("Access rules (often also called visibility rules) can be configured on a per-pane basis. This permission allows users to configure those settings."),
),
'use panels in place editing' => array(
'title' => t("Use the Panels In-Place Editor"),
'description' => t("Allows a user to utilize Panels' In-Place Editor."),
),
'change layouts in place editing' => array(
'title' => t("Change layouts with the Panels In-Place Editor"),
'description' => t("Allows a user to change layouts with the IPE."),
),
'bypass access in place editing' => array(
'title' => t("Bypass access checks when using Panels In-Place Editor"),
'description' => t("Allows using IPE even if user does not have additional permissions granted by other modules."),
'restrict access' => TRUE,
),
'administer advanced pane settings' => array(
'title' => t("Configure advanced settings on Panel panes"),
'description' => "",
),
'administer panels layouts' => array(
'title' => t("Administer Panels layouts"),
'description' => t("Allows a user to administer exported Panels layout plugins & instances."),
),
'administer panels styles' => array(
'title' => t("Administer Panels styles"),
'description' => t("DEPRECATED: Modules using this permission should use specific style permissions. See Issue #2329419 for more info."),
),
'administer panels display styles' => array(
'title' => t("Administer Panels display styles"),
'description' => t("Allows a user to administer the styles of Panel displays."),
),
'administer panels pane styles' => array(
'title' => t("Administer Panels pane styles"),
'description' => t("Allows a user to administer the styles of Panel panes."),
),
'administer panels region styles' => array(
'title' => t("Administer Panels region styles"),
'description' => t("Allows a user to administer the styles of Panel regions."),
),
'use panels caching features' => array(
'title' => t("Configure caching settings on Panels"),
'description' => t("Allows a user to configure caching on Panels displays and panes."),
),
'use panels locks' => array(
'title' => t('Use panel locks'),
'description' => t('Allows a user to lock and unlock panes in a panel display.'),
),
'use ipe with page manager' => array(
'title' => t("Use the Panels In-Place Editor with Page Manager"),
'description' => t('Allows users with access to the In-Place editor to administer page manager pages. This permission is only needed for users without "use page manager" access.'),
),
);
}
function panels_flush_caches() {
if (db_table_exists('cache_panels')) {
return array(
'cache_panels',
);
}
}
function panels_ctools_plugin_directory($module, $plugin) {
if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
return;
}
if ($module == 'ctools' && $plugin == 'cache') {
return;
}
if ($module == 'page_manager' || $module == 'panels' || $module == 'ctools' || $module == 'stylizer') {
if ($module == 'ctools' && $plugin == 'cache') {
return;
}
return 'plugins/' . $plugin;
}
}
function panels_ctools_plugin_type() {
return array(
'layouts' => array(
'load themes' => TRUE,
'process' => 'panels_layout_process',
'child plugins' => TRUE,
),
'styles' => array(
'load themes' => TRUE,
'process' => 'panels_plugin_styles_process',
'child plugins' => TRUE,
),
'cache' => array(),
'display_renderers' => array(
'classes' => array(
'renderer',
),
),
'panels_storage' => array(),
);
}
function panels_layout_process(&$plugin) {
$plugin += array(
'category' => t('Miscellaneous'),
'description' => '',
);
}
function panels_ctools_plugin_api($owner, $api) {
if ($owner == 'panels' && $api == 'styles') {
return array(
'version' => 2.0,
);
}
if ($owner == 'panels' && $api == 'pipelines') {
return array(
'version' => 1,
'path' => drupal_get_path('module', 'panels') . '/includes',
);
}
}
function panels_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'panels') . '/plugins/views',
);
}
function panels_plugin_styles_process(&$plugin, $info) {
$plugin += array(
'weight' => 0,
);
$compliant_modules = ctools_plugin_api_info('panels', 'styles', 2.0, 2.0);
$plugin['version'] = empty($compliant_modules[$plugin['module']]) ? 1.0 : $compliant_modules[$plugin['module']]['version'];
}
function panels_ctools_style_base_types() {
return array(
'region' => array(
'title' => t('Panel region'),
'preview' => 'panels_stylizer_region_preview',
'theme variables' => array(
'settings' => NULL,
'class' => NULL,
'content' => NULL,
),
),
'pane' => array(
'title' => t('Panel pane'),
'preview' => 'panels_stylizer_pane_preview',
'theme variables' => array(
'settings' => NULL,
'content' => NULL,
'pane' => NULL,
'display' => NULL,
),
),
);
}
function panels_stylizer_lipsum() {
return <<<LIPSUM
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at
velit dolor. Donec egestas tellus sit amet urna rhoncus adipiscing. Proin
nec porttitor sem. Maecenas aliquam, purus nec tempus dignissim, nulla arcu
aliquam diam, non tincidunt massa ante vel dolor. Aliquam sapien sapien,
tincidunt id tristique at, pretium sagittis libero.
</p>
<p>
Nulla facilisi. Curabitur lacinia, tellus sed tristique consequat, diam
lorem scelerisque felis, at dictum purus augue facilisis lorem. Duis
pharetra dignissim rutrum. Curabitur ac elit id dui dapibus tincidunt.
Nulla eget sem quam, non eleifend eros. Cras porttitor tempus lectus ac
scelerisque. Curabitur vehicula bibendum lorem, vitae ornare ligula
venenatis ut.
</p>
LIPSUM;
}
function panels_stylizer_region_preview($plugin, $settings) {
ctools_stylizer_add_css($plugin, $settings);
return theme($plugin['theme'], array(
'settings' => $settings,
'class' => ctools_stylizer_get_css_class($plugin, $settings),
'content' => panels_stylizer_lipsum(),
));
}
function panels_stylizer_pane_preview($plugin, $settings) {
ctools_stylizer_add_css($plugin, $settings);
$pane = new stdClass();
$content = new stdClass();
$content->title = t('Lorem ipsum');
$content->content = panels_stylizer_lipsum();
$content->type = 'dummy';
$content->subtype = 'dummy';
$content->css_class = ctools_stylizer_get_css_class($plugin, $settings);
$display = new panels_display();
if (!empty($plugin['theme'])) {
return theme($plugin['theme'], array(
'settings' => $settings,
'content' => $content,
'pane' => $pane,
'display' => $display,
));
}
else {
return theme('panels_pane', array(
'content' => $content,
'pane' => $pane,
'display' => $display,
));
}
}
function panels_edit($display, $destination = NULL, $content_types = NULL, $title = FALSE) {
ctools_include('display-edit', 'panels');
ctools_include('ajax');
ctools_include('plugins', 'panels');
return _panels_edit($display, $destination, $content_types, $title);
}
function panels_edit_layout($display, $finish, $destination = NULL, $allowed_layouts = NULL) {
ctools_include('display-layout', 'panels');
ctools_include('plugins', 'panels');
return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
}
class panels_display {
public $args = array();
public $content = array();
public $panels = array();
public $incoming_content = NULL;
public $css_id = NULL;
public $context = array();
public $did = 'new';
public $renderer = 'standard';
public function add_pane(&$pane, $location = NULL) {
if (empty($location)) {
$location = $pane->panel;
}
else {
$pane->panel = $location;
}
$pane->uuid = ctools_uuid_generate();
$pane->pid = 'new-' . $pane->uuid;
$this->content[$pane->pid] =& $pane;
$this->panels[$location][] = $pane->pid;
}
public function duplicate_pane($pid, $location = FALSE) {
$pane = $this
->clone_pane($pid);
$this
->add_pane($pane, $location);
}
public function clone_pane($pid) {
$pane = clone $this->content[$pid];
$pane->uuid = ctools_uuid_generate();
return $pane;
}
public function get_title() {
switch ($this->hide_title) {
case PANELS_TITLE_NONE:
return '';
case PANELS_TITLE_PANE:
return isset($this->stored_pane_title) ? $this->stored_pane_title : '';
case PANELS_TITLE_FIXED:
case FALSE:
if (!empty($this->title)) {
return filter_xss_admin(ctools_context_keyword_substitute($this->title, array(), $this->context));
}
return NULL;
}
}
public function render($renderer = NULL) {
$layout = panels_get_layout($this->layout);
if (!$layout) {
return NULL;
}
if (!is_object($renderer)) {
$renderer = panels_get_renderer_handler(!empty($renderer) ? $renderer : $this->renderer, $this);
if (!$renderer) {
return NULL;
}
}
$output = '';
foreach (module_implements('panels_pre_render') as $module) {
$function = $module . '_panels_pre_render';
$output .= $function($this, $renderer);
}
$output .= $renderer
->render();
foreach (module_implements('panels_post_render') as $module) {
$function = $module . '_panels_post_render';
$output .= $function($this, $renderer);
}
return $output;
}
public function access($op, $account = NULL) {
global $user;
if (!$account) {
$account = $user;
}
if ($account->uid == 1) {
return TRUE;
}
if (!in_array($op, array(
'create',
'read',
'update',
'delete',
'change layout',
))) {
return FALSE;
}
if (empty($this->storage_type) || empty($this->storage_id)) {
return FALSE;
}
if ($this->storage_type == 'unknown') {
return FALSE;
}
$storage_plugin = panels_get_panels_storage_plugin($this->storage_type);
if (!$storage_plugin) {
return FALSE;
}
$access_callback = panels_plugin_get_function('panels_storage', $storage_plugin, 'access callback');
if (!$access_callback) {
return FALSE;
}
return $access_callback($this->storage_type, $this->storage_id, $op, $account);
}
}
function panels_new_display() {
ctools_include('export');
$display = ctools_export_new_object('panels_display', FALSE);
$display->did = 'new';
return $display;
}
function panels_new_pane($type, $subtype, $set_defaults = FALSE) {
ctools_include('export');
$pane = ctools_export_new_object('panels_pane', FALSE);
$pane->pid = 'new';
$pane->type = $type;
$pane->subtype = $subtype;
if ($set_defaults) {
ctools_include('content');
$content_type = ctools_get_content_type($type);
$content_subtype = ctools_content_get_subtype($content_type, $subtype);
$pane->configuration = ctools_content_get_defaults($content_type, $content_subtype);
}
drupal_alter('panels_new_pane', $pane);
return $pane;
}
function panels_load_displays($dids) {
$displays = array();
if (empty($dids) || !is_array($dids)) {
return $displays;
}
$result = db_query("SELECT * FROM {panels_display} WHERE did IN (:dids)", array(
':dids' => $dids,
));
ctools_include('export');
foreach ($result as $obj) {
$displays[$obj->did] = ctools_export_unpack_object('panels_display', $obj);
}
$result = db_query("SELECT * FROM {panels_pane} WHERE did IN (:dids) ORDER BY did, panel, position", array(
':dids' => $dids,
));
foreach ($result as $obj) {
$pane = ctools_export_unpack_object('panels_pane', $obj);
$displays[$pane->did]->panels[$pane->panel][] = $pane->pid;
$displays[$pane->did]->content[$pane->pid] = $pane;
}
return $displays;
}
function panels_load_display($did) {
$displays = panels_load_displays(array(
$did,
));
if (!empty($displays)) {
return array_shift($displays);
}
}
function panels_save_display(&$display) {
$update = isset($display->did) && is_numeric($display->did) ? array(
'did',
) : array();
if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) {
$display->uuid = ctools_uuid_generate();
}
drupal_write_record('panels_display', $display, $update);
$pids = array();
if ($update) {
$result = db_query("SELECT pid FROM {panels_pane} WHERE did = :did", array(
':did' => $display->did,
));
foreach ($result as $pane) {
$pids[$pane->pid] = $pane->pid;
}
}
ctools_include('plugins', 'panels');
ctools_include('content');
foreach ($display->panels as $id => $panes) {
$position = 0;
$new_panes = array();
foreach ((array) $panes as $pid) {
if (!isset($display->content[$pid])) {
continue;
}
$pane = $display->content[$pid];
$type = ctools_get_content_type($pane->type);
$pane->position = $position++;
$pane->did = $display->did;
$old_pid = $pane->pid;
if (empty($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
$pane->uuid = ctools_uuid_generate();
}
drupal_write_record('panels_pane', $pane, is_numeric($pid) ? array(
'pid',
) : array());
if ($pane->pid == $old_pid) {
module_invoke_all('panels_pane_update', $pane);
}
else {
module_invoke_all('panels_pane_insert', $pane);
}
if ($pane->pid != $old_pid) {
unset($display->content[$pid]);
$display->content[$pane->pid] = $pane;
if (isset($display->title_pane) && $display->title_pane == $old_pid) {
$display->title_pane = $pane->pid;
db_update('panels_display')
->fields(array(
'title_pane' => $pane->pid,
))
->condition('did', $display->did)
->execute();
}
}
$new_panes[] = $pane->pid;
if (isset($pids[$pane->pid])) {
unset($pids[$pane->pid]);
}
}
$display->panels[$id] = $new_panes;
}
if (!empty($pids)) {
module_invoke_all('panels_pane_delete', $pids);
db_delete('panels_pane')
->condition('pid', $pids)
->execute();
}
panels_clear_cached_content($display);
module_invoke_all('panels_display_save', $display);
$watchdog_args = array(
'%did' => $display->did,
);
if (!empty($display->title)) {
$watchdog_args['%title'] = $display->title;
watchdog('content', 'Panels: saved display "%title" with display id %did', $watchdog_args, WATCHDOG_NOTICE);
}
else {
watchdog('content', 'Panels: saved display with id %did', $watchdog_args, WATCHDOG_NOTICE);
}
return $display;
}
function panels_delete_display($display) {
if (is_object($display)) {
$did = $display->did;
}
else {
$did = $display;
}
module_invoke_all('panels_delete_display', $did);
db_delete('panels_display')
->condition('did', $did)
->execute();
db_delete('panels_pane')
->condition('did', $did)
->execute();
}
function panels_export_display($display, $prefix = '') {
ctools_include('export');
if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) {
$display->uuid = ctools_uuid_generate();
}
$display->did = 'new-' . $display->uuid;
$output = ctools_export_object('panels_display', $display, $prefix);
$output .= $prefix . '$display->content = array()' . ";\n";
$output .= $prefix . '$display->panels = array()' . ";\n";
$panels = array();
$title_pid = 0;
if (!empty($display->content)) {
$region_counters = array();
foreach ($display->content as $pane) {
if (!isset($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
$pane->uuid = ctools_uuid_generate();
}
$pid = 'new-' . $pane->uuid;
if ($pane->pid == $display->title_pane) {
$title_pid = $pid;
}
$pane->pid = $pid;
$output .= ctools_export_object('panels_pane', $pane, $prefix);
$output .= $prefix . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
if (!isset($region_counters[$pane->panel])) {
$region_counters[$pane->panel] = 0;
}
$output .= $prefix . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ . '] = \'' . $pane->pid . "';\n";
}
}
$output .= $prefix . '$display->hide_title = ';
switch ($display->hide_title) {
case PANELS_TITLE_FIXED:
$output .= 'PANELS_TITLE_FIXED';
break;
case PANELS_TITLE_NONE:
$output .= 'PANELS_TITLE_NONE';
break;
case PANELS_TITLE_PANE:
$output .= 'PANELS_TITLE_PANE';
break;
}
$output .= ";\n";
$output .= $prefix . '$display->title_pane =' . " '{$title_pid}';\n";
return $output;
}
function panels_render_display(&$display, $renderer = NULL) {
ctools_include('plugins', 'panels');
ctools_include('context');
if (!empty($display->context)) {
if ($form_context = ctools_context_get_form($display->context)) {
$form_context->form['#theme'] = 'panels_render_display_form';
if (empty($form_context->form['#theme_wrappers']) || !in_array('form', $form_context->form['#theme_wrappers'])) {
$form_context->form['#theme_wrappers'][] = 'form';
}
$form_context->form['#display'] =& $display;
return $form_context->form;
}
}
return $display
->render($renderer);
}
function theme_panels_render_display_form($vars) {
return $vars['element']['#display']
->render();
}
function panels_print_layout_icon($id, $layout, $title = NULL) {
ctools_add_css('panels_admin', 'panels');
$file = $layout['path'] . '/' . $layout['icon'];
return theme('panels_layout_icon', array(
'id' => $id,
'image' => theme('image', array(
'path' => $file,
'alt' => strip_tags($layout['title']),
'title' => strip_tags($layout['description']),
)),
'title' => $title,
));
}
function theme_panels_layout_icon($vars) {
$id = $vars['id'];
$image = $vars['image'];
$title = $vars['title'];
$output = '<div class="layout-icon">';
$output .= $image;
if ($title) {
$output .= '<div class="caption">' . $title . '</div>';
}
$output .= '</div>';
return $output;
}
function theme_panels_layout_link($vars) {
$options = !empty($vars['options']) ? $vars['options'] : array();
if (!isset($options['attributes']['class'])) {
$options['attributes']['class'] = array();
}
$options['attributes']['class'] = array_merge($options['attributes']['class'], $vars['class']);
$content = $vars['image'] . '<span>' . $vars['title'] . '</span>';
return l($content, $vars['link'], $options + array(
'html' => TRUE,
));
}
function panels_print_layout_link($id, $layout, $link, $options = array(), $current_layout = FALSE) {
if (isset($options['query']['q'])) {
unset($options['query']['q']);
}
$class = array(
'layout-link',
);
if ($current_layout == $id) {
$options['attributes']['class'][] = 'current-layout-link';
$class[] = 'current-layout';
}
ctools_add_css('panels_admin', 'panels');
$file = $layout['path'] . '/' . $layout['icon'];
$image = theme('image', array(
'path' => $file,
));
return theme('panels_layout_link', array(
'title' => $layout['title'],
'image' => $image,
'link' => $link,
'class' => $class,
'options' => $options,
));
}
function panels_get_legacy_state() {
static $legacy = NULL;
if (!isset($legacy)) {
ctools_include('legacy', 'panels');
$legacy = new PanelsLegacyState();
}
return $legacy;
}
function panels_get_current_page_display($change = NULL) {
static $display = NULL;
if ($change) {
$display = $change;
}
return $display;
}
function template_preprocess_panels_pane(&$vars) {
$content =& $vars['content'];
$vars['contextual_links'] = array();
$vars['classes_array'] = array();
$vars['admin_links'] = '';
if (module_exists('contextual') && user_access('access contextual links')) {
$links = array();
if (!empty($content->admin_links)) {
$links += $content->admin_links;
}
if (is_array($content->content) && isset($content->content['#contextual_links'])) {
$element = array(
'#type' => 'contextual_links',
'#contextual_links' => $content->content['#contextual_links'],
);
unset($content->content['#contextual_links']);
if (is_array($content->content)) {
$element['#element'] = $content->content;
}
$element = contextual_pre_render_links($element);
if (!empty($element['#links'])) {
$links += $element['#links'];
}
}
if ($links) {
$build = array(
'#prefix' => '<div class="contextual-links-wrapper">',
'#suffix' => '</div>',
'#theme' => 'links__contextual',
'#links' => $links,
'#attributes' => array(
'class' => array(
'contextual-links',
),
),
'#attached' => array(
'library' => array(
array(
'contextual',
'contextual-links',
),
),
),
);
$vars['classes_array'][] = 'contextual-links-region';
$vars['admin_links'] = drupal_render($build);
}
}
$vars['classes_array'][] = 'panel-pane';
$vars['id'] = '';
ctools_include('cleanstring');
$type_class = $content->type ? 'pane-' . ctools_cleanstring($content->type, array(
'lower case' => TRUE,
)) : '';
$subtype_class = $content->subtype ? 'pane-' . ctools_cleanstring($content->subtype, array(
'lower case' => TRUE,
)) : '';
$vars['classes_array'][] = $type_class;
if ($type_class != $subtype_class) {
$vars['classes_array'][] = $subtype_class;
}
if (!empty($content->content)) {
if (!empty($content->css_id)) {
$vars['id'] = ' id="' . $content->css_id . '"';
}
if (!empty($content->css_class)) {
$vars['classes_array'][] = $content->css_class;
}
}
$base = 'panels_pane';
$delimiter = '__';
$vars['theme_hook_suggestions'][] = $base . $delimiter . $content->type;
$vars['theme_hook_suggestions'][] = $base . $delimiter . strtr(ctools_cleanstring($content->type, array(
'lower case' => TRUE,
)), '-', '_') . $delimiter . strtr(ctools_cleanstring($content->subtype, array(
'lower case' => TRUE,
)), '-', '_');
$vars['pane_prefix'] = !empty($content->pane_prefix) ? $content->pane_prefix : '';
$vars['pane_suffix'] = !empty($content->pane_suffix) ? $content->pane_suffix : '';
$vars['title'] = !empty($content->title) ? $content->title : '';
$vars['title_heading'] = !empty($content->title_heading) ? $content->title_heading : variable_get('override_title_heading', 'h2');
$vars['title_attributes_array']['class'][] = 'pane-title';
$vars['feeds'] = !empty($content->feeds) ? implode(' ', $content->feeds) : '';
$vars['links'] = !empty($content->links) ? theme('links', array(
'links' => $content->links,
)) : '';
$vars['more'] = '';
if (!empty($content->more)) {
if (empty($content->more['title'])) {
$content->more['title'] = t('more');
}
$vars['more'] = l($content->more['title'], $content->more['href'], $content->more);
}
if (!empty($content->attributes)) {
$vars['attributes_array'] = array_merge($vars['attributes_array'], $content->attributes);
}
$vars['content'] = !empty($content->content) ? $content->content : '';
}
function panels_ajax_router() {
$args = func_get_args();
if (count($args) < 3) {
return MENU_NOT_FOUND;
}
ctools_include('display-edit', 'panels');
ctools_include('plugins', 'panels');
ctools_include('ajax');
ctools_include('modal');
ctools_include('context');
ctools_include('content');
$plugin_name = array_shift($args);
$method = array_shift($args);
$cache_key = array_shift($args);
$plugin = panels_get_display_renderer($plugin_name);
if (!$plugin) {
$plugin = panels_get_display_renderer('editor');
}
$cache = panels_edit_cache_get($cache_key);
if (empty($cache)) {
return MENU_ACCESS_DENIED;
}
$renderer = panels_get_renderer_handler($plugin, $cache->display);
if (!$renderer) {
return MENU_ACCESS_DENIED;
}
$method = 'ajax_' . str_replace('-', '_', $method);
if (!method_exists($renderer, $method)) {
return MENU_NOT_FOUND;
}
$renderer->cache =& $cache;
ctools_include('cleanstring');
$renderer->clean_key = ctools_cleanstring($cache_key);
$op = $renderer
->get_panels_storage_op_for_ajax($method);
if (!$cache->display
->access($op)) {
return MENU_ACCESS_DENIED;
}
$output = call_user_func_array(array(
$renderer,
$method,
), $args);
if (empty($output) && !empty($renderer->commands)) {
return array(
'#type' => 'ajax',
'#commands' => $renderer->commands,
);
}
else {
return $output;
}
}
function panels_cache_get($obj, $did, $skip_cache = FALSE) {
ctools_include('object-cache');
ctools_include('context');
return ctools_object_cache_get($obj, 'panels_display:' . $did, $skip_cache);
}
function panels_cache_set($obj, $did, $cache) {
ctools_include('object-cache');
return ctools_object_cache_set($obj, 'panels_display:' . $did, $cache);
}
function panels_cache_clear($obj, $did) {
ctools_include('object-cache');
return ctools_object_cache_clear($obj, 'panels_display:' . $did);
}
function panels_edit_cache_get_default(&$display, $content_types = NULL, $title = FALSE) {
if (empty($content_types)) {
$content_types = ctools_content_get_available_types();
}
$display->cache_key = $display->did;
panels_cache_clear('display', $display->did);
$cache = new stdClass();
$cache->display =& $display;
$cache->content_types = $content_types;
$cache->display_title = $title;
panels_edit_cache_set($cache);
return $cache;
}
function panels_edit_cache_get($cache_key) {
if (strpos($cache_key, ':') !== FALSE) {
list($module, $argument) = explode(':', $cache_key, 2);
return module_invoke($module, 'panels_cache_get', $argument);
}
return panels_cache_get('display', $cache_key);
}
function panels_edit_cache_set($cache) {
$cache_key = $cache->display->cache_key;
if (strpos($cache_key, ':') !== FALSE) {
list($module, $argument) = explode(':', $cache_key, 2);
return module_invoke($module, 'panels_cache_set', $argument, $cache);
}
return panels_cache_set('display', $cache_key, $cache);
}
function panels_edit_cache_save($cache) {
$cache_key = $cache->display->cache_key;
if (strpos($cache_key, ':') !== FALSE) {
list($module, $argument) = explode(':', $cache_key, 2);
if (function_exists($module . '_panels_cache_save')) {
return module_invoke($module, 'panels_cache_save', $argument, $cache);
}
}
return panels_save_display($cache->display);
}
function panels_edit_cache_clear($cache) {
$cache_key = $cache->display->cache_key;
if (strpos($cache_key, ':') !== FALSE) {
list($module, $argument) = explode(':', $cache_key, 2);
if (function_exists($module . '_panels_cache_clear')) {
return module_invoke($module, 'panels_cache_clear', $argument, $cache);
}
}
return panels_cache_clear('display', $cache_key);
}
function panels_edit_cache_break_lock($cache) {
if (empty($cache->locked)) {
return;
}
$cache_key = $cache->display->cache_key;
if (strpos($cache_key, ':') !== FALSE) {
list($module, $argument) = explode(':', $cache_key, 2);
if (function_exists($module . '_panels_cache_break_lock')) {
return module_invoke($module, 'panels_cache_break_lock', $argument, $cache);
}
}
}
function panel_context_panels_cache_get($key) {
ctools_include('common', 'panels');
ctools_include('context');
ctools_include('context-task-handler');
$plugin = page_manager_get_task_handler('panel_context');
list($task_name, $handler_name, $args, $q) = explode('::', $key, 4);
$page = page_manager_get_page_cache($task_name);
if (isset($page->display_cache[$handler_name])) {
return $page->display_cache[$handler_name];
}
if ($handler_name) {
$handler =& $page->handlers[$handler_name];
}
else {
$handler =& $page->new_handler;
}
$cache = new stdClass();
$task = page_manager_get_task($page->task_id);
$arguments = array();
if ($args) {
$arguments = explode('\\', $args);
$contexts = ctools_context_handler_get_task_contexts($task, $page->subtask, $arguments);
$contexts = ctools_context_handler_get_handler_contexts($contexts, $handler);
}
else {
$contexts = ctools_context_handler_get_all_contexts($page->task, $page->subtask, $handler);
}
$cache->display =& panels_panel_context_get_display($handler);
$cache->display->context = $contexts;
$cache->display->cache_key = 'panel_context:' . $key;
$cache->content_types = panels_common_get_allowed_types('panels_page', $cache->display->context);
$cache->display_title = TRUE;
$cache->locked = $page->locked;
return $cache;
}
function _panel_context_panels_cache_get_page_cache($key, $cache) {
list($task_name, $handler_name, $args, $q) = explode('::', $key, 4);
$page = page_manager_get_page_cache($task_name);
$page->display_cache[$handler_name] = $cache;
if ($handler_name) {
$page->handlers[$handler_name]->conf['display'] = $cache->display;
$page->handler_info[$handler_name]['changed'] |= PAGE_MANAGER_CHANGED_CACHED;
}
else {
$page->new_handler->conf['display'] = $cache->display;
}
return $page;
}
function panel_context_panels_cache_set($key, $cache) {
$page = _panel_context_panels_cache_get_page_cache($key, $cache);
page_manager_set_page_cache($page);
}
function panel_context_panels_cache_clear($key, $cache) {
$page = _panel_context_panels_cache_get_page_cache($key, $cache);
page_manager_clear_page_cache($page->task_name);
}
function panel_context_panels_cache_save($key, $cache) {
$page = _panel_context_panels_cache_get_page_cache($key, $cache);
page_manager_save_page_cache($page);
}
function panel_context_panels_cache_break_lock($key, $cache) {
$page = _panel_context_panels_cache_get_page_cache($key, $cache);
ctools_object_cache_clear_all('page_manager_page', $page->task_name);
}
function panels_page_wizard_panels_cache_get($key) {
ctools_include('page-wizard');
ctools_include('context');
$wizard_cache = page_manager_get_wizard_cache($key);
if (isset($wizard_cache->display_cache)) {
return $wizard_cache->display_cache;
}
ctools_include('common', 'panels');
$cache = new stdClass();
$cache->display = $wizard_cache->display;
$cache->display->context = !empty($wizard_cache->context) ? $wizard_cache->context : array();
$cache->display->cache_key = 'panels_page_wizard:' . $key;
$cache->content_types = panels_common_get_allowed_types('panels_page', $cache->display->context);
$cache->display_title = TRUE;
return $cache;
}
function panels_page_wizard_panels_cache_set($key, $cache) {
ctools_include('page-wizard');
$wizard_cache = page_manager_get_wizard_cache($key);
$wizard_cache->display_cache = $cache;
page_manager_set_wizard_cache($wizard_cache);
}
function panels_default_page_manager_handlers_alter(&$handlers) {
foreach ($handlers as &$handler) {
if ($handler->handler == 'panel_context') {
$display =& $handler->conf['display'];
if (empty($display->storage_type)) {
$display->storage_type = 'page_manager';
$display->storage_id = $handler->name;
}
}
}
}
function panels_default_page_manager_pages_alter(&$pages) {
foreach ($pages as &$page) {
panels_default_page_manager_handlers_alter($page->default_handlers);
}
}
function panels_goto($destination) {
if (!is_array($destination)) {
return drupal_goto($destination);
}
else {
$destination += array(
'query' => NULL,
'fragment' => NULL,
'http_response_code' => NULL,
);
return drupal_goto($destination['path'], $destination['query'], $destination['fragment'], $destination['http_response_code']);
}
}
function panels_print_layout($layout, $content, $meta = 'standard') {
ctools_include('plugins', 'panels');
$display = panels_new_display();
$display->layout = is_array($layout) ? $layout['name'] : $layout;
$display->content = $content;
$renderer = panels_get_renderer_handler('simple', $display);
$renderer->meta_location = $meta;
return $renderer
->render();
}
function _panels_builder_filter($layout) {
return empty($layout['builder']);
}
function panels_get_pane_links_alter(&$links, $pane, $content_type) {
if ($pane->type === "block") {
$prefixed_name = $pane->subtype;
$exploded_subtype = explode('-', $pane->subtype);
$subtype_prefix = $exploded_subtype[0];
$subtype_prefix_hyphen = $exploded_subtype[0] . '-';
$name_of_block = preg_replace("/^{$subtype_prefix_hyphen}/", '', $prefixed_name, 1);
if (substr($prefixed_name, 0, 10) === "menu-menu-") {
$name_of_block = substr($prefixed_name, 5);
$links['top'][] = array(
'title' => t('Edit block'),
'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
$links['top'][] = array(
'title' => t('Edit menu links'),
'href' => url('admin/structure/menu/manage/' . $name_of_block, array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
}
elseif (substr($prefixed_name, 0, 5) === "menu-") {
$name_of_block = substr($prefixed_name, 5);
$links['top'][] = array(
'title' => t('Edit block'),
'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
$links['top'][] = array(
'title' => t('Edit menu links'),
'href' => url('admin/structure/menu/manage/' . $name_of_block, array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
}
elseif (substr($prefixed_name, 0, 7) === "system-") {
$name_of_block = substr($prefixed_name, 7);
$names_of_system_menus = menu_list_system_menus();
$links['top'][] = array(
'title' => t('Edit block'),
'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
if (array_key_exists($name_of_block, $names_of_system_menus)) {
$links['top'][] = array(
'title' => t('Edit menu links'),
'href' => url('admin/structure/menu/manage/' . $name_of_block, array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
}
}
else {
$links['top'][] = array(
'title' => t('Edit block'),
'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array(
'absolute' => TRUE,
)),
'attributes' => array(
'target' => array(
'_blank',
),
),
);
}
}
}
function panels_get_path($file, $base_path = FALSE, $module = 'panels') {
$output = $base_path ? base_path() : '';
return $output . drupal_get_path('module', $module) . '/' . $file;
}
function panels_preprocess_html(&$vars) {
$panel_body_css =& drupal_static('panel_body_css', array());
if (!empty($panel_body_css['body_classes_to_remove'])) {
$classes_to_remove = array_filter(explode(' ', $panel_body_css['body_classes_to_remove']), 'strlen');
foreach ($vars['classes_array'] as $key => $css_class) {
if (in_array($css_class, $classes_to_remove)) {
unset($vars['classes_array'][$key]);
}
}
}
if (!empty($panel_body_css['body_classes_to_add'])) {
$vars['classes_array'][] = check_plain($panel_body_css['body_classes_to_add']);
}
}