From dba042adcccf3441dedb3f53aeffb25eb5cf8623 Mon Sep 17 00:00:00 2001 From: AntonLV Date: Wed, 13 Mar 2024 09:55:17 +0300 Subject: [PATCH] Ticket #4641 - Use HTMX to load page content without genaral page structure. --- inc/classes/BxDolMenu.php | 6 ++ inc/classes/BxDolPage.php | 14 ++- inc/classes/BxDolTemplate.php | 36 ++++++++ inc/utils.inc.php | 26 ++++++ install/sql/system.sql | 1 + .../template/system/menu_main_submenu.html | 2 +- .../template/system/scripts/BxTemplMenu.php | 18 +++- .../boonex/english/data/langs/system/en.xml | 2 +- .../boonex/russian/data/langs/system/ru.xml | 2 +- plugins_public/htmx.min.js | 1 + template/_page_content_beg.html | 5 ++ template/_page_content_end.html | 6 ++ template/_page_cover.html | 3 + template/_page_submenu.html | 19 +++++ template/_page_toolbar.html | 47 ++++++++++ template/_sub_footer.html | 13 ++- template/_sub_header.html | 85 ++----------------- template/menu_main_submenu.html | 2 +- template/page_50.html | 1 + template/page_54.html | 11 +++ template/page_56.html | 8 ++ template/scripts/BxBaseMenu.php | 14 +++ template/scripts/BxBasePage.php | 4 +- 23 files changed, 231 insertions(+), 95 deletions(-) create mode 100644 plugins_public/htmx.min.js create mode 100644 template/_page_content_beg.html create mode 100644 template/_page_content_end.html create mode 100644 template/_page_cover.html create mode 100644 template/_page_submenu.html create mode 100644 template/_page_toolbar.html create mode 100644 template/page_50.html create mode 100644 template/page_54.html create mode 100644 template/page_56.html diff --git a/inc/classes/BxDolMenu.php b/inc/classes/BxDolMenu.php index 01faa1f172..d326cd5806 100644 --- a/inc/classes/BxDolMenu.php +++ b/inc/classes/BxDolMenu.php @@ -83,6 +83,9 @@ class BxDolMenu extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla protected $_bIsApi; + protected $_bHx; + protected $_aHx; + protected $_bDynamicMode; protected $_bAddNoFollow; @@ -108,6 +111,9 @@ protected function __construct($aObject) $this->_bIsApi = bx_is_api(); + $this->_bHx = false; + $this->_aHx = []; + $this->_bDynamicMode = false; $this->_bAddNoFollow = getParam('sys_add_nofollow') == 'on'; diff --git a/inc/classes/BxDolPage.php b/inc/classes/BxDolPage.php index 18c9573b37..1bd39e5015 100644 --- a/inc/classes/BxDolPage.php +++ b/inc/classes/BxDolPage.php @@ -689,11 +689,17 @@ public function displayPage ($oTemplate = null) if(!$oTemplate) $oTemplate = BxDolTemplate::getInstance(); - $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT); + $oTemplate->setPageNameIndex(BX_PAGE_DEFAULT); + if(($sHxTarget = bx_get_htmx_target()) !== false) + $oTemplate->setPageNameIndexByTarget($sHxTarget); + $oTemplate->setPageUrl($this->_aObject['url']); - $oTemplate->setPageType ($this->getType()); - $oTemplate->setPageInjections ($this->getInjections()); - $oTemplate->setPageContent ('page_main_code', $this->getCode()); + $oTemplate->setPageType($this->getType()); + $oTemplate->setPageInjections($this->getInjections()); + if($oTemplate->getPageNameIndex() == BX_PAGE_CONTENT_PRELOAD) + $oTemplate->setPageContent('page_main_code', $this->getCodeDynamic(true)); + else + $oTemplate->setPageContent('page_main_code', $this->getCode()); $oTemplate->getPageCode(); } diff --git a/inc/classes/BxDolTemplate.php b/inc/classes/BxDolTemplate.php index d86d1c810c..ca4873a42e 100644 --- a/inc/classes/BxDolTemplate.php +++ b/inc/classes/BxDolTemplate.php @@ -33,6 +33,9 @@ define('BX_PAGE_CLEAR', 2); ///< clear page, without any headers and footers define('BX_PAGE_EMBED', 22); ///< page used for embeds define('BX_PAGE_POPUP', 44); ///< popup page, without any headers and footers +define('BX_PAGE_CONTENT_PRELOAD', 50); ///< page content preload for dynamic (htmx) loading +define('BX_PAGE_CONTENT_WITH_COVER', 54); ///< page content with cover and submenu for dynamic (htmx) loading +define('BX_PAGE_CONTENT_WITH_SUBMENU', 56); ///< page content with submenu for dynamic (htmx) loading define('BX_PAGE_TRANSITION', 150); ///< transition page with redirect to display some msg, like 'please wait', without headers footers /** @@ -724,6 +727,39 @@ function setPageNameIndex($i) { $this->aPage['name_index'] = $i; } + + /** + * Set page name index by target. + * @param string $s target. + */ + function setPageNameIndexByTarget($s) + { + $i = BX_PAGE_DEFAULT; + + switch($s) { + case 'bx-content-preload': + $i = BX_PAGE_CONTENT_PRELOAD; + break; + + case 'bx-content-with-toolbar-wrapper': + //$i = 52; + break; + + case 'bx-content-with-cover-wrapper': + $i = BX_PAGE_CONTENT_WITH_COVER; + break; + + case 'bx-content-with-submenu-wrapper': + $i = BX_PAGE_CONTENT_WITH_SUBMENU; + break; + + case 'bx-content-wrapper': + //$i = 58; + break; + } + + $this->aPage['name_index'] = $i; + } /** * Get page name index diff --git a/inc/utils.inc.php b/inc/utils.inc.php index b0f1d5be87..6b1e4b471d 100644 --- a/inc/utils.inc.php +++ b/inc/utils.inc.php @@ -2227,6 +2227,32 @@ function bx_is_dynamic_request () return bx_get('dynamic') || (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']); } +function bx_is_htmx_request () +{ + return !empty($_SERVER['HTTP_HX_REQUEST']); +} + +function bx_get_htmx_target () +{ + if(!bx_is_htmx_request()) + return false; + + return isset($_SERVER['HTTP_HX_TARGET']) ? $_SERVER['HTTP_HX_TARGET'] : false; +} + +function bx_get_htmx_attrs ($a) +{ + if(!$a) + return ''; + + $aHxAttrs = []; + array_walk($a, function($mixedValue, $sIndex) use (&$aHxAttrs) { + $aHxAttrs['hx-' . $sIndex] = $mixedValue; + }); + + return bx_convert_array2attrs($aHxAttrs); +} + function bx_idn_to_utf8($sUrl, $bReturnDomain = false) { return bx_idn_to('idn_to_utf8', $sUrl, $bReturnDomain); diff --git a/install/sql/system.sql b/install/sql/system.sql index edc1d5e572..88e94b34a1 100644 --- a/install/sql/system.sql +++ b/install/sql/system.sql @@ -6256,6 +6256,7 @@ INSERT INTO `sys_preloader`(`module`, `type`, `content`, `active`, `order`) VALU ('system', 'js_system', 'headroom.min.js', 1, 10), ('system', 'js_system', 'at.js/js/jquery.atwho.min.js', 1, 11), ('system', 'js_system', 'prism/prism.js', 1, 12), +('system', 'js_system', 'htmx.min.js', 1, 13), ('system', 'js_system', 'functions.js', 1, 20), ('system', 'js_system', 'jquery.webForms.js', 1, 21), ('system', 'js_system', 'jquery.dolPopup.js', 1, 22), diff --git a/modules/boonex/artificer/data/template/system/menu_main_submenu.html b/modules/boonex/artificer/data/template/system/menu_main_submenu.html index c2baed2647..733d666a7f 100644 --- a/modules/boonex/artificer/data/template/system/menu_main_submenu.html +++ b/modules/boonex/artificer/data/template/system/menu_main_submenu.html @@ -1,6 +1,6 @@