Skip to content

Commit

Permalink
initial clone from github
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon committed Apr 27, 2019
0 parents commit e6253cd
Show file tree
Hide file tree
Showing 10 changed files with 840 additions and 0 deletions.
403 changes: 403 additions & 0 deletions GitHub.php

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
29 changes: 29 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== Plugin Name ===
Contributors: leonstafford
Donate link: https://leonstafford.github.io
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 GitHub as a deployment option for WP2Static.

== Description ==

Take advantage of the GitHub and optionally CloudFront to host your WordPress
powered static website.

== Installation ==

Upload the ZIP to your WordPress plugins page within your dashboard.

Activate the plugin, then navigate to your WP2Static main plugin page to see
the new deployment option available.

== Changelog ==

= 0.1 =

First release
17 changes: 17 additions & 0 deletions admin/class-wp2static-addon-github-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class Wp2static_Addon_GitHub_Admin {

private $plugin_name;
private $version;

public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;

}

public function enqueue_scripts() {
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp2static-addon-github-admin.js', array( 'jquery' ), $this->version, false );
}
}
27 changes: 27 additions & 0 deletions admin/js/wp2static-addon-github-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function( $ ) {
'use strict';

$(function() {
deploy_options['github'] = {
exportSteps: [
'github_prepare_export',
'github_upload_files',
'finalize_deployment'
],
required_fields: {
ghToken: 'Please specify your GitHub personal access token in order to deploy to GitHub.',
ghRepo: 'Please specify your GitHub repository name in order to deploy to GitHub.',
ghBranch: 'Please specify which branch in your GitHub repository you want to deploy to.',
},
repo_field: {
field: 'ghRepo',
message: "Please ensure your GitHub repo is specified as USER_OR_ORG_NAME/REPO_NAME\n"
}
};

status_descriptions['github_prepare_export'] = 'Preparing files for GitHub deployment';
status_descriptions['github_upload_files'] = 'Deploying files via GitHub';
status_descriptions['cloudfront_invalidate_all_items'] = 'Invalidating CloudFront cache';
}); // end DOM ready

})( jQuery );
43 changes: 43 additions & 0 deletions includes/class-wp2static-addon-github-loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

class Wp2static_Addon_GitHub_Loader {

protected $actions;
protected $filters;

public function __construct() {
$this->actions = array();
$this->filters = array();

}

public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}

public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}

private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);

return $hooks;
}

public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}

foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}
136 changes: 136 additions & 0 deletions includes/class-wp2static-addon-github.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

class Wp2static_Addon_GitHub {

protected $loader;
protected $plugin_name;
protected $version;

public function __construct() {
if ( defined( 'PLUGIN_NAME_VERSION' ) ) {
$this->version = PLUGIN_NAME_VERSION;
} else {
$this->version = '1.0.0';
}
$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-github-loader.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp2static-addon-github-admin.php';

$this->loader = new Wp2static_Addon_GitHub_Loader();
}

private function define_admin_hooks() {
$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' );
}
}

public function add_deployment_option_to_ui( $deploy_options ) {
$deploy_options['github'] = array('GitHub');

return $deploy_options;
}

public function load_deployment_option_template( $templates ) {
$templates[] = __DIR__ . '/../views/github_settings_block.phtml';

return $templates;
}

public function add_deployment_option_keys( $keys ) {
$new_keys = array(
'baseUrl-github',
'ghBranch',
'ghPath',
'ghToken',
'ghRepo',
'ghCommitMessage',
);

$keys = array_merge(
$keys,
$new_keys
);

return $keys;
}

public function whitelist_deployment_option_keys( $keys ) {
$whitelist_keys = array(
'baseUrl-github',
'ghBranch',
'ghPath',
'ghRepo',
'ghCommitMessage',
);

$keys = array_merge(
$keys,
$whitelist_keys
);

return $keys;
}

public function add_post_and_db_keys( $keys ) {
$keys['github'] = array(
'baseUrl-github',
'ghBranch',
'ghPath',
'ghToken',
'ghRepo',
'ghCommitMessage',
);

return $keys;
}

public function run() {
$this->loader->run();

add_filter(
'wp2static_add_deployment_method_option_to_ui',
[$this, 'add_deployment_option_to_ui']
);

add_filter(
'wp2static_load_deploy_option_template',
[$this, 'load_deployment_option_template']
);

add_filter(
'wp2static_add_option_keys',
[$this, 'add_deployment_option_keys']
);

add_filter(
'wp2static_whitelist_option_keys',
[$this, 'whitelist_deployment_option_keys']
);

add_filter(
'wp2static_add_post_and_db_keys',
[$this, 'add_post_and_db_keys']
);
}

public function get_plugin_name() {
return $this->plugin_name;
}

public function get_loader() {
return $this->loader;
}

public function get_version() {
return $this->version;
}
}
31 changes: 31 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Fired when the plugin is uninstalled.
*
* When populating this file, consider the following flow
* of control:
*
* - This method should be static
* - Check if the $_REQUEST content actually is the plugin name
* - Run an admin referrer check to make sure it goes through authentication
* - Verify the output of $_GET makes sense
* - Repeat with other user roles. Best directly by using the links/query string parameters.
* - Repeat things for multisite. Once for a single site in the network, once sitewide.
*
* This file may be updated more in future version of the Boilerplate; however, this is the
* general skeleton and outline for how the file should work.
*
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
* @link https://leonstafford.github.io
* @since 1.0.0
*
* @package Wp2static_Addon_GitHub
*/

// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
66 changes: 66 additions & 0 deletions views/github_settings_block.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div class="github_settings_block" style="display:none;">
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="baseUrl-github"><?php echo __('Destination URL', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'baseUrl-github', 'http://mystaticsite.com', '', ''); ?><br>

<p><i><?php echo __("Set this to the URL you intend to host your static exported site on, ie http://mystaticsite.com. Do not set this to the same URL as the WordPress site you're currently using (the address in your browser above). This plugin will rewrite all URLs in the exported static html from your current WordPress URL to what you set here. Supports http, https and protocol relative URLs.", 'static-html-output-plugin');?></i></p>
</td>
</tr>
<tr>
<th scope="row">
<label for="ghToken"><?php echo __('Personl Access Token', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'ghToken', 'GitHub Personal Access Token', '<a href="https://github.com/settings/tokens/new" target="_blank">How do I get this?</a>', 'password'); ?>
</td>
</tr>
<tr>
<th scope="row">
<label for="ghRepo"><?php echo __('Account & Repository Name', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'ghRepo', 'Account / Repository Name', 'ie, leonstafford/wp2static'); ?><br>

</td>
</tr>
<tr>
<th scope="row">
<label for="ghBranch"><?php echo __('Branch', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'ghBranch', 'Branch', 'usually \'master\' or \'gh-pages\''); ?>
</td>
</tr>
<tr>
<th scope="row">
<label for="ghPath"><?php echo __('Subdirectory', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'ghPath', 'Path within repository', 'Usually the repository root (leave this blank) or the \'doc\' folder'); ?>
</td>
</tr>
<tr>
<th scope="row">
<label for="ghCommitMessage"><?php echo __('Commit message', 'static-html-output-plugin');?></label>
</th>
<td>
<?php $tpl->displayTextfield($this, 'ghCommitMessage', 'WP2Static %ACTION% %FILENAME%', 'Anything you like, with special vars %ACTION% and %FILENAME% available'); ?>

</td>
</tr>
<tr>
<th scope="row">
<label for="gh_test"><?php echo __('Test GitHub Settings', 'static-html-output-plugin');?></label>
</th>
<td>
<button id="github-test-button" type="button" class="btn-primary button">Test GitHub Settings</button>
</td>
</tr>
</tbody>
</table>
</div>
Loading

0 comments on commit e6253cd

Please sign in to comment.