* @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`
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]);
}
}
}
// Do we already have this item?
- $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+ $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = Item::selectFirst($fields, $condition);
}
if ($stored) {
- $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
+ $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = Item::selectFirst($fields, $condition);
$original_item["created"],
$orig_url
);
+
+ if (!empty($original_item['title'])) {
+ $prefix .= '[h3]' . $original_item['title'] . "[/h3]\n";
+ }
+
$datarray["body"] = $prefix.$original_item["body"]."[/share]";
$datarray["tag"] = $original_item["tag"];
+ $datarray["attach"] = $original_item["attach"];
$datarray["app"] = $original_item["app"];
$datarray["plink"] = self::plink($author, $guid);
{
$body = trim($body);
- // Skip if it isn't a pure repeated messages
- // Does it start with a share?
- if ((strpos($body, "[share") > 0) && $complete) {
- return false;
- }
-
- // Does it end with a share?
- if (strlen($body) > (strrpos($body, "[/share]") + 8)) {
+ $reshared = Item::getShareArray(['body' => $body]);
+ if (empty($reshared)) {
return false;
}
- $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
- // Skip if there is no shared message in there
- if ($body == $attributes) {
+ // Skip if it isn't a pure repeated messages
+ // Does it start with a share?
+ if (!empty($reshared['comment']) && $complete) {
return false;
}
- // If we don't do the complete check we quit here
-
- $guid = "";
- preg_match("/guid='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $guid = $matches[1];
- }
-
- preg_match('/guid="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $guid = $matches[1];
- }
-
- if (($guid != "") && $complete) {
- $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
+ if (!empty($reshared['guid']) && $complete) {
+ $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$item = Item::selectFirst(['contact-id'], $condition);
if (DBA::isResult($item)) {
- $ret= [];
+ $ret = [];
$ret["root_handle"] = self::handleFromContact($item["contact-id"]);
- $ret["root_guid"] = $guid;
+ $ret["root_guid"] = $reshared['guid'];
return $ret;
} elseif ($complete) {
// We are resharing something that isn't a DFRN or Diaspora post.
// So we have to return "false" on "$complete" to not trigger a reshare.
return false;
}
- } elseif (($guid == "") && $complete) {
+ } elseif (empty($reshared['guid']) && $complete) {
return false;
}
- $ret["root_guid"] = $guid;
-
- $profile = "";
- preg_match("/profile='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $profile = $matches[1];
- }
-
- preg_match('/profile="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $profile = $matches[1];
- }
-
- $ret= [];
+ $ret = [];
- if ($profile != "") {
- if (Contact::getIdForURL($profile)) {
- $author = Contact::getDetailsByURL($profile);
- $ret["root_handle"] = $author['addr'];
+ if (!empty($reshared['profile']) && ($cid = Contact::getIdForURL($reshared['profile']))) {
+ $contact = DBA::selectFirst('contact', ['addr'], ['id' => $cid]);
+ if (!empty($contact['addr'])) {
+ $ret['root_handle'] = $contact['addr'];
}
}
$myaddr = self::myHandle($owner);
$public = ($item["private"] ? "false" : "true");
-
- $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
+ $created = DateTimeFormat::utc($item['received'], DateTimeFormat::ATOM);
$edited = DateTimeFormat::utc($item["edited"] ?? $item["created"], DateTimeFormat::ATOM);
// Detect a share element and do a reshare
$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', 'attach_link_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"]) {