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