| Server IP : 85.158.181.41 / Your IP : 216.73.217.12 Web Server : Apache System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64 User : moncbefd ( 1024) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/moncbefd/www.moneta.at/GXEngine/Shared/ |
Upload File : |
<?php
/* --------------------------------------------------------------
UrlRewrite.inc.php 2016-05-02
Gambio GmbH
http://www.gambio.de
Copyright (c) 2016 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
/**
* UrlRewrite
*
* @category System
* @package Shared
*/
class UrlRewrite
{
/**
* Holds the content type as a string.
*
* @var string
*/
protected $contentType;
/**
* Holds the content ID as integer.
*
* @var int
*/
protected $contentId;
/**
* Holds the language ID as integer.
*
* @var int
*/
protected $languageId;
/**
* Holds the rewritten URL as string.
*
* @var string
*/
protected $rewriteUrl;
/**
* Holds the original target URL as string.
*
* @var string
*/
protected $targetUrl;
/**
* UrlRewrite constructor.
*
* @param NonEmptyStringType $contentType
* @param IdType $contentId
* @param IdType $languageId
* @param NonEmptyStringType $rewriteUrl
* @param NonEmptyStringType $targetUrl
*/
public function __construct(
NonEmptyStringType $contentType,
IdType $contentId,
IdType $languageId,
NonEmptyStringType $rewriteUrl,
NonEmptyStringType $targetUrl
) {
$this->contentType = $contentType->asString();
$this->contentId = $contentId->asInt();
$this->languageId = $languageId->asInt();
$this->rewriteUrl = $this->_sanitizeUrl($rewriteUrl);
$this->targetUrl = $targetUrl->asString();
}
/**
* @return string
*/
public function getContentType()
{
return $this->contentType;
}
/**
* @return int
*/
public function getContentId()
{
return $this->contentId;
}
/**
* @return int
*/
public function getLanguageId()
{
return $this->languageId;
}
/**
* @return string
*/
public function getRewriteUrl()
{
return $this->rewriteUrl;
}
/**
* @return string
*/
public function getTargetUrl()
{
return $this->targetUrl;
}
/**
* Filters a string allowing the characters a-z, 0-9, - and /.
* Similar characters are mapped to its latin equivalent.
*
* @param NonEmptyStringType $rewriteUrl
*
* @return string
*/
protected function _sanitizeUrl(NonEmptyStringType $rewriteUrl)
{
$search = [
'ä',
'Ä',
'ö',
'Ö',
'ü',
'Ü',
'ä',
'Ä',
'ö',
'Ö',
'ü',
'Ü',
'ß',
'ß'
];
$replace = ['ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'ae', 'Ae', 'oe', 'Oe', 'ue', 'Ue', 'ss', 'ss'];
$string = str_replace($search, $replace, $rewriteUrl->asString());
$search = [
'А',
'Б',
'В',
'Г',
'Д',
'Е',
'Ё',
'Ж',
'З',
'И',
'Й',
'К',
'Л',
'М',
'Н',
'О',
'П',
'Р',
'С',
'Т',
'У',
'Ф',
'Х',
'Ц',
'Ч',
'Ш',
'Щ',
'Ъ',
'Ы',
'Ь',
'Э',
'Ю',
'Я',
'а',
'б',
'в',
'г',
'д',
'е',
'ё',
'ж',
'з',
'и',
'й',
'к',
'л',
'м',
'н',
'о',
'п',
'р',
'с',
'т',
'у',
'ф',
'х',
'ц',
'ч',
'ш',
'щ',
'ъ',
'ы',
'ь',
'э',
'ю',
'я'
];
$replace = [
'A',
'B',
'W',
'G',
'D',
'Ie',
'Io',
'Z',
'Z',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'R',
'S',
'T',
'U',
'F',
'Ch',
'C',
'Tch',
'Sh',
'Shtch',
'',
'Y',
'',
'E',
'Iu',
'Ia',
'a',
'b',
'w',
'g',
'd',
'ie',
'io',
'z',
'z',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'r',
's',
't',
'u',
'f',
'ch',
'c',
'tch',
'sh',
'shtch',
'',
'y',
'',
'e',
'iu',
'ia'
];
$string = str_replace($search, $replace, $string);
$search = [
'Á',
'À',
'Â',
'Ä',
'Ă',
'Ā',
'Ã',
'Å',
'Ą',
'Æ',
'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'E',
'G',
'G',
'G',
'G',
'G',
'a',
'a',
'a',
'a',
'a',
'a',
'a',
'a',
'a',
'ae',
'c',
'c',
'c',
'c',
'c',
'd',
'd',
'd',
'e',
'e',
'e',
'e',
'e',
'e',
'e',
'e',
'g',
'g',
'g',
'g',
'g',
'H',
'H',
'I',
'I',
'I',
'I',
'I',
'I',
'I',
'I',
'IJ',
'J',
'K',
'L',
'L',
'N',
'N',
'N',
'N',
'O',
'O',
'O',
'O',
'O',
'O',
'O',
'O',
'CE',
'h',
'h',
'i',
'i',
'i',
'i',
'i',
'i',
'i',
'i',
'ij',
'j',
'k',
'l',
'l',
'n',
'n',
'n',
'n',
'o',
'o',
'o',
'o',
'o',
'o',
'o',
'o',
'o',
'R',
'R',
'S',
'S',
'S',
'S',
'T',
'T',
'T',
'U',
'U',
'U',
'U',
'U',
'U',
'U',
'U',
'U',
'U',
'W',
'Y',
'Y',
'Y',
'Z',
'Z',
'Z',
'r',
'r',
's',
's',
's',
's',
'B',
't',
't',
'b',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'u',
'w',
'y',
'y',
'y',
'z',
'z',
'z'
];
$string = str_replace($search, $replace, $string);
$string = strtolower($string);
$string = preg_replace('/[^a-z0-9\/]/', '-', $string);
$string = preg_replace('/--+/', '-', $string);
$string = preg_replace('/^-(.+)/', "$1", $string);
$string = preg_replace('/(.+)-$/', "$1", $string);
return $string;
}
}