Subversion Repositories oidplus

Rev

Rev 1162 | 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.                 // TODO: Find a way to translate plugin names
  137.                 return $this->name;
  138.         }
  139.  
  140.         /**
  141.          * @return string
  142.          */
  143.         public function getAuthor(): string {
  144.                 return $this->author;
  145.         }
  146.  
  147.         /**
  148.          * @return string
  149.          */
  150.         public function getLicense(): string {
  151.                 return $this->license;
  152.         }
  153.  
  154.         /**
  155.          * @return string
  156.          */
  157.         public function getVersion(): string {
  158.                 if (str_starts_with($this->oid,'1.3.6.1.4.1.37476.2.5.2.4.') && ($this->version == '')) {
  159.                         $sysver = OIDplus::getVersion();
  160.                         if ($sysver == '') {
  161.                                 //return _L('Part of OIDplus');
  162.                                 return 'built-in';
  163.                         } else {
  164.                                 //return _L('Part of OIDplus, version %1', $sysver);
  165.                                 return $sysver ?: 'unknown';
  166.                         }
  167.                 } else {
  168.                         return $this->version;
  169.                 }
  170.         }
  171.  
  172.         /**
  173.          * @return string
  174.          */
  175.         public function getHtmlDescription(): string {
  176.                 return $this->htmlDescription;
  177.         }
  178.  
  179.         /**
  180.          * @return string
  181.          */
  182.         public function getOid(): string {
  183.                 return $this->oid;
  184.         }
  185.  
  186.         /**
  187.          * @return string
  188.          */
  189.         public function getPhpMainClass(): string {
  190.                 return $this->phpMainClass;
  191.         }
  192.  
  193.         /**
  194.         * @return string[]
  195.         */
  196.         public function getCSSFiles(): array {
  197.                 return $this->cssFiles;
  198.         }
  199.  
  200.         /**
  201.          * @return string[]
  202.         */
  203.         public function getJSFiles(): array {
  204.                 return $this->jsFiles;
  205.         }
  206.  
  207.         /**
  208.          * @return string[]
  209.         */
  210.         public function getCSSFilesSetup(): array {
  211.                 return $this->cssFilesSetup;
  212.         }
  213.  
  214.         /**
  215.          * @return string[]
  216.         */
  217.         public function getJSFilesSetup(): array {
  218.                 return $this->jsFilesSetup;
  219.         }
  220.  
  221.         /**
  222.          * @return string
  223.          */
  224.         public function getManifestFile(): string {
  225.                 return $this->manifestFile;
  226.         }
  227.  
  228.         /**
  229.          * @return \SimpleXMLElement
  230.          */
  231.         public function getRawXml(): \SimpleXMLElement {
  232.                 return $this->rawXML;
  233.         }
  234.  
  235.         /**
  236.          * @return string
  237.          */
  238.         public function getLanguageCode(): string {
  239.                 return $this->languageCode;
  240.         }
  241.  
  242.         /**
  243.          * @return string
  244.          */
  245.         public function getLanguageFlag(): string {
  246.                 return $this->languageFlag;
  247.         }
  248.  
  249.         /**
  250.          * @return string
  251.          */
  252.         public function getLanguageMessages(): string {
  253.                 return $this->languageMessages;
  254.         }
  255.  
  256.         /**
  257.          * Lists all files referenced by the manifest files
  258.          * Not included are other files like menu images or other PHP classes
  259.          * @return string[]
  260.          * @throws \ReflectionException
  261.          */
  262.         public function getManifestLinkedFiles(): array {
  263.                 $files = array_merge(
  264.                         $this->getJSFiles(),
  265.                         $this->getCSSFiles(),
  266.                         $this->getJSFilesSetup(),
  267.                         $this->getCSSFilesSetup()
  268.                 );
  269.                 $files[] = $this->getManifestFile();
  270.                 $files[] = (new \ReflectionClass($this->getPhpMainClass()))->getFileName();
  271.                 sort($files);
  272.                 return $files;
  273.         }
  274.  
  275.         /**
  276.          * @param string $filename
  277.          * @return bool
  278.          */
  279.         public function loadManifest(string $filename): bool {
  280.                 if (!file_exists($filename)) return false;
  281.                 $xmldata = @simplexml_load_file($filename);
  282.                 if ($xmldata === false) return false; // TODO: rather throw an Exception and let the method return void only
  283.  
  284.                 $this->manifestFile = $filename;
  285.                 $this->rawXML = $xmldata;
  286.  
  287.                 // The following attributes are available for every plugin
  288.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 (page)
  289.                 //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1 (language)
  290.                 //            urn:oid:1.3.6.1.4.1.37476.2.5.2.5.5.1 (general)
  291.                 $this->type = (string)$xmldata->type;
  292.  
  293.                 $this->name = (string)$xmldata->info->name;
  294.                 $this->author = (string)$xmldata->info->author;
  295.                 $this->license = (string)$xmldata->info->license;
  296.                 $this->version = (string)$xmldata->info->version;
  297.                 $this->htmlDescription = (string)$xmldata->info->descriptionHTML;
  298.                 $this->oid = (string)$xmldata->info->oid;
  299.  
  300.                 $this->phpMainClass = (string)$xmldata->php->mainclass;
  301.  
  302.                 // The following functionalities are only available for page or design plugins
  303.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
  304.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.7.1
  305.                 foreach ((array)$xmldata->css->file as $css_file) {
  306.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  307.                         //if (!file_exists($file)) continue;
  308.                         $this->cssFiles[] = $file;
  309.                 }
  310.  
  311.                 // The following functionalities are only available for page plugins, captcha plugins, and object type plugins
  312.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1
  313.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.10.1
  314.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.12.1
  315.                 foreach ((array)$xmldata->js->file as $js_file) {
  316.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  317.                         //if (!file_exists($file)) continue;
  318.                         $this->jsFiles[] = $file;
  319.                 }
  320.  
  321.                 // The following functionalities are only available for database plugins
  322.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.6
  323.                 foreach ((array)$xmldata->cssSetup->file as $css_file) {
  324.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$css_file;
  325.                         //if (!file_exists($file)) continue;
  326.                         $this->cssFilesSetup[] = $file;
  327.                 }
  328.                 foreach ((array)$xmldata->jsSetup->file as $js_file) {
  329.                         $file = dirname($filename).DIRECTORY_SEPARATOR.$js_file;
  330.                         //if (!file_exists($file)) continue;
  331.                         $this->jsFilesSetup[] = $file;
  332.                 }
  333.  
  334.                 // The following functionalities are only available for language plugins
  335.                 // XML Schema urn:oid:1.3.6.1.4.1.37476.2.5.2.5.3.1
  336.                 $this->languageCode = (string)$xmldata->language->code;
  337.                 $this->languageFlag = (string)$xmldata->language->flag;
  338.                 $this->languageMessages = (string)$xmldata->language->messages;
  339.  
  340.                 return true;
  341.         }
  342.  
  343. }
  344.