3 * @file mod/subthread.php
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Item;
12 require_once 'include/security.php';
13 require_once 'include/bbcode.php';
14 require_once 'include/items.php';
16 function subthread_content(App $a) {
18 if(! local_user() && ! remote_user()) {
22 $activity = ACTIVITY_FOLLOW;
24 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
26 $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
31 if(! $item_id || (! DBM::is_result($r))) {
32 logger('subthread: no item ' . $item_id);
38 $owner_uid = $item['uid'];
40 if(! can_write_wall($owner_uid)) {
47 // The top level post may have been written by somebody on another system
48 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
49 intval($item['contact-id']),
52 if (! DBM::is_result($r)) {
55 if (! $r[0]['self']) {
56 $remote_owner = $r[0];
60 // this represents the post owner on this system.
62 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
63 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
66 if (DBM::is_result($r))
70 logger('like: no owner');
75 $remote_owner = $owner;
78 // This represents the person posting
80 if ((local_user()) && (local_user() == $owner_uid)) {
83 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
84 intval($_SESSION['visitor_id']),
87 if (DBM::is_result($r))
94 $uri = item_new_uri($a->get_hostname(),$owner_uid);
96 $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
97 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
98 $link = xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
99 $body = $item['body'];
104 <type>$objtype</type>
106 <id>{$item['uri']}</id>
109 <content>$body</content>
112 $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
114 if (! isset($bodyverb)) {
120 $arr['guid'] = get_guid(32);
122 $arr['uid'] = $owner_uid;
123 $arr['contact-id'] = $contact['id'];
124 $arr['type'] = 'activity';
125 $arr['wall'] = $item['wall'];
127 $arr['gravity'] = GRAVITY_LIKE;
128 $arr['parent'] = $item['id'];
129 $arr['parent-uri'] = $item['uri'];
130 $arr['thr-parent'] = $item['uri'];
131 $arr['owner-name'] = $remote_owner['name'];
132 $arr['owner-link'] = $remote_owner['url'];
133 $arr['owner-avatar'] = $remote_owner['thumb'];
134 $arr['author-name'] = $contact['name'];
135 $arr['author-link'] = $contact['url'];
136 $arr['author-avatar'] = $contact['thumb'];
138 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
139 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
140 $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
141 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
143 $arr['verb'] = $activity;
144 $arr['object-type'] = $objtype;
145 $arr['object'] = $obj;
146 $arr['allow_cid'] = $item['allow_cid'];
147 $arr['allow_gid'] = $item['allow_gid'];
148 $arr['deny_cid'] = $item['deny_cid'];
149 $arr['deny_gid'] = $item['deny_gid'];
153 $post_id = Item::insert($arr);
155 if (! $item['visible']) {
156 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
162 $arr['id'] = $post_id;
164 Addon::callHooks('post_local_end', $arr);