Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .zip
Binary file not shown.
Empty file modified CHANGELOG.md
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<tag name="kernel.event_subscriber"/>
</service>

<service id="rewriteurl.request.listener" class="RewriteUrl\EventListeners\RequestListener">
<tag name="kernel.event_subscriber"/>
</service>

<service id="rewriteurl.kernel.exception" class="RewriteUrl\EventListeners\KernelExceptionListener">
<argument type="service" id="request_stack" />
<tag name="kernel.event_subscriber"/>
Expand Down
13 changes: 13 additions & 0 deletions Config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
<route id="rewrite.url.config.set-rewriting_enable" path="/admin/module/RewriteUrl/config/setRewritingEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setRewritingEnableAction</default>
</route>

<!-- INDEX-REDIRECTION-ENABLE ROUTE -->
<route id="rewrite.url.config.set-index-redirection_enable" path="/admin/module/RewriteUrl/config/setIndexRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setIndexRedirectionEnableAction</default>
</route>
<!-- ############################# -->

<!-- HTTPS-REDIRECTION-ENABLE ROUTE -->
<route id="rewrite.url.config.set-https-redirection_enable" path="/admin/module/RewriteUrl/config/setHttpsRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setHttpsRedirectionEnableAction</default>
</route>
<!-- ############################# -->

Comment on lines +16 to +28

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- INDEX-REDIRECTION-ENABLE ROUTE -->
<route id="rewrite.url.config.set-index-redirection_enable" path="/admin/module/RewriteUrl/config/setIndexRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setIndexRedirectionEnableAction</default>
</route>
<!-- ############################# -->
<!-- HTTPS-REDIRECTION-ENABLE ROUTE -->
<route id="rewrite.url.config.set-https-redirection_enable" path="/admin/module/RewriteUrl/config/setHttpsRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setHttpsRedirectionEnableAction</default>
</route>
<!-- ############################# -->
<route id="rewrite.url.config.set-index-redirection_enable" path="/admin/module/RewriteUrl/config/setIndexRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setIndexRedirectionEnableAction</default>
</route>
<route id="rewrite.url.config.set-https-redirection_enable" path="/admin/module/RewriteUrl/config/setHttpsRedirectionEnable">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::setHttpsRedirectionEnableAction</default>
</route>

<route id="rewrite.url.rule.add" path="/admin/module/RewriteUrl/rule/add">
<default key="_controller">RewriteUrl\Controller\Admin\ModuleConfigController::addRuleAction</default>
</route>
Expand Down
Empty file modified Config/schema.xml
100644 → 100755
Empty file.
Empty file modified Config/sqldb.map
100644 → 100755
Empty file.
Empty file modified Config/thelia.sql
100644 → 100755
Empty file.
Empty file modified Config/update/1.4.8.sql
100644 → 100755
Empty file.
Empty file modified Config/update/1.5.0.sql
100644 → 100755
Empty file.
51 changes: 41 additions & 10 deletions Controller/Admin/ModuleConfigController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,

]
);
}
Expand Down Expand Up @@ -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()
Expand Down
Empty file modified Controller/Admin/NotRewritenUrlsAdminController.php
100644 → 100755
Empty file.
Empty file modified EventListeners/KernelExceptionListener.php
100644 → 100755
Empty file.
56 changes: 56 additions & 0 deletions EventListeners/RequestListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace RewriteUrl\EventListeners;

use RewriteUrl\RewriteUrl;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Model\ConfigQuery;


class RequestListener implements EventSubscriberInterface
{
public function redirect(GetResponseEvent $event)
{
$fullPath = $event->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"],
];
}
}
Empty file modified Hook/ConfigurationHook.php
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions I18n/backOffice/default/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ',
Expand Down
Empty file modified I18n/fr_FR.php
100644 → 100755
Empty file.
Empty file modified Loop/NotRewritenUrlCategoryLoop.php
100644 → 100755
Empty file.
Empty file modified Loop/RewriteUrlRuleLoop.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewriteurlRule.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewriteurlRuleParam.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewriteurlRuleParamQuery.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewriteurlRuleQuery.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewritingRedirectType.php
100644 → 100755
Empty file.
Empty file modified Model/Base/RewritingRedirectTypeQuery.php
100644 → 100755
Empty file.
Empty file modified Model/Map/RewriteurlRuleParamTableMap.php
100644 → 100755
Empty file.
Empty file modified Model/Map/RewriteurlRuleTableMap.php
100644 → 100755
Empty file.
Empty file modified Model/Map/RewritingRedirectTypeTableMap.php
100644 → 100755
Empty file.
Empty file modified Model/RewriteurlRule.php
100644 → 100755
Empty file.
Empty file modified Model/RewriteurlRuleParam.php
100644 → 100755
Empty file.
Empty file modified Model/RewriteurlRuleParamQuery.php
100644 → 100755
Empty file.
Empty file modified Model/RewriteurlRuleQuery.php
100644 → 100755
Empty file.
Empty file modified Model/RewritingRedirectType.php
100644 → 100755
Empty file.
Empty file modified Model/RewritingRedirectTypeQuery.php
100644 → 100755
Empty file.
Empty file modified Model/RewritingUrlOverride.php
100644 → 100755
Empty file.
Empty file modified Service/RewritingRouterFirst.php
100644 → 100755
Empty file.
Empty file modified Service/RewritingRouterLast.php
100644 → 100755
Empty file.
Empty file modified logo.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified screenshot/screenshot-1.jpeg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified screenshot/screenshot-2.jpeg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified screenshot/screenshot-3.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions templates/backOffice/default/RewriteUrl/module-configuration-js.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading