Changeset 2032304
- Timestamp:
- 02/16/2019 08:50:35 PM (7 years ago)
- Location:
- wp-permalink-translator
- Files:
-
- 19 added
- 2 edited
-
tags/1.7.5/img (added)
-
tags/1.7.5/img/donate.jpg (added)
-
tags/1.7.5/langs (added)
-
tags/1.7.5/langs/wp-permalink-translator-fa_IR.mo (added)
-
tags/1.7.5/langs/wp-permalink-translator-fa_IR.po (added)
-
tags/1.7.5/readme.txt (added)
-
tags/1.7.5/screenshot-1.jpg (added)
-
tags/1.7.5/screenshot-2.jpg (added)
-
tags/1.7.5/wp-permalink-translator.php (added)
-
tags/1.7.6 (added)
-
tags/1.7.6/img (added)
-
tags/1.7.6/img/donate.jpg (added)
-
tags/1.7.6/langs (added)
-
tags/1.7.6/langs/wp-permalink-translator-fa_IR.mo (added)
-
tags/1.7.6/langs/wp-permalink-translator-fa_IR.po (added)
-
tags/1.7.6/readme.txt (added)
-
tags/1.7.6/screenshot-1.jpg (added)
-
tags/1.7.6/screenshot-2.jpg (added)
-
tags/1.7.6/wp-permalink-translator.php (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wp-permalink-translator.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-permalink-translator/trunk/readme.txt
r2012240 r2032304 13 13 Allow admins to translate Permalink to another languages. 14 14 15 ### Development 16 [https://github.com/hossinasaadi/wp-permalink-translator/](https://github.com/hossinasaadi/wp-permalink-translator/ "https://github.com/hossinasaadi/wp-permalink-translator") 15 17 16 18 … … 24 26 == Changelog == 25 27 28 = 1.7.6 = 29 * fix some bugs. 30 26 31 = 1.7.5 = 27 32 * added tool to translate all posts at once. … … 29 34 30 35 == Upgrade Notice == 36 37 = 1.7.6 = 38 * fix some bugs. 31 39 32 40 = 1.7.5 = -
wp-permalink-translator/trunk/wp-permalink-translator.php
r2012257 r2032304 4 4 Plugin URI: https://wordpress.org/plugins/wp-permalink-translator/ 5 5 Description: a plugin to translate Permalink to another languages. 6 Version: 1.7. 56 Version: 1.7.6 7 7 Author: Hossin Asaadi 8 8 Author URI: https://profiles.wordpress.org/hossin277/ 9 9 License: GPL2 10 10 */ 11 add_action('admin_menu', ' add_menu_wp_permalink');12 add_action('plugins_loaded', ' myplugin_load_textdomain');11 add_action('admin_menu', 'wpt_add_menu'); 12 add_action('plugins_loaded', 'wpt_plugin_load_textdomain'); 13 13 /** 14 14 * Load plugin textdomain. … … 16 16 * @since 1.0.0 17 17 */ 18 function myplugin_load_textdomain()18 function wpt_plugin_load_textdomain() 19 19 { 20 20 load_plugin_textdomain('wp-permalink-translator', false, basename(dirname(__FILE__)) . '/langs/'); 21 21 } 22 22 23 function add_menu_wp_permalink()23 function wpt_add_menu() 24 24 { 25 25 … … 374 374 375 375 // add our custom hook 376 add_filter('sanitize_title', 'wp se8170_sanitize_title_with_dashes', 10, 3);377 function wp se8170_sanitize_title_with_dashes($title, $raw_title = '', $context = 'display')376 add_filter('sanitize_title', 'wpt_sanitize_title_with_dashes', 10, 3); 377 function wpt_sanitize_title_with_dashes($title, $raw_title = '', $context = 'display') 378 378 { 379 379 $title = strip_tags($title); … … 427 427 } 428 428 429 function nth_position_nth($str, $letter, $n, $offset = 0)429 function wpt_nth_position_nth($str, $letter, $n, $offset = 0) 430 430 { 431 431 $str_arr = str_split($str); … … 446 446 } 447 447 448 function a_new_post($new_status, $old_status, $post)448 function wpt_new_post($new_status, $old_status, $post) 449 449 { 450 450 if ('publish' !== $new_status or 'publish' === $old_status) … … 454 454 return; // restrict the filter to a specific post type 455 455 456 // do something awesome 457 458 $postname = $post->post_title; 459 $outp = (wp_p_translateor($postname)); 460 461 $my_post = array( 456 457 $post_name = $post->post_title; 458 $new_post_name = (wpt_translate_post_url($post_name)); 459 460 $new_post = array( 462 461 'ID' => $post->ID, 463 'post_name' => $ outp,462 'post_name' => $new_post_name, 464 463 ); 465 464 466 465 // Update the post into the database 467 wp_update_post($my_post); 468 469 // $postslug = urldecode($post->post_name); 470 471 // $outp = str_replace(array("-for","-by-","-the-","-of-","-a-"),array("-"), $postslug); 472 // $my_post = array( 473 // 'ID' => $post->ID, 474 // 'post_name' => $outp, 475 // ); 476 // wp_update_post( $my_post ); 477 478 } 479 480 add_action('transition_post_status', 'a_new_post', 10, 3); 481 482 function wp_p_translateor($string) 483 { 484 485 $word1 = str_replace("،", " ", $string); 486 $word1 = str_replace(array("!", "?", "؟"), "", $word1); 487 // echo ($_GET['word'])."<br>"; 488 $word = wpse8170_sanitize_title_with_dashes($word1); 489 //echo urldecode($word)."<br>"; 490 491 $wordreplace = str_replace(array("-"), array(" "), $word); 466 wp_update_post($new_post); 467 468 469 } 470 471 add_action('transition_post_status', 'wpt_new_post', 10, 3); 472 473 function wpt_translate_post_url($string) 474 { 475 476 $word = str_replace("،", " ", $string); 477 $word = str_replace(array("!", "?", "؟"), "", $word); 478 $word = wpt_sanitize_title_with_dashes($word); 479 480 $word_replace = str_replace(array("-"), array(" "), $word); 492 481 $word = str_replace(array("-"), array("+"), $word); 493 494 //echo urldecode($wordreplace)."<br>";495 482 $from = get_option('trans_from', 'en'); 496 483 $to = get_option('trans_to', 'en'); 497 484 $url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" . $from . "&tl=" . $to . "&dt=t&q=" . ($word) . "&tbb=1&ie=UTF-8&oe=UTF-8"; 498 485 $fileEndEnd = (file_get_contents($url)); 499 $fileEndEnd = str_replace(array("[", "]", "\"", urldecode($wordreplace)), array("", "", "", ""), $fileEndEnd); 500 $arr = array(); 501 // echo $fileEndEnd."<br>"; 502 503 $charpo = nth_position_nth($fileEndEnd, ',', 1); 504 505 $str1 = substr($fileEndEnd, 0, $charpo); 506 $str2 = substr($fileEndEnd, $charpo + 1, strlen($fileEndEnd) - 1); 507 // echo $str1.$str2."<br>"; 486 $fileEndEnd = str_replace(array("[", "]", "\"", urldecode($word_replace)), array("", "", "", ""), $fileEndEnd); 487 $list = array(); 488 489 $char_positon = wpt_nth_position_nth($fileEndEnd, ',', 1); 490 491 $str1 = substr($fileEndEnd, 0, $char_positon); 492 $str2 = substr($fileEndEnd, $char_positon + 1, strlen($fileEndEnd) - 1); 508 493 509 494 for ($i = 0; $i < 3; $i++) { 510 $ arr= explode(',', $str1 . $str2);495 $list = explode(',', $str1 . $str2); 511 496 } 512 $outp = urldecode($arr[0]);513 return $outp ;497 $output = urldecode($list[0]); 498 return $output; 514 499 } 515 500 … … 521 506 522 507 foreach ( $my_posts as $post ): 523 $post name = $post->post_title;524 $outp = (wp_p_translateor($postname));525 526 $post->post_name = $outp ;508 $post_name = $post->post_title; 509 $output = (wpt_translate_post_url($post_name)); 510 511 $post->post_name = $output; 527 512 528 513 wp_update_post( $post );
Note: See TracChangeset
for help on using the changeset viewer.