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\Util\Strings;
15 use Friendica\Util\XML;
16 use Friendica\Worker\Delivery;
18 function tagger_content(App $a) {
20 if (!Session::isAuthenticated()) {
24 $term = Strings::escapeTags(trim($_GET['term']));
26 $term = str_replace([',',' '],['','_'],$term);
32 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
34 Logger::log('tagger: tag ' . $term . ' item ' . $item_id);
37 $item = Item::selectFirst([], ['id' => $item_id]);
39 if (!$item_id || !DBA::isResult($item)) {
40 Logger::log('tagger: no item ' . $item_id);
44 $owner_uid = $item['uid'];
47 $r = q("select `blocktags` from user where uid = %d limit 1",
50 if (DBA::isResult($r)) {
51 $blocktags = $r[0]['blocktags'];
54 if (local_user() != $owner_uid) {
58 $r = q("select * from contact where self = 1 and uid = %d limit 1",
61 if (DBA::isResult($r)) {
64 Logger::log('tagger: no contact_id');
68 $uri = Item::newURI($owner_uid);
69 $xterm = XML::escape($term);
70 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
71 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
72 $href = System::baseUrl() . '/display/' . $item['guid'];
74 $link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
76 $body = XML::escape($item['body']);
80 <type>$targettype</type>
82 <id>{$item['uri']}</id>
85 <content>$body</content>
89 $tagid = System::baseUrl() . '/search?tag=' . $xterm;
90 $objtype = ACTIVITY_OBJ_TAGTERM;
99 <content>$xterm</content>
103 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
105 if (!isset($bodyverb)) {
109 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
113 $arr['guid'] = System::createUUID();
115 $arr['uid'] = $owner_uid;
116 $arr['contact-id'] = $contact['id'];
117 $arr['wall'] = $item['wall'];
118 $arr['gravity'] = GRAVITY_COMMENT;
119 $arr['parent'] = $item['id'];
120 $arr['parent-uri'] = $item['uri'];
121 $arr['owner-name'] = $item['author-name'];
122 $arr['owner-link'] = $item['author-link'];
123 $arr['owner-avatar'] = $item['author-avatar'];
124 $arr['author-name'] = $contact['name'];
125 $arr['author-link'] = $contact['url'];
126 $arr['author-avatar'] = $contact['thumb'];
128 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
129 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
130 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
131 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
133 $arr['verb'] = ACTIVITY_TAG;
134 $arr['target-type'] = $targettype;
135 $arr['target'] = $target;
136 $arr['object-type'] = $objtype;
137 $arr['object'] = $obj;
138 $arr['private'] = $item['private'];
139 $arr['allow_cid'] = $item['allow_cid'];
140 $arr['allow_gid'] = $item['allow_gid'];
141 $arr['deny_cid'] = $item['deny_cid'];
142 $arr['deny_gid'] = $item['deny_gid'];
147 $post_id = Item::insert($arr);
149 if (!$item['visible']) {
150 Item::update(['visible' => true], ['id' => $item['id']]);
153 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
155 $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)",
171 // if the original post is on this site, update it.
172 $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
173 if (DBA::isResult($original_item)) {
174 $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
175 intval($original_item['uid'])
177 $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
178 intval($original_item['id']),
182 if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
183 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
184 intval($original_item['id']),
195 $arr['id'] = $post_id;
197 Hook::callAll('post_local_end', $arr);
199 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id);