use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Profile;
+use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Network\Probe;
}
if ($item_id) {
- $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
+ $item = Item::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
if (DBA::isResult($item)) {
$old_tag = $item['tag'];
$profile = str_replace(',', '%2c', $profile);
$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
+
+ if (!empty($item['uri-id'])) {
+ Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
+ }
}
} elseif (strpos($tag, '#') === 0) {
$tagname = substr($tag, 1);
$str_tags .= '#[url=' . DI::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
+ if (!empty($item['uri-id'])) {
+ Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
+ }
}
}
}
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
+use Friendica\Model\Tag;
use Friendica\Model\Term;
use Friendica\Util\Strings;
return;
}
- $item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
+ $item = Item::selectFirst(['tag', 'uri-id'], ['id' => $item_id, 'uid' => local_user()]);
if (!DBA::isResult($item)) {
return;
}
$old_tags = explode(',', $item['tag']);
foreach ($tags as $new_tag) {
+ if (preg_match_all('/([#@!])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism', $new_tag, $results, PREG_SET_ORDER)) {
+ foreach ($results as $tag) {
+ Tag::removeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]);
+ }
+ }
+
foreach ($old_tags as $index => $old_tag) {
if (strcmp($old_tag, $new_tag) == 0) {
unset($old_tags[$index]);
}
if (empty($cid)) {
- $fields = ['name' => substr($name, 0, 96)];
+ $fields = ['name' => substr($name, 0, 96), 'url' => ''];
if (!empty($url) && ($url != $name)) {
$fields['url'] = strtolower($url);
self::storeByHash($uriid, $tag[1], $tag[3], $tag[2]);
}
}
+
+ /**
+ * Remove tag/mention
+ *
+ * @param integer $uriid
+ * @param integer $type
+ * @param string $name
+ * @param string $url
+ */
+ public static function remove(int $uriid, int $type, string $name, string $url = '')
+ {
+ $tag = DBA::fetchFirst("SELECT `id` FROM `tag` INNER JOIN `post-tag` ON `post-tag`.`tid` = `tag`.`id`
+ WHERE `uri-id` = ? AND `type` = ? AND `name` = ? AND `url` = ?", $uriid, $type, $name, $url);
+ if (!DBA::isResult($tag)) {
+ return;
+ }
+ Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['id'], 'name' => $name, 'url' => $url]);
+ DBA::delete('post-tag', ['uri-id' => $uriid, 'tid' => $tag['id']]);
+ }
+
+ /**
+ * Remove tag/mention
+ *
+ * @param integer $uriid
+ * @param string $hash
+ * @param string $name
+ * @param string $url
+ */
+ public static function removeByHash(int $uriid, string $hash, string $name, string $url = '')
+ {
+ if ($hash == self::TAG_CHARACTER[self::MENTION]) {
+ $type = self::MENTION;
+ } elseif ($hash == self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]) {
+ $type = self::EXCLUSIVE_MENTION;
+ } elseif ($hash == self::TAG_CHARACTER[self::IMPLICIT_MENTION]) {
+ $type = self::IMPLICIT_MENTION;
+ } elseif ($hash == self::TAG_CHARACTER[self::HASHTAG]) {
+ $type = self::HASHTAG;
+ } else {
+ return;
+ }
+
+ self::remove($uriid, $type, $name, $url);
+ }
}