]> git.mxchange.org Git - friendica.git/commitdiff
Diaspora Relay: Only accept postings from anyone when the relay is configured
authorMichael <heluecht@pirati.ca>
Fri, 10 Feb 2017 20:45:22 +0000 (20:45 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 10 Feb 2017 20:45:22 +0000 (20:45 +0000)
boot.php
include/diaspora.php
mod/_well_known.php

index 56fb05435832cd62ef134c699631f96e80988043..e6fe08951614ec37bf3e0c3bd2defb203f636f76 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -430,6 +430,17 @@ define('PRIORITY_LOW',       40);
 define('PRIORITY_NEGLIGIBLE',50);
 /* @}*/
 
+/**
+ * @name Social Relay settings
+ *
+ * See here: https://github.com/jaywink/social-relay
+ * and here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts
+ * @{
+ */
+define('SR_SCOPE_NONE', '');
+define('SR_SCOPE_ALL',  'all');
+define('SR_SCOPE_TAGS', 'tags');
+/* @}*/
 
 // Normally this constant is defined - but not if "pcntl" isn't installed
 if (!defined("SIGTERM"))
index fdbc0479f906a3439d37c9119aad05dfabed8412..53f2e7ea7d0b08ae8688d66361d763937f1aa82d 100644 (file)
@@ -8,6 +8,8 @@
  * This will change in the future.
  */
 
+use \Friendica\Core\Config;
+
 require_once("include/items.php");
 require_once("include/bb2diaspora.php");
 require_once("include/Scrape.php");
@@ -309,10 +311,6 @@ class Diaspora {
                        return false;
                }
 
-               // Use a dummy importer to import the data for the public copy
-               $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
-               $message_id = self::dispatch($importer,$msg);
-
                // Now distribute it to the followers
                $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
                        (SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
@@ -320,7 +318,7 @@ class Diaspora {
                        dbesc(NETWORK_DIASPORA),
                        dbesc($msg["author"])
                );
-               if ($r) {
+               if (dbm::is_result($r)) {
                        foreach ($r as $rr) {
                                logger("delivering to: ".$rr["username"]);
                                self::dispatch($rr,$msg);
@@ -329,6 +327,14 @@ class Diaspora {
                        logger("No subscribers for ".$msg["author"]." ".print_r($msg, true), LOGGER_DEBUG);
                }
 
+               $social_relay = (bool)Config::get('system', 'relay_subscribe', false);
+
+               // Use a dummy importer to import the data for the public copy
+               if (dbm::is_result($r) OR $social_relay) {
+                       $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
+                       $message_id = self::dispatch($importer,$msg);
+               }
+
                return $message_id;
        }
 
index 75948a008834abf70279834a1911dbe39a913f96..622d7fd93f647e9838e29af57f3649b8f5f02828 100644 (file)
@@ -1,67 +1,68 @@
-<?php\r
-/// @TODO This file has DOS line endings!\r
-require_once("mod/hostxrd.php");\r
-require_once("mod/nodeinfo.php");\r
-\r
-function _well_known_init(App $a) {\r
-       if ($a->argc > 1) {\r
-               switch($a->argv[1]) {\r
-                       case "host-meta":\r
-                               hostxrd_init($a);\r
-                               break;\r
-                       case "x-social-relay":\r
-                               wk_social_relay($a);\r
-                               break;\r
-                       case "nodeinfo":\r
-                               nodeinfo_wellknown($a);\r
-                               break;\r
-               }\r
-       }\r
-       http_status_exit(404);\r
-       killme();\r
-}\r
-\r
-function wk_social_relay(App $a) {\r
-\r
-       define('SR_SCOPE_ALL', 'all');\r
-       define('SR_SCOPE_TAGS', 'tags');\r
-\r
-       $subscribe = (bool)get_config('system', 'relay_subscribe');\r
-\r
-       if ($subscribe)\r
-               $scope = get_config('system', 'relay_scope');\r
-       else\r
-               $scope = "";\r
-\r
-       $tags = array();\r
-\r
-       if ($scope == SR_SCOPE_TAGS) {\r
-\r
-               $server_tags = get_config('system', 'relay_server_tags');\r
-               $tagitems = explode(",", $server_tags);\r
-\r
-               foreach($tagitems AS $tag)\r
-                       $tags[trim($tag, "# ")] = trim($tag, "# ");\r
-\r
-               if (get_config('system', 'relay_user_tags')) {\r
-                       $terms = q("SELECT DISTINCT(`term`) FROM `search`");\r
-\r
-                       foreach($terms AS $term) {\r
-                               $tag = trim($term["term"], "#");\r
-                               $tags[$tag] = $tag;\r
-                       }\r
-               }\r
-       }\r
-\r
-       $taglist = array();\r
-       foreach($tags AS $tag)\r
-               $taglist[] = $tag;\r
-\r
-       $relay = array("subscribe" => $subscribe,\r
-                       "scope" => $scope,\r
-                       "tags" => $taglist);\r
-\r
-       header('Content-type: application/json; charset=utf-8');\r
-       echo json_encode($relay, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);\r
-       exit;\r
-}\r
+<?php
+
+use \Friendica\Core\Config;
+
+require_once("mod/hostxrd.php");
+require_once("mod/nodeinfo.php");
+
+function _well_known_init(App $a) {
+       if ($a->argc > 1) {
+               switch($a->argv[1]) {
+                       case "host-meta":
+                               hostxrd_init($a);
+                               break;
+                       case "x-social-relay":
+                               wk_social_relay($a);
+                               break;
+                       case "nodeinfo":
+                               nodeinfo_wellknown($a);
+                               break;
+               }
+       }
+       http_status_exit(404);
+       killme();
+}
+
+function wk_social_relay(App $a) {
+
+       $subscribe = (bool)Config::get('system', 'relay_subscribe', false);
+
+       if ($subscribe) {
+               $scope = Config::get('system', 'relay_scope', SR_SCOPE_ALL);
+       } else {
+               $scope = SR_SCOPE_NONE;
+       }
+
+       $tags = array();
+
+       if ($scope == SR_SCOPE_TAGS) {
+               $server_tags = Config::get('system', 'relay_server_tags');
+               $tagitems = explode(",", $server_tags);
+
+               foreach($tagitems AS $tag) {
+                       $tags[trim($tag, "# ")] = trim($tag, "# ");
+               }
+
+               if (Config::get('system', 'relay_user_tags')) {
+                       $terms = q("SELECT DISTINCT(`term`) FROM `search`");
+
+                       foreach($terms AS $term) {
+                               $tag = trim($term["term"], "#");
+                               $tags[$tag] = $tag;
+                       }
+               }
+       }
+
+       $taglist = array();
+       foreach($tags AS $tag) {
+               $taglist[] = $tag;
+       }
+
+       $relay = array("subscribe" => $subscribe,
+                       "scope" => $scope,
+                       "tags" => $taglist);
+
+       header('Content-type: application/json; charset=utf-8');
+       echo json_encode($relay, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
+       exit;
+}