namespace Friendica\Protocol;
+use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Cache;
// Fetch the relay contact
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
- 'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
+ 'contact-type' => Contact::TYPE_RELAY];
$contact = DBA::selectFirst('contact', $fields, $condition);
if (DBA::isResult($contact)) {
$fields = array_merge($fields, $network_fields);
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
- 'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
+ 'contact-type' => Contact::TYPE_RELAY];
if (DBA::exists('contact', $condition)) {
unset($fields['created']);
/**
* @brief Dispatches the different message types to the different functions
*
- * @param array $importer Array of the importer user
- * @param array $msg The post that will be dispatched
- * @param object $fields SimpleXML object that contains the message
+ * @param array $importer Array of the importer user
+ * @param array $msg The post that will be dispatched
+ * @param SimpleXMLElement $fields SimpleXML object that contains the message
*
* @return int The message id of the generated message, "true" or "false" if there was an error
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function dispatch(array $importer, $msg, $fields = null)
+ public static function dispatch(array $importer, $msg, SimpleXMLElement $fields = null)
{
// The sender is the handle of the contact that sent the message.
// This will often be different with relayed messages (for example "like" and "comment")
*
* @param array $msg Array with the XML, the sender handle and the sender signature
*
- * @return bool|array If the posting is valid then an array with an SimpleXML object is returned
+ * @return bool|SimpleXMLElement If the posting is valid then an array with an SimpleXML object is returned
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
if (DBA::isResult($person)) {
- Logger::log("In cache " . print_r($person, true), Logger::DEBUG);
+ Logger::debug("In cache " . print_r($person, true));
// update record occasionally so it doesn't get stale
$d = strtotime($person["updated"]." +00:00");
* @param int $uid The user id
* @param string $handle The handle in the format user@domain.tld
*
- * @return int Contact id
+ * @return array Contact data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
// Logger::log("defining user ".$contact["nick"]." as friend");
//}
- // We don't seem to like that person
- if ($contact["blocked"]) {
+ // Contact server is blocked
+ if (Network::isUrlBlocked($contact['url'])) {
+ return false;
+ // We don't seem to like that person
+ } elseif ($contact["blocked"]) {
// Maybe blocked, don't accept.
return false;
// We are following this person?
Logger::log("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
- if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
+ if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::TYPE_RELAY)) {
Logger::log("queue message");
// queue message for redelivery
Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid);
return $msg;
}
+ private static function prependParentAuthorMention($body, $profile_url)
+ {
+ $profile = Contact::getDetailsByURL($profile_url);
+ if (!empty($profile['addr'])
+ && $profile['contact-type'] != Contact::TYPE_COMMUNITY
+ && !strstr($body, $profile['addr'])
+ && !strstr($body, $profile_url)
+ ) {
+ $body = '@[url=' . $profile_url . ']' . $profile['name'] . '[/url] ' . $body;
+ }
+
+ return $body;
+ }
+
/**
* @brief Sends a post
*
* @param array $item The item that will be exported
* @param array $owner the array of the item owner
*
- * @return array The data for a comment
+ * @return array|false The data for a comment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function constructComment(array $item, array $owner)
return $result;
}
- $parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
- if (!DBA::isResult($parent)) {
+ $toplevel_item = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
+ if (!DBA::isResult($toplevel_item)) {
+ Logger::error('Missing parent conversation item', ['parent' => $item["parent"]]);
return false;
}
- $text = html_entity_decode(BBCode::toMarkdown($item["body"]));
+ $thread_parent_item = $toplevel_item;
+ if ($item['thr-parent'] != $item['parent-uri']) {
+ $thread_parent_item = Item::selectFirst(['guid', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
+ }
+
+ $body = $item["body"];
+
+ if ((empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
+ && !Config::get('system', 'disable_implicit_mentions')
+ ) {
+ $body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']);
+ }
+
+ $text = html_entity_decode(BBCode::toMarkdown($body));
$created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
- $comment = ["author" => self::myHandle($owner),
- "guid" => $item["guid"],
- "created_at" => $created,
- "parent_guid" => $parent["guid"],
- "text" => $text,
- "author_signature" => ""];
+ $comment = [
+ "author" => self::myHandle($owner),
+ "guid" => $item["guid"],
+ "created_at" => $created,
+ "parent_guid" => $toplevel_item["guid"],
+ "text" => $text,
+ "author_signature" => ""
+ ];
// Send the thread parent guid only if it is a threaded comment
if ($item['thr-parent'] != $item['parent-uri']) {
- $comment['thread_parent_guid'] = self::getGuidFromUri($item['thr-parent'], $item['uid']);
+ $comment['thread_parent_guid'] = $thread_parent_item['guid'];
}
Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);
if ($profile['pub_keywords']) {
$kw = str_replace(',', ' ', $profile['pub_keywords']);
$kw = str_replace(' ', ' ', $kw);
- $arr = explode(' ', $profile['pub_keywords']);
+ $arr = explode(' ', $kw);
if (count($arr)) {
for ($x = 0; $x < 5; $x ++) {
if (!empty($arr[$x])) {