Subversion Repositories oidplus

Rev

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

Rev 1127 Rev 1130
Line 24... Line 24...
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPagePublicObjects extends OIDplusPagePluginPublic {
26
class OIDplusPagePublicObjects extends OIDplusPagePluginPublic {
27
 
27
 
28
        /**
28
        /**
29
         * @param $ot
29
         * @param string|OIDplusObject $ot
30
         * @return string|null
30
         * @return string|null
31
         */
31
         */
32
        private function get_treeicon_root($ot)/*: ?string*/ {
32
        private function get_treeicon_root($ot)/*: ?string*/ {
33
                $root = $ot::parse($ot::root());
33
                $root = $ot::parse($ot::root());
34
                if (!$root) return null;
34
                if (!$root) return null;
35
                return $root->getIcon();
35
                return $root->getIcon();
36
        }
36
        }
37
 
37
 
38
        /**
38
        /**
39
         * @param $id
39
         * @param string $id
40
         * @param $old_ra
40
         * @param string $old_ra
41
         * @param $new_ra
41
         * @param string $new_ra
42
         * @return void
42
         * @return void
43
         * @throws OIDplusConfigInitializationException
43
         * @throws OIDplusConfigInitializationException
44
         * @throws OIDplusException
44
         * @throws OIDplusException
45
         */
45
         */
46
        private function ra_change_rec($id, $old_ra, $new_ra) {
46
        private function ra_change_rec(string $id, string $old_ra, string $new_ra) {
47
                if (is_null($old_ra)) $old_ra = '';
-
 
48
                OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra));
47
                OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra));
49
                OIDplusObject::resetObjectInformationCache();
48
                OIDplusObject::resetObjectInformationCache();
50
 
49
 
51
                $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra));
50
                $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra));
52
                while ($row = $res->fetch_array()) {
51
                while ($row = $res->fetch_array()) {
Line 183... Line 182...
183
                                if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
182
                                if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) {
184
                                        throw new OIDplusException(_L('Invalid RA email address'));
183
                                        throw new OIDplusException(_L('Invalid RA email address'));
185
                                }
184
                                }
186
 
185
 
187
                                // Change RA recursively
186
                                // Change RA recursively
188
                                $current_ra = $obj->getRaMail();
187
                                $current_ra = $obj->getRaMail() ?? '';
189
                                if ($new_ra != $current_ra) {
188
                                if ($new_ra != $current_ra) {
190
                                        OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
189
                                        OIDplus::logger()->log("[INFO]OID($id)+[?INFO/!OK]SUPOIDRA($id)?/[?INFO/!OK]A?", "RA of object '$id' changed from '$current_ra' to '$new_ra'");
191
                                        OIDplus::logger()->log("[WARN]RA($current_ra)!",           "Lost ownership of object '$id' due to RA transfer of superior RA / admin.");
190
                                        OIDplus::logger()->log("[WARN]RA($current_ra)!",           "Lost ownership of object '$id' due to RA transfer of superior RA / admin.");
192
                                        OIDplus::logger()->log("[INFO]RA($new_ra)!",               "Gained ownership of object '$id' due to RA transfer of superior RA / admin.");
191
                                        OIDplus::logger()->log("[INFO]RA($new_ra)!",               "Gained ownership of object '$id' due to RA transfer of superior RA / admin.");
193
                                        if ($parentObj = $obj->getParent()) {
192
                                        if ($parentObj = $obj->getParent()) {
Line 402... Line 401...
402
                                }
401
                                }
403
                        }
402
                        }
404
 
403
 
405
                        // Apply superior RA change
404
                        // Apply superior RA change
406
                        $parent = $params['parent'];
405
                        $parent = $params['parent'];
407
                        $ra_email = isset($params['ra_email']) ? $params['ra_email'] : '';
406
                        $ra_email = $params['ra_email'] ?? '';
408
                        if ($obj::ns() == 'oid') {
407
                        if ($obj::ns() == 'oid') {
409
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
408
                                assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid");
410
                                if ($obj->isWellKnown()) {
409
                                if ($obj->isWellKnown()) {
411
                                        $ra_email = '';
410
                                        $ra_email = '';
412
                                }
411
                                }
Line 418... Line 417...
418
                        OIDplus::logger()->log("[INFO]OID($parent)+[INFO]OID($id)+[?INFO/!OK]OIDRA($parent)?/[?INFO/!OK]A?", "Object '$id' created, ".(empty($ra_email) ? "without defined RA" : "given to RA '$ra_email'")).", superior object is '$parent'";
417
                        OIDplus::logger()->log("[INFO]OID($parent)+[INFO]OID($id)+[?INFO/!OK]OIDRA($parent)?/[?INFO/!OK]A?", "Object '$id' created, ".(empty($ra_email) ? "without defined RA" : "given to RA '$ra_email'")).", superior object is '$parent'";
419
                        if (!empty($ra_email)) {
418
                        if (!empty($ra_email)) {
420
                                OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'");
419
                                OIDplus::logger()->log("[INFO]RA($ra_email)!", "Gained ownership of newly created object '$id'");
421
                        }
420
                        }
422
 
421
 
423
                        $confidential = isset($params['confidential']) ? ($params['confidential'] == 'true') : false;
422
                        $confidential = isset($params['confidential']) && $params['confidential'] == 'true';
424
                        $comment = isset($params['comment']) ? $params['comment'] : '';
423
                        $comment = $params['comment'] ?? '';
425
                        $title = '';
424
                        $title = '';
426
                        $description = '';
425
                        $description = '';
427
 
426
 
428
                        if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
427
                        if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) {
429
                                $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
428
                                $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH');
Line 495... Line 494...
495
                        }
494
                        }
496
                });
495
                });
497
        }
496
        }
498
 
497
 
499
        /**
498
        /**
500
         * @param $id
499
         * @param string $id
501
         * @param $out
500
         * @param array $out
502
         * @return array|false
501
         * @return array|false
503
         * @throws OIDplusException
502
         * @throws OIDplusException
504
         */
503
         */
505
        private function tryObject($id, &$out) {
504
        private function tryObject(string $id, array &$out) {
506
                $parent = null;
505
                $parent = null;
507
                $res = null;
506
                $res = null;
508
                $row = null;
507
                $row = null;
509
                $obj = OIDplusObject::parse($id);
508
                $obj = OIDplusObject::parse($id);
510
                if (!$obj) return false;
509
                if (!$obj) return false;
Line 523... Line 522...
523
                }
522
                }
524
                return array($id, $obj, $objParent);
523
                return array($id, $obj, $objParent);
525
        }
524
        }
526
 
525
 
527
        /**
526
        /**
528
         * @param $id
527
         * @param string $id
529
         * @return array
528
         * @return array
530
         */
529
         */
531
        public static function getAlternativesForQuery($id) {
530
        public static function getAlternativesForQuery(string $id): array {
532
                // Attention: This is NOT an implementation of 1.3.6.1.4.1.37476.2.5.2.3.7 !
531
                // Attention: This is NOT an implementation of 1.3.6.1.4.1.37476.2.5.2.3.7 !
533
                //            This is the function that calls getAlternativesForQuery() of every plugin that implements 1.3.6.1.4.1.37476.2.5.2.3.7
532
                //            This is the function that calls getAlternativesForQuery() of every plugin that implements 1.3.6.1.4.1.37476.2.5.2.3.7
534
 
533
 
535
                // e.g. used for "Reverse Alt Id"
534
                // e.g. used for "Reverse Alt Id"
536
                $alternatives = array();
535
                $alternatives = array();
Line 549... Line 548...
549
                // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
548
                // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID
550
                $alternatives_tmp = array();
549
                $alternatives_tmp = array();
551
                foreach ($alternatives as $alt) {
550
                foreach ($alternatives as $alt) {
552
                        if ($alt !== $id) $alternatives_tmp[] = $alt;
551
                        if ($alt !== $id) $alternatives_tmp[] = $alt;
553
                }
552
                }
554
                $alternatives = $alternatives_tmp;
-
 
555
 
-
 
556
                return $alternatives;
553
                return $alternatives_tmp;
557
        }
554
        }
558
 
555
 
559
        /**
556
        /**
560
         * @param string $id
557
         * @param string $id
561
         * @param array $out
558
         * @param array $out
Line 743... Line 740...
743
                        }
740
                        }
744
                }
741
                }
745
        }
742
        }
746
 
743
 
747
        /**
744
        /**
748
         * @param $json
745
         * @param array $json
749
         * @param $out
746
         * @param array $out
750
         * @return void
747
         * @return void
751
         */
748
         */
752
        private function publicSitemap_rec($json, &$out) {
749
        private function publicSitemap_rec(array $json, array &$out) {
753
                foreach ($json as $x) {
750
                foreach ($json as $x) {
754
                        if (isset($x['id']) && $x['id']) {
751
                        if (isset($x['id']) && $x['id']) {
755
                                $out[] = $x['id'];
752
                                $out[] = $x['id'];
756
                        }
753
                        }
757
                        if (isset($x['children'])) {
754
                        if (isset($x['children'])) {
Line 1145... Line 1142...
1145
 
1142
 
1146
                return $output;
1143
                return $output;
1147
        }
1144
        }
1148
 
1145
 
1149
        /**
1146
        /**
1150
         * @param $html
1147
         * @param string $html
1151
         * @return array|string|string[]|null
1148
         * @return string
1152
         */
1149
         */
1153
        protected static function objDescription($html) {
1150
        protected static function objDescription(string $html): string {
1154
                // We allow HTML, but no hacking
1151
                // We allow HTML, but no hacking
1155
                $html = anti_xss($html);
1152
                $html = anti_xss($html);
1156
 
1153
 
1157
                return trim_br($html);
1154
                return trim_br($html);
1158
        }
1155
        }
Line 1169... Line 1166...
1169
         * @var string[]
1166
         * @var string[]
1170
         */
1167
         */
1171
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
1168
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc');
1172
 
1169
 
1173
        /**
1170
        /**
1174
         * @param $name
1171
         * @param string $name
1175
         * @param $content
1172
         * @param string $content
1176
         * @return string
1173
         * @return string
1177
         * @throws OIDplusConfigInitializationException
1174
         * @throws OIDplusConfigInitializationException
1178
         * @throws OIDplusException
1175
         * @throws OIDplusException
1179
         */
1176
         */
1180
        protected static function showMCE($name, $content) {
1177
        protected static function showMCE(string $name, string $content): string {
1181
                $mce_plugins = array();
1178
                $mce_plugins = array();
1182
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1179
                foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */
1183
                        $mce_plugins[] = basename($m);
1180
                        $mce_plugins[] = basename($m);
1184
                }
1181
                }
1185
 
1182
 
Line 1306... Line 1303...
1306
                echo ' <font color="red"><b>'.$msg.'</b></font>';
1303
                echo ' <font color="red"><b>'.$msg.'</b></font>';
1307
        }
1304
        }
1308
 
1305
 
1309
        /**
1306
        /**
1310
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
1307
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
1311
         * @param $user
1308
         * @param string|null $user
1312
         * @return array
1309
         * @return array
1313
         * @throws OIDplusException
1310
         * @throws OIDplusException
1314
         */
1311
         */
1315
        public function getNotifications($user=null): array {
1312
        public function getNotifications(string $user=null): array {
1316
                $notifications = array();
1313
                $notifications = array();
1317
                $res = OIDplus::db()->query("select id, title from ###objects order by ".OIDplus::db()->natOrder('id'));
1314
                $res = OIDplus::db()->query("select id, title from ###objects order by ".OIDplus::db()->natOrder('id'));
1318
                if ($res->any()) {
1315
                if ($res->any()) {
1319
                        $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
1316
                        $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance
1320
                        while ($row = $res->fetch_array()) {
1317
                        while ($row = $res->fetch_array()) {