Exemple #1
0
/**
 * May the current user access item(s) on this page? If the page owner is a group,
 * membership, visibility, and logged in status are taken into account.
 *
 * @param boolean $forward If set to true (default), will forward the page;
 *                         if set to false, will return true or false.
 *
 * @return bool If $forward is set to false.
 */
function group_gatekeeper($forward = true)
{
    $page_owner_guid = elgg_get_page_owner_guid();
    if (!$page_owner_guid) {
        return true;
    }
    $visibility = ElggGroupItemVisibility::factory($page_owner_guid);
    if (!$visibility->shouldHideItems) {
        return true;
    }
    if ($forward) {
        // only forward to group if user can see it
        $group = get_entity($page_owner_guid);
        $forward_url = $group ? $group->getURL() : '';
        if (!elgg_is_logged_in()) {
            $_SESSION['last_forward_from'] = current_page_url();
            $forward_reason = 'login';
        } else {
            $forward_reason = 'member';
        }
        register_error(elgg_echo($visibility->reasonHidden));
        forward($forward_url, $forward_reason);
    }
    return false;
}
Exemple #2
0
/**
 * May the current user access item(s) on this page? If the page owner is a group,
 * membership, visibility, and logged in status are taken into account.
 *
 * @param boolean $forward If set to true (default), will forward the page;
 *                         if set to false, will return true or false.
 *
 * @return bool If $forward is set to false.
 */
function group_gatekeeper($forward = true)
{
    $page_owner_guid = elgg_get_page_owner_guid();
    if (!$page_owner_guid) {
        return true;
    }
    $visibility = ElggGroupItemVisibility::factory($page_owner_guid);
    if (!$visibility->shouldHideItems) {
        return true;
    }
    if ($forward) {
        // only forward to group if user can see it
        $group = get_entity($page_owner_guid);
        $forward_url = $group ? $group->getURL() : '';
        // subsite manager
        // allows to override group gatekeeper by plugins
        $allowed = elgg_trigger_plugin_hook("gatekeeper", "group", array("group" => $group, "user" => elgg_get_logged_in_user_entity()), false);
        if ($allowed === true) {
            return true;
        }
        if (!elgg_is_logged_in()) {
            $_SESSION['last_forward_from'] = current_page_url();
            $forward_reason = 'login';
        } else {
            $forward_reason = 'member';
        }
        register_error(elgg_echo($visibility->reasonHidden));
        forward($forward_url, $forward_reason);
    }
    return false;
}