- if($contact_id) {
- $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
- VALUES ( %d, %d, 1, %d, '%s', '%s', '%s' )",
- intval($uid),
- intval($contact_id),
- ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0),
- dbesc(trim($_POST['dfrn-request-message'])),
- dbesc($hash),
- dbesc(datetime_convert())
- );
- }
-
+ if(is_array($contact_record)) {
+ // There is a contact record but no issued-id, so this
+ // is a reciprocal introduction from a known contact
+ $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d LIMIT 1",
+ dbesc($issued_id),
+ intval($contact_record['id'])
+ );
+ }
+ else {
+ if(! validate_url($url)) {
+ notice( t('Invalid profile URL.') . EOL);
+ goaway($a->get_baseurl() . '/' . $a->cmd);
+ return; // NOTREACHED
+ }
+
+ if(! allowed_url($url)) {
+ notice( t('Disallowed profile URL.') . EOL);
+ goaway($a->get_baseurl() . '/' . $a->cmd);
+ return; // NOTREACHED
+ }
+
+
+ require_once('Scrape.php');
+
+ $parms = scrape_dfrn($url);
+
+ if(! count($parms)) {
+ notice( t('Profile location is not valid or does not contain profile information.') . EOL );
+ goaway($a->get_baseurl() . '/' . $a->cmd);
+ }
+ else {
+ if(! x($parms,'fn'))
+ notice( t('Warning: profile location has no identifiable owner name.') . EOL );
+ if(! x($parms,'photo'))
+ notice( t('Warning: profile location has no profile photo.') . EOL );
+ $invalid = validate_dfrn($parms);
+ if($invalid) {
+ notice( $invalid . t(' required parameter')
+ . (($invalid == 1) ? t(" was ") : t("s were ") )
+ . t("not found at the given location.") . EOL ) ;
+
+ return;
+ }
+ }
+
+
+ $parms['url'] = $url;
+ $parms['issued-id'] = $issued_id;
+
+
+ dbesc_array($parms);
+ $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
+ `request`, `confirm`, `notify`, `poll` )
+ VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+ intval($uid),
+ datetime_convert(),
+ $parms['url'],
+ $parms['fn'],
+ $parms['nick'],
+ $parms['issued-id'],
+ $parms['photo'],
+ $parms['key'],
+ $parms['dfrn-request'],
+ $parms['dfrn-confirm'],
+ $parms['dfrn-notify'],
+ $parms['dfrn-poll']
+ );
+
+ // find the contact record we just created
+ if($r) {
+ $r = q("SELECT `id` FROM `contact`
+ WHERE `uid` = %d AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1",
+ intval($uid),
+ $parms['url'],
+ $parms['issued-id']
+ );
+ if(count($r))
+ $contact_record = $r[0];
+ }