function _css_emimage_build_external in CSS Embedded Images 7
Same name and namespace in other branches
- 6.2 css_emimage.module \_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
2 calls to _css_emimage_build_external()
- _css_emimage_process in ./
css_emimage.module - Helper function to replace URLs with data URIs.
- _css_emimage_text_processor in ./
css_emimage.advagg.inc - Process the css text and replace it with image data where necessary.
File
- ./
css_emimage.inc, line 44 - 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);
$insert_string = implode(',', $data['selectors']) . '{' . $data['property'] . ':url(data:' . $data['mime_type'] . ';base64,' . $data['base64'] . ')' . ($data['important'] ? ' !important' : '') . ";}\n";
if (!empty($data['media_query'])) {
$insert_string = $data['media_query'] . ' { ' . $insert_string . ' } ';
}
$datauri_css .= $insert_string;
}
elseif ($datauri_css) {
// Only add these if the CSS has at least one data URI.
$css = str_replace($data['token'], 'none', $css);
$insert_string = implode(',', $data['selectors']) . '{' . $data['property'] . ':' . $data['url'] . ($data['important'] ? ' !important' : '') . ";}\n";
if (!empty($data['media_query'])) {
$insert_string = $data['media_query'] . ' { ' . $insert_string . ' } ';
}
$datauri_css .= $insert_string;
}
else {
$css = str_replace($data['token'], $data['url'], $css);
}
}
return array(
$css,
$datauri_css,
);
}