3 require_once("boot.php");
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);
13 $debugging = get_config('system','debugging');
15 require_once("session.php");
16 require_once("datetime.php");
17 require_once('include/items.php');
23 $a->set_baseurl(get_config('system','url'));
31 $item_id = intval($argv[2]);
40 $recipients = array();
44 $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
49 $uid = $message[0]['uid'];
50 $recipients[] = $message[0]['contact-id'];
57 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
63 $parent = $r[0]['parent'];
65 $updated = $r[0]['edited'];
67 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
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",
88 require_once('include/group.php');
92 if($parent['type'] === 'remote') {
93 // local followup to remote post
95 $conversant_str = dbesc($parent['contact-id']);
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']));
105 $conversants = array();
107 foreach($items as $item) {
108 $recipients[] = $item['contact-id'];
109 $conversants[] = $item['contact-id'];
112 $conversants = array_unique($conversants,SORT_NUMERIC);
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);
119 $conversant_str = dbesc(implode(', ',$conversants));
124 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
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');
136 $feed_template = load_view_file('view/atom_feed.tpl');
137 $mail_template = load_view_file('view/atom_mail.tpl');
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))
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'])
170 foreach($items as $item) { // there is only one item
172 $verb = construct_verb($item);
173 $actobj = construct_activity($item);
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']),
189 '$verb' => xmlify($verb),
190 '$actobj' => $actobj,
191 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
192 '$content' => xmlify($item['body']),
193 '$parent_id' => xmlify($item['parent-uri']),
194 '$comment_allow' => 0
200 foreach($items as $item) {
201 if($item['deleted']) {
202 $atom .= replace_macros($tomb_template, array(
203 '$id' => xmlify($item['uri']),
204 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME))
208 $contact = get_item_contact($item,$contacts);
212 $verb = construct_verb($item);
213 $actobj = construct_activity($item);
215 if($item['parent'] == $item['id']) {
216 $atom .= replace_macros($item_template, array(
217 '$name' => xmlify($contact['name']),
218 '$profile_page' => xmlify($contact['url']),
219 '$thumb' => xmlify($contact['thumb']),
220 '$owner_name' => xmlify($item['owner-name']),
221 '$owner_profile_page' => xmlify($item['owner-link']),
222 '$owner_thumb' => xmlify($item['owner-avatar']),
223 '$item_id' => xmlify($item['uri']),
224 '$title' => xmlify($item['title']),
225 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
226 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
227 '$location' => xmlify($item['location']),
229 '$verb' => xmlify($verb),
230 '$actobj' => $actobj,
231 '$content' => xmlify($item['body']),
232 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
233 '$comment_allow' => (($item['last-child']) ? 1 : 0)
237 $atom .= replace_macros($cmnt_template, array(
238 '$name' => xmlify($contact['name']),
239 '$profile_page' => xmlify($contact['url']),
240 '$thumb' => xmlify($contact['thumb']),
241 '$item_id' => xmlify($item['uri']),
242 '$title' => xmlify($item['title']),
243 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
244 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , ATOM_TIME)),
245 '$content' => xmlify($item['body']),
246 '$alt' => xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']),
247 '$location' => xmlify($item['location']),
249 '$verb' => xmlify($verb),
250 '$actobj' => $actobj,
251 '$parent_id' => xmlify($item['parent-uri']),
252 '$comment_allow' => (($item['last-child']) ? 1 : 0)
259 $atom .= '</feed>' . "\r\n";
266 $recip_str = $parent['contact-id'];
268 $recip_str = implode(', ', $recipients);
271 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
279 foreach($r as $contact) {
285 switch($contact['network']) {
287 $deliver_status = dfrn_deliver($contact,$atom,$debugging);
293 if(($cmd === 'mail') && ($deliver_status == 0)) {
294 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",