Subversion Repositories oidplus

Rev

Rev 988 | Rev 1086 | 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
828 daniel-mar 5
 * Copyright 2019 - 2022 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
 
730 daniel-mar 22
class OIDplusPluginManifest extends OIDplusBaseClass {
307 daniel-mar 23
 
632 daniel-mar 24
        private $manifestFile = null;
389 daniel-mar 25
        private $rawXML = null;
26
 
27
        // All plugins
308 daniel-mar 28
        private $name = '';
29
        private $author = '';
828 daniel-mar 30
        private $license = '';
308 daniel-mar 31
        private $version = '';
32
        private $htmlDescription = '';
33
        private $oid = '';
307 daniel-mar 34
 
308 daniel-mar 35
        private $type = '';
36
        private $phpMainClass = '';
389 daniel-mar 37
 
473 daniel-mar 38
        // Only page or design plugins
307 daniel-mar 39
        private $cssFiles = array();
473 daniel-mar 40
 
41
        // only page plugins
307 daniel-mar 42
        private $jsFiles = array();
43
 
411 daniel-mar 44
        // Only database plugins
45
        private $cssFilesSetup = array();
46
        private $jsFilesSetup = array();
47
 
389 daniel-mar 48
        // Only language plugins
49
        private $languageCode = '';
50
        private $languageFlag = '';
51
        private $languageMessages = '';
52
 
308 daniel-mar 53
        public function getTypeClass(): string {
54
                return $this->type;
55
        }
56
 
307 daniel-mar 57
        public function getName(): string {
58
                return $this->name;
59
        }
60
 
61
        public function getAuthor(): string {
62
                return $this->author;
63
        }
64
 
828 daniel-mar 65
        public function getLicense(): string {
66
                return $this->license;
67
        }
68
 
307 daniel-mar 69
        public function getVersion(): string {
973 daniel-mar 70
                if (str_starts_with($this->oid,'1.3.6.1.4.1.37476.2.5.2.4.') && ($this->version == '')) {
71
                        $sysver = OIDplus::getVersion();
72
                        if ($sysver == '') {
73
                                //return _L('Part of OIDplus');
74
                                return 'built-in';
75
                        } else {
76
                                //return _L('Part of OIDplus, version %1', $sysver);
77
                                return $sysver;
78
                        }
79
                } else {
80
                        return $this->version;
81
                }
307 daniel-mar 82
        }
83
 
84
        public function getHtmlDescription(): string {
85
                return $this->htmlDescription;
86
        }
87
 
308 daniel-mar 88
        public function getOid(): string {
89
                return $this->oid;
90
        }
91
 
307 daniel-mar 92
        public function getPhpMainClass(): string {
93
                return $this->phpMainClass;
94
        }
95
 
594 daniel-mar 96
        /**
97
        * @return array<string>
98
        */
307 daniel-mar 99
        public function getCSSFiles(): array {
100
                return $this->cssFiles;
101
        }
102
 
594 daniel-mar 103
        /**
104
        * @return array<string>
105
        */
307 daniel-mar 106
        public function getJSFiles(): array {
107
                return $this->jsFiles;
108
        }
109
 
594 daniel-mar 110
        /**
111
        * @return array<string>
112
        */
411 daniel-mar 113
        public function getCSSFilesSetup(): array {
114
                return $this->cssFilesSetup;
115
        }
116
 
594 daniel-mar 117
        /**
118
        * @return array<string>
119
        */
411 daniel-mar 120
        public function getJSFilesSetup(): array {
121
                return $this->jsFilesSetup;
122
        }
123
 
632 daniel-mar 124
        public function getManifestFile(): string {
125
                return $this->manifestFile;
126
        }
127
 
1050 daniel-mar 128
        public function getRawXml(): \SimpleXMLElement {
355 daniel-mar 129
                return $this->rawXML;
130
        }
131
 
389 daniel-mar 132
        public function getLanguageCode(): string {
133
                return $this->languageCode;
134
        }
135
 
136
        public function getLanguageFlag(): string {
137
                return $this->languageFlag;
138
        }
139
 
140
        public function getLanguageMessages(): string {
141
                return $this->languageMessages;
142
        }
143
 
988 daniel-mar 144
        /**
145
         * Lists all files referenced by the manifest files
146
         * Not included are other files like menu images or other PHP classes
147
         * @return array<string>
148
         */
149
        public function getManifestLinkedFiles(): array {
150
                $files = array_merge(
151
                        $this->getJSFiles(),
152
                        $this->getCSSFiles(),
153
                        $this->getJSFilesSetup(),
154
                        $this->getCSSFilesSetup()
155
                );
156
                $files[] = $this->getManifestFile();
157
                $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName();
158
                sort($files);
159
                return $files;
160
        }
161
 
307 daniel-mar 162
        public function loadManifest($filename) {
308 daniel-mar 163
                if (!file_exists($filename)) return false;
164
                $xmldata = @simplexml_load_file($filename);
165
                if ($xmldata === false) return false;
307 daniel-mar 166
 
632 daniel-mar 167
                $this->manifestFile = $filename;
389 daniel-mar 168
                $this->rawXML = $xmldata;
169
 
170
                // The following attributes are available for every plugin
391 daniel-mar 171
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 (page)
172
                //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 (language)
173
                //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.5.1 (general)
308 daniel-mar 174
                $this->type = (string)$xmldata->type;
307 daniel-mar 175
 
308 daniel-mar 176
                $this->name = (string)$xmldata->info->name;
177
                $this->author = (string)$xmldata->info->author;
828 daniel-mar 178
                $this->license = (string)$xmldata->info->license;
308 daniel-mar 179
                $this->version = (string)$xmldata->info->version;
180
                $this->htmlDescription = (string)$xmldata->info->descriptionHTML;
181
                $this->oid = (string)$xmldata->info->oid;
307 daniel-mar 182
 
308 daniel-mar 183
                $this->phpMainClass = (string)$xmldata->php->mainclass;
307 daniel-mar 184
 
473 daniel-mar 185
                // The following functionalities are only available for page or design plugins
391 daniel-mar 186
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
473 daniel-mar 187
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1
937 daniel-mar 188
                foreach ((array)$xmldata->css->file as $css_file) {
988 daniel-mar 189
                        $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
429 daniel-mar 190
                        //if (!file_exists($file)) continue;
327 daniel-mar 191
                        $this->cssFiles[] = $file;
307 daniel-mar 192
                }
473 daniel-mar 193
 
194
                // The following functionalities are only available for page plugins
195
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
937 daniel-mar 196
                foreach ((array)$xmldata->js->file as $js_file) {
988 daniel-mar 197
                        $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
429 daniel-mar 198
                        //if (!file_exists($file)) continue;
327 daniel-mar 199
                        $this->jsFiles[] = $file;
308 daniel-mar 200
                }
307 daniel-mar 201
 
411 daniel-mar 202
                // The following functionalities are only available for database plugins
203
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.6
937 daniel-mar 204
                foreach ((array)$xmldata->cssSetup->file as $css_file) {
988 daniel-mar 205
                        $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
429 daniel-mar 206
                        //if (!file_exists($file)) continue;
411 daniel-mar 207
                        $this->cssFilesSetup[] = $file;
208
                }
937 daniel-mar 209
                foreach ((array)$xmldata->jsSetup->file as $js_file) {
988 daniel-mar 210
                        $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
429 daniel-mar 211
                        //if (!file_exists($file)) continue;
411 daniel-mar 212
                        $this->jsFilesSetup[] = $file;
213
                }
214
 
389 daniel-mar 215
                // The following functionalities are only available for language plugins
391 daniel-mar 216
                // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1
389 daniel-mar 217
                $this->languageCode = (string)$xmldata->language->code;
218
                $this->languageFlag = (string)$xmldata->language->flag;
219
                $this->languageMessages = (string)$xmldata->language->messages;
355 daniel-mar 220
 
307 daniel-mar 221
                return true;
222
        }
223
 
224
}