function dynamic_background_create_css in Dynamic Background 6
Same name and namespace in other branches
- 7.2 dynamic_background.module \dynamic_background_create_css()
- 7 dynamic_background.module \dynamic_background_create_css()
Helper function that creates CSS based on user supplied css.
Parameters
array $images_conf:
boolean $reset optional:
Return value
string $css or FALSE if custom CSS have not been defined
2 calls to dynamic_background_create_css()
- dynamic_background_css in ./
dynamic_background.module - Menu callback function used to generate an body style css with the selected background image. The callback is /background.css.
- dynamic_background_preprocess_page in ./
dynamic_background.module - Page preprocess function used to create the $background variable, so it can be used in page.tpl.
File
- ./
dynamic_background.module, line 74 - This module enables administrators to upload images used as background on the site. The selected background image link is exposed as either $background in the page.tpl file or as /background.css.
Code
function dynamic_background_create_css($images_conf, $reset = FALSE) {
static $css;
if (!isset($css) || $reset) {
// Build style array based on weight, this will allow weight base override
// at the same time allowing different selectors.
$style_array = array();
foreach ($images_conf as $image_conf) {
// Only use image if css behaviour have be set.
if (!empty($image_conf['configuration'])) {
// Add imagecache preset, if one have been defined.
$image = $image_conf['image'];
if (isset($image_conf['imagecache']) && $image_conf['imagecache']) {
// Imagecache preset found, so update the image path with a
// imagecache based one.
$image = imagecache_create_path($image_conf['imagecache'], $image);
}
// Check if selector have been used, if it have and has a higher weight
// override it.
if (isset($style_array[$image_conf['configuration']['selector']])) {
if ($style_array[$image_conf['configuration']['selector']]['weight'] < $image_conf['weight']) {
// This css selector have been used before and the new whan was
// fater, so override the select in the style array.
$style_array[$image_conf['configuration']['selector']] = array(
'css' => $image_conf['configuration']['css'],
'image' => $image,
'weight' => $image_conf['weight'],
);
}
}
else {
// This selector have not been used before, so add it to the array.
$style_array[$image_conf['configuration']['selector']] = array(
'css' => $image_conf['configuration']['css'],
'image' => $image,
'weight' => $image_conf['weight'],
);
}
}
}
// Build css based on weighted style array.
$css = '';
foreach ($style_array as $selector => $style) {
$css .= $selector . " {\n background-image: url('" . file_create_url($style['image']) . "');\n " . $style['css'] . "\n }\n";
}
}
return $css;
}