save.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Save a discussion reply
  4. */
  5. // Get input
  6. $topic_guid = (int) get_input('topic_guid');
  7. $text = get_input('description');
  8. $reply_guid = (int) get_input('guid');
  9. // reply cannot be empty
  10. if (empty($text)) {
  11. register_error(elgg_echo('grouppost:nopost'));
  12. forward(REFERER);
  13. }
  14. if ($topic_guid) {
  15. $topic = get_entity($topic_guid);
  16. if (!elgg_instanceof($topic, 'object', 'groupforumtopic')) {
  17. register_error(elgg_echo('grouppost:nopost'));
  18. forward(REFERER);
  19. }
  20. $group = $topic->getContainerEntity();
  21. if (!$group->canWriteToContainer()) {
  22. register_error(elgg_echo('groups:notmember'));
  23. forward(REFERER);
  24. }
  25. }
  26. $user = elgg_get_logged_in_user_entity();
  27. if ($reply_guid) {
  28. $reply = get_entity($reply_guid);
  29. if (!elgg_instanceof($reply, 'object', 'discussion_reply', 'ElggDiscussionReply')) {
  30. register_error(elgg_echo('discussion:reply:error:notfound'));
  31. forward(REFERER);
  32. }
  33. if (!$reply->canEdit()) {
  34. register_error(elgg_echo('groups:notowner'));
  35. forward(REFERER);
  36. }
  37. $reply->description = $text;
  38. if ($reply->save()) {
  39. system_message(elgg_echo('groups:forumpost:edited'));
  40. } else {
  41. register_error(elgg_echo('groups:forumpost:error'));
  42. }
  43. } else {
  44. // add the reply to the forum topic
  45. $reply = new ElggDiscussionReply();
  46. $reply->description = $text;
  47. $reply->access_id = $topic->access_id;
  48. $reply->container_guid = $topic->getGUID();
  49. $reply->owner_guid = $user->getGUID();
  50. $reply_guid = $reply->save();
  51. if ($reply_guid == false) {
  52. register_error(elgg_echo('groupspost:failure'));
  53. forward(REFERER);
  54. }
  55. elgg_create_river_item(array(
  56. 'view' => 'river/object/discussion_reply/create',
  57. 'action_type' => 'reply',
  58. 'subject_guid' => $user->guid,
  59. 'object_guid' => $reply->guid,
  60. 'target_guid' => $topic->guid,
  61. ));
  62. system_message(elgg_echo('groupspost:success'));
  63. }
  64. forward(REFERER);