mirror of
https://ghproxy.net/https://github.com/elementor/wp2static-addon-github.git
synced 2025-10-04 04:23:50 +08:00
quick rewrite s3 -> github
This commit is contained in:
parent
a80054c0be
commit
c16801548f
9 changed files with 124 additions and 124 deletions
|
@ -1,18 +1,18 @@
|
||||||
=== Plugin Name ===
|
=== Plugin Name ===
|
||||||
Contributors: leonstafford
|
Contributors: leonstafford
|
||||||
Donate link: https://leonstafford.github.io
|
Donate link: https://leonstafford.github.io
|
||||||
Tags: wp2static,s3,static
|
Tags: wp2static,github,static
|
||||||
Requires at least: 3.2
|
Requires at least: 3.2
|
||||||
Tested up to: 5.0.3
|
Tested up to: 5.0.3
|
||||||
Stable tag: 0.1
|
Stable tag: 0.1
|
||||||
License: Unlicense
|
License: Unlicense
|
||||||
License URI: http://unlicense.org
|
License URI: http://unlicense.org
|
||||||
|
|
||||||
Adds AWS S3 as a deployment option for WP2Static.
|
Adds AWS GitHub as a deployment option for WP2Static.
|
||||||
|
|
||||||
== Description ==
|
== 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.
|
powered static website.
|
||||||
|
|
||||||
== Installation ==
|
== Installation ==
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class WP2Static_S3 extends WP2Static_SitePublisher {
|
class WP2Static_GitHub extends WP2Static_SitePublisher {
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
// calling outside WP chain, need to specify this
|
// calling outside WP chain, need to specify this
|
||||||
// Add-on's option keys
|
// Add-on's option keys
|
||||||
$deploy_keys = array(
|
$deploy_keys = array(
|
||||||
's3',
|
'github',
|
||||||
array(
|
array(
|
||||||
'baseUrl-s3',
|
'baseUrl-github',
|
||||||
'cfDistributionId',
|
'cfDistributionId',
|
||||||
's3Bucket',
|
'githubBucket',
|
||||||
's3Key',
|
'githubKey',
|
||||||
's3Region',
|
'githubRegion',
|
||||||
's3RemotePath',
|
'githubRemotePath',
|
||||||
's3Secret',
|
'githubSecret',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->loadSettings( 's3', $deploy_keys );
|
$this->loadSettings( 'github', $deploy_keys );
|
||||||
|
|
||||||
$this->previous_hashes_path =
|
$this->previous_hashes_path =
|
||||||
$this->settings['wp_uploads_path'] .
|
$this->settings['wp_uploads_path'] .
|
||||||
'/WP2STATIC-S3-PREVIOUS-HASHES.txt';
|
'/WP2STATIC-GitHub-PREVIOUS-HASHES.txt';
|
||||||
|
|
||||||
if ( defined( 'WP_CLI' ) ) {
|
if ( defined( 'WP_CLI' ) ) {
|
||||||
return; }
|
return; }
|
||||||
|
|
||||||
switch ( $_POST['ajax_action'] ) {
|
switch ( $_POST['ajax_action'] ) {
|
||||||
case 'test_s3':
|
case 'test_github':
|
||||||
$this->test_s3();
|
$this->test_github();
|
||||||
break;
|
break;
|
||||||
case 's3_prepare_export':
|
case 'github_prepare_export':
|
||||||
$this->bootstrap();
|
$this->bootstrap();
|
||||||
$this->loadArchive();
|
$this->loadArchive();
|
||||||
$this->prepareDeploy();
|
$this->prepareDeploy();
|
||||||
break;
|
break;
|
||||||
case 's3_transfer_files':
|
case 'github_transfer_files':
|
||||||
$this->bootstrap();
|
$this->bootstrap();
|
||||||
$this->loadArchive();
|
$this->loadArchive();
|
||||||
$this->upload_files();
|
$this->upload_files();
|
||||||
|
@ -76,13 +76,13 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
if ( ! is_file( $local_file ) ) {
|
if ( ! is_file( $local_file ) ) {
|
||||||
continue; }
|
continue; }
|
||||||
|
|
||||||
if ( isset( $this->settings['s3RemotePath'] ) ) {
|
if ( isset( $this->settings['githubRemotePath'] ) ) {
|
||||||
$this->target_path =
|
$this->target_path =
|
||||||
$this->settings['s3RemotePath'] . '/' . $this->target_path;
|
$this->settings['githubRemotePath'] . '/' . $this->target_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logAction(
|
$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 );
|
$this->local_file_contents = file_get_contents( $local_file );
|
||||||
|
@ -99,7 +99,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->put_s3_object(
|
$this->put_github_object(
|
||||||
$this->target_path .
|
$this->target_path .
|
||||||
basename( $local_file ),
|
basename( $local_file ),
|
||||||
$this->local_file_contents,
|
$this->local_file_contents,
|
||||||
|
@ -121,7 +121,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->put_s3_object(
|
$this->put_github_object(
|
||||||
$this->target_path .
|
$this->target_path .
|
||||||
basename( $local_file ),
|
basename( $local_file ),
|
||||||
$this->local_file_contents,
|
$this->local_file_contents,
|
||||||
|
@ -148,9 +148,9 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_s3() {
|
public function test_github() {
|
||||||
try {
|
try {
|
||||||
$this->put_s3_object(
|
$this->put_github_object(
|
||||||
'.tmp_wp2static.txt',
|
'.tmp_wp2static.txt',
|
||||||
'Test WP2Static connectivity',
|
'Test WP2Static connectivity',
|
||||||
'text/plain'
|
'text/plain'
|
||||||
|
@ -164,25 +164,25 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
'/../static-html-output-plugin' .
|
'/../static-html-output-plugin' .
|
||||||
'/plugin/WP2Static/WsLog.php';
|
'/plugin/WP2Static/WsLog.php';
|
||||||
|
|
||||||
WsLog::l( 'S3 ERROR RETURNED: ' . $e );
|
WsLog::l( 'GitHub ERROR RETURNED: ' . $e );
|
||||||
echo "There was an error testing S3.\n";
|
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
|
// 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.' .
|
$host_name = $this->settings['githubBucket'] . '.github.' .
|
||||||
$this->settings['s3Region'] . '.amazonaws.com';
|
$this->settings['githubRegion'] . '.amazonaws.com';
|
||||||
|
|
||||||
$this->logAction( "Using S3 Endpoint {$host_name}" );
|
$this->logAction( "Using GitHub Endpoint {$host_name}" );
|
||||||
|
|
||||||
//$content_acl = 'public-read';
|
//$content_acl = 'public-read';
|
||||||
$content_title = $s3_path;
|
$content_title = $github_path;
|
||||||
$aws_service_name = 's3';
|
$aws_service_name = 'github';
|
||||||
$timestamp = gmdate( 'Ymd\THis\Z' );
|
$timestamp = gmdate( 'Ymd\THis\Z' );
|
||||||
$date = gmdate( 'Ymd' );
|
$date = gmdate( 'Ymd' );
|
||||||
|
|
||||||
|
@ -194,8 +194,8 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
//$request_headers['x-amz-acl'] = $content_acl;
|
//$request_headers['x-amz-acl'] = $content_acl;
|
||||||
$request_headers['x-amz-content-sha256'] = hash( 'sha256', $content );
|
$request_headers['x-amz-content-sha256'] = hash( 'sha256', $content );
|
||||||
|
|
||||||
if ( ! empty( $this->settings[ 's3CacheControl' ] ) ) {
|
if ( ! empty( $this->settings[ 'githubCacheControl' ] ) ) {
|
||||||
$max_age = $this->settings[ 's3CacheControl' ];
|
$max_age = $this->settings[ 'githubCacheControl' ];
|
||||||
$request_headers['Cache-Control'] = 'max-age=' . $max_age;
|
$request_headers['Cache-Control'] = 'max-age=' . $max_age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
|
|
||||||
$scope = array();
|
$scope = array();
|
||||||
$scope[] = $date;
|
$scope[] = $date;
|
||||||
$scope[] = $this->settings['s3Region'];
|
$scope[] = $this->settings['githubRegion'];
|
||||||
$scope[] = $aws_service_name;
|
$scope[] = $aws_service_name;
|
||||||
$scope[] = 'aws4_request';
|
$scope[] = 'aws4_request';
|
||||||
|
|
||||||
|
@ -243,17 +243,17 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
$string_to_sign = implode( "\n", $string_to_sign );
|
$string_to_sign = implode( "\n", $string_to_sign );
|
||||||
|
|
||||||
// Signing key
|
// Signing key
|
||||||
$k_secret = 'AWS4' . $this->settings['s3Secret'];
|
$k_secret = 'AWS4' . $this->settings['githubSecret'];
|
||||||
$k_date = hash_hmac( 'sha256', $date, $k_secret, true );
|
$k_date = hash_hmac( 'sha256', $date, $k_secret, true );
|
||||||
$k_region =
|
$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_service = hash_hmac( 'sha256', $aws_service_name, $k_region, true );
|
||||||
$k_signing = hash_hmac( 'sha256', 'aws4_request', $k_service, true );
|
$k_signing = hash_hmac( 'sha256', 'aws4_request', $k_service, true );
|
||||||
|
|
||||||
$signature = hash_hmac( 'sha256', $string_to_sign, $k_signing );
|
$signature = hash_hmac( 'sha256', $string_to_sign, $k_signing );
|
||||||
|
|
||||||
$authorization = [
|
$authorization = [
|
||||||
'Credential=' . $this->settings['s3Key'] . '/' .
|
'Credential=' . $this->settings['githubKey'] . '/' .
|
||||||
implode( '/', $scope ),
|
implode( '/', $scope ),
|
||||||
'SignedHeaders=' . $signed_headers,
|
'SignedHeaders=' . $signed_headers,
|
||||||
'Signature=' . $signature,
|
'Signature=' . $signature,
|
||||||
|
@ -270,7 +270,7 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
|
|
||||||
$url = 'http://' . $host_name . '/' . $content_title;
|
$url = 'http://' . $host_name . '/' . $content_title;
|
||||||
|
|
||||||
$this->logAction( "S3 URL: {$url}" );
|
$this->logAction( "GitHub URL: {$url}" );
|
||||||
|
|
||||||
$ch = curl_init( $url );
|
$ch = curl_init( $url );
|
||||||
|
|
||||||
|
@ -337,8 +337,8 @@ class WP2Static_S3 extends WP2Static_SitePublisher {
|
||||||
}
|
}
|
||||||
|
|
||||||
$distribution = $this->settings['cfDistributionId'];
|
$distribution = $this->settings['cfDistributionId'];
|
||||||
$access_key = $this->settings['s3Key'];
|
$access_key = $this->settings['githubKey'];
|
||||||
$secret_key = $this->settings['s3Secret'];
|
$secret_key = $this->settings['githubSecret'];
|
||||||
|
|
||||||
$epoch = date( 'U' );
|
$epoch = date( 'U' );
|
||||||
|
|
||||||
|
@ -415,4 +415,4 @@ EOD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$s3 = new WP2Static_S3();
|
$github = new WP2Static_GitHub();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Wp2static_Addon_S3_Admin {
|
class Wp2static_Addon_GitHub_Admin {
|
||||||
|
|
||||||
private $plugin_name;
|
private $plugin_name;
|
||||||
private $version;
|
private $version;
|
||||||
|
@ -12,6 +12,6 @@ class Wp2static_Addon_S3_Admin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enqueue_scripts() {
|
public function enqueue_scripts() {
|
||||||
wp_enqueue_script( $this->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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,22 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
deploy_options['s3'] = {
|
deploy_options['github'] = {
|
||||||
exportSteps: [
|
exportSteps: [
|
||||||
's3_prepare_export',
|
'github_prepare_export',
|
||||||
's3_transfer_files',
|
'github_transfer_files',
|
||||||
'cloudfront_invalidate_all_items',
|
'cloudfront_invalidate_all_items',
|
||||||
'finalize_deployment'
|
'finalize_deployment'
|
||||||
],
|
],
|
||||||
required_fields: {
|
required_fields: {
|
||||||
s3Key: 'Please input an S3 Key in order to authenticate when using the S3 deployment method.',
|
githubKey: 'Please input an GitHub Key in order to authenticate when using the GitHub deployment method.',
|
||||||
s3Secret: 'Please input an S3 Secret in order to authenticate when using the S3 deployment method.',
|
githubSecret: 'Please input an GitHub Secret in order to authenticate when using the GitHub deployment method.',
|
||||||
s3Bucket: 'Please input the name of the S3 bucket you are trying to deploy to.',
|
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['github_prepare_export'] = 'Preparing files for GitHub deployment';
|
||||||
status_descriptions['s3_transfer_files'] = 'Deploying files to S3';
|
status_descriptions['github_transfer_files'] = 'Deploying files to GitHub';
|
||||||
status_descriptions['cloudfront_invalidate_all_items'] = 'Invalidating CloudFront cache';
|
status_descriptions['cloudfront_invalidate_all_items'] = 'Invalidating CloudFront cache';
|
||||||
}); // end DOM ready
|
}); // end DOM ready
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Wp2static_Addon_S3_Loader {
|
class Wp2static_Addon_GitHub_Loader {
|
||||||
|
|
||||||
protected $actions;
|
protected $actions;
|
||||||
protected $filters;
|
protected $filters;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Wp2static_Addon_S3 {
|
class Wp2static_Addon_GitHub {
|
||||||
|
|
||||||
protected $loader;
|
protected $loader;
|
||||||
protected $plugin_name;
|
protected $plugin_name;
|
||||||
|
@ -12,21 +12,21 @@ class Wp2static_Addon_S3 {
|
||||||
} else {
|
} else {
|
||||||
$this->version = '1.0.0';
|
$this->version = '1.0.0';
|
||||||
}
|
}
|
||||||
$this->plugin_name = 'wp2static-addon-s3';
|
$this->plugin_name = 'wp2static-addon-github';
|
||||||
|
|
||||||
$this->load_dependencies();
|
$this->load_dependencies();
|
||||||
$this->define_admin_hooks();
|
$this->define_admin_hooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function load_dependencies() {
|
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__ ) ) . 'includes/class-wp2static-addon-github-loader.php';
|
||||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp2static-addon-s3-admin.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() {
|
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')) {
|
if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wp2static')) {
|
||||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
|
$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 ) {
|
public function add_deployment_option_to_ui( $deploy_options ) {
|
||||||
$deploy_options['s3'] = array('Amazon S3');
|
$deploy_options['github'] = array('Amazon GitHub');
|
||||||
|
|
||||||
return $deploy_options;
|
return $deploy_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load_deployment_option_template( $templates ) {
|
public function load_deployment_option_template( $templates ) {
|
||||||
$templates[] = __DIR__ . '/../views/s3_settings_block.phtml';
|
$templates[] = __DIR__ . '/../views/github_settings_block.phtml';
|
||||||
|
|
||||||
return $templates;
|
return $templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_deployment_option_keys( $keys ) {
|
public function add_deployment_option_keys( $keys ) {
|
||||||
$new_keys = array(
|
$new_keys = array(
|
||||||
'baseUrl-s3',
|
'baseUrl-github',
|
||||||
'cfDistributionId',
|
'cfDistributionId',
|
||||||
's3Bucket',
|
'githubBucket',
|
||||||
's3CacheControl',
|
'githubCacheControl',
|
||||||
's3Key',
|
'githubKey',
|
||||||
's3Region',
|
'githubRegion',
|
||||||
's3RemotePath',
|
'githubRemotePath',
|
||||||
's3Secret',
|
'githubSecret',
|
||||||
);
|
);
|
||||||
|
|
||||||
$keys = array_merge(
|
$keys = array_merge(
|
||||||
|
@ -67,13 +67,13 @@ class Wp2static_Addon_S3 {
|
||||||
|
|
||||||
public function whitelist_deployment_option_keys( $keys ) {
|
public function whitelist_deployment_option_keys( $keys ) {
|
||||||
$whitelist_keys = array(
|
$whitelist_keys = array(
|
||||||
'baseUrl-s3',
|
'baseUrl-github',
|
||||||
'cfDistributionId',
|
'cfDistributionId',
|
||||||
's3Bucket',
|
'githubBucket',
|
||||||
's3CacheControl',
|
'githubCacheControl',
|
||||||
's3Key',
|
'githubKey',
|
||||||
's3Region',
|
'githubRegion',
|
||||||
's3RemotePath',
|
'githubRemotePath',
|
||||||
);
|
);
|
||||||
|
|
||||||
$keys = array_merge(
|
$keys = array_merge(
|
||||||
|
@ -85,15 +85,15 @@ class Wp2static_Addon_S3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_post_and_db_keys( $keys ) {
|
public function add_post_and_db_keys( $keys ) {
|
||||||
$keys['s3'] = array(
|
$keys['github'] = array(
|
||||||
'baseUrl-s3',
|
'baseUrl-github',
|
||||||
'cfDistributionId',
|
'cfDistributionId',
|
||||||
's3Bucket',
|
'githubBucket',
|
||||||
's3CacheControl',
|
'githubCacheControl',
|
||||||
's3Key',
|
'githubKey',
|
||||||
's3Region',
|
'githubRegion',
|
||||||
's3RemotePath',
|
'githubRemotePath',
|
||||||
's3Secret',
|
'githubSecret',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $keys;
|
return $keys;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* @link https://leonstafford.github.io
|
* @link https://leonstafford.github.io
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*
|
*
|
||||||
* @package Wp2static_Addon_S3
|
* @package Wp2static_Addon_GitHub
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// If uninstall not called from WordPress, then exit.
|
// If uninstall not called from WordPress, then exit.
|
||||||
|
|
|
@ -1,45 +1,45 @@
|
||||||
<div class="s3_settings_block" style="display:none;">
|
<div class="github_settings_block" style="display:none;">
|
||||||
|
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="baseUrl-s3"><?php echo __('Destination URL', 'static-html-output-plugin');?></label>
|
<label for="baseUrl-github"><?php echo __('Destination URL', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 'baseUrl-s3', 'http://mystaticsite.com', '', ''); ?><br>
|
<?php $tpl->displayTextfield($this, 'baseUrl-github', 'http://mystaticsite.com', '', ''); ?><br>
|
||||||
|
|
||||||
<p><i>Set this to the URL your visitors will use to access your site. For an S3 hosted website, you have a few options which will influence what you put in this field. </i></p>
|
<p><i>Set this to the URL your visitors will use to access your site. For an GitHub hosted website, you have a few options which will influence what you put in this field. </i></p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3Key"><?php echo __('Access Key ID', 'static-html-output-plugin');?></label>
|
<label for="githubKey"><?php echo __('Access Key ID', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 's3Key', 'Access Key ID', 'ie, AKIAIOSFODNN7EXAMPLE'); ?><br>
|
<?php $tpl->displayTextfield($this, 'githubKey', 'Access Key ID', 'ie, AKIAIOSFODNN7EXAMPLE'); ?><br>
|
||||||
|
|
||||||
<p><i>Your S3 user will need permissions to put objects into the bucket. Check that the user whose Key you are using has the correct permissions for S3. You may attach the 'AmazonS3FullAccess' to the user or give more fine grained permissions control via <a href="https://aws.amazon.com/iam/" target="_blank">AWS's IAM</a>.</i></p>
|
<p><i>Your GitHub user will need permissions to put objects into the bucket. Check that the user whose Key you are using has the correct permissions for GitHub. You may attach the 'AmazonGitHubFullAccess' to the user or give more fine grained permissions control via <a href="https://aws.amazon.com/iam/" target="_blank">AWS's IAM</a>.</i></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3Key"><?php echo __('Secret Access Key', 'static-html-output-plugin');?></label>
|
<label for="githubKey"><?php echo __('Secret Access Key', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 's3Secret', 'Secret Access Key', 'ie, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', 'password'); ?>
|
<?php $tpl->displayTextfield($this, 'githubSecret', 'Secret Access Key', 'ie, wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', 'password'); ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3Region"><?php echo __('Region', 'static-html-output-plugin');?></label>
|
<label for="githubRegion"><?php echo __('Region', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// TODO: shift to S3 model/helper
|
// TODO: shift to GitHub model/helper
|
||||||
$s3_regions = array(
|
$github_regions = array(
|
||||||
"us-east-1" => "US East (N. Virginia)",
|
"us-east-1" => "US East (N. Virginia)",
|
||||||
"us-east-2" => "US East (Ohio)",
|
"us-east-2" => "US East (Ohio)",
|
||||||
"us-west-1" => "US West (N. California)",
|
"us-west-1" => "US West (N. California)",
|
||||||
|
@ -62,39 +62,39 @@
|
||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php $tpl->displaySelectMenu($this, $s3_regions, 's3Region', 'Region', 'ie, my-static-site'); ?><br>
|
<?php $tpl->displaySelectMenu($this, $github_regions, 'githubRegion', 'Region', 'ie, my-static-site'); ?><br>
|
||||||
|
|
||||||
<span class="description">choose the AWS region your bucket was created in</span>
|
<span class="description">choose the AWS region your bucket was created in</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3Bucket"><?php echo __('Bucket', 'static-html-output-plugin');?></label>
|
<label for="githubBucket"><?php echo __('Bucket', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 's3Bucket', 'S3 Bucket', 'ie, my-static-site'); ?><br>
|
<?php $tpl->displayTextfield($this, 'githubBucket', 'GitHub Bucket', 'ie, my-static-site'); ?><br>
|
||||||
|
|
||||||
<p><i>Your bucket name as it appears in your <a href="https://s3.console.aws.amazon.com/s3/home" target="_blank">AWS Console for S3</a>.</i></p>
|
<p><i>Your bucket name as it appears in your <a href="https://github.console.aws.amazon.com/github/home" target="_blank">AWS Console for GitHub</a>.</i></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3RemotePath"><?php echo __('Subdirectory', 'static-html-output-plugin');?></label>
|
<label for="githubRemotePath"><?php echo __('Subdirectory', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 's3RemotePath', 'Subfolder in your bucket', 'ie, static-website'); ?><br>
|
<?php $tpl->displayTextfield($this, 'githubRemotePath', 'Subfolder in your bucket', 'ie, static-website'); ?><br>
|
||||||
|
|
||||||
<p><i>In case you want to put your site in a sub directory of a bucket, this will deploy all the static website files into the folder name you specify here.</i></p>
|
<p><i>In case you want to put your site in a sub directory of a bucket, this will deploy all the static website files into the folder name you specify here.</i></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3CacheControl"><?php echo __('Cache-Control', 'static-html-output-plugin');?></label>
|
<label for="githubCacheControl"><?php echo __('Cache-Control', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 's3CacheControl', 'Cache-Control', 'ie, 86400'); ?><br>
|
<?php $tpl->displayTextfield($this, 'githubCacheControl', 'Cache-Control', 'ie, 86400'); ?><br>
|
||||||
|
|
||||||
<p><i>Sets the cache-control max-age value applied to S3 objects. If you are using CloudFront it will use this value to determine how often to refresh the CDN for a particular URL. Reduces CDN Transfer costs. You will need to redeploy the entire site if this value is changed.</a>.</i></p>
|
<p><i>Sets the cache-control max-age value applied to GitHub objects. If you are using CloudFront it will use this value to determine how often to refresh the CDN for a particular URL. Reduces CDN Transfer costs. You will need to redeploy the entire site if this value is changed.</a>.</i></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -104,19 +104,19 @@
|
||||||
<td>
|
<td>
|
||||||
<?php $tpl->displayTextfield($this, 'cfDistributionId', 'CloudFront Distribution ID', 'ie, ABC123DEFX'); ?><br>
|
<?php $tpl->displayTextfield($this, 'cfDistributionId', 'CloudFront Distribution ID', 'ie, ABC123DEFX'); ?><br>
|
||||||
|
|
||||||
<p><i>If using CloudFront in your S3 static website setup, enter the CloudFront Distribution ID here and it will create an invalidation request for all files at the end of the deployment process. The invalidation usually happens within a few minutes. You can check any pending invalidations in your <a href="https://console.aws.amazon.com/cloudfront/home" target="_blank">AWS Console's CloudFront page</a>. You AWS user will need to have the CloudFrontFullAccess permissions or a more controlled policy, that includes the ability to send CloudFront invalidation requests.</i></p>
|
<p><i>If using CloudFront in your GitHub static website setup, enter the CloudFront Distribution ID here and it will create an invalidation request for all files at the end of the deployment process. The invalidation usually happens within a few minutes. You can check any pending invalidations in your <a href="https://console.aws.amazon.com/cloudfront/home" target="_blank">AWS Console's CloudFront page</a>. You AWS user will need to have the CloudFrontFullAccess permissions or a more controlled policy, that includes the ability to send CloudFront invalidation requests.</i></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">
|
<th scope="row">
|
||||||
<label for="s3_test"><?php echo __('Test S3 Settings', 'static-html-output-plugin');?></label>
|
<label for="github_test"><?php echo __('Test GitHub Settings', 'static-html-output-plugin');?></label>
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<button id="s3-test-button" type="button" class="btn-primary button">Test S3 Settings</button>
|
<button id="github-test-button" type="button" class="btn-primary button">Test GitHub Settings</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<a href="https://docs.wp2static.com/en/deploying/deployment-options/amazon-s3/" target="_blank">Read the docs</a> for more on deploying your WordPress site to S3
|
<a href="https://docs.wp2static.com/en/deploying/deployment-options/amazon-github/" target="_blank">Read the docs</a> for more on deploying your WordPress site to GitHub
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin Name: WP2Static Add-on: S3
|
* Plugin Name: WP2Static Add-on: GitHub
|
||||||
* Plugin URI: https://wp2static.com
|
* Plugin URI: https://wp2static.com
|
||||||
* Description: AWS S3 as a deployment option for WP2Static.
|
* Description: AWS GitHub as a deployment option for WP2Static.
|
||||||
* Version: 0.1
|
* Version: 0.1
|
||||||
* Author: Leon Stafford
|
* Author: Leon Stafford
|
||||||
* Author URI: https://leonstafford.github.io
|
* Author URI: https://leonstafford.github.io
|
||||||
* License: Unlicense
|
* License: Unlicense
|
||||||
* License URI: http://unlicense.org
|
* License URI: http://unlicense.org
|
||||||
* Text Domain: wp2static-addon-s3
|
* Text Domain: wp2static-addon-github
|
||||||
* Domain Path: /languages
|
* Domain Path: /languages
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -27,31 +27,31 @@ $wp2static_core_dir =
|
||||||
$add_on_dir = dirname( __FILE__ );
|
$add_on_dir = dirname( __FILE__ );
|
||||||
|
|
||||||
// NOTE: bypass instantiating plugin for specific AJAX requests
|
// NOTE: bypass instantiating plugin for specific AJAX requests
|
||||||
if ( $ajax_action == 'test_s3' ) {
|
if ( $ajax_action == 'test_github' ) {
|
||||||
require_once $wp2static_core_dir .
|
require_once $wp2static_core_dir .
|
||||||
'/plugin/WP2Static/SitePublisher.php';
|
'/plugin/WP2Static/SitePublisher.php';
|
||||||
require_once $add_on_dir . '/S3Deployer.php';
|
require_once $add_on_dir . '/GitHubDeployer.php';
|
||||||
|
|
||||||
wp_die();
|
wp_die();
|
||||||
return null;
|
return null;
|
||||||
} elseif ( $ajax_action == 's3_prepare_export' ) {
|
} elseif ( $ajax_action == 'github_prepare_export' ) {
|
||||||
require_once $wp2static_core_dir .
|
require_once $wp2static_core_dir .
|
||||||
'/plugin/WP2Static/SitePublisher.php';
|
'/plugin/WP2Static/SitePublisher.php';
|
||||||
require_once $add_on_dir . '/S3Deployer.php';
|
require_once $add_on_dir . '/GitHubDeployer.php';
|
||||||
|
|
||||||
wp_die();
|
wp_die();
|
||||||
return null;
|
return null;
|
||||||
} elseif ( $ajax_action == 's3_transfer_files' ) {
|
} elseif ( $ajax_action == 'github_transfer_files' ) {
|
||||||
require_once $wp2static_core_dir .
|
require_once $wp2static_core_dir .
|
||||||
'/plugin/WP2Static/SitePublisher.php';
|
'/plugin/WP2Static/SitePublisher.php';
|
||||||
require_once $add_on_dir . '/S3Deployer.php';
|
require_once $add_on_dir . '/GitHubDeployer.php';
|
||||||
|
|
||||||
wp_die();
|
wp_die();
|
||||||
return null;
|
return null;
|
||||||
} elseif ( $ajax_action == 'cloudfront_invalidate_all_items' ) {
|
} elseif ( $ajax_action == 'cloudfront_invalidate_all_items' ) {
|
||||||
require_once $wp2static_core_dir .
|
require_once $wp2static_core_dir .
|
||||||
'/plugin/WP2Static/SitePublisher.php';
|
'/plugin/WP2Static/SitePublisher.php';
|
||||||
require_once $add_on_dir . '/S3Deployer.php';
|
require_once $add_on_dir . '/GitHubDeployer.php';
|
||||||
|
|
||||||
wp_die();
|
wp_die();
|
||||||
return null;
|
return null;
|
||||||
|
@ -59,14 +59,14 @@ if ( $ajax_action == 'test_s3' ) {
|
||||||
|
|
||||||
define( 'PLUGIN_NAME_VERSION', '0.1' );
|
define( 'PLUGIN_NAME_VERSION', '0.1' );
|
||||||
|
|
||||||
require plugin_dir_path( __FILE__ ) . 'includes/class-wp2static-addon-s3.php';
|
require plugin_dir_path( __FILE__ ) . 'includes/class-wp2static-addon-github.php';
|
||||||
|
|
||||||
function run_wp2static_addon_s3() {
|
function run_wp2static_addon_github() {
|
||||||
|
|
||||||
$plugin = new Wp2static_Addon_S3();
|
$plugin = new Wp2static_Addon_GitHub();
|
||||||
$plugin->run();
|
$plugin->run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_wp2static_addon_s3();
|
run_wp2static_addon_github();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue