aboutsummaryrefslogtreecommitdiff
path: root/engine/classes
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes')
-rw-r--r--engine/classes/ElggEntity.php22
-rw-r--r--engine/classes/ElggGroup.php17
-rw-r--r--engine/classes/ElggObject.php35
-rw-r--r--engine/classes/ElggUser.php17
4 files changed, 91 insertions, 0 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php
index d6c8a1311..0298d6d6e 100644
--- a/engine/classes/ElggEntity.php
+++ b/engine/classes/ElggEntity.php
@@ -935,6 +935,28 @@ abstract class ElggEntity extends ElggData implements
}
/**
+ * Can a user comment on an entity
+ *
+ * @tip Can be overridden vy registering for the permissions_check:comment,
+ * <entity type> plugin hook.
+ *
+ * @param int $user_guid User guid (default is logged in user)
+ *
+ * @return bool
+ */
+ public function canComment($user_guid = 0) {
+ if ($user_guid == 0) {
+ $user_guid = elgg_get_logged_in_user_guid();
+ }
+ $user = get_entity($user_guid);
+
+ // By default, we don't take a position of whether commenting is allowed
+ // because it is handled by the subclasses of ElggEntity
+ $params = array('entity' => $this, 'user' => $user);
+ return elgg_trigger_plugin_hook('permissions_check:comment', $this->type, $params, null);
+ }
+
+ /**
* Returns the access_id.
*
* @return int The access ID
diff --git a/engine/classes/ElggGroup.php b/engine/classes/ElggGroup.php
index c709eb3a6..49ba27204 100644
--- a/engine/classes/ElggGroup.php
+++ b/engine/classes/ElggGroup.php
@@ -380,4 +380,21 @@ class ElggGroup extends ElggEntity
'description',
));
}
+
+ /**
+ * Can a user comment on this group?
+ *
+ * @see ElggEntity::canComment()
+ *
+ * @param int $user_guid User guid (default is logged in user)
+ * @return bool
+ * @since 1.8.0
+ */
+ public function canComment($user_guid = 0) {
+ $result = parent::canComment($user_guid);
+ if ($result !== null) {
+ return $result;
+ }
+ return false;
+ }
}
diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php
index c47cd217f..f71801144 100644
--- a/engine/classes/ElggObject.php
+++ b/engine/classes/ElggObject.php
@@ -184,4 +184,39 @@ class ElggObject extends ElggEntity {
'description',
));
}
+
+ /**
+ * Can a user comment on this object?
+ *
+ * @see ElggEntity::canComment()
+ *
+ * @param int $user_guid User guid (default is logged in user)
+ * @return bool
+ * @since 1.8.0
+ */
+ public function canComment($user_guid = 0) {
+ $result = parent::canComment($user_guid);
+ if ($result !== null) {
+ return $result;
+ }
+
+ if ($user_guid == 0) {
+ $user_guid = elgg_get_logged_in_user_guid();
+ }
+
+ // must be logged in to comment
+ if (!$user_guid) {
+ return false;
+ }
+
+ // must be member of group
+ if (elgg_instanceof($this->getContainerEntity(), 'group')) {
+ if (!$this->getContainerEntity()->isMember(get_user($user_guid))) {
+ return false;
+ }
+ }
+
+ // no checks on read access since a user cannot see entities outside his access
+ return true;
+ }
}
diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php
index 82f03c6ed..cceaacf58 100644
--- a/engine/classes/ElggUser.php
+++ b/engine/classes/ElggUser.php
@@ -559,4 +559,21 @@ class ElggUser extends ElggEntity
return parent::__get($name);
}
+
+ /**
+ * Can a user comment on this user?
+ *
+ * @see ElggEntity::canComment()
+ *
+ * @param int $user_guid User guid (default is logged in user)
+ * @return bool
+ * @since 1.8.0
+ */
+ public function canComment($user_guid = 0) {
+ $result = parent::canComment($user_guid);
+ if ($result !== null) {
+ return $result;
+ }
+ return false;
+ }
}