* Defines constants
* @todo //TODO: make them class constants of csstidy
*/
-define('AT_START', 1);
-define('AT_END', 2);
-define('SEL_START', 3);
-define('SEL_END', 4);
-define('PROPERTY', 5);
-define('VALUE', 6);
-define('COMMENT', 7);
-define('DEFAULT_AT', 41);
+define('AT_START', 1);
+define('AT_END', 2);
+define('SEL_START', 3);
+define('SEL_END', 4);
+define('PROPERTY', 5);
+define('VALUE', 6);
+define('COMMENT', 7);
+define('IMPORTANT_COMMENT',8);
+define('DEFAULT_AT', 41);
/**
* Contains a class for printing CSS code
*
- * @version 1.0
+ * @version 1.1.0
*/
require('class.csstidy_print.php');
* An online version should be available here: http://cdburnerxp.se/cssparse/css_optimiser.php
* @package csstidy
* @author Florian Schmitz (floele at gmail dot com) 2005-2006
- * @version 1.5.6
+ * @version 1.6.4
*/
class csstidy {
* @var string
* @access private
*/
- public $version = '1.5.6';
+ public $version = '1.6.4';
/**
* Stores the settings
* @var array
/* is dangeroues to be used: CSS is broken sometimes */
$this->settings['merge_selectors'] = 0;
/* preserve or not browser hacks */
+
+ /* Useful to produce a rtl css from a ltr one (or the opposite) */
+ $this->settings['reverse_left_and_right'] = 0;
+
$this->settings['discard_invalid_selectors'] = false;
$this->settings['discard_invalid_properties'] = false;
$this->settings['css_level'] = 'CSS3.0';
*/
public function _add_token($type, $data, $do = false) {
if ($this->get_cfg('preserve_css') || $do) {
- $this->tokens[] = array($type, ($type == COMMENT) ? $data : trim($data));
+ $this->tokens[] = array($type, ($type == COMMENT or $type == IMPORTANT_COMMENT) ? $data : trim($data));
}
}
if ($string{$i} === '*' && $string{$i + 1} === '/') {
$this->status = array_pop($this->from);
$i++;
- $this->_add_token(COMMENT, $cur_comment);
+ if (strlen($cur_comment) > 1 and strncmp($cur_comment, '!', 1) === 0) {
+ $this->_add_token(IMPORTANT_COMMENT, $cur_comment);
+ $this->css_add_important_comment($cur_comment);
+ }
+ else {
+ $this->_add_token(COMMENT, $cur_comment);
+ }
$cur_comment = '';
} else {
$cur_comment .= $string{$i};
return!(@($string{$pos - 1} !== '\\') || csstidy::escaped($string, $pos - 1));
}
+
+ /**
+ * Add an important comment to the css code
+ * (one we want to keep)
+ * @param $comment
+ */
+ public function css_add_important_comment($comment) {
+ if ($this->get_cfg('preserve_css') || trim($comment) == '') {
+ return;
+ }
+ if (!isset($this->css['!'])) {
+ $this->css['!'] = '';
+ }
+ else {
+ $this->css['!'] .= "\n";
+ }
+ $this->css['!'] .= $comment;
+ }
+
/**
* Adds a property with value to the existing CSS code
* @param string $media
return $media;
}
end($this->css);
- list($at,) = each($this->css);
+ $at = key($this->css);
if ($at == $media) {
return $media;
}
// if last is the same, keep it
end($this->css[$media]);
- list($sel,) = each($this->css[$media]);
+ $sel = key($this->css[$media]);
if ($sel == $selector) {
return $selector;
}