From e0d9fa933f8e33ff65492876c4bbbe7c93e9e2f4 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 2 Apr 2008 09:43:55 +0000 Subject: Introducing page_owner_entity git-svn-id: https://code.elgg.org/elgg/trunk@328 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/pageowner.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'engine/lib/pageowner.php') diff --git a/engine/lib/pageowner.php b/engine/lib/pageowner.php index 3cc0130f4..9d6231082 100644 --- a/engine/lib/pageowner.php +++ b/engine/lib/pageowner.php @@ -15,7 +15,7 @@ /** * Gets the page owner for the current page. * @uses $CONFIG - * @return int|false The current page owner guid (false if none). + * @return int|false The current page owner guid (0 if none). */ function page_owner() { @@ -46,6 +46,39 @@ } + /** + * Gets the page owner for the current page. + * @uses $CONFIG + * @return ElggUser|false The current page owner (false if none). + */ + function page_owner_entity() { + + global $CONFIG; + if ($username = get_input("username")) { + if ($user = get_user_by_username($username)) { + return $user; + } else { + return false; + } + } + if ($owner = get_input("owner_id")) { + if ($user = get_user($owner)) { + return $user; + } else { + return false; + } + } + if (!empty($CONFIG->page_owner_entity_handlers) && is_array($CONFIG->page_owner_entity_handlers)) { + foreach($CONFIG->page_owner_entity_handlers as $handler) { + if ($user = $handler()) { + return $user; + } + } + } + return false; + + } + /** * Adds a page owner handler - a function that will * return the page owner if required @@ -66,4 +99,23 @@ } + /** + * Adds a page owner entity handler - a function that will + * return the page owner ElggUser if required + * (Such functions are required to return false if they don't know) + * @uses $CONFIG + * @param string $functionname The name of the function to call + */ + function add_page_owner_entity_handler($functionname) { + + global $CONFIG; + if (empty($CONFIG->page_owner_entity_handlers)) { + $CONFIG->page_owner_entity_handlers = array(); + } + if (is_callable($functionname)) { + $CONFIG->page_owner_entity_handlers[] = $functionname; + } + + } + ?> \ No newline at end of file -- cgit v1.2.3