diff --git a/composer.json b/composer.json index dd51e66..89ba145 100644 --- a/composer.json +++ b/composer.json @@ -34,8 +34,8 @@ "ext-openssl": "*", "ext-json": "*", "ext-pdo_mysql": "*", - "melisplatform/melis-core": "^3.0.0", - "melisplatform/melis-engine": "^3.0.0", + "melisplatform/melis-core": "^2.3.0", + "melisplatform/melis-engine": "^2.3.0", "justinrainbow/json-schema": "5.2.1" }, "require-dev": { diff --git a/config/module.config.php b/config/module.config.php index fec355e..ae728db 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -186,6 +186,7 @@ 'MelisFrontShowListFromFolderPlugin' => 'MelisFront\Controller\Plugin\MelisFrontShowListFromFolderPlugin', 'MelisFrontSearchResultsPlugin' => 'MelisFront\Controller\Plugin\MelisFrontSearchResultsPlugin', 'MelisFrontBlockSectionPlugin' => 'MelisFront\Controller\Plugin\MelisFrontBlockSectionPlugin', + 'MiniTemplatePlugin' => 'MelisFront\Controller\Plugin\MiniTemplatePlugin', ) ), 'view_helpers' => array( @@ -221,6 +222,9 @@ 'MelisFront/list-paginator' => __DIR__ . '/../view/melis-front/plugins/list-paginator.phtml', 'MelisFront/block-section' => __DIR__ . '/../view/melis-front/plugins/block-section.phtml', 'MelisFront/block-section-container' => __DIR__ . '/../view/melis-front/plugins/block-section-container.phtml', + + //Mini Template plugins + 'MiniTemplate/Content' => __DIR__ . '/../view/melis-front/plugins/mini-template-default.phtml', ), 'template_path_stack' => array( __DIR__ . '/../view', diff --git a/config/plugins/MelisFrontBlockSectionPlugin.config.php b/config/plugins/MelisFrontBlockSectionPlugin.config.php index c85641d..e4add3b 100644 --- a/config/plugins/MelisFrontBlockSectionPlugin.config.php +++ b/config/plugins/MelisFrontBlockSectionPlugin.config.php @@ -22,7 +22,7 @@ ), 'name' => 'Block', 'thumbnail' => '/MelisFront/plugins/images/MelisFrontBlockPlugin_thumb.jpg', - 'description' => 'Add a section block in the drag drop zone', + 'description' => 'tr_melis_front_bloc_plugin_description', ), ), diff --git a/config/plugins/MiniTemplatePlugin.config.php b/config/plugins/MiniTemplatePlugin.config.php new file mode 100644 index 0000000..4fbed2b --- /dev/null +++ b/config/plugins/MiniTemplatePlugin.config.php @@ -0,0 +1,38 @@ + array( + 'template_path' => array('MiniTemplate/Content'), + 'id' => 'tag-miniTpl', + 'pageId' => 1, + 'type' => 'html', + 'default' => null, + 'value' => '', + 'widthDesktop' => 100, + 'widthTablet' => 100, + 'widthMobile' => 100, + 'pluginContainerId' => null, + 'files' => array( + 'css' => array( + ), + 'js' => array( + ), + ), + ), + 'melis' => array( + 'subcategory' => array( + 'id' => 'miniTemplatePlugins', + 'title' => 'Site Name' + ), + 'name' => 'Mini Template Name', + 'thumbnail' => null, + 'description' => null, + 'files' => array( + 'css' => array( + ), + 'js' => array( + 'js_melistag' => '/MelisFront/plugins/js/plugin.melistagHTML.init.js' + ), + ), + 'js_initialization' => array(), + ), +); \ No newline at end of file diff --git a/language/en_EN.interface.php b/language/en_EN.interface.php index 913f818..6a54705 100644 --- a/language/en_EN.interface.php +++ b/language/en_EN.interface.php @@ -74,5 +74,10 @@ 'tr_front_plugin_search_pagination_nbPerPage tooltip' => 'Number of results displayed on a single page', 'tr_front_plugin_search_pagination_nbPageBeforeAfter tooltip' => 'The display of the pagination generate a certain number of links before and after the current page, this field allows to limit this number of inks', + + 'tr_PluginSection_MelisMiniTemplate' => 'Mini Template', + // plugin config + 'tr_melis_front_bloc_plugin_description' => 'The plugin Block adds a simple empty block' + ); ?> \ No newline at end of file diff --git a/language/fr_FR.interface.php b/language/fr_FR.interface.php index fc80aab..89eeef0 100644 --- a/language/fr_FR.interface.php +++ b/language/fr_FR.interface.php @@ -77,5 +77,9 @@ 'tr_front_plugin_search_pagination_nbPerPage tooltip' => 'Nombre de résultats s'affichant sur une même page', 'tr_front_plugin_search_pagination_nbPageBeforeAfter tooltip' => 'L'affichage de la pagination génére un certains nombre de liens avant et après la page en cours, ce champ permet de limiter ce nombe de liens', + + 'tr_PluginSection_MelisMiniTemplate' => 'Mini Template', + // plugin config + 'tr_melis_front_bloc_plugin_description' => 'Le plugin Block ajoute un simple block vide' ); ?> \ No newline at end of file diff --git a/public/plugins/css/plugin.melisdragdropzone.css b/public/plugins/css/plugin.melisdragdropzone.css index 39f65e3..f058efc 100644 --- a/public/plugins/css/plugin.melisdragdropzone.css +++ b/public/plugins/css/plugin.melisdragdropzone.css @@ -15,6 +15,7 @@ border: 1px dashed #de7d79; border-radius: 4px; bottom: -25px; + width: inherit; } .melis-dragdropzone:after { @@ -45,7 +46,8 @@ .melis-dragdropzone .melis-ui-outlined { float: left; - margin: 0 5px 30px; + /* revise by: Junry @ 02082019 */ + margin: 0 5px 30px 0; } .wrapper div.melis-dragdropzone:last-of-type { margin-bottom: 35px; diff --git a/src/Controller/MelisPluginRendererController.php b/src/Controller/MelisPluginRendererController.php index 05f43ed..6277729 100644 --- a/src/Controller/MelisPluginRendererController.php +++ b/src/Controller/MelisPluginRendererController.php @@ -58,7 +58,21 @@ public function getPluginAction() try { - $melisPlugin = $this->getServiceLocator()->get('ControllerPluginManager')->get($pluginName); + /** + * check if plugin is came from the mini template + */ + if (strpos($pluginName, 'MiniTemplatePlugin') !== false) { + $old = $pluginName; + //explode to get the original plugin name + $plugin = explode('_', $pluginName); + //set the original plugin name + $pluginName = $plugin[0]; + + $melisPlugin = $this->getServiceLocator()->get('ControllerPluginManager')->get($pluginName); + $melisPlugin->setMiniTplPluginName($old); + }else{ + $melisPlugin = $this->getServiceLocator()->get('ControllerPluginManager')->get($pluginName); + } // dragdrop, delete only if plugin is not hardcoded if (empty($pluginId)) diff --git a/src/Controller/Plugin/MiniTemplatePlugin.php b/src/Controller/Plugin/MiniTemplatePlugin.php new file mode 100644 index 0000000..7974c65 --- /dev/null +++ b/src/Controller/Plugin/MiniTemplatePlugin.php @@ -0,0 +1,56 @@ +MiniTemplatePlugin(); + * $pluginView = $plugin->render(); + * + * How to call this plugin with custom parameters: + * $plugin = $this->MiniTemplatePlugin(); + * $parameters = array( + * 'template_path' => 'MySiteTest/tag/tag' + * ); + * $pluginView = $plugin->render($parameters); + * + * How to add to your controller's view: + * $view->addChild($pluginView, 'tag_01'); + * + * How to display in your controller's view: + * echo $this->tag_01; + * + * + */ +class MiniTemplatePlugin extends MelisFrontTagPlugin +{ + public function __construct() + { + $this->configPluginKey = 'MelisMiniTemplate'; + $this->pluginXmlDbKey = 'melisTag'; + } + + /** + * This function will set the plugin name + * + * @param $pluginName + */ + public function setMiniTplPluginName($pluginName){ + $this->pluginName = $pluginName; + } +} \ No newline at end of file diff --git a/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php b/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php index a114eef..2cab76c 100644 --- a/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php +++ b/src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php @@ -202,7 +202,53 @@ function(MvcEvent $e){ foreach ($routingResult as $keyResult => $result) $routeMatch->setParam($keyResult, $result); } - + /** + * Checking of the : + * - Controller + * - Controller action + * - layout / template + */ + $moduleTemplate = $datasTemplate; + if (! empty($datasTemplate)) { + $templateType = $datasTemplate->tpl_type; + if ($templateType == 'ZF2') { + $siteModule = $datasTemplate->tpl_zf2_website_folder; + $controller = $datasTemplate->tpl_zf2_controller; + $action = $datasTemplate->tpl_zf2_action; + $layout = $datasTemplate->tpl_zf2_layout; + + // check controller class if exists + $controllerClassName = "\\{$siteModule}\\Controller\\{$controller}Controller"; + if (class_exists($controllerClassName)) { + $routingResult['controller'] = $siteModule . '\Controller\\' . $controller; + $tmpClass = new $controllerClassName; + if (method_exists($tmpClass,$action . "Action")) { + $routingResult['action'] = $action; + } else { + echo "
Controller :[ " . $controller . " ] found in Module : [ {$siteModule} ]but
"; + echo "action: [ " . $action . " ] not found in Controller : [ {$controllerClassName} ]
"; + die;// die because we dont want to show errors everywhere + } + } else { + echo "Controller : [ " . $controller . " ] not found in Module : [ {$siteModule} ]
"; + die;// die because we dont want to show errors everywhere + } + // checking of the layout / zend template + $config = $sm->get('config'); + // get all template_map so we could check if the given template is present on a module + $templateMap = $config['view_manager']['template_map']; + // template to search + $templateName = $siteModule . "/" . $layout; + $checkTemplate = array_key_exists($templateName,$templateMap); + if ($checkTemplate === false) { + // message + $message1 = "Controller [ {$controller} ] and action [ {$action} ] found but
"; + $message2 = "layout / template: [ {$templateName} ] not found in Module : [ {$siteModule} ]
"; + echo $message1 . $message2; + die; // die because we dont want to show errors everywhere + } + } + } } }, 100); diff --git a/src/Module.php b/src/Module.php index abd151f..b1ee964 100644 --- a/src/Module.php +++ b/src/Module.php @@ -182,9 +182,68 @@ public function getConfig() $config = ArrayUtils::merge($config, $file); } + if(!empty($this->prepareMiniTemplateConfig())){ + $config = ArrayUtils::merge($config, $this->prepareMiniTemplateConfig()); + } + return $config; } + /** + * Function to prepare the Mini Template config + * + * @return array + */ + public function prepareMiniTemplateConfig() + { + $pluginsFormat = array(); + $userSites = $_SERVER['DOCUMENT_ROOT'] . '/../module/MelisSites'; + if(file_exists($userSites) && is_dir($userSites)) { + $sites = $this->getDir($userSites); + if(!empty($sites)){ + foreach($sites as $key => $val) { + //public site folder + $publicFolder = $userSites . DIRECTORY_SEPARATOR . $val . DIRECTORY_SEPARATOR . 'public'; + //mini template image folder +// $imgFolder = $publicFolder . DIRECTORY_SEPARATOR . 'images' .DIRECTORY_SEPARATOR . 'miniTemplate'; + //get the mini template folder path + $miniTplPath = $publicFolder . DIRECTORY_SEPARATOR . 'miniTemplatesTinyMce'; + //check if directory is available + if(file_exists($miniTplPath) && is_dir($miniTplPath)) { + //get the plugin config format + $pluginsConfig = include __DIR__ . '/../config/plugins/MiniTemplatePlugin.config.php'; + if(!empty($pluginsConfig)) { + //get all the mini template + $tpls = array_diff(scandir($miniTplPath), array('..', '.')); + if (!empty($tpls)) { + //set the site name as sub category title + $pluginsConfig['melis']['subcategory']['title'] = $val; + //set the id of the plugin + $pluginsConfig['melis']['subcategory']['id'] = $pluginsConfig['melis']['subcategory']['id'] . '_' . $val; + //get the content of the mini template + foreach ($tpls as $k => $v) { + //remove the file extension from the filename + $name = pathinfo($v, PATHINFO_FILENAME); + //create a plugin post name + $postName = $k . strtolower($name); + //prepare the content of the mini template + $content = $miniTplPath . DIRECTORY_SEPARATOR . $v; + //set the default layout for the plugin based on mini template + $pluginsConfig['front']['default'] = file_get_contents($content); + //set the plugin name using the template name + $pluginsConfig['melis']['name'] = $name; + //include the mini tpl plugin config + $pluginsFormat['plugins']['MelisMiniTemplate']['plugins']['MiniTemplatePlugin_' . $postName] = $pluginsConfig; + } + } + } + } + } + } + } + return $pluginsFormat; + } + public function getAutoloaderConfig() { return array( @@ -196,4 +255,27 @@ public function getAutoloaderConfig() ); } + /** + * Returns all the sub-folders in the provided path + * @param String $dir + * @param array $excludeSubFolders + * @return array + */ + protected function getDir($dir, $excludeSubFolders = array()) + { + $directories = array(); + if(file_exists($dir)) { + $excludeDir = array_merge(array('.', '..', '.gitignore'), $excludeSubFolders); + $directory = array_diff(scandir($dir), $excludeDir); + + foreach($directory as $d) { + if(is_dir($dir.'/'.$d)) { + $directories[] = $d; + } + } + + } + return $directories; + } + } diff --git a/src/Service/MelisFrontHeadService.php b/src/Service/MelisFrontHeadService.php index 466e2a4..317368f 100644 --- a/src/Service/MelisFrontHeadService.php +++ b/src/Service/MelisFrontHeadService.php @@ -105,37 +105,39 @@ public function updateTitleAndDescription($idPage, $contentGenerated) /** * Canonical Tag */ - $canonicalUrl = addslashes($datasPageSeo->pseo_canonical); - $canonicalUrl = str_replace("\'", "'", $canonicalUrl); - if ($canonicalUrl != '') { - $canonicalUrlTag = "\n\n"; - $canonicalRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; - preg_match($canonicalRegex, $contentGenerated, $canonicalFound); - if(!empty($canonicalFound)){ - $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated); - }else { - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated); - } - $contentGenerated = $newContent; - }else{ - /** - * @var MelisTreeService - */ - $pageService = $this->serviceLocator->get('MelisEngineTree'); - $pageUrl = $pageService->getPageLink($idPage); + if(isset($datasPageSeo->pseo_canonical)){ + $canonicalUrl = addslashes($datasPageSeo->pseo_canonical); + $canonicalUrl = str_replace("\'", "'", $canonicalUrl); + if ($canonicalUrl != '') { + $canonicalUrlTag = "\n\n"; + $canonicalRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; + preg_match($canonicalRegex, $contentGenerated, $canonicalFound); + if(!empty($canonicalFound)){ + $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated); + }else { + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated); + } + $contentGenerated = $newContent; + }else{ + /** + * @var MelisTreeService + */ + $pageService = $this->serviceLocator->get('MelisEngineTree'); + $pageUrl = $pageService->getPageLink($idPage); - $canonicalUrlTag = "\n\n"; - $canonicalRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; - preg_match($canonicalRegex, $contentGenerated, $canonicalFound); - if(!empty($canonicalFound)){ - $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated); - }else { - $headRegex = '/(]*>)/im'; - $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated); - } - $contentGenerated = $newContent; + $canonicalUrlTag = "\n\n"; + $canonicalRegex = '/(]*name=[\"\']description[\"\'][^>]*content=[\"\'](.*?)[\"\'][^>]*>)/i'; + preg_match($canonicalRegex, $contentGenerated, $canonicalFound); + if(!empty($canonicalFound)){ + $newContent = preg_replace($canonicalRegex, $canonicalUrlTag, $contentGenerated); + }else { + $headRegex = '/(]*>)/im'; + $newContent = preg_replace($headRegex, "$1$canonicalUrlTag", $contentGenerated); + } + $contentGenerated = $newContent; + } } } diff --git a/view/melis-front/plugins/mini-template-default.phtml b/view/melis-front/plugins/mini-template-default.phtml new file mode 100644 index 0000000..41b1c3d --- /dev/null +++ b/view/melis-front/plugins/mini-template-default.phtml @@ -0,0 +1,13 @@ +fromDragDropZone) { + $width = "$this->widthDesktop $this->widthTablet $this->widthMobile"; + $div = '