function readBackground() { // Read the background configuration XML $background_data = readXML('conf', 'background'); // Get the default values $background_default = defaultBackground(); // Stored data array $background_conf = array(); // Read the stored values if ($background_data) { // Initialize the background configuration XML data $background_xml = new SimpleXMLElement($background_data); // Loop the notice configuration elements foreach ($background_xml->children() as $background_child) { $background_conf[$background_child->getName()] = $background_child; } } // Checks no value is missing in the stored configuration foreach ($background_default as $background_name => $background_value) { if (!isset($background_conf[$background_name]) || empty($background_conf[$background_name])) { $background_conf[$background_name] = $background_default[$background_name]; } } return $background_conf; }
function setBackground($string) { // Get the default values $array = defaultBackground(); // Read the background configuration $xml = readXML('conf', 'background'); if ($xml) { $read = new SimpleXMLElement($xml); foreach ($read->children() as $child) { $current_child = (string) $child; // Any value? if ($current_child) { $array[$child->getName()] = $current_child; } } } $css = ''; // Generate the CSS code switch ($array['type']) { // Image case 'image': $css .= "\n" . ' background-image: url(../store/backgrounds/' . urlencode($array['image_file']) . '); background-repeat: ' . $array['image_repeat'] . '; background-position: ' . $array['image_horizontal'] . ' ' . $array['image_vertical'] . '; background-color: ' . $array['image_color'] . ';'; // Add CSS code to adapt the image? if ($array['image_adapt'] == 'on') { $css .= ' background-attachment: fixed; background-size: cover; -moz-background-size: cover; -webkit-background-size: cover;'; } $css .= "\n"; break; // Color // Color case 'color': $css .= "\n" . ' background-color: ' . $array['color_color'] . ';' . "\n"; break; // Default: use the filtering regex // Default: use the filtering regex default: $css .= '$3'; break; } // Apply the replacement! return preg_replace('/(\\.body-images( )?\\{)([^\\{\\}]+)(\\})/i', '$1' . $css . '$4', $string); }