]> git.mxchange.org Git - friendica.git/blob - src/Module/WellKnown/XSocialRelay.php
Refactor dynamic App::getConfig() to static DI::config()
[friendica.git] / src / Module / WellKnown / XSocialRelay.php
1 <?php
2
3 namespace Friendica\Module\WellKnown;
4
5 use Friendica\BaseModule;
6 use Friendica\DI;
7 use Friendica\Model\Search;
8
9 /**
10  * Node subscription preferences for social realy systems
11  * @see https://git.feneas.org/jaywink/social-relay/blob/master/docs/relays.md
12  */
13 class XSocialRelay extends BaseModule
14 {
15         public static function rawContent(array $parameters = [])
16         {
17                 $app = DI::app();
18                 $config = DI::config();
19
20                 $subscribe = $config->get('system', 'relay_subscribe', false);
21
22                 if ($subscribe) {
23                         $scope = $config->get('system', 'relay_scope', SR_SCOPE_ALL);
24                 } else {
25                         $scope = SR_SCOPE_NONE;
26                 }
27
28                 $systemTags = [];
29                 $userTags = [];
30
31                 if ($scope == SR_SCOPE_TAGS) {
32                         $server_tags = $config->get('system', 'relay_server_tags');
33                         $tagitems = explode(',', $server_tags);
34
35                         /// @todo Check if it was better to use "strtolower" on the tags
36                         foreach ($tagitems AS $tag) {
37                                 $systemTags[] = trim($tag, '# ');
38                         }
39
40                         if ($config->get('system', 'relay_user_tags')) {
41                                 $userTags = Search::getUserTags();
42                         }
43                 }
44
45                 $tagList = array_unique(array_merge($systemTags, $userTags));
46
47                 $relay = [
48                         'subscribe' => $subscribe,
49                         'scope'     => $scope,
50                         'tags'      => $tagList,
51                         'protocols' => [
52                                 'diaspora' => [
53                                         'receive' => $app->getBaseURL() . '/receive/public'
54                                 ],
55                                 'dfrn'     => [
56                                         'receive' => $app->getBaseURL() . '/dfrn_notify'
57                                 ]
58                         ]
59                 ];
60
61                 header('Content-type: application/json; charset=utf-8');
62                 echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
63                 exit;
64         }
65 }