aboutsummaryrefslogtreecommitdiff
path: root/mod/messageboard
diff options
context:
space:
mode:
Diffstat (limited to 'mod/messageboard')
-rw-r--r--mod/messageboard/actions/add.php21
-rw-r--r--mod/messageboard/actions/delete.php29
-rw-r--r--mod/messageboard/ajax_endpoint/load.php42
-rw-r--r--mod/messageboard/history.php41
-rw-r--r--mod/messageboard/index.php34
-rw-r--r--mod/messageboard/languages/en.php5
-rw-r--r--mod/messageboard/manifest.xml2
-rw-r--r--mod/messageboard/pages/owner.php58
-rw-r--r--mod/messageboard/start.php79
-rw-r--r--mod/messageboard/views/default/annotation/messageboard.php11
-rw-r--r--mod/messageboard/views/default/messageboard/js.php31
-rw-r--r--mod/messageboard/views/default/messageboard/messageboard_content.php61
-rw-r--r--mod/messageboard/views/default/widgets/messageboard/content.php28
-rw-r--r--mod/messageboard/views/default/widgets/messageboard/edit.php4
14 files changed, 206 insertions, 240 deletions
diff --git a/mod/messageboard/actions/add.php b/mod/messageboard/actions/add.php
index 5a34904d7..55bc5775a 100644
--- a/mod/messageboard/actions/add.php
+++ b/mod/messageboard/actions/add.php
@@ -10,15 +10,28 @@ $owner_guid = get_input("owner_guid");
$owner = get_entity($owner_guid);
if ($owner && !empty($message_content)) {
- if (messageboard_add(elgg_get_logged_in_user_entity(), $owner, $message_content, $owner->access_id)) {
+ $result = messageboard_add(elgg_get_logged_in_user_entity(), $owner, $message_content, $owner->access_id);
+
+ if ($result) {
system_message(elgg_echo("messageboard:posted"));
// push the newest content out if using ajax
$is_ajax = array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
if ($is_ajax) {
- $contents = $owner->getAnnotations('messageboard', 1, 0, 'desc');
- $post = elgg_view("messageboard/messageboard_content", array('annotation' => $contents[0]));
- echo json_encode(array('post' => $post));
+ // always return the entity with the full ul and li
+ // this is parsed out as needed by js.
+ // if this is the only post we need to return the entire ul
+ $options = array(
+ 'annotations_name' => 'messageboard',
+ 'guid' => $owner->getGUID(),
+ 'limit' => $num_display,
+ 'pagination' => false,
+ 'reverse_order_by' => true,
+ 'limit' => 1
+ );
+
+ $output = elgg_list_annotations($options);
+ echo json_encode(array('post' => $output));
}
} else {
diff --git a/mod/messageboard/actions/delete.php b/mod/messageboard/actions/delete.php
index 1cc20f285..a40329cb5 100644
--- a/mod/messageboard/actions/delete.php
+++ b/mod/messageboard/actions/delete.php
@@ -1,37 +1,18 @@
<?php
-
/**
* Elgg Message board: delete message action
*
* @package ElggMessageBoard
*/
-// Make sure we can get the comment in question
$annotation_id = (int) get_input('annotation_id');
+$message = elgg_get_annotation_from_id($annotation_id);
-//make sure that there is a message on the message board matching the passed id
-if ($message = elgg_get_annotation_from_id($annotation_id)) {
-
- //grab the user or group entity
- $entity = get_entity($message->entity_guid);
-
- //check to make sure the current user can actually edit the message board
- if ($message->canEdit()) {
- //delete the comment
- $message->delete();
- // delete river entry
- remove_from_river_by_annotation($annotation_id);
- //display message
- system_message(elgg_echo("messageboard:deleted"));
- //generate the url to forward to
- $url = "pg/messageboard/" . $entity->username;
- //forward the user back to their message board
- forward($url);
- }
-
+if ($message && $message->canEdit() && $message->delete()) {
+ remove_from_river_by_annotation($annotation_id);
+ system_message(elgg_echo("messageboard:deleted"));
} else {
- $url = "";
system_message(elgg_echo("messageboard:notdeleted"));
}
-forward($url);
+forward(REFERER);
diff --git a/mod/messageboard/ajax_endpoint/load.php b/mod/messageboard/ajax_endpoint/load.php
deleted file mode 100644
index 4509c30ef..000000000
--- a/mod/messageboard/ajax_endpoint/load.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-/**
- * Elgg message board widget ajax logic page
- *
- * @package ElggMessageBoard
- */
-
-// Load Elgg engine will not include plugins
-require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");
-
-//get the required info
-
-//the actual message
-$message = get_input('messageboard_content');
-//the number of messages to display
-$numToDisplay = get_input('numToDisplay');
-//get the full page owner entity
-$user = get_entity(get_input('pageOwner'));
-
-//stage one - if a message was posted, add it as an annotation
-if ($message) {
-
- if (!messageboard_add(elgg_get_logged_in_user_entity(), $user, $message, $user->access_id)) {
- echo elgg_echo("messageboard:failure");
- }
-
-} else {
- echo elgg_echo('messageboard:somethingwentwrong');
-}
-
-
-//step two - grab the latest messageboard contents, this will include the message above, unless an issue
-//has occurred.
-$contents = $user->getAnnotations('messageboard', $numToDisplay, 0, 'desc');
-
-//step three - display the latest results
-if ($contents) {
- foreach ($contents as $content) {
- echo elgg_view("messageboard/messageboard_content", array('annotation' => $content));
- }
-}
diff --git a/mod/messageboard/history.php b/mod/messageboard/history.php
deleted file mode 100644
index 2275ab9da..000000000
--- a/mod/messageboard/history.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-/**
- * Elgg Message board history page
- *
- * @package ElggMessageBoard
- */
-
-
-// Load Elgg engine
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-// Get the user who is the owner of the message board
-$current_user = elgg_get_logged_in_user_guid();
-
-// this is the user how has posted on your messageboard that you want to display your history with
-$history_user = get_input('user');
-
-$users_array = array($current_user, $history_user);
-
-$options = array(
- 'guids' => $users_array,
- 'type' => 'user',
- 'annotation_name' => 'messageboard',
- 'owner_guids' => $users_array,
- 'limit' => 10,
- 'offset' => 0,
- 'reverse_order_by' => true
-);
-
-$contents = elgg_get_annotations($options);
-
-// Get the content to display
-$area2 = elgg_view_title(elgg_echo('messageboard:history:title'));
-$area2 .= elgg_view("messageboard/messageboard", array('annotation' => $contents));
-
-//select the correct canvas area
-$body = elgg_view_layout("two_column_left_sidebar", '', $area2);
-
-// Display page
-echo elgg_view_page(elgg_echo('messageboard:history:title'),$body);
diff --git a/mod/messageboard/index.php b/mod/messageboard/index.php
deleted file mode 100644
index 102959e24..000000000
--- a/mod/messageboard/index.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-/**
- * Elgg Message board index page
- *
- * @package ElggMessageBoard
- */
-
-
-// Load Elgg engine
-require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-// Get the user who is the owner of the message board
-$entity = elgg_get_page_owner_entity();
-
-// Get any annotations for their message board
-$contents = $entity->getAnnotations('messageboard', 50, 0, 'desc');
-
-// Get the content to display
-$area2 = elgg_view_title(elgg_echo('messageboard:board'));
-
-// only display the add form and board to logged in users
-if (elgg_is_logged_in()) {
- $area2 .= elgg_view("messageboard/forms/add");
- $area2 .= elgg_view("messageboard/messageboard", array('annotation' => $contents));
-}
-
-
-//select the correct canvas area
-$body = elgg_view_layout("two_column_left_sidebar", '', $area2);
-
-// Display page
-echo elgg_view_page(elgg_echo('messageboard:user', array($entity->name)), $body);
-
diff --git a/mod/messageboard/languages/en.php b/mod/messageboard/languages/en.php
index 537177014..2ae6f3a49 100644
--- a/mod/messageboard/languages/en.php
+++ b/mod/messageboard/languages/en.php
@@ -20,6 +20,9 @@ $english = array(
'messageboard:replyon' => 'reply on',
'messageboard:history' => "history",
+ 'messageboard:owner' => '%s\'s message board',
+ 'messageboard:owner_history' => '%s\'s posts on %s\'s message board',
+
/**
* Message board widget river
**/
@@ -45,7 +48,7 @@ $english = array(
'messageboard:email:subject' => 'You have a new message board comment!',
'messageboard:email:body' => "You have a new message board comment from %s. It reads:
-
+
%s
diff --git a/mod/messageboard/manifest.xml b/mod/messageboard/manifest.xml
index fa8774cf5..3f9e95125 100644
--- a/mod/messageboard/manifest.xml
+++ b/mod/messageboard/manifest.xml
@@ -2,7 +2,7 @@
<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
<name>Message Board</name>
<author>Core developers</author>
- <version>1.7</version>
+ <version>1.8</version>
<description>This plugin allows users to put a message board on their profile for other users to post comments.</description>
<website>http://www.elgg.org/</website>
<copyright>See COPYRIGHT.txt</copyright>
diff --git a/mod/messageboard/pages/owner.php b/mod/messageboard/pages/owner.php
new file mode 100644
index 000000000..7a65ec68b
--- /dev/null
+++ b/mod/messageboard/pages/owner.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Elgg Message board index page
+ *
+ * @package MessageBoard
+ */
+
+$page_owner_guid = get_input('page_owner_guid');
+elgg_set_page_owner_guid($page_owner_guid);
+$page_owner = elgg_get_page_owner_entity();
+$history_username = get_input('history_username');
+$history_user = get_user_by_username($history_username);
+
+elgg_push_breadcrumb($page_owner->name, $page_owner->getURL());
+
+$options = array(
+ 'annotations_name' => 'messageboard',
+ 'guid' => $page_owner_guid,
+ 'limit' => 10
+);
+
+if ($history_user) {
+ $options['annotations_owner_guid'] = $history_user->getGUID();
+ $title = elgg_echo('messageboard:owner_history', array($history_user->name, $page_owner->name));
+
+ if ($page_owner instanceof ElggGroup) {
+ $mb_url = "pg/messageboard/group/$page_owner->guid/owner";
+ } else {
+ $mb_url = "pg/messageboard/owner/$page_owner->username";
+ }
+} else {
+ $title = elgg_echo('messageboard:owner', array($page_owner->name));
+ $mb_url = '';
+}
+
+elgg_push_breadcrumb(elgg_echo('messageboard:board'), $mb_url);
+
+if ($history_user) {
+ elgg_push_breadcrumb($history_user->name);
+}
+
+$content = elgg_list_annotations($options);
+
+if (!$content) {
+ $content = elgg_echo('messageboard:none');
+}
+
+$vars = array(
+ 'filter' => false,
+ 'buttons' => false,
+ 'content' => $content,
+ 'title' => $title,
+ 'reverse_order_by' => true
+);
+
+$body = elgg_view_layout('content', $vars);
+
+echo elgg_view_page($title, $body); \ No newline at end of file
diff --git a/mod/messageboard/start.php b/mod/messageboard/start.php
index a4792d322..ecf5615b5 100644
--- a/mod/messageboard/start.php
+++ b/mod/messageboard/start.php
@@ -1,48 +1,89 @@
<?php
-
/**
* Elgg Message board
* This plugin allows users and groups to attach a message board to their profile for other users
* to post comments.
*
- * @package ElggMessageBoard
+ * @package MessageBoard
*/
/**
* MessageBoard initialisation
*/
function messageboard_init() {
-
- // add css and js
- elgg_extend_view('css/screen', 'messageboard/css');
+ // js
elgg_extend_view('js/elgg', 'messageboard/js');
- // Register a page handler, so we can have nice URLs
elgg_register_page_handler('messageboard', 'messageboard_page_handler');
- // add a messageboard widget - only for profile
+ // messageboard widget - only for profile for now
elgg_register_widget_type('messageboard', elgg_echo("messageboard:board"), elgg_echo("messageboard:desc"), "profile");
- // Register actions
- $action_path = elgg_get_plugins_path() . 'messageboard/actions';
+ // actions
+ $action_path = dirname(__FILE__) . '/actions';
elgg_register_action("messageboard/add", "$action_path/add.php");
elgg_register_action("messageboard/delete", "$action_path/delete.php");
}
/**
- * Messageboard page handler
+ * Messageboard dispatcher for flat message board.
+ * Profile (and eventually group) widgets handle their own.
+ *
+ * URLs take the form of
+ * User's messageboard: pg/messageboard/owner/<username>
+ * Y's history of posts on X's board: pg/messageboard/owner/<X>/history/<Y>
+ * New post: pg/messageboard/add/<guid> (container: user or group)
+ * Group messageboard: pg/messageboard/group/<guid>/owner
*
- * @param array $page Array of page elements, forwarded by the page handling mechanism
+ * @param array $page Array of page elements
+ * @return bool
*/
function messageboard_page_handler($page) {
+ $new_section_one = array('owner', 'add', 'group');
+
+ // if the first part is a username, forward to new format
+ if (isset($page[0]) && !in_array($page[0], $new_section_one) && get_user_by_username($page[0])) {
+ register_error(elgg_echo("changebookmark"));
+ $url = "pg/messageboard/owner/{$page[0]}";
+ forward($url);
+ }
- // The username should be the first array entry
- if (isset($page[0])) {
- set_input('username', $page[0]);
+ $pages = dirname(__FILE__) . '/pages';
+
+ switch ($page[0]) {
+ case 'owner':
+ //@todo if they have the widget disabled, don't allow this.
+ $owner_name = elgg_extract(1, $page);
+ $owner = get_user_by_username($owner_name);
+ set_input('page_owner_guid', $owner->guid);
+ $history = elgg_extract(2, $page);
+ $username = elgg_extract(3, $page);
+
+ if ($history && $username) {
+ set_input('history_username', $username);
+ }
+
+ include "$pages/owner.php";
+ break;
+
+ case 'add':
+ $container_guid = elgg_extract(1, $page);
+ set_input('container_guid', $container_guid);
+ include "$pages/add.php";
+ break;
+
+ case 'group':
+ group_gatekeeper();
+ $owner_guid = elgg_extract(1, $page);
+ set_input('page_owner_guid', $owner_guid);
+ include "$pages/owner.php";
+ break;
}
// Include the standard messageboard index
include(elgg_get_plugins_path() . "messageboard/index.php");
+
+ return true;
}
/**
@@ -55,10 +96,10 @@ function messageboard_page_handler($page) {
* @return bool
*/
function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC) {
-
$result = $owner->annotate('messageboard', $message, $access_id, $poster->guid);
+
if (!$result) {
- return FALSE;
+ return false;
}
add_to_river('river/object/messageboard/create',
@@ -83,9 +124,7 @@ function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC)
notify_user($owner->guid, $poster->guid, $subject, $body);
}
- return TRUE;
+ return $result;
}
-
-// Register initialisation callback
-elgg_register_event_handler('init', 'system', 'messageboard_init');
+elgg_register_event_handler('init', 'system', 'messageboard_init'); \ No newline at end of file
diff --git a/mod/messageboard/views/default/annotation/messageboard.php b/mod/messageboard/views/default/annotation/messageboard.php
new file mode 100644
index 000000000..fa4b43ff3
--- /dev/null
+++ b/mod/messageboard/views/default/annotation/messageboard.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Message board post
+ *
+ * @uses $vars['annotation'] ElggAnnotation object
+ * @uses $vars['full'] Display fill view or brief view
+ */
+
+$vars['delete_action'] = 'action/messageboard/delete';
+
+echo elgg_view('annotation/generic_comment', $vars); \ No newline at end of file
diff --git a/mod/messageboard/views/default/messageboard/js.php b/mod/messageboard/views/default/messageboard/js.php
index c76040945..b51c59209 100644
--- a/mod/messageboard/views/default/messageboard/js.php
+++ b/mod/messageboard/views/default/messageboard/js.php
@@ -1,7 +1,13 @@
elgg.provide('elgg.messageboard');
elgg.messageboard.init = function() {
- $('form.elgg-messageboard input[type=submit]').live('click', elgg.messageboard.submit);
+ var form = $('form[name=elgg-messageboard]');
+ form.find('input[type=submit]').live('click', elgg.messageboard.submit);
+
+ // can't undelete because of init load order
+ form.parent().find('a.elgg-requires-confirmation').removeClass('elgg-requires-confirmation');
+ // delegate() instead of live() because live() has to be at the top level of chains...can't use parent().
+ form.parent().delegate('.delete-button a', 'click', elgg.messageboard.delete);
}
elgg.messageboard.submit = function(e) {
@@ -11,7 +17,14 @@ elgg.messageboard.submit = function(e) {
elgg.action('messageboard/add', {
data: data,
success: function(json) {
- form.parent().find('#messageboard_wrapper').prepend(json.output.post);
+ // the action always returns the full ul and li wrapped annotation.
+ var ul = form.next('ul.elgg-annotation-list');
+
+ if (ul.length < 1) {
+ form.parent().append(json.output.post);
+ } else {
+ ul.prepend($(json.output.post).find('li:first'));
+ };
form.find('textarea').val('');
}
});
@@ -19,6 +32,20 @@ elgg.messageboard.submit = function(e) {
e.preventDefault();
}
+elgg.messageboard.delete = function(e) {
+ var link = $(this);
+ var confirmText = link.attr('title') || elgg.echo('question:areyousure');
+
+ if (confirm(confirmText)) {
+ elgg.action($(this).attr('href'), {
+ success: function() {
+ $(link).closest('li').remove();
+ }
+ });
+ }
+
+ e.preventDefault();
+}
elgg.register_event_handler('init', 'system', elgg.messageboard.init); \ No newline at end of file
diff --git a/mod/messageboard/views/default/messageboard/messageboard_content.php b/mod/messageboard/views/default/messageboard/messageboard_content.php
deleted file mode 100644
index abd81d0ad..000000000
--- a/mod/messageboard/views/default/messageboard/messageboard_content.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-/**
- * Elgg Message board individual item display view
- *
- * @package ElggMessageBoard
- */
-
-?>
-
-<div class="messageboard"><!-- start of messageboard div -->
-
- <!-- display the user icon of the user that posted the message -->
- <div class="message_sender">
- <?php
- echo elgg_view("profile/icon",array('entity' => get_entity($vars['annotation']->owner_guid), 'size' => 'tiny'));
- ?>
- </div>
-
- <!-- display the user's name who posted and the date/time -->
- <p class="message_item_timestamp">
- <?php echo get_entity($vars['annotation']->owner_guid)->name . " " . elgg_view_friendly_time($vars['annotation']->time_created); ?>
- </p>
-
- <!-- output the actual comment -->
- <div class="message"><?php echo elgg_view("output/longtext",array("value" => parse_urls($vars['annotation']->value))); ?></div>
- <div class="message_buttons">
-
- <?php
-
- // if the user looking at the comment can edit, show the delete link
- if ($vars['annotation']->canEdit()) {
-
-
- echo "<div class='delete_message'>" . elgg_view("output/confirmlink",array(
- 'href' => "action/messageboard/delete?annotation_id=" . $vars['annotation']->id,
- 'text' => elgg_echo('delete'),
- 'confirm' => elgg_echo('deleteconfirm'),
- )) . "</div>";
-
- } //end of can edit if statement
- ?>
- <?php
- // If the message being looked at is owned by the current user, don't show the reply
- // Also do not show if the user is not logged in
- if (elgg_is_logged_in() && $vars['annotation']->owner_guid != elgg_get_logged_in_user_guid()) {
-
- //get the message owner
- $msg_owner = get_entity($vars['annotation']->owner_guid);
- //create the url to their messageboard
- $user_mb = "pg/messageboard/" . $msg_owner->username;
-
- echo "<a href=\"" . elgg_get_site_url() . $user_mb . "\">".elgg_echo('messageboard:replyon')." " . $msg_owner->name . "'s " . elgg_echo('messageboard:messageboard') . "</a> | ";
-
- echo "<a href=\"" . elgg_get_site_url() . "mod/messageboard/history.php?user=" . $msg_owner->guid ."\">" . elgg_echo('messageboard:history') . "</a>";
- }
- ?>
-
- </div>
- <div class="clearfloat"></div>
-</div><!-- end of messageboard div -->
diff --git a/mod/messageboard/views/default/widgets/messageboard/content.php b/mod/messageboard/views/default/widgets/messageboard/content.php
index 5f0cc8676..7ec3e5d4e 100644
--- a/mod/messageboard/views/default/widgets/messageboard/content.php
+++ b/mod/messageboard/views/default/widgets/messageboard/content.php
@@ -6,7 +6,7 @@
* @package ElggMessageBoard
*/
-$user = elgg_get_page_owner_entity();
+$owner = elgg_get_page_owner_entity();
$num_display = 5;
if (isset($vars['entity']->num_display)) {
@@ -14,12 +14,26 @@ if (isset($vars['entity']->num_display)) {
}
if (elgg_is_logged_in()) {
- echo elgg_view_form('messageboard/add', array('class' => 'elgg-messageboard'));
+ echo elgg_view_form('messageboard/add', array('name' => 'elgg-messageboard'));
}
-//this for the first time the page loads, grab the latest messages.
-$contents = $user->getAnnotations('messageboard', $num_display, 0, 'desc');
+$options = array(
+ 'annotations_name' => 'messageboard',
+ 'guid' => $owner->getGUID(),
+ 'limit' => $num_display,
+ 'pagination' => false,
+ 'reverse_order_by' => true
+);
-if ($contents) {
- echo elgg_view('messageboard/messageboard', array('annotation' => $contents));
-} \ No newline at end of file
+echo elgg_list_annotations($options);
+
+if ($owner instanceof ElggGroup) {
+ $url = "pg/messageboard/group/$owner->guid/owner";
+} else {
+ $url = "pg/messageboard/owner/$owner->username";
+}
+
+echo elgg_view('output/url', array(
+ 'href' => $url,
+ 'text' => elgg_echo('messageboard:viewall')
+)); \ No newline at end of file
diff --git a/mod/messageboard/views/default/widgets/messageboard/edit.php b/mod/messageboard/views/default/widgets/messageboard/edit.php
index 470d49060..2157da6c4 100644
--- a/mod/messageboard/views/default/widgets/messageboard/edit.php
+++ b/mod/messageboard/views/default/widgets/messageboard/edit.php
@@ -1,18 +1,16 @@
<?php
-
/**
* Elgg message board widget edit view
*
* @package ElggMessageBoard
*/
-// default value
$num_display = 5;
+
if (isset($vars['entity']->num_display)) {
$num_display = $vars['entity']->num_display;
}
-
?>
<p>
<?php echo elgg_echo("messageboard:num_display"); ?>: