6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Core\Worker;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Item;
13 require_once 'include/security.php';
14 require_once 'include/bbcode.php';
15 require_once 'include/items.php';
17 function tagger_content(App $a) {
19 if(! local_user() && ! remote_user()) {
23 $term = notags(trim($_GET['term']));
25 $term = str_replace([',',' '],['','_'],$term);
30 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
32 logger('tagger: tag ' . $term . ' item ' . $item_id);
35 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
39 if(! $item_id || (! DBM::is_result($r))) {
40 logger('tagger: no item ' . $item_id);
46 $owner_uid = $item['uid'];
48 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
51 if (DBM::is_result($r)) {
52 $owner_nick = $r[0]['nickname'];
53 $blocktags = $r[0]['blocktags'];
56 if(local_user() != $owner_uid)
59 $r = q("select * from contact where self = 1 and uid = %d limit 1",
62 if (DBM::is_result($r))
65 logger('tagger: no contact_id');
69 $uri = item_new_uri($a->get_hostname(),$owner_uid);
70 $xterm = xmlify($term);
71 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
72 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
74 $link = xmlify('<link rel="alternate" type="text/html" href="'
75 . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
77 $body = xmlify($item['body']);
81 <type>$targettype</type>
83 <id>{$item['uri']}</id>
86 <content>$body</content>
90 $tagid = System::baseUrl() . '/search?tag=' . $term;
91 $objtype = ACTIVITY_OBJ_TAGTERM;
100 <content>$xterm</content>
104 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
106 if (! isset($bodyverb)) {
110 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
114 $arr['guid'] = get_guid(32);
116 $arr['uid'] = $owner_uid;
117 $arr['contact-id'] = $contact['id'];
118 $arr['type'] = 'activity';
119 $arr['wall'] = $item['wall'];
120 $arr['gravity'] = GRAVITY_COMMENT;
121 $arr['parent'] = $item['id'];
122 $arr['parent-uri'] = $item['uri'];
123 $arr['owner-name'] = $item['author-name'];
124 $arr['owner-link'] = $item['author-link'];
125 $arr['owner-avatar'] = $item['author-avatar'];
126 $arr['author-name'] = $contact['name'];
127 $arr['author-link'] = $contact['url'];
128 $arr['author-avatar'] = $contact['thumb'];
130 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
131 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
132 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
133 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
135 $arr['verb'] = ACTIVITY_TAG;
136 $arr['target-type'] = $targettype;
137 $arr['target'] = $target;
138 $arr['object-type'] = $objtype;
139 $arr['object'] = $obj;
140 $arr['private'] = $item['private'];
141 $arr['allow_cid'] = $item['allow_cid'];
142 $arr['allow_gid'] = $item['allow_gid'];
143 $arr['deny_cid'] = $item['deny_cid'];
144 $arr['deny_gid'] = $item['deny_gid'];
149 $post_id = Item::insert($arr);
151 if (!$item['visible']) {
152 Item::update(['visible' => true], ['id' => $item['id']]);
155 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
156 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
160 if((! $blocktags) && $t[0]['tcount']==0 ) {
161 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
166 dbesc(System::baseUrl() . '/search?tag=' . $term),
171 // if the original post is on this site, update it.
173 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
176 if (DBM::is_result($r)) {
177 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
180 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
184 if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
185 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
190 dbesc(System::baseUrl() . '/search?tag=' . $term),
197 $arr['id'] = $post_id;
199 Addon::callHooks('post_local_end', $arr);
201 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
205 return; // NOTREACHED