Subversion Repositories oidplus

Rev

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