-
Notifications
You must be signed in to change notification settings - Fork 14
/
repository.php
164 lines (140 loc) · 5.52 KB
/
repository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
* DokuWiki plugin/template/popularity data repository API
*
* The API repository.php is (only?) used for the Translation Tool, which just need all extensions
* Filtering does not reduce collection significant for this application, so is skipped since October 2020.
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Håkan Sandell <hakan.sandell@home.se>
*/
use dokuwiki\Cache\Cache;
if (!defined('DOKU_INC')) {
define('DOKU_INC', __DIR__ . '/../../../');
}
require_once(DOKU_INC . 'inc/init.php');
require_once(DOKU_PLUGIN . 'pluginrepo/helper/repository.php');
//close session
session_write_close();
// check cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: application/xml; charset=utf-8');
header('X-Robots-Tag: noindex');
http_conditionalRequest(time());
$string = "pluginrepo";
$cache = new Cache($string, '.xml');
if ($cache->useCache(['age' => 7200])) {
$feed = $cache->retrieveCache();
} else {
// create new feed
$feed = getRepository();
// save cachefile
$cache->storeCache($feed);
}
// finally deliver
echo $feed;
// ---------------------------------------------------------------- //
/**
* Return XML string with repository data, plugin relations (tags, similar, depends)
* are only returned if $opt['plugins'] is used to return named plugins
*
* @return string
*/
function getRepository()
{
$hlp = new helper_plugin_pluginrepo_repository();
$plugins = $hlp->getAllExtensions();
$feed = '<?xml version="1.0" encoding="utf-8"?>';
$feed .= '<repository>';
foreach ($plugins as $plugin) {
$id = hsc($plugin['plugin']);
$feed .= '<plugin>';
$feed .= '<id>' . $id . '</id>';
$feed .= '<dokulink>' . ($plugin['type'] == 32 ? $id : 'plugin:' . $id) . '</dokulink>';
$feed .= '<popularity>' . $plugin['popularity'] . '</popularity>';
$feed .= '<name>' . hsc($plugin['name']) . '</name>';
$feed .= '<description>' . hsc($plugin['description']) . '</description>';
$feed .= '<author>' . hsc($plugin['author']) . '</author>'; // mail not exposed as an anti-spam measure
$feed .= '<type>';
if ($plugin['type']) {
$types = [];
foreach ($hlp->types as $number => $label) {
if ($plugin['type'] & $number) {
$types[] = $label;
}
}
sort($types);
$feed .= implode(', ', $types);
}
$feed .= '</type>';
$feed .= '<lastupdate>' . hsc(str_replace("'", '', $plugin['lastupdate'])) . '</lastupdate>';
if (strpos($plugin['compatible'], 'devel') !== false) {
$feed .= '<develonly>true</develonly>';
}
$feed .= '<compatible>';
$compatibility = $hlp->cleanCompat($plugin['compatible']);
foreach (array_keys($compatibility) as $date) {
$feed .= '<release>' . $date . '</release>';
}
$feed .= '</compatible>';
$feed .= '<updatemessage>' . hsc($plugin['updatemessage']) . '</updatemessage>';
$feed .= '<securityissue>' . hsc($plugin['securityissue']) . '</securityissue>';
$feed .= '<securitywarning>';
if (in_array($plugin['securitywarning'], $hlp->securitywarning)) {
$feed .= $hlp->getLang('security_' . $plugin['securitywarning']);
} else {
$feed .= hsc($plugin['securitywarning']);
}
$feed .= '</securitywarning>';
$feed .= '<tags>';
$tags = $hlp->parsetags($plugin['tags']);
foreach ($tags as $link) {
$feed .= '<tag>' . hsc($link) . '</tag>';
}
$feed .= '</tags>';
if (empty($plugin['screenshot'])) {
$feed .= '<screenshoturl></screenshoturl>';
$feed .= '<thumbnailurl></thumbnailurl>';
} else {
if (!preg_match('/^https?:\/\//', $plugin['screenshot'])) {
$feed .= '<screenshoturl>' . hsc(ml($plugin['screenshot'], [], true, '&', true)) . '</screenshoturl>';
} else {
$feed .= '<screenshoturl>' . hsc($plugin['screenshot']) . '</screenshoturl>';
}
$param = ['cache' => 'cache', 'w' => 120, 'h' => 70];
$feed .= '<thumbnailurl>' . hsc(ml($plugin['screenshot'], $param, true, '&', true)) . '</thumbnailurl>';
}
$feed .= '<downloadurl>' . hsc($plugin['downloadurl']) . '</downloadurl>';
$feed .= '<sourcerepo>' . hsc($plugin['sourcerepo']) . '</sourcerepo>';
$feed .= '<bugtracker>' . hsc($plugin['bugtracker']) . '</bugtracker>';
$feed .= '<donationurl>' . hsc($plugin['donationurl']) . '</donationurl>';
$rel = $hlp->getPluginRelations($id);
$feed .= '<relations>';
$feed .= '<similar>';
if ($rel['similar']) {
foreach ($rel['similar'] as $link) {
$feed .= '<id>' . hsc($link) . '</id>';
}
}
$feed .= '</similar>';
$feed .= '<conflicts>';
if ($rel['conflicts']) {
foreach ($rel['conflicts'] as $link) {
$feed .= '<id>' . hsc($link) . '</id>';
}
}
$feed .= '</conflicts>';
$feed .= '<depends>';
if ($rel['depends']) {
foreach ($rel['depends'] as $link) {
$feed .= '<id>' . hsc($link) . '</id>';
}
}
$feed .= '</depends>';
$feed .= '</relations>';
$feed .= '</plugin>';
}
$feed .= '</repository>';
return $feed;
}