Skip to content

Commit 3aeaa9a

Browse files
committed
Add support for /all plugins JSON feed
1 parent f4c8c95 commit 3aeaa9a

4 files changed

Lines changed: 104 additions & 76 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "<txp:article_url_title escape="json" />",
3+
<txp:if_variable name="json-require-plugin">
4+
"require": {
5+
"<txp:variable name="json-require-plugin" escape="json" />": "<txp:if_variable name="json-require-match" value="greater than">></txp:if_variable><txp:if_variable name="json-require-match" value="at least">>=</txp:if_variable><txp:if_variable name="json-require-match" value="less than"><</txp:if_variable><txp:if_variable name="json-require-match" value="no greater than"><=</txp:if_variable><txp:if_variable name="json-require-match" value="equal">=</txp:if_variable><txp:variable name="json-require-version" escape="json" />"
6+
},
7+
</txp:if_variable>
8+
<txp:if_variable name="superseded-by-type">
9+
"supersededBy": {
10+
"name": "<txp:variable name="superseded-by-type" escape="json" />",
11+
"location": "<txp:variable name="superseded-by-location" escape="json" />"
12+
},
13+
</txp:if_variable>
14+
<txp:if_variable name="json-latest-is-beta">
15+
"beta": {
16+
"version": "<txp:variable name="json-beta-version" escape="json" />",
17+
<txp:if_variable name="json-beta-manifest">"phpHasManifest": 1,</txp:if_variable>
18+
<txp:if_custom_field name="max-txp-version-verified-beta">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified-beta" escape="json" />",</txp:if_custom_field>
19+
<txp:if_variable name="json-beta-date">"datePublished": "<txp:variable name="json-beta-date" escape="json" />",</txp:if_variable>
20+
<txp:if_variable name="json-beta-txt">"endpointUrl": "<txp:variable name="json-beta-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-beta-php" escape="json" />"</txp:if_variable>
21+
},
22+
</txp:if_variable>
23+
<txp:if_variable name="json-stable-version">
24+
"stable": {
25+
"version": "<txp:variable name="json-stable-version" escape="json" />",
26+
<txp:if_variable name="json-stable-manifest">"phpHasManifest": 1,</txp:if_variable>
27+
<txp:if_custom_field name="max-txp-version-verified">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified" escape="json" />",</txp:if_custom_field>
28+
<txp:if_custom_field name="min-txp-version-verified">"verifiedMinTxpCompatibility": "<txp:custom_field name="min-txp-version-verified" escape="json" />",</txp:if_custom_field>
29+
<txp:if_variable name="json-stable-date">"datePublished": "<txp:variable name="json-stable-date" escape="json" />",</txp:if_variable>
30+
<txp:if_variable name="json-stable-txt">"endpointUrl": "<txp:variable name="json-stable-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-stable-php" escape="json" />"</txp:if_variable>
31+
}
32+
<txp:else />
33+
"beta": {
34+
"version": "<txp:variable name="json-beta-version" escape="json" />",
35+
<txp:if_variable name="json-beta-manifest">"phpHasManifest": 1,</txp:if_variable>
36+
<txp:if_custom_field name="max-txp-version-verified-beta">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified-beta" escape="json" />",</txp:if_custom_field>
37+
<txp:if_custom_field name="min-txp-version-verified">"verifiedMinTxpCompatibility": "<txp:custom_field name="min-txp-version-verified" escape="json" />",</txp:if_custom_field>
38+
<txp:if_variable name="json-beta-date">"datePublished": "<txp:variable name="json-beta-date" escape="json" />",</txp:if_variable>
39+
<txp:if_variable name="json-beta-txt">"endpointUrl": "<txp:variable name="json-beta-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-beta-php" escape="json" />"</txp:if_variable>
40+
}
41+
</txp:if_variable>
42+
<txp:php>
43+
global $gotFile;
44+
global $json;
45+
46+
$json2 = json_decode($gotFile, true);
47+
$newJson = array();
48+
49+
if (!empty($json2['legacy'])) {
50+
foreach ($json2['legacy'] as $txpBlock) {
51+
foreach ($txpBlock as $txpver => $endpointData) {
52+
$newJson['legacy'][$txpver]['version'] = txpspecialchars($endpointData['version']);
53+
54+
if (!empty($endpointData['phpHasManifest'])) {
55+
if ($endpointData['phpHasManifest'] = 1) {
56+
$newJson['legacy'][$txpver]['phpHasManifest'] = txpspecialchars($endpointData['phpHasManifest']);
57+
}
58+
}
59+
60+
if (!empty($endpointData['datePublished'])) {
61+
$newJson['legacy'][$txpver]['datePublished'] = txpspecialchars($endpointData['datePublished']);
62+
}
63+
64+
if (!empty($endpointData['downloadUrlTxt'])) {
65+
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlTxt']);
66+
} elseif (!empty($endPointData['downloadUrlPhp'])) {
67+
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlPhp']);
68+
}
69+
}
70+
}
71+
72+
$out = json_encode($newJson, JSON_PRETTY_PRINT);
73+
echo ' ,'.trim($out, '{..}');
74+
}
75+
</txp:php>
76+
}

src/templates/forms/misc/json_card_reader.txp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* <txp:variable name="json-stable-php" /> (URL of latest PHP download stable release)
2626
* <txp:variable name="json-stable-txt" /> (URL of latest TXT download stable release)
2727
* <txp:variable name="json-latest-is-beta" /> (set if beta version is a higher semver than stable version)
28+
* <txp:variable name="superseded-by-type" /> (plugin replaced by different plugin or core functionality)
2829
*/
2930

3031
global $gotFile;

src/templates/pages/all.txp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<txp:hide>Initialize all variables so they don't hang around after each article</txp:hide>
2+
<txp:variable name="json-repo-XXX" reset output="" />
3+
<txp:variable name="json-require-plugin" reset output="" />
4+
<txp:variable name="json-require-match" reset output="" />
5+
<txp:variable name="json-require-version" reset output="" />
6+
<txp:variable name="json-beta-version" reset output="" />
7+
<txp:variable name="json-beta-manifest" reset output="" />
8+
<txp:variable name="json-beta-date" reset output="" />
9+
<txp:variable name="json-beta-php" reset output="" />
10+
<txp:variable name="json-beta-txt" reset output="" />
11+
<txp:variable name="json-stable-version" reset output="" />
12+
<txp:variable name="json-stable-manifest" reset output="" />
13+
<txp:variable name="json-stable-date" reset output="" />
14+
<txp:variable name="json-stable-php" reset output="" />
15+
<txp:variable name="json-stable-txt" reset output="" />
16+
<txp:variable name="json-latest-is-beta" reset output="" />
17+
<txp:variable name="superseded-by-type" reset output="" />
18+
19+
<txp:header name="Content-Type" value="application/json; charset=utf-8" />
20+
{"all_txp_plugins": [
21+
<article::custom section="plugins" limit="0" sort="title">
22+
<txp:output_form form="json_card_reader" />
23+
<txp:output_form form="json_card" />
24+
<if::last_article not>,</if::last_article>
25+
</article::custom>
26+
]}

src/templates/pages/plugins.txp

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,7 @@
11
<txp:evaluate query='"<txp:page_url type="3" />" = "json"'>
22
<txp:output_form form="json_card_reader" />
33
<txp:variable name="body"><txp:article><txp:body /></txp:article></txp:variable>
4-
<txp:header name="Content-Type" value="application/json; charset=utf-8" />{
5-
"name": "<txp:article_url_title escape="json" />",
6-
<txp:if_variable name="json-require-plugin">
7-
"require": {
8-
"<txp:variable name="json-require-plugin" escape="json" />": "<txp:if_variable name="json-require-match" value="greater than">></txp:if_variable><txp:if_variable name="json-require-match" value="at least">>=</txp:if_variable><txp:if_variable name="json-require-match" value="less than"><</txp:if_variable><txp:if_variable name="json-require-match" value="no greater than"><=</txp:if_variable><txp:if_variable name="json-require-match" value="equal">=</txp:if_variable><txp:variable name="json-require-version" escape="json" />"
9-
},
10-
</txp:if_variable>
11-
<txp:if_variable name="superseded-by-type">
12-
"supersededBy": {
13-
"name": "<txp:variable name="superseded-by-type" escape="json" />",
14-
"location": "<txp:variable name="superseded-by-location" escape="json" />"
15-
},
16-
</txp:if_variable>
17-
<txp:if_variable name="json-latest-is-beta">
18-
"beta": {
19-
"version": "<txp:variable name="json-beta-version" escape="json" />",
20-
<txp:if_variable name="json-beta-manifest">"phpHasManifest": 1,</txp:if_variable>
21-
<txp:if_custom_field name="max-txp-version-verified-beta">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified-beta" escape="json" />",</txp:if_custom_field>
22-
<txp:if_variable name="json-beta-date">"datePublished": "<txp:variable name="json-beta-date" escape="json" />",</txp:if_variable>
23-
<txp:if_variable name="json-beta-txt">"endpointUrl": "<txp:variable name="json-beta-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-beta-php" escape="json" />"</txp:if_variable>
24-
},
25-
</txp:if_variable>
26-
<txp:if_variable name="json-stable-version">
27-
"stable": {
28-
"version": "<txp:variable name="json-stable-version" escape="json" />",
29-
<txp:if_variable name="json-stable-manifest">"phpHasManifest": 1,</txp:if_variable>
30-
<txp:if_custom_field name="max-txp-version-verified">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified" escape="json" />",</txp:if_custom_field>
31-
<txp:if_custom_field name="min-txp-version-verified">"verifiedMinTxpCompatibility": "<txp:custom_field name="min-txp-version-verified" escape="json" />",</txp:if_custom_field>
32-
<txp:if_variable name="json-stable-date">"datePublished": "<txp:variable name="json-stable-date" escape="json" />",</txp:if_variable>
33-
<txp:if_variable name="json-stable-txt">"endpointUrl": "<txp:variable name="json-stable-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-stable-php" escape="json" />"</txp:if_variable>
34-
}
35-
<txp:else />
36-
"beta": {
37-
"version": "<txp:variable name="json-beta-version" escape="json" />",
38-
<txp:if_variable name="json-beta-manifest">"phpHasManifest": 1,</txp:if_variable>
39-
<txp:if_custom_field name="max-txp-version-verified-beta">"verifiedMaxTxpCompatibility": "<txp:custom_field name="max-txp-version-verified-beta" escape="json" />",</txp:if_custom_field>
40-
<txp:if_custom_field name="min-txp-version-verified">"verifiedMinTxpCompatibility": "<txp:custom_field name="min-txp-version-verified" escape="json" />",</txp:if_custom_field>
41-
<txp:if_variable name="json-beta-date">"datePublished": "<txp:variable name="json-beta-date" escape="json" />",</txp:if_variable>
42-
<txp:if_variable name="json-beta-txt">"endpointUrl": "<txp:variable name="json-beta-txt" escape="json" />"<txp:else />"endpointUrl": "<txp:variable name="json-beta-php" escape="json" />"</txp:if_variable>
43-
}
44-
</txp:if_variable>
45-
<txp:php>
46-
global $gotFile;
47-
global $json;
48-
49-
$json2 = json_decode($gotFile, true);
50-
$newJson = array();
51-
52-
if (!empty($json2['legacy'])) {
53-
foreach ($json2['legacy'] as $txpBlock) {
54-
foreach ($txpBlock as $txpver => $endpointData) {
55-
$newJson['legacy'][$txpver]['version'] = txpspecialchars($endpointData['version']);
56-
57-
if (!empty($endpointData['phpHasManifest'])) {
58-
if ($endpointData['phpHasManifest'] = 1) {
59-
$newJson['legacy'][$txpver]['phpHasManifest'] = txpspecialchars($endpointData['phpHasManifest']);
60-
}
61-
}
62-
63-
if (!empty($endpointData['datePublished'])) {
64-
$newJson['legacy'][$txpver]['datePublished'] = txpspecialchars($endpointData['datePublished']);
65-
}
66-
67-
if (!empty($endpointData['downloadUrlTxt'])) {
68-
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlTxt']);
69-
} elseif (!empty($endPointData['downloadUrlPhp'])) {
70-
$newJson['legacy'][$txpver]['endpointUrl'] = txpspecialchars($endpointData['downloadUrlPhp']);
71-
}
72-
}
73-
}
74-
75-
$out = json_encode($newJson, JSON_PRETTY_PRINT);
76-
echo ' ,'.trim($out, '{..}');
77-
}
78-
</txp:php>
79-
}
4+
<txp:header name="Content-Type" value="application/json; charset=utf-8" /><txp:output_form form="json_card" />
805
<txp:else />
816
<!DOCTYPE html>
827
<html lang="en-GB-oxendict">

0 commit comments

Comments
 (0)