- // Simplify image codes
- $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
-
- // Grab all pictures without alternative descriptions and create attachments out of them
- if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
- foreach ($pictures[1] as $picture) {
- $imgdata = Images::getInfoFromURLCached($picture);
- if ($imgdata) {
- $attachments[] = ['type' => 'Document',
- 'mediaType' => $imgdata['mime'],
- 'url' => $picture,
- 'name' => null];
- }
- }
- }
-
- // Grab all pictures with alternative description and create attachments out of them
- if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
- foreach ($pictures as $picture) {
- $imgdata = Images::getInfoFromURLCached($picture[1]);
- if ($imgdata) {
- $attachments[] = ['type' => 'Document',
- 'mediaType' => $imgdata['mime'],
- 'url' => $picture[1],
- 'name' => $picture[2]];
- }
- }
+ foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) {
+ $attachments[] = ['type' => 'Document',
+ 'mediaType' => $attachment['mimetype'],
+ 'url' => $attachment['url'],
+ 'name' => $attachment['description']];