3 * @file mod/subthread.php
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Item;
12 require_once 'include/security.php';
13 require_once 'include/items.php';
15 function subthread_content(App $a) {
17 if (!local_user() && !remote_user()) {
21 $activity = ACTIVITY_FOLLOW;
23 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
25 $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
26 $item = Item::selectFirst([], $condition);
28 if (empty($item_id) || !DBA::isResult($item)) {
29 logger('subthread: no item ' . $item_id);
33 $owner_uid = $item['uid'];
35 if (!can_write_wall($owner_uid)) {
42 // The top level post may have been written by somebody on another system
43 $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
44 if (!DBA::isResult($contact)) {
47 if (!$contact['self']) {
48 $remote_owner = $contact;
53 // this represents the post owner on this system.
55 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
56 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
60 if (DBA::isResult($r)) {
65 logger('like: no owner');
70 $remote_owner = $owner;
74 // This represents the person posting
76 if (local_user() && (local_user() == $owner_uid)) {
79 $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
80 if (!DBA::isResult($contact)) {
85 $uri = Item::newURI($owner_uid);
87 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
88 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
89 $link = xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
90 $body = $item['body'];
97 <id>{$item['uri']}</id>
100 <content>$body</content>
103 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
105 if (!isset($bodyverb)) {
111 $arr['guid'] = System::createUUID();
113 $arr['uid'] = $owner_uid;
114 $arr['contact-id'] = $contact['id'];
115 $arr['wall'] = $item['wall'];
117 $arr['gravity'] = GRAVITY_ACTIVITY;
118 $arr['parent'] = $item['id'];
119 $arr['parent-uri'] = $item['uri'];
120 $arr['thr-parent'] = $item['uri'];
121 $arr['owner-name'] = $remote_owner['name'];
122 $arr['owner-link'] = $remote_owner['url'];
123 $arr['owner-avatar'] = $remote_owner['thumb'];
124 $arr['author-name'] = $contact['name'];
125 $arr['author-link'] = $contact['url'];
126 $arr['author-avatar'] = $contact['thumb'];
128 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
129 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
130 $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
131 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
133 $arr['verb'] = $activity;
134 $arr['object-type'] = $objtype;
135 $arr['object'] = $obj;
136 $arr['allow_cid'] = $item['allow_cid'];
137 $arr['allow_gid'] = $item['allow_gid'];
138 $arr['deny_cid'] = $item['deny_cid'];
139 $arr['deny_gid'] = $item['deny_gid'];
143 $post_id = Item::insert($arr);
145 if (!$item['visible']) {
146 Item::update(['visible' => true], ['id' => $item['id']]);
149 $arr['id'] = $post_id;
151 Addon::callHooks('post_local_end', $arr);