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, $install);
10 unset($db_host, $db_user, $db_pass, $db_data);
12 require_once("session.php");
13 require_once("datetime.php");
15 // FIXME - generalise for other content, probably create a notify queue in
16 // the db with type and recipient list
21 $baseurl = trim(hex2bin($argv[1]));
28 $item_id = intval($argv[3]);
35 $recipients = array();
39 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
45 $parent = $r[0]['parent'];
47 $updated = $r[0]['edited'];
49 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
56 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
66 require_once('include/group.php');
70 if(strlen($parent['remote-id'])) {
72 $conversant_str = dbesc($parent['contact-id']);
77 $allow_people = expand_acl($parent['allow_cid']);
78 $allow_groups = expand_groups(expand_acl($parent['allow_gid']));
79 $deny_people = expand_acl($parent['deny_cid']);
80 $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
82 $conversants = array();
84 foreach($items as $item) {
85 $recipients[] = $item['contact-id'];
86 $conversants[] = $item['contact-id'];
89 $conversants = array_unique($conversants,SORT_NUMERIC);
92 $recipients = array_unique(array_merge($recipients,$allow_people,$allow_groups),SORT_NUMERIC);
93 $deny = array_unique(array_merge($deny_people,$deny_groups),SORT_NUMERIC);
94 $recipients = array_diff($recipients,$deny);
96 $conversant_str = dbesc(implode(', ',$conversants));
99 $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) ");
107 $feed_template = file_get_contents('view/atom_feed.tpl');
108 $tomb_template = file_get_contents('view/atom_tomb.tpl');
109 $item_template = file_get_contents('view/atom_item.tpl');
110 $cmnt_template = file_get_contents('view/atom_cmnt.tpl');
115 $atom .= replace_macros($feed_template, array(
116 '$feed_id' => xmlify($baseurl),
117 '$feed_title' => xmlify($owner['name']),
118 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
119 '$name' => xmlify($owner['name']),
120 '$profile_page' => xmlify($owner['url']),
121 '$photo' => xmlify($owner['photo'])
125 $atom .= replace_macros($cmnt_template, array(
126 '$name' => xmlify($contact['name']),
127 '$profile_page' => xmlify($contact['url']),
128 '$thumb' => xmlify($contact['thumb']),
129 '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
130 '$title' => xmlify($item['title']),
131 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
132 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
133 '$content' =>xmlify($item['body']),
134 '$parent_id' => xmlify("{$items[0]['remote-id']}"),
135 '$comment_allow' => 0
139 foreach($items as $item) {
140 if($item['deleted']) {
141 $atom .= replace_macros($tomb_template, array(
142 '$id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
143 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
147 foreach($contacts as $contact) {
148 if($item['contact-id'] == $contact['id']) {
149 if($item['parent'] == $item['id']) {
150 $atom .= replace_macros($item_template, array(
151 '$name' => xmlify($contact['name']),
152 '$profile_page' => xmlify($contact['url']),
153 '$thumb' => xmlify($contact['thumb']),
154 '$owner_name' => xmlify($item['owner-name']),
155 '$owner_profile_page' => xmlify($item['owner-link']),
156 '$owner_thumb' => xmlify($item['owner-avatar']),
157 '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
158 '$title' => xmlify($contact['name']),
159 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
160 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
161 '$content' =>xmlify($item['body']),
162 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'] && (! $contact['blocked']))) ? 1 : 0)
166 $atom .= replace_macros($cmnt_template, array(
167 '$name' => xmlify($contact['name']),
168 '$profile_page' => xmlify($contact['url']),
169 '$thumb' => xmlify($contact['thumb']),
170 '$item_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$item['hash']}"),
171 '$title' => xmlify($item['title']),
172 '$published' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
173 '$updated' => xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
174 '$content' =>xmlify($item['body']),
175 '$parent_id' => xmlify("urn:X-dfrn:$baseurl:{$owner['uid']}:{$items[0]['hash']}"),
176 '$comment_allow' => (($item['last-child']) ? 1 : 0)
184 $atom .= "</feed>\r\n";
186 // create a clone of this feed but with comments disabled to send to those who can't respond.
188 $atom_nowrite = str_replace('<dfrn:comment-allow>1</dfrn:comment-allow>','<dfrn:comment-allow>0</dfrn:comment-allow>',$atom);
192 $recip_str = $parent['contact-id'];
194 $recip_str = implode(', ', $recipients);
196 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
208 if(! strlen($rr['dfrn-id']))
210 $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
212 $xml = fetch_url($url);
217 $res = simplexml_load_string($xml);
219 if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
224 $postvars['dfrn_id'] = $rr['dfrn-id'];
225 $challenge = hex2bin($res->challenge);
227 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
229 if(strlen($rr['dfrn-id']) && (! $rr['blocked']))
230 $postvars['data'] = $atom;
232 $postvars['data'] = $atom_nowrite;
235 $xml = post_url($url,$postvars);