| 1 |
<?php
|
| 2 |
|
| 3 |
// Initialize theme settings
|
| 4 |
if (is_null(theme_get_setting('fixedfluid'))) { // <-- if settings have never ben set
|
| 5 |
|
| 6 |
// get theme key
|
| 7 |
global $theme_key;
|
| 8 |
|
| 9 |
// include theme settings defaults
|
| 10 |
if(is_file($theme_path . 'theme-settings-defaults.php')) {
|
| 11 |
include('theme-settings-defaults.php');
|
| 12 |
}
|
| 13 |
|
| 14 |
// Don't save the toggle_node_info_ variables
|
| 15 |
if (module_exists('node')) {
|
| 16 |
foreach (node_get_types() as $type => $name) {
|
| 17 |
unset($settings['toggle_node_info_'. $type]);
|
| 18 |
}
|
| 19 |
}
|
| 20 |
// Save default theme settings
|
| 21 |
variable_set(
|
| 22 |
str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
|
| 23 |
array_merge($defaults, $settings)
|
| 24 |
);
|
| 25 |
// Force refresh of Drupal internals
|
| 26 |
theme_get_setting('', TRUE);
|
| 27 |
}
|
| 28 |
|
| 29 |
if (theme_get_setting('timestamp') > 0) {
|
| 30 |
GLOBAL $theme;
|
| 31 |
drupal_add_css(file_directory_path().'/cto-'.$theme.'.css', 'theme', 'all');
|
| 32 |
}
|
| 33 |
|
| 34 |
if (theme_get_setting('cufon_enable')) {
|
| 35 |
//Load Cufon font replacement scripts
|
| 36 |
if(is_file($theme_path .'scripts/typography/cufon-yui.js')) {
|
| 37 |
drupal_add_js($theme_path .'scripts/typography/cufon-yui.js');
|
| 38 |
}
|
| 39 |
if(is_file($theme_path .'scripts/typography/fonts/'. theme_get_setting('cufon_font_face'))) {
|
| 40 |
drupal_add_js($theme_path .'scripts/typography/fonts/'. theme_get_setting('cufon_font_face'));
|
| 41 |
}
|
| 42 |
if(is_file($theme_path .'scripts/typography/invoke-cufon.js')) {
|
| 43 |
drupal_add_js($theme_path .'scripts/typography/invoke-cufon.js');
|
| 44 |
}
|
| 45 |
}
|
| 46 |
if (theme_get_setting('superfish_enable')) {
|
| 47 |
//Load superfish drop-down scripts
|
| 48 |
if ((theme_get_setting('superfish_delay') > 0)) {
|
| 49 |
if(is_file($theme_path .'scripts/drop_down/hoverIntent.js')) {
|
| 50 |
drupal_add_js($theme_path .'scripts/drop_down/hoverIntent.js');
|
| 51 |
}
|
| 52 |
}
|
| 53 |
if(is_file($theme_path .'scripts/drop_down/adt-superfish.js')) {
|
| 54 |
drupal_add_js($theme_path .'scripts/drop_down/adt-superfish.js');
|
| 55 |
}
|
| 56 |
if(is_file($theme_path .'scripts/drop_down/invoke-superfish.js')) {
|
| 57 |
drupal_add_js($theme_path .'scripts/drop_down/invoke-superfish.js');
|
| 58 |
}
|
| 59 |
foreach (theme_get_setting('superfish_properties') as $property => $value) {
|
| 60 |
if ($value){
|
| 61 |
drupal_add_js(array('superfish' => array('animation' => array($property => 'show'))), 'setting');
|
| 62 |
}
|
| 63 |
}
|
| 64 |
drupal_add_js(array('superfish' => array('speed' => theme_get_setting('superfish_speed'))), 'setting');
|
| 65 |
drupal_add_js(array('superfish' => array('delay' => theme_get_setting('superfish_delay'))), 'setting');
|
| 66 |
drupal_add_js(array('superfish' => array('easing' => theme_get_setting('superfish_easing'))), 'setting');
|
| 67 |
}
|
| 68 |
|
| 69 |
// Load jQuery example plugin
|
| 70 |
if (theme_get_setting('input_example')) {
|
| 71 |
drupal_add_js($theme_path .'scripts/misc/jquery.example.min.js');
|
| 72 |
}
|
| 73 |
|
| 74 |
// Load jQuery equal heights plugin
|
| 75 |
if (theme_get_setting('force_eq_heights')) {
|
| 76 |
if(is_file($theme_path .'scripts/misc/jQuery.equalHeights.js')) {
|
| 77 |
drupal_add_js($theme_path .'scripts/misc/jQuery.equalHeights.js');
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
CSS Caching Workflow:
|
| 83 |
|
| 84 |
* 1. A file is created in /files
|
| 85 |
* 2. Theme settings and derivative variables are used to make up CSS style rules
|
| 86 |
* 3. The file is filled with the generated CSS style rules.
|
| 87 |
* 4. On each pageload, the last-modified time of the file is compared to the last-modified time that is saved as a hidden form field in the themesettings form.
|
| 88 |
* 5.a If the microtimes are the same, theme settings are not updated
|
| 89 |
* 5.b. If the microtimes are different, theme settings have been re-saved (and possibly changed). Theme settings will be loaded from the database and derivative css styles will be generated.
|
| 90 |
* 6. The themesettings stylesheet will be filled with the newly generated CSS
|
| 91 |
|
| 92 |
**/
|
| 93 |
if (user_access('access administration pages') && (arg(2) == 'themes') && (arg(3) == 'settings') && (arg(4) != FALSE)) {
|
| 94 |
GLOBAL $theme;
|
| 95 |
|
| 96 |
if (theme_get_setting('timestamp')) { // If theme settings are in fact "customized", this only returns FALSE if the theme settings never have been saved
|
| 97 |
$newTimestamp = "/*".theme_get_setting('timestamp')."*/\n";
|
| 98 |
$ctoCssFile = file_directory_path().'/cto-'.$theme.'.css';
|
| 99 |
if (is_file($ctoCssFile)) {
|
| 100 |
$fh = fopen($ctoCssFile, 'r');
|
| 101 |
$oldTimestamp = fgets($fh,1024); // extract timestamp from first line of css file. Note: the timestap is in a css file so it is wrapped in /* css comment */ characters.
|
| 102 |
fclose($fh);
|
| 103 |
}
|
| 104 |
|
| 105 |
if (($oldTimestamp) != ($newTimestamp)) { // if custom theme options have been saved since last time css file was written
|
| 106 |
/* Construct CSS file: */
|
| 107 |
|
| 108 |
$CSS = '';
|
| 109 |
$layout_width_fixed = theme_get_setting('layout_width_fixed');
|
| 110 |
$layout_width_fluid = theme_get_setting('layout_width_fluid');
|
| 111 |
$layout_min_width = theme_get_setting('layout_min_width');
|
| 112 |
$layout_max_width = theme_get_setting('layout_max_width');
|
| 113 |
|
| 114 |
if (theme_get_setting('fixedfluid') == 'px') {
|
| 115 |
$CSS .= "#container { width: {$layout_width_fixed}px; }\n";
|
| 116 |
} else {
|
| 117 |
$CSS .= "#container { width: {$layout_width_fluid}%; }\n";
|
| 118 |
}
|
| 119 |
if ($layout_min_width) {
|
| 120 |
$CSS .= "body #container { min-width: {$layout_min_width}px; }\n";
|
| 121 |
} else {
|
| 122 |
$CSS .= "body #container { min-width: none; }\n";
|
| 123 |
}
|
| 124 |
if ($layout_max_width) {
|
| 125 |
$CSS .= "body #container { max-width: {$layout_max_width}px; }\n";
|
| 126 |
} else {
|
| 127 |
$CSS .= "body #container { max-width: none; }\n";
|
| 128 |
}
|
| 129 |
if (theme_get_setting('expand_admin')):
|
| 130 |
$CSS .= "body.section-admin #container,body.section-admin #footer { width:90%; }\n";
|
| 131 |
endif;
|
| 132 |
|
| 133 |
if (theme_get_setting('body_font_face')):
|
| 134 |
$font_set = font_stack(theme_get_setting('body_font_face'));
|
| 135 |
$CSS .= "html body { font-family: {$font_set}; }\n";
|
| 136 |
endif;
|
| 137 |
|
| 138 |
if (theme_get_setting('headings_font_face')):
|
| 139 |
$font_set = font_stack(theme_get_setting('headings_font_face'));
|
| 140 |
$CSS .= "h1, h2, h3, h4, h5, h6, legend, p.mission, p.slogan { font-family: {$font_set}; }\n";
|
| 141 |
endif;
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Color module injection
|
| 145 |
* Writes the colors to the stylesheet, using the color_get_palette('themename') function, and assisting color-calibration functions if applicable
|
| 146 |
* (color module's own color shifting in CSS works unreliably and inaccurately)
|
| 147 |
*/
|
| 148 |
if (module_exists(color)):
|
| 149 |
// Override colors in style.css with color palette from theme settings. All selectors have increased specificity so that they will override other stylesheets and not be overriden
|
| 150 |
$ctopalette = color_get_palette($theme);
|
| 151 |
$CSS .= "html body, body .nodetitle a:hover, body .nodetitle a:focus { color:".$ctopalette['text'].";}\n";
|
| 152 |
$CSS .= "html body a { color:".$ctopalette['top'].";}\n";
|
| 153 |
$CSS .= "html body, .poll .bar .foreground { background-color:".$ctopalette['base'].";}\n";
|
| 154 |
$CSS .= "body .adtblocks .block .block-inner { background-color:".$ctopalette['link'].";}\n";
|
| 155 |
$CSS .= "body h1, body h2, body h3, body h4, body h5, body h6, legend, p.mission, p.slogan { color:".$ctopalette['bottom'].";}\n";
|
| 156 |
endif;
|
| 157 |
|
| 158 |
$fh = fopen($ctoCssFile, 'w');
|
| 159 |
if ($fh) {
|
| 160 |
fwrite($fh, $newTimestamp); // write new timestamp to file
|
| 161 |
fwrite($fh, $CSS); // write css to file
|
| 162 |
} else {
|
| 163 |
drupal_set_message(t('Cannot write theme-settings file, please check your file system. (Visit status report page)'), 'error');
|
| 164 |
}
|
| 165 |
fclose($fh);
|
| 166 |
// If the CSS & JS aggregation performance options are enabled we need to clear the caches
|
| 167 |
drupal_clear_css_cache();
|
| 168 |
drupal_clear_js_cache();
|
| 169 |
}
|
| 170 |
} else {
|
| 171 |
$msgthemeset = 'Hello administrator! It looks like you\'ve never set your theme settings before, check out out the <a href="'. base_path() .'admin/build/themes/settings/'. $theme .'">theme settings page</a> to learn about the options.';
|
| 172 |
drupal_set_message($msgthemeset, 'message');
|
| 173 |
}
|
| 174 |
}
|
| 175 |
|
| 176 |
/**
|
| 177 |
* Provides Font Stack values for theme settings which are written to custom.css
|
| 178 |
* @see font_list()
|
| 179 |
* @param $attributes
|
| 180 |
* @return string
|
| 181 |
*/
|
| 182 |
function font_stack($font) {
|
| 183 |
if ($font) {
|
| 184 |
$fonts = array(
|
| 185 |
'helvetica' => 'Arial, Helvetica, "Nimbus Sans L", "Liberation Sans", "FreeSans", sans-serif',
|
| 186 |
'verdana' => 'Verdana, "Bitstream Vera Sans", Arial, sans-serif',
|
| 187 |
'lucida' => '"Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", "DejaVu Sans", Arial, sans-serif',
|
| 188 |
'geneva' => '"Geneva", "Bitstream Vera Serif", "Tahoma", sans-serif',
|
| 189 |
'tahoma' => 'Tahoma, Geneva, "DejaVu Sans Condensed", sans-serif',
|
| 190 |
'century' => '"Century Gothic", "URW Gothic L", Helvetica, Arial, sans-serif',
|
| 191 |
'georgia' => 'Georgia, "Bitstream Vera Serif", serif',
|
| 192 |
'palatino' => '"Palatino Linotype", "URW Palladio L", "Book Antiqua", "Palatino", serif',
|
| 193 |
'times' => '"Free Serif", "Times New Roman", Times, serif',
|
| 194 |
);
|
| 195 |
|
| 196 |
foreach ($fonts as $key => $value) {
|
| 197 |
if ($font == $key) {
|
| 198 |
$output = $value;
|
| 199 |
}
|
| 200 |
}
|
| 201 |
}
|
| 202 |
return $output;
|
| 203 |
}
|