* Please see the {@link css_optimiser} class for greater detail.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$css = $optimiser->process($css);
// If cssoptimisestats is set then stats from the optimisation are collected
- // and output at the beginning of the CSS
+ // and output at the beginning of the CSS.
if (!empty($CFG->cssoptimiserstats)) {
$css = $optimiser->output_stats_css().$css;
}
fclose($fp);
rename($filename.'.tmp', $filename);
@chmod($filename, $CFG->filepermissions);
- @unlink($filename.'.tmp'); // just in case anything fails
+ @unlink($filename.'.tmp'); // Just in case anything fails.
}
}
* @param string $etag The revision to make sure we utilise any caches.
*/
function css_send_cached_css($csspath, $etag) {
- $lifetime = 60*60*24*60; // 60 days only - the revision may get incremented quite often
+ // 60 days only - the revision may get incremented quite often.
+ $lifetime = 60*60*24*60;
header('Etag: "'.$etag.'"');
header('Content-Disposition: inline; filename="styles.php"');
*
* @param string $css
*/
-function css_send_uncached_css($css, $themesupportsoptimisation = true) {
- global $CFG;
-
+function css_send_uncached_css($css) {
header('Content-Disposition: inline; filename="styles_debug.php"');
header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
header('Expires: '. gmdate('D, d M Y H:i:s', time() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT');
if (is_array($css)) {
$css = implode("\n\n", $css);
}
-
echo $css;
-
die;
}
/**
* Send file not modified headers
+ *
* @param int $lastmodified
* @param string $etag
*/
function css_send_unmodified($lastmodified, $etag) {
- $lifetime = 60*60*24*60; // 60 days only - the revision may get incremented quite often
+ // 60 days only - the revision may get incremented quite often.
+ $lifetime = 60*60*24*60;
header('HTTP/1.1 304 Not Modified');
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
header('Cache-Control: public, max-age='.$lifetime);
} else if (in_array(strtolower($value), array_keys(css_optimiser::$htmlcolours))) {
return true;
} else if (preg_match($rgb, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
- // It is an RGB colour
+ // It is an RGB colour.
return true;
} else if (preg_match($rgba, $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
- // It is an RGBA colour
+ // It is an RGBA colour.
return true;
} else if (preg_match($hsl, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
- // It is an HSL colour
+ // It is an HSL colour.
return true;
} else if (preg_match($hsla, $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
- // It is an HSLA colour
+ // It is an HSLA colour.
return true;
}
// Doesn't look like a colour.
}
/**
- * A basic CSS optimiser that strips out unwanted things and then processing the
- * CSS organising styles and moving duplicates and useless CSS.
+ * A basic CSS optimiser that strips out unwanted things and then processes CSS organising and cleaning styles.
*
* This CSS optimiser works by reading through a CSS string one character at a
* time and building an object structure of the CSS.
* then combined into an optimised form to keep them as short as possible.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* @return string The optimised CSS
*/
public function process($css) {
- global $CFG;
-
- // Easiest win there is
+ // Easiest win there is.
$css = trim($css);
$this->reset_stats();
$css = preg_replace('#\r?\n#', ' ', $css);
// Next remove the comments... no need to them in an optimised world and
- // knowing they're all gone allows us to REALLY make our processing simpler
+ // knowing they're all gone allows us to REALLY make our processing simpler.
$css = preg_replace('#/\*(.*?)\*/#m', '', $css, -1, $this->commentsincss);
$medias = array(
$inbraces = false; // {
$inbrackets = false; // [
$inparenthesis = false; // (
+ /* @var css_media $currentmedia */
$currentmedia = $medias['all'];
$currentatrule = null;
$suspectatrule = false;
$suspectatrule = true;
}
switch ($currentprocess) {
- // Start processing an @ rule e.g. @media, @page, @keyframes
+ // Start processing an @ rule e.g. @media, @page, @keyframes.
case self::PROCESSING_ATRULE:
switch ($char) {
case ';':
$buffer = '';
$currentatrule = false;
}
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case '{':
- if ($currentatrule == 'media' && preg_match('#\s*@media\s*([a-zA-Z0-9]+(\s*,\s*[a-zA-Z0-9]+)*)\s*{#', $buffer, $matches)) {
- // Basic media declaration
+ $regexmediabasic = '#\s*@media\s*([a-zA-Z0-9]+(\s*,\s*[a-zA-Z0-9]+)*)\s*{#';
+ $regexadvmedia = '#\s*@media\s*([^{]+)#';
+ $regexkeyframes = '#@((\-moz\-|\-webkit\-|\-ms\-|\-o\-)?keyframes)\s*([^\s]+)#';
+
+ if ($currentatrule == 'media' && preg_match($regexmediabasic, $buffer, $matches)) {
+ // Basic media declaration.
$mediatypes = str_replace(' ', '', $matches[1]);
if (!array_key_exists($mediatypes, $medias)) {
$medias[$mediatypes] = new css_media($mediatypes);
$currentmedia = $medias[$mediatypes];
$currentprocess = self::PROCESSING_SELECTORS;
$buffer = '';
- } else if ($currentatrule == 'media' && preg_match('#\s*@media\s*([^{]+)#', $buffer, $matches)) {
- // Advanced media query declaration http://www.w3.org/TR/css3-mediaqueries/
+ } else if ($currentatrule == 'media' && preg_match($regexadvmedia, $buffer, $matches)) {
+ // Advanced media query declaration http://www.w3.org/TR/css3-mediaqueries/.
$mediatypes = $matches[1];
$hash = md5($mediatypes);
$medias[$hash] = new css_media($mediatypes);
$currentmedia = $medias[$hash];
$currentprocess = self::PROCESSING_SELECTORS;
$buffer = '';
- } else if ($currentatrule == 'keyframes' && preg_match('#@((\-moz\-|\-webkit\-)?keyframes)\s*([^\s]+)#', $buffer, $matches)) {
+ } else if ($currentatrule == 'keyframes' && preg_match($regexkeyframes, $buffer, $matches)) {
// Keyframes declaration, we treat it exactly like a @media declaration except we don't allow
- // them to be overridden to ensure we don't mess anything up. (means we keep everything in order)
+ // them to be overridden to ensure we don't mess anything up. (means we keep everything in order).
$keyframefor = $matches[1];
$keyframename = $matches[3];
$keyframe = new css_keyframe($keyframefor, $keyframename);
$currentprocess = self::PROCESSING_SELECTORS;
$buffer = '';
}
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
break;
- // Start processing selectors
+ // Start processing selectors.
case self::PROCESSING_START:
case self::PROCESSING_SELECTORS:
+ $regexatrule = '#@(media|import|charset|(\-moz\-|\-webkit\-|\-ms\-|\-o\-)?(keyframes))\s*#';
switch ($char) {
case '[':
$inbrackets ++;
$buffer .= $char;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case ']':
$inbrackets --;
$buffer .= $char;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case ' ':
if ($inbrackets) {
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
if (!empty($buffer)) {
- // Check for known @ rules
- if ($suspectatrule && preg_match('#@(media|import|charset|(\-moz\-|\-webkit\-)?(keyframes))\s*#', $buffer, $matches)) {
+ // Check for known @ rules.
+ if ($suspectatrule && preg_match($regexatrule, $buffer, $matches)) {
$currentatrule = (!empty($matches[3]))?$matches[3]:$matches[1];
$currentprocess = self::PROCESSING_ATRULE;
$buffer .= $char;
}
}
$suspectatrule = false;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case '{':
if ($inbrackets) {
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
+ continue 3;
+ }
+ // Check for known @ rules.
+ if ($suspectatrule && preg_match($regexatrule, $buffer, $matches)) {
+ // Ahh we've been in an @rule, lets rewind one and have the @rule case process this.
+ $currentatrule = (!empty($matches[3]))?$matches[3]:$matches[1];
+ $currentprocess = self::PROCESSING_ATRULE;
+ $i--;
+ $suspectatrule = false;
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
if ($buffer !== '') {
$currentprocess = self::PROCESSING_STYLES;
$buffer = '';
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case '}':
if ($inbrackets) {
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
if ($currentatrule == 'media') {
$currentatrule = false;
$buffer = '';
}
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case ',':
if ($inbrackets) {
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
$currentselector->add($buffer);
$currentrule->add_selector($currentselector);
$currentselector = css_selector::init();
$buffer = '';
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
break;
- // Start processing styles
+ // Start processing styles.
case self::PROCESSING_STYLES:
if ($char == '"' || $char == "'") {
if ($inquotes === false) {
case ';':
if ($inparenthesis) {
$buffer .= $char;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
$currentrule->add_style($buffer);
$buffer = '';
$inquotes = false;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case '}':
$currentrule->add_style($buffer);
$buffer = '';
$inquotes = false;
$inparenthesis = false;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case '(':
$inparenthesis = true;
$buffer .= $char;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
case ')':
$inparenthesis = false;
$buffer .= $char;
- // continue 1: The switch processing chars
- // continue 2: The switch processing the state
- // continue 3: The for loop
+ // Continue 1: The switch processing chars
+ // Continue 2: The switch processing the state
+ // Continue 3: The for loop.
continue 3;
}
break;
* Produces CSS for the given charset, imports, media, and keyframes
* @param string $charset
* @param array $imports
- * @param array $medias
- * @param array $keyframes
+ * @param css_media[] $medias
+ * @param css_keyframe[] $keyframes
* @return string
*/
protected function produce_css($charset, array $imports, array $medias, array $keyframes) {
$cssstandard = array();
$csskeyframes = array();
- // Process each media declaration individually
+ // Process each media declaration individually.
foreach ($medias as $media) {
- // If this declaration applies to all media types
+ // If this declaration applies to all media types.
if (in_array('all', $media->get_types())) {
// Collect all rules that represet reset rules and remove them from the media object at the same time.
// We do this because we prioritise reset rules to the top of a CSS output. This ensures that they
$cssreset[] = css_writer::media('all', $resetrules);
}
}
- // Get the standard cSS
+ // Get the standard cSS.
$cssstandard[] = $media->out();
}
}
}
- // Join it all together
+ // Join it all together.
$css .= join('', $cssreset);
$css .= join('', $cssstandard);
$css .= join('', $csskeyframes);
// Record the strlenght of the now optimised CSS.
$this->optimisedstrlen = strlen($css);
- // Return the now produced CSS
+ // Return the now produced CSS.
return $css;
}
'improvementrules' => '-',
'improvementselectors' => '-',
);
- // Avoid division by 0 errors by checking we have valid raw values
+ // Avoid division by 0 errors by checking we have valid raw values.
if ($this->rawstrlen > 0) {
$stats['improvementstrlen'] = round(100 - ($this->optimisedstrlen / $this->rawstrlen) * 100, 1).'%';
}
public function get_errors($clear = false) {
$errors = $this->errors;
if ($clear) {
- // Reset the error array
+ // Reset the error array.
$this->errors = array();
}
return $errors;
* This reference table is used to allow us to unify colours, and will aid
* us in identifying buggy CSS using unsupported colours.
*
- * @staticvar array
- * @var array
+ * @var string[]
*/
public static $htmlcolours = array(
'aliceblue' => '#F0F8FF',
* Used to prepare CSS strings
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* Returns CSS for media
*
* @param string $typestring
- * @param array $rules An array of css_rule objects
+ * @param css_rule[] $rules An array of css_rule objects
* @return string
*/
public static function media($typestring, array &$rules) {
*
* @param string $for The desired declaration. e.g. keyframes, -moz-keyframes, -webkit-keyframes
* @param string $name The name for the keyframe
- * @param array $rules An array of rules belonging to the keyframe
+ * @param css_rule[] $rules An array of rules belonging to the keyframe
* @return string
*/
public static function keyframe($for, $name, array &$rules) {
- $nl = self::get_separator();
-
$output = "\n@{$for} {$name} {";
foreach ($rules as $rule) {
$output .= $rule->out();
/**
* Returns CSS for the selectors of a rule
*
- * @param array $selectors Array of css_selector objects
+ * @param css_selector[] $selectors Array of css_selector objects
* @return string
*/
public static function selectors(array $selectors) {
/**
* Returns a CSS string for the provided styles
*
- * @param array $styles Array of css_style objects
+ * @param css_style[] $styles Array of css_style objects
* @return string
*/
public static function styles(array $styles) {
// An advanced style is a style with one or more values, and can occur in situations like background-image
// where browse specific values are being used.
if (is_array($style)) {
+ /* @var css_style[] $style */
foreach ($style as $advstyle) {
$bits[] = $advstyle->out();
}
}
}
+/**
+ * A consolidatable style interface.
+ *
+ * Class that implement this have a short-hand notation for specifying multiple styles.
+ *
+ * @package core
+ * @subpackage cssoptimiser
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+interface core_css_consolidatable_style {
+ /**
+ * Used to consolidate several styles into a single "short-hand" style.
+ * @param array $styles
+ * @return mixed
+ */
+ public static function consolidate(array $styles);
+}
+
/**
* A structure to represent a CSS selector.
*
* rule.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* CSS selectors can only be created through the init method above.
*/
- protected function __construct() {}
+ protected function __construct() {
+ // Nothing to do here by default.
+ }
/**
* Adds a selector to the end of the current selector
if (strpos($selector, '.') !== 0 && strpos($selector, '#') !== 0) {
$count ++;
}
- // If its already false then no need to continue, its not basic
+ // If its already false then no need to continue, its not basic.
if ($this->isbasic !== false) {
- // If theres more than one part making up this selector its not basic
+ // If theres more than one part making up this selector its not basic.
if ($count > 1) {
$this->isbasic = false;
} else {
- // Check whether it is a basic element (a-z+) with possible psuedo selector
+ // Check whether it is a basic element (a-z+) with possible psuedo selector.
$this->isbasic = (bool)preg_match('#^[a-z]+(:[a-zA-Z]+)?$#', $selector);
}
}
* A structure to represent a CSS rule.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* An array of CSS selectors {@link css_selector}
- * @var array
+ * @var css_selector[]
*/
protected $selectors = array();
/**
* An array of CSS styles {@link css_style}
- * @var array
+ * @var css_style[]
*/
protected $styles = array();
* Constructs a new css rule.
*
* @param string $selector The selector or array of selectors that make up this rule.
- * @param array $styles An array of styles that belong to this rule.
+ * @param css_style[] $styles An array of styles that belong to this rule.
*/
protected function __construct($selector = null, array $styles = array()) {
if ($selector != null) {
} 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
+ // rules.
$style = clone($style);
}
if ($style instanceof css_style) {
* This method simply iterates over the array and calls {@link css_rule::add_style()}
* with each.
*
- * @param array $styles Adds an array of styles
+ * @param css_style[] $styles Adds an array of styles
*/
public function add_styles(array $styles) {
foreach ($styles as $style) {
/**
* Returns the array of selectors
*
- * @return array
+ * @return css_selector[]
*/
public function get_selectors() {
return $this->selectors;
/**
* Returns the array of styles
*
- * @return array
+ * @return css_style[]
*/
public function get_styles() {
return $this->styles;
/**
* Consolidates all styles associated with this rule
*
- * @return array An array of consolidated styles
+ * @return css_style[] An array of consolidated styles
*/
public function get_consolidated_styles() {
+ /* @var css_style[] $organisedstyles */
$organisedstyles = array();
+ /* @var css_style[] $finalstyles */
$finalstyles = array();
+ /* @var core_css_consolidatable_style[] $consolidate */
$consolidate = array();
+ /* @var css_style[] $advancedstyles */
$advancedstyles = array();
foreach ($this->styles as $style) {
// If the style is an array then we are processing an advanced style. An advanced style is a style that can have
$single = null;
$count = 0;
foreach ($style as $advstyle) {
+ /* @var css_style $advstyle */
$key = $count++;
$advancedstyles[$key] = $advstyle;
if (!$advstyle->allows_multiple_values()) {
$style = $advancedstyles[$single];
$consolidatetoclass = $style->consolidate_to();
- if (($style->is_valid() || $style->is_special_empty_value()) && !empty($consolidatetoclass) && class_exists('css_style_'.$consolidatetoclass)) {
+ if (($style->is_valid() || $style->is_special_empty_value()) && !empty($consolidatetoclass) &&
+ class_exists('css_style_'.$consolidatetoclass)) {
$class = 'css_style_'.$consolidatetoclass;
if (!array_key_exists($class, $consolidate)) {
$consolidate[$class] = array();
continue;
}
$consolidatetoclass = $style->consolidate_to();
- if (($style->is_valid() || $style->is_special_empty_value()) && !empty($consolidatetoclass) && class_exists('css_style_'.$consolidatetoclass)) {
+ if (($style->is_valid() || $style->is_special_empty_value()) && !empty($consolidatetoclass) &&
+ class_exists('css_style_'.$consolidatetoclass)) {
$class = 'css_style_'.$consolidatetoclass;
if (!array_key_exists($class, $consolidate)) {
$consolidate[$class] = array();
}
foreach ($consolidate as $class => $styles) {
- $organisedstyles[$class] = $class::consolidate($styles);
+ $organisedstyles[$class] = call_user_func(array($class, 'consolidate'), $styles);
}
foreach ($organisedstyles as $style) {
* Splits this rules into an array of CSS rules. One for each of the selectors
* that make up this rule.
*
- * @return array(css_rule)
+ * @return css_rule[]
*/
public function split_by_selector() {
$return = array();
* Splits this rule into an array of rules. One for each of the styles that
* make up this rule
*
- * @return array Array of css_rule objects
+ * @return css_rule[] Array of css_rule objects
*/
public function split_by_style() {
$return = array();
public function has_errors() {
foreach ($this->styles as $style) {
if (is_array($style)) {
+ /* @var css_style[] $style */
foreach ($style as $advstyle) {
if ($advstyle->has_error()) {
return true;
$errors = array();
foreach ($this->styles as $style) {
if (is_array($style)) {
- foreach ($style as $s) {
- if ($style instanceof css_style && $style->has_error()) {
- $errors[] = " * ".$style->get_last_error();
+ /* @var css_style[] $style */
+ foreach ($style as $advstyle) {
+ if ($advstyle instanceof css_style && $advstyle->has_error()) {
+ $errors[] = " * ".$advstyle->get_last_error();
}
}
} else if ($style instanceof css_style && $style->has_error()) {
* When no declaration is specified rules accumulate into @media all.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class css_rule_collection {
/**
* An array of rules within this collection instance
- * @var array
+ * @var css_rule[]
*/
protected $rules = array();
/**
* Returns the rules used by this collection
*
- * @return array
+ * @return css_rule[]
*/
public function get_rules() {
return $this->rules;
* @return bool True if the CSS was optimised by this method
*/
public function organise_rules_by_selectors() {
- $optimised = array();
+ /* @var css_rule[] $optimisedrules */
+ $optimisedrules = array();
$beforecount = count($this->rules);
$lasthash = null;
+ /* @var css_rule $lastrule */
$lastrule = null;
foreach ($this->rules as $rule) {
$hash = $rule->get_style_hash();
}
$lastrule = clone($rule);
$lasthash = $hash;
- $optimised[] = $lastrule;
+ $optimisedrules[] = $lastrule;
}
$this->rules = array();
- foreach ($optimised as $optimised) {
+ foreach ($optimisedrules as $optimised) {
$this->rules[$optimised->get_selector_hash()] = $optimised;
}
$aftercount = count($this->rules);
/**
* Returns any errors that have happened within rules in this collection.
*
- * @return string
+ * @return string[]
*/
public function get_errors() {
$errors = array();
* A media class to organise rules by the media they apply to.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A media class to organise rules by the media they apply to.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class css_keyframe extends css_rule_collection {
- /** @var string $for The directive e.g. keyframes, -moz-keyframes, -webkit-keyframes */
+ /**
+ * The directive e.g. keyframes, -moz-keyframes, -webkit-keyframes
+ * @var string
+ */
protected $for;
- /** @var string $name The name for the keyframes */
+ /**
+ * The name for the keyframes
+ * @var string
+ */
protected $name;
/**
* Constructs a new keyframe
* An absract class to represent CSS styles
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* @return css_style_generic
*/
public static function init_automatic($name, $value) {
- $specificclass = 'css_style_'.preg_replace('#[^a-zA-Z0-9]+#', '', $name);
+ $cleanedname = preg_replace('#[^a-zA-Z0-9]+#', '', $name);
+ $specificclass = 'css_style_'.$cleanedname;
if (class_exists($specificclass)) {
- return $specificclass::init($value);
+ $style = call_user_func(array($specificclass, 'init'), $value);
+ if ($cleanedname !== $name && !is_array($style)) {
+ $style->set_actual_name($name);
+ }
+ return $style;
}
return new css_style_generic($name, $value);
}
public function set_important($important = true) {
$this->important = (bool) $important;
}
+
+ /**
+ * Sets the actual name used within the style.
+ *
+ * This method allows us to support browser hacks like *width:0;
+ *
+ * @param string $name
+ */
+ public function set_actual_name($name) {
+ $this->name = $name;
+ }
}
/**
* A generic CSS style class to use when a more specific class does not exist.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A colour CSS style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A width style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A margin style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class css_style_margin extends css_style_width {
+class css_style_margin extends css_style_width implements core_css_consolidatable_style {
/**
* Initialises a margin style.
/**
* Consolidates individual margin styles into a single margin style
*
- * @param array $styles
- * @return array An array of consolidated styles
+ * @param css_style[] $styles
+ * @return css_style[] An array of consolidated styles
*/
public static function consolidate(array $styles) {
if (count($styles) != 4) {
* A margin top style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A margin right style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A margin bottom style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A margin left style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class css_style_border extends css_style {
+class css_style_border extends css_style implements core_css_consolidatable_style {
/**
* Initalises the border style into an array of individual style compontents
if (!css_style_borderwidth::is_border_width($width)) {
$width = '0';
}
- $return[] = new css_style_borderwidth('border-top-width', $width);
- $return[] = new css_style_borderwidth('border-right-width', $width);
- $return[] = new css_style_borderwidth('border-bottom-width', $width);
- $return[] = new css_style_borderwidth('border-left-width', $width);
+ $return[] = css_style_bordertopwidth::init($width);
+ $return[] = css_style_borderrightwidth::init($width);
+ $return[] = css_style_borderbottomwidth::init($width);
+ $return[] = css_style_borderleftwidth::init($width);
}
if (count($bits) > 0) {
$style = array_shift($bits);
- $return[] = new css_style_borderstyle('border-top-style', $style);
- $return[] = new css_style_borderstyle('border-right-style', $style);
- $return[] = new css_style_borderstyle('border-bottom-style', $style);
- $return[] = new css_style_borderstyle('border-left-style', $style);
+ $return[] = css_style_bordertopstyle::init($style);
+ $return[] = css_style_borderrightstyle::init($style);
+ $return[] = css_style_borderbottomstyle::init($style);
+ $return[] = css_style_borderleftstyle::init($style);
}
if (count($bits) > 0) {
$colour = array_shift($bits);
- $return[] = new css_style_bordercolor('border-top-color', $colour);
- $return[] = new css_style_bordercolor('border-right-color', $colour);
- $return[] = new css_style_bordercolor('border-bottom-color', $colour);
- $return[] = new css_style_bordercolor('border-left-color', $colour);
+ $return[] = css_style_bordertopcolor::init($colour);
+ $return[] = css_style_borderrightcolor::init($colour);
+ $return[] = css_style_borderbottomcolor::init($colour);
+ $return[] = css_style_borderleftcolor::init($colour);
}
return $return;
}
/**
* Consolidates all border styles into a single style
*
- * @param array $styles An array of border styles
- * @return array An optimised array of border styles
+ * @param css_style[] $styles An array of border styles
+ * @return css_style[] An optimised array of border styles
*/
public static function consolidate(array $styles) {
$allstylesnull = $allstylesthesame && $nullstyles;
$allcolorsnull = $allcolorsthesame && $nullcolors;
+ /* @var css_style[] $return */
$return = array();
if ($allwidthsnull && $allstylesnull && $allcolorsnull) {
- // Everything is null still... boo
+ // Everything is null still... boo.
return array(new css_style_border('border', ''));
} else if ($allwidthsnull && $allstylesnull) {
self::consolidate_styles_by_direction($return, 'css_style_bordercolor', 'border-color', $bordercolors);
}
- } else if (!$nullwidths && !$nullcolors && !$nullstyles && max(array_count_values($borderwidths)) == 3 && max(array_count_values($borderstyles)) == 3 && max(array_count_values($bordercolors)) == 3) {
+ } else if (!$nullwidths && !$nullcolors && !$nullstyles &&
+ max(array_count_values($borderwidths)) == 3 &&
+ max(array_count_values($borderstyles)) == 3 &&
+ max(array_count_values($bordercolors)) == 3) {
+
$widthkeys = array();
$stylekeys = array();
$colorkeys = array();
if ($widthkeys == $stylekeys && $stylekeys == $colorkeys) {
$key = $widthkeys[0][0];
- self::build_style_string($return, 'css_style_border', 'border', $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
+ self::build_style_string($return, 'css_style_border', 'border',
+ $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
$key = $widthkeys[1][0];
- self::build_style_string($return, 'css_style_border'.$key, 'border-'.$key, $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
+ self::build_style_string($return, 'css_style_border'.$key, 'border-'.$key,
+ $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
} else {
- self::build_style_string($return, 'css_style_bordertop', 'border-top', $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
- self::build_style_string($return, 'css_style_borderright', 'border-right', $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
- self::build_style_string($return, 'css_style_borderbottom', 'border-bottom', $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
- self::build_style_string($return, 'css_style_borderleft', 'border-left', $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
+ self::build_style_string($return, 'css_style_bordertop', 'border-top',
+ $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
+ self::build_style_string($return, 'css_style_borderright', 'border-right',
+ $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
+ self::build_style_string($return, 'css_style_borderbottom', 'border-bottom',
+ $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
+ self::build_style_string($return, 'css_style_borderleft', 'border-left',
+ $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
}
} else {
- self::build_style_string($return, 'css_style_bordertop', 'border-top', $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
- self::build_style_string($return, 'css_style_borderright', 'border-right', $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
- self::build_style_string($return, 'css_style_borderbottom', 'border-bottom', $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
- self::build_style_string($return, 'css_style_borderleft', 'border-left', $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
+ self::build_style_string($return, 'css_style_bordertop', 'border-top',
+ $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
+ self::build_style_string($return, 'css_style_borderright', 'border-right',
+ $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
+ self::build_style_string($return, 'css_style_borderbottom', 'border-bottom',
+ $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
+ self::build_style_string($return, 'css_style_borderleft', 'border-left',
+ $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
}
foreach ($return as $key => $style) {
if ($style->get_value() == '') {
* @param string $left The left value
* @return bool
*/
- public static function consolidate_styles_by_direction(&$array, $class, $style, $top, $right = null, $bottom = null, $left = null) {
+ public static function consolidate_styles_by_direction(&$array, $class, $style,
+ $top, $right = null, $bottom = null, $left = null) {
if (is_array($top)) {
$right = $top['right'];
$bottom = $top['bottom'];
* A border colour style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border left style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border right style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border top style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border bottom style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border width style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border style style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border top colour style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border left colour style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border right colour style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border bottom colour style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border width top style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border width left style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border width right style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border width bottom style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border top style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border left style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border right style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A border bottom style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background style
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class css_style_background extends css_style {
+class css_style_background extends css_style implements core_css_consolidatable_style {
/**
* Initialises a background style
* @return array An array of background component.
*/
public static function init($value) {
- // colour - image - repeat - attachment - position
-
+ // Colour - image - repeat - attachment - position.
$imageurl = null;
if (preg_match('#url\(([^\)]+)\)#', $value, $matches)) {
$imageurl = trim($matches[1]);
$value = str_replace($matches[1], '', $value);
}
- // Switch out the brackets so that they don't get messed up when we explode
+ // Switch out the brackets so that they don't get messed up when we explode.
$brackets = array();
$bracketcount = 0;
while (preg_match('#\([^\)\(]+\)#', $value, $matches)) {
$important = (stripos($value, '!important') !== false);
if ($important) {
- // Great some genius put !important in the background shorthand property
+ // Great some genius put !important in the background shorthand property.
$value = str_replace('!important', '', $value);
}
$attachments = array('scroll' , 'fixed', 'inherit');
$positions = array('top', 'left', 'bottom', 'right', 'center');
+ /* @var css_style_background[] $return */
$return = array();
$unknownbits = array();
$attachment = self::NULL_VALUE;
if (count($bits) > 0 && in_array(reset($bits), $attachments)) {
- // scroll , fixed, inherit
+ // Scroll , fixed, inherit.
$attachment = array_shift($bits);
}
}
}
- if ($color === self::NULL_VALUE && $image === self::NULL_VALUE && $repeat === self::NULL_VALUE && $attachment === self::NULL_VALUE && $position === self::NULL_VALUE) {
+ if ($color === self::NULL_VALUE &&
+ $image === self::NULL_VALUE &&
+ $repeat === self::NULL_VALUE && $attachment === self::NULL_VALUE &&
+ $position === self::NULL_VALUE) {
// All primaries are null, return without doing anything else. There may be advanced madness there.
return $return;
}
- $return[] = new css_style_backgroundcolor('background-color', $color);
- $return[] = new css_style_backgroundimage('background-image', $image);
- $return[] = new css_style_backgroundrepeat('background-repeat', $repeat);
- $return[] = new css_style_backgroundattachment('background-attachment', $attachment);
- $return[] = new css_style_backgroundposition('background-position', $position);
+ $return[] = css_style_backgroundcolor::init($color);
+ $return[] = css_style_backgroundimage::init($image);
+ $return[] = css_style_backgroundrepeat::init($repeat);
+ $return[] = css_style_backgroundattachment::init($attachment);
+ $return[] = css_style_backgroundposition::init($position);
if ($important) {
foreach ($return as $style) {
/**
* Consolidates background styles into a single background style
*
- * @param array $styles Consolidates the provided array of background styles
- * @return array Consolidated optimised background styles
+ * @param css_style_background[] $styles Consolidates the provided array of background styles
+ * @return css_style[] Consolidated optimised background styles
*/
public static function consolidate(array $styles) {
}
}
+ /* @var css_style[] $organisedstyles */
$organisedstyles = array();
+ /* @var css_style[] $advancedstyles */
$advancedstyles = array();
+ /* @var css_style[] $importantstyles */
$importantstyles = array();
foreach ($styles as $style) {
if ($style instanceof css_style_backgroundimage_advanced) {
}
}
+ /* @var css_style[] $consolidatetosingle */
$consolidatetosingle = array();
if (!is_null($color) && !is_null($image) && !is_null($repeat) && !is_null($attachment) && !is_null($position)) {
// We can use the shorthand background-style!
}
$return = array();
- // Single background style needs to come first;
+ // Single background style needs to come first.
if (count($consolidatetosingle) > 0) {
$returnstyle = new css_style_background('background', join(' ', $consolidatetosingle));
if ($allimportant) {
foreach ($styles as $style) {
$value = null;
switch ($style->get_name()) {
- case 'background-color' : $value = $color; break;
- case 'background-image' : $value = $image; break;
- case 'background-repeat' : $value = $repeat; break;
- case 'background-attachment' : $value = $attachment; break;
- case 'background-position' : $value = $position; break;
- case 'background-clip' : $value = $clip; break;
- case 'background-origin' : $value = $origin; break;
- case 'background-size' : $value = $size; break;
+ case 'background-color' :
+ $value = $color;
+ break;
+ case 'background-image' :
+ $value = $image;
+ break;
+ case 'background-repeat' :
+ $value = $repeat;
+ break;
+ case 'background-attachment' :
+ $value = $attachment;
+ break;
+ case 'background-position' :
+ $value = $position;
+ break;
+ case 'background-clip' :
+ $value = $clip;
+ break;
+ case 'background-origin':
+ $value = $origin;
+ break;
+ case 'background-size':
+ $value = $size;
+ break;
}
if (!is_null($value)) {
$return[] = $style;
* A advanced background style that allows multiple values to preserve unknown entities
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* Based upon the colour style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background image style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* @return css_style_backgroundimage
*/
public static function init($value) {
- if (!preg_match('#^\s*(none|inherit|url\()#i', $value)) {
+ if ($value !== self::NULL_VALUE && !preg_match('#^\s*(none|inherit|url\()#i', $value)) {
return css_style_backgroundimage_advanced::init($value);
}
return new css_style_backgroundimage('background-image', $value);
}
/**
- * A background image style that supports mulitple values and masquerades as a background-image
+ * A background image style that supports multiple values and masquerades as a background-image
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background repeat style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background attachment style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background position style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background size style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background clip style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A background origin style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A padding style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class css_style_padding extends css_style_width {
+class css_style_padding extends css_style_width implements core_css_consolidatable_style {
/**
* Initialises this padding style into several individual padding styles
/**
* Consolidates several padding styles into a single style.
*
- * @param array $styles Array of padding styles
- * @return array Optimised+consolidated array of padding styles
+ * @param css_style_padding[] $styles Array of padding styles
+ * @return css_style[] Optimised+consolidated array of padding styles
*/
public static function consolidate(array $styles) {
if (count($styles) != 4) {
$left = null;
foreach ($styles as $style) {
switch ($style->get_name()) {
- case 'padding-top' : $top = $style->get_value(false);break;
- case 'padding-right' : $right = $style->get_value(false);break;
- case 'padding-bottom' : $bottom = $style->get_value(false);break;
- case 'padding-left' : $left = $style->get_value(false);break;
+ case 'padding-top' :
+ $top = $style->get_value(false);
+ break;
+ case 'padding-right' :
+ $right = $style->get_value(false);
+ break;
+ case 'padding-bottom' :
+ $bottom = $style->get_value(false);
+ break;
+ case 'padding-left' :
+ $left = $style->get_value(false);
+ break;
}
}
if ($top == $bottom && $left == $right) {
* A padding top style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A padding right style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A padding bottom style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A padding left style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A cursor style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* @return string
*/
protected function clean_value($value) {
- // Allowed values for the cursor style
+ // Allowed values for the cursor style.
$allowed = array('auto', 'crosshair', 'default', 'e-resize', 'help', 'move', 'n-resize', 'ne-resize', 'nw-resize',
'pointer', 'progress', 's-resize', 'se-resize', 'sw-resize', 'text', 'w-resize', 'wait', 'inherit');
- // Has to be one of the allowed values of an image to use. Loosely match the image... doesn't need to be thorough
+ // Has to be one of the allowed values of an image to use. Loosely match the image... doesn't need to be thorough.
if (!in_array($value, $allowed) && !preg_match('#\.[a-zA-Z0-9_\-]{1,5}$#', $value)) {
$this->set_error('Invalid or unexpected cursor value specified: '.$value);
}
* A vertical alignment style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
* A float style.
*
* @package core
- * @category css
+ * @subpackage cssoptimiser
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/