diff options
Diffstat (limited to 'mod/messageboard')
-rw-r--r-- | mod/messageboard/actions/add.php | 38 | ||||
-rw-r--r-- | mod/messageboard/actions/delete.php | 17 | ||||
-rw-r--r-- | mod/messageboard/languages/en.php | 72 | ||||
-rw-r--r-- | mod/messageboard/manifest.xml | 17 | ||||
-rw-r--r-- | mod/messageboard/pages/messageboard/owner.php | 58 | ||||
-rw-r--r-- | mod/messageboard/start.php | 163 | ||||
-rw-r--r-- | mod/messageboard/views/default/forms/messageboard/add.php | 20 | ||||
-rw-r--r-- | mod/messageboard/views/default/messageboard/css.php | 10 | ||||
-rw-r--r-- | mod/messageboard/views/default/messageboard/js.php | 56 | ||||
-rw-r--r-- | mod/messageboard/views/default/river/object/messageboard/create.php | 12 | ||||
-rw-r--r-- | mod/messageboard/views/default/widgets/messageboard/content.php | 35 | ||||
-rw-r--r-- | mod/messageboard/views/default/widgets/messageboard/edit.php | 22 |
12 files changed, 520 insertions, 0 deletions
diff --git a/mod/messageboard/actions/add.php b/mod/messageboard/actions/add.php new file mode 100644 index 000000000..971dd22fc --- /dev/null +++ b/mod/messageboard/actions/add.php @@ -0,0 +1,38 @@ +<?php +/** + * Elgg Message board: add message action + * + * @package ElggMessageBoard + */ + +$message_content = get_input('message_content'); +$owner_guid = get_input("owner_guid"); +$owner = get_entity($owner_guid); + +if ($owner && !empty($message_content)) { + $result = messageboard_add(elgg_get_logged_in_user_entity(), $owner, $message_content, $owner->access_id); + + if ($result) { + system_message(elgg_echo("messageboard:posted")); + + $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 $output; + + } else { + register_error(elgg_echo("messageboard:failure")); + } + +} else { + register_error(elgg_echo("messageboard:blank")); +} + +forward(REFERER); diff --git a/mod/messageboard/actions/delete.php b/mod/messageboard/actions/delete.php new file mode 100644 index 000000000..a1f62278c --- /dev/null +++ b/mod/messageboard/actions/delete.php @@ -0,0 +1,17 @@ +<?php +/** + * Elgg Message board: delete message action + * + * @package ElggMessageBoard + */ + +$annotation_id = (int) get_input('annotation_id'); +$message = elgg_get_annotation_from_id($annotation_id); + +if ($message && $message->canEdit() && $message->delete()) { + system_message(elgg_echo("messageboard:deleted")); +} else { + system_message(elgg_echo("messageboard:notdeleted")); +} + +forward(REFERER); diff --git a/mod/messageboard/languages/en.php b/mod/messageboard/languages/en.php new file mode 100644 index 000000000..9027eb650 --- /dev/null +++ b/mod/messageboard/languages/en.php @@ -0,0 +1,72 @@ +<?php + +$english = array( + + /** + * Menu items and titles + */ + + 'messageboard:board' => "Message board", + 'messageboard:messageboard' => "message board", + 'messageboard:viewall' => "View all", + 'messageboard:postit' => "Post", + 'messageboard:history:title' => "History", + 'messageboard:none' => "There is nothing on this message board yet", + 'messageboard:num_display' => "Number of messages to display", + 'messageboard:desc' => "This is a message board that you can put on your profile where other users can comment.", + + 'messageboard:user' => "%s's message board", + + '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 + */ + 'river:messageboard:user:default' => "%s posted on %s's message board", + + /** + * Status messages + */ + + 'messageboard:posted' => "You successfully posted on the message board.", + 'messageboard:deleted' => "You successfully deleted the message.", + + /** + * Email messages + */ + + '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 + + +To view your message board comments, click here: + + %s + +To view %s's profile, click here: + + %s + +You cannot reply to this email.", + + /** + * Error messages + */ + + 'messageboard:blank' => "Sorry; you need to actually put something in the message area before we can save it.", + 'messageboard:notfound' => "Sorry; we could not find the specified item.", + 'messageboard:notdeleted' => "Sorry; we could not delete this message.", + 'messageboard:somethingwentwrong' => "Something went wrong when trying to save your message, make sure you actually wrote a message.", + + 'messageboard:failure' => "An unexpected error occurred when adding your message. Please try again.", + +); + +add_translation("en", $english); diff --git a/mod/messageboard/manifest.xml b/mod/messageboard/manifest.xml new file mode 100644 index 000000000..617813725 --- /dev/null +++ b/mod/messageboard/manifest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Message Board</name> + <author>Core developers</author> + <version>1.8</version> + <category>bundled</category> + <category>widget</category> + <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> + <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/messageboard/pages/messageboard/owner.php b/mod/messageboard/pages/messageboard/owner.php new file mode 100644 index 000000000..2c854d4f3 --- /dev/null +++ b/mod/messageboard/pages/messageboard/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, + 'reverse_order_by' => true, +); + +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 = "messageboard/group/$page_owner->guid/all"; + } else { + $mb_url = "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, + '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 new file mode 100644 index 000000000..0c65edc4f --- /dev/null +++ b/mod/messageboard/start.php @@ -0,0 +1,163 @@ +<?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 MessageBoard + */ + +/** + * MessageBoard initialisation + */ +function messageboard_init() { + // js + elgg_extend_view('js/elgg', 'messageboard/js'); + + // css + elgg_extend_view('css/elgg', 'messageboard/css'); + + elgg_register_page_handler('messageboard', 'messageboard_page_handler'); + + // messageboard widget - only for profile for now + elgg_register_widget_type('messageboard', elgg_echo("messageboard:board"), elgg_echo("messageboard:desc"), "profile"); + + // actions + $action_path = dirname(__FILE__) . '/actions'; + elgg_register_action("messageboard/add", "$action_path/add.php"); + elgg_register_action("messageboard/delete", "$action_path/delete.php"); + + // delete annotations for posts + elgg_register_plugin_hook_handler('register', 'menu:annotation', 'messageboard_annotation_menu_setup'); +} + +/** + * Messageboard dispatcher for flat message board. + * Profile (and eventually group) widgets handle their own. + * + * URLs take the form of + * User's messageboard: messageboard/owner/<username> + * Y's history of posts on X's board: messageboard/owner/<X>/history/<Y> + * New post: messageboard/add/<guid> (container: user or group) + * Group messageboard: messageboard/group/<guid>/all (not implemented) + * + * @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 = "messageboard/owner/{$page[0]}"; + forward($url); + } + + $pages = dirname(__FILE__) . '/pages/messageboard'; + + 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; + + default: + return false; + } + return true; +} + +/** + * Add messageboard post + * + * @param ElggUser $poster User posting the message + * @param ElggUser $owner User who owns the message board + * @param string $message The posted message + * @param int $access_id Access level (see defines in elgglib.php) + * @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; + } + + add_to_river('river/object/messageboard/create', + 'messageboard', + $poster->guid, + $owner->guid, + $access_id, + 0, + $result); + + // only send notification if not self + if ($poster->guid != $owner->guid) { + $subject = elgg_echo('messageboard:email:subject'); + $body = elgg_echo('messageboard:email:body', array( + $poster->name, + $message, + elgg_get_site_url() . "messageboard/" . $owner->username, + $poster->name, + $poster->getURL() + )); + + notify_user($owner->guid, $poster->guid, $subject, $body); + } + + return $result; +} + + +/** + * Add edit and delete links for forum replies + */ +function messageboard_annotation_menu_setup($hook, $type, $return, $params) { + $annotation = $params['annotation']; + if ($annotation->name != 'messageboard') { + return $return; + } + + if ($annotation->canEdit()) { + $url = elgg_http_add_url_query_elements('action/messageboard/delete', array( + 'annotation_id' => $annotation->id, + )); + + $options = array( + 'name' => 'delete', + 'href' => $url, + 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>", + 'confirm' => elgg_echo('deleteconfirm'), + 'encode_text' => false + ); + $return[] = ElggMenuItem::factory($options); + } + + return $return; +} + +elgg_register_event_handler('init', 'system', 'messageboard_init');
\ No newline at end of file diff --git a/mod/messageboard/views/default/forms/messageboard/add.php b/mod/messageboard/views/default/forms/messageboard/add.php new file mode 100644 index 000000000..b219fd800 --- /dev/null +++ b/mod/messageboard/views/default/forms/messageboard/add.php @@ -0,0 +1,20 @@ +<?php +/** + * Elgg Message board add form body + * + * @package ElggMessageBoard + */ + +echo elgg_view('input/plaintext', array( + 'name' => 'message_content', + 'class' => 'messageboard-input mbs' +)); + +echo elgg_view('input/hidden', array( + 'name' => 'owner_guid', + 'value' => elgg_get_page_owner_guid() +)); + +echo elgg_view('input/submit', array( + 'value' => elgg_echo('post') +)); diff --git a/mod/messageboard/views/default/messageboard/css.php b/mod/messageboard/views/default/messageboard/css.php new file mode 100644 index 000000000..b3cfab957 --- /dev/null +++ b/mod/messageboard/views/default/messageboard/css.php @@ -0,0 +1,10 @@ +<?php +/** + * Elgg Messageboard CSS view + * + */ +?> + +.messageboard-input { + height: 100px; +} diff --git a/mod/messageboard/views/default/messageboard/js.php b/mod/messageboard/views/default/messageboard/js.php new file mode 100644 index 000000000..79472069d --- /dev/null +++ b/mod/messageboard/views/default/messageboard/js.php @@ -0,0 +1,56 @@ +//<script> +elgg.provide('elgg.messageboard'); + +elgg.messageboard.init = function() { + var form = $('form[name=elgg-messageboard]'); + form.find('input[type=submit]').live('click', elgg.messageboard.submit); + + // remove the default binding for confirmation since we're doing extra stuff. + // @todo remove if we add a hook to the requires confirmation callback + form.parent().find('a.elgg-requires-confirmation') + .click(elgg.messageboard.deletePost) + + // double whammy for in case the load order changes. + .unbind('click', elgg.ui.requiresConfirmation) + .removeClass('elgg-requires-confirmation'); +}; + +elgg.messageboard.submit = function(e) { + var form = $(this).parents('form'); + var data = form.serialize(); + + elgg.action('messageboard/add', { + data: data, + success: function(json) { + // the action always returns the full ul and li wrapped annotation. + var ul = form.next('ul.elgg-list-annotation'); + + if (ul.length < 1) { + form.parent().append(json.output); + } else { + ul.prepend($(json.output).find('li:first')); + }; + form.find('textarea').val(''); + } + }); + + e.preventDefault(); +}; + +elgg.messageboard.deletePost = function(e) { + var link = $(this); + var confirmText = link.attr('title') || elgg.echo('question:areyousure'); + + if (confirm(confirmText)) { + elgg.action($(this).attr('href'), { + success: function() { + var item = $(link).closest('.elgg-item'); + item.remove(); + } + }); + } + + e.preventDefault(); +}; + +elgg.register_hook_handler('init', 'system', elgg.messageboard.init); diff --git a/mod/messageboard/views/default/river/object/messageboard/create.php b/mod/messageboard/views/default/river/object/messageboard/create.php new file mode 100644 index 000000000..ac10a55c1 --- /dev/null +++ b/mod/messageboard/views/default/river/object/messageboard/create.php @@ -0,0 +1,12 @@ +<?php
+/**
+ * Messageboard river view
+ */
+
+$messageboard = $vars['item']->getAnnotation();
+$excerpt = elgg_get_excerpt($messageboard->value);
+
+echo elgg_view('river/elements/layout', array(
+ 'item' => $vars['item'],
+ 'message' => $excerpt,
+));
diff --git a/mod/messageboard/views/default/widgets/messageboard/content.php b/mod/messageboard/views/default/widgets/messageboard/content.php new file mode 100644 index 000000000..35954e7a3 --- /dev/null +++ b/mod/messageboard/views/default/widgets/messageboard/content.php @@ -0,0 +1,35 @@ +<?php +/** + * Elgg messageboard widget view + * + */ + +$owner = elgg_get_page_owner_entity(); + +$num_display = $vars['entity']->num_display; + +if (elgg_is_logged_in()) { + echo elgg_view_form('messageboard/add', array('name' => 'elgg-messageboard')); +} + +$options = array( + 'annotations_name' => 'messageboard', + 'guid' => $owner->getGUID(), + 'limit' => $num_display, + 'pagination' => false, + 'reverse_order_by' => true, +); + +echo elgg_list_annotations($options); + +if ($owner instanceof ElggGroup) { + $url = "messageboard/group/$owner->guid/all"; +} else { + $url = "messageboard/owner/$owner->username"; +} + +echo elgg_view('output/url', array( + 'href' => $url, + 'text' => elgg_echo('messageboard:viewall'), + 'is_trusted' => true, +));
\ 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 new file mode 100644 index 000000000..74848f832 --- /dev/null +++ b/mod/messageboard/views/default/widgets/messageboard/edit.php @@ -0,0 +1,22 @@ +<?php +/** + * Messageboard widget edit view + */ + +// set default value +if (!isset($vars['entity']->num_display)) { + $vars['entity']->num_display = 5; +} + +$params = array( + 'name' => 'params[num_display]', + 'value' => $vars['entity']->num_display, + 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), +); +$dropdown = elgg_view('input/dropdown', $params); + +?> +<div> + <?php echo elgg_echo('messageboard:num_display'); ?>: + <?php echo $dropdown; ?> +</div> |