| 727 | | /* |
|---|
| 728 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 729 | | if ( is_null($user) |
|---|
| 730 | | && ! is_null($this->user) |
|---|
| 731 | | && $this->admin) |
|---|
| 732 | | { |
|---|
| 733 | | // Administrators always have access. |
|---|
| 734 | | debug_pop(); |
|---|
| 735 | | return true; |
|---|
| 736 | | } |
|---|
| 737 | | |
|---|
| 738 | | debug_add("Querying privilege {$privilege} to " . get_class($content_object) . " {$content_object->guid}", MIDCOM_LOG_DEBUG); |
|---|
| 739 | | |
|---|
| 740 | | if ($this->_internal_sudo) |
|---|
| 741 | | { |
|---|
| 742 | | debug_add('INTERNAL SUDO mode is enabled. Generic Read-Only mode set.', MIDCOM_LOG_DEBUG); |
|---|
| 743 | | debug_pop(); |
|---|
| 744 | | return $this->_can_do_internal_sudo($privilege); |
|---|
| 745 | | } |
|---|
| 746 | | |
|---|
| 747 | | if ($this->_component_sudo) |
|---|
| 748 | | { |
|---|
| 749 | | debug_pop(); |
|---|
| 750 | | return true; |
|---|
| 751 | | } |
|---|
| 752 | | |
|---|
| 753 | | // Cache results of ACL checks per session |
|---|
| 754 | | static $cached_privileges = array(); |
|---|
| 755 | | |
|---|
| 756 | | if (is_null($this->user)) |
|---|
| 757 | | { |
|---|
| 758 | | $privilege_key = "{$content_object->guid}-{$privilege}"; |
|---|
| 759 | | } |
|---|
| 760 | | else |
|---|
| 761 | | { |
|---|
| 762 | | $privilege_key = "{$this->user->id}-{$content_object->guid}-{$privilege}"; |
|---|
| 763 | | } |
|---|
| 764 | | |
|---|
| 765 | | if (!array_key_exists($privilege_key, $cached_privileges)) |
|---|
| 766 | | { |
|---|
| 767 | | $full_privileges = $this->get_privileges($content_object, $user); |
|---|
| 768 | | |
|---|
| 769 | | if (! array_key_exists($privilege, $full_privileges)) |
|---|
| 770 | | { |
|---|
| 771 | | debug_add("The privilege {$privilege} is unknown at this point. Assuming not granted privilege.", MIDCOM_LOG_WARN); |
|---|
| 772 | | debug_pop(); |
|---|
| 773 | | return false; |
|---|
| 774 | | } |
|---|
| 775 | | |
|---|
| 776 | | if ($full_privileges[$privilege] == MIDCOM_PRIVILEGE_ALLOW) |
|---|
| 777 | | { |
|---|
| 778 | | $cached_privileges[$privilege_key] = true; |
|---|
| 779 | | } |
|---|
| 780 | | else |
|---|
| 781 | | { |
|---|
| 782 | | $cached_privileges[$privilege_key] = false; |
|---|
| 783 | | } |
|---|
| 784 | | } |
|---|
| 785 | | debug_pop(); |
|---|
| 786 | | return $cached_privileges[$privilege_key]; |
|---|
| 787 | | */ |
|---|
| 1030 | | /* |
|---|
| 1031 | | if (is_null($user)) |
|---|
| 1032 | | { |
|---|
| 1033 | | $user =& $this->user; |
|---|
| 1034 | | } |
|---|
| 1035 | | |
|---|
| 1036 | | if (is_string($user)) |
|---|
| 1037 | | { |
|---|
| 1038 | | if ($user == 'EVERYONE') |
|---|
| 1039 | | { |
|---|
| 1040 | | $user = null; |
|---|
| 1041 | | } |
|---|
| 1042 | | else |
|---|
| 1043 | | { |
|---|
| 1044 | | $user =& $_MIDCOM->auth->get_user($user); |
|---|
| 1045 | | } |
|---|
| 1046 | | } |
|---|
| 1047 | | |
|---|
| 1048 | | |
|---|
| 1049 | | if (! $_MIDCOM->dbclassloader->is_midcom_db_object($content_object)) |
|---|
| 1050 | | { |
|---|
| 1051 | | $object = $_MIDCOM->dbfactory->convert_midgard_to_midcom($content_object); |
|---|
| 1052 | | if (is_null($object)) |
|---|
| 1053 | | { |
|---|
| 1054 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 1055 | | debug_add('Failed to convert an object, falling back to an empty privilege set for the object in question. See debug level log for details.'); |
|---|
| 1056 | | debug_print_r('Content object was:', $content_object); |
|---|
| 1057 | | debug_pop(); |
|---|
| 1058 | | return Array(); |
|---|
| 1059 | | } |
|---|
| 1060 | | } |
|---|
| 1061 | | else |
|---|
| 1062 | | { |
|---|
| 1063 | | $object =& $content_object; |
|---|
| 1064 | | } |
|---|
| 1065 | | |
|---|
| 1066 | | // Check for a cache Hit. |
|---|
| 1067 | | $cache_user_id = is_null($user) ? 'EVERYONE' : $user->id; |
|---|
| 1068 | | $cache_id = "{$cache_user_id}:{$object->guid}"; |
|---|
| 1069 | | if (array_key_exists($cache_id, $this->_privileges_cache)) |
|---|
| 1070 | | { |
|---|
| 1071 | | $full_privileges = $this->_privileges_cache[$cache_id]; |
|---|
| 1072 | | } |
|---|
| 1073 | | else |
|---|
| 1074 | | { |
|---|
| 1075 | | if ( is_null($user) |
|---|
| 1076 | | || ( !is_object($user) |
|---|
| 1077 | | && $user == 'EVERYONE')) |
|---|
| 1078 | | { |
|---|
| 1079 | | $user_privileges = Array(); |
|---|
| 1080 | | $user_per_class_privileges = Array(); |
|---|
| 1081 | | } |
|---|
| 1082 | | else |
|---|
| 1083 | | { |
|---|
| 1084 | | $user_privileges = $user->get_privileges(); |
|---|
| 1085 | | $user_per_class_privileges = $user->get_per_class_privileges($object); |
|---|
| 1086 | | } |
|---|
| 1087 | | $this->_load_class_magic_privileges($object); |
|---|
| 1088 | | |
|---|
| 1089 | | // Remember to sync this merging chain with can_user_do. |
|---|
| 1090 | | $full_privileges = array_merge |
|---|
| 1091 | | ( |
|---|
| 1092 | | $this->_default_privileges, |
|---|
| 1093 | | $this->_default_magic_class_privileges[$object->__new_class_name__]['EVERYONE'], |
|---|
| 1094 | | ( |
|---|
| 1095 | | (is_null($this->user)) |
|---|
| 1096 | | ? $this->_default_magic_class_privileges[$object->__new_class_name__]['ANONYMOUS'] |
|---|
| 1097 | | : $this->_default_magic_class_privileges[$object->__new_class_name__]['USERS'] |
|---|
| 1098 | | ), |
|---|
| 1099 | | $user_privileges, |
|---|
| 1100 | | $user_per_class_privileges, |
|---|
| 1101 | | midcom_core_privilege::collect_content_privileges($object) |
|---|
| 1102 | | ); |
|---|
| 1103 | | |
|---|
| 1104 | | $this->_privileges_cache[$cache_id] = $full_privileges; |
|---|
| 1105 | | } |
|---|
| 1106 | | |
|---|
| 1107 | | return $full_privileges; |
|---|
| 1108 | | */ |
|---|