webfinger.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) { exit(1); }
  20. /**
  21. * @package WebFingerPlugin
  22. * @author James Walker <james@status.net>
  23. * @author Mikael Nordfeldth <mmn@hethane.se>
  24. */
  25. class WebfingerAction extends XrdAction
  26. {
  27. protected $resource = null; // string with the resource URI
  28. protected $target = null; // object of the WebFingerResource class
  29. protected function prepare(array $args=array())
  30. {
  31. parent::prepare($args);
  32. // throws exception if resource is empty
  33. $this->resource = Discovery::normalize($this->trimmed('resource'));
  34. try {
  35. if (Event::handle('StartGetWebFingerResource', array($this->resource, &$this->target, $this->args))) {
  36. Event::handle('EndGetWebFingerResource', array($this->resource, &$this->target, $this->args));
  37. }
  38. } catch (NoSuchUserException $e) {
  39. throw new ServerException($e->getMessage(), 404);
  40. }
  41. if (!$this->target instanceof WebFingerResource) {
  42. // TRANS: Error message when an object URI which we cannot find was requested
  43. throw new ServerException(_m('Resource not found in local database.'), 404);
  44. }
  45. return true;
  46. }
  47. protected function setXRD()
  48. {
  49. $this->xrd->subject = $this->resource;
  50. foreach ($this->target->getAliases() as $alias) {
  51. if ($alias != $this->xrd->subject && !in_array($alias, $this->xrd->aliases)) {
  52. $this->xrd->aliases[] = $alias;
  53. }
  54. }
  55. $this->target->updateXRD($this->xrd);
  56. }
  57. }