Changeset 2768836
- Timestamp:
- 08/10/2022 11:06:45 AM (4 years ago)
- Location:
- easytranslate/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (1 diff)
-
admin/class-easy-translate-post-translation-list.php (modified) (2 diffs)
-
admin/class-easy-translate-translation-list.php (modified) (5 diffs)
-
admin/class-easy-translate-translation-updater.php (modified) (4 diffs)
-
admin/class-easy-translate-translation.php (modified) (4 diffs)
-
easy-translate.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easytranslate/trunk/README.txt
r2762429 r2768836 5 5 Requires at least: 4.7 6 6 Tested up to: 6.0 7 Stable tag: 4. 27 Stable tag: 4.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
easytranslate/trunk/admin/class-easy-translate-post-translation-list.php
r2674447 r2768836 338 338 $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION); 339 339 $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options)); 340 $response = $service->translate($this->source_language, array_keys($_REQUEST['target_languages']), 341 $content, $workflow, $name); 340 $response = $service->translate( 341 $this->source_language, 342 array_keys($_REQUEST['target_languages']), 343 $content, 344 $workflow, 345 $name 346 ); 342 347 if ($response['error'] ?? false) { 343 348 add_settings_error( … … 357 362 ); 358 363 $this->update_string_status($a_string_id, self::STATUS_WAITING); 359 $this->update_duplicate_status($_REQUEST['posts'], array_keys($_REQUEST['target_languages']), 360 self::STATUS_WAITING); 364 $this->update_duplicate_status( 365 $_REQUEST['posts'], 366 array_keys($_REQUEST['target_languages']), 367 self::STATUS_WAITING 368 ); 361 369 } else { 362 370 add_settings_error( -
easytranslate/trunk/admin/class-easy-translate-translation-list.php
r2762424 r2768836 12 12 * Translation statuses. 13 13 */ 14 const STATUS_NOT_TRANSLATED = 0;15 const STATUS_WAITING = 1;16 const STATUS_PARTIAL = 2;17 const STATUS_NEEDS_UPDATE = 3;18 const STATUS_DUPLICATE = 9;19 const STATUS_COMPLETE = 10;14 const STATUS_NOT_TRANSLATED = ICL_TM_NOT_TRANSLATED; 15 const STATUS_WAITING = ICL_TM_WAITING_FOR_TRANSLATOR; 16 const STATUS_PARTIAL = ICL_STRING_TRANSLATION_PARTIAL; 17 const STATUS_NEEDS_UPDATE = ICL_TM_NEEDS_UPDATE; 18 const STATUS_DUPLICATE = ICL_TM_DUPLICATE; 19 const STATUS_COMPLETE = ICL_TM_COMPLETE; 20 20 21 21 /** … … 379 379 public function invalid_nonce_redirect() 380 380 { 381 382 381 wp_die(__('Invalid Nonce', EASY_TRANSLATE), 383 382 __('Error', EASY_TRANSLATE), … … 450 449 * Updates post content and title. 451 450 * 451 * @param int $source_post_id 452 452 * @param int $post_id 453 453 * @param string $post_content 454 454 * @param string $post_title 455 * @return bool|int 456 */ 457 public static function update_post($post_id, $post_content, $post_title = '') 458 { 459 460 $set_title = ''; 455 * @param string $post_excerpt 456 * @param array $woocommerce 457 */ 458 public static function update_post( 459 int $source_post_id, 460 int $post_id, 461 string $post_content = '', 462 string $post_title = '', 463 string $post_excerpt = '', 464 array $woocommerce = [] 465 ) { 466 $update = ''; 461 467 if ($post_title) { 462 $set_title = ', post_title="' . $post_title . '"'; 468 $update = ', post_title="' . esc_sql($post_title) . '"'; 469 } 470 if ($post_excerpt) { 471 $update = ', post_excerpt="' . esc_sql($post_excerpt) . '"'; 463 472 } 464 473 465 474 global $wpdb; 466 475 $post_content = esc_sql($post_content); 467 $post_id = intval($post_id); 468 $query = "UPDATE {$wpdb->prefix}posts SET post_content = '{$post_content}' {$set_title} WHERE id = {$post_id}"; 469 470 return $wpdb->query($query); 471 476 $query = "UPDATE {$wpdb->prefix}posts SET post_content = '{$post_content}' {$update} WHERE id = {$post_id}"; 477 $wpdb->query($query); 478 479 if (empty($woocommerce)) { 480 return; 481 } 482 483 if (isset($woocommerce['_product_attributes'])) { 484 $post_meta_fields = get_post_meta($post_id); 485 $attributes = []; 486 if (isset($post_meta_fields['_product_attributes']) && !empty($product_attributes = $post_meta_fields['_product_attributes'])) { 487 foreach (unserialize($product_attributes[0]) as $field_name => $values) { 488 if (!isset($woocommerce['_product_attributes'][$field_name])) { 489 continue; 490 } 491 $attributes[$field_name] = $values; 492 $attributes[$field_name]['name'] = $woocommerce['_product_attributes'][$field_name]['name']; 493 $attributes[$field_name]['value'] = $woocommerce['_product_attributes'][$field_name]['value']; 494 } 495 496 if (!empty($attributes)) { 497 update_post_meta($post_id, '_product_attributes', $attributes); 498 } 499 } 500 } 501 if (isset($woocommerce['_purchase_note'])) { 502 update_post_meta($post_id, '_purchase_note', $woocommerce['_purchase_note']); 503 } 472 504 } 473 505 … … 566 598 * Return post content. 567 599 * 568 * @param int $post_id569 * @param $a_string_id570 * @param bool $updated600 * @param int $post_id 601 * @param array $a_string_id 602 * @param bool $updated 571 603 * @return array 572 604 */ 573 public static function get_post_content($post_id, &$a_string_id, $updated = false) 574 { 575 605 public static function get_post_content(int $post_id, array &$a_string_id, $updated = false): array 606 { 576 607 $content = []; 577 608 $package_id = self::get_post_package_id($post_id); … … 595 626 $content['post_full'][$post_id]['title'] = $post->post_title; 596 627 } 628 if ($post->post_excerpt) { 629 $content['post_full'][$post_id]['excerpt'] = $post->post_excerpt; 630 } 631 632 $post_meta_fields = get_post_meta($post_id); 633 if (isset($post_meta_fields['_product_attributes']) && !empty($product_attributes = $post_meta_fields['_product_attributes'])) { 634 foreach (unserialize($product_attributes[0]) as $field_name => $values) { 635 $content['post_full'][$post_id]['woocommerce']['_product_attributes'][$field_name]['name'] = $values['name']; 636 $content['post_full'][$post_id]['woocommerce']['_product_attributes'][$field_name]['value'] = $values['value']; 637 } 638 } 639 if (isset($post_meta_fields['_purchase_note']) && !empty($purchase_note = $post_meta_fields['_purchase_note'])) { 640 $content['post_full'][$post_id]['woocommerce']['_purchase_note'] = $purchase_note; 641 } 597 642 } 598 643 -
easytranslate/trunk/admin/class-easy-translate-translation-updater.php
r2674447 r2768836 17 17 public function run($post_id) 18 18 { 19 20 if (get_post_meta($post_id, 'et_auto_translate', true) && Easy_Translate_Translation_List::compare_post_source_language($post_id) && Easy_Translate_Translation_List::check_dependencies()) { 21 $a_string_id = array(); 19 if (get_post_meta($post_id, 'et_auto_translate', true) 20 && Easy_Translate_Translation_List::compare_post_source_language($post_id) 21 && Easy_Translate_Translation_List::check_dependencies() 22 ) { 23 $a_string_id = []; 22 24 $content[] = Easy_Translate_Translation_List::get_post_content($post_id, $a_string_id, false); 23 25 … … 27 29 28 30 if ($this->update_strings($source, $target_languages, $content)) { 29 Easy_Translate_Translation_List::update_string_status($a_string_id, Easy_Translate_Translation_List::STATUS_WAITING); 30 Easy_Translate_Translation_List::update_duplicate_status(array($post_id), $target_languages, Easy_Translate_Translation_List::STATUS_WAITING); 31 Easy_Translate_Translation_List::update_string_status( 32 $a_string_id, 33 Easy_Translate_Translation_List::STATUS_WAITING 34 ); 35 Easy_Translate_Translation_List::update_duplicate_status( 36 [$post_id], 37 $target_languages, 38 Easy_Translate_Translation_List::STATUS_WAITING 39 ); 31 40 } 32 41 } 33 42 } 34 35 43 } 36 44 … … 39 47 * 40 48 * @param string $source 41 * @param array $target42 * @param array $content49 * @param array $target 50 * @param array $content 43 51 * @return bool 44 52 */ 45 53 protected function update_strings($source, $target, $content) 46 54 { 47 48 55 $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION); 49 56 $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options)); … … 51 58 52 59 return !isset($result['error']); 53 54 60 } 55 56 61 } -
easytranslate/trunk/admin/class-easy-translate-translation.php
r2674447 r2768836 13 13 * Translation status. 14 14 */ 15 const STATUS_COMPLETE = 10;15 const STATUS_COMPLETE = ICL_TM_COMPLETE; 16 16 17 17 /** … … 45 45 protected function post_strings_handler($content, $target_language) 46 46 { 47 48 47 if (isset(current($content)['title']) && current($content)['title']) { 49 48 if ($source_translations = Easy_Translate_Post_Translation_List::get_translations_by_element_id(key($content))) { 50 if ($translations = Easy_Translate_Post_Translation_List::get_translations_by_source($source_translations, 51 $target_language)) { 52 Easy_Translate_Post_Translation_List::update_post_title($translations['element_id'], 53 current($content)['title']); 49 $translations = Easy_Translate_Post_Translation_List::get_translations_by_source( 50 $source_translations, 51 $target_language 52 ); 53 if ($translations) { 54 Easy_Translate_Post_Translation_List::update_post_title( 55 $translations['element_id'], 56 current($content)['title'] 57 ); 54 58 } 55 59 } 56 60 } 61 57 62 $this->strings_handler(current($content)['content'], $target_language); 58 59 63 } 60 64 … … 67 71 protected function post_full_handler($content, $target_language) 68 72 { 69 70 73 $source_post_id = key($content); 71 $post_title = current($content)['title'] ?? ''; 72 $post_content = current($content)['content']; 74 $post_title = $content[$source_post_id]['title'] ?? null; 75 $post_content = $content[$source_post_id]['content'] ?? null; 76 $post_excerpt = $content[$source_post_id]['excerpt'] ?? null; 77 $woocommerce = $content[$source_post_id]['woocommerce'] ?? []; 73 78 74 79 if ($source_translations = Easy_Translate_Post_Translation_List::get_translations_by_element_id($source_post_id)) { 75 76 if ($translations = Easy_Translate_Post_Translation_List::get_translations_by_source($source_translations, 77 $target_language)) { 78 80 $translations = Easy_Translate_Post_Translation_List::get_translations_by_source( 81 $source_translations, 82 $target_language 83 ); 84 if ($translations) { 79 85 if (isset($translations['element_id'])) { 80 Easy_Translate_Post_Translation_List::update_post($translations['element_id'], $post_content, 81 $post_title); 82 Easy_Translate_Post_Translation_List::update_translations_status($translations['translation_id'], 83 self::STATUS_COMPLETE); 86 Easy_Translate_Post_Translation_List::update_post( 87 $source_post_id, 88 $translations['element_id'], 89 $post_content, 90 $post_title, 91 $post_excerpt, 92 $woocommerce 93 ); 94 Easy_Translate_Post_Translation_List::update_translations_status( 95 $translations['translation_id'], 96 self::STATUS_COMPLETE 97 ); 84 98 } 85 99 } 86 100 } 87 88 101 } 89 102 … … 112 125 protected function fetch_content($task) 113 126 { 114 115 127 $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION); 116 128 $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options)); -
easytranslate/trunk/easy-translate.php
r2762424 r2768836 15 15 * Plugin URI: https://www.easytranslate.com/en/integrations/cms/wordpress-plugin/ 16 16 * Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area. 17 * Version: 1. 6.217 * Version: 1.7.0 18 18 * Author: EasyTranslate 19 19 * Author URI: https://easytranslate.com … … 34 34 * Rename this for your plugin and update it as you release new versions. 35 35 */ 36 define('EASY_TRANSLATE_VERSION', '1. 6.2');36 define('EASY_TRANSLATE_VERSION', '1.7.0'); 37 37 38 38 /**
Note: See TracChangeset
for help on using the changeset viewer.