Notifications redirect links when not logged in

 I ran into an issue where if my users where not logged in and followed certain links in a notification, say for a new file upload or a blog entry, they would simply get a page that said 'No results found'. When they did this with photo albums it would redirect them to the login page and present a message that said "You need to be logged in to view this page"

 Since I wanted this behavior on all such things I poked around the Wiki and found the gatekeeper() function. I inserted it after the else clause in the entities/index.php file. and in other places for thewire, messageboard and progfle display.  We did not want much publically available content :)

I'm fairly new to Elgg so if there is a better way to do this,, please educate me :)

entities/index.php:

// Get the entity, if possible
if ($entity = get_entity($guid)) {
        if ($entity->container_guid) {
                set_page_owner($entity->container_guid);
        } else {
                set_page_owner($entity->owner_guid);
        }

        // Set the body to be the full view of the entity, and the title to be its title
        if ($entity instanceof ElggObject) {
                $title = $entity->title;
        } else if ($entity instanceof ElggEntity) {
                $title = $entity->name;
        }
        $area2 = elgg_view_entity($entity,true);
        if ($shell) {
                $body = elgg_view_layout('two_column_left_sidebar', '', $area2);
        } else {
                $body = $area2;
        }
} else {
        gatekeeper();
        $body = elgg_echo('notfound');
}

mod/profile/index.php:

        // Get the Elgg engine
                require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

        gatekeeper();

        // Get the username
                $username = get_input('username');

                $body = "";

mod/thewire/index.php

        // Load Elgg engine
                require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

                gatekeeper();

        // Get the current page's owner
                $page_owner = page_owner_entity();
                if ($page_owner === false || is_null($page_owner)) {
                        $page_owner = $_SESSION['user'];
                        set_page_owner($page_owner->getGUID());
                }

mod/messageboard/start.php (caught early to minimize processing overhead!)

/**
 * Messageboard page handler
 *
 * @param array $page Array of page elements, forwarded by the page handling mechanism
 */
function messageboard_page_handler($page) {

        global $CONFIG;

        gatekeeper();

        // The username should be the first array entry
        if (isset($page[0])) {
                set_input('username', $page[0]);
        }

  • It seems the issue is that the entity (file, wire post, etc.) has a permissions level that prevents someone who is not logged in from seeing the entity. That's why you are ending up with a no file found error message. If you really want to limit the content available to non-logged in users, you could try the walled garden plugin. It makes almost all pages forward to the login page if someone is not logged in.

  • Yes, you are correct.  That is exactly the case I was trying to address by letting them know that they needed to log in first and taking them to the login page to do that.  Interestingly enough this logic allows the content that was published as public to go through  This does behave exactly as I would have expected and has the added benefit of taking them straight to the content that redirected them to the login page - once they log in.  I thought that was nice of the function developer :) But,, I do know it will break on upgrade :(

    Is the walled garden plugin you refer to called Site Access 2.6?

    Thanks Cash.

  • Oh very cool! Thanks again Cash, I hadn't got 'round to poking around svn yet :)