static function loggedInUserCanViewEntity($entity = false, $ignore_access = false, $logged_in_user_guid = false) { // run blocked content handlers $handlers = Cache::get("blocked_content_handlers", "session"); if ($handlers) { foreach ($handlers as $handler) { $handlerEntity = "SocialApparatus\\" . $handler; $r = new $handlerEntity(); $return = $r->validate($entity); if (!$return) { return false; } } } if ($entity->access_id == "system") { return true; } if (!is_a($entity, "SocialApparatus\\User")) { if (loggedIn()) { $logged_in_user_guid = getLoggedInUserGuid(); } } if (!is_object($entity)) { return true; } if (!$entity) { return true; } if (!$entity->access_id) { $entity->access_id = "system"; $entity->save(); } if ($ignore_access) { return true; } if (!is_object($entity)) { return true; } if (getIgnoreAccess()) { return true; } // Logged in user trying to view him/herself if (getLoggedInUserGuid() == $entity->guid || $logged_in_user_guid == $entity->guid) { return true; } // Logged in user owns entity if (getLoggedInUserGuid() == $entity->owner_guid || $logged_in_user_guid == $entity->owner_guid) { return true; } // Admins can view everything if (adminLoggedIn()) { return true; } if (is_numeric($entity->access_id)) { $access_entity = getEntity($entity->access_id); if (is_a($access_entity, "SocialApparatus\\Group")) { if (isEnabledPlugin("Groups")) { if ($access_entity->loggedInUserIsMember($logged_in_user_guid)) { return true; } } } return false; } $access_handler = Accesshandler::get($entity->access_id); $access_handler = ucfirst($entity->access_id) . "AccessHandler"; $access_handler = "SocialApparatus\\" . $access_handler; if (class_exists($access_handler)) { $return = (new $access_handler())->init($entity, $logged_in_user_guid); return $return; } return false; }
function getAccessHandler($handler) { return Accesshandler::get($handler); }