aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-07 14:40:53 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-07 14:40:53 +0000
commit389b0a5862a9f4130ca0765ba6155d81bd84499b (patch)
treee6991259eb924e3e6c44ea08f5dc3c6862fac8f5 /engine/lib
parentdba0e07bd47324501123090ef6159b07a672d004 (diff)
downloadelgg-389b0a5862a9f4130ca0765ba6155d81bd84499b.tar.gz
elgg-389b0a5862a9f4130ca0765ba6155d81bd84499b.tar.bz2
Properly extensible canEdit functionality for metadata, annotations, and anything else that supports the ElggExtender interface
git-svn-id: https://code.elgg.org/elgg/trunk@410 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/annotations.php3
-rw-r--r--engine/lib/extender.php36
-rw-r--r--engine/lib/metadata.php35
3 files changed, 41 insertions, 33 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 3f965ec6d..f2b9e16fb 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -40,7 +40,8 @@
$objarray = (array) $annotation;
foreach($objarray as $key => $value) {
$this->attributes[$key] = $value;
- }
+ }
+ $this->attributes['type'] = "annotation";
}
}
}
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index 4f588acdd..aca8a0fca 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -69,6 +69,16 @@
* Delete this data.
*/
abstract public function delete();
+
+ /**
+ * Determines whether or not the specified user can edit this
+ *
+ * @param int $user_guid The GUID of the user (defaults to currently logged in user)
+ * @return true|false
+ */
+ function canEdit($user_guid = 0) {
+ return can_edit_extender($this->id,$this->type,$user_guid);
+ }
public function export()
{
@@ -145,6 +155,32 @@
return $tmp;
}
}
+
+ /**
+ * Determines whether or not the specified user can edit the specified piece of extender
+ *
+ * @param int $extender_id The ID of the piece of extender
+ * @param string $type 'metadata' or 'annotation'
+ * @param int $user_guid The GUID of the user
+ * @return true|false
+ */
+ function can_edit_extender($extender_id, $type, $user_guid = 0) {
+
+ if ($user_guid == 0) {
+ $user = $_SESSION['user'];
+ } else {
+ $user = get_entity($user_guid);
+ }
+ $functionname = "get_{$type}";
+ if (is_callable($functionname)) {
+ $extender = $functionname($extender_id);
+ } else return false;
+
+ if ($extender->getOwner() == $user->getGUID()) return true;
+
+ return trigger_plugin_hook('permissions_check',$type,array('entity' => $entity, 'user' => $user),false);
+
+ }
/** Register the hook */
register_plugin_hook("import", "all", "import_extender_plugin_hook", 2);
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 99153a98a..3b84d3575 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -39,7 +39,8 @@
$objarray = (array) $metadata;
foreach($objarray as $key => $value) {
$this->attributes[$key] = $value;
- }
+ }
+ $this->attributes['type'] = "metadata";
}
}
}
@@ -73,38 +74,8 @@
return delete_metadata($this->id);
}
- /**
- * Determines whether or not the specified user can edit this
- *
- * @param int $user_guid The GUID of the user (defaults to currently logged in user)
- * @return true|false
- */
- function canEdit($user_guid = 0) {
- return can_edit_metadata($this->id,$user_guid);
- }
-
- }
-
- /**
- * Determines whether or not the specified user can edit the specified piece of metadata
- *
- * @param int $metadata_id The ID of the piece of metadata
- * @param int $user_guid The GUID of the user
- * @return true|false
- */
- function can_edit_metadata($metadata_id, $user_guid = 0) {
-
- if ($user_guid == 0) {
- $user = $_SESSION['user'];
- } else {
- $user = get_entity($user_guid);
- }
- $metadata = get_metadata($metadata_id);
-
- if ($metadata->owner_guid == $user->getGUID()) return true;
-
- return trigger_plugin_hook('permissions_check','metadata',array('entity' => $entity, 'user' => $user),false);
+
}
/**