]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/WellKnown/XSocialRelay.php
Use centralized function to fetch query results
[friendica.git] / src / Module / WellKnown / XSocialRelay.php
index bbd51069d9fa67ff88b6791370be355dce138c4f..bf767a3e7ba0f0d34b5570ab42596a9629dc73e6 100644 (file)
@@ -1,9 +1,30 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module\WellKnown;
 
 use Friendica\BaseModule;
+use Friendica\DI;
 use Friendica\Model\Search;
+use Friendica\Protocol\Relay;
 
 /**
  * Node subscription preferences for social realy systems
@@ -11,28 +32,21 @@ use Friendica\Model\Search;
  */
 class XSocialRelay extends BaseModule
 {
-       public static function rawContent($parameters)
+       protected function rawContent(array $request = [])
        {
-               $app = self::getApp();
-               $config = $app->getConfig();
-
-               $subscribe = $config->get('system', 'relay_subscribe', false);
+               $config = DI::config();
 
-               if ($subscribe) {
-                       $scope = $config->get('system', 'relay_scope', SR_SCOPE_ALL);
-               } else {
-                       $scope = SR_SCOPE_NONE;
-               }
+               $scope = $config->get('system', 'relay_scope');
 
                $systemTags = [];
                $userTags = [];
 
-               if ($scope == SR_SCOPE_TAGS) {
+               if ($scope == Relay::SCOPE_TAGS) {
                        $server_tags = $config->get('system', 'relay_server_tags');
                        $tagitems = explode(',', $server_tags);
 
                        /// @todo Check if it was better to use "strtolower" on the tags
-                       foreach ($tagitems AS $tag) {
+                       foreach ($tagitems as $tag) {
                                $systemTags[] = trim($tag, '# ');
                        }
 
@@ -44,19 +58,24 @@ class XSocialRelay extends BaseModule
                $tagList = array_unique(array_merge($systemTags, $userTags));
 
                $relay = [
-                       'subscribe' => $subscribe,
+                       'subscribe' => ($scope != Relay::SCOPE_NONE),
                        'scope'     => $scope,
                        'tags'      => $tagList,
                        'protocols' => [
-                               'diaspora' => [
-                                       'receive' => $app->getBaseURL() . '/receive/public'
+                               'activitypub' => [
+                                       'actor' => DI::baseUrl()->get() . '/friendica',
+                                       'receive' => DI::baseUrl()->get() . '/inbox'
                                ],
                                'dfrn'     => [
-                                       'receive' => $app->getBaseURL() . '/dfrn_notify'
+                                       'receive' => DI::baseUrl()->get() . '/dfrn_notify'
                                ]
                        ]
                ];
 
+               if (DI::config()->get("system", "diaspora_enabled")) {
+                       $relay['protocols']['diaspora'] = ['receive' => DI::baseUrl()->get() . '/receive/public'];
+               }
+
                header('Content-type: application/json; charset=utf-8');
                echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
                exit;