use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\Probe;
+use Friendica\Protocol\ActivityNamespace;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
* @return array with the contact
* @throws \Exception
*/
- private static function getRelayContact(string $server_url, array $fields = ['batch', 'id', 'name', 'network', 'protocol', 'archive', 'blocked'])
+ private static function getRelayContact(string $server_url, array $fields = ['batch', 'id', 'url', 'name', 'network', 'protocol', 'archive', 'blocked'])
{
// Fetch the relay contact
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
*/
public static function participantsForThread($thread, array $contacts)
{
- $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
+ $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`,
`fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
/**
* @brief: Decodes incoming Diaspora message in the new format
*
- * @param array $importer Array of the importer user
* @param string $raw raw post message
+ * @param string $privKey The private key of the importer
* @param boolean $no_exit Don't do an http exit on error
*
* @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function decodeRaw(array $importer, $raw, $no_exit = false)
+ public static function decodeRaw(string $raw, string $privKey = '', bool $no_exit = false)
{
$data = json_decode($raw);
$ciphertext = base64_decode($data->encrypted_magic_envelope);
$outer_key_bundle = '';
- @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['prvkey']);
+ @openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
$j_outer_key_bundle = json_decode($outer_key_bundle);
if (!is_object($j_outer_key_bundle)) {
}
}
- $base = $basedom->children(NAMESPACE_SALMON_ME);
+ $base = $basedom->children(ActivityNamespace::SALMON_ME);
// Not sure if this cleaning is needed
$data = str_replace([" ", "\t", "\r", "\n"], ["", "", "", ""], $base->data);
/**
* @brief: Decodes incoming Diaspora message in the deprecated format
*
- * @param array $importer Array of the importer user
* @param string $xml urldecoded Diaspora salmon
+ * @param string $privKey The private key of the importer
*
* @return array
* 'message' -> decoded Diaspora XML message
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function decode(array $importer, $xml)
+ public static function decode(string $xml, string $privKey = '')
{
$public = false;
$basedom = XML::parseString($xml);
$author_link = str_replace('acct:', '', $children->header->author_id);
} else {
// This happens with posts from a relais
- if (!$importer) {
+ if (empty($privKey)) {
Logger::log("This is no private post in the old format", Logger::DEBUG);
return false;
}
$ciphertext = base64_decode($encrypted_header->ciphertext);
$outer_key_bundle = '';
- openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['prvkey']);
+ openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $privKey);
$j_outer_key_bundle = json_decode($outer_key_bundle);
$author_link = str_replace('acct:', '', $idom->author_id);
}
- $dom = $basedom->children(NAMESPACE_SALMON_ME);
+ $dom = $basedom->children(ActivityNamespace::SALMON_ME);
// figure out where in the DOM tree our data is hiding
}
if (self::isRedmatrix($contact["url"])) {
- return $contact["url"] . "/?f=&mid=" . $guid;
+ return $contact["url"] . "/?mid=" . $guid;
}
if ($parent_guid != '') {
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_COMMENT;
if ($thr_uri != "") {
$datarray["parent-uri"] = $parent_item["uri"];
}
- $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
+ $datarray["object-type"] = Activity\ObjectType::COMMENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
// We would accept this anyhow.
if ($positive == "true") {
- $verb = ACTIVITY_LIKE;
+ $verb = Activity::LIKE;
} else {
- $verb = ACTIVITY_DISLIKE;
+ $verb = Activity::DISLIKE;
}
$datarray = [];
$datarray["gravity"] = GRAVITY_ACTIVITY;
$datarray["parent-uri"] = $parent_item["uri"];
- $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+ $datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["body"] = $verb;
return false;
}
- $batch = (($ret["batch"]) ? $ret["batch"] : implode("/", array_slice(explode("/", $ret["url"]), 0, 3))."/receive/public");
-
- q(
- "INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
- VALUES (%d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d)",
- intval($importer["uid"]),
- DBA::escape($ret["network"]),
- DBA::escape($ret["addr"]),
- DateTimeFormat::utcNow(),
- DBA::escape($ret["url"]),
- DBA::escape(Strings::normaliseLink($ret["url"])),
- DBA::escape($batch),
- DBA::escape($ret["name"]),
- DBA::escape($ret["nick"]),
- DBA::escape($ret["photo"]),
- DBA::escape($ret["pubkey"]),
- DBA::escape($ret["notify"]),
- DBA::escape($ret["poll"]),
- 1,
- 2
- );
-
- // find the contact record we just created
-
- $contact_record = self::contactByHandle($importer["uid"], $author);
-
- if (!$contact_record) {
- Logger::log("unable to locate newly created contact record.");
- return;
- }
-
- Logger::log("Author ".$author." was added as contact number ".$contact_record["id"].".", Logger::DEBUG);
-
- Group::addMember(User::getDefaultGroup($importer['uid'], $ret["network"]), $contact_record['id']);
-
- Contact::updateAvatar($ret["photo"], $importer['uid'], $contact_record["id"], true);
-
- if (in_array($importer["page-flags"], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) {
- Logger::log("Sending intra message for author ".$author.".", Logger::DEBUG);
-
- $hash = Strings::getRandomHex().(string)time(); // Generate a confirm_key
-
- q(
- "INSERT INTO `intro` (`uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
- VALUES (%d, %d, %d, %d, '%s', '%s', '%s')",
- intval($importer["uid"]),
- intval($contact_record["id"]),
- 0,
- 0,
- DBA::escape(L10n::t("Sharing notification from Diaspora network")),
- DBA::escape($hash),
- DBA::escape(DateTimeFormat::utcNow())
- );
+ $cid = Contact::getIdForURL($ret['url'], $importer['uid']);
+ if (!empty($cid)) {
+ $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]);
} else {
- // automatic friend approval
-
- Logger::log("Does an automatic friend approval for author ".$author.".", Logger::DEBUG);
+ $contact = [];
+ }
- Contact::updateAvatar($contact_record["photo"], $importer["uid"], $contact_record["id"]);
+ $item = ['author-id' => Contact::getIdForURL($ret['url']),
+ 'author-link' => $ret['url']];
- /*
- * technically they are sharing with us (Contact::SHARING),
- * but if our page-type is Profile::PAGE_COMMUNITY or Profile::PAGE_SOAPBOX
- * we are going to change the relationship and make them a follower.
- */
- if (($importer["page-flags"] == User::PAGE_FLAGS_FREELOVE) && $sharing && $following) {
- $new_relation = Contact::FRIEND;
- } elseif (($importer["page-flags"] == User::PAGE_FLAGS_FREELOVE) && $sharing) {
- $new_relation = Contact::SHARING;
- } else {
- $new_relation = Contact::FOLLOWER;
+ $result = Contact::addRelationship($importer, $contact, $item, false);
+ if ($result === true) {
+ $contact_record = self::contactByHandle($importer['uid'], $author);
+ if (!$contact_record) {
+ Logger::info('unable to locate newly created contact record.');
+ return;
}
- q(
- "UPDATE `contact` SET `rel` = %d,
- `name-date` = '%s',
- `uri-date` = '%s',
- `blocked` = 0,
- `pending` = 0,
- `writable` = 1
- WHERE `id` = %d
- ",
- intval($new_relation),
- DBA::escape(DateTimeFormat::utcNow()),
- DBA::escape(DateTimeFormat::utcNow()),
- intval($contact_record["id"])
- );
-
- $user = DBA::selectFirst('user', [], ['uid' => $importer["uid"]]);
+ $user = DBA::selectFirst('user', [], ['uid' => $importer['uid']]);
if (DBA::isResult($user)) {
- Logger::log("Sending share message (Relation: ".$new_relation.") to author ".$author." - Contact: ".$contact_record["id"]." - User: ".$importer["uid"], Logger::DEBUG);
self::sendShare($user, $contact_record);
// Send the profile data, maybe it weren't transmitted before
- self::sendProfile($importer["uid"], [$contact_record]);
+ self::sendProfile($importer['uid'], [$contact_record]);
}
}
$datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
$datarray['parent-uri'] = $parent['uri'];
- $datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
+ $datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
$datarray['gravity'] = GRAVITY_ACTIVITY;
- $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
+ $datarray['object-type'] = Activity\ObjectType::NOTE;
$datarray['protocol'] = $item['protocol'];
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
}
- $datarray["object-type"] = ACTIVITY_OBJ_IMAGE;
+ $datarray["object-type"] = Activity\ObjectType::IMAGE;
} else {
- $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
+ $datarray["object-type"] = Activity\ObjectType::NOTE;
// Add OEmbed and other information to the body
if (!self::isRedmatrix($contact["url"])) {
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
- $datarray["verb"] = ACTIVITY_POST;
+ $datarray["verb"] = Activity::POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$title = $item["title"];
$body = $item["body"];
+ // Fetch the title from an attached link - if there is one
+ if (empty($item["title"]) && PConfig::get($owner['uid'], 'system', 'append_title')) {
+ $page_data = BBCode::getAttachmentData($item['body']);
+ if (!empty($page_data['type']) && !empty($page_data['title']) && ($page_data['type'] == 'link')) {
+ $title = $page_data['title'];
+ }
+ }
+
if ($item['author-link'] != $item['owner-link']) {
require_once 'mod/share.php';
$body = share_header($item['author-name'], $item['author-link'], $item['author-avatar'],
// Adding the title
if (strlen($title)) {
- $body = "## ".html_entity_decode($title)."\n\n".$body;
+ $body = "### ".html_entity_decode($title)."\n\n".$body;
}
if ($item["attach"]) {
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
$positive = null;
- if ($item['verb'] === ACTIVITY_LIKE) {
+ if ($item['verb'] === Activity::LIKE) {
$positive = "true";
- } elseif ($item['verb'] === ACTIVITY_DISLIKE) {
+ } elseif ($item['verb'] === Activity::DISLIKE) {
$positive = "false";
}
}
switch ($item['verb']) {
- case ACTIVITY_ATTEND:
+ case Activity::ATTEND:
$attend_answer = 'accepted';
break;
- case ACTIVITY_ATTENDNO:
+ case Activity::ATTENDNO:
$attend_answer = 'declined';
break;
- case ACTIVITY_ATTENDMAYBE:
+ case Activity::ATTENDMAYBE:
$attend_answer = 'tentative';
break;
default:
*/
public static function sendFollowup(array $item, array $owner, array $contact, $public_batch = false)
{
- if (in_array($item['verb'], [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE])) {
+ if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
$message = self::constructAttend($item, $owner);
$type = "event_participation";
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$message = self::constructLike($item, $owner);
$type = "like";
- } elseif (!in_array($item["verb"], [ACTIVITY_FOLLOW, ACTIVITY_TAG])) {
+ } elseif (!in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
$message = self::constructComment($item, $owner);
$type = "comment";
}
$message = ["author" => $item['signer'],
"target_guid" => $signed_parts[0],
"target_type" => $signed_parts[1]];
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$message = ["author" => $signed_parts[4],
"guid" => $signed_parts[1],
"parent_guid" => $signed_parts[3],
{
if ($item["deleted"]) {
return self::sendRetraction($item, $owner, $contact, $public_batch, true);
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$type = "like";
} else {
$type = "comment";
if ($item['id'] == $item['parent']) {
$target_type = "Post";
- } elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
$target_type = "Like";
} else {
$target_type = "Comment";
return false;
}
- if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+ if (!in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
return false;
}