avatarbynickname.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Retrieve user avatar by nickname action class.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @author Robin Millette <millette@status.net>
  11. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  12. * @link http://status.net/
  13. *
  14. * StatusNet - the distributed open-source microblogging tool
  15. * Copyright (C) 2008, 2009, StatusNet, Inc.
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Retrieve user avatar by nickname action class.
  33. *
  34. * @category Action
  35. * @package GNUsocial
  36. * @author Evan Prodromou <evan@status.net>
  37. * @author Robin Millette <millette@status.net>
  38. * @author Mikael Nordfeldth <mmn@hethane.se>
  39. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  40. * @link http://www.gnu.org/software/social/
  41. */
  42. class AvatarbynicknameAction extends Action
  43. {
  44. /**
  45. * Class handler.
  46. *
  47. * @param array $args query arguments
  48. *
  49. * @return boolean false if nickname or user isn't found
  50. */
  51. protected function handle()
  52. {
  53. parent::handle();
  54. $nickname = $this->trimmed('nickname');
  55. if (!$nickname) {
  56. // TRANS: Client error displayed trying to get an avatar without providing a nickname.
  57. $this->clientError(_('No nickname.'));
  58. }
  59. $size = $this->trimmed('size') ?: 'original';
  60. $user = User::getKV('nickname', $nickname);
  61. if (!$user) {
  62. // TRANS: Client error displayed trying to get an avatar for a non-existing user.
  63. $this->clientError(_('No such user.'));
  64. }
  65. $profile = $user->getProfile();
  66. if (!$profile) {
  67. // TRANS: Error message displayed when referring to a user without a profile.
  68. $this->clientError(_('User has no profile.'));
  69. }
  70. if ($size === 'original') {
  71. try {
  72. $avatar = Avatar::getUploaded($profile);
  73. $url = $avatar->displayUrl();
  74. } catch (NoAvatarException $e) {
  75. $url = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
  76. }
  77. } else {
  78. $url = $profile->avatarUrl($size);
  79. }
  80. common_redirect($url, 302);
  81. }
  82. function isReadOnly($args)
  83. {
  84. return true;
  85. }
  86. }