Plugin Directory

Changeset 2032304


Ignore:
Timestamp:
02/16/2019 08:50:35 PM (7 years ago)
Author:
hossin277
Message:

-add github repository link
-fix bugs

Location:
wp-permalink-translator
Files:
19 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-permalink-translator/trunk/readme.txt

    r2012240 r2032304  
    1313Allow admins to translate Permalink to another languages.
    1414
     15### Development
     16[https://github.com/hossinasaadi/wp-permalink-translator/](https://github.com/hossinasaadi/wp-permalink-translator/ "https://github.com/hossinasaadi/wp-permalink-translator")
    1517
    1618
     
    2426== Changelog ==
    2527
     28= 1.7.6 =
     29* fix some bugs.
     30
    2631= 1.7.5 =
    2732* added tool to translate all posts at once.
     
    2934 
    3035== Upgrade Notice ==
     36
     37= 1.7.6 =
     38* fix some bugs.
    3139
    3240= 1.7.5 =
  • wp-permalink-translator/trunk/wp-permalink-translator.php

    r2012257 r2032304  
    44Plugin URI: https://wordpress.org/plugins/wp-permalink-translator/
    55Description: a plugin to translate Permalink to another languages.
    6 Version: 1.7.5
     6Version: 1.7.6
    77Author: Hossin Asaadi
    88Author URI: https://profiles.wordpress.org/hossin277/
    99License: GPL2
    1010*/
    11 add_action('admin_menu', 'add_menu_wp_permalink');
    12 add_action('plugins_loaded', 'myplugin_load_textdomain');
     11add_action('admin_menu', 'wpt_add_menu');
     12add_action('plugins_loaded', 'wpt_plugin_load_textdomain');
    1313/**
    1414 * Load plugin textdomain.
     
    1616 * @since 1.0.0
    1717 */
    18 function myplugin_load_textdomain()
     18function wpt_plugin_load_textdomain()
    1919{
    2020    load_plugin_textdomain('wp-permalink-translator', false, basename(dirname(__FILE__)) . '/langs/');
    2121}
    2222
    23 function add_menu_wp_permalink()
     23function wpt_add_menu()
    2424{
    2525
     
    374374
    375375// add our custom hook
    376 add_filter('sanitize_title', 'wpse8170_sanitize_title_with_dashes', 10, 3);
    377 function wpse8170_sanitize_title_with_dashes($title, $raw_title = '', $context = 'display')
     376add_filter('sanitize_title', 'wpt_sanitize_title_with_dashes', 10, 3);
     377function wpt_sanitize_title_with_dashes($title, $raw_title = '', $context = 'display')
    378378{
    379379    $title = strip_tags($title);
     
    427427}
    428428
    429 function nth_position_nth($str, $letter, $n, $offset = 0)
     429function wpt_nth_position_nth($str, $letter, $n, $offset = 0)
    430430{
    431431    $str_arr = str_split($str);
     
    446446}
    447447
    448 function a_new_post($new_status, $old_status, $post)
     448function wpt_new_post($new_status, $old_status, $post)
    449449{
    450450    if ('publish' !== $new_status or 'publish' === $old_status)
     
    454454        return; // restrict the filter to a specific post type
    455455
    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(
    462461        'ID' => $post->ID,
    463         'post_name' => $outp,
     462        'post_name' => $new_post_name,
    464463    );
    465464
    466465    // 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
     471add_action('transition_post_status', 'wpt_new_post', 10, 3);
     472
     473function 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);
    492481    $word = str_replace(array("-"), array("+"), $word);
    493 
    494 //echo urldecode($wordreplace)."<br>";
    495482    $from = get_option('trans_from', 'en');
    496483    $to = get_option('trans_to', 'en');
    497484    $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";
    498485    $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);
    508493
    509494    for ($i = 0; $i < 3; $i++) {
    510         $arr = explode(',', $str1 . $str2);
     495        $list = explode(',', $str1 . $str2);
    511496    }
    512     $outp = urldecode($arr[0]);
    513     return $outp;
     497    $output = urldecode($list[0]);
     498    return $output;
    514499}
    515500
     
    521506
    522507    foreach ( $my_posts as $post ):
    523         $postname = $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;
    527512
    528513        wp_update_post( $post );
Note: See TracChangeset for help on using the changeset viewer.