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'];
50 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
53 if (DBM::is_result($r)) {
54 $owner_nick = $r[0]['nickname'];
55 $blocktags = $r[0]['blocktags'];
58 if(local_user() != $owner_uid)
61 $r = q("select * from contact where self = 1 and uid = %d limit 1",
64 if (DBM::is_result($r))
67 logger('tagger: no contact_id');
71 $uri = item_new_uri($a->get_hostname(),$owner_uid);
72 $xterm = xmlify($term);
73 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
74 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
77 $href = System::baseUrl() . '/display/' . $owner_nick . '/' . $item['id'];
79 $href = System::baseUrl() . '/display/' . $item['guid'];
82 $link = xmlify('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n") ;
84 $body = xmlify($item['body']);
88 <type>$targettype</type>
90 <id>{$item['uri']}</id>
93 <content>$body</content>
97 $tagid = System::baseUrl() . '/search?tag=' . $term;
98 $objtype = ACTIVITY_OBJ_TAGTERM;
102 <type>$objtype</type>
106 <title>$xterm</title>
107 <content>$xterm</content>
111 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
113 if (! isset($bodyverb)) {
117 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
121 $arr['guid'] = get_guid(32);
123 $arr['uid'] = $owner_uid;
124 $arr['contact-id'] = $contact['id'];
125 $arr['type'] = 'activity';
126 $arr['wall'] = $item['wall'];
127 $arr['gravity'] = GRAVITY_COMMENT;
128 $arr['parent'] = $item['id'];
129 $arr['parent-uri'] = $item['uri'];
130 $arr['owner-name'] = $item['author-name'];
131 $arr['owner-link'] = $item['author-link'];
132 $arr['owner-avatar'] = $item['author-avatar'];
133 $arr['author-name'] = $contact['name'];
134 $arr['author-link'] = $contact['url'];
135 $arr['author-avatar'] = $contact['thumb'];
137 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
138 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
139 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
140 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
142 $arr['verb'] = ACTIVITY_TAG;
143 $arr['target-type'] = $targettype;
144 $arr['target'] = $target;
145 $arr['object-type'] = $objtype;
146 $arr['object'] = $obj;
147 $arr['private'] = $item['private'];
148 $arr['allow_cid'] = $item['allow_cid'];
149 $arr['allow_gid'] = $item['allow_gid'];
150 $arr['deny_cid'] = $item['deny_cid'];
151 $arr['deny_gid'] = $item['deny_gid'];
156 $post_id = Item::insert($arr);
158 if (!$item['visible']) {
159 Item::update(['visible' => true], ['id' => $item['id']]);
162 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
163 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
167 if((! $blocktags) && $t[0]['tcount']==0 ) {
168 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
173 dbesc(System::baseUrl() . '/search?tag=' . $term),
178 // if the original post is on this site, update it.
180 $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
183 if (DBM::is_result($r)) {
184 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
187 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
191 if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
192 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
197 dbesc(System::baseUrl() . '/search?tag=' . $term),
204 $arr['id'] = $post_id;
206 Addon::callHooks('post_local_end', $arr);
208 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
212 return; // NOTREACHED