Plugin Directory

Changeset 2268197


Ignore:
Timestamp:
03/26/2020 01:24:22 PM (6 years ago)
Author:
awslabs
Message:

trunk 4.2.0

Location:
amazon-polly/trunk
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • amazon-polly/trunk/README.md

    r2219187 r2268197  
    77| Requires PHP | 5.6 |
    88| Tested up to | 5.3 |
    9 | Stable tag | 4.0.3 |
     9| Stable tag | 4.2.0 |
    1010| License | GPLv3 ONLY |
    1111| License URI | https://www.gnu.org/licenses/gpl-3.0.html |
     
    136136#### Changelog
    137137
     138= 4.2.0 =
     139* Code Refactoring
     140
    138141= 4.0.3 =
    139 * Bug Fixing.
    140 *
     142* Bug Fixing
     143
     144*
    141145= 4.0.2 =
    142146* Added translate support for multiple new languages
  • amazon-polly/trunk/README.txt

    r2219187 r2268197  
    55Requires PHP: 5.6
    66Tested up to: 5.3
    7 Stable tag: 4.0.3
     7Stable tag: 4.2.0
    88License: GPLv3 ONLY
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    134134
    135135== Changelog ==
     136
     137= 4.2.0 =
     138* Code Refactoring
    136139
    137140= 4.0.3 =
  • amazon-polly/trunk/admin/AmazonAI-AlexaConfiguration.php

    r2031081 r2268197  
    1111class AmazonAI_AlexaConfiguration
    1212{
     13    /**
     14     * @var AmazonAI_Common
     15     */
     16    private $common;
     17
     18    /**
     19     * AmazonAI_PodcastConfiguration constructor.
     20     *
     21     * @param AmazonAI_Common $common
     22     */
     23    public function __construct(AmazonAI_Common $common) {
     24        $this->common = $common;
     25    }
    1326
    1427    public function amazon_ai_add_menu()
     
    2942     </div>
    3043     <?php
    31 
    32       $this->common = new AmazonAI_Common();
    33       $this->common->init();
    3444      if ( $this->common->is_podcast_enabled() ) {
    3545        echo '<p class="description">You can extend WordPress websites and blogs through Alexa devices. This opens new possibilities for the creators and authors of websites to reach an even broader audience. It also makes it easier for people to listen to their favorite blogs by just asking Alexa to read them! </p>';
  • amazon-polly/trunk/admin/AmazonAI-CloudFrontConfiguration.php

    r2188605 r2268197  
    1515    private $cloudformation; //Required to retrieve Cloudformation service
    1616
    17     public function __construct() {
    18         $this->common = new AmazonAI_Common();
    19         $this->common->init();
    20         $this->cloudformation = new AmazonAI_Cloudformation();
     17    public function __construct(AmazonAI_Common $common, AmazonAI_Cloudformation $cloudformation) {
     18        $this->common = $common;
     19        $this->cloudformation = $cloudformation;
    2120    }
    2221
  • amazon-polly/trunk/admin/AmazonAI-Cloudformation.php

    r2188605 r2268197  
    2020    private $stack_resources;
    2121
    22     public function __construct() {
    23         $this->common = new AmazonAI_Common();
    24         $this->common->init();
     22    public function __construct(AmazonAI_Common $common) {
     23        $this->common = $common;
    2524        $this->cloudformation_client = $this->common->get_cloudformation_client();
    2625        $this->acm_client = $this->common->get_acm_client();
  • amazon-polly/trunk/admin/AmazonAI-Common.php

    r2219187 r2268197  
    7171    ];
    7272
     73    private $sdk;
     74    private $sdk_use1; // SDK with region fixed as us-east-1
     75    private $polly_client;
     76    private $translate_client;
     77    private $s3_handler;
     78    private $local_file_handler;
     79    private $translate;
     80    private $logger;
     81    private $cloudformation_client;
     82    private $cloudfront_client;
     83    private $acm_client;
     84
     85    /**
     86     * Creates SDK objects for the plugin.
     87     *
     88     * @since    2.5.0
     89     */
     90    public function __construct() {
     91        $this->logger = new AmazonAI_Logger();
     92    }
     93
    7394    public function prepare_paragraphs($post_id) {
    7495
     
    259280  }
    260281
    261     private $sdk;
    262     private $sdk_use1; // SDK with region fixed as us-east-1
    263     private $polly_client;
    264     private $translate_client;
    265     private $s3_handler;
    266     private $local_file_handler;
    267     private $translate;
    268     private $logger;
    269     private $cloudformation_client;
    270     private $cloudfront_client;
    271     private $acm_client;
    272 
    273     /**
    274      * Creates SDK objects for the plugin.
    275      *
    276      * @since    2.5.0
    277      */
    278     public function __construct() {
    279         $this->logger = new AmazonAI_Logger();
    280     }
    281 
    282282    public function init() {
    283283        $aws_sdk_config = $this->get_aws_sdk_config();
     
    286286        $this->translate_client = $this->sdk->createTranslate();
    287287
    288         $this->s3_handler = new AmazonAI_S3FileHandler();
    289         $this->local_file_handler = new AmazonAI_LocalFileHandler();
     288        $this->s3_handler = new AmazonAI_S3FileHandler($this);
     289        $this->local_file_handler = new AmazonAI_LocalFileHandler($this);
    290290
    291291        $this->s3_handler->set_s3_client($this->sdk->createS3());
    292         $this->translate = new AmazonAI_Translator();
     292        $this->translate = new AmazonAI_Translator($this);
    293293
    294294        $aws_sdk_config_use1 = $this->get_aws_sdk_config_use1();
     
    625625        $file_name  = 'amazon_polly_' . $post_id . $language . '.mp3';
    626626        $s3BucketName = $this->get_s3_bucket_name();
    627         $cloudfront_domain_name = get_option( 'amazon_polly_cloudfront' );
     627        $cloudfront_domain_name = apply_filters('amazon_polly_cloudfront_domain', get_option( 'amazon_polly_cloudfront' ));
    628628
    629629        if ( get_option('uploads_use_yearmonth_folders') ) {
     
    768768    public function get_aws_region()
    769769    {
    770         $region = get_option('amazon_polly_region');
     770        $region = apply_filters('amazon_polly_aws_region', get_option('amazon_polly_region'));
    771771        if (empty($region)) {
    772772            update_option('amazon_polly_region', 'us-east-1');
     
    12121212     * @since    2.5.0
    12131213     */
    1214     private function get_aws_sdk_config()
    1215     {
     1214    private function get_aws_sdk_config($region = null)
     1215    {
     1216        $aws_sdk_config = [
     1217            'region' => $this->get_aws_region(),
     1218            'version' => 'latest',
     1219        ];
     1220        $credentials = false;
    12161221        $aws_access_key = get_option('amazon_polly_access_key');
    12171222        $aws_secret_key = get_option('amazon_polly_secret_key');
    1218         if (empty($aws_access_key)) {
    1219             $aws_sdk_config = array(
    1220                 'region' => $this->get_aws_region() ,
    1221                 'version' => 'latest',
    1222             );
    1223         }
    1224         else {
    1225             $aws_sdk_config = array(
    1226                 'region' => $this->get_aws_region() ,
    1227                 'version' => 'latest',
    1228                 'credentials' => array(
    1229                     'key' => $aws_access_key,
    1230                     'secret' => $aws_secret_key,
    1231                 ) ,
    1232             );
     1223
     1224        if ($aws_access_key && $aws_secret_key) {
     1225            $credentials = [
     1226                'key' => $aws_access_key,
     1227                'secret' => $aws_secret_key,
     1228            ];
     1229        }
     1230
     1231        if ($credentials = apply_filters('amazon_polly_aws_sdk_credentials', $credentials)) {
     1232            $aws_sdk_config['credentials'] = $credentials;
     1233        }
     1234
     1235        if ($region) {
     1236            $aws_sdk_config['region'] = $region;
    12331237        }
    12341238
     
    12361240    }
    12371241
    1238      /**
     1242  /**
    12391243      * Returns AWS SDK configuration to allow connection with AWS account and region us-east-1.
    12401244      *
     
    12421246      */
    12431247    private function get_aws_sdk_config_use1()
    1244         {
    1245             $aws_access_key = get_option('amazon_polly_access_key');
    1246             $aws_secret_key = get_option('amazon_polly_secret_key');
    1247             if (empty($aws_access_key)) {
    1248                 $aws_sdk_config = array(
    1249                     'region' => 'us-east-1' ,
    1250                     'version' => 'latest',
    1251                 );
    1252             }
    1253             else {
    1254                 $aws_sdk_config = array(
    1255                     'region' => 'us-east-1' ,
    1256                     'version' => 'latest',
    1257                     'credentials' => array(
    1258                         'key' => $aws_access_key,
    1259                         'secret' => $aws_secret_key,
    1260                     ) ,
    1261                 );
    1262             }
    1263 
    1264             return $aws_sdk_config;
    1265         }
     1248    {
     1249        return $this->get_aws_sdk_config('us-east-1');
     1250    }
    12661251
    12671252
     
    16761661     */
    16771662    public function add_quicktags() {
    1678 
    1679         $common = new AmazonAI_Common();
    1680         $is_ssml_enabled = $common->is_ssml_enabled();
     1663        $is_ssml_enabled = $this->is_ssml_enabled();
    16811664
    16821665        if ( $is_ssml_enabled ) {
     
    18481831        $post_types_supported = $this->get_posttypes_array();
    18491832
     1833        $meta_box = new AmazonAI_PostMetaBox($this);
     1834
    18501835        add_meta_box(
    18511836            'amazon_polly_box_id',
     
    18531838            'Amazon Polly',
    18541839            // Title of the box.
    1855             'amazon_polly_box_content',
     1840            [ $meta_box, 'display_box_content'],
    18561841            // Function to be called to display the checkboxes, see the function below.
    18571842            $post_types_supported,
     
    19041889    }
    19051890
    1906 
    1907 
     1891        public function aws_configuration_update($new_value, $old_value) {
     1892
     1893            $default_value = '********************';
     1894
     1895            if ( !isset($new_value) ) {
     1896                $new_value = $default_value;
     1897            }
     1898
     1899            if ($new_value != $default_value) {
     1900                update_option('amazon_polly_secret_key', $new_value);
     1901            }
     1902
     1903            return $default_value;
     1904    }
    19081905
    19091906}
  • amazon-polly/trunk/admin/AmazonAI-GeneralConfiguration.php

    r2183170 r2268197  
    1212class AmazonAI_GeneralConfiguration
    1313{
     14    /**
     15     * @var AmazonAI_Common
     16     */
     17    private $common;
    1418
    15   private $common;
    16 
     19    /**
     20     * AmazonAI_GeneralConfiguration constructor.
     21     *
     22     * @param AmazonAI_Common $common
     23     */
     24    public function __construct(AmazonAI_Common $common) {
     25        $this->common = $common;
     26    }
    1727
    1828    public function amazon_ai_add_menu()
     
    5868    {
    5969
    60         $this->common = new AmazonAI_Common();
    61         $this->common->init();
    62 
    6370        // ************************************************* *
    6471        // ************** GENERAL SECTION ************** *
     
    7380            'label_for' => 'amazon_polly_access_key'
    7481        ));
    75         add_settings_field('amazon_polly_secret_key', __('AWS secret key:', 'amazonpolly'), array(
     82        add_settings_field('amazon_polly_secret_key_fake', __('AWS secret key:', 'amazonpolly'), array(
    7683            $this,
    7784            'secret_key_gui'
    7885        ), 'amazon_ai', 'amazon_ai_general', array(
    79             'label_for' => 'amazon_polly_secret_key'
     86            'label_for' => 'amazon_polly_secret_key_fake'
    8087        ));
    8188
    8289
    8390        register_setting('amazon_ai', 'amazon_polly_access_key');
    84         register_setting('amazon_ai', 'amazon_polly_secret_key');
     91        register_setting('amazon_ai', 'amazon_polly_secret_key_fake');
    8592
    8693          add_settings_field('amazon_polly_region', __('AWS Region:', 'amazonpolly'), array(
     
    116123     */
    117124    function secret_key_gui() {
    118         $secret_key = get_option('amazon_polly_secret_key');
    119         echo '<input type="password" class="regular-text" name="amazon_polly_secret_key" id="amazon_polly_secret_key" value="' . esc_attr($secret_key) . '" autocomplete="off"> ';
     125        $secret_key = get_option('amazon_polly_secret_key_fake','********************');
     126        echo '<input type="password" class="regular-text" name="amazon_polly_secret_key_fake" id="amazon_polly_secret_key_fake" value="' . esc_attr($secret_key) . '" autocomplete="off"> ';
    120127        echo '<p class="description" id="amazon_polly_access_key">Required only if you aren\'t using IAM roles</p>';
    121128    }
  • amazon-polly/trunk/admin/AmazonAI-LocalFileHandler.php

    r1967308 r2268197  
    1111
    1212class AmazonAI_LocalFileHandler extends AmazonAI_FileHandler {
     13    /**
     14     * @var AmazonAI_Common
     15     */
     16    private $common;
    1317
     18    /**
     19     * AmazonAI_LocalFileHandler constructor.
     20     *
     21     * @param AmazonAI_Common $common
     22     */
     23    public function __construct(AmazonAI_Common $common) {
     24        $this->common = $common;
     25    }
    1426
    1527  /**
     
    7385
    7486        // Adding audio info to media library (If Media Library was selected)
    75         $common = new AmazonAI_Common();
     87        $common = $this->common;
    7688        if ($common->is_medialibrary_enabled()) {
    7789
  • amazon-polly/trunk/admin/AmazonAI-Logger.php

    r1991560 r2268197  
    1313    public function log($log) {
    1414
    15         if (true === WP_DEBUG) {
    16 
    17             $common = new AmazonAI_Common();
    18             if ( $common->is_logging_enabled() ) {
    19                 error_log($log);
    20             }
    21 
     15        if (true === WP_DEBUG && apply_filters('amazon_polly_logging_enabled', false)) {
     16            error_log($log);
    2217        }
    2318    }
  • amazon-polly/trunk/admin/AmazonAI-PodcastConfiguration.php

    r2188605 r2268197  
    1111
    1212class AmazonAI_PodcastConfiguration {
     13    /**
     14     * @var AmazonAI_Common
     15     */
     16    private $common;
     17
     18    /**
     19     * AmazonAI_PodcastConfiguration constructor.
     20     *
     21     * @param AmazonAI_Common $common
     22     */
     23    public function __construct(AmazonAI_Common $common) {
     24        $this->common = $common;
     25    }
    1326
    1427    public function amazon_ai_add_menu() {
     
    4053        function display_options()
    4154        {
    42 
    43             $this->common = new AmazonAI_Common();
    44             $this->common->init();
    45 
    4655            add_settings_section('amazon_ai_podcast', "Amazon Pollycast configuration", array($this,'podcast_gui'), 'amazon_ai_podcast');
    4756            add_settings_field( 'amazon_polly_podcast_enabled', __( 'Pollycast enabled:', 'amazonpolly' ), array( $this, 'podcast_enabled_gui' ), 'amazon_ai_podcast', 'amazon_ai_podcast', array( 'label_for' => 'amazon_polly_podcast_enabled' ) );
  • amazon-polly/trunk/admin/AmazonAI-PollyConfiguration.php

    r2218638 r2268197  
    1111
    1212class AmazonAI_PollyConfiguration {
    13 
    14   private $common;
     13    /**
     14     * @var AmazonAI_Common
     15     */
     16    private $common;
     17
     18    /**
     19     * AmazonAI_PollyConfiguration constructor.
     20     *
     21     * @param AmazonAI_Common $common
     22     */
     23    public function __construct(AmazonAI_Common $common) {
     24        $this->common = $common;
     25    }
    1526
    1627    public function amazon_ai_add_menu() {
     
    4253    function display_options()
    4354    {
    44 
    45         $this->common = new AmazonAI_Common();
    46     $this->common->init();
    47 
    4855        register_setting('amazon_ai_polly', 'amazon_ai_polly_enable');
    4956        add_settings_section('amazon_ai_polly', "Amazon Polly configuration", array($this,'polly_gui'), 'amazon_ai_polly');
  • amazon-polly/trunk/admin/AmazonAI-PollyService.php

    r2218638 r2268197  
    1515    const NONCE_NAME = 'amazon-polly-post-nonce';
    1616
     17    /**
     18     * @var AmazonAI_Common
     19     */
     20    private $common;
     21
     22    /**
     23     * AmazonAI_PollyService constructor.
     24     *
     25     * @param AmazonAI_Common $common
     26     */
     27    public function __construct(AmazonAI_Common $common) {
     28        $this->common = $common;
     29    }
    1730
    1831    /**
     
    2235     */
    2336    public function save_post( $post_id, $post, $updated ) {
    24 
    25         // Creating new standard common object for interacting with other methods of the plugin.
    26         $common = new AmazonAI_Common();
    27         $common->init();
    28 
     37        $common = $this->common;
    2938        $logger = new AmazonAI_Logger();
    3039        $logger->log(sprintf('%s Saving post ( id=%s )', __METHOD__, $post_id));
     
    7786     */
    7887    public function generate_audio( $post_id ) {
    79 
    8088        $logger = new AmazonAI_Logger();
    8189        $logger->log(sprintf('%s Generating audio for post ( id=%s )', __METHOD__, $post_id));
     
    8997
    9098        // Creating new standard common object for interacting with other methods of the plugin.
    91         $common = new AmazonAI_Common();
    92         $common->init();
    93 
     99        $common = $this->common;
    94100        $is_polly_enabled = (bool) get_post_meta($post_id, 'amazon_polly_enable', true);
    95101        $is_key_valid = (bool) get_option('amazon_polly_valid_keys');
     
    258264
    259265        // Creating new standard common object for interacting with other methods of the plugin.
    260         $common = new AmazonAI_Common();
    261         $common->init();
     266        $common = $this->common;
    262267
    263268        // This part will be called only in case of translate opration and converting
     
    539544
    540545            $batch_size                  = 1;
    541             $common = new AmazonAI_Common();
    542             $common->init();
     546            $common = $this->common;
    543547            $post_types_supported        = $common->get_posttypes_array();
    544548            $amazon_polly_voice_id       = $common->get_voice_id();
     
    607611        private function get_percentage_complete() {
    608612            $total_posts               = 0;
    609             $common = new AmazonAI_Common();
    610             $common->init();
     613            $common = $this->common;
    611614            $post_types_supported      = $common->get_posttypes_array();
    612615            $posts_needing_translation = $this->get_num_posts_needing_transcription();
     
    634637            public function get_num_posts_needing_transcription() {
    635638
    636                 $common = new AmazonAI_Common();
    637                 $common->init();
     639                $common = $this->common;
    638640                $post_types_supported        = $common->get_posttypes_array();
    639641                $amazon_polly_voice_id       = get_option( 'amazon_polly_voice_id' );
  • amazon-polly/trunk/admin/AmazonAI-S3FileHandler.php

    r1991560 r2268197  
    1111
    1212class AmazonAI_S3FileHandler extends AmazonAI_FileHandler {
    13 
    14   private $s3_client;
     13    private $s3_client;
     14 
     15    /**
     16     * @var AmazonAI_Common
     17     */
     18    private $common;
     19
     20    /**
     21     * AmazonAI_S3FileHandler constructor.
     22     *
     23     * @param AmazonAI_Common $common
     24     */
     25    public function __construct(AmazonAI_Common $common) {
     26        $this->common = $common;
     27    }
    1528
    1629  /**
     
    3750    public function delete($wp_filesystem, $file, $post_id) {
    3851
    39       $common = new AmazonAI_Common();
     52      $common = $this->common;
    4053
    4154      // Retrieve the name of the bucket where audio files are stored.
     
    96109
    97110      $s3BucketName = $this->get_bucket_name();
    98       $cloudfront_domain_name = get_option( 'amazon_polly_cloudfront' );
     111      $cloudfront_domain_name = apply_filters('amazon_polly_cloudfront_domain', get_option( 'amazon_polly_cloudfront' ));
    99112      $key = $this->get_prefix($post_id) . $file_name;
    100113
    101114      if ( empty( $cloudfront_domain_name ) ) {
    102115
    103         $common = new AmazonAI_Common();
     116        $common = $this->common;
    104117        $selected_region = $common->get_aws_region();
    105118
  • amazon-polly/trunk/admin/AmazonAI-TranslateConfiguration.php

    r2218638 r2268197  
    1111class AmazonAI_TranslateConfiguration
    1212{
    13     private $common;
    14     private $aws_ok;
    15     private $s3_ok;
    16 
     13    private $aws_ok;
     14    private $s3_ok;
     15
     16    /**
     17     * @var AmazonAI_Common
     18     */
     19    private $common;
     20
     21    /**
     22     * AmazonAI_TranslateConfiguration constructor.
     23     *
     24     * @param AmazonAI_Common $common
     25     */
     26    public function __construct(AmazonAI_Common $common) {
     27        $this->common = $common;
     28    }
    1729
    1830    public function amazon_ai_add_menu()
     
    4557    function display_options()
    4658    {
    47         $this->common = new AmazonAI_Common();
    48         $this->common->init();
    49 
    5059        add_settings_section('amazon_ai_translate', "Amazon Translate configuration", array(
    5160            $this,
  • amazon-polly/trunk/admin/AmazonAI-Translator.php

    r2183170 r2268197  
    1212
    1313class AmazonAI_Translator {
     14    /**
     15     * @var AmazonAI_Common
     16     */
     17    private $common;
     18
     19    /**
     20     * AmazonAI_Translator constructor.
     21     *
     22     * @param AmazonAI_Common $common
     23     */
     24    public function __construct(AmazonAI_Common $common) {
     25        $this->common = $common;
     26    }
    1427
    1528  /**
     
    235248        check_ajax_referer( 'pollyajaxnonce', 'nonce' );
    236249
    237         $polly = new AmazonAI_PollyService();
    238         $common = new AmazonAI_Common();
    239         $common->init();
     250        $common = $this->common;
     251        $polly = new AmazonAI_PollyService($common);
    240252
    241253        $logger = new AmazonAI_Logger();
  • amazon-polly/trunk/amazonpolly.php

    r2219190 r2268197  
    1717 * Plugin URI:        https://wordpress.org/plugins/amazon-polly/
    1818 * Description:       Create audio versions of your posts, translate them into other languages, and create podcasts. Integrate with Amazon Alexa to listen to your posts on Alexa-enabled devices. Use Amazon CloudFront to accelerate your website and provide a faster, more reliable viewing experience.
    19  * Version:           4.0.3
     19 * Version:           4.2.0
    2020 * Author:            AWS Labs, WP Engine
    2121 * Author URI:        https://aws.amazon.com/
  • amazon-polly/trunk/includes/class-amazonpolly-activator.php

    r1942322 r2268197  
    3030
    3131        // Flush the permalinks to enable the "amazon-pollycast" route.
    32         $amazon_pollycast = new Amazonpolly_PollyCast();
     32        $amazon_pollycast = new Amazonpolly_PollyCast(new AmazonAI_Common());
    3333        $amazon_pollycast->create_podcast();
    3434        flush_rewrite_rules();
  • amazon-polly/trunk/includes/class-amazonpolly-pollycast.php

    r2183170 r2268197  
    1818 */
    1919class Amazonpolly_PollyCast {
     20    /**
     21     * @var AmazonAI_Common
     22     */
     23    private $common;
     24
     25    /**
     26     * AmazonAI_PodcastConfiguration constructor.
     27     *
     28     * @param AmazonAI_Common $common
     29     */
     30    public function __construct(AmazonAI_Common $common) {
     31        $this->common = $common;
     32    }
    2033
    2134    /**
     
    4659     */
    4760    public function render_rss() {
     61        // Used by template
     62        $amazonai_common = $this->common;
     63
    4864        require_once dirname( __FILE__ ) . '/template-amazon-pollycast.php';
    4965    }
     
    8197        }
    8298
    83         $common = new AmazonAI_Common();
    84         $feed_size = $common->get_feed_size();
     99        $feed_size = $this->common->get_feed_size();
    85100
    86101        // How many items to show in the Amazon PollyCast feed.
     
    96111     */
    97112    public function get_posttypes_array() {
    98         $this->common = new AmazonAI_Common();
    99113        $posttypes_array = $this->common->get_posttypes();
    100114        $posttypes_array = explode( ' ', $posttypes_array );
  • amazon-polly/trunk/includes/class-amazonpolly.php

    r2183170 r2268197  
    7171        $this->plugin_name = 'amazonpolly';
    7272        $this->version     = '1.0.0';
    73 
    7473        $this->load_dependencies();
     74
     75        $this->common      = new AmazonAI_Common();
     76        $this->common->init();
     77
     78        $this->define_global_hooks();
    7579        $this->set_locale();
    7680        $this->define_admin_hooks();
     
    9498     * @access   private
    9599     */
    96     private function load_dependencies() {
    97 
     100    private function load_dependencies()
     101    {
    98102        /**
    99103         * The class responsible for orchestrating the actions and filters of the
    100104         * core plugin.
    101105         */
    102         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-amazonpolly-loader.php';
     106        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-amazonpolly-loader.php';
    103107
    104108        /**
     
    106110         * of the plugin.
    107111         */
    108         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-amazonpolly-i18n.php';
    109 
    110         /**
    111          * The class responsible for defining all actions that occur in the admin area.
    112          */
    113         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/amazonpolly-metabox.php';
    114 
    115         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-BackgroundTask.php';
    116         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Exceptions.php';
    117         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Translator.php';
    118         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-FileHandler.php';
    119         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-LocalFileHandler.php';
    120         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-S3FileHandler.php';
    121 
    122         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Logger.php';
    123         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-Common.php';
    124         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-PollyService.php';
    125         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-GeneralConfiguration.php';
    126         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-PollyConfiguration.php';
    127         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-TranslateConfiguration.php';
    128         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-PodcastConfiguration.php';
    129         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/AmazonAI-AlexaConfiguration.php';
    130         //Class responsible for GUI for the CloudFront Menu
    131         require_once plugin_dir_path( dirname( __FILE__)) . 'admin/AmazonAI-CloudFrontConfiguration.php';
    132 
    133         /**
    134          * The class responsible for defining all actions that occur in the public-facing
    135          * side of the site.
    136          */
    137         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-amazonpolly-public.php';
    138 
    139         //Class responsible for CloudFormation and associated resources
    140         require_once plugin_dir_path( dirname( __FILE__)) . 'admin/AmazonAI-Cloudformation.php';
    141         //This class is responsible for rewriting uURLs
    142         require_once plugin_dir_path( dirname( __FILE__)) . 'admin/class-url-rewriter.php';
    143 
    144 
    145         require_once plugin_dir_path( dirname( __FILE__)) . 'admin/class-custom-settings.php';
    146 
    147         /**
    148          * The class responsible for defining all actions that occur in the public-facing
    149          * side of the site.
    150          */
    151         require_once plugin_dir_path( dirname( __FILE__)) . 'public/class-amazonpolly-public.php';
     112        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-amazonpolly-i18n.php';
     113
     114        /**
     115         * Misc. classes responsible for helping with admin requests
     116         */
     117        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-PostMetaBox.php';
     118        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-BackgroundTask.php';
     119        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-Exceptions.php';
     120        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-Translator.php';
     121        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-FileHandler.php';
     122        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-LocalFileHandler.php';
     123        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-S3FileHandler.php';
     124        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-Logger.php';
     125        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-Common.php';
     126
     127        /**
     128         * Classes responsible for admin setting pages
     129         */
     130        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-AlexaConfiguration.php';
     131        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-CloudFrontConfiguration.php';
     132        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-GeneralConfiguration.php';
     133        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-PollyService.php';
     134        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-PodcastConfiguration.php';
     135        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-PollyConfiguration.php';
     136        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-TranslateConfiguration.php';
     137
     138        /**
     139         * The class responsible for defining all actions that occur in the public-facing
     140         * side of the site.
     141         */
     142        require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-amazonpolly-public.php';
     143
     144        /**
     145         * Class responsible for CloudFormation and associated resources
     146         */
     147        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/AmazonAI-Cloudformation.php';
     148
     149        /**
     150         * This class is responsible for rewriting URLs
     151         */
     152        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-url-rewriter.php';
    152153
    153154        /**
    154155         * The class responsible for creating the podcast feature.
    155156         */
    156         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-amazonpolly-pollycast.php';
    157 
    158         /**
    159          * Load AWS PHP SDK
    160          */
    161         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'vendor/autoload.php';
    162        
    163         /**
    164          * The class responsible for custom helper functions
    165          */
    166         require_once plugin_dir_path( dirname( __FILE__)) . 'includes/class-helper.php';
    167         /**
    168          * Load AWS PHP SDK
    169          */
    170         require_once plugin_dir_path( dirname( __FILE__)) . 'vendor/autoload.php';
    171 
    172          $this->loader = new Amazonpolly_Loader();
    173 
     157        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-amazonpolly-pollycast.php';
     158
     159        /**
     160         * Load AWS PHP SDK
     161         */
     162        require_once plugin_dir_path(dirname(__FILE__)) . 'vendor/autoload.php';
     163
     164        /**
     165         * The class responsible for custom helper functions
     166         */
     167        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-helper.php';
     168
     169        $this->loader = new Amazonpolly_Loader();
    174170    }
    175171
     
    191187    }
    192188
     189    /**
     190     * @return mixed
     191     */
     192    private function define_global_hooks()
     193    {
     194        add_filter('amazon_polly_logging_enabled', [ $this->common, 'is_logging_enabled' ]);
     195    }
    193196
    194197    /**
     
    202205
    203206        $background_task = new AmazonAI_BackgroundTask();
    204         $general_configuration = new AmazonAI_GeneralConfiguration();
    205         $polly_configuration = new AmazonAI_PollyConfiguration();
    206         $translate_configuration = new AmazonAI_TranslateConfiguration();
    207         $podcast_configuration = new AmazonAI_PodcastConfiguration();
    208         $alexa_configuration = new AmazonAI_AlexaConfiguration();
    209         $cloudfront_configuration = new AmazonAI_CloudFrontConfiguration();
    210 
    211         $cloudformation_service = new AmazonAI_Cloudformation();
    212         $polly_service = new AmazonAI_PollyService();
    213         $common = new AmazonAI_Common();
    214         $translate_service = new AmazonAI_Translator();
     207        $cloudformation_service = new AmazonAI_Cloudformation($this->common);
     208        $general_configuration = new AmazonAI_GeneralConfiguration($this->common);
     209        $polly_configuration = new AmazonAI_PollyConfiguration($this->common);
     210        $translate_configuration = new AmazonAI_TranslateConfiguration($this->common);
     211        $podcast_configuration = new AmazonAI_PodcastConfiguration($this->common);
     212        $alexa_configuration = new AmazonAI_AlexaConfiguration($this->common);
     213        $cloudfront_configuration = new AmazonAI_CloudFrontConfiguration($this->common, $cloudformation_service);
     214        $polly_service = new AmazonAI_PollyService($this->common);
     215        $translate_service = new AmazonAI_Translator($this->common);
    215216
    216217        $plugin_name = get_option('amazon_plugin_name');
    217         $this->loader->add_filter( "plugin_action_links_$plugin_name", $common, 'add_settings_link');
    218 
     218        $this->loader->add_filter( "plugin_action_links_$plugin_name", $this->common, 'add_settings_link');
    219219
    220220        $this->loader->add_action( sprintf('admin_post_%s', AmazonAI_BackgroundTask::ADMIN_POST_ACTION), $background_task, 'run');
    221221
    222         $this->loader->add_action( 'admin_print_footer_scripts', $common, 'add_quicktags');
    223         $this->loader->add_action( 'admin_enqueue_scripts', $common, 'enqueue_styles');
    224         $this->loader->add_action( 'admin_enqueue_scripts', $common, 'enqueue_scripts');
    225         $this->loader->add_action( 'admin_enqueue_scripts', $common, 'enqueue_custom_scripts');
    226         $this->loader->add_action( 'add_meta_boxes', $common, 'field_checkbox');
     222        $this->loader->add_action( 'admin_print_footer_scripts', $this->common, 'add_quicktags');
     223        $this->loader->add_action( 'admin_enqueue_scripts', $this->common, 'enqueue_styles');
     224        $this->loader->add_action( 'admin_enqueue_scripts', $this->common, 'enqueue_scripts');
     225        $this->loader->add_action( 'admin_enqueue_scripts', $this->common, 'enqueue_custom_scripts');
     226        $this->loader->add_action( 'add_meta_boxes', $this->common, 'field_checkbox');
    227227        $this->loader->add_action( 'save_post', $polly_service, 'save_post', 10, 3);
    228228        $this->loader->add_action( 'amazon_polly_background_task_generate_post_audio', $polly_service, 'generate_audio', 10, 3);
    229229
    230230
    231         $this->loader->add_action( 'before_delete_post', $common, 'delete_post' );
     231        $this->loader->add_action( 'before_delete_post', $this->common, 'delete_post' );
    232232        $this->loader->add_action( 'wp_ajax_polly_transcribe', $polly_service, 'ajax_bulk_synthesize' );
    233233        $this->loader->add_action( 'wp_ajax_polly_translate', $translate_service, 'ajax_translate' );
     
    251251        $plugin = plugin_basename( plugin_dir_path( dirname( __FILE__)) . 'amazonpolly.php');
    252252
    253         $this->loader->add_filter( 'wp_kses_allowed_html', $common, 'allowed_tags_kses');
    254         $this->loader->add_filter( 'tiny_mce_before_init', $common, 'allowed_tags_tinymce');
     253        $this->loader->add_filter( 'wp_kses_allowed_html', $this->common, 'allowed_tags_kses');
     254        $this->loader->add_filter( 'tiny_mce_before_init', $this->common, 'allowed_tags_tinymce');
     255                $this->loader->add_filter( "pre_update_option_amazon_polly_secret_key_fake", $this->common, 'aws_configuration_update', 10, 2 );
     256
     257
    255258
    256259        $this->loader->add_action('wp_ajax_display_stack_details_creation', $cloudfront_configuration, 'display_stack_details_creation');
     
    270273        $this->loader->add_action('wp_ajax_get_stack_state', $cloudformation_service, 'get_stack_state');
    271274        $this->loader->add_action('wp_ajax_complete_setup', $cloudformation_service, 'complete_setup');
     275
     276
    272277    }
     278
     279
     280    private function update_aws_configuration() {
     281        error_log("SAVING");
     282    }
    273283
    274284    /**
     
    281291    private function define_public_hooks() {
    282292        // Front-end
    283         $plugin_public = new Amazonpolly_Public( $this->get_plugin_name(), $this->get_version() );
     293        $plugin_public = new Amazonpolly_Public( $this->get_plugin_name(), $this->get_version(), $this->common);
    284294
    285295        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
     
    290300
    291301        // Podcast
    292         $amazon_pollycast = new Amazonpolly_PollyCast();
     302        $amazon_pollycast = new Amazonpolly_PollyCast($this->common);
    293303        $this->loader->add_filter( 'pre_get_posts', $amazon_pollycast, 'filter_pre_get_posts' );
    294304        $this->loader->add_filter( 'the_excerpt_rss', $amazon_pollycast, 'filter_force_html_decode', 99999 );
    295305
    296         $common = new AmazonAI_Common();
    297         if ( $common->is_podcast_enabled()) {
     306        if ( $this->common->is_podcast_enabled()) {
    298307            $this->loader->add_action( 'init', $amazon_pollycast, 'create_podcast');
    299308        }
     
    301310        //Rewrite URLs if site acceleration is enabled and a CloudFront distribution has been deployed
    302311        $url_rewriter = new AmazonAI_UrlRewriter();
    303         if ( $common->is_cloudfront_enabled() and $common->is_cloudfront_deployed()) {
     312        if ( $this->common->is_cloudfront_enabled() and $this->common->is_cloudfront_deployed()) {
    304313            $this->loader->add_action( 'init', $url_rewriter, 'define_url_rewrite_hooks');
    305314        }
  • amazon-polly/trunk/includes/template-amazon-pollycast.php

    r2163519 r2268197  
    44 *
    55 * @package WordPress
     6 *
     7 * @var AmazonAI_Common $amazonai_common
    68 */
    79
     
    1113echo '<?xml version="1.0" encoding="' . esc_attr( get_option( 'blog_charset' ) ) . '"?' . '>';
    1214
    13 $amazon_pollycast = new Amazonpolly_PollyCast();
     15$amazon_pollycast = new Amazonpolly_PollyCast($amazonai_common);
    1416
    1517/**
     
    3335$itunes_description = $amazon_pollycast->get_itunes_description();
    3436
    35 $common = new AmazonAI_Common();
    36 $itunes_author = $common->get_podcast_author();
     37$itunes_author = $amazonai_common->get_podcast_author();
    3738$amazon_pollycast->start_podcast_rss();
    3839
     
    5556     * @since 2.0.0
    5657     */
    57      $rss2namespace = $common->is_rss2namespace_enabled();
     58     $rss2namespace = $amazonai_common->is_rss2namespace_enabled();
    5859     if ($rss2namespace) {
    5960         do_action( 'rss2_ns' );
     
    145146        <description><![CDATA[<?php the_excerpt_rss(); ?>]]></description><?php
    146147            $fileSize = 0;
    147             if ($common->is_medialibrary_enabled() && !$common->is_s3_enabled()) {
     148            if ($amazonai_common->is_medialibrary_enabled() && !$amazonai_common->is_s3_enabled()) {
    148149                $fileSize = filesize(getcwd() . str_replace(get_home_url(), "", preg_replace('/\?.*/', '', $audio_file)));
    149150            }
  • amazon-polly/trunk/public/class-amazonpolly-public.php

    r2183170 r2268197  
    5050
    5151    /**
     52     * @var AmazonAI_Common
     53     */
     54    private $common;
     55
     56    /**
    5257     * Initialize the class and set its properties.
    5358     *
    54      * @since    1.0.0
    55      * @param      string $plugin_name       The name of the plugin.
    56      * @param      string $version    The version of this plugin.
    57      */
    58     public function __construct( $plugin_name, $version ) {
     59     * @param string $plugin_name The name of the plugin.
     60     * @param string $version The version of this plugin.
     61     * @param AmazonAI_Common $common
     62     *
     63     * @since    1.0.0
     64     */
     65    public function __construct( $plugin_name, $version, AmazonAI_Common $common ) {
    5966
    6067        $this->plugin_name = $plugin_name;
    6168        $this->version     = $version;
    62 
     69        $this->common = $common;
    6370    }
    6471
    6572    public function title_filter( $title, $id = null ) {
    66 
    67         $common = new AmazonAI_Common();
     73        $common = $this->common;
    6874
    6975            if ( is_singular() ) {
     
    105111
    106112        $post_id = $GLOBALS['post']->ID;
    107         $common = new AmazonAI_Common();
     113        $common = $this->common;
    108114
    109115        $source_language = $common->get_post_source_language($post_id);
     
    289295        }
    290296
    291         $common = new AmazonAI_Common();
     297        $common = $this->common;
    292298        $controlsList = '';
    293299        if ( !$common->is_audio_download_enabled() ) {
     
    308314        $part = '';
    309315
    310         $common = new AmazonAI_Common();
     316        $common = $this->common;
    311317        $is_subscribe_button_enabled = $common->is_subscribe_button_enabled();
    312318        if ($is_subscribe_button_enabled) {
Note: See TracChangeset for help on using the changeset viewer.