Required only if you aren\'t using IAM roles
'; } /** * Render the Secret Key input for this plugin * * @since 1.0.0 */ public function amazon_polly_secret_key_cb() { $secret_key = get_option( 'amazon_polly_secret_key' ); echo ' '; echo 'Required only if you aren\'t using IAM roles
'; } /** * Render the Automated Breath input. * * @since 1.0.7 */ public function amazon_polly_auto_breaths_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $is_breaths_enabled = $this->amazon_polly_is_auto_breaths_enabled(); if ( $is_breaths_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; echo 'If enabled, Amazon Polly automatically creates breathing noises at appropriate intervals
'; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Podcast enabled input. * * @since 1.0.7 */ public function amazon_polly_podcast_enabled_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $is_podcast_enabled = $this->amazon_polly_is_podcast_enabled(); if ( $is_podcast_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; echo 'If enabled, Amazon Pollycast will be generated
'; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Add post title to audio input. * * @since 1.0.7 */ public function amazon_polly_add_post_title_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $is_title_adder_enabled = $this->amazon_polly_is_title_adder_enabled(); if ( $is_title_adder_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; echo 'If enabled, each audio file will start from post title.
'; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Default Configuration input. * * @since 1.0.0 */ public function amazon_polly_defconf_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $selected_defconf = get_option( 'amazon_polly_defconf' ); $defconf_values = [ 'Amazon Polly enabled', 'Amazon Polly disabled' ]; echo ''; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Position input. * * @since 1.0.0 */ public function amazon_polly_position_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $selected_position = get_option( 'amazon_polly_position' ); $positions_values = array( 'Before post', 'After post', 'Do not show' ); echo ''; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Player Label input. * * @since 1.0.3 */ public function amazon_polly_player_label_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $player_label = get_option( 'amazon_polly_player_label' ); echo ' '; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Post Type input box. * * @since 1.0.7 */ public function amazon_polly_posttypes_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $posttypes = $this->amazon_polly_get_posttypes(); echo ' '; echo 'Post types in your WordPress environment
'; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the text for the Amazon Polly settings section * * @since 1.0.7 */ public function amazon_polly_pollysettings_cb() { } /** * Render the text for Player settings section * * @since 1.0.7 */ public function amazon_polly_playersettings_cb() { } /** * Render the text for the storage section * * @since 1.0.0 */ public function amazon_polly_storage_cb() { } /** * Render the text for the additional section * * @since 1.0.0 */ public function amazon_polly_additional_cb() { } /** * Render the 'store in S3' input. * * @since 1.0.0 */ public function amazon_polly_s3_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $selected_s3 = get_option( 'amazon_polly_s3' ); $s3_bucket_name = $this->get_bucket_name(); $message = ''; if ( empty( $s3_bucket_name ) ) { $checkbox_disabled = ''; } else { $checkbox_disabled = ''; } if ( empty( $selected_s3 ) ) { $checked = ' '; $bucket_name_visibility = 'display:none'; } else { $checked = ' checked '; $bucket_name_visibility = ' '; } echo '' . esc_attr( $message ) . '
'; $is_s3_enabled = $this->amazon_polly_is_s3_enabled(); if ( $is_s3_enabled ) { echo ''; } echo 'Audio files are saved on and streamed from Amazon S3. Learn more https://aws.amazon.com/s3
'; } else { echo 'Please verify your AWS Credentials are accurate
'; }//end if } /** * Render the 'use CloudFront' input. * * @since 1.0.0 */ public function amazon_polly_cloudfront_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $is_s3_enabled = $this->amazon_polly_is_s3_enabled(); if ( $is_s3_enabled ) { $cloudfront_domain_name = get_option( 'amazon_polly_cloudfront' ); $s3_enabled = get_option( 'amazon_polly_s3' ); if ( empty( $s3_enabled ) ) { $disabled = ' disabled="disabled" '; } else { $disabled = ' '; } echo ' '; echo 'If you have set up CloudFront distribution for your S3 bucket, the name of the domain. For additional information and pricing, see: https://aws.amazon.com/cloudfront
'; } else { echo 'Amazon S3 Storage needs to be enabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the enable SSML input. * * @since 1.0.7 */ public function amazon_polly_ssml_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $is_s3_enabled = $this->amazon_polly_is_s3_enabled(); if ( $is_s3_enabled ) { $is_ssml_enabled = $this->amazon_polly_is_ssml_enabled(); if ( $is_ssml_enabled ) { $checked = ' checked '; } else { $checked = ' '; } echo ' '; } else { echo 'Amazon S3 Storage needs to be enabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the autoplay input. * * @since 1.0.0 */ public function amazon_polly_autoplay_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $selected_autoplay = get_option( 'amazon_polly_autoplay' ); if ( empty( $selected_autoplay ) ) { $checked = ' '; } else { $checked = ' checked '; } echo ' '; echo 'Automatically play audio content when page loads
'; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the autoplay input. * * @since 1.0.5 */ public function amazon_polly_speed_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $speed = $this->amazon_polly_get_speed(); echo ''; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Return post type value. * * @since 1.0.7 */ public function amazon_polly_get_posttypes() { $posttypes = get_option( 'amazon_polly_posttypes', 'post' ); return $posttypes; } /** * Return post type value array. * * @since 1.0.7 */ public function amazon_polly_get_posttypes_array() { $posttypes_array = get_option( 'amazon_polly_posttypes', 'post' ); $posttypes_array = explode( ' ', $posttypes_array ); $posttypes_array = apply_filters( 'amazon_polly_post_types', $posttypes_array ); return $posttypes_array; } /** * Check if AWS credentials are correct * * @since 1.0.7 */ private function amazon_polly_is_ok() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { return true; } else { return false; } } /** * Check if SSML is enabled. * * @since 1.0.7 */ public function amazon_polly_is_ssml_enabled() { $ssml_enabled = get_option( 'amazon_polly_ssml', 'on' ); if ( empty( $ssml_enabled ) ) { $result = false; } else { $result = true; } $is_s3_enabled = $this->amazon_polly_is_s3_enabled(); if ( $is_s3_enabled ) { return $result; } return false; } /** * Return speed for audio files. * * @since 1.0.5 */ public function amazon_polly_get_speed() { $speed = get_option( 'amazon_polly_speed' ); if ( empty( $speed ) ) { $speed = '100'; } if ( intval( $speed ) < 20 ) { $speed = '20'; } if ( intval( $speed ) > 200 ) { $speed = '200'; } update_option( 'amazon_polly_speed', $speed ); return $speed; } /** * Checks if pollycast is enabled. * * @since 1.0.7 */ public function amazon_polly_is_podcast_enabled() { $value = get_option( 'amazon_polly_podcast_enabled', 'on' ); if ( empty( $value ) ) { $result = false; } else { $result = true; } return $result; } /** * Checks if auto breaths are enabled. * * @since 1.0.7 */ public function amazon_polly_is_auto_breaths_enabled() { $value = get_option( 'amazon_polly_auto_breaths', 'on' ); if ( empty( $value ) ) { $result = false; } else { $result = true; } return $result; } /** * Checks if post title should be added. * * @since 1.0.7 */ public function amazon_polly_is_title_adder_enabled() { $value = get_option( 'amazon_polly_add_post_title', 'on' ); if ( empty( $value ) ) { $result = false; } else { $result = true; } return $result; } /** * Render the region input. * * @since 1.0.3 */ public function amazon_polly_region_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $selected_region = get_option( 'amazon_polly_region' ); $regions = array( 'us-east-1' => 'US East (N. Virginia)', 'us-east-2' => 'US East (Ohio)', 'us-west-1' => 'US West (N. California)', 'us-west-2' => 'US West (Oregon)', 'eu-west-1' => 'EU (Ireland)', 'eu-west-2' => 'EU (London)', 'eu-west-3' => 'EU (Paris)', 'eu-central-1' => 'EU (Frankfurt)', 'ca-central-1' => 'Canada (Central)', 'sa-east-1' => 'South America (Sao Paulo)', 'ap-southeast-1' => 'Asia Pacific (Singapore)', 'ap-northeast-1' => 'Asia Pacific (Tokyo)', 'ap-southeast-2' => 'Asia Pacific (Sidney)', 'ap-northeast-2' => 'Asia Pacific (Seul)', 'ap-south-1' => 'Asia Pacific (Mumbai)', ); echo ''; } else { echo 'Please verify your AWS Credentials are accurate
'; }//end if } /** * Render the Sample Rate input for this plugin * * @since 1.0.0 */ public function amazon_polly_sample_rate_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $sample_rate = get_option( 'amazon_polly_sample_rate' ); $sample_array = array( '22050', '16000', '8000' ); echo ''; } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Validate if AWS credentials are proper. * * @since 1.0.0 */ private function amazon_polly_validate_credentials() { try { $voice_list = $this->client->describeVoices(); update_option( 'amazon_polly_valid_keys', '1' ); } catch ( Exception $e ) { update_option( 'amazon_polly_valid_keys', '0' ); } } /** * Render the Polly Voice input for this plugin * * @since 1.0.0 */ public function amazon_polly_voice_id_cb() { /** * Compare two voices for ordering purpose. * * @param string $voice1 First voice. * @param string $voice2 Second voice. * @since 1.0.0 */ function sort_voices( $voice1, $voice2 ) { return strcmp( $voice1['LanguageName'], $voice2['LanguageName'] ); } $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $voice_id = get_option( 'amazon_polly_voice_id' ); $voice_list = $this->client->describeVoices(); echo ''; } else { $voice_id = get_option( 'amazon_polly_voice_id' ); echo ''; echo 'Please verify your AWS Credentials are accurate
'; }//end if } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function amazon_polly_update_all_cb() { $this->amazon_polly_validate_credentials(); $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { $message = $this->get_price_message_for_update_all(); echo ''; echo ''; echo ''; echo '
'; echo '' . esc_html( $message ) . '
'; echo ''; echo 'Please verify your AWS Credentials are accurate
'; } } /** * Podcast section description. * * @since 1.0.0 */ public function amazon_pollycast_cb() { if ( $this->amazon_polly_is_podcast_enabled() ) { echo 'Amazon Pollycast available at: ' . esc_html( get_feed_link( 'amazon-pollycast' ) ) . '
'; echo 'Submit your Amazon Pollycast to iTunes iConnect: ' . esc_html( 'https://podcastsconnect.apple.com/' ) . '
'; } } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function amazon_polly_podcast_email_cb() { $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { if ( $this->amazon_polly_is_podcast_enabled() ) { $selected_email = get_option( 'amazon_polly_podcast_email' ); echo ''; } else { echo 'Amazon Pollycast is disabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function amazon_polly_podcast_category_cb() { $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); $default_category = 'News & Politics'; $select_categories = array( 'Arts', 'Business', 'Comedy', 'Education', 'Games & Hobbies', 'Government & Organizations', 'Health', 'Kids', 'Music', 'News & Politics', 'Religion', 'Science & Medicine', 'Society & Culture', 'Sports & Recreation', 'Technology', 'TV & Film', ); if ( $is_key_valid ) { if ( $this->amazon_polly_is_podcast_enabled() ) { $selected_category = get_option( 'amazon_polly_podcast_category' ); if ( ! $selected_category ) { $selected_category = 'News & Politics'; } echo ''; } else { echo 'Amazon Pollycast is disabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function amazon_polly_podcast_explicit_cb() { $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); $select_explicits = array( 'yes', 'no', ); if ( $is_key_valid ) { if ( $this->amazon_polly_is_podcast_enabled() ) { $selected_explicit = get_option( 'amazon_polly_podcast_explicit' ); echo ''; } else { echo 'Amazon Pollycast is disabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Render the Update All input for this plugin * * @since 1.0.0 */ public function amazon_polly_podcast_icon_cb() { $is_key_valid = ( get_option( 'amazon_polly_valid_keys' ) === '1' ); if ( $is_key_valid ) { if ( $this->amazon_polly_is_podcast_enabled() ) { $query['autofocus[section]'] = 'amazonpolly'; $section_link = add_query_arg( $query, admin_url( 'customize.php' ) ); echo 'Upload a podcast icon using the Customizer.
'; } else { echo 'Amazon Pollycast is disabled
'; } } else { echo 'Please verify your AWS Credentials are accurate
'; } } /** * Determine how many posts should be transcribed. */ public function get_num_posts_needing_transcription() { $post_types_supported = $this->amazon_polly_get_posttypes_array(); $amazon_polly_voice_id = get_option( 'amazon_polly_voice_id' ); $amazon_polly_sample_rate = get_option( 'amazon_polly_sample_rate' ); $amazon_polly_audio_location = ( 'on' === get_option( 'amazon_polly_s3' ) ) ? 's3' : 'local'; $args = array( 'posts_per_page' => '-1', 'post_type' => $post_types_supported, 'meta_query' => array( 'relation' => 'AND', array( 'key' => $this->audio_location_link_metakey, 'compare' => 'EXISTS', ), array( 'key' => 'amazon_polly_voice_id', 'value' => $amazon_polly_voice_id, 'compare' => '=', ), array( 'key' => 'amazon_polly_sample_rate', 'value' => $amazon_polly_sample_rate, 'compare' => '=', ), array( 'key' => 'amazon_polly_audio_location', 'value' => $amazon_polly_audio_location, 'compare' => '=', ), ), ); $query = new WP_Query( $args ); return count( $query->posts ); } /** * Calculate the total price of converting all posts into audio. * * @since 1.0.0 */ private function get_price_message_for_update_all() { $post_types_supported = $this->amazon_polly_get_posttypes_array(); $number_of_characters = 0; $posts_per_page = apply_filters( 'amazon_polly_posts_per_page', 5 ); $count_posts = wp_count_posts()->publish; $max_count_posts = 100; // Retrieving the number of characters in all posts. $paged = 0; $post_count = 0; do { $paged++; $wp_query = new WP_Query( array( 'posts_per_page' => $posts_per_page, 'post_type' => $post_types_supported, 'fields' => 'ids', 'paged' => $paged, ) ); $number_of_posts = $wp_query->max_num_pages; while ( $wp_query->have_posts() ) { $post_count++; $wp_query->the_post(); $post_id = get_the_ID(); $post_sentences = $this->prepare_post_text( $post_id ); if ( ! empty( $post_sentences ) ) { foreach ( $post_sentences as $sentence ) { $sentence = str_replace( '