diff options
Diffstat (limited to 'engine/lib/pageowner.php')
| -rw-r--r-- | engine/lib/pageowner.php | 224 |
1 files changed, 110 insertions, 114 deletions
diff --git a/engine/lib/pageowner.php b/engine/lib/pageowner.php index 6cd4f8e95..bd63d08c6 100644 --- a/engine/lib/pageowner.php +++ b/engine/lib/pageowner.php @@ -13,7 +13,7 @@ * @param int $guid Optional parameter used by elgg_set_page_owner_guid(). * * @return int The current page owner guid (0 if none). - * @since 1.8 + * @since 1.8.0 */ function elgg_get_page_owner_guid($guid = 0) { static $page_owner_guid; @@ -26,100 +26,73 @@ function elgg_get_page_owner_guid($guid = 0) { return $page_owner_guid; } - $guid = trigger_plugin_hook('page_owner', 'system', NULL, 0); + // return guid of page owner entity + $guid = elgg_trigger_plugin_hook('page_owner', 'system', NULL, 0); - $page_owner_guid = $guid; + if ($guid) { + $page_owner_guid = $guid; + } return $guid; } /** - * Gets the guid of the entity that owns the current page. - * - * @deprecated 1.8 Use elgg_get_page_owner_guid() - * - * @return int The current page owner guid (0 if none). - */ -function page_owner() { - elgg_deprecated_notice('page_owner() was deprecated by elgg_get_page_owner_guid().', 1.8); - return elgg_get_page_owner_guid(); -} - -/** * Gets the owner entity for the current page. * - * @return ElggEntity|false The current page owner or false if none. + * @note Access is disabled when getting the page owner entity. * - * @since 1.8 + * @return ElggUser|ElggGroup|false The current page owner or false if none. + * + * @since 1.8.0 */ -function elgg_get_page_owner() { +function elgg_get_page_owner_entity() { $guid = elgg_get_page_owner_guid(); if ($guid > 0) { - return get_entity($guid); - } + $ia = elgg_set_ignore_access(true); + $owner = get_entity($guid); + elgg_set_ignore_access($ia); - return FALSE; -} + return $owner; + } -/** - * Gets the owner entity for the current page. - * - * @deprecated 1.8 Use elgg_get_page_owner() - * @return ElggEntity|false The current page owner or false if none. - * - * @since 1.8 - */ -function page_owner_entity() { - elgg_deprecated_notice('page_owner_entity() was deprecated by elgg_get_page_owner().', 1.8); - return elgg_get_page_owner(); + return false; } /** * Set the guid of the entity that owns this page * * @param int $guid The guid of the page owner - * - * @since 1.8 + * @return void + * @since 1.8.0 */ function elgg_set_page_owner_guid($guid) { elgg_get_page_owner_guid($guid); } - /** - * Registers a page owner handler function + * Sets the page owner based on request * - * @param string $functionname The callback function + * Tries to figure out the page owner by looking at the URL or a request + * parameter. The request parameters used are 'username' and 'owner_guid'. If + * the page request is going through the page handling system, this function + * attempts to figure out the owner if the url fits the patterns of: + * <handler>/owner/<username> + * <handler>/friends/<username> + * <handler>/view/<entity guid> + * <handler>/add/<container guid> + * <handler>/edit/<entity guid> + * <handler>/group/<group guid> * - * @deprecated 1.8 Use the 'page_owner', 'system' plugin hook - * @return void - */ -function add_page_owner_handler($functionname) { - elgg_deprecated_notice("add_page_owner_handler() was deprecated by the plugin hook 'page_owner', 'system'.", 1.8); -} - -/** - * Set a page owner entity + * @note Access is disabled while finding the page owner for the group gatekeeper functions. * - * @param int $entitytoset The GUID of the entity - * - * @deprecated 1.8 Use elgg_set_page_owner_guid() - * @return void - */ -function set_page_owner($entitytoset = -1) { - elgg_deprecated_notice('set_page_owner() was deprecated by elgg_set_page_owner_guid().', 1.8); - elgg_set_page_owner_guid($entitytoset); -} - -/** - * Handles default page owners * - * @param string $hook page_owner - * @param string $entity_type system - * @param mixed $returnvalue Previous function's return value - * @param mixed $params Params + * @param string $hook 'page_owner' + * @param string $entity_type 'system' + * @param int $returnvalue Previous function's return value + * @param array $params no parameters * - * @return int + * @return int GUID + * @access private */ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) { @@ -127,17 +100,22 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) return $returnvalue; } + $ia = elgg_set_ignore_access(true); + $username = get_input("username"); if ($username) { + // @todo using a username of group:<guid> is deprecated if (substr_count($username, 'group:')) { preg_match('/group\:([0-9]+)/i', $username, $matches); $guid = $matches[1]; if ($entity = get_entity($guid)) { + elgg_set_ignore_access($ia); return $entity->getGUID(); } } if ($user = get_user_by_username($username)) { + elgg_set_ignore_access($ia); return $user->getGUID(); } } @@ -145,11 +123,53 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) $owner = get_input("owner_guid"); if ($owner) { if ($user = get_entity($owner)) { + elgg_set_ignore_access($ia); return $user->getGUID(); } } - return $returnvalue; + // ignore root and query + $uri = current_page_url(); + $path = str_replace(elgg_get_site_url(), '', $uri); + $path = trim($path, "/"); + if (strpos($path, "?")) { + $path = substr($path, 0, strpos($path, "?")); + } + + // @todo feels hacky + if (get_input('page', FALSE)) { + $segments = explode('/', $path); + if (isset($segments[1]) && isset($segments[2])) { + switch ($segments[1]) { + case 'owner': + case 'friends': + $user = get_user_by_username($segments[2]); + if ($user) { + elgg_set_ignore_access($ia); + return $user->getGUID(); + } + break; + case 'view': + case 'edit': + $entity = get_entity($segments[2]); + if ($entity) { + elgg_set_ignore_access($ia); + return $entity->getContainerGUID(); + } + break; + case 'add': + case 'group': + $entity = get_entity($segments[2]); + if ($entity) { + elgg_set_ignore_access($ia); + return $entity->getGUID(); + } + break; + } + } + } + + elgg_set_ignore_access($ia); } /** @@ -160,8 +180,8 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) * output could be different for those two contexts ('blog' vs 'widget'). * * Pages that pass through the page handling system set the context to the - * first string after 'pg'. Example: http://elgg.org/pg/bookmarks/ results in - * the initial context being set to 'bookmarks'. + * first string after the root url. Example: http://example.org/elgg/bookmarks/ + * results in the initial context being set to 'bookmarks'. * * The context is a stack so that for a widget on a profile, the context stack * may contain first 'profile' and then 'widget'. @@ -171,9 +191,9 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) * @warning The context is not available until the page_handler runs (after * the 'init, system' event processing has completed). * - * @param string $context The context of the page + * @param string $context The context of the page * @return bool - * @since 1.8 + * @since 1.8.0 */ function elgg_set_context($context) { global $CONFIG; @@ -198,11 +218,15 @@ function elgg_set_context($context) { * Since context is a stack, this is equivalent to a peek. * * @return string|NULL - * @since 1.8 + * @since 1.8.0 */ function elgg_get_context() { global $CONFIG; + if (!$CONFIG->context) { + return null; + } + return $CONFIG->context[count($CONFIG->context) - 1]; } @@ -210,7 +234,8 @@ function elgg_get_context() { * Push a context onto the top of the stack * * @param string $context The context string to add to the context stack - * @since 1.8 + * @return void + * @since 1.8.0 */ function elgg_push_context($context) { global $CONFIG; @@ -222,7 +247,7 @@ function elgg_push_context($context) { * Removes and returns the top context string from the stack * * @return string|NULL - * @since 1.8 + * @since 1.8.0 */ function elgg_pop_context() { global $CONFIG; @@ -238,9 +263,9 @@ function elgg_pop_context() { * itself differently based on being on the dashboard or profile pages, it * can check the stack. * - * @param string $context The context string to check for + * @param string $context The context string to check for * @return bool - * @since 1.8 + * @since 1.8.0 */ function elgg_in_context($context) { global $CONFIG; @@ -249,53 +274,24 @@ function elgg_in_context($context) { } /** - * Sets the functional context of a page - * - * @deprecated 1.8 Use elgg_set_context() - * - * @param string $context The context of the page - * - * @return mixed Either the context string, or false on failure - */ -function set_context($context) { - elgg_deprecated_notice('set_context() was deprecated by elgg_set_context().', 1.8); - elgg_set_context($context); - if (empty($context)) { - return false; - } - return $context; -} - -/** - * Returns the functional context of a page - * - * @deprecated 1.8 Use elgg_get_context() - * - * @return string The context, or 'main' if no context has been provided - */ -function get_context() { - elgg_deprecated_notice('get_context() was deprecated by elgg_get_context().', 1.8); - return elgg_get_context(); - - // @todo - used to set context based on calling script - // $context = get_plugin_name(true) -} - - -/** * Initializes the page owner functions * * @note This is on the 'boot, system' event so that the context is set up quickly. * * @return void + * @access private */ function page_owner_boot() { - global $CONFIG; - register_plugin_hook('page_owner', 'system', 'default_page_owner_handler'); - - // initial context - will be replaced by page handler - $CONFIG->context = array('main'); + elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler'); + + // Bootstrap the context stack by setting its first entry to the handler. + // This is the first segment of the URL and the handler is set by the rewrite rules. + // @todo this does not work for actions + $handler = get_input('handler', FALSE); + if ($handler) { + elgg_set_context($handler); + } } -register_elgg_event_handler('boot', 'system', 'page_owner_boot');
\ No newline at end of file +elgg_register_event_handler('boot', 'system', 'page_owner_boot'); |
