From 5d9b6863b66f092100380f88d00df65086e4a1d1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 25 Jan 2022 00:39:46 -0700 Subject: [PATCH] Update atom feeds, include media alt text. Fixes #3184 --- app/Http/Controllers/ProfileController.php | 46 +++++++++++------ resources/views/atom/user.blade.php | 58 +++++++++++----------- 2 files changed, 61 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index eb841178a..83872b443 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 DB; use View; use App\Follower; use App\FollowRequest; @@ -15,6 +16,7 @@ use App\UserFilter; use League\Fractal; use App\Services\AccountService; use App\Services\FollowerService; +use App\Services\StatusService; use App\Util\Lexer\Nickname; use App\Util\Webfinger\Webfinger; use App\Transformer\ActivityPub\ProfileOutbox; @@ -187,20 +189,36 @@ class ProfileController extends Controller { abort_if(!config('federation.atom.enabled'), 404); - $profile = $user = Profile::whereNull('status')->whereNull('domain')->whereUsername($user)->whereIsPrivate(false)->firstOrFail(); - if($profile->status != null) { - return $this->accountCheck($profile); - } - if($profile->is_private || Auth::check()) { - $blocked = $this->blockedProfileCheck($profile); - $check = $this->privateProfileCheck($profile, null); - if($check || $blocked) { - return redirect($profile->url()); - } - } - $items = $profile->statuses()->whereHas('media')->whereIn('visibility',['public', 'unlisted'])->orderBy('created_at', 'desc')->take(10)->get(); - return response()->view('atom.user', compact('profile', 'items')) - ->header('Content-Type', 'application/atom+xml'); + $pid = AccountService::usernameToId($user); + + abort_if(!$pid, 404); + + $profile = AccountService::get($pid); + + abort_if(!$profile || $profile['locked'] || !$profile['local'], 404); + + $items = DB::table('statuses') + ->whereProfileId($pid) + ->whereVisibility('public') + ->whereType('photo') + ->latest() + ->take(10) + ->get() + ->map(function($status) { + return StatusService::get($status->id); + }) + ->filter(function($status) { + return $status && + isset($status['account']) && + isset($status['media_attachments']) && + count($status['media_attachments']); + }) + ->values(); + $permalink = config('app.url') . "/users/{$profile['username']}.atom"; + + return response() + ->view('atom.user', compact('profile', 'items', 'permalink')) + ->header('Content-Type', 'application/atom+xml'); } public function meRedirect() diff --git a/resources/views/atom/user.blade.php b/resources/views/atom/user.blade.php index a99263038..219c11ce4 100644 --- a/resources/views/atom/user.blade.php +++ b/resources/views/atom/user.blade.php @@ -1,38 +1,38 @@ ` won't get parsed as short tags */ - ''.PHP_EOL + /* Using an echo tag here so the `` won't get parsed as short tags */ + ''.PHP_EOL ?> - {{$profile->permalink('.atom')}} - {{$profile->username}} on Pixelfed - {{$profile->bio}} - {{$profile->updated_at->toAtomString()}} + {{$permalink}} + {{$profile['username']}} on Pixelfed + {{$profile['note']}} + {{$profile['created_at']}} - {{$profile->permalink()}} - {{$profile->permalink()}} - {{$profile->permalink()}} - {{$profile->bio}} - - + {{$profile['url']}} + {{$profile['url']}} + {{$profile['url']}} + {{$profile['note']}} + + - - + + @foreach($items as $item) - - {{ $item->caption }} - - {{ $item->url() }} - - profile->username }}]]> - - - iteration}}" src="{{ $item->thumb() }}"> -

{{ $item->caption }}

- ]]> -
- {{ $item->updated_at->toAtomString() }} -
+ + {{ strip_tags($item['content']) }} + + {{ $item['url'] }} + + + + + iteration}}" src="{{ $item['media_attachments'][0]['url'] }}" alt="{{ $item['media_attachments'][0]['description'] }}"> +

{{ $item['content'] }}

+ ]]> +
+ {{ $item['created_at'] }} +
@endforeach