4 use Friendica\Core\Addon;
5 use Friendica\Core\System;
6 use Friendica\Core\Worker;
7 use Friendica\Database\DBM;
9 require_once('include/security.php');
10 require_once('include/bbcode.php');
11 require_once('include/items.php');
13 function tagger_content(App $a) {
15 if(! local_user() && ! remote_user()) {
19 $term = notags(trim($_GET['term']));
21 $term = str_replace([',',' '],['','_'],$term);
26 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
28 logger('tagger: tag ' . $term . ' item ' . $item_id);
31 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
35 if(! $item_id || (! DBM::is_result($r))) {
36 logger('tagger: no item ' . $item_id);
42 $owner_uid = $item['uid'];
44 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
47 if (DBM::is_result($r)) {
48 $owner_nick = $r[0]['nickname'];
49 $blocktags = $r[0]['blocktags'];
52 if(local_user() != $owner_uid)
55 $r = q("select * from contact where self = 1 and uid = %d limit 1",
58 if (DBM::is_result($r))
61 logger('tagger: no contact_id');
65 $uri = item_new_uri($a->get_hostname(),$owner_uid);
66 $xterm = xmlify($term);
67 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
68 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
70 $link = xmlify('<link rel="alternate" type="text/html" href="'
71 . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
73 $body = xmlify($item['body']);
77 <type>$targettype</type>
79 <id>{$item['uri']}</id>
82 <content>$body</content>
86 $tagid = System::baseUrl() . '/search?tag=' . $term;
87 $objtype = ACTIVITY_OBJ_TAGTERM;
96 <content>$xterm</content>
100 $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
102 if (! isset($bodyverb)) {
106 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
110 $arr['guid'] = get_guid(32);
112 $arr['uid'] = $owner_uid;
113 $arr['contact-id'] = $contact['id'];
114 $arr['type'] = 'activity';
115 $arr['wall'] = $item['wall'];
116 $arr['gravity'] = GRAVITY_COMMENT;
117 $arr['parent'] = $item['id'];
118 $arr['parent-uri'] = $item['uri'];
119 $arr['owner-name'] = $item['author-name'];
120 $arr['owner-link'] = $item['author-link'];
121 $arr['owner-avatar'] = $item['author-avatar'];
122 $arr['author-name'] = $contact['name'];
123 $arr['author-link'] = $contact['url'];
124 $arr['author-avatar'] = $contact['thumb'];
126 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
127 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
128 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
129 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
131 $arr['verb'] = ACTIVITY_TAG;
132 $arr['target-type'] = $targettype;
133 $arr['target'] = $target;
134 $arr['object-type'] = $objtype;
135 $arr['object'] = $obj;
136 $arr['private'] = $item['private'];
137 $arr['allow_cid'] = $item['allow_cid'];
138 $arr['allow_gid'] = $item['allow_gid'];
139 $arr['deny_cid'] = $item['deny_cid'];
140 $arr['deny_gid'] = $item['deny_gid'];
145 $post_id = item_store($arr);
147 // q("UPDATE `item` set plink = '%s' where id = %d",
148 // dbesc(System::baseUrl() . '/display/' . $owner_nick . '/' . $post_id),
153 if(! $item['visible']) {
154 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
160 $term_objtype = (($item['resource-id']) ? TERM_OBJ_PHOTO : TERM_OBJ_POST );
161 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
165 if((! $blocktags) && $t[0]['tcount']==0 ) {
166 /*q("update item set tag = '%s' where id = %d",
167 dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
171 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
176 dbesc(System::baseUrl() . '/search?tag=' . $term),
181 // if the original post is on this site, update it.
183 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
186 if (DBM::is_result($r)) {
187 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
190 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
194 if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
195 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
200 dbesc(System::baseUrl() . '/search?tag=' . $term),
205 /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
206 q("update item set tag = '%s' where id = %d",
207 dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]'),
215 $arr['id'] = $post_id;
217 Addon::callHooks('post_local_end', $arr);
219 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
223 return; // NOTREACHED