From b78f8104f638e87165f9fea5b272a398a5c5d51d Mon Sep 17 00:00:00 2001 From: jun Date: Tue, 14 Apr 2020 19:16:44 +0800 Subject: [PATCH 01/31] fixing issue on drag and drop margins and resize --- public/plugins/css/plugin.melisdragdropzone.css | 12 +++++++++++- src/Controller/StyleController.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/public/plugins/css/plugin.melisdragdropzone.css b/public/plugins/css/plugin.melisdragdropzone.css index d584c67..2332c3e 100644 --- a/public/plugins/css/plugin.melisdragdropzone.css +++ b/public/plugins/css/plugin.melisdragdropzone.css @@ -45,9 +45,19 @@ .melis-dragdropzone .melis-ui-outlined { float: left; - /* revise by: Junry @ 02082019 */ margin: 0 5px 30px 0; + /* margin: 0 5px 30px 0; .container overflow */ } + +/* .melis-dragdropzone .melis-ui-outlined:not(.plugin-width-lg-99-40 ), +.melis-dragdropzone .melis-ui-outlined:not(.plugin-width-lg-100-00) { + margin: 0 5px 30px; +} */ + +/* .plugin-width-md-100-00.melis-ui-outlined { + margin: 0 0 30px; +} */ + .wrapper div.melis-dragdropzone:last-of-type { margin-bottom: 35px; } diff --git a/src/Controller/StyleController.php b/src/Controller/StyleController.php index 3df715a..3da6239 100644 --- a/src/Controller/StyleController.php +++ b/src/Controller/StyleController.php @@ -24,7 +24,7 @@ public function getPagePluginWidthCssAction() ->addHeaderLine('Pragma' , 'no-cache') ->addHeaderLine('Content-Type' , 'text/css;charset=UTF-8'); - $css = '[class^="plugin-width"] {float: left;margin: 0 0px 30px;}'; + $css = '[class^="plugin-width"] {float: left;margin: 0 5px 30px;}'; $pageId = (int) $this->params()->fromQuery('idpage'); $pageSvc = $this->getServiceLocator()->get('MelisEnginePage'); From 32333bc9aad74ea5e4e196970580bfb7ce95d0e8 Mon Sep 17 00:00:00 2001 From: jun Date: Tue, 21 Apr 2020 17:14:11 +0800 Subject: [PATCH 02/31] fix issue on https://trello.com/c/vz3MTpf4/128-wrapper-drag-n-drop-margins-and-resize --- config/plugins/MelisFrontTagPlugin.config.php | 1 + .../plugins/css/plugin.melisdragdropzone.css | 2 +- public/plugins/js/plugin.melistagHTML.init.js | 7 +- public/plugins/js/plugin.related.data.js | 153 ++++++++++++++++++ .../dragdropzone-melis-container.phtml | 10 +- 5 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 public/plugins/js/plugin.related.data.js diff --git a/config/plugins/MelisFrontTagPlugin.config.php b/config/plugins/MelisFrontTagPlugin.config.php index 3c41f54..6aa9dbf 100644 --- a/config/plugins/MelisFrontTagPlugin.config.php +++ b/config/plugins/MelisFrontTagPlugin.config.php @@ -42,6 +42,7 @@ 'css' => array( ), 'js' => array( + 'js_melistag_custom_js' => '/MelisFront/plugins/js/plugin.related.data.js', 'js_melistag' => '/MelisFront/plugins/js/plugin.melistagHTML.init.js' ), ), diff --git a/public/plugins/css/plugin.melisdragdropzone.css b/public/plugins/css/plugin.melisdragdropzone.css index 2332c3e..9333901 100644 --- a/public/plugins/css/plugin.melisdragdropzone.css +++ b/public/plugins/css/plugin.melisdragdropzone.css @@ -45,7 +45,7 @@ .melis-dragdropzone .melis-ui-outlined { float: left; - margin: 0 5px 30px 0; + margin: 0 5px 30px; /* margin: 0 5px 30px 0; .container overflow */ } diff --git a/public/plugins/js/plugin.melistagHTML.init.js b/public/plugins/js/plugin.melistagHTML.init.js index 03ff0a3..75f2129 100644 --- a/public/plugins/js/plugin.melistagHTML.init.js +++ b/public/plugins/js/plugin.melistagHTML.init.js @@ -21,8 +21,7 @@ function melistagHTML_savePlugin(editor){ } // run this function when you click out of the tinymce -$("body").on("blur", "div.html-editable", function(){ - +$("body").on("blur", "div.html-editable", function() { // get all data-attributes from the clicked var currentdata = $(this).data(); @@ -36,9 +35,9 @@ $("body").on("blur", "div.html-editable", function(){ tagType: currentdata.tagType, tagId : currentdata.tagId, tagValue : content, - }; + }; melisPluginEdition.calcFrameHeight(); - melisPluginEdition.savePluginUpdate(data, currentdata.siteModule); + melisPluginEdition.savePluginUpdate(data, currentdata.siteModule); }); melistagHTML_init(); \ No newline at end of file diff --git a/public/plugins/js/plugin.related.data.js b/public/plugins/js/plugin.related.data.js new file mode 100644 index 0000000..4f23ff7 --- /dev/null +++ b/public/plugins/js/plugin.related.data.js @@ -0,0 +1,153 @@ +var pluginRelatedData = (function($, window) { + /** + * Process el from .html-editable on blur event + * Need processPluginData(toolBox, percentTotalWidth ) + * */ + function setPercentTotalWidth( el ) { + //setTimeout(function() { + // .melis-dragdropzone find .children(".melis-plugin-tools-box") + var $melisUI = el.closest(".melis-ui-outlined"), + melisDndZone = $melisUI.parent(), + $toolBox = $melisUI.children(".melis-plugin-tools-box"), + melisUIWidth = $melisUI.outerWidth(), // totalWidth + dragDropZoneWidth = $(melisDndZone).outerWidth(); // parentWidth + + percentTotalWidth = ( 100 * dragDropZoneWidth / melisUIWidth ); + percentTotalWidth = percentTotalWidth.toFixed(2); + + /* console.log("melisDndZone: ", melisDndZone); + console.log("melisDndZone length: ", melisDndZone.length); + console.log("setPercentTotalWidth $toolBox: ", $toolBox); + console.log("setPercentTotalWidth $toolBox length: ", $toolBox.length); */ + + //if ( $toolBox.length > 0 ) { + processPluginData( $toolBox, percentTotalWidth ); + //} + //}, 1000); + } + + function processPluginData( el, percentTotalWidth ) { + var toolBox = el, + mobileWidth, tabletWidth, desktopWidth, currentClass, newClass, + iframe = window.parent.$("#"+ parent.activeTabId).find('iframe'), + parentOutlined = $(toolBox).closest(".melis-ui-outlined"), + classes = parentOutlined.attr("class").split(" "), + editable = parentOutlined.find(".melis-editable"); + + /* console.log("processPluginData toolBox: ", toolBox); + console.log("processPluginData parentOutlined: ", parentOutlined); + console.log("parentOutlined: ", parentOutlined + " classes: ", + classes); */ + + //console.log("toolBox length: ", toolBox.length); + + if ( toolBox.length ) { + var pluginList = new Object(); + // get data first load + $( toolBox ).map(function() { + var $this = $(this); + + pluginList['melisIdPage'] = window.parent.$("#"+parent.activeTabId).find(".melis-iframe").data("iframe-id"); + pluginList['melisModule'] = $this.data("module"); + pluginList['melisPluginName'] = $this.data("plugin"); + pluginList['melisPluginId'] = $this.data("plugin-id"); + pluginList['melisPluginTag'] = $this.data("melis-tag"); + mobileWidth = $this.attr("data-plugin-width-mobile"); + tabletWidth = $this.attr("data-plugin-width-tablet"); + desktopWidth = $this.attr("data-plugin-width-desktop"); + }); + + // custom action check if plugin tags + /* if( $(editable).length ) { + // trigger focus to saveSession + var data = $(editable).data(); + $(editable).focus().removeClass("mce-edit-focus"); + + // hide tinymce option while resizing + var inst = tinyMCE.EditorManager.get(data.pluginId); + inst.fire("blur"); + iframe.blur(); + + $(editable).map(function() { + var $this = $(this); + + pluginList['tagType'] = $this.data("tag-type"); + pluginList['tagId'] = $this.data("tag-id"); + pluginList['tagValue'] = tinyMCE.activeEditor.getContent({format : 'html'}); + }); + } */ + + console.log("mobileWidth: ", + mobileWidth + " tabletWidth: ", + tabletWidth + " desktopWidth: ", desktopWidth); + + // check if resize in mobile + if(iframe.width() <= 480) { + mobileWidth = percentTotalWidth; + // update DOM data attribute + $(toolBox).attr("data-plugin-width-mobile", mobileWidth); + currentClass = "plugin-width-xs-"; + + var strPercentTotalWidth = percentTotalWidth; + // newClass = "plugin-width-xs-"+Math.floor(percentTotalWidth); // removed when css is ready + newClass = "plugin-width-xs-"+strPercentTotalWidth.replace(".", "-"); // removed when css is ready + $.each(classes, function(key, value) { + if( value.indexOf(currentClass) != -1 ) { + parentOutlined.removeClass(value).addClass(newClass); + } + }); + } + // check if resize in tablet + if(iframe.width() > 490 && iframe.width() <= 980) { + tabletWidth = percentTotalWidth; + $(toolBox).attr("data-plugin-width-tablet", tabletWidth); + currentClass = "plugin-width-md-"; + var strPercentTotalWidth = percentTotalWidth; + // newClass = "plugin-width-md-"+Math.floor(percentTotalWidth); // removed when css is ready + newClass = "plugin-width-lg-"+strPercentTotalWidth.replace(".", "-"); // removed when css is ready + $.each(classes, function(key, value) { + if( value.indexOf(currentClass) != -1 ) { + parentOutlined.removeClass(value).addClass(newClass); + } + }); + } + // check if resize in desktop + if(iframe.width() >= 981) { + desktopWidth = percentTotalWidth; + $(toolBox).attr("data-plugin-width-desktop", desktopWidth); + currentClass = "plugin-width-lg-"; + var strPercentTotalWidth = percentTotalWidth; + // newClass = "plugin-width-lg-"+Math.floor(percentTotalWidth); // removed when css is ready + newClass = "plugin-width-lg-" + strPercentTotalWidth.replace(".", "-"); // removed when css is ready + $.each(classes, function(key, value) { + if( value.indexOf(currentClass) != -1 ) { + parentOutlined.removeClass(value).addClass(newClass); + } + }); + } + + // set data attribute for width + pluginList['melisPluginMobileWidth'] = mobileWidth; + pluginList['melisPluginTabletWidth'] = tabletWidth; + pluginList['melisPluginDesktopWidth'] = desktopWidth; + pluginList['resize'] = true; + + // recalculate frame height + melisPluginEdition.calcFrameHeight(); + + // pass is to savePageSession + melisPluginEdition.savePluginUpdate(pluginList, toolBox.data("site-module")); + + // get plugin ID and re init + // check if owl re init + var owlCheck = $(parentOutlined).find(".owl-carousel"); + if( $(owlCheck).length ) { + // setTimeout to re init, conflict with transition need to timeout + setTimeout(function() { + $(owlCheck).trigger('refresh.owl.carousel'); + }, 500); + } + } + } + + return { + setPercentTotalWidth : setPercentTotalWidth + } +})(jQuery, window); \ No newline at end of file diff --git a/view/melis-front/plugins/dragdropzone-melis-container.phtml b/view/melis-front/plugins/dragdropzone-melis-container.phtml index 864bbdb..b733279 100644 --- a/view/melis-front/plugins/dragdropzone-melis-container.phtml +++ b/view/melis-front/plugins/dragdropzone-melis-container.phtml @@ -14,7 +14,11 @@ data-plugin-id="" data-melis-tag="pluginXmlDbKey; ?>" data-site-module="siteModule; ?>"> -viewFront; -?> +
+
+ viewFront; + ?> +
+
\ No newline at end of file From 01f01b00a1c24c8c2f7c39a1d3b47cf0dde1d67f Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 24 Apr 2020 15:30:52 +0800 Subject: [PATCH 03/31] Merge request and Breadcrumb fixes --- public/plugins/js/plugin.melisGdprBanner.init.js | 4 +--- src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php | 9 ++++++--- view/layout/layoutFront.phtml | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/public/plugins/js/plugin.melisGdprBanner.init.js b/public/plugins/js/plugin.melisGdprBanner.init.js index fb48146..fcab995 100644 --- a/public/plugins/js/plugin.melisGdprBanner.init.js +++ b/public/plugins/js/plugin.melisGdprBanner.init.js @@ -29,9 +29,7 @@ window.MelisGdprBanner = (function () { * * src: https://zellwk.com/blog/looping-through-js-objects/ */ - options = Object.entries({...defaultOptions,...options - }) - ; + options = Object.entries({defaultOptions,options}); var updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value); for (const [key, value] of options) { updatedCookie += "; " + key + "=" + value; diff --git a/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php b/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php index 7de0fd1..5c3c9a5 100644 --- a/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php +++ b/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php @@ -77,7 +77,10 @@ public function front() { foreach ($pageBreadcrumb As $key => $val) { - if (in_array($val->page_type, array('PAGE', 'SITE'))) + if($val->page_menu == "NONE") + continue; + + if (in_array($val->page_type, array('PAGE', 'FOLDER', 'SITE'))) { // Checking if the pageId is the current viewed $flag = ($val->page_id == $pageId) ? 1 : 0; @@ -87,7 +90,7 @@ public function front() $tmp = array( 'label' => $label, 'menu' => $val->page_menu, - 'uri' => $treeSrv->getPageLink($val->page_id, false), + 'uri' => ($val->page_menu == "LINK") ? $treeSrv->getPageLink($val->page_id, false) : null, 'idPage' => $val->page_id, 'lastEditDate' => $val->page_edit_date, 'pageStat' => $val->page_status, @@ -260,4 +263,4 @@ public function savePluginConfigToXml($parameters) } -} +} \ No newline at end of file diff --git a/view/layout/layoutFront.phtml b/view/layout/layoutFront.phtml index d5f61c2..52d2305 100644 --- a/view/layout/layoutFront.phtml +++ b/view/layout/layoutFront.phtml @@ -1,2 +1,2 @@ content; ?> - \ No newline at end of file + \ No newline at end of file From cc632165a732970c2e99472dd835b06063c4beca Mon Sep 17 00:00:00 2001 From: jun Date: Mon, 27 Apr 2020 20:21:36 +0800 Subject: [PATCH 04/31] fix drag and drop plugin ko --- .../plugins/dragdropzone-melis-container.phtml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/view/melis-front/plugins/dragdropzone-melis-container.phtml b/view/melis-front/plugins/dragdropzone-melis-container.phtml index b733279..c7c1249 100644 --- a/view/melis-front/plugins/dragdropzone-melis-container.phtml +++ b/view/melis-front/plugins/dragdropzone-melis-container.phtml @@ -14,11 +14,7 @@ data-plugin-id="" data-melis-tag="pluginXmlDbKey; ?>" data-site-module="siteModule; ?>"> -
-
- viewFront; - ?> -
-
+ viewFront; + ?> \ No newline at end of file From 408afc73a39b7810cdecc8bc9ad9b1d0592993df Mon Sep 17 00:00:00 2001 From: jun Date: Tue, 28 Apr 2020 19:36:33 +0800 Subject: [PATCH 05/31] fix wrapper drag and drop --- public/plugins/css/plugin.melisdragdropzone.css | 11 +---------- src/Controller/StyleController.php | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/public/plugins/css/plugin.melisdragdropzone.css b/public/plugins/css/plugin.melisdragdropzone.css index 9333901..ee8ab7c 100644 --- a/public/plugins/css/plugin.melisdragdropzone.css +++ b/public/plugins/css/plugin.melisdragdropzone.css @@ -45,19 +45,10 @@ .melis-dragdropzone .melis-ui-outlined { float: left; - margin: 0 5px 30px; + margin: 0 5px 30px 0; /* margin: 0 5px 30px 0; .container overflow */ } -/* .melis-dragdropzone .melis-ui-outlined:not(.plugin-width-lg-99-40 ), -.melis-dragdropzone .melis-ui-outlined:not(.plugin-width-lg-100-00) { - margin: 0 5px 30px; -} */ - -/* .plugin-width-md-100-00.melis-ui-outlined { - margin: 0 0 30px; -} */ - .wrapper div.melis-dragdropzone:last-of-type { margin-bottom: 35px; } diff --git a/src/Controller/StyleController.php b/src/Controller/StyleController.php index 3da6239..1268985 100644 --- a/src/Controller/StyleController.php +++ b/src/Controller/StyleController.php @@ -24,7 +24,7 @@ public function getPagePluginWidthCssAction() ->addHeaderLine('Pragma' , 'no-cache') ->addHeaderLine('Content-Type' , 'text/css;charset=UTF-8'); - $css = '[class^="plugin-width"] {float: left;margin: 0 5px 30px;}'; + $css = '[class^="plugin-width"] {float: left;margin: 0 5px 30px 0;}'; $pageId = (int) $this->params()->fromQuery('idpage'); $pageSvc = $this->getServiceLocator()->get('MelisEnginePage'); From 302f792c69d633afbbf1169ebe3505c891ed5d56 Mon Sep 17 00:00:00 2001 From: jun Date: Thu, 30 Apr 2020 16:04:20 +0800 Subject: [PATCH 06/31] remove margins on drag and drop plugins --- public/plugins/css/plugin.melisdragdropzone.css | 3 +-- src/Controller/StyleController.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/public/plugins/css/plugin.melisdragdropzone.css b/public/plugins/css/plugin.melisdragdropzone.css index ee8ab7c..f6e6e61 100644 --- a/public/plugins/css/plugin.melisdragdropzone.css +++ b/public/plugins/css/plugin.melisdragdropzone.css @@ -45,8 +45,7 @@ .melis-dragdropzone .melis-ui-outlined { float: left; - margin: 0 5px 30px 0; - /* margin: 0 5px 30px 0; .container overflow */ + margin: 0; } .wrapper div.melis-dragdropzone:last-of-type { diff --git a/src/Controller/StyleController.php b/src/Controller/StyleController.php index 1268985..7cc4298 100644 --- a/src/Controller/StyleController.php +++ b/src/Controller/StyleController.php @@ -24,7 +24,7 @@ public function getPagePluginWidthCssAction() ->addHeaderLine('Pragma' , 'no-cache') ->addHeaderLine('Content-Type' , 'text/css;charset=UTF-8'); - $css = '[class^="plugin-width"] {float: left;margin: 0 5px 30px 0;}'; + $css = '[class^="plugin-width"] {float: left;margin: 0;}'; $pageId = (int) $this->params()->fromQuery('idpage'); $pageSvc = $this->getServiceLocator()->get('MelisEnginePage'); From 6204f8cca3c800c5ffa1ebd455498ffa835b3475 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 May 2020 17:46:06 +0800 Subject: [PATCH 07/31] Added cache on getting site config --- src/Service/MelisSiteConfigService.php | 150 ++++++++++++++----------- 1 file changed, 82 insertions(+), 68 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index e2871c4..bd71bff 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -169,92 +169,106 @@ public function getSiteConfig($siteId, $returnAll = false) $arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args()); // Sending service start event $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_start', $arrayParameters); - $siteId = $arrayParameters['siteId']; - $site = $this->getSiteDataById($siteId); - $siteName = $site['site_name']; - $configFromFile = $this->getConfig($siteName); - $siteConfig = []; - - if (array_key_exists('site', $configFromFile)) { - $dbConfigData = $this->getSiteConfigFromDb($siteId); - // merge config from file and from the db | the one on the db will be prioritized - $siteConfig = ArrayUtils::merge($siteConfig, $configFromFile, true); - /** - * Make sure that we are accessing the correct config - */ - if(isset($siteConfig['site'][$siteName][$siteId])) { - $activeSiteLangs = $this->getSiteActiveLanguages($siteId); - - // add langauges that are active but not on the config file - foreach ($activeSiteLangs as $lang) { - if (!array_key_exists($lang['lang_cms_locale'], $siteConfig['site'][$siteName][$siteId])) { - $siteConfig['site'][$siteName][$siteId][$lang['lang_cms_locale']] = []; + + //try to get config from cache + $cacheKey = 'getSiteConfig_' . $siteId.'_'.$returnAll; + $cacheConfig = 'engine_page_services'; + $melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); + + if(empty($results)) { + + $site = $this->getSiteDataById($siteId); + $siteName = $site['site_name']; + $configFromFile = $this->getConfig($siteName); + $siteConfig = []; + + if (array_key_exists('site', $configFromFile)) { + $dbConfigData = $this->getSiteConfigFromDb($siteId); + // merge config from file and from the db | the one on the db will be prioritized + $siteConfig = ArrayUtils::merge($siteConfig, $configFromFile, true); + /** + * Make sure that we are accessing the correct config + */ + if (isset($siteConfig['site'][$siteName][$siteId])) { + $activeSiteLangs = $this->getSiteActiveLanguages($siteId); + + // add langauges that are active but not on the config file + foreach ($activeSiteLangs as $lang) { + if (!array_key_exists($lang['lang_cms_locale'], $siteConfig['site'][$siteName][$siteId])) { + $siteConfig['site'][$siteName][$siteId][$lang['lang_cms_locale']] = []; + } } - } - // also merge all language config (except the general one) because some variables could be defined in one - // one language but not on the other - if (!empty($siteConfig['site'][$siteName][$siteId])) { - foreach ($siteConfig['site'][$siteName][$siteId] as $langConfigKey => $langConfigVal) { - foreach ($siteConfig['site'][$siteName][$siteId] as $otherLangConfigKey => $otherLangConfigVal) { - if ($langConfigKey !== $otherLangConfigKey) { - foreach ($otherLangConfigVal as $configKey => $configValue) { - if (!array_key_exists($configKey, $siteConfig['site'][$siteName][$siteId][$langConfigKey])) { - if (is_array($configValue)) { - $arr = []; - - foreach ($configValue as $key => $val) { - if (!is_array($val)) { - $arr[$key] = ''; + // also merge all language config (except the general one) because some variables could be defined in one + // one language but not on the other + if (!empty($siteConfig['site'][$siteName][$siteId])) { + foreach ($siteConfig['site'][$siteName][$siteId] as $langConfigKey => $langConfigVal) { + foreach ($siteConfig['site'][$siteName][$siteId] as $otherLangConfigKey => $otherLangConfigVal) { + if ($langConfigKey !== $otherLangConfigKey) { + foreach ($otherLangConfigVal as $configKey => $configValue) { + if (!array_key_exists($configKey, $siteConfig['site'][$siteName][$siteId][$langConfigKey])) { + if (is_array($configValue)) { + $arr = []; + + foreach ($configValue as $key => $val) { + if (!is_array($val)) { + $arr[$key] = ''; + } } - } - $siteConfig['site'][$siteName][$siteId][$langConfigKey] = ArrayUtils::merge($siteConfig['site'][$siteName][$siteId][$langConfigKey], [$configKey => $arr], true); - } else { - $siteConfig['site'][$siteName][$siteId][$langConfigKey] = ArrayUtils::merge($siteConfig['site'][$siteName][$siteId][$langConfigKey], [$configKey => ''], true); + $siteConfig['site'][$siteName][$siteId][$langConfigKey] = ArrayUtils::merge($siteConfig['site'][$siteName][$siteId][$langConfigKey], [$configKey => $arr], true); + } else { + $siteConfig['site'][$siteName][$siteId][$langConfigKey] = ArrayUtils::merge($siteConfig['site'][$siteName][$siteId][$langConfigKey], [$configKey => ''], true); + } } } } } } } - } - if (!empty($dbConfigData)) { - foreach ($dbConfigData as $dbConf) { - if ($dbConf['sconf_lang_id'] === '-1') { - $siteConfig = ArrayUtils::merge( - $siteConfig, - [ - 'site' => [ - $siteName => unserialize($dbConf['sconf_datas']) - ], - ], - true - ); - } else { - $siteConfig = ArrayUtils::merge( - $siteConfig, - [ - 'site' => [ - $siteName => [ - $siteId => unserialize($dbConf['sconf_datas']) + if (!empty($dbConfigData)) { + foreach ($dbConfigData as $dbConf) { + if ($dbConf['sconf_lang_id'] === '-1') { + $siteConfig = ArrayUtils::merge( + $siteConfig, + [ + 'site' => [ + $siteName => unserialize($dbConf['sconf_datas']) ], - ] - ], - true - ); + ], + true + ); + } else { + $siteConfig = ArrayUtils::merge( + $siteConfig, + [ + 'site' => [ + $siteName => [ + $siteId => unserialize($dbConf['sconf_datas']) + ], + ] + ], + true + ); + } } } - } - $arrayParameters['config'] = ($arrayParameters['returnAll']) ? $siteConfig : $siteConfig['site'][$siteName][$siteId]; - }else{ + $arrayParameters['config'] = ($arrayParameters['returnAll']) ? $siteConfig : $siteConfig['site'][$siteName][$siteId]; + } else { + $arrayParameters['config'] = []; + } + } else { $arrayParameters['config'] = []; } - } else { - $arrayParameters['config'] = []; + // Save cache key + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $arrayParameters['config']); + }else{ + //return the config from cache + $arrayParameters['config'] = $results; } $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_end', $arrayParameters); From 02d4be1b04a6b02413610277493c6e6c30127439 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 May 2020 18:05:31 +0800 Subject: [PATCH 08/31] Added cache system --- src/Service/MelisSiteConfigService.php | 128 ++++++++++++++----------- 1 file changed, 71 insertions(+), 57 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index bd71bff..2c9b2d4 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -78,80 +78,94 @@ public function getSiteConfigByKey($key, $pageId, $section = 'sites', $language */ public function getSiteConfigByPageId($pageId, $langLocale = false) { - // Event parameters prepare $arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args()); // Sending service start event $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_by_page_id_start', $arrayParameters); - $siteConfig = array( - 'siteConfig' => array(), - 'allSites' => array(), - ); + //try to get config from cache + $cacheKey = 'getSiteConfigByPageId_' . $siteId.'_'.$langLocale; + $cacheConfig = 'engine_page_services'; + $melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); - if(!empty($pageId)) { - /** - * get the language if the page - */ - $cmsPageLang = $this->getServiceLocator()->get('MelisEngineTablePageLang'); - $pageLang = $cmsPageLang->getEntryByField('plang_page_id', $arrayParameters['pageId'])->current(); - /** - * get page lang locale - */ - $langData = array(); - $langId = null; - if (!empty($pageLang)) { - $langCmsTbl = $this->getServiceLocator()->get('MelisEngineTableCmsLang'); - $langData = $langCmsTbl->getEntryById($pageLang->plang_lang_id)->current(); + if(empty($results)) { + + $siteConfig = array( + 'siteConfig' => array(), + 'allSites' => array(), + ); + + if (!empty($pageId)) { + /** + * get the language if the page + */ + $cmsPageLang = $this->getServiceLocator()->get('MelisEngineTablePageLang'); + $pageLang = $cmsPageLang->getEntryByField('plang_page_id', $arrayParameters['pageId'])->current(); + /** + * get page lang locale + */ + $langData = array(); + $langId = null; + if (!empty($pageLang)) { + $langCmsTbl = $this->getServiceLocator()->get('MelisEngineTableCmsLang'); + $langData = $langCmsTbl->getEntryById($pageLang->plang_lang_id)->current(); + + } + /** + * get the site config + */ + if (!empty($langData)) { + $siteData = $this->getSiteDataByPageId($arrayParameters['pageId']); + if (!empty($siteData)) { + $siteId = $siteData->site_id; + $siteName = $siteData->site_name; - } - /** - * get the site config - */ - if(!empty($langData)){ - $siteData = $this->getSiteDataByPageId($arrayParameters['pageId']); - if(!empty($siteData)){ - $siteId = $siteData->site_id; - $siteName = $siteData->site_name; - - /** - * First, let's try fetch the site config - * using the config service that has been updated - * through a listener - */ - $config = $this->serviceLocator->get('config'); - - if(!empty($config['site'])){ /** - * If site config not in the list, - * let's try again to get it directly from the - * db and file + * First, let's try fetch the site config + * using the config service that has been updated + * through a listener */ - if(empty($config['site'][$siteName][$siteId])) { - $config = $this->getSiteConfig($siteId, true); - } + $config = $this->serviceLocator->get('config'); + + if (!empty($config['site'])) { + /** + * If site config not in the list, + * let's try again to get it directly from the + * db and file + */ + if (empty($config['site'][$siteName][$siteId])) { + $config = $this->getSiteConfig($siteId, true); + } - if(!empty($config['site'][$siteName][$siteId])) { + if (!empty($config['site'][$siteName][$siteId])) { - if ($arrayParameters['langLocale']) { - $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$arrayParameters['langLocale']]; - $siteLangData = $langCmsTbl->getEntryByField('lang_cms_locale', $arrayParameters['langLocale'])->current(); - if(!empty($siteLangData)){ - $langId = $siteLangData->lang_cms_id; + if ($arrayParameters['langLocale']) { + $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$arrayParameters['langLocale']]; + $siteLangData = $langCmsTbl->getEntryByField('lang_cms_locale', $arrayParameters['langLocale'])->current(); + if (!empty($siteLangData)) { + $langId = $siteLangData->lang_cms_id; + } + } else { + $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$langData->lang_cms_locale]; + $langId = $langData->lang_cms_id; } - } else { - $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$langData->lang_cms_locale]; - $langId = $langData->lang_cms_id; + $siteConfig['siteConfig']['site_id'] = $siteId; + $siteConfig['siteConfig']['default_lang_id'] = $langId; + $siteConfig['allSites'] = $config['site'][$siteName]['allSites']; } - $siteConfig['siteConfig']['site_id'] = $siteId; - $siteConfig['siteConfig']['default_lang_id'] = $langId; - $siteConfig['allSites'] = $config['site'][$siteName]['allSites']; } } } } + $arrayParameters['result'] = $siteConfig; + // Save cache key + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $arrayParameters['result']); + }else{ + //return the config from cache + $arrayParameters['result'] = $results; } - $arrayParameters['result'] = $siteConfig; + $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_by_page_id_end', $arrayParameters); return $arrayParameters['result']; @@ -170,7 +184,7 @@ public function getSiteConfig($siteId, $returnAll = false) // Sending service start event $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_start', $arrayParameters); $siteId = $arrayParameters['siteId']; - + //try to get config from cache $cacheKey = 'getSiteConfig_' . $siteId.'_'.$returnAll; $cacheConfig = 'engine_page_services'; From 55582b407ffa06432a7e64ae84ff01ec56c330fd Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Thu, 7 May 2020 18:21:12 +0800 Subject: [PATCH 09/31] Result data --- src/Navigation/MelisFrontNavigation.php | 198 ++++++++++++------------ 1 file changed, 96 insertions(+), 102 deletions(-) diff --git a/src/Navigation/MelisFrontNavigation.php b/src/Navigation/MelisFrontNavigation.php index 922c49d..b49675f 100644 --- a/src/Navigation/MelisFrontNavigation.php +++ b/src/Navigation/MelisFrontNavigation.php @@ -51,28 +51,28 @@ public function getServiceLocator() public function getPageAndSubPages($pageId) { - $melisPage = $this->serviceLocator->get('MelisEnginePage'); - $pageTree = $melisPage->getDatasPage($pageId); - - $pages = array(); - - if (!is_null($pageTree)) - { - $page = $this->formatPageInArray((Array)$pageTree->getMelisPageTree()); - - $children = $this->getChildrenRecursive($pageId); - if (!empty($children)) - { - $page['pages'] = $children; - } - - if ($page) - { - $pages[] = $page; - } - } - - return $pages; + $melisPage = $this->serviceLocator->get('MelisEnginePage'); + $pageTree = $melisPage->getDatasPage($pageId); + + $pages = array(); + + if (!is_null($pageTree)) + { + $page = $this->formatPageInArray((Array)$pageTree->getMelisPageTree()); + + $children = $this->getChildrenRecursive($pageId); + if (!empty($children)) + { + $page['pages'] = $children; + } + + if ($page) + { + $pages[] = $page; + } + } + + return $pages; } /** @@ -91,11 +91,8 @@ public function getChildrenRecursive($idPage) if ($pages) { - $rpages = $pages->toArray(); - - foreach ($rpages as $page) + foreach ($pages as $page) { - $tmp = $this->formatPageInArray($page); $children = $this->getChildrenRecursive($page['tree_page_id']); @@ -114,44 +111,44 @@ public function formatPageInArray($page,$pageSearchType = null) $melisTree = $this->serviceLocator->get('MelisEngineTree'); if (empty($page) || empty($page['tree_page_id'])) - return null; + return null; if (empty($page['purl_page_url'])) - $uri = $melisTree->getPageLink($page['tree_page_id'], 0); + $uri = $melisTree->getPageLink($page['tree_page_id'], 0); else - $uri = $page['purl_page_url']; + $uri = $page['purl_page_url']; - if (empty($page['page_edit_date'])) - $page['page_edit_date'] = date('Y-m-d H:i:s'); + if (empty($page['page_edit_date'])) + $page['page_edit_date'] = date('Y-m-d H:i:s'); - $pageName = $page['page_name']; - - $tmp = array( - 'label' => $pageName, - 'menu' => $page['page_menu'], - 'uri' => $uri, - 'idPage' => $page['tree_page_id'], - 'lastEditDate' => $page['page_edit_date'], - 'pageStat' => $page['page_status'], - 'pageType' => $page['page_type'], - 'pageSearchType' => $pageSearchType, - ); - - if ($this->idpage == $page['tree_page_id']) - $tmp['active'] = true; - - return $tmp; + $pageName = $page['page_name']; + + $tmp = array( + 'label' => $pageName, + 'menu' => $page['page_menu'], + 'uri' => $uri, + 'idPage' => $page['tree_page_id'], + 'lastEditDate' => $page['page_edit_date'], + 'pageStat' => $page['page_status'], + 'pageType' => $page['page_type'], + 'pageSearchType' => $pageSearchType, + ); + + if ($this->idpage == $page['tree_page_id']) + $tmp['active'] = true; + + return $tmp; } public function getSiteMainPageByPageId($idPage) { - $melisTree = $this->serviceLocator->get('MelisEngineTree'); - $datasSite = $melisTree->getSiteByPageId($idPage); - - if (!empty($datasSite)) - return $datasSite->site_main_page_id; - - return null; + $melisTree = $this->serviceLocator->get('MelisEngineTree'); + $datasSite = $melisTree->getSiteByPageId($idPage); + + if (!empty($datasSite)) + return $datasSite->site_main_page_id; + + return null; } /** @@ -202,55 +199,52 @@ protected function getPages(ContainerInterface $container) return $this->pages; } - /** - * Get all Subpages including published and unplublished - * @param $pageId - * @return array - */ - public function getAllSubpages($pageId) - { - $results = array(); - //Services - $melisTree = $this->serviceLocator->get('MelisEngineTree'); - $pagePub = $this->getServiceLocator()->get('MelisEngineTablePagePublished'); - $pageSave = $this->getServiceLocator()->get('MelisEngineTablePageSaved'); + /** + * Get all Subpages including published and unplublished + * @param $pageId + * @return array + */ + public function getAllSubpages($pageId) + { + $results = array(); + //Services + $melisTree = $this->serviceLocator->get('MelisEngineTree'); + $pagePub = $this->getServiceLocator()->get('MelisEngineTablePagePublished'); + $pageSave = $this->getServiceLocator()->get('MelisEngineTablePageSaved'); - $pageSearchType = null; - $pages = $melisTree->getPageChildren($pageId,2); - - - if($pages) - { - $rpages = $pages->toArray(); - - foreach ($rpages as $page) - { - $pageStat = $page['page_status'] ?? null; - //if the page is published - if($pageStat){ - $pageData = $pagePub->getEntryById($page['tree_page_id'])->current(); - $pageSearchType = $pageData->page_search_type ?? null; - } - //if the page is unpublished - else{ - $pageData = $pageSave->getEntryById($page['tree_page_id'])->current(); - //if the unpublishedData is not present in page_saved table - if(!$pageData){ - //Get the pageData in page_published table - $pageData = $pagePub->getEntryById($page['tree_page_id'])->current(); - } - $pageSearchType = $pageData->page_search_type ?? null; - } + $pageSearchType = null; + $pages = $melisTree->getPageChildren($pageId,2); + + if($pages) + { + foreach ($pages as $page) + { + $pageStat = $page['page_status'] ?? null; + //if the page is published + if($pageStat){ + $pageData = $pagePub->getEntryById($page['tree_page_id'])->current(); + $pageSearchType = $pageData->page_search_type ?? null; + } + //if the page is unpublished + else{ + $pageData = $pageSave->getEntryById($page['tree_page_id'])->current(); + //if the unpublishedData is not present in page_saved table + if(!$pageData){ + //Get the pageData in page_published table + $pageData = $pagePub->getEntryById($page['tree_page_id'])->current(); + } + $pageSearchType = $pageData->page_search_type ?? null; + } - $tmp = $this->formatPageInArray($page,$pageSearchType); - $children = $this->getAllSubpages($page['tree_page_id'] ?? null); + $tmp = $this->formatPageInArray($page,$pageSearchType); + $children = $this->getAllSubpages($page['tree_page_id'] ?? null); - if (!empty($children)) - $tmp['pages'] = $children; + if (!empty($children)) + $tmp['pages'] = $children; - $results[] = $tmp; - } - } - return $results; - } + $results[] = $tmp; + } + } + return $results; + } } \ No newline at end of file From b098539111d90ed853d05c0103c2c858833d1d8a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 May 2020 19:39:18 +0800 Subject: [PATCH 10/31] Changed variable on cache --- src/Service/MelisSiteConfigService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index 2c9b2d4..86b8b50 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -84,7 +84,7 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) $arrayParameters = $this->sendEvent('meliscms_site_tool_get_site_config_by_page_id_start', $arrayParameters); //try to get config from cache - $cacheKey = 'getSiteConfigByPageId_' . $siteId.'_'.$langLocale; + $cacheKey = 'getSiteConfigByPageId_' . $pageId.'_'.$langLocale; $cacheConfig = 'engine_page_services'; $melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem'); $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); From 318aae3d0bab8665390942d8d634a3cf80e2bbf1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 May 2020 21:41:57 +0800 Subject: [PATCH 11/31] Update caching services --- src/Service/MelisSiteConfigService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index 86b8b50..a9c9cc9 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -85,7 +85,7 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) //try to get config from cache $cacheKey = 'getSiteConfigByPageId_' . $pageId.'_'.$langLocale; - $cacheConfig = 'engine_page_services'; + $cacheConfig = 'meliscms_page'; $melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem'); $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); @@ -187,7 +187,7 @@ public function getSiteConfig($siteId, $returnAll = false) //try to get config from cache $cacheKey = 'getSiteConfig_' . $siteId.'_'.$returnAll; - $cacheConfig = 'engine_page_services'; + $cacheConfig = 'meliscms_page'; $melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem'); $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); From 298f5e413da2da617d82ae36e2ace15add36543c Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Thu, 7 May 2020 23:55:47 +0800 Subject: [PATCH 12/31] Tempalte service --- src/Controller/Plugin/MelisFrontGdprBannerPlugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controller/Plugin/MelisFrontGdprBannerPlugin.php b/src/Controller/Plugin/MelisFrontGdprBannerPlugin.php index 7576122..776d085 100644 --- a/src/Controller/Plugin/MelisFrontGdprBannerPlugin.php +++ b/src/Controller/Plugin/MelisFrontGdprBannerPlugin.php @@ -80,9 +80,9 @@ public function front() $langId = empty($pageData->lang_cms_id) ? $langId : $pageData->lang_cms_id; $locale = empty($pageData->lang_cms_locale) ? $locale : $pageData->lang_cms_locale; if (!empty($pageData->page_tpl_id)) { - /** @var \MelisEngine\Model\Tables\MelisTemplateTable $tplTable */ - $tplTable = $this->getServiceLocator()->get('MelisEngineTableTemplate'); - $tplData = $tplTable->getEntryById($pageData->page_tpl_id)->toArray(); + /** @var \MelisEngine\Service\MelisEngineTemplateService $tplSrv */ + $tplSrv = $this->getServiceLocator()->get('MelisEngineTemplateService'); + $tplData = $tplSrv->getTemplate($pageData->page_tpl_id)->toArray(); if (!empty($tplData [0]['tpl_site_id'])) { $siteId = $tplData [0]['tpl_site_id']; } From ab2912afd5cd0b2d6604ff56ce18c9c68efb0a2b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 00:16:25 +0800 Subject: [PATCH 13/31] Update listener to use service --- .../MelisFrontHomePageIdOverrideListener.php | 64 +++++++++---------- .../MelisFrontHomePageRoutingListener.php | 16 ++--- src/Listener/MelisFrontSiteConfigListener.php | 43 ++++++------- 3 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/Listener/MelisFrontHomePageIdOverrideListener.php b/src/Listener/MelisFrontHomePageIdOverrideListener.php index 4e10308..a0623d2 100644 --- a/src/Listener/MelisFrontHomePageIdOverrideListener.php +++ b/src/Listener/MelisFrontHomePageIdOverrideListener.php @@ -53,48 +53,46 @@ function(MvcEvent $e){ */ if(empty($uri)) { /** - * Get domain data + * get domain */ $domain = $_SERVER['SERVER_NAME']; - $melisTableDomain = $sm->get('MelisEngineTableSiteDomain'); - $datasDomain = $melisTableDomain->getEntryByField('sdom_domain', $domain)->current(); - $siteId = $datasDomain->sdom_site_id; /** - * Get site data + * get site data */ - $siteTable = $sm->get('MelisEngineTableSite'); - $siteData = $siteTable->getEntryById($siteId)->current(); - - /** - * We override only the page id - * if the site lang option is set to - * default (1), because there is already - * a separate listener that handled - * the home page routes if the site lang option - * is set to 2. - * - * This Listener: MelisFrontHomePageRoutingListener - */ - if($siteData->site_opt_lang_url == 1) { - $pageId = !empty($siteData->site_main_page_id) ? $siteData->site_main_page_id : null; + $siteService = $sm->get('MelisEngineSiteService'); + $siteData = $siteService->getSiteDataByDomain($domain); + if(!empty($siteData)) { + /** + * We override only the page id + * if the site lang option is set to + * default (1), because there is already + * a separate listener that handled + * the home page routes if the site lang option + * is set to 2. + * + * This Listener: MelisFrontHomePageRoutingListener + */ + if ($siteData->site_opt_lang_url == 1) { + $pageId = !empty($siteData->site_main_page_id) ? $siteData->site_main_page_id : null; // $routeMatch->setParam('idpage', $pageId); - $router = $e->getRouter(); - $request = $e->getRequest(); - $routeM = $router->match($request); - //get the default params of the route - $params = $routeM->getParams(); + $router = $e->getRouter(); + $request = $e->getRequest(); + $routeM = $router->match($request); + //get the default params of the route + $params = $routeM->getParams(); - //override the page id - $params['idpage'] = !empty($pageId) ? $pageId : $params['idpage']; + //override the page id + $params['idpage'] = !empty($pageId) ? $pageId : $params['idpage']; - $route = Segment::factory(array( - 'route' => '/', - 'defaults' => $params, - )); + $route = Segment::factory(array( + 'route' => '/', + 'defaults' => $params, + )); - // add the route to the router - $router->addRoute($routeM->getMatchedRouteName(), $route); + // add the route to the router + $router->addRoute($routeM->getMatchedRouteName(), $route); + } } } } diff --git a/src/Listener/MelisFrontHomePageRoutingListener.php b/src/Listener/MelisFrontHomePageRoutingListener.php index 5f5d46c..8461e82 100644 --- a/src/Listener/MelisFrontHomePageRoutingListener.php +++ b/src/Listener/MelisFrontHomePageRoutingListener.php @@ -49,8 +49,8 @@ function(MvcEvent $e){ $uri = str_replace($getString, '', $uri); $domain = $_SERVER['SERVER_NAME']; - $melisTableDomain = $sm->get('MelisEngineTableSiteDomain'); - $datasDomain = $melisTableDomain->getEntryByField('sdom_domain', $domain)->current(); + $domainSrv = $sm->get('MelisEngineSiteDomainService'); + $datasDomain = $domainSrv->getDomainByDomainName($domain); if (empty($datasDomain) || empty($uri)) { @@ -68,15 +68,15 @@ function(MvcEvent $e){ */ $siteLangLocale = $uriArr[0] . '_' . strtoupper($uriArr[0]); - $langCmsTbl = $sm->get('MelisEngineTableCmsLang'); - $langData = $langCmsTbl->getEntryByField('lang_cms_locale', $siteLangLocale)->current(); + $langSrv = $sm->get('MelisEngineLang'); + $langData = $langSrv->getLangDataByLangLocale($siteLangLocale); /** * Make sure that lang locale is exist */ + $siteService = $sm->get('MelisEngineSiteService'); if(!empty($langData)) { $langId = $langData->lang_cms_id; - $siteHomeTable = $sm->get('MelisEngineTableCmsSiteHome'); - $siteHomeData = $siteHomeTable->getHomePageBySiteIdAndLangId($siteId, $langId)->current(); + $siteHomeData = $siteService->getHomePageBySiteIdAndLangId($siteId, $langId)->current(); /** * Check if site home page id exit from site home table, * else we used the default main page id @@ -85,9 +85,7 @@ function(MvcEvent $e){ if(!empty($siteHomeData)) { $pageId = $siteHomeData->shome_page_id; }else{ - $siteTbl = $sm->get('MelisEngineTableSite'); - $siteDatas = $siteTbl->getEntryById($siteId)->current(); - $pageId = $siteDatas->site_main_page_id; + $pageId = $siteService->getSiteMainHomePageIdBySiteId($siteId); } /** * Check if page is empty diff --git a/src/Listener/MelisFrontSiteConfigListener.php b/src/Listener/MelisFrontSiteConfigListener.php index ec42ac1..e16f8f1 100644 --- a/src/Listener/MelisFrontSiteConfigListener.php +++ b/src/Listener/MelisFrontSiteConfigListener.php @@ -43,34 +43,29 @@ public function onLoadModulesPost(ModuleEvent $e) $config = $configListener->getMergedConfig(false); /** - * get the site id via domain + * get domain */ $domain = $_SERVER['SERVER_NAME']; - $melisTableDomain = $serviceManager->get('MelisEngineTableSiteDomain'); - $datasDomain = $melisTableDomain->getEntryByField('sdom_domain', $domain)->current(); - if(!empty($datasDomain)){ - $siteId = $datasDomain->sdom_site_id; + /** + * get site data + */ + $siteService = $serviceManager->get('MelisEngineSiteService'); + $siteData = $siteService->getSiteDataByDomain($domain); + if(!empty($siteData)) { + /** + * get the site config + */ + $siteConfig = $serviceManager->get('MelisSiteConfigService'); + $siteConfig = $siteConfig->getSiteConfig($siteId, true); + $config = ArrayUtils::merge($config, $siteConfig, true); /** - * get site name + * remove other site data from the config */ - $siteTable = $serviceManager->get('MelisEngineTableSite'); - $siteData = $siteTable->getEntryById($siteId)->current(); - if(!empty($siteData)) { - /** - * get the site config - */ - $siteConfig = $serviceManager->get('MelisSiteConfigService'); - $siteConfig = $siteConfig->getSiteConfig($siteId, true); - $config = ArrayUtils::merge($config, $siteConfig, true); - /** - * remove other site data from the config - */ - if (!empty($config['site'][$siteData->site_name])) { - foreach ($config['site'][$siteData->site_name] as $id => $site) { - if ($id != $siteId && $id != 'allSites') { - if (is_int($id)) - unset($config['site'][$siteData->site_name][$id]); - } + if (!empty($config['site'][$siteData->site_name])) { + foreach ($config['site'][$siteData->site_name] as $id => $site) { + if ($id != $siteId && $id != 'allSites') { + if (is_int($id)) + unset($config['site'][$siteData->site_name][$id]); } } } From bcc69b390b7038a8c60b68c8f762ef860d2c1719 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 10:59:54 +0800 Subject: [PATCH 14/31] Added site id --- src/Listener/MelisFrontSiteConfigListener.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Listener/MelisFrontSiteConfigListener.php b/src/Listener/MelisFrontSiteConfigListener.php index e16f8f1..cd07153 100644 --- a/src/Listener/MelisFrontSiteConfigListener.php +++ b/src/Listener/MelisFrontSiteConfigListener.php @@ -52,6 +52,7 @@ public function onLoadModulesPost(ModuleEvent $e) $siteService = $serviceManager->get('MelisEngineSiteService'); $siteData = $siteService->getSiteDataByDomain($domain); if(!empty($siteData)) { + $siteId = $siteData->site_id; /** * get the site config */ From 76f0e4c5388908ddb5c828c17084ab86c79eb957 Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 11:27:38 +0800 Subject: [PATCH 15/31] Direct cal db changed to service --- src/Listener/MelisFrontHomePageIdOverrideListener.php | 4 ++-- src/Listener/MelisFrontSiteConfigListener.php | 4 ++-- src/Service/MelisSiteTranslationService.php | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Listener/MelisFrontHomePageIdOverrideListener.php b/src/Listener/MelisFrontHomePageIdOverrideListener.php index 4e10308..93cb497 100644 --- a/src/Listener/MelisFrontHomePageIdOverrideListener.php +++ b/src/Listener/MelisFrontHomePageIdOverrideListener.php @@ -62,8 +62,8 @@ function(MvcEvent $e){ /** * Get site data */ - $siteTable = $sm->get('MelisEngineTableSite'); - $siteData = $siteTable->getEntryById($siteId)->current(); + $siteSrv = $sm->get('MelisEngineSiteService'); + $siteData = $siteSrv->getSiteById($siteId)->current(); /** * We override only the page id diff --git a/src/Listener/MelisFrontSiteConfigListener.php b/src/Listener/MelisFrontSiteConfigListener.php index ec42ac1..6e90c35 100644 --- a/src/Listener/MelisFrontSiteConfigListener.php +++ b/src/Listener/MelisFrontSiteConfigListener.php @@ -53,8 +53,8 @@ public function onLoadModulesPost(ModuleEvent $e) /** * get site name */ - $siteTable = $serviceManager->get('MelisEngineTableSite'); - $siteData = $siteTable->getEntryById($siteId)->current(); + $siteSrv = $serviceManager->get('MelisEngineSiteService'); + $siteData = $siteSrv->getSiteById($siteId)->current(); if(!empty($siteData)) { /** * get the site config diff --git a/src/Service/MelisSiteTranslationService.php b/src/Service/MelisSiteTranslationService.php index be350c7..7e0d299 100644 --- a/src/Service/MelisSiteTranslationService.php +++ b/src/Service/MelisSiteTranslationService.php @@ -400,8 +400,10 @@ public function getSiteTranslationFromFile($translationKey = null, $langId = nul $moduleFolders = array(); if (!empty($arrayParameters['siteId'])) { - $siteTbl = $this->getServiceLocator()->get('MelisEngineTableSite'); - $siteData = $siteTbl->getEntryById($arrayParameters['siteId'])->current(); + + $siteSrv = $this->getServiceLocator()->get('MelisEngineSiteService'); + $siteData = $siteSrv->getSiteById($arrayParameters['siteId'])->current(); + if (!empty($siteData)) { $siteName = $siteData->site_name; From b56480c2482ad8e920e4842c0affd9d2a1d6b725 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 12:30:42 +0800 Subject: [PATCH 16/31] Update to get the cache if lang data instead of new query --- src/Service/MelisSiteTranslationService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteTranslationService.php b/src/Service/MelisSiteTranslationService.php index 7e0d299..2be365f 100644 --- a/src/Service/MelisSiteTranslationService.php +++ b/src/Service/MelisSiteTranslationService.php @@ -436,6 +436,7 @@ public function getSiteTranslationFromFile($translationKey = null, $langId = nul $tmpTrans = array(); $langTable = $this->getServiceLocator()->get('MelisEngineTableCmsLang'); + $langService = $this->getServiceLocator()->get('MelisEngineLang'); /** * if langId is null or empty, get all the languages */ @@ -446,7 +447,7 @@ public function getSiteTranslationFromFile($translationKey = null, $langId = nul $siteLangs = $sitelangsTable->getSiteLanguagesBySiteId($arrayParameters['siteId'])->toArray(); $langList = []; foreach ($siteLangs as $key => $data) { - $cmsLang = $langTable->getEntryById($data['slang_lang_id'])->toArray(); + $cmsLang = $langService->getLangDataById($data['slang_lang_id']); foreach ($cmsLang as $k => $lang) { array_push($langList, $lang); } @@ -455,7 +456,7 @@ public function getSiteTranslationFromFile($translationKey = null, $langId = nul $langList = $langTable->fetchAll()->toArray(); } } else { - $langList = $langTable->getEntryById($arrayParameters['langId'])->toArray(); + $langList = $langService->getLangDataById($arrayParameters['langId']); } //get the language info From 7964ec48ae0d8d6156c6a2979e96a703d4ff1557 Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 12:38:04 +0800 Subject: [PATCH 17/31] Table direct call updated to service --- ...ontSEODispatchRouterRegularUrlListener.php | 364 +++++++++--------- src/Service/MelisFrontHeadService.php | 170 ++++---- 2 files changed, 267 insertions(+), 267 deletions(-) diff --git a/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php b/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php index 0a11515..db4a62c 100644 --- a/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php +++ b/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php @@ -31,175 +31,175 @@ class MelisFrontSEODispatchRouterRegularUrlListener public function attach(EventManagerInterface $events) { $callBackHandler = $events->attach( - MvcEvent::EVENT_DISPATCH, - function(MvcEvent $e){ + MvcEvent::EVENT_DISPATCH, + function(MvcEvent $e){ - $sm = $e->getApplication()->getServiceManager(); - $eventManager = $e->getApplication()->getEventManager(); - - $routeMatch = $e->getRouteMatch(); - $matchedRouteName_full = $routeMatch->getMatchedRouteName(); - - $routeNameParts = explode('/', $matchedRouteName_full); - if (!empty($routeNameParts)) - $matchedRouteName = $routeNameParts[0]; - + $sm = $e->getApplication()->getServiceManager(); + $eventManager = $e->getApplication()->getEventManager(); + + $routeMatch = $e->getRouteMatch(); + $matchedRouteName_full = $routeMatch->getMatchedRouteName(); + + $routeNameParts = explode('/', $matchedRouteName_full); + if (!empty($routeNameParts)) + $matchedRouteName = $routeNameParts[0]; + $idpage = null; $params = $routeMatch->getParams(); // If no id of page, then we're not in a melis page if (!empty($params['idpage'])) { - $idpage = $params['idpage']; - $renderType = $routeMatch->getParam('renderType'); - $renderMode = $routeMatch->getParam('renderMode'); - - // Creating the result array that will also be sent as a paramater when event is triggered - $routingResult = $routeMatch->getParams(); - $routingResult['301'] = null; - $routingResult['301_type'] = ''; - $routingResult['404'] = null; - $routingResult['front_route'] = $matchedRouteName_full; + $idpage = $params['idpage']; + $renderType = $routeMatch->getParam('renderType'); + $renderMode = $routeMatch->getParam('renderMode'); + + // Creating the result array that will also be sent as a paramater when event is triggered + $routingResult = $routeMatch->getParams(); + $routingResult['301'] = null; + $routingResult['301_type'] = ''; + $routingResult['404'] = null; + $routingResult['front_route'] = $matchedRouteName_full; - // Getting the datas of the page depending on front or BO - if ($renderMode == 'melis') - $getmode = 'saved'; - else - $getmode = 'published'; - - // Get page datas - $melisPage = $sm->get('MelisEnginePage'); - $datasPage = $melisPage->getDatasPage($idpage, $getmode); - $datasTemplate = $datasPage->getMelisTemplate(); - $pageTree = $datasPage->getMelisPageTree(); - - // Save the datas of the page in the results object so other listeners can - // have access without making a query when updating the results - $routingResult['datasPage'] = $datasPage; + // Getting the datas of the page depending on front or BO + if ($renderMode == 'melis') + $getmode = 'saved'; + else + $getmode = 'published'; + + // Get page datas + $melisPage = $sm->get('MelisEnginePage'); + $datasPage = $melisPage->getDatasPage($idpage, $getmode); + $datasTemplate = $datasPage->getMelisTemplate(); + $pageTree = $datasPage->getMelisPageTree(); + + // Save the datas of the page in the results object so other listeners can + // have access without making a query when updating the results + $routingResult['datasPage'] = $datasPage; - // Check if page exist and page published - if (empty($pageTree) || ($pageTree->page_status == 0 && $renderMode == 'front')) - { - if (isset($pageTree->page_status) && $pageTree->page_status == 0 && - $renderMode == 'front') - { - // The page is inactive, let's try SEO redirection - $routingResult['301'] = $this->redirectPageSEO301($e, $idpage); - if ($routingResult['301'] != null) - $routingResult['301_type'] = 'seo301'; - } + // Check if page exist and page published + if (empty($pageTree) || ($pageTree->page_status == 0 && $renderMode == 'front')) + { + if (isset($pageTree->page_status) && $pageTree->page_status == 0 && + $renderMode == 'front') + { + // The page is inactive, let's try SEO redirection + $routingResult['301'] = $this->redirectPageSEO301($e, $idpage); + if ($routingResult['301'] != null) + $routingResult['301_type'] = 'seo301'; + } - // If no SEO has been found, then this will end up as 404 - if ($routingResult['301'] == null) - $routingResult['404'] = $this->redirect404($e, $idpage); - } - else - if ($renderMode == 'front') - { - $type = $datasPage->getType(); - $status = $pageTree->page_status; - if (($type == 'published' && $status == 0) || $type == 'saved') - $routingResult['404'] = $this->redirect404($e, $idpage); - } + // If no SEO has been found, then this will end up as 404 + if ($routingResult['301'] == null) + $routingResult['404'] = $this->redirect404($e, $idpage); + } + else + if ($renderMode == 'front') + { + $type = $datasPage->getType(); + $status = $pageTree->page_status; + if (($type == 'published' && $status == 0) || $type == 'saved') + $routingResult['404'] = $this->redirect404($e, $idpage); + } - // If displayed in front, check URLs, Redirect 301 if URL not good - if ($renderMode != 'melis' && $routingResult['301'] == null && $routingResult['404'] == null) - { - // Try SEO Url first - $routingResult['301'] = $this->redirectPageSEORedirect($e, $idpage); - if ($routingResult['301'] != null) - $routingResult['301_type'] = 'seoURL'; - - // No SEO, then try regular Page Url - if ($routingResult['301'] == null && - (empty($routingResult['norewrite']) || !$routingResult['norewrite'])) - { - $routingResult['301'] = $this->redirectPageMelisURL($e, $idpage); - if ($routingResult['301'] != null) - $routingResult['301_type'] = 'seoMelisURL'; - } - } - - // Setting all router datas - if ($routingResult['301'] == null && $routingResult['404'] == null) - { - if (!empty($datasPage->getMelisPageTree())) - { - $routingResult['pageLangId'] = $datasPage->getMelisPageTree()->plang_lang_id; - $routingResult['pageLangLocale'] = $datasPage->getMelisPageTree()->lang_cms_locale; - - $container = new Container('melisplugins'); - $container['melis-plugins-lang-id'] = $datasPage->getMelisPageTree()->plang_lang_id; - $container['melis-plugins-lang-locale'] = $datasPage->getMelisPageTree()->lang_cms_locale; + // If displayed in front, check URLs, Redirect 301 if URL not good + if ($renderMode != 'melis' && $routingResult['301'] == null && $routingResult['404'] == null) + { + // Try SEO Url first + $routingResult['301'] = $this->redirectPageSEORedirect($e, $idpage); + if ($routingResult['301'] != null) + $routingResult['301_type'] = 'seoURL'; + + // No SEO, then try regular Page Url + if ($routingResult['301'] == null && + (empty($routingResult['norewrite']) || !$routingResult['norewrite'])) + { + $routingResult['301'] = $this->redirectPageMelisURL($e, $idpage); + if ($routingResult['301'] != null) + $routingResult['301_type'] = 'seoMelisURL'; + } + } + + // Setting all router datas + if ($routingResult['301'] == null && $routingResult['404'] == null) + { + if (!empty($datasPage->getMelisPageTree())) + { + $routingResult['pageLangId'] = $datasPage->getMelisPageTree()->plang_lang_id; + $routingResult['pageLangLocale'] = $datasPage->getMelisPageTree()->lang_cms_locale; + + $container = new Container('melisplugins'); + $container['melis-plugins-lang-id'] = $datasPage->getMelisPageTree()->plang_lang_id; + $container['melis-plugins-lang-locale'] = $datasPage->getMelisPageTree()->lang_cms_locale; - if (!empty($datasTemplate)) { - if ($datasTemplate->tpl_type == 'ZF2' || $datasTemplate->tpl_type == 'TWG') { - $routingResult['module'] = $datasTemplate->tpl_zf2_website_folder; - $routingResult['controller'] = $datasTemplate->tpl_zf2_website_folder . '\Controller\\' . $datasTemplate->tpl_zf2_controller; - $routingResult['action'] = $datasTemplate->tpl_zf2_action; - } else { - if ($datasTemplate->tpl_type == 'PHP') { - $routingResult['action'] = 'phprenderer'; - $routingResult['renderType'] = 'melis_php'; - } - } - } - } - }else{ - if (!empty($datasPage->getMelisPageTree())) { - $container = new Container('melisplugins'); - $container['melis-plugins-lang-id'] = $datasPage->getMelisPageTree()->plang_lang_id; - $container['melis-plugins-lang-locale'] = $datasPage->getMelisPageTree()->lang_cms_locale; - } - } - - /** + if (!empty($datasTemplate)) { + if ($datasTemplate->tpl_type == 'ZF2' || $datasTemplate->tpl_type == 'TWG') { + $routingResult['module'] = $datasTemplate->tpl_zf2_website_folder; + $routingResult['controller'] = $datasTemplate->tpl_zf2_website_folder . '\Controller\\' . $datasTemplate->tpl_zf2_controller; + $routingResult['action'] = $datasTemplate->tpl_zf2_action; + } else { + if ($datasTemplate->tpl_type == 'PHP') { + $routingResult['action'] = 'phprenderer'; + $routingResult['renderType'] = 'melis_php'; + } + } + } + } + }else{ + if (!empty($datasPage->getMelisPageTree())) { + $container = new Container('melisplugins'); + $container['melis-plugins-lang-id'] = $datasPage->getMelisPageTree()->plang_lang_id; + $container['melis-plugins-lang-locale'] = $datasPage->getMelisPageTree()->lang_cms_locale; + } + } + + /** * SENDING EVENT BEFORE MAKING REDIRECTIONS * OTHER PLUGINS SHOULD ATTACH THIS EVENT */ - $routingResult = $eventManager->prepareArgs($routingResult); - $eventManager->trigger('melisfront_site_dispatch_ready', $this, $routingResult); - - // Changing the router with what we have in the routing array generated - if ($routingResult['301'] != null || $routingResult['404'] != null) - { - // Code fo redirection - if ($routingResult['301'] != null) - $statusCode = 301; - if ($routingResult['404'] != null) - $statusCode = 404; - - // Exceptional case, 404 completely undefined, even the cross site default one in DB - if ($routingResult['404'] === '') - die('404'); - - // Redirection - $response = $e->getResponse (); - $response->setHeaders($response->getHeaders ()->addHeaderLine('Location', $routingResult[''.$statusCode])); - $response->setStatusCode($statusCode); - $response->sendHeaders(); - exit (); - } - else - { - // We're all good to display a page! - unset($routingResult['301']); - unset($routingResult['404']); - $datasPage = $routingResult['datasPage']; + $routingResult = $eventManager->prepareArgs($routingResult); + $eventManager->trigger('melisfront_site_dispatch_ready', $this, $routingResult); + + // Changing the router with what we have in the routing array generated + if ($routingResult['301'] != null || $routingResult['404'] != null) + { + // Code fo redirection + if ($routingResult['301'] != null) + $statusCode = 301; + if ($routingResult['404'] != null) + $statusCode = 404; + + // Exceptional case, 404 completely undefined, even the cross site default one in DB + if ($routingResult['404'] === '') + die('404'); + + // Redirection + $response = $e->getResponse (); + $response->setHeaders($response->getHeaders ()->addHeaderLine('Location', $routingResult[''.$statusCode])); + $response->setStatusCode($statusCode); + $response->sendHeaders(); + exit (); + } + else + { + // We're all good to display a page! + unset($routingResult['301']); + unset($routingResult['404']); + $datasPage = $routingResult['datasPage']; - if (!empty($datasPage->getMelisTemplate())) - { - // Setting the template and creating translations and session for the site module - $e->getViewModel()->setTemplate($datasPage->getMelisTemplate()->tpl_zf2_website_folder . '/' . $datasTemplate->tpl_zf2_layout); - $this->createTranslations($e, $datasPage->getMelisTemplate()->tpl_zf2_website_folder, - $datasPage->getMelisPageTree()->lang_cms_locale); - $this->initSession($datasPage->getMelisTemplate()->tpl_zf2_website_folder); - } - - // Making a route param of every variable in the result object - foreach ($routingResult as $keyResult => $result) - $routeMatch->setParam($keyResult, $result); - } + if (!empty($datasPage->getMelisTemplate())) + { + // Setting the template and creating translations and session for the site module + $e->getViewModel()->setTemplate($datasPage->getMelisTemplate()->tpl_zf2_website_folder . '/' . $datasTemplate->tpl_zf2_layout); + $this->createTranslations($e, $datasPage->getMelisTemplate()->tpl_zf2_website_folder, + $datasPage->getMelisPageTree()->lang_cms_locale); + $this->initSession($datasPage->getMelisTemplate()->tpl_zf2_website_folder); + } + + // Making a route param of every variable in the result object + foreach ($routingResult as $keyResult => $result) + $routeMatch->setParam($keyResult, $result); + } /** * Checking of the : * - Controller @@ -264,10 +264,10 @@ function(MvcEvent $e){ */ public function redirectPageSEO301($e, $idpage) { - $sm = $e->getApplication()->getServiceManager(); + $sm = $e->getApplication()->getServiceManager(); $router = $e->getRouter(); $uri = $router->getRequestUri(); - + // Check for defined SEO 301 redirection $uri = $uri->getPath(); if (substr($uri, 0, 1) == '/') @@ -304,34 +304,34 @@ public function redirectPageSEO301($e, $idpage) */ public function redirectPageSEORedirect($e, $idpage) { - $sm = $e->getApplication()->getServiceManager(); - - $router = $e->getRouter(); - $uri = $router->getRequestUri(); - - // Check for defined SEO regular redirection - $uri = $uri->getPath(); - if (substr($uri, 0, 1) == '/') - $uri = substr($uri, 1, strlen($uri)); - - $melisTablePageSeo = $sm->get('MelisEngineTablePageSeo'); - $datasPageSeo = $melisTablePageSeo->getEntryById($idpage); - if (!empty($datasPageSeo)) - { - $datasPageSeo = $datasPageSeo->current(); - if (!empty($datasPageSeo) && !empty($datasPageSeo->pseo_url_redirect)) - { - if (substr($datasPageSeo->pseo_url_redirect, 0, 4) != 'http') - $newuri = '/' . $datasPageSeo->pseo_url_redirect; - else - $newuri = $datasPageSeo->pseo_url_redirect; + $sm = $e->getApplication()->getServiceManager(); + + $router = $e->getRouter(); + $uri = $router->getRequestUri(); + + // Check for defined SEO regular redirection + $uri = $uri->getPath(); + if (substr($uri, 0, 1) == '/') + $uri = substr($uri, 1, strlen($uri)); + + $pageSeoSrv = $sm->get('MelisEngineSEOService'); + $datasPageSeo = $pageSeoSrv->getSEOById($idpage); + if (!empty($datasPageSeo)) + { + $datasPageSeo = $datasPageSeo->current(); + if (!empty($datasPageSeo) && !empty($datasPageSeo->pseo_url_redirect)) + { + if (substr($datasPageSeo->pseo_url_redirect, 0, 4) != 'http') + $newuri = '/' . $datasPageSeo->pseo_url_redirect; + else + $newuri = $datasPageSeo->pseo_url_redirect; - $newuri .= $this->getQueryParameters($e); - - return $newuri; - } - } + $newuri .= $this->getQueryParameters($e); + + return $newuri; + } + } - return null; + return null; } } \ No newline at end of file diff --git a/src/Service/MelisFrontHeadService.php b/src/Service/MelisFrontHeadService.php index c8915b1..4295c6c 100644 --- a/src/Service/MelisFrontHeadService.php +++ b/src/Service/MelisFrontHeadService.php @@ -56,8 +56,8 @@ public function updateTitleAndDescription($idPage, $contentGenerated) /** * Get SEO for this page */ - $melisTablePageSeo = $this->serviceLocator->get('MelisEngineTablePageSeo'); - $datasPageSeo = $melisTablePageSeo->getEntryById($idPage); + $pageSeoSrv = $this->serviceLocator->get('MelisEngineSEOService'); + $datasPageSeo = $pageSeoSrv->getSEOById($idPage); /** * Description tag */ @@ -65,75 +65,75 @@ public function updateTitleAndDescription($idPage, $contentGenerated) { if (!empty($datasPageSeo)) { $descriptionPage = addslashes($datasPageSeo->pseo_meta_description); - $descriptionPage = str_replace("\'", "'", $descriptionPage); + $descriptionPage = str_replace("\'", "'", $descriptionPage); - $titlePage = addslashes($datasPageSeo->pseo_meta_title); - $titlePage = str_replace("\'", "'", $titlePage); + $titlePage = addslashes($datasPageSeo->pseo_meta_title); + $titlePage = str_replace("\'", "'", $titlePage); if ($descriptionPage != '') { - $descriptionTag = "\n\t\n"; - $titleTag = "$titlePage"; - $descriptionRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; - $titleReg = '/\+(.*?)+\<\/title>/'; + $descriptionTag = "\n\t\n"; + $titleTag = "$titlePage"; + $descriptionRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; + $titleReg = '/\+(.*?)+\<\/title>/'; - preg_match($descriptionRegex, $contentGenerated, $descriptions); - preg_match($titleReg, $contentGenerated, $titles); - if (!empty($descriptions)) { - // Replace existing title in source with the page name - $newContent = preg_replace($descriptionRegex, $descriptionTag, $contentGenerated,1); - } else { - // Title doesn't exist, look for head tag to add - // if no head tag, then nothing will happen - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$descriptionTag", $contentGenerated,1); - } + preg_match($descriptionRegex, $contentGenerated, $descriptions); + preg_match($titleReg, $contentGenerated, $titles); + if (!empty($descriptions)) { + // Replace existing title in source with the page name + $newContent = preg_replace($descriptionRegex, $descriptionTag, $contentGenerated,1); + } else { + // Title doesn't exist, look for head tag to add + // if no head tag, then nothing will happen + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$descriptionTag", $contentGenerated,1); + } - if (!empty($titles)) { - // Replace existing title in source with the page name - $newContent = preg_replace($titleReg, $titleTag, $newContent); - } else { - // Title doesn't exist, look for head tag to add - // if no head tag, then nothing will happen - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$titleTag", $newContent,1); - } + if (!empty($titles)) { + // Replace existing title in source with the page name + $newContent = preg_replace($titleReg, $titleTag, $newContent); + } else { + // Title doesn't exist, look for head tag to add + // if no head tag, then nothing will happen + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$titleTag", $newContent,1); + } - $contentGenerated = $newContent; + $contentGenerated = $newContent; - } + } + } + /** + * Canonical Tag + */ + $canonicalUrl = addslashes($datasPageSeo->pseo_canonical); + $canonicalUrl = str_replace("\'", "'", $canonicalUrl); + if ($canonicalUrl != '') { + $canonicalUrlTag = "\n\t\n"; + $canonicalRegex = '/(]*rel=[\"\']canonical[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; + preg_match($canonicalRegex, $contentGenerated, $canonicalFound); + if(!empty($canonicalFound)){ + $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated,1); + }else { + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated,1); + } + $contentGenerated = $newContent; + }else{ + /** + * @var MelisTreeService + */ + $pageService = $this->serviceLocator->get('MelisEngineTree'); + $pageUrl = $pageService->getPageLink($idPage); + $canonicalUrlTag = "\n\t\n"; + $canonicalRegex = '/(]*rel=[\"\']canonical[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; + preg_match($canonicalRegex, $contentGenerated, $canonicalFound); + if(!empty($canonicalFound)){ + $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated ,1); + }else { + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated,1); + } + $contentGenerated = $newContent; } - /** - * Canonical Tag - */ - $canonicalUrl = addslashes($datasPageSeo->pseo_canonical); - $canonicalUrl = str_replace("\'", "'", $canonicalUrl); - if ($canonicalUrl != '') { - $canonicalUrlTag = "\n\t\n"; - $canonicalRegex = '/(]*rel=[\"\']canonical[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; - preg_match($canonicalRegex, $contentGenerated, $canonicalFound); - if(!empty($canonicalFound)){ - $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated,1); - }else { - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated,1); - } - $contentGenerated = $newContent; - }else{ - /** - * @var MelisTreeService - */ - $pageService = $this->serviceLocator->get('MelisEngineTree'); - $pageUrl = $pageService->getPageLink($idPage); - $canonicalUrlTag = "\n\t\n"; - $canonicalRegex = '/(]*rel=[\"\']canonical[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; - preg_match($canonicalRegex, $contentGenerated, $canonicalFound); - if(!empty($canonicalFound)){ - $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated ,1); - }else { - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated,1); - } - $contentGenerated = $newContent; - } } /** @@ -167,28 +167,28 @@ public function updateTitleAndDescription($idPage, $contentGenerated) public function updatePluginsRessources($content) { - $newContent = $content; - - // Auto adding plugins CSS and JS files to layout - if ($this->serviceLocator->get('templating_plugins')->hasItem('plugins_front')) - { - $files = $this->serviceLocator->get('templating_plugins')->getItem('plugins_front'); - - $cssHtmlToAdd = "\n"; - foreach ($files['css'] as $css) - $cssHtmlToAdd .= '' . "\n"; + $newContent = $content; + + // Auto adding plugins CSS and JS files to layout + if ($this->serviceLocator->get('templating_plugins')->hasItem('plugins_front')) + { + $files = $this->serviceLocator->get('templating_plugins')->getItem('plugins_front'); + + $cssHtmlToAdd = "\n"; + foreach ($files['css'] as $css) + $cssHtmlToAdd .= '' . "\n"; - $headRegex = '/(<\/head[^>]*>)/im'; - $newContent = preg_replace($headRegex, "$cssHtmlToAdd$1", $newContent); - - $jsHtmlToAdd = "\n"; - foreach ($files['js'] as $js) - $jsHtmlToAdd .= '' . "\n"; + $headRegex = '/(<\/head[^>]*>)/im'; + $newContent = preg_replace($headRegex, "$cssHtmlToAdd$1", $newContent); + + $jsHtmlToAdd = "\n"; + foreach ($files['js'] as $js) + $jsHtmlToAdd .= '' . "\n"; - $bodyRegex = '/(<\/body[^>]*>)/im'; - $newContent = preg_replace($bodyRegex, "$jsHtmlToAdd$1", $newContent); - } - - return $newContent; + $bodyRegex = '/(<\/body[^>]*>)/im'; + $newContent = preg_replace($bodyRegex, "$jsHtmlToAdd$1", $newContent); + } + + return $newContent; } } \ No newline at end of file From 2ccfc3202fa4559d3287d0fe3a7642877cc9f262 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 12:59:15 +0800 Subject: [PATCH 18/31] Cache the translation that came from db --- src/Service/MelisSiteTranslationService.php | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteTranslationService.php b/src/Service/MelisSiteTranslationService.php index 2be365f..48186a1 100644 --- a/src/Service/MelisSiteTranslationService.php +++ b/src/Service/MelisSiteTranslationService.php @@ -367,8 +367,7 @@ public function getSiteTranslationFromDb($translationKey = null, $langId = null, $arrayParameters = $this->sendEvent('melis_site_translation_get_trans_db_start', $arrayParameters); $transFromDb = array(); - $mstTable = $this->getServiceLocator()->get('MelisSiteTranslationTable'); - $translationFromDb = $mstTable->getSiteTranslation($arrayParameters['translationKey'], $arrayParameters['langId'], $arrayParameters['siteId'])->toArray(); + $translationFromDb = $this->getCachedSiteTranslationFromDb($arrayParameters['translationKey'], $arrayParameters['langId'], $arrayParameters['siteId']); foreach ($translationFromDb as $keyDb => $valueDb) { array_push($transFromDb, array('mst_id' => $valueDb['mst_id'], 'mstt_id' => $valueDb['mstt_id'], 'mst_site_id' => $valueDb['mst_site_id'], 'mstt_lang_id' => $valueDb['mstt_lang_id'], 'mst_key' => $valueDb['mst_key'], 'mstt_text' => $valueDb['mstt_text'], 'module' => null)); @@ -379,6 +378,29 @@ public function getSiteTranslationFromDb($translationKey = null, $langId = null, return $arrayParameters['results']; } + /** + * @param $key + * @param $langId + * @param $siteId + * @return mixed + */ + public function getCachedSiteTranslationFromDb($key, $langId, $siteId) + { + //try to get data from cache + $cacheKey = 'getCachedSiteTranslationFromDb_' . $key.'_'.$langId.'_'.$siteId; + $cacheConfig = 'engine_page_services'; + $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); + if(!is_null($results)) return $results; + + $mstTable = $this->getServiceLocator()->get('MelisSiteTranslationTable'); + $translationFromDb = $mstTable->getSiteTranslation($key, $langId, $siteId)->toArray(); + + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $translationFromDb); + + return $translationFromDb; + } + /** * Function to get all translation of every module in the file * From 954aa753a46a16b070f73af30c6907bf0b57ae41 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 13:06:10 +0800 Subject: [PATCH 19/31] Get lang data from service instead of from db --- src/Module.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Module.php b/src/Module.php index b393356..cc1b207 100644 --- a/src/Module.php +++ b/src/Module.php @@ -145,13 +145,13 @@ public function createTranslations($e, $routeMatch) $sm = $e->getApplication()->getServiceManager(); $melisPagelangTbl = $sm->get('MelisEngine\Model\Tables\MelisPageLangTable'); $currentPage = $melisPagelangTbl->getEntryByField('plang_page_id', $idpage)->current(); - $melisCmsLang = $sm->get('MelisEngine\Model\Tables\MelisCmsLangTable'); - $currentPageLang = $melisCmsLang->getEntryById($currentPage->plang_lang_id)->current(); + $langSrv = $sm->get('MelisEngineLang'); + $currentPageLang = $langSrv->getLangDataById($currentPage->plang_lang_id); if (!empty($currentPageLang)) { $container = new Container('melisplugins'); - $container['melis-plugins-lang-id'] = $currentPageLang->lang_cms_id; - $container['melis-plugins-lang-locale'] = $currentPageLang->lang_cms_locale; - $locale = $currentPageLang->lang_cms_locale; + $container['melis-plugins-lang-id'] = $currentPageLang['lang_cms_id']; + $container['melis-plugins-lang-locale'] = $currentPageLang['lang_cms_locale']; + $locale = $currentPageLang['lang_cms_locale']; } } } From 50e4d6f04606a6a3f35b3574a98c067e727f579f Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 13:30:08 +0800 Subject: [PATCH 20/31] Array index --- src/Module.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Module.php b/src/Module.php index cc1b207..37fe65a 100644 --- a/src/Module.php +++ b/src/Module.php @@ -143,15 +143,22 @@ public function createTranslations($e, $routeMatch) if (!empty($param['idpage']) || !empty($param['frontIdpage'])) { $idpage = !empty($param['idpage']) ? $param['idpage'] : $param['frontIdpage']; $sm = $e->getApplication()->getServiceManager(); + // var_dump($idpage); $melisPagelangTbl = $sm->get('MelisEngine\Model\Tables\MelisPageLangTable'); $currentPage = $melisPagelangTbl->getEntryByField('plang_page_id', $idpage)->current(); + + $langSrv = $sm->get('MelisEngineLang'); $currentPageLang = $langSrv->getLangDataById($currentPage->plang_lang_id); + + // var_dump($currentPage); + // var_dump($currentPageLang); + // die; if (!empty($currentPageLang)) { $container = new Container('melisplugins'); - $container['melis-plugins-lang-id'] = $currentPageLang['lang_cms_id']; - $container['melis-plugins-lang-locale'] = $currentPageLang['lang_cms_locale']; - $locale = $currentPageLang['lang_cms_locale']; + $container['melis-plugins-lang-id'] = $currentPageLang[0]['lang_cms_id']; + $container['melis-plugins-lang-locale'] = $currentPageLang[0]['lang_cms_locale']; + $locale = $currentPageLang[0]['lang_cms_locale']; } } } From 4f26d5ae98ea64b8346a9fdff10c875a84b20b08 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 14:00:11 +0800 Subject: [PATCH 21/31] Apply cache on getting template --- src/Service/MelisSiteConfigService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index a9c9cc9..67285c3 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -360,7 +360,7 @@ private function getSiteDataByPageId($pageId) $pageSaved = $this->getServiceLocator()->get('MelisEngineTablePageSaved'); $pagePublished = $this->getServiceLocator()->get('MelisEngineTablePagePublished'); - $template = $this->getServiceLocator()->get('MelisEngineTableTemplate'); + $tplSrv = $this->getServiceLocator()->get('MelisEngineTemplateService'); if(!empty($pageId)){ /** @@ -376,7 +376,7 @@ private function getSiteDataByPageId($pageId) } if(!empty($tplId)){ - $tplData = $template->getEntryById($tplId)->current(); + $tplData = $tplSrv->getTemplate($tplId)->current(); if(!empty($tplData)){ $siteId = $tplData->tpl_site_id; } From caa6b4c4f8ef2c5448b4fcf7321047020abf1388 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 14:56:00 +0800 Subject: [PATCH 22/31] Fixed proble mon duplicate queries for lang and site --- src/Service/MelisSiteConfigService.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index 67285c3..fed9dd7 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -108,8 +108,8 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) $langData = array(); $langId = null; if (!empty($pageLang)) { - $langCmsTbl = $this->getServiceLocator()->get('MelisEngineTableCmsLang'); - $langData = $langCmsTbl->getEntryById($pageLang->plang_lang_id)->current(); + $langCmsSrv = $this->getServiceLocator()->get('MelisEngineLang'); + $langData = $langCmsSrv->getLangDataById($pageLang->plang_lang_id); } /** @@ -147,8 +147,8 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) $langId = $siteLangData->lang_cms_id; } } else { - $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$langData->lang_cms_locale]; - $langId = $langData->lang_cms_id; + $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$langData['lang_cms_locale']]; + $langId = $langData['lang_cms_id']; } $siteConfig['siteConfig']['site_id'] = $siteId; $siteConfig['siteConfig']['default_lang_id'] = $langId; @@ -384,8 +384,8 @@ private function getSiteDataByPageId($pageId) } if(!empty($siteId)){ - $siteTbl = $this->getServiceLocator()->get('MelisEngineTableSite'); - $siteData = $siteTbl->getEntryById($siteId)->current(); + $siteSrv = $this->getServiceLocator()->get('MelisEngineSiteService'); + $siteData = $siteSrv->getSiteById($siteId)->current(); } return $siteData; From 86c4397c59a8beb29aef3c08d21d1e4ec7b3f4f2 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 17:06:13 +0800 Subject: [PATCH 23/31] Clean code --- src/Listener/MelisFrontMiniTemplateConfigListener.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Listener/MelisFrontMiniTemplateConfigListener.php b/src/Listener/MelisFrontMiniTemplateConfigListener.php index 3441b3c..5fd1322 100644 --- a/src/Listener/MelisFrontMiniTemplateConfigListener.php +++ b/src/Listener/MelisFrontMiniTemplateConfigListener.php @@ -85,8 +85,9 @@ public function onLoadModulesPost(ModuleEvent $e) } //get the config for mini template - if(!empty($this->prepareMiniTemplateConfig($sitePath))){ - $config = ArrayUtils::merge($config, $this->prepareMiniTemplateConfig($sitePath)); + $miniTplConfig = $this->prepareMiniTemplateConfig($sitePath); + if(!empty($miniTplConfig)){ + $config = ArrayUtils::merge($config, $miniTplConfig); } // Pass the changed configuration back to the listener: From 3ea68973d900fa807463cd9414026fcb57411223 Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 17:48:48 +0800 Subject: [PATCH 24/31] Front menu plugin cached --- config/module.config.php | 21 ++++++ .../Plugin/MelisFrontMenuPlugin.php | 18 +++++ .../MelisFrontDeletePluginCacheListener.php | 73 +++++++++++++++++++ src/Module.php | 2 + 4 files changed, 114 insertions(+) create mode 100644 src/Listener/MelisFrontDeletePluginCacheListener.php diff --git a/config/module.config.php b/config/module.config.php index e02cc31..2612f47 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -268,4 +268,25 @@ ), ), ), + 'caches' => [ + 'melisfront_pages_file_cache' => array( + 'active' => true, // activate or deactivate Melis Cache for this conf + 'adapter' => array( + 'name' => 'Filesystem', + 'options' => array( + 'ttl' => 0, // 24hrs + 'namespace' => 'melisfront_pages_file_cache', + 'cache_dir' => $_SERVER['DOCUMENT_ROOT'] . '/../cache' + ), + ), + 'plugins' => array( + 'exception_handler' => array('throw_exceptions' => false), + 'Serializer' + ), + 'ttls' => array( + // add a specific ttl for a specific cache key (found via regexp) + // 'my_cache_key' => 60, + ) + ), + ] ); diff --git a/src/Controller/Plugin/MelisFrontMenuPlugin.php b/src/Controller/Plugin/MelisFrontMenuPlugin.php index 1abd4f6..58cdc6a 100644 --- a/src/Controller/Plugin/MelisFrontMenuPlugin.php +++ b/src/Controller/Plugin/MelisFrontMenuPlugin.php @@ -65,6 +65,15 @@ public function front() $pageId = !empty($data['pageIdRootMenu']) ? $data['pageIdRootMenu'] : 1; + // Retrieve cache version if front mode to avoid multiple calls + $cacheKey = 'MelisFrontMenuPlugin_' . $this->cleanString($data['id']). '_' .$this->cleanString($data['template_path']); + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); + + if (!is_null($results)) + return $results; + // Getting the Site Menu from MelisFrontNavigator $site = new MelisFrontNavigation($this->getServiceLocator(), $pageId, $this->renderMode); @@ -77,6 +86,9 @@ public function front() 'menu' => $siteMenu ); + // Save cache key + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $viewVariables); + // return the variable array and let the view be created return $viewVariables; } @@ -126,6 +138,12 @@ public function createOptionsForms() $errors = array(); if ($form->isValid()) { + + $cacheKey = 'MelisFrontMenuPlugin_' . $this->getFormData()['id']; + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); + $melisEngineCacheSystem->deleteCacheByPrefix($cacheKey, $cacheConfig); + $data = $form->getData(); $success = true; array_push($response, [ diff --git a/src/Listener/MelisFrontDeletePluginCacheListener.php b/src/Listener/MelisFrontDeletePluginCacheListener.php new file mode 100644 index 0000000..def5dcd --- /dev/null +++ b/src/Listener/MelisFrontDeletePluginCacheListener.php @@ -0,0 +1,73 @@ +getSharedManager(); + + $callBackHandler = $sharedEvents->attach( + '*', + [ + 'meliscms_page_save_end', + 'meliscms_page_publish_end', + 'meliscms_page_unpublish_end', + 'meliscms_page_delete_end', + 'meliscms_page_move_end', + ], + function($e){ + + $sm = $e->getTarget()->getServiceLocator(); + + $params = $e->getParams(); + + if (!$params['success']) + return; + + $melisEngineCacheSystem = $sm->get('MelisEngineCacheSystem'); + + // Delete Menu plugin cached + $cacheKey = 'MelisFrontMenuPlugin'; + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem->deleteCacheByPrefix($cacheKey, $cacheConfig); + } + ); + + $this->listeners[] = $callBackHandler; + } + + public function detach(EventManagerInterface $events) + { + foreach ($this->listeners as $index => $listener) { + if ($events->detach($listener)) { + unset($this->listeners[$index]); + } + } + } +} \ No newline at end of file diff --git a/src/Module.php b/src/Module.php index 37fe65a..bc43276 100644 --- a/src/Module.php +++ b/src/Module.php @@ -34,6 +34,7 @@ use MelisFront\Listener\MelisFrontXSSParameterListener; use Zend\Session\Container; use MelisFront\Listener\MelisFrontPageCacheListener; +use MelisFront\Listener\MelisFrontDeletePluginCacheListener; class Module { @@ -120,6 +121,7 @@ public function onBootstrap(MvcEvent $e) } else { $eventManager->attach(new MelisFrontPluginLangSessionUpdateListener()); + $eventManager->attach(new MelisFrontDeletePluginCacheListener()); } } From 8f4ce4eff7f4d91518816ac1655c5014ebb84a29 Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 17:49:17 +0800 Subject: [PATCH 25/31] Return array parse to object --- src/Controller/Plugin/MelisFrontShowListFromFolderPlugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/Plugin/MelisFrontShowListFromFolderPlugin.php b/src/Controller/Plugin/MelisFrontShowListFromFolderPlugin.php index e4e18a6..9648f1e 100644 --- a/src/Controller/Plugin/MelisFrontShowListFromFolderPlugin.php +++ b/src/Controller/Plugin/MelisFrontShowListFromFolderPlugin.php @@ -71,6 +71,7 @@ public function front() foreach ($pages as $key => $val) { + $val = (object) $val; /** * Page content has a values of XML type * so need to parse to make the content of the page easy to manage From 420b49646170103d86447a309ef09d9c54109fe5 Mon Sep 17 00:00:00 2001 From: Ralph Bryan Brioso Date: Fri, 8 May 2020 18:10:51 +0800 Subject: [PATCH 26/31] Breadcrumbplugin added cache --- .../Plugin/MelisFrontBreadcrumbPlugin.php | 17 +++++++++++++++++ .../MelisFrontDeletePluginCacheListener.php | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php b/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php index 7de0fd1..4c2cacc 100644 --- a/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php +++ b/src/Controller/Plugin/MelisFrontBreadcrumbPlugin.php @@ -64,6 +64,13 @@ public function front() { // Get the parameters and config from $this->pluginFrontConfig (default > hardcoded > get > post) $data = $this->getFormData(); + + // Retrieve cache version if front mode to avoid multiple calls + $cacheKey = 'MelisFrontBreadcrumbPlugin_' . $this->cleanString($data['id']). '_' .$this->cleanString($data['template_path']); + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); + $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig); + // Retrieving the pageId from config $pageId = (!empty($data['pageId'])) ? $data['pageId'] : null; $startingPage = $data['pageIdRootBreadcrumb'] ?? $data['pageIdRootBreadcrumb']; @@ -118,6 +125,9 @@ public function front() 'pluginId' => $data['id'], 'breadcrumb' => $breadcrumb, ); + + // Save cache key + $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $viewVariables); // return the variable array and let the view be created return $viewVariables; @@ -169,6 +179,13 @@ public function createOptionsForms() $errors = array(); if ($form->isValid()) { + + // Deleting file cache + $cacheKey = 'MelisFrontBreadcrumbPlugin_' . $this->getFormData()['id']; + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); + $melisEngineCacheSystem->deleteCacheByPrefix($cacheKey, $cacheConfig); + $data = $form->getData(); $success = true; array_push($response, [ diff --git a/src/Listener/MelisFrontDeletePluginCacheListener.php b/src/Listener/MelisFrontDeletePluginCacheListener.php index def5dcd..3fba2cd 100644 --- a/src/Listener/MelisFrontDeletePluginCacheListener.php +++ b/src/Listener/MelisFrontDeletePluginCacheListener.php @@ -56,6 +56,11 @@ function($e){ $cacheKey = 'MelisFrontMenuPlugin'; $cacheConfig = 'melisfront_pages_file_cache'; $melisEngineCacheSystem->deleteCacheByPrefix($cacheKey, $cacheConfig); + + // Delete Breadcrumb plugin cached + $cacheKey = 'MelisFrontBreadcrumbPlugin'; + $cacheConfig = 'melisfront_pages_file_cache'; + $melisEngineCacheSystem->deleteCacheByPrefix($cacheKey, $cacheConfig); } ); From c46ecd660734ac8e0b4b7271e29f6f35ab0700aa Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 18:42:10 +0800 Subject: [PATCH 27/31] Fixed a small issue on config --- src/Service/MelisSiteConfigService.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index fed9dd7..0111945 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -147,8 +147,10 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) $langId = $siteLangData->lang_cms_id; } } else { - $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$langData['lang_cms_locale']]; - $langId = $langData['lang_cms_id']; + foreach($langData as $val) { + $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$val['lang_cms_locale']]; + $langId = $val['lang_cms_id']; + } } $siteConfig['siteConfig']['site_id'] = $siteId; $siteConfig['siteConfig']['default_lang_id'] = $langId; @@ -158,6 +160,7 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) } } } + $arrayParameters['result'] = $siteConfig; // Save cache key $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $arrayParameters['result']); From db65cbecf65d846755597e00efe6bdbb459a8469 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 8 May 2020 22:46:13 +0800 Subject: [PATCH 28/31] Fixed undefined variable --- src/Service/MelisSiteConfigService.php | 71 ++++++++++++-------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/src/Service/MelisSiteConfigService.php b/src/Service/MelisSiteConfigService.php index 0111945..e9414cf 100644 --- a/src/Service/MelisSiteConfigService.php +++ b/src/Service/MelisSiteConfigService.php @@ -27,45 +27,41 @@ class MelisSiteConfigService extends MelisEngineGeneralService */ public function getSiteConfigByKey($key, $pageId, $section = 'sites', $language = null) { - try { - if(empty($section)) - $section = 'sites'; - - /** - * check if we are getting it from the current site config - * or from the allSites - */ - if ($section == 'sites' || $section == 'allSites') { - $siteConfigData = $this->getSiteConfigByPageId($pageId); - if ($section == 'sites') { - if (empty($language)) { - //return the value if the given key - return (isset($siteConfigData['siteConfig'][$key])) ? $siteConfigData['siteConfig'][$key] : null; - } else { - //return the given key value from its specific language - $langLocale = strtolower($language) . '_' . strtoupper($language); - $siteConfigData = $this->getSiteConfigByPageId($pageId, $langLocale); - return (isset($siteConfigData['siteConfig'][$key])) ? $siteConfigData['siteConfig'][$key] : null; - } + if(empty($section)) + $section = 'sites'; + + /** + * check if we are getting it from the current site config + * or from the allSites + */ + if ($section == 'sites' || $section == 'allSites') { + $siteConfigData = $this->getSiteConfigByPageId($pageId); + if ($section == 'sites') { + if (empty($language)) { + //return the value if the given key + return (isset($siteConfigData['siteConfig'][$key])) ? $siteConfigData['siteConfig'][$key] : null; } else { - //return given key value from allSites - return (isset($siteConfigData['allSites'][$key])) ? $siteConfigData['allSites'][$key] : null; - } - } else { - $siteConfigData = $this->getSiteConfig($section); - $data = []; - foreach ($siteConfigData as $locale => $value) { - $data[$locale] = array($key => $value[$key]); - } - if (empty($language)) - return $data; - else { + //return the given key value from its specific language $langLocale = strtolower($language) . '_' . strtoupper($language); - return $data[$langLocale][$key]; + $siteConfigData = $this->getSiteConfigByPageId($pageId, $langLocale); + return (isset($siteConfigData['siteConfig'][$key])) ? $siteConfigData['siteConfig'][$key] : null; } + } else { + //return given key value from allSites + return (isset($siteConfigData['allSites'][$key])) ? $siteConfigData['allSites'][$key] : null; + } + } else { + $siteConfigData = $this->getSiteConfig($section); + $data = []; + foreach ($siteConfigData as $locale => $value) { + $data[$locale] = array($key => $value[$key]); + } + if (empty($language)) + return $data; + else { + $langLocale = strtolower($language) . '_' . strtoupper($language); + return $data[$langLocale][$key]; } - }catch (\Exception $ex) { - return null; } } @@ -105,12 +101,11 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) /** * get page lang locale */ + $langCmsSrv = $this->getServiceLocator()->get('MelisEngineLang'); $langData = array(); $langId = null; if (!empty($pageLang)) { - $langCmsSrv = $this->getServiceLocator()->get('MelisEngineLang'); $langData = $langCmsSrv->getLangDataById($pageLang->plang_lang_id); - } /** * get the site config @@ -142,7 +137,7 @@ public function getSiteConfigByPageId($pageId, $langLocale = false) if ($arrayParameters['langLocale']) { $siteConfig['siteConfig'] = $config['site'][$siteName][$siteId][$arrayParameters['langLocale']]; - $siteLangData = $langCmsTbl->getEntryByField('lang_cms_locale', $arrayParameters['langLocale'])->current(); + $siteLangData = $langCmsSrv->getLangDataByLangLocale($arrayParameters['langLocale']); if (!empty($siteLangData)) { $langId = $siteLangData->lang_cms_id; } From 450c8045f0c3c2cfcb99f0e756041b0e4ba0b776 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 11 May 2020 15:27:14 +0800 Subject: [PATCH 29/31] Update site translation view helper to get the translation from the cache --- src/Service/MelisSiteTranslationService.php | 57 +++++++++++++++++++ .../Helper/MelisSiteTranslationHelper.php | 14 ++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/Service/MelisSiteTranslationService.php b/src/Service/MelisSiteTranslationService.php index 48186a1..2e64c87 100644 --- a/src/Service/MelisSiteTranslationService.php +++ b/src/Service/MelisSiteTranslationService.php @@ -14,6 +14,7 @@ use MelisCore\Service\MelisCoreModulesService; use MelisEngine\Service\MelisEngineComposerService; use MelisEngine\Service\MelisEngineGeneralService; +use Zend\Config\Writer\PhpArray; class MelisSiteTranslationService extends MelisEngineGeneralService { @@ -566,6 +567,62 @@ public function getSiteTranslationsFromVendor() return $moduleFolders; } + /** + * Cache translations + * @param $siteId + */ + public function cacheTranslations($siteId) + { + //make cache writable + $cacheDir = $_SERVER['DOCUMENT_ROOT'].'/../cache'; + if(!is_writable($cacheDir)) + chmod($cacheDir, 0777); + //check translation folder inside cache + $transCacheDir = $cacheDir.'/translations'; + if(!file_exists($transCacheDir)) + //create directory + mkdir($transCacheDir, 0777); + + /** + * Create trans file per site and inside the site we separate + * the translation per language. + */ + //get all translations + $transData = $this->getSiteTranslation(null, null, $siteId); + $transPerLang = []; + foreach($transData as $key => $val){ + //check if lang id already exist in array + if(!array_key_exists($val['mstt_lang_id'], $transPerLang)){ + $transPerLang[$val['mstt_lang_id']] = []; + $transPerLang[$val['mstt_lang_id']][$val['mst_key']] = $val['mstt_text']; + }else{ + $transPerLang[$val['mstt_lang_id']][$val['mst_key']] = $val['mstt_text']; + } + } + //create directory for site + $siteTransDir = $transCacheDir.'/'.$siteId; + if(!file_exists($siteTransDir)) + mkdir($siteTransDir, 0777); + //store the translations + $writer = new PhpArray(); + file_put_contents($siteTransDir.'/translations.php', $writer->toString($transPerLang)); + } + + /** + * @param $siteId + * @return mixed + */ + public function getCachedTranslations($siteId) + { + $transCacheData = []; + $transCacheDir = $_SERVER['DOCUMENT_ROOT'].'/../cache/translations/'.$siteId.'/translations.php'; + if(file_exists($transCacheDir)) + $transCacheData = include $transCacheDir; + + return $transCacheData; + } + + /** ======================================================================================================================= **/ /** ======================================================================================================================= **/ /** ======================================================================================================================= **/ diff --git a/src/View/Helper/MelisSiteTranslationHelper.php b/src/View/Helper/MelisSiteTranslationHelper.php index d061584..6a12bcf 100644 --- a/src/View/Helper/MelisSiteTranslationHelper.php +++ b/src/View/Helper/MelisSiteTranslationHelper.php @@ -32,8 +32,18 @@ public function __construct($sm) public function __invoke($key, $langId, $siteId) { $siteTransSrv = $this->serviceManager->get('MelisSiteTranslationService'); - - $str = $siteTransSrv->getText($key, $langId, $siteId); + + /** + * Try to get the translation from the cache + */ + $cacheData = $siteTransSrv->getCachedTranslations($siteId); + if(empty($cacheData)){ + //generate cache for translation + $siteTransSrv->cacheTranslations($siteId); + //get the data again from cache + $cacheData = $siteTransSrv->getCachedTranslations($siteId); + } + $str = $cacheData[$langId][$key] ?? $key; return $str; } From bcfba3ada8ff1009959c62670e74c85e55270c2a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 May 2020 19:23:31 +0800 Subject: [PATCH 30/31] Fixed problem on rendering site with different language --- src/Listener/MelisFrontHomePageRoutingListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Listener/MelisFrontHomePageRoutingListener.php b/src/Listener/MelisFrontHomePageRoutingListener.php index 0bda0b0..6a39300 100644 --- a/src/Listener/MelisFrontHomePageRoutingListener.php +++ b/src/Listener/MelisFrontHomePageRoutingListener.php @@ -76,7 +76,7 @@ function(MvcEvent $e){ $siteService = $sm->get('MelisEngineSiteService'); if(!empty($langData)) { $langId = $langData->lang_cms_id; - $siteHomeData = $siteService->getHomePageBySiteIdAndLangId($siteId, $langId)->current(); + $siteHomeData = $siteService->getHomePageBySiteIdAndLangId($siteId, $langId); /** * Check if site home page id exit from site home table, * else we used the default main page id From a3435dd75384a6ab2d1ab93662a10c5c52994450 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2020 16:19:24 +0800 Subject: [PATCH 31/31] Added page id to cachekey on FrontMenuPlugin --- src/Controller/Plugin/MelisFrontMenuPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/Plugin/MelisFrontMenuPlugin.php b/src/Controller/Plugin/MelisFrontMenuPlugin.php index 58cdc6a..486d031 100644 --- a/src/Controller/Plugin/MelisFrontMenuPlugin.php +++ b/src/Controller/Plugin/MelisFrontMenuPlugin.php @@ -66,7 +66,7 @@ public function front() $pageId = !empty($data['pageIdRootMenu']) ? $data['pageIdRootMenu'] : 1; // Retrieve cache version if front mode to avoid multiple calls - $cacheKey = 'MelisFrontMenuPlugin_' . $this->cleanString($data['id']). '_' .$this->cleanString($data['template_path']); + $cacheKey = 'MelisFrontMenuPlugin_'.$data['pageId'].'_'.$this->cleanString($data['id']). '_' .$this->cleanString($data['template_path']); $cacheConfig = 'melisfront_pages_file_cache'; $melisEngineCacheSystem = $this->getServiceLocator()->get('MelisEngineCacheSystem'); $results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);