Subversion Repositories oidplus

Rev

Rev 804 | Rev 817 | 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
 
730 daniel-mar 22
abstract class OIDplusObject extends OIDplusBaseClass {
261 daniel-mar 23
        const UUID_NAMEBASED_NS_OidPlusMisc = 'ad1654e6-7e15-11e4-9ef6-78e3b5fc7f22';
150 daniel-mar 24
 
2 daniel-mar 25
        public static function parse($node_id) { // please overwrite this function!
26
                // TODO: in case we are not calling this class directly, check if function is overwritten and throw exception otherwise
227 daniel-mar 27
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
2 daniel-mar 28
                        if ($obj = $ot::parse($node_id)) return $obj;
29
                }
30
                return null;
31
        }
32
 
228 daniel-mar 33
        public function /*OIDplusAltId[]*/ getAltIds() {
193 daniel-mar 34
                if ($this->isRoot()) return array();
35
 
36
                $ids = array();
37
                if ($this->ns() != 'oid') {
38
                        // Creates an OIDplus-Hash-OID
39
                        // If the object type has a better way of defining an OID, please override this method!
227 daniel-mar 40
                        $sid = OIDplus::getSystemId(true);
193 daniel-mar 41
                        if (!empty($sid)) {
42
                                $oid = $sid . '.' . smallhash($this->nodeId());
360 daniel-mar 43
                                $ids[] = new OIDplusAltId('oid', $oid, _L('OIDplus Information Object ID'));
193 daniel-mar 44
                        }
45
                }
46
                if ($this->ns() != 'guid') {
360 daniel-mar 47
                        $ids[] = new OIDplusAltId('guid', gen_uuid_md5_namebased(self::UUID_NAMEBASED_NS_OidPlusMisc, $this->nodeId()), _L('Name based version 3 / MD5 UUID with namespace %1','UUID_NAMEBASED_NS_OidPlusMisc'));
48
                        $ids[] = new OIDplusAltId('guid', gen_uuid_sha1_namebased(self::UUID_NAMEBASED_NS_OidPlusMisc, $this->nodeId()), _L('Name based version 5 / SHA1 UUID with namespace %1','UUID_NAMEBASED_NS_OidPlusMisc'));
193 daniel-mar 49
                }
50
                return $ids;
83 daniel-mar 51
        }
52
 
2 daniel-mar 53
        public abstract static function objectTypeTitle();
54
 
55
        public abstract static function objectTypeTitleShort();
56
 
57
        public abstract static function ns();
58
 
59
        public abstract static function root();
60
 
61
        public abstract function isRoot();
62
 
247 daniel-mar 63
        public abstract function nodeId($with_ns=true);
2 daniel-mar 64
 
65
        public abstract function addString($str);
66
 
67
        public abstract function crudShowId(OIDplusObject $parent);
68
 
707 daniel-mar 69
        public function crudInsertPrefix() {
70
                return '';
71
        }
2 daniel-mar 72
 
707 daniel-mar 73
        public function crudInsertSuffix() {
74
                return '';
75
        }
76
 
2 daniel-mar 77
        public abstract function jsTreeNodeName(OIDplusObject $parent = null);
78
 
79
        public abstract function defaultTitle();
80
 
16 daniel-mar 81
        public abstract function isLeafNode();
82
 
34 daniel-mar 83
        public abstract function getContentPage(&$title, &$content, &$icon);
2 daniel-mar 84
 
27 daniel-mar 85
        public static function getRaRoots($ra_email=null) {
115 daniel-mar 86
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
87
 
27 daniel-mar 88
                $out = array();
150 daniel-mar 89
 
261 daniel-mar 90
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
150 daniel-mar 91
                        if (is_null($ra_email)) {
261 daniel-mar 92
                                $res = OIDplus::db()->query("select oChild.id as id, oChild.ra_email as child_mail, oParent.ra_email as parent_mail from ###objects as oChild ".
93
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
150 daniel-mar 94
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'));
236 daniel-mar 95
                                while ($row = $res->fetch_array()) {
549 daniel-mar 96
                                        if (!OIDplus::authUtils()->isRaLoggedIn($row['parent_mail']) && OIDplus::authUtils()->isRaLoggedIn($row['child_mail'])) {
150 daniel-mar 97
                                                $x = self::parse($row['id']); // can be FALSE if namespace was disabled
98
                                                if ($x) $out[] = $x;
99
                                        }
100
                                }
101
                        } else {
261 daniel-mar 102
                                $res = OIDplus::db()->query("select oChild.id as id from ###objects as oChild ".
103
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
433 daniel-mar 104
                                                            "where (".OIDplus::db()->getSlang()->isNullFunction('oParent.ra_email',"''")." <> ? and ".
105
                                                            OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) or ".
106
                                                            "      (oParent.ra_email is null and ".OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) ".
150 daniel-mar 107
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'), array($ra_email, $ra_email, $ra_email));
236 daniel-mar 108
                                while ($row = $res->fetch_array()) {
68 daniel-mar 109
                                        $x = self::parse($row['id']); // can be FALSE if namespace was disabled
150 daniel-mar 110
                                        if ($x) $out[] = self::parse($row['id']);
27 daniel-mar 111
                                }
2 daniel-mar 112
                        }
113
                } else {
150 daniel-mar 114
                        if (is_null($ra_email)) {
415 daniel-mar 115
                                $ra_mails_to_check = OIDplus::authUtils()->loggedInRaList();
150 daniel-mar 116
                                if (count($ra_mails_to_check) == 0) return $out;
117
                        } else {
118
                                $ra_mails_to_check = array($ra_email);
2 daniel-mar 119
                        }
150 daniel-mar 120
 
121
                        self::buildObjectInformationCache();
122
 
123
                        foreach ($ra_mails_to_check as $check_ra_mail) {
193 daniel-mar 124
                                $out_part = array();
150 daniel-mar 125
 
193 daniel-mar 126
                                foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) {
127
                                        // If the OID RA is the RA we are searching, then add the object to the choice list
128
                                        if ($ra_email == $check_ra_mail) $out_part[] = $id;
150 daniel-mar 129
                                }
130
 
193 daniel-mar 131
                                foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) {
132
                                        if (isset(self::$object_info_cache[$parent])) {
133
                                                if (self::$object_info_cache[$parent][self::CACHE_RA_EMAIL] == $ra_email) {
134
                                                        // if the parent has the same RA, then this OID cannot be a root => remove the element from the choice list
135
                                                        foreach (array_keys($out_part, $id) as $key) unset($out_part[$key]);
150 daniel-mar 136
                                                }
137
                                        }
138
                                }
139
 
140
                                natsort($out_part);
141
 
142
                                foreach ($out_part as $id) {
143
                                        $obj = self::parse($id);
144
                                        if ($obj) $out[] = $obj;
145
                                }
146
                        }
2 daniel-mar 147
                }
150 daniel-mar 148
 
2 daniel-mar 149
                return $out;
150
        }
151
 
150 daniel-mar 152
        public static function getAllNonConfidential() {
153
                $out = array();
154
 
261 daniel-mar 155
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
443 daniel-mar 156
                        $res = OIDplus::db()->query("select id from ###objects where confidential = ? order by ".OIDplus::db()->natOrder('id'), array(false));
150 daniel-mar 157
 
236 daniel-mar 158
                        while ($row = $res->fetch_array()) {
150 daniel-mar 159
                                $obj = self::parse($row['id']); // will be NULL if the object type is not registered
169 daniel-mar 160
                                if ($obj && (!$obj->isConfidential())) {
150 daniel-mar 161
                                        $out[] = $row['id'];
162
                                }
2 daniel-mar 163
                        }
164
                } else {
150 daniel-mar 165
                        self::buildObjectInformationCache();
2 daniel-mar 166
 
193 daniel-mar 167
                        foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) {
150 daniel-mar 168
                                if (!$confidential) {
169
                                        $obj = self::parse($id); // will be NULL if the object type is not registered
169 daniel-mar 170
                                        if ($obj && (!$obj->isConfidential())) {
150 daniel-mar 171
                                                $out[] = $id;
172
                                        }
173
                                }
2 daniel-mar 174
                        }
175
                }
176
 
177
                return $out;
178
        }
179
 
180
        public function isConfidential() {
261 daniel-mar 181
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
426 daniel-mar 182
                        //static $confidential_cache = array();
150 daniel-mar 183
                        $curid = $this->nodeId();
426 daniel-mar 184
                        //$orig_curid = $curid;
185
                        //if (isset($confidential_cache[$curid])) return $confidential_cache[$curid];
150 daniel-mar 186
                        // Recursively search for the confidential flag in the parents
790 daniel-mar 187
                        while (($res = OIDplus::db()->query("select parent, confidential from ###objects where id = ?", array($curid)))->any()) {
236 daniel-mar 188
                                $row = $res->fetch_array();
150 daniel-mar 189
                                if ($row['confidential']) {
426 daniel-mar 190
                                        //$confidential_cache[$curid] = true;
191
                                        //$confidential_cache[$orig_curid] = true;
150 daniel-mar 192
                                        return true;
193
                                } else {
426 daniel-mar 194
                                        //$confidential_cache[$curid] = false;
150 daniel-mar 195
                                }
196
                                $curid = $row['parent'];
426 daniel-mar 197
                                //if (isset($confidential_cache[$curid])) {
198
                                        //$confidential_cache[$orig_curid] = $confidential_cache[$curid];
199
                                        //return $confidential_cache[$curid];
200
                                //}
150 daniel-mar 201
                        }
202
 
426 daniel-mar 203
                        //$confidential_cache[$orig_curid] = false;
150 daniel-mar 204
                        return false;
205
                } else {
206
                        self::buildObjectInformationCache();
207
 
208
                        $curid = $this->nodeId();
209
                        // Recursively search for the confidential flag in the parents
169 daniel-mar 210
                        while (isset(self::$object_info_cache[$curid])) {
150 daniel-mar 211
                                if (self::$object_info_cache[$curid][self::CACHE_CONFIDENTIAL]) return true;
212
                                $curid = self::$object_info_cache[$curid][self::CACHE_PARENT];
213
                        }
214
                        return false;
2 daniel-mar 215
                }
216
        }
217
 
218
        public function isChildOf(OIDplusObject $obj) {
261 daniel-mar 219
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
150 daniel-mar 220
                        $curid = $this->nodeId();
790 daniel-mar 221
                        while (($res = OIDplus::db()->query("select parent from ###objects where id = ?", array($curid)))->any()) {
236 daniel-mar 222
                                $row = $res->fetch_array();
150 daniel-mar 223
                                if ($curid == $obj->nodeId()) return true;
224
                                $curid = $row['parent'];
225
                        }
226
                        return false;
227
                } else {
228
                        self::buildObjectInformationCache();
229
 
230
                        $curid = $this->nodeId();
169 daniel-mar 231
                        while (isset(self::$object_info_cache[$curid])) {
150 daniel-mar 232
                                if ($curid == $obj->nodeId()) return true;
233
                                $curid = self::$object_info_cache[$curid][self::CACHE_PARENT];
234
                        }
235
                        return false;
2 daniel-mar 236
                }
150 daniel-mar 237
        }
2 daniel-mar 238
 
150 daniel-mar 239
        public function getChildren() {
240
                $out = array();
261 daniel-mar 241
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
242
                        $res = OIDplus::db()->query("select id from ###objects where parent = ?", array($this->nodeId()));
236 daniel-mar 243
                        while ($row = $res->fetch_array()) {
150 daniel-mar 244
                                $obj = self::parse($row['id']);
245
                                if (!$obj) continue;
246
                                $out[] = $obj;
247
                        }
248
                } else {
249
                        self::buildObjectInformationCache();
250
 
193 daniel-mar 251
                        foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) {
150 daniel-mar 252
                                if ($parent == $this->nodeId()) {
253
                                        $obj = self::parse($id);
254
                                        if (!$obj) continue;
255
                                        $out[] = $obj;
256
                                }
257
                        }
258
                }
259
                return $out;
2 daniel-mar 260
        }
261
 
115 daniel-mar 262
        public function getRa() {
150 daniel-mar 263
                return new OIDplusRA($this->getRaMail());
115 daniel-mar 264
        }
265
 
2 daniel-mar 266
        public function userHasReadRights($ra_email=null) {
115 daniel-mar 267
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
268
 
2 daniel-mar 269
                // If it is not confidential, everybody can read/see it.
416 daniel-mar 270
                // Note: This also checks if superior OIDs are confidential.
2 daniel-mar 271
                if (!$this->isConfidential()) return true;
272
 
273
                if (is_null($ra_email)) {
416 daniel-mar 274
                        // Admin may do everything
549 daniel-mar 275
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
416 daniel-mar 276
 
277
                        // If the RA is logged in, then they can see the OID.
549 daniel-mar 278
                        if (OIDplus::authUtils()->isRaLoggedIn($this->getRaMail())) return true;
2 daniel-mar 279
                } else {
416 daniel-mar 280
                        // If this OID belongs to the requested RA, then they may see it.
150 daniel-mar 281
                        if ($this->getRaMail() == $ra_email) return true;
2 daniel-mar 282
                }
283
 
284
                // If someone has rights to an object below our confidential node,
285
                // we let him see the confidential node,
286
                // Otherwise he could not browse through to his own node.
287
                $roots = $this->getRaRoots($ra_email);
288
                foreach ($roots as $root) {
289
                        if ($root->isChildOf($this)) return true;
290
                }
291
 
292
                return false;
293
        }
294
 
295
        public function getIcon($row=null) {
20 daniel-mar 296
                $namespace = $this->ns(); // must use $this, not self::, otherwise the virtual method will not be called
2 daniel-mar 297
 
298
                if (is_null($row)) {
150 daniel-mar 299
                        $ra_email = $this->getRaMail();
300
                } else {
301
                        $ra_email = $row['ra_email'];
2 daniel-mar 302
                }
303
                // TODO: have different icons for Leaf-Nodes
632 daniel-mar 304
 
635 daniel-mar 305
                $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/objectTypes/'.$namespace.'/');
632 daniel-mar 306
 
307
                if (count($dirs) == 0) return null; // default icon (folder)
308
 
309
                $dir = substr($dirs[0], strlen(OIDplus::localpath()));
310
 
805 daniel-mar 311
                // We use $this:: instead of self:: , because we want to call the overridden methods
549 daniel-mar 312
                if (OIDplus::authUtils()->isRaLoggedIn($ra_email)) {
805 daniel-mar 313
                        $icon = $dir.'/'.$this::treeIconFilename('own');
2 daniel-mar 314
                } else {
805 daniel-mar 315
                        $icon = $dir.'/'.$this::treeIconFilename('general');
2 daniel-mar 316
                }
632 daniel-mar 317
 
318
                if (!file_exists($icon)) return null; // default icon (folder)
319
 
2 daniel-mar 320
                return $icon;
321
        }
322
 
12 daniel-mar 323
        public static function exists($id) {
261 daniel-mar 324
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
325
                        $res = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
790 daniel-mar 326
                        return $res->any();
150 daniel-mar 327
                } else {
328
                        self::buildObjectInformationCache();
329
                        return isset(self::$object_info_cache[$id]);
330
                }
12 daniel-mar 331
        }
332
 
415 daniel-mar 333
        // Get parent gives the next possible parent which is EXISTING in OIDplus
334
        // It does not give the immediate parent
2 daniel-mar 335
        public function getParent() {
261 daniel-mar 336
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
337
                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId()));
790 daniel-mar 338
                        if (!$res->any()) return null;
236 daniel-mar 339
                        $row = $res->fetch_array();
150 daniel-mar 340
                        $parent = $row['parent'];
341
                        $obj = OIDplusObject::parse($parent);
342
                        if ($obj) return $obj;
415 daniel-mar 343
                        // TODO: Also implement one_up() like below
150 daniel-mar 344
                } else {
345
                        self::buildObjectInformationCache();
346
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
347
                                $parent = self::$object_info_cache[$this->nodeId()][self::CACHE_PARENT];
348
                                $obj = OIDplusObject::parse($parent);
349
                                if ($obj) return $obj;
350
                        }
20 daniel-mar 351
 
150 daniel-mar 352
                        // If this OID does not exist, the SQL query "select parent from ..." does not work. So we try to find the next possible parent using one_up()
353
                        $cur = $this->one_up();
418 daniel-mar 354
                        if (!$cur) return null;
150 daniel-mar 355
                        do {
415 daniel-mar 356
                                // findFitting() checks if that OID exists
150 daniel-mar 357
                                if ($fitting = self::findFitting($cur->nodeId())) return $fitting;
20 daniel-mar 358
 
150 daniel-mar 359
                                $prev = $cur;
360
                                $cur = $cur->one_up();
418 daniel-mar 361
                                if (!$cur) return null;
150 daniel-mar 362
                        } while ($prev != $cur);
363
 
418 daniel-mar 364
                        return null;
150 daniel-mar 365
                }
2 daniel-mar 366
        }
367
 
368
        public function getRaMail() {
261 daniel-mar 369
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
370
                        $res = OIDplus::db()->query("select ra_email from ###objects where id = ?", array($this->nodeId()));
790 daniel-mar 371
                        if (!$res->any()) return null;
236 daniel-mar 372
                        $row = $res->fetch_array();
150 daniel-mar 373
                        return $row['ra_email'];
374
                } else {
375
                        self::buildObjectInformationCache();
376
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
377
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_RA_EMAIL];
378
                        }
379
                        return false;
380
                }
2 daniel-mar 381
        }
382
 
192 daniel-mar 383
        public function getTitle() {
261 daniel-mar 384
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
385
                        $res = OIDplus::db()->query("select title from ###objects where id = ?", array($this->nodeId()));
790 daniel-mar 386
                        if (!$res->any()) return null;
236 daniel-mar 387
                        $row = $res->fetch_array();
192 daniel-mar 388
                        return $row['title'];
389
                } else {
390
                        self::buildObjectInformationCache();
391
                        if (isset(self::$object_info_cache[$this->nodeId()])) {
392
                                return self::$object_info_cache[$this->nodeId()][self::CACHE_TITLE];
393
                        }
394
                        return false;
395
                }
396
        }
397
 
2 daniel-mar 398
        public function userHasParentalWriteRights($ra_email=null) {
115 daniel-mar 399
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
400
 
2 daniel-mar 401
                if (is_null($ra_email)) {
549 daniel-mar 402
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
2 daniel-mar 403
                }
404
 
405
                $objParent = $this->getParent();
419 daniel-mar 406
                if (!$objParent) return false;
2 daniel-mar 407
                return $objParent->userHasWriteRights($ra_email);
408
        }
409
 
410
        public function userHasWriteRights($ra_email=null) {
115 daniel-mar 411
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
412
 
2 daniel-mar 413
                if (is_null($ra_email)) {
549 daniel-mar 414
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
415
                        return OIDplus::authUtils()->isRaLoggedIn($this->getRaMail());
2 daniel-mar 416
                } else {
417
                        return $this->getRaMail() == $ra_email;
418
                }
419
        }
12 daniel-mar 420
 
421
        public function distance($to) {
422
                return null; // not implemented
423
        }
20 daniel-mar 424
 
425
        public function equals($obj) {
426
                if (!is_object($obj)) $obj = OIDplusObject::parse($obj);
28 daniel-mar 427
                if (!($obj instanceof $this)) return false;
428
 
20 daniel-mar 429
                $distance = $this->distance($obj);
430
                if (is_numeric($distance)) return $distance === 0; // if the distance function is implemented, use it
431
 
432
                return $this->nodeId() == $obj->nodeId(); // otherwise compare the node id case-sensitive
433
        }
434
 
435
        public static function findFitting($id) {
436
                $obj = OIDplusObject::parse($id);
360 daniel-mar 437
                if (!$obj) throw new OIDplusException(_L('findFitting: Parse failed'));
20 daniel-mar 438
 
261 daniel-mar 439
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
440
                        $res = OIDplus::db()->query("select id from ###objects where id like ?", array($obj->ns().':%'));
236 daniel-mar 441
                        while ($row = $res->fetch_object()) {
150 daniel-mar 442
                                $test = OIDplusObject::parse($row->id);
443
                                if ($obj->equals($test)) return $test;
444
                        }
445
                        return false;
446
                } else {
447
                        self::buildObjectInformationCache();
193 daniel-mar 448
                        foreach (self::$object_info_cache as $id => list($confidential, $parent, $ra_email, $title)) {
150 daniel-mar 449
                                if (strpos($id, $obj->ns().':') === 0) {
450
                                        $test = OIDplusObject::parse($id);
451
                                        if ($obj->equals($test)) return $test;
452
                                }
453
                        }
454
                        return false;
20 daniel-mar 455
                }
456
        }
457
 
458
        public function one_up() {
459
                return null; // not implemented
460
        }
150 daniel-mar 461
 
462
        // Caching stuff
463
 
464
        protected static $object_info_cache = null;
465
 
466
        public static function resetObjectInformationCache() {
467
                self::$object_info_cache = null;
468
        }
469
 
193 daniel-mar 470
        const CACHE_CONFIDENTIAL = 0; // TODO: An object would be better so you can use $cacheitem->isConfidential() etc.
150 daniel-mar 471
        const CACHE_PARENT = 1;
472
        const CACHE_RA_EMAIL = 2;
192 daniel-mar 473
        const CACHE_TITLE = 3;
150 daniel-mar 474
 
475
        private static function buildObjectInformationCache() {
476
                if (is_null(self::$object_info_cache)) {
477
                        self::$object_info_cache = array();
261 daniel-mar 478
                        $res = OIDplus::db()->query("select id, parent, confidential, ra_email, title from ###objects");
236 daniel-mar 479
                        while ($row = $res->fetch_array()) {
192 daniel-mar 480
                                self::$object_info_cache[$row['id']] = array($row['confidential'], $row['parent'], $row['ra_email'], $row['title']);
150 daniel-mar 481
                        }
482
                }
483
        }
513 daniel-mar 484
 
485
        // override this function if you want your object type to save
486
        // attachments in directories with easy names.
487
        // Take care that your custom directory name will not allow jailbreaks (../) !
488
        public function getDirectoryName() {
514 daniel-mar 489
                if ($this->isRoot()) return $this->ns();
490
                return $this->getLegacyDirectoryName();
513 daniel-mar 491
        }
492
 
514 daniel-mar 493
        public final function getLegacyDirectoryName() {
804 daniel-mar 494
                if ($this::ns() == 'oid') {
513 daniel-mar 495
                        $oid = $this->nodeId(false);
496
                } else {
497
                        $oid = null;
498
                        $alt_ids = $this->getAltIds();
499
                        foreach ($alt_ids as $alt_id) {
500
                                if ($alt_id->getNamespace() == 'oid') {
501
                                        $oid = $alt_id->getId();
502
                                        break; // we prefer the first OID (for GUIDs, the first OID is the OIDplus-OID, and the second OID is the UUID OID)
503
                                }
504
                        }
505
                }
506
 
507
                if (!is_null($oid) && ($oid != '')) {
508
                        // For OIDs, it is the OID, for other identifiers
509
                        // it it the OID alt ID (generated using the SystemID)
510
                        return str_replace('.', '_', $oid);
511
                } else {
512
                        // Can happen if you don't have a system ID (due to missing OpenSSL plugin)
513
                        return md5($this->nodeId(true)); // we don't use $id, because $this->nodeId(true) is possibly more canonical than $id
514
                }
515
        }
800 daniel-mar 516
 
805 daniel-mar 517
        public static function treeIconFilename($mode) {
800 daniel-mar 518
                // for backwards-compatibility with older plugins
519
                return 'img/treeicon_'.$mode.'.png';
520
        }
521
 
415 daniel-mar 522
}