3 require_once('include/security.php');
4 require_once('include/bbcode.php');
5 require_once('include/items.php');
8 function subthread_content(App &$a) {
10 if(! local_user() && ! remote_user()) {
14 $activity = ACTIVITY_FOLLOW;
16 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
18 $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
23 if(! $item_id || (! dbm::is_result($r))) {
24 logger('subthread: no item ' . $item_id);
30 $owner_uid = $item['uid'];
32 if(! can_write_wall($a,$owner_uid)) {
39 // The top level post may have been written by somebody on another system
40 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
41 intval($item['contact-id']),
44 if (! dbm::is_result($r)) {
47 if (! $r[0]['self']) {
48 $remote_owner = $r[0];
52 // this represents the post owner on this system.
54 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
55 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
58 if (dbm::is_result($r))
62 logger('like: no owner');
67 $remote_owner = $owner;
70 // This represents the person posting
72 if ((local_user()) && (local_user() == $owner_uid)) {
76 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
77 intval($_SESSION['visitor_id']),
80 if (dbm::is_result($r))
87 $uri = item_new_uri($a->get_hostname(),$owner_uid);
89 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
90 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
91 $link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
92 $body = $item['body'];
99 <id>{$item['uri']}</id>
102 <content>$body</content>
105 $bodyverb = t('%1$s is following %2$s\'s %3$s');
107 if (! isset($bodyverb)) {
113 $arr['guid'] = get_guid(32);
115 $arr['uid'] = $owner_uid;
116 $arr['contact-id'] = $contact['id'];
117 $arr['type'] = 'activity';
118 $arr['wall'] = $item['wall'];
120 $arr['gravity'] = GRAVITY_LIKE;
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=' . App::get_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'];
145 $arr['last-child'] = 0;
147 $post_id = item_store($arr);
149 if (! $item['visible']) {
150 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
156 $arr['id'] = $post_id;
158 call_hooks('post_local_end', $arr);