3 require_once('simplepie/simplepie.inc');
4 require_once('include/items.php');
5 function dfrn_notify_post(&$a) {
7 $dfrn_id = ((x($_POST,'dfrn_id')) ? notags(trim($_POST['dfrn_id'])) : '');
8 $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0);
9 $challenge = ((x($_POST,'challenge')) ? notags(trim($_POST['challenge'])) : '');
10 $data = ((x($_POST,'data')) ? $_POST['data'] : '');
11 $key = ((x($_POST,'key')) ? $_POST['key'] : '');
12 $dissolve = ((x($_POST,'dissolve')) ? intval($_POST['dissolve']) : 0);
13 $perm = ((x($_POST,'perm')) ? notags(trim($_POST['perm'])) : 'r');
16 if($dfrn_version >= 2.21) {
17 $writable = (($perm === 'rw') ? 1 : 0);
21 if(strpos($dfrn_id,':') == 1) {
22 $direction = intval(substr($dfrn_id,0,1));
23 $dfrn_id = substr($dfrn_id,2);
26 $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
31 logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge);
35 $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1",
40 // find the local user who owns this relationship.
45 $sql_extra = sprintf(" AND ( `issued-id` = '%s' OR `dfrn-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
48 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
51 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
59 $r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
60 `contact`.`pubkey` AS `cpubkey`,
61 `contact`.`prvkey` AS `cprvkey`,
62 `contact`.`thumb` AS `thumb`,
63 `contact`.`url` as `url`,
64 `contact`.`name` as `senderName`,
67 LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
68 WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0
69 AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
74 logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id);
79 // $importer in this case contains the contact record for the remote contact joined with the user record of our user.
83 if(($writable != (-1)) && ($writable != $importer['writable'])) {
84 q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
86 intval($importer['id'])
88 $importer['writable'] = $writable;
91 logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']);
92 logger('dfrn_notify: data: ' . $data, LOGGER_DATA);
97 * Relationship is dissolved permanently
100 require_once('include/Contact.php');
101 contact_remove($importer['id']);
102 logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']);
108 $rawkey = hex2bin(trim($key));
109 logger('rino: md5 raw key: ' . md5($rawkey));
112 if($dfrn_version >= 2.1) {
113 if((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) {
114 openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']);
117 openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']);
121 if((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) {
122 openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']);
125 openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']);
129 logger('rino: received key : ' . $final_key);
130 $data = aes_decrypt(hex2bin($data),$final_key);
131 logger('rino: decrypted data: ' . $data, LOGGER_DATA);
135 if($importer['readonly']) {
136 // We aren't receiving stuff from this person. But we will quietly ignore them
137 // rather than a blatant "go away" message.
138 logger('dfrn_notify: ignoring');
143 // Consume notification feed. This may differ from consuming a public feed in several ways
144 // - might contain email
145 // - might contain remote followup to our message
146 // - in which case we need to accept it and then notify other conversants
147 // - we may need to send various email notifications
149 $feed = new SimplePie();
150 $feed->set_raw_data($data);
151 $feed->enable_order_by_date(false);
156 $rawmail = $feed->get_feed_tags( NAMESPACE_DFRN, 'mail' );
157 if(isset($rawmail[0]['child'][NAMESPACE_DFRN])) {
159 logger('dfrn_notify: private message received');
162 $base = $rawmail[0]['child'][NAMESPACE_DFRN];
165 $msg['uid'] = $importer['importer_uid'];
166 $msg['from-name'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['name'][0]['data']));
167 $msg['from-photo'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']));
168 $msg['from-url'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['uri'][0]['data']));
169 $msg['contact-id'] = $importer['id'];
170 $msg['title'] = notags(unxmlify($base['subject'][0]['data']));
171 $msg['body'] = escape_tags(unxmlify($base['content'][0]['data']));
174 $msg['uri'] = notags(unxmlify($base['id'][0]['data']));
175 $msg['parent-uri'] = notags(unxmlify($base['in-reply-to'][0]['data']));
176 $msg['created'] = datetime_convert(notags(unxmlify('UTC','UTC',$base['sentdate'][0]['data'])));
180 $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg))
181 . "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
183 // send email notification if requested.
185 require_once('bbcode.php');
186 if($importer['notify-flags'] & NOTIFY_MAIL) {
188 push_lang($importer['language']);
190 // name of the automated email sender
191 $msg['notificationfromname'] = t('Administrator');
192 // noreply address to send from
193 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
196 // process the message body to display properly in text mode
197 // 1) substitute a \n character for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
198 // 2) remove escape slashes
199 // 3) decode any bbcode from the message editor
200 // 4) decode any encoded html tags
201 // 5) remove html tags
203 = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",$msg['body']))),ENT_QUOTES,'UTF-8'));
206 // process the message body to display properly in text mode
207 // 1) substitute a <br /> tag for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
208 // 2) remove escape slashes
209 // 3) decode any bbcode from the message editor
210 // 4) decode any encoded html tags
212 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$msg['body']))));
214 // load the template for private message notifications
215 $tpl = get_intltext_template('mail_received_html_body_eml.tpl');
216 $email_html_body_tpl = replace_macros($tpl,array(
217 '$siteName' => $a->config['sitename'], // name of this site
218 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
219 '$thumb' => $importer['thumb'], // thumbnail url for sender icon
220 '$email' => $importer['email'], // email address to send to
221 '$url' => $importer['url'], // full url for the site
222 '$from' => $msg['from-name'], // name of the person sending the message
223 '$title' => stripslashes($msg['title']), // subject of the message
224 '$htmlversion' => $msg['htmlversion'], // html version of the message
225 '$mimeboundary' => $msg['mimeboundary'], // mime message divider
226 '$hostname' => $a->get_hostname() // name of this host
229 // load the template for private message notifications
230 $tpl = get_intltext_template('mail_received_text_body_eml.tpl');
231 $email_text_body_tpl = replace_macros($tpl,array(
232 '$siteName' => $a->config['sitename'], // name of this site
233 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
234 '$thumb' => $importer['thumb'], // thumbnail url for sender icon
235 '$email' => $importer['email'], // email address to send to
236 '$url' => $importer['url'], // full url for the site
237 '$from' => $msg['from-name'], // name of the person sending the message
238 '$title' => stripslashes($msg['title']), // subject of the message
239 '$textversion' => $msg['textversion'], // text version of the message
240 '$mimeboundary' => $msg['mimeboundary'], // mime message divider
241 '$hostname' => $a->get_hostname() // name of this host
244 // use the EmailNotification library to send the message
245 require_once("include/EmailNotification.php");
246 EmailNotification::sendTextHtmlEmail(
247 $msg['notificationfromname'],
248 $msg['notificationfromemail'],
249 $msg['notificationfromemail'],
251 t('New mail received at ') . $a->config['sitename'],
252 $email_html_body_tpl,
262 logger('dfrn_notify: feed item count = ' . $feed->get_item_quantity());
264 // process any deleted entries
266 $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
267 if(is_array($del_entries) && count($del_entries)) {
268 foreach($del_entries as $dentry) {
270 if(isset($dentry['attribs']['']['ref'])) {
271 $uri = $dentry['attribs']['']['ref'];
273 if(isset($dentry['attribs']['']['when'])) {
274 $when = $dentry['attribs']['']['when'];
275 $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
278 $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
282 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
284 intval($importer['importer_uid']),
285 intval($importer['id'])
291 if(! $item['deleted'])
292 logger('dfrn_notify: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
294 if($item['uri'] == $item['parent-uri']) {
295 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
296 WHERE `parent-uri` = '%s' AND `uid` = %d",
298 dbesc(datetime_convert()),
300 intval($importer['importer_uid'])
304 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
305 WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
307 dbesc(datetime_convert()),
309 intval($importer['importer_uid'])
311 if($item['last-child']) {
312 // ensure that last-child is set in case the comment that had it just got wiped.
313 q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
314 dbesc(datetime_convert()),
315 dbesc($item['parent-uri']),
318 // who is the last child now?
319 $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d
320 ORDER BY `created` DESC LIMIT 1",
321 dbesc($item['parent-uri']),
322 intval($importer['importer_uid'])
325 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
337 foreach($feed->get_items() as $item) {
340 $item_id = $item->get_id();
341 $rawthread = $item->get_item_tags( NAMESPACE_THREAD, 'in-reply-to');
342 if(isset($rawthread[0]['attribs']['']['ref'])) {
344 $parent_uri = $rawthread[0]['attribs']['']['ref'];
348 if($feed->get_item_quantity() == 1) {
349 logger('dfrn_notify: received remote comment');
351 // remote reply to our post. Import and then notify everybody else.
352 $datarray = get_atom_elements($feed,$item);
353 $datarray['type'] = 'remote-comment';
354 $datarray['wall'] = 1;
355 $datarray['parent-uri'] = $parent_uri;
356 $datarray['uid'] = $importer['importer_uid'];
357 $datarray['contact-id'] = $importer['id'];
358 if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
360 $datarray['type'] = 'activity';
361 $datarray['gravity'] = GRAVITY_LIKE;
362 $datarray['last-child'] = 0;
364 $posted_id = item_store($datarray);
368 $r = q("SELECT `parent` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
370 intval($importer['importer_uid'])
373 $parent = $r[0]['parent'];
376 $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
377 dbesc(datetime_convert()),
378 intval($importer['importer_uid']),
379 intval($r[0]['parent'])
382 $r2 = q("UPDATE `item` SET `last-child` = 1, `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
383 dbesc(datetime_convert()),
384 intval($importer['importer_uid']),
389 if($posted_id && $parent) {
391 proc_run('php',"include/notifier.php","comment-import","$posted_id");
393 if((! $is_like) && ($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {
394 push_lang($importer['language']);
395 require_once('bbcode.php');
396 $from = stripslashes($datarray['author-name']);
398 // name of the automated email sender
399 $msg['notificationfromname'] = stripslashes($datarray['author-name']);;
400 // noreply address to send from
401 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
404 // process the message body to display properly in text mode
406 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
409 // process the message body to display properly in text mode
411 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
413 // load the template for private message notifications
414 $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
415 $email_html_body_tpl = replace_macros($tpl,array(
416 '$sitename' => $a->config['sitename'], // name of this site
417 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
418 '$thumb' => $datarray['author-avatar'], // thumbnail url for sender icon
419 '$email' => $importer['email'], // email address to send to
420 '$url' => $datarray['author-link'], // full url for the site
421 '$from' => $from, // name of the person sending the message
422 '$body' => 'q1' .$msg['htmlversion'], // html version of the message
423 '$display' => $a->get_baseurl() . '/display/' . $importer['nick'] . '/' . $posted_id,
426 // load the template for private message notifications
427 $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
428 $email_text_body_tpl = replace_macros($tpl,array(
429 '$sitename' => $a->config['sitename'], // name of this site
430 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
431 '$thumb' => $datarray['author-avatar'], // thumbnail url for sender icon
432 '$email' => $importer['email'], // email address to send to
433 '$url' => $datarray['author-link'], // full url for the site
434 '$from' => $from, // name of the person sending the message
435 '$body' => $msg['textversion'], // text version of the message
436 '$display' => $a->get_baseurl() . '/display/' . $importer['nick'] . '/' . $posted_id,
439 // use the EmailNotification library to send the message
440 require_once("include/EmailNotification.php");
441 EmailNotification::sendTextHtmlEmail(
442 $msg['notificationfromname'],
443 t("Administrator@") . $a->get_hostname(),
444 t("noreply") . '@' . $a->get_hostname(),
446 $from . t(" commented on an item at ") . $a->config['sitename'],
447 $email_html_body_tpl,
459 // regular comment that is part of this total conversation. Have we seen it? If not, import it.
461 $item_id = $item->get_id();
462 $datarray = get_atom_elements($feed,$item);
464 $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
466 intval($importer['importer_uid'])
469 // Update content if 'updated' changes
472 if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
473 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
474 dbesc($datarray['body']),
475 dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
477 intval($importer['importer_uid'])
481 // update last-child if it changes
483 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
484 if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
485 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
486 dbesc(datetime_convert()),
488 intval($importer['importer_uid'])
490 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
491 intval($allow[0]['data']),
492 dbesc(datetime_convert()),
494 intval($importer['importer_uid'])
500 $datarray['parent-uri'] = $parent_uri;
501 $datarray['uid'] = $importer['importer_uid'];
502 $datarray['contact-id'] = $importer['id'];
503 if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
504 $datarray['type'] = 'activity';
505 $datarray['gravity'] = GRAVITY_LIKE;
507 $r = item_store($datarray);
509 // find out if our user is involved in this conversation and wants to be notified.
511 if(($datarray['type'] != 'activity') && ($importer['notify-flags'] & NOTIFY_COMMENT)) {
513 $myconv = q("SELECT `author-link`, `author-avatar` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
515 intval($importer['importer_uid'])
518 $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
519 foreach($myconv as $conv) {
520 if(! link_compare($conv['author-link'],$importer_url))
523 push_lang($importer['language']);
524 require_once('bbcode.php');
525 $from = stripslashes($datarray['author-name']);
527 // name of the automated email sender
528 $msg['notificationfromname'] = stripslashes($datarray['author-name']);;
529 // noreply address to send from
530 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
533 // process the message body to display properly in text mode
535 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
538 // process the message body to display properly in text mode
540 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
542 // load the template for private message notifications
543 $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
544 $email_html_body_tpl = replace_macros($tpl,array(
545 '$sitename' => $a->config['sitename'], // name of this site
546 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
547 '$thumb' => $conv['author-avatar'], // thumbnail url for sender icon
548 '$url' => $conv['author-link'], // full url for the site
549 '$from' => $from, // name of the person sending the message
550 '$body' => $msg['htmlversion'], // html version of the message
551 '$display' => $a->get_baseurl() . '/display/' . $importer['nick'] . '/' . $posted_id,
554 // load the template for private message notifications
555 $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
556 $email_text_body_tpl = replace_macros($tpl,array(
557 '$sitename' => $a->config['sitename'], // name of this site
558 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
559 '$thumb' => $conv['author-avatar'], // thumbnail url for sender icon
560 '$url' => $conv['author-link'], // full url for the site
561 '$from' => $from, // name of the person sending the message
562 '$body' => $msg['textversion'], // text version of the message
563 '$display' => $a->get_baseurl() . '/display/' . $importer['nick'] . '/' . $posted_id,
566 // use the EmailNotification library to send the message
567 require_once("include/EmailNotification.php");
568 EmailNotification::sendTextHtmlEmail(
569 $msg['notificationfromname'],
570 t("Administrator@") . $a->get_hostname(),
571 t("noreply") . '@' . $a->get_hostname(),
573 $from . t(" commented on an item at ") . $a->config['sitename'],
574 $email_html_body_tpl,
588 // Head post of a conversation. Have we seen it? If not, import it.
591 $item_id = $item->get_id();
592 $datarray = get_atom_elements($feed,$item);
594 $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
596 intval($importer['importer_uid'])
599 // Update content if 'updated' changes
602 if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
603 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
604 dbesc($datarray['body']),
605 dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
607 intval($importer['importer_uid'])
611 // update last-child if it changes
613 $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
614 if($allow && $allow[0]['data'] != $r[0]['last-child']) {
615 $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
616 intval($allow[0]['data']),
617 dbesc(datetime_convert()),
619 intval($importer['importer_uid'])
625 $datarray['parent-uri'] = $item_id;
626 $datarray['uid'] = $importer['importer_uid'];
627 $datarray['contact-id'] = $importer['id'];
628 $r = item_store($datarray);
639 function dfrn_notify_content(&$a) {
641 if(x($_GET,'dfrn_id')) {
643 // initial communication from external contact, $direction is their direction.
644 // If this is a duplex communication, ours will be the opposite.
646 $dfrn_id = notags(trim($_GET['dfrn_id']));
647 $dfrn_version = (float) $_GET['dfrn_version'];
649 logger('dfrn_notify: new notification dfrn_id=' . $dfrn_id);
652 if(strpos($dfrn_id,':') == 1) {
653 $direction = intval(substr($dfrn_id,0,1));
654 $dfrn_id = substr($dfrn_id,2);
657 $hash = random_string();
661 $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
663 $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` )
664 VALUES( '%s', '%s', %d ) ",
670 logger('dfrn_notify: challenge=' . $hash );
675 $sql_extra = sprintf(" AND ( `issued-id` = '%s' OR `dfrn-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
679 $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
680 $my_id = '1:' . $dfrn_id;
683 $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
684 $my_id = '0:' . $dfrn_id;
691 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
692 WHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `user`.`nickname` = '%s' $sql_extra LIMIT 1",
701 $id_str = $my_id . '.' . mt_rand(1000,9999);
703 if((($r[0]['duplex']) && strlen($r[0]['prvkey'])) || (! strlen($r[0]['pubkey']))) {
704 openssl_private_encrypt($hash,$challenge,$r[0]['prvkey']);
705 openssl_private_encrypt($id_str,$encrypted_id,$r[0]['prvkey']);
708 openssl_public_encrypt($hash,$challenge,$r[0]['pubkey']);
709 openssl_public_encrypt($id_str,$encrypted_id,$r[0]['pubkey']);
712 $challenge = bin2hex($challenge);
713 $encrypted_id = bin2hex($encrypted_id);
715 $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
717 $rino_enable = get_config('system','rino_encrypt');
723 header("Content-type: text/xml");
725 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n"
726 . '<dfrn_notify>' . "\r\n"
727 . "\t" . '<status>' . $status . '</status>' . "\r\n"
728 . "\t" . '<dfrn_version>' . DFRN_PROTOCOL_VERSION . '</dfrn_version>' . "\r\n"
729 . "\t" . '<rino>' . $rino . '</rino>' . "\r\n"
730 . "\t" . '<dfrn_id>' . $encrypted_id . '</dfrn_id>' . "\r\n"
731 . "\t" . '<challenge>' . $challenge . '</challenge>' . "\r\n"
732 . '</dfrn_notify>' . "\r\n" ;