From 483f34c4ce7cf9a9b0404488d8a5c46a6532f29b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 29 Dec 2016 03:13:57 +0000 Subject: [PATCH] We now transmit event data as well --- include/diaspora.php | 73 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 2bbd1f4ab0..d3038e62ce 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1914,18 +1914,18 @@ class Diaspora { * * @return string The XML */ - private function construct_new_friend_object($contact) { - $objtype = ACTIVITY_OBJ_PERSON; - $link = ''."\n". - ''."\n"; + private function construct_new_friend_object($contact) { + $objtype = ACTIVITY_OBJ_PERSON; + $link = ''."\n". + ''."\n"; - $xmldata = array("object" => array("type" => $objtype, - "title" => $contact["name"], - "id" => $contact["url"]."/".$contact["name"], - "link" => $link)); + $xmldata = array("object" => array("type" => $objtype, + "title" => $contact["name"], + "id" => $contact["url"]."/".$contact["name"], + "link" => $link)); - return xml::from_array($xmldata, $xml, true); - } + return xml::from_array($xmldata, $xml, true); + } /** * @brief Processes incoming sharing notification @@ -2939,6 +2939,52 @@ class Diaspora { return($ret); } + /** + * @brief Create an event array + * + * @param integer $event_id The id of the event + * + * @return array with event data + */ + private static function build_event($event_id) { + $r = q("SELECT `start`, `finish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($event_id)); + if (!dbm::is_result($r)) { + return array(); + } + + $eventdata = array(); + + /// @todo Timezone in start und end? + + if ($r[0]['adjust']) { + $eventdata['timezone'] = 'UTC'; + } else { + $eventdata['timezone'] = date_default_timezone_get(); + } + + if ($r[0]['start']) { + $eventdata['start'] = datetime_convert("UTC", "UTC", $r[0]['start'], 'Y-m-d\TH:i:s\Z'); + } + if ($r[0]['finish']) { + $eventdata['end'] = datetime_convert("UTC", "UTC", $r[0]['finish'], 'Y-m-d\TH:i:s\Z'); + } + if ($r[0]['summary']) { + $eventdata['summary'] = html_entity_decode(bb2diaspora($r[0]['summary'])); + } + if ($r[0]['desc']) { + $eventdata['description'] = html_entity_decode(bb2diaspora($r[0]['desc'])); + } + if ($r[0]['location']) { + $location = array(); + $location["address"] = html_entity_decode(bb2diaspora($r[0]['location'])); + $location["lat"] = 0; + $location["lng"] = 0; + $eventdata['location'] = $location; + } + + return $eventdata; + } + /** * @brief Create a post (status message or reshare) * @@ -3012,6 +3058,13 @@ class Diaspora { unset($message["location"]); } + if ($item['event-id'] > 0) { + $event = self::build_event($item['event-id']); + if (count($event)) { + $message['event'] = $event; + } + } + $type = "status_message"; } return array("type" => $type, "message" => $message);