+
+ /**
+ * Store provided media ids in the item array and adjust permissions
+ *
+ * @param array $media_ids
+ * @param array $item
+ * @return array
+ */
+ private function storeMediaIds(array $media_ids, array $item): array
+ {
+ $item['object-type'] = Activity\ObjectType::IMAGE;
+ $item['post-type'] = Item::PT_IMAGE;
+ $item['attachments'] = [];
+
+ foreach ($media_ids as $id) {
+ $media = DBA::toArray(DBA::p("SELECT `resource-id`, `scale`, `type`, `desc`, `filename`, `datasize`, `width`, `height` FROM `photo`
+ WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = ?) AND `photo`.`uid` = ?
+ ORDER BY `photo`.`width` DESC LIMIT 2", $id, $item['uid']));
+
+ if (empty($media)) {
+ continue;
+ }
+
+ Photo::setPermissionForRessource($media[0]['resource-id'], $item['uid'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid']);
+
+ $ressources[] = $media[0]['resource-id'];
+ $phototypes = Images::supportedTypes();
+ $ext = $phototypes[$media[0]['type']];
+
+ $attachment = ['type' => Post\Media::IMAGE, 'mimetype' => $media[0]['type'],
+ 'url' => DI::baseUrl() . '/photo/' . $media[0]['resource-id'] . '-' . $media[0]['scale'] . '.' . $ext,
+ 'size' => $media[0]['datasize'],
+ 'name' => $media[0]['filename'] ?: $media[0]['resource-id'],
+ 'description' => $media[0]['desc'] ?? '',
+ 'width' => $media[0]['width'],
+ 'height' => $media[0]['height']];
+
+ if (count($media) > 1) {
+ $attachment['preview'] = DI::baseUrl() . '/photo/' . $media[1]['resource-id'] . '-' . $media[1]['scale'] . '.' . $ext;
+ $attachment['preview-width'] = $media[1]['width'];
+ $attachment['preview-height'] = $media[1]['height'];
+ }
+ $item['attachments'][] = $attachment;
+ }
+ return $item;
+ }