mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 04:05:16 +02:00
two-way subscriptions working with federated social accounts
This commit is contained in:
parent
1335ef7595
commit
c16f314ec3
15 changed files with 356 additions and 34 deletions
|
@ -2,15 +2,6 @@
|
|||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
|
||||
if(! function_exists('attribute_contains')) {
|
||||
function attribute_contains($attr,$s) {
|
||||
$a = explode(' ', $attr);
|
||||
if(count($a) && in_array($s,$a))
|
||||
return true;
|
||||
return false;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('scrape_dfrn')) {
|
||||
function scrape_dfrn($url) {
|
||||
|
||||
|
@ -53,7 +44,7 @@ function scrape_dfrn($url) {
|
|||
$ret['photo'] = $x->getAttribute('src');
|
||||
if(attribute_contains($x->getAttribute('class'),'key'))
|
||||
$ret['key'] = $x->textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,3 +98,40 @@ function scrape_meta($url) {
|
|||
|
||||
return $ret;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('scrape_vcard')) {
|
||||
function scrape_vcard($url) {
|
||||
|
||||
$ret = array();
|
||||
$s = fetch_url($url);
|
||||
|
||||
if(! $s)
|
||||
return $ret;
|
||||
|
||||
$dom = HTML5_Parser::parse($s);
|
||||
|
||||
if(! $dom)
|
||||
return $ret;
|
||||
|
||||
// Pull out hCard profile elements
|
||||
|
||||
$items = $dom->getElementsByTagName('*');
|
||||
foreach($items as $item) {
|
||||
if(attribute_contains($item->getAttribute('class'), 'vcard')) {
|
||||
$level2 = $item->getElementsByTagName('*');
|
||||
foreach($level2 as $x) {
|
||||
if(attribute_contains($x->getAttribute('class'),'fn'))
|
||||
$ret['fn'] = $x->textContent;
|
||||
if((attribute_contains($x->getAttribute('class'),'photo'))
|
||||
|| (attribute_contains($x->getAttribute('class'),'avatar')))
|
||||
$ret['photo'] = $x->getAttribute('src');
|
||||
if((attribute_contains($x->getAttribute('class'),'nickname'))
|
||||
|| (attribute_contains($x->getAttribute('class'),'uid')))
|
||||
$ret['nick'] = $x->textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}}
|
||||
|
|
|
@ -41,7 +41,7 @@ if((x($_SESSION,'authenticated')) && (! ($_POST['auth-params'] === 'login'))) {
|
|||
|
||||
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
|
||||
intval($_SESSION['uid']));
|
||||
if(count($r)) {
|
||||
$a->contact = $r[0];
|
||||
|
@ -91,6 +91,7 @@ else {
|
|||
$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
|
||||
intval($_SESSION['uid']));
|
||||
if(count($r)) {
|
||||
$a->contact = $r[0];
|
||||
$a->cid = $r[0]['id'];
|
||||
$_SESSION['cid'] = $a->cid;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,8 @@ $namespaces = <<< EOT
|
|||
xmlns:media="http://purl.org/syndication/atommedia"
|
||||
xmlns:dfrn="http://purl.org/macgirvin/dfrn/1.0"
|
||||
xmlns:as="http://activitystrea.ms/spec/1.0/"
|
||||
xmlns:georss="http://www.georss.org/georss" >
|
||||
xmlns:georss="http://www.georss.org/georss"
|
||||
xmlns:poco="http://portablecontacts.net/spec/1.0" >
|
||||
EOT;
|
||||
|
||||
$slap = str_replace('<entry>',$namespaces,$slap);
|
||||
|
@ -129,7 +130,7 @@ EOT;
|
|||
$rsa->setHash('sha256');
|
||||
$rsa->loadKey($owner['sprvkey']);
|
||||
|
||||
$signature = $rsa->sign($data);
|
||||
$signature = base64url_encode($rsa->sign($data));
|
||||
|
||||
$salmon_tpl = load_view_file('view/magicsig.tpl');
|
||||
$salmon = replace_macros($salmon_tpl,array(
|
||||
|
@ -141,7 +142,13 @@ EOT;
|
|||
));
|
||||
|
||||
// slap them
|
||||
post_url($contact['notify'],$salmon);
|
||||
post_url($contact['notify'],$salmon, array(
|
||||
'Content-type: application/magic-envelope+xml',
|
||||
'Content-length: ' . strlen($salmon)
|
||||
));
|
||||
|
||||
$a = get_app();
|
||||
echo "CURL returned: " . $a->get_curl_code() . "\n";
|
||||
|
||||
return;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue