Changeset 1991560
- Timestamp:
- 12/11/2018 09:00:32 AM (7 years ago)
- Location:
- amazon-polly/trunk
- Files:
-
- 2 added
- 13 edited
-
README.md (modified) (2 diffs)
-
README.txt (modified) (2 diffs)
-
admin/AmazonAI-BackgroundTask.php (added)
-
admin/AmazonAI-Common.php (modified) (11 diffs)
-
admin/AmazonAI-GeneralConfiguration.php (modified) (3 diffs)
-
admin/AmazonAI-Logger.php (added)
-
admin/AmazonAI-PodcastConfiguration.php (modified) (2 diffs)
-
admin/AmazonAI-PollyService.php (modified) (3 diffs)
-
admin/AmazonAI-S3FileHandler.php (modified) (2 diffs)
-
admin/AmazonAI-TranslateConfiguration.php (modified) (1 diff)
-
admin/AmazonAI-Translator.php (modified) (7 diffs)
-
amazonpolly.php (modified) (1 diff)
-
includes/class-amazonpolly-pollycast.php (modified) (2 diffs)
-
includes/class-amazonpolly.php (modified) (5 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
amazon-polly/trunk/README.md
r1967308 r1991560 7 7 | Requires PHP | 5.6 | 8 8 | Tested up to | 4.9 | 9 | Stable tag | 2.6. 0|9 | Stable tag | 2.6.1 | 10 10 | License | GPLv3 ONLY | 11 11 | License URI | https://www.gnu.org/licenses/gpl-3.0.html | … … 259 259 #### Changelog 260 260 261 = 2.6.1 = 262 * Added support for 8 new languages for translate functionality. 263 * Changed the way how audio is being generate (background process). 264 * Added a way of enabling plugin logging. 265 261 266 = 2.6.0 = 262 267 * Fix problem with media library. -
amazon-polly/trunk/README.txt
r1967308 r1991560 5 5 Requires PHP: 5.6 6 6 Tested up to: 4.9 7 Stable tag: 2.6. 07 Stable tag: 2.6.1 8 8 License: GPLv3 ONLY 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 252 252 == Changelog == 253 253 254 = 2.6.1 = 255 * Added support for 8 new languages for translate functionality. 256 * Changed the way how audio is being generate (background process). 257 * Added a way of enabling plugin logging. 258 254 259 = 2.6.0 = 255 260 * Fix problem with media library. -
amazon-polly/trunk/admin/AmazonAI-Common.php
r1967308 r1991560 13 13 // Information about languages supported by the Amazon AI plugin 14 14 private $languages = [ 15 ['code' => 'da', 'name' => 'Danish', 'transable' => ' ', 'polly' => '1'],16 ['code' => 'nl', 'name' => 'Dutch', 'transable' => ' ', 'polly' => '1'],15 ['code' => 'da', 'name' => 'Danish', 'transable' => '1', 'polly' => '1'], 16 ['code' => 'nl', 'name' => 'Dutch', 'transable' => '1', 'polly' => '1'], 17 17 ['code' => 'zh', 'name' => 'Chinese', 'transable' => '1', 'polly' => '1'], 18 18 ['code' => 'cs', 'name' => 'Czech', 'transable' => '1', 'polly' => ''], 19 19 ['code' => 'en', 'name' => 'English', 'transable' => '1', 'polly' => '1'], 20 ['code' => 'fi', 'name' => 'Finish', 'transable' => '1', 'polly' => ''], 20 21 ['code' => 'fr', 'name' => 'French', 'transable' => '1', 'polly' => '1'], 21 22 ['code' => 'de', 'name' => 'German', 'transable' => '1', 'polly' => '1'], 23 ['code' => 'he', 'name' => 'Hebraw', 'transable' => '1', 'polly' => ''], 22 24 ['code' => 'it', 'name' => 'Italian', 'transable' => '1', 'polly' => '1'], 25 ['code' => 'id', 'name' => 'Indonesian', 'transable' => '1', 'polly' => ''], 23 26 ['code' => 'ja', 'name' => 'Japanese', 'transable' => '1', 'polly' => '1'], 24 ['code' => 'ko', 'name' => 'Korean', 'transable' => ' ', 'polly' => '1'],27 ['code' => 'ko', 'name' => 'Korean', 'transable' => '1', 'polly' => '1'], 25 28 ['code' => 'nb', 'name' => 'Norwegian', 'transable' => '', 'polly' => '1'], 26 ['code' => 'pl', 'name' => 'Polish', 'transable' => ' ', 'polly' => '1'],29 ['code' => 'pl', 'name' => 'Polish', 'transable' => '1', 'polly' => '1'], 27 30 ['code' => 'pt', 'name' => 'Portuguese', 'transable' => '1', 'polly' => '1'], 28 31 ['code' => 'ro', 'name' => 'Romanian', 'transable' => '', 'polly' => '1'], 29 32 ['code' => 'ru', 'name' => 'Russian', 'transable' => '1', 'polly' => '1'], 30 33 ['code' => 'es', 'name' => 'Spanish', 'transable' => '1', 'polly' => '1'], 31 ['code' => 'sv', 'name' => 'Swedish', 'transable' => ' ', 'polly' => '1'],34 ['code' => 'sv', 'name' => 'Swedish', 'transable' => '1', 'polly' => '1'], 32 35 ['code' => 'tr', 'name' => 'Turkish', 'transable' => '1', 'polly' => '1'], 33 36 ['code' => 'cy', 'name' => 'Welsh', 'transable' => '', 'polly' => '1'] … … 214 217 private $local_file_handler; 215 218 private $translate; 219 private $logger; 220 216 221 /** 217 222 * Creates SDK objects for the plugin. … … 220 225 */ 221 226 public function __construct() { 222 //Empty227 $this->logger = new AmazonAI_Logger(); 223 228 } 224 229 … … 386 391 } 387 392 393 /** 394 * Validates if logging is enabled. 395 * 396 * @since 2.6.1 397 */ 398 public function is_logging_enabled() { 399 $value = $this->checked_validator('amazon_ai_logging'); 400 if ('checked' == trim($value)) { 401 return true; 402 } else { 403 return false; 404 } 405 } 388 406 389 407 /** … … 582 600 } 583 601 602 $this->logger->log(sprintf('%s Sample rate: %s ', __METHOD__, $sample_rate)); 603 584 604 return $sample_rate; 585 605 } … … 612 632 613 633 public function if_translable_enabled_for_language($language_code) { 614 $ option = 'amazon_polly_trans_langs_' . $language_code;615 $value = $this->check_if_language_is_checked($ option);634 $source_language_code = $this->get_source_language(); 635 $value = $this->check_if_language_is_checked($language_code, $source_language_code); 616 636 if (empty($value)) { 617 637 return false; … … 626 646 * @since 2.0.0 627 647 */ 628 public function check_if_language_is_checked($lang_code) 629 { 630 $value = get_option($lang_code, ''); 631 if ('amazon_polly_trans_langs_en' == $lang_code) { 632 return ' checked '; 633 } 648 public function check_if_language_is_checked($language_code, $source_language_code) 649 { 650 #Some translations between languages are not supported by the service. 651 #Details: https://docs.aws.amazon.com/translate/latest/dg/pairs.html 652 if (!$this->is_translation_supported($source_language_code, $language_code)) { 653 return ''; 654 } 655 656 $option = 'amazon_polly_trans_langs_' . $language_code; 657 658 $value = get_option($option, ''); 634 659 635 660 if (empty($value)) { … … 667 692 { 668 693 $posttypes = get_option('amazon_polly_posttypes', 'post'); 694 $posttypes = str_replace(",", " ", $posttypes); 695 $posttypes = preg_replace('!\s+!', ' ', $posttypes); 696 update_option('amazon_polly_posttypes', $posttypes); 697 669 698 return $posttypes; 670 699 } … … 732 761 { 733 762 $poweredby = get_option('amazon_polly_poweredby', 'on'); 734 763 735 764 if (empty($poweredby)) { 736 765 $result = false; … … 1078 1107 public function clean_text($post_id, $with_title, $only_title) 1079 1108 { 1109 1110 #$this->logger->log(sprintf('%s Cleaning text (%s, %s) ', __METHOD__, $with_title, $only_title)); 1111 1080 1112 $clean_text = ''; 1081 1113 … … 1352 1384 } 1353 1385 1386 public function is_translation_supported($source_language, $target_language) { 1387 1388 if (( 'ko'== $source_language ) && ( 'he' == $target_language )) { 1389 return false; 1390 } 1391 1392 return true; 1393 } 1394 1354 1395 /** 1355 1396 * Register meta box for 'Enable Amazon Polly' on post creation form. -
amazon-polly/trunk/admin/AmazonAI-GeneralConfiguration.php
r1967308 r1991560 135 135 'label_for' => 'amazon_polly_poweredby' 136 136 )); 137 add_settings_field('amazon_ai_logging', __('Enable logging:', 'amazonpolly'), array( 138 $this, 139 'logging_gui' 140 ), 'amazon_ai', 'amazon_ai_other', array( 141 'label_for' => 'amazon_ai_logging' 142 )); 137 143 138 144 register_setting('amazon_ai', 'amazon_ai_source_language'); … … 142 148 register_setting('amazon_ai', 'amazon_polly_posttypes'); 143 149 register_setting('amazon_ai', 'amazon_polly_poweredby'); 150 register_setting('amazon_ai', 'amazon_ai_logging'); 144 151 145 152 } … … 313 320 } 314 321 322 /** 323 * Render the 'Enable Logging' input. 324 * 325 * @since 2.6.2 326 */ 327 function logging_gui() 328 { 329 $checked = $this->common->checked_validator("amazon_ai_logging"); 330 echo '<input type="checkbox" name="amazon_ai_logging" id="amazon_ai_logging" ' . esc_attr($checked) . ' > <p class="description"></p>'; 331 } 332 315 333 function other_gui() 316 334 { -
amazon-polly/trunk/admin/AmazonAI-PodcastConfiguration.php
r1941297 r1991560 56 56 add_settings_field( 'amazon_polly_podcast_post_cat', __( 'Post categories:', 'amazonpolly' ), array( $this, 'podcast_post_cat_gui' ), 'amazon_ai_podcast', 'amazon_ai_podcast', array( 'label_for' => 'amazon_polly_podcast_post_cat' ) ); 57 57 add_settings_field( 'amazon_polly_podcast_author', __( 'Author:', 'amazonpolly' ), array( $this, 'podcast_author_gui' ), 'amazon_ai_podcast', 'amazon_ai_podcast', array( 'label_for' => 'amazon_polly_podcast_author' ) ); 58 add_settings_field( 'amazon_polly_podcast_https', __( 'Use HTTPS for audio files:', 'amazonpolly' ), array( $this, 'podcast_https_gui' ), 'amazon_ai_podcast', 'amazon_ai_podcast', array( 'label_for' => 'amazon_polly_podcast_https' ) ); 58 59 59 60 register_setting('amazon_ai_podcast', 'amazon_polly_podcast_email'); … … 64 65 register_setting('amazon_ai_podcast', 'amazon_polly_podcast_post_cat'); 65 66 register_setting('amazon_ai_podcast', 'amazon_polly_podcast_author'); 66 } 67 register_setting('amazon_ai_podcast', 'amazon_polly_podcast_https'); 68 } 69 } 70 71 72 /** 73 * Render the HTTPS podcast input. 74 * 75 * @since 4.0.5 76 */ 77 public function podcast_https_gui() { 78 79 echo '<input type="checkbox" name="amazon_polly_podcast_https" id="amazon_polly_podcast_https" ' . $this->common->checked_validator( 'amazon_polly_podcast_https' ) . '> '; 80 67 81 } 68 82 -
amazon-polly/trunk/admin/AmazonAI-PollyService.php
r1967308 r1991560 12 12 13 13 class AmazonAI_PollyService { 14 const GENERATE_POST_AUDIO_TASK = 'generate_post_audio'; 15 const NONCE_NAME = 'amazon-polly-post-nonce'; 14 16 15 17 /** 16 * Important. Run whenever new post is being created (or updated). The method executes Amazon Polly API to create audio file.18 * Important. Run whenever new post is being created (or updated). The method generates a background task to generate the audio file. 17 19 * 18 20 * @since 1.0.0 … … 24 26 $common->init(); 25 27 28 $logger = new AmazonAI_Logger(); 29 $logger->log(sprintf('%s Saving post ( id=%s )', __METHOD__, $post_id)); 30 26 31 // Check if this isn't an auto save. 27 32 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { … … 37 42 $post_types_supported = $common->get_posttypes_array(); 38 43 $post_type = get_post_type($post_id); 39 if ( !in_array($post_type, $post_types_supported )) {44 if ( !in_array($post_type, $post_types_supported) ) { 40 45 return; 41 46 } 42 47 43 $is_quick_edit = isset($_POST['_inline_edit']) && wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce'); 44 $is_polly_nonce_ok = isset( $_POST['amazon-polly-post-nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['amazon-polly-post-nonce'] ), 'amazon-polly' ); 45 46 // Check if this post is saved in 'regular' way. 47 if ( $is_polly_nonce_ok || $is_quick_edit ) { 48 49 $is_polly_enabled = isset( $_POST['amazon_polly_enable'] ); 50 51 // Check if translation deactivation flag is enabled. If yes, disable 52 // and delete all files. 53 $is_translate_deactivation_enabled = isset( $_POST['amazon_ai_deactive_translation'] ); 54 if ( !empty($is_translate_deactivation_enabled) ) { 48 // If nonce is valid then update post meta 49 // If it's not valid then this is probably a quick or bulk edit request in which case we won't update the polly post meta 50 if ( isset($_POST[self::NONCE_NAME]) && wp_verify_nonce($_POST[self::NONCE_NAME], 'amazon-polly') ) { 51 update_post_meta( $post_id, 'amazon_polly_enable', (int) isset($_POST['amazon_polly_enable'])); 52 53 // If disabling post translation 54 if ( isset($_POST['amazon_ai_deactive_translation']) ) { 55 55 $common->deactive_translation_for_post($post_id); 56 56 } 57 57 58 $is_post_id_available = isset( $post_id ); 59 $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); 60 61 // If this is quick edit, we need to check other place to see if polly was already enabled for this post. 62 if ( $is_post_id_available && $is_quick_edit ) { 63 if ( 1 == get_post_meta( $post_id, 'amazon_polly_enable', true)) { 64 $is_polly_enabled = true; 65 } 66 } 67 68 // Input var okay. 69 $is_amazon_polly_voice_id_available = isset( $_POST['amazon_polly_voice_id'] ); 70 71 if ( $is_post_id_available && $is_polly_enabled && $is_key_valid && $is_amazon_polly_voice_id_available ) { 72 73 // Getting voice and sample rate which should be used for converting post to audio. 74 $voice_id = sanitize_text_field( wp_unslash( $_POST['amazon_polly_voice_id'] ) ); 75 $sample_rate = $common->get_sample_rate(); 76 77 // Cleaning text. Includes for example removing not supported characters etc. 78 $clean_text = $common->clean_text( $post_id, true, false); 79 80 // Breaking text into smaller parts, which will be then send to Amazon Polly for conversion. 81 $sentences = $common->break_text( $clean_text ); 82 83 // We will be operating on local file system for stiching files together. 84 $wp_filesystem = $common->prepare_wp_filesystem(); 85 86 // Actual invocation of method which will call Amazon Polly API and create audio file. 87 $this->convert_to_audio( $post_id, $sample_rate, $voice_id, $sentences, $wp_filesystem, '' ); 88 89 // Checking what was the source language of text and updating options for translate operations. 90 $source_language = $common->get_source_language(); 91 update_post_meta( $post_id, 'amazon_polly_transcript_' . $source_language, $clean_text ); 92 update_post_meta( $post_id, 'amazon_polly_transcript_source_lan', $source_language ); 93 94 } 95 96 // It's possible that Amazon Polly was not enabled, then we make sure that the audio file 97 // for the post is deleted (if existing) and options are removed. 98 if ( $is_post_id_available && ! $is_polly_enabled ) { 99 $common->delete_post_audio( $post_id ); 100 update_post_meta( $post_id, 'amazon_polly_enable', 0 ); 101 update_post_meta( $post_id, 'amazon_polly_audio_location', '' ); 102 } 103 } 58 // Update post voice ID 59 if ( isset( $_POST['amazon_polly_voice_id']) ) { 60 $voice_id = sanitize_text_field(wp_unslash($_POST['amazon_polly_voice_id'])); 61 update_post_meta( $post_id, 'amazon_polly_voice_id', $voice_id); 62 } 63 } 64 65 $background_task = new AmazonAI_BackgroundTask(); 66 $background_task->trigger(self::GENERATE_POST_AUDIO_TASK, [ $post_id ]); 67 } 68 69 /** 70 * Important. Executes the Amazon Polly API to create audio file and save to the configured storage location 71 * 72 * @since 1.0.0 73 */ 74 public function generate_audio( $post_id ) { 75 76 $logger = new AmazonAI_Logger(); 77 $logger->log(sprintf('%s Generating audio for post ( id=%s )', __METHOD__, $post_id)); 78 79 /** 80 * Fires before attempting to generate and save the Amazon Polly audio files 81 * 82 * @param int $post_id The post id to generate audio files for 83 */ 84 do_action('amazon_polly_pre_generate_audio', $post_id); 85 86 // Creating new standard common object for interacting with other methods of the plugin. 87 $common = new AmazonAI_Common(); 88 $common->init(); 89 90 $is_polly_enabled = (bool) get_post_meta($post_id, 'amazon_polly_enable', true); 91 $is_key_valid = (bool) get_option('amazon_polly_valid_keys'); 92 $voice_id = get_post_meta($post_id, 'amazon_polly_voice_id', true); 93 94 if ( $is_polly_enabled && $is_key_valid ) { 95 96 $logger->log(sprintf('%s Basic validation OK', __METHOD__)); 97 98 // Sammple Rate 99 $sample_rate = $common->get_sample_rate(); 100 101 // Cleaning text. Includes for example removing not supported characters etc. 102 $clean_text = $common->clean_text( $post_id, true, false); 103 104 // Breaking text into smaller parts, which will be then send to Amazon Polly for conversion. 105 $sentences = $common->break_text( $clean_text ); 106 107 // We will be operating on local file system for stiching files together. 108 $wp_filesystem = $common->prepare_wp_filesystem(); 109 110 // Actual invocation of method which will call Amazon Polly API and create audio file. 111 $this->convert_to_audio( $post_id, $sample_rate, $voice_id, $sentences, $wp_filesystem, '' ); 112 113 // Checking what was the source language of text and updating options for translate operations. 114 $source_language = $common->get_source_language(); 115 update_post_meta( $post_id, 'amazon_polly_transcript_' . $source_language, $clean_text ); 116 update_post_meta( $post_id, 'amazon_polly_transcript_source_lan', $source_language ); 117 } 118 119 // Remove audio files and post meta (if existing) if Polly is not enabled 120 else if ( ! $is_polly_enabled ) { 121 $common->delete_post_audio( $post_id ); 122 update_post_meta( $post_id, 'amazon_polly_audio_location', '' ); 123 } 124 125 /** 126 * Fires after attempting to generate and save the Amazon Polly audio files 127 * 128 * @param int $post_id The post id to generate audio files for 129 */ 130 do_action('amazon_polly_post_generate_audio', $post_id, $is_polly_enabled); 104 131 } 105 132 -
amazon-polly/trunk/admin/AmazonAI-S3FileHandler.php
r1967308 r1991560 136 136 public function create_s3_bucket() { 137 137 138 $logger = new AmazonAI_Logger(); 139 $logger->log(sprintf('%s Creating new S3 Bucket', __METHOD__)); 140 138 141 $createNewBucket = true; 139 142 … … 153 156 $createNewBucket = false; 154 157 158 $logger->log(sprintf('%s New S3 Bucket created ( name=%s )', __METHOD__, $name)); 159 155 160 } catch ( Aws\S3\Exception\S3Exception $e ) { 161 $logger->log(sprintf('%s Failed to Create new S3 Bucket! ( error=%s )', __METHOD__, $e)); 156 162 error_log($e); 157 163 update_option( 'amazon_polly_s3_bucket', '' ); -
amazon-polly/trunk/admin/AmazonAI-TranslateConfiguration.php
r1942322 r1991560 119 119 $lan_display = 'amazon_polly_trans_langs_' . $lanuage . '_display'; 120 120 $disabled = ''; 121 if ( ($src_lang == $lanuage) or ('en' == $lanuage)) {121 if ( $src_lang == $lanuage ) { 122 122 $disabled = 'disabled'; 123 123 } 124 124 125 #Some translations between languages are not supported by the service. 126 #Details: https://docs.aws.amazon.com/translate/latest/dg/pairs.html 127 if (!$this->common->is_translation_supported($src_lang, $lanuage)) { 128 $disabled = 'disabled'; 129 } 130 125 131 echo '<tr>'; 126 echo '<td><input type="checkbox" name="' . $lan_option . '" id="' . $lan_option . '" ' . $this->common->check_if_language_is_checked($lan _option, $src_lang) . ' ' . $disabled . '>' . $language_name . ' </td><td>';132 echo '<td><input type="checkbox" name="' . $lan_option . '" id="' . $lan_option . '" ' . $this->common->check_if_language_is_checked($lanuage, $src_lang) . ' ' . $disabled . '>' . $language_name . ' </td><td>'; 127 133 $voice_id = get_option($lan_voice_option); 128 134 -
amazon-polly/trunk/admin/AmazonAI-Translator.php
r1935214 r1991560 107 107 public function translate( $translate_client, $source_text, $source_language, $target_language) { 108 108 109 $logger = new AmazonAI_Logger(); 110 $logger->log(sprintf('%s Traslating', __METHOD__)); 111 109 112 // Translate functionality doesn't support SSML, ONLYAUDIO, ONLYWORDS tags 110 113 $source_text = preg_replace( '/(\*\*AMAZONPOLLY\*SSML\*BREAK\*)(.*?)(\*\*\*)(.*?)(\*\*\*SSML\*\*)/', '', $source_text ); … … 140 143 141 144 } 145 146 $logger->log(sprintf('%s Translated text:', __METHOD__)); 147 $logger->log(sprintf('%s', $translated_text)); 142 148 143 149 return $translated_text; … … 207 213 $common->init(); 208 214 215 $logger = new AmazonAI_Logger(); 216 $logger->log(sprintf('%s Ajax Translate', __METHOD__)); 217 209 218 $post_id = $_POST['post_id']; 210 219 $phase = $_POST['phase']; 211 220 $langs = $_POST['langs']; 221 222 $logger->log(sprintf('%s Phase ( %s )', __METHOD__, $phase)); 212 223 213 224 $step = ''; … … 225 236 $step = 'done'; 226 237 $percentage = 100; 238 239 $logger->log(sprintf('%s Transalte functionality is not enabled )', __METHOD__)); 227 240 228 241 } else { … … 240 253 241 254 $langs = $all_langs; 242 243 if ( 'en' == $source_language ) {244 $english_content = get_post_field('post_content', $post_id);245 update_post_meta( $post_id, 'amazon_polly_transcript_en', $english_content );246 }247 248 255 update_post_meta( $post_id, 'amazon_ai_source_language', $source_language ); 249 256 250 257 } else { 251 258 252 253 if ( ( $key = array_search( 'en', $langs ) ) !== false ) { 254 $language_code = 'en'; 255 unset( $langs[ $key ] ); 256 } else { 257 $language_code = array_shift( $langs ); 258 } 259 260 if ( 'en' == $language_code ) { 261 $clean_text = $common->clean_text( $post_id, false, false ); 262 } else { 263 $english_content = get_post_meta( $post_id, 'amazon_polly_transcript_en', true ); 264 $source_language = 'en'; 265 } 259 $logger->log(sprintf('%s Languages ( %s )', __METHOD__, implode(" ", $langs))); 260 261 # Check what language 262 $language_code = array_shift( $langs ); 263 264 #Retrieve original text 265 $content = get_post_field('post_content', $post_id); 266 $clean_text = $common->clean_text( $post_id, false, false ); 267 268 $logger->log(sprintf('%s Translating from ( %s ) to ( %s )', __METHOD__, $source_language, $language_code)); 266 269 267 270 $wp_filesystem = $common->prepare_wp_filesystem(); … … 272 275 $clean_title = $common->clean_text( $post_id, false, true ); 273 276 $translated_title = $this->translate( $translate_client, $clean_title, $source_language, $language_code); 274 $translated_text = $this->translate_post( $common, $translate_client, $ english_content, $source_language, $language_code);277 $translated_text = $this->translate_post( $common, $translate_client, $content, $source_language, $language_code); 275 278 update_post_meta( $post_id, 'amazon_polly_transcript_' . $language_code, $translated_text ); 276 279 update_post_meta( $post_id, 'amazon_polly_transcript_title_' . $language_code, $translated_title ); … … 295 298 }//end if 296 299 297 $next_langs = $langs; 298 if ( ( 'en' != $source_language ) && ( $key = array_search( 'en', $next_langs ) ) !== false ) { 299 $next_lang = 'en'; 300 } else { 301 $next_lang = array_shift( $next_langs ); 302 } 300 $temp_langs = $langs; 301 $next_lang = array_shift( $temp_langs ); 303 302 304 303 if ( ! empty( $next_lang ) ) { 304 $logger->log(sprintf('%s Next language ( %s ))', __METHOD__, $next_lang)); 305 305 $message = 'Translating from ' . $common->get_language_name( $source_language ) . ' to ' . $common->get_language_name( $next_lang ); 306 306 } else { -
amazon-polly/trunk/amazonpolly.php
r1967308 r1991560 17 17 * Plugin URI: https://wordpress.org/plugins/amazon-polly/ 18 18 * Description: Create audio version of your posts, translate them into other languages and create podcasts! Amazon Polly is a service that turns text into lifelike speech. With dozens of voices across a variety of languages, you can select the ideal voice and build engaging speech-enabled applications that work in many different countries. The Amazon Polly plugin for WordPress is a sample application that shows how WordPress creators can easily add Text-to-Speech capabilities to written content with Amazon Polly. You can generate an audio feed for text-based content and insert it into an embedded player to increase the accessibility of your WordPress site. The sample code also enables you to publish podcasts directly from your site and make them available for listeners in the form of podcasts. In addition, the plugin allows to translate your text from one language to another using Amazon Translate– which is a neural machine translation service that delivers fast, high-quality, and affordable language translation. Amazon Translate allows you to localize content - such as websites and applications - for international users, and to easily translate large volumes of text efficiently. 19 * Version: 2.6. 019 * Version: 2.6.1 20 20 * Author: AWS Labs, WP Engine 21 21 * Author URI: https://aws.amazon.com/ -
amazon-polly/trunk/includes/class-amazonpolly-pollycast.php
r1935214 r1991560 95 95 */ 96 96 public function get_posttypes_array() { 97 $posttypes_array = get_option( 'amazon_polly_posttypes', 'post' ); 97 $this->common = new AmazonAI_Common(); 98 $posttypes_array = $this->common->get_posttypes(); 98 99 $posttypes_array = explode( ' ', $posttypes_array ); 99 100 $posttypes_array = apply_filters( 'amazon_polly_post_types', $posttypes_array ); … … 113 114 public function get_audio_file_location( $post_id ) { 114 115 $audio_file_location = get_post_meta( $post_id, 'amazon_polly_audio_link_location', true ); 115 $audio_file_location = str_replace( 'https://', 'http://', $audio_file_location ); 116 117 $https_enabled = get_option( 'amazon_polly_podcast_https' ); 118 if ( empty( $https_enabled ) ) { 119 $audio_file_location = str_replace( 'https://', 'http://', $audio_file_location ); 120 } 116 121 117 122 return $audio_file_location; -
amazon-polly/trunk/includes/class-amazonpolly.php
r1967308 r1991560 113 113 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/amazonpolly-metabox.php'; 114 114 115 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-BackgroundTask.php'; 115 116 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Exceptions.php'; 116 117 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Translator.php'; … … 119 120 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-S3FileHandler.php'; 120 121 122 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Logger.php'; 121 123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Common.php'; 122 124 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-PollyService.php'; … … 176 178 private function define_admin_hooks() { 177 179 180 $background_task = new AmazonAI_BackgroundTask(); 178 181 $general_configuration = new AmazonAI_GeneralConfiguration(); 179 182 $polly_configuration = new AmazonAI_PollyConfiguration(); … … 185 188 $translate_service = new AmazonAI_Translator(); 186 189 190 $this->loader->add_action( sprintf('admin_post_%s', AmazonAI_BackgroundTask::ADMIN_POST_ACTION), $background_task, 'run' ); 191 187 192 $this->loader->add_action( 'admin_print_footer_scripts', $common, 'add_quicktags' ); 188 193 $this->loader->add_action( 'admin_enqueue_scripts', $common, 'enqueue_styles' ); … … 190 195 $this->loader->add_action( 'add_meta_boxes', $common, 'field_checkbox' ); 191 196 $this->loader->add_action( 'save_post', $polly_service, 'save_post', 10, 3 ); 197 $this->loader->add_action( 'amazon_polly_background_task_generate_post_audio', $polly_service, 'generate_audio', 10, 3 ); 192 198 193 199 -
amazon-polly/trunk/uninstall.php
r1898887 r1991560 9 9 */ 10 10 11 12 error_log("DDD");13 11 // If uninstall not called from WordPress, then exit. 14 12 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 15 16 error_log("Usuwam");17 13 exit; 18 14 }
Note: See TracChangeset
for help on using the changeset viewer.