<?php
namespace Think\Template\TagLib;
use Think\Template\TagLib;
class Uu extends TagLib {

    // 标签定义
    protected $tags   =  array(
		'cat' =>  array('attr'=>'listname,type,pid,id,field','close'=>0),
		'question' =>  array('attr'=>'listname,type,field,uid,category1,category2','close'=>0),
		'nav' =>  array('attr'=>'listname,field','close'=>0),
		'questionview' =>  array('attr'=>'listname,field','close'=>0),
		'answer' =>  array('attr'=>'listname,field','close'=>0),
		'intro' =>  array('attr'=>'listname,field','close'=>0),
		'introview' =>  array('attr'=>'listname,field','close'=>0),
		'tag' =>  array('attr'=>'listname,field','close'=>0),
		'u' =>  array('attr'=>'listname,field','close'=>0),
		'tagview' =>  array('attr'=>'listname,field','close'=>0),
		'tagcat' =>  array('attr'=>'listname,field','close'=>0),
		'article' =>  array('attr'=>'listname,field','close'=>0),
		'articleview' =>  array('attr'=>'listname,field','close'=>0),
		'track' =>  array('attr'=>'listname,field','close'=>0),
		'exps' =>  array('attr'=>'listname,field','close'=>0),
		'fans' =>  array('attr'=>'listname,field','close'=>0),
		'notice' =>  array('attr'=>'listname,field','close'=>0),
		'noticeview' =>  array('attr'=>'listname,field','close'=>0),
		'links' =>  array('attr'=>'listname,field','close'=>0),
		
        );

 	//获取分类
	function __call($function_name,$args)
	{
		$tag = substr($function_name, 1);
		if (!isset($this->tags[$tag])) return false;
		$_tag = $args[0];
		$_tag['cache'] = isset($_tag['cache']) ? intval($_tag['cache']) : 0;
		$_tag['listname'] = isset($_tag['listname']) ? trim($_tag['listname']) : 'li';
		$tag_array=$this->uu_var_export($_tag);
		$class = "\$tag_{$tag}_class";
		$phpstr  = '<?php ';
		//$phpstr .= " unset(\${$_tag['listname']});" ;
		$phpstr .= "{$class}  = new \\Common\\Taglib\\{$tag}();";
		$phpstr .= "\${$_tag['listname']} = {$class}->run({$tag_array}); ";
		$phpstr .= '?>';
		$phpstr .= $args[1];
		return $phpstr;
	}
private static function uu_var_export($data) {
        if (is_array($data)) {
            $str = 'array(';
                foreach ($data as $key=>$val) {
                    if (is_array($val)) {
                        $str .= "'$key'=>".self::arr_to_html($val).",";
                    } else {
                        if (strpos($val, '$')===0) {
                            $str .= "'$key'=>$val,";
                        } else {
                            $str .= "'$key'=>'".$val."',";
                        }
                    }
                }
                return $str.')';
            }
            return false;
}
 
}
?>