/** * * 压缩当前的模板Token */ public function compress($tpl, Fl_Base &$instance) { $tplText = $instance->getTplText($tpl); //smarty的extends后必须有个空白字符 if (strpos($tplText, 'extends ') === 0) { $tpl .= ' '; } return $tpl; }
/** * * 检测当前的tpl是否会输出 * @param string $tpl */ public function checkHasOutput($tpl, Fl_Base &$instance) { $tplText = $instance->getTplText($tpl, true); //目前只处理 {{{ a }}} 的情况 if ($tplText[0] === '{') { return true; } return false; // $reg = "/^[A-Za-z\.]+/"; // if (! preg_match ( $reg, $tplText )) { // return false; // } // foreach ( $this->keywords as $keyword ) { // if (strpos ( $tplText, $keyword ) === 0) { // return false; // } // } // return true; }
/** * * 异常处理 */ public function throwException($msg = '', $detail = true) { $ext = ' at line:' . ($this->line + 1) . ', col:' . ($this->col + 1) . ', pos:' . $this->pos; if ($detail) { $msg .= $ext; } parent::throwException($msg, -1); }
public function __construct($text = '') { parent::__construct($text); $this->setDefaultOptions(); }
/** * * 获取结束标签的名字 * @param string $endTag */ public static function getEndTagName($endTag = '', Fl_Base $instance) { preg_match(self::$endTagNamePattern, $endTag, $matches); if (is_array($matches) && $matches[1]) { return $matches[1]; } $instance->throwException('analytic end tag error'); }
/** * * 异常处理 */ public function throwException($msg = '') { $ext = ' at line:' . ($this->line + 1) . ', col:' . ($this->col + 1) . ', pos:' . $this->pos; parent::throwException($msg . $ext, $code); }
/** * * get info in script tag,is external & js * @param string $tag */ public static function getScriptTagInfo($tag = '', Fl_Base $instance) { $tagInfo = $instance->getInstance("Fl_Html_TagToken", $tag)->run(); $isExternal = false; $isScript = true; $isTpl = false; $isInline = false; $src = ''; foreach ($tagInfo['attrs'] as $item) { $nameLower = strtolower($item[0]); if (count($item) == 3) { $valueDetail = Fl_Html_Static::getUnquoteText($item[2]); $value = $valueDetail['text']; $tagInfo[$nameLower] = $value; if ($nameLower === 'src') { $isExternal = true; $src = $item[2]; } elseif ($nameLower === 'type') { if ($value && strtolower($value) != 'text/javascript') { $isScript = false; } //前端模版 if (strtolower($value) == 'text/html' || strtolower($value) == 'text/template') { $isTpl = true; } } } if ($nameLower == 'inline') { $isInline = true; } } $tagInfo['external'] = $isExternal; $tagInfo['script'] = $isScript; $tagInfo['tpl'] = $isTpl; $tagInfo['inline'] = $isInline; $tagInfo['src'] = $src; return $tagInfo; }
/** * * 抛出token的相关异常 */ public function throwException($msg = '', $token = false) { if ($token === false) { $token = $this->currentToken; } $ext = ' at line:' . strval($token['tokline']) . ', col:' . $token['tokcol'] . ', pos:' . $token['tokpos']; parent::throwException($msg . $ext); }