]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/WebFinger/actions/webfinger.php
[TRANSLATION] Update license and copyright notice in translation files
[quix0rs-gnu-social.git] / plugins / WebFinger / actions / webfinger.php
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
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * @package WebFingerPlugin
24  * @author James Walker <james@status.net>
25  * @author Mikael Nordfeldth <mmn@hethane.se>
26  */
27 class WebfingerAction extends XrdAction
28 {
29     protected $resource = null; // string with the resource URI
30     protected $target   = null; // object of the WebFingerResource class
31
32     protected function prepare(array $args=array())
33     {
34         parent::prepare($args);
35
36         // throws exception if resource is empty
37         $this->resource = Discovery::normalize($this->trimmed('resource'));
38
39         try {
40             if (Event::handle('StartGetWebFingerResource', array($this->resource, &$this->target, $this->args))) {
41                 Event::handle('EndGetWebFingerResource', array($this->resource, &$this->target, $this->args));
42             }
43         } catch (NoSuchUserException $e) {
44             throw new ServerException($e->getMessage(), 404);
45         }
46
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);
50         }
51
52         return true;
53     }
54
55     protected function setXRD()
56     {
57         $this->xrd->subject = $this->resource;
58
59         foreach ($this->target->getAliases() as $alias) {
60             if ($alias != $this->xrd->subject && !in_array($alias, $this->xrd->aliases)) {
61                 $this->xrd->aliases[] = $alias;
62             }
63         }
64
65         $this->target->updateXRD($this->xrd);
66     }
67 }