Skip to content

Commit

Permalink
Merge pull request #5 from melisplatform/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
benborla authored Feb 14, 2019
2 parents 6147465 + 2e5e9ca commit e36a27a
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 35 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion config/plugins/MelisFrontBlockSectionPlugin.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

),
),
Expand Down
38 changes: 38 additions & 0 deletions config/plugins/MiniTemplatePlugin.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
return array(
'front' => 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(),
),
);
5 changes: 5 additions & 0 deletions language/en_EN.interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'

);
?>
4 changes: 4 additions & 0 deletions language/fr_FR.interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@

'tr_front_plugin_search_pagination_nbPerPage tooltip' => 'Nombre de résultats s&#39;affichant sur une même page',
'tr_front_plugin_search_pagination_nbPageBeforeAfter tooltip' => 'L&#39;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'
);
?>
4 changes: 3 additions & 1 deletion public/plugins/css/plugin.melisdragdropzone.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
border: 1px dashed #de7d79;
border-radius: 4px;
bottom: -25px;
width: inherit;
}

.melis-dragdropzone:after {
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion src/Controller/MelisPluginRendererController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
56 changes: 56 additions & 0 deletions src/Controller/Plugin/MiniTemplatePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace MelisFront\Controller\Plugin;


/**
* This plugin implements the business logic of the
* "Tag" plugin.
*
* Please look inside app.plugins.php for possible awaited parameters
* in front and back function calls.
*
* front() and back() are the only functions to create / update.
* front() generates the website view
* back() generates the plugin view in template edition mode (TODO)
*
* Configuration can be found in $pluginConfig / $pluginFrontConfig / $pluginBackConfig
* Configuration is automatically merged with the parameters provided when calling the plugin.
* Merge detects automatically from the route if rendering must be done for front or back.
*
* How to call this plugin without parameters:
* $plugin = $this->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;
}
}
48 changes: 47 additions & 1 deletion src/Listener/MelisFrontSEODispatchRouterRegularUrlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<p>Controller :[ <strong>" . $controller . "</strong> ] found in Module : [ <strong>{$siteModule}</strong> ]but </p> ";
echo "<p>action: [ <strong>" . $action . "</strong> ] not found in Controller : [ <strong>{$controllerClassName}</strong> ]</p>";
die;// die because we dont want to show errors everywhere
}
} else {
echo "<p>Controller : [ <strong>" . $controller . "</strong> ] not found in Module : [ <strong>{$siteModule}</strong> ]</p>";
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 = "<p>Controller [ <strong>{$controller}</strong> ] and action [ <strong>{$action}</strong> ] found but</p>";
$message2 = "<p>layout / template: [ <strong>{$templateName}</strong> ] not found in Module : [ <strong>{$siteModule}</strong> ]</p>";
echo $message1 . $message2;
die; // die because we dont want to show errors everywhere
}
}
}
}
},
100);
Expand Down
82 changes: 82 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}

}
Loading

0 comments on commit e36a27a

Please sign in to comment.