Rev 1116 | Rev 1143 | Go to most recent revision | 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 { |
136 | return $this->name; |
||
137 | } |
||
138 | |||
1116 | daniel-mar | 139 | /** |
140 | * @return string |
||
141 | */ |
||
307 | daniel-mar | 142 | public function getAuthor(): string { |
143 | return $this->author; |
||
144 | } |
||
145 | |||
1116 | daniel-mar | 146 | /** |
147 | * @return string |
||
148 | */ |
||
828 | daniel-mar | 149 | public function getLicense(): string { |
150 | return $this->license; |
||
151 | } |
||
152 | |||
1116 | daniel-mar | 153 | /** |
154 | * @return string |
||
155 | */ |
||
307 | daniel-mar | 156 | public function getVersion(): string { |
973 | daniel-mar | 157 | if (str_starts_with($this->oid,'1.3.6.1.4.1.37476.2.5.2.4.') && ($this->version == '')) { |
158 | $sysver = OIDplus::getVersion(); |
||
159 | if ($sysver == '') { |
||
160 | //return _L('Part of OIDplus'); |
||
161 | return 'built-in'; |
||
162 | } else { |
||
163 | //return _L('Part of OIDplus, version %1', $sysver); |
||
164 | return $sysver; |
||
165 | } |
||
166 | } else { |
||
167 | return $this->version; |
||
168 | } |
||
307 | daniel-mar | 169 | } |
170 | |||
1116 | daniel-mar | 171 | /** |
172 | * @return string |
||
173 | */ |
||
307 | daniel-mar | 174 | public function getHtmlDescription(): string { |
175 | return $this->htmlDescription; |
||
176 | } |
||
177 | |||
1116 | daniel-mar | 178 | /** |
179 | * @return string |
||
180 | */ |
||
308 | daniel-mar | 181 | public function getOid(): string { |
182 | return $this->oid; |
||
183 | } |
||
184 | |||
1116 | daniel-mar | 185 | /** |
186 | * @return string |
||
187 | */ |
||
307 | daniel-mar | 188 | public function getPhpMainClass(): string { |
189 | return $this->phpMainClass; |
||
190 | } |
||
191 | |||
594 | daniel-mar | 192 | /** |
1116 | daniel-mar | 193 | * @return string[] |
594 | daniel-mar | 194 | */ |
307 | daniel-mar | 195 | public function getCSSFiles(): array { |
196 | return $this->cssFiles; |
||
197 | } |
||
198 | |||
594 | daniel-mar | 199 | /** |
1116 | daniel-mar | 200 | * @return string[] |
594 | daniel-mar | 201 | */ |
307 | daniel-mar | 202 | public function getJSFiles(): array { |
203 | return $this->jsFiles; |
||
204 | } |
||
205 | |||
594 | daniel-mar | 206 | /** |
1116 | daniel-mar | 207 | * @return string[] |
594 | daniel-mar | 208 | */ |
411 | daniel-mar | 209 | public function getCSSFilesSetup(): array { |
210 | return $this->cssFilesSetup; |
||
211 | } |
||
212 | |||
594 | daniel-mar | 213 | /** |
1116 | daniel-mar | 214 | * @return string[] |
594 | daniel-mar | 215 | */ |
411 | daniel-mar | 216 | public function getJSFilesSetup(): array { |
217 | return $this->jsFilesSetup; |
||
218 | } |
||
219 | |||
1116 | daniel-mar | 220 | /** |
221 | * @return string |
||
222 | */ |
||
632 | daniel-mar | 223 | public function getManifestFile(): string { |
224 | return $this->manifestFile; |
||
225 | } |
||
226 | |||
1116 | daniel-mar | 227 | /** |
228 | * @return \SimpleXMLElement |
||
229 | */ |
||
1050 | daniel-mar | 230 | public function getRawXml(): \SimpleXMLElement { |
355 | daniel-mar | 231 | return $this->rawXML; |
232 | } |
||
233 | |||
1116 | daniel-mar | 234 | /** |
235 | * @return string |
||
236 | */ |
||
389 | daniel-mar | 237 | public function getLanguageCode(): string { |
238 | return $this->languageCode; |
||
239 | } |
||
240 | |||
1116 | daniel-mar | 241 | /** |
242 | * @return string |
||
243 | */ |
||
389 | daniel-mar | 244 | public function getLanguageFlag(): string { |
245 | return $this->languageFlag; |
||
246 | } |
||
247 | |||
1116 | daniel-mar | 248 | /** |
249 | * @return string |
||
250 | */ |
||
389 | daniel-mar | 251 | public function getLanguageMessages(): string { |
252 | return $this->languageMessages; |
||
253 | } |
||
254 | |||
988 | daniel-mar | 255 | /** |
256 | * Lists all files referenced by the manifest files |
||
257 | * Not included are other files like menu images or other PHP classes |
||
1116 | daniel-mar | 258 | * @return string[] |
259 | * @throws \ReflectionException |
||
988 | daniel-mar | 260 | */ |
261 | public function getManifestLinkedFiles(): array { |
||
262 | $files = array_merge( |
||
263 | $this->getJSFiles(), |
||
264 | $this->getCSSFiles(), |
||
265 | $this->getJSFilesSetup(), |
||
266 | $this->getCSSFilesSetup() |
||
267 | ); |
||
268 | $files[] = $this->getManifestFile(); |
||
269 | $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName(); |
||
270 | sort($files); |
||
271 | return $files; |
||
272 | } |
||
273 | |||
1116 | daniel-mar | 274 | /** |
275 | * @param string $filename |
||
276 | * @return bool |
||
277 | */ |
||
1130 | daniel-mar | 278 | public function loadManifest(string $filename): bool { |
308 | daniel-mar | 279 | if (!file_exists($filename)) return false; |
280 | $xmldata = @simplexml_load_file($filename); |
||
1116 | daniel-mar | 281 | if ($xmldata === false) return false; // TODO: rather throw an Exception and let the method return void only |
307 | daniel-mar | 282 | |
632 | daniel-mar | 283 | $this->manifestFile = $filename; |
389 | daniel-mar | 284 | $this->rawXML = $xmldata; |
285 | |||
286 | // The following attributes are available for every plugin |
||
391 | daniel-mar | 287 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 (page) |
288 | // urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 (language) |
||
289 | // urn:oid:1.3.6.1.4.1.37476.2.5.2.5.5.1 (general) |
||
308 | daniel-mar | 290 | $this->type = (string)$xmldata->type; |
307 | daniel-mar | 291 | |
308 | daniel-mar | 292 | $this->name = (string)$xmldata->info->name; |
293 | $this->author = (string)$xmldata->info->author; |
||
828 | daniel-mar | 294 | $this->license = (string)$xmldata->info->license; |
308 | daniel-mar | 295 | $this->version = (string)$xmldata->info->version; |
296 | $this->htmlDescription = (string)$xmldata->info->descriptionHTML; |
||
297 | $this->oid = (string)$xmldata->info->oid; |
||
307 | daniel-mar | 298 | |
308 | daniel-mar | 299 | $this->phpMainClass = (string)$xmldata->php->mainclass; |
307 | daniel-mar | 300 | |
473 | daniel-mar | 301 | // The following functionalities are only available for page or design plugins |
391 | daniel-mar | 302 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 |
473 | daniel-mar | 303 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1 |
937 | daniel-mar | 304 | foreach ((array)$xmldata->css->file as $css_file) { |
988 | daniel-mar | 305 | $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file; |
429 | daniel-mar | 306 | //if (!file_exists($file)) continue; |
327 | daniel-mar | 307 | $this->cssFiles[] = $file; |
307 | daniel-mar | 308 | } |
473 | daniel-mar | 309 | |
1116 | daniel-mar | 310 | // The following functionalities are only available for page plugins, captcha plugins, and object type plugins |
473 | daniel-mar | 311 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 |
1116 | daniel-mar | 312 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.10.1 |
313 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.12.1 |
||
937 | daniel-mar | 314 | foreach ((array)$xmldata->js->file as $js_file) { |
988 | daniel-mar | 315 | $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file; |
429 | daniel-mar | 316 | //if (!file_exists($file)) continue; |
327 | daniel-mar | 317 | $this->jsFiles[] = $file; |
308 | daniel-mar | 318 | } |
307 | daniel-mar | 319 | |
411 | daniel-mar | 320 | // The following functionalities are only available for database plugins |
321 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.6 |
||
937 | daniel-mar | 322 | foreach ((array)$xmldata->cssSetup->file as $css_file) { |
988 | daniel-mar | 323 | $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file; |
429 | daniel-mar | 324 | //if (!file_exists($file)) continue; |
411 | daniel-mar | 325 | $this->cssFilesSetup[] = $file; |
326 | } |
||
937 | daniel-mar | 327 | foreach ((array)$xmldata->jsSetup->file as $js_file) { |
988 | daniel-mar | 328 | $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file; |
429 | daniel-mar | 329 | //if (!file_exists($file)) continue; |
411 | daniel-mar | 330 | $this->jsFilesSetup[] = $file; |
331 | } |
||
332 | |||
389 | daniel-mar | 333 | // The following functionalities are only available for language plugins |
391 | daniel-mar | 334 | // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 |
389 | daniel-mar | 335 | $this->languageCode = (string)$xmldata->language->code; |
336 | $this->languageFlag = (string)$xmldata->language->flag; |
||
337 | $this->languageMessages = (string)$xmldata->language->messages; |
||
355 | daniel-mar | 338 | |
307 | daniel-mar | 339 | return true; |
340 | } |
||
341 | |||
342 | } |