X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Freceive.php;h=95a51016757da46217f277e4b641799c43b1ec2c;hb=d9e56e04506cdfc9abd87d84cff4f730708db51d;hp=c3738c1431c20e28221e24ad79bdc31cf96648e3;hpb=d8bd4fbb3e38bf0ff9c7b61dba58e20c0d097d75;p=friendica.git diff --git a/mod/receive.php b/mod/receive.php index c3738c1431..95a5101675 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -9,26 +9,41 @@ require_once('include/salmon.php'); require_once('include/crypto.php'); require_once('include/diaspora.php'); - + function receive_post(&$a) { - if($a->argc != 3 || $a->argv[1] !== 'users') + + $enabled = intval(get_config('system','diaspora_enabled')); + if(! $enabled) { + logger('mod-diaspora: disabled'); http_status_exit(500); + } - logger('receive: raw input: ' . file_get_contents('php://input'), LOGGER_DATA); + $public = false; - $guid = $a->argv[2]; + if(($a->argc == 2) && ($a->argv[1] === 'public')) { + $public = true; + } + else { - $r = q("SELECT * FROM `user` WHERE `guid` = '%s' LIMIT 1", - dbesc($guid) - ); - if(! count($r)) - http_status_exit(500); + if($a->argc != 3 || $a->argv[1] !== 'users') + http_status_exit(500); - $importer = $r[0]; + $guid = $a->argv[2]; + + $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", + dbesc($guid) + ); + if(! count($r)) + http_status_exit(500); + + $importer = $r[0]; + } // It is an application/x-www-form-urlencoded + logger('mod-diaspora: receiving post', LOGGER_DEBUG); + $xml = urldecode($_POST['xml']); logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA); @@ -36,38 +51,26 @@ function receive_post(&$a) { if(! $xml) http_status_exit(500); + logger('mod-diaspora: message is okay', LOGGER_DEBUG); + $msg = diaspora_decode($importer,$xml); + logger('mod-diaspora: decoded', LOGGER_DEBUG); + logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA); if(! is_array($msg)) http_status_exit(500); + logger('mod-diaspora: dispatching', LOGGER_DEBUG); - $parsed_xml = parse_xml_string($msg['message'],false); - - $xmlbase = $parsed_xml->post; - - if($xmlbase->request) { - diaspora_request($importer,$xmlbase->request); - } - elseif($xmlbase->status_message) { - diaspora_post($importer,$xmlbase->status_message); - } - elseif($xmlbase->comment) { - diaspora_comment($importer,$xmlbase->comment,$msg); - } - elseif($xmlbase->like) { - diaspora_like($importer,$xmlbase->like,$msg); - } - elseif($xmlbase->retraction) { - diaspora_retraction($importer,$xmlbase->retraction,$msg); - } - else { - logger('mod-diaspora: unknown message type: ' . print_r($xmlbase,true)); - } + $ret = 0; + if($public) + diaspora_dispatch_public($msg); + else + $ret = diaspora_dispatch($importer,$msg); - http_status_exit(200); + http_status_exit(($ret) ? $ret : 200); // NOTREACHED }