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 | 1 + .../views/status/embed-removed.blade.php | 46 +++++ resources/views/status/embed.blade.php | 178 ++++++++++++++++++ routes/web.php | 1 + 5 files changed, 241 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 000000000..5acc20efe --- /dev/null +++ b/public/embed.js @@ -0,0 +1 @@ +!function(){var e;e=function(){var e=[];window.addEventListener("message",function(t){var n=t.data||{};"setHeight"===n.type&&e[n.id]&&(e[n.id].height=n.height)}),[].forEach.call(document.querySelectorAll("iframe.pixelfed__embed"),function(t){t.scrolling="no",t.style.overflow="hidden",e.push(t);var n=e.length-1;t.onload=function(){t.contentWindow.postMessage({type:"setHeight",id:n},"*")},t.onload()})},-1!==["interactive","complete"].indexOf(document.readyState)?e():document.addEventListener("DOMContentLoaded",e)}(); \ No newline at end of file diff --git a/resources/views/status/embed-removed.blade.php b/resources/views/status/embed-removed.blade.php new file mode 100644 index 000000000..3e147ec89 --- /dev/null +++ b/resources/views/status/embed-removed.blade.php @@ -0,0 +1,46 @@ + + + + + + + + + + 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');