From 5193a07cc9dba5a593f750b23c6d99fb984e1473 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 3 Feb 2010 14:13:48 -0700 Subject: [PATCH] Add filterBySelector(). --- .../Horde/Text/Filter/Csstidy/class.csstidy.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/framework/Text_Filter_Csstidy/lib/Horde/Text/Filter/Csstidy/class.csstidy.php b/framework/Text_Filter_Csstidy/lib/Horde/Text/Filter/Csstidy/class.csstidy.php index d72756f4d..c074a7aeb 100644 --- a/framework/Text_Filter_Csstidy/lib/Horde/Text/Filter/Csstidy/class.csstidy.php +++ b/framework/Text_Filter_Csstidy/lib/Horde/Text/Filter/Csstidy/class.csstidy.php @@ -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; + } + } -- 2.11.0