+ if(stristr($res, "<status")===false) {
+ // wrong xml! stop here!
+ notice( t('Unexpected response from remote site: ') . EOL . htmlspecialchars($res) . EOL );
+ return;
+ }
+
+ $xml = parse_xml_string($res);
+ $status = (int) $xml->status;
+ $message = unxmlify($xml->message); // human readable text of what may have gone wrong.
+ switch($status) {
+ case 0:
+ info( t("Confirmation completed successfully.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;
+ case 1:
+ // birthday paradox - generate new dfrn-id and fall through.
+ $new_dfrn_id = random_string();
+ $r = q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d",
+ dbesc($new_dfrn_id),
+ intval($contact_id),
+ intval($uid)
+ );
+
+ case 2:
+ notice( t("Temporary failure. Please wait and try again.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;
+
+
+ case 3:
+ notice( t("Introduction failed or was revoked.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;
+ }
+
+ if(($status == 0) && ($intro_id)) {
+
+ // Success. Delete the notification.
+
+ $r = q("DELETE FROM `intro` WHERE `id` = %d AND `uid` = %d",
+ intval($intro_id),
+ intval($uid)
+ );
+
+ }
+
+ if($status != 0)
+ return;
+ }
+
+
+ /*
+ *
+ * We have now established a relationship with the other site.
+ * Let's make our own personal copy of their profile photo so we don't have
+ * to always load it from their site.
+ *
+ * We will also update the contact record with the nature and scope of the relationship.
+ *
+ */
+
+ require_once('include/Photo.php');
+
+ $photos = import_profile_photo($contact['photo'],$uid,$contact_id);
+
+ logger('dfrn_confirm: confirm - imported photos');
+
+ if($network === NETWORK_DFRN) {
+
+ $new_relation = CONTACT_IS_FOLLOWER;
+ if(($relation == CONTACT_IS_SHARING) || ($duplex))
+ $new_relation = CONTACT_IS_FRIEND;
+
+ if(($relation == CONTACT_IS_SHARING) && ($duplex))
+ $duplex = 0;
+
+ $r = q("UPDATE `contact` SET
+ `photo` = '%s',
+ `thumb` = '%s',
+ `micro` = '%s',
+ `rel` = %d,
+ `name-date` = '%s',
+ `uri-date` = '%s',
+ `avatar-date` = '%s',
+ `blocked` = 0,
+ `pending` = 0,
+ `duplex` = %d,
+ `hidden` = %d,
+ `network` = '%s' WHERE `id` = %d
+ ",
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ intval($new_relation),