Commit 3973ffd6 by Scott Vivian

Renamed addon metadata function, removed duplicate strings and optimised code

parent dafef9a2
......@@ -134,9 +134,9 @@ function qa_admin_click(target)
return false;
}
function qa_version_check(uri, versionkey, version, urikey, elem)
function qa_version_check(uri, type, version, elem)
{
var params={uri:uri, versionkey:versionkey, version:version, urikey:urikey};
var params={uri:uri, type:type, version:version};
qa_ajax_post('version', params,
function (lines) {
......@@ -144,4 +144,4 @@ function qa_version_check(uri, versionkey, version, urikey, elem)
document.getElementById(elem).innerHTML=lines[1];
}
);
}
\ No newline at end of file
}
......@@ -27,46 +27,42 @@
require_once QA_INCLUDE_DIR.'qa-app-admin.php';
$uri=qa_post_text('uri');
$versionkey=qa_post_text('versionkey');
$urikey=qa_post_text('urikey');
$version=qa_post_text('version');
$uri = qa_post_text('uri');
$type = (qa_post_text('type') === 'Theme' ? 'Theme' : 'Plugin');
$version = qa_post_text('version');
$metadata=qa_admin_addon_metadata(qa_retrieve_url($uri), array(
'version' => $versionkey,
'uri' => $urikey,
// these two elements are only present for plugins, not themes, so we can hard code them here
'min_q2a' => 'Plugin Minimum Question2Answer Version',
'min_php' => 'Plugin Minimum PHP Version',
));
$metadata = qa_addon_metadata(qa_retrieve_url($uri), $type);
if (strlen(@$metadata['version'])) {
if (strcmp($metadata['version'], $version)) {
if (qa_qa_version_below(@$metadata['min_q2a']))
$response=strtr(qa_lang_html('admin/version_requires_q2a'), array(
if (qa_qa_version_below(@$metadata['min_q2a'])) {
$response = strtr(qa_lang_html('admin/version_requires_q2a'), array(
'^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_q2a']),
));
}
elseif (qa_php_version_below(@$metadata['min_php']))
$response=strtr(qa_lang_html('admin/version_requires_php'), array(
elseif (qa_php_version_below(@$metadata['min_php'])) {
$response = strtr(qa_lang_html('admin/version_requires_php'), array(
'^1' => qa_html('v'.$metadata['version']),
'^2' => qa_html($metadata['min_php']),
));
}
else {
$response=qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version']));
$response = qa_lang_html_sub('admin/version_get_x', qa_html('v'.$metadata['version']));
if (strlen(@$metadata['uri']))
$response='<a href="'.qa_html($metadata['uri']).'" style="color:#d00;">'.$response.'</a>';
$response = '<a href="'.qa_html($metadata['uri']).'" style="color:#d00;">'.$response.'</a>';
}
} else
$response=qa_lang_html('admin/version_latest');
}
else
$response = qa_lang_html('admin/version_latest');
} else
$response=qa_lang_html('admin/version_latest_unknown');
}
else
$response = qa_lang_html('admin/version_latest_unknown');
echo "QA_AJAX_RESPONSE\n1\n".$response;
......
......@@ -576,9 +576,12 @@
function qa_admin_addon_metadata($contents, $fields)
/*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, mapping via $fields
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, mapping via $fields.
This function is now DEPRECATED.
*/
{
trigger_error('Function qa_admin_addon_metadata is deprecated; use qa_addon_metadata instead', E_USER_NOTICE);
$metadata=array();
foreach ($fields as $key => $field)
......
......@@ -272,6 +272,38 @@
}
function qa_addon_metadata($contents, $type)
/*
Retrieve metadata information from the $contents of a qa-theme.php or qa-plugin.php file, specified by $type ('Plugin' or 'Theme').
Name, Description, Min Q2A & Min PHP are not currently used by themes.
*/
{
$fields = array(
'name' => 'Name',
'uri' => 'URI',
'description' => 'Description',
'version' => 'Version',
'date' => 'Date',
'author' => 'Author',
'author_uri' => 'Author URI',
'license' => 'License',
'min_q2a' => 'Minimum Question2Answer Version',
'min_php' => 'Minimum PHP Version',
'update' => 'Update Check URI',
);
$metadata = array();
foreach ($fields as $key => $field) {
// prepend 'Theme'/'Plugin' and search for key data
$fieldregex = str_replace(' ', '[ \t]*', preg_quote("$type $field", '/'));
if (preg_match('/'.$fieldregex.':[ \t]*([^\n\f]*)[\n\f]/i', $contents, $matches))
$metadata[$key] = trim($matches[1]);
}
return $metadata;
}
function qa_load_plugin_files()
/*
Load all the qa-plugin.php files from plugins that are compatible with this version of Q2A
......
......@@ -985,21 +985,13 @@
case 'site_theme_mobile':
$themeoptions=qa_admin_theme_options();
if (!isset($themeoptions[$value]))
$value='Classic'; // check here because we also need $value for qa_admin_addon_metadata()
$value='Classic'; // check here because we also need $value for qa_addon_metadata()
qa_optionfield_make_select($optionfield, $themeoptions, $value, 'Classic');
$contents=file_get_contents(QA_THEME_DIR.$value.'/qa-styles.css');
$metadata=qa_admin_addon_metadata($contents, array(
'uri' => 'Theme URI',
'version' => 'Theme Version',
'date' => 'Theme Date',
'author' => 'Theme Author',
'author_uri' => 'Theme Author URI',
'license' => 'Theme License',
'update' => 'Theme Update Check URI',
));
// limit theme parsing to first 8kB
$contents = file_get_contents(QA_THEME_DIR.$value.'/qa-styles.css', false, NULL, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Theme');
if (strlen(@$metadata['version']))
$namehtml='v'.qa_html($metadata['version']);
......@@ -1030,7 +1022,7 @@
$updatehtml='(<span id="'.$elementid.'">...</span>)';
$qa_content['script_onloads'][]=array(
"qa_version_check(".qa_js($metadata['update']).", 'Theme Version', ".qa_js($metadata['version'], true).", 'Theme URI', ".qa_js($elementid).");"
"qa_version_check(".qa_js($metadata['update']).", 'Theme', ".qa_js($metadata['version'], true).", ".qa_js($elementid).");"
);
} else
......
......@@ -107,21 +107,9 @@
$hash=qa_admin_plugin_directory_hash($plugindirectory);
$showthisform=$showpluginforms && (qa_get('show')==$hash);
$contents=file_get_contents($pluginfile);
$metadata=qa_admin_addon_metadata($contents, array(
'name' => 'Plugin Name',
'uri' => 'Plugin URI',
'description' => 'Plugin Description',
'version' => 'Plugin Version',
'date' => 'Plugin Date',
'author' => 'Plugin Author',
'author_uri' => 'Plugin Author URI',
'license' => 'Plugin License',
'min_q2a' => 'Plugin Minimum Question2Answer Version',
'min_php' => 'Plugin Minimum PHP Version',
'update' => 'Plugin Update Check URI',
));
// limit plugin parsing to first 8kB
$contents = file_get_contents($pluginfile, false, NULL, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Plugin');
if (strlen(@$metadata['name']))
$namehtml=qa_html($metadata['name']);
......@@ -153,7 +141,7 @@
$updatehtml='(<span id="'.$elementid.'">...</span>)';
$qa_content['script_onloads'][]=array(
"qa_version_check(".qa_js($metadata['update']).", 'Plugin Version', ".qa_js($metadata['version'], true).", 'Plugin URI', ".qa_js($elementid).");"
"qa_version_check(".qa_js($metadata['update']).", 'Plugin', ".qa_js($metadata['version'], true).", ".qa_js($elementid).");"
);
} else
......
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