Subversion Repositories oidplus

Rev

Rev 1050 | Rev 1116 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  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.  
  20. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusPluginManifest extends OIDplusBaseClass {
  27.  
  28.         private $manifestFile = null;
  29.         private $rawXML = null;
  30.  
  31.         // All plugins
  32.         private $name = '';
  33.         private $author = '';
  34.         private $license = '';
  35.         private $version = '';
  36.         private $htmlDescription = '';
  37.         private $oid = '';
  38.  
  39.         private $type = '';
  40.         private $phpMainClass = '';
  41.  
  42.         // Only page or design plugins
  43.         private $cssFiles = array();
  44.  
  45.         // only page plugins
  46.         private $jsFiles = array();
  47.  
  48.         // Only database plugins
  49.         private $cssFilesSetup = array();
  50.         private $jsFilesSetup = array();
  51.  
  52.         // Only language plugins
  53.         private $languageCode = '';
  54.         private $languageFlag = '';
  55.         private $languageMessages = '';
  56.  
  57.         public function getTypeClass(): string {
  58.                 return $this->type;
  59.         }
  60.  
  61.         public function getName(): string {
  62.                 return $this->name;
  63.         }
  64.  
  65.         public function getAuthor(): string {
  66.                 return $this->author;
  67.         }
  68.  
  69.         public function getLicense(): string {
  70.                 return $this->license;
  71.         }
  72.  
  73.         public function getVersion(): string {
  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.                 }
  86.         }
  87.  
  88.         public function getHtmlDescription(): string {
  89.                 return $this->htmlDescription;
  90.         }
  91.  
  92.         public function getOid(): string {
  93.                 return $this->oid;
  94.         }
  95.  
  96.         public function getPhpMainClass(): string {
  97.                 return $this->phpMainClass;
  98.         }
  99.  
  100.         /**
  101.         * @return array<string>
  102.         */
  103.         public function getCSSFiles(): array {
  104.                 return $this->cssFiles;
  105.         }
  106.  
  107.         /**
  108.         * @return array<string>
  109.         */
  110.         public function getJSFiles(): array {
  111.                 return $this->jsFiles;
  112.         }
  113.  
  114.         /**
  115.         * @return array<string>
  116.         */
  117.         public function getCSSFilesSetup(): array {
  118.                 return $this->cssFilesSetup;
  119.         }
  120.  
  121.         /**
  122.         * @return array<string>
  123.         */
  124.         public function getJSFilesSetup(): array {
  125.                 return $this->jsFilesSetup;
  126.         }
  127.  
  128.         public function getManifestFile(): string {
  129.                 return $this->manifestFile;
  130.         }
  131.  
  132.         public function getRawXml(): \SimpleXMLElement {
  133.                 return $this->rawXML;
  134.         }
  135.  
  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.  
  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.  
  166.         public function loadManifest($filename) {
  167.                 if (!file_exists($filename)) return false;
  168.                 $xmldata = @simplexml_load_file($filename);
  169.                 if ($xmldata === false) return false;
  170.  
  171.                 $this->manifestFile = $filename;
  172.                 $this->rawXML = $xmldata;
  173.  
  174.                 // The following attributes are available for every plugin
  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)
  178.                 $this->type = (string)$xmldata->type;
  179.  
  180.                 $this->name = (string)$xmldata->info->name;
  181.                 $this->author = (string)$xmldata->info->author;
  182.                 $this->license = (string)$xmldata->info->license;
  183.                 $this->version = (string)$xmldata->info->version;
  184.                 $this->htmlDescription = (string)$xmldata->info->descriptionHTML;
  185.                 $this->oid = (string)$xmldata->info->oid;
  186.  
  187.                 $this->phpMainClass = (string)$xmldata->php->mainclass;
  188.  
  189.                 // The following functionalities are only available for page or design plugins
  190.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
  191.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1
  192.                 foreach ((array)$xmldata->css->file as $css_file) {
  193.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  194.                         //if (!file_exists($file)) continue;
  195.                         $this->cssFiles[] = $file;
  196.                 }
  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
  200.                 foreach ((array)$xmldata->js->file as $js_file) {
  201.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  202.                         //if (!file_exists($file)) continue;
  203.                         $this->jsFiles[] = $file;
  204.                 }
  205.  
  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
  208.                 foreach ((array)$xmldata->cssSetup->file as $css_file) {
  209.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  210.                         //if (!file_exists($file)) continue;
  211.                         $this->cssFilesSetup[] = $file;
  212.                 }
  213.                 foreach ((array)$xmldata->jsSetup->file as $js_file) {
  214.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  215.                         //if (!file_exists($file)) continue;
  216.                         $this->jsFilesSetup[] = $file;
  217.                 }
  218.  
  219.                 // The following functionalities are only available for language plugins
  220.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1
  221.                 $this->languageCode = (string)$xmldata->language->code;
  222.                 $this->languageFlag = (string)$xmldata->language->flag;
  223.                 $this->languageMessages = (string)$xmldata->language->messages;
  224.  
  225.                 return true;
  226.         }
  227.  
  228. }
  229.