use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
-use Friendica\Util\Network;
use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\XML;
+use GuzzleHttp\Psr7\Uri;
/**
* This class contain functions to create and send DFRN XML files
$root->setAttribute('xmlns:ostatus', ActivityNamespace::OSTATUS);
$root->setAttribute('xmlns:statusnet', ActivityNamespace::STATUSNET);
- //$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
-
foreach ($items as $item) {
$entry = self::entry($doc, $type, $item, $owner, true, 0);
if (isset($entry)) {
}
// Add conversation data. This is used for OStatus
- $conversation_href = DI::baseUrl()."/display/".$item["parent-guid"];
- $conversation_uri = $conversation_href;
-
- if (isset($parent_item)) {
- $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $item['thr-parent']]);
- if (DBA::isResult($conversation)) {
- if ($conversation['conversation-uri'] != '') {
- $conversation_uri = $conversation['conversation-uri'];
- }
- if ($conversation['conversation-href'] != '') {
- $conversation_href = $conversation['conversation-href'];
- }
- }
- }
-
$attributes = [
- 'href' => $conversation_href,
- 'ref' => $conversation_uri,
+ 'href' => $item['conversation'],
+ 'ref' => $item['conversation'],
];
- XML::addElement($doc, $entry, 'ostatus:conversation', $conversation_uri, $attributes);
+ XML::addElement($doc, $entry, 'ostatus:conversation', $item['conversation'], $attributes);
XML::addElement($doc, $entry, 'id', $item['uri']);
XML::addElement($doc, $entry, 'title', $item['title']);
Logger::notice('Unable to find contact details for ' . $contact['id'] . ' - ' . $contact['addr']);
return -22;
}
- $pubkey = $fcontact['pubkey'];
+ $pubkey = $fcontact['pubkey'] ?? '';
} else {
$pubkey = '';
}
$path_parts = explode('/', $parts['path']);
array_pop($path_parts);
$parts['path'] = implode('/', $path_parts);
- $contact['batch'] = Network::unparseURL($parts);
+ $contact['batch'] = (string)Uri::fromParts($parts);
}
$dest_url = ($public_batch ? $contact['batch'] : $contact['notify']);
}
}
- /**
- * Send a "poke"
- *
- * @param array $item The new item record
- * @param array $importer Record of the importer user mixed with contact of the content
- * @return void
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @todo set proper type-hints (array?)
- */
- private static function doPoke(array $item, array $importer)
- {
- $verb = urldecode(substr($item['verb'], strpos($item['verb'], '#')+1));
- if (!$verb) {
- return;
- }
- $xo = XML::parseString($item['object']);
-
- if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
- // somebody was poked/prodded. Was it me?
- $Blink = '';
- foreach ($xo->link as $l) {
- $atts = $l->attributes();
- switch ($atts['rel']) {
- case 'alternate':
- $Blink = $atts['href'];
- break;
-
- default:
- break;
- }
- }
-
- if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . '/profile/' . $importer['nickname'])) {
- $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
-
- $parent = Post::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer['importer_uid']]);
- $item['parent'] = $parent['id'];
-
- // send a notification
- DI::notify()->createFromArray(
- [
- 'type' => Notification\Type::POKE,
- 'otype' => Notification\ObjectType::PERSON,
- 'activity' => $verb,
- 'verb' => $item['verb'],
- 'uid' => $importer['importer_uid'],
- 'cid' => $author['id'],
- 'item' => $item,
- 'link' => DI::baseUrl() . '/display/' . urlencode($item['guid']),
- ]
- );
- }
- }
- }
-
/**
* Processes several actions, depending on the verb
*
*/
private static function processVerbs(int $entrytype, array $importer, array &$item, bool &$is_like)
{
- Logger::info("Process verb " . $item['verb'] . " and object-type " . $item['object-type'] . " for entrytype " . $entrytype);
+ Logger::info('Process verb ' . $item['verb'] . ' and object-type ' . $item['object-type'] . ' for entrytype ' . $entrytype);
if (($entrytype == DFRN::TOP_LEVEL) && !empty($importer['id'])) {
// The filling of the the "contact" variable is done for legcy reasons
$item = $header;
- $item['protocol'] = $protocol;
-
$item['source'] = $xml;
// Get the uri
self::parseLinks($links, $item);
}
- $item['conversation-uri'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
+ $item['conversation'] = XML::getFirstNodeValue($xpath, 'ostatus:conversation/text()', $entry);
$conv = $xpath->query('ostatus:conversation', $entry);
if (is_object($conv->item(0))) {
foreach ($conv->item(0)->attributes as $attributes) {
if ($attributes->name == 'ref') {
- $item['conversation-uri'] = $attributes->textContent;
+ $item['conversation'] = $attributes->textContent;
}
if ($attributes->name == 'href') {
- $item['conversation-href'] = $attributes->textContent;
+ $item['conversation'] = $attributes->textContent;
}
}
}
if ($item['uid'] == 0) {
Item::distribute($posted_id);
}
-
- if (stristr($item['verb'], Activity::POKE)) {
- $item['id'] = $posted_id;
- self::doPoke($item, $importer);
- }
}
}
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
if (!DBA::isResult($item)) {
- Logger::info("Item with uri " . $uri . " for user " . $importer['importer_uid'] . " wasn't found.");
+ Logger::info('Item with URI ' . $uri . ' for user ' . $importer['importer_uid'] . ' was not found.');
return;
}
if (DBA::exists('post-category', ['uri-id' => $item['uri-id'], 'uid' => $importer['importer_uid'], 'type' => Post\Category::FILE])) {
- Logger::notice("Item is filed. It won't be deleted.", ['uri' => $uri, 'uri-id' => $item['uri_id'], 'uid' => $importer['importer_uid']]);
+ Logger::notice('Item is filed. It will not be deleted.', ['uri' => $uri, 'uri-id' => $item['uri_id'], 'uid' => $importer['importer_uid']]);
return;
}
// When it is a starting post it has to belong to the person that wants to delete it
if (($item['gravity'] == GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
- Logger::info("Item with uri " . $uri . " don't belong to contact " . $importer['id'] . " - ignoring deletion.");
+ Logger::info('Item with URI ' . $uri . ' do not belong to contact ' . $importer['id'] . ' - ignoring deletion.');
return;
}
if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
$condition = ['id' => $item['parent'], 'contact-id' => $importer['id']];
if (!Post::exists($condition)) {
- Logger::info("Item with uri " . $uri . " wasn't found or mustn't be deleted by contact " . $importer['id'] . " - ignoring deletion.");
+ Logger::info('Item with URI ' . $uri . ' was not found or must not be deleted by contact ' . $importer['id'] . ' - ignoring deletion.');
return;
}
}
$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['direction'] = $direction;
+
+ $header = Diaspora::setDirection($header, $direction);
if ($direction === Conversation::RELAY) {
$header['post-reason'] = Item::PR_RELAY;