3 * @file mod/subthread.php
6 use Friendica\Core\Hook;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Model\Item;
12 use Friendica\Util\Security;
13 use Friendica\Util\Strings;
14 use Friendica\Util\XML;
16 function subthread_content(App $a) {
18 if (!local_user() && !remote_user()) {
22 $activity = ACTIVITY_FOLLOW;
24 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
26 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
27 $item = Item::selectFirst([], $condition);
29 if (empty($item_id) || !DBA::isResult($item)) {
30 Logger::log('subthread: no item ' . $item_id);
34 $owner_uid = $item['uid'];
36 if (!Security::canWriteToUserWall($owner_uid)) {
43 // The top level post may have been written by somebody on another system
44 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
45 if (!DBA::isResult($contact)) {
48 if (!$contact['self']) {
49 $remote_owner = $contact;
54 // this represents the post owner on this system.
56 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
57 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
61 if (DBA::isResult($r)) {
66 Logger::log('like: no owner');
71 $remote_owner = $owner;
75 // This represents the person posting
77 if (local_user() && (local_user() == $owner_uid)) {
80 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
81 if (!DBA::isResult($contact)) {
86 $uri = Item::newURI($owner_uid);
88 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
89 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
90 $link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
91 $body = $item['body'];
98 <id>{$item['uri']}</id>
101 <content>$body</content>
104 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
106 if (!isset($bodyverb)) {
112 $arr['guid'] = System::createUUID();
114 $arr['uid'] = $owner_uid;
115 $arr['contact-id'] = $contact['id'];
116 $arr['wall'] = $item['wall'];
118 $arr['gravity'] = GRAVITY_ACTIVITY;
119 $arr['parent'] = $item['id'];
120 $arr['parent-uri'] = $item['uri'];
121 $arr['thr-parent'] = $item['uri'];
122 $arr['owner-name'] = $remote_owner['name'];
123 $arr['owner-link'] = $remote_owner['url'];
124 $arr['owner-avatar'] = $remote_owner['thumb'];
125 $arr['author-name'] = $contact['name'];
126 $arr['author-link'] = $contact['url'];
127 $arr['author-avatar'] = $contact['thumb'];
129 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
130 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
131 $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
132 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
134 $arr['verb'] = $activity;
135 $arr['object-type'] = $objtype;
136 $arr['object'] = $obj;
137 $arr['allow_cid'] = $item['allow_cid'];
138 $arr['allow_gid'] = $item['allow_gid'];
139 $arr['deny_cid'] = $item['deny_cid'];
140 $arr['deny_gid'] = $item['deny_gid'];
144 $post_id = Item::insert($arr);
146 if (!$item['visible']) {
147 Item::update(['visible' => true], ['id' => $item['id']]);
150 $arr['id'] = $post_id;
152 Hook::callAll('post_local_end', $arr);