diff --git a/src/Model/Item.php b/src/Model/Item.php
index c814ac9d8..765812b9f 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -2643,50 +2643,7 @@ class Item
return $s;
}
- $as = '';
- $vhead = false;
- foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
- $mime = $attachment['mimetype'];
-
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
- $the_url = Contact::magicLinkByContact($author, $attachment['url']);
-
- if (strpos($mime, 'video') !== false) {
- if (!$vhead) {
- $vhead = true;
- DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'));
- }
-
- $as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
- '$video' => [
- 'id' => $item['author-id'],
- 'title' => DI::l10n()->t('View Video'),
- 'src' => $the_url,
- 'mime' => $mime,
- ],
- ]);
- }
-
- $filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
- if ($filetype) {
- $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
- $filesubtype = str_replace('.', '-', $filesubtype);
- } else {
- $filetype = 'unkn';
- $filesubtype = 'unkn';
- }
-
- $title = Strings::escapeHtml(trim(($attachment['description'] ?? '') ?: $attachment['url']));
- $title .= ' ' . ($attachment['size'] ?? 0) . ' ' . DI::l10n()->t('bytes');
-
- $icon = '
';
- $as .= '' . $icon . '';
- }
-
- if ($as != '') {
- $s .= '';
- }
+ $s = self::addMediaAttachments($item, $s);
// Map.
if (strpos($s, '') !== false && !empty($item['coord'])) {
@@ -2710,6 +2667,68 @@ class Item
return $hook_data['html'];
}
+ /**
+ * Add media attachments to the content
+ *
+ * @param array $item
+ * @param string $content
+ * @return modified content
+ */
+ private static function addMediaAttachments(array $item, string $content)
+ {
+ $attached = '';
+ foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) {
+ $mime = $attachment['mimetype'];
+
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $the_url = Contact::magicLinkByContact($author, $attachment['url']);
+
+ $filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
+ if ($filetype) {
+ $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
+ $filesubtype = str_replace('.', '-', $filesubtype);
+ } else {
+ $filetype = 'unkn';
+ $filesubtype = 'unkn';
+ }
+
+ if (($filetype == 'video')) {
+ $attached .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
+ '$video' => [
+ 'id' => $item['author-id'],
+ 'src' => $the_url,
+ 'mime' => $mime,
+ ],
+ ]);
+ } elseif ($filetype == 'audio') {
+ $attached .= Renderer::replaceMacros(Renderer::getMarkupTemplate('audio.tpl'), [
+ '$audio' => [
+ 'id' => $item['author-id'],
+ 'src' => $the_url,
+ 'mime' => $mime,
+ ],
+ ]);
+ } else {
+ $title = Strings::escapeHtml(trim(($attachment['description'] ?? '') ?: $attachment['url']));
+
+ if (!empty($attachment['size'])) {
+ $title .= ' ' . $attachment['size'] . ' ' . DI::l10n()->t('bytes');
+ }
+
+ /// @todo Use a template
+ $icon = '
';
+ $attached .= '
' . $icon . '';
+ }
+ }
+
+ if ($attached != '') {
+ $content .= '
';
+ }
+
+ return $content;
+ }
+
/**
* get private link for item
*
diff --git a/view/templates/audio.tpl b/view/templates/audio.tpl
new file mode 100644
index 000000000..0b0467ab2
--- /dev/null
+++ b/view/templates/audio.tpl
@@ -0,0 +1,4 @@
+
+