Changeset 2558516
- Timestamp:
- 07/05/2021 05:34:54 AM (4 years ago)
- Location:
- c3-cloudfront-clear-cache/trunk
- Files:
-
- 33 added
- 4 deleted
- 3 edited
-
c3-cloudfront-clear-cache.php (modified) (2 diffs)
-
classes (added)
-
classes/AWS (added)
-
classes/AWS/CloudFront_Service.php (added)
-
classes/AWS/Invalidation_Batch.php (added)
-
classes/AWS/Invalidation_Batch_Service.php (added)
-
classes/Class_Loader.php (added)
-
classes/Constants.php (added)
-
classes/Cron_Service.php (added)
-
classes/Invalidation_Service.php (added)
-
classes/Settings_Service.php (added)
-
classes/Views (added)
-
classes/Views/Settings.php (added)
-
classes/WP (added)
-
classes/WP/Admin_Notice.php (added)
-
classes/WP/Environment.php (added)
-
classes/WP/Fixtures.php (added)
-
classes/WP/Hooks.php (added)
-
classes/WP/Options.php (added)
-
classes/WP/Options_Service.php (added)
-
classes/WP/Post.php (added)
-
classes/WP/Post_Service.php (added)
-
classes/WP/Transient.php (added)
-
classes/WP/Transient_Service.php (added)
-
classes/WP/WP_CLI_Command.php (added)
-
cli.php (deleted)
-
composer.json (modified) (1 diff)
-
libs/aws.phar (added)
-
libs/aws.v2.phar (deleted)
-
libs/aws.v3.phar (deleted)
-
loader.php (added)
-
module (deleted)
-
package.json (added)
-
readme.txt (modified) (3 diffs)
-
templates (added)
-
templates/Invalidation_Logs.php (added)
-
templates/Manually_Invalidation.php (added)
-
templates/Plugin_Options.php (added)
-
templates/Settings.php (added)
-
uninstall.php (added)
Legend:
- Unmodified
- Added
- Removed
-
c3-cloudfront-clear-cache/trunk/c3-cloudfront-clear-cache.php
r2303154 r2558516 1 1 <?php 2 /* 2 /** 3 3 * Plugin Name: C3 Cloudfront Cache Controller 4 * Version: 5.5.14 * Version: 6.1.1 5 5 * Plugin URI:https://github.com/amimoto-ami/c3-cloudfront-clear-cache 6 6 * Description: Manage CloudFront Cache and provide some fixtures. 7 7 * Author: hideokamoto 8 8 * Author URI: https://wp-kyoto.net/ 9 * Requires PHP: 7.0 9 10 * Text Domain: c3-cloudfront-clear-cache 11 * 10 12 * @package c3-cloudfront-clear-cache 11 13 */ 12 14 13 define( 'C3_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); 14 define( 'C3_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 15 define( 'C3_PLUGIN_ROOT', __FILE__ ); 15 /** 16 * Load the class loader 17 */ 18 require_once( __DIR__ . '/loader.php' ); 16 19 17 // fixtures 18 require_once( __DIR__ . '/module/model/fixtures/wp_is_mobile.php' ); 19 require_once( __DIR__ . '/module/model/fixtures/avoid_preview_cache.php' ); 20 use C3_CloudFront_Cache_Controller\WP; 21 use C3_CloudFront_Cache_Controller\AWS; 20 22 21 $c3 = C3_Controller::get_instance(); 22 $c3->init(); 23 /** 24 * Load AWS SDK and classes 25 */ 26 function c3_init() { 27 if ( ! class_exists( '\\Aws\\CloudFront\\CloudFrontClient' ) ) { 28 $aws_sdk_path = apply_filters( 'c3_aws_sdk_path', dirname( __FILE__ ) . '/libs/aws.phar' ); 29 if ( isset( $aws_sdk_path ) ) { 30 require_once( $aws_sdk_path ); 31 } 32 } 33 new C3_CloudFront_Cache_Controller\Invalidation_Service(); 34 new C3_CloudFront_Cache_Controller\Cron_Service(); 35 new C3_CloudFront_Cache_Controller\Settings_Service(); 36 new C3_CloudFront_Cache_Controller\Views\Settings(); 37 new WP\Fixtures(); 38 } 39 c3_init(); 23 40 24 function c3_get_aws_sdk_version() { 25 if ( class_exists('\\Aws\\CloudFront\\CloudFrontClient') ) { 26 return c3_get_loaded_aws_sdk_version(); 27 } 28 if ( c3_is_later_than_php_55() ) { 29 return 'v3'; 30 } 31 return 'v2'; 41 /** 42 * For WP-CLI. 43 */ 44 if ( defined( 'WP_CLI' ) && WP_CLI ) { 45 WP_CLI::add_command( 'c3', 'C3_CloudFront_Cache_Controller\\WP\\WP_CLI_Command' ); 32 46 } 33 47 34 function c3_is_later_than_php_55() {35 $is_later_than_55 = true;36 if ( version_compare( phpversion(), '5.5', '<') ) {37 $is_later_than_55 = false;38 }39 return apply_filters( 'c3_select_aws_sdk', $is_later_than_55 );40 }41 48 42 class C3_Controller { 43 private $base; 49 /** 50 * Backward compatibility 51 * 52 * @since 6.1.1 53 * @package C3_CloudFront_Cache_Controller 54 */ 55 class CloudFront_Clear_Cache { 56 /** 57 * Class instance 58 * 59 * @var CloudFront_Clear_Cache 60 */ 44 61 private static $instance; 45 62 63 /** 64 * Create instance 65 * 66 * @return CloudFront_Clear_Cache 67 */ 46 68 public static function get_instance() { 47 69 if ( ! isset( self::$instance ) ) { 48 $c = __CLASS__;70 $c = __CLASS__; 49 71 self::$instance = new $c(); 50 72 } … … 53 75 54 76 /** 55 * Initialize Plugin 56 * 57 * @access public 58 * @param none 59 * @return none 60 * @since 4.0.0 77 * Run invalidation all 61 78 */ 62 public function init() { 63 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); 64 } 65 66 /** 67 * Initialize Plugin 68 * 69 * @access public 70 * @param none 71 * @return none 72 * @since 5.3.3 73 */ 74 public function plugins_loaded() { 75 if ( ! class_exists('\\Aws\\CloudFront\\CloudFrontClient') ) { 76 if ( 'v2' === c3_get_aws_sdk_version() ) { 77 require_once( dirname( __FILE__ ) . '/libs/aws.v2.phar' ); 78 } else { 79 require_once( dirname( __FILE__ ) . '/libs/aws.v3.phar' ); 80 } 81 } 82 require_once( dirname( __FILE__ ).'/module/includes.php' ); 83 84 $this->base = new C3_Base(); 85 $menu = C3_Menus::get_instance(); 86 $menu->init(); 87 add_action( 'admin_init', array( $this, 'update_settings' ) ); 88 $invalidator = C3_Invalidation::get_instance(); 89 add_action( 'transition_post_status' , array( $invalidator, 'post_invalidation' ) , 10 , 3 ); 90 add_filter( 'amimoto_c3_add_settings', array( $this, 'inject_c3_admin_content' ) ); 91 add_action( 'c3_cron_invalidation', array( $invalidator, 'cron_invalidation' ) ); 92 } 93 94 /** 95 * Inject C3 Content to AMIMOTO Dashboard 96 * 97 * @access public 98 * @since 4.2.0 99 * @param string $html 100 * @return string 101 **/ 102 public function inject_c3_admin_content( $html ) { 103 $root = C3_Admin::get_instance(); 104 $html .= '<hr/>'; 105 $html .= $root->inject_to_amimoto_dashboard(); 106 return $html; 107 } 108 109 /** 110 * Controller of C3 plugin 111 * 112 * @access public 113 * @param none 114 * @return none 115 * @since 4.0.0 116 */ 117 public function update_settings() { 118 if ( empty( $_POST ) ) { 119 return; 120 } 121 $result = false; 122 if ( $this->is_trust_post_param( C3_Base::C3_AUTHENTICATION ) ) { 123 $options = $this->_esc_setting_param( $_POST[ C3_Base::OPTION_NAME ] ); 124 update_option( C3_Base::OPTION_NAME, $options ); 125 126 $auth = C3_Auth::get_instance(); 127 $result = $auth->auth( $options ); 128 if ( is_wp_error( $result ) ) { 129 //@TODO Show WP Error message 130 } 131 } 132 if ( $this->is_trust_post_param( C3_Base::C3_INVALIDATION ) ) { 133 $invalidator = C3_Invalidation::get_instance(); 134 $result = $invalidator->invalidation(); 135 if ( is_wp_error( $result ) ) { 136 //@TODO Show WP Error message 137 } 138 } 139 if ( $result ) { 140 if ( is_wp_error( $result ) ) { 141 $this->_show_error( $result ); 142 } else { 143 // $this->_show_result( $result ); 144 } 145 } 146 } 147 148 /** 149 * Show error message on wp-admin 150 * 151 * @access private 152 * @param WP_Error $error Wp_error object. 153 * @since 4.4.0 154 **/ 155 private function _show_error( WP_Error $error ) { 156 $messages = $error->get_error_messages(); 157 $codes = $error->get_error_codes(); 158 $code = esc_html( $codes[0] ); 159 ?> 160 <div class='error'><ul> 161 <?php foreach ( $messages as $key => $message ) : ?> 162 <li> 163 <b><?php echo esc_html( $code );?></b> 164 : <?php echo esc_html( $message );?> 165 </li> 166 <?php endforeach; ?> 167 </ul></div> 168 <?php 169 } 170 171 /** 172 * Check plugin nonce key 173 * 174 * @access public 175 * @param none 176 * @return none 177 * @since 4.0.0 178 */ 179 private function is_trust_post_param( $key ) { 180 if ( isset( $_POST[ $key ] ) && $_POST[ $key ] ) { 181 if ( check_admin_referer( $key, $key ) ) { 182 return true; 183 } 184 } 185 return false; 186 } 187 188 /** 189 * Escape setting params 190 * 191 * @return array 192 * @since 4.0.0 193 * @access private 194 */ 195 private function _esc_setting_param( $param ) { 196 $esc_param = array(); 197 foreach ( $param as $key => $value ) { 198 $esc_param[ $key ] = esc_attr( $value ); 199 } 200 return $esc_param; 201 } 202 203 } 204 205 /** 206 * Backward compatible ( Before version3.x) 207 * 208 * @class CloudFront_Clear_Cache 209 * @since 1.0.0 210 */ 211 class CloudFront_Clear_Cache { 212 private static $instance; 213 public static function get_instance() { 214 if ( ! isset( self::$instance ) ) { 215 $c = __CLASS__; 216 self::$instance = new $c(); 217 } 218 return self::$instance; 219 } 220 221 public function c3_invalidation( $post = null ) { 222 $invalidator = C3_Invalidation::get_instance(); 223 $result = $invalidator->invalidation( $post ); 224 return $result; 79 public function c3_invalidation() { 80 $service = new C3_CloudFront_Cache_Controller\Invalidation_Service(); 81 return $service->invalidate_all(); 225 82 } 226 83 } 227 228 // WP-CLI229 if ( defined('WP_CLI') && WP_CLI ) {230 include __DIR__ . '/cli.php';231 } -
c3-cloudfront-clear-cache/trunk/composer.json
r1970683 r2558516 1 1 { 2 "name": " c3-cloudfront-clear-cache",2 "name": "digitalcube/c3-cloudfront-clear-cache", 3 3 "version": "0.0.0", 4 4 "type": "wordpress-plugin", 5 5 "require": { 6 6 "php": ">=5.5" 7 } 7 }, 8 "require-dev": { 9 "dealerdirect/phpcodesniffer-composer-installer": "*", 10 "phpcompatibility/phpcompatibility-wp": "*", 11 "squizlabs/php_codesniffer": "*", 12 "wp-coding-standards/wpcs": "*", 13 "wp-phpunit/wp-phpunit": "5.7.2", 14 "phpunit/phpunit": "^7.5.20" 15 }, 16 "autoload": { 17 "psr-4": { 18 "C3_CloudFront_Cache_Controller\\" : "classes/", 19 "C3_CloudFront_Cache_Controller\\WP\\" : "classes/WP/", 20 "C3_CloudFront_Cache_Controller\\Test\\" : "tests/" 21 } 22 }, 23 "scripts": { 24 "test": "phpunit", 25 "format": "phpcbf --standard=./.phpcs.xml.dist --report-summary --report-source", 26 "lint": "phpcs --standard=./.phpcs.xml.dist", 27 "phpcs": "phpcs --standard=./.phpcs.xml.dist" 28 } 8 29 } -
c3-cloudfront-clear-cache/trunk/readme.txt
r2303154 r2558516 1 1 === C3 Cloudfront Cache Controller === 2 Contributors: amimotoami,hideokamoto,megumithemes,wokamoto,miyauchi,hnle,bartoszgadomski,jepser,johnbillion 2 Contributors: amimotoami,hideokamoto,megumithemes,wokamoto,miyauchi,hnle,bartoszgadomski,jepser,johnbillion,pacifika 3 3 Donate link: http://wp-kyoto.net/ 4 4 Tags: AWS,CDN,CloudFront 5 5 Requires at least: 4.9.0 6 Tested up to: 5. 2.37 Stable tag: 5.5.16 Tested up to: 5.7.2 7 Stable tag: 6.1.1 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 111 111 == Changelog == 112 112 113 == 6.1.0 == 114 * [Fix] Plugin deactivation issue 115 116 == 6.1.0 == 117 * [Update] Flush cache by post_ids 118 119 == 6.0.0 == 120 * [Breaking Change] Re-write entire code 121 * [Update] Add `c3_log_cron_invalidation_task` filter to show cron job Logs 122 * [Update] Add `c3_aws_sdk_path` filter to change or remove bundled AWS SDK path 123 113 124 == 5.5.1 == 114 125 * [Update] Replace the top level menu with a Settings submenu … … 245 256 == Upgrade Notice == 246 257 247 = 5.5.0=248 * [ Update] Can use defined variables for AWS Credentials258 == 6.1.0 == 259 * [Fix] Plugin deactivation issue
Note: See TracChangeset
for help on using the changeset viewer.