Merge pull request #11899 from annando/native-xml
Template based XML generation is replaced with native XML
This commit is contained in:
commit
636325efcc
9 changed files with 222 additions and 174 deletions
|
@ -20,20 +20,77 @@
|
|||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Module\Security\Login;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
function oexchange_init(App $a) {
|
||||
|
||||
if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'xrd')) {
|
||||
$tpl = Renderer::getMarkupTemplate('oexchange_xrd.tpl');
|
||||
|
||||
$o = Renderer::replaceMacros($tpl, ['$base' => DI::baseUrl()]);
|
||||
System::httpExit($o, Response::TYPE_XML, 'application/xrd+xml');
|
||||
function oexchange_init(App $a)
|
||||
{
|
||||
if ((DI::args()->getArgc() <= 1) || (DI::args()->getArgv()[1] != 'xrd')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$baseURL = DI::baseUrl()->get();
|
||||
|
||||
$xml = null;
|
||||
|
||||
XML::fromArray([
|
||||
'XRD' => [
|
||||
'@attributes' => [
|
||||
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
||||
],
|
||||
'Subject' => $baseURL,
|
||||
'1:Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://www.oexchange.org/spec/0.8/prop/vendor',
|
||||
],
|
||||
'Friendica'
|
||||
],
|
||||
'2:Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://www.oexchange.org/spec/0.8/prop/title',
|
||||
],
|
||||
'Friendica Social Network'
|
||||
],
|
||||
'3:Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://www.oexchange.org/spec/0.8/prop/name',
|
||||
],
|
||||
'Friendica'
|
||||
],
|
||||
'4:Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://www.oexchange.org/spec/0.8/prop/prompt',
|
||||
],
|
||||
'Send to Friendica'
|
||||
],
|
||||
'1:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'icon',
|
||||
'type' => 'image/png',
|
||||
'href' => $baseURL . '/images/friendica-16.png'
|
||||
]
|
||||
],
|
||||
'2:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'icon32',
|
||||
'type' => 'image/png',
|
||||
'href' => $baseURL . '/images/friendica-32.png'
|
||||
]
|
||||
],
|
||||
'3:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://www.oexchange.org/spec/0.8/rel/offer',
|
||||
'type' => 'text/html',
|
||||
'href' => $baseURL . '/oexchange'
|
||||
]
|
||||
],
|
||||
],
|
||||
], $xml);
|
||||
|
||||
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
||||
}
|
||||
|
||||
function oexchange_content(App $a) {
|
||||
|
|
|
@ -24,13 +24,10 @@ use Friendica\App;
|
|||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
function poco_init(App $a) {
|
||||
if (intval(DI::config()->get('system', 'block_public')) || (DI::config()->get('system', 'block_local_dir'))) {
|
||||
|
@ -229,12 +226,9 @@ function poco_init(App $a) {
|
|||
|
||||
Logger::info("End of poco");
|
||||
|
||||
if ($format === 'xml') {
|
||||
System::httpExit(Renderer::replaceMacros(Renderer::getMarkupTemplate('poco_xml.tpl'), XML::arrayEscape(['$response' => $ret])), Response::TYPE_XML);
|
||||
}
|
||||
if ($format === 'json') {
|
||||
System::jsonExit($ret);
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
throw new \Friendica\Network\HTTPException\UnsupportedMediaTypeException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
namespace Friendica\Module\WellKnown;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
/**
|
||||
* Prints the metadata for describing this host
|
||||
|
@ -46,14 +46,58 @@ class HostMeta extends BaseModule
|
|||
$config->set('system', 'site_pubkey', $res['pubkey']);
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
|
||||
$content = Renderer::replaceMacros($tpl, [
|
||||
'$zhost' => DI::baseUrl()->getHostname(),
|
||||
'$zroot' => DI::baseUrl()->get(),
|
||||
'$domain' => DI::baseUrl()->get(),
|
||||
'$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey'))
|
||||
]);
|
||||
$domain = DI::baseUrl()->get();
|
||||
|
||||
System::httpExit($content, Response::TYPE_XML, 'application/xrd+xml');
|
||||
$xml = null;
|
||||
XML::fromArray([
|
||||
'XRD' => [
|
||||
'@attributes' => [
|
||||
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
||||
],
|
||||
'hm:Host' => DI::baseUrl()->getHostname(),
|
||||
'1:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'lrdd',
|
||||
'type' => 'application/xrd+xml',
|
||||
'template' => $domain . '/xrd?uri={uri}'
|
||||
]
|
||||
],
|
||||
'2:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'lrdd',
|
||||
'type' => 'application/json',
|
||||
'template' => $domain . '/.well-known/webfinger?resource={uri}'
|
||||
]
|
||||
],
|
||||
'3:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'acct-mgmt',
|
||||
'href' => $domain . '/amcd'
|
||||
]
|
||||
],
|
||||
'4:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://services.mozilla.com/amcd/0.1',
|
||||
'href' => $domain . '/amcd'
|
||||
]
|
||||
],
|
||||
'5:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://oexchange.org/spec/0.8/rel/resident-target',
|
||||
'type' => 'application/xrd+xml',
|
||||
'href' => $domain . '/oexchange/xrd'
|
||||
]
|
||||
],
|
||||
'Property' => [
|
||||
'@attributes' => [
|
||||
'type' => 'http://salmon-protocol.org/ns/magic-key',
|
||||
'mk:key_id' => '1'
|
||||
],
|
||||
Salmon::salmonKey($config->get('system', 'site_pubkey'))
|
||||
]
|
||||
],
|
||||
], $xml, false, ['hm' => 'http://host-meta.net/xrd/1.0', 'mk' => 'http://salmon-protocol.org/ns/magic-key']);
|
||||
|
||||
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Photo;
|
||||
|
@ -31,6 +29,7 @@ use Friendica\Model\User;
|
|||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
/**
|
||||
* Prints responses to /.well-known/webfinger or /xrd requests
|
||||
|
@ -82,15 +81,10 @@ class Xrd extends BaseModule
|
|||
}
|
||||
$this->printSystemJSON($owner);
|
||||
} else {
|
||||
$user = User::getByNickname($name);
|
||||
if (empty($user)) {
|
||||
throw new NotFoundException('User was not found for name=' . $name);
|
||||
}
|
||||
|
||||
$owner = User::getOwnerDataById($user['uid']);
|
||||
$owner = User::getOwnerDataByNick($name);
|
||||
if (empty($owner)) {
|
||||
DI::logger()->warning('No owner data for user id', ['uri' => $uri, 'name' => $name, 'user' => $user]);
|
||||
throw new NotFoundException('Owner was not found for user->uid=' . $user['uid']);
|
||||
DI::logger()->warning('No owner data for user id', ['uri' => $uri, 'name' => $name]);
|
||||
throw new NotFoundException('Owner was not found for user->uid=' . $name);
|
||||
}
|
||||
|
||||
$alias = str_replace('/profile/', '/~', $owner['url']);
|
||||
|
@ -103,7 +97,7 @@ class Xrd extends BaseModule
|
|||
}
|
||||
|
||||
if ($mode == Response::TYPE_XML) {
|
||||
$this->printXML($alias, $user, $owner, $avatar);
|
||||
$this->printXML($alias, $owner, $avatar);
|
||||
} else {
|
||||
$this->printJSON($alias, $owner, $avatar);
|
||||
}
|
||||
|
@ -158,7 +152,6 @@ class Xrd extends BaseModule
|
|||
private function printJSON(string $alias, array $owner, array $avatar)
|
||||
{
|
||||
$baseURL = $this->baseUrl->get();
|
||||
$salmon_key = Salmon::salmonKey($owner['spubkey']);
|
||||
|
||||
$json = [
|
||||
'subject' => 'acct:' . $owner['addr'],
|
||||
|
@ -223,7 +216,7 @@ class Xrd extends BaseModule
|
|||
],
|
||||
[
|
||||
'rel' => 'magic-public-key',
|
||||
'href' => 'data:application/magic-public-key,' . $salmon_key,
|
||||
'href' => 'data:application/magic-public-key,' . Salmon::salmonKey($owner['spubkey']),
|
||||
],
|
||||
[
|
||||
'rel' => 'http://purl.org/openwebauth/v1',
|
||||
|
@ -237,35 +230,109 @@ class Xrd extends BaseModule
|
|||
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
|
||||
}
|
||||
|
||||
private function printXML(string $alias, array $user, array $owner, array $avatar)
|
||||
private function printXML(string $alias, array $owner, array $avatar)
|
||||
{
|
||||
$baseURL = $this->baseUrl->get();
|
||||
$salmon_key = Salmon::salmonKey($owner['spubkey']);
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
|
||||
$xml = null;
|
||||
|
||||
$o = Renderer::replaceMacros($tpl, [
|
||||
'$nick' => $owner['nickname'],
|
||||
'$accturi' => 'acct:' . $owner['addr'],
|
||||
'$alias' => $alias,
|
||||
'$profile_url' => $owner['url'],
|
||||
'$hcard_url' => $baseURL . '/hcard/' . $owner['nickname'],
|
||||
'$atom' => $owner['poll'],
|
||||
'$poco_url' => $owner['poco'],
|
||||
'$photo' => User::getAvatarUrl($owner),
|
||||
'$type' => $avatar['type'],
|
||||
'$salmon' => $baseURL . '/salmon/' . $owner['nickname'],
|
||||
'$salmen' => $baseURL . '/salmon/' . $owner['nickname'] . '/mention',
|
||||
'$subscribe' => $baseURL . '/follow?url={uri}',
|
||||
'$openwebauth' => $baseURL . '/owa',
|
||||
'$modexp' => 'data:application/magic-public-key,' . $salmon_key
|
||||
]);
|
||||
|
||||
$arr = ['user' => $user, 'xml' => $o];
|
||||
Hook::callAll('personal_xrd', $arr);
|
||||
XML::fromArray([
|
||||
'XRD' => [
|
||||
'@attributes' => [
|
||||
'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
|
||||
],
|
||||
'Subject' => 'acct:' . $owner['addr'],
|
||||
'1:Alias' => $owner['url'],
|
||||
'2:Alias' => $alias,
|
||||
'1:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://purl.org/macgirvin/dfrn/1.0',
|
||||
'href' => $owner['url']
|
||||
]
|
||||
],
|
||||
'2:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://schemas.google.com/g/2010#updates-from',
|
||||
'type' => 'application/atom+xml',
|
||||
'href' => $owner['poll']
|
||||
]
|
||||
],
|
||||
'3:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://webfinger.net/rel/profile-page',
|
||||
'type' => 'text/html',
|
||||
'href' => $owner['url']
|
||||
]
|
||||
],
|
||||
'4:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://microformats.org/profile/hcard',
|
||||
'type' => 'text/html',
|
||||
'href' => $baseURL . '/hcard/' . $owner['nickname']
|
||||
]
|
||||
],
|
||||
'5:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://portablecontacts.net/spec/1.0',
|
||||
'href' => $owner['poco']
|
||||
]
|
||||
],
|
||||
'6:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://webfinger.net/rel/avatar',
|
||||
'type' => $avatar['type'],
|
||||
'href' => User::getAvatarUrl($owner)
|
||||
]
|
||||
],
|
||||
'7:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://joindiaspora.com/seed_location',
|
||||
'type' => 'text/html',
|
||||
'href' => $baseURL
|
||||
]
|
||||
],
|
||||
'8:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'salmon',
|
||||
'href' => $baseURL . '/salmon/' . $owner['nickname']
|
||||
]
|
||||
],
|
||||
'9:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://salmon-protocol.org/ns/salmon-replies',
|
||||
'href' => $baseURL . '/salmon/' . $owner['nickname']
|
||||
]
|
||||
],
|
||||
'10:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://salmon-protocol.org/ns/salmon-mention',
|
||||
'href' => $baseURL . '/salmon/' . $owner['nickname'] . '/mention'
|
||||
]
|
||||
],
|
||||
'11:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||
'template' => $baseURL . '/follow?url={uri}'
|
||||
]
|
||||
],
|
||||
'12:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'magic-public-key',
|
||||
'href' => 'data:application/magic-public-key,' . Salmon::salmonKey($owner['spubkey'])
|
||||
]
|
||||
],
|
||||
'13:link' => [
|
||||
'@attributes' => [
|
||||
'rel' => 'http://purl.org/openwebauth/v1',
|
||||
'type' => 'application/x-zot+json',
|
||||
'href' => $baseURL . '/owa'
|
||||
]
|
||||
],
|
||||
],
|
||||
], $xml);
|
||||
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
|
||||
System::httpExit($arr['xml'], Response::TYPE_XML, 'application/xrd+xml');
|
||||
System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
||||
<Subject>{{$base}}</Subject>
|
||||
|
||||
<Property
|
||||
type="http://www.oexchange.org/spec/0.8/prop/vendor">Friendica</Property>
|
||||
<Property
|
||||
type="http://www.oexchange.org/spec/0.8/prop/title">Friendica Social Network</Property>
|
||||
<Property
|
||||
type="http://www.oexchange.org/spec/0.8/prop/name">Friendica</Property>
|
||||
<Property
|
||||
type="http://www.oexchange.org/spec/0.8/prop/prompt">Send to Friendica</Property>
|
||||
|
||||
<Link
|
||||
rel="icon"
|
||||
href="{{$base}}/images/friendica-16.png"
|
||||
type="image/png"
|
||||
/>
|
||||
|
||||
<Link
|
||||
rel="icon32"
|
||||
href="{{$base}}/images/friendica-32.png"
|
||||
type="image/png"
|
||||
/>
|
||||
|
||||
<Link
|
||||
rel= "http://www.oexchange.org/spec/0.8/rel/offer"
|
||||
href="{{$base}}/oexchange"
|
||||
type="text/html"
|
||||
/>
|
||||
</XRD>
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
<entry>
|
||||
{{if $entry.id}}<id>{{$entry.id}}</id>{{/if}}
|
||||
{{if $entry.displayName}}<displayName>{{$entry.displayName}}</displayName>{{/if}}
|
||||
{{if $entry.preferredUsername}}<preferredUsername>{{$entry.preferredUsername}}</preferredUsername>{{/if}}
|
||||
{{if $entry.urls}}{{foreach $entry.urls as $url}}<urls><value>{{$url.value}}</value><type>{{$url.type}}</type></urls>{{/foreach}}{{/if}}
|
||||
{{if $entry.photos}}{{foreach $entry.photos as $photo}}<photos><value>{{$photo.value}}</value><type>{{$photo.type}}</type></photos>{{/foreach}}{{/if}}
|
||||
</entry>
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<response>
|
||||
{{if $response.sorted}}<sorted>{{$response.sorted}}</sorted>{{/if}}
|
||||
{{if $response.filtered}}<filtered>{{$response.filtered}}</filtered>{{/if}}
|
||||
{{if $response.updatedSince}}<updatedSince>{{$response.updatedSince}}</updatedSince>{{/if}}
|
||||
<startIndex>{{$response.startIndex}}</startIndex>
|
||||
<itemsPerPage>{{$response.itemsPerPage}}</itemsPerPage>
|
||||
<totalResults>{{$response.totalResults}}</totalResults>
|
||||
|
||||
|
||||
{{if $response.totalResults}}
|
||||
{{foreach $response.entry as $entry}}
|
||||
{{include file="poco_entry_xml.tpl"}}
|
||||
{{/foreach}}
|
||||
{{else}}
|
||||
<entry></entry>
|
||||
{{/if}}
|
||||
</response>
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
||||
xmlns:hm='http://host-meta.net/xrd/1.0'>
|
||||
|
||||
<hm:Host>{{$zhost}}</hm:Host>
|
||||
|
||||
<Link rel='lrdd' type='application/xrd+xml' template='{{$domain}}/xrd?uri={uri}' />
|
||||
<Link rel='lrdd' type='application/json' template='{{$domain}}/.well-known/webfinger?resource={uri}' />
|
||||
<Link rel='acct-mgmt' href='{{$domain}}/amcd' />
|
||||
<Link rel='http://services.mozilla.com/amcd/0.1' href='{{$domain}}/amcd' />
|
||||
<Link rel="http://oexchange.org/spec/0.8/rel/resident-target" type="application/xrd+xml"
|
||||
href="{{$domain}}/oexchange/xrd" />
|
||||
|
||||
<Property xmlns:mk="http://salmon-protocol.org/ns/magic-key"
|
||||
type="http://salmon-protocol.org/ns/magic-key"
|
||||
mk:key_id="1">{{$bigkey}}</Property>
|
||||
</XRD>
|
|
@ -1,39 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>{{$accturi}}</Subject>
|
||||
<Alias>{{$profile_url}}</Alias>
|
||||
<Alias>{{$alias}}</Alias>
|
||||
|
||||
<Link rel="http://purl.org/macgirvin/dfrn/1.0"
|
||||
href="{{$profile_url}}" />
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from"
|
||||
type="application/atom+xml"
|
||||
href="{{$atom}}" />
|
||||
<Link rel="http://webfinger.net/rel/profile-page"
|
||||
type="text/html"
|
||||
href="{{$profile_url}}" />
|
||||
<Link rel="http://microformats.org/profile/hcard"
|
||||
type="text/html"
|
||||
href="{{$hcard_url}}" />
|
||||
<Link rel="http://portablecontacts.net/spec/1.0"
|
||||
href="{{$poco_url}}" />
|
||||
<Link rel="http://webfinger.net/rel/avatar"
|
||||
type="{{$type}}"
|
||||
href="{{$photo}}" />
|
||||
<Link rel="http://joindiaspora.com/seed_location"
|
||||
type="text/html"
|
||||
href="{{$baseurl}}/" />
|
||||
<Link rel="salmon"
|
||||
href="{{$salmon}}" />
|
||||
<Link rel="http://salmon-protocol.org/ns/salmon-replies"
|
||||
href="{{$salmon}}" />
|
||||
<Link rel="http://salmon-protocol.org/ns/salmon-mention"
|
||||
href="{{$salmen}}" />
|
||||
<Link rel="http://ostatus.org/schema/1.0/subscribe"
|
||||
template="{{$subscribe}}" />
|
||||
<Link rel="magic-public-key"
|
||||
href="{{$modexp}}" />
|
||||
<Link rel="http://purl.org/openwebauth/v1"
|
||||
type="application/x-zot+json"
|
||||
href="{{$openwebauth}}" />
|
||||
</XRD>
|
Loading…
Reference in a new issue