Version Description
- Fixed transliteration when saving a draft
Download this release
Release Info
Developer | SergeyBiryukov |
Plugin | Cyr-To-Lat |
Version | 3.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 3.1
- cyr-to-lat.php +68 -26
- readme.txt +23 -3
cyr-to-lat.php
CHANGED
@@ -2,32 +2,74 @@
|
|
2 |
/*
|
3 |
Plugin Name: Cyr-To-Lat
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/cyr2lat/
|
5 |
-
Description:
|
6 |
-
Author:
|
7 |
-
|
|
|
8 |
*/
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/*
|
3 |
Plugin Name: Cyr-To-Lat
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/cyr2lat/
|
5 |
+
Description: Converts Cyrillic characters in post and term slugs to Latin characters. Useful for creating human-readable URLs. Based on the original plugin by Anton Skorobogatov.
|
6 |
+
Author: Sol, Sergey Biryukov
|
7 |
+
Author URI: http://ru.wordpress.org/
|
8 |
+
Version: 3.1
|
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', 'Й' => 'Y',
|
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 |
+
'Ы' => 'YI', 'Ь' => '`', 'Э' => 'E`', 'Ю' => 'YU', 'Я' => 'YA',
|
24 |
+
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'ѓ' => 'g',
|
25 |
+
'ґ' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'є' => 'ye',
|
26 |
+
'ж' => 'zh', 'з' => 'z', 'ѕ' => 'z', 'и' => 'i', 'й' => 'y',
|
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 |
+
'ы' => 'yi', 'ъ' => "'", 'э' => 'e`', 'ю' => 'yu', 'я' => 'ya'
|
33 |
+
);
|
34 |
+
|
35 |
+
$term = $wpdb->get_var("SELECT slug FROM {$wpdb->terms} WHERE name = '$title'");
|
36 |
+
if ( empty($term) ) {
|
37 |
+
$title = strtr($title, apply_filters('ctl_table', $iso9_table));
|
38 |
+
$title = preg_replace("/[^A-Za-z0-9`'\-\.]/", '-', $title);
|
39 |
+
} else {
|
40 |
+
$title = $term;
|
41 |
+
}
|
42 |
+
|
43 |
+
return $title;
|
44 |
+
}
|
45 |
+
if ( !empty($_POST) || !empty($_GET['action']) && $_GET['action'] == 'edit' ) {
|
46 |
+
add_filter('sanitize_title', 'ctl_sanitize_title', 9);
|
47 |
+
add_filter('sanitize_file_name', 'ctl_sanitize_title');
|
48 |
}
|
49 |
|
50 |
+
function ctl_convert_existing_slugs() {
|
51 |
+
global $wpdb;
|
52 |
+
|
53 |
+
$posts = $wpdb->get_results("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_name REGEXP('[^A-Za-z0-9\-]+') AND post_status = 'publish'");
|
54 |
+
foreach ( (array) $posts as $post ) {
|
55 |
+
$sanitized_name = ctl_sanitize_title(urldecode($post->post_name));
|
56 |
+
if ( $post->post_name != $sanitized_name ) {
|
57 |
+
add_post_meta($post->ID, '_wp_old_slug', $post->post_name);
|
58 |
+
$wpdb->update($wpdb->posts, array( 'post_name' => $sanitized_name ), array( 'ID' => $post->ID ));
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
$terms = $wpdb->get_results("SELECT term_id, slug FROM {$wpdb->terms} WHERE slug REGEXP('[^A-Za-z0-9\-]+') ");
|
63 |
+
foreach ( (array) $terms as $term ) {
|
64 |
+
$sanitized_slug = ctl_sanitize_title(urldecode($term->slug));
|
65 |
+
if ( $term->slug != $sanitized_slug ) {
|
66 |
+
$wpdb->update($wpdb->terms, array( 'slug' => $sanitized_slug ), array( 'term_id' => $term->term_id ));
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
function ctl_schedule_conversion() {
|
72 |
+
add_action('shutdown', 'ctl_convert_existing_slugs');
|
73 |
+
}
|
74 |
+
register_activation_hook(__FILE__, 'ctl_schedule_conversion');
|
75 |
+
?>
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Cyr-To-Lat ===
|
2 |
-
Contributors: Atrax
|
3 |
Tags: l10n, translations, transliteration, slugs, russian, rustolat
|
4 |
Requires at least: 2.3
|
5 |
-
Tested up to: 3.0
|
6 |
-
Stable tag:
|
7 |
|
8 |
Converts Cyrillic characters in post and term slugs to Latin characters.
|
9 |
|
@@ -20,5 +20,25 @@ Based on the original Rus-To-Lat plugin by Anton Skorobogatov.
|
|
20 |
|
21 |
== Changelog ==
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
= 1.0 =
|
24 |
* Initial release
|
1 |
=== Cyr-To-Lat ===
|
2 |
+
Contributors: Atrax, SergeyBiryukov
|
3 |
Tags: l10n, translations, transliteration, slugs, russian, rustolat
|
4 |
Requires at least: 2.3
|
5 |
+
Tested up to: 3.0.1
|
6 |
+
Stable tag: 3.1
|
7 |
|
8 |
Converts Cyrillic characters in post and term slugs to Latin characters.
|
9 |
|
20 |
|
21 |
== Changelog ==
|
22 |
|
23 |
+
= 3.1 =
|
24 |
+
* Fixed transliteration when saving a draft
|
25 |
+
|
26 |
+
= 3.0 =
|
27 |
+
* Added automatic conversion of existing post, page and term slugs
|
28 |
+
* Added saving of existing post and page permalinks integrity
|
29 |
+
* Added transliteration of attachment file names
|
30 |
+
* Adjusted transliteration table in accordance with ISO 9 standard
|
31 |
+
* Included Russian, Belarusian, Ukrainian, Bulgarian and Macedonian characters
|
32 |
+
* Added filter for the transliteration table
|
33 |
+
|
34 |
+
= 2.1 =
|
35 |
+
* Optimized filter call
|
36 |
+
|
37 |
+
= 2.0 =
|
38 |
+
* Added check for existing terms
|
39 |
+
|
40 |
+
= 1.0.1 =
|
41 |
+
* Updated description
|
42 |
+
|
43 |
= 1.0 =
|
44 |
* Initial release
|