4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
7 require_once('include/security.php');
8 require_once('include/bbcode.php');
9 require_once('include/items.php');
11 function subthread_content(App $a) {
13 if(! local_user() && ! remote_user()) {
17 $activity = ACTIVITY_FOLLOW;
19 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
21 $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
26 if(! $item_id || (! DBM::is_result($r))) {
27 logger('subthread: no item ' . $item_id);
33 $owner_uid = $item['uid'];
35 if(! can_write_wall($a,$owner_uid)) {
42 // The top level post may have been written by somebody on another system
43 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
44 intval($item['contact-id']),
47 if (! DBM::is_result($r)) {
50 if (! $r[0]['self']) {
51 $remote_owner = $r[0];
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",
61 if (DBM::is_result($r))
65 logger('like: no owner');
70 $remote_owner = $owner;
73 // This represents the person posting
75 if ((local_user()) && (local_user() == $owner_uid)) {
78 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
79 intval($_SESSION['visitor_id']),
82 if (DBM::is_result($r))
89 $uri = item_new_uri($a->get_hostname(),$owner_uid);
91 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
92 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
93 $link = xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
94 $body = $item['body'];
101 <id>{$item['uri']}</id>
104 <content>$body</content>
107 $bodyverb = t('%1$s is following %2$s\'s %3$s');
109 if (! isset($bodyverb)) {
115 $arr['guid'] = get_guid(32);
117 $arr['uid'] = $owner_uid;
118 $arr['contact-id'] = $contact['id'];
119 $arr['type'] = 'activity';
120 $arr['wall'] = $item['wall'];
122 $arr['gravity'] = GRAVITY_LIKE;
123 $arr['parent'] = $item['id'];
124 $arr['parent-uri'] = $item['uri'];
125 $arr['thr-parent'] = $item['uri'];
126 $arr['owner-name'] = $remote_owner['name'];
127 $arr['owner-link'] = $remote_owner['url'];
128 $arr['owner-avatar'] = $remote_owner['thumb'];
129 $arr['author-name'] = $contact['name'];
130 $arr['author-link'] = $contact['url'];
131 $arr['author-avatar'] = $contact['thumb'];
133 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
134 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
135 $plink = '[url=' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
136 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
138 $arr['verb'] = $activity;
139 $arr['object-type'] = $objtype;
140 $arr['object'] = $obj;
141 $arr['allow_cid'] = $item['allow_cid'];
142 $arr['allow_gid'] = $item['allow_gid'];
143 $arr['deny_cid'] = $item['deny_cid'];
144 $arr['deny_gid'] = $item['deny_gid'];
147 $arr['last-child'] = 0;
149 $post_id = item_store($arr);
151 if (! $item['visible']) {
152 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
158 $arr['id'] = $post_id;
160 call_hooks('post_local_end', $arr);