Commit 49b6843d authored by John Albin Wilkins's avatar John Albin Wilkins
Browse files

by JohnAlbin: Update template.conditional-styles.inc to use latest code from...

by JohnAlbin: Update template.conditional-styles.inc to use latest code from Conditional Styles 6.x-1.2.
parent c33d648e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -324,7 +324,8 @@ function zen_preprocess_page(&$vars, $hook) {
  }
  // Add conditional stylesheets.
  elseif (!module_exists('conditional_styles')) {
    $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
    $language = $GLOBALS['language']->direction == LANGUAGE_RTL ? '_rtl' : '';
    $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'] . $language, '');
    $vars['styles'] .= $vars['conditional_styles'];
  }

@@ -410,7 +411,8 @@ function zen_preprocess_maintenance_page(&$vars, $hook) {
  }
  // Add conditional stylesheets.
  elseif (!module_exists('conditional_styles')) {
    $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
    $language = $GLOBALS['language']->direction == LANGUAGE_RTL ? '_rtl' : '';
    $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'] . $language, '');
    $vars['styles'] .= $vars['conditional_styles'];
  }
}
+12 −13
Original line number Diff line number Diff line
@@ -38,12 +38,7 @@ function conditional_styles_paths_to_basetheme($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.
  global $language;
  $themes = list_themes();
  foreach (array_keys($themes) AS $theme) {
    // We only need to process active themes.
@@ -67,29 +62,30 @@ function _conditional_styles_theme($existing, $type, $theme, $path) {
        }
      }
      // Render the stylesheets to link elements.
      $conditional_styles = '';
      $conditional_styles = $conditional_styles_rtl = '';
      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 = '';
          $output = $output_rtl = '';
          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 ($language->direction == LANGUAGE_RTL){
                $link = "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file$query_string\" />\n";
                $output .= $link;
                $output_rtl .= $link;
                $file_rtl = str_replace('.css', '-rtl.css', $file);
                if (file_exists("./$path/$file_rtl")) {
                    $output .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file_rtl$query_string\" />\n";
                  }
                  $output_rtl .= "<link type=\"text/css\" rel=\"stylesheet\" media=\"$media\" href=\"$base_path$path/$file_rtl$query_string\" />\n";
                }
              }
            }
          }
          if ($output) {
            $conditional_styles .= "<!--[$condition]>\n$output<![endif]-->\n";
            $conditional_styles_rtl .= "<!--[$condition]>\n$output_rtl<![endif]-->\n";
          }
        }
      }
@@ -97,13 +93,16 @@ function _conditional_styles_theme($existing, $type, $theme, $path) {
      if ($conditional_styles) {
        if (db_is_active()) {
          variable_set('conditional_styles_' . $theme, $conditional_styles);
          variable_set('conditional_styles_' . $theme . '_rtl', $conditional_styles_rtl);
        }
        else {
          $GLOBALS['conf']['conditional_styles_' . $theme] = $conditional_styles;
          $GLOBALS['conf']['conditional_styles_' . $theme . '_rtl'] = $conditional_styles_rtl;
        }
      }
      elseif (db_is_active()) {
        variable_del('conditional_styles_' . $theme);
        variable_del('conditional_styles_' . $theme . '_rtl');
      }
    }
  }