<?php
/**
 * Magic CMS 自定义标签
 * ============================================================================
 * Copyright 2014 大秦科技，并保留所有权利。
 * 网站地址: http://www.qintech.net；
 * ----------------------------------------------------------------------------
 * 未获商业授权之前，不得将Magic CMS用于商业用途（包括但不限于企业网站、经营性网站
 * 以营利为目的或实现盈利的网站）未经官方许可，禁止在Magic CMS的整体或任何部分基础
 * 上以发展任何派生版本、修改版本或第三方版本用于重新分发。如果您未能遵守本协议的
 * 条款，您的授权将被终止，所被许可的权利将被收回，并承担相应法律责任。
 * ============================================================================
 * Date:2014/12/31
**/
 if (!defined('APP_PATH'))exit('No direct script access allowed');
class BaseTag extends Tag{
	static public $tagcache;


	 /**
     * 构造函数
     */
    public function __construct(){
        //左侧标签
        $this->left = '{mac:';
        //右侧标签
        $this->right = '}';
		//加载模板标签设置缓存
		self::$tagcache  = F('TempletssettingCache',false,ROOT_PATH.'Data/Cache/');

    }

	public $Tag= array(
			'channel'  => array('block' => 1, 'level' => 4,'method' => true),
			'arclist'  => array('block' => 1, 'level' => 4,'method' => true),
		    'slide'    => array('block' => 1, 'level' => 4,'method' => true),
			'flink'    => array('block' => 1, 'level' => 4,'method' => true),
		    'special'  => array('block' => 1, 'level' => 4,'method' => true),
		    'field'    => array('block' => 0, 'level' => 4,'method' => true),
			'pageshow' => array('block' => 0, 'level' => 0,'method' => true),
	  	    'kefu'     => array('block' => 0, 'level' => 0,'method' => true),
        );


	//解析Channel标签
    public function _channel($attr, $content){

		$item = isset($attr['item']) ? $attr['item'] : 'field';
		$key  = isset($attr['key']) ? $attr['key'] : 'key';
		$php = "<?php \$channel".$item." = call_user_func(array('TaglibModule', 'channelTag'),".self::parseAttrArr($attr).");if(empty(\$channel".$item.")){ echo '<div class=\"nodata\">".$attr['empty']."</div>';}else{foreach(\$channel".$item." as \$".$key."=>\$".$item."){?>";
		$php .= $content;
        $php .= '<?php };};unset($channel'.$item.',$'.$key.');?>';
		return $php;
    }

	//解析Arclist标签
    public function _arclist($attr, $content){

		$item = isset($attr['item']) ? $attr['item'] : 'field';
		$key  = isset($attr['key']) ? $attr['key'] : 'key';
		$php = "<?php \$arclist".$item." = call_user_func(array('TaglibModule', 'arclistTag'),".self::parseAttrArr($attr).");if(empty(\$arclist".$item.")){ echo '<div class=\"nodata\">".$attr['empty']."</div>';}else{foreach(\$arclist".$item." as \$".$key."=>\$".$item."){?>";
		$php .= $content;
        $php .= '<?php };};unset($arclist'.$item.',$'.$key.');?>';
		return $php;
    }


	//解析Field标签
    public function _field($attr, $content){
		$php = "<?php \$field = call_user_func(array('TaglibModule', 'fieldTag'),".self::parseAttrArr($attr)."); echo \$field;unset(\$field);?>";
		return $php;
    }

	//解析Slide标签
    public function _slide($attr, $content){
		$item = isset($attr['item']) ? $attr['item'] : 'field';
		$key  = isset($attr['key']) ? $attr['key'] : 'key';
		$php = "<?php \$slide".$item." = call_user_func(array('TaglibModule', 'slideTag'),".self::parseAttrArr($attr).");if(empty(\$slide".$item.")){ echo '<div class=\"nodata\">".$attr['empty']."</div>';}else{foreach(\$slide".$item." as \$".$key."=>\$".$item."){?>";
		$php .= $content;
        $php .= '<?php };};unset($slide'.$item.',$'.$key.');?>';
		return $php;
    }


	//解析Kefu标签
    public function _kefu($attr, $content){
		return "<?php \$kefu = call_user_func(array('TaglibModule', 'kefuTag'),".self::parseAttrArr($attr).");echo \$kefu;unset(\$kefu);?>";
    }

	//解析Flink标签
    public function _flink($attr, $content){
		$php = "<?php \$flink = call_user_func(array('TaglibModule', 'flinkTag'),".self::parseAttrArr($attr).");if(empty(\$flink)){ echo '<div class=\"nodata\">".$attr['empty']."</div>';}else{foreach(\$flink as \$key=>\$field){?>";
		$php .= $content;
        $php .= '<?php };};unset($flink);?>';
		return $php;
    }

	//解析Page标签
    public function _pageshow($attr, $content){
		return "<?php \$page = call_user_func(array('TaglibModule', 'pageshowTag'),".self::parseAttrArr($attr)."); echo \$page;unset(\$page);?>";
    }

	//解析Special标签
    public function _special($attr, $content){
		$php = "<?php \$special = call_user_func(array('TaglibModule', 'specialTag'),".self::parseAttrArr($attr).");if(empty(\$special)){ echo '<div class=\"nodata\">".$attr['empty']."</div>';}else{foreach(\$special as \$key=>\$field){?>";
		$php .= $content;
        $php .= '<?php };};unset($special);?>';
		return $php;
    }

}