]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
[add] HTML Purifier added to clean code
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / AttrDef / CSS / ListStyle.php
diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
new file mode 100644 (file)
index 0000000..b4cce9a
--- /dev/null
@@ -0,0 +1,112 @@
+<?php\r
+\r
+/**\r
+ * Validates shorthand CSS property list-style.\r
+ * @warning Does not support url tokens that have internal spaces.\r
+ */\r
+class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef\r
+{\r
+\r
+    /**\r
+     * Local copy of validators.\r
+     * @type HTMLPurifier_AttrDef[]\r
+     * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.\r
+     */\r
+    protected $info;\r
+\r
+    /**\r
+     * @param HTMLPurifier_Config $config\r
+     */\r
+    public function __construct($config)\r
+    {\r
+        $def = $config->getCSSDefinition();\r
+        $this->info['list-style-type'] = $def->info['list-style-type'];\r
+        $this->info['list-style-position'] = $def->info['list-style-position'];\r
+        $this->info['list-style-image'] = $def->info['list-style-image'];\r
+    }\r
+\r
+    /**\r
+     * @param string $string\r
+     * @param HTMLPurifier_Config $config\r
+     * @param HTMLPurifier_Context $context\r
+     * @return bool|string\r
+     */\r
+    public function validate($string, $config, $context)\r
+    {\r
+        // regular pre-processing\r
+        $string = $this->parseCDATA($string);\r
+        if ($string === '') {\r
+            return false;\r
+        }\r
+\r
+        // assumes URI doesn't have spaces in it\r
+        $bits = explode(' ', strtolower($string)); // bits to process\r
+\r
+        $caught = array();\r
+        $caught['type'] = false;\r
+        $caught['position'] = false;\r
+        $caught['image'] = false;\r
+\r
+        $i = 0; // number of catches\r
+        $none = false;\r
+\r
+        foreach ($bits as $bit) {\r
+            if ($i >= 3) {\r
+                return;\r
+            } // optimization bit\r
+            if ($bit === '') {\r
+                continue;\r
+            }\r
+            foreach ($caught as $key => $status) {\r
+                if ($status !== false) {\r
+                    continue;\r
+                }\r
+                $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);\r
+                if ($r === false) {\r
+                    continue;\r
+                }\r
+                if ($r === 'none') {\r
+                    if ($none) {\r
+                        continue;\r
+                    } else {\r
+                        $none = true;\r
+                    }\r
+                    if ($key == 'image') {\r
+                        continue;\r
+                    }\r
+                }\r
+                $caught[$key] = $r;\r
+                $i++;\r
+                break;\r
+            }\r
+        }\r
+\r
+        if (!$i) {\r
+            return false;\r
+        }\r
+\r
+        $ret = array();\r
+\r
+        // construct type\r
+        if ($caught['type']) {\r
+            $ret[] = $caught['type'];\r
+        }\r
+\r
+        // construct image\r
+        if ($caught['image']) {\r
+            $ret[] = $caught['image'];\r
+        }\r
+\r
+        // construct position\r
+        if ($caught['position']) {\r
+            $ret[] = $caught['position'];\r
+        }\r
+\r
+        if (empty($ret)) {\r
+            return false;\r
+        }\r
+        return implode(' ', $ret);\r
+    }\r
+}\r
+\r
+// vim: et sw=4 sts=4\r