В бета версии инфоблоков наконец то реализована поддержа указывать вместо ID символьный код элементов и разделов (наконец то), собственно сделал для себя автоматический транслит названия элемента и раздела добавлющий символьный код, на универсальность не претендую но думаю такое решение устроит большинство:
Данный код разместить в init.php
AddEventHandler("iblock", "OnBeforeIBlockElementAdd", array("MyEventHandlerClass", "IBlockElementAddCodeFromName")); AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", array("MyEventHandlerClass", "IBlockElementAddCodeFromName")); AddEventHandler("iblock", "OnBeforeIBlockSectionAdd", array("MyEventHandlerClass", "IBlockSectionAddCodeFromName")); AddEventHandler("iblock", "OnBeforeIBlockSectionUpdate", array("MyEventHandlerClass", "IBlockSectionAddCodeFromName")); class MyEventHandlerClass { function IBlockElementAddCodeFromName(&$arFields) { static $NEWS_IBLOCK_ID; if(empty($NEWS_IBLOCK_ID)) { $NEWS_IBLOCK_ID = array(0); $resIBlock = CIBlock::GetList(array(), array('TYPE' => 'news'), false); while($arIBlock = $resIBlock->Fetch()) { $NEWS_IBLOCK_ID[] = $arIBlock["ID"]; } } $arFields["CODE"] = Translit::UrlTranslit($arFields["NAME"]); $arFields["CODE"] .= ".".$arFields["ID"]; if(in_array($arFields["IBLOCK_ID"], $NEWS_IBLOCK_ID) and $arFields["ACTIVE_FROM"]) { if($stmp = MakeTimeStamp($arFields["ACTIVE_FROM"])) { $arFields["CODE"] = date("d-m-Y", $stmp).".".$arFields["CODE"]; } } } function IBlockSectionAddCodeFromName(&$arFields) { $arFields["CODE"] = Translit::UrlTranslit($arFields["NAME"]); // $arFields["CODE"] .= "_".$arFields["ID"]; } } class Translit { function Transliterate($string) { $cyr=array( "Щ", "Ш", "Ч", "Ц","Ю", "Я", "Ж", "А","Б","В","Г","Д","Е","Ё","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х", "Ь","Ы","Ъ","Э","Є","Ї", "щ", "ш", "ч", "ц","ю", "я", "ж", "а","б","в","г","д","е","ё","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х", "ь","ы","ъ","э","є","ї" ); $lat=array( "Shh","Sh","Ch","C","Ju","Ja","Zh","A","B","V","G","D","Je","Jo","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","Kh","'","Y","`","E","Je","Ji", "shh","sh","ch","c","ju","ja","zh","a","b","v","g","d","je","jo","z","i","j","k","l","m","n","o","p","r","s","t","u","f","kh","'","y","`","e","je","ji" ); for($i=0; $i<count($cyr); $i++) { $c_cyr = $cyr[$i]; $c_lat = $lat[$i]; $string = str_replace($c_cyr, $c_lat, $string); } $string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]e/", "\${1}e", $string); $string = preg_replace("/([qwrtpsdfghklzxcvbnmQWRTPSDFGHKLZXCVBNM]+)[jJ]/", "\${1}'", $string); $string = preg_replace("/([eyuioaEYUIOA]+)[Kk]h/", "\${1}h", $string); $string = preg_replace("/^kh/", "h", $string); $string = preg_replace("/^Kh/", "H", $string); return $string; } function UrlTranslit($string) { $string = preg_replace("/[_\s\.,?!\[\](){}]+/", "_", $string); $string = preg_replace("/-{2,}/", "--", $string); $string = preg_replace("/_-+_/", "--", $string); $string = preg_replace("/[_\-]+$/", "", $string); $string = Translit::Transliterate($string); $string = ToLower($string); $string = preg_replace("/j{2,}/", "j", $string); $string = preg_replace("/[^0-9a-z_\-]+/", "", $string); return $string; } } |
Данный код разместить в init.php