diff --git a/README.txt b/README.txt index 7f3a6a3..fbaf8e0 100644 --- a/README.txt +++ b/README.txt @@ -1,18 +1,18 @@ === Plugin Name === Contributors: leonstafford Donate link: https://leonstafford.github.io -Tags: wp2static,s3,static +Tags: wp2static,github,static Requires at least: 3.2 Tested up to: 5.0.3 Stable tag: 0.1 License: Unlicense License URI: http://unlicense.org -Adds AWS S3 as a deployment option for WP2Static. +Adds AWS GitHub as a deployment option for WP2Static. == Description == -Take advantage of the S3 and optionally CloudFront to host your WordPress +Take advantage of the GitHub and optionally CloudFront to host your WordPress powered static website. == Installation == diff --git a/S3Deployer.php b/S3Deployer.php index d4a64bb..7e1bb34 100755 --- a/S3Deployer.php +++ b/S3Deployer.php @@ -1,42 +1,42 @@ loadSettings( 's3', $deploy_keys ); + $this->loadSettings( 'github', $deploy_keys ); $this->previous_hashes_path = $this->settings['wp_uploads_path'] . - '/WP2STATIC-S3-PREVIOUS-HASHES.txt'; + '/WP2STATIC-GitHub-PREVIOUS-HASHES.txt'; if ( defined( 'WP_CLI' ) ) { return; } switch ( $_POST['ajax_action'] ) { - case 'test_s3': - $this->test_s3(); + case 'test_github': + $this->test_github(); break; - case 's3_prepare_export': + case 'github_prepare_export': $this->bootstrap(); $this->loadArchive(); $this->prepareDeploy(); break; - case 's3_transfer_files': + case 'github_transfer_files': $this->bootstrap(); $this->loadArchive(); $this->upload_files(); @@ -76,13 +76,13 @@ class WP2Static_S3 extends WP2Static_SitePublisher { if ( ! is_file( $local_file ) ) { continue; } - if ( isset( $this->settings['s3RemotePath'] ) ) { + if ( isset( $this->settings['githubRemotePath'] ) ) { $this->target_path = - $this->settings['s3RemotePath'] . '/' . $this->target_path; + $this->settings['githubRemotePath'] . '/' . $this->target_path; } $this->logAction( - "Uploading {$local_file} to {$this->target_path} in S3" + "Uploading {$local_file} to {$this->target_path} in GitHub" ); $this->local_file_contents = file_get_contents( $local_file ); @@ -99,7 +99,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher { ); try { - $this->put_s3_object( + $this->put_github_object( $this->target_path . basename( $local_file ), $this->local_file_contents, @@ -121,7 +121,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher { ); try { - $this->put_s3_object( + $this->put_github_object( $this->target_path . basename( $local_file ), $this->local_file_contents, @@ -148,9 +148,9 @@ class WP2Static_S3 extends WP2Static_SitePublisher { } } - public function test_s3() { + public function test_github() { try { - $this->put_s3_object( + $this->put_github_object( '.tmp_wp2static.txt', 'Test WP2Static connectivity', 'text/plain' @@ -164,25 +164,25 @@ class WP2Static_S3 extends WP2Static_SitePublisher { '/../static-html-output-plugin' . '/plugin/WP2Static/WsLog.php'; - WsLog::l( 'S3 ERROR RETURNED: ' . $e ); - echo "There was an error testing S3.\n"; + WsLog::l( 'GitHub ERROR RETURNED: ' . $e ); + echo "There was an error testing GitHub.\n"; } } - public function put_s3_object( $s3_path, $content, $content_type ) { + public function put_github_object( $github_path, $content, $content_type ) { // NOTE: quick fix for #287 - $s3_path = str_replace( '@', '%40', $s3_path ); + $github_path = str_replace( '@', '%40', $github_path ); - $this->logAction( "PUT'ing file to {$s3_path} in S3" ); + $this->logAction( "PUT'ing file to {$github_path} in GitHub" ); - $host_name = $this->settings['s3Bucket'] . '.s3.' . - $this->settings['s3Region'] . '.amazonaws.com'; + $host_name = $this->settings['githubBucket'] . '.github.' . + $this->settings['githubRegion'] . '.amazonaws.com'; - $this->logAction( "Using S3 Endpoint {$host_name}" ); + $this->logAction( "Using GitHub Endpoint {$host_name}" ); //$content_acl = 'public-read'; - $content_title = $s3_path; - $aws_service_name = 's3'; + $content_title = $github_path; + $aws_service_name = 'github'; $timestamp = gmdate( 'Ymd\THis\Z' ); $date = gmdate( 'Ymd' ); @@ -194,8 +194,8 @@ class WP2Static_S3 extends WP2Static_SitePublisher { //$request_headers['x-amz-acl'] = $content_acl; $request_headers['x-amz-content-sha256'] = hash( 'sha256', $content ); - if ( ! empty( $this->settings[ 's3CacheControl' ] ) ) { - $max_age = $this->settings[ 's3CacheControl' ]; + if ( ! empty( $this->settings[ 'githubCacheControl' ] ) ) { + $max_age = $this->settings[ 'githubCacheControl' ]; $request_headers['Cache-Control'] = 'max-age=' . $max_age; } @@ -231,7 +231,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher { $scope = array(); $scope[] = $date; - $scope[] = $this->settings['s3Region']; + $scope[] = $this->settings['githubRegion']; $scope[] = $aws_service_name; $scope[] = 'aws4_request'; @@ -243,17 +243,17 @@ class WP2Static_S3 extends WP2Static_SitePublisher { $string_to_sign = implode( "\n", $string_to_sign ); // Signing key - $k_secret = 'AWS4' . $this->settings['s3Secret']; + $k_secret = 'AWS4' . $this->settings['githubSecret']; $k_date = hash_hmac( 'sha256', $date, $k_secret, true ); $k_region = - hash_hmac( 'sha256', $this->settings['s3Region'], $k_date, true ); + hash_hmac( 'sha256', $this->settings['githubRegion'], $k_date, true ); $k_service = hash_hmac( 'sha256', $aws_service_name, $k_region, true ); $k_signing = hash_hmac( 'sha256', 'aws4_request', $k_service, true ); $signature = hash_hmac( 'sha256', $string_to_sign, $k_signing ); $authorization = [ - 'Credential=' . $this->settings['s3Key'] . '/' . + 'Credential=' . $this->settings['githubKey'] . '/' . implode( '/', $scope ), 'SignedHeaders=' . $signed_headers, 'Signature=' . $signature, @@ -270,7 +270,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher { $url = 'http://' . $host_name . '/' . $content_title; - $this->logAction( "S3 URL: {$url}" ); + $this->logAction( "GitHub URL: {$url}" ); $ch = curl_init( $url ); @@ -337,8 +337,8 @@ class WP2Static_S3 extends WP2Static_SitePublisher { } $distribution = $this->settings['cfDistributionId']; - $access_key = $this->settings['s3Key']; - $secret_key = $this->settings['s3Secret']; + $access_key = $this->settings['githubKey']; + $secret_key = $this->settings['githubSecret']; $epoch = date( 'U' ); @@ -415,4 +415,4 @@ EOD; } } -$s3 = new WP2Static_S3(); +$github = new WP2Static_GitHub(); diff --git a/admin/class-wp2static-addon-s3-admin.php b/admin/class-wp2static-addon-s3-admin.php index f881e52..b1eab1a 100644 --- a/admin/class-wp2static-addon-s3-admin.php +++ b/admin/class-wp2static-addon-s3-admin.php @@ -1,6 +1,6 @@ plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp2static-addon-s3-admin.js', array( 'jquery' ), $this->version, false ); + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp2static-addon-github-admin.js', array( 'jquery' ), $this->version, false ); } } diff --git a/admin/js/wp2static-addon-s3-admin.js b/admin/js/wp2static-addon-s3-admin.js index 2ccb8bf..0374530 100644 --- a/admin/js/wp2static-addon-s3-admin.js +++ b/admin/js/wp2static-addon-s3-admin.js @@ -2,22 +2,22 @@ 'use strict'; $(function() { - deploy_options['s3'] = { + deploy_options['github'] = { exportSteps: [ - 's3_prepare_export', - 's3_transfer_files', + 'github_prepare_export', + 'github_transfer_files', 'cloudfront_invalidate_all_items', 'finalize_deployment' ], required_fields: { - s3Key: 'Please input an S3 Key in order to authenticate when using the S3 deployment method.', - s3Secret: 'Please input an S3 Secret in order to authenticate when using the S3 deployment method.', - s3Bucket: 'Please input the name of the S3 bucket you are trying to deploy to.', + githubKey: 'Please input an GitHub Key in order to authenticate when using the GitHub deployment method.', + githubSecret: 'Please input an GitHub Secret in order to authenticate when using the GitHub deployment method.', + githubBucket: 'Please input the name of the GitHub bucket you are trying to deploy to.', } }; - status_descriptions['s3_prepare_export'] = 'Preparing files for S3 deployment'; - status_descriptions['s3_transfer_files'] = 'Deploying files to S3'; + status_descriptions['github_prepare_export'] = 'Preparing files for GitHub deployment'; + status_descriptions['github_transfer_files'] = 'Deploying files to GitHub'; status_descriptions['cloudfront_invalidate_all_items'] = 'Invalidating CloudFront cache'; }); // end DOM ready diff --git a/includes/class-wp2static-addon-s3-loader.php b/includes/class-wp2static-addon-s3-loader.php index 3dc796d..25a563e 100644 --- a/includes/class-wp2static-addon-s3-loader.php +++ b/includes/class-wp2static-addon-s3-loader.php @@ -1,6 +1,6 @@ version = '1.0.0'; } - $this->plugin_name = 'wp2static-addon-s3'; + $this->plugin_name = 'wp2static-addon-github'; $this->load_dependencies(); $this->define_admin_hooks(); } private function load_dependencies() { - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp2static-addon-s3-loader.php'; - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp2static-addon-s3-admin.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp2static-addon-github-loader.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp2static-addon-github-admin.php'; - $this->loader = new Wp2static_Addon_S3_Loader(); + $this->loader = new Wp2static_Addon_GitHub_Loader(); } private function define_admin_hooks() { - $plugin_admin = new Wp2static_Addon_S3_Admin( $this->get_plugin_name(), $this->get_version() ); + $plugin_admin = new Wp2static_Addon_GitHub_Admin( $this->get_plugin_name(), $this->get_version() ); if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wp2static')) { $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); @@ -34,27 +34,27 @@ class Wp2static_Addon_S3 { } public function add_deployment_option_to_ui( $deploy_options ) { - $deploy_options['s3'] = array('Amazon S3'); + $deploy_options['github'] = array('Amazon GitHub'); return $deploy_options; } public function load_deployment_option_template( $templates ) { - $templates[] = __DIR__ . '/../views/s3_settings_block.phtml'; + $templates[] = __DIR__ . '/../views/github_settings_block.phtml'; return $templates; } public function add_deployment_option_keys( $keys ) { $new_keys = array( - 'baseUrl-s3', + 'baseUrl-github', 'cfDistributionId', - 's3Bucket', - 's3CacheControl', - 's3Key', - 's3Region', - 's3RemotePath', - 's3Secret', + 'githubBucket', + 'githubCacheControl', + 'githubKey', + 'githubRegion', + 'githubRemotePath', + 'githubSecret', ); $keys = array_merge( @@ -67,13 +67,13 @@ class Wp2static_Addon_S3 { public function whitelist_deployment_option_keys( $keys ) { $whitelist_keys = array( - 'baseUrl-s3', + 'baseUrl-github', 'cfDistributionId', - 's3Bucket', - 's3CacheControl', - 's3Key', - 's3Region', - 's3RemotePath', + 'githubBucket', + 'githubCacheControl', + 'githubKey', + 'githubRegion', + 'githubRemotePath', ); $keys = array_merge( @@ -85,15 +85,15 @@ class Wp2static_Addon_S3 { } public function add_post_and_db_keys( $keys ) { - $keys['s3'] = array( - 'baseUrl-s3', + $keys['github'] = array( + 'baseUrl-github', 'cfDistributionId', - 's3Bucket', - 's3CacheControl', - 's3Key', - 's3Region', - 's3RemotePath', - 's3Secret', + 'githubBucket', + 'githubCacheControl', + 'githubKey', + 'githubRegion', + 'githubRemotePath', + 'githubSecret', ); return $keys; diff --git a/uninstall.php b/uninstall.php index ebba9d4..ff98220 100644 --- a/uninstall.php +++ b/uninstall.php @@ -22,7 +22,7 @@ * @link https://leonstafford.github.io * @since 1.0.0 * - * @package Wp2static_Addon_S3 + * @package Wp2static_Addon_GitHub */ // If uninstall not called from WordPress, then exit. diff --git a/views/s3_settings_block.phtml b/views/s3_settings_block.phtml index 9b50ee7..3fad74c 100755 --- a/views/s3_settings_block.phtml +++ b/views/s3_settings_block.phtml @@ -1,45 +1,45 @@ -