friendica_2021.01_tupambae_.../mod/_well_known.php

83 lines
1.7 KiB
PHP
Raw Normal View History

<?php
use Friendica\App;
2017-04-30 06:01:26 +02:00
use Friendica\Core\Config;
use Friendica\Core\System;
2019-04-30 22:22:36 +02:00
use Friendica\Module\Hostxrd;
use Friendica\Module\Nodeinfo;
require_once 'mod/xrd.php';
function _well_known_init(App $a)
{
if ($a->argc > 1) {
switch ($a->argv[1]) {
case "host-meta":
2019-04-30 22:22:36 +02:00
Hostxrd::printHostMeta();
break;
case "x-social-relay":
wk_social_relay();
break;
case "nodeinfo":
Nodeinfo::printWellKnown($a);
break;
case "webfinger":
xrd_init($a);
break;
}
}
System::httpExit(404);
}
function wk_social_relay()
{
$subscribe = (bool) Config::get('system', 'relay_subscribe', false);
if ($subscribe) {
$scope = Config::get('system', 'relay_scope', SR_SCOPE_ALL);
} else {
$scope = SR_SCOPE_NONE;
}
$tags = [];
if ($scope == SR_SCOPE_TAGS) {
$server_tags = Config::get('system', 'relay_server_tags');
$tagitems = explode(",", $server_tags);
/// @todo Check if it was better to use "strtolower" on the tags
foreach ($tagitems AS $tag) {
$tag = trim($tag, "# ");
$tags[$tag] = $tag;
}
if (Config::get('system', 'relay_user_tags')) {
$terms = q("SELECT DISTINCT(`term`) FROM `search`");
foreach ($terms AS $term) {
$tag = trim($term["term"], "#");
$tags[$tag] = $tag;
}
}
}
$taglist = [];
foreach ($tags AS $tag) {
if (!empty($tag)) {
$taglist[] = $tag;
}
}
$relay = [
'subscribe' => $subscribe,
'scope' => $scope,
'tags' => $taglist,
'protocols' => ['diaspora' => ['receive' => System::baseUrl() . '/receive/public'],
'dfrn' => ['receive' => System::baseUrl() . '/dfrn_notify']]
];
header('Content-type: application/json; charset=utf-8');
echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit;
}