Subversion Repositories oidplus

Rev

Rev 1130 | Rev 1162 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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