remove.php 820 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Avatar remove action
  4. */
  5. $user_guid = get_input('guid');
  6. $user = get_user($user_guid);
  7. if (!$user || !$user->canEdit()) {
  8. register_error(elgg_echo('avatar:remove:fail'));
  9. forward(REFERER);
  10. }
  11. // Delete all icons from diskspace
  12. $icon_sizes = elgg_get_config('icon_sizes');
  13. foreach ($icon_sizes as $name => $size_info) {
  14. $file = new ElggFile();
  15. $file->owner_guid = $user_guid;
  16. $file->setFilename("profile/{$user_guid}{$name}.jpg");
  17. $filepath = $file->getFilenameOnFilestore();
  18. if (!$file->delete()) {
  19. elgg_log("Avatar file remove failed. Remove $filepath manually, please.", 'WARNING');
  20. }
  21. }
  22. // Remove crop coords
  23. unset($user->x1);
  24. unset($user->x2);
  25. unset($user->y1);
  26. unset($user->y2);
  27. // Remove icon
  28. unset($user->icontime);
  29. system_message(elgg_echo('avatar:remove:success'));
  30. forward(REFERER);