approve.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. $friend_guid = (int) get_input('guid');
  3. $friend = get_user($friend_guid);
  4. if (empty($friend)) {
  5. register_error(elgg_echo('error:missing_data'));
  6. forward(REFERER);
  7. }
  8. $user = elgg_get_logged_in_user_entity();
  9. if (!remove_entity_relationship($friend->getGUID(), 'friendrequest', $user->getGUID())) {
  10. register_error(elgg_echo('friend_request:approve:fail', [$friend->name]));
  11. forward(REFERER);
  12. }
  13. $user->addFriend($friend->getGUID());
  14. $friend->addFriend($user->getGUID()); //Friends mean reciprical...
  15. // notify the user about the acceptance
  16. $subject = elgg_echo('friend_request:approve:subject', [$user->name]);
  17. $message = elgg_echo('friend_request:approve:message', [$friend->name, $user->name]);
  18. $params = [
  19. 'action' => 'add_friend',
  20. 'object' => $user,
  21. ];
  22. notify_user($friend->getGUID(), $user->getGUID(), $subject, $message, $params);
  23. // add to river
  24. friend_request_create_river_events($user->getGUID(), $friend->getGUID());
  25. system_message(elgg_echo('friend_request:approve:successful', [$friend->name]));
  26. forward(REFERER);