Skip to content

Instantly share code, notes, and snippets.

@sdelfi
Last active February 28, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdelfi/c9f37c4b55878bb57c93eec25dd601d0 to your computer and use it in GitHub Desktop.
Save sdelfi/c9f37c4b55878bb57c93eec25dd601d0 to your computer and use it in GitHub Desktop.
Easy Table of Contents (Wordpress Plugin) - add Cyrillic anchor convertations
<?php
function transliterate($textcyr = null, $textlat = null) {
$textcyr = strtolower($textcyr);
$textcyr = strip_tags($textcyr);
$cyr = array(' ', ' ', '?', '!', '.', ',', '/', '\\', '--', '---', ': ', ':', '(', ')', '–', '«', '»',
'ж', 'ч', 'щ', 'ш', 'ю', 'а', 'б', 'в', 'г', 'д', 'е', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'ы', 'э', 'ю', 'я',
'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Ы', 'э', 'Ю', 'Я');
$lat = array('-', '-', '', '', '-', '-', '-', '-', '-', '-', '-','-', '-', '-', '-', '-', '-',
'zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', '', '', 'y', 'e', 'yu', 'ya',
'zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', '', '', 'y', 'e', 'yu', 'ya');
if($textcyr) {
//var_dump($textcyr);echo "<br/>";
$return = str_replace($cyr, $lat, $textcyr);
//var_dump($return);echo "<br/>";
$return = mb_strtolower($return);
//var_dump($return);echo "<br/>";
$return = str_replace(' ', '-', $return);
$return = str_replace(' ', '-', $return);
$return = str_replace(' ', '-', $return);
$return = str_replace(' ', '-', $return);
$return = str_replace('_', '-', $return);
$return = str_replace('-–-', '-', $return);
$return = str_replace('--', '-', $return);
$return = str_replace('--', '-', $return);
$return = str_replace('--', '-', $return);
$return = str_replace('--', '-', $return);
$return = str_replace('--', '-', $return);
$return = rtrim($return, '-');
$return = ltrim($return, '-');
return $return;
} else if($textlat) {
return str_replace($lat, $cyr, $textlat);
} else return null;
}
add_filter('ez_toc_url_anchor_target', 'transliterate_f', 10, 2);
function transliterate_f($r, $t) {
$r2 = strip_tags($t);
$r2 = transliterate($r2);
return $r2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment