6 * Contains infrequently used theme registry build functions.
10 * Implements HOOK_theme().
12 * We are simply using this hook as a convenient time to do some related work.
14 function _zen_theme(&$existing, $type, $theme, $path) {
15 // Compute the conditional stylesheets.
16 if (!module_exists('conditional_styles')) {
17 include_once
'./' .
_zen_path() .
'/zen-internals/template.conditional-styles.inc';
18 // _conditional_styles_theme() only needs to be run once.
19 if ($theme == 'zen') {
20 _conditional_styles_theme($existing, $type, $theme, $path);
24 // Since we are rebuilding the theme registry and the theme settings' default
25 // values may have changed, make sure they are saved in the database properly.
26 zen_theme_get_default_settings($theme);
28 // If we are auto-rebuilding the theme registry, warn about the feature.
29 // Always display the warning in the admin section, otherwise limit to three
31 if (function_exists('user_access') && user_access('administer site configuration') && theme_get_setting('zen_rebuild_registry') && $theme == $GLOBALS['theme'] && (arg(0) == 'admin' || flood_is_allowed($GLOBALS['theme'] .
'_rebuild_registry_warning', 3))) {
32 flood_register_event($GLOBALS['theme'] .
'_rebuild_registry_warning');
33 drupal_set_message(t('For easier theme development, the theme registry is being rebuilt on every page request. It is <em>extremely</em> important to <a href="!link">turn off this feature</a> on production websites.', array('!link' => url('admin/build/themes/settings/' .
$GLOBALS['theme']))), 'warning', FALSE
);
36 // Keep track of all the base themes.
37 static
$base_themes = array();
38 $base_themes[] = $theme;
40 // Add a "process" phase to come after the "preprocess" functions.
41 if ($type == 'theme') {
42 foreach (array_keys($existing) as
$hook) {
43 // Normally, preprocess functions are added to the registry after
44 // HOOK_theme() returns, but if we add them first, they won't be re-added.
45 if (function_exists($theme .
'_preprocess')) {
46 $existing[$hook]['preprocess functions'][] = $theme .
'_preprocess';
48 if (function_exists($theme .
'_preprocess_' .
$hook)) {
49 $existing[$hook]['preprocess functions'][] = $theme .
'_preprocess_' .
$hook;
51 // Add base theme process functions.
52 foreach ($base_themes as
$base_theme) {
53 if (function_exists($base_theme .
'_process')) {
54 $existing[$hook]['preprocess functions'][] = $base_theme .
'_process';
56 if (function_exists($base_theme .
'_process_' .
$hook)) {
57 $existing[$hook]['preprocess functions'][] = $base_theme .
'_process_' .
$hook;
60 // Add the theme process functions.
61 if (function_exists($theme .
'_process')) {
62 $existing[$hook]['preprocess functions'][] = $theme .
'_process';
64 if (function_exists($theme .
'_process_' .
$hook)) {
65 $existing[$hook]['preprocess functions'][] = $theme .
'_process_' .
$hook;
70 // Manipulations only to be done by the base theme.
71 if ($theme == 'zen') {
72 // Insert zen_show_blocks_discovery() before template_preprocess_page().
73 $existing['page']['preprocess functions'] = array_merge(array('zen_show_blocks_discovery'), $existing['page']['preprocess functions']);
75 // The base theme registers region.tpl.php.
78 'arguments' => array('elements' => NULL
),
79 'pattern' => 'region_',
80 'path' => drupal_get_path('theme', 'zen') .
'/templates',
81 'template' => 'region',
82 // We manually register the preprocess and process functions, since
83 // Drupal won't auto-register template_preprocess or process functions.
84 'preprocess functions' => array(
85 'template_preprocess',
87 'zen_preprocess_region',
94 // Else return nothing.
99 * Return the theme settings' default values from the .info and save them into the database.
104 function zen_theme_get_default_settings($theme) {
105 $themes = list_themes();
107 // Get the default values from the .info file.
108 $defaults = !empty($themes[$theme]->info
['settings']) ?
$themes[$theme]->info
['settings'] : array();
110 if (!empty($defaults)) {
111 // Merge the defaults with the theme settings saved in the database.
112 $settings = array_merge($defaults, variable_get('theme_'.
$theme .
'_settings', array()));
113 // Save the settings back to the database.
114 variable_set('theme_'.
$theme .
'_settings', $settings);
115 // If the active theme has been loaded, force refresh of Drupal internals.
116 if (!empty($GLOBALS['theme_key'])) {
117 theme_get_setting('', TRUE
);
121 // Return the default settings.