Mike, how would you suggest I add the advagg_css_extra_alter() hook to the Fusion theme - for support of its CSS conditionals?

Currently, I have this: (fusion_core/template.php)

  // Peter: Conditional CSS: + Updated for CDN to use file_create_url() instead of base_path()
  // Add grid, color, ie6, ie7, ie8 & local stylesheets, including inherited & rtl versions
  $grid_style = '/css/' . theme_get_setting('theme_grid');
  $themes = fusion_core_theme_paths($theme_key);
//  $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);   // Peter: no to this '' - it causes Query Strings to CDN
  $style_categories = array(
    // category => file basename
    'setting'   => $grid_style,
    'ie6'       => 'css/ie6-fixes',
    'ie7'       => 'css/ie7-fixes',
    'ie8'       => 'css/ie8-fixes',
    'local'     => 'css/local',
  );
  // Initialize.
  $css_files = array();
  foreach (array_keys($style_categories) as $category) {
    $vars[$category . '_styles'] = '';
  }
  // Find all CSS files that should be added.
  foreach ($themes as $name => $path) {
    foreach ($style_categories as $category => $file_basename) {
      // Check if a CSS file for this style category exists.
      if (file_exists($path . $file_basename . '.css')) {
        $css_files[$category] = $path . $file_basename . '.css';
      }
      // Check if a CSS file for this style category, but in RTL, exists.
      if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($path . $file_basename . '-rtl.css')) {
        $css_files[$category] = $path . $file_basename . '-rtl.css';
      }
    }
  }
  $link_prefix = '<link type="text/css" rel="stylesheet" media="all" href="';
  $link_suffix = '" />' . "\n";
  // Add all found CSS files to their corresponding style categories.
  foreach ($css_files as $category => $css_file) {
    // Use the file_create_url() function to create file URLs when it's
    // available, to add automatic support for CDN integration.
    // This is also the way it will work in Drupal 7.
    if (module_exists('cdn')) {
      $vars[$category . '_styles'] .= $link_prefix . file_create_url($css_file) . $link_suffix;
    }
    else {
      $vars[$category . '_styles'] .= $link_prefix . base_path() . $css_file . $link_suffix;
    }
  }

Thanks for any tips!

Advagg's advagg_css_extra_alter() hook API is not well documented!
The closest I can get to knowing advagg_css_extra_alter() is picking away at the advagg patched 'css_emimage' module!

Comments

mikeytown2’s picture

Looks like you can tell what type of conditional it will be based off of the filename, correct?

function fusion_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;

  if (strpos($filename, 'ie6-fixes') !== FALSE) {
    $prefix = "<!--[if IE 6]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie7-fixes') !== FALSE) {
    $prefix = "<!--[if IE 7]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie8-fixes') !== FALSE) {
    $prefix = "<!--[if IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}

Then you add in the files by using drupal_add_css() or including it in the themes info file, and hook_advagg_css_extra_alter() will make it conditional. It was the only way I could think of making drupal_add_css work like this without hacking up core. If you can't tell what kind of prefix to use based off of the filename then using some sort of lookup is how to do it (see css_emimage).

Peter Bowey’s picture

Many thanks Mike,

The above code templates advagg's *hook()* method very well!
Great to get such a fast and helpful answer!

mikeytown2’s picture

Status: Active » Fixed

Marking this as fixed. Re-open if this is not the case.

Peter Bowey’s picture

Mike, in using this method, via themes .inf, the style sheets remained static! No prefix /suffix occurred.

I tried using both the base theme; 'fusion_core' as well the sub-theme 'acquia_prosper'
I am missing something here.

Code in base template.php [fusion_core]

/**
 * Advagg Module preprocessing - style conditionals
 */
function fusion_core_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;

  if (strpos($filename, 'ie6-fixes') !== FALSE) {
    $prefix = "<!--[if lte IE 6]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie7-fixes') !== FALSE) {
    $prefix = "<!--[if IE 7]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie8-fixes') !== FALSE) {
    $prefix = "<!--[if IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}

fusion_core.info:

stylesheets[all][] = css/grid16-960.css
; Peter: conditionals via advagg follow here
stylesheets[all][] = css/ie8-fixes.css
stylesheets[all][] = css/ie7-fixes.css
stylesheets[all][] = css/ie6-fixes.css

Referring to your post http://drupal.org/node/1154732

mikeytown2’s picture

did you flush the caches?

Peter Bowey’s picture

Refer #5
Yes, full flush! Even changed the theme to another and then back to 'acquia_prosper'!
advagg 'Debug' shows that the 3 IE* conditional files are simply part of the aggregate 'bundle' -not seperate.

Peter Bowey’s picture

I note that the D7 version of 'fusion' theme uses this method:

  // Add grid, local, & IE stylesheets, including versions inherited from parent themes
  $themes = fusion_core_theme_paths($theme_key);
  foreach ($themes as $name => $path) {
    $file = theme_get_setting('theme_grid') . '.css';
    if (file_exists($path . '/css/' . $file)) {
      drupal_add_css($path . '/css/' . $file, array('basename' => $name . '-' . $file, 'group' => CSS_THEME, 'preprocess' => TRUE));
    }
    if (file_exists($path . '/css/local.css')) {
      drupal_add_css($path . '/css/local.css', array('basename' => $name . '-local.css', 'group' => CSS_THEME, 'preprocess' => TRUE));
    }
    for ($v = 6; $v <= 9; $v++) {
      $file = 'ie' . $v . '-fixes.css';
      if (file_exists($path . '/css/' . $file)) {
        drupal_add_css($path . '/css/' . $file,
          array(
            'basename' => $name . '-' . $file,
            'group' => CSS_THEME,
            'browsers' => array(
              'IE' => 'IE ' . $v,
              '!IE' => FALSE),
            'preprocess' => FALSE)
        );
      }
    }
  }
}

But that's the new D7 'conditional' drupal_add_css()
Reference: http://drupal.org/node/1154732#comment-4457636

mikeytown2’s picture

Status: Fixed » Needs work

working on a solution... need to pull the .css file out of the aggregate first & looks like you've found a bug! Working on a patch for this :)

Peter Bowey’s picture

Many thanks Mike!
This is part of work on client's D6 website - with a 'short' ETA.
By the way, the client loves the *new* site speed with 'CDN + Boost + Advagg'.
I appreciate your code and motivation!

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new5 KB

Try this

/**
 * Implement hook_advagg_css_extra_alter.
 */
function fusion_core_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;

  if (strpos($filename, 'ie6-fixes.css') !== FALSE) {
    $prefix = "<!--[if lte IE 6]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie7-fixes.css') !== FALSE) {
    $prefix = "<!--[if IE 7]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie8-fixes.css') !== FALSE) {
    $prefix = "<!--[if IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}


/**
 * Implement hook_advagg_css_pre_alter.
 */
function fusion_core_advagg_css_pre_alter(&$css, $preprocess_css, $public_downloads) {
  // Do nothing if aggregation is off. 
  if (!$preprocess_css) {
    return;
  }

  // Turn off aggregation for the selected files.
  foreach ($css as $media => &$types) {
    foreach ($types as $type => &$files) {
      foreach ($files as $file => &$preprocess) {
        if ($preprocess && (
              strpos($file, 'ie6-fixes.css') !== FALSE 
            || strpos($file, 'ie7-fixes.css') !== FALSE
            || strpos($file, 'ie8-fixes.css') !== FALSE
              )
            ) {
          $preprocess = FALSE;
        }
      }
    }
  }
}

With this patch that has just been applied to git.

Peter Bowey’s picture

Many thanks Mike,
will report on status shortly!
Adding code now...

mikeytown2’s picture

The JS side looks like it might take some clean-up to get it where I want it.

Peter Bowey’s picture

Still a issue Mike...

Seems that 'css_emimage' is doing stuff on the CSS conditionals:

Using advagg/info view shows this:

sites/all/themes/acquia_prosper/css/ie8-fixes.css:
Array (
    [css_emimage] => 0
)

sites/all/themes/acquia_prosper/css/ie7-fixes.css: 
Array ( [css_emimage] => Array ( [sites/all/themes/acquia_prosper/images/list-level-3_ie.png] => d93045fd386b0cffc4171bc4bebe74ad ) )

sites/all/themes/acquia_prosper/css/ie6-fixes.css:
Array ( [css_emimage] => Array ( [sites/all/themes/acquia_prosper/images/list-level-3_ie.png] => d93045fd386b0cffc4171bc4bebe74ad ) )

No CSS conditionals yet, other than those generated by 'css_emimage'

advagg's hook/theme 'info' shows:

fusion_core_preprocess_page
Peter Bowey’s picture

I will try shifting the 2 above functions 'hook_advagg_css_*' to the 'child theme' -> acquia_prosper
via it's' template.php'

Peter Bowey’s picture

Nope, the child theme 'acquia_prosper' does not use a 'preprocess' hook.

Reverting to using Paul Irish's / html5-boilerplate -> conditional CSS 'classes' in the html tag

<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>

Also, see -> http://drupal.org/project/zentropy

mikeytown2’s picture

First step, are the conditional css files out of the aggregates and by them self? That is what hook_advagg_css_pre_alter() is for.

Peter Bowey’s picture

No, the 'conditional css' files are bundled in the aggregate!

mikeytown2’s picture

AdvAgg has very aggressive caching so be sure to flush after every change/test we are doing here. It was the only way to be faster then what core does and provide all of this functionality. I did get this to work locally, so it can be done.

Just for kicks run this, it will echo out in this hook. Make sure the hook is running.

/**
* Implement hook_advagg_css_pre_alter.
*/
function fusion_core_advagg_css_pre_alter(&$css, $preprocess_css, $public_downloads) {
  echo print_r($css, TRUE);
  // Do nothing if aggregation is off.
  if (!$preprocess_css) {
    return;
  }

  // Turn off aggregation for the selected files.
  foreach ($css as $media => &$types) {
    foreach ($types as $type => &$files) {
      foreach ($files as $file => &$preprocess) {
        echo $file;
        if ($preprocess && (
              strpos($file, 'ie6-fixes.css') !== FALSE
            || strpos($file, 'ie7-fixes.css') !== FALSE
            || strpos($file, 'ie8-fixes.css') !== FALSE
              )
            ) {
          $preprocess = FALSE;
        }
      }
    }
  }
}
Peter Bowey’s picture

Thanks Mike,

I applied the above code, then 'dosed well' with full flushes, template change, reset advagg, and etc...

I can now conclude that both;

   fusion_core_advagg_css_pre_alter()
and
   fusion_core_advagg_css_extra_alter()

are not called in the 'fusion_core' template.php
The

echo print_r($css, TRUE);

gave no display or logs whatsoever?

Here is [part] of the given 'fusion_core' template.php

/**
 * Implement hook_advagg_css_extra_alter.
 */
function fusion_core_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;

  if (strpos($filename, 'ie6-fixes.css') !== FALSE) {
    $prefix = "<!--[if lte IE 6]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie7-fixes.css') !== FALSE) {
    $prefix = "<!--[if IE 7]>";
    $suffix = "<![endif]-->";
  }
  elseif (strpos($filename, 'ie8-fixes.css') !== FALSE) {
    $prefix = "<!--[if IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}


/**
* Implement hook_advagg_css_pre_alter.
*/
function fusion_core_advagg_css_pre_alter(&$css, $preprocess_css, $public_downloads) {
  echo print_r($css, TRUE);
  // Do nothing if aggregation is off.
  if (!$preprocess_css) {
    return;
  }

  // Turn off aggregation for the selected files.
  foreach ($css as $media => &$types) {
    foreach ($types as $type => &$files) {
      foreach ($files as $file => &$preprocess) {
        echo $file;
        if ($preprocess && (
              strpos($file, 'ie6-fixes.css') !== FALSE
            || strpos($file, 'ie7-fixes.css') !== FALSE
            || strpos($file, 'ie8-fixes.css') !== FALSE
              )
            ) {
          $preprocess = FALSE;
        }
      }
    }
  }
}


/**
 * Page preprocessing
 */
function fusion_core_preprocess_page(&$vars) {
  global $language, $theme_key, $theme_info, $user;

The fusion_core.info file has this:

name = Fusion Core
description = <a href="http://drupal.org/project/fusion">Fusion Core</a> is the grid-enabled base theme for powerful sub-themes.  With the <a href="http://drupal.org/project/skinr">Skinr</a> module, it enables easy point-and-click theming
. By <a href="http://www.topnotchthemes.com">TopNotchThemes</a>
core = 6.x
engine = phptemplate

stylesheets[all][] = css/style.css
stylesheets[all][] = css/typography.css
stylesheets[all][] = css/superfish.css
stylesheets[all][] = css/superfish-navbar.css
stylesheets[all][] = css/superfish-vertical.css
; Peter: added
; stylesheets[all][] = css/grid16-960.css
; Peter: conditionals via advagg follow here
stylesheets[all][] = css/ie8-fixes.css
stylesheets[all][] = css/ie7-fixes.css
stylesheets[all][] = css/ie6-fixes.css
; Peter; end - added

scripts[] = js/jquery.bgiframe.min.js

I am 'dense and stupid'
but ready for Step '2'...

mikeytown2’s picture

Time to try plan B. Change the hook names from "fusion_core" to "node"

Peter Bowey’s picture

OK will try that, thanks!

Peter Bowey’s picture

OK that shot out some values via print_r();

Array ( [all] => Array ( [module] => Array ( [modules/acquia/admin_menu/admin_menu.css] => [modules/acquia/date/date.css] => 1 [modules/acquia/date/date_popup/themes/datepicker.css] => 1 [modules/acquia/date/date_popup/themes/jquery.timeentry.css] => 1 [modules/acquia/img_assist/img_assist.css] => 1 [modules/acquia/tagadelic/tagadelic.css] => 1 [modules/aggregator/aggregator.css] => 1 [modules/node/node.css] => 1 [modules/system/defaults.css] => 1 [modules/system/system.css] => 1 [modules/system/system-menus.css] => 1 [modules/user/user.css] => 1 [sites/all/modules/cck/theme/content-module.css] => 1 [sites/all/modules/ckeditor/ckeditor.css] => 1 [sites/all/modules/ctools/css/ctools.css] => 1 [sites/all/modules/filefield/filefield.css] => 1 [sites/all/modules/lightbox2/css/lightbox.css] => 1 [sites/all/modules/ubercart/shipping/uc_quote/uc_quote.css] => 1 [sites/all/modules/ubercart/uc_attribute/uc_attribute.css] => 1 [sites/all/modules/ubercart/uc_order/uc_order.css] => 1 [sites/all/modules/ubercart/uc_product/uc_product.css] => 1 [sites/all/modules/ubercart/uc_store/uc_store.css] => 1 [sites/all/modules/views_slideshow/contrib/views_slideshow_singleframe/views_slideshow.css] => 1 [misc/farbtastic/farbtastic.css] => 1 [modules/acquia/calendar/calendar.css] => 1 [sites/all/modules/cck/modules/fieldgroup/fieldgroup.css] => 1 [sites/all/modules/views/css/views.css] => 1 ) [theme] => Array ( [sites/all/themes/fusion/fusion_core/css/style.css] => 1 [sites/all/themes/fusion/fusion_core/css/typography.css] => 1 [sites/all/themes/fusion/fusion_core/css/superfish.css] => 1 [sites/all/themes/fusion/fusion_core/css/superfish-navbar.css] => 1 [sites/all/themes/fusion/fusion_core/css/superfish-vertical.css] => 1 [sites/all/themes/fusion/fusion_core/css/ie8-fixes.css] => 1 [sites/all/themes/fusion/fusion_core/css/ie7-fixes.css] => 1 [sites/all/themes/fusion/fusion_core/css/ie6-fixes.css] => 1 [sites/all/themes/acquia_prosper/css/acquia-prosper-style.css] => 1 [sites/all/themes/acquia_prosper/design_packs/blue/blue.css] => 1 [sites/all/themes/acquia_prosper/css/grid16-960.css] => 1 [sites/all/themes/acquia_prosper/css/acquia-prosper.css] => 1 ) ) ) modules/acquia/admin_menu/admin_menu.cssmodules/acquia/date/date.cssmodules/acquia/date/date_popup/themes/datepicker.cssmodules/acquia/date/date_popup/themes/jquery.timeentry.cssmodules/acquia/img_assist/img_assist.cssmodules/acquia/tagadelic/tagadelic.cssmodules/aggregator/aggregator.cssmodules/node/node.cssmodules/system/defaults.cssmodules/system/system.cssmodules/system/system-menus.cssmodules/user/user.csssites/all/modules/cck/theme/content-module.csssites/all/modules/ckeditor/ckeditor.csssites/all/modules/ctools/css/ctools.csssites/all/modules/filefield/filefield.csssites/all/modules/lightbox2/css/lightbox.csssites/all/modules/ubercart/shipping/uc_quote/uc_quote.csssites/all/modules/ubercart/uc_attribute/uc_attribute.csssites/all/modules/ubercart/uc_order/uc_order.csssites/all/modules/ubercart/uc_product/uc_product.csssites/all/modules/ubercart/uc_store/uc_store.csssites/all/modules/views_slideshow/contrib/views_slideshow_singleframe/views_slideshow.cssmisc/farbtastic/farbtastic.cssmodules/acquia/calendar/calendar.csssites/all/modules/cck/modules/fieldgroup/fieldgroup.csssites/all/modules/views/css/views.csssites/all/themes/fusion/fusion_core/css/style.csssites/all/themes/fusion/fusion_core/css/typography.csssites/all/themes/fusion/fusion_core/css/superfish.csssites/all/themes/fusion/fusion_core/css/superfish-navbar.csssites/all/themes/fusion/fusion_core/css/superfish-vertical.csssites/all/themes/fusion/fusion_core/css/ie8-fixes.csssites/all/themes/fusion/fusion_core/css/ie7-fixes.csssites/all/themes/fusion/fusion_core/css/ie6-fixes.csssites/all/themes/acquia_prosper/css/acquia-prosper-style.csssites/all/themes/acquia_prosper/design_packs/blue/blue.csssites/all/themes/acquia_prosper/css/grid16-960.csssites/all/themes/acquia_prosper/css/acquia-prosper.css

I disabled this once it was tested, as it is a live site -with real clients... :)

Peter Bowey’s picture

I notice from the above print_r() that the last /*/*.css is one long string?
If I expand and format the print_r() we have:

Array ( [all] => Array (
    [module] => Array (
    [modules/acquia/admin_menu/admin_menu.css] => [modules/acquia/date/date.css] => 1
    [modules/acquia/date/date_popup/themes/datepicker.css] => 1
    [modules/acquia/date/date_popup/themes/jquery.timeentry.css] => 1
    [modules/acquia/img_assist/img_assist.css] => 1
    [modules/acquia/tagadelic/tagadelic.css] => 1
    [modules/aggregator/aggregator.css] => 1
    [modules/node/node.css] => 1
    [modules/system/defaults.css] => 1
    [modules/system/system.css] => 1
    [modules/system/system-menus.css] => 1
    [modules/user/user.css] => 1
    [sites/all/modules/cck/theme/content-module.css] => 1
    [sites/all/modules/ckeditor/ckeditor.css] => 1
    [sites/all/modules/ctools/css/ctools.css] => 1
    [sites/all/modules/filefield/filefield.css] => 1
    [sites/all/modules/lightbox2/css/lightbox.css] => 1
    [sites/all/modules/ubercart/shipping/uc_quote/uc_quote.css] => 1
    [sites/all/modules/ubercart/uc_attribute/uc_attribute.css] => 1
    [sites/all/modules/ubercart/uc_order/uc_order.css] => 1
    [sites/all/modules/ubercart/uc_product/uc_product.css] => 1
    [sites/all/modules/ubercart/uc_store/uc_store.css] => 1
    [sites/all/modules/views_slideshow/contrib/views_slideshow_singleframe/views_slideshow.css] => 1
    [misc/farbtastic/farbtastic.css] => 1
    [modules/acquia/calendar/calendar.css] => 1
    [sites/all/modules/cck/modules/fieldgroup/fieldgroup.css] => 1
    [sites/all/modules/views/css/views.css] => 1 )

    [theme] => Array (
    [sites/all/themes/fusion/fusion_core/css/style.css] => 1
    [sites/all/themes/fusion/fusion_core/css/typography.css] => 1
    [sites/all/themes/fusion/fusion_core/css/superfish.css] => 1
    [sites/all/themes/fusion/fusion_core/css/superfish-navbar.css] => 1
    [sites/all/themes/fusion/fusion_core/css/superfish-vertical.css] => 1
    [sites/all/themes/fusion/fusion_core/css/ie8-fixes.css] => 1
    [sites/all/themes/fusion/fusion_core/css/ie7-fixes.css] => 1
    [sites/all/themes/fusion/fusion_core/css/ie6-fixes.css] => 1
    [sites/all/themes/acquia_prosper/css/acquia-prosper-style.css] => 1
    [sites/all/themes/acquia_prosper/design_packs/blue/blue.css] => 1
    [sites/all/themes/acquia_prosper/css/grid16-960.css] => 1
    [sites/all/themes/acquia_prosper/css/acquia-prosper.css] => 1 ) ) )

    modules/acquia/admin_menu/admin_menu.css
    modules/acquia/date/date.css
    modules/acquia/date/date_popup/themes/datepicker.css
    modules/acquia/date/date_popup/themes/jquery.timeentry.css
    modules/acquia/img_assist/img_assist.css
    modules/acquia/tagadelic/tagadelic.cssmodules/aggregator/aggregator.css
    modules/node/node.cssmodules/system/defaults.css
    modules/system/system.cssmodules/system/system-menus.css
    modules/user/user.csssites/all/modules/cck/theme/content-module.css
    sites/all/modules/ckeditor/ckeditor.csssites/all/modules/ctools/css/ctools.css
    sites/all/modules/filefield/filefield.css
    sites/all/modules/lightbox2/css/lightbox.css
    sites/all/modules/ubercart/shipping/uc_quote/uc_quote.css
    sites/all/modules/ubercart/uc_attribute/uc_attribute.css
    sites/all/modules/ubercart/uc_order/uc_order.css
    sites/all/modules/ubercart/uc_product/uc_product.css
    sites/all/modules/ubercart/uc_store/uc_store.css
    sites/all/modules/views_slideshow/contrib/views_slideshow_singleframe/views_slideshow.css
    misc/farbtastic/farbtastic.cssmodules/acquia/calendar/calendar.css
    sites/all/modules/cck/modules/fieldgroup/fieldgroup.css
    sites/all/modules/views/css/views.css
    sites/all/themes/fusion/fusion_core/css/style.css
    sites/all/themes/fusion/fusion_core/css/typography.css
    sites/all/themes/fusion/fusion_core/css/superfish.css
    sites/all/themes/fusion/fusion_core/css/superfish-navbar.css
    sites/all/themes/fusion/fusion_core/css/superfish-vertical.css
    sites/all/themes/fusion/fusion_core/css/ie8-fixes.css
    sites/all/themes/fusion/fusion_core/css/ie7-fixes.css
    sites/all/themes/fusion/fusion_core/css/ie6-fixes.css
    sites/all/themes/acquia_prosper/css/acquia-prosper-style.css
    sites/all/themes/acquia_prosper/design_packs/blue/blue.css
    sites/all/themes/acquia_prosper/css/grid16-960.css
    sites/all/themes/acquia_prosper/css/acquia-prosper.css
Peter Bowey’s picture

Just realized there was a 2nd 'echo' line in the debug code :)
So I removed both 'echo' lines and ran the show:

<!--[if gte IE 8]><!-->
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic1/sites/all/themes/fusion/fusion_core/css/ie8-fixes.css?0">
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic2/sites/all/themes/fusion/fusion_core/css/ie7-fixes.css?0">
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic2/sites/all/themes/fusion/fusion_core/css/ie6-fixes.css?0">
   <!--<![endif]-->

Notes: Interesting change of conditionals here; [if gte IE 8] - and why the 'query string'?
I have setup my Edgecast PULL CDN to return requests with 'query' strings back to the origin source...

Does this suggest that function node_advagg_css_extra_alter(&$values) is not being called?

Answer: No, I did some debug echo's and the three CSS files arrive within the node_advagg_css_extra_alter(),
and are selectively processed by '(strpos($filename, 'iex-fixes.css'). So the prefix + suffix are being ignored.

Conclusion: I hazard a 'guess' that css_emimage is over-riding this conditional processing, for it is the only 'hook' that offers
the incorrect '<!--[if gte IE 8]><!-->'

css_emimage.module

/**
 * Implementation of hook_advagg_css_extra_alter().
 *
 * Set the CSS prefix and suffix.
 */
function css_emimage_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;
  $type = cache_get($bundle_md5, 'cache_css_emimage_advagg');
  if (!empty($type->data)) {
    $type = $type->data;
  }

  if ($type == 'base') {
    $prefix = "<!--[if gte IE 8]><!-->";
    $suffix = "<!--<![endif]-->";
  }
  elseif ($type == 'emimage') {
    $prefix = "<!--[if gte IE 8]><!-->";
    $suffix = "<!--<![endif]-->";
  }
  elseif ($type == 'orig') {
    $prefix = "<!--[if lt IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}

I am not sure [yet] how to deal with this $type 'problem'.

[Later] I made a simple change to the above css_emimage_advagg_css_extra_alter()

function css_emimage_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;
  $type = cache_get($bundle_md5, 'cache_css_emimage_advagg');
  if (!empty($type->data)) {
    $type = $type->data;
  }

  if ($type == 'base' && empty($prefix)) {
    $prefix = "<!--[if gte IE 8]><!-->";
    $suffix = "<!--<![endif]-->";
  }
  elseif ($type == 'emimage' && empty($prefix)) {
    $prefix = "<!--[if gte IE 8]><!-->";
    $suffix = "<!--<![endif]-->";
  }
  elseif ($type == 'orig' && empty($prefix)) {
    $prefix = "<!--[if lt IE 8]>";
    $suffix = "<![endif]-->";
  }
  $values = array($filename, $bundle_md5, $prefix, $suffix);
}

and now we have this result:

<!--[if IE 8]>
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic1/sites/all/themes/fusion/fusion_core/css/ie8-fixes.css?I" />
   <![endif]-->
   <!--[if IE 7]>
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic2/sites/all/themes/fusion/fusion_core/css/ie7-fixes.css?I" />
   <![endif]-->
   <!--[if lte IE 6]>
   <link type="text/css" rel="stylesheet" media="all" href="http://small.gdlcdn.com/802C5F/artlogic2/sites/all/themes/fusion/fusion_core/css/ie6-fixes.css?I" />
   <![endif]-->

Thoughts; conditional CSS files are unlikely to have 'Embedded Images' as we are mostly dealing with CSS IE* issues...

Now it would be good to get rid of the 'query string' and have md5 / unique 'bundle' filename...

In advagg.module we have:

/**
 * Returns an array of values needed for aggregation
 *
 * @param $noagg
 *   (optional) Bool indicating that aggregation should be disabled if TRUE.
 * @return
 *   array of values to be imported via list() function.
 */
function advagg_process_css_js_prep($noagg = FALSE) {
  global $conf;
  $preprocess = (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update');
  .. [code]
  .. [code]
  // A dummy query-string is added to filenames, to gain control over
  // browser-caching. The string changes on every update or full cache
  // flush, forcing browsers to load a new copy of the files, as the
  // URL changed.
  $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);

  return array($preprocess, $public_downloads, $query_string);
}

I use etags [generally] for such 'changes'. So for now, I have 'zapped' the advagg $query_string

mikeytown2’s picture

OK, to go that route it will be a different work flow. hook_advagg_filenames_alter() will be the weapon of choice. If I get the time I'll give you a fully working example tomorrow, but in short you need to create a bundle for each conditional... the advantage is if you have multiple IE-x (x being 7, etc...) files you can then aggregate them into one. So in this case you will not use hook_advagg_css_pre_alter().

Here's a quick start from the bundler sub module; below is not production ready code.

/**
 * Implement hook_advagg_filenames_alter.
 */
function HOOK_bundler_advagg_filenames_alter(&$filenames) {
  $groupings = array();
  foreach ($filenames as $key => $values) {
    // Extract values and set them.
    $filetype = $values['filetype'];
    $files = $values['files'];
    $bundle_md5 = $values['bundle_md5'];

    // Load up each file.
    foreach ($files as &$filename) {
      // Assign each file to their group.
      if (strpos($filename, 'ie6-fixes.css') !== FALSE) {
        $groupings['ie6'][] = $filename;
        unset($filename);
        continue;
      }
      if (strpos($filename, 'ie7-fixes.css') !== FALSE) {
        $groupings['ie7'][] = $filename;
        unset($filename);
        continue;
      }
      if (strpos($filename, 'ie8-fixes.css') !== FALSE) {
        $groupings['ie8'][] = $filename;
        unset($filename);
        continue;
      }
    }
    $groupings[$key] = $files;
  }

  // Rebuild array
  $output = array();
  foreach ($groupings as $key => $bundle) {
    $values = array();
    $values['bundle_md5'] = md5(implode('', $bundle));
    $values['files'] = $bundle;
    $values['filetype'] = $filetype;
    $output[] = $values;

    // Using a global variable below might be the best option.
    if ($key == 'ie6') {
      // Save the bundle_md5 value and use it in hook_advagg_css_extra_alter().
    }
    if ($key == 'ie7') {
      // Save the bundle_md5 value and use it in hook_advagg_css_extra_alter().
    }
    if ($key == 'ie8') {
      // Save the bundle_md5 value and use it in hook_advagg_css_extra_alter().
    }
  }
  $filenames = $output;
}
Peter Bowey’s picture

Many thanks Mike!

Is that a real 'bug' with css_emimage_advagg_css_extra_alter() - per my tests above?

incorrect '<!--[if gte IE 8]><!-->'

Some amazing 'potential' exists in advagg APIs!

mikeytown2’s picture

In regards to css_emimage; thats the problem when you only use a hook in one place, one finds bugs when the 2nd implementation of the API is in use. A quick fix for that below.

function css_emimage_advagg_css_extra_alter(&$values) {
  list($filename, $bundle_md5, $prefix, $suffix) = $values;
  if (!empty($prefix) || !empty($suffix)) {
    return;
  }
  $type = cache_get($bundle_md5, 'cache_css_emimage_advagg');
  if (!empty($type->data)) {
    $type = $type->data;
  }

mikeytown2’s picture

Project: Advanced CSS/JS Aggregation » Fork of CSS Embedded Images
Version: 6.x-1.x-dev »

Moving this over here, so it can be fixed.

mikeytown2’s picture

Component: Miscellaneous » Code
Category: support » bug
Status: Needs review » Fixed
StatusFileSize
new517 bytes

This patch has been committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

notes on css_emimage as guide