4 require_once("boot.php");
8 @include(".htconfig.php");
9 require_once("dba.php");
10 $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
11 unset($db_host, $db_user, $db_pass, $db_data);
13 require_once("session.php");
14 require_once("datetime.php");
20 $a->set_baseurl($argv[1]);
27 $item_id = intval($argv[3]);
34 $recipients = array();
38 $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
44 $parent = $r[0]['parent'];
46 $updated = $r[0]['edited'];
48 $items = q("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id` ASC",
55 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
65 require_once('include/group.php');
69 if($parent['type'] == 'remote') {
70 // local followup to remote post
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 ) AND `blocked` = 0 AND `pending` = 0");
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($a->get_baseurl()),
117 '$feed_title' => xmlify($owner['name']),
118 '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC',
119 $updated . '+00:00' , 'Y-m-d\TH:i:s\Z')) ,
120 '$name' => xmlify($owner['name']),
121 '$profile_page' => xmlify($owner['url']),
122 '$photo' => xmlify($owner['photo'])
126 foreach($items as $item) {
127 if($item['id'] == $item_id) {
128 $atom .= replace_macros($cmnt_template, array(
129 '$name' => xmlify($owner['name']),
130 '$profile_page' => xmlify($owner['url']),
131 '$thumb' => xmlify($owner['thumb']),
132 '$item_id' => xmlify($item['uri']),
133 '$title' => xmlify($item['title']),
134 '$published' => xmlify(datetime_convert('UTC', 'UTC',
135 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
136 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
137 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
138 '$content' =>xmlify($item['body']),
139 '$parent_id' => xmlify($item['parent-uri']),
140 '$comment_allow' => 0
146 foreach($items as $item) {
147 if($item['deleted']) {
148 $atom .= replace_macros($tomb_template, array(
149 '$id' => xmlify($item['uri']),
150 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
151 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z'))
155 foreach($contacts as $contact) {
156 if($item['contact-id'] == $contact['id']) {
157 if($item['parent'] == $item['id']) {
158 $atom .= replace_macros($item_template, array(
159 '$name' => xmlify($contact['name']),
160 '$profile_page' => xmlify($contact['url']),
161 '$thumb' => xmlify($contact['thumb']),
162 '$owner_name' => xmlify($item['owner-name']),
163 '$owner_profile_page' => xmlify($item['owner-link']),
164 '$owner_thumb' => xmlify($item['owner-avatar']),
165 '$item_id' => xmlify($item['uri']),
166 '$title' => xmlify($item['title']),
167 '$published' => xmlify(datetime_convert('UTC', 'UTC',
168 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
169 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
170 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
171 '$content' =>xmlify($item['body']),
172 '$comment_allow' => (($item['last-child'] && strlen($contact['dfrn-id'])) ? 1 : 0)
176 $atom .= replace_macros($cmnt_template, array(
177 '$name' => xmlify($contact['name']),
178 '$profile_page' => xmlify($contact['url']),
179 '$thumb' => xmlify($contact['thumb']),
180 '$item_id' => xmlify($item['uri']),
181 '$title' => xmlify($item['title']),
182 '$published' => xmlify(datetime_convert('UTC', 'UTC',
183 $item['created'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
184 '$updated' => xmlify(datetime_convert('UTC', 'UTC',
185 $item['edited'] . '+00:00' , 'Y-m-d\TH:i:s\Z')),
186 '$content' =>xmlify($item['body']),
187 '$parent_id' => xmlify($item['parent-uri']),
188 '$comment_allow' => (($item['last-child']) ? 1 : 0)
196 $atom .= "</feed>\r\n";
198 // create a clone of this feed but with comments disabled to send to those who can't respond.
200 $atom_nowrite = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
204 $recip_str = $parent['contact-id'];
206 $recip_str = implode(', ', $recipients);
209 $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) ",
221 if(! strlen($rr['dfrn-id']))
226 $url = $rr['notify'] . '?dfrn_id=' . $rr['dfrn-id'];
228 $xml = fetch_url($url);
233 $res = simplexml_load_string($xml);
235 if((intval($res->status) != 0) || (! strlen($res->challenge)) || ($res->dfrn_id != $rr['dfrn-id']))
240 $postvars['dfrn_id'] = $rr['dfrn-id'];
241 $challenge = hex2bin($res->challenge);
243 openssl_public_decrypt($challenge,$postvars['challenge'],$rr['pubkey']);
245 if(strlen($rr['dfrn-id']) && (! ($rr['blocked']) || ($rr['readonly'])))
246 $postvars['data'] = $atom;
248 $postvars['data'] = $atom_nowrite;
250 $xml = post_url($rr['notify'],$postvars);