3 * @file mod/subthread.php
6 use Friendica\Core\Hook;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Session;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Item;
13 use Friendica\Util\Security;
14 use Friendica\Util\Strings;
15 use Friendica\Util\XML;
17 function subthread_content(App $a) {
19 if (!Session::isAuthenticated()) {
23 $activity = ACTIVITY_FOLLOW;
25 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
27 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
28 $item = Item::selectFirst([], $condition);
30 if (empty($item_id) || !DBA::isResult($item)) {
31 Logger::log('subthread: no item ' . $item_id);
35 $owner_uid = $item['uid'];
37 if (!Security::canWriteToUserWall($owner_uid)) {
44 // The top level post may have been written by somebody on another system
45 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
46 if (!DBA::isResult($contact)) {
49 if (!$contact['self']) {
50 $remote_owner = $contact;
55 // this represents the post owner on this system.
57 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
58 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
62 if (DBA::isResult($r)) {
67 Logger::log('like: no owner');
72 $remote_owner = $owner;
76 // This represents the person posting
78 if (local_user() && (local_user() == $owner_uid)) {
81 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
82 if (!DBA::isResult($contact)) {
87 $uri = Item::newURI($owner_uid);
89 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
90 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
91 $link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $item['guid'] . '" />' . "\n");
92 $body = $item['body'];
99 <id>{$item['uri']}</id>
102 <content>$body</content>
105 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
107 if (!isset($bodyverb)) {
113 $arr['guid'] = System::createUUID();
115 $arr['uid'] = $owner_uid;
116 $arr['contact-id'] = $contact['id'];
117 $arr['wall'] = $item['wall'];
119 $arr['gravity'] = GRAVITY_ACTIVITY;
120 $arr['parent'] = $item['id'];
121 $arr['parent-uri'] = $item['uri'];
122 $arr['thr-parent'] = $item['uri'];
123 $arr['owner-name'] = $remote_owner['name'];
124 $arr['owner-link'] = $remote_owner['url'];
125 $arr['owner-avatar'] = $remote_owner['thumb'];
126 $arr['author-name'] = $contact['name'];
127 $arr['author-link'] = $contact['url'];
128 $arr['author-avatar'] = $contact['thumb'];
130 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
131 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
132 $plink = '[url=' . System::baseUrl() . '/display/' . $item['guid'] . ']' . $post_type . '[/url]';
133 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
135 $arr['verb'] = $activity;
136 $arr['object-type'] = $objtype;
137 $arr['object'] = $obj;
138 $arr['allow_cid'] = $item['allow_cid'];
139 $arr['allow_gid'] = $item['allow_gid'];
140 $arr['deny_cid'] = $item['deny_cid'];
141 $arr['deny_gid'] = $item['deny_gid'];
145 $post_id = Item::insert($arr);
147 if (!$item['visible']) {
148 Item::update(['visible' => true], ['id' => $item['id']]);
151 $arr['id'] = $post_id;
153 Hook::callAll('post_local_end', $arr);