X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdiaspora.php;h=eca22092d81352987a2a8a0e6981c8c7aa3fb206;hb=bb59f105e719ef420a5cd0dcacfa3e3955dc5a0c;hp=1cb4f0e9228da4ccf03ec59a71211390dde213ec;hpb=44d966574dc2edc58e1f5c0402a1956d4d554235;p=friendica.git diff --git a/include/diaspora.php b/include/diaspora.php index 1cb4f0e922..eca22092d8 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -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"); @@ -45,13 +47,13 @@ class Diaspora { foreach($servers AS $server) { $server = trim($server); + $addr = "relay@".str_replace("http://", "", normalise_link($server)); $batch = $server."/receive/public"; - $relais = q("SELECT `batch`, `id`, `name`,`network` FROM `contact` WHERE `uid` = 0 AND `batch` = '%s' LIMIT 1", dbesc($batch)); + $relais = q("SELECT `batch`, `id`, `name`,`network` FROM `contact` WHERE `uid` = 0 AND `batch` = '%s' AND `addr` = '%s' AND `nurl` = '%s' LIMIT 1", + dbesc($batch), dbesc($addr), dbesc(normalise_link($server))); if (!$relais) { - $addr = "relay@".str_replace("http://", "", normalise_link($server)); - $r = q("INSERT INTO `contact` (`uid`, `created`, `name`, `nick`, `addr`, `url`, `nurl`, `batch`, `network`, `rel`, `blocked`, `pending`, `writable`, `name-date`, `uri-date`, `avatar-date`) VALUES (0, '%s', '%s', 'relay', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, '%s', '%s', '%s')", datetime_convert(), @@ -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,13 +318,23 @@ 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); } - } else - logger("No subscribers for ".$msg["author"]." ".print_r($msg, true)); + } else { + $social_relay = (bool)Config::get('system', 'relay_subscribe', false); + + // Use a dummy importer to import the data for the public copy + if ($social_relay) { + $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE); + $message_id = self::dispatch($importer,$msg); + } else { + logger("Unwanted message from ".$msg["author"]." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG); + } + } return $message_id; } @@ -743,8 +751,7 @@ class Diaspora { dbesc($handle) ); - if ($r) { - //logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - first try", LOGGER_DEBUG); + if (dbm::is_result($r)) { return $r[0]; } else { // We haven't found it? @@ -755,7 +762,6 @@ class Diaspora { $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); if (dbm::is_result($r)) { - logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - second try", LOGGER_DEBUG); return $r[0]; } } @@ -768,8 +774,7 @@ class Diaspora { intval($uid), dbesc($nurl_sql) ); - if(dbm::is_result($r)) { - logger("Found contact ".$r[0]['id']." for user ".$uid." and handle ".$handle." - third try", LOGGER_DEBUG); + if (dbm::is_result($r)) { return $r[0]; } @@ -848,12 +853,12 @@ class Diaspora { * @return int|bool message id if the message already was stored into the system - or false. */ private static function message_exists($uid, $guid) { - $r = q("SELECT `guid` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), dbesc($guid) ); - if ($r) { + if (dbm::is_result($r)) { logger("message ".$guid." already exists for user ".$uid); return $r[0]["id"]; } @@ -2303,8 +2308,9 @@ class Diaspora { dbesc($target_guid), intval($importer["uid"]) ); - if (!$r) + if (!$r) { return false; + } // Check if the sender is the thread owner $p = q("SELECT `id`, `author-link`, `origin` FROM `item` WHERE `id` = %d", @@ -2327,7 +2333,7 @@ class Diaspora { logger("Deleted target ".$target_guid." (".$r[0]["id"].") from user ".$importer["uid"]." parent: ".$p[0]["id"], LOGGER_DEBUG); // Now check if the retraction needs to be relayed by us - if($p[0]["origin"]) { + if ($p[0]["origin"]) { // notify others proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $r[0]["id"]); } @@ -2498,15 +2504,17 @@ class Diaspora { * @return string the handle in the format user@domain.tld */ private static function my_handle($contact) { - if ($contact["addr"] != "") + if ($contact["addr"] != "") { return $contact["addr"]; + } // Normally we should have a filled "addr" field - but in the past this wasn't the case // So - just in case - we build the the address here. - if ($contact["nickname"] != "") + if ($contact["nickname"] != "") { $nick = $contact["nickname"]; - else + } else { $nick = $contact["nick"]; + } return $nick."@".substr(App::get_baseurl(), strpos(App::get_baseurl(),"://") + 3); }