3 * @file mod/subthread.php
6 use Friendica\Core\Addon;
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 require_once 'include/items.php';
18 function subthread_content(App $a) {
20 if (!local_user() && !remote_user()) {
24 $activity = ACTIVITY_FOLLOW;
26 $item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
28 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
29 $item = Item::selectFirst([], $condition);
31 if (empty($item_id) || !DBA::isResult($item)) {
32 Logger::log('subthread: no item ' . $item_id);
36 $owner_uid = $item['uid'];
38 if (!Security::canWriteToUserWall($owner_uid)) {
45 // The top level post may have been written by somebody on another system
46 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
47 if (!DBA::isResult($contact)) {
50 if (!$contact['self']) {
51 $remote_owner = $contact;
56 // this represents the post owner on this system.
58 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
59 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
63 if (DBA::isResult($r)) {
68 Logger::log('like: no owner');
73 $remote_owner = $owner;
77 // This represents the person posting
79 if (local_user() && (local_user() == $owner_uid)) {
82 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
83 if (!DBA::isResult($contact)) {
88 $uri = Item::newURI($owner_uid);
90 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
91 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
92 $link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
93 $body = $item['body'];
100 <id>{$item['uri']}</id>
103 <content>$body</content>
106 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
108 if (!isset($bodyverb)) {
114 $arr['guid'] = System::createUUID();
116 $arr['uid'] = $owner_uid;
117 $arr['contact-id'] = $contact['id'];
118 $arr['wall'] = $item['wall'];
120 $arr['gravity'] = GRAVITY_ACTIVITY;
121 $arr['parent'] = $item['id'];
122 $arr['parent-uri'] = $item['uri'];
123 $arr['thr-parent'] = $item['uri'];
124 $arr['owner-name'] = $remote_owner['name'];
125 $arr['owner-link'] = $remote_owner['url'];
126 $arr['owner-avatar'] = $remote_owner['thumb'];
127 $arr['author-name'] = $contact['name'];
128 $arr['author-link'] = $contact['url'];
129 $arr['author-avatar'] = $contact['thumb'];
131 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
132 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
133 $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
134 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
136 $arr['verb'] = $activity;
137 $arr['object-type'] = $objtype;
138 $arr['object'] = $obj;
139 $arr['allow_cid'] = $item['allow_cid'];
140 $arr['allow_gid'] = $item['allow_gid'];
141 $arr['deny_cid'] = $item['deny_cid'];
142 $arr['deny_gid'] = $item['deny_gid'];
146 $post_id = Item::insert($arr);
148 if (!$item['visible']) {
149 Item::update(['visible' => true], ['id' => $item['id']]);
152 $arr['id'] = $post_id;
154 Addon::callHooks('post_local_end', $arr);