From 3fe07cca57146f29ce964a6eeb868909aa9477da Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 19 May 2018 14:55:27 +0000 Subject: [PATCH] Issue 2880: Editing post doesn't destroy mentions or hashtags anymore --- include/text.php | 5 +++++ mod/item.php | 5 +++++ src/Model/Item.php | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index 4c9a8864d5..6830f91e0f 100644 --- a/include/text.php +++ b/include/text.php @@ -14,6 +14,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Model\Contact; use Friendica\Model\Event; use Friendica\Model\Item; use Friendica\Model\Profile; @@ -1965,6 +1966,10 @@ function undo_post_tagging($s) { $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism', $s, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { + if (in_array($mtch[1], ['!', '@'])) { + $contact = Contact::getDetailsByURL($mtch[2]); + $mtch[3] = empty($contact['addr']) ? $mtch[2] : $contact['addr']; + } $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s); } } diff --git a/mod/item.php b/mod/item.php index 1bbc085279..a3ed63cd97 100644 --- a/mod/item.php +++ b/mod/item.php @@ -661,6 +661,11 @@ function item_post(App $a) { $datarray['edit'] = true; } + // Check for hashtags in the body and repair or add hashtag links + if ($preview || $orig_post) { + Item::setHashtags($datarray); + } + // preview mode - prepare the body for display and send it via json if ($preview) { require_once 'include/conversation.php'; diff --git a/src/Model/Item.php b/src/Model/Item.php index 0a480d755b..309ddd858d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1250,7 +1250,7 @@ class Item extends BaseObject } } - private static function setHashtags(&$item) + public static function setHashtags(&$item) { $tags = get_tags($item["body"]);