wordpress/php-fpm/wordpress_files/plugins/fg-spip-to-wp/includes/class-fg-spip-to-wp-tools.php
2020-05-22 01:40:23 +00:00

68 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Useful functions
*
* @link https://wordpress.org/plugins/fg-spip-to-wp/
* @since 1.0.0
*
* @package FG_Spip_to_WordPress
* @subpackage FG_Spip_to_WordPress/includes
*/
/**
* Useful functions class
*
* @since 1.0.0
* @package FG_Spip_to_WordPress
* @subpackage FG_Spip_to_WordPress/includes
* @author Frédéric GILLES
*/
if ( !class_exists('FG_Spip_to_WordPress_Tools', false) ) {
class FG_Spip_to_WordPress_Tools {
/**
* Convert string to latin
*/
public static function convert_to_latin($string) {
$string = self::greek_to_latin($string); // For Greek characters
$string = self::cyrillic_to_latin($string); // For Cyrillic characters
return $string;
}
/**
* Convert Greek characters to latin
*/
private static function greek_to_latin($string) {
static $from = array('Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϑ','ϒ','ϖ');
static $to = array('A','V','G','D','E','Z','I','TH','I','K','L','M','N','X','O','P','R','S','T','Y','F','CH','PS','O','a','v','g','d','e','z','i','th','i','k','l','m','n','x','o','p','r','s','s','t','y','f','ch','ps','o','th','y','p');
return str_replace($from, $to, $string);
}
/**
* Convert Cyrillic (Russian) characters to latin
*/
private static function cyrillic_to_latin($string) {
static $from = array('ж', 'ч', 'щ', 'ш', 'ю', 'а', 'б', 'в', 'г', 'д', 'е', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я', 'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
static $to = 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', 'x', 'q', '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', 'X', 'Q');
return str_replace($from, $to, $string);
}
/**
* Fix the bad encoding
*
* @param string $string Original string
* @return string Fixed string
*/
public static function fix_encoding($string) {
if ( strpos($string, 'Ì') !== false ) {
$string = @iconv('UTF-8', 'ISO-8859-15', $string);
}
if ( (strpos($string, 'Ã') !== false) ) {
$string = @iconv('UTF-8', 'CP1252', $string);
}
return $string;
}
}
}