6 use Friendica\Core\Hook;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\System;
10 use Friendica\Core\Session;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBA;
13 use Friendica\Model\Item;
14 use Friendica\Protocol\Activity;
15 use Friendica\Util\Strings;
16 use Friendica\Util\XML;
17 use Friendica\Worker\Delivery;
19 function tagger_content(App $a) {
21 if (!Session::isAuthenticated()) {
25 $term = Strings::escapeTags(trim($_GET['term']));
27 $term = str_replace([',',' '],['','_'],$term);
33 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
35 Logger::log('tagger: tag ' . $term . ' item ' . $item_id);
38 $item = Item::selectFirst([], ['id' => $item_id]);
40 if (!$item_id || !DBA::isResult($item)) {
41 Logger::log('tagger: no item ' . $item_id);
45 $owner_uid = $item['uid'];
48 $r = q("select `blocktags` from user where uid = %d limit 1",
51 if (DBA::isResult($r)) {
52 $blocktags = $r[0]['blocktags'];
55 if (local_user() != $owner_uid) {
59 $r = q("select * from contact where self = 1 and uid = %d limit 1",
62 if (DBA::isResult($r)) {
65 Logger::log('tagger: no contact_id');
69 $uri = Item::newURI($owner_uid);
70 $xterm = XML::escape($term);
71 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
72 $targettype = (($item['resource-id']) ? Activity::OBJ_IMAGE : Activity::OBJ_NOTE );
73 $href = System::baseUrl() . '/display/' . $item['guid'];
75 $link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
77 $body = XML::escape($item['body']);
81 <type>$targettype</type>
83 <id>{$item['uri']}</id>
86 <content>$body</content>
90 $tagid = System::baseUrl() . '/search?tag=' . $xterm;
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=' . $term . ']'. $term . '[/url]';
114 $arr['guid'] = System::createUUID();
116 $arr['uid'] = $owner_uid;
117 $arr['contact-id'] = $contact['id'];
118 $arr['wall'] = $item['wall'];
119 $arr['gravity'] = GRAVITY_COMMENT;
120 $arr['parent'] = $item['id'];
121 $arr['parent-uri'] = $item['uri'];
122 $arr['owner-name'] = $item['author-name'];
123 $arr['owner-link'] = $item['author-link'];
124 $arr['owner-avatar'] = $item['author-avatar'];
125 $arr['author-name'] = $contact['name'];
126 $arr['author-link'] = $contact['url'];
127 $arr['author-avatar'] = $contact['thumb'];
129 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
130 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
131 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
132 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
134 $arr['verb'] = Activity::TAG;
135 $arr['target-type'] = $targettype;
136 $arr['target'] = $target;
137 $arr['object-type'] = $objtype;
138 $arr['object'] = $obj;
139 $arr['private'] = $item['private'];
140 $arr['allow_cid'] = $item['allow_cid'];
141 $arr['allow_gid'] = $item['allow_gid'];
142 $arr['deny_cid'] = $item['deny_cid'];
143 $arr['deny_gid'] = $item['deny_gid'];
148 $post_id = Item::insert($arr);
150 if (!$item['visible']) {
151 Item::update(['visible' => true], ['id' => $item['id']]);
154 $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'",
161 if (!$blocktags && $t[0]['tcount'] == 0) {
162 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
172 // if the original post is on this site, update it.
173 $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
174 if (DBA::isResult($original_item)) {
175 $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
176 intval($original_item['uid'])
178 $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
179 intval($original_item['id']),
183 if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
184 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
185 intval($original_item['id']),
196 $arr['id'] = $post_id;
198 Hook::callAll('post_local_end', $arr);
200 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id);