From 2ad2a3c318bac10aaf25f6c2f9ed7dec548e1047 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 11:51:03 -0800 Subject: [PATCH 1/8] add extra headers for compatibility --- includes/class-controller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/class-controller.php b/includes/class-controller.php index 565cebe..2da42d4 100755 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -144,6 +144,8 @@ public function clear_cache_if_debugging() { public function extra_plugin_headers( $headers ) { $headers[] = 'Git URI'; $headers[] = 'Git Branch'; + $headers[] = 'GitHub Plugin URI'; + $headers[] = 'GitHub Branch'; return $headers; } @@ -207,7 +209,7 @@ public function load_plugins( $plugins ) { foreach ( get_plugins() as $slug => $args ) { $args = array_merge( array( 'slug' => $slug ), $args ); - + $plugin = $this->get_plugin_updater_object( $args ); if ( false === $plugin ) { From d8d9fe35212ac7cf2906c6273d988dc70ac7a4ae Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 11:52:03 -0800 Subject: [PATCH 2/8] return proper update URL if $this->branch exists --- includes/class-updater-github.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/class-updater-github.php b/includes/class-updater-github.php index ff3270a..12e44c3 100755 --- a/includes/class-updater-github.php +++ b/includes/class-updater-github.php @@ -114,8 +114,12 @@ protected function get_api_url( $endpoint ) { protected function get_zip_url() { - return 'https://github.com/' . $this->owner . '/' . $this->repository . + if ( ! empty( $this->branch ) ) + return 'https://github.com/' . $this->owner . '/' . $this->repository . '/archive/' . $this->branch . '.zip'; + + return 'https://github.com/' . $this->owner . '/' . $this->repository . + '/archive/master.zip'; } From 4e21edb0f309d3e765831fdccce5040c561c7abd Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 11:53:07 -0800 Subject: [PATCH 3/8] return early for undefined index error --- includes/class-updater.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/class-updater.php b/includes/class-updater.php index 5b7ac1b..bb84565 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -120,6 +120,7 @@ public static function parse_plugin_uri( $plugin ) { $url = parse_url( $plugin['PluginURI'] ); } + if ( empty( $url ) ) return; return $url; } From 1c30fce9071b45eedd80854642c22510f12e7e61 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 11:54:03 -0800 Subject: [PATCH 4/8] read and return 'Git(.*) Branch' header --- includes/class-updater.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/class-updater.php b/includes/class-updater.php index bb84565..fa558a3 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -116,7 +116,7 @@ public static function parse_plugin_uri( $plugin ) { if ( !empty( $plugin['Git URI'] ) ) { $url = parse_url( $plugin['Git URI'] ); - }elseif ( apply_filters( 'gpu_use_plugin_uri_header', false ) ) { + } else { $url = parse_url( $plugin['PluginURI'] ); } @@ -200,6 +200,13 @@ protected function get_default_branch() { return 'master'; } + $content = base64_decode( $response->content ); + + preg_match( '/^[ \t\/*#@]*Git.* Branch\:\s*(.*)$/im', $content, $matches ); + + if ( ! empty( $matches[1] ) ) + return $matches[1]; + // Assuming we've got some remote info, parse the 'url' field to get the last bit of the ref query string $components = parse_url( $response->url, PHP_URL_QUERY ); parse_str( $components ); From 7941333ebac1bca7602d25fb68a02eca490ab7cb Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 13:21:05 -0800 Subject: [PATCH 5/8] spacing fixes --- includes/class-updater-github.php | 2 +- includes/class-updater.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-updater-github.php b/includes/class-updater-github.php index 12e44c3..1050014 100755 --- a/includes/class-updater-github.php +++ b/includes/class-updater-github.php @@ -117,7 +117,7 @@ protected function get_zip_url() { if ( ! empty( $this->branch ) ) return 'https://github.com/' . $this->owner . '/' . $this->repository . '/archive/' . $this->branch . '.zip'; - + return 'https://github.com/' . $this->owner . '/' . $this->repository . '/archive/master.zip'; diff --git a/includes/class-updater.php b/includes/class-updater.php index fa558a3..c46ad09 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -121,6 +121,7 @@ public static function parse_plugin_uri( $plugin ) { } if ( empty( $url ) ) return; + return $url; } From 5159b75c482ee788d3c44398540d7c3fff64bfd6 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 14:10:08 -0800 Subject: [PATCH 6/8] needed to set zip_url --- includes/class-updater-github.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-updater-github.php b/includes/class-updater-github.php index 1050014..492fff3 100755 --- a/includes/class-updater-github.php +++ b/includes/class-updater-github.php @@ -18,7 +18,8 @@ public function __construct( $args ){ parent::__construct( $args ); // Todo: Properly set branch from plugin header - $this->branch = $this->get_default_branch(); + $this->branch = $this->get_default_branch(); + $this->zip_url = $this->get_zip_url(); } /** From 8e028a96ed8472a9ab111b9f89a79fb4aa12803f Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Sun, 10 Nov 2013 15:33:41 -0800 Subject: [PATCH 7/8] get branch from local repo as default --- includes/class-updater-github.php | 3 ++- includes/class-updater.php | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/includes/class-updater-github.php b/includes/class-updater-github.php index 492fff3..87f5f5d 100755 --- a/includes/class-updater-github.php +++ b/includes/class-updater-github.php @@ -18,7 +18,8 @@ public function __construct( $args ){ parent::__construct( $args ); // Todo: Properly set branch from plugin header - $this->branch = $this->get_default_branch(); + $this->default_branch = $this->get_local_branch() ? $this->get_local_branch() : $this->get_default_branch(); + $this->branch = $this->default_branch; $this->zip_url = $this->get_zip_url(); } diff --git a/includes/class-updater.php b/includes/class-updater.php index c46ad09..f3ccc57 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -152,6 +152,26 @@ protected function get_local_version() { return false; } + /** + * Retrieves the local branch from the file header of the plugin + * + * @author Andy Fragen, Codepress + * @link https://github.com/afragen/github-updater + * + * @return string|boolean Version of installed plugin, false if not determined. + */ + protected function get_local_branch() { + $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->slug ); + + if ( ! empty( $data['Git Branch'] ) ) + return $data['Git Branch']; + + if ( ! empty( $data['GitHub Branch'] ) ) + return $data['GitHub Branch']; + + return false; + } + /** * Retrieve the remote version from the file header of the plugin * @@ -201,13 +221,6 @@ protected function get_default_branch() { return 'master'; } - $content = base64_decode( $response->content ); - - preg_match( '/^[ \t\/*#@]*Git.* Branch\:\s*(.*)$/im', $content, $matches ); - - if ( ! empty( $matches[1] ) ) - return $matches[1]; - // Assuming we've got some remote info, parse the 'url' field to get the last bit of the ref query string $components = parse_url( $response->url, PHP_URL_QUERY ); parse_str( $components ); From 8e75b51c93118cc6708a7f95cb8002b1ae192916 Mon Sep 17 00:00:00 2001 From: Andy Fragen Date: Wed, 13 Nov 2013 18:01:10 -0800 Subject: [PATCH 8/8] minor doc fixes for get_local_branch --- includes/class-updater.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-updater.php b/includes/class-updater.php index f3ccc57..d9b0994 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -155,10 +155,10 @@ protected function get_local_version() { /** * Retrieves the local branch from the file header of the plugin * - * @author Andy Fragen, Codepress + * @author Andy Fragen * @link https://github.com/afragen/github-updater * - * @return string|boolean Version of installed plugin, false if not determined. + * @return string|boolean default branch of installed plugin, false if not determined. */ protected function get_local_branch() { $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->slug );