]> git.mxchange.org Git - friendica.git/blob - mod/subthread.php
Cleanup /format pre-move
[friendica.git] / mod / subthread.php
1 <?php
2
3 require_once('include/security.php');
4 require_once('include/bbcode.php');
5 require_once('include/items.php');
6
7 function subthread_content(App $a) {
8
9         if(! local_user() && ! remote_user()) {
10                 return;
11         }
12
13         $activity = ACTIVITY_FOLLOW;
14
15         $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
16
17         $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
18                 dbesc($item_id),
19                 dbesc($item_id)
20         );
21
22         if(! $item_id || (! dbm::is_result($r))) {
23                 logger('subthread: no item ' . $item_id);
24                 return;
25         }
26
27         $item = $r[0];
28
29         $owner_uid = $item['uid'];
30
31         if(! can_write_wall($a,$owner_uid)) {
32                 return;
33         }
34
35         $remote_owner = null;
36
37         if(! $item['wall']) {
38                 // The top level post may have been written by somebody on another system
39                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
40                         intval($item['contact-id']),
41                         intval($item['uid'])
42                 );
43                 if (! dbm::is_result($r)) {
44                         return;
45                 }
46                 if (! $r[0]['self']) {
47                         $remote_owner = $r[0];
48                 }
49         }
50
51         // this represents the post owner on this system.
52
53         $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
54                 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
55                 intval($owner_uid)
56         );
57         if (dbm::is_result($r))
58                 $owner = $r[0];
59
60         if (! $owner) {
61                 logger('like: no owner');
62                 return;
63         }
64
65         if (! $remote_owner)
66                 $remote_owner = $owner;
67
68
69         // This represents the person posting
70
71         if ((local_user()) && (local_user() == $owner_uid)) {
72                 $contact = $owner;
73         } else {
74                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
75                         intval($_SESSION['visitor_id']),
76                         intval($owner_uid)
77                 );
78                 if (dbm::is_result($r))
79                         $contact = $r[0];
80         }
81         if (! $contact) {
82                 return;
83         }
84
85         $uri = item_new_uri($a->get_hostname(),$owner_uid);
86
87         $post_type = (($item['resource-id']) ? t('photo') : t('status'));
88         $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
89         $link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
90         $body = $item['body'];
91
92         $obj = <<< EOT
93
94         <object>
95                 <type>$objtype</type>
96                 <local>1</local>
97                 <id>{$item['uri']}</id>
98                 <link>$link</link>
99                 <title></title>
100                 <content>$body</content>
101         </object>
102 EOT;
103         $bodyverb = t('%1$s is following %2$s\'s %3$s');
104
105         if (! isset($bodyverb)) {
106                 return;
107         }
108
109         $arr = array();
110
111         $arr['guid'] = get_guid(32);
112         $arr['uri'] = $uri;
113         $arr['uid'] = $owner_uid;
114         $arr['contact-id'] = $contact['id'];
115         $arr['type'] = 'activity';
116         $arr['wall'] = $item['wall'];
117         $arr['origin'] = 1;
118         $arr['gravity'] = GRAVITY_LIKE;
119         $arr['parent'] = $item['id'];
120         $arr['parent-uri'] = $item['uri'];
121         $arr['thr-parent'] = $item['uri'];
122         $arr['owner-name'] = $remote_owner['name'];
123         $arr['owner-link'] = $remote_owner['url'];
124         $arr['owner-avatar'] = $remote_owner['thumb'];
125         $arr['author-name'] = $contact['name'];
126         $arr['author-link'] = $contact['url'];
127         $arr['author-avatar'] = $contact['thumb'];
128
129         $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
130         $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
131         $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
132         $arr['body'] =  sprintf( $bodyverb, $ulink, $alink, $plink );
133
134         $arr['verb'] = $activity;
135         $arr['object-type'] = $objtype;
136         $arr['object'] = $obj;
137         $arr['allow_cid'] = $item['allow_cid'];
138         $arr['allow_gid'] = $item['allow_gid'];
139         $arr['deny_cid'] = $item['deny_cid'];
140         $arr['deny_gid'] = $item['deny_gid'];
141         $arr['visible'] = 1;
142         $arr['unseen'] = 1;
143         $arr['last-child'] = 0;
144
145         $post_id = item_store($arr);
146
147         if (! $item['visible']) {
148                 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
149                         intval($item['id']),
150                         intval($owner_uid)
151                 );
152         }
153
154         $arr['id'] = $post_id;
155
156         call_hooks('post_local_end', $arr);
157
158         killme();
159
160 }
161
162