get_all_config();
$module_config = $global_class -> get_module_config($module,$view,$task);
$cache_time = 0;
if(USE_CACHE){
$cache_time = isset($module_config -> cache)?$module_config -> cache:0;
}
// load main content use Template
include("libraries/templates.php");
global $tmpl;
$tmpl = new Templates();
if($print){
$main_content = loadMainContent($module,$view,$task,0);
include_once("templates/".TEMPLATE."/print.php");
die;
}
if(!$cache_time || !USE_CACHE){
$main_content = loadMainContent($module,$view,$task,0);
ob_start();
include_once("templates/".TEMPLATE."/index.php");
$all_website_content = ob_get_contents();
ob_end_clean();
echo get_wrapper_site($tmpl,'header',$module,0);
echo $all_website_content;
if(USE_BENMARCH){
echo '
';
echo Benchmark::showTimer(5) . ' sec| ';
echo Benchmark::showMemory('kb') . ' kb' ;
echo '
';
}
echo get_wrapper_site($tmpl,'footer',$module,0);
}else if(USE_CACHE != 2){// use cache local or no cache
$main_content = loadMainContent($module,$view,$task,$cache_time);
ob_start();
include_once("templates/".TEMPLATE."/index.php");
$all_website_content = ob_get_contents();
ob_end_clean();
echo get_wrapper_site($tmpl,'header',$module,$cache_time);
echo $all_website_content;
if(USE_BENMARCH){
echo '';
echo Benchmark::showTimer(5) . ' sec| ';
echo Benchmark::showMemory('kb') . ' kb' ;
echo '
';
}
echo get_wrapper_site($tmpl,'footer',$module,$cache_time);
} else { // use cache global
$fsCache = FSFactory::getClass('FSCache');
$key = md5($_SERVER['REQUEST_URI']);
$content_cache = $fsCache -> get($key,'modules/'.$module,$cache_time);
if($content_cache){
echo $content_cache;
if(USE_BENMARCH){
echo '';
echo Benchmark::showTimer(5) . ' sec| ';
echo Benchmark::showMemory('kb') . ' kb' ;
echo '
';
}
}else{
// load content module ( not use cache by use cache Global)
$main_content = loadMainContent($module,$view,$task,0);
ob_start();
include_once("templates/".TEMPLATE."/index.php");
$html_body = $all_website_content = ob_get_contents();
$html_header = get_wrapper_site($tmpl,'header',$module,0);
$html_footer = get_wrapper_site($tmpl,'footer',$module,0);
ob_end_clean();
$html = $html_header.$html_body.$html_footer;
// put cache
$fsCache -> put($key, $html,'modules/'.$module);
echo $html;
if(USE_BENMARCH){
echo '';
echo Benchmark::showTimer(5) . ' sec| ';
echo Benchmark::showMemory('kb') . ' kb' ;
echo '
';
}
}
}
}
/*
* Display msg when redirect
*/
function display_msg_redirect() {
$html = '';
$str_msg = '';
if (isset ( $_SESSION ['have_redirect'] )) {
if ($_SESSION ['have_redirect'] == 1) {
$types = array (0 => 'error', 1 => 'alert', 2 => 'suc' );
foreach ( $types as $type ) {
if (isset ( $_SESSION ["msg_$type"] )) {
$msg_error = $_SESSION ["msg_$type"];
foreach ( $msg_error as $item ) {
if($str_msg)
$str_msg .= '
';
$str_msg .= $item;
}
unset ( $_SESSION ["msg_$type"] );
}
}
}
unset ( $_SESSION ['have_redirect'] );
}
if($str_msg){
$html .= "";
}
return $html;
}
/*
* function Load Main content
*/
function loadMainContent($module = '',$view = '',$task = '',$cache_time = 0){
$html = '';
// message when redirect
$html .= display_msg_redirect();
if($cache_time){
$fsCache = FSFactory::getClass('FSCache');
$key = md5($_SERVER['REQUEST_URI']);
$content_cache = $fsCache -> get($key,'modules/'.$module,$cache_time);
if($content_cache){
return $html.$content_cache;
} else {
$main_content = call_module($module,$view,$task);
$fsCache -> put($key, $main_content,'modules/'.$module);
return $html.$main_content;
}
}else{
$main_content = call_module($module,$view,$task);
return $html.$main_content;
}
}
function call_module($module,$view,$task){
$path = PATH_BASE.'modules' . DS . $module . DS . 'controllers' . DS . $view. ".php";
if(file_exists($path)){
ob_start();
require_once $path;
$c = ucfirst($module).'Controllers'.ucfirst($view);
$controller = new $c();
$controller->$task();
$main_content = ob_get_contents();
ob_end_clean();
return $main_content;
}else{
return ;
}
}
/*
* Get header, footer for case: Cache Local
* @cache_time ( second)
*/
function get_wrapper_site($tmpl,$wrapper_name = 'header',$module,$cache,$cache_time = 10){
if($cache && $cache_time){
$fsCache = FSFactory::getClass('FSCache');
$key = md5($_SERVER['REQUEST_URI']);
$wrapper = $fsCache -> get($key,$wrapper_name.'/'.$module,$cache_time);
if($wrapper){
return $wrapper;
} else {
$func_call = 'load'.ucfirst($wrapper_name);
ob_start();
$tmpl -> $func_call();
$wrapper = ob_get_contents();
ob_end_clean();
$fsCache -> put($key, $wrapper,$wrapper_name.'/'.$module);
return $wrapper;
}
}else{
$func_call = 'load'.ucfirst($wrapper_name);
ob_start();
$tmpl -> $func_call();
$rs = ob_get_contents();
ob_end_clean();
return $rs;
}
}
?>