4 use Friendica\Core\System;
5 use Friendica\Core\Worker;
6 use Friendica\Database\DBM;
8 require_once('include/security.php');
9 require_once('include/bbcode.php');
10 require_once('include/items.php');
12 function tagger_content(App $a) {
14 if(! local_user() && ! remote_user()) {
18 $term = notags(trim($_GET['term']));
20 $term = str_replace(array(',',' '),array('','_'),$term);
25 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
27 logger('tagger: tag ' . $term . ' item ' . $item_id);
30 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
34 if(! $item_id || (! DBM::is_result($r))) {
35 logger('tagger: no item ' . $item_id);
41 $owner_uid = $item['uid'];
43 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
46 if (DBM::is_result($r)) {
47 $owner_nick = $r[0]['nickname'];
48 $blocktags = $r[0]['blocktags'];
51 if(local_user() != $owner_uid)
54 $r = q("select * from contact where self = 1 and uid = %d limit 1",
57 if (DBM::is_result($r))
60 logger('tagger: no contact_id');
64 $uri = item_new_uri($a->get_hostname(),$owner_uid);
65 $xterm = xmlify($term);
66 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
67 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
69 $link = xmlify('<link rel="alternate" type="text/html" href="'
70 . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
72 $body = xmlify($item['body']);
76 <type>$targettype</type>
78 <id>{$item['uri']}</id>
81 <content>$body</content>
85 $tagid = System::baseUrl() . '/search?tag=' . $term;
86 $objtype = ACTIVITY_OBJ_TAGTERM;
95 <content>$xterm</content>
99 $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
101 if (! isset($bodyverb)) {
105 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
109 $arr['guid'] = get_guid(32);
111 $arr['uid'] = $owner_uid;
112 $arr['contact-id'] = $contact['id'];
113 $arr['type'] = 'activity';
114 $arr['wall'] = $item['wall'];
115 $arr['gravity'] = GRAVITY_COMMENT;
116 $arr['parent'] = $item['id'];
117 $arr['parent-uri'] = $item['uri'];
118 $arr['owner-name'] = $item['author-name'];
119 $arr['owner-link'] = $item['author-link'];
120 $arr['owner-avatar'] = $item['author-avatar'];
121 $arr['author-name'] = $contact['name'];
122 $arr['author-link'] = $contact['url'];
123 $arr['author-avatar'] = $contact['thumb'];
125 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
126 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
127 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
128 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
130 $arr['verb'] = ACTIVITY_TAG;
131 $arr['target-type'] = $targettype;
132 $arr['target'] = $target;
133 $arr['object-type'] = $objtype;
134 $arr['object'] = $obj;
135 $arr['private'] = $item['private'];
136 $arr['allow_cid'] = $item['allow_cid'];
137 $arr['allow_gid'] = $item['allow_gid'];
138 $arr['deny_cid'] = $item['deny_cid'];
139 $arr['deny_gid'] = $item['deny_gid'];
142 $arr['last-child'] = 1;
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 call_hooks('post_local_end', $arr);
219 Worker::add(PRIORITY_HIGH, "notifier", "tag", $post_id);
223 return; // NOTREACHED