Subversion Repositories oidplus

Rev

Rev 1086 | Rev 1130 | 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.         /**
  58.          * @return string
  59.          */
  60.         public function getTypeClass(): string {
  61.                 return $this->type;
  62.         }
  63.  
  64.         /**
  65.          * @return string
  66.          */
  67.         public function getName(): string {
  68.                 return $this->name;
  69.         }
  70.  
  71.         /**
  72.          * @return string
  73.          */
  74.         public function getAuthor(): string {
  75.                 return $this->author;
  76.         }
  77.  
  78.         /**
  79.          * @return string
  80.          */
  81.         public function getLicense(): string {
  82.                 return $this->license;
  83.         }
  84.  
  85.         /**
  86.          * @return string
  87.          */
  88.         public function getVersion(): string {
  89.                 if (str_starts_with($this->oid,'1.3.6.1.4.1.37476.2.5.2.4.') && ($this->version == '')) {
  90.                         $sysver = OIDplus::getVersion();
  91.                         if ($sysver == '') {
  92.                                 //return _L('Part of OIDplus');
  93.                                 return 'built-in';
  94.                         } else {
  95.                                 //return _L('Part of OIDplus, version %1', $sysver);
  96.                                 return $sysver;
  97.                         }
  98.                 } else {
  99.                         return $this->version;
  100.                 }
  101.         }
  102.  
  103.         /**
  104.          * @return string
  105.          */
  106.         public function getHtmlDescription(): string {
  107.                 return $this->htmlDescription;
  108.         }
  109.  
  110.         /**
  111.          * @return string
  112.          */
  113.         public function getOid(): string {
  114.                 return $this->oid;
  115.         }
  116.  
  117.         /**
  118.          * @return string
  119.          */
  120.         public function getPhpMainClass(): string {
  121.                 return $this->phpMainClass;
  122.         }
  123.  
  124.         /**
  125.         * @return string[]
  126.         */
  127.         public function getCSSFiles(): array {
  128.                 return $this->cssFiles;
  129.         }
  130.  
  131.         /**
  132.          * @return string[]
  133.         */
  134.         public function getJSFiles(): array {
  135.                 return $this->jsFiles;
  136.         }
  137.  
  138.         /**
  139.          * @return string[]
  140.         */
  141.         public function getCSSFilesSetup(): array {
  142.                 return $this->cssFilesSetup;
  143.         }
  144.  
  145.         /**
  146.          * @return string[]
  147.         */
  148.         public function getJSFilesSetup(): array {
  149.                 return $this->jsFilesSetup;
  150.         }
  151.  
  152.         /**
  153.          * @return string
  154.          */
  155.         public function getManifestFile(): string {
  156.                 return $this->manifestFile;
  157.         }
  158.  
  159.         /**
  160.          * @return \SimpleXMLElement
  161.          */
  162.         public function getRawXml(): \SimpleXMLElement {
  163.                 return $this->rawXML;
  164.         }
  165.  
  166.         /**
  167.          * @return string
  168.          */
  169.         public function getLanguageCode(): string {
  170.                 return $this->languageCode;
  171.         }
  172.  
  173.         /**
  174.          * @return string
  175.          */
  176.         public function getLanguageFlag(): string {
  177.                 return $this->languageFlag;
  178.         }
  179.  
  180.         /**
  181.          * @return string
  182.          */
  183.         public function getLanguageMessages(): string {
  184.                 return $this->languageMessages;
  185.         }
  186.  
  187.         /**
  188.          * Lists all files referenced by the manifest files
  189.          * Not included are other files like menu images or other PHP classes
  190.          * @return string[]
  191.          * @throws \ReflectionException
  192.          */
  193.         public function getManifestLinkedFiles(): array {
  194.                 $files = array_merge(
  195.                         $this->getJSFiles(),
  196.                         $this->getCSSFiles(),
  197.                         $this->getJSFilesSetup(),
  198.                         $this->getCSSFilesSetup()
  199.                 );
  200.                 $files[] = $this->getManifestFile();
  201.                 $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName();
  202.                 sort($files);
  203.                 return $files;
  204.         }
  205.  
  206.         /**
  207.          * @param string $filename
  208.          * @return bool
  209.          */
  210.         public function loadManifest(string $filename) {
  211.                 if (!file_exists($filename)) return false;
  212.                 $xmldata = @simplexml_load_file($filename);
  213.                 if ($xmldata === false) return false; // TODO: rather throw an Exception and let the method return void only
  214.  
  215.                 $this->manifestFile = $filename;
  216.                 $this->rawXML = $xmldata;
  217.  
  218.                 // The following attributes are available for every plugin
  219.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 (page)
  220.                 //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 (language)
  221.                 //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.5.1 (general)
  222.                 $this->type = (string)$xmldata->type;
  223.  
  224.                 $this->name = (string)$xmldata->info->name;
  225.                 $this->author = (string)$xmldata->info->author;
  226.                 $this->license = (string)$xmldata->info->license;
  227.                 $this->version = (string)$xmldata->info->version;
  228.                 $this->htmlDescription = (string)$xmldata->info->descriptionHTML;
  229.                 $this->oid = (string)$xmldata->info->oid;
  230.  
  231.                 $this->phpMainClass = (string)$xmldata->php->mainclass;
  232.  
  233.                 // The following functionalities are only available for page or design plugins
  234.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
  235.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1
  236.                 foreach ((array)$xmldata->css->file as $css_file) {
  237.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  238.                         //if (!file_exists($file)) continue;
  239.                         $this->cssFiles[] = $file;
  240.                 }
  241.  
  242.                 // The following functionalities are only available for page plugins, captcha plugins, and object type plugins
  243.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
  244.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.10.1
  245.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.12.1
  246.                 foreach ((array)$xmldata->js->file as $js_file) {
  247.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  248.                         //if (!file_exists($file)) continue;
  249.                         $this->jsFiles[] = $file;
  250.                 }
  251.  
  252.                 // The following functionalities are only available for database plugins
  253.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.6
  254.                 foreach ((array)$xmldata->cssSetup->file as $css_file) {
  255.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  256.                         //if (!file_exists($file)) continue;
  257.                         $this->cssFilesSetup[] = $file;
  258.                 }
  259.                 foreach ((array)$xmldata->jsSetup->file as $js_file) {
  260.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  261.                         //if (!file_exists($file)) continue;
  262.                         $this->jsFilesSetup[] = $file;
  263.                 }
  264.  
  265.                 // The following functionalities are only available for language plugins
  266.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1
  267.                 $this->languageCode = (string)$xmldata->language->code;
  268.                 $this->languageFlag = (string)$xmldata->language->flag;
  269.                 $this->languageMessages = (string)$xmldata->language->messages;
  270.  
  271.                 return true;
  272.         }
  273.  
  274. }
  275.