<?php
defined('PP_PATH') or exit;
class tag_control extends base_control{
	public $_cfg = array();
	public $_var = array();
	public function index() {
		$this->_cfg = $this->runtime->xget();
		$mid = max(2, (int)R('mid'));
		$table = isset($this->_cfg['table_arr'][$mid]) ? $this->_cfg['table_arr'][$mid] : 'products';
		$name = R('name');
		empty($name) && core::error404();
		$name = substr(urldecode($name), 0, 30);
		$name = safe_str($name); 
		$this->cms_content_tag->table = 'cms_'.$table.'_tag';
		$tags = $this->cms_content_tag->find_fetch(array('name'=>$name), array(), 0, 1);
		empty($tags) && core::error404();
		$tags = current($tags);
		$this->_cfg['titles'] = $tags['name'];
		$this->_var['topcid'] = -1;
		$this->assign('pp', $this->_cfg);
		$this->assign('mid', $mid);
		$this->assign('pp_var', $this->_var);
		$GLOBALS['run'] = &$this;
		$GLOBALS['tags'] = &$tags;
		$GLOBALS['mid'] = &$mid;
		$GLOBALS['table'] = &$table;
		$_ENV['_theme'] = &$this->_cfg['theme'];
		$this->display('tag_list.htm');
	}
	public function top() {
		$this->_cfg = $this->runtime->xget();
		$this->_cfg['titles'] = '热门标签';
		$this->_var['topcid'] = -1;
		$this->assign('pp', $this->_cfg);
		$this->assign('pp_var', $this->_var);
		$GLOBALS['run'] = &$this;
		$_ENV['_theme'] = &$this->_cfg['theme'];
		$this->display('tag_top.htm');
	}
}
