Commit 3699ec82 by pupi1985

Version checks now return JSON

parent ff847ff0
......@@ -149,13 +149,18 @@ function qa_admin_click(target)
function qa_version_check(uri, version, elem, isCore)
{
var params = {uri: uri, version: version, isCore: isCore};
qa_ajax_post(
'version',
{uri: uri, version: version, isCore: isCore},
function (response) {
if (response.result === 'error') {
alert(response.error.message);
qa_ajax_post('version', params,
function(lines) {
if (lines[0] == '1')
document.getElementById(elem).innerHTML = lines[1];
}
return;
}
document.getElementById(elem).innerHTML = response.html;
}, 1
);
}
......
......@@ -23,28 +23,35 @@ require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'app/users.php';
if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) {
echo "QA_AJAX_RESPONSE\n0\n" . qa_lang_html('admin/no_privileges');
$response = array(
'result' => 'error',
'error' => array(
'message' => qa_lang_html('admin/no_privileges'),
),
);
echo json_encode($response);
return;
}
$uri = qa_post_text('uri');
$version = qa_post_text('version');
$isCore = qa_post_text('isCore') === "true";
$isCore = qa_post_text('isCore') === 'true';
if ($isCore) {
$contents = qa_retrieve_url($uri);
if (strlen($contents) > 0) {
if (qa_qa_version_below($contents)) {
$response =
$versionResponse =
'<a href="https://github.com/q2a/question2answer/releases" style="color:#d00;">' .
qa_lang_html_sub('admin/version_get_x', qa_html('v' . $contents)) .
'</a>';
} else {
$response = qa_html($contents); // Output the current version number
$versionResponse = qa_html($contents); // Output the current version number
}
} else {
$response = qa_lang_html('admin/version_latest_unknown');
$versionResponse = qa_lang_html('admin/version_latest_unknown');
}
} else {
$metadataUtil = new Q2A_Util_Metadata();
......@@ -53,28 +60,33 @@ if ($isCore) {
if (strlen(@$metadata['version']) > 0) {
if (strcmp($metadata['version'], $version)) {
if (qa_qa_version_below(@$metadata['min_q2a'])) {
$response = strtr(qa_lang_html('admin/version_requires_q2a'), array(
$versionResponse = 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(
$versionResponse = 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']));
$versionResponse = 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>';
$versionResponse = '<a href="' . qa_html($metadata['uri']) . '" style="color:#d00;">' . $versionResponse . '</a>';
}
}
} else {
$response = qa_lang_html('admin/version_latest');
$versionResponse = qa_lang_html('admin/version_latest');
}
} else {
$response = qa_lang_html('admin/version_latest_unknown');
$versionResponse = qa_lang_html('admin/version_latest_unknown');
}
}
echo "QA_AJAX_RESPONSE\n1\n" . $response;
$response = array(
'result' => 'success',
'html' => $versionResponse,
);
echo json_encode($response);
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