Subversion Repositories oidplus

Rev

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