array(
'file' => 'themekey_admin.inc',
'render element' => 'form',
),
'themekey_debug_messages' => array(
'template' => 'themekey-debug-messages',
'variables' => array('messages' => array()),
),
'themekey_page_cache_icon' => array(
'file' => 'themekey_admin.inc',
'variables' => array('page_cache_support' => 0),
),
);
return $items;
}
/**
* Implements hook_permission().
*/
function themekey_permission() {
return array(
'administer theme assignments' => array(
'title' => t('administer theme assignments'),
'description' => t('TODO Add a description for \'administer theme assignments\''),
),
'administer themekey settings' => array(
'title' => t('administer themekey settings'),
'description' => t('TODO Add a description for \'administer themekey settings\''),
),
);
}
/**
* Implements hook_menu().
*/
function themekey_menu() {
$items = array();
$items['admin/config/user-interface/themekey'] = array(
'title' => 'ThemeKey',
'description' => 'Set up rules to switch the site\'s appearance (theme) dynamically depending on Drupal paths or different properties.',
'access callback' => 'user_access',
'access arguments' => array('administer theme assignments'),
'file' => 'themekey_admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('themekey_rule_chain_form'),
);
$items['admin/config/user-interface/themekey/properties'] = array(
'title' => 'Theme Switching Rule Chain',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/config/user-interface/themekey/properties/delete'] = array(
'title' => 'Delete ThemeKey Property',
'page callback' => 'drupal_get_form',
'page arguments' => array('themekey_admin_delete_rule_confirm', 1),
'access callback' => 'user_access',
'access arguments' => array('administer theme assignments'),
'file' => 'themekey_admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/user-interface/themekey/settings'] = array(
'title' => 'Settings',
'access callback' => 'user_access',
'access arguments' => array('administer themekey settings'),
'file' => 'themekey_admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('themekey_settings_form'),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/config/user-interface/themekey/settings/general'] = array(
'title' => 'General',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
return $items;
}
/**
* Implements hook_custom_theme().
*
* Here happens all the magic of ThemeKey.
* ThemeKey detects if any Theme Switching Rule matches
* the current request and returns a custom theme.
*/
function themekey_custom_theme() {
if (!defined('THEMEKEY_PAGECACHE_UNSUPPORTED')) {
define('THEMEKEY_PAGECACHE_UNSUPPORTED', 0);
define('THEMEKEY_PAGECACHE_SUPPORTED', 1);
define('THEMEKEY_PAGECACHE_TIMEBASED', 2);
}
$custom_theme_called = &drupal_static('themekey_custom_theme_called', FALSE);
$custom_theme_called = TRUE;
$custom_theme = &drupal_static('themekey_custom_theme', '');
// don't change theme when administer blocks or during cron run executed by cron.php or drush
if (strpos($_GET['q'], 'admin/structure/block') !== 0 && strpos($_SERVER['SCRIPT_FILENAME'], 'cron.php') === FALSE && strpos($_SERVER['SCRIPT_FILENAME'], 'drush.php') === FALSE) {
if (!$custom_theme) {
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'themekey') . '/themekey_base.inc';
$theme_candidate = themekey_match_rules();
// If no theme has been triggered but a theme
// is in the user's session, use that theme.
if (!$theme_candidate && !empty($_SESSION['themekey_theme'])
&& (!$custom_theme || $custom_theme == variable_get('theme_default', 'bartik'))) {
$theme_candidate = $_SESSION['themekey_theme'];
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('ThemeKey Debug: No rule triggered a different theme. Reusing last theme from users session: %custom_theme', array('%custom_theme' => $theme_candidate));
}
}
// We have a theme, apply it
if (!empty($theme_candidate) && $theme_candidate != 'default') {
if ((user_is_logged_in() && variable_get('themekey_theme_maintain', 0)) ||
(!user_is_logged_in() && variable_get('themekey_theme_maintain_anonymous', 0))) {
$_SESSION['themekey_theme'] = $theme_candidate;
}
elseif (!empty($_SESSION['themekey_theme'])) {
unset($_SESSION['themekey_theme']);
}
$custom_theme = $theme_candidate;
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Switching theme to %custom_theme.', array('%custom_theme' => $custom_theme));
}
}
elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if ($custom_theme) {
// REVIEW
// static rules set $theme_candidate to 'default and $custom_theme directly
themekey_set_debug_message('$custom_theme has been set to %custom_theme during rule matching.', array('%custom_theme' => $custom_theme));
}
else {
themekey_set_debug_message('Using default theme.');
}
}
}
}
elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if (strpos($_GET['q'], 'admin/structure/block') !== 0) {
themekey_set_debug_message('Rule checking disabled on block configuration.');
}
}
if (variable_get('themekey_debug_show_property_values', FALSE) && module_exists('themekey_debug')) {
themekey_debug_properties();
}
if ($custom_theme && variable_get('themekey_override_custom_theme', 0)) {
// TODO initialize theme right here
}
return $custom_theme;
}
/**
* Implements hook_custom_theme().
*
* Detects if hook_custom_theme() has been skipped because
* a different module already initialized the theme engine.
*/
function themekey_init() {
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if (path_is_admin($_GET['q']) && variable_get('admin_theme', '0')) {
themekey_set_debug_message('%admin_theme is configured as administration theme at !link. This setting is more powerful than a corresponding ThemeKey rule.',
array('%admin_theme' => variable_get('admin_theme', '0'), '!link' => l(t('!path', array('!path' => 'admin/appearance')), 'admin/appearance')), TRUE, TRUE);
}
$custom_theme_called = &drupal_static('themekey_custom_theme_called', FALSE);
if (!$custom_theme_called) {
themekey_set_debug_message('Skipped rule checking because another module already initialized the theme engine. $theme has been set to %theme.
This seems to be a bug. Visit !link and help us improving other modules.', array('%theme' => $theme, '!link' => l('drupal.org/node/754970', 'http://drupal.org/node/754970')), TRUE, TRUE);
}
else {
global $theme;
$custom_theme = &drupal_static('themekey_custom_theme', '');
if (!empty($custom_theme) && 'default' != $custom_theme && $theme != $custom_theme) {
themekey_set_debug_message('Theme switching to custom theme %custom_theme did not work because theme has been set to %theme by another module.', array('%custom_theme' => $custom_theme, '%theme' => $theme), TRUE, TRUE);
}
}
}
}
/**
* Implements hook_form_node_form_alter().
*
* Detects if custom theme has been skipped because
* the adminstration theme is used for node editing.
*/
function themekey_form_node_form_alter() {
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if (variable_get('node_admin_theme', '0')) {
themekey_set_debug_message('As configured at !link adding or editing a node will use the administration theme %admin_theme.',
array('%admin_theme' => variable_get('admin_theme', '0'), '!link' => l(t('!path', array('!path' => 'admin/appearance')), 'admin/appearance')), TRUE, TRUE);
}
}
}
/**
* Implements hook_themekey_load_validators().
*/
function themekey_themekey_load_validators() {
module_load_include('inc', 'themekey', 'themekey_validators');
}
/**
* Implements hook_help().
*/
function themekey_help($path, $arg) {
$text_1 = t('For every page request Drupal steps through this Theme Switching Rule Chain until an activated rule matches or it reaches the end. If a rule matches the theme associated to this rule will be applied to render the requested page.');
switch ($path) {
case 'admin/help#themekey':
module_load_include('inc', 'themekey', 'themekey_help');
return '
' . t('ThemeKey allows you to define simple or sophisticated Theme Switching Rules. Using these rules you are able to use a different theme depending on current path, taxonomy terms, language, node type and many many more properties. It can also be easily extended to support additional properties as exposed by other modules.') . '
' . '' . $text_1 . '
' . drupal_render(drupal_get_form('themekey_help_tutorials_form', FALSE)) . drupal_render(drupal_get_form('themekey_help_examples_form', FALSE)) . drupal_render(drupal_get_form('themekey_help_properties_form', FALSE)) . drupal_render(drupal_get_form('themekey_help_operators_form', FALSE)); case 'admin/config/user-interface/themekey': module_load_include('inc', 'themekey', 'themekey_help'); return '' . $text_1 . '
' . t('To get an idea how to get started you might have a look at the !tutorials_link.', array('!tutorials_link' => l(t('tutorials'), 'admin/help/themekey'))) . '