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