public function display_polly_gui()

in admin/AmazonAI-PostMetaBox.php [40:105]


  public function display_polly_gui($post) {
    $nonce = wp_create_nonce('amazon-polly');

    echo '<input type="hidden" name="amazon-polly-post-nonce" value="' . esc_attr($nonce) . '" />';

    // Check if Text-To-Speech (Amazon Polly) functionality is enabled.
    if ($this->common->is_polly_enabled()) {
      // Check if Amazon Polly is enabled for specific post.
      // 1 - Means that it's enabled for post
      // 0 - Means that it's not enabled for the post
      // No value - Means that it's new post
      $is_polly_enabled_for_post = get_post_meta($post->ID, 'amazon_polly_enable', true);
      if ('1' === $is_polly_enabled_for_post) {
        $polly_checked = 'checked';
      }
      elseif ('0' === $is_polly_enabled_for_post) {
        $polly_checked = '';
      }
      else {
        if ($this->common->is_polly_enabled_for_new_posts()) {
          $polly_checked = 'checked';
        }
        else {
          $polly_checked = '';
        }
      }

      $post_options_visibility = '';

      echo '<p><input type="checkbox" name="amazon_polly_enable" id="amazon_polly_enable" value="1"  ' . esc_attr($polly_checked) . '/><label for="amazon_polly_enable">Enable Text-To-Speech (Amazon Polly)</label> </p>';
      echo '<div id="amazon_polly_post_options" style="' . esc_attr($post_options_visibility) . '">';

      if (! function_exists('sort_polly_voices')) {
        function sort_polly_voices($voice1, $voice2) {
          return strcmp($voice1['LanguageName'], $voice2['LanguageName']);
        }
      }

      $voice_id = $this->common->get_voice_id();
      $voices = $this->common->get_polly_voices();
      $language_name = $this->common->get_source_language_name();

      $voice_id = get_post_meta($post->ID, 'amazon_polly_voice_id', true);
      $global_voice_id = $this->common->get_voice_id();

      if (0 === strcmp($voice_id, '') && '' !== $global_voice_id) {
        $voice_id = $global_voice_id;
      }

      usort($voices['Voices'], 'sort_polly_voices');

      echo '<p>Voice name: <select name="amazon_polly_voice_id" id="amazon_polly_voice_id" >';
      foreach ($voices['Voices'] as $voice) {
        if (strpos($voice['LanguageName'], $language_name) !== false) {
          echo '<option value="' . esc_attr($voice['Id']) . '" ';
          if (strcmp($voice_id, $voice['Id']) === 0) {
            echo 'selected="selected"';
          }
          echo '>' . esc_attr($voice['LanguageName']) . ' - ' . esc_attr($voice['Id']) . '</option>';
        }
      }
      echo '</select></p>';

      echo '</div>';
    }
  }