Version Description
Download this release
Release Info
Developer | karevn |
Plugin | Cyr to Lat enhanced |
Version | 3.3 |
Comparing to | |
See all releases |
Version 3.3
- cyr-to-lat.php +99 -0
- readme.txt +73 -0
cyr-to-lat.php
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Cyr to Lat enhanced
|
4 |
+
Plugin URI: http://wordpress.org/extend/plugins/cyr3lat/
|
5 |
+
Description: Converts Cyrillic characters in post, term slugs and media file names to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
|
6 |
+
Author: Sol, Sergey Biryukov, Nikolay Karev
|
7 |
+
Author URI: http://karevn.com/
|
8 |
+
Version: 3.3
|
9 |
+
*/
|
10 |
+
|
11 |
+
function ctl_sanitize_title($title) {
|
12 |
+
global $wpdb;
|
13 |
+
|
14 |
+
$iso9_table = array(
|
15 |
+
'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Ѓ' => 'G`',
|
16 |
+
'Ґ' => 'G`', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'YO', 'Є' => 'YE',
|
17 |
+
'Ж' => 'ZH', 'З' => 'Z', 'Ѕ' => 'Z', 'И' => 'I', 'Й' => 'J',
|
18 |
+
'Ј' => 'J', 'І' => 'I', 'Ї' => 'YI', 'К' => 'K', 'Ќ' => 'K`',
|
19 |
+
'Л' => 'L', 'Љ' => 'L', 'М' => 'M', 'Н' => 'N', 'Њ' => 'N`',
|
20 |
+
'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
|
21 |
+
'У' => 'U', 'Ў' => 'U`', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'TS',
|
22 |
+
'Ч' => 'CH', 'Џ' => 'DH', 'Ш' => 'SH', 'Щ' => 'SHH', 'Ъ' => '``',
|
23 |
+
'Ы' => 'Y`', 'Ь' => '`', 'Э' => 'E`', 'Ю' => 'YU', 'Я' => 'YA',
|
24 |
+
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'ѓ' => 'g',
|
25 |
+
'ґ' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'є' => 'ye',
|
26 |
+
'ж' => 'zh', 'з' => 'z', 'ѕ' => 'z', 'и' => 'i', 'й' => 'j',
|
27 |
+
'ј' => 'j', 'і' => 'i', 'ї' => 'yi', 'к' => 'k', 'ќ' => 'k`',
|
28 |
+
'л' => 'l', 'љ' => 'l', 'м' => 'm', 'н' => 'n', 'њ' => 'n`',
|
29 |
+
'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
|
30 |
+
'у' => 'u', 'ў' => 'u`', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts',
|
31 |
+
'ч' => 'ch', 'џ' => 'dh', 'ш' => 'sh', 'щ' => 'shh', 'ъ' => '``',
|
32 |
+
'ы' => 'y`', 'ь' => '`', 'э' => 'e`', 'ю' => 'yu', 'я' => 'ya'
|
33 |
+
);
|
34 |
+
|
35 |
+
$locale = get_locale();
|
36 |
+
switch ( $locale ) {
|
37 |
+
case 'bg_BG':
|
38 |
+
$iso9_table['Щ'] = 'SHT';
|
39 |
+
$iso9_table['щ'] = 'sht';
|
40 |
+
$iso9_table['Ъ'] = 'A`';
|
41 |
+
$iso9_table['ъ'] = 'a`';
|
42 |
+
break;
|
43 |
+
case 'uk':
|
44 |
+
$iso9_table['И'] = 'Y`';
|
45 |
+
$iso9_table['и'] = 'y`';
|
46 |
+
break;
|
47 |
+
}
|
48 |
+
|
49 |
+
$is_term = false;
|
50 |
+
$backtrace = debug_backtrace();
|
51 |
+
foreach ( $backtrace as $backtrace_entry ) {
|
52 |
+
if ( $backtrace_entry['function'] == 'wp_insert_term' ) {
|
53 |
+
$is_term = true;
|
54 |
+
break;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
$term = $is_term ? $wpdb->get_var("SELECT slug FROM {$wpdb->terms} WHERE name = '$title'") : '';
|
59 |
+
if ( empty($term) ) {
|
60 |
+
$title = strtr($title, apply_filters('ctl_table', $iso9_table));
|
61 |
+
$title = preg_replace("/[^A-Za-z0-9`'_\-\.]/", '-', $title);
|
62 |
+
$title = preg_replace('/\-+/', '-', $title);
|
63 |
+
$title = preg_replace('/^-+/', '', $title);
|
64 |
+
$title = preg_replace('/-+$/', '', $title);
|
65 |
+
} else {
|
66 |
+
$title = $term;
|
67 |
+
}
|
68 |
+
|
69 |
+
return $title;
|
70 |
+
}
|
71 |
+
add_filter('sanitize_title', 'ctl_sanitize_title', 9);
|
72 |
+
add_filter('sanitize_file_name', 'ctl_sanitize_title');
|
73 |
+
|
74 |
+
function ctl_convert_existing_slugs() {
|
75 |
+
global $wpdb;
|
76 |
+
|
77 |
+
$posts = $wpdb->get_results("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_name REGEXP('[^A-Za-z0-9\-]+') AND post_status = 'publish'");
|
78 |
+
foreach ( (array) $posts as $post ) {
|
79 |
+
$sanitized_name = ctl_sanitize_title(urldecode($post->post_name));
|
80 |
+
if ( $post->post_name != $sanitized_name ) {
|
81 |
+
add_post_meta($post->ID, '_wp_old_slug', $post->post_name);
|
82 |
+
$wpdb->update($wpdb->posts, array( 'post_name' => $sanitized_name ), array( 'ID' => $post->ID ));
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
$terms = $wpdb->get_results("SELECT term_id, slug FROM {$wpdb->terms} WHERE slug REGEXP('[^A-Za-z0-9\-]+') ");
|
87 |
+
foreach ( (array) $terms as $term ) {
|
88 |
+
$sanitized_slug = ctl_sanitize_title(urldecode($term->slug));
|
89 |
+
if ( $term->slug != $sanitized_slug ) {
|
90 |
+
$wpdb->update($wpdb->terms, array( 'slug' => $sanitized_slug ), array( 'term_id' => $term->term_id ));
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
function ctl_schedule_conversion() {
|
96 |
+
add_action('shutdown', 'ctl_convert_existing_slugs');
|
97 |
+
}
|
98 |
+
register_activation_hook(__FILE__, 'ctl_schedule_conversion');
|
99 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Cyr to Lat enhanced ===
|
2 |
+
Contributors: Atrax, SergeyBiryukov, karevn
|
3 |
+
Tags: cyrillic, latin, l10n, russian, rustolat, slugs, translations, transliteration, media
|
4 |
+
Requires at least: 2.3
|
5 |
+
Tested up to: 3.2
|
6 |
+
Stable tag: 3.3
|
7 |
+
|
8 |
+
Converts Cyrillic characters in post, page and term slugs to Latin characters.
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
Converts Cyrillic characters in post, page and term slugs to Latin characters. Useful for creating human-readable URLs.
|
13 |
+
|
14 |
+
This plugin is a fork of [cyr2lat](http://wordpress.org/extend/plugins/cyr2lat/) plugin.
|
15 |
+
|
16 |
+
= Features =
|
17 |
+
* Automatically converts existing post, page and term slugs on activation
|
18 |
+
* Saves existing post and page permalinks integrity
|
19 |
+
* Performs transliteration of attachment file names
|
20 |
+
* Includes Russian, Belarusian, Ukrainian, Bulgarian and Macedonian characters
|
21 |
+
* Transliteration table can be customized without editing the plugin itself
|
22 |
+
|
23 |
+
Based on the original Rus-To-Lat plugin by Anton Skorobogatov.
|
24 |
+
|
25 |
+
== Installation ==
|
26 |
+
|
27 |
+
1. Upload `cyr2lat` folder to the `/wp-content/plugins/` directory.
|
28 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
29 |
+
|
30 |
+
== Frequently Asked Questions ==
|
31 |
+
|
32 |
+
= How can I define my own substitutions? =
|
33 |
+
|
34 |
+
Add this code to your theme's `functions.php` file:
|
35 |
+
`
|
36 |
+
function my_cyr_to_lat_table($ctl_table) {
|
37 |
+
$ctl_table['Ъ'] = 'U';
|
38 |
+
$ctl_table['ъ'] = 'u';
|
39 |
+
return $ctl_table;
|
40 |
+
}
|
41 |
+
add_filter('ctl_table', 'my_cyr_to_lat_table');
|
42 |
+
`
|
43 |
+
|
44 |
+
== Changelog ==
|
45 |
+
|
46 |
+
= 3.3 =
|
47 |
+
|
48 |
+
= 3.2 =
|
49 |
+
* Added transliteration when publishing via XML-RPC
|
50 |
+
* Fixed Invalid Taxonomy error when viewing the most used tags
|
51 |
+
|
52 |
+
= 3.1 =
|
53 |
+
* Fixed transliteration when saving a draft
|
54 |
+
|
55 |
+
= 3.0 =
|
56 |
+
* Added automatic conversion of existing post, page and term slugs
|
57 |
+
* Added saving of existing post and page permalinks integrity
|
58 |
+
* Added transliteration of attachment file names
|
59 |
+
* Adjusted transliteration table in accordance with ISO 9 standard
|
60 |
+
* Included Russian, Belarusian, Ukrainian, Bulgarian and Macedonian characters
|
61 |
+
* Added filter for the transliteration table
|
62 |
+
|
63 |
+
= 2.1 =
|
64 |
+
* Optimized filter call
|
65 |
+
|
66 |
+
= 2.0 =
|
67 |
+
* Added check for existing terms
|
68 |
+
|
69 |
+
= 1.0.1 =
|
70 |
+
* Updated description
|
71 |
+
|
72 |
+
= 1.0 =
|
73 |
+
* Initial release
|