mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-23 03:34:22 -05:00
add: anon forum posts
This commit is contained in:
@@ -66,6 +66,7 @@ class PostController extends Controller
|
||||
$request->validate([
|
||||
'content' => 'required|min:1',
|
||||
'topic_id' => 'required|integer',
|
||||
'anon' => 'sometimes|boolean',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
@@ -76,6 +77,7 @@ class PostController extends Controller
|
||||
|
||||
$post = Post::create([
|
||||
'content' => $request->input('content'),
|
||||
'anon' => $request->boolean('anon'),
|
||||
'user_id' => $user->id,
|
||||
'topic_id' => $topic->id,
|
||||
]);
|
||||
@@ -115,7 +117,11 @@ class PostController extends Controller
|
||||
$staffer->notify(new NewPost('staff', $user, $post));
|
||||
}
|
||||
} else {
|
||||
$this->chatRepository->systemMessage(\sprintf('[url=%s]%s[/url] has left a reply on topic [url=%s]%s[/url]', $profileUrl, $user->username, $postUrl, $topic->name));
|
||||
if ($post->anon) {
|
||||
$this->chatRepository->systemMessage(\sprintf('An anonymous user has left a reply on topic [url=%s]%s[/url]', $postUrl, $topic->name));
|
||||
} else {
|
||||
$this->chatRepository->systemMessage(\sprintf('[url=%s]%s[/url] has left a reply on topic [url=%s]%s[/url]', $profileUrl, $user->username, $postUrl, $topic->name));
|
||||
}
|
||||
|
||||
$topicStarter = $topic->user;
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ class TopicController extends Controller
|
||||
$request->validate([
|
||||
'title' => 'required',
|
||||
'content' => 'required',
|
||||
'anon' => 'sometimes|boolean',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
@@ -118,6 +119,7 @@ class TopicController extends Controller
|
||||
|
||||
$post = Post::create([
|
||||
'content' => $request->input('content'),
|
||||
'anon' => $request->boolean('anon'),
|
||||
'user_id' => $user->id,
|
||||
'topic_id' => $topic->id,
|
||||
]);
|
||||
@@ -148,10 +150,14 @@ class TopicController extends Controller
|
||||
->get();
|
||||
|
||||
foreach ($staffers as $staffer) {
|
||||
$staffer->notify(new NewTopic('staff', $user, $topic));
|
||||
$staffer->notify(new NewTopic('staff', $user, $topic, $post));
|
||||
}
|
||||
} else {
|
||||
$this->chatRepository->systemMessage(\sprintf('[url=%s]%s[/url] has created a new topic [url=%s]%s[/url]', $profileUrl, $user->username, $topicUrl, $topic->name));
|
||||
if ($post->anon) {
|
||||
$this->chatRepository->systemMessage(\sprintf('An anonymous user has created a new topic [url=%s]%s[/url]', $topicUrl, $topic->name));
|
||||
} else {
|
||||
$this->chatRepository->systemMessage(\sprintf('[url=%s]%s[/url] has created a new topic [url=%s]%s[/url]', $profileUrl, $user->username, $topicUrl, $topic->name));
|
||||
}
|
||||
|
||||
$subscribers = User::query()
|
||||
->where('id', '!=', $topic->first_post_user_id)
|
||||
@@ -168,7 +174,7 @@ class TopicController extends Controller
|
||||
->get();
|
||||
|
||||
foreach ($subscribers as $subscriber) {
|
||||
$subscriber->notify(new NewTopic('forum', $user, $topic));
|
||||
$subscriber->notify(new NewTopic('forum', $user, $topic, $post));
|
||||
}
|
||||
|
||||
//Achievements
|
||||
|
||||
@@ -25,6 +25,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $content
|
||||
* @property bool $anon
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property int $user_id
|
||||
@@ -44,10 +45,23 @@ class Post extends Model
|
||||
*/
|
||||
protected $fillable = [
|
||||
'content',
|
||||
'anon',
|
||||
'topic_id',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array{anon: 'bool'}
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'anon' => 'bool',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Belongs To A Topic.
|
||||
*
|
||||
|
||||
@@ -88,27 +88,31 @@ class NewPost extends Notification implements ShouldQueue
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
public function toArray(User $notifiable): array
|
||||
{
|
||||
$username = ($this->post->anon && !$notifiable->group->is_modo && !$notifiable->is($this->user))
|
||||
? 'Anonymous'
|
||||
: $this->user->username;
|
||||
|
||||
if ($this->type == 'subscription') {
|
||||
return [
|
||||
'title' => $this->user->username.' Has Posted In A Subscribed Topic',
|
||||
'body' => $this->user->username.' has left a new post in Subscribed Topic '.$this->post->topic->name,
|
||||
'title' => $username.' Has Posted In A Subscribed Topic',
|
||||
'body' => $username.' has left a new post in Subscribed Topic '.$this->post->topic->name,
|
||||
'url' => \sprintf('/forums/topics/%s/posts/%s', $this->post->topic->id, $this->post->id),
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->type == 'staff') {
|
||||
return [
|
||||
'title' => $this->user->username.' Has Posted In A Staff Forum Topic',
|
||||
'body' => $this->user->username.' has left a new post in Staff Topic '.$this->post->topic->name,
|
||||
'title' => $username.' Has Posted In A Staff Forum Topic',
|
||||
'body' => $username.' has left a new post in Staff Topic '.$this->post->topic->name,
|
||||
'url' => \sprintf('%s/posts/%s', route('topics.show', ['id' => $this->post->topic->id]), $this->post->id),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $this->user->username.' Has Posted In A Topic You Started',
|
||||
'body' => $this->user->username.' has left a new post in Your Topic '.$this->post->topic->name,
|
||||
'title' => $username.' Has Posted In A Topic You Started',
|
||||
'body' => $username.' has left a new post in Your Topic '.$this->post->topic->name,
|
||||
'url' => \sprintf('/forums/topics/%s/posts/%s', $this->post->topic->id, $this->post->id),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\Topic;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@@ -29,7 +30,7 @@ class NewTopic extends Notification implements ShouldQueue
|
||||
/**
|
||||
* NewTopic Constructor.
|
||||
*/
|
||||
public function __construct(public string $type, public User $user, public Topic $topic)
|
||||
public function __construct(public string $type, public User $user, public Topic $topic, public ?Post $firstPost = null)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -66,19 +67,23 @@ class NewTopic extends Notification implements ShouldQueue
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
public function toArray(User $notifiable): array
|
||||
{
|
||||
$username = ($this->firstPost?->anon && !$notifiable->group->is_modo && !$notifiable->is($this->user))
|
||||
? 'Anonymous'
|
||||
: $this->user->username;
|
||||
|
||||
if ($this->type == 'staff') {
|
||||
return [
|
||||
'title' => $this->user->username.' Has Posted In A Staff Forum',
|
||||
'body' => $this->user->username.' has started a new staff topic in '.$this->topic->forum->name,
|
||||
'title' => $username.' Has Posted In A Staff Forum',
|
||||
'body' => $username.' has started a new staff topic in '.$this->topic->forum->name,
|
||||
'url' => route('topics.show', ['id' => $this->topic->id]),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'title' => $this->user->username.' Has Posted In A Subscribed Forum',
|
||||
'body' => $this->user->username.' has started a new topic in '.$this->topic->forum->name,
|
||||
'title' => $username.' Has Posted In A Subscribed Forum',
|
||||
'body' => $username.' has started a new topic in '.$this->topic->forum->name,
|
||||
'url' => \sprintf('/forums/topics/%s', $this->topic->id),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* NOTICE OF LICENSE.
|
||||
*
|
||||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D Community Edition
|
||||
*
|
||||
* @author HDVinnie <hdinnovations@protonmail.com>
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('posts', function (Blueprint $table): void {
|
||||
$table->boolean('anon')->default(false)->after('content');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1296,6 +1296,7 @@ DROP TABLE IF EXISTS `posts`;
|
||||
CREATE TABLE `posts` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`anon` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
`user_id` int unsigned NOT NULL,
|
||||
@@ -3031,3 +3032,4 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (357,'2025_07_15_06
|
||||
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (358,'2025_08_22_064916_add_season_episode_to_requests_table',1);
|
||||
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (359,'2025_08_30_015125_create_torrent_reseeds_table',1);
|
||||
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (360,'2025_09_02_013312_add_color_icon_to_ticket_priorities_table',1);
|
||||
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (361,'2025_09_02_140036_add_anon_to_posts_table',1);
|
||||
|
||||
@@ -159,64 +159,68 @@
|
||||
<figure class="post__figure">
|
||||
<img
|
||||
class="post__avatar"
|
||||
src="{{ $post->user->image === null ? url('img/profile.png') : route('authenticated_images.user_avatar', ['user' => $post->user]) }}"
|
||||
src="{{ $post->anon && auth()->user()->isNot($post->user) &&! auth()->user()->group->is_modo ? url('img/profile.png') : ($post->user->image === null ? url('img/profile.png') : route('authenticated_images.user_avatar', ['user' => $post->user])) }}"
|
||||
alt=""
|
||||
/>
|
||||
</figure>
|
||||
<x-user-tag class="post__author" :anon="false" :user="$post->user">
|
||||
<x-user-tag class="post__author" :anon="$post->anon" :user="$post->user">
|
||||
<x-slot:appended-icons>
|
||||
@if ($post->user->isOnline())
|
||||
<i
|
||||
class="{{ config('other.font-awesome') }} fa-circle text-green"
|
||||
title="Online"
|
||||
></i>
|
||||
@else
|
||||
<i
|
||||
class="{{ config('other.font-awesome') }} fa-circle text-red"
|
||||
title="Offline"
|
||||
></i>
|
||||
@if (! $post->anon ||auth()->user()->is($post->user) ||auth()->user()->group->is_modo)
|
||||
@if ($post->user->isOnline())
|
||||
<i
|
||||
class="{{ config('other.font-awesome') }} fa-circle text-green"
|
||||
title="Online"
|
||||
></i>
|
||||
@else
|
||||
<i
|
||||
class="{{ config('other.font-awesome') }} fa-circle text-red"
|
||||
title="Offline"
|
||||
></i>
|
||||
@endif
|
||||
<a
|
||||
href="{{ route('users.conversations.create', ['user' => auth()->user(), 'username' => $post->user->username]) }}"
|
||||
>
|
||||
<i class="{{ config('other.font-awesome') }} fa-envelope text-info"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a
|
||||
href="{{ route('users.conversations.create', ['user' => auth()->user(), 'username' => $post->user->username]) }}"
|
||||
>
|
||||
<i class="{{ config('other.font-awesome') }} fa-envelope text-info"></i>
|
||||
</a>
|
||||
</x-slot>
|
||||
</x-user-tag>
|
||||
@if (! empty($post->user->title))
|
||||
<p class="post__author-title">
|
||||
{{ $post->user->title }}
|
||||
</p>
|
||||
@endif
|
||||
@if (! $post->anon ||auth()->user()->is($post->user) ||auth()->user()->group->is_modo)
|
||||
@if (! empty($post->user->title))
|
||||
<p class="post__author-title">
|
||||
{{ $post->user->title }}
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<dl class="post__author-join">
|
||||
<dt>Joined</dt>
|
||||
<dd>
|
||||
<time
|
||||
class="post__author-join-datetime"
|
||||
datetime="{{ $post->user->created_at }}"
|
||||
title="{{ $post->user->created_at }}"
|
||||
>
|
||||
{{ date('d M Y', $post->user->created_at?->getTimestamp() ?? '') }}
|
||||
</time>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="post__author-topics">
|
||||
<dt>
|
||||
<a href="{{ route('users.topics.index', ['user' => $post->user]) }}">
|
||||
{{ __('forum.topics') }}
|
||||
</a>
|
||||
</dt>
|
||||
<dd>{{ $post->author_topics_count ?? '0' }}</dd>
|
||||
</dl>
|
||||
<dl class="post__author-posts">
|
||||
<dt>
|
||||
<a href="{{ route('users.posts.index', ['user' => $post->user]) }}">
|
||||
{{ __('forum.posts') }}
|
||||
</a>
|
||||
</dt>
|
||||
<dd>{{ $post->author_posts_count ?? '0' }}</dd>
|
||||
</dl>
|
||||
<dl class="post__author-join">
|
||||
<dt>Joined</dt>
|
||||
<dd>
|
||||
<time
|
||||
class="post__author-join-datetime"
|
||||
datetime="{{ $post->user->created_at }}"
|
||||
title="{{ $post->user->created_at }}"
|
||||
>
|
||||
{{ date('d M Y', $post->user->created_at?->getTimestamp() ?? '') }}
|
||||
</time>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="post__author-topics">
|
||||
<dt>
|
||||
<a href="{{ route('users.topics.index', ['user' => $post->user]) }}">
|
||||
{{ __('forum.topics') }}
|
||||
</a>
|
||||
</dt>
|
||||
<dd>{{ $post->author_topics_count ?? '0' }}</dd>
|
||||
</dl>
|
||||
<dl class="post__author-posts">
|
||||
<dt>
|
||||
<a href="{{ route('users.posts.index', ['user' => $post->user]) }}">
|
||||
{{ __('forum.posts') }}
|
||||
</a>
|
||||
</dt>
|
||||
<dd>{{ $post->author_posts_count ?? '0' }}</dd>
|
||||
</dl>
|
||||
@endif
|
||||
</aside>
|
||||
<div
|
||||
class="post__content bbcode-rendered"
|
||||
@@ -225,7 +229,7 @@
|
||||
>
|
||||
@bbcode($post->content)
|
||||
</div>
|
||||
@if (! empty($post->user->signature))
|
||||
@if (! empty($post->user->signature) &&(! $post->anon ||auth()->user()->is($post->user) ||auth()->user()->group->is_modo))
|
||||
<footer class="post__footer" x-init>
|
||||
<p class="post__signature">
|
||||
@bbcode($post->user->signature)
|
||||
|
||||
@@ -63,6 +63,18 @@
|
||||
</label>
|
||||
</p>
|
||||
@livewire('bbcode-input', ['name' => 'content', 'label' => __('forum.post'), 'required' => true ])
|
||||
<p class="form__group">
|
||||
<input type="hidden" name="anon" value="0" />
|
||||
<input
|
||||
type="checkbox"
|
||||
class="form__checkbox"
|
||||
id="anon"
|
||||
name="anon"
|
||||
value="1"
|
||||
@checked(old('anon'))
|
||||
/>
|
||||
<label class="form__label" for="anon">{{ __('common.anonymous') }}?</label>
|
||||
</p>
|
||||
<button class="form__button form__button--filled">
|
||||
{{ __('forum.send-new-topic') }}
|
||||
</button>
|
||||
|
||||
@@ -48,6 +48,18 @@
|
||||
@csrf
|
||||
<input type="hidden" name="topic_id" value="{{ $topic->id }}" />
|
||||
@livewire('bbcode-input', ['name' => 'content', 'label' => __('forum.post') ])
|
||||
<p class="form__group">
|
||||
<input type="hidden" name="anon" value="0" />
|
||||
<input
|
||||
type="checkbox"
|
||||
class="form__checkbox"
|
||||
id="anon"
|
||||
name="anon"
|
||||
value="1"
|
||||
@checked(old('anon'))
|
||||
/>
|
||||
<label class="form__label" for="anon">{{ __('common.anonymous') }}?</label>
|
||||
</p>
|
||||
<p class="form__group">
|
||||
<button type="submit" class="form__button form__button--filled">
|
||||
{{ __('common.submit') }}
|
||||
|
||||
Reference in New Issue
Block a user