PATH:
home
/
letacommog
/
letaweb
/
admin
/
classes
<?php class CSSParser { public $code = ''; public function __construct($code) { $this->code = $code; } public static function stripComments($ret) { return preg_replace("/\/\*[\s\S]*?\*\//", '', $ret); } public static function clearWhiteSpace($ret) { $ret = preg_replace("/\t/", '', $ret); $ret = preg_replace("/[\r|\n]/", ' ', $ret); $ret = preg_replace("/\s{1,300}/", ' ', $ret); return $ret; } public static function isCSSvalid($css) { $css = self::stripComments($css); //if (preg_match("/\{([^}]*){/", $css) == 1) { // return false; // } echo $css; return true; } protected function isBreakChar($c, $break_chars) { for ($i = 0;$i < sizeof($break_chars);++$i) { if ($c == $break_chars[$i]) { return true; } } return false; } protected function getMediaType($selector) { if (strlen($selector) == 0) { return false; } if ($selector[0] != '@') { return false; } $s = explode(' ', $selector); $s = $s[0]; $s = explode('(', $s); $s = $s[0]; return substr($s, 1); } protected function isMediaType($selector) { if (strlen($selector) == 0) { return false; } if ($selector[0] != '@') { return false; } return true; } protected function isMediaCombinableType($selector) { if (strlen($selector) == 0) { return false; } $combinable_media_query = array( 'font-face' => false, 'keyframes' => true, 'media' => true, 'charset' => false, ); $type = $this->getMediaType($selector); if ($type == false) { return false; } return $combinable_media_query[$type]; } public function parse() { $css = $this->code; /*if (!self::isCSSvalid($css)) { //trigger_error("NOT_VALID_SOURCE_CSS", E_USER_NOTICE); return false; }*/ $rules = array(); if (!$css) { return $rules; } $css = self::stripComments($css); $css = self::clearWhiteSpace($css); $current_token = ''; $tokens = array(); $rules = array(); $brakets = array(); $START_STYLE_BLOCK = 1; $START_MEDIA_BLOCK = 2; $WHITE_SPACE = ' '; $END_STYLE_BLOCK = 3; $END_MEDIA_BLOCK = 4; $parsed_css = array(); $index = -1; $child_index = -1; $break_chars = array('{',';'); for ($i = 0;$i < strlen($css);++$i) { $current_char = $css[$i]; $rule = array(); $child_rule; if (!$this->isBreakChar($current_char, $break_chars)) { $current_token .= $current_char; } else { $current_token = trim($current_token); if (strlen($current_token) != 0) { array_push($tokens, trim($current_token)); } array_push($tokens, $current_char); if ($current_char == ';') { if (sizeof($brakets) == 0) { if ($this->isMediaType($current_token)) { ++$index; array_push($parsed_css, array('selector' => current_token)); } } else { $break_chars = array('}','{',':'); } } if ($current_char == '{') { $break_chars = array('{',':','}'); $rule = array(); $rule['selector'] = $current_token; if (sizeof($brakets) == 0 || $brakets[sizeof($brakets) - 1] == $START_MEDIA_BLOCK) { if (sizeof($brakets) > 0 && $brakets[sizeof($brakets) - 1] == $START_MEDIA_BLOCK) { array_push($brakets, $START_STYLE_BLOCK); ++$child_index; array_push($parsed_css[$index]['rules'], array('selector' => $current_token)); } elseif ($this->isMediaType($current_token)) { if ($this->isMediaCombinableType($current_token)) { array_push($brakets, $START_MEDIA_BLOCK); ++$index; $child_index = -1; array_push($parsed_css, array('selector' => $current_token)); $parsed_css[$index]['rules'] = array(); $break_chars = array('{','}'); } else { $child_index = -1; ++$index; array_push($parsed_css, array('selector' => $current_token)); array_push($brakets, $START_STYLE_BLOCK); } } else { $child_index = -1; ++$index; array_push($parsed_css, array('selector' => $current_token)); array_push($brakets, $START_STYLE_BLOCK); } } else { //echo $css; //print_r($brakets); //echo ('Parse Error:Unexpected { at char '.$current_token.' '. $i . ':' . $css[$i]); } } if ($current_char == '}') { $break_chars = array('}','{'); $top_braket = array_pop($brakets); if (isset($top_braket) && $top_braket != $START_MEDIA_BLOCK && $top_braket != $START_STYLE_BLOCK) { throw new Exception('Parse Error:Expected } at char '.$i.':'.$css[$i]); } if ($top_braket == $START_STYLE_BLOCK) { $top_token; $selector_body = array(); $css_style = array(); array_pop($tokens); if ($tokens[sizeof($tokens) - 1] != ';') { array_push($tokens, ';'); } while ($top_token = array_pop($tokens) != '{') { if ($top_token == ';') { if ($tokens[sizeof($tokens) - 1] == ';') { continue; } $css_style = array(); $value = array_pop($tokens); if ($value == '{') { break; } $colons = array_pop($tokens); if ($colons != ':') { //print_r($tokens); throw new Exception('Parse Error:Expected : at char '.$i.', value is '.$colons); //return false; } $property = array_pop($tokens); $css_style = array('property' => $property, 'value' => $value); array_unshift($selector_body, $css_style); } } array_pop($tokens); if ($index >= 0) { if ($child_index >= 0) { $parsed_css[$index]['rules'][$child_index]['selector_body'] = $selector_body; } else { $parsed_css[$index]['selector_body'] = $selector_body; } } } else { array_pop($tokens); array_pop($tokens); array_pop($tokens); } } if ($current_char == ':') { $break_chars = array('}',';'); } $current_token = ''; } } //console.log(parsed_css); return $parsed_css; } }
[+]
..
[+]
php-jwt
[-] Blowfish.php
[edit]
[+]
socialEmbed
[+]
mailchimp
[+]
swiftMailer
[-] CMS_Rewrite.php
[edit]
[+]
hosting
[-] general.php
[edit]
[-] ScreenShot.php
[edit]
[-] UrlManager.php
[edit]
[+]
payments
[-] Configuration.php
[edit]
[+]
twig-renderer-master
[-] Functions.php
[edit]
[+]
twig
[+]
addons
[+]
hoauth
[-] package.xml
[edit]
[-] PController.php
[edit]
[-] ETwigViewRenderer.php
[edit]
[+]
htmlpurifier
[-] Randomness.php
[edit]
[-] CSSParser.php
[edit]
[-] Mail.php
[edit]
[-] Rijndael.php
[edit]
[+]
components
[+]
rss
[-] WebApplication.php
[edit]
[-] passwordhash.php
[edit]
[-] DLDatabaseHelper.php
[edit]
[+]
Exceptions