Subversion Repositories oidplus

Rev

Rev 1130 | Rev 1162 | 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.         /**
  29.          * @var string
  30.          */
  31.         private $manifestFile = null;
  32.  
  33.         /**
  34.          * @var \SimpleXMLElement|null
  35.          */
  36.         private $rawXML = null;
  37.  
  38.         // --- All plugins ---
  39.  
  40.         /**
  41.          * @var string
  42.          */
  43.         private $name = '';
  44.  
  45.         /**
  46.          * @var string
  47.          */
  48.         private $author = '';
  49.  
  50.         /**
  51.          * @var string
  52.          */
  53.         private $license = '';
  54.  
  55.         /**
  56.          * @var string
  57.          */
  58.         private $version = '';
  59.  
  60.         /**
  61.          * @var string
  62.          */
  63.         private $htmlDescription = '';
  64.  
  65.         /**
  66.          * @var string
  67.          */
  68.         private $oid = '';
  69.  
  70.         /**
  71.          * @var string
  72.          */
  73.         private $type = '';
  74.  
  75.         /**
  76.          * @var string
  77.          */
  78.         private $phpMainClass = '';
  79.  
  80.         // --- Only page or design plugins ---
  81.  
  82.         /**
  83.          * @var array
  84.          */
  85.         private $cssFiles = array();
  86.  
  87.         // --- Only page plugins ---
  88.  
  89.         /**
  90.          * @var array
  91.          */
  92.         private $jsFiles = array();
  93.  
  94.         // --- Only database plugins ---
  95.  
  96.         /**
  97.          * @var array
  98.          */
  99.         private $cssFilesSetup = array();
  100.  
  101.         /**
  102.          * @var array
  103.          */
  104.         private $jsFilesSetup = array();
  105.  
  106.         // --- Only language plugins ---
  107.  
  108.         /**
  109.          * @var string
  110.          */
  111.         private $languageCode = '';
  112.  
  113.         /**
  114.          * @var string
  115.          */
  116.         private $languageFlag = '';
  117.  
  118.         /**
  119.          * @var string
  120.          */
  121.         private $languageMessages = '';
  122.  
  123.         # -------------
  124.  
  125.         /**
  126.          * @return string
  127.          */
  128.         public function getTypeClass(): string {
  129.                 return $this->type;
  130.         }
  131.  
  132.         /**
  133.          * @return string
  134.          */
  135.         public function getName(): string {
  136.                 return $this->name;
  137.         }
  138.  
  139.         /**
  140.          * @return string
  141.          */
  142.         public function getAuthor(): string {
  143.                 return $this->author;
  144.         }
  145.  
  146.         /**
  147.          * @return string
  148.          */
  149.         public function getLicense(): string {
  150.                 return $this->license;
  151.         }
  152.  
  153.         /**
  154.          * @return string
  155.          */
  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 == '')) {
  158.                         $sysver = OIDplus::getVersion();
  159.                         if ($sysver == '') {
  160.                                 //return _L('Part of OIDplus');
  161.                                 return 'built-in';
  162.                         } else {
  163.                                 //return _L('Part of OIDplus, version %1', $sysver);
  164.                                 return $sysver ? $sysver : 'unknown';
  165.                         }
  166.                 } else {
  167.                         return $this->version;
  168.                 }
  169.         }
  170.  
  171.         /**
  172.          * @return string
  173.          */
  174.         public function getHtmlDescription(): string {
  175.                 return $this->htmlDescription;
  176.         }
  177.  
  178.         /**
  179.          * @return string
  180.          */
  181.         public function getOid(): string {
  182.                 return $this->oid;
  183.         }
  184.  
  185.         /**
  186.          * @return string
  187.          */
  188.         public function getPhpMainClass(): string {
  189.                 return $this->phpMainClass;
  190.         }
  191.  
  192.         /**
  193.         * @return string[]
  194.         */
  195.         public function getCSSFiles(): array {
  196.                 return $this->cssFiles;
  197.         }
  198.  
  199.         /**
  200.          * @return string[]
  201.         */
  202.         public function getJSFiles(): array {
  203.                 return $this->jsFiles;
  204.         }
  205.  
  206.         /**
  207.          * @return string[]
  208.         */
  209.         public function getCSSFilesSetup(): array {
  210.                 return $this->cssFilesSetup;
  211.         }
  212.  
  213.         /**
  214.          * @return string[]
  215.         */
  216.         public function getJSFilesSetup(): array {
  217.                 return $this->jsFilesSetup;
  218.         }
  219.  
  220.         /**
  221.          * @return string
  222.          */
  223.         public function getManifestFile(): string {
  224.                 return $this->manifestFile;
  225.         }
  226.  
  227.         /**
  228.          * @return \SimpleXMLElement
  229.          */
  230.         public function getRawXml(): \SimpleXMLElement {
  231.                 return $this->rawXML;
  232.         }
  233.  
  234.         /**
  235.          * @return string
  236.          */
  237.         public function getLanguageCode(): string {
  238.                 return $this->languageCode;
  239.         }
  240.  
  241.         /**
  242.          * @return string
  243.          */
  244.         public function getLanguageFlag(): string {
  245.                 return $this->languageFlag;
  246.         }
  247.  
  248.         /**
  249.          * @return string
  250.          */
  251.         public function getLanguageMessages(): string {
  252.                 return $this->languageMessages;
  253.         }
  254.  
  255.         /**
  256.          * Lists all files referenced by the manifest files
  257.          * Not included are other files like menu images or other PHP classes
  258.          * @return string[]
  259.          * @throws \ReflectionException
  260.          */
  261.         public function getManifestLinkedFiles(): array {
  262.                 $files = array_merge(
  263.                         $this->getJSFiles(),
  264.                         $this->getCSSFiles(),
  265.                         $this->getJSFilesSetup(),
  266.                         $this->getCSSFilesSetup()
  267.                 );
  268.                 $files[] = $this->getManifestFile();
  269.                 $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName();
  270.                 sort($files);
  271.                 return $files;
  272.         }
  273.  
  274.         /**
  275.          * @param string $filename
  276.          * @return bool
  277.          */
  278.         public function loadManifest(string $filename): bool {
  279.                 if (!file_exists($filename)) return false;
  280.                 $xmldata = @simplexml_load_file($filename);
  281.                 if ($xmldata === false) return false; // TODO: rather throw an Exception and let the method return void only
  282.  
  283.                 $this->manifestFile = $filename;
  284.                 $this->rawXML = $xmldata;
  285.  
  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)
  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)
  290.                 $this->type = (string)$xmldata->type;
  291.  
  292.                 $this->name = (string)$xmldata->info->name;
  293.                 $this->author = (string)$xmldata->info->author;
  294.                 $this->license = (string)$xmldata->info->license;
  295.                 $this->version = (string)$xmldata->info->version;
  296.                 $this->htmlDescription = (string)$xmldata->info->descriptionHTML;
  297.                 $this->oid = (string)$xmldata->info->oid;
  298.  
  299.                 $this->phpMainClass = (string)$xmldata->php->mainclass;
  300.  
  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
  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) {
  305.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  306.                         //if (!file_exists($file)) continue;
  307.                         $this->cssFiles[] = $file;
  308.                 }
  309.  
  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
  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
  314.                 foreach ((array)$xmldata->js->file as $js_file) {
  315.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  316.                         //if (!file_exists($file)) continue;
  317.                         $this->jsFiles[] = $file;
  318.                 }
  319.  
  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
  322.                 foreach ((array)$xmldata->cssSetup->file as $css_file) {
  323.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  324.                         //if (!file_exists($file)) continue;
  325.                         $this->cssFilesSetup[] = $file;
  326.                 }
  327.                 foreach ((array)$xmldata->jsSetup->file as $js_file) {
  328.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  329.                         //if (!file_exists($file)) continue;
  330.                         $this->jsFilesSetup[] = $file;
  331.                 }
  332.  
  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
  335.                 $this->languageCode = (string)$xmldata->language->code;
  336.                 $this->languageFlag = (string)$xmldata->language->flag;
  337.                 $this->languageMessages = (string)$xmldata->language->messages;
  338.  
  339.                 return true;
  340.         }
  341.  
  342. }
  343.