summaryrefslogtreecommitdiffstats
path: root/zen
diff options
context:
space:
mode:
authorJohnAlbin2008-09-15 03:24:48 +0000
committerJohnAlbin2008-09-15 03:24:48 +0000
commit719059ea537c5429a498249e0847818e3ff21750 (patch)
tree78efb2272f40a92179d36395a11b329e16445593 /zen
parent184bd5158a51f85d7113b7b1505d97ebe01c69dc (diff)
#245832: Add IE conditional stylesheets to .info file
Diffstat (limited to 'zen')
-rw-r--r--zen/page.tpl.php7
-rw-r--r--zen/template.conditional-styles.inc101
-rw-r--r--zen/template.php39
-rw-r--r--zen/template.theme-registry.inc9
-rw-r--r--zen/zen.info3
5 files changed, 132 insertions, 27 deletions
diff --git a/zen/page.tpl.php b/zen/page.tpl.php
index 634e050..a36caea 100644
--- a/zen/page.tpl.php
+++ b/zen/page.tpl.php
@@ -6,13 +6,6 @@
<title><?php print $head_title; ?></title>
<?php print $head; ?>
<?php print $styles; ?>
- <!--[if IE]>
- <?php if (file_exists($directory . '/ie.css')): ?>
- <link rel="stylesheet" href="<?php print $base_path . $directory; ?>/ie.css" type="text/css">
- <?php else: ?>
- <link rel="stylesheet" href="<?php print $base_path . $zentheme_directory; ?>/ie.css" type="text/css">
- <?php endif; ?>
- <![endif]-->
<?php print $scripts; ?>
</head>
diff --git a/zen/template.conditional-styles.inc b/zen/template.conditional-styles.inc
new file mode 100644
index 0000000..3cca524
--- /dev/null
+++ b/zen/template.conditional-styles.inc
@@ -0,0 +1,101 @@
+<?php
+// The code for conditional stylesheets started out as a patch for Zen. Now that
+// it has been spun out to its own separate module, It would be nice to prevent
+// code drift between the Zen implementation and the conditional_styles.module,
+// so Zen now includes an exact copy of conditonal_style module's:
+// conditional_styles.theme.inc,v 1.4 2008/09/14 23:26:47 johnalbin Exp
+
+/**
+ * @file
+ * Allows themes to add conditional stylesheets.
+ *
+ * @see http://msdn.microsoft.com/en-us/library/ms537512.aspx
+ */
+
+/**
+ * Return paths for the theme and its base themes.
+ *
+ * @param $theme
+ * The name of the theme.
+ * @return
+ * An array of all the theme paths.
+ */
+function conditional_styles_paths_to_basetheme($theme) {
+ static $theme_paths;
+ if (empty($theme_paths[$theme])) {
+ $theme_paths[$theme] = array();
+ $themes = list_themes();
+ // Grab the paths from the base theme.
+ if (!empty($themes[$theme]->base_theme)) {
+ $theme_paths[$theme] = conditional_styles_paths_to_basetheme($themes[$theme]->base_theme);
+ }
+ $theme_paths[$theme][$theme] = dirname($themes[$theme]->filename);
+ }
+ return $theme_paths[$theme];
+}
+
+/**
+ * When the theme registry is rebuilt, we also build the conditional stylesheets.
+ */
+function _conditional_styles_theme($existing, $type, $theme, $path) {
+ // @TODO: For PHP 4 compatibility we use foreach (array_keys($array) AS $key).
+ // When PHP 5 becomes required (Drupal 7.x), use the following faster
+ // implementation: foreach ($array AS $key => &$value) {}
+
+ // Process the conditional stylesheets for every active theme.
+ $themes = list_themes();
+ foreach (array_keys($themes) AS $theme) {
+ // We only need to process active themes.
+ if ($themes[$theme]->status) {
+ $paths = conditional_styles_paths_to_basetheme($theme);
+
+ // Grab all the conditional stylesheets.
+ $stylesheets = array();
+ // Start with the base theme and travel up the chain to the active theme.
+ foreach ($paths AS $theme_name => $path) {
+ // Look at the conditional-stylesheets defined in the theme's .info file.
+ if (!empty($themes[$theme_name]->info['conditional-stylesheets'])) {
+ foreach ($themes[$theme_name]->info['conditional-stylesheets'] AS $condition => $css) {
+ // Allow the theme to override its base themes' styles.
+ foreach ($css AS $media => $files) {
+ foreach ($files AS $file) {
+ $stylesheets[$condition][$media][$file] = $path;
+ }
+ }
+ }
+ }
+ }
+ // Render the stylesheets to link elements.
+ $conditional_styles = '';
+ if (!empty($stylesheets)) {
+ $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
+ $base_path = base_path();
+ foreach ($stylesheets AS $condition => $css) {
+ // Each condition requires its own set of links.
+ $output = '';
+ foreach ($css AS $media => $files) {
+ foreach ($files AS $file => $path) {
+ // Don't allow non-existent stylesheets to clutter the logs with 404.
+ if (file_exists("./$path/$file")) {
+ $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file$query_string\" />\n";
+ }
+ }
+ }
+ if ($output) {
+ $conditional_styles .= "<!--[$condition]>\n$output<![endif]-->\n";
+ }
+ }
+ }
+ // Save the stylesheets for later retrieval.
+ if ($conditional_styles) {
+ variable_set('conditional_styles_' . $theme, $conditional_styles);
+ }
+ else {
+ variable_del('conditional_styles_' . $theme);
+ }
+ }
+ }
+
+ // Return nothing.
+ return array();
+}
diff --git a/zen/template.php b/zen/template.php
index c9a1c5e..7465f1b 100644
--- a/zen/template.php
+++ b/zen/template.php
@@ -14,6 +14,20 @@
*/
+/*
+ * Add stylesheets only needed when Zen is the active theme. Don't do something
+ * this dumb in your sub-theme; see how wireframes.css is handled instead.
+ */
+if ($GLOBALS['theme'] == 'zen') { // If we're in the main theme
+ if (theme_get_setting('zen_layout') == 'border-politics-fixed') {
+ drupal_add_css(drupal_get_path('theme', 'zen') . '/layout-fixed.css', 'theme', 'all');
+ }
+ else {
+ drupal_add_css(drupal_get_path('theme', 'zen') . '/layout-liquid.css', 'theme', 'all');
+ }
+}
+
+
/**
* Implements HOOK_theme().
*/
@@ -95,26 +109,6 @@ function zen_menu_local_tasks() {
* The name of the template being rendered ("page" in this case.)
*/
function zen_preprocess_page(&$vars, $hook) {
- global $theme;
-
- // These next lines add additional CSS files and redefine
- // the $css and $styles variables available to your page template
- if ($theme == 'zen') { // If we're in the main theme
- // Load the stylesheet for a liquid layout
- if (theme_get_setting('zen_layout') == 'border-politics-liquid') {
- drupal_add_css($vars['directory'] . '/layout-liquid.css', 'theme', 'all');
- }
- // Or load the stylesheet for a fixed width layout
- else {
- drupal_add_css($vars['directory'] . '/layout-fixed.css', 'theme', 'all');
- }
- $vars['css'] = drupal_add_css();
- $vars['styles'] = drupal_get_css();
- }
-
- // Allow sub-themes to have an ie.css file
- $vars['zentheme_directory'] = path_to_zentheme();
-
// Add an optional title to the end of the breadcrumb.
if (theme_get_setting('zen_breadcrumb_title') && $vars['breadcrumb']) {
$vars['breadcrumb'] = substr($vars['breadcrumb'], 0, -6) . $vars['title'] . '</div>';
@@ -125,6 +119,11 @@ function zen_preprocess_page(&$vars, $hook) {
$vars['help'] = '';
}
+ // Add conditional stylesheets.
+ if (!module_exists('conditional_styles')) {
+ $vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
+ }
+
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
$body_classes = array($vars['body_classes']);
diff --git a/zen/template.theme-registry.inc b/zen/template.theme-registry.inc
index b1e9b0f..7bab165 100644
--- a/zen/template.theme-registry.inc
+++ b/zen/template.theme-registry.inc
@@ -45,6 +45,15 @@ function _zen_theme(&$existing, $type, $theme, $path) {
}
}
+ // Compute the conditional stylesheets.
+ if (!module_exists('conditional_styles')) {
+ include_once './' . drupal_get_path('theme', 'zen') . '/template.conditional-styles.inc';
+ // _conditional_styles_theme() only needs to be run once.
+ if ($theme == 'zen') {
+ _conditional_styles_theme($existing, $type, $theme, $path);
+ }
+ }
+
// Since we are rebuilding the theme registry and the theme settings' default
// values may have changed, make sure they are saved in the database properly.
zen_theme_get_default_settings($theme);
diff --git a/zen/zen.info b/zen/zen.info
index 0fb74cb..c1934b3 100644
--- a/zen/zen.info
+++ b/zen/zen.info
@@ -36,6 +36,9 @@ stylesheets[print][] = print.css
; stylesheets[all][] = layout.css
; stylesheets[all][] = layout-liquid.css
+ ; Set the conditional stylesheets that are processed by IE.
+conditional-stylesheets[if IE][all][] = ie.css
+
; The regions defined in Zen's default page.tpl.php file. The name in
; brackets is the name of the variable in the page.tpl.php file, (e.g.
; "[content_top]" in the .info file means there should be a $content_top