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 '$content' => xmlify($item['body']),
192 '$parent_id' => xmlify($item['parent-uri']),
193 '$comment_allow' => 0
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))
207 $contact = get_item_contact($item,$contacts);
211 $verb = construct_verb($item);
212 $actobj = construct_activity($item);
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']),
228 '$verb' => xmlify($verb),
229 '$actobj' => $actobj,
230 '$content' => xmlify($item['body']),
231 '$comment_allow' => (($item['last-child']) ? 1 : 0)
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']),
246 '$verb' => xmlify($verb),
247 '$actobj' => $actobj,
248 '$parent_id' => xmlify($item['parent-uri']),
249 '$comment_allow' => (($item['last-child']) ? 1 : 0)
256 $atom .= '</feed>' . "\r\n";
263 $recip_str = $parent['contact-id'];
265 $recip_str = implode(', ', $recipients);
268 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
276 foreach($r as $contact) {
282 switch($contact['network']) {
284 $deliver_status = dfrn_deliver($contact,$atom,$debugging);
290 if(($cmd === 'mail') && ($deliver_status == 0)) {
291 $r = q("UPDATE `mail` SET `delivered` = 1 WHERE `id` = %d LIMIT 1",