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);
29 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
31 logger('tagger: tag ' . $term . ' item ' . $item_id);
34 $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
38 if(! $item_id || (! DBM::is_result($r))) {
39 logger('tagger: no item ' . $item_id);
45 $owner_uid = $item['uid'];
49 $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
52 if (DBM::is_result($r)) {
53 $owner_nick = $r[0]['nickname'];
54 $blocktags = $r[0]['blocktags'];
57 if(local_user() != $owner_uid)
60 $r = q("select * from contact where self = 1 and uid = %d limit 1",
63 if (DBM::is_result($r))
66 logger('tagger: no contact_id');
70 $uri = item_new_uri($a->get_hostname(),$owner_uid);
71 $xterm = xmlify($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 = xmlify('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n") ;
83 $body = xmlify($item['body']);
87 <type>$targettype</type>
89 <id>{$item['uri']}</id>
92 <content>$body</content>
96 $tagid = System::baseUrl() . '/search?tag=' . $term;
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=' . urlencode($term) . ']'. $term . '[/url]';
120 $arr['guid'] = get_guid(32);
122 $arr['uid'] = $owner_uid;
123 $arr['contact-id'] = $contact['id'];
124 $arr['type'] = 'activity';
125 $arr['wall'] = $item['wall'];
126 $arr['gravity'] = GRAVITY_COMMENT;
127 $arr['parent'] = $item['id'];
128 $arr['parent-uri'] = $item['uri'];
129 $arr['owner-name'] = $item['author-name'];
130 $arr['owner-link'] = $item['author-link'];
131 $arr['owner-avatar'] = $item['author-avatar'];
132 $arr['author-name'] = $contact['name'];
133 $arr['author-link'] = $contact['url'];
134 $arr['author-avatar'] = $contact['thumb'];
136 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
137 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
138 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
139 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
141 $arr['verb'] = ACTIVITY_TAG;
142 $arr['target-type'] = $targettype;
143 $arr['target'] = $target;
144 $arr['object-type'] = $objtype;
145 $arr['object'] = $obj;
146 $arr['private'] = $item['private'];
147 $arr['allow_cid'] = $item['allow_cid'];
148 $arr['allow_gid'] = $item['allow_gid'];
149 $arr['deny_cid'] = $item['deny_cid'];
150 $arr['deny_gid'] = $item['deny_gid'];
155 $post_id = Item::insert($arr);
157 if (!$item['visible']) {
158 Item::update(['visible' => true], ['id' => $item['id']]);
161 $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'",
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",
182 if (DBM::is_result($r)) {
183 $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
186 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
190 if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
191 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
196 dbesc(System::baseUrl() . '/search?tag=' . $term),
203 $arr['id'] = $post_id;
205 Addon::callHooks('post_local_end', $arr);
207 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id);
211 return; // NOTREACHED