a33c086bc8acf1586498130e59595ac3a7d4ad92
[project/zen.git] / zen-internals / 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 * We are simply using this hook as a convenient time to do some related work.
13 */
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);
21 }
22 }
23
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);
27
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
30 // warnings per hour.
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);
34 }
35
36 // Keep track of all the base themes.
37 static $base_themes = array();
38 $base_themes[] = $theme;
39
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';
47 }
48 if (function_exists($theme . '_preprocess_' . $hook)) {
49 $existing[$hook]['preprocess functions'][] = $theme . '_preprocess_' . $hook;
50 }
51 // Now add the process functions.
52 foreach ($base_themes as $base_theme) {
53 if (function_exists($base_theme . '_process')) {
54 $existing[$hook]['preprocess functions'][] = $base_theme . '_process';
55 }
56 if (function_exists($base_theme . '_process_' . $hook)) {
57 $existing[$hook]['preprocess functions'][] = $base_theme . '_process_' . $hook;
58 }
59 }
60 }
61 }
62
63 // Return nothing.
64 return array();
65 }
66
67 /**
68 * Return the theme settings' default values from the .info and save them into the database.
69 *
70 * @param $theme
71 * The name of theme.
72 */
73 function zen_theme_get_default_settings($theme) {
74 $themes = list_themes();
75
76 // Get the default values from the .info file.
77 $defaults = !empty($themes[$theme]->info['settings']) ? $themes[$theme]->info['settings'] : array();
78
79 if (!empty($defaults)) {
80 // Get the theme settings saved in the database.
81 $settings = theme_get_settings($theme);
82 // Don't save the toggle_node_info_ variables.
83 if (module_exists('node')) {
84 foreach (node_get_types() as $type => $name) {
85 unset($settings['toggle_node_info_' . $type]);
86 }
87 }
88 // Save default theme settings.
89 variable_set(
90 str_replace('/', '_', 'theme_' . $theme . '_settings'),
91 array_merge($defaults, $settings)
92 );
93 // If the active theme has been loaded, force refresh of Drupal internals.
94 if (!empty($GLOBALS['theme_key'])) {
95 theme_get_setting('', TRUE);
96 }
97 }
98
99 // Return the default settings.
100 return $defaults;
101 }