3 * @copyright Copyright (C) 2020, Friendica
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\Database\DBA;
29 use Friendica\Model\Item;
30 use Friendica\Protocol\Activity;
31 use Friendica\Util\Security;
32 use Friendica\Util\Strings;
33 use Friendica\Util\XML;
35 function subthread_content(App $a) {
37 if (!Session::isAuthenticated()) {
41 $activity = Activity::FOLLOW;
43 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
45 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
46 $item = Item::selectFirst([], $condition);
48 if (empty($item_id) || !DBA::isResult($item)) {
49 Logger::log('subthread: no item ' . $item_id);
53 $owner_uid = $item['uid'];
55 if (!Security::canWriteToUserWall($owner_uid)) {
62 // The top level post may have been written by somebody on another system
63 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
64 if (!DBA::isResult($contact)) {
67 if (!$contact['self']) {
68 $remote_owner = $contact;
73 // this represents the post owner on this system.
75 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
76 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
80 if (DBA::isResult($r)) {
85 Logger::log('like: no owner');
90 $remote_owner = $owner;
94 // This represents the person posting
96 if (local_user() && (local_user() == $owner_uid)) {
99 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
100 if (!DBA::isResult($contact)) {
105 $uri = Item::newURI($owner_uid);
107 $post_type = (($item['resource-id']) ? DI::l10n()->t('photo') : DI::l10n()->t('status'));
108 $objtype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
109 $link = XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/display/' . $item['guid'] . '" />' . "\n");
110 $body = $item['body'];
115 <type>$objtype</type>
117 <id>{$item['uri']}</id>
120 <content>$body</content>
123 $bodyverb = DI::l10n()->t('%1$s is following %2$s\'s %3$s');
125 if (!isset($bodyverb)) {
131 $arr['guid'] = System::createUUID();
133 $arr['uid'] = $owner_uid;
134 $arr['contact-id'] = $contact['id'];
135 $arr['wall'] = $item['wall'];
137 $arr['gravity'] = GRAVITY_ACTIVITY;
138 $arr['parent'] = $item['id'];
139 $arr['parent-uri'] = $item['uri'];
140 $arr['thr-parent'] = $item['uri'];
141 $arr['owner-name'] = $remote_owner['name'];
142 $arr['owner-link'] = $remote_owner['url'];
143 $arr['owner-avatar'] = $remote_owner['thumb'];
144 $arr['author-name'] = $contact['name'];
145 $arr['author-link'] = $contact['url'];
146 $arr['author-avatar'] = $contact['thumb'];
148 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
149 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
150 $plink = '[url=' . DI::baseUrl() . '/display/' . $item['guid'] . ']' . $post_type . '[/url]';
151 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
153 $arr['verb'] = $activity;
154 $arr['object-type'] = $objtype;
155 $arr['object'] = $obj;
156 $arr['allow_cid'] = $item['allow_cid'];
157 $arr['allow_gid'] = $item['allow_gid'];
158 $arr['deny_cid'] = $item['deny_cid'];
159 $arr['deny_gid'] = $item['deny_gid'];
163 $post_id = Item::insert($arr);
165 if (!$item['visible']) {
166 Item::update(['visible' => true], ['id' => $item['id']]);
169 $arr['id'] = $post_id;
171 Hook::callAll('post_local_end', $arr);