aboutsummaryrefslogtreecommitdiff
path: root/mod/groups
diff options
context:
space:
mode:
Diffstat (limited to 'mod/groups')
-rw-r--r--mod/groups/icon.php6
-rw-r--r--mod/groups/languages/en.php10
-rw-r--r--mod/groups/start.php142
-rw-r--r--mod/groups/topicposts.php2
4 files changed, 127 insertions, 33 deletions
diff --git a/mod/groups/icon.php b/mod/groups/icon.php
index f86f84fa5..1bd240ea6 100644
--- a/mod/groups/icon.php
+++ b/mod/groups/icon.php
@@ -8,7 +8,13 @@
require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
$group_guid = get_input('group_guid');
+
+/* @var ElggGroup $group */
$group = get_entity($group_guid);
+if (!($group instanceof ElggGroup)) {
+ header("HTTP/1.1 404 Not Found");
+ exit;
+}
// If is the same ETag, content didn't changed.
$etag = $group->icontime . $group_guid;
diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php
index e51e51a14..88aeccb54 100644
--- a/mod/groups/languages/en.php
+++ b/mod/groups/languages/en.php
@@ -64,6 +64,7 @@ $english = array(
'groups:search_in_group' => "Search in this group",
'groups:acl' => "Group: %s",
+ 'discussion:notification:topic:subject' => 'New group discussion post',
'groups:notification' =>
'%s added a new discussion topic to %s:
@@ -74,6 +75,15 @@ View and reply to the discussion:
%s
',
+ 'discussion:notification:reply:body' =>
+'%s replied to the discussion topic %s in the group %s:
+
+%s
+
+View and reply to the discussion:
+%s
+',
+
'groups:activity' => "Group activity",
'groups:enableactivity' => 'Enable group activity',
'groups:activity:none' => "There is no group activity yet",
diff --git a/mod/groups/start.php b/mod/groups/start.php
index c8198371b..d85bb6492 100644
--- a/mod/groups/start.php
+++ b/mod/groups/start.php
@@ -93,7 +93,6 @@ function groups_init() {
elgg_register_event_handler('join', 'group', 'groups_user_join_event_listener');
elgg_register_event_handler('leave', 'group', 'groups_user_leave_event_listener');
elgg_register_event_handler('pagesetup', 'system', 'groups_setup_sidebar_menus');
- elgg_register_event_handler('annotate', 'all', 'group_object_notifications');
elgg_register_plugin_hook_handler('access:collections:add_user', 'collection', 'groups_access_collection_override');
@@ -284,12 +283,21 @@ function groups_url($entity) {
* @return string Relative URL
*/
function groups_icon_url_override($hook, $type, $returnvalue, $params) {
+ /* @var ElggGroup $group */
$group = $params['entity'];
$size = $params['size'];
- if (isset($group->icontime)) {
+ $icontime = $group->icontime;
+ // handle missing metadata (pre 1.7 installations)
+ if (null === $icontime) {
+ $file = new ElggFile();
+ $file->owner_guid = $group->owner_guid;
+ $file->setFilename("groups/" . $group->guid . "large.jpg");
+ $icontime = $file->exists() ? time() : 0;
+ create_metadata($group->guid, 'icontime', $icontime, 'integer', $group->owner_guid, ACCESS_PUBLIC);
+ }
+ if ($icontime) {
// return thumbnail
- $icontime = $group->icontime;
return "groupicon/$group->guid/$size/$icontime.jpg";
}
@@ -741,8 +749,10 @@ function discussion_init() {
elgg_extend_view('groups/tool_latest', 'discussion/group_module');
// notifications
- register_notification_object('object', 'groupforumtopic', elgg_echo('groupforumtopic:new'));
+ register_notification_object('object', 'groupforumtopic', elgg_echo('discussion:notification:topic:subject'));
elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'groupforumtopic_notify_message');
+ elgg_register_event_handler('create', 'annotation', 'discussion_reply_notifications');
+ elgg_register_plugin_hook_handler('notify:annotation:message', 'group_topic_post', 'discussion_create_reply_notification');
}
/**
@@ -863,36 +873,16 @@ function discussion_add_to_river_menu($hook, $type, $return, $params) {
}
/**
- * Event handler for group forum posts
+ * Create discussion notification body
*
- */
-function group_object_notifications($event, $object_type, $object) {
-
- static $flag;
- if (!isset($flag)) {
- $flag = 0;
- }
-
- if (is_callable('object_notifications'))
- if ($object instanceof ElggObject) {
- if ($object->getSubtype() == 'groupforumtopic') {
- if ($flag == 0) {
- $flag = 1;
- object_notifications($event, $object_type, $object);
- }
- }
- }
-}
-
-/**
- * Returns a more meaningful message
+ * @todo namespace method with 'discussion'
*
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
+ * @param string $hook
+ * @param string $type
+ * @param string $message
+ * @param array $params
*/
-function groupforumtopic_notify_message($hook, $entity_type, $returnvalue, $params) {
+function groupforumtopic_notify_message($hook, $type, $message, $params) {
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
@@ -912,11 +902,99 @@ function groupforumtopic_notify_message($hook, $entity_type, $returnvalue, $para
$entity->getURL()
));
}
-
+
return null;
}
/**
+ * Create discussion reply notification body
+ *
+ * @param string $hook
+ * @param string $type
+ * @param string $message
+ * @param array $params
+ */
+function discussion_create_reply_notification($hook, $type, $message, $params) {
+ $reply = $params['annotation'];
+ $method = $params['method'];
+ $topic = $reply->getEntity();
+ $poster = $reply->getOwnerEntity();
+ $group = $topic->getContainerEntity();
+
+ return elgg_echo('discussion:notification:reply:body', array(
+ $poster->name,
+ $topic->title,
+ $group->name,
+ $reply->value,
+ $topic->getURL(),
+ ));
+}
+
+/**
+ * Catch reply to discussion topic and generate notifications
+ *
+ * @todo this will be replaced in Elgg 1.9 and is a clone of object_notifications()
+ *
+ * @param string $event
+ * @param string $type
+ * @param ElggAnnotation $annotation
+ * @return void
+ */
+function discussion_reply_notifications($event, $type, $annotation) {
+ global $CONFIG, $NOTIFICATION_HANDLERS;
+
+ // Have we registered notifications for this type of entity?
+ $object_type = 'object';
+ $object_subtype = 'groupforumtopic';
+
+ $topic = $annotation->getEntity();
+ if (!$topic) {
+ return;
+ }
+
+ $poster = $annotation->getOwnerEntity();
+ if (!$poster) {
+ return;
+ }
+
+ if (isset($CONFIG->register_objects[$object_type][$object_subtype])) {
+ $subject = $CONFIG->register_objects[$object_type][$object_subtype];
+ $string = $subject . ": " . $topic->getURL();
+
+ // Get users interested in content from this person and notify them
+ // (Person defined by container_guid so we can also subscribe to groups if we want)
+ foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
+ $interested_users = elgg_get_entities_from_relationship(array(
+ 'relationship' => 'notify' . $method,
+ 'relationship_guid' => $topic->getContainerGUID(),
+ 'inverse_relationship' => true,
+ 'types' => 'user',
+ 'limit' => 0,
+ ));
+
+ if ($interested_users && is_array($interested_users)) {
+ foreach ($interested_users as $user) {
+ if ($user instanceof ElggUser && !$user->isBanned()) {
+ if (($user->guid != $poster->guid) && has_access_to_entity($topic, $user) && $topic->access_id != ACCESS_PRIVATE) {
+ $body = elgg_trigger_plugin_hook('notify:annotation:message', $annotation->getSubtype(), array(
+ 'annotation' => $annotation,
+ 'to_entity' => $user,
+ 'method' => $method), $string);
+ if (empty($body) && $body !== false) {
+ $body = $string;
+ }
+ if ($body !== false) {
+ notify_user($user->guid, $topic->getContainerGUID(), $subject, $body, null, array($method));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
* A simple function to see who can edit a group discussion post
* @param the comment $entity
* @param user who owns the group $group_owner
diff --git a/mod/groups/topicposts.php b/mod/groups/topicposts.php
index 81c860631..d0137e2f5 100644
--- a/mod/groups/topicposts.php
+++ b/mod/groups/topicposts.php
@@ -16,4 +16,4 @@ $guid = get_input('topic');
register_error(elgg_echo('changebookmark'));
-topic_handle_view_page($guid);
+forward("/discussion/view/$guid");