]> git.mxchange.org Git - friendica.git/commitdiff
We now transmit location and application as well.
authorMichael <heluecht@pirati.ca>
Sat, 13 Oct 2018 19:49:20 +0000 (19:49 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 13 Oct 2018 19:49:20 +0000 (19:49 +0000)
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php

index f54503708be603b7245112b0cc221c6f9c8dcc08..773d45c83ae951ddf070c82710abd481c204ee1e 100644 (file)
@@ -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
index f5765ccdd31f5e509d7a34cda6887791b5ffe9af..3c22f8f62b04c8809759e7c8676b0589d28c12f4 100644 (file)
@@ -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;