aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 22:00:35 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-20 22:00:35 +0000
commit6d4d67605bc2804df5a0e48e910c72b79eb40108 (patch)
tree03ada780f28bedcbfb41771e61e97b5ba2dfa4a2 /engine/lib
parent30264aed3809e54fc2246f7ae3e588f13e820db6 (diff)
downloadelgg-6d4d67605bc2804df5a0e48e910c72b79eb40108.tar.gz
elgg-6d4d67605bc2804df5a0e48e910c72b79eb40108.tar.bz2
added code to figure out page owner rather than explicitly setting in all the plugin page handlers
git-svn-id: http://code.elgg.org/elgg/trunk@8370 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/pageowner.php56
1 files changed, 50 insertions, 6 deletions
diff --git a/engine/lib/pageowner.php b/engine/lib/pageowner.php
index 3f0c58a5d..034349d67 100644
--- a/engine/lib/pageowner.php
+++ b/engine/lib/pageowner.php
@@ -26,6 +26,7 @@ function elgg_get_page_owner_guid($guid = 0) {
return $page_owner_guid;
}
+ // return guid of page owner entity
$guid = elgg_trigger_plugin_hook('page_owner', 'system', NULL, 0);
$page_owner_guid = $guid;
@@ -61,14 +62,26 @@ function elgg_set_page_owner_guid($guid) {
}
/**
- * Handles default page owners
+ * Sets the page owner based on request
*
- * @param string $hook page_owner
- * @param string $entity_type system
- * @param mixed $returnvalue Previous function's return value
- * @param mixed $params Params
+ * 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:
+ * pg/<handler>/owner/<username>
+ * pg/<handler>/friends/<username>
+ * pg/<handler>/view/<entity guid>
+ * pg/<handler>/add/<container guid>
+ * pg/<handler>/edit/<entity guid>
+ * pg/<handler>/group/<group guid>
*
- * @return int
+ *
+ * @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 GUID
*/
function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
@@ -78,6 +91,7 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
$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];
@@ -98,6 +112,36 @@ function default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
}
}
+ $uri = $_SERVER['REQUEST_URI'];
+ if (strpos($uri, '/pg') === 0) {
+ $segments = explode('/', $uri);
+ if (isset($segments[3]) && isset($segments[4])) {
+ switch ($segments[3]) {
+ case 'owner':
+ case 'friends':
+ $user = get_user_by_username($segments[4]);
+ if ($user) {
+ return $user->getGUID();
+ }
+ break;
+ case 'view':
+ case 'edit':
+ $entity = get_entity($segments[4]);
+ if ($entity) {
+ return $entity->getContainerGUID();
+ }
+ break;
+ case 'add':
+ case 'group':
+ $entity = get_entity($segments[4]);
+ if ($entity) {
+ return $entity->getGUID();
+ }
+ break;
+ }
+ }
+ }
+
return $returnvalue;
}