+
+ /**
+ * Collects implicit mentions like:
+ * - the author of the parent item
+ * - all the mentioned conversants in the parent item
+ *
+ * @param array $parent Item array with at least ['id', 'author-link', 'alias']
+ * @return array
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function getImplicitMentionList(array $parent)
+ {
+ $parent_terms = Term::tagArrayFromItemId($parent['id'], [TERM_MENTION]);
+
+ $implicit_mentions = [
+ $parent['author-link']
+ ];
+
+ if ($parent['alias']) {
+ $implicit_mentions[] = $parent['alias'];
+ }
+
+ foreach ($parent_terms as $term) {
+ $contact = Contact::getDetailsByURL($term['url'], 0);
+ if (!empty($contact)) {
+ $implicit_mentions[] = $contact['url'];
+ $implicit_mentions[] = $contact['nurl'];
+ $implicit_mentions[] = $contact['alias'];
+ }
+ }
+
+ return $implicit_mentions;
+ }
+
+ /**
+ * Strips from the body prepended implicit mentions
+ *
+ * @param string $body
+ * @param array $implicit_mentions List of profile URLs
+ * @return string
+ */
+ private static function removeImplicitMentionsFromBody($body, array $implicit_mentions)
+ {
+ if (Config::get('system', 'disable_implicit_mentions')) {
+ return $body;
+ }
+
+ $kept_mentions = [];
+
+ // Extract one prepended mention at a time from the body
+ while(preg_match('#^(@\[url=([^\]]+)].*?\[\/url]\s)(.*)#mis', $body, $matches)) {
+ if (!in_array($matches[2], $implicit_mentions) ) {
+ $kept_mentions[] = $matches[1];
+ }
+
+ $body = $matches[3];
+ }
+
+ // Re-appending the kept mentions to the body after extraction
+ $kept_mentions[] = $body;
+
+ return implode('', $kept_mentions);
+ }