From a2e5d6e6b783355c0ea6a929fa9983f852448482 Mon Sep 17 00:00:00 2001 From: Maria Teresa Pomar Date: Tue, 22 Oct 2024 17:41:20 +0800 Subject: [PATCH] updated --- .../MelisFrontMiniTemplateConfigListener.php | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Listener/MelisFrontMiniTemplateConfigListener.php b/src/Listener/MelisFrontMiniTemplateConfigListener.php index c3d0f8b..cffebac 100644 --- a/src/Listener/MelisFrontMiniTemplateConfigListener.php +++ b/src/Listener/MelisFrontMiniTemplateConfigListener.php @@ -84,8 +84,21 @@ public function onLoadModulesPost(ModuleEvent $e, $priority = 1) } } + /** + * get all minitemplates from public root + */ + $rootMinitemplates = $_SERVER['DOCUMENT_ROOT'] . '/../public/miniTemplatesTinyMce'; + if (file_exists($rootMinitemplates) && is_dir($rootMinitemplates)) { + $publicSites = $this->getDir($rootMinitemplates); + if (!empty($publicSites)) { + foreach ($publicSites as $rootSite) { + $sitePath[$rootSite.'_root'] = $rootMinitemplates . '/' . $rootSite; + } + } + } + //get the config for mini template - $miniTplConfig = $this->prepareMiniTemplateConfig($sitePath); + $miniTplConfig = $this->prepareMiniTemplateConfig($sitePath, $serviceManager); if(!empty($miniTplConfig)){ $config = ArrayUtils::merge($config, $miniTplConfig); } @@ -107,13 +120,25 @@ public function onLoadModulesPost(ModuleEvent $e, $priority = 1) * Function to prepare the Mini Template config * * @param $miniTplPath + * @param $serviceManager * @return array */ - public function prepareMiniTemplateConfig($miniTplPath) + public function prepareMiniTemplateConfig($miniTplPath, $serviceManager) { + $flaggedTable = $serviceManager->get('MelisEngineTableFlaggedTemplate'); $image_ext = ['PNG', 'png', 'JPG', 'jpg', 'JPEG', 'jpeg', 'gif', 'GIF']; $pluginsFormat = array(); + foreach($miniTplPath as $siteName => $path) { + $isRoot = false; + //get all flagged templates of the site, these are the templates that were edited and its updated data are now inside root minitemplate directory + $allFlaggedTemplates = $flaggedTable->getFlaggedTemplate($siteName)->toArray(); + + if (strpos($siteName, '_root') !== false) { + $isRoot = true; + $siteName = str_replace('_root', '', $siteName); + } + if (file_exists($path) && is_dir($path)) { $tplImgList = []; //get the plugin config format @@ -129,7 +154,18 @@ public function prepareMiniTemplateConfig($miniTplPath) //if image found, store the image path with the template name as the key if(strpos($tpl, $ext) !== false) { $fName = pathinfo($tpl, PATHINFO_FILENAME); - $tplImgList[$fName] = '/'.$siteName.'/miniTemplatesTinyMce/'.$fName.'.'.$ext; + + //exclude flagged template + if (!$isRoot && in_array($fName, array_column($allFlaggedTemplates, 'mtpft_template_name'))) { + continue; + } + + if ($isRoot) { + $tplImgList[$fName] = '/miniTemplatesTinyMce/' . $siteName . '/' . $fName . '.' . $ext; + } else { + $tplImgList[$fName] = '/'.$siteName.'/miniTemplatesTinyMce/'.$fName.'.'.$ext; + } + //remove the image unset($tpls[$key]); } @@ -145,6 +181,12 @@ public function prepareMiniTemplateConfig($miniTplPath) foreach ($tpls as $k => $v) { //remove the file extension from the filename $name = pathinfo($v, PATHINFO_FILENAME); + + //exclude flagged template + if (!$isRoot && in_array($name, array_column($allFlaggedTemplates, 'mtpft_template_name'))) { + continue; + } + //create a plugin post name $postName = strtolower($name).'_'. strtolower($siteName); //prepare the content of the mini template