Send a salmon notification to every mentioned person.

This commit is contained in:
Michael Vogel 2015-06-09 08:27:04 +02:00
parent 419a3ab2d3
commit cb0351dba0
5 changed files with 55 additions and 32 deletions

View File

@ -2228,7 +2228,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if ($contact['network'] === NETWORK_OSTATUS) { if ($contact['network'] === NETWORK_OSTATUS) {
if ($pass < 2) { if ($pass < 2) {
logger("Consume OStatus messages ", LOGGER_DEBUG); logger("Consume OStatus messages ", LOGGER_DEBUG);
ostatus_import($xml,$importer,$contact); ostatus_import($xml,$importer,$contact, $hub);
} }
return; return;
} }
@ -4406,9 +4406,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
$tags = item_getfeedtags($item); $tags = item_getfeedtags($item);
if(count($tags)) { if(count($tags)) {
foreach($tags as $t) { foreach($tags as $t)
$o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n"; if (($type != 'html') OR ($t[0] != "@"))
} $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
} }
//$o .= '<link rel="ostatus:conversation" href="'.xmlify($a->get_baseurl().'/display/'.$owner['nickname'].'/'.$item['parent']).'"/>'."\r\n"; //$o .= '<link rel="ostatus:conversation" href="'.xmlify($a->get_baseurl().'/display/'.$owner['nickname'].'/'.$item['parent']).'"/>'."\r\n";

View File

@ -2,6 +2,7 @@
require_once("boot.php"); require_once("boot.php");
require_once('include/queue_fn.php'); require_once('include/queue_fn.php');
require_once('include/html2plain.php'); require_once('include/html2plain.php');
require_once("include/Scrape.php");
/* /*
* This file was at one time responsible for doing all deliveries, but this caused * This file was at one time responsible for doing all deliveries, but this caused
@ -295,9 +296,9 @@ function notifier_run(&$argv, &$argc){
$conversant_str = dbesc($parent['contact-id']); $conversant_str = dbesc($parent['contact-id']);
$recipients = array($parent['contact-id']); $recipients = array($parent['contact-id']);
if (!$item['private'] AND $item['wall'] AND if (!$target_item['private'] AND $target_item['wall'] AND
(strlen($item['allow_cid'].$item['allow_gid']. (strlen($target_item['allow_cid'].$target_item['allow_gid'].
$item['deny_cid'].$item['deny_gid']) == 0)) $target_item['deny_cid'].$target_item['deny_gid']) == 0))
$push_notify = true; $push_notify = true;
if ($parent['network'] == NETWORK_OSTATUS) { if ($parent['network'] == NETWORK_OSTATUS) {
@ -305,15 +306,28 @@ function notifier_run(&$argv, &$argc){
$push_notify = true; $push_notify = true;
// Send a salmon notification to every person we mentioned in the post
$arr = explode(',',$target_item['tag']);
foreach($arr as $x) {
logger('Checking tag '.$x, LOGGER_DEBUG);
$matches = null;
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
$probed_contact = probe_url($matches[1]);
if ($probed_contact["notify"] != "") {
logger('scrape data for slapper: '.print_r($probed_contact, true));
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
}
}
}
/*
// Check if the recipient isn't in your contact list, try to slap it // Check if the recipient isn't in your contact list, try to slap it
// Not sure if it is working or not. // Not sure if it is working or not.
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']); $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']);
if (count($r)) { if (count($r)) {
$url_recipients = array();
$thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"])); $thrparent = q("SELECT `author-link` FROM `item` WHERE `uri` = '%s'", dbesc($target_item["thr-parent"]));
if (count($thrparent) AND (normalise_link($r[0]["url"]) != normalise_link($thrparent[0]["author-link"]))) { if (count($thrparent) AND (normalise_link($r[0]["url"]) != normalise_link($thrparent[0]["author-link"]))) {
require_once("include/Scrape.php");
$probed_contact = probe_url($thrparent[0]["author-link"]); $probed_contact = probe_url($thrparent[0]["author-link"]);
if ($probed_contact["notify"] != "") { if ($probed_contact["notify"] != "") {
logger('scrape data for slapper: '.print_r($probed_contact, true)); logger('scrape data for slapper: '.print_r($probed_contact, true));
@ -321,7 +335,9 @@ function notifier_run(&$argv, &$argc){
} }
} }
} }
logger("url_recipients".print_r($url_recipients,true)); */
if (count($url_recipients))
logger("url_recipients ".print_r($url_recipients,true));
} }
} else { } else {
$followup = false; $followup = false;
@ -372,7 +388,8 @@ function notifier_run(&$argv, &$argc){
} }
} }
logger('notifier: url_recipients' . print_r($url_recipients,true)); if (count($url_recipients))
logger('notifier: url_recipients ' . print_r($url_recipients,true));
$conversants = array_unique($conversants); $conversants = array_unique($conversants);
@ -911,7 +928,7 @@ function notifier_run(&$argv, &$argc){
// send additional slaps to mentioned remote tags (@foo@example.com) // send additional slaps to mentioned remote tags (@foo@example.com)
if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) { if($slap && count($url_recipients) && ($followup || $top_level) && ($public_message || $push_notify) && (! $expire)) {
if(! get_config('system','dfrn_only')) { if(! get_config('system','dfrn_only')) {
foreach($url_recipients as $url) { foreach($url_recipients as $url) {
if($url) { if($url) {

View File

@ -59,7 +59,10 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact) {
return($author); return($author);
} }
function ostatus_import($xml,$importer,&$contact) { function ostatus_import($xml,$importer,&$contact, &$hub) {
// To-Do:
// Hub
$a = get_app(); $a = get_app();
@ -69,7 +72,7 @@ function ostatus_import($xml,$importer,&$contact) {
return; return;
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->loadXML($xml); @$doc->loadXML($xml);
$xpath = new DomXPath($doc); $xpath = new DomXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
@ -103,6 +106,8 @@ function ostatus_import($xml,$importer,&$contact) {
$item_id = 0; $item_id = 0;
// Reverse the order of the entries // Reverse the order of the entries
$entrylist = array();
foreach ($entries AS $entry) foreach ($entries AS $entry)
$entrylist[] = $entry; $entrylist[] = $entry;
@ -296,7 +301,7 @@ function ostatus_import($xml,$importer,&$contact) {
$reply_xml = fetch_url($reply_path); $reply_xml = fetch_url($reply_path);
$reply_contact = $contact; $reply_contact = $contact;
ostatus_import($reply_xml,$importer,$reply_contact); ostatus_import($reply_xml,$importer,$reply_contact, $reply_hub);
// After the import try to fetch the parent item again // After the import try to fetch the parent item again
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",

View File

@ -7,7 +7,7 @@ require_once('include/crypto.php');
function get_salmon_key($uri,$keyhash) { function get_salmon_key($uri,$keyhash) {
$ret = array(); $ret = array();
logger('Fetching salmon key'); logger('Fetching salmon key for '.$uri);
$arr = lrdd($uri); $arr = lrdd($uri);
@ -44,10 +44,10 @@ function get_salmon_key($uri,$keyhash) {
if(count($ret) == 1) { if(count($ret) == 1) {
// We only found one one key so we don't care if the hash matches. // We only found one one key so we don't care if the hash matches.
// If it's the wrong key we'll find out soon enough because // If it's the wrong key we'll find out soon enough because
// message verification will fail. This also covers some older // message verification will fail. This also covers some older
// software which don't supply a keyhash. As long as they only // software which don't supply a keyhash. As long as they only
// have one key we'll be right. // have one key we'll be right.
return $ret[0]; return $ret[0];
} }
@ -62,20 +62,20 @@ function get_salmon_key($uri,$keyhash) {
return ''; return '';
} }
function slapper($owner,$url,$slap) { function slapper($owner,$url,$slap) {
logger('slapper called. Data: ' . $slap); logger('slapper called for '.$url.'. Data: ' . $slap);
// does contact have a salmon endpoint? // does contact have a salmon endpoint?
if(! strlen($url)) if(! strlen($url))
return; return;
if(! $owner['sprvkey']) { if(! $owner['sprvkey']) {
logger(sprintf("slapper: user '%s' (%d) does not have a salmon private key. Send failed.", logger(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.",
$owner['username'],$owner['uid'])); $owner['username'],$owner['uid']));
return; return;
} }
@ -96,7 +96,7 @@ $namespaces = <<< EOT
EOT; EOT;
$slap = str_replace('<entry>',$namespaces,$slap); $slap = str_replace('<entry>',$namespaces,$slap);
// create a magic envelope // create a magic envelope
$data = base64url_encode($slap); $data = base64url_encode($slap);
@ -125,7 +125,7 @@ EOT;
'$signature' => $signature '$signature' => $signature
)); ));
// slap them // slap them
post_url($url,$salmon, array( post_url($url,$salmon, array(
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
@ -138,7 +138,7 @@ EOT;
if($return_code > 299) { if($return_code > 299) {
logger('slapper: compliant salmon failed. Falling back to status.net hack2'); logger('compliant salmon failed. Falling back to status.net hack2');
// Entirely likely that their salmon implementation is // Entirely likely that their salmon implementation is
// non-compliant. Let's try once more, this time only signing // non-compliant. Let's try once more, this time only signing
@ -152,7 +152,7 @@ EOT;
'$signature' => $signature2 '$signature' => $signature2
)); ));
// slap them // slap them
post_url($url,$salmon, array( post_url($url,$salmon, array(
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
@ -162,11 +162,11 @@ EOT;
if($return_code > 299) { if($return_code > 299) {
logger('slapper: compliant salmon failed. Falling back to status.net hack3'); logger('compliant salmon failed. Falling back to status.net hack3');
// Entirely likely that their salmon implementation is // Entirely likely that their salmon implementation is
// non-compliant. Let's try once more, this time only signing // non-compliant. Let's try once more, this time only signing
// the data, without the precomputed blob // the data, without the precomputed blob
$salmon = replace_macros($salmon_tpl,array( $salmon = replace_macros($salmon_tpl,array(
'$data' => $data, '$data' => $data,
@ -176,7 +176,7 @@ EOT;
'$signature' => $signature3 '$signature' => $signature3
)); ));
// slap them // slap them
post_url($url,$salmon, array( post_url($url,$salmon, array(
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
@ -184,7 +184,7 @@ EOT;
$return_code = $a->get_curl_code(); $return_code = $a->get_curl_code();
} }
} }
logger('slapper returned ' . $return_code); logger('slapper for '.$url.' returned ' . $return_code);
if(! $return_code) if(! $return_code)
return(-1); return(-1);
if(($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after'))) if(($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))

View File

@ -24,6 +24,7 @@ require_once('include/files.php');
require_once('include/threads.php'); require_once('include/threads.php');
require_once('include/text.php'); require_once('include/text.php');
require_once('include/items.php'); require_once('include/items.php');
require_once('include/Scrape.php');
function item_post(&$a) { function item_post(&$a) {