1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 16:54:44 +02:00
This commit is contained in:
Ryan Cramer
2024-07-05 11:35:51 -04:00
parent 2690115966
commit 36227dc778

View File

@@ -366,8 +366,6 @@ class Sanitizer extends Wire {
*/ */
public function nameFilter($value, array $allowedExtras, $replacementChar, $beautify = false, $maxLength = 128) { public function nameFilter($value, array $allowedExtras, $replacementChar, $beautify = false, $maxLength = 128) {
static $replacements = array();
if(!is_string($value)) $value = $this->string($value); if(!is_string($value)) $value = $this->string($value);
$allowed = array_merge($this->allowedASCII, $allowedExtras); $allowed = array_merge($this->allowedASCII, $allowedExtras);
$needsWork = strlen(str_replace($allowed, '', $value)); $needsWork = strlen(str_replace($allowed, '', $value));
@@ -376,27 +374,30 @@ class Sanitizer extends Wire {
if($beautify && $needsWork) { if($beautify && $needsWork) {
if($beautify === self::translate && $this->multibyteSupport) { if($beautify === self::translate && $this->multibyteSupport) {
$value = mb_strtolower($value); $value = mb_strtolower($value);
$replacements = array();
if(empty($replacements)) { if(empty($this->caches['nameFilterReplace'])) {
$modules = $this->wire()->modules; $modules = $this->wire()->modules;
if($modules) { if($modules) {
$configData = $this->wire()->modules->getModuleConfigData('InputfieldPageName'); $replacements = $this->wire()->modules->getConfig('InputfieldPageName', 'replacements');
$replacements = empty($configData['replacements']) ? InputfieldPageName::$defaultReplacements : $configData['replacements']; if(empty($replacements)) $replacements = InputfieldPageName::$defaultReplacements;
$this->caches['nameFilterReplace'] = $replacements;
} }
} else {
$replacements = $this->caches['nameFilterReplace'];
} }
foreach($replacements as $from => $to) { if(count($replacements)) {
if(mb_strpos($value, $from) !== false) { $value = str_replace(array_keys($replacements), array_values($replacements), $value);
$value = mb_eregi_replace($from, $to, $value); $needsWork = strlen(str_replace($allowed, '', $value));
}
} }
} }
if(function_exists("\\iconv")) { if($needsWork && function_exists("\\iconv")) {
$v = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $value); $v = iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $value);
if($v) $value = $v; if($v) $value = $v;
$needsWork = strlen(str_replace($allowed, '', $value));
} }
$needsWork = strlen(str_replace($allowed, '', $value));
} }
if(strlen($value) > $maxLength) $value = substr($value, 0, $maxLength); if(strlen($value) > $maxLength) $value = substr($value, 0, $maxLength);