0cf209198997a38244652b1125bf06f44c27263c
[project/zen.git] / zen / template.theme-registry.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Contains infrequently used theme registry build functions.
7 */
8
9 /**
10 * Implements HOOK_theme().
11 *
12 * The Zen base theme uses this function as a work-around for a bug in Drupal
13 * 6.0-6.4: #252430 (Allow BASETHEME_ prefix in preprocessor function names).
14 *
15 * Sub-themes Also use this function by calling it from their HOOK_theme() in
16 * order to get around a design limitation in Drupal 6: #249532 (Allow subthemes
17 * to have preprocess hooks without tpl files.)
18 *
19 * @param $existing
20 * An array of existing implementations that may be used for override purposes.
21 * @param $type
22 * What 'type' is being processed.
23 * @param $theme
24 * The actual name of theme that is being being checked.
25 * @param $path
26 * The directory path of the theme or module, so that it doesn't need to be looked up.
27 */
28 function _zen_theme(&$existing, $type, $theme, $path) {
29 // Each theme has two possible preprocess functions that can act on a hook.
30 // This function applies to every hook.
31 $functions[0] = $theme . '_preprocess';
32 // Inspect the preprocess functions for every hook in the theme registry.
33 // @TODO: When PHP 5 becomes required (Zen 7.x), use the following faster
34 // implementation: foreach ($existing AS $hook => &$value) {}
35 foreach (array_keys($existing) AS $hook) {
36 // Each theme has two possible preprocess functions that can act on a hook.
37 // This function only applies to this hook.
38 $functions[1] = $theme . '_preprocess_' . $hook;
39 foreach ($functions AS $key => $function) {
40 // Add any functions that are not already in the registry.
41 if (function_exists($function) && !in_array($function, $existing[$hook]['preprocess functions'])) {
42 // We add the preprocess function to the end of the existing list.
43 $existing[$hook]['preprocess functions'][] = $function;
44 }
45 }
46 }
47
48 // Compute the conditional stylesheets.
49 if (!module_exists('conditional_styles')) {
50 include_once './' . drupal_get_path('theme', 'zen') . '/template.conditional-styles.inc';
51 // _conditional_styles_theme() only needs to be run once.
52 if ($theme == 'zen') {
53 _conditional_styles_theme($existing, $type, $theme, $path);
54 }
55 }
56
57 // Since we are rebuilding the theme registry and the theme settings' default
58 // values may have changed, make sure they are saved in the database properly.
59 zen_theme_get_default_settings($theme);
60
61 // If we are auto-rebuilding the theme registry, warn about feature.
62 if (theme_get_setting('zen_rebuild_registry')) {
63 drupal_set_message(t('The theme registry has been rebuilt. <a href="!link">Turn off</a> this feature on production websites.', array('!link' => base_path() . 'admin/build/themes/settings/' . $GLOBALS['theme'])), 'warning');
64 }
65
66 // Since we modify the $existing cache directly, return nothing.
67 return array();
68 }
69
70 /**
71 * Return the theme settings' default values from the .info and save them into the database.
72 *
73 * @param $theme
74 * The name of theme.
75 */
76 function zen_theme_get_default_settings($theme) {
77 $themes = list_themes();
78
79 // Get the default values from the .info file.
80 $defaults = !empty($themes[$theme]->info['settings']) ? $themes[$theme]->info['settings'] : array();
81
82 if (!empty($defaults)) {
83 // Get the theme settings saved in the database.
84 $settings = theme_get_settings($theme);
85 // Don't save the toggle_node_info_ variables.
86 if (module_exists('node')) {
87 foreach (node_get_types() as $type => $name) {
88 unset($settings['toggle_node_info_' . $type]);
89 }
90 }
91 // Save default theme settings.
92 variable_set(
93 str_replace('/', '_', 'theme_' . $theme . '_settings'),
94 array_merge($defaults, $settings)
95 );
96 // If the active theme has been loaded, force refresh of Drupal internals.
97 if (!empty($GLOBALS['theme_key'])) {
98 theme_get_setting('', TRUE);
99 }
100 }
101
102 // Return the default settings.
103 return $defaults;
104 }