public static function toLatin($string, $separator = '', $clean = false)
{
$cyrillicCount = count(self::$cyr);
for ($i = 0; $i < $cyrillicCount; $i++) {
$string = str_replace(self::$cyr[$i], self::$lat[$i], $string);
}
$string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]e/", "\${1}e", $string);
$string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]/", "\${1}y", $string);
$string = preg_replace("/([eyuioaEYUIOA]+)[Kk]h/", "\${1}h", $string);
$string = preg_replace("/^kh/", "h", $string);
$string = preg_replace("/^Kh/", "H", $string);
$string = trim($string);
if (empty($separator) === false) {
$string = str_replace(' ', $separator, $string);
$string = preg_replace('/[' . $separator . ']{2,}/', '', $string);
}
if ($clean !== false) {
$string = strtolower($string);
$string = preg_replace('/[^-_a-z0-9.]+/', '', $string);
}
return $string;
}
/** * Check if upload files are valid * * @return void */ public function move() { // do any actions if files exists foreach ($this->files as $n => $file) { $filename = $file->getName(); if (isset($this->rules['hash']) === true) { if (empty($this->rules['hash']) === true) { $this->rules['hash'] = 'md5'; } if (!is_string($this->rules['hash']) === true) { $filename = call_user_func($this->rules['hash']) . '.' . $file->getExtension(); } else { $filename = $this->rules['hash']($filename) . '.' . $file->getExtension(); } } if (isset($this->rules['sanitize']) === true) { $filename = Format::toLatin($filename, '', true); } if (isset($this->rules['directory'])) { $tmp = rtrim($this->rules['directory'], '/') . DIRECTORY_SEPARATOR . $filename; } else { $tmp = rtrim($this->rules['dynamic'], '/') . DIRECTORY_SEPARATOR . $filename; } // move file to target directory $isUploaded = $file->moveTo($tmp); if ($isUploaded === true) { $this->info[] = ['path' => $tmp, 'directory' => dirname($tmp), 'filename' => $filename, 'size' => $file->getSize(), 'extension' => $file->getExtension()]; } } return $this->getInfo(); }