From 4fa4c3996f3d1f338608f33a9eb2518c35fc9507 Mon Sep 17 00:00:00 2001 From: hieutmd Date: Sun, 28 Jan 2024 11:08:45 +0700 Subject: [PATCH] c --- inc/Hura8/AppAdmin.php | 43 ++++++++++++++++++++----- template/customer/comment.html | 0 template/customer/customer-contact.html | 0 template/customer/home.html | 0 template/customer/review.html | 0 template/template/home.html | 0 template/theme.html | 4 +-- 7 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 template/customer/comment.html create mode 100644 template/customer/customer-contact.html create mode 100644 template/customer/home.html create mode 100644 template/customer/review.html create mode 100644 template/template/home.html diff --git a/inc/Hura8/AppAdmin.php b/inc/Hura8/AppAdmin.php index b743330..eb29ac5 100644 --- a/inc/Hura8/AppAdmin.php +++ b/inc/Hura8/AppAdmin.php @@ -48,13 +48,14 @@ class AppAdmin str_replace("-", "_", $this->current_route_info["view"]).".php" ]) ; - if(!file_exists($module_file)) { + if(file_exists($module_file)) { // print_r($this->current_route_info); - die('Page '. $module_file .' not found!'); + // die('Page '. $module_file .' not found!'); + $data = include_once $module_file; + }else{ + $data = ['file data '. $module_file .' not found!']; } - $data = include_once $module_file; - $global_data = [ "module" => $this->current_route_info['module'], "view" => $this->current_route_info['view'], @@ -71,11 +72,16 @@ class AppAdmin protected function renderModule() { - $template_file_path = $this->tpl_path ."/". $this->current_route_info['module']."/".$this->current_route_info['view'].".html"; + $template_file_path = $this->tpl_path ."/". $this->current_route_info['module']; + $template_file_name = $this->current_route_info['view'].".html"; + $template_file_full_path = $template_file_path."/".$template_file_name; //check exist - if(!@file_exists( $template_file_path)) { - die("Not found : ". $template_file_path); + if(!@file_exists( $template_file_full_path)) { + // attempt to auto create first + if(!$this->autoCreateTplFile( $template_file_path, $template_file_name )) { + die("Please manually create template file at: ". $template_file_full_path); + } } $theme_file_path = $this->tpl_path ."/theme.html"; @@ -84,7 +90,7 @@ class AppAdmin } $theme_content = @file_get_contents( $theme_file_path ); - $module_content = @file_get_contents( $template_file_path ); + $module_content = @file_get_contents( $template_file_full_path ); $page_content_to_parse = preg_replace([ "/{{(\s+)?page_content(\s+)?}}/" @@ -99,6 +105,27 @@ class AppAdmin ); } + + protected function autoCreateTplFile($file_path, $file_name) : bool { + // create dir if not exist + if(!file_exists($file_path)) { + if(!mkdir($file_path, 0755, true)) { + return false; + } + + if(!file_exists($file_path)) { + return false; + } + } + + //create file + $file_full_path = $file_path . "/". $file_name; + @file_put_contents($file_full_path, $file_full_path); + + return file_exists($file_full_path); + } + + /* * 2 ways to render a html template * 1. Use $html_to_parse, which requires no dependencies diff --git a/template/customer/comment.html b/template/customer/comment.html new file mode 100644 index 0000000..e69de29 diff --git a/template/customer/customer-contact.html b/template/customer/customer-contact.html new file mode 100644 index 0000000..e69de29 diff --git a/template/customer/home.html b/template/customer/home.html new file mode 100644 index 0000000..e69de29 diff --git a/template/customer/review.html b/template/customer/review.html new file mode 100644 index 0000000..e69de29 diff --git a/template/template/home.html b/template/template/home.html new file mode 100644 index 0000000..e69de29 diff --git a/template/theme.html b/template/theme.html index 8ea3bf2..1c47122 100644 --- a/template/theme.html +++ b/template/theme.html @@ -31,7 +31,7 @@