diff --git a/.zip b/.zip new file mode 100644 index 0000000..6101221 Binary files /dev/null and b/.zip differ diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/Config/config.xml b/Config/config.xml index 0e2de2a..96de8ee 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -22,6 +22,10 @@ + + + + diff --git a/Config/routing.xml b/Config/routing.xml index 8db07fa..fd9f731 100755 --- a/Config/routing.xml +++ b/Config/routing.xml @@ -13,6 +13,19 @@ RewriteUrl\Controller\Admin\ModuleConfigController::setRewritingEnableAction + + + + RewriteUrl\Controller\Admin\ModuleConfigController::setIndexRedirectionEnableAction + + + + + + RewriteUrl\Controller\Admin\ModuleConfigController::setHttpsRedirectionEnableAction + + + RewriteUrl\Controller\Admin\ModuleConfigController::addRuleAction diff --git a/Config/schema.xml b/Config/schema.xml old mode 100644 new mode 100755 diff --git a/Config/sqldb.map b/Config/sqldb.map old mode 100644 new mode 100755 diff --git a/Config/thelia.sql b/Config/thelia.sql old mode 100644 new mode 100755 diff --git a/Config/update/1.4.8.sql b/Config/update/1.4.8.sql old mode 100644 new mode 100755 diff --git a/Config/update/1.5.0.sql b/Config/update/1.5.0.sql old mode 100644 new mode 100755 diff --git a/Controller/Admin/ModuleConfigController.php b/Controller/Admin/ModuleConfigController.php old mode 100644 new mode 100755 index 4e9fe0a..d7e371d --- a/Controller/Admin/ModuleConfigController.php +++ b/Controller/Admin/ModuleConfigController.php @@ -7,6 +7,7 @@ use RewriteUrl\Model\RewriteurlRuleParam; use RewriteUrl\Model\RewriteurlRuleQuery; use RewriteUrl\RewriteUrl; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\HttpFoundation\JsonResponse; use Thelia\Core\Security\AccessManager; @@ -23,11 +24,16 @@ public function viewConfigAction($params = array()) } $isRewritingEnabled = ConfigQuery::isRewritingEnable(); + $isIndexRedirectionEnabled = RewriteUrl::getConfigValue("index_redirection_enable"); + $isHttpsRedirectionEnabled = RewriteUrl::getConfigValue("https_redirection_enable"); return $this->render( "RewriteUrl/module-configuration", [ - "isRewritingEnabled" => $isRewritingEnabled + "isRewritingEnabled" => $isRewritingEnabled, + "isIndexRedirectionEnabled" => $isIndexRedirectionEnabled, + "isHttpsRedirectionEnabled" => $isHttpsRedirectionEnabled, + ] ); } @@ -124,16 +130,41 @@ public function setRewritingEnableAction() $request = $this->getRequest()->request; $isRewritingEnable = $request->get("rewriting_enable", null); - if ($isRewritingEnable !== null) { - ConfigQuery::write("rewriting_enable", $isRewritingEnable ? 1 : 0); - return $this->jsonResponse(json_encode(["state" => "Success"]), 200); - } else { - return $this->jsonResponse(Translator::getInstance()->trans( - "Unable to change the configuration variable.", - [], - RewriteUrl::MODULE_DOMAIN - ), 500); + if ($isRewritingEnable === null) { + + throw new BadRequestHttpException('Unable to change the configuration variable.'); } + ConfigQuery::write("rewriting_enable", $isRewritingEnable ? 1 : 0); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + + } + + public function setIndexRedirectionEnableAction() + { + $request = $this->getRequest()->request; + $isIndexRedirectionEnable = $request->get("index_redirection_enable", null); + + if ($isIndexRedirectionEnable === null) { + + throw new BadRequestHttpException('Missing index_redirection_enable parameter in url'); + } + RewriteUrl::setConfigValue("index_redirection_enable", $isIndexRedirectionEnable); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + + } + + public function setHttpsRedirectionEnableAction() + { + $request = $this->getRequest()->request; + $isHttpsRedirectionEnable = $request->get("https_redirection_enable", null); + + if ($isHttpsRedirectionEnable === null) { + + throw new BadRequestHttpException('Missing https_redirection_enable parameter in url'); + } + RewriteUrl::setConfigValue("https_redirection_enable", $isHttpsRedirectionEnable); + return $this->jsonResponse(json_encode(["state" => "Success"]), 200); + } public function addRuleAction() diff --git a/Controller/Admin/NotRewritenUrlsAdminController.php b/Controller/Admin/NotRewritenUrlsAdminController.php old mode 100644 new mode 100755 diff --git a/EventListeners/KernelExceptionListener.php b/EventListeners/KernelExceptionListener.php old mode 100644 new mode 100755 diff --git a/EventListeners/RequestListener.php b/EventListeners/RequestListener.php new file mode 100755 index 0000000..74b5033 --- /dev/null +++ b/EventListeners/RequestListener.php @@ -0,0 +1,56 @@ +getRequest()->getUri(); + $regexToMatch = "^\/index.php^"; + + /** permanently redirect request if url contain $regexToMatch string */ + + if (RewriteUrl::getConfigValue("index_redirection_enable")) + { + if (preg_match($regexToMatch, $fullPath)) + { + $newPath = preg_replace($regexToMatch, "", $fullPath) ; + $event->setResponse(new RedirectResponse( + $newPath, + 301 + )); + } + } + + /** permanently redirect http to https protocol */ + + if (RewriteUrl::getConfigValue("https_redirection_enable")) + { + if (!$event->getRequest()->isSecure()) + { + $securePath = preg_replace("/^http:/i", "https:", $fullPath) ; + $event->setResponse(new RedirectResponse( + $securePath, + 301 + )); + } + } + } + + public static function getSubscribedEvents() + { + return + [ + KernelEvents::REQUEST => ["redirect"], + ]; + } +} \ No newline at end of file diff --git a/Hook/ConfigurationHook.php b/Hook/ConfigurationHook.php old mode 100644 new mode 100755 diff --git a/I18n/backOffice/default/fr_FR.php b/I18n/backOffice/default/fr_FR.php index 6757470..ef2c22d 100755 --- a/I18n/backOffice/default/fr_FR.php +++ b/I18n/backOffice/default/fr_FR.php @@ -29,6 +29,10 @@ 'Do you really want to delete the url %html ?' => 'Voulez-vous vraiment supprimer l\'url %html ?', 'Edit information in %lng' => 'Modifier l\'information en %lng', 'Enable URL rewriting' => 'Activer la réécriture d\'URL', + 'Enable index.php redirection' => 'Activer la redirection d\'index.php', + 'Enable https redirection' => 'Activer la redirection HTTPS', + 'Auto redirect http to https protocol' => 'Rediriger automatiquement vers les adresses HTTPS', + 'URL which contain index.php will be erased' => 'Les url contenants "index.php" seront redirigées', 'Enter a URL with a leading \'/\' and no domain name. Ex : for \'www.mysite.com/one/two\', enter \'/one/two\'.' => 'Saisissez une URL commençant par un \'/\' et sans nom de domaine. Ex : pour \'www.monsite.com/un/deux\', saisissez \'/un/deux\'.', 'Enter new rule position' => 'Saisir une nouvelle position de règle', 'Error this url already exist you can reassign by follow this ' => 'Erreur cette url existe déjà, vous pouvez la réassigner en suivant ce ', diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php old mode 100644 new mode 100755 diff --git a/Loop/NotRewritenUrlCategoryLoop.php b/Loop/NotRewritenUrlCategoryLoop.php old mode 100644 new mode 100755 diff --git a/Loop/RewriteUrlRuleLoop.php b/Loop/RewriteUrlRuleLoop.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRule.php b/Model/Base/RewriteurlRule.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleParam.php b/Model/Base/RewriteurlRuleParam.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleParamQuery.php b/Model/Base/RewriteurlRuleParamQuery.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewriteurlRuleQuery.php b/Model/Base/RewriteurlRuleQuery.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewritingRedirectType.php b/Model/Base/RewritingRedirectType.php old mode 100644 new mode 100755 diff --git a/Model/Base/RewritingRedirectTypeQuery.php b/Model/Base/RewritingRedirectTypeQuery.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewriteurlRuleParamTableMap.php b/Model/Map/RewriteurlRuleParamTableMap.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewriteurlRuleTableMap.php b/Model/Map/RewriteurlRuleTableMap.php old mode 100644 new mode 100755 diff --git a/Model/Map/RewritingRedirectTypeTableMap.php b/Model/Map/RewritingRedirectTypeTableMap.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRule.php b/Model/RewriteurlRule.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleParam.php b/Model/RewriteurlRuleParam.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleParamQuery.php b/Model/RewriteurlRuleParamQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewriteurlRuleQuery.php b/Model/RewriteurlRuleQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewritingRedirectType.php b/Model/RewritingRedirectType.php old mode 100644 new mode 100755 diff --git a/Model/RewritingRedirectTypeQuery.php b/Model/RewritingRedirectTypeQuery.php old mode 100644 new mode 100755 diff --git a/Model/RewritingUrlOverride.php b/Model/RewritingUrlOverride.php old mode 100644 new mode 100755 diff --git a/Service/RewritingRouterFirst.php b/Service/RewritingRouterFirst.php old mode 100644 new mode 100755 diff --git a/Service/RewritingRouterLast.php b/Service/RewritingRouterLast.php old mode 100644 new mode 100755 diff --git a/logo.jpg b/logo.jpg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-1.jpeg b/screenshot/screenshot-1.jpeg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-2.jpeg b/screenshot/screenshot-2.jpeg old mode 100644 new mode 100755 diff --git a/screenshot/screenshot-3.png b/screenshot/screenshot-3.png old mode 100644 new mode 100755 diff --git a/templates/backOffice/default/RewriteUrl/module-configuration-js.html b/templates/backOffice/default/RewriteUrl/module-configuration-js.html old mode 100644 new mode 100755 index 12ec175..0d886ac --- a/templates/backOffice/default/RewriteUrl/module-configuration-js.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration-js.html @@ -41,6 +41,47 @@ }); }); + /** index.php redirection ajax request */ + $(".js_switch_index_redirection").on("switch-change", function (event, data) { + $loader.show(); + var checkbox = $(this); + + $.ajax({ + url : '{url path="/admin/module/RewriteUrl/config/setIndexRedirectionEnable"}', + data : { index_redirection_enable : (data.value ? 1 : 0) }, + type : 'post', + success : function(){ + $loader.hide(); + location.reload() + }, + error : function(jqXHR, textStatus, errorThrown) { + $alertError.html(jqXHR.responseText); + checkbox.bootstrapSwitch('toggleState', true); + $loader.hide(); + } + }); + }); + + /** https redirection ajax request */ + $(".js_switch_https_redirection").on("switch-change", function (event, data) { + $loader.show(); + var checkbox = $(this); + + $.ajax({ + url : '{url path="/admin/module/RewriteUrl/config/setHttpsRedirectionEnable"}', + data : { https_redirection_enable : (data.value ? 1 : 0) }, + type : 'post', + success : function(){ + $loader.hide(); + location.reload() + }, + error : function(jqXHR, textStatus, errorThrown) { + $alertError.html(jqXHR.responseText); + checkbox.bootstrapSwitch('toggleState', true); + $loader.hide(); + } + }); + }); $('.js_editable_rule_position').editable({ diff --git a/templates/backOffice/default/RewriteUrl/module-configuration.html b/templates/backOffice/default/RewriteUrl/module-configuration.html old mode 100644 new mode 100755 index c55bb42..45f5bb5 --- a/templates/backOffice/default/RewriteUrl/module-configuration.html +++ b/templates/backOffice/default/RewriteUrl/module-configuration.html @@ -25,106 +25,128 @@ {hook name="module.configuration" location="module_configuration" modulecode="$module_code"} -
-
-
-
-
-
- -
- -
-
- {intl l="Set the config variable 'rewriting_enable'"} + +
+
+
+
+ +
+
+ {intl l="Set the config variable 'rewriting_enable'"} +
+
+ + {* index.php redirection switch *} +
+
+
+ +
+ +
+
+ {intl l="URL which contain index.php will be erased"} +
+
+ {* end of index.php redirection switch *} + + {* https redirection switch *} +
+
+
+ +
+ +
+
+ {intl l="Auto redirect http to https protocol"} +
+
+ {* end of https redirection switch *} - - -
-
-
- {intl l="Rule management"} -
+
+
+
+ {intl l="Rule management"}
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- / - - / -
- -
- -
-
- - - - - - -

{intl l="Currently enabled rules"}


- - - - - - - - - - - - -
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ / + + / +
+ +
+ +
+
+ + + + + + +

{intl l="Currently enabled rules"}


+ + + + + + + + + + + + +
+
-
-