Add filterBySelector().
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 21:13:48 +0000 (14:13 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 21:42:44 +0000 (14:42 -0700)
framework/Text_Filter_Csstidy/lib/Horde/Text/Filter/Csstidy/class.csstidy.php

index d72756f..c074a7a 100644 (file)
@@ -979,4 +979,37 @@ class csstidy {
         return (isset($all_properties[$property]) && strpos($all_properties[$property],strtoupper($this->get_cfg('css_level'))) !== false );
     }
 
+    /**
+     * Filters CSS by a list of simple selectors and returns a string suitable
+     * for use in a HTML style attribute.
+     *
+     * @param array $input  The list of selectors to filter by.
+     *
+     * @return string  The CSS string.
+     */
+    function filterBySelector($input)
+    {
+        if (empty($input)) {
+            return '';
+        }
+
+        $cssarray = reset($this->css);
+        $style = '';
+
+        foreach (array_keys($cssarray) as $val) {
+            foreach (array_map('trim', explode(',', $val)) as $entry) {
+                if (in_array($entry, $input)) {
+                    foreach ($cssarray[$val] as $key2 => $val2) {
+                        foreach ($val2['p'] as $val3) {
+                            $style .= $key2 . ':' . $val3 . ';';
+                        }
+                    }
+                    continue;
+                }
+            }
+        }
+
+        return $style;
+    }
+
 }