From 35b61600672cd19529753f7f135587b347faf9e5 Mon Sep 17 00:00:00 2001 From: Puleeno Nguyen Date: Sun, 23 Feb 2020 18:02:30 +0700 Subject: [PATCH 1/5] Remove old structure --- src/Abstracts/Boilerplate.php | 8 - src/Abstracts/TemplateEngine.php | 224 --------------------------- src/Boilerplate/HTML5Boilerplate.php | 50 ------ src/Engine/WordPress.php | 58 ------- src/Exceptions/TemplateException.php | 10 -- src/Initialize.php | 84 ---------- src/Interfaces/Boilerplate.php | 11 -- src/Interfaces/TemplateEngine.php | 17 -- src/Traits/PageTemplate.php | 98 ------------ src/UI/Breadcrumb.php | 7 - src/UI/FooterWidget.php | 45 ------ src/UI/Pagination.php | 33 ---- 12 files changed, 645 deletions(-) delete mode 100644 src/Abstracts/Boilerplate.php delete mode 100644 src/Abstracts/TemplateEngine.php delete mode 100644 src/Boilerplate/HTML5Boilerplate.php delete mode 100644 src/Engine/WordPress.php delete mode 100644 src/Exceptions/TemplateException.php delete mode 100644 src/Initialize.php delete mode 100644 src/Interfaces/Boilerplate.php delete mode 100644 src/Interfaces/TemplateEngine.php delete mode 100644 src/Traits/PageTemplate.php delete mode 100644 src/UI/Breadcrumb.php delete mode 100644 src/UI/FooterWidget.php delete mode 100644 src/UI/Pagination.php diff --git a/src/Abstracts/Boilerplate.php b/src/Abstracts/Boilerplate.php deleted file mode 100644 index 40943cc..0000000 --- a/src/Abstracts/Boilerplate.php +++ /dev/null @@ -1,8 +0,0 @@ -wpThemeRootDir = sprintf('%s%s/', WP_CONTENT_DIR, $roots); - } - - $defaultTemplateDirName = $this->getDefaultTemplateDirectory(); - if (($pos= strpos($defaultTemplateDirName, $this->wpThemeRootDir)) !== false) { - $this->templateDirInTheme = true; - $this->defaultTemplateDirName = substr($defaultTemplateDirName, $pos + strlen(get_template_directory()) + 1); - } - } - - - public function setOriginTemplate($templateFile) - { - if (preg_match('/(.+)\/([^\/]*)\.php$/', trim($templateFile), $matches)) { - list($this->templateFile, $this->rootDirectory, $this->baseTemplate) = $matches; - $pos = strpos($this->baseTemplate, '-'); - if (is_numeric($pos)) { - $this->pageTemplate = substr($this->baseTemplate, 0, $pos); - $this->pageType = substr($this->baseTemplate, $pos + 1); - } else { - $this->pageTemplate = $this->baseTemplate; - } - - $boilerplate_class = apply_filters('boilerplate_adapter_class', HTML5Boilerplate::class); - if (class_exists($boilerplate_class)) { - $boilerplate = new $boilerplate_class(); - - if ($boilerplate instanceof BoilerPlate) { - $this->boilerplate = $boilerplate; - } else { - throw new TemplateException( - sprintf('%s class must is an instance of %s', $boilerplate_class, 'ad'), - TemplateException::TEMPLATE_EXCEPTION_INVALID_BOILERPLATE - ); - } - } else { - throw new TemplateException( - sprintf('Jankx template engine must be have define boilerplate'), - TemplateException::TEMPLATE_EXCEPTION_NOT_FOUND_BOILERPLATE - ); - } - } - } - - public function setAutoloaded($autoloaded = false) - { - /** - * This variable use as flag to specify the template render via Jankx or not - */ - $this->autoloaded = $autoloaded; - } - - public function getBoilerplate() - { - return $this->boilerplate; - } - - public function getHeader($name = null) - { - /** - * Do all actions before get site header - */ - do_action('jankx_before_header', $name); - - /** - * Call to WordPress native function to get site header - * Use WordPress native to integrated with other library and plugins. - */ - get_header($name); - - /** - * Do all actions after get site header - */ - do_action('jankx_after_header', $name); - } - - public function getContent($name, $context = '') - { - do_action('jankx_before_main_content', $name); - $pre = apply_filters("jankx_content_{$context}", null, $name); - if (empty($pre)) { - jankx_template($name); - } else { - echo wp_kses_post($pre); - } - - do_action('jankx_after_main_content', $name); - } - - public function getSidebar($name = null) - { - /** - * Do all actions before get sidebar - */ - do_action('jankx_before_sidebar', $name); - - /** - * Call to WordPress native function to get site sidebar - * Use WordPress native to integrated with other library and plugins. - */ - get_sidebar($name); - - /** - * Do all actions after get sidebar - */ - do_action('jankx_after_sidebar', $name); - } - - public function getFooter($name = null) - { - /** - * Do all actions before get site footer - */ - do_action('jankx_before_footer', $name); - - /** - * Call to WordPress native function to get site footer - * Use WordPress native to integrated with other library and plugins. - */ - get_footer($name); - - /** - * Do all actions after get site footer - */ - do_action('jankx_after_footer', $name); - } - - public function defaultHandler() - { - $pre_404 = apply_filters('jankx_404_custom_content', null); - if ($pre_404) { - echo $pre_404; - return; - } - - $this->getHeader(); - $this->getContent(array( - '404' - )); - $this->getFooter(); - } - - public function render() - { - $this->boilerplate->doctype(); - $this->boilerplate->head(); - - - $handler = array($this, $this->pageTemplate); - if ($this->autoloaded) { - $handler = array($this, 'autoload'); - } - - $contentHandler = apply_filters( - 'jankx_page_handler', - $handler, - $this->pageTemplate, - $this->pageType, - $this->templateFile - ); - - if (is_callable($contentHandler)) { - call_user_func($contentHandler); - } else { - $this->defaultHandler(); - } - - $this->boilerplate->footer(); - } - - protected function searchTemplates($templateFiles) - { - $templateFiles = (array)$templateFiles; - foreach ($templateFiles as $index => $templateFile) { - $templateFiles[$index] = sprintf( - '%s/%s%s', - Jankx::templateDirectory(), - $templateFile, - $this->templateExtension() - ); - - if ($this->templateDirInTheme) { - $templateFiles[] = sprintf( - '%s/%s%s', - $this->defaultTemplateDirName, - $templateFile, - $this->templateExtension() - ); - } - } - - return $templateFiles; - } -} diff --git a/src/Boilerplate/HTML5Boilerplate.php b/src/Boilerplate/HTML5Boilerplate.php deleted file mode 100644 index 0358528..0000000 --- a/src/Boilerplate/HTML5Boilerplate.php +++ /dev/null @@ -1,50 +0,0 @@ -'; - } - - public function head() - { - ?> - > - - - - <?php wp_title(); ?> - - - > - - - - - searchTemplates($templates), - false - ); - - if (empty($searched_template)) { - $defaultDirectory = $this->getDefaultTemplateDirectory(); - foreach ((array)$templates as $template) { - $template = sprintf('%s/%s.php', $defaultDirectory, $template); - if (file_exists($template)) { - $searched_template = $template; - break; - } - } - } - - if (!$searched_template || !$loadTemplate) { - return $searched_template; - } - if ($require_once) { - require_once $temsearched_templateplate; - } else { - require $searched_template; - } - } -} diff --git a/src/Exceptions/TemplateException.php b/src/Exceptions/TemplateException.php deleted file mode 100644 index d8cbe5b..0000000 --- a/src/Exceptions/TemplateException.php +++ /dev/null @@ -1,10 +0,0 @@ -hasActiveFooterWidgets = function () { - return FooterWidget::isActive(); - }; - - $jankx->footerWidgets = function () { - return FooterWidget::render(); - }; - } - - public static function loadHelpers() - { - require_once realpath(dirname(__FILE__) . '/../frontend-helpers.php'); - } - - public static function supportNotJankxTemplate($templateFile) - { - if (empty($templateFile)) { - return $templateFile; - } - - $relativePath = str_replace(WP_CONTENT_DIR, '', $templateFile); - if (!preg_match('/^\/themes/', $relativePath)) { - self::addJankxHookViaWordPressNativeFunctions(); - jankx_page($templateFile, true); - } else { - return $templateFile; - } - } - - public static function addJankxHookViaWordPressNativeFunctions() - { - add_action('get_header', function () { - do_action('jankx_before_get_header'); - }, 5); - add_action('jankx_template_header', function () { - do_action('jankx_after_get_header'); - }, 15); - - add_action('jankx_template_header', function () { - do_action('jankx_before_main_content'); - }, 35); - add_action('get_footer', function () { - do_action('jankx_after_main_content'); - }, 5); - - add_action('get_footer', function () { - do_action('jankx_before_get_footer'); - }, 35); - add_action('jankx_template_footer', function () { - do_action('jankx_after_get_footer'); - }); - } - - public static function custom_404_page() - { - ob_start(); - jankx_template(array('error/404', '404')); - return ob_get_clean(); - } - } -} diff --git a/src/Interfaces/Boilerplate.php b/src/Interfaces/Boilerplate.php deleted file mode 100644 index 7173093..0000000 --- a/src/Interfaces/Boilerplate.php +++ /dev/null @@ -1,11 +0,0 @@ -getHeader(); - do_action('before_home_content'); - $this->getContent(array('home', 'index'), 'home'); - do_action('after_home_content'); - $this->getFooter(); - } - - /** - * Load the page template - */ - public function page() - { - $this->getHeader(); - do_action('before_page_content'); - $this->getContent('page', 'page'); - do_action('after_page_content'); - $this->getFooter(); - } - - /** - * Load the single post template - */ - public function single() - { - $this->getHeader(); - do_action('before_single_content'); - $this->getContent(array( - sprintf( - 'single/%s', - empty($this->pageType) ? get_post_type() : $this->pageType - ), - 'single' - ), 'single'); - do_action('after_single_content'); - $this->getFooter(); - } - - /** - * Load the archive template - */ - public function archive() - { - $this->getHeader(); - do_action('after_archive_content'); - $this->getContent(array( - sprintf( - 'archive/%s', - empty($this->pageType) ? get_post_type() : $this->pageType - ), - 'archive' - ), 'archive'); - do_action('after_archive_content'); - $this->getFooter(); - } - - /** - * Load the search result template - */ - public function search() - { - $this->getHeader(); - do_action('after_search_content'); - $this->getContent(array( - sprintf( - 'search/%s', - get_post_type() - ), - 'search' - ), 'search'); - do_action('after_search_content'); - $this->getFooter(); - } - - /** - * This method to load the template in contain in theme directory - * Them like Woocommerce template or similar template - */ - public function autoload() - { - require_once $this->templateFile; - } -} diff --git a/src/UI/Breadcrumb.php b/src/UI/Breadcrumb.php deleted file mode 100644 index 219c254..0000000 --- a/src/UI/Breadcrumb.php +++ /dev/null @@ -1,7 +0,0 @@ - 0 && is_dynamic_sidebar($first_sidebar); - } -} diff --git a/src/UI/Pagination.php b/src/UI/Pagination.php deleted file mode 100644 index f0521ae..0000000 --- a/src/UI/Pagination.php +++ /dev/null @@ -1,33 +0,0 @@ -format = $format; - $this->currentPage = max(1, get_query_var('paged')); - $this->big = 999999999; - $this->base = str_replace( - $this->big, - '%#%', - esc_url(get_pagenum_link($this->big)) - ); - } - - public function render() - { - global $wp_query; - echo paginate_links( - array( - 'base' => $this->base, - 'format' => $this->format, - 'current' => $this->currentPage, - 'total' => $wp_query->max_num_pages - ) - ); - } -} From 05f177b15d7d178801befaa67ac25b9eb4edcfb9 Mon Sep 17 00:00:00 2001 From: Puleeno Nguyen Date: Mon, 24 Feb 2020 23:34:23 +0700 Subject: [PATCH 2/5] Remove old templates --- default/404.php | 383 --------------------------- default/comments.php | 5 - default/header-preset/logo-left.php | 0 default/header-preset/menu-left.php | 0 default/header-preset/menu-right.php | 0 default/home.php | 16 -- default/loop/post.php | 12 - default/page.php | 6 - default/partials/footer.php | 13 - default/partials/header.php | 21 -- default/partials/sidebar-alt.php | 3 - default/partials/sidebar.php | 3 - default/search.php | 0 default/single.php | 6 - frontend-helpers.php | 63 ----- 15 files changed, 531 deletions(-) delete mode 100644 default/404.php delete mode 100644 default/comments.php delete mode 100644 default/header-preset/logo-left.php delete mode 100644 default/header-preset/menu-left.php delete mode 100644 default/header-preset/menu-right.php delete mode 100644 default/home.php delete mode 100644 default/loop/post.php delete mode 100644 default/page.php delete mode 100644 default/partials/footer.php delete mode 100644 default/partials/header.php delete mode 100644 default/partials/sidebar-alt.php delete mode 100644 default/partials/sidebar.php delete mode 100644 default/search.php delete mode 100644 default/single.php delete mode 100644 frontend-helpers.php diff --git a/default/404.php b/default/404.php deleted file mode 100644 index a2d1a05..0000000 --- a/default/404.php +++ /dev/null @@ -1,383 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Xin chào?? Có gì ở đây không?!?' ); ?> - Chúng tôi biết nó rất đáng sợ, nhưng trang mà bạn đang cố gắng tiếp cận có thể được tìm thấy. Có lẽ đó chỉ là một giấc mơ?

-

Về trang chủ

' ); ?> - -
- - - - - - diff --git a/default/comments.php b/default/comments.php deleted file mode 100644 index f440bb5..0000000 --- a/default/comments.php +++ /dev/null @@ -1,5 +0,0 @@ -
- -
- - diff --git a/default/header-preset/logo-left.php b/default/header-preset/logo-left.php deleted file mode 100644 index e69de29..0000000 diff --git a/default/header-preset/menu-left.php b/default/header-preset/menu-left.php deleted file mode 100644 index e69de29..0000000 diff --git a/default/header-preset/menu-right.php b/default/header-preset/menu-right.php deleted file mode 100644 index e69de29..0000000 diff --git a/default/home.php b/default/home.php deleted file mode 100644 index 59dcb5e..0000000 --- a/default/home.php +++ /dev/null @@ -1,16 +0,0 @@ -

- Blog/Thông tin -

-
- -
- -'; - while ( have_posts() ) { - the_post(); - jankx_template( 'loop/post' ); - } - echo ''; -} diff --git a/default/loop/post.php b/default/loop/post.php deleted file mode 100644 index 0452e91..0000000 --- a/default/loop/post.php +++ /dev/null @@ -1,12 +0,0 @@ -
-
- thumbnail(); ?> -
-

- title(); ?> -

- -
- -
-
diff --git a/default/page.php b/default/page.php deleted file mode 100644 index 49999bf..0000000 --- a/default/page.php +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - - diff --git a/default/partials/header.php b/default/partials/header.php deleted file mode 100644 index 61af644..0000000 --- a/default/partials/header.php +++ /dev/null @@ -1,21 +0,0 @@ - - diff --git a/default/partials/sidebar-alt.php b/default/partials/sidebar-alt.php deleted file mode 100644 index b0df0b9..0000000 --- a/default/partials/sidebar-alt.php +++ /dev/null @@ -1,3 +0,0 @@ -
- -
diff --git a/default/partials/sidebar.php b/default/partials/sidebar.php deleted file mode 100644 index 8f3de79..0000000 --- a/default/partials/sidebar.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/default/search.php b/default/search.php deleted file mode 100644 index e69de29..0000000 diff --git a/default/single.php b/default/single.php deleted file mode 100644 index 49999bf..0000000 --- a/default/single.php +++ /dev/null @@ -1,6 +0,0 @@ -setOriginTemplate($originTemplate); - $templateEngine->setAutoloaded($auto); - - if (!$templateEngine instanceof TemplateEngine) { - throw new TemplateException( - sprintf('The template engine must be an instance of %s class', TemplateEngine::class), - TemplateException::TEMPLATE_EXCEPTION_INVALID_ENGINE - ); - } - - do_action('jankx_page_setup', $templateEngine); - - $templateEngine->render(); -} - -function jankx_get_template_engine() -{ - if (empty($GLOBALS['template_engine'])) { - $template = apply_filters('jankx_template_engine', WordPress::class); - if (!class_exists($template)) { - throw new TemplateException( - sprintf('The engine with class "%s " is not exists to load', $template), - TemplateException::TEMPLATE_EXCEPTION_ENGINE_NOT_FOUND - ); - } - $GLOBALS['template_engine'] = new $template(); - } - - return $GLOBALS['template_engine']; -} - -function jankx_template($templateFiles, $context = null) -{ - do_action("jankx_template_before_{$context}"); - - /** - * Get current template engine is used in Jankx framework - */ - $engine = jankx_get_template_engine(); - $ret = $engine->loadTemplates( - apply_filters('jankx_search_templates', $templateFiles) - ); - - do_action("jankx_template_{$context}", $ret, $templateFiles); - return $ret; -} From bfa6627b96b99d7e73f8e440f507dfd9f0064415 Mon Sep 17 00:00:00 2001 From: Puleeno Nguyen Date: Tue, 25 Feb 2020 07:38:39 +0700 Subject: [PATCH 3/5] Added new structure --- src/Abstracts/Component.php | 5 +++++ src/Template.php | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 src/Abstracts/Component.php create mode 100644 src/Template.php diff --git a/src/Abstracts/Component.php b/src/Abstracts/Component.php new file mode 100644 index 0000000..820155a --- /dev/null +++ b/src/Abstracts/Component.php @@ -0,0 +1,5 @@ + Date: Tue, 25 Feb 2020 22:29:49 +0700 Subject: [PATCH 4/5] Added new structure for template --- src/Abstracts/Component.php | 3 ++- src/Abstracts/TemplateEngine.php | 6 ++++++ src/Component.php | 6 ++++++ src/Engine/WordPress.php | 8 ++++++++ src/Loader.php | 25 +++++++++++++++++++++++++ src/Template.php | 16 +++++++++++++++- 6 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/Abstracts/TemplateEngine.php create mode 100644 src/Component.php create mode 100644 src/Engine/WordPress.php create mode 100644 src/Loader.php diff --git a/src/Abstracts/Component.php b/src/Abstracts/Component.php index 820155a..40fb531 100644 --- a/src/Abstracts/Component.php +++ b/src/Abstracts/Component.php @@ -1,5 +1,6 @@ defaultTemplateDirectory = $defaultTemplateDirectory; + } + + public function search($templates, $context = null) + { + } + + public function load($data = [], $echo = true) + { + } + + public function searchInDefautDirectory($templates, $context = null) + { + } +} diff --git a/src/Template.php b/src/Template.php index c5e5942..1b081bb 100644 --- a/src/Template.php +++ b/src/Template.php @@ -1,5 +1,19 @@ Date: Wed, 26 Feb 2020 21:43:05 +0700 Subject: [PATCH 5/5] Move WordPress template engine to new package --- src/Component.php | 6 ------ src/Engine/WordPress.php | 8 -------- src/Loader.php | 2 +- src/Template.php | 4 ++++ 4 files changed, 5 insertions(+), 15 deletions(-) delete mode 100644 src/Component.php delete mode 100644 src/Engine/WordPress.php diff --git a/src/Component.php b/src/Component.php deleted file mode 100644 index ea423d3..0000000 --- a/src/Component.php +++ /dev/null @@ -1,6 +0,0 @@ -