planiverse

A minimalist, no-JS front-end for Mastodon.
git clone https://git.stjo.hn/planiverse
Log | Files | Refs | README | LICENSE

commit 87e1fbd3aa9119245378a803e69bd52f7e965fc1
parent 144848225f750cf8fa00067268d03c6622947b7e
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Sun, 12 Aug 2018 07:39:01 -0700

Replace regex with media attachments

Replaced the regex that embedded images and switched to using
proper media attachments. Currently only supporting images.

Diffstat:
Mapp/Http/Controllers/TimelineController.php | 20--------------------
Mresources/views/timeline.blade.php | 5+++++
2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php @@ -12,8 +12,6 @@ class TimelineController extends Controller $timeline = Mastodon::domain(env('MASTODON_DOMAIN')) ->get('/timelines/public', ['local' => true]); - $timeline = $this->embed_images($timeline); - return view('timeline', ['statuses' => $timeline]); } @@ -24,24 +22,6 @@ class TimelineController extends Controller ->token($user->token) ->get('/timelines/home'); - $timeline = $this->embed_images($timeline); - return view('timeline', ['statuses' => $timeline]); } - - private function embed_images($timeline) - { - foreach ($timeline as $index => $status) - { - # Search for links to images and replace the inner HTML - # with an img tag of the image itself. - $timeline[$index]['content'] = preg_replace( - '/<a href="([^>]+)\.(png|jpg|jpeg|gif)">([^<]+)<\/a>/', - '<a href="${1}.${2}"><img src="${1}.${2}" alt="${3}" /></a>', - $status['content'] - ); - } - - return $timeline; - } } diff --git a/resources/views/timeline.blade.php b/resources/views/timeline.blade.php @@ -20,6 +20,11 @@ <span class="tooltiptext">{{ $status['account']['acct'] }}</span> </div> <p>{!! $status['content'] !!}</p> + @foreach ($status['media_attachments'] as $attachment) + @if ($attachment['type'] === 'image') + <p><img src="{{ $attachment['url'] }}" alt="{{ $attachment['description'] }}" /></p> + @endif + @endforeach </div> @endforeach </body>