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