Subversion Repositories oidplus

Rev

Rev 1086 | Rev 1121 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1086 Rev 1116
Line 24... Line 24...
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
abstract class OIDplusObject extends OIDplusBaseClass {
26
abstract class OIDplusObject extends OIDplusBaseClass {
27
        const UUID_NAMEBASED_NS_OidPlusMisc = 'ad1654e6-7e15-11e4-9ef6-78e3b5fc7f22';
27
        const UUID_NAMEBASED_NS_OidPlusMisc = 'ad1654e6-7e15-11e4-9ef6-78e3b5fc7f22';
28
 
28
 
-
 
29
        /**
-
 
30
         * Please overwrite this function!
-
 
31
         * @param string $node_id
-
 
32
         * @return OIDplusObject|null
-
 
33
         */
29
        public static function parse($node_id) { // please overwrite this function!
34
        public static function parse(string $node_id)/*: ?OIDplusObject*/ {
30
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
35
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
31
                        try {
36
                        try {
32
                                $good = false;
37
                                $good = false;
33
                                if (get_parent_class($ot) == OIDplusObject::class) {
38
                                if (get_parent_class($ot) == OIDplusObject::class) {
34
                                        $reflector = new \ReflectionMethod($ot, 'parse');
39
                                        $reflector = new \ReflectionMethod($ot, 'parse');
Line 43... Line 48...
43
                        } catch (\Exception $e) {}
48
                        } catch (\Exception $e) {}
44
                }
49
                }
45
                return null;
50
                return null;
46
        }
51
        }
47
 
52
 
-
 
53
        /**
-
 
54
         * @return OIDplusAltId[]
-
 
55
         * @throws OIDplusException
-
 
56
         */
48
        public function /*OIDplusAltId[]*/ getAltIds() {
57
        public function getAltIds(): array {
49
                if ($this->isRoot()) return array();
58
                if ($this->isRoot()) return array();
50
 
59
 
51
                $ids = array();
60
                $ids = array();
52
 
61
 
53
                // Creates an OIDplus-Hash-OID
62
                // Creates an OIDplus-Hash-OID
Line 80... Line 89...
80
 
89
 
81
                // Make a AID based on ViaThinkSoft schema
90
                // Make a AID based on ViaThinkSoft schema
82
                // ... but not for OIDs below oid:1.3.6.1.4.1.37476.30.9, because these are the definition of these Information Object AIDs (which will be decoded in the OID object type plugin)
91
                // ... but not for OIDs below oid:1.3.6.1.4.1.37476.30.9, because these are the definition of these Information Object AIDs (which will be decoded in the OID object type plugin)
83
                if (($this->ns() != 'aid') && !str_starts_with($this->nodeId(true), 'oid:1.3.6.1.4.1.37476.30.9.')) {
92
                if (($this->ns() != 'aid') && !str_starts_with($this->nodeId(true), 'oid:1.3.6.1.4.1.37476.30.9.')) {
84
                        $sid = OIDplus::getSystemId(false);
93
                        $sid = OIDplus::getSystemId(false);
85
                        if (!empty($sid)) {
94
                        if ($sid !== false) {
86
                                $ns_oid = $this->getPlugin()->getManifest()->getOid();
95
                                $ns_oid = $this->getPlugin()->getManifest()->getOid();
87
                                if (str_starts_with($ns_oid, '1.3.6.1.4.1.37476.2.5.2.')) {
96
                                if (str_starts_with($ns_oid, '1.3.6.1.4.1.37476.2.5.2.')) {
88
                                        // Official ViaThinkSoft object type plugins
97
                                        // Official ViaThinkSoft object type plugins
89
                                        // For backwards compatibility with existing IDs,
98
                                        // For backwards compatibility with existing IDs,
90
                                        // set the hash_payload as '<namespace>:<id>'
99
                                        // set the hash_payload as '<namespace>:<id>'
Line 93... Line 102...
93
                                        // Third-party object type plugins
102
                                        // Third-party object type plugins
94
                                        // Set the hash_payload as '<plugin oid>:<id>'
103
                                        // Set the hash_payload as '<plugin oid>:<id>'
95
                                        $hash_payload = $ns_oid.':'.$this->nodeId(false);
104
                                        $hash_payload = $ns_oid.':'.$this->nodeId(false);
96
                                }
105
                                }
97
 
106
 
98
                                $sid_hex = strtoupper(str_pad(dechex($sid),8,'0',STR_PAD_LEFT));
107
                                $sid_hex = strtoupper(str_pad(dechex((int)$sid),8,'0',STR_PAD_LEFT));
99
                                $obj_hex = strtoupper(str_pad(dechex(smallhash($hash_payload)),8,'0',STR_PAD_LEFT));
108
                                $obj_hex = strtoupper(str_pad(dechex(smallhash($hash_payload)),8,'0',STR_PAD_LEFT));
100
                                $aid = 'D276000186B20005'.$sid_hex.$obj_hex;
109
                                $aid = 'D276000186B20005'.$sid_hex.$obj_hex;
101
                                $ids[] = new OIDplusAltId('aid', $aid, _L('OIDplus Information Object Application Identifier (ISO/IEC 7816)'), ' ('._L('No PIX allowed').')');
110
                                $ids[] = new OIDplusAltId('aid', $aid, _L('OIDplus Information Object Application Identifier (ISO/IEC 7816)'), ' ('._L('No PIX allowed').')');
102
                        }
111
                        }
103
                }
112
                }
104
 
113
 
105
                return $ids;
114
                return $ids;
106
        }
115
        }
107
 
116
 
-
 
117
        /**
-
 
118
         * @return string
-
 
119
         */
108
        public abstract static function objectTypeTitle();
120
        public abstract static function objectTypeTitle(): string;
109
 
121
 
-
 
122
        /**
-
 
123
         * @return string
-
 
124
         */
110
        public abstract static function objectTypeTitleShort();
125
        public abstract static function objectTypeTitleShort(): string;
111
 
126
 
-
 
127
        /**
-
 
128
         * @return OIDplusObjectTypePlugin|null
-
 
129
         */
112
        public function getPlugin()/*: ?OIDplusObjectTypePlugin */ {
130
        public function getPlugin()/*: ?OIDplusObjectTypePlugin */ {
113
                $res = null;
-
 
114
                $plugins = OIDplus::getObjectTypePlugins();
131
                $plugins = OIDplus::getObjectTypePlugins();
115
                foreach ($plugins as $plugin) {
132
                foreach ($plugins as $plugin) {
116
                        if (get_class($this) == $plugin::getObjectTypeClassName($this)) {
133
                        if (get_class($this) == $plugin::getObjectTypeClassName()) {
117
                                return $plugin;
134
                                return $plugin;
118
                        }
135
                        }
119
                }
136
                }
120
                return $res;
137
                return null;
121
        }
138
        }
122
 
139
 
-
 
140
        /**
-
 
141
         * @return string
-
 
142
         */
123
        public abstract static function ns();
143
        public abstract static function ns(): string;
124
 
144
 
-
 
145
        /**
-
 
146
         * @return string
-
 
147
         */
125
        public abstract static function root();
148
        public abstract static function root(): string;
126
 
149
 
-
 
150
        /**
-
 
151
         * @return bool
-
 
152
         */
127
        public abstract function isRoot();
153
        public abstract function isRoot(): bool;
128
 
154
 
-
 
155
        /**
-
 
156
         * @param bool $with_ns
-
 
157
         * @return string
-
 
158
         */
129
        public abstract function nodeId($with_ns=true);
159
        public abstract function nodeId(bool $with_ns=true): string;
130
 
160
 
-
 
161
        /**
-
 
162
         * @param string $str
-
 
163
         * @return string mixed
-
 
164
         * @throws OIDplusException
-
 
165
         */
131
        public abstract function addString($str);
166
        public abstract function addString(string $str): string;
132
 
167
 
-
 
168
        /**
-
 
169
         * @param OIDplusObject $parent
-
 
170
         * @return string
-
 
171
         */
133
        public abstract function crudShowId(OIDplusObject $parent);
172
        public abstract function crudShowId(OIDplusObject $parent): string;
134
 
173
 
-
 
174
        /**
-
 
175
         * @return string
-
 
176
         */
135
        public function crudInsertPrefix() {
177
        public function crudInsertPrefix(): string {
136
                return '';
178
                return '';
137
        }
179
        }
138
 
180
 
-
 
181
        /**
-
 
182
         * @return string
-
 
183
         */
139
        public function crudInsertSuffix() {
184
        public function crudInsertSuffix(): string {
140
                return '';
185
                return '';
141
        }
186
        }
142
 
187
 
-
 
188
        /**
-
 
189
         * @param OIDplusObject|null $parent
-
 
190
         * @return string
-
 
191
         */
143
        public abstract function jsTreeNodeName(OIDplusObject $parent = null);
192
        public abstract function jsTreeNodeName(OIDplusObject $parent = null): string;
144
 
193
 
-
 
194
        /**
-
 
195
         * @return string
-
 
196
         */
145
        public abstract function defaultTitle();
197
        public abstract function defaultTitle(): string;
146
 
198
 
-
 
199
        /**
-
 
200
         * @return bool
-
 
201
         */
147
        public abstract function isLeafNode();
202
        public abstract function isLeafNode(): bool;
148
 
203
 
-
 
204
        /**
-
 
205
         * @param string $title
-
 
206
         * @param string $content
-
 
207
         * @param string $icon
-
 
208
         * @return void
-
 
209
         */
149
        public abstract function getContentPage(&$title, &$content, &$icon);
210
        public abstract function getContentPage(string &$title, string &$content, string &$icon);
150
 
211
 
-
 
212
        /**
-
 
213
         * @param OIDplusRA|string|null $ra
-
 
214
         * @return array
-
 
215
         * @throws OIDplusConfigInitializationException
-
 
216
         * @throws OIDplusException
-
 
217
         */
151
        public static function getRaRoots($ra_email=null) {
218
        public static function getRaRoots($ra=null) : array{
152
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
219
                if ($ra instanceof OIDplusRA) $ra = $ra->raEmail();
153
 
220
 
154
                $out = array();
221
                $out = array();
155
 
222
 
156
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
223
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
157
                        if (!$ra_email) {
224
                        if (!$ra) {
158
                                $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 ".
225
                                $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 ".
159
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
226
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
160
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'));
227
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'));
161
                                while ($row = $res->fetch_array()) {
228
                                while ($row = $res->fetch_array()) {
162
                                        if (!OIDplus::authUtils()->isRaLoggedIn($row['parent_mail']) && OIDplus::authUtils()->isRaLoggedIn($row['child_mail'])) {
229
                                        if (!OIDplus::authUtils()->isRaLoggedIn($row['parent_mail']) && OIDplus::authUtils()->isRaLoggedIn($row['child_mail'])) {
Line 168... Line 235...
168
                                $res = OIDplus::db()->query("select oChild.id as id from ###objects as oChild ".
235
                                $res = OIDplus::db()->query("select oChild.id as id from ###objects as oChild ".
169
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
236
                                                            "left join ###objects as oParent on oChild.parent = oParent.id ".
170
                                                            "where (".OIDplus::db()->getSlang()->isNullFunction('oParent.ra_email',"''")." <> ? and ".
237
                                                            "where (".OIDplus::db()->getSlang()->isNullFunction('oParent.ra_email',"''")." <> ? and ".
171
                                                            OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) or ".
238
                                                            OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) or ".
172
                                                            "      (oParent.ra_email is null and ".OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) ".
239
                                                            "      (oParent.ra_email is null and ".OIDplus::db()->getSlang()->isNullFunction('oChild.ra_email',"''")." = ?) ".
173
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'), array($ra_email, $ra_email, $ra_email));
240
                                                            "order by ".OIDplus::db()->natOrder('oChild.id'), array($ra, $ra, $ra));
174
                                while ($row = $res->fetch_array()) {
241
                                while ($row = $res->fetch_array()) {
175
                                        $x = self::parse($row['id']); // can be FALSE if namespace was disabled
242
                                        $x = self::parse($row['id']); // can be FALSE if namespace was disabled
176
                                        if ($x) $out[] = $x;
243
                                        if ($x) $out[] = $x;
177
                                }
244
                                }
178
                        }
245
                        }
179
                } else {
246
                } else {
180
                        if (!$ra_email) {
247
                        if (!$ra) {
181
                                $ra_mails_to_check = OIDplus::authUtils()->loggedInRaList();
248
                                $ra_mails_to_check = OIDplus::authUtils()->loggedInRaList();
182
                                if (count($ra_mails_to_check) == 0) return $out;
249
                                if (count($ra_mails_to_check) == 0) return $out;
183
                        } else {
250
                        } else {
184
                                $ra_mails_to_check = array($ra_email);
251
                                $ra_mails_to_check = array($ra);
185
                        }
252
                        }
186
 
253
 
187
                        self::buildObjectInformationCache();
254
                        self::buildObjectInformationCache();
188
 
255
 
189
                        foreach ($ra_mails_to_check as $check_ra_mail) {
256
                        foreach ($ra_mails_to_check as $check_ra_mail) {
Line 208... Line 275...
208
                }
275
                }
209
 
276
 
210
                return $out;
277
                return $out;
211
        }
278
        }
212
 
279
 
-
 
280
        /**
-
 
281
         * @return array
-
 
282
         * @throws OIDplusException
-
 
283
         */
213
        public static function getAllNonConfidential() {
284
        public static function getAllNonConfidential(): array {
214
                $out = array();
285
                $out = array();
215
 
286
 
216
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
287
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
217
                        $res = OIDplus::db()->query("select id from ###objects where confidential = ? order by ".OIDplus::db()->natOrder('id'), array(false));
288
                        $res = OIDplus::db()->query("select id from ###objects where confidential = ? order by ".OIDplus::db()->natOrder('id'), array(false));
218
 
289
 
Line 237... Line 308...
237
                }
308
                }
238
 
309
 
239
                return $out;
310
                return $out;
240
        }
311
        }
241
 
312
 
-
 
313
        /**
-
 
314
         * @return bool
-
 
315
         * @throws OIDplusException
-
 
316
         */
242
        public function isConfidential() {
317
        public function isConfidential(): bool {
243
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
318
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
244
                        //static $confidential_cache = array();
319
                        //static $confidential_cache = array();
245
                        $curid = $this->nodeId();
320
                        $curid = $this->nodeId();
246
                        //$orig_curid = $curid;
321
                        //$orig_curid = $curid;
247
                        //if (isset($confidential_cache[$curid])) return $confidential_cache[$curid];
322
                        //if (isset($confidential_cache[$curid])) return $confidential_cache[$curid];
Line 275... Line 350...
275
                        }
350
                        }
276
                        return false;
351
                        return false;
277
                }
352
                }
278
        }
353
        }
279
 
354
 
-
 
355
        /**
-
 
356
         * @param OIDplusObject $obj
-
 
357
         * @return bool
-
 
358
         * @throws OIDplusException
-
 
359
         */
280
        public function isChildOf(OIDplusObject $obj) {
360
        public function isChildOf(OIDplusObject $obj): bool {
281
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
361
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
282
                        $curid = $this->nodeId();
362
                        $curid = $this->nodeId();
283
                        while (($res = OIDplus::db()->query("select parent from ###objects where id = ?", array($curid)))->any()) {
363
                        while (($res = OIDplus::db()->query("select parent from ###objects where id = ?", array($curid)))->any()) {
284
                                $row = $res->fetch_array();
364
                                $row = $res->fetch_array();
285
                                if ($curid == $obj->nodeId()) return true;
365
                                if ($curid == $obj->nodeId()) return true;
Line 296... Line 376...
296
                        }
376
                        }
297
                        return false;
377
                        return false;
298
                }
378
                }
299
        }
379
        }
300
 
380
 
-
 
381
        /**
-
 
382
         * @return array
-
 
383
         * @throws OIDplusException
-
 
384
         */
301
        public function getChildren() {
385
        public function getChildren(): array {
302
                $out = array();
386
                $out = array();
303
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
387
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
304
                        $res = OIDplus::db()->query("select id from ###objects where parent = ?", array($this->nodeId()));
388
                        $res = OIDplus::db()->query("select id from ###objects where parent = ?", array($this->nodeId()));
305
                        while ($row = $res->fetch_array()) {
389
                        while ($row = $res->fetch_array()) {
306
                                $obj = self::parse($row['id']);
390
                                $obj = self::parse($row['id']);
Line 320... Line 404...
320
                        }
404
                        }
321
                }
405
                }
322
                return $out;
406
                return $out;
323
        }
407
        }
324
 
408
 
-
 
409
        /**
-
 
410
         * @return OIDplusRA
-
 
411
         * @throws OIDplusException
-
 
412
         */
325
        public function getRa() {
413
        public function getRa(): OIDplusRA {
326
                return new OIDplusRA($this->getRaMail());
414
                return new OIDplusRA($this->getRaMail());
327
        }
415
        }
328
 
416
 
-
 
417
        /**
-
 
418
         * @param OIDplusRA|string|null $ra
-
 
419
         * @return bool
-
 
420
         * @throws OIDplusConfigInitializationException
-
 
421
         * @throws OIDplusException
-
 
422
         */
329
        public function userHasReadRights($ra_email=null) {
423
        public function userHasReadRights($ra=null): bool {
330
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
424
                if ($ra instanceof OIDplusRA) $ra = $ra->raEmail();
331
 
425
 
332
                // If it is not confidential, everybody can read/see it.
426
                // If it is not confidential, everybody can read/see it.
333
                // Note: This also checks if superior OIDs are confidential.
427
                // Note: This also checks if superior OIDs are confidential.
334
                if (!$this->isConfidential()) return true;
428
                if (!$this->isConfidential()) return true;
335
 
429
 
336
                if (!$ra_email) {
430
                if (!$ra) {
337
                        // Admin may do everything
431
                        // Admin may do everything
338
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
432
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
339
 
433
 
340
                        // If the RA is logged in, then they can see the OID.
434
                        // If the RA is logged in, then they can see the OID.
341
                        if (OIDplus::authUtils()->isRaLoggedIn($this->getRaMail())) return true;
435
                        if (OIDplus::authUtils()->isRaLoggedIn($this->getRaMail())) return true;
342
                } else {
436
                } else {
343
                        // If this OID belongs to the requested RA, then they may see it.
437
                        // If this OID belongs to the requested RA, then they may see it.
344
                        if ($this->getRaMail() == $ra_email) return true;
438
                        if ($this->getRaMail() == $ra) return true;
345
                }
439
                }
346
 
440
 
347
                // If someone has rights to an object below our confidential node,
441
                // If someone has rights to an object below our confidential node,
348
                // we let him see the confidential node,
442
                // we let him see the confidential node,
349
                // Otherwise he could not browse through to his own node.
443
                // Otherwise he could not browse through to his own node.
350
                $roots = $this->getRaRoots($ra_email);
444
                $roots = $this->getRaRoots($ra);
351
                foreach ($roots as $root) {
445
                foreach ($roots as $root) {
352
                        if ($root->isChildOf($this)) return true;
446
                        if ($root->isChildOf($this)) return true;
353
                }
447
                }
354
 
448
 
355
                return false;
449
                return false;
356
        }
450
        }
357
 
451
 
-
 
452
        /**
-
 
453
         * @param array|null $row
-
 
454
         * @return string|null
-
 
455
         * @throws OIDplusException
-
 
456
         */
358
        public function getIcon($row=null) {
457
        public function getIcon(array $row=null) {
359
                $namespace = $this->ns(); // must use $this, not self::, otherwise the virtual method will not be called
458
                $namespace = $this->ns(); // must use $this, not self::, otherwise the virtual method will not be called
360
 
459
 
361
                if (is_null($row)) {
460
                if (is_null($row)) {
362
                        $ra_email = $this->getRaMail();
461
                        $ra_email = $this->getRaMail();
363
                } else {
462
                } else {
Line 381... Line 480...
381
                if (!file_exists($icon)) return null; // default icon (folder)
480
                if (!file_exists($icon)) return null; // default icon (folder)
382
 
481
 
383
                return $icon;
482
                return $icon;
384
        }
483
        }
385
 
484
 
-
 
485
        /**
-
 
486
         * @param string $id
-
 
487
         * @return bool
-
 
488
         * @throws OIDplusException
-
 
489
         */
386
        public static function exists(string $id) {
490
        public static function exists(string $id): bool {
387
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
491
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
388
                        $res = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
492
                        $res = OIDplus::db()->query("select id from ###objects where id = ?", array($id));
389
                        return $res->any();
493
                        return $res->any();
390
                } else {
494
                } else {
391
                        self::buildObjectInformationCache();
495
                        self::buildObjectInformationCache();
392
                        return isset(self::$object_info_cache[$id]);
496
                        return isset(self::$object_info_cache[$id]);
393
                }
497
                }
394
        }
498
        }
395
 
499
 
-
 
500
        /**
396
        // Get parent gives the next possible parent which is EXISTING in OIDplus
501
         * Get parent gives the next possible parent which is EXISTING in OIDplus
397
        // It does not give the immediate parent
502
         * It does not give the immediate parent
-
 
503
         * @return OIDplusObject|null
-
 
504
         * @throws OIDplusException
-
 
505
         */
398
        public function getParent()/*: ?OIDplusObject*/ {
506
        public function getParent()/*: ?OIDplusObject*/ {
399
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
507
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
400
                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId()));
508
                        $res = OIDplus::db()->query("select parent from ###objects where id = ?", array($this->nodeId()));
401
                        if (!$res->any()) return null;
509
                        if (!$res->any()) return null;
402
                        $row = $res->fetch_array();
510
                        $row = $res->fetch_array();
Line 420... Line 528...
420
                                if ($fitting = self::findFitting($cur->nodeId())) return $fitting;
528
                                if ($fitting = self::findFitting($cur->nodeId())) return $fitting;
421
 
529
 
422
                                $prev = $cur;
530
                                $prev = $cur;
423
                                $cur = $cur->one_up();
531
                                $cur = $cur->one_up();
424
                                if (!$cur) return null;
532
                                if (!$cur) return null;
425
                        } while ($prev != $cur);
533
                        } while ($prev !== $cur);
426
                }
534
                }
427
                return null;
535
                return null;
428
        }
536
        }
429
 
537
 
-
 
538
        /**
-
 
539
         * @return false|string|null
-
 
540
         * @throws OIDplusException
-
 
541
         */
430
        public function getRaMail() {
542
        public function getRaMail() {
431
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
543
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
432
                        $res = OIDplus::db()->query("select ra_email from ###objects where id = ?", array($this->nodeId()));
544
                        $res = OIDplus::db()->query("select ra_email from ###objects where id = ?", array($this->nodeId()));
433
                        if (!$res->any()) return null;
545
                        if (!$res->any()) return null;
434
                        $row = $res->fetch_array();
546
                        $row = $res->fetch_array();
Line 440... Line 552...
440
                        }
552
                        }
441
                        return false;
553
                        return false;
442
                }
554
                }
443
        }
555
        }
444
 
556
 
-
 
557
        /**
-
 
558
         * @return false|string|null
-
 
559
         * @throws OIDplusException
-
 
560
         */
445
        public function getTitle() {
561
        public function getTitle() {
446
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
562
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
447
                        $res = OIDplus::db()->query("select title from ###objects where id = ?", array($this->nodeId()));
563
                        $res = OIDplus::db()->query("select title from ###objects where id = ?", array($this->nodeId()));
448
                        if (!$res->any()) return null;
564
                        if (!$res->any()) return null;
449
                        $row = $res->fetch_array();
565
                        $row = $res->fetch_array();
Line 455... Line 571...
455
                        }
571
                        }
456
                        return false;
572
                        return false;
457
                }
573
                }
458
        }
574
        }
459
 
575
 
-
 
576
        /**
-
 
577
         * @return false|string|null
-
 
578
         * @throws OIDplusException
-
 
579
         */
460
        public function getDescription() {
580
        public function getDescription() {
461
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
581
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
462
                        $res = OIDplus::db()->query("select description from ###objects where id = ?", array($this->nodeId()));
582
                        $res = OIDplus::db()->query("select description from ###objects where id = ?", array($this->nodeId()));
463
                        if (!$res->any()) return null;
583
                        if (!$res->any()) return null;
464
                        $row = $res->fetch_array();
584
                        $row = $res->fetch_array();
Line 470... Line 590...
470
                        }
590
                        }
471
                        return false;
591
                        return false;
472
                }
592
                }
473
        }
593
        }
474
 
594
 
-
 
595
        /**
-
 
596
         * @return false|string|null
-
 
597
         * @throws OIDplusException
-
 
598
         */
475
        public function getComment() {
599
        public function getComment() {
476
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
600
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
477
                        $res = OIDplus::db()->query("select comment from ###objects where id = ?", array($this->nodeId()));
601
                        $res = OIDplus::db()->query("select comment from ###objects where id = ?", array($this->nodeId()));
478
                        if (!$res->any()) return null;
602
                        if (!$res->any()) return null;
479
                        $row = $res->fetch_array();
603
                        $row = $res->fetch_array();
Line 485... Line 609...
485
                        }
609
                        }
486
                        return false;
610
                        return false;
487
                }
611
                }
488
        }
612
        }
489
 
613
 
-
 
614
        /**
-
 
615
         * @return false|string|null
-
 
616
         * @throws OIDplusException
-
 
617
         */
490
        public function getCreatedTime() {
618
        public function getCreatedTime() {
491
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
619
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
492
                        $res = OIDplus::db()->query("select created from ###objects where id = ?", array($this->nodeId()));
620
                        $res = OIDplus::db()->query("select created from ###objects where id = ?", array($this->nodeId()));
493
                        if (!$res->any()) return null;
621
                        if (!$res->any()) return null;
494
                        $row = $res->fetch_array();
622
                        $row = $res->fetch_array();
Line 500... Line 628...
500
                        }
628
                        }
501
                        return false;
629
                        return false;
502
                }
630
                }
503
        }
631
        }
504
 
632
 
-
 
633
        /**
-
 
634
         * @return false|string|null
-
 
635
         * @throws OIDplusException
-
 
636
         */
505
        public function getUpdatedTime() {
637
        public function getUpdatedTime() {
506
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
638
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
507
                        $res = OIDplus::db()->query("select updated from ###objects where id = ?", array($this->nodeId()));
639
                        $res = OIDplus::db()->query("select updated from ###objects where id = ?", array($this->nodeId()));
508
                        if (!$res->any()) return null;
640
                        if (!$res->any()) return null;
509
                        $row = $res->fetch_array();
641
                        $row = $res->fetch_array();
Line 515... Line 647...
515
                        }
647
                        }
516
                        return false;
648
                        return false;
517
                }
649
                }
518
        }
650
        }
519
 
651
 
-
 
652
        /**
-
 
653
         * @param OIDplusRA|string|null $ra
-
 
654
         * @return bool
-
 
655
         * @throws OIDplusException
-
 
656
         */
520
        public function userHasParentalWriteRights($ra_email=null) {
657
        public function userHasParentalWriteRights($ra=null) {
521
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
658
                if ($ra instanceof OIDplusRA) $ra = $ra->raEmail();
522
 
659
 
523
                if (!$ra_email) {
660
                if (!$ra) {
524
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
661
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
525
                }
662
                }
526
 
663
 
527
                $objParent = $this->getParent();
664
                $objParent = $this->getParent();
528
                if (!$objParent) return false;
665
                if (!$objParent) return false;
529
                return $objParent->userHasWriteRights($ra_email);
666
                return $objParent->userHasWriteRights($ra);
530
        }
667
        }
531
 
668
 
-
 
669
        /**
-
 
670
         * @param OIDplusRA|string|null $ra
-
 
671
         * @return bool
-
 
672
         * @throws OIDplusException
-
 
673
         */
532
        public function userHasWriteRights($ra_email=null) {
674
        public function userHasWriteRights($ra=null): bool {
533
                if ($ra_email instanceof OIDplusRA) $ra_email = $ra_email->raEmail();
675
                if ($ra instanceof OIDplusRA) $ra = $ra->raEmail();
534
 
676
 
535
                if (!$ra_email) {
677
                if (!$ra) {
536
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
678
                        if (OIDplus::authUtils()->isAdminLoggedIn()) return true;
537
                        return OIDplus::authUtils()->isRaLoggedIn($this->getRaMail());
679
                        return OIDplus::authUtils()->isRaLoggedIn($this->getRaMail());
538
                } else {
680
                } else {
539
                        return $this->getRaMail() == $ra_email;
681
                        return $this->getRaMail() == $ra;
540
                }
682
                }
541
        }
683
        }
542
 
684
 
-
 
685
        /**
-
 
686
         * @param string|OIDplusObject $to
-
 
687
         * @return int|null
-
 
688
         */
543
        public function distance($to) {
689
        public function distance($to)/*: ?int*/ {
544
                return null; // not implemented
690
                return null; // not implemented
545
        }
691
        }
546
 
692
 
-
 
693
        /**
-
 
694
         * @param OIDplusObject $obj
-
 
695
         * @return bool
-
 
696
         */
547
        public function equals($obj) {
697
        public function equals(OIDplusObject $obj): bool {
548
                if (!is_object($obj)) $obj = OIDplusObject::parse($obj);
698
                if (!is_object($obj)) $obj = OIDplusObject::parse($obj);
549
                if (!($obj instanceof $this)) return false;
699
                if (!($obj instanceof $this)) return false;
550
 
700
 
551
                $distance = $this->distance($obj);
701
                $distance = $this->distance($obj);
552
                if (is_numeric($distance)) return $distance === 0; // if the distance function is implemented, use it
702
                if (is_numeric($distance)) return $distance === 0; // if the distance function is implemented, use it
553
 
703
 
554
                return $this->nodeId() == $obj->nodeId(); // otherwise compare the node id case-sensitive
704
                return $this->nodeId() == $obj->nodeId(); // otherwise compare the node id case-sensitive
555
        }
705
        }
556
 
706
 
-
 
707
        /**
-
 
708
         * @param string $id
-
 
709
         * @return OIDplusObject|false
-
 
710
         * @throws OIDplusException
-
 
711
         */
557
        public static function findFitting(string $id) {
712
        public static function findFitting(string $id) {
558
                $obj = OIDplusObject::parse($id);
713
                $obj = OIDplusObject::parse($id);
559
                if (!$obj) return false; // e.g. if ObjectType plugin is disabled
714
                if (!$obj) return false; // e.g. if ObjectType plugin is disabled
560
 
715
 
561
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
716
                if (!OIDplus::baseConfig()->getValue('OBJECT_CACHING', true)) {
Line 575... Line 730...
575
                        }
730
                        }
576
                        return false;
731
                        return false;
577
                }
732
                }
578
        }
733
        }
579
 
734
 
-
 
735
        /**
-
 
736
         * @return OIDplusObject|null
-
 
737
         */
580
        public function one_up() {
738
        public function one_up()/*: ?OIDplusObject*/ {
581
                return null; // not implemented
739
                return null; // not implemented
582
        }
740
        }
583
 
741
 
584
        // Caching stuff
742
        // Caching stuff
585
 
743
 
586
        protected static $object_info_cache = null;
744
        protected static $object_info_cache = null;
587
 
745
 
-
 
746
        /**
-
 
747
         * @return void
-
 
748
         */
588
        public static function resetObjectInformationCache() {
749
        public static function resetObjectInformationCache() {
589
                self::$object_info_cache = null;
750
                self::$object_info_cache = null;
590
        }
751
        }
591
 
752
 
592
        const CACHE_ID = 'id';
753
        const CACHE_ID = 'id';
Line 597... Line 758...
597
        const CACHE_CONFIDENTIAL = 'confidential';
758
        const CACHE_CONFIDENTIAL = 'confidential';
598
        const CACHE_CREATED = 'created';
759
        const CACHE_CREATED = 'created';
599
        const CACHE_UPDATED = 'updated';
760
        const CACHE_UPDATED = 'updated';
600
        const CACHE_COMMENT = 'comment';
761
        const CACHE_COMMENT = 'comment';
601
 
762
 
-
 
763
        /**
-
 
764
         * @return void
-
 
765
         * @throws OIDplusException
-
 
766
         */
602
        private static function buildObjectInformationCache() {
767
        private static function buildObjectInformationCache() {
603
                if (is_null(self::$object_info_cache)) {
768
                if (is_null(self::$object_info_cache)) {
604
                        self::$object_info_cache = array();
769
                        self::$object_info_cache = array();
605
                        $res = OIDplus::db()->query("select * from ###objects");
770
                        $res = OIDplus::db()->query("select * from ###objects");
606
                        while ($row = $res->fetch_array()) {
771
                        while ($row = $res->fetch_array()) {
607
                                self::$object_info_cache[$row['id']] = $row;
772
                                self::$object_info_cache[$row['id']] = $row;
608
                        }
773
                        }
609
                }
774
                }
610
        }
775
        }
611
 
776
 
-
 
777
        /**
612
        // override this function if you want your object type to save
778
         * override this function if you want your object type to save
613
        // attachments in directories with easy names.
779
         * attachments in directories with easy names.
614
        // Take care that your custom directory name will not allow jailbreaks (../) !
780
         * Take care that your custom directory name will not allow jailbreaks (../) !
-
 
781
         * @return string
-
 
782
         * @throws OIDplusException
-
 
783
         */
615
        public function getDirectoryName() {
784
        public function getDirectoryName(): string {
616
                if ($this->isRoot()) return $this->ns();
785
                if ($this->isRoot()) return $this->ns();
617
                return $this->getLegacyDirectoryName();
786
                return $this->getLegacyDirectoryName();
618
        }
787
        }
619
 
788
 
-
 
789
        /**
-
 
790
         * @return string
-
 
791
         * @throws OIDplusException
-
 
792
         */
620
        public final function getLegacyDirectoryName() {
793
        public final function getLegacyDirectoryName(): string {
621
                if ($this::ns() == 'oid') {
794
                if ($this::ns() == 'oid') {
622
                        $oid = $this->nodeId(false);
795
                        $oid = $this->nodeId(false);
623
                } else {
796
                } else {
624
                        $oid = null;
797
                        $oid = null;
625
                        $alt_ids = $this->getAltIds();
798
                        $alt_ids = $this->getAltIds();
Line 639... Line 812...
639
                        // Can happen if you don't have a system ID (due to missing OpenSSL plugin)
812
                        // Can happen if you don't have a system ID (due to missing OpenSSL plugin)
640
                        return md5($this->nodeId(true)); // we don't use $id, because $this->nodeId(true) is possibly more canonical than $id
813
                        return md5($this->nodeId(true)); // we don't use $id, because $this->nodeId(true) is possibly more canonical than $id
641
                }
814
                }
642
        }
815
        }
643
 
816
 
-
 
817
        /**
-
 
818
         * @param string $mode
-
 
819
         * @return string
-
 
820
         */
644
        public static function treeIconFilename($mode) {
821
        public static function treeIconFilename(string $mode): string {
645
                // for backwards-compatibility with older plugins
822
                // for backwards-compatibility with older plugins
646
                return 'img/treeicon_'.$mode.'.png';
823
                return 'img/treeicon_'.$mode.'.png';
647
        }
824
        }
648
 
825
 
649
}
826
}