7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Logger;
10 use Friendica\Core\Session;
11 use Friendica\Core\System;
12 use Friendica\Core\Worker;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Item;
15 use Friendica\Protocol\Activity;
16 use Friendica\Util\Strings;
17 use Friendica\Util\XML;
18 use Friendica\Worker\Delivery;
20 function tagger_content(App $a) {
22 if (!Session::isAuthenticated()) {
26 $term = Strings::escapeTags(trim($_GET['term']));
28 $term = str_replace([',',' '],['','_'],$term);
34 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
36 Logger::log('tagger: tag ' . $term . ' item ' . $item_id);
39 $item = Item::selectFirst([], ['id' => $item_id]);
41 if (!$item_id || !DBA::isResult($item)) {
42 Logger::log('tagger: no item ' . $item_id);
46 $owner_uid = $item['uid'];
49 $r = q("select `blocktags` from user where uid = %d limit 1",
52 if (DBA::isResult($r)) {
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\ObjectType::IMAGE : Activity\ObjectType::NOTE );
74 $href = System::baseUrl() . '/display/' . $item['guid'];
76 $link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
78 $body = XML::escape($item['body']);
82 <type>$targettype</type>
84 <id>{$item['uri']}</id>
87 <content>$body</content>
91 $tagid = System::baseUrl() . '/search?tag=' . $xterm;
92 $objtype = Activity\ObjectType::TAGTERM;
100 <title>$xterm</title>
101 <content>$xterm</content>
105 $bodyverb = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s');
107 if (!isset($bodyverb)) {
111 $termlink = html_entity_decode('⌗') . '[url=' . System::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
115 $arr['guid'] = System::createUUID();
117 $arr['uid'] = $owner_uid;
118 $arr['contact-id'] = $contact['id'];
119 $arr['wall'] = $item['wall'];
120 $arr['gravity'] = GRAVITY_COMMENT;
121 $arr['parent'] = $item['id'];
122 $arr['parent-uri'] = $item['uri'];
123 $arr['owner-name'] = $item['author-name'];
124 $arr['owner-link'] = $item['author-link'];
125 $arr['owner-avatar'] = $item['author-avatar'];
126 $arr['author-name'] = $contact['name'];
127 $arr['author-link'] = $contact['url'];
128 $arr['author-avatar'] = $contact['thumb'];
130 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
131 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
132 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
133 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
135 $arr['verb'] = Activity::TAG;
136 $arr['target-type'] = $targettype;
137 $arr['target'] = $target;
138 $arr['object-type'] = $objtype;
139 $arr['object'] = $obj;
140 $arr['private'] = $item['private'];
141 $arr['allow_cid'] = $item['allow_cid'];
142 $arr['allow_gid'] = $item['allow_gid'];
143 $arr['deny_cid'] = $item['deny_cid'];
144 $arr['deny_gid'] = $item['deny_gid'];
149 $post_id = Item::insert($arr);
151 if (!$item['visible']) {
152 Item::update(['visible' => true], ['id' => $item['id']]);
155 $term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
157 $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
162 if (!$blocktags && $t[0]['tcount'] == 0) {
163 q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
173 // if the original post is on this site, update it.
174 $original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
175 if (DBA::isResult($original_item)) {
176 $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
177 intval($original_item['uid'])
179 $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
180 intval($original_item['id']),
184 if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
185 q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
186 intval($original_item['id']),
197 $arr['id'] = $post_id;
199 Hook::callAll('post_local_end', $arr);
201 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id);