mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-05-03 16:59:32 -05:00
(Update) Cleanup Forums System
This commit is contained in:
@@ -59,16 +59,14 @@ class ForumController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for topics
|
||||
*
|
||||
* @access public
|
||||
* @return View page.torrents
|
||||
* Search For Topics
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function search(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$search = $request->input('name');
|
||||
$results = Topic::where([
|
||||
['name', 'like', '%' . $request->input('name') . '%'],
|
||||
])->latest()->paginate(25);
|
||||
@@ -79,73 +77,88 @@ class ForumController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the forum homepage
|
||||
* Show All Forums
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$categories = Forum::oldest('position')->get();
|
||||
|
||||
// Total Forums Count
|
||||
$num_forums = Forum::all()->count();
|
||||
// Total Posts Count
|
||||
$num_posts = Post::all()->count();
|
||||
// Total Topics Count
|
||||
$num_topics = Topic::all()->count();
|
||||
return view('forum.index', ['categories' => $categories, 'num_posts' => $num_posts, 'num_forums' => $num_forums, 'num_topics' => $num_topics]);
|
||||
|
||||
return view('forum.index', [
|
||||
'categories' => $categories,
|
||||
'num_posts' => $num_posts,
|
||||
'num_forums' => $num_forums,
|
||||
'num_topics' => $num_topics
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the requested category
|
||||
* Show The Forum Category
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return void
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function category($slug, $id)
|
||||
{
|
||||
$category = Forum::findOrFail($id);
|
||||
|
||||
if ($category->getPermission()->show_forum != true) {
|
||||
return redirect()->route('forum_index')->with(Toastr::error('You Do Not Have Access To This Category!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Do Not Have Access To This Category!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
return view('forum.category', ['c' => $category]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows forums and topics inside
|
||||
* Show Forums And Topics Inside
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return View forum.display
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function display($slug, $id)
|
||||
{
|
||||
// Find the topic
|
||||
$forum = Forum::findOrFail($id);
|
||||
|
||||
// Check if this is a category or forum
|
||||
if ($forum->parent_id == 0) {
|
||||
return redirect()->route('forum_category', ['slug' => $forum->slug, 'id' => $forum->id]);
|
||||
}
|
||||
$category = Forum::findOrFail($forum->parent_id);
|
||||
|
||||
// Check if the user has permission to view the forum
|
||||
$category = Forum::findOrFail($forum->parent_id);
|
||||
if ($category->getPermission()->show_forum != true) {
|
||||
return redirect()->route('forum_index')->with(Toastr::error('You Do Not Have Access To This Forum!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Do Not Have Access To This Forum!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
// Fetch topics->posts in descending order
|
||||
$topics = $forum->topics()->latest('pinned')->latest('last_reply_at')->latest()->paginate(25);
|
||||
|
||||
return view('forum.display', ['forum' => $forum, 'topics' => $topics, 'category' => $category]);
|
||||
return view('forum.display', [
|
||||
'forum' => $forum,
|
||||
'topics' => $topics,
|
||||
'category' => $category
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the topic
|
||||
* Show The Topic
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return forum.topic
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function topic($slug, $id)
|
||||
{
|
||||
@@ -167,21 +180,30 @@ class ForumController extends Controller
|
||||
// The user can post a topic here ?
|
||||
if ($category->getPermission()->read_topic != true) {
|
||||
// Redirect him to the forum index
|
||||
return redirect()->route('forum_index')->with(Toastr::error('You Do Not Have Access To Read This Topic!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Do Not Have Access To Read This Topic!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
// Increment view
|
||||
$topic->views++;
|
||||
$topic->save();
|
||||
|
||||
return view('forum.topic', ['topic' => $topic, 'forum' => $forum, 'category' => $category, 'posts' => $posts, 'firstPost' => $firstPost]);
|
||||
return view('forum.topic', [
|
||||
'topic' => $topic,
|
||||
'forum' => $forum,
|
||||
'category' => $category,
|
||||
'posts' => $posts,
|
||||
'firstPost' => $firstPost
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reply to a topic
|
||||
* Add A Post To A Topic
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function reply(Request $request, $slug, $id)
|
||||
{
|
||||
@@ -192,123 +214,147 @@ class ForumController extends Controller
|
||||
|
||||
// The user has the right to create a topic here?
|
||||
if (!$category->getPermission()->reply_topic || ($topic->state == "close" && !auth()->user()->group->is_modo)) {
|
||||
return redirect()->route('forum_index')->with(Toastr::error('You Cannot Reply To This Topic!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Cannot Reply To This Topic!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
$v = validator($request->all(), [
|
||||
'content' => 'required',
|
||||
$post = new Post();
|
||||
$post->content = $request->input('content');
|
||||
$post->user_id = $user->id;
|
||||
$post->topic_id = $topic->id;
|
||||
|
||||
$v = validator($post->toArray(), [
|
||||
'content' => 'required|min:1',
|
||||
'user_id' => 'required',
|
||||
'topic_id' => 'required'
|
||||
]);
|
||||
|
||||
if ($v->failed()) {
|
||||
return redirect()->route('forum_topic', [
|
||||
'slug' => $topic->slug,
|
||||
'id' => $topic->id
|
||||
])->with(Toastr::error('You Cannot Reply To This Topic!', 'Whoops!', ['options']));
|
||||
}
|
||||
if ($v->fails()) {
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
|
||||
} else {
|
||||
$post->save();
|
||||
|
||||
$content = $request->input('content');
|
||||
$appurl = config('app.url');
|
||||
$href = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}?page={$post->getPageNumber()}#post-{$post->id}";
|
||||
$message = "{$user->username} has tagged you in a forum post. You can view it [url=$href] HERE [/url]";
|
||||
|
||||
$post = new Post();
|
||||
$post->content = $content;
|
||||
$post->user_id = $user->id;
|
||||
$post->topic_id = $topic->id;
|
||||
$post->save();
|
||||
if ($this->tag->hasTags($request->input('content'))) {
|
||||
|
||||
$appurl = config('app.url');
|
||||
$href = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}?page={$post->getPageNumber()}#post-{$post->id}";
|
||||
$message = "{$user->username} has tagged you in a forum post. You can view it [url=$href] HERE [/url]";
|
||||
//$this->tag->setDebug(true);
|
||||
|
||||
if ($this->tag->hasTags($content)) {
|
||||
if ($this->tag->contains($request->input('content'), '@here') && $user->group->is_modo) {
|
||||
$users = collect([]);
|
||||
|
||||
//$this->tag->setDebug(true);
|
||||
$topic->posts()->get()->each(function ($p, $v) use ($users) {
|
||||
$users->push($p->user);
|
||||
});
|
||||
|
||||
if ($this->tag->contains($content, '@here') && $user->group->is_modo) {
|
||||
$users = collect([]);
|
||||
|
||||
$topic->posts()->get()->each(function ($p, $v) use ($users) {
|
||||
$users->push($p->user);
|
||||
});
|
||||
|
||||
$this->tag->messageUsers($users,
|
||||
"You are being notified by staff!",
|
||||
$message
|
||||
);
|
||||
} else {
|
||||
$this->tag->messageTaggedUsers($content,
|
||||
"You have been tagged by {$user->username}",
|
||||
$message
|
||||
);
|
||||
$this->tag->messageUsers($users,
|
||||
"You are being notified by staff!",
|
||||
$message
|
||||
);
|
||||
} else {
|
||||
$this->tag->messageTaggedUsers($request->input('content'),
|
||||
"You have been tagged by {$user->username}",
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Save last post user data to topic table
|
||||
$topic->last_post_user_id = $user->id;
|
||||
$topic->last_post_user_username = $user->username;
|
||||
|
||||
// Count post in topic
|
||||
$topic->num_post = Post::where('topic_id', $topic->id)->count();
|
||||
|
||||
// Update time
|
||||
$topic->last_reply_at = $post->created_at;
|
||||
|
||||
// Save
|
||||
$topic->save();
|
||||
|
||||
// Count posts
|
||||
$forum->num_post = $forum->getPostCount($forum->id);
|
||||
// Count topics
|
||||
$forum->num_topic = $forum->getTopicCount($forum->id);
|
||||
// Save last post user data to the forum table
|
||||
$forum->last_post_user_id = $user->id;
|
||||
$forum->last_post_user_username = $user->username;
|
||||
// Save last topic data to the forum table
|
||||
$forum->last_topic_id = $topic->id;
|
||||
$forum->last_topic_name = $topic->name;
|
||||
// Save
|
||||
$forum->save();
|
||||
|
||||
// Find the user who initated the topic
|
||||
$topicCreator = User::findOrFail($topic->first_post_user_id);
|
||||
|
||||
// Post To Chatbox
|
||||
$appurl = config('app.url');
|
||||
$postUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}?page={$post->getPageNumber()}#post-{$post->id}";
|
||||
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
|
||||
|
||||
$this->chat->systemMessage("[url=$profileUrl]{$user->username}[/url] has left a reply on topic [url={$postUrl}]{$topic->name}[/url]");
|
||||
|
||||
// Mail Topic Creator Of New Reply
|
||||
if ($post->user_id != $topic->first_post_user_id) {
|
||||
Mail::to($topicCreator->email)->send(new NewReply($user, $topic));
|
||||
}
|
||||
|
||||
//Achievements
|
||||
$user->unlock(new UserMadeFirstPost(), 1);
|
||||
$user->addProgress(new UserMade25Posts(), 1);
|
||||
$user->addProgress(new UserMade50Posts(), 1);
|
||||
$user->addProgress(new UserMade100Posts(), 1);
|
||||
$user->addProgress(new UserMade200Posts(), 1);
|
||||
$user->addProgress(new UserMade300Posts(), 1);
|
||||
$user->addProgress(new UserMade400Posts(), 1);
|
||||
$user->addProgress(new UserMade500Posts(), 1);
|
||||
$user->addProgress(new UserMade600Posts(), 1);
|
||||
$user->addProgress(new UserMade700Posts(), 1);
|
||||
$user->addProgress(new UserMade800Posts(), 1);
|
||||
$user->addProgress(new UserMade900Posts(), 1);
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('Post Successfully Posted', 'Yay!', ['options']));
|
||||
}
|
||||
|
||||
// Save last post user data to topic table
|
||||
$topic->last_post_user_id = $user->id;
|
||||
$topic->last_post_user_username = $user->username;
|
||||
|
||||
// Count post in topic
|
||||
$topic->num_post = Post::where('topic_id', $topic->id)->count();
|
||||
|
||||
// Update time
|
||||
$topic->last_reply_at = $post->created_at;
|
||||
|
||||
// Save
|
||||
$topic->save();
|
||||
|
||||
// Count posts
|
||||
$forum->num_post = $forum->getPostCount($forum->id);
|
||||
// Count topics
|
||||
$forum->num_topic = $forum->getTopicCount($forum->id);
|
||||
// Save last post user data to the forum table
|
||||
$forum->last_post_user_id = $user->id;
|
||||
$forum->last_post_user_username = $user->username;
|
||||
// Save last topic data to the forum table
|
||||
$forum->last_topic_id = $topic->id;
|
||||
$forum->last_topic_name = $topic->name;
|
||||
// Save
|
||||
$forum->save();
|
||||
|
||||
// Find the user who initated the topic
|
||||
$topicCreator = User::findOrFail($topic->first_post_user_id);
|
||||
|
||||
// Post To Chatbox
|
||||
$appurl = config('app.url');
|
||||
$postUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}?page={$post->getPageNumber()}#post-{$post->id}";
|
||||
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
|
||||
|
||||
$this->chat->systemMessage("[url=$profileUrl]{$user->username}[/url] has left a reply on topic [url={$postUrl}]{$topic->name}[/url]");
|
||||
|
||||
// Mail Topic Creator Of New Reply
|
||||
if ($post->user_id != $topic->first_post_user_id) {
|
||||
Mail::to($topicCreator->email)->send(new NewReply($user, $topic));
|
||||
}
|
||||
|
||||
//Achievements
|
||||
$user->unlock(new UserMadeFirstPost(), 1);
|
||||
$user->addProgress(new UserMade25Posts(), 1);
|
||||
$user->addProgress(new UserMade50Posts(), 1);
|
||||
$user->addProgress(new UserMade100Posts(), 1);
|
||||
$user->addProgress(new UserMade200Posts(), 1);
|
||||
$user->addProgress(new UserMade300Posts(), 1);
|
||||
$user->addProgress(new UserMade400Posts(), 1);
|
||||
$user->addProgress(new UserMade500Posts(), 1);
|
||||
$user->addProgress(new UserMade600Posts(), 1);
|
||||
$user->addProgress(new UserMade700Posts(), 1);
|
||||
$user->addProgress(new UserMade800Posts(), 1);
|
||||
$user->addProgress(new UserMade900Posts(), 1);
|
||||
|
||||
return redirect()->route('forum_topic', [
|
||||
'slug' => $topic->slug,
|
||||
'id' => $topic->id
|
||||
])->with(Toastr::success('Post Successfully Posted', 'Yay!', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new topic in the forum
|
||||
* Topic Add Form
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function addForm(Request $request, $slug, $id)
|
||||
{
|
||||
$forum = Forum::findOrFail($id);
|
||||
$category = $forum->getCategory();
|
||||
|
||||
// The user has the right to create a topic here?
|
||||
if ($category->getPermission()->start_topic != true) {
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Cannot Start A New Topic Here!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
return view('forum.new_topic', [
|
||||
'forum' => $forum,
|
||||
'category' => $category,
|
||||
'title' => $request->input('title')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create A New Topic In The Forum
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function newTopic(Request $request, $slug, $id)
|
||||
{
|
||||
@@ -318,102 +364,126 @@ class ForumController extends Controller
|
||||
|
||||
// The user has the right to create a topic here?
|
||||
if ($category->getPermission()->start_topic != true) {
|
||||
return redirect()->route('forum_index')->with(Toastr::error('You Cannot Start A New Topic Here!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error('You Cannot Start A New Topic Here!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
// Preview The Post
|
||||
$parsedContent = null;
|
||||
if ($request->isMethod('POST') && $request->input('preview') == true) {
|
||||
$code = new Decoda($request->input('content'));
|
||||
$code->defaults();
|
||||
$code->setXhtml(false);
|
||||
$code->setStrict(false);
|
||||
$code->setLineBreaks(true);
|
||||
$parsedContent = $code->parse();
|
||||
}
|
||||
// Create The Topic
|
||||
$topic = new Topic();
|
||||
$topic->name = $request->input('title');
|
||||
$topic->slug = str_slug($request->input('title'));
|
||||
$topic->state = 'open';
|
||||
$topic->first_post_user_id = $topic->last_post_user_id = $user->id;
|
||||
$topic->first_post_user_username = $topic->last_post_user_username = $user->username;
|
||||
$topic->views = 0;
|
||||
$topic->pinned = false;
|
||||
$topic->forum_id = $forum->id;
|
||||
|
||||
if ($request->isMethod('POST') && $request->input('post') == true) {
|
||||
// Create The Topic
|
||||
$topic = new Topic();
|
||||
$topic->name = $request->input('title');
|
||||
$topic->slug = str_slug($request->input('title'));
|
||||
$topic->state = 'open';
|
||||
$topic->first_post_user_id = $topic->last_post_user_id = $user->id;
|
||||
$topic->first_post_user_username = $topic->last_post_user_username = $user->username;
|
||||
$topic->views = 0;
|
||||
$topic->pinned = false;
|
||||
$topic->forum_id = $forum->id;
|
||||
$v = validator($topic->toArray(), $topic->rules);
|
||||
if ($v->passes()) {
|
||||
$topic->save();
|
||||
$v = validator($topic->toArray(), [
|
||||
'name' => 'required',
|
||||
'slug' => 'required',
|
||||
'state' => 'required',
|
||||
'num_post' => '',
|
||||
'first_post_user_id' => 'required',
|
||||
'first_post_user_username' => 'required',
|
||||
'last_post_user_id' => '',
|
||||
'last_post_user_username' => '',
|
||||
'views' => '',
|
||||
'pinned' => '',
|
||||
'forum_id' => 'required'
|
||||
]);
|
||||
|
||||
$post = new Post();
|
||||
$post->content = $request->input('content');
|
||||
$post->user_id = $user->id;
|
||||
$post->topic_id = $topic->id;
|
||||
$v = validator($post->toArray(), $post->rules);
|
||||
if ($v->passes()) {
|
||||
$post->save();
|
||||
$topic->num_post = 1;
|
||||
$topic->last_reply_at = $post->created_at;
|
||||
$topic->save();
|
||||
$forum->num_topic = $forum->getTopicCount($forum->id);
|
||||
$forum->num_post = $forum->getPostCount($forum->id);
|
||||
$forum->last_topic_id = $topic->id;
|
||||
$forum->last_topic_name = $topic->name;
|
||||
$forum->last_topic_slug = $topic->slug;
|
||||
$forum->last_post_user_id = $user->id;
|
||||
$forum->last_post_user_username = $user->username;
|
||||
$forum->save();
|
||||
if ($v->fails()) {
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
|
||||
} else {
|
||||
$topic->save();
|
||||
|
||||
// Post To ShoutBox
|
||||
$appurl = config('app.url');
|
||||
$topicUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}";
|
||||
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
|
||||
$post = new Post();
|
||||
$post->content = $request->input('content');
|
||||
$post->user_id = $user->id;
|
||||
$post->topic_id = $topic->id;
|
||||
|
||||
$this->chat->systemMessage("[url={$profileUrl}]{$user->username}[/url] has created a new topic [url={$topicUrl}]{$topic->name}[/url]");
|
||||
$v = validator($post->toArray(), [
|
||||
'content' => 'required',
|
||||
'user_id' => 'required',
|
||||
'topic_id' => 'required'
|
||||
]);
|
||||
|
||||
//Achievements
|
||||
$user->unlock(new UserMadeFirstPost(), 1);
|
||||
$user->addProgress(new UserMade25Posts(), 1);
|
||||
$user->addProgress(new UserMade50Posts(), 1);
|
||||
$user->addProgress(new UserMade100Posts(), 1);
|
||||
$user->addProgress(new UserMade200Posts(), 1);
|
||||
$user->addProgress(new UserMade300Posts(), 1);
|
||||
$user->addProgress(new UserMade400Posts(), 1);
|
||||
$user->addProgress(new UserMade500Posts(), 1);
|
||||
$user->addProgress(new UserMade600Posts(), 1);
|
||||
$user->addProgress(new UserMade700Posts(), 1);
|
||||
$user->addProgress(new UserMade800Posts(), 1);
|
||||
$user->addProgress(new UserMade900Posts(), 1);
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id]);
|
||||
} else {
|
||||
// Unable to save the first post doc delete the topic
|
||||
Toastr::error('You Did Not Meet All The Requirments For Creating A Yopic!', 'Whoops!', ['options']);
|
||||
$topic->delete();
|
||||
}
|
||||
if ($v->fails()) {
|
||||
return redirect()->route('forum_index')
|
||||
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
|
||||
} else {
|
||||
Toastr::error('A Error Has Occured With This Topic! Please Try Again!', 'Whoops!', ['options']);
|
||||
$post->save();
|
||||
$topic->num_post = 1;
|
||||
$topic->last_reply_at = $post->created_at;
|
||||
$topic->save();
|
||||
$forum->num_topic = $forum->getTopicCount($forum->id);
|
||||
$forum->num_post = $forum->getPostCount($forum->id);
|
||||
$forum->last_topic_id = $topic->id;
|
||||
$forum->last_topic_name = $topic->name;
|
||||
$forum->last_topic_slug = $topic->slug;
|
||||
$forum->last_post_user_id = $user->id;
|
||||
$forum->last_post_user_username = $user->username;
|
||||
$forum->save();
|
||||
|
||||
// Post To ShoutBox
|
||||
$appurl = config('app.url');
|
||||
$topicUrl = "{$appurl}/forums/topic/{$topic->slug}.{$topic->id}";
|
||||
$profileUrl = "{$appurl}/{$user->username}.{$user->id}";
|
||||
|
||||
$this->chat->systemMessage("[url={$profileUrl}]{$user->username}[/url] has created a new topic [url={$topicUrl}]{$topic->name}[/url]");
|
||||
|
||||
//Achievements
|
||||
$user->unlock(new UserMadeFirstPost(), 1);
|
||||
$user->addProgress(new UserMade25Posts(), 1);
|
||||
$user->addProgress(new UserMade50Posts(), 1);
|
||||
$user->addProgress(new UserMade100Posts(), 1);
|
||||
$user->addProgress(new UserMade200Posts(), 1);
|
||||
$user->addProgress(new UserMade300Posts(), 1);
|
||||
$user->addProgress(new UserMade400Posts(), 1);
|
||||
$user->addProgress(new UserMade500Posts(), 1);
|
||||
$user->addProgress(new UserMade600Posts(), 1);
|
||||
$user->addProgress(new UserMade700Posts(), 1);
|
||||
$user->addProgress(new UserMade800Posts(), 1);
|
||||
$user->addProgress(new UserMade900Posts(), 1);
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('Topic Created Successfully!', 'Yay!', ['options']));
|
||||
}
|
||||
}
|
||||
return view('forum.new_topic', ['forum' => $forum, 'category' => $category, 'parsedContent' => $parsedContent, 'title' => $request->input('title'), 'content' => $request->input('content')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit topic in the forum
|
||||
* Topic Edit Form
|
||||
*
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function editForm($slug, $id)
|
||||
{
|
||||
$topic = Topic::findOrFail($id);
|
||||
$categories = Forum::where('parent_id', '!=', 0)->get();
|
||||
|
||||
return view('forum.edit_topic', ['topic' => $topic, 'categories' => $categories]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Topic In The Forum
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editTopic(Request $request, $slug, $id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$topic = Topic::findOrFail($id);
|
||||
$categories = Forum::where('parent_id', '!=', 0)->get();
|
||||
|
||||
if ($user->group->is_modo) {
|
||||
if ($request->isMethod('POST')) {
|
||||
$name = $request->input('name');
|
||||
$forum_id = $request->input('forum_id');
|
||||
|
||||
@@ -421,59 +491,71 @@ class ForumController extends Controller
|
||||
$topic->forum_id = $forum_id;
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::success('Topic Successfully Edited', 'Yay!', ['options']));
|
||||
} else {
|
||||
return view('forum.edit_topic', ['topic' => $topic, 'categories' => $categories]);
|
||||
}
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('Topic Successfully Edited', 'Yay!', ['options']));
|
||||
} else {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit user's post
|
||||
* Edit Post Form
|
||||
*
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @param $postId
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function postEditForm($slug, $id, $postId)
|
||||
{
|
||||
$topic = Topic::findOrFail($id);
|
||||
$forum = $topic->forum;
|
||||
$category = $forum->getCategory();
|
||||
$post = Post::findOrFail($postId);
|
||||
|
||||
return view('forum.post_edit', [
|
||||
'topic' => $topic,
|
||||
'forum' => $forum,
|
||||
'post' => $post,
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit A Post In A Topic
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @param $postId
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postEdit(Request $request, $slug, $id, $postId)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$topic = Topic::findOrFail($id);
|
||||
$forum = $topic->forum;
|
||||
$category = $forum->getCategory();
|
||||
$post = Post::findOrFail($postId);
|
||||
$parsedContent = null;
|
||||
|
||||
if ($user->group->is_modo == false) {
|
||||
if ($post->user_id != $user->id) {
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::error('You Cannot Edit This!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::error('You Cannot Edit This!', 'Whoops!', ['options']));
|
||||
}
|
||||
}
|
||||
|
||||
// Post preview
|
||||
if ($request->isMethod('POST') && $request->input('preview') == true) {
|
||||
$post->content = $request->input('content');
|
||||
$code = new Decoda($post->content);
|
||||
$code->defaults();
|
||||
$parsedContent = $code->parse();
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST') && $request->input('post') == true) {
|
||||
$post->content = $request->input('content');
|
||||
$post->save();
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id]);
|
||||
}
|
||||
return view('forum.post_edit', ['user' => $user, 'topic' => $topic, 'forum' => $forum, 'post' => $post, 'category' => $category, 'parsedContent' => $parsedContent]);
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('Post Successfully Edited!', 'Yay!', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user's post
|
||||
* Delete A Post
|
||||
*
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @param $postId
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postDelete($slug, $id, $postId)
|
||||
{
|
||||
@@ -483,21 +565,23 @@ class ForumController extends Controller
|
||||
|
||||
if ($user->group->is_modo == false) {
|
||||
if ($post->user_id != $user->id) {
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::error('You Cannot Delete This!', 'Whoops!', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::error('You Cannot Delete This!', 'Whoops!', ['options']));
|
||||
}
|
||||
}
|
||||
$post->delete();
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::success('This Post Is Now Deleted!', 'Success', ['options']));
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('This Post Is Now Deleted!', 'Success', ['options']));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close The Topic
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function closeTopic($slug, $id)
|
||||
{
|
||||
@@ -505,32 +589,33 @@ class ForumController extends Controller
|
||||
$topic->state = "close";
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::error('This Topic Is Now Closed!', 'Warning', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::error('This Topic Is Now Closed!', 'Warning', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open The Topic
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function openTopic($slug, $id)
|
||||
{
|
||||
$topic = Topic::findOrFail($id);
|
||||
$topic->state = "open";
|
||||
$topic->save();
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::success('This Topic Is Now Open!', 'Success', ['options']));
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('This Topic Is Now Open!', 'Success', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the topic and the posts
|
||||
* Delete The Topic and The Posts
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteTopic($slug, $id)
|
||||
{
|
||||
@@ -540,51 +625,54 @@ class ForumController extends Controller
|
||||
$posts = $topic->posts();
|
||||
$posts->delete();
|
||||
$topic->delete();
|
||||
return redirect()->route('forum_display', ['slug' => $topic->forum->slug, 'id' => $topic->forum->id])->with(Toastr::error('This Topic Is Now Deleted!', 'Warning', ['options']));
|
||||
return redirect()->route('forum_display', ['slug' => $topic->forum->slug, 'id' => $topic->forum->id])
|
||||
->with(Toastr::error('This Topic Is Now Deleted!', 'Warning', ['options']));
|
||||
} else {
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::error('You Do Not Have Access To Perform This Function!', 'Warning', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::error('You Do Not Have Access To Perform This Function!', 'Warning', ['options']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pin The Topic
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function pinTopic($slug, $id)
|
||||
{
|
||||
$topic = Topic::findOrFail($id);
|
||||
$topic->pinned = 1;
|
||||
$topic->save();
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::success('This Topic Is Now Pinned!', 'Success', ['options']));
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('This Topic Is Now Pinned!', 'Success', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpin The Topic
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function unpinTopic($slug, $id)
|
||||
{
|
||||
$topic = Topic::findOrFail($id);
|
||||
$topic->pinned = 0;
|
||||
$topic->save();
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::success('This Topic Is Now Unpinned!', 'Success', ['options']));
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::success('This Topic Is Now Unpinned!', 'Success', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forum Tag System
|
||||
*
|
||||
* @access public
|
||||
* @param $slug
|
||||
* @param $id
|
||||
* @return Redirect to forum_topic
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function approvedTopic($slug, $id)
|
||||
{
|
||||
@@ -596,7 +684,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function deniedTopic($slug, $id)
|
||||
@@ -609,7 +698,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function solvedTopic($slug, $id)
|
||||
@@ -622,7 +712,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function invalidTopic($slug, $id)
|
||||
@@ -635,7 +726,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function bugTopic($slug, $id)
|
||||
@@ -648,7 +740,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function suggestionTopic($slug, $id)
|
||||
@@ -661,7 +754,8 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
public function implementedTopic($slug, $id)
|
||||
@@ -674,9 +768,16 @@ class ForumController extends Controller
|
||||
}
|
||||
$topic->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])
|
||||
->with(Toastr::info('Label Change Has Been Applied', 'Info', ['options']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Like A Post
|
||||
*
|
||||
* @param $postId
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function likePost($postId)
|
||||
{
|
||||
$post = Post::findOrFail($postId);
|
||||
@@ -685,9 +786,11 @@ class ForumController extends Controller
|
||||
$dislike = $user->likes()->where('post_id', $post->id)->where('dislike', 1)->first();
|
||||
|
||||
if ($like || $dislike) {
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::error('You have already liked/disliked this post!', 'Bro', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::error('You have already liked/disliked this post!', 'Bro', ['options']));
|
||||
} elseif ($user->id == $post->user_id) {
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::error('You cannot like your own post!', 'Umm', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::error('You cannot like your own post!', 'Umm', ['options']));
|
||||
} else {
|
||||
$new = new Like();
|
||||
$new->user_id = $user->id;
|
||||
@@ -695,10 +798,17 @@ class ForumController extends Controller
|
||||
$new->like = 1;
|
||||
$new->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::success('Like Successfully Applied!', 'Yay', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::success('Like Successfully Applied!', 'Yay', ['options']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dislike A Post
|
||||
*
|
||||
* @param $postId
|
||||
* @return Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function dislikePost($postId)
|
||||
{
|
||||
$post = Post::findOrFail($postId);
|
||||
@@ -707,9 +817,11 @@ class ForumController extends Controller
|
||||
$dislike = $user->likes()->where('post_id', $post->id)->where('dislike', 1)->first();
|
||||
|
||||
if ($like || $dislike) {
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::error('You have already liked/disliked this post!', 'Bro', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::error('You have already liked/disliked this post!', 'Bro', ['options']));
|
||||
} elseif ($user->id == $post->user_id) {
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::error('You cannot like your own post!', 'Umm', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::error('You cannot like your own post!', 'Umm', ['options']));
|
||||
} else {
|
||||
$new = new Like();
|
||||
$new->user_id = $user->id;
|
||||
@@ -717,7 +829,8 @@ class ForumController extends Controller
|
||||
$new->dislike = 1;
|
||||
$new->save();
|
||||
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])->with(Toastr::success('Dislike Successfully Applied!', 'Yay', ['options']));
|
||||
return redirect()->route('forum_topic', ['slug' => $post->topic->slug, 'id' => $post->topic->id])
|
||||
->with(Toastr::success('Dislike Successfully Applied!', 'Yay', ['options']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user