コード例 #1
0
ファイル: Compress.class.php プロジェクト: DXkite/Fl
 /**
  * 
  * 压缩一些通用的,如:注释,换行等
  * @param array $token
  */
 public function compressCommon($token)
 {
     $return = $comment = $newline = '';
     foreach ($token['commentBefore'] as $item) {
         //如果注释内容第一个字符是!,则保留该注释
         if (preg_match('/^\\<\\!\\-\\-\\!/', $item['text']) || !$this->options['remove_comment']) {
             $comment .= $item['text'];
         }
     }
     if (!$token['newlineBefore']) {
         return $comment;
     }
     if (Fl_Html_Static::isNoNewlineToken($token['type'])) {
         return $comment;
     }
     //如果是模版语法且不会输出,则不添加空白字符
     if ($token['type'] === FL_TOKEN_TPL && !$this->checkTplHasOutput($token['value'])) {
         return $comment;
     }
     if (!$this->options['remove_newline']) {
         if ($this->options['newline_to_space']) {
             $newline = FL_SPACE;
         } else {
             $newline = FL_NEWLINE;
         }
         $preText = $this->preOutputText;
         if (!$this->isXML && $preText && substr($preText, strlen($preText) - 1, 1) == $newline) {
             return $comment;
         }
     }
     if (Fl_Html_Static::isTag($token)) {
         if (Fl_Html_Static::isSafeTag($token['tag'])) {
             return $comment;
         }
         if ($this->options['remove_inter_tag_space']) {
             return $comment;
         }
         if ($this->options['remove_inter_block_tag_space'] && Fl_Html_Static::isBlockTag($token['tag'])) {
             return $comment;
         }
     }
     if (Fl_Html_Static::isTag($this->nextToken) || Fl_Html_Static::isTag($this->preToken)) {
         if ($this->options['remove_inter_tag_space']) {
             return $comment;
         } else {
             if ($this->options['remove_inter_block_tag_space'] && (Fl_Html_Static::isBlockTag($this->nextToken['lowerTag']) || Fl_Html_Static::isBlockTag($this->preToken['lowerTag']))) {
                 return $comment;
             }
         }
     }
     if ($token['col'] == 0) {
         $return .= $comment . $newline;
     } else {
         $return .= $newline . $comment;
     }
     return $return;
 }