From 6f4ca315db3a8c162fe032e79a9b27f16732bf2d Mon Sep 17 00:00:00 2001 From: Brett Profitt Date: Wed, 24 Aug 2011 20:38:12 -0700 Subject: Fixes #3612, #3750. Added edit replies back to group plugin with the annotation menu. --- mod/groups/actions/discussion/reply/save.php | 35 +++++++++++----- mod/groups/start.php | 48 ++++++++++++++++++++++ .../views/default/annotation/group_topic_post.php | 17 ++++++-- .../views/default/forms/discussion/reply/save.php | 32 +++++++++++++-- .../views/default/annotation/messageboard.php | 11 ----- 5 files changed, 115 insertions(+), 28 deletions(-) delete mode 100644 mod/messageboard/views/default/annotation/messageboard.php diff --git a/mod/groups/actions/discussion/reply/save.php b/mod/groups/actions/discussion/reply/save.php index 109938dbb..a1ed036b6 100644 --- a/mod/groups/actions/discussion/reply/save.php +++ b/mod/groups/actions/discussion/reply/save.php @@ -9,6 +9,7 @@ gatekeeper(); // Get input $entity_guid = (int) get_input('entity_guid'); $text = get_input('group_topic_post'); +$annotation_id = (int) get_input('annotation_id'); // reply cannot be empty if (empty($text)) { @@ -30,16 +31,30 @@ if (!$group->canWriteToContainer($user)) { forward(REFERER); } - -// add the reply to the forum topic -$reply_id = $topic->annotate('group_topic_post', $text, $topic->access_id, $user->guid); -if ($reply_id == false) { - system_message(elgg_echo('groupspost:failure')); - forward(REFERER); +// if editing a reply, make sure it's valid +if ($annotation_id) { + $annotation = elgg_get_annotation_from_id($annotation_id); + if (!$annotation->canEdit()) { + register_error(elgg_echo('groups:notowner')); + forward(REFERER); + } + + $annotation->value = $text; + if (!$annotation->save()) { + system_message(elgg_echo('groups:forumpost:error')); + forward(REFERER); + } + system_message(elgg_echo('groups:forumpost:edited')); +} else { + // add the reply to the forum topic + $reply_id = $topic->annotate('group_topic_post', $text, $topic->access_id, $user->guid); + if ($reply_id == false) { + system_message(elgg_echo('groupspost:failure')); + forward(REFERER); + } + + add_to_river('river/annotation/group_topic_post/reply', 'reply', $user->guid, $topic->guid, "", 0, $reply_id); + system_message(elgg_echo('groupspost:success')); } -add_to_river('river/annotation/group_topic_post/reply', 'reply', $user->guid, $topic->guid, "", 0, $reply_id); - -system_message(elgg_echo('groupspost:success')); - forward(REFERER); diff --git a/mod/groups/start.php b/mod/groups/start.php index 83353bae5..9e4694457 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -65,6 +65,9 @@ function groups_init() { // group user hover menu elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'groups_user_entity_menu_setup'); + // delete and edit annotations for topic replies + elgg_register_plugin_hook_handler('register', 'menu:annotation', 'groups_annotation_menu_setup'); + //extend some views elgg_extend_view('css/elgg', 'groups/css'); elgg_extend_view('js/elgg', 'groups/js'); @@ -408,6 +411,51 @@ function groups_user_entity_menu_setup($hook, $type, $return, $params) { return $return; } +/** + * Add edit and delete links for forum replies + */ +function groups_annotation_menu_setup($hook, $type, $return, $params) { + if (elgg_in_context('widgets')) { + return $return; + } + + $annotation = $params['annotation']; + + if ($annotation->name != 'group_topic_post') { + return $return; + } + + if ($annotation->canEdit()) { + $url = elgg_http_add_url_query_elements('action/discussion/reply/delete', array( + 'annotation_id' => $annotation->id, + )); + + $options = array( + 'name' => 'delete', + 'href' => $url, + 'text' => "", + 'confirm' => elgg_echo('deleteconfirm'), + 'text_encode' => false + ); + $return[] = ElggMenuItem::factory($options); + + $url = elgg_http_add_url_query_elements('discussion', array( + 'annotation_id' => $annotation->id, + )); + + $options = array( + 'name' => 'edit', + 'href' => "#edit-annotation-$annotation->id", + 'text' => elgg_echo('edit'), + 'text_encode' => false, + 'rel' => 'toggle', + ); + $return[] = ElggMenuItem::factory($options); + } + + return $return; +} + /** * Groups created so create an access list for it */ diff --git a/mod/groups/views/default/annotation/group_topic_post.php b/mod/groups/views/default/annotation/group_topic_post.php index d2303aba8..f38d2a77a 100644 --- a/mod/groups/views/default/annotation/group_topic_post.php +++ b/mod/groups/views/default/annotation/group_topic_post.php @@ -1,8 +1,19 @@ canEdit()) { + $form = elgg_view_form('discussion/reply/save', array(), array_merge(array( + 'entity' => get_entity($annotation->entity_guid), + 'annotation' => $annotation + ), $vars) + ); + + echo "
id\">$form
"; +} + diff --git a/mod/groups/views/default/forms/discussion/reply/save.php b/mod/groups/views/default/forms/discussion/reply/save.php index 40ea07303..083fefb78 100644 --- a/mod/groups/views/default/forms/discussion/reply/save.php +++ b/mod/groups/views/default/forms/discussion/reply/save.php @@ -6,7 +6,6 @@ * @uses $vars['inline'] Display a shortened form? */ - if (isset($vars['entity']) && elgg_is_logged_in()) { echo elgg_view('input/hidden', array( 'name' => 'entity_guid', @@ -14,18 +13,43 @@ if (isset($vars['entity']) && elgg_is_logged_in()) { )); $inline = elgg_extract('inline', $vars, false); + + $annotation = elgg_extract('annotation', $vars); + + $value = ''; + + if ($annotation) { + $value = $annotation->value; + echo elgg_view('input/hidden', array( + 'name' => 'annotation_id', + 'value' => $annotation->id + )); + } + if ($inline) { - echo elgg_view('input/text', array('name' => 'group_topic_post')); + echo elgg_view('input/text', array('name' => 'group_topic_post', 'value' => $value)); echo elgg_view('input/submit', array('value' => elgg_echo('reply'))); } else { ?>
- - 'group_topic_post')); ?> + + 'group_topic_post', 'value' => $value)); ?>
elgg_echo('save'))); + } else { echo elgg_view('input/submit', array('value' => elgg_echo('reply'))); + } ?>