3 * @copyright Copyright (C) 2010-2022, 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\System;
26 use Friendica\Core\Worker;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Contact;
30 use Friendica\Model\Item;
31 use Friendica\Model\Post;
32 use Friendica\Model\Tag;
33 use Friendica\Protocol\Activity;
34 use Friendica\Util\XML;
35 use Friendica\Worker\Delivery;
37 function tagger_content(App $a)
39 if (!DI::userSession()->isAuthenticated()) {
43 $term = trim($_GET['term'] ?? '');
45 $term = str_replace([',',' ', '<', '>'],['','_', '', ''], $term);
51 $item_id = ((DI::args()->getArgc() > 1) ? trim(DI::args()->getArgv()[1]) : 0);
53 Logger::info('tagger: tag', ['term' => $term, 'item' => $item_id]);
56 $item = Post::selectFirst([], ['id' => $item_id]);
58 if (!$item_id || !DBA::isResult($item)) {
59 Logger::notice('tagger: no item ' . $item_id);
63 $owner_uid = $item['uid'];
65 if (DI::userSession()->getLocalUserId() != $owner_uid) {
69 $contact = Contact::selectFirst([], ['self' => true, 'uid' => DI::userSession()->getLocalUserId()]);
70 if (!DBA::isResult($contact)) {
71 Logger::warning('Self contact not found.', ['uid' => DI::userSession()->getLocalUserId()]);
75 $uri = Item::newURI();
76 $xterm = XML::escape($term);
77 $post_type = (($item['resource-id']) ? DI::l10n()->t('photo') : DI::l10n()->t('status'));
78 $targettype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
79 $href = DI::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 = DI::baseUrl() . '/search?tag=' . $xterm;
97 $objtype = Activity\ObjectType::TAGTERM;
101 <type>$objtype</type>
105 <title>$xterm</title>
106 <content>$xterm</content>
110 $bodyverb = DI::l10n()->t('%1$s tagged %2$s\'s %3$s with %4$s');
112 if (!isset($bodyverb)) {
116 $termlink = html_entity_decode('⌗') . '[url=' . DI::baseUrl() . '/search?tag=' . $term . ']'. $term . '[/url]';
118 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
119 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
120 $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
123 'guid' => System::createUUID(),
126 'contact-id' => $contact['id'],
127 'wall' => $item['wall'],
128 'gravity' => Item::GRAVITY_COMMENT,
129 'parent' => $item['id'],
130 'thr-parent' => $item['uri'],
131 'owner-name' => $item['author-name'],
132 'owner-link' => $item['author-link'],
133 'owner-avatar' => $item['author-avatar'],
134 'author-name' => $contact['name'],
135 'author-link' => $contact['url'],
136 'author-avatar' => $contact['thumb'],
137 'body' => sprintf($bodyverb, $ulink, $alink, $plink, $termlink),
138 'verb' => Activity::TAG,
139 'target-type' => $targettype,
141 'object-type' => $objtype,
143 'private' => $item['private'],
144 'allow_cid' => $item['allow_cid'],
145 'allow_gid' => $item['allow_gid'],
146 'deny_cid' => $item['deny_cid'],
147 'deny_gid' => $item['deny_gid'],
154 $post_id = Item::insert($arr);
156 if (!$item['visible']) {
157 Item::update(['visible' => true], ['id' => $item['id']]);
160 Tag::store($item['uri-id'], Tag::HASHTAG, $term);
162 $arr['id'] = $post_id;
164 Hook::callAll('post_local_end', $arr);
166 $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
168 Worker::add(Worker::PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']);