- if(! count($parms)) {
- $_SESSION['sysmsg'] .= 'URL is not valid or does not contain profile information.' . EOL ;
- $failed = true;
- }
- else {
- if(! x($parms,'fn'))
- $_SESSION['sysmsg'] .= 'Warning: DFRN profile has no identifiable owner name.' . EOL ;
- if(! x($parms,'photo'))
- $_SESSION['sysmsg'] .= 'Warning: DFRN profile has no profile photo.' . EOL ;
- $invalid = validate_dfrn($parms);
- if($invalid) {
- echo $invalid . ' required DFRN parameter'
- . (($invalid == 1) ? " was " : "s were " )
- . "not found at the given URL" . '<br />';
+ $contact_record = null;
+
+ if(x($dfrn_url)) {
+
+ $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1",
+ intval($_SESSION['uid']),
+ dbesc($dfrn_url)
+ );
+
+ if(count($r)) {
+ if(strlen($r[0]['dfrn-id'])) {
+ notice( t("This introduction has already been accepted.") . EOL );
+ return;
+ }
+ else
+ $contact_record = $r[0];
+ }
+
+ if(is_array($contact_record)) {
+ $r = q("UPDATE `contact` SET `ret-aes` = %d WHERE `id` = %d LIMIT 1",
+ intval($aes_allow),
+ intval($contact_record['id'])
+ );
+ }
+ else {
+
+ require_once('Scrape.php');
+
+
+ $parms = scrape_dfrn($dfrn_url);
+
+ if(! count($parms)) {
+ notice( t('Profile location is not valid or does not contain profile information.') . EOL );
+ return;
+ }
+ 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;
+ }
+ }
+
+
+
+ $dfrn_request = $parms['dfrn-request'];
+
+ dbesc_array($parms);
+
+
+ $r = q("INSERT INTO `contact` ( `uid`, `created`,`url`, `name`, `photo`, `site-pubkey`,
+ `request`, `confirm`, `notify`, `poll`, `aes_allow`)
+ VALUES ( %d, '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', %d)",
+ intval($_SESSION['uid']),
+ datetime_convert(),
+ dbesc($dfrn_url),
+ $parms['fn'],
+ $parms['photo'],
+ $parms['key'],
+ $parms['dfrn-request'],
+ $parms['dfrn-confirm'],
+ $parms['dfrn-notify'],
+ $parms['dfrn-poll'],
+ intval($aes_allow)
+ );
+ }