From d1259398887b092f991ed6ac893c9cac9792ab3d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 30 Jun 2016 07:46:00 +0200 Subject: [PATCH] Just some more centralised functionality --- include/diaspora.php | 18 +++++++++++++++--- mod/fetch.php | 7 +------ mod/p.php | 3 +-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 8e206533d0..1e8d586c78 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2532,6 +2532,20 @@ class diaspora { } + /** + * @brief Build the post xml + * + * @param string $type The message type + * @param array $message The message data + * + * @return string The post XML + */ + public static function build_post_xml($type, $message) { + + $data = array("XML" => array("post" => array($type => $message))); + return xml::from_array($data, $xml); + } + /** * @brief Builds and transmit messages * @@ -2547,9 +2561,7 @@ class diaspora { */ private function build_and_transmit($owner, $contact, $type, $message, $public_batch = false, $guid = "", $spool = false) { - $data = array("XML" => array("post" => array($type => $message))); - - $msg = xml::from_array($data, $xml); + $msg = build_post_xml($type, $message); logger('message: '.$msg, LOGGER_DATA); logger('send guid '.$guid, LOGGER_DEBUG); diff --git a/mod/fetch.php b/mod/fetch.php index 5db6250a21..70766e8e5e 100644 --- a/mod/fetch.php +++ b/mod/fetch.php @@ -35,16 +35,11 @@ function fetch_init($a){ $user = $r[0]; $status = diaspora::build_status($item[0], $user); - $data = array("XML" => array("post" => array($status["type"] => $status["message"]))); - $xml = xml::from_array($data, $xmlobj); + $xml = diaspora::build_post_xml($status["type"], $status["message"]); // Send the envelope header("Content-Type: application/magic-envelope+xml; charset=utf-8"); echo diaspora::build_magic_envelope($xml, $user); - //header("Content-Type: application/xml; charset=utf-8"); - //echo $xml; - //killme(); - killme(); } diff --git a/mod/p.php b/mod/p.php index ae25a0889e..80333ef21e 100644 --- a/mod/p.php +++ b/mod/p.php @@ -39,8 +39,7 @@ function p_init($a){ $user = $r[0]; $status = diaspora::build_status($item[0], $user); - $data = array("XML" => array("post" => array($status["type"] => $status["message"]))); - $xml = xml::from_array($data, $xmlobj); + $xml = diaspora::build_post_xml($status["type"], $status["message"]); header("Content-Type: application/xml; charset=utf-8"); echo $xml;