]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3612, #3750. Added edit replies back to group plugin with the annotation menu.
authorBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 03:38:12 +0000 (20:38 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 03:38:12 +0000 (20:38 -0700)
mod/groups/actions/discussion/reply/save.php
mod/groups/start.php
mod/groups/views/default/annotation/group_topic_post.php
mod/groups/views/default/forms/discussion/reply/save.php
mod/messageboard/views/default/annotation/messageboard.php [deleted file]

index 109938dbb91817e6b0e81735bf142fc9831827c8..a1ed036b66a1f664f846784d903f17b6d6e0d852 100644 (file)
@@ -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);
index 83353bae579fac7b5011624e389c89859df83d97..9e4694457484c98d50c7beb60c03754d03a4cd3f 100644 (file)
@@ -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' => "<span class=\"elgg-icon elgg-icon-delete\"></span>",
+                       '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
  */
index d2303aba854010e4cd88a566651a0952149f09ba..f38d2a77a47e9c2966ee129b65e785e7b90056cd 100644 (file)
@@ -1,8 +1,19 @@
 <?php
-/**
- * Discussion reply
+/*
+ * Embeds an edit link for the annotation
  */
 
-$vars['delete_action'] = 'action/discussion/reply/delete';
+$annotation = elgg_extract('annotation', $vars);
 
 echo elgg_view('annotation/default', $vars);
+
+if ($annotation->canEdit()) {
+       $form = elgg_view_form('discussion/reply/save', array(), array_merge(array(
+                       'entity' => get_entity($annotation->entity_guid),
+                       'annotation' => $annotation
+               ), $vars)
+       );
+
+       echo "<div class=\"hidden mbm\" id=\"edit-annotation-$annotation->id\">$form</div>";
+}
+
index 40ea0730301bc18241f44fedef3bf1ff41b68193..083fefb78c20f7d1e87c0f778e9d44b0ab2294ca 100644 (file)
@@ -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 {
 ?>
        <div>
-               <label><?php echo elgg_echo("reply"); ?></label>
-               <?php echo elgg_view('input/longtext', array('name' => 'group_topic_post')); ?>
+               <label>
+               <?php
+                       if ($annotation) {
+                               echo elgg_echo('edit');
+                       } else {
+                               echo elgg_echo("reply");
+                       }
+               ?>
+               </label>
+               <?php echo elgg_view('input/longtext', array('name' => 'group_topic_post', 'value' => $value)); ?>
        </div>
        <div class="elgg-foot">
 <?php
+       if ($annotation) {
+               echo elgg_view('input/submit', array('value' => elgg_echo('save')));
+       } else {
                echo elgg_view('input/submit', array('value' => elgg_echo('reply')));
+       }
 ?>
        </div>
 <?php
diff --git a/mod/messageboard/views/default/annotation/messageboard.php b/mod/messageboard/views/default/annotation/messageboard.php
deleted file mode 100644 (file)
index 8dfba3a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-/**
- * Message board post
- *
- * @uses $vars['annotation']  ElggAnnotation object
- * @uses $vars['full_view']        Display fill view or brief view
- */
-
-$vars['delete_action'] = 'action/messageboard/delete';
-
-echo elgg_view('annotation/default', $vars);
\ No newline at end of file