From 39b7fd6dca0ed5b02a0382c20200879c6ee76186 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 21 May 2020 22:31:56 +0200 Subject: [PATCH 1/2] fix crash when a user was deleted. fixes #12 --- src/Controller/DiscussionFeedController.php | 4 +++- src/Controller/DiscussionsActivityFeedController.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Controller/DiscussionFeedController.php b/src/Controller/DiscussionFeedController.php index a3b9161..5538ddc 100644 --- a/src/Controller/DiscussionFeedController.php +++ b/src/Controller/DiscussionFeedController.php @@ -101,7 +101,9 @@ protected function getFeedContent(Request $request) 'content' => $this->summarize($this->stripHTML($post->attributes->contentHtml)), 'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $post->attributes->number]) . '/' . $post->attributes->number, // TODO check out why the near parameter refuses to work 'pubdate' => $this->parseDate($post->attributes->createdAt), - 'author' => $this->getRelationship($posts, $post->relationships->user)->username + 'author' => ($post->relationships->user !== null) + ? $this->getRelationship($posts, $post->relationships->user)->username + : $this->translator->trans('core.lib.username.deleted_text') ]; $modified = $this->parseDate($post->attributes->editedAt || $post->attributes->createdAt); diff --git a/src/Controller/DiscussionsActivityFeedController.php b/src/Controller/DiscussionsActivityFeedController.php index 0937559..49deeaa 100644 --- a/src/Controller/DiscussionsActivityFeedController.php +++ b/src/Controller/DiscussionsActivityFeedController.php @@ -137,13 +137,22 @@ protected function getFeedContent(Request $request) $content->contentHtml = ''; } + $userRelation = null; + if($this->lastTopics && isset($discussion->relationships->user)) { + $userRelation = $discussion->relationships->user; + } elseif (isset($discussion->relationships->lastPostedUser)) { + $userRelation = $discussion->relationships->lastPostedUser; + } + $entries[] = [ 'title' => $discussion->attributes->title, 'content' => $this->summarize($this->stripHTML($content->contentHtml)), 'id' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug]), 'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $content->number]) . '/' . $content->number, // TODO same than DiscussionFeedController 'pubdate' => $this->parseDate($this->lastTopics ? $discussion->attributes->createdAt : $discussion->attributes->lastPostedAt), - 'author' => $this->getRelationship($last_discussions, $this->lastTopics ? $discussion->relationships->user : $discussion->relationships->lastPostedUser)->username + 'author' => $userRelation !== null + ? $this->getRelationship($last_discussions, $userRelation)->username + : $this->translator->trans('core.lib.username.deleted_text') ]; $modified = $this->parseDate($this->lastTopics ? $discussion->attributes->createdAt : $discussion->attributes->lastPostedAt); From 59c801518644f30a56673cf6fc02389a321fdd6f Mon Sep 17 00:00:00 2001 From: zgq354 Date: Tue, 14 Apr 2020 17:57:56 +0800 Subject: [PATCH 2/2] ensure the author name is properly wrapped for XML This ensures that any special char in the author name wil not break the XML. Special chars are unlikely in vanilla flarum, but might be added by extensions or imports from other forum software --- views/atom.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/atom.blade.php b/views/atom.blade.php index 63c294d..c06de23 100644 --- a/views/atom.blade.php +++ b/views/atom.blade.php @@ -20,7 +20,7 @@ type="html" @endif> - {{ $entry['author'] }} + @endforeach