Rev 1162 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
307 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
307 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
511 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
730 | daniel-mar | 26 | class OIDplusPluginManifest extends OIDplusBaseClass { |
307 | daniel-mar | 27 | |
1130 | daniel-mar | 28 | /** |
29 | * @var string |
||
30 | */ |
||
632 | daniel-mar | 31 | private $manifestFile = null; |
1130 | daniel-mar | 32 | |
33 | /** |
||
34 | * @var \SimpleXMLElement|null |
||
35 | */ |
||
389 | daniel-mar | 36 | private $rawXML = null; |
37 | |||
1130 | daniel-mar | 38 | // --- All plugins --- |
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
308 | daniel-mar | 43 | private $name = ''; |
1130 | daniel-mar | 44 | |
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
308 | daniel-mar | 48 | private $author = ''; |
1130 | daniel-mar | 49 | |
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
828 | daniel-mar | 53 | private $license = ''; |
1130 | daniel-mar | 54 | |
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
308 | daniel-mar | 58 | private $version = ''; |
1130 | daniel-mar | 59 | |
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
308 | daniel-mar | 63 | private $htmlDescription = ''; |
1130 | daniel-mar | 64 | |
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
308 | daniel-mar | 68 | private $oid = ''; |
307 | daniel-mar | 69 | |
1130 | daniel-mar | 70 | /** |
71 | * @var string |
||
72 | */ |
||
308 | daniel-mar | 73 | private $type = ''; |
1130 | daniel-mar | 74 | |
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
308 | daniel-mar | 78 | private $phpMainClass = ''; |
389 | daniel-mar | 79 | |
1130 | daniel-mar | 80 | // --- Only page or design plugins --- |
81 | |||
82 | /** |
||
83 | * @var array |
||
84 | */ |
||
307 | daniel-mar | 85 | private $cssFiles = array(); |
473 | daniel-mar | 86 | |
1130 | daniel-mar | 87 | // --- Only page plugins --- |
88 | |||
89 | /** |
||
90 | * @var array |
||
91 | */ |
||
307 | daniel-mar | 92 | private $jsFiles = array(); |
93 | |||
1130 | daniel-mar | 94 | // --- Only database plugins --- |
95 | |||
96 | /** |
||
97 | * @var array |
||
98 | */ |
||
411 | daniel-mar | 99 | private $cssFilesSetup = array(); |
1130 | daniel-mar | 100 | |
101 | /** |
||
102 | * @var array |
||
103 | */ |
||
411 | daniel-mar | 104 | private $jsFilesSetup = array(); |
105 | |||
1130 | daniel-mar | 106 | // --- Only language plugins --- |
107 | |||
108 | /** |
||
109 | * @var string |
||
110 | */ |
||
389 | daniel-mar | 111 | private $languageCode = ''; |
1130 | daniel-mar | 112 | |
113 | /** |
||
114 | * @var string |
||
115 | */ |
||
389 | daniel-mar | 116 | private $languageFlag = ''; |
1130 | daniel-mar | 117 | |
118 | /** |
||
119 | * @var string |
||
120 | */ |
||
389 | daniel-mar | 121 | private $languageMessages = ''; |
122 | |||
1130 | daniel-mar | 123 | # ------------- |
124 | |||
1116 | daniel-mar | 125 | /** |
126 | * @return string |
||
127 | */ |
||
308 | daniel-mar | 128 | public function getTypeClass(): string { |
129 | return $this->type; |
||
130 | } |
||
131 | |||
1116 | daniel-mar | 132 | /** |
133 | * @return string |
||
134 | */ |
||
307 | daniel-mar | 135 | public function getName(): string { |
1272 | daniel-mar | 136 | // TODO: Find a way to translate plugin names |
307 | daniel-mar | 137 | return $this->name; |
138 | } |
||
139 | |||
1116 | daniel-mar | 140 | /** |
141 | * @return string |
||
142 | */ |
||
307 | daniel-mar | 143 | public function getAuthor(): string { |
144 | return $this->author; |
||
145 | } |
||
146 | |||
1116 | daniel-mar | 147 | /** |
148 | * @return string |
||
149 | */ |
||
828 | daniel-mar | 150 | public function getLicense(): string { |
151 | return $this->license; |
||
152 | } |
||
153 | |||
1116 | daniel-mar | 154 | /** |
155 | * @return string |
||
156 | */ |
||
307 | daniel-mar | 157 | public function getVersion(): string { |
973 | daniel-mar | 158 | if (str_starts_with($this->oid,'1.3.6.1.4.1.37476.2.5.2.4.') && ($this->version == '')) { |
159 | $sysver = OIDplus::getVersion(); |
||
160 | if ($sysver == '') { |
||
161 | //return _L('Part of OIDplus'); |
||
162 | return 'built-in'; |
||
163 | } else { |
||
164 | //return _L('Part of OIDplus, version %1', $sysver); |
||
1162 | daniel-mar | 165 | return $sysver ?: 'unknown'; |
973 | daniel-mar | 166 | } |
167 | } else { |
||
168 | return $this->version; |
||
169 | } |
||
307 | daniel-mar | 170 | } |
171 | |||
1116 | daniel-mar | 172 | /** |
173 | * @return string |
||
174 | */ |
||
307 | daniel-mar | 175 | public function getHtmlDescription(): string { |
176 | return $this->htmlDescription; |
||
177 | } |
||
178 | |||
1116 | daniel-mar | 179 | /** |
180 | * @return string |
||
181 | */ |
||
308 | daniel-mar | 182 | public function getOid(): string { |
183 | return $this->oid; |
||
184 | } |
||
185 | |||
1116 | daniel-mar | 186 | /** |
187 | * @return string |
||
188 | */ |
||
307 | daniel-mar | 189 | public function getPhpMainClass(): string { |
190 | return $this->phpMainClass; |
||
191 | } |
||
192 | |||
594 | daniel-mar | 193 | /** |
1116 | daniel-mar | 194 | * @return string[] |
594 | daniel-mar | 195 | */ |
307 | daniel-mar | 196 | public function getCSSFiles(): array { |
197 | return $this->cssFiles; |
||
198 | } |
||
199 | |||
594 | daniel-mar | 200 | /** |
1116 | daniel-mar | 201 | * @return string[] |
594 | daniel-mar | 202 | */ |
307 | daniel-mar | 203 | public function getJSFiles(): array { |
204 | return $this->jsFiles; |
||
205 | } |
||
206 | |||
594 | daniel-mar | 207 | /** |
1116 | daniel-mar | 208 | * @return string[] |
594 | daniel-mar | 209 | */ |
411 | daniel-mar | 210 | public function getCSSFilesSetup(): array { |
211 | return $this->cssFilesSetup; |
||
212 | } |
||
213 | |||
594 | daniel-mar | 214 | /** |
1116 | daniel-mar | 215 | * @return string[] |
594 | daniel-mar | 216 | */ |
411 | daniel-mar | 217 | public function getJSFilesSetup(): array { |
218 | return $this->jsFilesSetup; |
||
219 | } |
||
220 | |||
1116 | daniel-mar | 221 | /** |
222 | * @return string |
||
223 | */ |
||
632 | daniel-mar | 224 | public function getManifestFile(): string { |
225 | return $this->manifestFile; |
||
226 | } |
||
227 | |||
1116 | daniel-mar | 228 | /** |
229 | * @return \SimpleXMLElement |
||
230 | */ |
||
1050 | daniel-mar | 231 | public function getRawXml(): \SimpleXMLElement { |
355 | daniel-mar | 232 | return $this->rawXML; |
233 | } |
||
234 | |||
1116 | daniel-mar | 235 | /** |
236 | * @return string |
||
237 | */ |
||
389 | daniel-mar | 238 | public function getLanguageCode(): string { |
239 | return $this->languageCode; |
||
240 | } |
||
241 | |||
1116 | daniel-mar | 242 | /** |
243 | * @return string |
||
244 | */ |
||
389 | daniel-mar | 245 | public function getLanguageFlag(): string { |
246 | return $this->languageFlag; |
||
247 | } |
||
248 | |||
1116 | daniel-mar | 249 | /** |
250 | * @return string |
||
251 | */ |
||
389 | daniel-mar | 252 | public function getLanguageMessages(): string { |
253 | return $this->languageMessages; |
||
254 | } |
||
255 | |||
988 | daniel-mar | 256 | /** |
257 | * Lists all files referenced by the manifest files |
||
258 | * Not included are other files like menu images or other PHP classes |
||
1116 | daniel-mar | 259 | * @return string[] |
260 | * @throws \ReflectionException |
||
988 | daniel-mar | 261 | */ |
262 | public function getManifestLinkedFiles(): array { |
||
263 | $files = array_merge( |
||
264 | $this->getJSFiles(), |
||
265 | $this->getCSSFiles(), |
||
266 | $this->getJSFilesSetup(), |
||
267 | $this->getCSSFilesSetup() |
||
268 | ); |
||
269 | $files[] = $this->getManifestFile(); |
||
270 | $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName(); |
||
271 | sort($files); |
||
272 | return $files; |
||
273 | } |
||
274 | |||
1116 | daniel-mar | 275 | /** |
276 | * @param string $filename |
||
277 | * @return bool |
||
278 | */ |
||
1130 | daniel-mar | 279 | public function loadManifest(string $filename): bool { |
308 | daniel-mar | 280 | if (!file_exists($filename)) return false; |
281 | $xmldata = @simplexml_load_file($filename); |
||
1116 | daniel-mar | 282 | if ($xmldata === false) return false; // TODO: rather throw an Exception and let the method return void only |
307 | daniel-mar | 283 | |
632 | daniel-mar | 284 | $this->manifestFile = $filename; |
389 | daniel-mar | 285 | $this->rawXML = $xmldata; |
286 | |||
287 | // The following attributes are available for every plugin |
||
391 | daniel-mar | 288 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 (page) |
289 | // urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 (language) |
||
290 | // urn:oid:1.3.6.1.4.1.37476.2.5.2.5.5.1 (general) |
||
308 | daniel-mar | 291 | $this->type = (string)$xmldata->type; |
307 | daniel-mar | 292 | |
308 | daniel-mar | 293 | $this->name = (string)$xmldata->info->name; |
294 | $this->author = (string)$xmldata->info->author; |
||
828 | daniel-mar | 295 | $this->license = (string)$xmldata->info->license; |
308 | daniel-mar | 296 | $this->version = (string)$xmldata->info->version; |
297 | $this->htmlDescription = (string)$xmldata->info->descriptionHTML; |
||
298 | $this->oid = (string)$xmldata->info->oid; |
||
307 | daniel-mar | 299 | |
308 | daniel-mar | 300 | $this->phpMainClass = (string)$xmldata->php->mainclass; |
307 | daniel-mar | 301 | |
473 | daniel-mar | 302 | // The following functionalities are only available for page or design plugins |
391 | daniel-mar | 303 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 |
473 | daniel-mar | 304 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1 |
937 | daniel-mar | 305 | foreach ((array)$xmldata->css->file as $css_file) { |
988 | daniel-mar | 306 | $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file; |
429 | daniel-mar | 307 | //if (!file_exists($file)) continue; |
327 | daniel-mar | 308 | $this->cssFiles[] = $file; |
307 | daniel-mar | 309 | } |
473 | daniel-mar | 310 | |
1116 | daniel-mar | 311 | // The following functionalities are only available for page plugins, captcha plugins, and object type plugins |
473 | daniel-mar | 312 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 |
1116 | daniel-mar | 313 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.10.1 |
314 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.12.1 |
||
937 | daniel-mar | 315 | foreach ((array)$xmldata->js->file as $js_file) { |
988 | daniel-mar | 316 | $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file; |
429 | daniel-mar | 317 | //if (!file_exists($file)) continue; |
327 | daniel-mar | 318 | $this->jsFiles[] = $file; |
308 | daniel-mar | 319 | } |
307 | daniel-mar | 320 | |
411 | daniel-mar | 321 | // The following functionalities are only available for database plugins |
322 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.6 |
||
937 | daniel-mar | 323 | foreach ((array)$xmldata->cssSetup->file as $css_file) { |
988 | daniel-mar | 324 | $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file; |
429 | daniel-mar | 325 | //if (!file_exists($file)) continue; |
411 | daniel-mar | 326 | $this->cssFilesSetup[] = $file; |
327 | } |
||
937 | daniel-mar | 328 | foreach ((array)$xmldata->jsSetup->file as $js_file) { |
988 | daniel-mar | 329 | $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file; |
429 | daniel-mar | 330 | //if (!file_exists($file)) continue; |
411 | daniel-mar | 331 | $this->jsFilesSetup[] = $file; |
332 | } |
||
333 | |||
389 | daniel-mar | 334 | // The following functionalities are only available for language plugins |
391 | daniel-mar | 335 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 |
389 | daniel-mar | 336 | $this->languageCode = (string)$xmldata->language->code; |
337 | $this->languageFlag = (string)$xmldata->language->flag; |
||
338 | $this->languageMessages = (string)$xmldata->language->messages; |
||
355 | daniel-mar | 339 | |
307 | daniel-mar | 340 | return true; |
341 | } |
||
342 | |||
343 | } |