1
1
Fork 0

Issue 3318: Make sure that we fetch an author

This commit is contained in:
Michael 2017-05-05 19:41:41 +00:00
parent 17632118d6
commit 30476623c5
2 changed files with 43 additions and 11 deletions

View file

@ -3,6 +3,8 @@
* @file include/ostatus.php * @file include/ostatus.php
*/ */
use \Friendica\Core\Config;
require_once("include/Contact.php"); require_once("include/Contact.php");
require_once("include/threads.php"); require_once("include/threads.php");
require_once("include/html2bbcode.php"); require_once("include/html2bbcode.php");
@ -79,23 +81,43 @@ class ostatus {
$author = array(); $author = array();
$author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; $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; $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"]; $aliaslink = $author["author-link"];
$alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes; $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes;
if (is_object($alternate)) if (is_object($alternate)) {
foreach($alternate AS $attributes) foreach ($alternate AS $attributes) {
if ($attributes->name == "href") if (($attributes->name == "href") AND ($attributes->textContent != "")) {
$author["author-link"] = $attributes->textContent; $author["author-link"] = $attributes->textContent;
}
}
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", $author["contact-id"] = $contact["id"];
intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET)); if ($author["author-link"] != "") {
if ($r) { if ($aliaslink == "") {
$contact = $r[0]; $aliaslink = $author["author-link"];
$author["contact-id"] = $r[0]["id"]; }
} else
$author["contact-id"] = $contact["id"]; $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(); $avatarlist = array();
$avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context); $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context);
@ -2268,6 +2290,9 @@ class ostatus {
$root = self::add_header($doc, $owner); $root = self::add_header($doc, $owner);
foreach ($items AS $item) { foreach ($items AS $item) {
if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🍼';
}
$entry = self::entry($doc, $item, $owner); $entry = self::entry($doc, $item, $owner);
$root->appendChild($entry); $root->appendChild($entry);
} }
@ -2288,6 +2313,10 @@ class ostatus {
$doc = new DOMDocument('1.0', 'utf-8'); $doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true; $doc->formatOutput = true;
if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🐟';
}
$entry = self::entry($doc, $item, $owner, true); $entry = self::entry($doc, $item, $owner, true);
$doc->appendChild($entry); $doc->appendChild($entry);

View file

@ -33,6 +33,9 @@ function handle_pubsubhubbub($id) {
else else
$rr = $r[0]; $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); 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']); $params = ostatus::feed($a, $rr['nickname'], $rr['last_update']);