diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index f54503708b..773d45c83a 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -25,6 +25,10 @@ use Friendica\Util\DateTimeFormat; * - Event * - Undo Announce * + * Missing object fields: + * - Location + * - Generator + * * Check what this is meant to do: * - Add * - Block diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index f5765ccdd3..3c22f8f62b 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -24,6 +24,7 @@ use Friendica\Object\Image; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Core\Cache; +use Friendica\Util\Map; require_once 'include/api.php'; @@ -32,10 +33,6 @@ require_once 'include/api.php'; * * To-Do: * - * Missing object fields: - * - service (App) - * - location - * * Missing object types: * - Event * @@ -600,6 +597,40 @@ class Transmitter return $data; } + /** + * Creates a location entry for a given item array + * + * @param array $item + * + * @return array with location array + */ + private static function createLocation($item) + { + $location = ['type' => 'Place']; + + if (!empty($item['location'])) { + $location['name'] = $item['location']; + } + + $coord = []; + + if (empty($item['coord'])) { + $coord = Map::getCoordinates($item['location']); + } else { + $coords = explode(' ', $item['coord']); + if (count($coords) == 2) { + $coord = ['lat' => $coords[0], 'lon' => $coords[1]]; + } + } + + if (!empty($coord['lat']) && !empty($coord['lon'])) { + $location['latitude'] = $coord['lat']; + $location['longitude'] = $coord['lon']; + } + + return $location; + } + /** * Returns a tag array for a given item array * @@ -801,6 +832,15 @@ class Transmitter $data['attachment'] = self::createAttachmentList($item, $type); $data['tag'] = self::createTagList($item); + + if (!empty($item['coord']) || !empty($item['location'])) { + $data['location'] = self::createLocation($item); + } + + if (!empty($item['app'])) { + $data['generator'] = ['type' => 'Application', 'name' => $item['app']]; + } + $data = array_merge($data, self::createPermissionBlockForItem($item)); return $data;