Skip to content

Commit

Permalink
Merge branch 'install-zipfile' into develop
Browse files Browse the repository at this point in the history
Fixes #713
Fixes #712
Related cedaro/satispress#76
  • Loading branch information
afragen committed Sep 7, 2018
2 parents d3646dc + 2bfb390 commit 2af9c54
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* fixed to only load `Settings` on appropriate pages, fixes [#711](https://github.com/afragen/github-updater/issues/711)
* fixed issue where saving options during background updating could cause some checkbox options to be cleared, [5d68ea5](https://github.com/afragen/github-updater/commit/5d68ea54385a2fe62093e25ef42672bbfd504f89)
* updated error handling of Singleton factory
* added remote install from a zipfile, remote URL or local file

#### 8.2.1 / 2018-07-22
* fixed setting of `Requires PHP` header in `API::set_readme_info()`
Expand Down
2 changes: 1 addition & 1 deletion github-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin Name: GitHub Updater
* Plugin URI: https://github.com/afragen/github-updater
* Description: A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs. It also allows for remote installation of plugins or themes into WordPress.
* Version: 8.2.1.9
* Version: 8.2.1.10

This comment has been minimized.

Copy link
@GaryJones

GaryJones Sep 8, 2018

Contributor

This seems like a new feature, and yet it only has a smaller-than-minor version bump?

This comment has been minimized.

Copy link
@afragen

afragen Sep 8, 2018

Author Owner

The version bump will be to 8.3.0 when released. I only bump development versions in the last place so anyone on the develop branch gets an update and I don’t accidentally screw up my versioning. 😉

* Author: Andy Fragen
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
4 changes: 2 additions & 2 deletions js/ghu-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jQuery( document ).ready(
function ($) {
// Hide non-default (Bitbucket & GitLab) settings on page load.
$.each(
['bitbucket', 'gitlab', 'gitea'], function () {
['bitbucket', 'gitlab', 'gitea', 'zipfile'], function () {
$( 'input.'.concat( this, '_setting' ) ).parents( 'tr' ).hide();
}
);
Expand All @@ -22,7 +22,7 @@ jQuery( document ).ready(
'change', function () {

// create difference array.
var hideMe = $( ['github', 'bitbucket', 'gitlab', 'gitea'] ).not( [this.value] ).get();
var hideMe = $( ['github', 'bitbucket', 'gitlab', 'gitea', 'zipfile'] ).not( [this.value] ).get();

/*
* Show/hide all settings that have the selected api's class.
Expand Down
73 changes: 73 additions & 0 deletions src/GitHub_Updater/API/Zipfile_API.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* GitHub Updater
*
* @author Andy Fragen
* @license GPL-2.0+
* @link https://github.com/afragen/github-updater
* @package github-updater
*/

namespace Fragen\GitHub_Updater\API;

/*
* Exit if called directly.
*/
if ( ! defined( 'WPINC' ) ) {
die;
}

/**
* Class Zipfile_API
*
* Remote install from a Zipfile.
*
* @author Andy Fragen
*/
class Zipfile_API {

/**
* Add remote install settings fields.
*
* @param $type
*/
public function add_install_settings_fields( $type ) {
add_settings_field(
'zipfile_slug',
esc_html__( 'Zipfile Slug', 'github-updater' ),
[ $this, 'zipfile_slug' ],
'github_updater_install_' . $type,
$type
);
}

/**
* Set repo slug for remote install.
*/
public function zipfile_slug() {
?>
<label for="zipfile_slug">
<input class="zipfile_setting" type="text" style="width:50%;" name="zipfile_slug" value="" placeholder="my-repo-slug">
<br>
<span class="description">
<?php esc_html_e( 'Enter plugin or theme slug.', 'github-updater' ); ?>
</span>
</label>
<?php
}

/**
* Add remote install feature, create endpoint.
*
* @param $headers
* @param $install
*
* @return mixed $install
*/
public function remote_install( $headers, $install ) {
$install['download_link'] = ! empty( $headers['uri'] ) ? $headers['uri'] : $headers['original'];
$install['github_updater_install_repo'] = $install['zipfile_slug'];

return $install;
}
}
7 changes: 7 additions & 0 deletions src/GitHub_Updater/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ protected function set_installed_apis() {
} else {
self::$installed_apis['gitea_api'] = false;
}
if ( file_exists( __DIR__ . '/API/Zipfile_API.php' ) ) {
self::$installed_apis['zipfile_api'] = true;
self::$git_servers['zipfile'] = 'Zipfile';

} else {
self::$installed_apis['zipfile_api'] = false;
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/GitHub_Updater/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public function install( $type, $config = null ) {
}
}

/*
* Install from Zipfile.
*/
if ( 'zipfile' === self::$install['github_updater_api'] ) {
self::$install = Singleton::get_instance( 'API\Zipfile_API', $this )->remote_install( $headers, self::$install );
}

if ( isset( self::$install['options'] ) ) {
$this->save_options_on_install( self::$install['options'] );
}
Expand Down Expand Up @@ -277,6 +284,9 @@ private function set_install_post_data( $config ) {
case 'gitea':
$_POST['gitea_access_token'] = $config['private'] ?: null;
break;
case 'zipfile':
$_POST['zipfile_slug'] = $config['slug'];
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/GitHub_Updater/Traits/GHU_Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function ( $e ) {
protected function parse_header_uri( $repo_header ) {
$header_parts = parse_url( $repo_header );
$header_path = pathinfo( $header_parts['path'] );
$header['original'] = $repo_header;
$header['scheme'] = isset( $header_parts['scheme'] ) ? $header_parts['scheme'] : null;
$header['host'] = isset( $header_parts['host'] ) ? $header_parts['host'] : null;
$header['owner'] = trim( $header_path['dirname'], '/' );
Expand Down
22 changes: 19 additions & 3 deletions src/GitHub_Updater/WP_CLI/CLI_Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function init_themes() {
* [--bitbucket-private]
* : Indicates a private Bitbucket repository
*
* [--slug=<slug>]
* : Optional string indicating the plugin slug
* [--github]
* : Optional to denote a GitHub repository
* Required when installing from a self-hosted GitHub installation
Expand All @@ -100,6 +103,10 @@ public function init_themes() {
* : Optional switch to denote a Gitea repository
* Required when installing from a Gitea installation
*
* [--zipfile]
* : Optional switch to denote a Zipfile
* Required when installing from a Zipfile
*
* ## EXAMPLES
*
* wp plugin install-git https://github.com/afragen/my-plugin
Expand Down Expand Up @@ -146,6 +153,9 @@ public function install_plugin( $args, $assoc_args ) {
* [--bitbucket-private]
* : Indicates a private Bitbucket repository
*
* [--slug=<slug>]
* : Optional string indicating the theme slug
*
* [--github]
* : Optional to denote a GitHub repository
* Required when installing from a self-hosted GitHub installation
Expand All @@ -162,6 +172,10 @@ public function install_plugin( $args, $assoc_args ) {
* : Optional switch to denote a Gitea repository
* Required when installing from a Gitea installation
*
* [--zipfile]
* : Optional switch to denote a Zipfile
* Required when installing from a Zipfile
*
* ## EXAMPLES
*
* wp theme install-git https://github.com/afragen/my-theme
Expand Down Expand Up @@ -202,9 +216,8 @@ private function process_args( $uri, $assoc_args ) {
$cli_config = [];
$cli_config['uri'] = $uri;
$cli_config['private'] = $token ?: $bitbucket_private;
$cli_config['branch'] = isset( $assoc_args['branch'] )
? $assoc_args['branch']
: 'master';
$cli_config['branch'] = isset( $assoc_args['branch'] ) ? $assoc_args['branch'] : 'master';
$cli_config['slug'] = isset( $assoc_args['slug'] ) ? $assoc_args['slug'] : null;

switch ( $assoc_args ) {
case isset( $assoc_args['github'] ):
Expand All @@ -219,6 +232,9 @@ private function process_args( $uri, $assoc_args ) {
case isset( $assoc_args['gitea'] ):
$cli_config['git'] = 'gitea';
break;
case isset( $assoc_args['zipfile'] ):
$cli_config['git'] = 'zipfile';
break;
}

return $cli_config;
Expand Down

0 comments on commit 2af9c54

Please sign in to comment.