compile_check = true; // ki?m tra xem template d? có thay d?i g? không, n?u có, n?p d? li?u m?i $smarty->template_dir ='templates'; $smarty->compile_dir ='templates_c'; $smarty->config_dir ='config_smarty'; $smarty->cache_dir = 'cache_folder'; $smarty->left_delimiter="<%"; $smarty->right_delimiter="%>"; //$smarty->debugging = true; if($_SERVER['REQUEST_METHOD']=="POST") { $smarty->clear_all_cache(); } //khoi tao lop ket noi $db = new DB(USER, PASS, DBNAME, HOST); $db->connect(); $db->set_utf8(); //Khoi tao lop base_class $base=new BASE_CLASS(); $base->SetCountVisit();//Dem so nguoi truy cap //Thong tin cau hinh site $smarty->assign("lang",$lang); $sql="select * from tbl_config cf, tbl_config_language cfl where cf.id=cfl.group_id and lang='{$lang}' limit 0,1"; $config=$db->getRow($sql); $smarty->assign("config",$base->ConvertObjectToArray($config)); $smarty->assign("title",$config->sitetitle); if($config) { if($config->port!='') $port=$config->port; else $port="25"; //$mail_server=$config->mail_server.":".$config->port; $mail_server=$config->mail_server; $mail=new MAIL_SMTP($config->email_address, $mail_server, $port, $config->email_address,$config->login_name,$config->pass_email_server); } else{ $mail=new MAIL_SMTP(); } // bat dau vao trang home tai day!!! $arr=explode('/',$_SERVER['SCRIPT_NAME']);//Lay ra thu muc goc cua website $arr_temp=explode('/',$base->request_uri()); $root=array(); $j=0; for($i=count($arr);$igetRow($sql); if(!isset($infopage)){//Neu trang nay bi cam hoac khong ton tai thi di chuyen toi trang 404 $page="404"; $temp="default"; } else { $temp=$infopage->template;//Lay giao dien cua trang } $smarty->assign('page',$page); $page_active=explode('-',$page); if($page!='supports-faqs') $smarty->assign('pageActive',$page_active[0]); else $smarty->assign('pageActive',$page_active[1]); $smarty->assign('menu_active_'.$page_active[0],'_act'); $smarty->assign('active_'.$page_active[0],'active'); if($page_active[0]=='gallery') { $smarty->assign('menu_active_about','_act'); $smarty->assign('menu_active_gallery','active'); } //lay cac bien querystring dua vao mang //array(2) { ["bai-viet"]=> string(16) "nguoi-duong-thoi" ["id"]=> string(0) "123" } $var=array(); for($i=1;$iassign("var",$var); if($smarty->template_exists($temp)) { $temp="default";//Chon template } $www=$_SERVER['SCRIPT_NAME']; $smarty->assign("www",$www);//Duong dan tinh tu thu muc go cua website, duoc dung de gan vao link ; $pathroot=root; $smarty->assign("pathroot",$pathroot);//Duong vao thu muc go cua website: $pathTemp=$pathroot."templates/".$temp."/";//Duong dan toi template $smarty->assign("pathTemp",$pathTemp); $smarty-> caching =1; $cacheId=$_SERVER['PHP_SELF'].'_'.$lang; include_once("modules/utilities/model.php"); if(!$smarty->is_cached($temp."/layout.html",$cacheId)){ //Lay cac module duoc hien tren trang $sql="select `module_id`, `action`,`location` from tbl_page_modules where `page_id`='{$page}' order by `location`, ordering"; $locations=$db->getRows($sql);//Lay cac vi tri tren trang if(isset($locations))//Vi tri hien thi { $tempLocal='';$i=0; $module="";$action="";$layout_view=""; $j=0; foreach($locations as $mod) { if($tempLocal==$mod->location) { $i++; } else { if($tempLocal!='') $smarty->assign($tempLocal,$arr_view); $tempLocal=$mod->location; $arr_view=array(); $i=0; } //Thuc thi module, o day se khoi tao ca bien de file layout hien thi lai $module=$mod->module_id; $action=$mod->action; $layout_view=$action; //Neu file da duoc include thi thuc thi function $fn=$action."_".$module; if(function_exists($fn)) { $fn(); } else { include_once("modules/".$module."/model.php"); $fn(); } // Hien thi thong tin len layout cua module tuong ung $arr_view[$i]="../modules/".$module."/views/".$layout_view.".php"; if($j==count($locations)-1) $smarty->assign($tempLocal,$arr_view); $j++; } } } function smarty_block_dynamic($param, $content, &$smarty) { return $content; } $smarty->register_block('dynamic', 'smarty_block_dynamic', false); $smarty->cache_lifetime = 30000;//Luu cache trong 30' $smarty->display($temp."/layout.html",$cacheId);//Hien thi thong tin cua module len layout chính $db->disconnect(); ?>