From 8916fcdca6a2950d210abd2db7e6fb104abec149 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Fri, 7 Sep 2012 01:38:03 -0400 Subject: Fixes #4789: group_gatekeeper() and river hide closed/invisible group content more reliably --- engine/classes/ElggGroupItemVisibility.php | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 engine/classes/ElggGroupItemVisibility.php (limited to 'engine/classes') diff --git a/engine/classes/ElggGroupItemVisibility.php b/engine/classes/ElggGroupItemVisibility.php new file mode 100644 index 000000000..2c7e2abb4 --- /dev/null +++ b/engine/classes/ElggGroupItemVisibility.php @@ -0,0 +1,93 @@ +guid : 0; + + $container_guid = (int) $container_guid; + + $cache_key = "$container_guid|$user_guid"; + if (empty($cache[$cache_key])) { + // compute + + $container = get_entity($container_guid); + $is_visible = (bool) $container; + + if (!$is_visible) { + // see if it *really* exists... + $prev_access = elgg_set_ignore_access(); + $container = get_entity($container_guid); + elgg_set_ignore_access($prev_access); + } + + if ($container && $container instanceof ElggGroup) { + /* @var ElggGroup $container */ + + if ($is_visible) { + if (!$container->isPublicMembership()) { + if ($user) { + if (!$container->isMember($user) && !$user->isAdmin()) { + $ret->shouldHideItems = true; + $ret->reasonHidden = self::REASON_MEMBERSHIP; + } + } else { + $ret->shouldHideItems = true; + $ret->reasonHidden = self::REASON_LOGGEDOUT; + } + } + } else { + $ret->shouldHideItems = true; + $ret->reasonHidden = self::REASON_NOACCESS; + } + } + $cache[$cache_key] = $ret; + } + return $cache[$cache_key]; + } +} -- cgit v1.2.3 From a0005033ac0d69ef462ff27394cd1c34d5dd5fab Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Fri, 7 Sep 2012 02:20:56 -0400 Subject: Better logic for when to forward to login --- engine/classes/ElggGroupItemVisibility.php | 10 ++++++++++ engine/lib/group.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggGroupItemVisibility.php b/engine/classes/ElggGroupItemVisibility.php index 2c7e2abb4..743c935da 100644 --- a/engine/classes/ElggGroupItemVisibility.php +++ b/engine/classes/ElggGroupItemVisibility.php @@ -26,6 +26,11 @@ class ElggGroupItemVisibility { */ public $reasonHidden = ''; + /** + * @var bool + */ + public $requireLogin = false; + /** * Determine visibility of items within a container for the current user * @@ -86,6 +91,11 @@ class ElggGroupItemVisibility { $ret->reasonHidden = self::REASON_NOACCESS; } } + + if ($ret->shouldHideItems && !$user) { + $ret->requireLogin = true; + } + $cache[$cache_key] = $ret; } return $cache[$cache_key]; diff --git a/engine/lib/group.php b/engine/lib/group.php index b81146e61..b32c4bd48 100644 --- a/engine/lib/group.php +++ b/engine/lib/group.php @@ -271,7 +271,7 @@ function group_gatekeeper($forward = true) { $group = get_entity($page_owner_guid); $forward_url = $group ? $group->getURL() : ''; - if ($visibility->reasonHidden !== ElggGroupItemVisibility::REASON_MEMBERSHIP) { + if (!elgg_is_logged_in()) { $_SESSION['last_forward_from'] = current_page_url(); $forward_reason = 'login'; } else { -- cgit v1.2.3 From d764446654f2c590391841ae25a9d22166b556ee Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Fri, 7 Sep 2012 02:22:20 -0400 Subject: Remove unneeded code --- engine/classes/ElggGroupItemVisibility.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggGroupItemVisibility.php b/engine/classes/ElggGroupItemVisibility.php index 743c935da..2c7e2abb4 100644 --- a/engine/classes/ElggGroupItemVisibility.php +++ b/engine/classes/ElggGroupItemVisibility.php @@ -26,11 +26,6 @@ class ElggGroupItemVisibility { */ public $reasonHidden = ''; - /** - * @var bool - */ - public $requireLogin = false; - /** * Determine visibility of items within a container for the current user * @@ -91,11 +86,6 @@ class ElggGroupItemVisibility { $ret->reasonHidden = self::REASON_NOACCESS; } } - - if ($ret->shouldHideItems && !$user) { - $ret->requireLogin = true; - } - $cache[$cache_key] = $ret; } return $cache[$cache_key]; -- cgit v1.2.3