<?php
require(YOUKE365_PATH.'extend/smarty/Smarty.class.php');

$table = $DB->table('templates');
$default_tpl = get_query("select directory from ".$table." where status = 1");

$template_dir = THEME_DIR.'/'.$default_tpl[0]['directory'].'/';
$compile_dir = ROOT_PATH.'data/compile/';
$cache_dir = ROOT_PATH.'data/cache/';
$smarty = new Smarty();	
$smarty->debugging = false;	
if (defined('YOUKE365_ADMIN') && YOUKE365_ADMIN == TRUE) {
    $dirname = '/'.APP_PATH.'/templates/default/';
	$lifetime = 0;
	$caching = false;
    $smarty->template_dir = ROOT_PATH.$dirname;
    define('tpl',$dirname); //默认模板
} elseif (defined('YOUKE365_MEMBER')) {
	$dirname = 'member';
	$lifetime = 0;
	$caching = false;
	$smarty->template_dir = ROOT_PATH.$template_dir.$dirname.'/';
	define('tpl','/'.$template_dir.$dirname.'/'); //默认模板
} else {
	$dirname = 'home';
	$lifetime = CACHE_LIFETIME;
	$caching = CACHE_ON;
	$smarty->template_dir = ROOT_PATH.$template_dir.$dirname.'/';
	define('tpl','/'.$template_dir.$dirname.'/'); //默认模板
}




$smarty->compile_dir = $compile_dir.$dirname.'/';
$smarty->cache_dir = $cache_dir.$dirname.'/';
$smarty->caching = $caching;
$smarty->cache_lifetime = $lifetime;
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";

/** check if a template resource exists */
function template_exists($template) {
	global $smarty;
	
	if (!$smarty->templateExists($template)){
		exit('YOUKE365提醒："'.$template.'"模板不存在！');
	}
}


// $smarty->registerPlugin("function","date_now", "print_current_date");

// function tag($table='',$field='*',$where='',$order='',$limit='10'){
// 	  $where = "";
//    if(!empty($where)){
//      $where  .="where {$where} ";
//      }
//      $order ='';
//      if(!empty($order)){
//       $order  .="order {$order} ";
//      }
//      $limit ='';
//        if(!empty($limit)){
//       $limit  .="limit {$limit} ";
//      }

//    $sql  ="select {$field} from {$table} {$where} {$order} {$limit}";

// }
?>
