[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / compresseur / lib / csstidy / class.csstidy.php
index 4410da7..3520279 100644 (file)
@@ -61,19 +61,20 @@ if (!function_exists('ctype_xdigit')){
  * 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');
 
@@ -94,7 +95,7 @@ require('class.csstidy_optimise.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 {
 
@@ -147,7 +148,7 @@ class csstidy {
         * @var string
         * @access private
         */
-       public $version = '1.5.6';
+       public $version = '1.6.4';
        /**
         * Stores the settings
         * @var array
@@ -318,6 +319,10 @@ class csstidy {
                /* 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';
@@ -411,7 +416,7 @@ class csstidy {
         */
        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));
                }
        }
 
@@ -947,7 +952,13 @@ class csstidy {
                                        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};
@@ -1036,6 +1047,25 @@ class csstidy {
                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
@@ -1080,7 +1110,7 @@ class csstidy {
                        return $media;
                }
                end($this->css);
-               list($at,) = each($this->css);
+               $at = key($this->css);
                if ($at == $media) {
                        return $media;
                }
@@ -1119,7 +1149,7 @@ class csstidy {
 
                        // 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;
                        }