Bläddra i källkod

Update atom feeds, include media alt text. Fixes #3184

Daniel Supernault 3 år sedan
förälder
incheckning
5d9b6863b6
2 ändrade filer med 61 tillägg och 43 borttagningar
  1. 32 14
      app/Http/Controllers/ProfileController.php
  2. 29 29
      resources/views/atom/user.blade.php

+ 32 - 14
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()

+ 29 - 29
resources/views/atom/user.blade.php

@@ -1,38 +1,38 @@
 <?=
-    /* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
-    '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
+	/* Using an echo tag here so the `<? ... ?>` won't get parsed as short tags */
+	'<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL
 ?>
 <feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
-  <id>{{$profile->permalink('.atom')}}</id>
-  <title>{{$profile->username}} on Pixelfed</title>
-  <subtitle>{{$profile->bio}}</subtitle>
-  <updated>{{$profile->updated_at->toAtomString()}}</updated>
+  <id>{{$permalink}}</id>
+  <title>{{$profile['username']}} on Pixelfed</title>
+  <subtitle type="html">{{$profile['note']}}</subtitle>
+  <updated>{{$profile['created_at']}}</updated>
   <logo></logo>
   <author>
-    <id>{{$profile->permalink()}}</id>
-    <uri>{{$profile->permalink()}}</uri>
-    <name>{{$profile->permalink()}}</name>
-    <summary type="html">{{$profile->bio}}</summary>
-    <link rel="alternate" type="text/html" href="{{$profile->url()}}"/>
-    <link rel="avatar" type="image/jpeg" media:width="120" media:height="120" href="{{$profile->avatarUrl()}}"/>
+	<id>{{$profile['url']}}</id>
+	<uri>{{$profile['url']}}</uri>
+	<name>{{$profile['url']}}</name>
+	<summary type="html">{{$profile['note']}}</summary>
+	<link rel="alternate" type="text/html" href="{{$profile['url']}}"/>
+	<link rel="avatar" type="image/jpeg" media:width="120" media:height="120" href="{{$profile['avatar']}}"/>
   </author>
-  <link rel="alternate" type="text/html" href="{{$profile->url()}}"/>
-  <link rel="self" type="application/atom+xml" href="{{$profile->permalink('.atom')}}"/>
+  <link rel="alternate" type="text/html" href="{{$profile['url']}}"/>
+  <link rel="self" type="application/atom+xml" href="{{$permalink}}"/>
 @foreach($items as $item)
-    <entry>
-        <title>{{ $item->caption }}</title>
-        <link rel="alternate" href="{{ $item->url() }}" />
-        <id>{{ $item->url() }}</id>
-        <author>
-            <name> <![CDATA[{{ $item->profile->username }}]]></name>
-        </author>
-        <summary type="html">
-        <![CDATA[
-            <img id="rss_item_{{$loop->iteration}}" src="{{ $item->thumb() }}">
-            <p style="padding:10px;">{{ $item->caption }}</p>
-          ]]>
-        </summary>
-        <updated>{{ $item->updated_at->toAtomString() }}</updated>
-    </entry>
+	<entry>
+		<title>{{ strip_tags($item['content']) }}</title>
+		<link rel="alternate" href="{{ $item['url'] }}" />
+		<id>{{ $item['url'] }}</id>
+		<author>
+			<name> <![CDATA[{{ $profile['username'] }}]]></name>
+		</author>
+		<summary type="html">
+		<![CDATA[
+			<img id="rss_item_{{$loop->iteration}}" src="{{ $item['media_attachments'][0]['url'] }}" alt="{{ $item['media_attachments'][0]['description'] }}">
+			<p style="padding:10px;">{{ $item['content'] }}</p>
+		  ]]>
+		</summary>
+		<updated>{{ $item['created_at'] }}</updated>
+	</entry>
 @endforeach
 </feed>