avatar.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Retrieve user avatar by nickname action class.
  18. *
  19. * @category Action
  20. * @package GNUsocial
  21. *
  22. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  23. */
  24. if (!defined('GNUSOCIAL')) {
  25. exit(1);
  26. }
  27. /**
  28. * Retrieve user avatar by nickname action class.
  29. *
  30. * @category Action
  31. * @package GNUsocial
  32. *
  33. * @author Evan Prodromou <evan@status.net>
  34. * @author Robin Millette <millette@status.net>
  35. * @author Mikael Nordfeldth <mmn@hethane.se>
  36. * @author Hugo Sales <hugo@fc.up.pt>
  37. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  38. *
  39. * @see http://www.gnu.org/software/social/
  40. */
  41. class AvatarAction extends Action
  42. {
  43. public $filename;
  44. protected function prepare(array $args = [])
  45. {
  46. parent::prepare($args);
  47. if (empty($this->filename = $this->trimmed('file'))) {
  48. // TRANS: Client error displayed trying to get a non-existing avatar.
  49. $this->clientError(_m('No such avatar.'), 404);
  50. }
  51. return true;
  52. }
  53. protected function handle()
  54. {
  55. parent::handle();
  56. if (is_string($srv = common_config('avatar', 'server')) && $srv != '') {
  57. common_redirect(Avatar::url($this->filename), 302);
  58. } else {
  59. $attachment = new AttachmentAction(); // kludge...
  60. $attachment->filepath = common_config('avatar', 'dir') . $this->filename;
  61. $attachment->sendFile();
  62. }
  63. return true;
  64. }
  65. }