mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Fixes #1681
Added a customzied slug-function to MediaManager which supports @-signs
This commit is contained in:
parent
ce0bbc988e
commit
ed583491e0
@ -945,6 +945,25 @@ class MediaManager extends WidgetBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a slug form the string. A modified version of Laravel's Str::slug
|
||||
* with the main difference that it accepts @-signs
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public static function slug($string)
|
||||
{
|
||||
$title = Str::ascii($title);
|
||||
// Convert all dashes/underscores into separator
|
||||
$flip = $separator == '-' ? '_' : '-';
|
||||
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
|
||||
// Remove all characters that are not the separator, letters, numbers, whitespace or @.
|
||||
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s@]+!u', '', mb_strtolower($title));
|
||||
// Replace all separator characters and whitespace by a single separator
|
||||
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
|
||||
return trim($title, $separator);
|
||||
}
|
||||
|
||||
protected function checkUploadPostback()
|
||||
{
|
||||
$fileName = null;
|
||||
@ -973,7 +992,7 @@ class MediaManager extends WidgetBase
|
||||
* File name contains non-latin characters, attempt to slug the value
|
||||
*/
|
||||
if (!$this->validateFileName($fileName)) {
|
||||
$fileNameSlug = Str::slug(File::name($fileName), '-');
|
||||
$fileNameSlug = static::slug(File::name($fileName), '-');
|
||||
$fileName = $fileNameSlug.'.'.$extension;
|
||||
}
|
||||
|
||||
@ -1001,7 +1020,7 @@ class MediaManager extends WidgetBase
|
||||
|
||||
protected function validateFileName($name)
|
||||
{
|
||||
if (!preg_match('/^[0-9a-z\.\s_\-]+$/i', $name)) {
|
||||
if (!preg_match('/^[0-9a-z@\.\s_\-]+$/i', $name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user