/** * * get propertis in a selector */ public function getSelectorProperties() { $braces = $this->tokenInstance->getNextToken(); if ($braces['type'] !== FL_TOKEN_CSS_BRACES_ONE_START) { $this->throwException("after selector must be a {"); } $attrs = array(); $attr = $value = ''; $pos = 0; $hack = $hasColon = $hasTpl = $tpl = false; while (true) { $token = $this->tokenInstance->getNextToken(); if (empty($token)) { break; } elseif ($token['type'] === FL_TOKEN_CSS_PROPERTY) { $attr .= $this->options['property_to_lower'] ? strtolower($token['value']) : $token['value']; if (!$this->options['override_same_property'] && isset($attrs[$attr])) { $attr .= $pos++; } } elseif ($token['type'] === FL_TOKEN_CSS_VALUE) { $value .= $token['value']; } elseif ($token['type'] === FL_TOKEN_CSS_SEMICOLON || $token['type'] === FL_TOKEN_CSS_BRACES_ONE_END) { if (!strlen($value)) { if ($attr && $this->containTpl($attr)) { $attrs[$attr . '%' . $pos++] = array("type" => FL_TOKEN_TPL, "value" => $attr); } $attr = $value = ''; $hasColon = $tpl = false; if ($token['type'] === FL_TOKEN_CSS_SEMICOLON) { continue; } else { break; } } if ($tpl || $this->containTpl($attr)) { $hasTpl = true; $attrs[$attr . '%' . $pos++] = array("property" => $attr, "value" => $value); } else { $propertyDetail = Fl_Css_Static::getPropertyDetail($attr); //if property is filter, can't replace `, ` to `,` //see http://www.imququ.com/post/the_bug_of_ie-matrix-filter.html if (strtolower($propertyDetail['property']) !== 'filter') { $value = preg_replace("/,\\s+/", ",", $value); } $valueDetail = Fl_Css_Static::getValueDetail($value); //get short value if ($this->options['short_value']) { $valueDetail['value'] = Fl_Css_Static::getShortValue($valueDetail['value'], $propertyDetail['property']); } //merge them with `+` $detail = $propertyDetail + $valueDetail; //add pos key for property sort $detail['pos'] = $pos++; /** * for div{color:red;color:blue\9;} * if suffix in css value, can not override property. */ $attr .= $valueDetail['suffix']; //multi same property //background:red;background:url(xx.png) if (Fl_Css_Static::isMultiSameProperty($attr, $valueDetail['value'])) { $attr .= "%" . $pos; $detail['type'] = FL_TOKEN_CSS_MULTI_PROPERTY; } if (!$this->options['override_same_property']) { $attrs[$attr] = $detail; } else { $attrs = Fl_Css_Static::mergeProperties($attrs, array($attr => $detail)); } } $attr = $value = ''; $hasColon = $tpl = false; } elseif ($token['type'] === FL_TOKEN_CSS_HACK) { //for css hack [;color:red;] if (strpos($token['value'], ":") != false) { $vs = explode(":", $token['value'], 2); $attrs[$vs[0] . strval($pos++)] = array('value' => $vs[1], 'property' => $vs[0], 'type' => FL_TOKEN_CSS_HACK); $hack = true; } } else { if ($token['type'] === FL_TOKEN_TPL) { if ($hasColon) { $value .= $token['value']; } else { $attr .= $token['value']; } $tpl = true; } elseif ($token['type'] === FL_TOKEN_CSS_COLON) { if ($hasColon) { $value .= $token['value']; } else { $hasColon = true; } } } if ($token['type'] === FL_TOKEN_CSS_BRACES_ONE_END) { break; } } if ($hasTpl) { $this->options = array_merge($this->options, $this->tplOptions); } if (!$hasTpl && !$hack) { if ($this->options['merge_property']) { $attrs = $this->shortProperties($attrs); } //if hack in attrs, can't sort it if ($this->options['sort_property']) { $attrs = Fl_Css_Static::sortProperties($attrs); } } return $attrs; }