mirror of
https://ghproxy.net/https://github.com/elementor/wp2static-addon-netlify.git
synced 2025-10-04 04:27:18 +08:00
bulk rename
This commit is contained in:
parent
625881c9eb
commit
32f8ef3904
10 changed files with 168 additions and 169 deletions
|
@ -1,19 +1,18 @@
|
|||
=== Plugin Name ===
|
||||
Contributors: leonstafford
|
||||
Donate link: https://leonstafford.github.io
|
||||
Tags: wp2static,s3,static
|
||||
Tags: wp2static,netlify,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 Netlify as a deployment option for WP2Static.
|
||||
|
||||
== Description ==
|
||||
|
||||
Take advantage of the S3 and optionally CloudFront to host your WordPress
|
||||
powered static website.
|
||||
Take advantage of the Netlify to host your WordPress powered static website.
|
||||
|
||||
== Installation ==
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wp2static_Addon_S3_Admin {
|
||||
class Wp2static_Addon_Netlify_Admin {
|
||||
|
||||
private $plugin_name;
|
||||
private $version;
|
||||
|
@ -12,6 +12,6 @@ class Wp2static_Addon_S3_Admin {
|
|||
}
|
||||
|
||||
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-netlify-admin.js', array( 'jquery' ), $this->version, false );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
'use strict';
|
||||
|
||||
$(function() {
|
||||
deploy_options['s3'] = {
|
||||
deploy_options['netlify'] = {
|
||||
exportSteps: [
|
||||
's3_prepare_export',
|
||||
's3_transfer_files',
|
||||
'netlify_prepare_export',
|
||||
'netlify_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.',
|
||||
netlifyKey: 'Please input an Netlify Key in order to authenticate when using the Netlify deployment method.',
|
||||
netlifySecret: 'Please input an Netlify Secret in order to authenticate when using the Netlify deployment method.',
|
||||
netlifyBucket: 'Please input the name of the Netlify 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['netlify_prepare_export'] = 'Preparing files for Netlify deployment';
|
||||
status_descriptions['netlify_transfer_files'] = 'Deploying files to Netlify';
|
||||
status_descriptions['cloudfront_invalidate_all_items'] = 'Invalidating CloudFront cache';
|
||||
}); // end DOM ready
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "wp2static/wp2static-addon-s3",
|
||||
"description": "S3 deployment Add-on for WP2Static.",
|
||||
"name": "wp2static/wp2static-addon-netlify",
|
||||
"description": "Netlify deployment Add-on for WP2Static.",
|
||||
"homepage": "https://wp2static.com",
|
||||
"license": "UNLICENSE",
|
||||
"authors": [
|
||||
|
@ -12,10 +12,10 @@
|
|||
],
|
||||
"type": "wordpress-plugin",
|
||||
"support": {
|
||||
"issues": "https://github.com/WP2Static/wp2static-addon-s3/issues",
|
||||
"issues": "https://github.com/WP2Static/wp2static-addon-netlify/issues",
|
||||
"forum": "https://wp2static.com/community",
|
||||
"docs": "https://wp2static.com/documentation",
|
||||
"source": "https://github.com/WP2Static/wp2static-addon-s3"
|
||||
"source": "https://github.com/WP2Static/wp2static-addon-netlify"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
|
@ -37,13 +37,13 @@
|
|||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WP2StaticS3\\": "src/"
|
||||
"WP2StaticNetlify\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"PHPStan\\WordPress\\": "tests/phpstan/",
|
||||
"WP2StaticS3\\": "src/"
|
||||
"WP2StaticNetlify\\": "src/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Wp2static_Addon_S3 {
|
||||
class Wp2static_Addon_Netlify {
|
||||
|
||||
protected $loader;
|
||||
protected $plugin_name;
|
||||
|
@ -12,21 +12,21 @@ class Wp2static_Addon_S3 {
|
|||
} else {
|
||||
$this->version = '1.0.0';
|
||||
}
|
||||
$this->plugin_name = 'wp2static-addon-s3';
|
||||
$this->plugin_name = 'wp2static-addon-netlify';
|
||||
|
||||
$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-netlify-loader.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp2static-addon-netlify-admin.php';
|
||||
|
||||
$this->loader = new Wp2static_Addon_S3_Loader();
|
||||
$this->loader = new Wp2static_Addon_Netlify_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_Netlify_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['netlify'] = array('Amazon Netlify');
|
||||
|
||||
return $deploy_options;
|
||||
}
|
||||
|
||||
public function load_deployment_option_template( $templates ) {
|
||||
$templates[] = __DIR__ . '/../views/s3_settings_block.phtml';
|
||||
$templates[] = __DIR__ . '/../views/netlify_settings_block.phtml';
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
public function add_deployment_option_keys( $keys ) {
|
||||
$new_keys = array(
|
||||
'baseUrl-s3',
|
||||
'baseUrl-netlify',
|
||||
'cfDistributionId',
|
||||
's3Bucket',
|
||||
's3CacheControl',
|
||||
's3Key',
|
||||
's3Region',
|
||||
's3RemotePath',
|
||||
's3Secret',
|
||||
'netlifyBucket',
|
||||
'netlifyCacheControl',
|
||||
'netlifyKey',
|
||||
'netlifyRegion',
|
||||
'netlifyRemotePath',
|
||||
'netlifySecret',
|
||||
);
|
||||
|
||||
$keys = array_merge(
|
||||
|
@ -67,13 +67,13 @@ class Wp2static_Addon_S3 {
|
|||
|
||||
public function whitelist_deployment_option_keys( $keys ) {
|
||||
$whitelist_keys = array(
|
||||
'baseUrl-s3',
|
||||
'baseUrl-netlify',
|
||||
'cfDistributionId',
|
||||
's3Bucket',
|
||||
's3CacheControl',
|
||||
's3Key',
|
||||
's3Region',
|
||||
's3RemotePath',
|
||||
'netlifyBucket',
|
||||
'netlifyCacheControl',
|
||||
'netlifyKey',
|
||||
'netlifyRegion',
|
||||
'netlifyRemotePath',
|
||||
);
|
||||
|
||||
$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['netlify'] = array(
|
||||
'baseUrl-netlify',
|
||||
'cfDistributionId',
|
||||
's3Bucket',
|
||||
's3CacheControl',
|
||||
's3Key',
|
||||
's3Region',
|
||||
's3RemotePath',
|
||||
's3Secret',
|
||||
'netlifyBucket',
|
||||
'netlifyCacheControl',
|
||||
'netlifyKey',
|
||||
'netlifyRegion',
|
||||
'netlifyRemotePath',
|
||||
'netlifySecret',
|
||||
);
|
||||
|
||||
return $keys;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace WP2StaticS3;
|
||||
namespace WP2StaticNetlify;
|
||||
|
||||
class Controller {
|
||||
const WP2STATIC_S3_VERSION = '0.1';
|
||||
const WP2STATIC_Netlify_VERSION = '0.1';
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
|
@ -11,7 +11,7 @@ class Controller {
|
|||
// initialize options DB
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
|
@ -31,14 +31,14 @@ class Controller {
|
|||
// if deployment_url option doesn't exist, create:
|
||||
$options = $this->getOptions();
|
||||
|
||||
if ( ! isset( $options['s3Bucket'] ) ) {
|
||||
if ( ! isset( $options['netlifyBucket'] ) ) {
|
||||
$this->seedOptions();
|
||||
}
|
||||
|
||||
add_filter( 'wp2static_add_menu_items', [ 'WP2StaticS3\Controller', 'addSubmenuPage' ] );
|
||||
add_filter( 'wp2static_add_menu_items', [ 'WP2StaticNetlify\Controller', 'addSubmenuPage' ] );
|
||||
|
||||
add_action(
|
||||
'admin_post_wp2static_s3_save_options',
|
||||
'admin_post_wp2static_netlify_save_options',
|
||||
[ $this, 'saveOptionsFromUI' ],
|
||||
15,
|
||||
1);
|
||||
|
@ -51,14 +51,14 @@ class Controller {
|
|||
|
||||
add_action(
|
||||
'wp2static_post_deploy_trigger',
|
||||
[ 'WP2StaticS3\Deployer', 'cloudfront_invalidate' ],
|
||||
[ 'WP2StaticNetlify\Deployer', 'cloudfront_invalidate' ],
|
||||
15,
|
||||
1);
|
||||
|
||||
// if ( defined( 'WP_CLI' ) ) {
|
||||
// \WP_CLI::add_command(
|
||||
// 'wp2static s3',
|
||||
// [ 'WP2StaticS3\CLI', 's3' ]);
|
||||
// 'wp2static netlify',
|
||||
// [ 'WP2StaticNetlify\CLI', 'netlify' ]);
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class Controller {
|
|||
global $wpdb;
|
||||
$options = [];
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$rows = $wpdb->get_results( "SELECT * FROM $table_name" );
|
||||
|
||||
|
@ -94,7 +94,7 @@ class Controller {
|
|||
public static function seedOptions() : void {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$query_string = "INSERT INTO $table_name (name, value, label, description) VALUES (%s, %s, %s, %s);";
|
||||
$query = $wpdb->prepare(
|
||||
|
@ -108,7 +108,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3Bucket',
|
||||
'netlifyBucket',
|
||||
'',
|
||||
'Bucket name',
|
||||
'');
|
||||
|
@ -117,7 +117,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3AccessKeyID',
|
||||
'netlifyAccessKeyID',
|
||||
'',
|
||||
'Access Key ID',
|
||||
'');
|
||||
|
@ -126,7 +126,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3SecretAccessKey',
|
||||
'netlifySecretAccessKey',
|
||||
'',
|
||||
'Secret Access Key',
|
||||
'');
|
||||
|
@ -154,7 +154,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3Region',
|
||||
'netlifyRegion',
|
||||
'',
|
||||
'Region',
|
||||
'');
|
||||
|
@ -163,7 +163,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3Profile',
|
||||
'netlifyProfile',
|
||||
'',
|
||||
'Profile',
|
||||
'');
|
||||
|
@ -190,7 +190,7 @@ class Controller {
|
|||
|
||||
$query = $wpdb->prepare(
|
||||
$query_string,
|
||||
's3RemotePath',
|
||||
'netlifyRemotePath',
|
||||
'',
|
||||
'Path prefix in bucket',
|
||||
'Optionally, deploy to a subdirectory within bucket');
|
||||
|
@ -205,7 +205,7 @@ class Controller {
|
|||
public static function saveOption( $name, $value ) : void {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$query_string = "INSERT INTO $table_name (name, value) VALUES (%s, %s);";
|
||||
$query = $wpdb->prepare( $query_string, $name, $value );
|
||||
|
@ -213,28 +213,28 @@ class Controller {
|
|||
$wpdb->query( $query );
|
||||
}
|
||||
|
||||
public static function renderS3Page() : void {
|
||||
public static function renderNetlifyPage() : void {
|
||||
$view = [];
|
||||
$view['nonce_action'] = 'wp2static-s3-options';
|
||||
$view['nonce_action'] = 'wp2static-netlify-options';
|
||||
$view['uploads_path'] = \WP2Static\SiteInfo::getPath('uploads');
|
||||
$s3_path = \WP2Static\SiteInfo::getPath( 'uploads' ) . 'wp2static-processed-site.s3';
|
||||
$netlify_path = \WP2Static\SiteInfo::getPath( 'uploads' ) . 'wp2static-processed-site.netlify';
|
||||
|
||||
|
||||
$view['options'] = self::getOptions();
|
||||
|
||||
$view['s3_url'] =
|
||||
is_file( $s3_path ) ?
|
||||
\WP2Static\SiteInfo::getUrl( 'uploads' ) . 'wp2static-processed-site.s3' : '#';
|
||||
$view['netlify_url'] =
|
||||
is_file( $netlify_path ) ?
|
||||
\WP2Static\SiteInfo::getUrl( 'uploads' ) . 'wp2static-processed-site.netlify' : '#';
|
||||
|
||||
require_once __DIR__ . '/../views/s3-page.php';
|
||||
require_once __DIR__ . '/../views/netlify-page.php';
|
||||
}
|
||||
|
||||
|
||||
public function deploy( $processed_site_path ) {
|
||||
\WP2Static\WsLog::l('S3 Addon deploying');
|
||||
\WP2Static\WsLog::l('Netlify Addon deploying');
|
||||
|
||||
$s3_deployer = new Deployer();
|
||||
$s3_deployer->upload_files( $processed_site_path );
|
||||
$netlify_deployer = new Deployer();
|
||||
$netlify_deployer->upload_files( $processed_site_path );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -269,15 +269,15 @@ class Controller {
|
|||
}
|
||||
|
||||
public static function activate_for_single_site() : void {
|
||||
error_log('activating WP2Static S3 Add-on');
|
||||
error_log('activating WP2Static Netlify Add-on');
|
||||
}
|
||||
|
||||
public static function deactivate_for_single_site() : void {
|
||||
error_log('deactivating WP2Static S3 Add-on, maintaining options');
|
||||
error_log('deactivating WP2Static Netlify Add-on, maintaining options');
|
||||
}
|
||||
|
||||
public static function deactivate( bool $network_wide = null ) : void {
|
||||
error_log('deactivating WP2Static S3 Add-on');
|
||||
error_log('deactivating WP2Static Netlify Add-on');
|
||||
if ( $network_wide ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -303,7 +303,7 @@ class Controller {
|
|||
}
|
||||
|
||||
public static function activate( bool $network_wide = null ) : void {
|
||||
error_log('activating s3 addon');
|
||||
error_log('activating netlify addon');
|
||||
if ( $network_wide ) {
|
||||
global $wpdb;
|
||||
|
||||
|
@ -329,17 +329,17 @@ class Controller {
|
|||
}
|
||||
|
||||
public static function addSubmenuPage( $submenu_pages ) {
|
||||
$submenu_pages['s3'] = [ 'WP2StaticS3\Controller', 'renderS3Page' ];
|
||||
$submenu_pages['netlify'] = [ 'WP2StaticNetlify\Controller', 'renderNetlifyPage' ];
|
||||
|
||||
return $submenu_pages;
|
||||
}
|
||||
|
||||
public static function saveOptionsFromUI() {
|
||||
check_admin_referer( 'wp2static-s3-options' );
|
||||
check_admin_referer( 'wp2static-netlify-options' );
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
|
@ -349,27 +349,27 @@ class Controller {
|
|||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => sanitize_text_field( $_POST['s3Bucket'] ) ],
|
||||
[ 'name' => 's3Bucket' ]
|
||||
[ 'value' => sanitize_text_field( $_POST['netlifyBucket'] ) ],
|
||||
[ 'name' => 'netlifyBucket' ]
|
||||
);
|
||||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => sanitize_text_field( $_POST['s3AccessKeyID'] ) ],
|
||||
[ 'name' => 's3AccessKeyID' ]
|
||||
[ 'value' => sanitize_text_field( $_POST['netlifyAccessKeyID'] ) ],
|
||||
[ 'name' => 'netlifyAccessKeyID' ]
|
||||
);
|
||||
|
||||
$secret_access_key =
|
||||
$_POST['s3SecretAccessKey'] ?
|
||||
$_POST['netlifySecretAccessKey'] ?
|
||||
self::encrypt_decrypt(
|
||||
'encrypt',
|
||||
sanitize_text_field( $_POST['s3SecretAccessKey'] )
|
||||
sanitize_text_field( $_POST['netlifySecretAccessKey'] )
|
||||
) : '';
|
||||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => $secret_access_key ],
|
||||
[ 'name' => 's3SecretAccessKey' ]
|
||||
[ 'name' => 'netlifySecretAccessKey' ]
|
||||
);
|
||||
|
||||
$wpdb->update(
|
||||
|
@ -393,8 +393,8 @@ class Controller {
|
|||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => sanitize_text_field( $_POST['s3Region'] ) ],
|
||||
[ 'name' => 's3Region' ]
|
||||
[ 'value' => sanitize_text_field( $_POST['netlifyRegion'] ) ],
|
||||
[ 'name' => 'netlifyRegion' ]
|
||||
);
|
||||
|
||||
$wpdb->update(
|
||||
|
@ -405,8 +405,8 @@ class Controller {
|
|||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => sanitize_text_field( $_POST['s3Profile'] ) ],
|
||||
[ 'name' => 's3Profile' ]
|
||||
[ 'value' => sanitize_text_field( $_POST['netlifyProfile'] ) ],
|
||||
[ 'name' => 'netlifyProfile' ]
|
||||
);
|
||||
|
||||
$wpdb->update(
|
||||
|
@ -417,11 +417,11 @@ class Controller {
|
|||
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
[ 'value' => sanitize_text_field( $_POST['s3RemotePath'] ) ],
|
||||
[ 'name' => 's3RemotePath' ]
|
||||
[ 'value' => sanitize_text_field( $_POST['netlifyRemotePath'] ) ],
|
||||
[ 'name' => 'netlifyRemotePath' ]
|
||||
);
|
||||
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=wp2static-s3' ) );
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=wp2static-netlify' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
|
@ -433,7 +433,7 @@ class Controller {
|
|||
public static function getValue( string $name ) : string {
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_s3_options';
|
||||
$table_name = $wpdb->prefix . 'wp2static_addon_netlify_options';
|
||||
|
||||
$sql = $wpdb->prepare(
|
||||
"SELECT value FROM $table_name WHERE" . ' name = %s LIMIT 1',
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace WP2StaticS3;
|
||||
namespace WP2StaticNetlify;
|
||||
|
||||
use RecursiveIteratorIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use Aws\S3\S3Client;
|
||||
use Aws\Netlify\NetlifyClient;
|
||||
use Aws\CloudFront\CloudFrontClient;
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
|
@ -26,9 +26,9 @@ class Deployer {
|
|||
}
|
||||
|
||||
$client_options = [
|
||||
'profile' => Controller::getValue( 's3Profile' ),
|
||||
'profile' => Controller::getValue( 'netlifyProfile' ),
|
||||
'version' => 'latest',
|
||||
'region' => Controller::getValue( 's3Region' ),
|
||||
'region' => Controller::getValue( 'netlifyRegion' ),
|
||||
];
|
||||
|
||||
/*
|
||||
|
@ -39,15 +39,15 @@ class Deployer {
|
|||
- an IAM role.
|
||||
*/
|
||||
if (
|
||||
Controller::getValue( 's3AccessKeyID' ) &&
|
||||
Controller::getValue( 's3SecretAccessKey' )
|
||||
Controller::getValue( 'netlifyAccessKeyID' ) &&
|
||||
Controller::getValue( 'netlifySecretAccessKey' )
|
||||
) {
|
||||
error_log('using supplied creds');
|
||||
$client_options['credentials'] = [
|
||||
'key' => Controller::getValue( 's3AccessKeyID' ),
|
||||
'secret' => \WP2StaticS3\Controller::encrypt_decrypt(
|
||||
'key' => Controller::getValue( 'netlifyAccessKeyID' ),
|
||||
'secret' => \WP2StaticNetlify\Controller::encrypt_decrypt(
|
||||
'decrypt',
|
||||
Controller::getValue( 's3SecretAccessKey' )
|
||||
Controller::getValue( 'netlifySecretAccessKey' )
|
||||
)
|
||||
];
|
||||
unset( $client_options['profile'] );
|
||||
|
@ -55,8 +55,8 @@ class Deployer {
|
|||
|
||||
error_log(print_r($client_options, true));
|
||||
|
||||
// instantiate S3 client
|
||||
$s3 = new \Aws\S3\S3Client( $client_options );
|
||||
// instantiate Netlify client
|
||||
$netlify = new \Aws\Netlify\NetlifyClient( $client_options );
|
||||
|
||||
|
||||
// iterate each file in ProcessedSite
|
||||
|
@ -93,12 +93,12 @@ class Deployer {
|
|||
}
|
||||
|
||||
$key =
|
||||
Controller::getValue( 's3RemotePath' ) ?
|
||||
Controller::getValue( 's3RemotePath' ) . '/' . ltrim( str_replace( $processed_site_path, '', $filename ), '/' ) :
|
||||
Controller::getValue( 'netlifyRemotePath' ) ?
|
||||
Controller::getValue( 'netlifyRemotePath' ) . '/' . ltrim( str_replace( $processed_site_path, '', $filename ), '/' ) :
|
||||
ltrim( str_replace( $processed_site_path, '', $filename ), '/' );
|
||||
|
||||
$result = $s3->putObject([
|
||||
'Bucket' => Controller::getValue( 's3Bucket' ),
|
||||
$result = $netlify->putObject([
|
||||
'Bucket' => Controller::getValue( 'netlifyBucket' ),
|
||||
'Key' => $key,
|
||||
'Body' => file_get_contents( $filename ),
|
||||
'ACL' => 'public-read',
|
||||
|
@ -134,15 +134,15 @@ class Deployer {
|
|||
- an IAM role.
|
||||
*/
|
||||
if (
|
||||
Controller::getValue( 's3AccessKeyID' ) &&
|
||||
Controller::getValue( 's3SecretAccessKey' )
|
||||
Controller::getValue( 'netlifyAccessKeyID' ) &&
|
||||
Controller::getValue( 'netlifySecretAccessKey' )
|
||||
) {
|
||||
|
||||
$credentials = new Aws\Credentials\Credentials(
|
||||
Controller::getValue( 's3AccessKeyID' ),
|
||||
\WP2StaticS3\Controller::encrypt_decrypt(
|
||||
Controller::getValue( 'netlifyAccessKeyID' ),
|
||||
\WP2StaticNetlify\Controller::encrypt_decrypt(
|
||||
'decrypt',
|
||||
Controller::getValue( 's3SecretAccessKey' )
|
||||
Controller::getValue( 'netlifySecretAccessKey' )
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -155,7 +155,7 @@ class Deployer {
|
|||
$result = $client->createInvalidation([
|
||||
'DistributionId' => Controller::getValue( 'cfDistributionID' ),
|
||||
'InvalidationBatch' => [
|
||||
'CallerReference' => 'WP2Static S3 Add-on',
|
||||
'CallerReference' => 'WP2Static Netlify Add-on',
|
||||
'Paths' => [
|
||||
'Items' => ['/*'],
|
||||
'Quantity' => 1,
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* @link https://leonstafford.github.io
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Wp2static_Addon_S3
|
||||
* @package Wp2static_Addon_Netlify
|
||||
*/
|
||||
|
||||
// If uninstall not called from WordPress, then exit.
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<h2>S3 Deployment Options</h2>
|
||||
<h2>Netlify Deployment Options</h2>
|
||||
|
||||
<h3>S3</h3>
|
||||
<h3>Netlify</h3>
|
||||
|
||||
<form
|
||||
name="wp2static-s3-save-options"
|
||||
name="wp2static-netlify-save-options"
|
||||
method="POST"
|
||||
action="<?php echo esc_url( admin_url('admin-post.php') ); ?>">
|
||||
|
||||
<?php wp_nonce_field( $view['nonce_action'] ); ?>
|
||||
<input name="action" type="hidden" value="wp2static_s3_save_options" />
|
||||
<input name="action" type="hidden" value="wp2static_netlify_save_options" />
|
||||
|
||||
<table class="widefat striped">
|
||||
<tbody>
|
||||
|
@ -16,15 +16,15 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3Bucket']->name; ?>"
|
||||
><?php echo $view['options']['s3Bucket']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifyBucket']->name; ?>"
|
||||
><?php echo $view['options']['netlifyBucket']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3Bucket']->name; ?>"
|
||||
name="<?php echo $view['options']['s3Bucket']->name; ?>"
|
||||
id="<?php echo $view['options']['netlifyBucket']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifyBucket']->name; ?>"
|
||||
type="text"
|
||||
value="<?php echo $view['options']['s3Bucket']->value !== '' ? $view['options']['s3Bucket']->value : ''; ?>"
|
||||
value="<?php echo $view['options']['netlifyBucket']->value !== '' ? $view['options']['netlifyBucket']->value : ''; ?>"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -32,15 +32,15 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3Region']->name; ?>"
|
||||
><?php echo $view['options']['s3Region']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifyRegion']->name; ?>"
|
||||
><?php echo $view['options']['netlifyRegion']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3Region']->name; ?>"
|
||||
name="<?php echo $view['options']['s3Region']->name; ?>"
|
||||
id="<?php echo $view['options']['netlifyRegion']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifyRegion']->name; ?>"
|
||||
type="text"
|
||||
value="<?php echo $view['options']['s3Region']->value !== '' ? $view['options']['s3Region']->value : ''; ?>"
|
||||
value="<?php echo $view['options']['netlifyRegion']->value !== '' ? $view['options']['netlifyRegion']->value : ''; ?>"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -48,14 +48,14 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3AccessKeyID']->name; ?>"
|
||||
><?php echo $view['options']['s3AccessKeyID']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifyAccessKeyID']->name; ?>"
|
||||
><?php echo $view['options']['netlifyAccessKeyID']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3AccessKeyID']->name; ?>"
|
||||
name="<?php echo $view['options']['s3AccessKeyID']->name; ?>"
|
||||
value="<?php echo $view['options']['s3AccessKeyID']->value !== '' ? $view['options']['s3AccessKeyID']->value : ''; ?>"
|
||||
id="<?php echo $view['options']['netlifyAccessKeyID']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifyAccessKeyID']->name; ?>"
|
||||
value="<?php echo $view['options']['netlifyAccessKeyID']->value !== '' ? $view['options']['netlifyAccessKeyID']->value : ''; ?>"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -63,16 +63,16 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3SecretAccessKey']->name; ?>"
|
||||
><?php echo $view['options']['s3SecretAccessKey']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifySecretAccessKey']->name; ?>"
|
||||
><?php echo $view['options']['netlifySecretAccessKey']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3SecretAccessKey']->name; ?>"
|
||||
name="<?php echo $view['options']['s3SecretAccessKey']->name; ?>"
|
||||
id="<?php echo $view['options']['netlifySecretAccessKey']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifySecretAccessKey']->name; ?>"
|
||||
type="password"
|
||||
value="<?php echo $view['options']['s3SecretAccessKey']->value !== '' ?
|
||||
\WP2StaticS3\Controller::encrypt_decrypt('decrypt', $view['options']['s3SecretAccessKey']->value) :
|
||||
value="<?php echo $view['options']['netlifySecretAccessKey']->value !== '' ?
|
||||
\WP2StaticNetlify\Controller::encrypt_decrypt('decrypt', $view['options']['netlifySecretAccessKey']->value) :
|
||||
''; ?>"
|
||||
/>
|
||||
</td>
|
||||
|
@ -81,15 +81,15 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3Profile']->name; ?>"
|
||||
><?php echo $view['options']['s3Profile']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifyProfile']->name; ?>"
|
||||
><?php echo $view['options']['netlifyProfile']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3Profile']->name; ?>"
|
||||
name="<?php echo $view['options']['s3Profile']->name; ?>"
|
||||
id="<?php echo $view['options']['netlifyProfile']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifyProfile']->name; ?>"
|
||||
type="text"
|
||||
value="<?php echo $view['options']['s3Profile']->value !== '' ? $view['options']['s3Profile']->value : ''; ?>"
|
||||
value="<?php echo $view['options']['netlifyProfile']->value !== '' ? $view['options']['netlifyProfile']->value : ''; ?>"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -98,15 +98,15 @@
|
|||
<tr>
|
||||
<td style="width:50%;">
|
||||
<label
|
||||
for="<?php echo $view['options']['s3RemotePath']->name; ?>"
|
||||
><?php echo $view['options']['s3RemotePath']->label; ?></label>
|
||||
for="<?php echo $view['options']['netlifyRemotePath']->name; ?>"
|
||||
><?php echo $view['options']['netlifyRemotePath']->label; ?></label>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
id="<?php echo $view['options']['s3RemotePath']->name; ?>"
|
||||
name="<?php echo $view['options']['s3RemotePath']->name; ?>"
|
||||
id="<?php echo $view['options']['netlifyRemotePath']->name; ?>"
|
||||
name="<?php echo $view['options']['netlifyRemotePath']->name; ?>"
|
||||
type="text"
|
||||
value="<?php echo $view['options']['s3RemotePath']->value !== '' ? $view['options']['s3RemotePath']->value : ''; ?>"
|
||||
value="<?php echo $view['options']['netlifyRemotePath']->value !== '' ? $view['options']['netlifyRemotePath']->value : ''; ?>"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -163,7 +163,7 @@
|
|||
name="<?php echo $view['options']['cfSecretAccessKey']->name; ?>"
|
||||
type="password"
|
||||
value="<?php echo $view['options']['cfSecretAccessKey']->value !== '' ?
|
||||
\WP2StaticS3\Controller::encrypt_decrypt('decrypt', $view['options']['cfSecretAccessKey']->value) :
|
||||
\WP2StaticNetlify\Controller::encrypt_decrypt('decrypt', $view['options']['cfSecretAccessKey']->value) :
|
||||
''; ?>"
|
||||
/>
|
||||
</td>
|
||||
|
@ -207,6 +207,6 @@
|
|||
|
||||
<br>
|
||||
|
||||
<button class="button btn-primary">Save S3 Options</button>
|
||||
<button class="button btn-primary">Save Netlify Options</button>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Plugin Name: WP2Static Add-on: S3 Deployment
|
||||
* Plugin Name: WP2Static Add-on: Netlify Deployment
|
||||
* Plugin URI: https://wp2static.com
|
||||
* Description: AWS S3 deployment add-on for WP2Static.
|
||||
* Description: Netlify deployment add-on for WP2Static.
|
||||
* Version: 0.1
|
||||
* Author: Leon Stafford
|
||||
* Author URI: https://ljs.dev
|
||||
* License: Unlicense
|
||||
* License URI: http://unlicense.org
|
||||
* Text Domain: wp2static-addon-s3
|
||||
* Text Domain: wp2static-addon-netlify
|
||||
*/
|
||||
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
define( 'WP2STATIC_S3_PATH', plugin_dir_path( __FILE__ ) );
|
||||
define( 'WP2STATIC_S3_VERSION', '0.1' );
|
||||
define( 'WP2STATIC_Netlify_PATH', plugin_dir_path( __FILE__ ) );
|
||||
define( 'WP2STATIC_Netlify_VERSION', '0.1' );
|
||||
|
||||
require WP2STATIC_S3_PATH . 'vendor/autoload.php';
|
||||
require WP2STATIC_Netlify_PATH . 'vendor/autoload.php';
|
||||
|
||||
function run_wp2static_addon_s3() {
|
||||
$controller = new WP2StaticS3\Controller();
|
||||
function run_wp2static_addon_netlify() {
|
||||
$controller = new WP2StaticNetlify\Controller();
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
register_activation_hook(
|
||||
__FILE__,
|
||||
[ 'WP2StaticS3\Controller', 'activate' ]
|
||||
[ 'WP2StaticNetlify\Controller', 'activate' ]
|
||||
);
|
||||
|
||||
register_deactivation_hook(
|
||||
__FILE__,
|
||||
[ 'WP2StaticS3\Controller', 'deactivate' ]
|
||||
[ 'WP2StaticNetlify\Controller', 'deactivate' ]
|
||||
);
|
||||
|
||||
run_wp2static_addon_s3();
|
||||
run_wp2static_addon_netlify();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue