From 1fecf7170ce76251006ff50731a82a957a137933 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 23 Nov 2019 21:44:41 -0700 Subject: [PATCH] Add post embeds --- app/Http/Controllers/StatusController.php | 20 +- public/embed.js | Bin 0 -> 520 bytes .../views/status/embed-removed.blade.php | 46 +++++ resources/views/status/embed.blade.php | 178 ++++++++++++++++++ routes/web.php | 1 + 5 files changed, 240 insertions(+), 5 deletions(-) create mode 100644 public/embed.js create mode 100644 resources/views/status/embed-removed.blade.php create mode 100644 resources/views/status/embed.blade.php diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 7327cc0a4..f8e37a296 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -76,13 +76,23 @@ class StatusController extends Controller public function showEmbed(Request $request, $username, int $id) { - abort(404); - $profile = Profile::whereNull('status')->whereUsername($username)->first(); - $status = Status::whereProfileId($profile->id)->whereScope('public')->find($id); - if(!$profile || !$status) { + $profile = Profile::whereNull(['domain','status'])->whereUsername($username)->first(); + if(!$profile) { return view('status.embed-removed'); } - return view('status.embed', compact('status')); + $status = Status::whereProfileId($profile->id) + ->whereNull('uri') + ->whereScope('public') + ->whereIsNsfw(false) + ->whereIn('type', ['photo', 'video']) + ->find($id); + if(!$status) { + return view('status.embed-removed'); + } + $showLikes = $request->filled('likes') && $request->likes == true; + $showCaption = $request->filled('caption') && $request->caption !== false; + $layout = $request->filled('layout') && $request->layout == 'compact' ? 'compact' : 'full'; + return view('status.embed', compact('status', 'showLikes', 'showCaption', 'layout')); } public function showObject(Request $request, $username, int $id) diff --git a/public/embed.js b/public/embed.js new file mode 100644 index 0000000000000000000000000000000000000000..5acc20efeefbe8f96118d48eddf247477b824aea GIT binary patch literal 520 zcmZXRO>4t242J*8>O-)HYv{GXjIkAVXz8Jc9YQHytRx1<&KxCeX!GCaE~ERp30Z!4 z^=MXfE=S`XW#?XnJ4iwPZOLq(9*xufD3sQ#9vrSsi{KzoQbXIS5(vNj!inT03awCG zF6S{NE#M27vO*%IbOMJ4k_0j*jNT^+{i;OuITHt_f{l!4dr|nXQh6nEWi8b{@9G#q zymt_W9azZGhsXFrOc7KKqA@411?a;8>Nn7Y{mO=-&4ahrxKa}536BjNEC}C2D6Bt9 zQW>qm5gt)pTTx``RgIG%EVvS@`65N(o%Krpl!YSqE^5KoNmk=q+)R4t`MUA)hX!u+ z(v6(l6E?;O6OG1&M?PQ7q|Atktf1m?`e>KrzHTfakiCd>IBkn>69JSScBl~815mcS XDf)k|=k4Zc3b~HyqZ|%wq%8davst + + + + + + + + + Pixelfed | 404 Embed Not Found + + + + + + + + + + + + +
+
+
+ +

Pixelfed

+

The link to this photo or video may be broken, or the post may have been removed.

+

Visit Pixelfed

+
+
+
+ + + diff --git a/resources/views/status/embed.blade.php b/resources/views/status/embed.blade.php new file mode 100644 index 000000000..42f9a2594 --- /dev/null +++ b/resources/views/status/embed.blade.php @@ -0,0 +1,178 @@ + + + + + + + + + + {{ $title ?? config('app.name', 'Pixelfed') }} + + + + + + + + + + + + + + +
+ @php($item = $status) +
+ + + @php($status = $item) + @switch($status->viewType()) + @case('photo') + @case('image') + @if($status->is_nsfw) +
+ +

CW / NSFW / Hidden Media

+

(click to show)

+
+
+ + +
+ @else +
+ +
+ @endif + @break + @case('album') + @if($status->is_nsfw) + + @else + + @endif + @break + @case('video') + @if($status->is_nsfw) +
+ +

CW / NSFW / Hidden Media

+

(click to show)

+
+
+ +
+
+ @else +
+ +
+ @endif + @break + @case('video-album') + @if($status->is_nsfw) +
+ +

CW / NSFW / Hidden Media

+

(click to show)

+
+
+ +
+
+ @else +
+ +
+ @endif + @break + @endswitch + + @if($layout != 'compact') +
+ +
+ @if($showLikes) + + @endif +
+

+ + {{$item->profile->username}} + + @if($showCaption) + {!! $item->rendered ?? e($item->caption) !!} + @endif +

+
+
+ @endif + +
+
+ + + + diff --git a/routes/web.php b/routes/web.php index 08593aa01..1774e7cbb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -373,6 +373,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('c/{collection}', 'CollectionController@show'); Route::get('p/{username}/{id}/c', 'CommentController@showAll'); + Route::get('p/{username}/{id}/embed', 'StatusController@showEmbed'); Route::get('p/{username}/{id}/edit', 'StatusController@edit'); Route::post('p/{username}/{id}/edit', 'StatusController@editStore'); Route::get('p/{username}/{id}.json', 'StatusController@showObject');