3 * @file mod/subthread.php
7 use Friendica\Core\Hook;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Session;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
13 use Friendica\Model\Item;
14 use Friendica\Protocol\Activity;
15 use Friendica\Util\Security;
16 use Friendica\Util\Strings;
17 use Friendica\Util\XML;
19 function subthread_content(App $a) {
21 if (!Session::isAuthenticated()) {
25 $activity = Activity::FOLLOW;
27 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
29 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
30 $item = Item::selectFirst([], $condition);
32 if (empty($item_id) || !DBA::isResult($item)) {
33 Logger::log('subthread: no item ' . $item_id);
37 $owner_uid = $item['uid'];
39 if (!Security::canWriteToUserWall($owner_uid)) {
46 // The top level post may have been written by somebody on another system
47 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
48 if (!DBA::isResult($contact)) {
51 if (!$contact['self']) {
52 $remote_owner = $contact;
57 // this represents the post owner on this system.
59 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
60 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
64 if (DBA::isResult($r)) {
69 Logger::log('like: no owner');
74 $remote_owner = $owner;
78 // This represents the person posting
80 if (local_user() && (local_user() == $owner_uid)) {
83 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
84 if (!DBA::isResult($contact)) {
89 $uri = Item::newURI($owner_uid);
91 $post_type = (($item['resource-id']) ? DI::l10n()->t('photo') : DI::l10n()->t('status'));
92 $objtype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
93 $link = XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/display/' . $item['guid'] . '" />' . "\n");
94 $body = $item['body'];
101 <id>{$item['uri']}</id>
104 <content>$body</content>
107 $bodyverb = DI::l10n()->t('%1$s is following %2$s\'s %3$s');
109 if (!isset($bodyverb)) {
115 $arr['guid'] = System::createUUID();
117 $arr['uid'] = $owner_uid;
118 $arr['contact-id'] = $contact['id'];
119 $arr['wall'] = $item['wall'];
121 $arr['gravity'] = GRAVITY_ACTIVITY;
122 $arr['parent'] = $item['id'];
123 $arr['parent-uri'] = $item['uri'];
124 $arr['thr-parent'] = $item['uri'];
125 $arr['owner-name'] = $remote_owner['name'];
126 $arr['owner-link'] = $remote_owner['url'];
127 $arr['owner-avatar'] = $remote_owner['thumb'];
128 $arr['author-name'] = $contact['name'];
129 $arr['author-link'] = $contact['url'];
130 $arr['author-avatar'] = $contact['thumb'];
132 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
133 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
134 $plink = '[url=' . DI::baseUrl() . '/display/' . $item['guid'] . ']' . $post_type . '[/url]';
135 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
137 $arr['verb'] = $activity;
138 $arr['object-type'] = $objtype;
139 $arr['object'] = $obj;
140 $arr['allow_cid'] = $item['allow_cid'];
141 $arr['allow_gid'] = $item['allow_gid'];
142 $arr['deny_cid'] = $item['deny_cid'];
143 $arr['deny_gid'] = $item['deny_gid'];
147 $post_id = Item::insert($arr);
149 if (!$item['visible']) {
150 Item::update(['visible' => true], ['id' => $item['id']]);
153 $arr['id'] = $post_id;
155 Hook::callAll('post_local_end', $arr);