]> git.mxchange.org Git - friendica.git/blob - include/notifier.php
show members of locked conversations
[friendica.git] / include / notifier.php
1 <?php
2
3         require_once("boot.php");
4
5         $a = new App;
6
7         @include(".htconfig.php");
8         require_once("dba.php");
9         $db = new dba($db_host, $db_user, $db_pass, $db_data);
10                 unset($db_host, $db_user, $db_pass, $db_data);
11
12
13         $debugging = get_config('system','debugging');
14
15         require_once("session.php");
16         require_once("datetime.php");
17         require_once('include/items.php');
18
19
20         if($argc < 3)
21                 exit;
22
23         $a->set_baseurl(get_config('system','url'));
24
25         $cmd = $argv[1];
26
27         switch($cmd) {
28
29                 case 'mail':
30                 default:
31                         $item_id = intval($argv[2]);
32                         if(! $item_id)
33                                 killme();
34                         break;
35         }
36
37         if($debugging)
38                 dbg(3);
39
40         $recipients = array();
41
42         if($cmd === 'mail') {
43
44                 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
45                                 intval($item_id)
46                 );
47                 if(! count($message))
48                         killme();
49                 $uid = $message[0]['uid'];
50                 $recipients[] = $message[0]['contact-id'];
51                 $item = $message[0];
52
53         }
54         else {
55                 // find ancestors
56
57                 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
58                         intval($item_id)
59                 );
60                 if(! count($r))
61                         killme();
62
63                 $parent = $r[0]['parent'];
64                 $uid = $r[0]['uid'];
65                 $updated = $r[0]['edited'];
66
67                 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
68                         intval($parent)
69                 );
70
71                 if(! count($items))
72                         killme();
73         }
74
75         $r = q("SELECT `contact`.*, `user`.`nickname` 
76                 FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` 
77                 WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
78                 intval($uid)
79         );
80
81         if(count($r))
82                 $owner = $r[0];
83         else
84                 killme();
85
86         if($cmd != 'mail') {
87
88                 require_once('include/group.php');
89
90                 $parent = $items[0];
91
92                 if($parent['type'] === 'remote') {
93                         // local followup to remote post
94                         $followup = true;
95                         $conversant_str = dbesc($parent['contact-id']);
96                 }
97                 else {
98                         $followup = false;
99
100                         $allow_people = expand_acl($parent['allow_cid']);
101                         $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
102                         $deny_people = expand_acl($parent['deny_cid']);
103                         $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
104
105                         $conversants = array();
106
107                         foreach($items as $item) {
108                                 $recipients[] = $item['contact-id'];
109                                 $conversants[] = $item['contact-id'];
110                         }
111
112                         $conversants = array_unique($conversants,SORT_NUMERIC);
113
114
115                         $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
116                         $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
117                         $recipients = array_diff($recipients,$deny);
118
119                         $conversant_str = dbesc(implode(', ',$conversants));
120
121
122                 }
123
124                 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
125
126                 if( ! count($r))
127                         killme();
128
129                 $contacts = $r;
130
131                 $tomb_template = load_view_file('view/atom_tomb.tpl');
132                 $item_template = load_view_file('view/atom_item.tpl');
133                 $cmnt_template = load_view_file('view/atom_cmnt.tpl');
134         }
135
136         $feed_template = load_view_file('view/atom_feed.tpl');
137         $mail_template = load_view_file('view/atom_mail.tpl');
138
139         $atom = '';
140
141
142         $atom .= replace_macros($feed_template, array(
143                         '$feed_id'      => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
144                         '$feed_title'   => xmlify($owner['name']),
145                         '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
146                         '$name'         => xmlify($owner['name']),
147                         '$profile_page' => xmlify($owner['url']),
148                         '$photo'        => xmlify($owner['photo']),
149                         '$thumb'        => xmlify($owner['thumb']),
150                         '$picdate'      => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
151                         '$uridate'      => xmlify(datetime_convert('UTC','UTC',$owner['uri-date']    . '+00:00' , ATOM_TIME)) ,
152                         '$namdate'      => xmlify(datetime_convert('UTC','UTC',$owner['name-date']   . '+00:00' , ATOM_TIME))
153         ));
154
155         if($cmd === 'mail') {
156                 $atom .= replace_macros($mail_template, array(
157                         '$name'         => xmlify($owner['name']),
158                         '$profile_page' => xmlify($owner['url']),
159                         '$thumb'        => xmlify($owner['thumb']),
160                         '$item_id'      => xmlify($item['uri']),
161                         '$subject'      => xmlify($item['title']),
162                         '$created'      => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
163                         '$content'      => xmlify($item['body']),
164                         '$parent_id'    => xmlify($item['parent-uri'])
165                 ));
166         }
167         else {
168
169                 if($followup) {
170                         foreach($items as $item) {  // there is only one item
171
172                                 $verb = construct_verb($item);
173                                 $actobj = construct_activity($item);
174
175                                 if($item['id'] == $item_id) {
176                                         $atom .= replace_macros($cmnt_template, array(
177                                                 '$name'               => xmlify($owner['name']),
178                                                 '$profile_page'       => xmlify($owner['url']),
179                                                 '$thumb'              => xmlify($owner['thumb']),
180                                                 '$owner_name'         => xmlify($item['owner-name']),
181                                                 '$owner_profile_page' => xmlify($item['owner-link']),
182                                                 '$owner_thumb'        => xmlify($item['owner-avatar']),
183                                                 '$item_id'            => xmlify($item['uri']),
184                                                 '$title'              => xmlify($item['title']),
185                                                 '$published'          => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
186                                                 '$updated'            => xmlify(datetime_convert('UTC', 'UTC', $item['edited']  . '+00:00' , ATOM_TIME)),
187                                                 '$location'           => xmlify($item['location']),
188                                                 '$type'               => 'text',
189                                                 '$verb'               => xmlify($verb),
190                                                 '$actobj'             => $actobj,
191                                                 '$content'            => xmlify($item['body']),
192                                                 '$parent_id'          => xmlify($item['parent-uri']),
193                                                 '$comment_allow'      => 0
194                                         ));
195                                 }
196                         }
197                 }
198                 else {
199                         foreach($items as $item) {
200                                 if($item['deleted']) {
201                                         $atom .= replace_macros($tomb_template, array(
202                                                 '$id' => xmlify($item['uri']),
203                                                 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME))
204                                         ));
205                                 }
206                                 else {
207                                         $contact = get_item_contact($item,$contacts);
208                                         if(! $contact)
209                                                 continue;
210
211                                         $verb = construct_verb($item);
212                                         $actobj = construct_activity($item);
213
214                                         if($item['parent'] == $item['id']) {
215                                                 $atom .= replace_macros($item_template, array(
216                                                         '$name'               => xmlify($contact['name']),
217                                                         '$profile_page'       => xmlify($contact['url']),
218                                                         '$thumb'              => xmlify($contact['thumb']),
219                                                         '$owner_name'         => xmlify($item['owner-name']),
220                                                         '$owner_profile_page' => xmlify($item['owner-link']),
221                                                         '$owner_thumb'        => xmlify($item['owner-avatar']),
222                                                         '$item_id'            => xmlify($item['uri']),
223                                                         '$title'              => xmlify($item['title']),
224                                                         '$published'          => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
225                                                         '$updated'            => xmlify(datetime_convert('UTC', 'UTC', $item['edited']  . '+00:00' , ATOM_TIME)),
226                                                         '$location'           => xmlify($item['location']),
227                                                         '$type'               => 'text',
228                                                         '$verb'               => xmlify($verb),
229                                                         '$actobj'             => $actobj,
230                                                         '$content'            => xmlify($item['body']),
231                                                         '$comment_allow'      => (($item['last-child']) ? 1 : 0)
232                                                 ));
233                                         }
234                                         else {
235                                                 $atom .= replace_macros($cmnt_template, array(
236                                                         '$name'          => xmlify($contact['name']),
237                                                         '$profile_page'  => xmlify($contact['url']),
238                                                         '$thumb'         => xmlify($contact['thumb']),
239                                                         '$item_id'       => xmlify($item['uri']),
240                                                         '$title'         => xmlify($item['title']),
241                                                         '$published'     => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
242                                                         '$updated'       => xmlify(datetime_convert('UTC', 'UTC', $item['edited']  . '+00:00' , ATOM_TIME)),
243                                                         '$content'       => xmlify($item['body']),
244                                                         '$location'      => xmlify($item['location']),
245                                                         '$type'          => 'text',
246                                                         '$verb'          => xmlify($verb),
247                                                         '$actobj'        => $actobj,
248                                                         '$parent_id'     => xmlify($item['parent-uri']),
249                                                         '$comment_allow' => (($item['last-child']) ? 1 : 0)
250                                                 ));
251                                         }
252                                 }
253                         }
254                 }
255         }
256         $atom .= '</feed>' . "\r\n";
257
258         if($debugging)
259                 echo $atom;
260
261
262         if($followup)
263                 $recip_str = $parent['contact-id'];
264         else
265                 $recip_str = implode(', ', $recipients);
266
267
268         $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
269                 dbesc($recip_str)
270         );
271         if(! count($r))
272                 killme();
273
274         // delivery loop
275
276         foreach($r as $contact) {
277                 if($contact['self'])
278                         continue;
279
280                 $deliver_status = 0;
281
282                 switch($contact['network']) {
283                         case 'dfrn':
284                                 $deliver_status = dfrn_deliver($contact,$atom,$debugging);
285                                 break;
286                         default:
287                                 break;
288                 }
289
290                 if(($cmd === 'mail') && ($deliver_status == 0)) {
291                         $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",
292                                 intval($item_id)
293                         );
294                 }
295         }
296
297         killme();
298