From 3cdf73acb6641827dda69599496384f33a8e0ffb Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 23 Feb 2009 11:07:42 +0000 Subject: Introducing group_gatekeeper() git-svn-id: https://code.elgg.org/elgg/trunk@2888 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/group.php | 30 ++++++++++++++++++++++++++++++ mod/groups/groupprofile.php | 6 ++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/engine/lib/group.php b/engine/lib/group.php index 588a60aac..cff387298 100644 --- a/engine/lib/group.php +++ b/engine/lib/group.php @@ -793,6 +793,36 @@ return get_entities_from_relationship('member', $user_guid, false); } + /** + * Checks access to a group. + * + * @param boolean $forward If set to true (default), will forward the page; if set to false, will return true or false. + * @return true|false If $forward is set to false. + */ + function group_gatekeeper($forward = true) { + + $allowed = true; + $url = ''; + + if ($group = page_owner_entity()) { + if ($group instanceof ElggGroup) { + $url = $group->getURL(); + if ( + ((!isloggedin()) && (!$group->isPublicMembership())) || + ((!$group->isMember(get_loggedin_user()) && (!$group->isPublicMembership()))) + ) $allowed = false; + } + } + + if ($forward && $allowed == false) { + forward($url); + exit; + } + + return $allowed; + + } + /** * Performs initialisation functions for groups * diff --git a/mod/groups/groupprofile.php b/mod/groups/groupprofile.php index 437685313..b7dffa524 100644 --- a/mod/groups/groupprofile.php +++ b/mod/groups/groupprofile.php @@ -22,10 +22,8 @@ // Hide some items from closed groups when the user is not logged in. $view_all = true; - if ( - ((!isloggedin()) && (!$group->isPublicMembership())) || - ((!$group->isMember(get_loggedin_user()) && (!$group->isPublicMembership()))) - ) + $groupaccess = group_gatekeeper(false); + if (!$groupaccess) $view_all = false; -- cgit v1.2.3