View source
<?php
function panelizer_perm() {
return array(
'administer panelizer',
'use panelizer',
);
}
function panelizer_theme() {
$items = array();
$items['panelizer_node_settings_page_form'] = array(
'arguments' => array(
'form' => NULL,
),
'file' => 'includes/admin.inc',
);
return $items;
}
function panelizer_menu() {
if (!defined('PANELS_REQUIRED_CTOOLS_API') || !module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
return array();
}
$settings_base = array(
'access arguments' => array(
'administer panelizer',
),
'file' => 'includes/admin.inc',
);
$items['admin/settings/panelizer'] = array(
'title' => 'Panelizer',
'description' => 'Configure panelizer availability and defaults',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'panelizer_settings_page_form',
),
'type' => MENU_NORMAL_ITEM,
) + $settings_base;
$items['admin/settings/panelizer/%/%'] = array(
'title callback' => 'panelizer_default_title_callback',
'title arguments' => array(
3,
4,
),
'page callback' => 'panelizer_allowed_content_page',
'page arguments' => array(
3,
4,
),
'type' => MENU_CALLBACK,
) + $settings_base;
$items['admin/settings/panelizer/%/%/allowed'] = array(
'title' => 'Available content',
'page callback' => 'panelizer_allowed_content_page',
'page arguments' => array(
3,
4,
),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
) + $settings_base;
$items['admin/settings/panelizer/%/%/list'] = array(
'title' => 'List defaults',
'access callback' => 'panelizer_has_choice_callback',
'access arguments' => array(
3,
4,
'',
),
'page callback' => 'panelizer_default_list_page',
'page arguments' => array(
3,
4,
),
'type' => MENU_LOCAL_TASK,
'weight' => -6,
) + $settings_base;
$tabs_base = array(
'access callback' => 'panelizer_has_no_choice_callback',
'access arguments' => array(
3,
4,
),
'page arguments' => array(
3,
4,
'default',
),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/admin.inc',
);
$items['admin/settings/panelizer/%/%/settings'] = array(
'title' => 'Settings',
'page callback' => 'panelizer_default_settings_page',
'weight' => -5,
) + $tabs_base;
$items['admin/settings/panelizer/%/%/context'] = array(
'title' => 'Contexts',
'page callback' => 'panelizer_default_context_page',
'weight' => -4,
) + $tabs_base;
$items['admin/settings/panelizer/%/%/layout'] = array(
'title' => 'Layout',
'page callback' => 'panelizer_default_layout_page',
'weight' => -3,
) + $tabs_base;
$items['admin/settings/panelizer/%/%/content'] = array(
'title' => 'Content',
'page callback' => 'panelizer_default_content_page',
'weight' => -2,
) + $tabs_base;
$subtabs_base = array(
'access callback' => 'panelizer_has_choice_callback',
'access arguments' => array(
3,
4,
5,
),
'page arguments' => array(
3,
4,
5,
),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/admin.inc',
);
$items['admin/settings/panelizer/%/%/%'] = array(
'title' => 'Settings',
'page callback' => 'panelizer_default_settings_page',
'title callback' => 'panelizer_default_name_title_callback',
'type' => MENU_CALLBACK,
) + $subtabs_base;
$items['admin/settings/panelizer/%/%/%/settings'] = array(
'title' => 'Settings',
'page callback' => 'panelizer_default_settings_page',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -5,
) + $subtabs_base;
$items['admin/settings/panelizer/%/%/%/context'] = array(
'title' => 'Contexts',
'page callback' => 'panelizer_default_context_page',
'weight' => -4,
) + $subtabs_base;
$items['admin/settings/panelizer/%/%/%/layout'] = array(
'title' => 'Layout',
'page callback' => 'panelizer_default_layout_page',
'weight' => -3,
) + $subtabs_base;
$items['admin/settings/panelizer/%/%/%/content'] = array(
'title' => 'Content',
'page callback' => 'panelizer_default_content_page',
'weight' => -2,
) + $subtabs_base;
$base = array(
'access callback' => 'panelizer_edit_node_callback',
'access arguments' => array(
1,
),
'page arguments' => array(
1,
),
'type' => MENU_LOCAL_TASK,
'file' => 'includes/node.inc',
);
$items['node/%node/panelizer'] = array(
'title' => 'Panelizer',
'access arguments' => array(
1,
FALSE,
),
'page callback' => 'panelizer_edit_node_settings_page',
'weight' => 11,
) + $base;
$items['node/%node/panelizer/settings'] = array(
'title' => 'Settings',
'page callback' => 'panelizer_edit_node_settings_page',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 11,
) + $base;
$items['node/%node/panelizer/context'] = array(
'title' => 'Context',
'page callback' => 'panelizer_edit_node_context_page',
'weight' => 12,
) + $base;
$items['node/%node/panelizer/layout'] = array(
'title' => 'Layout',
'page callback' => 'panelizer_edit_node_layout_page',
'weight' => 13,
) + $base;
$items['node/%node/panelizer/content'] = array(
'title' => 'Content',
'page callback' => 'panelizer_edit_node_content_page',
'weight' => 14,
) + $base;
return $items;
}
function panelizer_edit_node_callback($node, $check_for_default = TRUE) {
if (!user_access('use panelizer') || !panelizer_is_panelized('node', $node->type)) {
return FALSE;
}
if ($check_for_default && !panelizer_has_default('node', $node->type)) {
ctools_include('node', 'panelizer');
if (!panelizer_load_node_panelizer($node)) {
return FALSE;
}
}
return node_access('update', $node);
}
function panelizer_default_title_callback($type, $key) {
switch ($type) {
case 'node':
$name = node_get_types('name', $key);
return check_plain($name);
case 'user':
}
}
function panelizer_has_choice_callback($type, $key, $name = NULL) {
if (!user_access('administer panelizer')) {
return FALSE;
}
if ($name && !panelizer_load_default($type, $key, $name)) {
return FALSE;
}
return panelizer_has_choice($type, $key);
}
function panelizer_has_no_choice_callback($type, $key) {
if (!user_access('administer panelizer')) {
return FALSE;
}
$settings = variable_get('panelizer_defaults', array());
return !empty($settings[$type][$key]['status']) && !empty($settings[$type][$key]['default']) && empty($settings[$type][$key]['choice']);
}
function panelizer_nodeapi(&$node, $op) {
switch ($op) {
case 'delete':
return panelizer_node_delete($node);
case 'insert':
return panelizer_node_insert($node);
}
}
function panelizer_node_delete($node) {
ctools_include('node', 'panelizer');
$panelizer = panelizer_load_node_panelizer($node);
panelizer_delete_node_panelizer($panelizer);
}
function panelizer_node_insert($node) {
if (!empty($node->clone_from_original_nid)) {
$original_node = node_load($node->clone_from_original_nid);
ctools_include('node', 'panelizer');
$original_panelizer = panelizer_load_node_panelizer($original_node);
if (!empty($original_panelizer)) {
$cloned_panelizer = panelizer_clone_node_panelizer($original_panelizer, $node->nid);
panelizer_save_node_panelizer($cloned_panelizer);
}
}
}
function panelizer_get_type_key($default_name) {
$separator = ':';
return @explode($separator, $default_name, 2);
}
function panelizer_get_type_key_name($load_name) {
$separator = ':';
return @explode($separator, $load_name, 3);
}
function panelizer_is_panelized($type, $key) {
$settings = variable_get('panelizer_defaults', array());
return !empty($settings[$type][$key]['status']);
}
function panelizer_has_default($type, $key) {
$settings = variable_get('panelizer_defaults', array());
return !empty($settings[$type][$key]['status']) && !empty($settings[$type][$key]['default']);
}
function panelizer_has_choice($type, $key) {
$settings = variable_get('panelizer_defaults', array());
return !empty($settings[$type][$key]['status']) && !empty($settings[$type][$key]['default']) && !empty($settings[$type][$key]['choice']);
}
function panelizer_load_default_by_name($load_name, $default_anyway = FALSE) {
list($type, $key, $name) = panelizer_get_type_key_name($load_name);
return _panelizer_load_default($type, $key, $name, $load_name, $default_anyway);
}
function panelizer_load_default($type, $key, $name, $default_anyway = FALSE) {
$load_name = $type . ':' . $key . ':' . $name;
return _panelizer_load_default($type, $key, $name, $load_name, $default_anyway);
}
function _panelizer_load_default($type, $key, $name, $load_name, $default_anyway = FALSE) {
if (!$default_anyway && !panelizer_has_default($type, $key)) {
return;
}
ctools_include('export');
$panelizer = ctools_export_crud_load('panelizer_defaults', $load_name);
if (empty($panelizer)) {
$panelizer = ctools_export_crud_new('panelizer_defaults');
$panelizer->panelizer_type = $type;
$panelizer->panelizer_key = $key;
$panelizer->name = $load_name;
$panelizer->display = panelizer_get_default_display($type);
}
return $panelizer;
}
function panelizer_get_default_display($type) {
ctools_include($type, 'panelizer');
$function = 'panelizer_get_default_display_' . $type;
if (function_exists($function)) {
return $function();
}
}
function panelizer_load_display(&$object) {
if (empty($object->display)) {
if (!empty($object->did)) {
$object->display = panels_load_display($object->did);
}
else {
$object->display = new panels_display();
}
}
return $object->display;
}
function panelizer_export_save_callback(&$object) {
if (!empty($object->display)) {
panels_save_display($object->display);
$object->did = $object->display->did;
}
if ($object->export_type & EXPORT_IN_DATABASE) {
$update = array(
'pnid',
);
}
else {
$update = array();
$object->export_type = EXPORT_IN_DATABASE;
}
return drupal_write_record('panelizer_defaults', $object, $update);
}
function panelizer_export_export_callback($object, $indent) {
$output = ctools_export_object('panelizer_defaults', $object, $indent);
$display = panelizer_load_display($object);
$output .= panels_export_display($display, $indent);
$output .= $indent . '$panelizer->display = $display;' . "\n";
return $output;
}
function panelizer_export_delete_callback($object) {
if (!empty($object->did)) {
panels_delete_display($object->did);
}
db_query("DELETE FROM {panelizer_defaults} WHERE name = '%s'", $object->name);
}
function panelizer_context_cache_get($type, $key) {
ctools_include('object-cache');
$cache = ctools_object_cache_get('panelizer_context_cache', $type . ':' . $key);
if (!empty($cache)) {
$cache->cached = TRUE;
return $cache;
}
switch ($type) {
case 'default':
$panelizer = panelizer_load_default_by_name($key);
$panelizer->base_contexts = panelizer_get_base_context($panelizer->panelizer_type);
return $panelizer;
case 'node':
ctools_include('node', 'panelizer');
return panelizer_load_node_panelizer($key);
case 'user':
}
}
function panelizer_context_cache_set($type, $key, $object) {
ctools_include('object-cache');
ctools_object_cache_set('panelizer_context_cache', $type . ':' . $key, $object);
}
function panelizer_context_cache_clear($type, $key) {
ctools_include('object-cache');
ctools_object_cache_clear('panelizer_context_cache', $type . ':' . $key);
}
function panelizer_panels_cache_get($argument) {
ctools_include('object-cache');
list($type, $key) = explode(':', $argument, 2);
$cache = ctools_object_cache_get('panelizer_display_cache', $type . ':' . $key);
if (!empty($cache)) {
$cache->cached = TRUE;
switch ($type) {
case 'default':
$panelizer = panelizer_load_default_by_name($key);
$cache->display->context = panelizer_get_contexts($panelizer);
break;
case 'node':
ctools_include('node', 'panelizer');
$panelizer = panelizer_load_node_panelizer($key);
$node = node_load($key);
$cache->display->context = panelizer_get_contexts($panelizer, $node);
break;
case 'user':
}
return $cache;
}
switch ($type) {
case 'default':
$panelizer = panelizer_load_default_by_name($key);
$cache = new stdClass();
ctools_include('common', 'panels');
$cache->display = panelizer_load_display($panelizer);
$cache->display->context = panelizer_get_contexts($panelizer);
$cache->display->cache_key = "panelizer:{$type}:{$key}";
$cache->content_types = panels_common_get_allowed_types('panelizer_node:' . $type, $cache->display->context);
return $cache;
case 'node':
ctools_include('node', 'panelizer');
$panelizer = panelizer_load_node_panelizer($key);
$cache = new stdClass();
ctools_include('common', 'panels');
$cache->display = panelizer_load_display($panelizer);
$node = node_load($key);
$cache->display->context = panelizer_get_contexts($panelizer, $node);
$cache->display->cache_key = "panelizer:{$type}:{$key}";
$cache->content_types = panels_common_get_allowed_types('panelizer_node:' . $node->type, $cache->display->context);
return $cache;
case 'user':
}
}
function panelizer_panels_cache_set($argument, $cache) {
list($type, $key) = explode(':', $argument, 2);
ctools_include('object-cache');
ctools_object_cache_set('panelizer_display_cache', $type . ':' . $key, $cache);
}
function panelizer_panels_cache_clear($argument, $cache) {
list($type, $key) = explode(':', $argument, 2);
ctools_include('object-cache');
ctools_object_cache_clear('panelizer_display_cache', $type . ':' . $key);
}
function panelizer_panels_cache_save($argument, $cache) {
list($type, $key) = explode(':', $argument, 2);
switch ($type) {
case 'default':
$panelizer = panelizer_load_default($key);
$panelizer->display = $cache->display;
ctools_include('export');
ctools_export_crud_save('panelizer_defaults', $panelizer);
break;
case 'node':
ctools_include('node', 'panelizer');
$panelizer = panelizer_load_node_panelizer($key);
$panelizer->display = $cache->display;
panelizer_save_node_panelizer($panelizer);
break;
case 'user':
}
}
function panelizer_get_base_context($type, $object = NULL) {
ctools_include($type, 'panelizer');
$function = 'panelizer_get_base_context_' . $type;
if (function_exists($function)) {
return $function($object);
}
}
function panelizer_get_contexts($panelizer, $object = NULL) {
ctools_include('context');
if (empty($panelizer->base_contexts)) {
$panelizer->base_contexts = panelizer_get_base_context($panelizer->panelizer_type, $object);
}
return ctools_context_load_contexts($panelizer);
}
function panelizer_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'page_manager') {
return 'plugins/' . $plugin_type;
}
}
function panelizer_ctools_plugin_api($module, $api) {
if ($module == 'page_manager' && $api == 'pages_default') {
return array(
'version' => 1,
'path' => drupal_get_path('module', 'panelizer') . '/includes',
);
}
}
function panelizer_export_node_alter(&$node, $original_node, $method) {
}
function panelizer_panelizer_default_types_alter(&$types, $type) {
switch ($type) {
case 'node':
if (!empty($types['panel'])) {
unset($types['panel']);
}
break;
case 'user':
}
}
function panelizer_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'panelizer') . '/plugins/views',
);
}