Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbbrioso28 committed Aug 7, 2019
2 parents bf6da20 + ea62d4c commit e2bb935
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 99 deletions.
24 changes: 13 additions & 11 deletions public/plugins/js/plugin.melisGdprBanner.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ window.MelisGdprBanner = (function () {
* @param options
*/
function setCookie(name, value, options = {}) {
let defaultOptions = {
var defaultOptions = {
path: '/',
expires: new Date(MAX_COOKIE_AGE).toUTCString()
};
Expand All @@ -29,8 +29,10 @@ window.MelisGdprBanner = (function () {
*
* src: https://zellwk.com/blog/looping-through-js-objects/
*/
options = Object.entries({...defaultOptions, ...options});
let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
options = Object.entries({...defaultOptions,...options
})
;
var updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
for (const [key, value] of options) {
updatedCookie += "; " + key + "=" + value;
}
Expand All @@ -39,7 +41,7 @@ window.MelisGdprBanner = (function () {
}

function getCookie(name) {
let matches = document.cookie.match(new RegExp(
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace("/([\.$?*|{}\(\)\[\]\\\/\+^])/g", '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
Expand All @@ -57,14 +59,14 @@ window.MelisGdprBanner = (function () {
deleteCookie: deleteCookie,
/** You can always set a different cookie name & banner container*/
cookieName: BANNER_COOKIE_NAME,
container: BANNER_CONTAINER,
container: BANNER_CONTAINER
};
})();

function melisGdprBanner_init(pluginId) {
if (pluginId === undefined) {
/** pluginId is initially "undefined" when the plugin is loaded in front */
let bannerContainer = $("." + MelisGdprBanner.container);
var bannerContainer = $("." + MelisGdprBanner.container);
if (bannerContainer.length > 0) {
bannerContainer.each(function () {
pluginId = this.id;
Expand All @@ -73,10 +75,10 @@ function melisGdprBanner_init(pluginId) {
}

if (typeof pluginId !== 'undefined' && pluginId) {
let banner = $("#" + pluginId);
let isBackOffice = banner.data("isBo");
var banner = $("#" + pluginId);
var isBackOffice = banner.data("isBo");

let bannerCookie = MelisGdprBanner.getCookie(MelisGdprBanner.cookieName);
var bannerCookie = MelisGdprBanner.getCookie(MelisGdprBanner.cookieName);
if (isBackOffice === false && bannerCookie === undefined) {
/** User's first visit: Declare banner cookie for this site */
MelisGdprBanner.setCookie(MelisGdprBanner.cookieName, "true");
Expand All @@ -91,11 +93,11 @@ function melisGdprBanner_init(pluginId) {
}

$(document).ready(function () {
let $body = $("body");
var $body = $("body");

/** Agree to the site's cookie policy */
$body.on('click', '.melis-gdpr-banner-agree', function () {
let banner = $body.find(this).data();
var banner = $body.find(this).data();

if (typeof banner.isBo !== 'undefined' && banner.isBo === false) {
MelisGdprBanner.setCookie(MelisGdprBanner.cookieName, false);
Expand Down
63 changes: 0 additions & 63 deletions src/Listener/MelisFrontSEODispatchRouterAbstractListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,67 +244,4 @@ public function detach(EventManagerInterface $events)
}
}
}
public function createTranslationsOfLoadedModules($e, $siteId,$locale = "en_EN")
{
// get serivce manager
$sm = $e->getApplication()->getServiceManager();
// get site table
$siteTable = $sm->get('MelisEngineTableSite');
// get site data
$site = $siteTable->getEntryById($siteId)->current();
// module name
$moduleName = $site->site_name;
// melis asset manager module service
$moduleSvc = $sm->get('MelisAssetManagerModulesService');
// get module path
$modulePath = $moduleSvc->getModulePath($moduleName);
// module load file
$moduleLoadFile = "module.load.php";
if (file_exists($modulePath . "/config/$moduleLoadFile")) {
// include file
$modules = include $modulePath . "/config/$moduleLoadFile" ?? [];
// set excluded modules
$excludedModules = [
'MelisAssetManager',
$moduleName
];
// remove exluded modules
$modules = array_diff($modules,$excludedModules);
if (! empty($modules)) {
// get translator
$translator = $sm->get('translator');
$translationType = array(
'interface',
'install',
'setup',
'forms',
'form'
);
// module config translation type
$translationList = array();
if(file_exists($_SERVER['DOCUMENT_ROOT'].'/../module/MelisModuleConfig/config/translation.list.php')){
$translationList = include 'module/MelisModuleConfig/config/translation.list.php';
}
$moduleTranslationsPath = [];
// create translations for every module that is loaded
foreach ($modules as $idx => $module) {
$modulePath = $moduleSvc->getModulePath($module);
foreach ($translationType as $type) {
$localeFile = "$locale.$type.php";
if (file_exists($modulePath. "/language/$localeFile")) {
// seperate into onther variable to avoid multiple loops
$moduleTranslationsPath[] = $modulePath. "/language/$localeFile";
}
}
}
if (! empty($moduleTranslationsPath)) {
foreach ($moduleTranslationsPath as $idx => $modulepath) {
$translator->addTranslationFile('phparray', $modulepath);
}
}

}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ function(MvcEvent $e){
$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);
// create translations for loaded modules
if ($routingResult['renderMode'] == 'front') {
$this->createTranslationsOfLoadedModules($e,$datasTemplate->tpl_site_id,$pageTree->lang_cms_locale);
}
$this->initSession($datasPage->getMelisTemplate()->tpl_zf2_website_folder);
}

Expand Down
76 changes: 76 additions & 0 deletions src/Listener/MelisFrontSEORouteListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Melis Technology (http://www.melistechnology.com)
*
* @copyright Copyright (c) 2016 Melis Technology (http://www.melistechnology.com)
*
*/

namespace MelisFront\Listener;

use Zend\ModuleManager\ModuleEvent;
use Zend\Mvc\Router\Http\Segment;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;


class MelisFrontSEORouteListener
{
public function onLoadModulesPost(ModuleEvent $e)
{
/** @var ServiceManager $sm */
$sm = $e->getParam('ServiceManager');
if(!empty($_SERVER['REQUEST_URI'])){
$uri = $_SERVER['REQUEST_URI'];

//we don't want listener to be executed if it's not a php code
preg_match('/.*\.((?!php).)+(?:\?.*|)$/i', $uri, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) > 1)
return;

//check if we are in front
if ($uri != 'melis')
{
// get request
$request = $sm->get('request');
// get uri
$uri = $request->getUri();
$url = $uri->getPath();
// remove slash on first
$url = preg_replace('/\//i',null,$url,1);
// get the url parameters
$urlParams = $request->getQuery()->toString();
if (! empty($urlParams)) {
$urlParams = '?' . $urlParams;
}
// Trying to find an URL in Melis SEO
$melisTablePageSeo = $sm->get('MelisEngineTablePageSeo');
$datasPageSeo = $melisTablePageSeo->getEntryByField('pseo_url', $url);
if (!empty($datasPageSeo)) {
// get page seo data
$datasPageSeo = $datasPageSeo->current();
if (!empty($datasPageSeo)) {
// get router
$router = $sm->get('router');
// Creating dynamicaly the route and the params that are needed in the regular melis routing
$route = Segment::factory(array(
'route' => '/' . $url,
'defaults' => array(
'controller' => 'MelisFront\Controller\Index',
'action' => 'index',
'idpage' => $datasPageSeo->pseo_id,
'renderType' => 'melis_zf2_mvc',
'renderMode' => 'front',
'preview' => false,
'urlparams' => $urlParams,
)
));
// add the route to the router
$router->addRoute('melis-front-page-seo', $route);
}
}
}
}
}
}
30 changes: 16 additions & 14 deletions src/Listener/MelisFrontSiteConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ public function onLoadModulesPost(ModuleEvent $e)
*/
$siteTable = $serviceManager->get('MelisEngineTableSite');
$siteData = $siteTable->getEntryById($siteId)->current();
/**
* 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($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]);
}
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use MelisFront\Listener\MelisFrontMinifiedAssetsCheckerListener;
use MelisFront\Listener\MelisFrontMiniTemplateConfigListener;
use MelisFront\Listener\MelisFrontPluginLangSessionUpdateListener;
use MelisFront\Listener\MelisFrontSEORouteListener;
use MelisFront\Listener\MelisFrontSiteConfigListener;
use Zend\ModuleManager\ModuleEvent;
use Zend\Mvc\ModuleRouteListener;
Expand Down Expand Up @@ -46,6 +47,11 @@ public function init(ModuleManager $moduleManager)
* get the site config (merged with db)
*/
$events->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, array(new MelisFrontSiteConfigListener, 'onLoadModulesPost'));
/**
* - Catching PAGE SEO URLs to update Router
* > create SEO route first so the modules can have a route match in creating translations
*/
$events->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, array(new MelisFrontSEORouteListener(), 'onLoadModulesPost'));
}

public function onBootstrap(MvcEvent $e)
Expand Down Expand Up @@ -84,7 +90,7 @@ public function onBootstrap(MvcEvent $e)
if(!$isBackOffice)
{
// Catching PAGE SEO URLs to update Router
$eventManager->attach(new MelisFrontSEOReformatToRoutePageUrlListener());
//$eventManager->attach(new MelisFrontSEOReformatToRoutePageUrlListener()); -> refer init() Listener: MelisFrontSEORouteListener, issueL no translations of melis-modules

// Adding css linked to the page
$eventManager->attach(new MelisFrontAttachCssListener());
Expand Down Expand Up @@ -181,7 +187,10 @@ public function createTranslations($e, $routeMatch)

$sm = $e->getApplication()->getServiceManager();
$translator = $sm->get('translator');
$translator->addTranslationFile('phparray', $transPath);
if (file_exists($transPath)){
$translator->addTranslationFile('phparray', $transPath);
}

}
}

Expand Down
27 changes: 22 additions & 5 deletions src/View/Helper/SiteConfigViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace MelisFront\View\Helper;

use MelisFront\Service\MelisSiteConfigService;
use Zend\Http\Request;
use Zend\View\Helper\AbstractHelper;


Expand Down Expand Up @@ -44,14 +45,30 @@ public function __invoke($key, $section = null, $language = null)
$routeMatch = $router->match($request);
$params = $routeMatch->getParams();

$pageId = null;

if (!empty($params['idpage']))
$pageId = $params['idpage'];
//if page id is still empty, try to get it on the post
$postVal = $request->getPost();
if(empty($pageId) && !empty($postVal['idpage'])){
$pageId = $postVal['idpage'];
}
if(empty($pageId) && !empty($postVal['pageId'])){
$pageId = $postVal['pageId'];
}

/**
* check page id
* if page id is still empty, try on get
*/
if(!empty($params['idpage'])){
$pageId = $params['idpage'];
}else{
$pageId = (!empty($_GET['pageId'])) ? $_GET['pageId'] : $_POST['pageId'];
$getValue = $request->getQuery();
if(empty($pageId) && !empty($getValue['idpage'])){
$pageId = $getValue['idpage'];
}
if(empty($pageId) && !empty($getValue['pageId'])){
$pageId = $getValue['pageId'];
}

/** @var MelisSiteConfigService $siteConfigSrv */
$siteConfigSrv = $this->serviceManager->get('MelisSiteConfigService');
$config = $siteConfigSrv->getSiteConfigByKey($key, $pageId, $section, $language);
Expand Down

0 comments on commit e2bb935

Please sign in to comment.