]> git.mxchange.org Git - friendica.git/blob - mod/subthread.php
Class file relocations
[friendica.git] / mod / subthread.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
6
7 require_once('include/security.php');
8 require_once('include/bbcode.php');
9 require_once('include/items.php');
10
11 function subthread_content(App $a) {
12
13         if(! local_user() && ! remote_user()) {
14                 return;
15         }
16
17         $activity = ACTIVITY_FOLLOW;
18
19         $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
20
21         $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
22                 dbesc($item_id),
23                 dbesc($item_id)
24         );
25
26         if(! $item_id || (! DBM::is_result($r))) {
27                 logger('subthread: no item ' . $item_id);
28                 return;
29         }
30
31         $item = $r[0];
32
33         $owner_uid = $item['uid'];
34
35         if(! can_write_wall($a,$owner_uid)) {
36                 return;
37         }
38
39         $remote_owner = null;
40
41         if(! $item['wall']) {
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']),
45                         intval($item['uid'])
46                 );
47                 if (! DBM::is_result($r)) {
48                         return;
49                 }
50                 if (! $r[0]['self']) {
51                         $remote_owner = $r[0];
52                 }
53         }
54
55         // this represents the post owner on this system.
56
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",
59                 intval($owner_uid)
60         );
61         if (DBM::is_result($r))
62                 $owner = $r[0];
63
64         if (! $owner) {
65                 logger('like: no owner');
66                 return;
67         }
68
69         if (! $remote_owner)
70                 $remote_owner = $owner;
71
72
73         // This represents the person posting
74
75         if ((local_user()) && (local_user() == $owner_uid)) {
76                 $contact = $owner;
77         } else {
78                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
79                         intval($_SESSION['visitor_id']),
80                         intval($owner_uid)
81                 );
82                 if (DBM::is_result($r))
83                         $contact = $r[0];
84         }
85         if (! $contact) {
86                 return;
87         }
88
89         $uri = item_new_uri($a->get_hostname(),$owner_uid);
90
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'];
95
96         $obj = <<< EOT
97
98         <object>
99                 <type>$objtype</type>
100                 <local>1</local>
101                 <id>{$item['uri']}</id>
102                 <link>$link</link>
103                 <title></title>
104                 <content>$body</content>
105         </object>
106 EOT;
107         $bodyverb = t('%1$s is following %2$s\'s %3$s');
108
109         if (! isset($bodyverb)) {
110                 return;
111         }
112
113         $arr = array();
114
115         $arr['guid'] = get_guid(32);
116         $arr['uri'] = $uri;
117         $arr['uid'] = $owner_uid;
118         $arr['contact-id'] = $contact['id'];
119         $arr['type'] = 'activity';
120         $arr['wall'] = $item['wall'];
121         $arr['origin'] = 1;
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'];
132
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 );
137
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'];
145         $arr['visible'] = 1;
146         $arr['unseen'] = 1;
147         $arr['last-child'] = 0;
148
149         $post_id = item_store($arr);
150
151         if (! $item['visible']) {
152                 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d",
153                         intval($item['id']),
154                         intval($owner_uid)
155                 );
156         }
157
158         $arr['id'] = $post_id;
159
160         call_hooks('post_local_end', $arr);
161
162         killme();
163
164 }
165
166