6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Core\Worker;
10 use Friendica\Database\DBA;
11 use Friendica\Model\Item;
13 require_once 'include/items.php';
15 function tagger_content(App $a) {
17 if (!local_user() && !remote_user()) {
21 $term = notags(trim($_GET['term']));
23 $term = str_replace([',',' '],['','_'],$term);
29 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
31 logger('tagger: tag ' . $term . ' item ' . $item_id);
34 $item = Item::selectFirst([], ['id' => $item_id]);
36 if (!$item_id || !DBA::isResult($item)) {
37 logger('tagger: no item ' . $item_id);
41 $owner_uid = $item['uid'];
45 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
48 if (DBA::isResult($r)) {
49 $owner_nick = $r[0]['nickname'];
50 $blocktags = $r[0]['blocktags'];
53 if (local_user() != $owner_uid) {
57 $r = q("select * from contact where self = 1 and uid = %d limit 1",
60 if (DBA::isResult($r)) {
63 logger('tagger: no contact_id');
67 $uri = Item::newURI($owner_uid);
68 $xterm = xmlify($term);
69 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
70 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
73 $href = System::baseUrl() . '/display/' . $owner_nick . '/' . $item['id'];
75 $href = System::baseUrl() . '/display/' . $item['guid'];
78 $link = xmlify('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n") ;
80 $body = xmlify($item['body']);
84 <type>$targettype</type>
86 <id>{$item['uri']}</id>
89 <content>$body</content>
93 $tagid = System::baseUrl() . '/search?tag=' . $term;
94 $objtype = ACTIVITY_OBJ_TAGTERM;
102 <title>$xterm</title>
103 <content>$xterm</content>
107 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
109 if (!isset($bodyverb)) {
113 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
117 $arr['guid'] = System::createUUID();
119 $arr['uid'] = $owner_uid;
120 $arr['contact-id'] = $contact['id'];
121 $arr['wall'] = $item['wall'];
122 $arr['gravity'] = GRAVITY_COMMENT;
123 $arr['parent'] = $item['id'];
124 $arr['parent-uri'] = $item['uri'];
125 $arr['owner-name'] = $item['author-name'];
126 $arr['owner-link'] = $item['author-link'];
127 $arr['owner-avatar'] = $item['author-avatar'];
128 $arr['author-name'] = $contact['name'];
129 $arr['author-link'] = $contact['url'];
130 $arr['author-avatar'] = $contact['thumb'];
132 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
133 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
134 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
135 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
137 $arr['verb'] = ACTIVITY_TAG;
138 $arr['target-type'] = $targettype;
139 $arr['target'] = $target;
140 $arr['object-type'] = $objtype;
141 $arr['object'] = $obj;
142 $arr['private'] = $item['private'];
143 $arr['allow_cid'] = $item['allow_cid'];
144 $arr['allow_gid'] = $item['allow_gid'];
145 $arr['deny_cid'] = $item['deny_cid'];
146 $arr['deny_gid'] = $item['deny_gid'];
151 $post_id = Item::insert($arr);
153 if (!$item['visible']) {
154 Item::update(['visible' => true], ['id' => $item['id']]);
157 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
159 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
164 if (!$blocktags && $t[0]['tcount'] == 0) {
165 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
170 DBA::escape(System::baseUrl() . '/search?tag=' . $term),
175 // if the original post is on this site, update it.
176 $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
177 if (DBA::isResult($original_item)) {
178 $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
179 intval($original_item['uid'])
181 $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
182 intval($original_item['id']),
186 if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
187 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
188 intval($original_item['id']),
192 DBA::escape(System::baseUrl() . '/search?tag=' . $term),
199 $arr['id'] = $post_id;
201 Addon::callHooks('post_local_end', $arr);
203 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
207 return; // NOTREACHED