aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/diaspora.php88
-rw-r--r--include/queue.php13
2 files changed, 75 insertions, 26 deletions
diff --git a/include/diaspora.php b/include/diaspora.php
index 320f716bf..5ea38bad5 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -4,6 +4,36 @@ require_once('include/crypto.php');
require_once('include/items.php');
require_once('include/bb2diaspora.php');
+function diaspora_dispatch($importer,$msg) {
+
+ $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);
+ }
+ elseif($xmlbase->photo) {
+ diaspora_photo($importer,$xmlbase->photo,$msg);
+ }
+ else {
+ logger('diaspora_dispatch: unknown message type: ' . print_r($xmlbase,true));
+ }
+ return;
+}
+
function diaspora_get_contact_by_handle($uid,$handle) {
$r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `addr` = '%s' LIMIT 1",
dbesc(NETWORK_DIASPORA),
@@ -866,10 +896,7 @@ function diaspora_share($me,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_share: returns: ' . $return_code);
- return $return_code;
+ return(diaspora_transmit($owner,$contact,$slap));
}
function diaspora_unshare($me,$contact) {
@@ -886,10 +913,8 @@ function diaspora_unshare($me,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_unshare: returns: ' . $return_code);
- return $return_code;
+ return(diaspora_transmit($owner,$contact,$slap));
+
}
@@ -937,9 +962,7 @@ function diaspora_send_status($item,$owner,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_status: returns: ' . $return_code);
+ $return_code = diaspora_transmit($owner,$contact,$slap);
if(count($images)) {
diaspora_send_images($item,$owner,$contact,$images);
@@ -979,12 +1002,11 @@ function diaspora_send_images($item,$owner,$contact,$images) {
'$created_at' => xmlify(datetime_convert('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C'))
));
+
logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_photo: returns: ' . $return_code);
+ diaspora_transmit($owner,$contact,$slap);
}
}
@@ -1039,11 +1061,7 @@ function diaspora_send_followup($item,$owner,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_followup: returns: ' . $return_code);
- return $return_code;
-
+ return(diaspora_transmit($owner,$contact,$slap));
}
@@ -1115,10 +1133,7 @@ function diaspora_send_relay($item,$owner,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
- post_url($contact['notify'] . '/',$slap);
- $return_code = $a->get_curl_code();
- logger('diaspora_send_relay: returns: ' . $return_code);
- return $return_code;
+ return(diaspora_transmit($owner,$contact,$slap));
}
@@ -1138,9 +1153,30 @@ function diaspora_send_retraction($item,$owner,$contact) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'])));
+ return(diaspora_transmit($owner,$contact,$slap));
+}
+
+
+
+function diaspora_transmit($owner,$contact,$slap) {
+
+ $a = get_app();
+
post_url($contact['notify'] . '/',$slap);
$return_code = $a->get_curl_code();
- logger('diaspora_send_retraction: returns: ' . $return_code);
- return $return_code;
+ logger('diaspora_transmit: returns: ' . $return_code);
+
+ if(! $return_code) {
+ logger('diaspora_transmit: queue message');
+ // queue message for redelivery
+ q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
+ VALUES ( %d, '%s', '%s', '%s') ",
+ intval($contact['id']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($slap)
+ );
+ }
-} \ No newline at end of file
+ return(($return_code) ? $return_code : (-1));
+}
diff --git a/include/queue.php b/include/queue.php
index fb65d5c25..da5028aee 100644
--- a/include/queue.php
+++ b/include/queue.php
@@ -56,6 +56,7 @@ function queue_run($argv, $argc){
// delivery loop
require_once('include/salmon.php');
+ require_once('include/diaspora.php');
foreach($r as $q_item) {
@@ -120,6 +121,18 @@ function queue_run($argv, $argc){
remove_queue_item($q_item['id']);
}
break;
+ case NETWORK_DIASPORA:
+ if($contact['notify']) {
+ logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
+ $deliver_status = diaspora_transmit($owner,$contact['notify'],$data);
+
+ if($deliver_status == (-1))
+ update_queue_time($q_item['id']);
+ else
+ remove_queue_item($q_item['id']);
+ }
+ break;
+
default:
$params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false);
call_hooks('queue_deliver', $a, $params);