You are here

function _wysiwyg_pre_render_styles in Wysiwyg 7.2

Creates a cache of the stylesheets used by the currently set theme.

Since this is a pre render callback for the styles element, it should run late enough to catch all the stylesheets added just before the actual markup for them is rendered.

The first time this runs for a theme it's too late for a module to have any use of the cache, so wysiwyg_get_css() uses drupal_http_request() to fetch a dummy page, filling the cache before the original response is sent.

Intended to run after Core has sorted/grouped/aggregated stylesheets.

1 string reference to '_wysiwyg_pre_render_styles'
wysiwyg_element_info_alter in ./wysiwyg.module
Implements hook_element_info_alter().

File

includes/styling.inc, line 109
Handles adding theme stylesheets into WYSIWYG editors.

Code

function _wysiwyg_pre_render_styles($elements) {
  global $theme_key;
  $css = array();
  if (strpos(current_path(), 'wysiwyg_theme/') !== 0) {
    return $elements;
  }
  $cached = cache_get('wysiwyg_css');
  foreach (element_children($elements) as $child) {
    switch ($elements[$child]['#tag']) {
      case 'link':
        $css[] = $elements[$child]['#attributes']['href'];
        break;
      case 'style':
        if (!empty($elements[$child]['#attributes']['href'])) {
          $css[] = $elements[$child]['#attributes']['href'];
        }
        elseif (!empty($elements[$child]['#value'])) {
          preg_match_all('/\\@import url\\("([^"]+)"\\);/', $elements[$child]['#value'], $matches, PREG_SET_ORDER);
          foreach ($matches as $val) {
            $css[] = $val[1];
          }
        }
        break;
    }
    $all = empty($cached->data) ? array() : $cached->data;
    $all[$theme_key] = array(
      'files' => $css,
      'aggregated' => variable_get('preprocess_css', FALSE),
    );
  }
  $all['_css_js_query_string'] = variable_get('css_js_query_string');
  cache_set('wysiwyg_css', $all);
  return $elements;
}