6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\System;
10 use Friendica\Core\Worker;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Item;
13 use Friendica\Util\Strings;
14 use Friendica\Util\XML;
16 require_once 'include/items.php';
18 function tagger_content(App $a) {
20 if (!local_user() && !remote_user()) {
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'];
48 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
51 if (DBA::isResult($r)) {
52 $owner_nick = $r[0]['nickname'];
53 $blocktags = $r[0]['blocktags'];
56 if (local_user() != $owner_uid) {
60 $r = q("select * from contact where self = 1 and uid = %d limit 1",
63 if (DBA::isResult($r)) {
66 Logger::log('tagger: no contact_id');
70 $uri = Item::newURI($owner_uid);
71 $xterm = XML::escape($term);
72 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
73 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
76 $href = System::baseUrl() . '/display/' . $owner_nick . '/' . $item['id'];
78 $href = System::baseUrl() . '/display/' . $item['guid'];
81 $link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
83 $body = XML::escape($item['body']);
87 <type>$targettype</type>
89 <id>{$item['uri']}</id>
92 <content>$body</content>
96 $tagid = System::baseUrl() . '/search?tag=' . $xterm;
97 $objtype = ACTIVITY_OBJ_TAGTERM;
101 <type>$objtype</type>
105 <title>$xterm</title>
106 <content>$xterm</content>
110 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
112 if (!isset($bodyverb)) {
116 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
120 $arr['guid'] = System::createUUID();
122 $arr['uid'] = $owner_uid;
123 $arr['contact-id'] = $contact['id'];
124 $arr['wall'] = $item['wall'];
125 $arr['gravity'] = GRAVITY_COMMENT;
126 $arr['parent'] = $item['id'];
127 $arr['parent-uri'] = $item['uri'];
128 $arr['owner-name'] = $item['author-name'];
129 $arr['owner-link'] = $item['author-link'];
130 $arr['owner-avatar'] = $item['author-avatar'];
131 $arr['author-name'] = $contact['name'];
132 $arr['author-link'] = $contact['url'];
133 $arr['author-avatar'] = $contact['thumb'];
135 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
136 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
137 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
138 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
140 $arr['verb'] = ACTIVITY_TAG;
141 $arr['target-type'] = $targettype;
142 $arr['target'] = $target;
143 $arr['object-type'] = $objtype;
144 $arr['object'] = $obj;
145 $arr['private'] = $item['private'];
146 $arr['allow_cid'] = $item['allow_cid'];
147 $arr['allow_gid'] = $item['allow_gid'];
148 $arr['deny_cid'] = $item['deny_cid'];
149 $arr['deny_gid'] = $item['deny_gid'];
154 $post_id = Item::insert($arr);
156 if (!$item['visible']) {
157 Item::update(['visible' => true], ['id' => $item['id']]);
160 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
162 $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)",
178 // if the original post is on this site, update it.
179 $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
180 if (DBA::isResult($original_item)) {
181 $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
182 intval($original_item['uid'])
184 $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
185 intval($original_item['id']),
189 if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
190 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
191 intval($original_item['id']),
202 $arr['id'] = $post_id;
204 Addon::callHooks('post_local_end', $arr);
206 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
210 return; // NOTREACHED