/[drupal]/contributions/theme-settings.php
ViewVC logotype

Contents of /contributions/theme-settings.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Oct 21 13:39:20 2009 UTC (5 weeks, 2 days ago) by mcrittenden
Branch: MAIN
File MIME type: text/x-php
Initial commit
1 <?php
2
3 function newhorizon_settings($saved_settings, $subtheme_defaults = array()) {
4
5 // Get the default values from the .info file.
6 $defaults = newhorizon_theme_get_default_settings('newhorizon');
7
8 // Merge the saved variables and their default values.
9 $settings = array_merge($defaults, $saved_settings);
10
11 /**
12 * Create the form using Forms API.
13 */
14
15 $form['newhorizon_wireframe'] = array(
16 '#type' => 'checkbox',
17 '#title' => t('Display borders around main layout elements'),
18 '#default_value' => $settings['newhorizon_wireframe'],
19 '#description' => t('<a href="!link">Wireframes</a> are useful when prototyping a website.', array('!link' => 'http://www.boxesandarrows.com/view/html_wireframes_and_prototypes_all_gain_and_no_pain')),
20 '#prefix' => '<strong>' . t('Wireframes:') . '</strong>',
21 );
22
23 $form['newhorizon_block_editing'] = array(
24 '#type' => 'checkbox',
25 '#title' => t('Show block editing on hover'),
26 '#description' => t('When hovering over a block, privileged users will see block editing links.'),
27 '#default_value' => $settings['newhorizon_block_editing'],
28 '#prefix' => '<strong>' . t('Block Edit Links:') . '</strong>',
29 );
30
31 $form['themedev']['newhorizon_rebuild_registry'] = array(
32 '#type' => 'checkbox',
33 '#title' => t('Rebuild theme registry on every page.'),
34 '#default_value' => $settings['newhorizon_rebuild_registry'],
35 '#description' => t('During theme development, it can be very useful to continuously <a href="!link">rebuild the theme registry</a>. WARNING: this is a huge performance penalty and must be turned off on production websites.', array('!link' => 'http://drupal.org/node/173880#theme-registry')),
36 '#prefix' => '<strong>' . t('Theme registry:') . '</strong>',
37 );
38
39 $form['themedev']['newhorizon_registry_reminder'] = array(
40 '#type' => 'checkbox',
41 '#title' => t('Display reminder to turn off registry rebuild feature.'),
42 '#default_value' => $settings['newhorizon_registry_reminder'],
43 '#description' => t('By default, if the above option is checked, a message is displayed telling you to turn off that feature for production sites. Uncheck this box to stop displaying that message.'),
44 );
45
46 // Return the form
47 return $form;
48 }
49
50
51 function _newhorizon_theme(&$existing, $type, $theme, $path) {
52 // Each theme has two possible preprocess functions that can act on a hook.
53 // This function applies to every hook.
54 $functions[0] = $theme . '_preprocess';
55 // Inspect the preprocess functions for every hook in the theme registry.
56 // @TODO: When PHP 5 becomes required (Zen 7.x), use the following faster
57 // implementation: foreach ($existing AS $hook => &$value) {}
58 foreach (array_keys($existing) AS $hook) {
59 // Each theme has two possible preprocess functions that can act on a hook.
60 // This function only applies to this hook.
61 $functions[1] = $theme . '_preprocess_' . $hook;
62 foreach ($functions AS $key => $function) {
63 // Add any functions that are not already in the registry.
64 if (function_exists($function) && !in_array($function, $existing[$hook]['preprocess functions'])) {
65 // We add the preprocess function to the end of the existing list.
66 $existing[$hook]['preprocess functions'][] = $function;
67 }
68 }
69 }
70
71 // Since we are rebuilding the theme registry and the theme settings' default
72 // values may have changed, make sure they are saved in the database properly.
73 newhorizon_theme_get_default_settings($theme);
74 // Since we modify the $existing cache directly, return nothing.
75 return array();
76 }
77
78
79 function newhorizon_theme_get_default_settings($theme) {
80 $themes = list_themes();
81
82 // Get the default values from the .info file.
83 $defaults = !empty($themes[$theme]->info['settings']) ? $themes[$theme]->info['settings'] : array();
84
85 if (!empty($defaults)) {
86 // Get the theme settings saved in the database.
87 $settings = theme_get_settings($theme);
88 // Don't save the toggle_node_info_ variables.
89 if (module_exists('node')) {
90 foreach (node_get_types() as $type => $name) {
91 unset($settings['toggle_node_info_' . $type]);
92 }
93 }
94 // Save default theme settings.
95 variable_set(
96 str_replace('/', '_', 'theme_' . $theme . '_settings'),
97 array_merge($defaults, $settings)
98 );
99 // If the active theme has been loaded, force refresh of Drupal internals.
100 if (!empty($GLOBALS['theme_key'])) {
101 theme_get_setting('', TRUE);
102 }
103 }
104
105 // Return the default settings.
106 return $defaults;
107 }

  ViewVC Help
Powered by ViewVC 1.1.2