3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Core\Hook;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Session;
26 use Friendica\Core\System;
27 use Friendica\Core\Worker;
28 use Friendica\Database\DBA;
30 use Friendica\Model\Contact;
31 use Friendica\Model\Item;
32 use Friendica\Model\Post;
33 use Friendica\Model\Tag;
34 use Friendica\Protocol\Activity;
35 use Friendica\Util\Strings;
36 use Friendica\Util\XML;
37 use Friendica\Worker\Delivery;
39 function tagger_content(App $a) {
41 if (!Session::isAuthenticated()) {
45 $term = Strings::escapeTags(trim($_GET['term']));
47 $term = str_replace([',',' '],['','_'],$term);
53 $item_id = ((DI::args()->getArgc() > 1) ? Strings::escapeTags(trim(DI::args()->getArgv()[1])) : 0);
55 Logger::notice('tagger: tag ' . $term . ' item ' . $item_id);
58 $item = Post::selectFirst([], ['id' => $item_id]);
60 if (!$item_id || !DBA::isResult($item)) {
61 Logger::notice('tagger: no item ' . $item_id);
65 $owner_uid = $item['uid'];
67 if (local_user() != $owner_uid) {
71 $contact = Contact::selectFirst([], ['self' => true, 'uid' => local_user()]);
72 if (!DBA::isResult($contact)) {
73 Logger::notice('tagger: no contact_id');
77 $uri = Item::newURI($owner_uid);
78 $xterm = XML::escape($term);
79 $post_type = (($item['resource-id']) ? DI::l10n()->t('photo') : DI::l10n()->t('status'));
80 $targettype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
81 $href = DI::baseUrl() . '/display/' . $item['guid'];
83 $link = XML::escape('<link rel="alternate" type="text/html" href="'. $href . '" />' . "\n");
85 $body = XML::escape($item['body']);
89 <type>$targettype</type>
91 <id>{$item['uri']}</id>
94 <content>$body</content>
98 $tagid = DI::baseUrl() . '/search?tag=' . $xterm;
99 $objtype = Activity\ObjectType::TAGTERM;
103 <type>$objtype</type>
107 <title>$xterm</title>
108 <content>$xterm</content>
112 $bodyverb = DI::l10n()->t('%1$s tagged %2$s\'s %3$s with %4$s');
114 if (!isset($bodyverb)) {
118 $termlink = html_entity_decode('⌗') . '[url=' . DI::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
122 $arr['guid'] = System::createUUID();
124 $arr['uid'] = $owner_uid;
125 $arr['contact-id'] = $contact['id'];
126 $arr['wall'] = $item['wall'];
127 $arr['gravity'] = GRAVITY_COMMENT;
128 $arr['parent'] = $item['id'];
129 $arr['thr-parent'] = $item['uri'];
130 $arr['owner-name'] = $item['author-name'];
131 $arr['owner-link'] = $item['author-link'];
132 $arr['owner-avatar'] = $item['author-avatar'];
133 $arr['author-name'] = $contact['name'];
134 $arr['author-link'] = $contact['url'];
135 $arr['author-avatar'] = $contact['thumb'];
137 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
138 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
139 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
140 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
142 $arr['verb'] = Activity::TAG;
143 $arr['target-type'] = $targettype;
144 $arr['target'] = $target;
145 $arr['object-type'] = $objtype;
146 $arr['object'] = $obj;
147 $arr['private'] = $item['private'];
148 $arr['allow_cid'] = $item['allow_cid'];
149 $arr['allow_gid'] = $item['allow_gid'];
150 $arr['deny_cid'] = $item['deny_cid'];
151 $arr['deny_gid'] = $item['deny_gid'];
156 $post_id = Item::insert($arr);
158 if (!$item['visible']) {
159 Item::update(['visible' => true], ['id' => $item['id']]);
162 Tag::store($item['uri-id'], Tag::HASHTAG, $term);
164 $arr['id'] = $post_id;
166 Hook::callAll('post_local_end', $arr);
168 $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
170 Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']);