diff --git a/Puc/v4p9/Factory.php b/Puc/v4p9/Factory.php index de6f7f7..ddcbf1c 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 buildFromHeader( $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, EXTR_SKIP ); + + //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( $data 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;