3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * @package WebFingerPlugin
24 * @author James Walker <james@status.net>
25 * @author Mikael Nordfeldth <mmn@hethane.se>
27 class WebfingerAction extends XrdAction
29 protected $resource = null; // string with the resource URI
30 protected $target = null; // object of the WebFingerResource class
32 protected function prepare(array $args=array())
34 parent::prepare($args);
36 // throws exception if resource is empty
37 $this->resource = Discovery::normalize($this->trimmed('resource'));
40 if (Event::handle('StartGetWebFingerResource', array($this->resource, &$this->target, $this->args))) {
41 Event::handle('EndGetWebFingerResource', array($this->resource, &$this->target, $this->args));
43 } catch (NoSuchUserException $e) {
44 throw new ServerException($e->getMessage(), 404);
47 if (!$this->target instanceof WebFingerResource) {
48 // TRANS: Error message when an object URI which we cannot find was requested
49 throw new ServerException(_m('Resource not found in local database.'), 404);
55 protected function setXRD()
57 $this->xrd->subject = $this->resource;
59 foreach ($this->target->getAliases() as $alias) {
60 if ($alias != $this->xrd->subject && !in_array($alias, $this->xrd->aliases)) {
61 $this->xrd->aliases[] = $alias;
65 $this->target->updateXRD($this->xrd);