You are here

function _css_emimage_build_external in CSS Embedded Images 6.2

Same name and namespace in other branches
  1. 7 css_emimage.inc \_css_emimage_build_external()

Generates CSS with external data URIs.

Return value

array a tuple where the first element is the updated CSS and the second element is the CSS declarations containing only data URIs

1 call to _css_emimage_build_external()
_css_emimage_text_processor in ./css_emimage.module
Process the css text and replace it with image data where necessary.

File

./css_emimage.module, line 660
CSS Embedded Images module.

Code

function _css_emimage_build_external($css, $declarations) {
  $datauri_css = '';
  foreach ($declarations as $data) {
    if ($data['base64']) {
      $css = str_replace($data['token'], 'none', $css);
      $datauri_css .= implode(',', $data['selectors']) . '{' . $data['property'] . ':url(data:' . $data['mime_type'] . ';base64,' . $data['base64'] . ')' . ($data['important'] ? ' !important' : '') . ";}\n";
    }
    else {
      if ($datauri_css) {

        // Only add these if the CSS has at least one data URI.
        $css = str_replace($data['token'], 'none', $css);
        $datauri_css .= implode(',', $data['selectors']) . '{' . $data['property'] . ':' . $data['url'] . ($data['important'] ? ' !important' : '') . ";}\n";
      }
      else {
        $css = str_replace($data['token'], $data['url'], $css);
      }
    }
  }
  return array(
    $css,
    $datauri_css,
  );
}