Created
September 30, 2011 10:24
-
-
Save mozzi/1253376 to your computer and use it in GitHub Desktop.
Плагин для транслитерации русских имен файлов загружаемых в ModX Revolution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Плагин для транслитерации русских имен файлов загружаемых в ModX Revolution через менеджер файлов. Все русские символы переводятся | |
в нижний регистр и транслителируются, спецсимволы заменяются на "_". Привязывать к событию OnFileManagerUpload. */ | |
<?php | |
function UrlTranslit($string) { | |
$alfavitlover = explode(',', 'ё,й,ц,у,к,е,н,г,ш,щ,з,х,ъ,ф,ы,в,а,п,р,о,л,д,ж,э,я,ч,с,м,и,т,ь,б,ю'); | |
$alfavitupper = explode(',', 'Ё,Й,Ц,У,К,Е,Н,Г,Ш,Щ,З,Х,Ъ,Ф,Ы,В,А,П,Р,О,Л,Д,Ж,Э,Я,Ч,С,М,И,Т,Ь,Б,Ю'); | |
for ($wr = 0; $wr < sizeof($alfavitupper); $wr++) { | |
$string = str_replace($alfavitupper[$wr], $alfavitlover[$wr], $string); | |
} | |
$LettersFrom = explode(",", "ё,й,у,к,е,н,г,з,х,ф,ы,в,а,п,р,о,л,д,э,с,м,и,т,б"); | |
$LettersTo = explode(',', 'e,j,u,k,e,n,g,z,x,f,y,v,a,p,r,o,l,d,e,s,m,i,t,b'); | |
static $Consonant = "бвгджзйклмнпрстфхцчшщ"; | |
static $Vowel = "аеёиоуыэюя"; | |
static $BiLetters = array ( | |
"ж" => "zh", | |
"ц" => "ts", | |
"ч" => "ch", | |
"ш" => "sh", | |
"щ" => "sch", | |
"ю" => "ju", | |
"я" => "ja", | |
); | |
//here we replace ъ/ь | |
$string = preg_replace("/(ь|ъ)([" . $Vowel . "])/", "j\\2", $string); | |
$string = preg_replace("/(ь|ъ)/", "", $string); | |
$string = str_replace($LettersFrom, $LettersTo, $string); | |
// $string = strtr($string, $LettersFrom, $LettersTo ); | |
$string = strtr($string, $BiLetters); | |
$string = preg_replace("/j{2,}/", "j", $string); | |
//$string = preg_replace("/[^a-z0-9_]/", "_", $string); | |
$string = preg_replace("/[^0-9a-z_\-\.]/", "", $string); | |
return $string; | |
} | |
foreach ($files as $file) { | |
$ext = @pathinfo($file['name'],PATHINFO_EXTENSION); | |
rename($directory->getPath().$file['name'], $directory->getPath().UrlTranslit($file['name'])); | |
} |
$currentdoc = $modx->newObject('modResource'); foreach($files as $file) { if($file['error'] == 0) { $pathInfo = pathinfo($file['name']); $oldPath = $directory . $file['name']; $newPath = $currentdoc->cleanAlias($pathInfo['filename']).'-'.date("Y-m-d-h-s").'.'. $pathInfo['extension']; $source->renameObject($oldPath, $newPath); } }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
В версии 2.2.2 отказывается работать.