Skip to content

Commit 3bad29d

Browse files
committed
Fix the legacy JSON output
Fixes #10
1 parent 8e5998e commit 3bad29d

2 files changed

Lines changed: 31 additions & 36 deletions

File tree

src/templates/forms/misc/json_card_reader.txp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
* <txp:variable name="json-latest-is-beta" /> (set if beta version is a higher semver than stable version)
2323
*/
2424

25+
global $gotFile;
2526
global $json;
2627

2728
$file = 'library-of-plugins/'.parse('<txp:title escape="json" />').'.json';
2829

2930
if (is_readable($file)) {
30-
$json = file_get_contents($file);
31-
$json = json_decode($json);
31+
$gotFile = file_get_contents($file);
32+
$json = json_decode($gotFile);
3233
$vars = array();
3334

3435
if (!empty($json->name)) {

src/templates/pages/plugins.txp

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,6 @@
99
"location": "<txp:variable name="superseded-by-location" escape="json" />"
1010
},
1111
</txp:if_variable>
12-
<txp:php>
13-
global $json;
14-
15-
if (!empty($json->legacy)) {
16-
echo ' "legacy": [';
17-
18-
foreach ($json->legacy as $avail) {
19-
foreach ($avail as $txpver => $legacy) {
20-
$safe_txpver = txpspecialchars($txpver);
21-
$safe_plugver = txpspecialchars($legacy->version);
22-
23-
echo n.' {';
24-
echo n.' "'.$safe_txpver.'": {';
25-
26-
echo n.' "version": "'.$safe_plugver.'",';
27-
28-
if (!empty($legacy->datePublished)) {
29-
echo n.' "datePublished": "'.txpspecialchars($legacy->datePublished).'",';
30-
}
31-
32-
if (!empty($legacy->downloadUrlPhp)) {
33-
echo n.' "endpointUrl": "'.txpspecialchars($legacy->downloadUrlPhp).'"';
34-
} else {
35-
echo n.' "endpointUrl": "'.txpspecialchars($legacy->downloadUrlTxt).'"';
36-
}
37-
38-
echo n.' }';
39-
echo n.' },';
40-
}
41-
}
42-
43-
echo n.' ],';
44-
}
45-
</txp:php>
4612
<txp:if_variable name="json-latest-is-beta">
4713
"beta": {
4814
"version": "<txp:variable name="json-beta-version" escape="json" />",
@@ -68,6 +34,34 @@ if (!empty($json->legacy)) {
6834
<txp:if_variable name="json-beta-php">"endpointUrl": "<txp:variable name="json-beta-php" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-beta-txt" escape="json" />"</txp:if_variable>
6935
}
7036
</txp:if_variable>
37+
<txp:php>
38+
global $gotFile;
39+
global $json;
40+
41+
$json2 = json_decode($gotFile, true);
42+
$newJson = array();
43+
44+
if (!empty($json2['legacy'])) {
45+
foreach ($json2['legacy'] as $txpBlock) {
46+
foreach ($txpBlock as $txpver => $endpointData) {
47+
$newJson['legacy'][$txpver]['version'] = txpspecialchars($endpointData['version']);
48+
49+
if (!empty($endpointData['datePublished'])) {
50+
$newJson['legacy'][$txpver]['datePublished'] = txpspecialchars($endpointData['datePublished']);
51+
}
52+
53+
if (!empty($endpointData['downloadUrlPhp'])) {
54+
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlPhp']);
55+
} elseif (!empty($endPointData['downloadUrlTxt'])) {
56+
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlTxt']);
57+
}
58+
}
59+
}
60+
61+
$out = json_encode($newJson, JSON_PRETTY_PRINT);
62+
echo ','.$out;
63+
}
64+
</txp:php>
7165
}
7266
<txp:else />
7367
<!DOCTYPE html>

0 commit comments

Comments
 (0)