From dcc817106aca1ab9a3d805228311231b122f2792 Mon Sep 17 00:00:00 2001 From: Richard Coffee Date: Sun, 29 Mar 2020 14:25:16 -0400 Subject: [PATCH 1/3] add updateChecker and getServiceURI methods --- Puc/v4p9/Factory.php | 61 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Puc/v4p9/Factory.php b/Puc/v4p9/Factory.php index de6f7f7..9fd1cd9 100644 --- a/Puc/v4p9/Factory.php +++ b/Puc/v4p9/Factory.php @@ -18,6 +18,34 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): protected static $myMajorVersion = ''; protected static $latestCompatibleVersion = ''; + /** + * Wrapper method for buildUpdateChecker. + * + * @param string $fullPath + * @param array + */ + public static function updateChecker( $fullPath, $args = array() ) { + $fullPath = self::normalizePath( $fullPath ); + + //Set up defaults. + $defaults = array( + 'metadataUrl' => '', + 'slug' => '', + 'checkPeriod' => 12, + 'optionName' => '', + 'muPluginFile' => '', + ); + $args = array_merge( $defaults, array_intersect_key( $args, $defaults ) ); + extract( $args ); + + //Check for the service URI + if ( empty( $metadataUrl ) ) { + $metadataUrl = self::getServiceURI( $fullPath ); + } + + return self::buildUpdateChecker( $metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile ); + } + /** * Create a new instance of the update checker. * @@ -178,6 +206,37 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): return null; } + /** + * Get the service URI from the file header. + * + * @param string $fullPath + * @return string + */ + private static function getServiceURI( $fullPath ) { + //Look for the URI + if ( is_readable( $fullPath ) ) { + $seek = array( + 'github' => 'GitHub URI', + 'gitlab' => 'GitLab URI', + 'bucket' => 'BitBucket URI' + ); + $seek = apply_filters( 'puc_get_source_uri', $seek ); + $data = get_file_data( $fullPath, $seek ); + foreach( $seek as $key => $uri ) { + if ( $uri ) return $uri; + } + } + + //URI was not found so trigger an error. + trigger_error( + sprintf( + 'Unable to locate uri in header of "%s"', + htmlentities( $fullPath ) + ), + E_USER_ERROR + ); + } + /** * Get the name of the hosting service that the URL points to. * @@ -294,4 +353,4 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): } } -endif; \ No newline at end of file +endif; From e61f3f5cba1231cbd3f7710c2360fe05d1abe0fb Mon Sep 17 00:00:00 2001 From: Richard Coffee Date: Sun, 29 Mar 2020 15:29:23 -0400 Subject: [PATCH 2/3] Fix logic error --- Puc/v4p9/Factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Puc/v4p9/Factory.php b/Puc/v4p9/Factory.php index 9fd1cd9..77b0afa 100644 --- a/Puc/v4p9/Factory.php +++ b/Puc/v4p9/Factory.php @@ -222,7 +222,7 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): ); $seek = apply_filters( 'puc_get_source_uri', $seek ); $data = get_file_data( $fullPath, $seek ); - foreach( $seek as $key => $uri ) { + foreach( $data as $key => $uri ) { if ( $uri ) return $uri; } } From b2ca059c05c41c00d769a4c77c6ba9aad85992f9 Mon Sep 17 00:00:00 2001 From: Richard Coffee Date: Mon, 30 Mar 2020 15:15:35 -0400 Subject: [PATCH 3/3] change method name, add EXTR_SKIP to extract call --- Puc/v4p9/Factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Puc/v4p9/Factory.php b/Puc/v4p9/Factory.php index 77b0afa..ddcbf1c 100644 --- a/Puc/v4p9/Factory.php +++ b/Puc/v4p9/Factory.php @@ -24,7 +24,7 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): * @param string $fullPath * @param array */ - public static function updateChecker( $fullPath, $args = array() ) { + public static function buildFromHeader( $fullPath, $args = array() ) { $fullPath = self::normalizePath( $fullPath ); //Set up defaults. @@ -36,7 +36,7 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): 'muPluginFile' => '', ); $args = array_merge( $defaults, array_intersect_key( $args, $defaults ) ); - extract( $args ); + extract( $args, EXTR_SKIP ); //Check for the service URI if ( empty( $metadataUrl ) ) {