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/items.php';
16 function tagger_content(App $a) {
18 if (!local_user() && !remote_user()) {
22 $term = notags(trim($_GET['term']));
24 $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 $item = Item::selectFirst([], ['id' => $item_id]);
37 if (!$item_id || !DBM::is_result($item)) {
38 logger('tagger: no item ' . $item_id);
42 $owner_uid = $item['uid'];
46 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
49 if (DBM::is_result($r)) {
50 $owner_nick = $r[0]['nickname'];
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 (DBM::is_result($r)) {
64 logger('tagger: no contact_id');
68 $uri = Item::newURI($owner_uid);
69 $xterm = xmlify($term);
70 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
71 $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
74 $href = System::baseUrl() . '/display/' . $owner_nick . '/' . $item['id'];
76 $href = System::baseUrl() . '/display/' . $item['guid'];
79 $link = xmlify('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n") ;
81 $body = xmlify($item['body']);
85 <type>$targettype</type>
87 <id>{$item['uri']}</id>
90 <content>$body</content>
94 $tagid = System::baseUrl() . '/search?tag=' . $term;
95 $objtype = ACTIVITY_OBJ_TAGTERM;
103 <title>$xterm</title>
104 <content>$xterm</content>
108 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
110 if (!isset($bodyverb)) {
114 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]';
118 $arr['guid'] = get_guid(32);
120 $arr['uid'] = $owner_uid;
121 $arr['contact-id'] = $contact['id'];
122 $arr['type'] = 'activity';
123 $arr['wall'] = $item['wall'];
124 $arr['gravity'] = GRAVITY_COMMENT;
125 $arr['parent'] = $item['id'];
126 $arr['parent-uri'] = $item['uri'];
127 $arr['owner-name'] = $item['author-name'];
128 $arr['owner-link'] = $item['author-link'];
129 $arr['owner-avatar'] = $item['author-avatar'];
130 $arr['author-name'] = $contact['name'];
131 $arr['author-link'] = $contact['url'];
132 $arr['author-avatar'] = $contact['thumb'];
134 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
135 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
136 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
137 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
139 $arr['verb'] = ACTIVITY_TAG;
140 $arr['target-type'] = $targettype;
141 $arr['target'] = $target;
142 $arr['object-type'] = $objtype;
143 $arr['object'] = $obj;
144 $arr['private'] = $item['private'];
145 $arr['allow_cid'] = $item['allow_cid'];
146 $arr['allow_gid'] = $item['allow_gid'];
147 $arr['deny_cid'] = $item['deny_cid'];
148 $arr['deny_gid'] = $item['deny_gid'];
153 $post_id = Item::insert($arr);
155 if (!$item['visible']) {
156 Item::update(['visible' => true], ['id' => $item['id']]);
159 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
161 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
166 if (!$blocktags && $t[0]['tcount'] == 0) {
167 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
172 dbesc(System::baseUrl() . '/search?tag=' . $term),
177 // if the original post is on this site, update it.
179 $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'",
192 if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
193 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
198 dbesc(System::baseUrl() . '/search?tag=' . $term),
205 $arr['id'] = $post_id;
207 Addon::callHooks('post_local_end', $arr);
209 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
213 return; // NOTREACHED