Fix code style

This commit is contained in:
Art4 2025-01-13 13:31:54 +00:00
parent d4697a17a3
commit 0e59dba914
102 changed files with 3038 additions and 2764 deletions

View file

@ -45,7 +45,6 @@ use GuzzleHttp\Psr7\Uri;
*/
class DFRN
{
const TOP_LEVEL = 0; // Top level posting
const REPLY = 1; // Regular reply that is stored locally
const REPLY_RC = 2; // Reply that will be relayed
@ -64,27 +63,27 @@ class DFRN
public static function getImporter(int $cid, int $uid = 0): array
{
$condition = ['id' => $cid, 'blocked' => false, 'pending' => false];
$contact = DBA::selectFirst('contact', [], $condition);
$contact = DBA::selectFirst('contact', [], $condition);
if (!DBA::isResult($contact)) {
return [];
}
$contact['cpubkey'] = $contact['pubkey'];
$contact['cprvkey'] = $contact['prvkey'];
$contact['cpubkey'] = $contact['pubkey'];
$contact['cprvkey'] = $contact['prvkey'];
$contact['senderName'] = $contact['name'];
if ($uid != 0) {
$condition = ['uid' => $uid, 'verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
$user = DBA::selectFirst('user', [], $condition);
$user = DBA::selectFirst('user', [], $condition);
if (!DBA::isResult($user)) {
return [];
}
$user['importer_uid'] = $user['uid'];
$user['uprvkey'] = $user['prvkey'];
$user['uprvkey'] = $user['prvkey'];
} else {
$user = ['importer_uid' => 0, 'uprvkey' => '', 'timezone' => 'UTC',
'nickname' => '', 'page-flags' => 0, 'account-type' => 0, 'prvnets' => 0];
'nickname' => '', 'page-flags' => 0, 'account-type' => 0, 'prvnets' => 0];
}
return array_merge($contact, $user);
@ -105,7 +104,7 @@ class DFRN
*/
public static function entries(array $items, array $owner): string
{
$doc = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
@ -118,7 +117,7 @@ class DFRN
// These values aren't sent when sending from the queue.
/// @todo Check if we can set these values from the queue or if they are needed at all.
$item['entry:comment-allow'] = ($item['entry:comment-allow'] ?? '') ?: true;
$item['entry:cid'] = $item['entry:cid'] ?? 0;
$item['entry:cid'] = $item['entry:cid'] ?? 0;
$entry = self::entry($doc, 'text', $item, $owner, $item['entry:comment-allow'], $item['entry:cid']);
if (isset($entry)) {
@ -166,9 +165,9 @@ class DFRN
$owner = ['uid' => 0, 'nick' => 'feed-item'];
}
$doc = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$type = 'html';
$type = 'html';
if ($conversation) {
$root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
@ -210,12 +209,12 @@ class DFRN
*/
public static function mail(array $mail, array $owner): string
{
$doc = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
$mailElement = $doc->createElement('dfrn:mail');
$mailElement = $doc->createElement('dfrn:mail');
$senderElement = $doc->createElement('dfrn:sender');
XML::addElement($doc, $senderElement, 'dfrn:name', $owner['name']);
@ -247,7 +246,7 @@ class DFRN
*/
public static function fsuggest(array $item, array $owner): string
{
$doc = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
@ -293,7 +292,7 @@ class DFRN
$photos[$p['scale']] = DI::baseUrl() . '/photo/' . $p['resource-id'] . '-' . $p['scale'] . Images::getExtensionByMimeType($p['type']);
}
$doc = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
@ -411,10 +410,10 @@ class DFRN
if (DBA::isResult($profile)) {
$tmp_dob = substr($profile['dob'], 5);
if (intval($tmp_dob)) {
$y = DateTimeFormat::timezoneNow($tz, 'Y');
$bd = $y . '-' . $tmp_dob . ' 00:00';
$y = DateTimeFormat::timezoneNow($tz, 'Y');
$bd = $y . '-' . $tmp_dob . ' 00:00';
$t_dob = strtotime($bd);
$now = strtotime(DateTimeFormat::timezoneNow($tz));
$now = strtotime(DateTimeFormat::timezoneNow($tz));
if ($t_dob < $now) {
$bd = (int) $y + 1 . '-' . $tmp_dob . ' 00:00';
}
@ -457,11 +456,11 @@ class DFRN
XML::addElement($doc, $author, 'dfrn:handle', $owner['addr'], $attributes);
$attributes = [
'rel' => 'photo',
'type' => 'image/jpeg',
'media:width' => Proxy::PIXEL_SMALL,
'rel' => 'photo',
'type' => 'image/jpeg',
'media:width' => Proxy::PIXEL_SMALL,
'media:height' => Proxy::PIXEL_SMALL,
'href' => User::getAvatarUrl($owner, Proxy::SIZE_SMALL),
'href' => User::getAvatarUrl($owner, Proxy::SIZE_SMALL),
];
if (!$public || !$hide) {
@ -489,9 +488,11 @@ class DFRN
}
// Only show contact details when we are allowed to
$profile = DBA::selectFirst('owner-view',
$profile = DBA::selectFirst(
'owner-view',
['about', 'name', 'homepage', 'nickname', 'timezone', 'locality', 'region', 'country-name', 'pub_keywords', 'xmpp', 'dob'],
['uid' => $owner['uid'], 'hidewall' => false]);
['uid' => $owner['uid'], 'hidewall' => false]
);
if (DBA::isResult($profile)) {
XML::addElement($doc, $author, 'poco:displayName', $profile['name']);
XML::addElement($doc, $author, 'poco:updated', $namdate);
@ -578,20 +579,20 @@ class DFRN
/// - Check real image type and image size
/// - Check which of these elements we should use
$attributes = [
'rel' => 'photo',
'type' => 'image/jpeg',
'media:width' => 80,
'rel' => 'photo',
'type' => 'image/jpeg',
'media:width' => 80,
'media:height' => 80,
'href' => $contact['photo'],
'href' => $contact['photo'],
];
XML::addElement($doc, $author, 'link', '', $attributes);
$attributes = [
'rel' => 'avatar',
'type' => 'image/jpeg',
'media:width' => 80,
'rel' => 'avatar',
'type' => 'image/jpeg',
'media:width' => 80,
'media:height' => 80,
'href' => $contact['photo'],
'href' => $contact['photo'],
];
XML::addElement($doc, $author, 'link', '', $attributes);
}
@ -680,8 +681,8 @@ class DFRN
{
foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT]) as $attachment) {
$attributes = ['rel' => 'enclosure',
'href' => $attachment['url'],
'type' => $attachment['mimetype']];
'href' => $attachment['url'],
'type' => $attachment['mimetype']];
if (!empty($attachment['size'])) {
$attributes['length'] = intval($attachment['size']);
@ -771,8 +772,8 @@ class DFRN
if ($item['gravity'] != Item::GRAVITY_PARENT) {
$parent = Post::selectFirst(['guid', 'plink'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
if (DBA::isResult($parent)) {
$attributes = ["ref" => $item['thr-parent'], "type" => "text/html",
"href" => $parent['plink'],
$attributes = ["ref" => $item['thr-parent'], "type" => "text/html",
"href" => $parent['plink'],
"dfrn:diaspora_guid" => $parent['guid']];
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
}
@ -781,7 +782,7 @@ class DFRN
// Add conversation data. This is used for OStatus
$attributes = [
'href' => $item['conversation'],
'ref' => $item['conversation'],
'ref' => $item['conversation'],
];
XML::addElement($doc, $entry, 'ostatus:conversation', $item['conversation'], $attributes);
@ -806,7 +807,7 @@ class DFRN
'link',
'',
[
'rel' => 'alternate',
'rel' => 'alternate',
'type' => 'text/html',
'href' => DI::baseUrl() . '/display/' . $item['guid']
],
@ -888,7 +889,7 @@ class DFRN
foreach ($mentioned as $mention) {
$condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($mention)];
$contact = DBA::selectFirst('contact', ['contact-type'], $condition);
$contact = DBA::selectFirst('contact', ['contact-type'], $condition);
if (DBA::isResult($contact) && ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
XML::addElement(
@ -897,9 +898,9 @@ class DFRN
'link',
'',
[
'rel' => 'mentioned',
'rel' => 'mentioned',
'ostatus:object-type' => Activity\ObjectType::GROUP,
'href' => $mention,
'href' => $mention,
],
);
} else {
@ -909,9 +910,9 @@ class DFRN
'link',
'',
[
'rel' => 'mentioned',
'rel' => 'mentioned',
'ostatus:object-type' => Activity\ObjectType::PERSON,
'href' => $mention,
'href' => $mention,
],
);
}
@ -939,7 +940,7 @@ class DFRN
if (empty($contact['addr'])) {
DI::logger()->notice('Empty contact handle for ' . $contact['id'] . ' - ' . $contact['url'] . ' - trying to update it.');
if (Contact::updateFromProbe($contact['id'])) {
$new_contact = DBA::selectFirst('contact', ['addr'], ['id' => $contact['id']]);
$new_contact = DBA::selectFirst('contact', ['addr'], ['id' => $contact['id']]);
$contact['addr'] = $new_contact['addr'];
}
@ -963,10 +964,10 @@ class DFRN
// Create the endpoint for public posts. This is some WIP and should later be added to the probing
if ($public_batch && empty($contact['batch'])) {
$parts = parse_url($contact['notify']);
$parts = parse_url($contact['notify']);
$path_parts = explode('/', $parts['path']);
array_pop($path_parts);
$parts['path'] = implode('/', $path_parts);
$parts['path'] = implode('/', $path_parts);
$contact['batch'] = (string)Uri::fromParts($parts);
}
@ -1043,7 +1044,7 @@ class DFRN
*/
private static function fetchauthor(\DOMXPath $xpath, \DOMNode $context, array $importer, string $element, bool $onlyfetch, string $xml = ''): array
{
$author = [];
$author = [];
$author["name"] = XML::getFirstNodeValue($xpath, $element."/atom:name/text()", $context);
$author["link"] = XML::getFirstNodeValue($xpath, $element."/atom:uri/text()", $context);
@ -1060,15 +1061,15 @@ class DFRN
if (DBA::isResult($contact_old)) {
$author["contact-id"] = $contact_old["id"];
$author["network"] = $contact_old["network"];
$author["network"] = $contact_old["network"];
} else {
DI::logger()->info('Contact not found', ['condition' => $condition]);
$author["contact-unknown"] = true;
$contact = Contact::getByURL($author["link"], null, ["id", "network"]);
$author["contact-id"] = $contact["id"] ?? $importer["id"];
$author["network"] = $contact["network"] ?? $importer["network"];
$onlyfetch = true;
$contact = Contact::getByURL($author["link"], null, ["id", "network"]);
$author["contact-id"] = $contact["id"] ?? $importer["id"];
$author["network"] = $contact["network"] ?? $importer["network"];
$onlyfetch = true;
}
// Until now we aren't serving different sizes - but maybe later
@ -1076,7 +1077,7 @@ class DFRN
/// @todo check if "avatar" or "photo" would be the best field in the specification
$avatars = $xpath->query($element . "/atom:link[@rel='avatar']", $context);
foreach ($avatars as $avatar) {
$href = "";
$href = "";
$width = 0;
foreach ($avatar->attributes as $attributes) {
/// @TODO Rewrite these similar if() to one switch
@ -1186,7 +1187,7 @@ class DFRN
}
// Save the keywords into the contact table
$tags = [];
$tags = [];
$tagelements = $xpath->evaluate($element . "/poco:tags/text()", $context);
foreach ($tagelements as $tag) {
$tags[$tag->nodeValue] = $tag->nodeValue;
@ -1212,7 +1213,7 @@ class DFRN
if (!in_array($value, ["", "0000-00-00", DBA::NULL_DATE])) {
$bdyear = date("Y");
$value = str_replace(["0000", "0001"], $bdyear, $value);
$value = str_replace(["0000", "0001"], $bdyear, $value);
if (strtotime($value) < time()) {
$value = str_replace($bdyear, $bdyear + 1, $value);
@ -1228,10 +1229,10 @@ class DFRN
}
$fields = ['name' => $contact['name'], 'nick' => $contact['nick'], 'about' => $contact['about'],
'location' => $contact['location'], 'addr' => $contact['addr'], 'keywords' => $contact['keywords'],
'bdyear' => $contact['bdyear'], 'bd' => $contact['bd'], 'hidden' => $contact['hidden'],
'xmpp' => $contact['xmpp'], 'name-date' => DateTimeFormat::utc($contact['name-date']),
'unsearchable' => $contact['hidden'], 'uri-date' => DateTimeFormat::utc($contact['uri-date'])];
'location' => $contact['location'], 'addr' => $contact['addr'], 'keywords' => $contact['keywords'],
'bdyear' => $contact['bdyear'], 'bd' => $contact['bd'], 'hidden' => $contact['hidden'],
'xmpp' => $contact['xmpp'], 'name-date' => DateTimeFormat::utc($contact['name-date']),
'unsearchable' => $contact['hidden'], 'uri-date' => DateTimeFormat::utc($contact['uri-date'])];
Contact::update($fields, ['id' => $contact['id'], 'network' => $contact['network']], $contact_old);
@ -1267,7 +1268,7 @@ class DFRN
return "";
}
$obj_doc = new DOMDocument("1.0", "utf-8");
$obj_doc = new DOMDocument("1.0", "utf-8");
$obj_doc->formatOutput = true;
$obj_element = $obj_doc->createElementNS( ActivityNamespace::ATOM1, $element);
@ -1319,17 +1320,17 @@ class DFRN
{
DI::logger()->info("Processing mails");
$msg = [];
$msg['uid'] = $importer['importer_uid'];
$msg['from-name'] = XML::getFirstValue($xpath, 'dfrn:sender/dfrn:name/text()', $mail);
$msg['from-url'] = XML::getFirstValue($xpath, 'dfrn:sender/dfrn:uri/text()', $mail);
$msg = [];
$msg['uid'] = $importer['importer_uid'];
$msg['from-name'] = XML::getFirstValue($xpath, 'dfrn:sender/dfrn:name/text()', $mail);
$msg['from-url'] = XML::getFirstValue($xpath, 'dfrn:sender/dfrn:uri/text()', $mail);
$msg['from-photo'] = XML::getFirstValue($xpath, 'dfrn:sender/dfrn:avatar/text()', $mail);
$msg['contact-id'] = $importer['id'];
$msg['uri'] = XML::getFirstValue($xpath, 'dfrn:id/text()', $mail);
$msg['uri'] = XML::getFirstValue($xpath, 'dfrn:id/text()', $mail);
$msg['parent-uri'] = XML::getFirstValue($xpath, 'dfrn:in-reply-to/text()', $mail);
$msg['created'] = DateTimeFormat::utc(XML::getFirstValue($xpath, 'dfrn:sentdate/text()', $mail));
$msg['title'] = XML::getFirstValue($xpath, 'dfrn:subject/text()', $mail);
$msg['body'] = XML::getFirstValue($xpath, 'dfrn:content/text()', $mail);
$msg['created'] = DateTimeFormat::utc(XML::getFirstValue($xpath, 'dfrn:sentdate/text()', $mail));
$msg['title'] = XML::getFirstValue($xpath, 'dfrn:subject/text()', $mail);
$msg['body'] = XML::getFirstValue($xpath, 'dfrn:content/text()', $mail);
Mail::insert($msg);
}
@ -1347,8 +1348,8 @@ class DFRN
{
DI::logger()->info('Processing suggestions');
$url = $xpath->evaluate('string(dfrn:url[1]/text())', $suggestion);
$cid = Contact::getIdForURL($url);
$url = $xpath->evaluate('string(dfrn:url[1]/text())', $suggestion);
$cid = Contact::getIdForURL($url);
$note = $xpath->evaluate('string(dfrn:note[1]/text())', $suggestion);
return self::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
@ -1364,8 +1365,8 @@ class DFRN
*/
private static function addSuggestion(int $uid, int $cid, int $from_cid, string $note = ''): bool
{
$owner = User::getOwnerDataById($uid);
$contact = Contact::getById($cid);
$owner = User::getOwnerDataById($uid);
$contact = Contact::getById($cid);
$from_contact = Contact::getById($from_cid);
if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($contact['url']), 'uid' => $uid])) {
@ -1377,15 +1378,15 @@ class DFRN
return false;
}
$suggest = [];
$suggest['uid'] = $uid;
$suggest['cid'] = $from_cid;
$suggest['url'] = $contact['url'];
$suggest['name'] = $contact['name'];
$suggest['photo'] = $contact['photo'];
$suggest = [];
$suggest['uid'] = $uid;
$suggest['cid'] = $from_cid;
$suggest['url'] = $contact['url'];
$suggest['name'] = $contact['name'];
$suggest['photo'] = $contact['photo'];
$suggest['request'] = $contact['request'];
$suggest['title'] = '';
$suggest['body'] = $note;
$suggest['title'] = '';
$suggest['body'] = $note;
DI::intro()->save(DI::introFactory()->createNew(
$suggest['uid'],
@ -1424,20 +1425,20 @@ class DFRN
DI::logger()->info("Processing relocations");
/// @TODO Rewrite this to one statement
$relocate = [];
$relocate['uid'] = $importer['importer_uid'];
$relocate['cid'] = $importer['id'];
$relocate['url'] = $xpath->query('dfrn:url/text()', $relocation)->item(0)->nodeValue;
$relocate['addr'] = $xpath->query('dfrn:addr/text()', $relocation)->item(0)->nodeValue;
$relocate['name'] = $xpath->query('dfrn:name/text()', $relocation)->item(0)->nodeValue;
$relocate['avatar'] = $xpath->query('dfrn:avatar/text()', $relocation)->item(0)->nodeValue;
$relocate['photo'] = $xpath->query('dfrn:photo/text()', $relocation)->item(0)->nodeValue;
$relocate['thumb'] = $xpath->query('dfrn:thumb/text()', $relocation)->item(0)->nodeValue;
$relocate['micro'] = $xpath->query('dfrn:micro/text()', $relocation)->item(0)->nodeValue;
$relocate['request'] = $xpath->query('dfrn:request/text()', $relocation)->item(0)->nodeValue;
$relocate['confirm'] = $xpath->query('dfrn:confirm/text()', $relocation)->item(0)->nodeValue;
$relocate['notify'] = $xpath->query('dfrn:notify/text()', $relocation)->item(0)->nodeValue;
$relocate['poll'] = $xpath->query('dfrn:poll/text()', $relocation)->item(0)->nodeValue;
$relocate = [];
$relocate['uid'] = $importer['importer_uid'];
$relocate['cid'] = $importer['id'];
$relocate['url'] = $xpath->query('dfrn:url/text()', $relocation)->item(0)->nodeValue;
$relocate['addr'] = $xpath->query('dfrn:addr/text()', $relocation)->item(0)->nodeValue;
$relocate['name'] = $xpath->query('dfrn:name/text()', $relocation)->item(0)->nodeValue;
$relocate['avatar'] = $xpath->query('dfrn:avatar/text()', $relocation)->item(0)->nodeValue;
$relocate['photo'] = $xpath->query('dfrn:photo/text()', $relocation)->item(0)->nodeValue;
$relocate['thumb'] = $xpath->query('dfrn:thumb/text()', $relocation)->item(0)->nodeValue;
$relocate['micro'] = $xpath->query('dfrn:micro/text()', $relocation)->item(0)->nodeValue;
$relocate['request'] = $xpath->query('dfrn:request/text()', $relocation)->item(0)->nodeValue;
$relocate['confirm'] = $xpath->query('dfrn:confirm/text()', $relocation)->item(0)->nodeValue;
$relocate['notify'] = $xpath->query('dfrn:notify/text()', $relocation)->item(0)->nodeValue;
$relocate['poll'] = $xpath->query('dfrn:poll/text()', $relocation)->item(0)->nodeValue;
$relocate['sitepubkey'] = $xpath->query('dfrn:sitepubkey/text()', $relocation)->item(0)->nodeValue;
if (($relocate['avatar'] == '') && ($relocate['photo'] != '')) {
@ -1457,15 +1458,15 @@ class DFRN
// Update the contact table. We try to find every entry.
$fields = [
'name' => $relocate['name'],
'avatar' => $relocate['avatar'],
'url' => $relocate['url'],
'nurl' => Strings::normaliseLink($relocate['url']),
'addr' => $relocate['addr'],
'request' => $relocate['request'],
'confirm' => $relocate['confirm'],
'notify' => $relocate['notify'],
'poll' => $relocate['poll'],
'name' => $relocate['name'],
'avatar' => $relocate['avatar'],
'url' => $relocate['url'],
'nurl' => Strings::normaliseLink($relocate['url']),
'addr' => $relocate['addr'],
'request' => $relocate['request'],
'confirm' => $relocate['confirm'],
'notify' => $relocate['notify'],
'poll' => $relocate['poll'],
'site-pubkey' => $relocate['sitepubkey'],
];
$condition = ["(`id` = ?) OR (`nurl` = ?)", $importer['id'], Strings::normaliseLink($old['url'])];
@ -1506,10 +1507,10 @@ class DFRN
}
$fields = [
'title' => $item['title'] ?? '',
'body' => $item['body'] ?? '',
'title' => $item['title'] ?? '',
'body' => $item['body'] ?? '',
'changed' => DateTimeFormat::utcNow(),
'edited' => DateTimeFormat::utc($item['edited']),
'edited' => DateTimeFormat::utc($item['edited']),
];
$condition = ["`uri` = ? AND `uid` IN (0, ?)", $item['uri'], $importer['importer_uid']];
@ -1611,16 +1612,16 @@ class DFRN
}
$condition = ['uid' => $item['uid'], 'author-id' => $item['author-id'], 'gravity' => Item::GRAVITY_ACTIVITY,
'verb' => $item['verb'], 'thr-parent' => $item['thr-parent']];
'verb' => $item['verb'], 'thr-parent' => $item['thr-parent']];
if (Post::exists($condition)) {
return false;
}
// The owner of an activity must be the author
$item['owner-name'] = $item['author-name'];
$item['owner-link'] = $item['author-link'];
$item['owner-name'] = $item['author-name'];
$item['owner-link'] = $item['author-link'];
$item['owner-avatar'] = $item['author-avatar'];
$item['owner-id'] = $item['author-id'];
$item['owner-id'] = $item['author-id'];
}
if (($item['verb'] == Activity::TAG) && ($item['object-type'] == Activity\ObjectType::TAGTERM)) {
@ -1654,19 +1655,24 @@ class DFRN
*/
private static function parseLinks($links, array &$item)
{
$rel = '';
$href = '';
$type = null;
$rel = '';
$href = '';
$type = null;
$length = null;
$title = null;
$title = null;
foreach ($links as $link) {
foreach ($link->attributes as $attributes) {
switch ($attributes->name) {
case 'href' : $href = $attributes->textContent; break;
case 'rel' : $rel = $attributes->textContent; break;
case 'type' : $type = $attributes->textContent; break;
case 'length': $length = $attributes->textContent; break;
case 'title' : $title = $attributes->textContent; break;
case 'href': $href = $attributes->textContent;
break;
case 'rel': $rel = $attributes->textContent;
break;
case 'type': $type = $attributes->textContent;
break;
case 'length': $length = $attributes->textContent;
break;
case 'title': $title = $attributes->textContent;
break;
}
}
if (($rel != '') && ($href != '')) {
@ -1677,7 +1683,7 @@ class DFRN
case 'enclosure':
Post\Media::insert(['uri-id' => $item['uri-id'], 'type' => Post\Media::DOCUMENT,
'url' => $href, 'mimetype' => $type, 'size' => $length, 'description' => $title]);
'url' => $href, 'mimetype' => $type, 'size' => $length, 'description' => $title]);
break;
}
}
@ -1745,7 +1751,8 @@ class DFRN
$item['edited'] = XML::getFirstNodeValue($xpath, 'atom:updated/text()', $entry);
$current = Post::selectFirst(['id', 'uid', 'edited', 'body'],
$current = Post::selectFirst(
['id', 'uid', 'edited', 'body'],
['uri' => $item['uri'], 'uid' => $importer['importer_uid']]
);
// Is there an existing item?
@ -1759,18 +1766,18 @@ class DFRN
$owner_unknown = (isset($owner['contact-unknown']) && $owner['contact-unknown']);
$item['owner-name'] = $owner['name'];
$item['owner-link'] = $owner['link'];
$item['owner-name'] = $owner['name'];
$item['owner-link'] = $owner['link'];
$item['owner-avatar'] = $owner['avatar'];
$item['owner-id'] = Contact::getIdForURL($owner['link'], 0);
$item['owner-id'] = Contact::getIdForURL($owner['link'], 0);
// fetch the author
$author = self::fetchauthor($xpath, $entry, $importer, 'atom:author', true, $xml);
$item['author-name'] = $author['name'];
$item['author-link'] = $author['link'];
$item['author-name'] = $author['name'];
$item['author-link'] = $author['link'];
$item['author-avatar'] = $author['avatar'];
$item['author-id'] = Contact::getIdForURL($author['link'], 0);
$item['author-id'] = Contact::getIdForURL($author['link'], 0);
$item['title'] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
@ -1794,8 +1801,8 @@ class DFRN
// We don't need the content element since "dfrn:env" is always present
//$item['body'] = $xpath->query('atom:content/text()', $entry)->item(0)->nodeValue;
$item['location'] = XML::getFirstNodeValue($xpath, 'dfrn:location/text()', $entry);
$item['coord'] = XML::getFirstNodeValue($xpath, 'georss:point', $entry);
$item['private'] = XML::getFirstNodeValue($xpath, 'dfrn:private/text()', $entry);
$item['coord'] = XML::getFirstNodeValue($xpath, 'georss:point', $entry);
$item['private'] = XML::getFirstNodeValue($xpath, 'dfrn:private/text()', $entry);
$unlisted = XML::getFirstNodeValue($xpath, 'dfrn:unlisted/text()', $entry);
if (!empty($unlisted) && ($item['private'] != Item::PRIVATE)) {
@ -1845,7 +1852,7 @@ class DFRN
$item['object-type'] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
}
$object = $xpath->query('activity:object', $entry)->item(0);
$object = $xpath->query('activity:object', $entry)->item(0);
$item['object'] = self::transformActivity($xpath, $object, 'object');
if (trim($item['object']) != '') {
@ -1855,13 +1862,13 @@ class DFRN
}
}
$target = $xpath->query('activity:target', $entry)->item(0);
$target = $xpath->query('activity:target', $entry)->item(0);
$item['target'] = self::transformActivity($xpath, $target, 'target');
$categories = $xpath->query('atom:category', $entry);
if ($categories) {
foreach ($categories as $category) {
$term = '';
$term = '';
$scheme = '';
foreach ($category->attributes as $attributes) {
if ($attributes->name == 'term') {
@ -1977,7 +1984,7 @@ class DFRN
$ev['source'] = $item['source'];
$condition = ['uri' => $item['uri'], 'uid' => $importer['importer_uid']];
$event = DBA::selectFirst('event', ['id'], $condition);
$event = DBA::selectFirst('event', ['id'], $condition);
if (DBA::isResult($event)) {
$ev['id'] = $event['id'];
}
@ -2054,7 +2061,7 @@ class DFRN
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
$notify = Item::isRemoteSelf($importer, $item);
$notify = Item::isRemoteSelf($importer, $item);
$item['wall'] = (bool)$notify;
$posted_id = Item::insert($item, $notify);
@ -2096,7 +2103,7 @@ class DFRN
}
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
if (!DBA::isResult($item)) {
DI::logger()->info('Item with URI ' . $uri . ' for user ' . $importer['importer_uid'] . ' was not found.');
return;
@ -2163,12 +2170,12 @@ class DFRN
$xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
$xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
$header = [];
$header['uid'] = $importer['importer_uid'];
$header['network'] = Protocol::DFRN;
$header['protocol'] = $protocol;
$header['wall'] = 0;
$header['origin'] = 0;
$header = [];
$header['uid'] = $importer['importer_uid'];
$header['network'] = Protocol::DFRN;
$header['protocol'] = $protocol;
$header['wall'] = 0;
$header['origin'] = 0;
$header['contact-id'] = $importer['id'];
$header = Diaspora::setDirection($header, $direction);
@ -2314,7 +2321,7 @@ class DFRN
}
$existing_edited = DateTimeFormat::utc($existing['edited']);
$update_edited = DateTimeFormat::utc($update['edited']);
$update_edited = DateTimeFormat::utc($update['edited']);
return (strcmp($existing_edited, $update_edited) < 0);
}