3 * @file mod/subthread.php
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\Database\DBA;
14 use Friendica\Model\Item;
15 use Friendica\Protocol\Activity;
16 use Friendica\Util\Security;
17 use Friendica\Util\Strings;
18 use Friendica\Util\XML;
20 function subthread_content(App $a) {
22 if (!Session::isAuthenticated()) {
26 $activity = Activity::FOLLOW;
28 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
30 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
31 $item = Item::selectFirst([], $condition);
33 if (empty($item_id) || !DBA::isResult($item)) {
34 Logger::log('subthread: no item ' . $item_id);
38 $owner_uid = $item['uid'];
40 if (!Security::canWriteToUserWall($owner_uid)) {
47 // The top level post may have been written by somebody on another system
48 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
49 if (!DBA::isResult($contact)) {
52 if (!$contact['self']) {
53 $remote_owner = $contact;
58 // this represents the post owner on this system.
60 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
61 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
65 if (DBA::isResult($r)) {
70 Logger::log('like: no owner');
75 $remote_owner = $owner;
79 // This represents the person posting
81 if (local_user() && (local_user() == $owner_uid)) {
84 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
85 if (!DBA::isResult($contact)) {
90 $uri = Item::newURI($owner_uid);
92 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
93 $objtype = (($item['resource-id']) ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE );
94 $link = XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/display/' . $item['guid'] . '" />' . "\n");
95 $body = $item['body'];
100 <type>$objtype</type>
102 <id>{$item['uri']}</id>
105 <content>$body</content>
108 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
110 if (!isset($bodyverb)) {
116 $arr['guid'] = System::createUUID();
118 $arr['uid'] = $owner_uid;
119 $arr['contact-id'] = $contact['id'];
120 $arr['wall'] = $item['wall'];
122 $arr['gravity'] = GRAVITY_ACTIVITY;
123 $arr['parent'] = $item['id'];
124 $arr['parent-uri'] = $item['uri'];
125 $arr['thr-parent'] = $item['uri'];
126 $arr['owner-name'] = $remote_owner['name'];
127 $arr['owner-link'] = $remote_owner['url'];
128 $arr['owner-avatar'] = $remote_owner['thumb'];
129 $arr['author-name'] = $contact['name'];
130 $arr['author-link'] = $contact['url'];
131 $arr['author-avatar'] = $contact['thumb'];
133 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
134 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
135 $plink = '[url=' . DI::baseUrl() . '/display/' . $item['guid'] . ']' . $post_type . '[/url]';
136 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
138 $arr['verb'] = $activity;
139 $arr['object-type'] = $objtype;
140 $arr['object'] = $obj;
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'];
148 $post_id = Item::insert($arr);
150 if (!$item['visible']) {
151 Item::update(['visible' => true], ['id' => $item['id']]);
154 $arr['id'] = $post_id;
156 Hook::callAll('post_local_end', $arr);