diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 59fc4f451..7e66211d2 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Auth; use Cache; +use View; use App\Follower; use App\FollowRequest; use App\Profile; @@ -189,4 +190,29 @@ class ProfileController extends Controller abort_if(!Auth::check(), 404); return redirect(Auth::user()->url()); } + + public function embed(Request $request, $username) + { + $res = view('profile.embed-removed'); + + if(strlen($username) > 15 || strlen($username) < 2) { + return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); + } + + $profile = Profile::whereUsername($username) + ->whereIsPrivate(false) + ->whereNull('status') + ->whereNull('domain') + ->first(); + + if(!$profile) { + return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); + } + + $content = Cache::remember('profile:embed:'.$profile->id, now()->addHours(12), function() use($profile) { + return View::make('profile.embed')->with(compact('profile'))->render(); + }); + + return response($content)->withHeaders(['X-Frame-Options' => 'ALLOWALL']); + } } diff --git a/resources/views/profile/embed-removed.blade.php b/resources/views/profile/embed-removed.blade.php new file mode 100644 index 000000000..5cb28218b --- /dev/null +++ b/resources/views/profile/embed-removed.blade.php @@ -0,0 +1,46 @@ + + + + + + + + + + Pixelfed | 404 Embed Not Found + + + + + + + + + + + + +
+
+
+ +

Pixelfed

+

Cannot display profile embed, it may be deleted or set to private.

+

Visit Pixelfed

+
+
+
+ + + diff --git a/resources/views/profile/embed.blade.php b/resources/views/profile/embed.blade.php new file mode 100644 index 000000000..3d5e3de11 --- /dev/null +++ b/resources/views/profile/embed.blade.php @@ -0,0 +1,101 @@ + + + + + + + + + + {{ $title ?? config('app.name', 'Pixelfed') }} + + + + + + + + + + + + + + +
+
+ +
+
+
+

{{$profile->statuses()->count()}}

+

Posts

+
+
+

{{$profile->followers()->count()}}

+

Followers

+
+
+

{{$profile->following()->count()}}

+

Following

+
+
+

Follow

+
+
+
+ @foreach($profile->statuses()->latest()->whereScope('public')->whereIsNsfw(false)->has('media')->whereType('photo')->take(9)->get() as $post) + + @endforeach +
+
+ +
+
+ + + + + + + + diff --git a/routes/web.php b/routes/web.php index 26b20c558..a2dc0bc23 100644 --- a/routes/web.php +++ b/routes/web.php @@ -382,5 +382,6 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('p/{username}/{id}/edit', 'StatusController@editStore'); Route::get('p/{username}/{id}.json', 'StatusController@showObject'); Route::get('p/{username}/{id}', 'StatusController@show'); + Route::get('{username}/embed', 'ProfileController@embed'); Route::get('{username}', 'ProfileController@show'); });