-<?php\r
-require_once("mod/hostxrd.php");\r
-\r
-function _well_known_init(&$a){\r
- if ($a->argc > 1) {\r
- switch($a->argv[1]) {\r
- case "host-meta":\r
- hostxrd_init($a);\r
- break;\r
- case "x-social-relay":\r
- wk_social_relay($a);\r
- break;\r
- }\r
- }\r
- http_status_exit(404);\r
- killme();\r
-}\r
-\r
-function wk_social_relay(&$a) {\r
-\r
- define('SR_SCOPE_ALL', 'all');\r
- define('SR_SCOPE_TAGS', 'tags');\r
-\r
- $subscribe = (bool)true;\r
- $scope = SR_SCOPE_ALL;\r
- //$scope = SR_SCOPE_TAGS;\r
-\r
- $tags = array();\r
-\r
- if ($scope == SR_SCOPE_TAGS) {\r
- $terms = q("SELECT DISTINCT(`term`) FROM `search`");\r
-\r
- foreach($terms AS $term) {\r
- $tag = trim($term["term"], "#");\r
- $tags[] = $tag;\r
- }\r
- }\r
-\r
- $relay = array("subscribe" => $subscribe,\r
- "scope" => $scope,\r
- "tags" => array_unique($tags));\r
-\r
- header('Content-type: application/json; charset=utf-8');\r
- echo json_encode($relay, true);\r
- exit;\r
-}\r
+<?php
+
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Core\System;
+
+require_once 'mod/hostxrd.php';
+require_once 'mod/nodeinfo.php';
+require_once 'mod/xrd.php';
+
+function _well_known_init(App $a)
+{
+ if ($a->argc > 1) {
+ switch ($a->argv[1]) {
+ case "host-meta":
+ hostxrd_init($a);
+ break;
+ case "x-social-relay":
+ wk_social_relay();
+ break;
+ case "nodeinfo":
+ nodeinfo_wellknown($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;
+}