From 2abca641c78081fe382a74161eda0f82b8a884c6 Mon Sep 17 00:00:00 2001 From: Hyleus Date: Thu, 25 Jan 2018 12:52:58 +0100 Subject: [PATCH 1/3] Modify the latest posts block to show only posts that are viewable by the user --- app/Post.php | 10 ++++++++++ resources/views/blocks/latest_posts.blade.php | 2 ++ 2 files changed, 12 insertions(+) diff --git a/app/Post.php b/app/Post.php index 5d13c9067f..b6bfb4d599 100755 --- a/app/Post.php +++ b/app/Post.php @@ -13,6 +13,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Auth; use App\Helpers\Bbcode; /** @@ -104,6 +105,15 @@ public function getBrief($length = 100, $ellipses = true, $strip_html = false) return $trimmed_text; } + public function viewable() + { + if (Auth::user()->group->is_modo) { + return true; + } + + return $this->topic->forum->getPermission()->read_topic; + } + public function getPostNumber() { return $this->topic->postNumberFromId($this->id); diff --git a/resources/views/blocks/latest_posts.blade.php b/resources/views/blocks/latest_posts.blade.php index db8cf1f2f3..47211af34e 100644 --- a/resources/views/blocks/latest_posts.blade.php +++ b/resources/views/blocks/latest_posts.blade.php @@ -16,12 +16,14 @@ @foreach($posts as $p) + @if ($p->viewable()) {{ preg_replace('#\[[^\]]+\]#', '', str_limit($p->content), 75) }}... {{ $p->topic->name }} {{ $p->user->username }} {{ $p->updated_at->diffForHumans() }} + @endif @endforeach From 7dd067ff7894dc3892f308f2b01c6a4b8787abd1 Mon Sep 17 00:00:00 2001 From: Hyleus Date: Thu, 25 Jan 2018 12:56:14 +0100 Subject: [PATCH 2/3] Modify the latest topics block to show only topics that are viewable by the user --- app/Topic.php | 10 ++++++++++ resources/views/blocks/latest_topics.blade.php | 2 ++ 2 files changed, 12 insertions(+) diff --git a/app/Topic.php b/app/Topic.php index ed55674728..70da47fa85 100755 --- a/app/Topic.php +++ b/app/Topic.php @@ -13,6 +13,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Auth; class Topic extends Model { @@ -46,6 +47,15 @@ public function posts() return $this->hasMany(\App\Post::class); } + public function viewable() + { + if (Auth::user()->group->is_modo) { + return true; + } + + return $this->forum->getPermission()->read_topic; + } + public function postNumberFromId($searchId) { $count = 0; diff --git a/resources/views/blocks/latest_topics.blade.php b/resources/views/blocks/latest_topics.blade.php index e2bc56291d..e7dce5824c 100644 --- a/resources/views/blocks/latest_topics.blade.php +++ b/resources/views/blocks/latest_topics.blade.php @@ -15,11 +15,13 @@ @foreach($topics as $t) + @if ($t->viewable()) {{ $t->name }} {{ $t->first_post_user_username }} {{ $t->created_at->diffForHumans() }} + @endif @endforeach From 540b4760b30b1954c946549c6e70b2861051da01 Mon Sep 17 00:00:00 2001 From: Hyleus Date: Thu, 25 Jan 2018 12:57:29 +0100 Subject: [PATCH 3/3] Refactor latest posts block --- app/Post.php | 10 ---------- resources/views/blocks/latest_posts.blade.php | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/app/Post.php b/app/Post.php index b6bfb4d599..5d13c9067f 100755 --- a/app/Post.php +++ b/app/Post.php @@ -13,7 +13,6 @@ namespace App; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Facades\Auth; use App\Helpers\Bbcode; /** @@ -105,15 +104,6 @@ public function getBrief($length = 100, $ellipses = true, $strip_html = false) return $trimmed_text; } - public function viewable() - { - if (Auth::user()->group->is_modo) { - return true; - } - - return $this->topic->forum->getPermission()->read_topic; - } - public function getPostNumber() { return $this->topic->postNumberFromId($this->id); diff --git a/resources/views/blocks/latest_posts.blade.php b/resources/views/blocks/latest_posts.blade.php index 47211af34e..963275eaf7 100644 --- a/resources/views/blocks/latest_posts.blade.php +++ b/resources/views/blocks/latest_posts.blade.php @@ -16,7 +16,7 @@ @foreach($posts as $p) - @if ($p->viewable()) + @if ($p->topic->viewable()) {{ preg_replace('#\[[^\]]+\]#', '', str_limit($p->content), 75) }}... {{ $p->topic->name }}