2013-09-30 16:13:03 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package WebFingerPlugin
|
|
|
|
* @author James Walker <james@status.net>
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
*/
|
|
|
|
class WebfingerAction extends XrdAction
|
|
|
|
{
|
2013-10-20 14:32:56 +01:00
|
|
|
protected $resource = null; // string with the resource URI
|
|
|
|
protected $target = null; // object of the WebFingerResource class
|
|
|
|
|
2013-09-30 16:13:03 +01:00
|
|
|
protected function prepare(array $args=array())
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
// throws exception if resource is empty
|
|
|
|
$this->resource = Discovery::normalize($this->trimmed('resource'));
|
|
|
|
|
2014-06-04 11:59:42 +01:00
|
|
|
try {
|
|
|
|
if (Event::handle('StartGetWebFingerResource', array($this->resource, &$this->target, $this->args))) {
|
|
|
|
Event::handle('EndGetWebFingerResource', array($this->resource, &$this->target, $this->args));
|
|
|
|
}
|
|
|
|
} catch (NoSuchUserException $e) {
|
|
|
|
throw new ServerException($e->getMessage(), 404);
|
2013-09-30 16:13:03 +01:00
|
|
|
}
|
|
|
|
|
2014-06-04 11:46:06 +01:00
|
|
|
if (!$this->target instanceof WebFingerResource) {
|
2014-06-04 11:59:42 +01:00
|
|
|
// TRANS: Error message when an object URI which we cannot find was requested
|
|
|
|
throw new ServerException(_m('Resource not found in local database.'), 404);
|
2014-06-04 11:46:06 +01:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:13:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setXRD()
|
|
|
|
{
|
|
|
|
$this->xrd->subject = $this->resource;
|
|
|
|
|
2013-10-20 14:32:56 +01:00
|
|
|
foreach ($this->target->getAliases() as $alias) {
|
|
|
|
if ($alias != $this->xrd->subject && !in_array($alias, $this->xrd->aliases)) {
|
|
|
|
$this->xrd->aliases[] = $alias;
|
2013-09-30 16:13:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 14:32:56 +01:00
|
|
|
$this->target->updateXRD($this->xrd);
|
2013-09-30 16:13:03 +01:00
|
|
|
}
|
|
|
|
}
|