/**
  * return stored referers
  * 处理站外连接
  * 原则:1. 把站外连接当成有意义有内容;2. 可以不记录链入的完整url,但一定要记录网站名(Host)
  * 
  * @param boolean
  * @return mixed
  */
 public static function storedReferers($return_array = true)
 {
     static $refs = null;
     if (is_null($refs)) {
         $refs = array(0 => '', 1 => '', 2 => '', 3 => '');
         isset($_COOKIE[self::COOKIE_REFS]) && ($refs = explode('~~', $_COOKIE[self::COOKIE_REFS]));
         //var_dump($refs);
         $need_set_cookie = false;
         if (isset($_GET["from"])) {
             $r_1 = $_GET["from"];
         } elseif (isset($_GET["unionfrom"])) {
             $r_1 = $_GET["unionfrom"];
         } else {
             $r_1 = null;
         }
         $need_set_cookie = !empty($r_1);
         if (!empty($r_1)) {
             // 有效的 from
             $refs[1] = $r_1;
             if (isset($_GET['tn']) && $refs[1] == 'baidu') {
                 $refs[2] = $_GET['tn'];
             } else {
                 $refs[2] = isset($_GET['locate']) ? $_GET['locate'] : '';
             }
             $refs[3] = isset($_GET['strsend']) ? $_GET['strsend'] : '';
         }
         if (isset($_SERVER["HTTP_REFERER"]) && preg_match("#http://([a-z0-9\\-\\.]+?\\.)?([a-z0-9\\-]+)\\.([a-z]{2,4})/([^\\/]+)?#i", $_SERVER["HTTP_REFERER"], $matches)) {
             //var_dump($matches);
             if ($matches[2] != 'togj') {
                 $r_0 = $matches[1] . $matches[2] . '.' . $matches[3];
                 // $_SERVER["HTTP_REFERER"];
             } elseif ($matches[2] == 'togj' && isset($matches[4]) && $matches[4] == 'feature') {
                 $r_0 = $matches[2] . '.' . $matches[3] . '/' . $matches[4];
             } else {
                 $r_0 = null;
             }
             if (!empty($r_0)) {
                 // 是有效的主机才取 From
                 $refs[0] = $r_0;
             }
         } elseif (isset($_GET['direct_from'])) {
             // 为了手工输入URL而设置, 17:29 2009-08-05
             $refs[0] = '(local)';
             $refs[1] = $_GET['direct_from'];
             $refs[2] = '';
             $refs[3] = '';
             if (!$need_set_cookie && !empty($refs[1])) {
                 $need_set_cookie = true;
             }
         } else {
             $refs[0] = '(empty)';
             // 为了空referrer也可以记录
         }
         //var_dump($refs);
         //Sp_Log::debug('will set cookie '.($need_set_cookie?'yes':'no'));
         if ($need_set_cookie && !empty($refs[0]) && !empty($refs[1]) && self::isHttp()) {
             setcookie(self::COOKIE_REFS, implode('~~', $refs), time() + 604800, '/', Request::genCookieDomain());
             //if(isset($_COOKIE['__refs']) ) setcookie('__refs', false, 0, '/',Request::genCookieDomain());	// delete old cookie, 记得一段时间后删除此块
         }
     }
     if ($return_array) {
         return $refs;
     }
     return implode('~~', $refs);
 }
 /**
  * 继承Smarty并设置项目的属性
  */
 function __construct($charset = 'UTF-8', $cur_skin = 'default')
 {
     //Class Constructor. These automatically get set with each new instance.
     method_exists('Smarty', 'Smarty') && $this->Smarty() || parent::__construct();
     if (isset($cur_skin) && !empty($cur_skin)) {
         $this->_cur_skin = $cur_skin;
     } else {
         if (defined('VIEW_SKIN_CURRENT')) {
             $this->_cur_skin = VIEW_SKIN_CURRENT;
         } else {
             $this->_cur_skin = $this->_dft_skin;
         }
     }
     if (defined('VIEW_SKINS_ROOT')) {
         $this->_parent_dir = VIEW_SKINS_ROOT;
     } else {
         die("please set template skin dir first! ");
     }
     $this->template_dir = VIEW_SKINS_ROOT . $this->_cur_skin . '/';
     //echo $this->template_dir;
     //$this->use_sub_dirs = true;
     $this->compile_id = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'local') . '_' . $this->_cur_skin;
     $this->compile_dir = VIEW_COMPILE_DIR;
     $this->config_dir = VIEW_CONFIG_DIR;
     $this->plugins_dir = array(LIB_ROOT . 'function/smarty/plugins', SMARTY_DIR . '/plugins');
     // Smarty 的模板缓存,奇怪的设计,慎用
     //$this->cache_dir = VIEW_CACHE_DIR;
     //$this->cache_lifetime = defined('VIEW_CACHE_LIFETIME') ? VIEW_CACHE_LIFETIME : 1440;
     //$this->clear_all_cache();
     //$this->caching = defined('VIEW_CACHE_ENABLE') ? VIEW_CACHE_ENABLE : true;
     //$this->security = true;
     $this->use_sub_dirs = TRUE;
     //开启缓存目录分级
     $this->left_delimiter = '{%';
     $this->right_delimiter = '%}';
     $this->_charset = $charset;
     new Sp_View_Helper($this);
     $this->assign_by_ref('head_title', $this->_head_title);
     $this->assign_by_ref('head_keywords', $this->_head_keywords);
     $this->assign_by_ref('head_description', $this->_head_description);
     $this->assign_by_ref('head_links', $this->_head_links);
     $this->assign_by_ref('head_styles', $this->_head_styles);
     $this->assign_by_ref('head_scripts', $this->_head_scripts);
     $this->assign_by_ref('foot_scripts', $this->_foot_scripts);
     $this->assign_by_ref('charset', $this->_charset);
     defined('SP_URL_API') && $this->assign('SP_URL_API', SP_URL_API);
     //API  kong 增加
     defined('SP_URL_HOME') && $this->assign('SP_URL_HOME', SP_URL_HOME);
     defined('SP_URL_CSS') && $this->assign('SP_URL_CSS', SP_URL_CSS);
     defined('SP_URL_IMG') && $this->assign('SP_URL_IMG', SP_URL_IMG);
     defined('SP_URL_JS') && $this->assign('SP_URL_JS', SP_URL_JS);
     defined('SP_URL_STO') && $this->assign('SP_URL_STO', SP_URL_STO);
     defined('SP_URL_CS') && $this->assign('SP_URL_CS', SP_URL_CS);
     defined('SP_URL_UPLOAD') && $this->assign('SP_URL_UPLOAD', SP_URL_UPLOAD);
     defined('SP_URL_FILE') && $this->assign('SP_URL_FILE', SP_URL_FILE);
     defined('SP_DOMAIN_SUFFIX') && $this->assign('SP_DOMAIN_SUFFIX', SP_DOMAIN_SUFFIX);
     defined('DATA_TYPE') && $this->assign('DATA_TYPE', DATA_TYPE);
     $this->assign('COOKIE_DOMAIN', Request::genCookieDomain());
     // current request
     $this->_request = Request::current();
     $this->assign_by_ref('_request', $this->_request);
     is_null($this->_parent_dir) && ($this->_parent_dir = CONF_ROOT . 'templates/');
     if (is_dir($this->_parent_dir)) {
         $this->assign('parent_dir', $this->_parent_dir);
     } else {
         $this->assign('parent_dir', '');
     }
     $user = Sp_Account_User::current();
     if ($user->isLogin()) {
         $user = Sp_Account_User::getUser($user->id, array('name', 'face', 'gender', 'province', 'city', 'area', 'mobile_status', 'email_status'));
         $this->assign('user', $user);
     }
     $this->assign('SP_COMPANY', SP_COMPANY);
     //公司名称
     $this->assign('SP_INVEST_COMPANY', SP_INVEST_COMPANY);
     //网站名称
     $this->default_template_handler_func = array($this, 'make_template');
 }
 /**
  * 退出(清除cookie)
  *
  * @return void
  */
 public function signout()
 {
     $this->_set('id', 0);
     $this->clear();
     return setcookie(self::COOKIE_NAME, FALSE, time() + 315360000, '/', Request::genCookieDomain());
 }