]> git.mxchange.org Git - friendica.git/blob - mod/_well_known.php
Merge pull request #2 from friendica/master
[friendica.git] / mod / _well_known.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6
7 require_once 'mod/hostxrd.php';
8 require_once 'mod/nodeinfo.php';
9 require_once 'mod/xrd.php';
10
11 function _well_known_init(App $a)
12 {
13         if ($a->argc > 1) {
14                 switch ($a->argv[1]) {
15                         case "host-meta":
16                                 hostxrd_init($a);
17                                 break;
18                         case "x-social-relay":
19                                 wk_social_relay();
20                                 break;
21                         case "nodeinfo":
22                                 nodeinfo_wellknown($a);
23                                 break;
24                         case "webfinger":
25                                 xrd_init($a);
26                                 break;
27                 }
28         }
29         System::httpExit(404);
30         killme();
31 }
32
33 function wk_social_relay()
34 {
35         $subscribe = (bool) Config::get('system', 'relay_subscribe', false);
36
37         if ($subscribe) {
38                 $scope = Config::get('system', 'relay_scope', SR_SCOPE_ALL);
39         } else {
40                 $scope = SR_SCOPE_NONE;
41         }
42
43         $tags = [];
44
45         if ($scope == SR_SCOPE_TAGS) {
46                 $server_tags = Config::get('system', 'relay_server_tags');
47                 $tagitems = explode(",", $server_tags);
48
49                 foreach ($tagitems AS $tag) {
50                         $tags[trim($tag, "# ")] = trim($tag, "# ");
51                 }
52
53                 if (Config::get('system', 'relay_user_tags')) {
54                         $terms = q("SELECT DISTINCT(`term`) FROM `search`");
55
56                         foreach ($terms AS $term) {
57                                 $tag = trim($term["term"], "#");
58                                 $tags[$tag] = $tag;
59                         }
60                 }
61         }
62
63         $taglist = [];
64         foreach ($tags AS $tag) {
65                 $taglist[] = $tag;
66         }
67
68         $relay = [
69                 "subscribe" => $subscribe,
70                 "scope" => $scope,
71                 "tags" => $taglist
72         ];
73
74         header('Content-type: application/json; charset=utf-8');
75         echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
76         exit;
77 }