From eeb7616c61cc38af026a39bf9a6932801675c0c9 Mon Sep 17 00:00:00 2001 From: marcus Date: Thu, 9 Apr 2009 17:07:27 +0000 Subject: Forward user if a page owner is inaccessible (Refs #969) git-svn-id: https://code.elgg.org/elgg/trunk@3200 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/pageowner.php | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/engine/lib/pageowner.php b/engine/lib/pageowner.php index d78aa3301..c2b98c284 100644 --- a/engine/lib/pageowner.php +++ b/engine/lib/pageowner.php @@ -20,37 +20,58 @@ function page_owner() { - global $CONFIG; + global $CONFIG; + + $returnval = NULL; $setpageowner = set_page_owner(); if ($setpageowner !== false) { return $setpageowner; } - if ($username = get_input("username")) { + if ((!isset($returnval)) && ($username = get_input("username"))) { if (substr_count($username,'group:')) { preg_match('/group\:([0-9]+)/i',$username,$matches); $guid = $matches[1]; - if ($entity = get_entity($guid)) { - return $entity->getGUID(); + if ($entity = get_entity($guid)) { + $returnval = $entity->getGUID(); } } - if ($user = get_user_by_username($username)) { - return $user->getGUID(); + if ((!isset($returnval)) && ($user = get_user_by_username($username))) { + $returnval = $user->getGUID(); } - } - if ($owner = get_input("owner_guid")) { + } + + + if ((!isset($returnval)) && ($owner = get_input("owner_guid"))) { if ($user = get_entity($owner)) { - return $user->getGUID(); + $returnval = $user->getGUID(); } - } - if (!empty($CONFIG->page_owner_handlers) && is_array($CONFIG->page_owner_handlers)) { + } + + + if ((!isset($returnval)) && (!empty($CONFIG->page_owner_handlers) && is_array($CONFIG->page_owner_handlers))) { foreach($CONFIG->page_owner_handlers as $handler) { - if ($guid = $handler()) { - return $guid; + if ((!isset($returnval)) && ($guid = $handler())) { + $returnval = $guid; } } - } + } + + if (isset($returnval)) { + + // Check if this is obtainable, forwarding if not. + /* + * If the owner entity has been set, but is inaccessible then we forward to the dashboard. This + * catches a bunch of WSoDs. It doesn't have much of a performance hit since 99.999% of the time the next thing + * a page does after calling this function is to retrieve the owner entity - which is of course cashed. + */ + $owner_entity = get_entity($returnval); + if (!$owner_entity) forward(); + + return $returnval; + } + return 0; } -- cgit v1.2.3