- foreach ($tags as $tag=>$link)
- $r = q("INSERT INTO `tag` (`iid`, `tag`, `link`, `created`, `edited`, `commented`, `received`, `changed`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
- intval($itemid), dbesc($tag), dbesc($link), dbesc($message["created"]),
- dbesc($message["edited"]), dbesc($message["commented"]), dbesc($message["received"]), dbesc($message["changed"]));
+ foreach ($tags as $tag=>$link) {
+
+ if (substr(trim($tag), 0, 1) == "#") {
+ $type = TERM_HASHTAG;
+ $term = substr($tag, 1);
+ } elseif (substr(trim($tag), 0, 1) == "@") {
+ $type = TERM_MENTION;
+ $term = substr($tag, 1);
+ } else { // This shouldn't happen
+ $type = TERM_HASHTAG;
+ $term = $tag;
+ }
+
+ $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`) VALUES (%d, %d, %d, %d, '%s', '%s')",
+ intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval($type), dbesc($term), dbesc($link));
+
+ // Search for mentions
+ if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
+ $users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link);
+ foreach ($users AS $user) {
+ if ($user["uid"] == $message["uid"])
+ q("UPDATE `item` SET `mention` = 1 WHERE `id` = %d", intval($itemid));
+ }
+ }
+ }