From e7d3e7d4eda4cd98ce0a2d70ee24f62a6d46a74f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Sep 2014 00:57:37 +0200 Subject: [PATCH 1/5] Add support for metainfo about plugin dependencies @see http://wordpress.org/plugins/plugin-dependencies/ @see https://github.com/x-team/wp-plugin-dependencies --- includes/Wpup/Package.php | 7 ++++++- includes/extension-meta/extension-meta.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/includes/Wpup/Package.php b/includes/Wpup/Package.php index 082a928..b2065b7 100644 --- a/includes/Wpup/Package.php +++ b/includes/Wpup/Package.php @@ -138,7 +138,12 @@ public static function extractMetadata($zipFilename){ } if ( !empty($packageInfo['readme']) ){ - $mapping = array('requires', 'tested'); + $mapping = array( + 'requires', + 'tested', + 'depends', + 'provides', + ); foreach($mapping as $readmeField){ if ( !empty($packageInfo['readme'][$readmeField]) ){ $meta[$readmeField] = $packageInfo['readme'][$readmeField]; diff --git a/includes/extension-meta/extension-meta.php b/includes/extension-meta/extension-meta.php index fd30bda..7b12fde 100644 --- a/includes/extension-meta/extension-meta.php +++ b/includes/extension-meta/extension-meta.php @@ -128,6 +128,8 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ 'stable' => '', 'short_description' => '', 'sections' => array(), + 'depends' => array(), + 'provides' => array(), ); //The readme.txt header has a fairly fixed structure, so we can parse it line-by-line @@ -148,6 +150,8 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ 'Requires at least' => 'requires', 'Tested up to' => 'tested', 'Stable tag' => 'stable', + 'Depends' => 'depends', + 'Provides' => 'provides', ); do { //Parse each readme.txt header $pieces = explode(':', array_shift($lines), 2); @@ -170,6 +174,16 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ $headers['tags'] = array_map('trim', explode(',', $headers['tags'])); } + //And for "Depends" + if ( !empty($headers['depends']) ){ + $headers['depends'] = array_map('trim', explode(',', $headers['depends'])); + } + + //As well as for "Provides" + if ( !empty($headers['provides']) ){ + $headers['provides'] = array_map('trim', explode(',', $headers['provides'])); + } + $readme = array_merge($readme, $headers); //After the headers comes the short description From 498ef41229b30d57e2abaa27772e7ebd8252fe53 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 11 Sep 2014 09:46:43 +0200 Subject: [PATCH 2/5] Darn.. let's get the tags from the correct file --- includes/extension-meta/extension-meta.php | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/includes/extension-meta/extension-meta.php b/includes/extension-meta/extension-meta.php index 7b12fde..bf987c2 100644 --- a/includes/extension-meta/extension-meta.php +++ b/includes/extension-meta/extension-meta.php @@ -128,8 +128,6 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ 'stable' => '', 'short_description' => '', 'sections' => array(), - 'depends' => array(), - 'provides' => array(), ); //The readme.txt header has a fairly fixed structure, so we can parse it line-by-line @@ -150,8 +148,6 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ 'Requires at least' => 'requires', 'Tested up to' => 'tested', 'Stable tag' => 'stable', - 'Depends' => 'depends', - 'Provides' => 'provides', ); do { //Parse each readme.txt header $pieces = explode(':', array_shift($lines), 2); @@ -174,16 +170,6 @@ public static function parseReadme($readmeTxtContents, $applyMarkdown = false){ $headers['tags'] = array_map('trim', explode(',', $headers['tags'])); } - //And for "Depends" - if ( !empty($headers['depends']) ){ - $headers['depends'] = array_map('trim', explode(',', $headers['depends'])); - } - - //As well as for "Provides" - if ( !empty($headers['provides']) ){ - $headers['provides'] = array_map('trim', explode(',', $headers['provides'])); - } - $readme = array_merge($readme, $headers); //After the headers comes the short description @@ -276,6 +262,9 @@ public static function getPluginHeaders($fileContents) { 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', 'Network' => 'Network', + 'Depends' => 'Depends', + 'Provides' => 'Provides', + //Site Wide Only is deprecated in favor of Network. '_sitewide' => 'Site Wide Only', ); @@ -291,6 +280,16 @@ public static function getPluginHeaders($fileContents) { //For backward compatibility by default Title is the same as Name. $headers['Title'] = $headers['Name']; + + //"Depends" is a comma-separated list. Convert it to an array. + if ( !empty($headers['depends']) ){ + $headers['depends'] = array_map('trim', explode(',', $headers['depends'])); + } + + //Same for "Provides" + if ( !empty($headers['provides']) ){ + $headers['provides'] = array_map('trim', explode(',', $headers['provides'])); + } //If it doesn't have a name, it's probably not a plugin. if ( empty($headers['Name']) ){ From cc7a6368def5aeff4b228707400ec72da6c1c7d0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 11 Sep 2014 09:50:55 +0200 Subject: [PATCH 3/5] Same for package --- includes/Wpup/Package.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/Wpup/Package.php b/includes/Wpup/Package.php index b2065b7..b324ff8 100644 --- a/includes/Wpup/Package.php +++ b/includes/Wpup/Package.php @@ -122,6 +122,9 @@ public static function extractMetadata($zipFilename){ 'Author' => 'author', 'AuthorURI' => 'author_homepage', 'DetailsURI' => 'details_url', //Only for themes. + 'Depends' => 'depends', // plugin-dependencies plugin + 'Provides' => 'provides', // plugin-dependencies plugin + ); foreach($mapping as $headerField => $metaField){ if ( array_key_exists($headerField, $packageInfo['header']) && !empty($packageInfo['header'][$headerField]) ){ @@ -141,8 +144,6 @@ public static function extractMetadata($zipFilename){ $mapping = array( 'requires', 'tested', - 'depends', - 'provides', ); foreach($mapping as $readmeField){ if ( !empty($packageInfo['readme'][$readmeField]) ){ From a6ae2c940739c8722129800152910a4a129da9dd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 11 Sep 2014 09:53:24 +0200 Subject: [PATCH 4/5] Whitespace --- includes/Wpup/Package.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/Wpup/Package.php b/includes/Wpup/Package.php index b324ff8..809085d 100644 --- a/includes/Wpup/Package.php +++ b/includes/Wpup/Package.php @@ -116,15 +116,14 @@ public static function extractMetadata($zipFilename){ if ( isset($packageInfo['header']) && !empty($packageInfo['header']) ){ $mapping = array( 'Name' => 'name', - 'Version' => 'version', - 'PluginURI' => 'homepage', - 'ThemeURI' => 'homepage', - 'Author' => 'author', - 'AuthorURI' => 'author_homepage', - 'DetailsURI' => 'details_url', //Only for themes. + 'Version' => 'version', + 'PluginURI' => 'homepage', + 'ThemeURI' => 'homepage', + 'Author' => 'author', + 'AuthorURI' => 'author_homepage', + 'DetailsURI' => 'details_url', //Only for themes. 'Depends' => 'depends', // plugin-dependencies plugin 'Provides' => 'provides', // plugin-dependencies plugin - ); foreach($mapping as $headerField => $metaField){ if ( array_key_exists($headerField, $packageInfo['header']) && !empty($packageInfo['header'][$headerField]) ){ From 1f409560ddc33ac1b19cff23619ad95018fc1da7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 11 Sep 2014 09:58:08 +0200 Subject: [PATCH 5/5] Capitalisation --- includes/extension-meta/extension-meta.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/extension-meta/extension-meta.php b/includes/extension-meta/extension-meta.php index bf987c2..f88d165 100644 --- a/includes/extension-meta/extension-meta.php +++ b/includes/extension-meta/extension-meta.php @@ -282,13 +282,13 @@ public static function getPluginHeaders($fileContents) { $headers['Title'] = $headers['Name']; //"Depends" is a comma-separated list. Convert it to an array. - if ( !empty($headers['depends']) ){ - $headers['depends'] = array_map('trim', explode(',', $headers['depends'])); + if ( !empty($headers['Depends']) ){ + $headers['Depends'] = array_map('trim', explode(',', $headers['Depends'])); } //Same for "Provides" - if ( !empty($headers['provides']) ){ - $headers['provides'] = array_map('trim', explode(',', $headers['provides'])); + if ( !empty($headers['Provides']) ){ + $headers['Provides'] = array_map('trim', explode(',', $headers['Provides'])); } //If it doesn't have a name, it's probably not a plugin.