<?php
if (!defined('IN_YOUKE365')) exit('Access Denied');

function smarty_output($template, $cache_id = NULL, $compile_id = NULL) {
	global $smarty, $options;
	
	template_exists($template);
	
	#common
	$options = stripslashes_deep($options);
	$stats = get_stats();
	$labels = stripslashes_deep(get_labels());
	
	#user login
	$auth_cookie = $_COOKIE['auth_cookie'];
	$user_info = check_user_login($auth_cookie);
	if (empty($user_info)) {
// 用户登录状态
		$login_status = '<div class="top-ulogin">
		<a href="'.$options['site_root'].'member/?mod=login"><i class="fa fa-sign-in" aria-hidden="true"></i> 登录</a>
		<a href="'.$options['site_root'].'member/?mod=register"><i class="fa fa-registered" aria-hidden="true"></i> 注册</a>
		<a href="'.$options['site_root'].'member/?mod=getpwd"><i class="fa fa-envelope-o" aria-hidden="true"></i> 找回密码</a></div>';

	} else {
		$login_status = '<div class="top-uinfo">您好 '.$user_info['nick_name'].'，
		<a href="'.$options['site_root'].'member/?mod=home"><i class="fa fa-user-circle" aria-hidden="true"></i> 会员中心</a> | 
		<a href="'.$options['site_root'].'member/?mod=logout"><i class="fa fa-sign-out" aria-hidden="true"></i> 退出</a></div>';
	}
  // echo $options['search_words'];
   $search_words = get_format_tags($options['search_words']);
    if(!isset($search_words)){
       $search_words ='';
    }
    $smarty->assign('search_words',$search_words);
	$smarty->assign('site_root', $options['site_root']);
	$smarty->assign('site_name', $options['site_name']);
	$smarty->assign('site_url', $options['site_url']);
	$smarty->assign('site_copyright', $options['site_copyright']);

	$smarty->assign('cfg', $options); #options
	$smarty->assign('stat', $stats); #stats
	$smarty->assign('label', $labels); #labels
	$smarty->assign('script_time', get_scripttime()); #script time
	$smarty->assign('login_status', $login_status); #user login
	
	#parse template and output
	$content = $smarty->fetch($template, $cache_id, $compile_id);
	if ($options['link_struct'] != 0) {
		$content = rewrite_output($content);
	}
	echo $content;
	#gzip
	$buffer = ob_get_contents();
	ob_end_clean();
	$options['is_enabled_gzip'] == 'yes' ? ob_start('ob_gzhandler') : ob_start();
	
	echo $buffer;
}



/** site path */
function get_sitepath($cate_id = 0) {
	global $options;
	
	$strpath = '当前位置：<a href="'.$options['site_url'].'">'.$options['site_name'].'</a>'.($cate_id > 0 ? get_category_path($cate_id) : '');
	
	return $strpath;
}

