- if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
- q("update item set tag = '%s' where id = %d limit 1",
- dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
- intval($r[0]['id'])
+ $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
+ intval($original_item['id']),
+ DBA::escape($term)
+ );
+
+ if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
+ q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
+ intval($original_item['id']),
+ $term_objtype,
+ TERM_HASHTAG,
+ DBA::escape($term),
+ '',
+ intval($owner_uid)