removefriend.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // Get the GUID of the user to friend
  3. $friend_guid = (int) get_input('friend');
  4. // Get the user
  5. $friend = get_user($friend_guid);
  6. if (empty($friend)) {
  7. register_error(elgg_echo('error:missing_data'));
  8. forward(REFERER);
  9. }
  10. $user = elgg_get_logged_in_user_entity();
  11. // remove friend from user
  12. try {
  13. $user->removeFriend($friend->getGUID());
  14. // remove river items
  15. elgg_delete_river([
  16. 'view' => 'river/relationship/friend/create',
  17. 'subject_guid' => $user->getGUID(),
  18. 'object_guid' => $friend->getGUID(),
  19. ]);
  20. } catch (Exception $e) {
  21. register_error(elgg_echo('friends:remove:failure', [$friend->name]));
  22. forward(REFERER);
  23. }
  24. // remove user from friend
  25. try {
  26. // V1.1 - Old relationships might not have the 2 as friends...
  27. $friend->removeFriend($user->getGUID());
  28. // remove river items
  29. elgg_delete_river([
  30. 'view' => 'river/relationship/friend/create',
  31. 'subject_guid' => $friend->getGUID(),
  32. 'object_guid' => $user->getGUID(),
  33. ]);
  34. } catch (Exception $e) {
  35. // do nothing
  36. }
  37. system_message(elgg_echo('friends:remove:successful', [$friend->name]));
  38. forward(REFERER);