Subversion Repositories oidplus

Rev

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