* @package Amimoto-dashboard * @since 0.0.1 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Amimoto Plugin Dashboard admin page to set-up CloudFront * * @class Amimoto_Dash_Cloudfront * @since 0.0.1 */ class Amimoto_Dash_Cloudfront extends Amimoto_Dash_Component { private static $instance; private static $text_domain; private function __construct() { self::$text_domain = Amimoto_Dash_Base::text_domain(); } /** * Get Instance Class * * @return Amimoto_Dash_Cloudfront * @since 0.0.1 * @access public */ public static function get_instance() { if ( ! isset( self::$instance ) ) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; } /** * Show admin page html * * @access public * @param none * @return none * @since 0.0.1 */ public function init_panel() { $this->show_panel_html(); } /** * Get admin page html content * * @access public * @param none * @return string(HTML) * @since 0.0.1 */ public function get_content_html() { $html = ''; if ( $this->is_amimoto_managed() ) { $html .= $this->_get_amimoto_managed_cache_control_form(); } else { $html .= $this->_get_cf_invalidation_form(); $html .= $this->_get_cf_setting_form(); if ( $this->is_activated_ncc() ) { $html .= '
'; $html .= $this->_get_ncc_update_form(); } } return apply_filters( 'amimoto_c3_add_settings', $html ); } /** * Get CloudFront Invalidation Form html * * @access private * @param none * @return string(HTML) * @since 0.0.1 */ private function _get_cf_invalidation_form() { $c3_settings = get_option( 'c3_settings' ); $html = ''; if ( ! $c3_settings ) { return $html; } $html .= "
"; $html .= ""; $html .= ''; $html .= "'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '

" . __( 'CloudFront Cache Control', self::$text_domain ). '

'. __( 'Flush All Cache', self::$text_domain ). ''; $html .= ""; $html .= wp_nonce_field( self::CLOUDFRONT_INVALIDATION , self::CLOUDFRONT_INVALIDATION , true , false ); $html .= get_submit_button( __( 'Flush All Cache', self::$text_domain ) ); $html .= '
'; $html .= '
'; $html .= '
'; return $html; } /** * Update Nginx Cache Controller Setting for CDN * * @access private * @param none * @return string(HTML) * @since 0.0.1 */ private function _get_ncc_update_form() { $html = ''; $html .= "
"; $html .= ""; $html .= ''; $html .= "'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '

" . __( 'Nginx Cache Settings', self::$text_domain ). '

'. __( 'Change Nginx Cache Expires Shorten', self::$text_domain ). ''; $html .= '

' . __( 'All Nginx Cache Expires change 30sec.', self::$text_domain ) . '

'; $html .= ""; $html .= wp_nonce_field( self::CLOUDFRONT_UPDATE_NCC , self::CLOUDFRONT_UPDATE_NCC , true , false ); $html .= get_submit_button( __( 'Change Expires', self::$text_domain ) ); $html .= '
'; $html .= '
'; return $html; } /** * Get CloudFront Distribution Id Form * * @params string $dist_id CloudFront Distribution Id * @return string HTML tag to show Distribution ID input form * @access private * @since 0.5.0 */ private function __get_cf_dist_input( $dist_id ) { $disabled = ''; if ( $this->is_amimoto_managed() && defined( 'AMIMOTO_CDN_ID' ) ) { $disabled = 'disabled'; $dist_id = AMIMOTO_CDN_ID; } $html = ''; $html .= ''. __( 'CloudFront Distribution ID', self::$text_domain ). ''; $html .= ""; $html .= ''; return $html; } /** * Get CloudFront Setting Form html * * @access private * @param none * @return string(HTML) * @since 0.0.1 */ private function _get_cf_setting_form() { $c3_settings = get_option( 'c3_settings' ); $has_ec2_instance_role = apply_filters( 'amimoto_has_ec2_instance_role', false ); if ( ! isset( $c3_settings['distribution_id'] ) || ! $c3_settings['distribution_id'] ) { $c3_settings['distribution_id'] = ''; } if ( ! isset( $c3_settings['access_key'] ) || ! $c3_settings['access_key'] ) { $c3_settings['access_key'] = ''; } if ( ! isset( $c3_settings['secret_key'] ) || ! $c3_settings['secret_key'] ) { $c3_settings['secret_key'] = ''; } $c3_settings = apply_filters( 'c3_settings', $c3_settings ); if ( ! isset( $c3_settings['access_key'] ) && ! isset( $c3_settings['secret_key'] ) ) { $has_ec2_instance_role = true; } $html = ''; $html .= "
"; $html .= ""; $html .= ''; $html .= "'; $html .= ''; $html .= ''; $html .= $this->__get_cf_dist_input($c3_settings['distribution_id']); if ( ! $has_ec2_instance_role ) { $html .= ''; $html .= ""; $html .= ''; $html .= ''; $html .= ""; $html .= ''; } $html .= "'; $html .= '

" . __( 'CloudFront Connection Settings', self::$text_domain ). '

'. __( 'AWS Access Key', self::$text_domain ). '
'. __( 'AWS Secret Key', self::$text_domain ). '
"; $html .= wp_nonce_field( self::CLOUDFRONT_SETTINGS , self::CLOUDFRONT_SETTINGS , true , false ); $html .= get_submit_button( __( 'Update CloudFront Settings', self::$text_domain ) ); $html .= '
'; $html .= '
'; return $html; } }