Exemplo n.º 1
0
 public function setOptions($options = array())
 {
     $this->_fl_instance = Fl::getInstance();
     $this->_indentDepth = 0;
     $this->_type = 0;
     $this->_text = '';
     $this->_preType = 0;
     $this->_preText = '';
     $this->_prePreText = '';
     $this->_mode = 0;
     $this->_output = array();
     $this->_lineStarters = split(',', 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function');
     $options = array_merge(array('indent' => "    ", 'braces-on-own-line' => false, 'keep-array-ident' => false, 'header' => "/*@Beautify at " . date('Y-m-d H:i:s', time()) . ":md5({md5})*/", 'header-pattern' => "/\\/\\*\\@Beautify\\sat.*?\\:md5\\(([a-f0-9]{32})\\)\\*\\//ies", 'header-var' => '~!header!~'), $options);
     $this->options = $options;
     $this->_flags = array('var-line' => false, 'var-line-reindented' => false, 'mode' => 0);
 }
Exemplo n.º 2
0
 public function run($content = '')
 {
     $instance = Fl::getInstance();
     $analyticContent = Fl::getInstance()->analytic_html($content);
     $newLine = "\n";
     for ($i = 0, $count = count($analyticContent); $i < $count; $i++) {
         $this->_tokenText = $analyticContent[$i][0];
         $tokenType = $analyticContent[$i][1];
         if ($tokenType === FL::FL_NEW_LINE) {
             continue;
         }
         switch ($tokenType) {
             case FL::HTML_COMMENT:
                 break;
             case Fl::HTML_CONTENT:
                 $this->_compressTextContent();
                 break;
             case FL::HTML_TAG_END:
                 if (!in_array(trim(trim($this->_tokenText, '<>/')), $this->_removeEndTag)) {
                     $this->_output[] = $this->_tokenText;
                 }
                 break;
             case FL::HTML_TAG_START:
             case FL::HTML_JS_START:
                 $this->_compressTag();
                 break;
             case FL::HTML_CSS_CONTENT:
                 $this->_compressCss();
                 break;
             case FL::HTML_JS_CONTENT:
                 $this->_compressJs();
                 break;
             case FL::FL_TPL_DELIMITER:
                 $text = $this->_tokenText;
                 if (strpos($text, 'extends') !== false) {
                     //smarty3里extends后至少要加个空白字符
                     $text .= ' ';
                 }
                 $this->_output[] = $text;
                 break;
             default:
                 $this->_output[] = $this->_tokenText;
         }
     }
     return join('', $this->_output);
 }