comment.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. $entity_guid = (int) get_input('entity_guid');
  3. $comment_text = get_input('generic_comment');
  4. if (empty($comment_text)) {
  5. register_error(elgg_echo("generic_comment:blank"));
  6. forward(REFERER);
  7. }
  8. // Let's see if we can get an entity with the specified GUID
  9. $entity = get_entity($entity_guid);
  10. if (!$entity) {
  11. register_error(elgg_echo("generic_comment:notfound"));
  12. forward(REFERER);
  13. }
  14. $user = elgg_get_logged_in_user_entity();
  15. $annotation = create_annotation($entity->guid,
  16. 'generic_comment',
  17. $comment_text,
  18. "",
  19. $user->guid,
  20. $entity->access_id);
  21. // tell user annotation posted
  22. if (!$annotation) {
  23. register_error(elgg_echo("generic_comment:failure"));
  24. forward(REFERER);
  25. }
  26. // Get who we need to notify
  27. $to_notify = array($entity->owner_guid);
  28. $annotations = elgg_get_annotations(array(
  29. 'annotation_name' => 'generic_comment',
  30. 'guid' => $entity->guid,
  31. 'limit' => 0,
  32. 'type' => 'object',
  33. ));
  34. foreach ($annotations as $a)
  35. $to_notify[] = $a->owner_guid;
  36. $to_notify = array_unique($to_notify);
  37. foreach ($to_notify as $to_guid) {
  38. // notify if poster wasn't owner
  39. if ($to_guid != $user->guid) {
  40. notify_user($to_guid,
  41. $user->guid,
  42. elgg_echo('generic_comment:email:subject'),
  43. elgg_echo('generic_comment:email:body', array(
  44. $entity->title,
  45. $user->name,
  46. $comment_text,
  47. $entity->getURL(),
  48. $user->name,
  49. $user->getURL()
  50. ))
  51. );
  52. }
  53. }
  54. system_message(elgg_echo("generic_comment:posted"));
  55. //add to river
  56. add_to_river('river/annotation/generic_comment/create', 'comment', $user->guid, $entity->guid, "", 0, $annotation);
  57. // Forward to the page the action occurred on
  58. forward(REFERER);