]> git.mxchange.org Git - friendica.git/commitdiff
Issue 3318: Make sure that we fetch an author
authorMichael <heluecht@pirati.ca>
Fri, 5 May 2017 19:41:41 +0000 (19:41 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 5 May 2017 19:41:41 +0000 (19:41 +0000)
include/ostatus.php
include/pubsubpublish.php

index 40bcdcdcc57d2d7b50f4fa1fc9d422974aec3069..5bd1865bd0f129d735fdc5237f3b66756a08395f 100644 (file)
@@ -3,6 +3,8 @@
  * @file include/ostatus.php
  */
 
+use \Friendica\Core\Config;
+
 require_once("include/Contact.php");
 require_once("include/threads.php");
 require_once("include/html2bbcode.php");
@@ -79,23 +81,43 @@ class ostatus {
                $author = array();
                $author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
                $author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue;
+               $addr = $xpath->evaluate('atom:author/atom:email/text()', $context)->item(0)->nodeValue;
 
                $aliaslink = $author["author-link"];
 
                $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes;
-               if (is_object($alternate))
-                       foreach($alternate AS $attributes)
-                               if ($attributes->name == "href")
+               if (is_object($alternate)) {
+                       foreach ($alternate AS $attributes) {
+                               if (($attributes->name == "href") AND ($attributes->textContent != "")) {
                                        $author["author-link"] = $attributes->textContent;
+                               }
+                       }
+               }
 
-               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'",
-                       intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
-                       dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET));
-               if ($r) {
-                       $contact = $r[0];
-                       $author["contact-id"] = $r[0]["id"];
-               } else
-                       $author["contact-id"] = $contact["id"];
+               $author["contact-id"] = $contact["id"];
+
+               if ($author["author-link"] != "") {
+                       if ($aliaslink == "") {
+                               $aliaslink = $author["author-link"];
+                       }
+
+                       $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'",
+                               intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
+                               dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET));
+                       if (dbm::is_result($r)) {
+                               $contact = $r[0];
+                               $author["contact-id"] = $r[0]["id"];
+                               $author["author-link"] = $r[0]["url"];
+                       }
+               } elseif ($addr != "") {
+                       // Should not happen
+                       $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `uid` = ? AND `addr` = ? AND `network` != ?",
+                                       $importer["uid"], $addr, NETWORK_STATUSNET);
+                       if (dbm::is_result($contact)) {
+                               $author["contact-id"] = $contact["id"];
+                               $author["author-link"] = $contact["url"];
+                       }
+               }
 
                $avatarlist = array();
                $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
@@ -2268,6 +2290,9 @@ class ostatus {
                $root = self::add_header($doc, $owner);
 
                foreach ($items AS $item) {
+                       if (Config::get('system', 'ostatus_debug')) {
+                               $item['body'] .= '🍼';
+                       }
                        $entry = self::entry($doc, $item, $owner);
                        $root->appendChild($entry);
                }
@@ -2288,6 +2313,10 @@ class ostatus {
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
 
+               if (Config::get('system', 'ostatus_debug')) {
+                       $item['body'] .= '🐟';
+               }
+
                $entry = self::entry($doc, $item, $owner, true);
 
                $doc->appendChild($entry);
index 3641bbcf74fc3d16f98ed67b13a687119e31739a..1e47c3085b40c74c2b46a79b64fd6d230f91ceae 100644 (file)
@@ -33,6 +33,9 @@ function handle_pubsubhubbub($id) {
        else
                $rr = $r[0];
 
+       /// @todo Check server status with poco_check_server()
+       // Before this can be done we need a way to safely detect the server url.
+
        logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
 
        $params = ostatus::feed($a, $rr['nickname'], $rr['last_update']);