aboutsummaryrefslogtreecommitdiff
path: root/mod/messages
diff options
context:
space:
mode:
Diffstat (limited to 'mod/messages')
-rw-r--r--mod/messages/actions/delete.php65
-rw-r--r--mod/messages/actions/messages/delete.php20
-rw-r--r--mod/messages/actions/messages/process.php35
-rw-r--r--mod/messages/actions/messages/send.php46
-rw-r--r--mod/messages/actions/send.php57
-rw-r--r--mod/messages/index.php49
-rw-r--r--mod/messages/languages/en.php26
-rw-r--r--mod/messages/lib/messages.php32
-rw-r--r--mod/messages/manifest.xml23
-rw-r--r--mod/messages/pages/messages/inbox.php48
-rw-r--r--mod/messages/pages/messages/read.php60
-rw-r--r--mod/messages/pages/messages/send.php27
-rw-r--r--mod/messages/pages/messages/sent.php48
-rw-r--r--mod/messages/read.php54
-rw-r--r--mod/messages/readme.txt24
-rw-r--r--mod/messages/send.php38
-rw-r--r--mod/messages/sent.php40
-rw-r--r--mod/messages/start.php625
-rw-r--r--mod/messages/views/default/forms/messages/process.php43
-rw-r--r--mod/messages/views/default/forms/messages/reply.php38
-rw-r--r--mod/messages/views/default/forms/messages/send.php54
-rw-r--r--mod/messages/views/default/messages/css.php114
-rw-r--r--mod/messages/views/default/messages/forms/reply.php44
-rw-r--r--mod/messages/views/default/messages/forms/send.php70
-rw-r--r--mod/messages/views/default/messages/forms/view.php22
-rw-r--r--mod/messages/views/default/messages/js.php7
-rw-r--r--mod/messages/views/default/messages/menu.php12
-rw-r--r--mod/messages/views/default/messages/messages.php117
-rw-r--r--mod/messages/views/default/messages/topbar.php26
-rw-r--r--mod/messages/views/default/messages/view.php121
-rw-r--r--mod/messages/views/default/object/messages.php86
31 files changed, 1001 insertions, 1070 deletions
diff --git a/mod/messages/actions/delete.php b/mod/messages/actions/delete.php
deleted file mode 100644
index d59aff025..000000000
--- a/mod/messages/actions/delete.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-/**
-* Elgg delete a message action page
-* It is worth noting that due to the nature of a messaging system and the fact 2 people access
-* the same message, messages don't actually delete, they are just removed from view for the user who deletes
-*
-* @package ElggMessages
-*/
-
-// Need to be logged in to do this
-gatekeeper();
-
-// grab details sent from the form
-$message_id_array = get_input('message_id');
-if (!is_array($message_id_array)) $message_id_array = array($message_id_array);
-$type = get_input('type'); // sent message or inbox
-$success = true;
-$submit = get_input('submit');
-$offset = get_input('offset');
-
-foreach($message_id_array as $message_id) {
-
-// get the message object
- $message = get_entity($message_id);
-
-// Make sure we actually have permission to edit and that the object is of sub-type messages
- if ($message && $message->getSubtype() == "messages") {
-
- if ($submit == elgg_echo('delete')) {
- if ($message->delete()) {
- } else {
- $success = false;
- }
- } else {
- if ($message->readYet = 1) {
- } else {
- $success = false;
- }
- }
-
- }else{
-
- // display the error message
- $success = false;
-
- }
-
-}
-
-if ($success) {
- if ($submit == elgg_echo('delete')) {
- system_message(elgg_echo("messages:deleted"));
- } else {
- system_message(elgg_echo("messages:markedread"));
- }
- // check to see if it is a sent message to be deleted
- if($type == 'sent'){
- forward("mod/messages/sent.php?offset={$offset}");
- }else{
- forward("mod/messages/?username=" . get_loggedin_user()->username . "&offset={$offset}");
- }
-} else {
- register_error(elgg_echo("messages:notfound"));
- forward(REFERER);
-} \ No newline at end of file
diff --git a/mod/messages/actions/messages/delete.php b/mod/messages/actions/messages/delete.php
new file mode 100644
index 000000000..ffdb3b3a3
--- /dev/null
+++ b/mod/messages/actions/messages/delete.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Delete message
+ */
+
+$guid = (int) get_input('guid');
+
+$message = get_entity($guid);
+if (!$message || !$message->canEdit()) {
+ register_error(elgg_echo('messages:error:delete:single'));
+ forward(REFERER);
+}
+
+if (!$message->delete()) {
+ register_error(elgg_echo('messages:error:delete:single'));
+} else {
+ system_message(elgg_echo('messages:success:delete:single'));
+}
+
+forward(REFERER);
diff --git a/mod/messages/actions/messages/process.php b/mod/messages/actions/messages/process.php
new file mode 100644
index 000000000..d929ae190
--- /dev/null
+++ b/mod/messages/actions/messages/process.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Process a set of messages
+ */
+
+$message_ids = get_input('message_id', array());
+
+if (!$message_ids) {
+ register_error(elgg_echo('messages:error:messages_not_selected'));
+ forward(REFERER);
+}
+
+$delete_flag = get_input('delete', false);
+$read_flag = get_input('read', false);
+
+if ($delete_flag) {
+ $success_msg = elgg_echo('messages:success:delete');
+ foreach ($message_ids as $guid) {
+ $message = get_entity($guid);
+ if ($message && $message->getSubtype() == 'messages' && $message->canEdit()) {
+ $message->delete();
+ }
+ }
+} else {
+ $success_msg = elgg_echo('messages:success:read');
+ foreach ($message_ids as $guid) {
+ $message = get_entity($guid);
+ if ($message && $message->getSubtype() == 'messages' && $message->canEdit()) {
+ $message->readYet = 1;
+ }
+ }
+}
+
+system_message($success_msg);
+forward(REFERER);
diff --git a/mod/messages/actions/messages/send.php b/mod/messages/actions/messages/send.php
new file mode 100644
index 000000000..9d9f6c8b7
--- /dev/null
+++ b/mod/messages/actions/messages/send.php
@@ -0,0 +1,46 @@
+<?php
+/**
+* Ssend a message action
+*
+* @package ElggMessages
+*/
+
+$subject = strip_tags(get_input('subject'));
+$body = get_input('body');
+$recipient_guid = get_input('recipient_guid');
+
+elgg_make_sticky_form('messages');
+
+//$reply = get_input('reply',0); // this is the guid of the message replying to
+
+if (!$recipient_guid) {
+ register_error(elgg_echo("messages:user:blank"));
+ forward("messages/compose");
+}
+
+$user = get_user($recipient_guid);
+if (!$user) {
+ register_error(elgg_echo("messages:user:nonexist"));
+ forward("messages/compose");
+}
+
+// Make sure the message field, send to field and title are not blank
+if (!$body || !$subject) {
+ register_error(elgg_echo("messages:blank"));
+ forward("messages/compose");
+}
+
+// Otherwise, 'send' the message
+$result = messages_send($subject, $body, $recipient_guid, 0, $reply);
+
+// Save 'send' the message
+if (!$result) {
+ register_error(elgg_echo("messages:error"));
+ forward("messages/compose");
+}
+
+elgg_clear_sticky_form('messages');
+
+system_message(elgg_echo("messages:posted"));
+
+forward('messages/inbox/' . elgg_get_logged_in_user_entity()->username);
diff --git a/mod/messages/actions/send.php b/mod/messages/actions/send.php
deleted file mode 100644
index 59d90a9d2..000000000
--- a/mod/messages/actions/send.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
-* Elgg send a message action page
-*
-* @package ElggMessages
-*/
-
-// Make sure we're logged in (send us to the front page if not)
-if (!isloggedin()) forward();
-
-// Get input data
-$title = strip_tags(get_input('title')); // message title
-$message_contents = get_input('message'); // the message
-$send_to = get_input('send_to'); // this is the user guid to whom the message is going to be sent
-$reply = get_input('reply',0); // this is the guid of the message replying to
-
-// Cache to the session to make form sticky
-$_SESSION['msg_to'] = $send_to;
-$_SESSION['msg_title'] = $title;
-$_SESSION['msg_contents'] = $message_contents;
-
-if (empty($send_to)) {
- register_error(elgg_echo("messages:user:blank"));
- forward("mod/messages/send.php");
-}
-
-$user = get_user($send_to);
-if (!$user) {
- register_error(elgg_echo("messages:user:nonexist"));
- forward("mod/messages/send.php");
-}
-
-// Make sure the message field, send to field and title are not blank
-if (empty($message_contents) || empty($title)) {
- register_error(elgg_echo("messages:blank"));
- forward("mod/messages/send.php");
-}
-
-// Otherwise, 'send' the message
-$result = messages_send($title,$message_contents,$send_to,0,$reply);
-
-// Save 'send' the message
-if (!$result) {
- register_error(elgg_echo("messages:error"));
- forward("mod/messages/send.php");
-}
-
-// successful so uncache form values
-unset($_SESSION['msg_to']);
-unset($_SESSION['msg_title']);
-unset($_SESSION['msg_contents']);
-
-// Success message
-system_message(elgg_echo("messages:posted"));
-
-// Forward to the users inbox
-forward('mod/messages/sent.php');
diff --git a/mod/messages/index.php b/mod/messages/index.php
deleted file mode 100644
index 5f4a483be..000000000
--- a/mod/messages/index.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Elgg messages inbox page
- *
- * @package ElggMessages
-*/
-
-
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-gatekeeper();
-global $CONFIG;
-
-$offset = get_input('offset', 0);
-$limit = 10;
-
-// Get the logged in user, you can't see other peoples messages so use session id
-$page_owner = get_loggedin_user();
-set_page_owner($page_owner->getGUID());
-
-// Get the user's inbox, this will be all messages where the 'toId' field matches their guid
-// @todo - fix hack where limit + 1 messages are requested
-$messages = elgg_get_entities_from_metadata(array(
- 'type' => 'object',
- 'subtype' => 'messages',
- 'metadata_name' => 'toId',
- 'metadata_value' => $page_owner->getGUID(),
- 'owner_guid' => $page_owner->guid,
- 'limit' => $limit + 1,
- 'offset' => $offset
-));
-
-// Set the page title
-$area2 = "<div id='content_header'><div class='content_header_title'>";
-$area2 .= elgg_view_title(elgg_echo("messages:inbox"))."</div>";
-$area2 .= "<div class='content_header_options'><a class='action_button' href='".elgg_get_site_url()."mod/messages/send.php'>" . elgg_echo('messages:compose') . "</a></div></div>";
-
-// Display them. The last variable 'page_view' is to allow the view page to know where this data is coming from,
-// in this case it is the inbox, this is necessary to ensure the correct display
-$area2 .= elgg_view("messages/forms/view",array('entity' => $messages, 'page_view' => "inbox", 'limit' => $limit, 'offset' => $offset));
-
-// Sidebar menu options
-//$area3 = elgg_view("messages/menu_options", array('context' => 'inbox'));
-
-// format
-$body = elgg_view_layout("one_column_with_sidebar", $area2);
-
-
-// Draw page
-echo elgg_view_page(sprintf(elgg_echo('messages:user'),$page_owner->name),$body);
diff --git a/mod/messages/languages/en.php b/mod/messages/languages/en.php
index f1ad22623..7732a9dce 100644
--- a/mod/messages/languages/en.php
+++ b/mod/messages/languages/en.php
@@ -11,15 +11,15 @@ $english = array(
*/
'messages' => "Messages",
+ 'messages:unreadcount' => "%s unread",
'messages:back' => "back to messages",
- 'messages:user' => "Your inbox",
- 'messages:sentMessages' => "Sent messages",
+ 'messages:user' => "%s's inbox",
'messages:posttitle' => "%s's messages: %s",
'messages:inbox' => "Inbox",
- 'messages:send' => "Send a message",
- 'messages:sent' => "Sent messages",
+ 'messages:send' => "Send",
+ 'messages:sent' => "Sent",
'messages:message' => "Message",
- 'messages:title' => "Title",
+ 'messages:title' => "Subject",
'messages:to' => "To",
'messages:from' => "From",
'messages:fly' => "Send",
@@ -27,6 +27,7 @@ $english = array(
'messages:inbox' => "Inbox",
'messages:sendmessage' => "Send a message",
'messages:compose' => "Compose a message",
+ 'messages:add' => "Compose a message",
'messages:sentmessages' => "Sent messages",
'messages:recent' => "Recent messages",
'messages:original' => "Original message",
@@ -35,10 +36,11 @@ $english = array(
'messages:toggle' => 'Toggle all',
'messages:markread' => 'Mark read',
'messages:recipient' => 'Choose a recipient&hellip;',
+ 'messages:to_user' => 'To: %s',
'messages:new' => 'New message',
- 'notification:method:site' => 'Messages',
+ 'notification:method:site' => 'Site',
'messages:error' => 'There was a problem saving your message. Please try again.',
@@ -49,8 +51,11 @@ $english = array(
*/
'messages:posted' => "Your message was successfully sent.",
- 'messages:deleted' => "Your messages were successfully deleted.",
- 'messages:markedread' => "Your messages were successfully marked as read.",
+ 'messages:success:delete:single' => 'Message was deleted',
+ 'messages:success:delete' => 'Messages deleted',
+ 'messages:success:read' => 'Messages marked as read',
+ 'messages:error:messages_not_selected' => 'No messages selected',
+ 'messages:error:delete:single' => 'Unable to delete the message',
/**
* Email messages
@@ -81,9 +86,12 @@ $english = array(
'messages:notfound' => "Sorry; we could not find the specified message.",
'messages:notdeleted' => "Sorry; we could not delete this message.",
'messages:nopermission' => "You do not have permission to alter that message.",
- 'messages:nomessages' => "There are no messages to display.",
+ 'messages:nomessages' => "There are no messages.",
'messages:user:nonexist' => "We could not find the recipient in the user database.",
'messages:user:blank' => "You did not select someone to send this to.",
+
+ 'messages:deleted_sender' => 'Deleted user',
+
);
add_translation("en", $english); \ No newline at end of file
diff --git a/mod/messages/lib/messages.php b/mod/messages/lib/messages.php
new file mode 100644
index 000000000..062670fe9
--- /dev/null
+++ b/mod/messages/lib/messages.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Messages helper functions
+ *
+ * @package ElggMessages
+ */
+
+/**
+ * Prepare the compose form variables
+ *
+ * @return array
+ */
+function messages_prepare_form_vars($recipient_guid = 0) {
+
+ // input names => defaults
+ $values = array(
+ 'subject' => '',
+ 'body' => '',
+ 'recipient_guid' => $recipient_guid,
+ );
+
+ if (elgg_is_sticky_form('messages')) {
+ foreach (array_keys($values) as $field) {
+ $values[$field] = elgg_get_sticky_value('messages', $field);
+ }
+ }
+
+ elgg_clear_sticky_form('messages');
+
+ return $values;
+}
+
diff --git a/mod/messages/manifest.xml b/mod/messages/manifest.xml
index 0c8731e76..6e3462901 100644
--- a/mod/messages/manifest.xml
+++ b/mod/messages/manifest.xml
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
-<plugin_manifest>
- <field key="version" value="1.7" />
- <field key="description" value="Elgg internal messages plugin. This plugin lets user send each other messages." />
- <field key="website" value="http://www.elgg.org/" />
- <field key="licence" value="GNU Public License version 2" />
- <field key="elgg_version" value="2010030101" />
- <field key="elgg_install_state" value="enabled" />
- <field key="admin_interface" value="simple" />
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Messages</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <category>communication</category>
+ <description>Elgg internal messages plugin. This plugin lets user send each other messages.</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+ <activate_on_install>true</activate_on_install>
</plugin_manifest>
diff --git a/mod/messages/pages/messages/inbox.php b/mod/messages/pages/messages/inbox.php
new file mode 100644
index 000000000..de5b8b231
--- /dev/null
+++ b/mod/messages/pages/messages/inbox.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Elgg messages inbox page
+ *
+ * @package ElggMessages
+*/
+
+gatekeeper();
+
+$page_owner = elgg_get_page_owner_entity();
+
+if (!$page_owner || !$page_owner->canEdit()) {
+ $guid = 0;
+ if($page_owner){
+ $guid = $page_owner->getGUID();
+ }
+ register_error(elgg_echo("pageownerunavailable", array($guid)));
+ forward();
+}
+
+elgg_push_breadcrumb(elgg_echo('messages:inbox'));
+
+elgg_register_title_button();
+
+$title = elgg_echo('messages:user', array($page_owner->name));
+
+$list = elgg_list_entities_from_metadata(array(
+ 'type' => 'object',
+ 'subtype' => 'messages',
+ 'metadata_name' => 'toId',
+ 'metadata_value' => elgg_get_page_owner_guid(),
+ 'owner_guid' => elgg_get_page_owner_guid(),
+ 'full_view' => false,
+));
+
+$body_vars = array(
+ 'folder' => 'inbox',
+ 'list' => $list,
+);
+$content = elgg_view_form('messages/process', array(), $body_vars);
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => elgg_echo('messages:inbox'),
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/messages/pages/messages/read.php b/mod/messages/pages/messages/read.php
new file mode 100644
index 000000000..4223c6bac
--- /dev/null
+++ b/mod/messages/pages/messages/read.php
@@ -0,0 +1,60 @@
+<?php
+/**
+* Read a message page
+*
+* @package ElggMessages
+*/
+
+gatekeeper();
+
+$message = get_entity(get_input('guid'));
+if (!$message || !elgg_instanceof($message, "object", "messages")) {
+ forward('messages/inbox/' . elgg_get_logged_in_user_entity()->username);
+}
+
+// mark the message as read
+$message->readYet = true;
+
+elgg_set_page_owner_guid($message->getOwnerGUID());
+$page_owner = elgg_get_page_owner_entity();
+
+$title = $message->title;
+
+$inbox = false;
+if ($page_owner->getGUID() == $message->toId) {
+ $inbox = true;
+ elgg_push_breadcrumb(elgg_echo('messages:inbox'), 'messages/inbox/' . $page_owner->username);
+} else {
+ elgg_push_breadcrumb(elgg_echo('messages:sent'), 'messages/sent/' . $page_owner->username);
+}
+elgg_push_breadcrumb($title);
+
+$content = elgg_view_entity($message, array('full_view' => true));
+if ($inbox) {
+ $form_params = array(
+ 'id' => 'messages-reply-form',
+ 'class' => 'hidden mtl',
+ 'action' => 'action/messages/send',
+ );
+ $body_params = array('message' => $message);
+ $content .= elgg_view_form('messages/reply', $form_params, $body_params);
+ $from_user = get_user($message->fromId);
+
+ if ((elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) && $from_user) {
+ elgg_register_menu_item('title', array(
+ 'name' => 'reply',
+ 'href' => '#messages-reply-form',
+ 'text' => elgg_echo('messages:answer'),
+ 'link_class' => 'elgg-button elgg-button-action',
+ 'rel' => 'toggle',
+ ));
+ }
+}
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/messages/pages/messages/send.php b/mod/messages/pages/messages/send.php
new file mode 100644
index 000000000..b46d0ba52
--- /dev/null
+++ b/mod/messages/pages/messages/send.php
@@ -0,0 +1,27 @@
+<?php
+/**
+* Compose a message
+*
+* @package ElggMessages
+*/
+
+gatekeeper();
+
+$page_owner = elgg_get_logged_in_user_entity();
+elgg_set_page_owner_guid($page_owner->getGUID());
+
+$title = elgg_echo('messages:add');
+
+elgg_push_breadcrumb($title);
+
+$params = messages_prepare_form_vars((int)get_input('send_to'));
+$params['friends'] = $page_owner->getFriends('', 50);
+$content = elgg_view_form('messages/send', array(), $params);
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/messages/pages/messages/sent.php b/mod/messages/pages/messages/sent.php
new file mode 100644
index 000000000..3d08cd5ee
--- /dev/null
+++ b/mod/messages/pages/messages/sent.php
@@ -0,0 +1,48 @@
+<?php
+/**
+* Elgg sent messages page
+*
+* @package ElggMessages
+*/
+
+gatekeeper();
+
+$page_owner = elgg_get_page_owner_entity();
+
+if (!$page_owner || !$page_owner->canEdit()) {
+ $guid = 0;
+ if($page_owner){
+ $guid = $page_owner->getGUID();
+ }
+ register_error(elgg_echo("pageownerunavailable", array($guid)));
+ forward();
+}
+
+elgg_push_breadcrumb(elgg_echo('messages:sent'));
+
+elgg_register_title_button();
+
+$title = elgg_echo('messages:sentmessages', array($page_owner->name));
+
+$list = elgg_list_entities_from_metadata(array(
+ 'type' => 'object',
+ 'subtype' => 'messages',
+ 'metadata_name' => 'fromId',
+ 'metadata_value' => elgg_get_page_owner_guid(),
+ 'owner_guid' => elgg_get_page_owner_guid(),
+ 'full_view' => false,
+));
+
+$body_vars = array(
+ 'folder' => 'sent',
+ 'list' => $list,
+);
+$content = elgg_view_form('messages/process', array(), $body_vars);
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/messages/read.php b/mod/messages/read.php
deleted file mode 100644
index 2bbae1c71..000000000
--- a/mod/messages/read.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
-* Elgg read a message page
-*
-* @package ElggMessages
-*/
-
-// Load Elgg engine
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-// If we're not logged in, forward to the front page
-gatekeeper();
-
-$page_owner = get_loggedin_user();
-$mbox_type = get_input('type', 'inbox');
-
-// Get the full message object to read
-$message = get_entity(get_input("message"));
-
-// If no message, must have been deleted, send user to inbox/sent mail
-if (!$message) {
- if ($mbox_type == 'sent') {
- forward("mod/messages/sent.php");
- } else {
- forward("pg/messages/{$page_owner->username}");
- }
-}
-
-// If the message is being read from the inbox, mark it as read, otherwise don't.
-// This stops a user who checks out a message they have sent having it being marked
-// as read for the recipient
-if($mbox_type != "sent"){
- // Mark the message as being read now
- if ($message->getSubtype() == "messages") {
- //set the message metadata to 1 which equals read
- $message->readYet = 1;
- }
-}
-
-set_page_owner($page_owner->getGUID());
-
-// Display it
-$content = elgg_view("messages/messages",array(
- 'entity' => $message,
- 'entity_owner' => $page_owner,
- 'full' => true
- ));
-
-$sidebar = elgg_view("messages/menu_options");
-
-$body = elgg_view_layout("one_column_with_sidebar", $content, $sidebar);
-
-// Display page
-echo elgg_view_page(sprintf(elgg_echo('messages:message')),$body); \ No newline at end of file
diff --git a/mod/messages/readme.txt b/mod/messages/readme.txt
deleted file mode 100644
index 04142be19..000000000
--- a/mod/messages/readme.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Elgg readme
- *
- * @package ElggMessages
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Dave Tosh <dave@elgg.com>
- * @copyright Curverider Ltd 2008-2009
- * @link http://elgg.com/
-*/
-
-Install: drop the plugin into your mod folder, that is it.
-
-Notes:
-
-Each message has a series of metadata which is used to control how the message displays.
-
-The metadata toggles are:
-
-hiddenFrom - used to 'delete' from the sentbox
-hiddenTo - used to 'delete' from the inbox
-readYet - 0 means no, 1 means yes it has been read
-
-This is actually a tricky little plugin as there is only ever one instance of a message, how it is viewed
-depends on who is looked at and in what context. \ No newline at end of file
diff --git a/mod/messages/send.php b/mod/messages/send.php
deleted file mode 100644
index 92563c91d..000000000
--- a/mod/messages/send.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
-* Elgg send a message page
-*
-* @package ElggMessages
-*/
-
-// Load Elgg engine
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-// If we're not logged in, forward to the front page
-gatekeeper();
-
-// Get the current page's owner
-$page_owner = elgg_get_page_owner();
-if ($page_owner === false || is_null($page_owner)) {
- $page_owner = get_loggedin_user();
- set_page_owner($page_owner->getGUID());
-}
-
-// Get the users friends; this is used in the drop down to select who to send the message to
-$user = get_loggedin_user();
-$friends = $user->getFriends('', 9999);
-
-// Set the page title
-$area2 = elgg_view_title(elgg_echo("messages:sendmessage"));
-
-// Get the send form
-$area2 .= elgg_view("messages/forms/send",array('friends' => $friends));
-
-// Sidebar menu options
-$area3 = elgg_view("messages/menu_options");
-
-// Format
-$body = elgg_view_layout("one_column_with_sidebar", $area2, $area3);
-
-// Draw page
-echo elgg_view_page(sprintf(elgg_echo('messages:send'),$page_owner->name),$body); \ No newline at end of file
diff --git a/mod/messages/sent.php b/mod/messages/sent.php
deleted file mode 100644
index e2b22502d..000000000
--- a/mod/messages/sent.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
-* Elgg sent messages page
-*
-* @package ElggMessages
-*/
-
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-global $CONFIG;
-
-gatekeeper();
-
-// Get the logged in user
-$page_owner = get_loggedin_user();
-set_page_owner($page_owner->guid);
-
-// Get offset
-$offset = get_input('offset',0);
-
-// Set limit
-$limit = 10;
-
-// Display all the messages a user owns, these will make up the sentbox
-// @todo - fix hack where limit + 1 is passed
-$messages = elgg_get_entities_from_metadata(array('metadata_name' => 'fromId', 'metadata_value' => get_loggedin_userid(), 'types' => 'object', 'subtypes' => 'messages', 'owner_guid' => $page_owner->guid, 'limit' => $limit + 1, 'offset' => $offset));
-
-
-// Set the page title
-$area2 = "<div id='content_header'><div class='content_header_title'>";
-$area2 .= elgg_view_title(elgg_echo("messages:sentmessages"))."</div>";
-$area2 .= "<div class='content_header_options'><a class='action_button' href='".elgg_get_site_url()."mod/messages/send.php'>" . elgg_echo('messages:compose') . "</a></div></div>";
-
-// Set content
-$area2 .= elgg_view("messages/forms/view",array('entity' => $messages, 'page_view' => "sent", 'limit' => $limit, 'offset' => $offset));
-
-// Format
-$body = elgg_view_layout("one_column_with_sidebar", $area2);
-
-// Draw page
-echo elgg_view_page(sprintf(elgg_echo('messages:sentMessages'),$page_owner->name),$body);
diff --git a/mod/messages/start.php b/mod/messages/start.php
index 07698d893..6d0e82744 100644
--- a/mod/messages/start.php
+++ b/mod/messages/start.php
@@ -1,58 +1,157 @@
<?php
-
/**
* Elgg internal messages plugin
-* This plugin lets user send each other messages.
-*
+* This plugin lets users send messages to each other.
+*
* @package ElggMessages
*/
-/**
-* Messages initialisation
-*
-* These parameters are required for the event API, but we won't use them:
-*
-* @param unknown_type $event
-* @param unknown_type $object_type
-* @param unknown_type $object
-*/
+
+elgg_register_event_handler('init', 'system', 'messages_init');
+
function messages_init() {
-
- // Load system configuration
- global $CONFIG;
-
- //add submenu options
- if (elgg_get_context() == "messages") {
- add_submenu_item(elgg_echo('messages:inbox'), "pg/messages/" . get_loggedin_user()->username);
- add_submenu_item(elgg_echo('messages:sentmessages'), "mod/messages/sent.php");
- }
-
- // Extend system CSS with our own styles, which are defined in the shouts/css view
- elgg_extend_view('css','messages/css');
+
+ // register a library of helper functions
+ elgg_register_library('elgg:messages', elgg_get_plugins_path() . 'messages/lib/messages.php');
+
+ // add page menu items
+ if (elgg_is_logged_in()) {
+ elgg_register_menu_item('page', array(
+ 'name' => 'messages:inbox',
+ 'text' => elgg_echo('messages:inbox'),
+ 'href' => "messages/inbox/" . elgg_get_logged_in_user_entity()->username,
+ 'context' => 'messages',
+ ));
- // Extend the elgg topbar
- elgg_extend_view('elgg_topbar/extend','messages/topbar');
+ elgg_register_menu_item('page', array(
+ 'name' => 'messages:sentmessages',
+ 'text' => elgg_echo('messages:sentmessages'),
+ 'href' => "messages/sent/" . elgg_get_logged_in_user_entity()->username,
+ 'context' => 'messages',
+ ));
+ }
+
+ elgg_register_event_handler('pagesetup', 'system', 'messages_notifier');
+
+ // Extend system CSS with our own styles, which are defined in the messages/css view
+ elgg_extend_view('css/elgg', 'messages/css');
+ elgg_extend_view('js/elgg', 'messages/js');
// Register a page handler, so we can have nice URLs
- register_page_handler('messages','messages_page_handler');
-
- // Register a URL handler for shouts posts
- register_entity_url_handler('messages_url','object','messages');
-
- // Extend avatar user-menu
- elgg_extend_view('profile/menu/links','messages/menu');
-
+ elgg_register_page_handler('messages', 'messages_page_handler');
+
+ // Register a URL handler
+ elgg_register_entity_url_handler('object', 'messages', 'messages_url');
+
+ // Extend avatar hover menu
+ elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'messages_user_hover_menu');
+
// Register a notification handler for site messages
- register_notification_handler("site", "messages_site_notify_handler");
- register_plugin_hook('notify:entity:message','object','messages_notification_msg');
- register_notification_object('object','messages',elgg_echo('messages:new'));
-
- // Override metadata permissions
- register_plugin_hook('permissions_check:metadata','object','messages_can_edit_metadata');
-
+ register_notification_handler("site", "messages_site_notify_handler");
+ elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'messages_notification_msg');
+ register_notification_object('object', 'messages', elgg_echo('messages:new'));
+
+ // delete messages sent by a user when user is deleted
+ elgg_register_event_handler('delete', 'user', 'messages_purge');
+
// ecml
- register_plugin_hook('get_views', 'ecml', 'messages_ecml_views_hook');
+ elgg_register_plugin_hook_handler('get_views', 'ecml', 'messages_ecml_views_hook');
+
+ // permission overrides
+ elgg_register_plugin_hook_handler('permissions_check:metadata', 'object', 'messages_can_edit_metadata');
+ elgg_register_plugin_hook_handler('permissions_check', 'object', 'messages_can_edit');
+ elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'messages_can_edit_container');
+ // Register actions
+ $action_path = elgg_get_plugins_path() . 'messages/actions/messages';
+ elgg_register_action("messages/send", "$action_path/send.php");
+ elgg_register_action("messages/delete", "$action_path/delete.php");
+ elgg_register_action("messages/process", "$action_path/process.php");
+}
+
+/**
+ * Messages page handler
+ *
+ * @param array $page Array of URL components for routing
+ * @return bool
+ */
+function messages_page_handler($page) {
+
+ $current_user = elgg_get_logged_in_user_entity();
+ if (!$current_user) {
+ register_error(elgg_echo('noaccess'));
+ $_SESSION['last_forward_from'] = current_page_url();
+ forward('');
+ }
+
+ elgg_load_library('elgg:messages');
+
+ elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username);
+
+ if (!isset($page[0])) {
+ $page[0] = 'inbox';
+ }
+
+ // Support the old inbox url /messages/<username>, but only if it matches the logged in user.
+ // Otherwise having a username like "read" on the system could confuse this function.
+ if ($current_user->username === $page[0]) {
+ $page[1] = $page[0];
+ $page[0] = 'inbox';
+ }
+
+ if (!isset($page[1])) {
+ $page[1] = $current_user->username;
+ }
+
+ $base_dir = elgg_get_plugins_path() . 'messages/pages/messages';
+
+ switch ($page[0]) {
+ case 'inbox':
+ set_input('username', $page[1]);
+ include("$base_dir/inbox.php");
+ break;
+ case 'sent':
+ set_input('username', $page[1]);
+ include("$base_dir/sent.php");
+ break;
+ case 'read':
+ set_input('guid', $page[1]);
+ include("$base_dir/read.php");
+ break;
+ case 'compose':
+ case 'add':
+ include("$base_dir/send.php");
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Display notification of new messages in topbar
+ */
+function messages_notifier() {
+ if (elgg_is_logged_in()) {
+ $class = "elgg-icon elgg-icon-mail";
+ $text = "<span class='$class'></span>";
+ $tooltip = elgg_echo("messages");
+
+ // get unread messages
+ $num_messages = (int)messages_count_unread();
+ if ($num_messages != 0) {
+ $text .= "<span class=\"messages-new\">$num_messages</span>";
+ $tooltip .= " (" . elgg_echo("messages:unreadcount", array($num_messages)) . ")";
+ }
+
+ elgg_register_menu_item('topbar', array(
+ 'name' => 'messages',
+ 'href' => 'messages/inbox/' . elgg_get_logged_in_user_entity()->username,
+ 'text' => $text,
+ 'priority' => 600,
+ 'title' => $tooltip,
+ ));
+ }
}
/**
@@ -62,16 +161,15 @@ function messages_init() {
function messages_can_edit_metadata($hook_name, $entity_type, $return_value, $parameters) {
global $messagesendflag;
-
+
if ($messagesendflag == 1) {
$entity = $parameters['entity'];
if ($entity->getSubtype() == "messages") {
return true;
}
}
-
+
return $return_value;
-
}
/**
@@ -79,48 +177,29 @@ function messages_can_edit_metadata($hook_name, $entity_type, $return_value, $pa
*
*/
function messages_can_edit($hook_name, $entity_type, $return_value, $parameters) {
-
+
global $messagesendflag;
-
+
if ($messagesendflag == 1) {
$entity = $parameters['entity'];
if ($entity->getSubtype() == "messages") {
return true;
}
}
-
+
return $return_value;
-
}
/**
- * We really don't want to send a notification message when a message is sent, if the method is messages ...
- *
+ * Prevent messages from generating a notification
*/
-function messages_notification_msg($hook_name, $entity_type, $return_value, $parameters) {
+function messages_notification_msg($hook_name, $entity_type, $return_value, $params) {
- global $CONFIG, $messages_pm;
-
- if ($parameters['entity'] instanceof ElggEntity) {
-
- if ($parameters['entity']->getSubtype() == 'messages') {
-
+ if ($params['entity'] instanceof ElggEntity) {
+ if ($params['entity']->getSubtype() == 'messages') {
return false;
- /*if (!$messages_pm) return false;
- if ($parameters['method'] == 'email') {
- return sprintf(
- elgg_echo('messages:email:body'),
- get_loggedin_user()->name,
- strip_tags($parameters['entity']->description),
- elgg_get_site_url() . "pg/messages/" . $user->username,
- get_loggedin_user()->name,
- elgg_get_site_url() . "mod/messages/send.php?send_to=" . get_loggedin_userid()
- );
- } else if ($parameters['method'] == 'site') return false;*/
}
}
- return null;
-
}
/**
@@ -128,15 +207,14 @@ function messages_notification_msg($hook_name, $entity_type, $return_value, $par
*
*/
function messages_can_edit_container($hook_name, $entity_type, $return_value, $parameters) {
-
+
global $messagesendflag;
-
+
if ($messagesendflag == 1) {
return true;
}
-
+
return $return_value;
-
}
/**
@@ -144,181 +222,252 @@ function messages_can_edit_container($hook_name, $entity_type, $return_value, $p
*
* @param string $subject The subject line of the message
* @param string $body The body of the mesage
- * @param int $send_to The GUID of the user to send to
- * @param int $from Optionally, the GUID of the user to send from
- * @param int $reply The GUID of the message to reply from (default: none)
- * @param true|false $notify Send a notification (default: true)
- * @param true|false $add_to_sent If true (default), will add a message to the sender's 'sent' tray
- * @return true|false Depending on success
+ * @param int $recipient_guid The GUID of the user to send to
+ * @param int $sender_guid Optionally, the GUID of the user to send from
+ * @param int $original_msg_guid The GUID of the message to reply from (default: none)
+ * @param bool $notify Send a notification (default: true)
+ * @param bool $add_to_sent If true (default), will add a message to the sender's 'sent' tray
+ * @return bool
*/
-function messages_send($subject, $body, $send_to, $from = 0, $reply = 0, $notify = true, $add_to_sent = true) {
-
- global $messagesendflag;
- $messagesendflag = 1;
-
- global $messages_pm;
- if ($notify) {
- $messages_pm = 1;
- } else {
- $messages_pm = 0;
- }
+function messages_send($subject, $body, $recipient_guid, $sender_guid = 0, $original_msg_guid = 0, $notify = true, $add_to_sent = true) {
+
+ // @todo remove globals
+ global $messagesendflag;
+ $messagesendflag = 1;
+
+ // @todo remove globals
+ global $messages_pm;
+ if ($notify) {
+ $messages_pm = 1;
+ } else {
+ $messages_pm = 0;
+ }
+
+ // If $sender_guid == 0, set to current user
+ if ($sender_guid == 0) {
+ $sender_guid = (int) elgg_get_logged_in_user_guid();
+ }
+
+ // Initialise 2 new ElggObject
+ $message_to = new ElggObject();
+ $message_sent = new ElggObject();
+
+ $message_to->subtype = "messages";
+ $message_sent->subtype = "messages";
+
+ $message_to->owner_guid = $recipient_guid;
+ $message_to->container_guid = $recipient_guid;
+ $message_sent->owner_guid = $sender_guid;
+ $message_sent->container_guid = $sender_guid;
+
+ $message_to->access_id = ACCESS_PUBLIC;
+ $message_sent->access_id = ACCESS_PUBLIC;
+
+ $message_to->title = $subject;
+ $message_to->description = $body;
+
+ $message_sent->title = $subject;
+ $message_sent->description = $body;
+
+ $message_to->toId = $recipient_guid; // the user receiving the message
+ $message_to->fromId = $sender_guid; // the user receiving the message
+ $message_to->readYet = 0; // this is a toggle between 0 / 1 (1 = read)
+ $message_to->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag
+ $message_to->hiddenTo = 0; // this is used when a user deletes a message in their inbox
+
+ $message_sent->toId = $recipient_guid; // the user receiving the message
+ $message_sent->fromId = $sender_guid; // the user receiving the message
+ $message_sent->readYet = 0; // this is a toggle between 0 / 1 (1 = read)
+ $message_sent->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag
+ $message_sent->hiddenTo = 0; // this is used when a user deletes a message in their inbox
+
+ $message_to->msg = 1;
+ $message_sent->msg = 1;
+
+ // Save the copy of the message that goes to the recipient
+ $success = $message_to->save();
+
+ // Save the copy of the message that goes to the sender
+ if ($add_to_sent) {
+ $message_sent->save();
+ }
+
+ $message_to->access_id = ACCESS_PRIVATE;
+ $message_to->save();
+
+ if ($add_to_sent) {
+ $message_sent->access_id = ACCESS_PRIVATE;
+ $message_sent->save();
+ }
+
+ // if the new message is a reply then create a relationship link between the new message
+ // and the message it is in reply to
+ if ($original_msg_guid && $success) {
+ add_entity_relationship($message_sent->guid, "reply", $original_msg_guid);
+ }
+
+ $message_contents = strip_tags($body);
+ if (($recipient_guid != elgg_get_logged_in_user_guid()) && $notify) {
+ $recipient = get_user($recipient_guid);
+ $sender = get_user($sender_guid);
- // If $from == 0, set to current user
- if ($from == 0)
- $from = (int) get_loggedin_userid();
-
- // Initialise a new ElggObject
- $message_to = new ElggObject();
- $message_sent = new ElggObject();
- // Tell the system it's a message
- $message_to->subtype = "messages";
- $message_sent->subtype = "messages";
- // Set its owner to the current user
- // $message_to->owner_guid = get_loggedin_userid();
- $message_to->owner_guid = $send_to;
- $message_to->container_guid = $send_to;
- $message_sent->owner_guid = $from;
- $message_sent->container_guid = $from;
- // For now, set its access to public (we'll add an access dropdown shortly)
- $message_to->access_id = ACCESS_PUBLIC;
- $message_sent->access_id = ACCESS_PUBLIC;
- // Set its description appropriately
- $message_to->title = $subject;
- $message_to->description = $body;
- $message_sent->title = $subject;
- $message_sent->description = $body;
- // set the metadata
- $message_to->toId = $send_to; // the user receiving the message
- $message_to->fromId = $from; // the user receiving the message
- $message_to->readYet = 0; // this is a toggle between 0 / 1 (1 = read)
- $message_to->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag
- $message_to->hiddenTo = 0; // this is used when a user deletes a message in their inbox
- $message_sent->toId = $send_to; // the user receiving the message
- $message_sent->fromId = $from; // the user receiving the message
- $message_sent->readYet = 0; // this is a toggle between 0 / 1 (1 = read)
- $message_sent->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag
- $message_sent->hiddenTo = 0; // this is used when a user deletes a message in their inbox
-
- $message_to->msg = 1;
- $message_sent->msg = 1;
-
- // Save the copy of the message that goes to the recipient
- $success = $message_to->save();
-
- // Save the copy of the message that goes to the sender
- if ($add_to_sent) $success2 = $message_sent->save();
-
- $message_to->access_id = ACCESS_PRIVATE;
- $message_to->save();
-
- if ($add_to_sent) {
- $message_sent->access_id = ACCESS_PRIVATE;
- $message_sent->save();
- }
-
- // if the new message is a reply then create a relationship link between the new message
- // and the message it is in reply to
- if($reply && $success){
- $create_relationship = add_entity_relationship($message_sent->guid, "reply", $reply);
- }
-
-
- global $CONFIG;
- $message_contents = strip_tags($body);
- if ($send_to != get_loggedin_user() && $notify)
- notify_user($send_to, get_loggedin_userid(), elgg_echo('messages:email:subject'),
- sprintf(
- elgg_echo('messages:email:body'),
- get_loggedin_user()->name,
- $message_contents,
- elgg_get_site_url() . "pg/messages/" . $user->username,
- get_loggedin_user()->name,
- elgg_get_site_url() . "mod/messages/send.php?send_to=" . get_loggedin_userid()
- )
- );
-
- $messagesendflag = 0;
- return $success;
-
+ $subject = elgg_echo('messages:email:subject');
+ $body = elgg_echo('messages:email:body', array(
+ $sender->name,
+ $message_contents,
+ elgg_get_site_url() . "messages/inbox/" . $recipient->username,
+ $sender->name,
+ elgg_get_site_url() . "messages/compose?send_to=" . $sender_guid
+ ));
+
+ notify_user($recipient_guid, $sender_guid, $subject, $body);
+ }
+
+ $messagesendflag = 0;
+ return $success;
}
/**
- * messages page handler; allows the use of fancy URLs
+ * Message URL override
*
- * @param array $page From the page_handler function
- * @return true|false Depending on success
+ * @param ElggObject $message
+ * @return string
*/
-function messages_page_handler($page) {
-
- // The first component of a messages URL is the username
- if (isset($page[0])) {
- set_input('username',$page[0]);
- }
-
- // The second part dictates what we're doing
- if (isset($page[1])) {
- switch($page[1]) {
- case "read": set_input('message',$page[2]);
- include(dirname(__FILE__) . "/read.php");
- return true;
- break;
- }
- // If the URL is just 'messages/username', or just 'messages/', load the standard messages index
- } else {
- include(dirname(__FILE__) . "/index.php");
- return true;
- }
-
- return false;
-
-}
-
function messages_url($message) {
- return "pg/messages/" . $message->getOwnerEntity()->username . "/read/" . $message->getGUID();
+ $url = elgg_get_site_url() . 'messages/read/' . $message->getGUID();
+ return $url;
}
-// A simple function to count the number of messages that are unread in a user's inbox
function count_unread_messages() {
-
- //get the users inbox messages
- //$num_messages = get_entities_from_metadata("toId", get_loggedin_userid(), "object", "messages", 0, 10, 0, "", 0, false);
- $num_messages = elgg_get_entities_from_metadata(array('metadata_name_value_pairs' => array(
- 'toId' => get_loggedin_userid(),
- 'readYet' => 0,
- 'msg' => 1
- ), 'owner_guid' => get_loggedin_userid()));
-
- if (is_array($num_messages))
- $counter = sizeof($num_messages);
- else
- $counter = 0;
-
- return $counter;
-
+ elgg_deprecated_notice('Your theme is using count_unread_messages which has been deprecated for messages_count_unread()', 1.8);
+ return messages_count_unread();
}
-function messages_site_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message, array $params = NULL)
-{
- global $CONFIG;
-
- if (!$from)
- throw new NotificationException(sprintf(elgg_echo('NotificationException:MissingParameter'), 'from'));
-
- if (!$to)
- throw new NotificationException(sprintf(elgg_echo('NotificationException:MissingParameter'), 'to'));
-
+/**
+ * Count the unread messages in a user's inbox
+ *
+ * @return int
+ */
+function messages_count_unread() {
+ $user_guid = elgg_get_logged_in_user_guid();
+ $db_prefix = elgg_get_config('dbprefix');
+
+ // denormalize the md to speed things up.
+ // seriously, 10 joins if you don't.
+ $strings = array('toId', $user_guid, 'readYet', 0, 'msg', 1);
+ $map = array();
+ foreach ($strings as $string) {
+ $id = get_metastring_id($string);
+ $map[$string] = $id;
+ }
+
+ $options = array(
+// 'metadata_name_value_pairs' => array(
+// 'toId' => elgg_get_logged_in_user_guid(),
+// 'readYet' => 0,
+// 'msg' => 1
+// ),
+ 'joins' => array(
+ "JOIN {$db_prefix}metadata msg_toId on e.guid = msg_toId.entity_guid",
+ "JOIN {$db_prefix}metadata msg_readYet on e.guid = msg_readYet.entity_guid",
+ "JOIN {$db_prefix}metadata msg_msg on e.guid = msg_msg.entity_guid",
+ ),
+ 'wheres' => array(
+ "msg_toId.name_id='{$map['toId']}' AND msg_toId.value_id='{$map[$user_guid]}'",
+ "msg_readYet.name_id='{$map['readYet']}' AND msg_readYet.value_id='{$map[0]}'",
+ "msg_msg.name_id='{$map['msg']}' AND msg_msg.value_id='{$map[1]}'",
+ ),
+ 'owner_guid' => $user_guid,
+ 'count' => true,
+ );
+
+ return elgg_get_entities_from_metadata($options);
+}
+
+/**
+ * Notification handler
+ *
+ * @param ElggEntity $from
+ * @param ElggUser $to
+ * @param string $subject
+ * @param string $message
+ * @param array $params
+ * @return bool
+ */
+function messages_site_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message, array $params = NULL) {
+
+ if (!$from) {
+ throw new NotificationException(elgg_echo('NotificationException:MissingParameter', array('from')));
+ }
+
+ if (!$to) {
+ throw new NotificationException(elgg_echo('NotificationException:MissingParameter', array('to')));
+ }
+
global $messages_pm;
- if (!$messages_pm)
- return messages_send($subject,$message,$to->guid,$from->guid,0,false,false);
- else return true;
-
+ if (!$messages_pm) {
+ return messages_send($subject, $message, $to->guid, $from->guid, 0, false, false);
+ }
+
+ return true;
}
+
+/**
+ * Add to the user hover menu
+ */
+function messages_user_hover_menu($hook, $type, $return, $params) {
+ $user = $params['entity'];
+
+ if (elgg_is_logged_in() && elgg_get_logged_in_user_guid() != $user->guid) {
+ $url = "messages/compose?send_to={$user->guid}";
+ $item = new ElggMenuItem('send', elgg_echo('messages:sendmessage'), $url);
+ $item->setSection('action');
+ $return[] = $item;
+ }
+
+ return $return;
+}
+
+/**
+ * Delete messages from a user who is being deleted
+ *
+ * @param string $event Event name
+ * @param string $type Event type
+ * @param ElggUser $user User being deleted
+ */
+function messages_purge($event, $type, $user) {
+
+ if (!$user->getGUID()) {
+ return;
+ }
+
+ // make sure we delete them all
+ $entity_disable_override = access_get_show_hidden_status();
+ access_show_hidden_entities(true);
+ $ia = elgg_set_ignore_access(true);
+
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'messages',
+ 'metadata_name' => 'fromId',
+ 'metadata_value' => $user->getGUID(),
+ 'limit' => 0,
+ );
+ $batch = new ElggBatch('elgg_get_entities_from_metadata', $options);
+ foreach ($batch as $e) {
+ $e->delete();
+ }
+
+ elgg_set_ignore_access($ia);
+ access_show_hidden_entities($entity_disable_override);
+}
+
/**
* Register messages with ECML.
*
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $return_value
+ * @param string $hook
+ * @param string $entity_type
+ * @param array $return_value
* @param unknown_type $params
*/
function messages_ecml_views_hook($hook, $entity_type, $return_value, $params) {
@@ -326,15 +475,3 @@ function messages_ecml_views_hook($hook, $entity_type, $return_value, $params) {
return $return_value;
}
-
-
-// Make sure the messages initialisation function is called on initialisation
-register_elgg_event_handler('init','system','messages_init');
-
-register_plugin_hook('permissions_check','object','messages_can_edit');
-register_plugin_hook('container_permissions_check','object','messages_can_edit_container');
-
-// Register actions
-global $CONFIG;
-register_action("messages/send",false,$CONFIG->pluginspath . "messages/actions/send.php");
-register_action("messages/delete",false,$CONFIG->pluginspath . "messages/actions/delete.php"); \ No newline at end of file
diff --git a/mod/messages/views/default/forms/messages/process.php b/mod/messages/views/default/forms/messages/process.php
new file mode 100644
index 000000000..cb30792e9
--- /dev/null
+++ b/mod/messages/views/default/forms/messages/process.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Messages folder view (inbox, sent)
+ *
+ * Provides form body for mass deleting messages
+ *
+ * @uses $vars['list'] List of messages
+ *
+ */
+
+$messages = $vars['list'];
+if (!$messages) {
+ echo elgg_echo('messages:nomessages');
+ return true;
+}
+
+echo '<div class="messages-container">';
+echo $messages;
+echo '</div>';
+
+echo '<div class="elgg-foot messages-buttonbank">';
+
+echo elgg_view('input/submit', array(
+ 'value' => elgg_echo('delete'),
+ 'name' => 'delete',
+ 'class' => 'elgg-button-delete elgg-requires-confirmation',
+ 'title' => elgg_echo('deleteconfirm:plural'),
+));
+
+if ($vars['folder'] == "inbox") {
+ echo elgg_view('input/submit', array(
+ 'value' => elgg_echo('messages:markread'),
+ 'name' => 'read',
+ ));
+}
+
+echo elgg_view('input/button', array(
+ 'value' => elgg_echo('messages:toggle'),
+ 'class' => 'elgg-button elgg-button-cancel',
+ 'id' => 'messages-toggle',
+));
+
+echo '</div>';
diff --git a/mod/messages/views/default/forms/messages/reply.php b/mod/messages/views/default/forms/messages/reply.php
new file mode 100644
index 000000000..9f3f4b57e
--- /dev/null
+++ b/mod/messages/views/default/forms/messages/reply.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Reply form
+ *
+ * @uses $vars['message']
+ */
+
+// fix for RE: RE: RE: that builds on replies
+$reply_title = $vars['message']->title;
+if (strncmp($reply_title, "RE:", 3) != 0) {
+ $reply_title = "RE: " . $reply_title;
+}
+
+echo elgg_view('input/hidden', array(
+ 'name' => 'recipient_guid',
+ 'value' => $vars['message']->fromId,
+));
+?>
+
+<div>
+ <label><?php echo elgg_echo("messages:title"); ?>: <br /></label>
+ <?php echo elgg_view('input/text', array(
+ 'name' => 'subject',
+ 'value' => $reply_title,
+ ));
+ ?>
+</div>
+<div>
+ <label><?php echo elgg_echo("messages:message"); ?>:</label>
+ <?php echo elgg_view("input/longtext", array(
+ 'name' => 'body',
+ 'value' => '',
+ ));
+ ?>
+</div>
+<div class="elgg-foot">
+ <?php echo elgg_view('input/submit', array('value' => elgg_echo('messages:send'))); ?>
+</div> \ No newline at end of file
diff --git a/mod/messages/views/default/forms/messages/send.php b/mod/messages/views/default/forms/messages/send.php
new file mode 100644
index 000000000..5b7e7830e
--- /dev/null
+++ b/mod/messages/views/default/forms/messages/send.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Compose message form
+ *
+ * @package ElggMessages
+ * @uses $vars['friends']
+ */
+
+$recipient_guid = elgg_extract('recipient_guid', $vars, 0);
+$subject = elgg_extract('subject', $vars, '');
+$body = elgg_extract('body', $vars, '');
+
+$recipients_options = array();
+foreach ($vars['friends'] as $friend) {
+ $recipients_options[$friend->guid] = $friend->name;
+}
+
+if (!array_key_exists($recipient_guid, $recipients_options)) {
+ $recipient = get_entity($recipient_guid);
+ if (elgg_instanceof($recipient, 'user')) {
+ $recipients_options[$recipient_guid] = $recipient->name;
+ }
+}
+
+$recipient_drop_down = elgg_view('input/dropdown', array(
+ 'name' => 'recipient_guid',
+ 'value' => $recipient_guid,
+ 'options_values' => $recipients_options,
+));
+
+?>
+<div>
+ <label><?php echo elgg_echo("messages:to"); ?>: </label>
+ <?php echo $recipient_drop_down; ?>
+</div>
+<div>
+ <label><?php echo elgg_echo("messages:title"); ?>: <br /></label>
+ <?php echo elgg_view('input/text', array(
+ 'name' => 'subject',
+ 'value' => $subject,
+ ));
+ ?>
+</div>
+<div>
+ <label><?php echo elgg_echo("messages:message"); ?>:</label>
+ <?php echo elgg_view("input/longtext", array(
+ 'name' => 'body',
+ 'value' => $body,
+ ));
+ ?>
+</div>
+<div class="elgg-foot">
+ <?php echo elgg_view('input/submit', array('value' => elgg_echo('messages:send'))); ?>
+</div>
diff --git a/mod/messages/views/default/messages/css.php b/mod/messages/views/default/messages/css.php
index 95bcba108..f304e0f15 100644
--- a/mod/messages/views/default/messages/css.php
+++ b/mod/messages/views/default/messages/css.php
@@ -6,84 +6,58 @@
*/
?>
-/* messages/new messages icon & counter in elgg_topbar */
-a.privatemessages {
- background:transparent url(<?php echo elgg_get_site_url(); ?>mod/messages/graphics/toolbar_messages_icon.gif) no-repeat left 2px;
- padding-left:16px;
- margin:4px 15px 0 5px;
- cursor:pointer;
+.messages-container {
+ min-height: 200px;
}
-a.privatemessages:hover {
- text-decoration: none;
- background:transparent url(<?php echo elgg_get_site_url(); ?>mod/messages/graphics/toolbar_messages_icon.gif) no-repeat left -36px;
+.message.unread a {
+ color: #d40005;
}
-a.privatemessages.new {
- background:transparent url(<?php echo elgg_get_site_url(); ?>mod/messages/graphics/toolbar_messages_icon.gif) no-repeat left 2px;
- padding-left:18px;
- margin:4px 15px 0 5px;
- color:white;
-}
-a.privatemessages.new:hover {
- text-decoration: none;
- background:transparent url(<?php echo elgg_get_site_url(); ?>mod/messages/graphics/toolbar_messages_icon.gif) no-repeat left -36px;
+.messages-buttonbank {
+ text-align: right;
}
-a.privatemessages.new span {
- background-color: red;
- -webkit-border-radius: 10px;
- -moz-border-radius: 10px;
- -webkit-box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.50); /* safari v3+ */
- -moz-box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.50); /* FF v3.5+ */
- color:white;
- display:block;
- float:right;
- padding:0;
- position:relative;
- text-align:center;
- top:-3px;
- right:5px;
- min-width: 16px;
- height:16px;
- font-size:10px;
- font-weight:bold;
+.messages-buttonbank input {
+ margin-left: 10px;
}
-/* page content */
-.message {
- border-bottom:1px dotted #cccccc;
- padding:5px 0 7px 0;
-}
-.message.notread .entity_listing_info p.entity_title a {
- color:#d40005;
-}
-.message_sender {
- float:left;
- width:180px;
- overflow: hidden;
-}
-.messages_to {
+/*** message metadata ***/
+.messages-owner {
float: left;
- margin-right: 10px;
-}
-
-/* view and reply to message view */
-.message_body {
- margin-left: 120px;
-}
-.message_subject {
- float:left;
- width:513px;
- padding-top:6px;
+ width: 20%;
+ margin-right: 2%;
}
-.message .delete_button {
- margin-top:3px;
+.messages-subject {
+ float: left;
+ width: 55%;
+ margin-right: 2%;
}
-.entity_listing.messages:hover {
- background-color:white;
+.messages-timestamp {
+ float: left;
+ width: 14%;
+ margin-right: 2%;
}
-.messages_buttonbank {
- margin:5px 0;
- text-align: right;
+.messages-delete {
+ float: left;
+ width: 5%;
}
-.messages_buttonbank input {
- margin:0 0 0 10px;
+/*** topbar icon ***/
+.messages-new {
+ color: white;
+ background-color: red;
+
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+
+ -webkit-box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.50);
+ -moz-box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.50);
+ box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.50);
+
+ position: absolute;
+ text-align: center;
+ top: 0px;
+ left: 26px;
+ min-width: 16px;
+ height: 16px;
+ font-size: 10px;
+ font-weight: bold;
}
diff --git a/mod/messages/views/default/messages/forms/reply.php b/mod/messages/views/default/messages/forms/reply.php
deleted file mode 100644
index 998c0071f..000000000
--- a/mod/messages/views/default/messages/forms/reply.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
- /**
- * Elgg reply to a message form
- * @uses $vars['entity'] This is the message being replied to
- */
-
- // fix for RE: RE: RE: that builds on replies
- $reply_title = $vars['entity']->title;
- if (strncmp($reply_title, "RE:", 3) != 0) {
- $reply_title = "RE: " . $reply_title;
- }
-?>
-
-<form class="margin_top" id="messages_reply_form" action="<?php echo elgg_get_site_url(); ?>action/messages/send" method="post" name="messageForm">
- <?php echo elgg_view('action/securitytoken'); ?>
-
- <!-- populate the title space with the orginal message title, inserting re: before it -->
- <p><label><?php echo elgg_echo("messages:title"); ?>: <br /><input type='text' name='title' class="input_text" value='<?php echo $reply_title; ?>' /></label></p>
- <p><label><?php echo elgg_echo("messages:message"); ?>: <br /><textarea name='message' value='' class="input_textarea" /></textarea></label></p>
-
- <p>
- <?php
-
- //pass across the guid of the message being replied to
- echo "<input type='hidden' name='reply' value='" . $vars['entity']->getGUID() . "' />";
- //pass along the owner of the message being replied to
- echo "<input type='hidden' name='send_to' value='BAAA" . $vars['entity']->fromId . "' />";
-
- ?>
- <input type="submit" class="submit_button" value="<?php echo elgg_echo("messages:fly"); ?>" />
- </p>
-
-</form>
-
- <?php
- //display the message you are replying to
- if (isset($vars['entity'])) {
-
- echo "<h3>" . elgg_echo("messages:replying") . "</h3>";
- echo $vars['entity']->description;
-
- }
- ?>
diff --git a/mod/messages/views/default/messages/forms/send.php b/mod/messages/views/default/messages/forms/send.php
deleted file mode 100644
index a2d373549..000000000
--- a/mod/messages/views/default/messages/forms/send.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
-* Elgg send a message view
-*
-* @package ElggMessages
- * @uses $vars['friends'] This is an array of a user's friends and is used to populate the list of
- * people the user can message
- *
- */
-
-//grab the user id to send a message to. This will only happen if a user clicks on the 'send a message'
-//link on a user's profile or hover-over menu
-$send_to = get_input('send_to');
-if ($send_to === "")
- $send_to = $_SESSION['msg_to'];
-
-$msg_title = $_SESSION['msg_title'];
-$msg_content = $_SESSION['msg_contents'];
-
-// clear sticky form cache in case user browses away from page and comes back
-unset($_SESSION['msg_to']);
-unset($_SESSION['msg_title']);
-unset($_SESSION['msg_contents']);
-?>
-<form id="messages_send_form" action="<?php echo elgg_get_site_url(); ?>action/messages/send" method="post" name="messageForm">
-<?php
- echo elgg_view('input/securitytoken');
- //check to see if the message recipient has already been selected
- if($send_to){
-
- //get the user object
- $user = get_user($send_to);
-
- echo "<div class='entity_listing messages clearfloat'><div class='entity_listing_icon'>".elgg_view("profile/icon",array('entity' => $user, 'size' => 'tiny'))."</div>";
-
- //draw it
- echo "<div class='entity_listing_info'>".elgg_echo("messages:to").": <a href='".elgg_get_site_url()."pg/profile/".$user->username."'>".$user->name."</a>";
- //set the hidden input field to the recipients guid
- echo "<input type='hidden' name='send_to' value=\"{$send_to}\" />";
- echo "</div></div>";
-
- } else {
- ?>
-
- <p class="margin_top"><label><?php echo elgg_echo("messages:to"); ?>: </label>
- <select name='send_to'>
- <?php
- // make the first option blank
- echo "<option value=''>".elgg_echo("messages:recipient")."</option>";
- foreach($vars['friends'] as $friend){
- //populate the send to box with a user's friends
- echo "<option value='{$friend->guid}'>" . $friend->name . "</option>";
- }
- ?>
- </select></p>
- <?php
- }
- ?>
-
- <p class="margin_top"><label><?php echo elgg_echo("messages:title"); ?>: <br /><input type='text' name='title' value='<?php echo $msg_title; ?>' class="input_text" /></label></p>
- <p class="longtext_inputarea"><label><?php echo elgg_echo("messages:message"); ?>:</label>
- <?php
- echo elgg_view("input/longtext", array(
- "internalname" => "message",
- "value" => $msg_content,
- ));
- ?>
- </p>
- <p><input type="submit" class="submit_button" value="<?php echo elgg_echo("messages:fly"); ?>" /></p>
-</form>
diff --git a/mod/messages/views/default/messages/forms/view.php b/mod/messages/views/default/messages/forms/view.php
deleted file mode 100644
index f8fce93a9..000000000
--- a/mod/messages/views/default/messages/forms/view.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-/**
-* View message
-*
-* @package ElggMessages
-*/
-
-$body = elgg_view("messages/view",$vars);
-
-$body .= '<div class="messages_buttonbank">';
-$body .= '<input type="hidden" name="type" value="'.$vars['page_view'].'" />';
-$body .= '<input type="hidden" name="offset" value="'.$vars['offset'].'" />';
-$body .= '<input type="submit" name="submit" value="'.elgg_echo('delete').'" /> ';
-
-if($vars['page_view'] == "inbox"){
- $body .= '<input type="submit" name="submit" value="'.elgg_echo('messages:markread').'" /> ';
-}
-
-$body .= '<input class="cancel_button" type="button" onclick="javascript:$(\'input[type=checkbox]\').click();" value="'.elgg_echo('messages:toggle').'" />';
-$body .= '</div>';
-
-echo elgg_view('input/form',array('body' => $body, 'action' => 'action/messages/delete', 'method' => 'post', 'internalid' => 'messages_list_form')); \ No newline at end of file
diff --git a/mod/messages/views/default/messages/js.php b/mod/messages/views/default/messages/js.php
new file mode 100644
index 000000000..60cf36b92
--- /dev/null
+++ b/mod/messages/views/default/messages/js.php
@@ -0,0 +1,7 @@
+
+// messages plugin toggle
+elgg.register_hook_handler('init', 'system', function() {
+ $("#messages-toggle").click(function() {
+ $('input[type=checkbox]').click();
+ });
+});
diff --git a/mod/messages/views/default/messages/menu.php b/mod/messages/views/default/messages/menu.php
deleted file mode 100644
index 566a87179..000000000
--- a/mod/messages/views/default/messages/menu.php
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-/**
- * Elgg hoverover extender for messages
- *
- * @package ElggMessages
- */
-
-// login check already performed in profile/icon
-?>
-<li class="user_menu_profile">
- <a class="send_message" href="<?php echo elgg_get_site_url(); ?>mod/messages/send.php?send_to=<?php echo $vars['entity']->guid; ?>"><?php echo elgg_echo("messages:sendmessage"); ?></a>
-</li> \ No newline at end of file
diff --git a/mod/messages/views/default/messages/messages.php b/mod/messages/views/default/messages/messages.php
deleted file mode 100644
index 9eeaa9ef4..000000000
--- a/mod/messages/views/default/messages/messages.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * Elgg messages individual view
- *
- * @package ElggMessages
- *
- *
- * @uses $vars['entity'] Optionally, the message to view
- * @uses get_input('type') If the user accesses the message from their sentbox, this variable is passed
- * and used to make sure the correct icon and name is displayed
- */
-// set some variables to use below
-if(get_input("type") == "sent"){
- // send back to the users sentbox
- $url = elgg_get_site_url() . "mod/messages/sent.php";
- // set up breadcrumbs context
- elgg_push_breadcrumb(elgg_echo('messages:sent'), $url);
- //this is used on the delete link so we know which type of message it is
- $type = "sent";
-} else {
- //send back to the users inbox
- $url = elgg_get_site_url() . "pg/messages/" . get_loggedin_user()->username;
- // set up breadcrumbs context
- elgg_push_breadcrumb(elgg_echo('messages:inbox'), $url);
- //this is used on the delete link so we know which type of message it is
- $type = "inbox";
-}
-
-// fix for RE: RE: RE: that builds on replies
-$reply_title = $vars['entity']->title;
-if (strncmp($reply_title, "RE:", 3) != 0) {
- $reply_title = "RE: " . $reply_title;
-}
-
-if (isloggedin())
- if (isset($vars['entity'])) {
- if ($vars['entity']->toId == get_loggedin_userid()
- || $vars['entity']->owner_guid == get_loggedin_userid()) {
- // display breadcrumbs
- elgg_push_breadcrumb($vars['entity']->title);
- echo elgg_view('navigation/breadcrumbs');
-?>
-<!-- display the content header block -->
- <div id="content_header" class="clearfloat">
- <div class="content_header_title"><h2><?php echo $vars['entity']->title; ?></h2></div>
- <div class="content_header_options">
- <a class="action_button message_reply" onclick="elgg_slide_toggle(this,'#elgg_page_contents','#message_reply_form');"><?php echo elgg_echo('messages:answer'); ?></a>
- <?php echo elgg_view("output/confirmlink", array(
- 'href' => "action/messages/delete?message_id=" . $vars['entity']->getGUID() . "&type={$type}&submit=" . elgg_echo('delete'),
- 'text' => elgg_echo('delete'),
- 'confirm' => elgg_echo('deleteconfirm'),
- 'class' => "action_button disabled"
- ));
- ?>
- </div>
- </div>
-
- <div class="entity_listing messages clearfloat">
- <?php
- // we need a different user icon and name depending on whether the user is reading the message
- // from their inbox or sentbox. If it is the inbox, then the icon and name will be the person who sent
- // the message. If it is the sentbox, the icon and name will be the user the message was sent to
- if($type == "sent"){
- //get an instance of the user who the message has been sent to so we can access the name and icon
- $user_object = get_entity($vars['entity']->toId);
- $message_icon = elgg_view("profile/icon",array('entity' => $user_object, 'size' => 'tiny'));
- $message_owner = elgg_echo('messages:to').": <a href='".elgg_get_site_url()."pg/profile/".$user_object->username."'>".$user_object->name."</a>";
- }else{
- $user_object = get_entity($vars['entity']->fromId);
- $message_icon = elgg_view("profile/icon",array('entity' => $user_object, 'size' => 'tiny'));
- $message_owner = elgg_echo('messages:from').": <a href='".elgg_get_site_url()."pg/profile/".$user_object->username."'>".get_entity($vars['entity']->fromId)->name."</a>";
- }
- ?>
- <div class="entity_listing_icon"><?php echo $message_icon ?></div>
- <div class="entity_listing_info"><p><?php echo $message_owner ?></p>
- <p class="entity_subtext"><?php echo elgg_view_friendly_time($vars['entity']->time_created); ?></p>
- </div>
- </div>
-
- <div class="messagebody margin_top clearfloat">
- <?php
- // if the message is a reply, display the message the reply was for
- // @todo I need to figure out how to get the description out using -> (anyone?)
- if($main_message = $vars['entity']->getEntitiesFromRelationship("reply")){
- echo $main_message[0][description];
- }
- ?>
- <!-- display the message -->
- <?php echo elgg_view('output/longtext',array('value' => $vars['entity']->description)); ?>
- </div>
-
- <!-- reply form -->
- <div id="message_reply_form" class="hidden margin_top">
- <h2><?php echo elgg_echo('messages:answer'); ?></h2>
- <form action="<?php echo elgg_get_site_url(); ?>action/messages/send" method="post" name="messageForm" class="margin_top" id="messages_send_form">
- <?php echo elgg_view('input/securitytoken'); ?>
- <p><label><?php echo elgg_echo("messages:title"); ?>: <br /><input type='text' name='title' class="input_text" value='<?php echo $reply_title; ?>' /></label></p>
- <p class="longtext_inputarea"><label><?php echo elgg_echo("messages:message"); ?>:</label>
- <?php echo elgg_view("input/longtext", array(
- "internalname" => "message",
- "value" => '',
- ));
- ?></p>
-
- <?php
- //pass across the guid of the message being replied to
- echo "<input type='hidden' name='reply' value='" . $vars['entity']->getGUID() . "' />";
- //pass along the owner of the message being replied to
- echo "<input type='hidden' name='send_to' value='" . $vars['entity']->fromId . "' />";
- ?>
- <input type="submit" class="submit_button" value="<?php echo elgg_echo("messages:fly"); ?>" />
- </form>
- </div>
-
-<?php
- }
-} \ No newline at end of file
diff --git a/mod/messages/views/default/messages/topbar.php b/mod/messages/views/default/messages/topbar.php
deleted file mode 100644
index 51ca8a15b..000000000
--- a/mod/messages/views/default/messages/topbar.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * Elgg messages topbar extender
- *
- * @package ElggMessages
- */
-
-gatekeeper();
-
-//get unread messages
-$num_messages = count_unread_messages();
-if($num_messages){
- $num = $num_messages;
-} else {
- $num = 0;
-}
-
-if($num == 0) {
-?>
- <a href="<?php echo elgg_get_site_url(); ?>pg/messages/<?php echo get_loggedin_user()->username; ?>" class="privatemessages" >&nbsp;</a>
-<?php
- }else{
-?>
- <a href="<?php echo elgg_get_site_url(); ?>pg/messages/<?php echo get_loggedin_user()->username; ?>" class="privatemessages new" ><span><?php echo $num; ?></span></a>
-<?php
- }
diff --git a/mod/messages/views/default/messages/view.php b/mod/messages/views/default/messages/view.php
deleted file mode 100644
index 13f6fec82..000000000
--- a/mod/messages/views/default/messages/view.php
+++ /dev/null
@@ -1,121 +0,0 @@
-<?php
-/**
- * Elgg messages view page
- *
- * @package ElggMessages
- *
- * @uses $vars['entity'] An array of messages to view
- * @uses $vars['page_view'] This is the page the messages are being accessed from; inbox or sentbox
- *
- */
-
-$limit = $vars['limit']; if (empty($limit)) $limit = 10;
-$offset = $vars['offset']; if (!isset($offset)) $offset = 0;
-
-// If there are any messages to view, view them
-if (isloggedin())
-if (is_array($vars['entity']) && sizeof($vars['entity']) > 0) {
-
- // get the correct display for the inbox view
- if($vars['page_view'] == "inbox") {
-
- $counter = 0;
-
- foreach($vars['entity'] as $message) {
- if ($message->owner_guid == get_loggedin_userid() || $message->toId == get_loggedin_userid()) {
-
- //make sure to only display the messages that have not been 'deleted' (1 = deleted)
- if($message->hiddenFrom != 1){
- // check to see if the message has been read, if so, set the correct container class
- if($message->readYet == 1){
- echo "<div class='message read clearfloat'>";
- }else{
- echo "<div class='message notread clearfloat'>";
- }
- // get the icon of the user who owns the message
- $from = get_entity($message->fromId);
- echo "<div class='entity_listing_icon'>".elgg_view("profile/icon",array('entity' => $from, 'size' => 'tiny'))."</div>";
- // message block (message sender, message subject, delete checkbox)
- echo "<div class='entity_listing_info'><div class='message_sender'>".$from->name."<p class='entity_subtext'>".elgg_view_friendly_time($message->time_created)."</p></div>";
- // display message subject
- echo "<div class='message_subject'>";
- // display delete button
- echo "<span class='delete_button'>" . elgg_view("output/confirmlink", array(
- 'href' => "action/messages/delete?message_id=" . $message->getGUID() . "&type=inbox&submit=" . urlencode(elgg_echo('delete')),
- 'text' => elgg_echo('delete'),
- 'confirm' => elgg_echo('deleteconfirm'),
- )) . "</span>";
- echo "<p class='entity_title'><input type='checkbox' name=\"message_id[]\" value=\"{$message->guid}\" />";
- echo "<a href=\"{$message->getURL()}\">" . $message->title . "</a></p>";
- echo "</div></div></div>"; // close the message container
- }//end of hiddenFrom if statement
- } // end of user check
- $counter++;
- if ($counter == $limit) break;
-
- }//end of for each loop
- }//end of inbox if statement
-
- // get the correct display for the sentbox view
- if($vars['page_view'] == "sent") {
-
- $counter = 0;
-
- foreach($vars['entity'] as $message) {
-
- //make sure to only display the messages that have not been 'deleted' (1 = deleted)
- if($message->hiddenTo != 1){
-
- //get the correct user entity
- $user = get_entity($message->toId);
- echo "<div class='message sent clearfloat'>";
- //get the icon for the user the message was sent to
- echo "<div class='entity_listing_icon'>".elgg_view("profile/icon",array('entity' => $user, 'size' => 'tiny'))."</div>";
- echo "<div class='entity_listing_info'><div class='message_sender'>".get_loggedin_user()->name."<p class='entity_subtext'>".elgg_view_friendly_time($message->time_created)."</p></div>";
- // display message subject
- echo "<div class='message_subject'>";
- //display the link to 'delete'
- echo "<div class='delete_button'>" . elgg_view("output/confirmlink", array(
- 'href' => "action/messages/delete?message_id=" . $message->getGUID() . "&type=sent&submit=" . urlencode(elgg_echo('delete')),
- 'text' => elgg_echo('delete'),
- 'confirm' => elgg_echo('deleteconfirm'),
- )) . "</div>";
- echo "<p class='entity_title'><input type='checkbox' name=\"message_id[]\" value=\"{$message->guid}\" /> ";
- echo "<a href=\"{$message->getURL()}?type=sent\">" . $message->title . "</a></p>";
- echo "</div></div></div>"; // close the message container
- }//close hiddeTo if statement
-
- $counter++;
- if ($counter == $limit) break;
-
- }//close foreach
-
- }//close page_view sent if statement
-
- $baseurl = $_SERVER['REQUEST_URI'];
- $nav = '';
-
- if (sizeof($vars['entity']) > $limit) {
- $newoffset = $offset + $limit;
- $nexturl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));
-
- $nav .= '<a class="pagination_previous" href="'.$nexturl.'">&laquo; ' . elgg_echo('previous') . '</a> ';
- }
-
- if ($offset > 0) {
- $newoffset = $offset - $limit;
- if ($newoffset < 0) $newoffset = 0;
-
- $prevurl = elgg_http_add_url_query_elements($baseurl, array('offset' => $newoffset));
-
- $nav .= '<a class="pagination_next" href="'.$prevurl.'">' . elgg_echo('next') . ' &raquo;</a> ';
- }
-
-
- if (!empty($nav)) {
- echo '<div class="pagination"><p>'.$nav.'</p></div>';
- }
-
-} else {
- echo "<p>".elgg_echo("messages:nomessages")."</p>";
-}
diff --git a/mod/messages/views/default/object/messages.php b/mod/messages/views/default/object/messages.php
new file mode 100644
index 000000000..b12f98522
--- /dev/null
+++ b/mod/messages/views/default/object/messages.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * File renderer.
+ *
+ * @package ElggFile
+ */
+
+$full = elgg_extract('full_view', $vars, false);
+$message = elgg_extract('entity', $vars, false);
+
+if (!$message) {
+ return true;
+}
+
+if ($message->toId == elgg_get_page_owner_guid()) {
+ // received
+ $user = get_entity($message->fromId);
+ if ($user) {
+ $icon = elgg_view_entity_icon($user, 'tiny');
+ $user_link = elgg_view('output/url', array(
+ 'href' => "messages/compose?send_to=$user->guid",
+ 'text' => $user->name,
+ 'is_trusted' => true,
+ ));
+ } else {
+ $icon = '';
+ $user_link = elgg_echo('messages:deleted_sender');
+ }
+
+ if ($message->readYet) {
+ $class = 'message read';
+ } else {
+ $class = 'message unread';
+ }
+
+} else {
+ // sent
+ $user = get_entity($message->toId);
+
+ if ($user) {
+ $icon = elgg_view_entity_icon($user, 'tiny');
+ $user_link = elgg_view('output/url', array(
+ 'href' => "messages/compose?send_to=$user->guid",
+ 'text' => elgg_echo('messages:to_user', array($user->name)),
+ 'is_trusted' => true,
+ ));
+ } else {
+ $icon = '';
+ $user_link = elgg_echo('messages:deleted_sender');
+ }
+
+ $class = 'message read';
+}
+
+$timestamp = elgg_view_friendly_time($message->time_created);
+
+$subject_info = '';
+if (!$full) {
+ $subject_info .= "<input type='checkbox' name=\"message_id[]\" value=\"{$message->guid}\" />";
+}
+$subject_info .= elgg_view('output/url', array(
+ 'href' => $message->getURL(),
+ 'text' => $message->title,
+ 'is_trusted' => true,
+));
+
+$delete_link = elgg_view("output/confirmlink", array(
+ 'href' => "action/messages/delete?guid=" . $message->getGUID(),
+ 'text' => "<span class=\"elgg-icon elgg-icon-delete float-alt\"></span>",
+ 'confirm' => elgg_echo('deleteconfirm'),
+ 'encode_text' => false,
+ ));
+
+$body = <<<HTML
+<div class="messages-owner">$user_link</div>
+<div class="messages-subject">$subject_info</div>
+<div class="messages-timestamp">$timestamp</div>
+<div class="messages-delete">$delete_link</div>
+HTML;
+
+if ($full) {
+ echo elgg_view_image_block($icon, $body, array('class' => $class));
+ echo elgg_view('output/longtext', array('value' => $message->description));
+} else {
+ echo elgg_view_image_block($icon, $body, array('class' => $class));
+} \ No newline at end of file