diff options
author | Mike Macgirvin <mike@macgirvin.com> | 2010-10-12 19:32:15 -0700 |
---|---|---|
committer | Mike Macgirvin <mike@macgirvin.com> | 2010-10-12 19:32:15 -0700 |
commit | 3c440f70c66953735d01841453fa6a7ed244ef1c (patch) | |
tree | e2bc845a34168be418fa845866431b92e53be74b /mod | |
parent | f1977d420ea025e9d8b1f47fb41b25468d07218f (diff) | |
download | volse-hubzilla-3c440f70c66953735d01841453fa6a7ed244ef1c.tar.gz volse-hubzilla-3c440f70c66953735d01841453fa6a7ed244ef1c.tar.bz2 volse-hubzilla-3c440f70c66953735d01841453fa6a7ed244ef1c.zip |
Provide the ability to subscribe to our user from other federated sites.
This is a read-only relationship until the rest of the salmon
magic-envelope stuff lands
Diffstat (limited to 'mod')
-rw-r--r-- | mod/dfrn_request.php | 246 |
1 files changed, 139 insertions, 107 deletions
diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 3cb2a16a4..f6a85fbab 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -183,143 +183,175 @@ function dfrn_request_post(&$a) { $url = webfinger_dfrn($url); + if(substr($url,0,5) === 'stat:') { + $network = 'stat'; + $url = substr($url,5); + } + else { + $network = 'dfrn'; + } + if(! strlen($url)) { notice( t("Unable to resolve your name at the provided location.") . EOL); return; } - $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", - intval($uid), - dbesc($url) - ); - if(count($ret)) { - if(strlen($ret[0]['issued-id'])) { - notice( t('You have already introduced yourself here.') . EOL ); - return; - } - else { - $contact_record = $ret[0]; - $parms = array('dfrn-request' => $ret[0]['request']); - } - } - $issued_id = random_string(); - - 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']) + if($network == 'dfrn') { + $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", + intval($uid), + dbesc($url) ); - } - 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 + if(count($ret)) { + if(strlen($ret[0]['issued-id'])) { + notice( t('You have already introduced yourself here.') . EOL ); + return; + } + else { + $contact_record = $ret[0]; + $parms = array('dfrn-request' => $ret[0]['request']); + } } - - - 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); + $issued_id = random_string(); + + 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(! 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 ) ; + if(! validate_url($url)) { + notice( t('Invalid profile URL.') . EOL); + goaway($a->get_baseurl() . '/' . $a->cmd); + return; // NOTREACHED + } - return; + if(! allowed_url($url)) { + notice( t('Disallowed profile URL.') . EOL); + goaway($a->get_baseurl() . '/' . $a->cmd); + return; // NOTREACHED } - } + + require_once('Scrape.php'); - $parms['url'] = $url; - $parms['issued-id'] = $issued_id; + $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; + } + } - dbesc_array($parms); - $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `issued-id`, `photo`, `site-pubkey`, - `request`, `confirm`, `notify`, `poll` ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", - intval($uid), - datetime_convert(), - $parms['url'], - $parms['fn'], - $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", + $parms['url'] = $url; + $parms['issued-id'] = $issued_id; + + + dbesc_array($parms); + $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `issued-id`, `photo`, `site-pubkey`, + `request`, `confirm`, `notify`, `poll` ) + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", intval($uid), + datetime_convert(), $parms['url'], - $parms['issued-id'] + $parms['fn'], + $parms['issued-id'], + $parms['photo'], + $parms['key'], + $parms['dfrn-request'], + $parms['dfrn-confirm'], + $parms['dfrn-notify'], + $parms['dfrn-poll'] ); - if(count($r)) - $contact_record = $r[0]; - } - - } - if($r === false) { - notice( t('Failed to update contact record.') . EOL ); - return; - } - $hash = random_string() . (string) time(); // Generate a confirm_key + // 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]; + } + + } + if($r === false) { + notice( t('Failed to update contact record.') . EOL ); + return; + } - if(is_array($contact_record)) { - $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_record['id']), - ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0), - dbesc(notags(trim($_POST['dfrn-request-message']))), - dbesc($hash), - dbesc(datetime_convert()) - ); - } + $hash = random_string() . (string) time(); // Generate a confirm_key + + if(is_array($contact_record)) { + $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_record['id']), + ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0), + dbesc(notags(trim($_POST['dfrn-request-message']))), + dbesc($hash), + dbesc(datetime_convert()) + ); + } - // This notice will only be seen by the requestor if the requestor and requestee are on the same server. + // This notice will only be seen by the requestor if the requestor and requestee are on the same server. - if(! $failed) - notice( t('Your introduction has been sent.') . EOL ); + if(! $failed) + notice( t('Your introduction has been sent.') . EOL ); - // "Homecoming" - send the requestor back to their site to record the introduction. + // "Homecoming" - send the requestor back to their site to record the introduction. - $dfrn_url = bin2hex($a->get_baseurl() . '/profile/' . $nickname); - $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0); + $dfrn_url = bin2hex($a->get_baseurl() . '/profile/' . $nickname); + $aes_allow = ((function_exists('openssl_encrypt')) ? 1 : 0); - goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url" . '&confirm_key=' . $hash . (($aes_allow) ? "&aes_allow=1" : "")); - return; // NOTREACHED + goaway($parms['dfrn-request'] . "?dfrn_url=$dfrn_url" + . '&dfrn_version=' . DFRN_PROTOCOL_VERSION + . '&confirm_key=' . $hash + . (($aes_allow) ? "&aes_allow=1" : "") + ); + // NOTREACHED + // END $network === 'dfrn' + } + elseif($network === 'stat') { + + /** + * + * OStatus network + * Check contact existence + * Try and scrape together enough information to create a contact record, with us as REL_VIP + * Substitute our user's feed URL into $url template + * Send the subscriber home to subscribe + * + **/ + + $url = str_replace('{uri}', $a->get_baseurl() . '/dfrn_poll/' . $nickname, $url); + goaway($url); + // NOTREACHED + // END $network === 'stat' + } - } - return; + } return; }} |