Example #1
0
 /**
  * 
  * @param array $token
  */
 public function checkHtmlTokens()
 {
     $tokens = $this->getTokens('html');
     foreach ($tokens as $item) {
         if ($item['type'] === FL_TOKEN_HTML_TAG_START) {
             $attrTokens = $this->getInstance("Fl_Html_TagToken", $item['value'])->run();
             $tagName = strtolower($attrTokens['tag']);
             $tag = '<' . $attrTokens['tag'] . FL_SPACE;
             $attrTokens = $attrTokens['attrs'];
             foreach ($attrTokens as $attrItem) {
                 $count = count($attrItem);
                 $attr = strtolower($attrItem[0]);
                 if ($count == 1) {
                     $tag .= $this->checkIt(array_merge($item, array('value' => $attrItem[0])), 'html') . FL_SPACE;
                 } elseif ($count === 3) {
                     if ($attr && strpos($attr, 'on') === 0) {
                         $type = 'event';
                     } elseif ($attr === 'src' || $attr === 'href' || $tagName === 'form' && $attr === 'action') {
                         $type = 'url';
                     } else {
                         $type = 'html';
                     }
                     $value = $this->checkIt(array_merge($item, array('value' => $attrItem[2])), $type);
                     $tag .= $attrItem[0] . '=' . $value . FL_SPACE;
                 }
             }
             $tag = trim($tag) . ">";
             $item['value'] = $tag;
         } else {
             if ($item['type'] === FL_TOKEN_HTML_SCRIPT_TAG) {
                 //这里要判断是否是前端模版
                 $detail = Fl_Html_Static::splitSpecialValue($item['value'], 'script', $this);
                 $tagInfo = Fl_Html_Static::getScriptTagInfo($detail['tag_start'], $this);
                 //前端模版用HTML转义
                 if ($tagInfo['tpl']) {
                     $item['value'] = $this->checkIt($item, 'html');
                 } else {
                     $item['value'] = $this->checkIt($item, 'js');
                 }
             } else {
                 $item['value'] = $this->checkIt($item, 'html');
             }
         }
         $this->addOutput($item);
     }
 }
Example #2
0
 /**
  * 
  * 过滤textarea
  * @param array $token
  */
 public function filterTextarea($token = array())
 {
     if ($this->options['use_blank_tag_filter']) {
         if (!in_array('textarea', $this->blankTagList)) {
             return '';
         }
     }
     //如果允许textarea标签的话,也要过滤textarea的属性
     $detail = Fl_Html_Static::splitSpecialValue($token['value'], 'textarea', $this);
     $tagStart = $this->filterTag(array('value' => $detail['tag_start']));
     return $tagStart . $detail['content'] . $detail['tag_end'];
 }
Example #3
0
 /**
  * 
  * compress style
  * @param array $token
  */
 public function compressStyle($token)
 {
     if (!$this->options['compress_tag']) {
         return $token['value'];
     }
     $info = Fl_Html_Static::splitSpecialValue($token['value'], 'style', $this);
     $content = trim($info['content']);
     if ($this->options['remove_empty_style'] && !$content) {
         return '';
     }
     if ($this->options['compress_inline_css'] && $content) {
         Fl::loadClass("Fl_Css_Static");
         $value = Fl_Css_Static::getStyleDetail($content);
         $containTpl = $this->containTpl($value['value']);
         //自定义内联CSS压缩方法
         if (!$containTpl && $this->cssCompressMethod) {
             $content = call_user_func($this->cssCompressMethod, $value['value'], $this);
         } else {
             $content = $this->getInstance("Fl_Css_Compress", $value['value'])->run();
         }
     }
     if ($this->options['remove_optional_attrs']) {
         $tagInfo = $this->getInstance("Fl_Html_TagToken", $info['tag_start'])->run();
         $tagInfo['lowerTag'] = strtolower($tagInfo['tag']);
         $info['tag_start'] = $this->compressStartTag($tagInfo);
     }
     if ($this->options['merge_adjacent_css']) {
         $endStyle = '</style>';
         $outputLen = strlen($this->output);
         $last = substr($this->output, $outputLen - 8);
         if (strtolower($last) === $endStyle) {
             $this->output = substr($this->output, 0, $outputLen - 8);
             return $content . $info['tag_end'];
         }
     }
     return $info['tag_start'] . $content . $info['tag_end'];
 }
Example #4
0
 /**
  * 
  * special
  */
 public function specialStatement()
 {
     $tag = strtolower(Fl_Html_Static::getTagName($this->currentToken['value'], $this));
     $special = Fl_Html_Static::splitSpecialValue($this->currentToken['value'], $tag, $this);
     $this->currentToken['value'] = $special['tag_start'];
     return array("type" => $this->currentToken['type'], "tag" => $tag, "value" => $this->getValue($this->currentToken), "children" => array(array("type" => FL_TOKEN_HTML_TEXT, "value" => $this->getValue(array_merge($this->currentToken, array("value" => $special["content"]))))));
 }