/** * Adds a new CSS style to this rule. * * @param css_style|string $style Adds a new style to this rule */ public function add_style($style) { if (is_string($style)) { $style = trim($style); if (empty($style)) { return; } $bits = explode(':', $style, 2); if (count($bits) == 2) { list($name, $value) = array_map('trim', $bits); } if (isset($name) && isset($value) && $name !== '' && $value !== '') { $style = css_style::init_automatic($name, $value); } } else { if ($style instanceof css_style) { // Clone the style as it may be coming from another rule and we don't // want references as it will likely be overwritten by proceeding // rules $style = clone $style; } } if ($style instanceof css_style) { $name = $style->get_name(); if (array_key_exists($name, $this->styles)) { $this->styles[$name]->set_value($style->get_value()); } else { $this->styles[$name] = $style; } } else { if (is_array($style)) { // We probably shouldn't worry about processing styles here but to // be truthful it doesn't hurt. foreach ($style as $astyle) { $this->add_style($astyle); } } } }
/** * Adds a new CSS style to this rule. * * @param css_style|string $style Adds a new style to this rule */ public function add_style($style) { if (is_string($style)) { $style = trim($style); if (empty($style)) { return; } $bits = explode(':', $style, 2); if (count($bits) == 2) { list($name, $value) = array_map('trim', $bits); } if (isset($name) && isset($value) && $name !== '' && $value !== '') { $style = css_style::init_automatic($name, $value); } } else { if ($style instanceof css_style) { // Clone the style as it may be coming from another rule and we don't // want references as it will likely be overwritten by proceeding // rules $style = clone $style; } } if ($style instanceof css_style) { $name = $style->get_name(); $exists = array_key_exists($name, $this->styles); // We need to find out if the current style support multiple values, or whether the style // is already set up to record multiple values. This can happen with background images which can have single // and multiple values. if ($style->allows_multiple_values() || $exists && is_array($this->styles[$name])) { if (!$exists) { $this->styles[$name] = array(); } else { if ($this->styles[$name] instanceof css_style) { $this->styles[$name] = array($this->styles[$name]); } } $this->styles[$name][] = $style; } else { if ($exists) { $this->styles[$name]->set_value($style->get_value()); } else { $this->styles[$name] = $style; } } } else { if (is_array($style)) { // We probably shouldn't worry about processing styles here but to // be truthful it doesn't hurt. foreach ($style as $astyle) { $this->add_style($astyle); } } } }