Subversion Repositories oidplus

Rev

Rev 112 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 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. if (!defined('IN_OIDPLUS')) die();
  21.  
  22. class OIDplusGuid extends OIDplusObject {
  23.         private $guid;
  24.  
  25.         public function __construct($guid) {
  26.                 // No syntax checks, since we also allow categories.
  27.                 $this->guid = $guid;
  28.         }
  29.  
  30.         public static function parse($node_id) {
  31.                 @list($namespace, $guid) = explode(':', $node_id, 2);
  32.                 if ($namespace !== 'guid') return false;
  33.                 return new self($guid);
  34.         }
  35.  
  36.         public static function objectTypeTitle() {
  37.                 return "Globally Unique Identifier (GUID)";
  38.         }
  39.  
  40.         public static function objectTypeTitleShort() {
  41.                 return "GUID";
  42.         }
  43.  
  44.         public static function ns() {
  45.                 return 'guid';
  46.         }
  47.  
  48.         public static function root() {
  49.                 return 'guid:';
  50.         }
  51.  
  52.         public function isRoot() {
  53.                 return $this->guid == '';
  54.         }
  55.  
  56.         public function nodeId() {
  57.                 return 'guid:'.$this->guid;
  58.         }
  59.  
  60.         public function addString($str) {
  61.                 if (uuid_valid($str)) {
  62.                         // real GUID
  63.                         return 'guid:'.$str;
  64.                 } else {
  65.                         // just a category
  66.                         return 'guid:'.$this->guid.'/'.$str;
  67.                 }
  68.         }
  69.  
  70.         public function crudShowId(OIDplusObject $parent) {
  71.                 $tmp = explode('/',$this->guid);
  72.                 return end($tmp);
  73.         }
  74.  
  75.         public function crudInsertPrefix() {
  76.                 return '';
  77.         }
  78.  
  79.         public function jsTreeNodeName(OIDplusObject $parent = null) {
  80.                 if ($parent == null) return $this->objectTypeTitle();
  81.                 return $this->crudShowId($parent);
  82.         }
  83.  
  84.         public function defaultTitle() {
  85.                 return $this->guid;
  86.         }
  87.  
  88.         public function isLeafNode() {
  89.                 return uuid_valid($this->guid);
  90.         }
  91.  
  92.         public function getContentPage(&$title, &$content, &$icon) {
  93.                 $icon = file_exists(__DIR__.'/icon_big.png') ? 'plugins/objectTypes/'.basename(__DIR__).'/icon_big.png' : '';
  94.  
  95.                 if ($this->isRoot()) {
  96.                         $title = OIDplusGuid::objectTypeTitle();
  97.  
  98.                         $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where parent = ?", array(self::root()));
  99.                         if (OIDplus::db()->num_rows($res) > 0) {
  100.                                 $content  = 'Please select a GUID in the tree view at the left to show its contents.';
  101.                         } else {
  102.                                 $content  = 'Currently, no GUID is registered in the system.';
  103.                         }
  104.  
  105.                         if (!$this->isLeafNode()) {
  106.                                 if (OIDplus::authUtils()::isAdminLoggedIn()) {
  107.                                         $content .= '<h2>Manage root objects / categories</h2>';
  108.                                 } else {
  109.                                         $content .= '<h2>Available objects / categories</h2>';
  110.                                 }
  111.                                 $content .= '%%CRUD%%';
  112.                         }
  113.                 } else {
  114.                         if ($this->isLeafNode()) {
  115.                                 ob_start();
  116.                                 uuid_info($this->guid);
  117.                                 $info = ob_get_contents();
  118.                                 ob_end_clean();
  119.                                 $info = preg_replace('@:\s*(.+)\n@ismU', ": <code>\\1</code><br>", $info);
  120.  
  121.                                 $content = "<h2>Technical information</h2><p>UUID: <code>" . uuid_canonize($this->guid) . "</code><br>" .
  122.                                        "OID: <code>" . uuid_to_oid($this->guid) . "</code><br>" .
  123.                                        "C++ notation: <code>" . uuid_c_syntax($this->guid) . "</code><br>" .
  124.                                        "$info";
  125.                                 //      "<a href=\"https://misc.daniel-marschall.de/tools/uuid_mac_decoder/interprete_uuid.php?uuid=".urlencode($this->guid)."\">More technical information</a></p>";
  126.                         } else {
  127.                                 $content = '';
  128.                         }
  129.  
  130.                         $content .= '<h2>Description</h2>%%DESC%%';
  131.  
  132.                         if (!$this->isLeafNode()) {
  133.                                 if ($this->userHasWriteRights()) {
  134.                                         $content .= '<h2>Create or change subsequent objects / categories</h2>';
  135.                                 } else {
  136.                                         $content .= '<h2>Subsequent objects / categories</h2>';
  137.                                 }
  138.                                 $content .= '%%CRUD%%';
  139.                         }
  140.                 }
  141.         }
  142.  
  143.         // TODO: It would be nice if category and leaf items could have different pictures.
  144.         //       But the problem is, that the RA link should have a orange "GUID" icon, not a folder icon
  145.         /*
  146.         public function getIcon($row) {
  147.                 if (!$this->isLeafNode()) return null; // foldericon
  148.                 return parent::getIcon($row);
  149.         }
  150.         */
  151.  
  152.         public function one_up() {
  153.                 // A GUID is a GUID, there is no hierarchy
  154.                 return false;
  155.         }
  156.  
  157.         public function distance($to) {
  158.                 // Distance between GUIDs is not possible
  159.                 return null;
  160.         }
  161. }
  162.  
  163. OIDplus::registerObjectType('OIDplusGuid');
  164.