save.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Topic save action
  4. */
  5. // Get variables
  6. $title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
  7. $desc = get_input("description");
  8. $status = get_input("status");
  9. $access_id = (int) get_input("access_id");
  10. $container_guid = (int) get_input('container_guid');
  11. $guid = (int) get_input('topic_guid');
  12. $tags = get_input("tags");
  13. elgg_make_sticky_form('topic');
  14. // validation of inputs
  15. if (!$title || !$desc) {
  16. register_error(elgg_echo('discussion:error:missing'));
  17. forward(REFERER);
  18. }
  19. $container = get_entity($container_guid);
  20. if (!$container || !$container->canWriteToContainer(0, 'object', 'groupforumtopic')) {
  21. register_error(elgg_echo('discussion:error:permissions'));
  22. forward(REFERER);
  23. }
  24. // check whether this is a new topic or an edit
  25. $new_topic = true;
  26. if ($guid > 0) {
  27. $new_topic = false;
  28. }
  29. if ($new_topic) {
  30. $topic = new ElggObject();
  31. $topic->subtype = 'groupforumtopic';
  32. } else {
  33. // load original file object
  34. $topic = get_entity($guid);
  35. if (!elgg_instanceof($topic, 'object', 'groupforumtopic') || !$topic->canEdit()) {
  36. register_error(elgg_echo('discussion:topic:notfound'));
  37. forward(REFERER);
  38. }
  39. }
  40. $topic->title = $title;
  41. $topic->description = $desc;
  42. $topic->status = $status;
  43. $topic->access_id = $access_id;
  44. $topic->container_guid = $container_guid;
  45. $topic->tags = string_to_tag_array($tags);
  46. $result = $topic->save();
  47. if (!$result) {
  48. register_error(elgg_echo('discussion:error:notsaved'));
  49. forward(REFERER);
  50. }
  51. // topic saved so clear sticky form
  52. elgg_clear_sticky_form('topic');
  53. // handle results differently for new topics and topic edits
  54. if ($new_topic) {
  55. system_message(elgg_echo('discussion:topic:created'));
  56. elgg_create_river_item(array(
  57. 'view' => 'river/object/groupforumtopic/create',
  58. 'action_type' => 'create',
  59. 'subject_guid' => elgg_get_logged_in_user_guid(),
  60. 'object_guid' => $topic->guid,
  61. ));
  62. } else {
  63. system_message(elgg_echo('discussion:topic:updated'));
  64. }
  65. forward($topic->getURL());