]> git.mxchange.org Git - friendica.git/blob - mod/subthread.php
Merge pull request #2158 from annando/1512-vier-fonts
[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
8 function subthread_content(&$a) {
9
10         if(! local_user() && ! remote_user()) {
11                 return;
12         }
13
14         $activity = ACTIVITY_FOLLOW;
15
16         $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
17
18         $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
19                 dbesc($item_id),
20                 dbesc($item_id)
21         );
22
23         if(! $item_id || (! count($r))) {
24                 logger('subthread: no item ' . $item_id);
25                 return;
26         }
27
28         $item = $r[0];
29
30         $owner_uid = $item['uid'];
31
32         if(! can_write_wall($a,$owner_uid)) {
33                 return;
34         }
35
36         $remote_owner = null;
37
38         if(! $item['wall']) {
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']),
42                         intval($item['uid'])
43                 );
44                 if(! count($r))
45                         return;
46                 if(! $r[0]['self'])
47                         $remote_owner = $r[0];
48         }
49
50         // this represents the post owner on this system. 
51
52         $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
53                 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
54                 intval($owner_uid)
55         );
56         if(count($r))
57                 $owner = $r[0];
58
59         if(! $owner) {
60                 logger('like: no owner');
61                 return;
62         }
63
64         if(! $remote_owner)
65                 $remote_owner = $owner;
66
67
68         // This represents the person posting
69
70         if((local_user()) && (local_user() == $owner_uid)) {
71                 $contact = $owner;
72         }
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(count($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_PHOTO : ACTIVITY_OBJ_NOTE );
89         $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->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         $arr = array();
109
110         $arr['uri'] = $uri;
111         $arr['uid'] = $owner_uid;
112         $arr['contact-id'] = $contact['id'];
113         $arr['type'] = 'activity';
114         $arr['wall'] = $item['wall'];
115         $arr['origin'] = 1;
116         $arr['gravity'] = GRAVITY_LIKE;
117         $arr['parent'] = $item['id'];
118         $arr['parent-uri'] = $item['uri'];
119         $arr['thr-parent'] = $item['uri'];
120         $arr['owner-name'] = $remote_owner['name'];
121         $arr['owner-link'] = $remote_owner['url'];
122         $arr['owner-avatar'] = $remote_owner['thumb'];
123         $arr['author-name'] = $contact['name'];
124         $arr['author-link'] = $contact['url'];
125         $arr['author-avatar'] = $contact['thumb'];
126         
127         $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
128         $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
129         $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
130         $arr['body'] =  sprintf( $bodyverb, $ulink, $alink, $plink );
131
132         $arr['verb'] = $activity;
133         $arr['object-type'] = $objtype;
134         $arr['object'] = $obj;
135         $arr['allow_cid'] = $item['allow_cid'];
136         $arr['allow_gid'] = $item['allow_gid'];
137         $arr['deny_cid'] = $item['deny_cid'];
138         $arr['deny_gid'] = $item['deny_gid'];
139         $arr['visible'] = 1;
140         $arr['unseen'] = 1;
141         $arr['last-child'] = 0;
142
143         $post_id = item_store($arr);
144
145         if(! $item['visible']) {
146                 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
147                         intval($item['id']),
148                         intval($owner_uid)
149                 );
150         }
151
152         $arr['id'] = $post_id;
153
154         call_hooks('post_local_end', $arr);
155
156         killme();
157
158 }
159
160