"inform" functionality moved / unified functionality
This commit is contained in:
parent
0e5ee88c43
commit
8034a48ffe
72
mod/item.php
72
mod/item.php
|
@ -394,57 +394,37 @@ function item_post(App $a) {
|
||||||
// Personal notes must never be altered to a forum post.
|
// Personal notes must never be altered to a forum post.
|
||||||
if ($posttype != Item::PT_PERSONAL_NOTE) {
|
if ($posttype != Item::PT_PERSONAL_NOTE) {
|
||||||
// Convert mentions in the body to a unified format
|
// Convert mentions in the body to a unified format
|
||||||
$body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network, &$inform) {
|
$body = BBCode::setMentions($body, local_user() ? local_user() : $profile_uid, $network);
|
||||||
$tags = BBCode::getTags($body);
|
|
||||||
|
|
||||||
$tagged = [];
|
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$tag_type = substr($tag, 0, 1);
|
|
||||||
|
|
||||||
if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
|
|
||||||
// Robert Johnson should be first in the $tags array
|
|
||||||
foreach ($tagged as $nextTag) {
|
|
||||||
if (stristr($nextTag, $tag . ' ')) {
|
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemHelper::replaceTag($body, $inform, local_user() ? local_user() : $profile_uid, $tag, $network);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $body;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Search for forum mentions
|
// Search for forum mentions
|
||||||
if (!$toplevel_item_id) {
|
foreach (Tag::getFromBody($body, Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
|
||||||
foreach (Tag::getFromBody($body, Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
|
$contact = Contact::getByURL($tag[2], false, [], $profile_uid);
|
||||||
$contact = Contact::getByURL($tag[2], false, [], $profile_uid);
|
if (!empty($inform)) {
|
||||||
if ($contact['contact-type'] != Contact::TYPE_COMMUNITY) {
|
$inform .= ',';
|
||||||
continue;
|
}
|
||||||
}
|
$inform .= 'cid:' . $contact['id'];
|
||||||
|
|
||||||
if (!empty($contact['prv']) || ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION])) {
|
if (!$toplevel_item_id || ($contact['contact-type'] != Contact::TYPE_COMMUNITY)) {
|
||||||
$private_forum = $contact['prv'];
|
continue;
|
||||||
$only_to_forum = ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]);
|
}
|
||||||
$private_id = $contact['id'];
|
|
||||||
$forum_contact = $contact;
|
if (!empty($contact['prv']) || ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION])) {
|
||||||
Logger::info('Private forum or exclusive mention', ['url' => $tag[2], 'mention' => $tag[1]]);
|
$private_forum = $contact['prv'];
|
||||||
} elseif ($str_contact_allow == '<' . $contact['id'] . '>') {
|
$only_to_forum = ($tag[1] == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]);
|
||||||
$private_forum = false;
|
$private_id = $contact['id'];
|
||||||
$only_to_forum = true;
|
$forum_contact = $contact;
|
||||||
$private_id = $contact['id'];
|
Logger::info('Private forum or exclusive mention', ['url' => $tag[2], 'mention' => $tag[1]]);
|
||||||
$forum_contact = $contact;
|
} elseif ($str_contact_allow == '<' . $contact['id'] . '>') {
|
||||||
Logger::info('Public forum', ['url' => $tag[2], 'mention' => $tag[1]]);
|
$private_forum = false;
|
||||||
} else {
|
$only_to_forum = true;
|
||||||
Logger::info('Post with forum mention will not be converted to a forum post', ['url' => $tag[2], 'mention' => $tag[1]]);
|
$private_id = $contact['id'];
|
||||||
}
|
$forum_contact = $contact;
|
||||||
|
Logger::info('Public forum', ['url' => $tag[2], 'mention' => $tag[1]]);
|
||||||
|
} else {
|
||||||
|
Logger::info('Post with forum mention will not be converted to a forum post', ['url' => $tag[2], 'mention' => $tag[1]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Logger::info('Got inform', ['inform' => $inform]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$original_contact_id = $contact_id;
|
$original_contact_id = $contact_id;
|
||||||
|
|
|
@ -135,7 +135,6 @@ class Item
|
||||||
* the appropriate link.
|
* the appropriate link.
|
||||||
*
|
*
|
||||||
* @param string $body the text to replace the tag in
|
* @param string $body the text to replace the tag in
|
||||||
* @param string $inform a comma-seperated string containing everybody to inform
|
|
||||||
* @param integer $profile_uid the user id to replace the tag for (0 = anyone)
|
* @param integer $profile_uid the user id to replace the tag for (0 = anyone)
|
||||||
* @param string $tag the tag to replace
|
* @param string $tag the tag to replace
|
||||||
* @param string $network The network of the post
|
* @param string $network The network of the post
|
||||||
|
@ -144,7 +143,7 @@ class Item
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function replaceTag(&$body, &$inform, $profile_uid, $tag, $network = '')
|
public static function replaceTag(&$body, $profile_uid, $tag, $network = '')
|
||||||
{
|
{
|
||||||
$replaced = false;
|
$replaced = false;
|
||||||
|
|
||||||
|
@ -218,16 +217,6 @@ class Item
|
||||||
|
|
||||||
// Check if $contact has been successfully loaded
|
// Check if $contact has been successfully loaded
|
||||||
if (DBA::isResult($contact)) {
|
if (DBA::isResult($contact)) {
|
||||||
if (strlen($inform) && (isset($contact['notify']) || isset($contact['id']))) {
|
|
||||||
$inform .= ',';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($contact['id'])) {
|
|
||||||
$inform .= 'cid:' . $contact['id'];
|
|
||||||
} elseif (isset($contact['notify'])) {
|
|
||||||
$inform .= $contact['notify'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile = $contact['url'];
|
$profile = $contact['url'];
|
||||||
$newname = ($contact['name'] ?? '') ?: $contact['nick'];
|
$newname = ($contact['name'] ?? '') ?: $contact['nick'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -2358,11 +2358,10 @@ class BBCode
|
||||||
public static function setMentions($body, $profile_uid = 0, $network = '')
|
public static function setMentions($body, $profile_uid = 0, $network = '')
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
|
$body = self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
|
||||||
$tags = self::getTags($body);
|
$tags = self::getTags($body);
|
||||||
|
|
||||||
$tagged = [];
|
$tagged = [];
|
||||||
$inform = '';
|
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$tag_type = substr($tag, 0, 1);
|
$tag_type = substr($tag, 0, 1);
|
||||||
|
@ -2381,7 +2380,7 @@ class BBCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network)) && $success['replaced']) {
|
if (($success = Item::replaceTag($body, $profile_uid, $tag, $network)) && $success['replaced']) {
|
||||||
$tagged[] = $tag;
|
$tagged[] = $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue