]> git.mxchange.org Git - friendica.git/commitdiff
Send a salmon notification to every mentioned person.
authorMichael Vogel <icarus@dabo.de>
Tue, 9 Jun 2015 06:27:04 +0000 (08:27 +0200)
committerMichael Vogel <icarus@dabo.de>
Tue, 9 Jun 2015 06:27:04 +0000 (08:27 +0200)
include/items.php
include/notifier.php
include/ostatus.php
include/salmon.php
mod/item.php

index 97eb15efcf13d9f9f05d4ad2553c302158a0f4db..0a52d49d8da7642d820a135d5d6b2ed2d609118a 100644 (file)
@@ -2228,7 +2228,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
        if ($contact['network'] === NETWORK_OSTATUS) {
                if ($pass < 2) {
                        logger("Consume OStatus messages ", LOGGER_DEBUG);
-                       ostatus_import($xml,$importer,$contact);
+                       ostatus_import($xml,$importer,$contact, $hub);
                }
                return;
        }
@@ -4406,9 +4406,9 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
 
        $tags = item_getfeedtags($item);
        if(count($tags)) {
-               foreach($tags as $t) {
-                       $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
-               }
+               foreach($tags as $t)
+                       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";
index dc4e1a2394e7aab5ee5f1e42a6b4865288735ee3..18d0aead8efadd1b99040745620e080d12e2484f 100644 (file)
@@ -2,6 +2,7 @@
 require_once("boot.php");
 require_once('include/queue_fn.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
@@ -295,9 +296,9 @@ function notifier_run(&$argv, &$argc){
                        $conversant_str = dbesc($parent['contact-id']);
                        $recipients = array($parent['contact-id']);
 
-                       if (!$item['private'] AND $item['wall'] AND
-                               (strlen($item['allow_cid'].$item['allow_gid'].
-                                       $item['deny_cid'].$item['deny_gid']) == 0))
+                       if (!$target_item['private'] AND $target_item['wall'] AND
+                               (strlen($target_item['allow_cid'].$target_item['allow_gid'].
+                                       $target_item['deny_cid'].$target_item['deny_gid']) == 0))
                                $push_notify = true;
 
                        if ($parent['network'] == NETWORK_OSTATUS) {
@@ -305,15 +306,28 @@ function notifier_run(&$argv, &$argc){
 
                                $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
                                // Not sure if it is working or not.
                                $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", $parent['contact-id']);
                                if (count($r)) {
-                                       $url_recipients = array();
 
                                        $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"]))) {
-                                               require_once("include/Scrape.php");
                                                $probed_contact = probe_url($thrparent[0]["author-link"]);
                                                if ($probed_contact["notify"] != "") {
                                                        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 {
                        $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);
 
@@ -911,7 +928,7 @@ function notifier_run(&$argv, &$argc){
 
        // 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')) {
                        foreach($url_recipients as $url) {
                                if($url) {
index a1a3f1f70ed59b725a7d51f6cf4027d5a5968434..41499a2c3ffbe541b69ab2db930991f85bd7c02c 100644 (file)
@@ -59,7 +59,10 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact) {
        return($author);
 }
 
-function ostatus_import($xml,$importer,&$contact) {
+function ostatus_import($xml,$importer,&$contact, &$hub) {
+
+       // To-Do:
+       // Hub
 
        $a = get_app();
 
@@ -69,7 +72,7 @@ function ostatus_import($xml,$importer,&$contact) {
                return;
 
        $doc = new DOMDocument();
-       $doc->loadXML($xml);
+       @$doc->loadXML($xml);
 
        $xpath = new DomXPath($doc);
        $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
@@ -103,6 +106,8 @@ function ostatus_import($xml,$importer,&$contact) {
        $item_id = 0;
 
        // Reverse the order of the entries
+       $entrylist = array();
+
        foreach ($entries AS $entry)
                $entrylist[] = $entry;
 
@@ -296,7 +301,7 @@ function ostatus_import($xml,$importer,&$contact) {
                                        $reply_xml = fetch_url($reply_path);
 
                                        $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
                                        $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
index 3d525f51ad36d0a2d55349937c140e404f8b56ea..7574374907eabf3f4cca2789b5be712dfebadee5 100644 (file)
@@ -7,7 +7,7 @@ require_once('include/crypto.php');
 function get_salmon_key($uri,$keyhash) {
        $ret = array();
 
-       logger('Fetching salmon key');
+       logger('Fetching salmon key for '.$uri);
 
        $arr = lrdd($uri);
 
@@ -44,10 +44,10 @@ function get_salmon_key($uri,$keyhash) {
        if(count($ret) == 1) {
 
                // 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 
-               // message verification will fail. This also covers some older 
+               // If it's the wrong key we'll find out soon enough because
+               // message verification will fail. This also covers some older
                // 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];
        }
@@ -62,20 +62,20 @@ function get_salmon_key($uri,$keyhash) {
        return '';
 }
 
-       
-               
+
+
 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))
                return;
 
 
        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']));
                return;
        }
@@ -96,7 +96,7 @@ $namespaces = <<< EOT
 EOT;
 
        $slap = str_replace('<entry>',$namespaces,$slap);
-       
+
        // create a magic envelope
 
        $data      = base64url_encode($slap);
@@ -125,7 +125,7 @@ EOT;
                '$signature' => $signature
        ));
 
-       // slap them 
+       // slap them
        post_url($url,$salmon, array(
                'Content-type: application/magic-envelope+xml',
                'Content-length: ' . strlen($salmon)
@@ -138,7 +138,7 @@ EOT;
 
        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
                // non-compliant. Let's try once more, this time only signing
@@ -152,7 +152,7 @@ EOT;
                        '$signature' => $signature2
                ));
 
-               // slap them 
+               // slap them
                post_url($url,$salmon, array(
                        'Content-type: application/magic-envelope+xml',
                        'Content-length: ' . strlen($salmon)
@@ -162,11 +162,11 @@ EOT;
 
                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
                        // 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(
                                '$data'      => $data,
@@ -176,7 +176,7 @@ EOT;
                                '$signature' => $signature3
                        ));
 
-                       // slap them 
+                       // slap them
                        post_url($url,$salmon, array(
                                'Content-type: application/magic-envelope+xml',
                                'Content-length: ' . strlen($salmon)
@@ -184,7 +184,7 @@ EOT;
                        $return_code = $a->get_curl_code();
                }
        }
-       logger('slapper returned ' . $return_code); 
+       logger('slapper for '.$url.' returned ' . $return_code);
        if(! $return_code)
                return(-1);
        if(($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))
index c3d85568ed98f0faa59fd0c822ccd14bac020eae..a5f483b3524089f778a226b792fae04c845473de 100644 (file)
@@ -24,6 +24,7 @@ require_once('include/files.php');
 require_once('include/threads.php');
 require_once('include/text.php');
 require_once('include/items.php');
+require_once('include/Scrape.php');
 
 function item_post(&$a) {