namespace Friendica\Protocol;
use Friendica\Content\Feature;
-use Friendica\Content\PageInfo;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Cache\Duration;
* 'key' => The public key of the author
* @throws \Exception
*/
- private static function message($guid, $server, $level = 0)
+ public static function message($guid, $server, $level = 0)
{
if ($level > 5) {
return false;
Logger::log("Fetch post from ".$source_url, Logger::DEBUG);
- $envelope = DI::httpRequest()->fetch($source_url);
+ $envelope = DI::httpClient()->fetch($source_url);
if ($envelope) {
Logger::log("Envelope was fetched.", Logger::DEBUG);
$x = self::verifyMagicEnvelope($envelope);
$item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]);
- // Add OEmbed and other information to the body
- $item["body"] = PageInfo::searchAndAppendToBody($item["body"], false, true);
-
return $item;
} else {
return $item;
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
- Post\Media::copy($original_item['uri-id'], $datarray['uri-id']);
$datarray["app"] = $original_item["app"];
$datarray["plink"] = self::plink($author, $guid);
if ($data->photo) {
foreach ($data->photo as $photo) {
self::storePhotoAsMedia($datarray['uri-id'], $photo);
- $body = "[img]".XML::unescape($photo->remote_photo_path).
- XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
}
$datarray["object-type"] = Activity\ObjectType::IMAGE;
} else {
$datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["post-type"] = Item::PT_NOTE;
-
- // Add OEmbed and other information to the body
- if (!self::isHubzilla($contact["url"])) {
- $body = PageInfo::searchAndAppendToBody($body, false, true);
- }
}
/// @todo enable support for polls
return false;
}
- $aes_key = openssl_random_pseudo_bytes(32);
+ $aes_key = random_bytes(32);
$b_aes_key = base64_encode($aes_key);
- $iv = openssl_random_pseudo_bytes(16);
+ $iv = random_bytes(16);
$b_iv = base64_encode($iv);
$ciphertext = self::aesEncrypt($aes_key, $iv, $msg);
if (!intval(DI::config()->get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
- $postResult = DI::httpRequest()->post($dest_url . "/", $envelope, ["Content-Type: " . $content_type]);
+ $postResult = DI::httpClient()->post($dest_url . "/", $envelope, ['Content-Type' => $content_type]);
$return_code = $postResult->getReturnCode();
} else {
Logger::log("test_mode");
{
$msg = self::buildPostXml($type, $message);
- Logger::log('message: '.$msg, Logger::DATA);
- Logger::log('send guid '.$guid, Logger::DEBUG);
-
// Fallback if the private key wasn't transmitted in the expected field
if (empty($owner['uprvkey'])) {
$owner['uprvkey'] = $owner['prvkey'];
if (!empty($fcontact)) {
$pubkey = $fcontact['pubkey'];
}
+ } else {
+ // The "addr" field should always be filled.
+ // If this isn't the case, it will raise a notice some lines later.
+ // And in the log we will see where it came from and we can handle it there.
+ Logger::notice('Empty addr', ['contact' => $contact ?? [], 'callstack' => System::callstack(20)]);
}
$envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey, $public_batch);
$return_code = self::transmit($owner, $contact, $envelope, $public_batch, $guid);
- Logger::log("guid: ".$guid." result ".$return_code, Logger::DEBUG);
+ Logger::info('Transmitted message', ['owner' => $owner['uid'], 'target' => $contact['addr'], 'type' => $type, 'guid' => $guid, 'result' => $return_code]);
return $return_code;
}
return;
}
- $owner = User::getOwnerDataById($item['uid']);
+ // Fetch some user id to have a valid handle to transmit the participation.
+ // In fact it doesn't matter which user sends this - but it is needed by the protocol.
+ // If the item belongs to a user, we take this user id.
+ if ($item['uid'] == 0) {
+ // @todo Possibly use an administrator account?
+ $condition = ['verified' => true, 'blocked' => false,
+ 'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON];
+ $first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]);
+ $owner = User::getOwnerDataById($first_user['uid']);
+ } else {
+ $owner = User::getOwnerDataById($item['uid']);
+ }
+
$author = self::myHandle($owner);
$message = ["author" => $author,
$type = "reshare";
} else {
$title = $item["title"];
- $body = $item["body"];
+ $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
// Fetch the title from an attached link - if there is one
if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
$thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
}
- $body = $item["body"];
+ $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
// The replied to autor mention is prepended for clarity if:
// - Item replied isn't yours
$dob = '';
if ($profile['dob'] && ($profile['dob'] > '0000-00-00')) {
- list($year, $month, $day) = sscanf($profile['dob'], '%4d-%2d-%2d');
+ [$year, $month, $day] = sscanf($profile['dob'], '%4d-%2d-%2d');
if ($year < 1004) {
$year = 1004;
}
}
if (!$recips) {
- $recips = q(
- "SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
- AND `uid` = %d AND `rel` != %d",
- DBA::escape(Protocol::DIASPORA),
- intval($uid),
- intval(Contact::SHARING)
- );
+ $recips = DBA::selectToArray('contact', [], ['network' => Protocol::DIASPORA, 'uid' => $uid, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
}
if (!$recips) {
/**
* Creates the signature for Comments that are created on our system
*
- * @param integer $uid The user of that comment
* @param array $item Item array
*
* @return array Signed content
* @throws \Exception
*/
- public static function createCommentSignature($uid, array $item)
+ public static function createCommentSignature(array $item)
{
+ if (!empty($item['author-link'])) {
+ $url = $item['author-link'];
+ } else {
+ $contact = Contact::getById($item['author-id'], ['url']);
+ if (empty($contact['url'])) {
+ Logger::warning('Author Contact not found', ['author-id' => $item['author-id']]);
+ return false;
+ }
+ $url = $contact['url'];
+ }
+
+ $uid = User::getIdForURL($url);
+ if (empty($uid)) {
+ Logger::info('No owner post, so not storing signature', ['url' => $contact['url']]);
+ return false;
+ }
+
$owner = User::getOwnerDataById($uid);
if (empty($owner)) {
Logger::info('No owner post, so not storing signature');
return false;
}
- $parent = Post::selectFirst(['parent-uri'], ['uri' => $item['thr-parent']]);
- if (!DBA::isResult($parent)) {
- return;
+ // This is only needed for the automated tests
+ if (empty($owner['uprvkey'])) {
+ return false;
}
- $item['parent-uri'] = $parent['parent-uri'];
-
$message = self::constructComment($item, $owner);
if ($message === false) {
return false;