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