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