Пример #1
0
 /**
    +----------------------------------------------------------
    * TagLib库解析
    +----------------------------------------------------------
    * @access public
    +----------------------------------------------------------
    * @param string $tagLib 要解析的标签库
    * @param string $content 要解析的模板内容
    * @param boolen $hide 是否隐藏标签库前缀
    +----------------------------------------------------------
    * @return string
    +----------------------------------------------------------
 */
 public function parseTagLib($tagLib, &$content, $hide = false)
 {
     $begin = $this->config['taglib_begin'];
     $end = $this->config['taglib_end'];
     $fileName = SITE_PATH . '/addons/plugins/Tags/TPTag.class.php';
     require_cache($fileName);
     $tLib = new TPTag($tagLib);
     if ($tLib->valid()) {
         //如果标签库有效则取出支持标签列表
         $tagList = $tLib->getTagList();
         //遍历标签列表进行模板标签解析
         foreach ($tagList as $tag) {
             self::$nowTags = $tag;
             // 实际要解析的标签名称
             $startTag = $tag['name'];
             // 检查可嵌套标签以及嵌套级别
             if ($tag['nested'] && $this->config['tag_level'] > 1) {
                 $level = $this->config['tag_level'];
             } else {
                 $level = 1;
             }
             $endTag = $startTag;
             if (false !== stripos($content, C('TAGLIB_BEGIN') . $startTag)) {
                 if (empty($tag['attribute'])) {
                     // 无属性标签
                     if ($tag['content'] != 'empty') {
                         for ($i = 0; $i < $level; $i++) {
                             $content = preg_replace('/' . $begin . $startTag . '(\\s*?)' . $end . '(.*?)' . $begin . '\\/' . $endTag . '(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','\\2')", $content);
                         }
                     } else {
                         $content = preg_replace('/' . $begin . $startTag . '(\\s*?)\\/(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','')", $content);
                     }
                 } elseif ($tag['content'] != 'empty') {
                     //闭合标签解析
                     for ($i = 0; $i < $level; $i++) {
                         $content = preg_replace('/' . $begin . $startTag . '\\s(.*?)' . $end . '(.+?)' . $begin . '\\/' . $endTag . '(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','\\2')", $content);
                     }
                 } else {
                     //开放标签解析
                     // 开始标签必须有一个空格
                     $content = preg_replace('/' . $begin . $startTag . '\\s(.*?)\\/(\\s*?)' . $end . '/eis', "\$this->parseXmlTag('" . $tagLib . "','" . $tag['name'] . "','\\1','')", $content);
                 }
             }
             self::$nowTags = array();
         }
     }
 }