[11/06/2024] Les premières modifs + installation de quelques modules indispensables
This commit is contained in:
104
domokits/local/modules/RewriteUrl/Model/RewriteurlRule.php
Normal file
104
domokits/local/modules/RewriteUrl/Model/RewriteurlRule.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Thelia package.
|
||||
* http://www.thelia.net
|
||||
*
|
||||
* (c) OpenStudio <info@thelia.net>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewriteurlRule as BaseRewriteurlRule;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
class RewriteurlRule extends BaseRewriteurlRule
|
||||
{
|
||||
use PositionManagementTrait;
|
||||
|
||||
/** @var string */
|
||||
public const TYPE_REGEX = 'regex';
|
||||
|
||||
/** @var string */
|
||||
public const TYPE_GET_PARAMS = 'params';
|
||||
|
||||
/** @var string */
|
||||
public const TYPE_REGEX_GET_PARAMS = 'regex-params';
|
||||
|
||||
/** @var string */
|
||||
public const TYPE_TEXT = 'text';
|
||||
|
||||
protected $rewriteUrlParamCollection = null;
|
||||
|
||||
/**
|
||||
* @return \Propel\Runtime\Collection\ObjectCollection|RewriteurlRuleParam[]
|
||||
*/
|
||||
public function getRewriteUrlParamCollection()
|
||||
{
|
||||
if ($this->rewriteUrlParamCollection === null) {
|
||||
$this->rewriteUrlParamCollection = RewriteurlRuleParamQuery::create()->filterByIdRule($this->getId())->find();
|
||||
}
|
||||
|
||||
return $this->rewriteUrlParamCollection;
|
||||
}
|
||||
|
||||
protected function isMatchingPath(string $url): bool
|
||||
{
|
||||
if (!empty($this->getValue())) {
|
||||
try {
|
||||
$match = @preg_match('/' . $this->getValue() . '/', $url);
|
||||
|
||||
if (false === $match) {
|
||||
Tlog::getInstance()->error('Invalid pattern: ' . $this->getValue());
|
||||
}
|
||||
|
||||
return (bool)$match;
|
||||
} catch (\Exception $ex) {
|
||||
Tlog::getInstance()->error('Failed to match rule : ' . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function isMatchingGetParams(array $getParamArray): bool
|
||||
{
|
||||
if ($this->getRewriteUrlParamCollection()->count() === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->getRewriteUrlParamCollection() as $rewriteUrlParam) {
|
||||
if (!$rewriteUrlParam->isMatching($getParamArray)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isMatching(string $url, array $getParamArray): bool
|
||||
{
|
||||
if ($this->getRuleType() === self::TYPE_REGEX) {
|
||||
return $this->isMatchingPath($url);
|
||||
}
|
||||
|
||||
if ($this->getRuleType() === self::TYPE_GET_PARAMS) {
|
||||
return $this->isMatchingGetParams($getParamArray);
|
||||
}
|
||||
|
||||
if ($this->getRuleType() === self::TYPE_REGEX_GET_PARAMS) {
|
||||
return $this->isMatchingPath($url) && $this->isMatchingGetParams($getParamArray);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function deleteAllRelatedParam(): void
|
||||
{
|
||||
RewriteurlRuleParamQuery::create()->filterByIdRule($this->getId())->find()->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewriteurlRuleParam as BaseRewriteurlRuleParam;
|
||||
|
||||
class RewriteurlRuleParam extends BaseRewriteurlRuleParam
|
||||
{
|
||||
const PARAM_CONDITION_EQUALS = "equals";
|
||||
const PARAM_CONDITION_NOT_EQUALS = "not_equals";
|
||||
const PARAM_CONDITION_EXISTS = "exists";
|
||||
const PARAM_CONDITION_MISSING = "missing";
|
||||
const PARAM_CONDITION_EMPTY = "empty";
|
||||
const PARAM_CONDITION_NOT_EMPTY = "not_empty";
|
||||
|
||||
|
||||
public function isMatching($getParamArray)
|
||||
{
|
||||
if (array_key_exists($this->getParamName(), $getParamArray)) {
|
||||
$value = $getParamArray[$this->getParamName()];
|
||||
if (empty($value)) {
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_EMPTY) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_NOT_EMPTY) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($value == $this->getParamValue()) {
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_EQUALS) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_NOT_EQUALS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_EXISTS) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
if ($this->getParamCondition() === self::PARAM_CONDITION_MISSING) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewriteurlRuleParamQuery as BaseRewriteurlRuleParamQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'rewriteurl_rule_param' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
*/
|
||||
class RewriteurlRuleParamQuery extends BaseRewriteurlRuleParamQuery
|
||||
{
|
||||
|
||||
} // RewriteurlRuleParamQuery
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewriteurlRuleQuery as BaseRewriteurlRuleQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'rewriteurl_rule' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
*/
|
||||
class RewriteurlRuleQuery extends BaseRewriteurlRuleQuery
|
||||
{
|
||||
|
||||
} // RewriteurlRuleQuery
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewritingRedirectType as BaseRewritingRedirectType;
|
||||
|
||||
class RewritingRedirectType extends BaseRewritingRedirectType
|
||||
{
|
||||
const TEMPORARY = 302;
|
||||
const PERMANENT = 301;
|
||||
|
||||
/**
|
||||
* Default redirect type for a URL if there is no matching row in the RewritingRedirectType table
|
||||
*/
|
||||
const DEFAULT_REDIRECT_TYPE = RewritingRedirectType::PERMANENT;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use RewriteUrl\Model\Base\RewritingRedirectTypeQuery as BaseRewritingRedirectTypeQuery;
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'rewriting_redirect_type' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
*/
|
||||
class RewritingRedirectTypeQuery extends BaseRewritingRedirectTypeQuery
|
||||
{
|
||||
|
||||
} // RewritingRedirectTypeQuery
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the RewriteUrl module for Thelia. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace RewriteUrl\Model;
|
||||
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\RewritingUrl;
|
||||
use RewriteUrl\Model\RewritingRedirectType as ChildRewritingRedirectType;
|
||||
|
||||
/**
|
||||
* Class RewritingUrlOverride
|
||||
* @package RewriteUrl\Model
|
||||
* @author Gilles Bourgeat <gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class RewritingUrlOverride extends RewritingUrl
|
||||
{
|
||||
/**
|
||||
* disable the Thelia behavior
|
||||
*
|
||||
* @param ConnectionInterface $con
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null): void
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user