Skip to content

Commit

Permalink
Merge pull request #11 from janki1/feature/webp-convertor
Browse files Browse the repository at this point in the history
NormalizeFileName Setting
  • Loading branch information
janki1 authored Sep 7, 2023
2 parents d1cb01d + a0cf370 commit e9205ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Module extends BaseModule
/**
* @var string default allowed files extension
*/
public $allowExtension = 'jpeg jpg png gif svg mov mp3 mp4 avi wmv flv mpeg webm ogg';
public $allowExtension = 'jpeg jpg png gif svg mov mp3 mp4 avi wmv flv mpeg webm ogg webp';

/**
* @var bool check mime type of uploaded files
Expand All @@ -82,6 +82,11 @@ class Module extends BaseModule
* @var string which schema should use form copy URL
*/
public string $urlSchema = 'https';

/**
* @var bool Set true for convert file names to unicode string
*/
public bool $normalizeFileName = true;

/**
* Initializes the module.
Expand Down
21 changes: 12 additions & 9 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,18 @@ public static function isImage($fileName)
*
* @return mixed|string
*/
public static function removeSign($convert, $char = "_")
public static function removeSign($convert, $char = "_") : string
{
$vietnameseChar = "à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ|đ|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ|Ì|Í|Ị|Ỉ|Ĩ|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ|Ỳ|Ý|Ỵ|Ỷ|Ỹ|Đ";
$unicodeChar = "a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|e|e|e|e|e|e|e|e|e|e|e|i|i|i|i|i|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|u|u|u|u|u|u|u|u|u|u|u|y|y|y|y|y|d|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|E|E|E|E|E|E|E|E|E|E|E|I|I|I|I|I|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|U|U|U|U|U|U|U|U|U|U|U|Y|Y|Y|Y|Y|D";
$vietnameseChars = explode("|", $vietnameseChar);
$unicodeChars = explode("|", $unicodeChar);
$str = strtolower(str_replace($vietnameseChars, $unicodeChars, $convert));
$str = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$str = preg_replace("/[\/_|+ -]+/", $char, $str);
return $str;
$result = $convert;
if (Yii::$app->controller->module->normalizeFileName) {
$vietnameseChar = "à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ|đ|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ|Ì|Í|Ị|Ỉ|Ĩ|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ|Ỳ|Ý|Ỵ|Ỷ|Ỹ|Đ";
$unicodeChar = "a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|e|e|e|e|e|e|e|e|e|e|e|i|i|i|i|i|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|u|u|u|u|u|u|u|u|u|u|u|y|y|y|y|y|d|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|E|E|E|E|E|E|E|E|E|E|E|I|I|I|I|I|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|U|U|U|U|U|U|U|U|U|U|U|Y|Y|Y|Y|Y|D";
$vietnameseChars = explode("|", $vietnameseChar);
$unicodeChars = explode("|", $unicodeChar);
$str = strtolower(str_replace($vietnameseChars, $unicodeChars, $convert));
$str = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$result = preg_replace("/[\/_|+ -]+/", $char, $str);
}
return $result;
}
}

0 comments on commit e9205ac

Please sign in to comment.