Commit bf4007d6 by Scott Vivian

Small optimization for qa_addon_metadata

parent 4aef3f2c
...@@ -272,13 +272,19 @@ ...@@ -272,13 +272,19 @@
} }
function qa_addon_metadata($contents, $type) function qa_addon_metadata($contents, $type, $versiononly=false)
/* /*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme'). Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme').
If $versiononly is true, only version metadata is parsed.
Name, Description, Min Q2A & Min PHP are not currently used by themes. Name, Description, Min Q2A & Min PHP are not currently used by themes.
*/ */
{ {
$fields = array( $fields = array(
'min_q2a' => 'Minimum Question2Answer Version',
'min_php' => 'Minimum PHP Version',
);
if (!$versiononly) {
$fields = array_merge($fields, $fields = array(
'name' => 'Name', 'name' => 'Name',
'uri' => 'URI', 'uri' => 'URI',
'description' => 'Description', 'description' => 'Description',
...@@ -287,12 +293,11 @@ ...@@ -287,12 +293,11 @@
'author' => 'Author', 'author' => 'Author',
'author_uri' => 'Author URI', 'author_uri' => 'Author URI',
'license' => 'License', 'license' => 'License',
'min_q2a' => 'Minimum Question2Answer Version',
'min_php' => 'Minimum PHP Version',
'update' => 'Update Check URI', 'update' => 'Update Check URI',
); ));
$metadata = array(); }
$metadata = array();
foreach ($fields as $key => $field) { foreach ($fields as $key => $field) {
// prepend 'Theme'/'Plugin' and search for key data // prepend 'Theme'/'Plugin' and search for key data
$fieldregex = str_replace(' ', '[ \t]*', preg_quote("$type $field", '/')); $fieldregex = str_replace(' ', '[ \t]*', preg_quote("$type $field", '/'));
...@@ -316,7 +321,7 @@ ...@@ -316,7 +321,7 @@
foreach ($pluginfiles as $pluginfile) { foreach ($pluginfiles as $pluginfile) {
// limit plugin parsing to first 8kB // limit plugin parsing to first 8kB
$contents = file_get_contents($pluginfile, false, NULL, -1, 8192); $contents = file_get_contents($pluginfile, false, NULL, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Plugin'); $metadata = qa_addon_metadata($contents, 'Plugin', true);
// skip plugin which requires a later version of Q2A // skip plugin which requires a later version of Q2A
if (isset($metadata['min_q2a']) && qa_qa_version_below($metadata['min_q2a'])) if (isset($metadata['min_q2a']) && qa_qa_version_below($metadata['min_q2a']))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment