Cyr-To-Lat - Version 3.0

Version Description

  • Added automatic conversion of existing post, page and term slugs
  • Added saving of existing post and page permalinks integrity
  • Added transliteration of attachment file names
  • Adjusted transliteration table in accordance with ISO 9 standard
  • Included Russian, Belarusian, Ukrainian, Bulgarian and Macedonian characters
  • Added filter for the transliteration table
Download this release

Release Info

Developer SergeyBiryukov
Plugin Icon 128x128 Cyr-To-Lat
Version 3.0
Comparing to
See all releases

Code changes from version 1.0 to 3.0

Files changed (2) hide show
  1. cyr-to-lat.php +68 -26
  2. readme.txt +19 -2
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: This plugin converts Cyrillic characters in post slug to Latin characters. You can use this plugin for creating human-readable links. Thanks to Alexander Shilyaev for the idea. Based on the oroginal plugin by Anton Skorobogatov.
6
- Author: Atrax
7
- Version: 1.0
 
8
  */
9
- $tr = array(
10
- "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
11
- "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
12
- "ї"=>"yi","А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
13
- "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
14
- "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
15
- "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
16
- "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
17
- "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"YI","Ь"=>"",
18
- "Э"=>"E","Ю"=>"YU","Я"=>"YA","а"=>"a","б"=>"b",
19
- "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
20
- "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
21
- "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
22
- "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
23
- "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
24
- "ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya"
25
- );
26
-
27
- function sanitize_title_with_translit($title) {
28
- global $tr;
29
- return strtr($title,$tr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
- add_action('sanitize_title', 'sanitize_title_with_translit', 0);
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.0
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) ) {
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: 2.1
7
 
8
  Converts Cyrillic characters in post and term slugs to Latin characters.
9
 
@@ -20,5 +20,22 @@ 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
6
+ Stable tag: 3.0
7
 
8
  Converts Cyrillic characters in post and term slugs to Latin characters.
9
 
20
 
21
  == Changelog ==
22
 
23
+ = 3.0 =
24
+ * Added automatic conversion of existing post, page and term slugs
25
+ * Added saving of existing post and page permalinks integrity
26
+ * Added transliteration of attachment file names
27
+ * Adjusted transliteration table in accordance with ISO 9 standard
28
+ * Included Russian, Belarusian, Ukrainian, Bulgarian and Macedonian characters
29
+ * Added filter for the transliteration table
30
+
31
+ = 2.1 =
32
+ * Optimized filter call
33
+
34
+ = 2.0 =
35
+ * Added check for existing terms
36
+
37
+ = 1.0.1 =
38
+ * Updated description
39
+
40
  = 1.0 =
41
  * Initial release