Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.8 updates and blade fixes #239

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f1c76e7
Updating views so reverse routing is used.
ChrisThompsonTLDR Sep 26, 2018
d0e66fd
Not everyone has PHP short codes enabled.
ChrisThompsonTLDR Sep 26, 2018
a288511
Don't double encode translations.
ChrisThompsonTLDR Sep 26, 2018
da4a5d9
Use reverse routing.
ChrisThompsonTLDR Sep 26, 2018
0682fbd
Use accessors to change markdown to HTML.
ChrisThompsonTLDR Sep 26, 2018
764b8ef
Use chatter's login and register routes.
ChrisThompsonTLDR Sep 26, 2018
84cedf4
Order the categories correctly.
ChrisThompsonTLDR Sep 26, 2018
73fdf06
Allow for the removal of the hero.
ChrisThompsonTLDR Sep 26, 2018
ded00ec
Load the CSS with a relative path (for when Laravel app is installed …
ChrisThompsonTLDR Sep 26, 2018
569b239
Load assets relatively so foldered installations work.
ChrisThompsonTLDR Sep 27, 2018
26d6ffa
More reverse routes fixed.
ChrisThompsonTLDR Sep 27, 2018
e5e25a0
More reverse routing.
ChrisThompsonTLDR Sep 27, 2018
bb44c04
Switching back to `mewebstudio/purifier` as the fork by LukeTowers is…
ChrisThompsonTLDR Mar 5, 2019
0abd4b9
Typo in last commit.
ChrisThompsonTLDR Mar 5, 2019
075f004
Apparently I don't understand versioning.
ChrisThompsonTLDR Mar 5, 2019
5024ceb
Wrong packagist name used.
ChrisThompsonTLDR Mar 5, 2019
6ec7efc
Load the correct classes.
ChrisThompsonTLDR Mar 5, 2019
b884360
Laravel 5.8 compatibility.
ChrisThompsonTLDR Mar 7, 2019
70b018c
Laravel 5.8 compatibility
ChrisThompsonTLDR Mar 7, 2019
fd699d4
Merge remote-tracking branch 'origin/master'
ChrisThompsonTLDR Mar 7, 2019
78b87ce
Removing Event::fire() and replacing with dispatch() for Laravel 5.8
ChrisThompsonTLDR Apr 13, 2019
7a054d0
Cleaning up some logic.
ChrisThompsonTLDR Apr 13, 2019
4208d56
Utilize configured routes.
ChrisThompsonTLDR Apr 14, 2019
bcd838d
Fixing typo.
Apr 18, 2019
1a7a55f
Spacing
Apr 18, 2019
d23f334
Adding notification subject.
ChrisThompsonTLDR Apr 18, 2019
e2bf5b4
Adding a missing controller action.
ChrisThompsonTLDR Apr 25, 2019
b317f81
Adding scout
jameswagoner May 31, 2019
4d41141
Adding scout
jameswagoner May 31, 2019
86bf18b
Tweaking the payload size
jameswagoner May 31, 2019
4124a99
isset to squelch errors
jameswagoner May 31, 2019
764247b
Chatter search
jameswagoner Jun 3, 2019
29cedff
Chatter search blade when env is set
jameswagoner Jun 3, 2019
08a90de
fixed $user variable
jameswagoner Jun 3, 2019
3965e62
version bump for composer
jameswagoner Jun 3, 2019
8b875a4
route typo
jameswagoner Jun 3, 2019
15fb118
Fixed stragler $user variable
jameswagoner Jun 3, 2019
882d8ba
let's return the array, shall we?
jameswagoner Jun 3, 2019
c15f61e
Missing eager loading and other configurable options
jameswagoner Jun 4, 2019
730466f
pagination links including search parameter
jameswagoner Jun 4, 2019
804b40f
Add ability to strip styles and tags from responses.
terrancewoest Jun 4, 2019
2f3b21e
Also remove any class attributes from new responses.
terrancewoest Jun 5, 2019
db9ec05
Merge pull request #1 from ChrisThompsonTLDR/feature/clean-responses
Jun 6, 2019
b5e79f2
Add some feedback items to search page. (#2)
terrancewoest Jun 6, 2019
62d6db9
Fixed new discussion button for no results.
terrancewoest Jun 6, 2019
e041f73
Merge pull request #3 from ChrisThompsonTLDR/bug/no-results-search-ne…
Jun 6, 2019
562b9ce
Use total not count for total results found.
terrancewoest Jun 7, 2019
bcee353
Delete line used for debugging.
terrancewoest Jun 11, 2019
a58c77c
Version bump
jameswagoner Oct 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
}
],
"require": {
"luketowers/purifier": "~3.0"
"mews/purifier": "^3.3",
"laravel/scout": "^7.1"
},
"require-dev": {
"illuminate/cache": "~5.1.20|5.2.*|5.3.*",
Expand Down
23 changes: 20 additions & 3 deletions config/chatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
| description from the language files will be used.
|
| *headline_logo*: If this is set an image will be used on the forum home
| instead of text. Specify the relative path to the image here.
| instead of text. Specify the relative path to the image here. If the
| value is false, nothing will be displayed.
|
*/

'headline_logo' => '/vendor/devdojo/chatter/assets/images/logo-light.png',
'headline_logo' => false,

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -190,6 +191,22 @@
'plugins' => 'link, image',
],

/*
|--------------------------------------------------------------------------
| Response Settings
|--------------------------------------------------------------------------
|
| Whether chatter should strip all styles attributes and remove tags
| from new responses.
|
*/

'response' => [
'strip_styles' => true,
'strip_tags' => true,
'allowed_tags' => '<a><ul><ol><li><strong><b><i><u><p><br>',
],

/*
|--------------------------------------------------------------------------
| Default orderby
Expand Down Expand Up @@ -253,7 +270,7 @@
'paginate' => [
'num_of_results' => 10,
],

/*
|--------------------------------------------------------------------------
| Show missing fields to users in forms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function up()
$table->increments('id');
$table->integer('chatter_category_id')->unsigned()->default('1');
$table->string('title');
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->boolean('sticky')->default(false);
$table->integer('views')->unsigned()->default('0');
$table->boolean('answered')->default(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function up()
Schema::create('chatter_post', function (Blueprint $table) {
$table->increments('id');
$table->integer('chatter_discussion_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->text('body');
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateChatterUserDiscussionPivotTable extends Migration
public function up()
{
Schema::create('chatter_user_discussion', function (Blueprint $table) {
$table->integer('user_id')->unsigned()->index();
$table->bigInteger('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('discussion_id')->unsigned()->index();
$table->foreign('discussion_id')->references('id')->on('chatter_discussion')->onDelete('cascade');
Expand Down
42 changes: 21 additions & 21 deletions public/assets/js/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ var chatter_tinymce_plugins = $('#chatter_tinymce_plugins').val();

// Initiate the tinymce editor on any textarea with a class of richText
tinymce.init({
selector:'textarea.richText',
skin: 'chatter',
plugins: chatter_tinymce_plugins,
toolbar: chatter_tinymce_toolbar,
menubar: false,
statusbar: false,
height : '220',
content_css : '/vendor/devdojo/chatter/assets/css/chatter.css',
template_popup_height: 380,
setup: function (editor) {
selector:'textarea.richText',
skin: 'chatter',
plugins: chatter_tinymce_plugins,
toolbar: chatter_tinymce_toolbar,
menubar: false,
statusbar: false,
height : '220',
content_css : document.querySelector('[href$="chatter.css"]').href,
template_popup_height: 380,
setup: function (editor) {
editor.on('init', function(args) {
// The tinymce editor is ready
// The tinymce editor is ready
document.getElementById('new_discussion_loader').style.display = "none";
if(!editor.getContent()){
document.getElementById('tinymce_placeholder').style.display = "block";
}
document.getElementById('chatter_form_editor').style.display = "block";
document.getElementById('chatter_form_editor').style.display = "block";

// check if user is in discussion view
if ($('#new_discussion_loader_in_discussion_view').length > 0) {
Expand All @@ -28,14 +28,14 @@ tinymce.init({
}
});
editor.on('keyup', function(e) {
content = editor.getContent();
if(content){
//$('#tinymce_placeholder').fadeOut();
document.getElementById('tinymce_placeholder').style.display = "none";
} else {
//$('#tinymce_placeholder').fadeIn();
document.getElementById('tinymce_placeholder').style.display = "block";
}
content = editor.getContent();
if(content){
//$('#tinymce_placeholder').fadeOut();
document.getElementById('tinymce_placeholder').style.display = "none";
} else {
//$('#tinymce_placeholder').fadeIn();
document.getElementById('tinymce_placeholder').style.display = "block";
}
});
}
});
Expand All @@ -49,7 +49,7 @@ function initializeNewTinyMCE(id){
menubar: false,
statusbar: false,
height : '300',
content_css : '/vendor/devdojo/chatter/assets/css/chatter.css',
content_css : document.querySelector('[href$="chatter.css"]').href,
template_popup_height: 380
});
}
9 changes: 7 additions & 2 deletions src/ChatterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DevDojo\Chatter;

use Illuminate\Support\ServiceProvider;
use DevDojo\Chatter\Models\Models;

class ChatterServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -36,6 +37,10 @@ public function boot()

// include the routes file
include __DIR__.'/Routes/web.php';

view()->composer(['chatter::blocks.sidebar', 'chatter::discussion', 'chatter::home'], function($view) {
$view->with('categories', Models::category()->orderBy('order')->get());
});
}

/**
Expand All @@ -48,13 +53,13 @@ public function register()
/*
* Register the service provider for the dependency.
*/
$this->app->register(\LukeTowers\Purifier\PurifierServiceProvider::class);
$this->app->register(\Mews\Purifier\PurifierServiceProvider::class);

/*
* Create aliases for the dependency.
*/
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Purifier', 'LukeTowers\Purifier\Facades\Purifier');
$loader->alias('Purifier', 'Mews\Purifier\Facades\Purifier');

$this->loadViewsFrom(__DIR__.'/Views', 'chatter');
}
Expand Down
24 changes: 12 additions & 12 deletions src/Controllers/ChatterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,43 @@ class ChatterController extends Controller
public function index($slug = '')
{
$pagination_results = config('chatter.paginate.num_of_results');
$discussions = Models::discussion()->with('user')->with('post')->with('postsCount')->with('category')->orderBy(config('chatter.order_by.discussions.order'), config('chatter.order_by.discussions.by'));

$discussions = Models::discussion()->with('user')->with('post')->with('category')->orderBy(config('chatter.order_by.discussions.order'), config('chatter.order_by.discussions.by'));
if (isset($slug)) {
$category = Models::category()->where('slug', '=', $slug)->first();

if (isset($category->id)) {
$current_category_id = $category->id;
$discussions = $discussions->where('chatter_category_id', '=', $category->id);
} else {
$current_category_id = null;
}
}

$discussions = $discussions->paginate($pagination_results);
$categories = Models::category()->get();

$categories = Models::category()->orderBy('order')->get();
$categoriesMenu = Helper::categoriesMenu(array_filter($categories->toArray(), function ($item) {
return $item['parent_id'] === null;
}));

$chatter_editor = config('chatter.editor');

if ($chatter_editor == 'simplemde') {
// Dynamically register markdown service provider
\App::register('GrahamCampbell\Markdown\MarkdownServiceProvider');
}
return view('chatter::home', compact('discussions', 'categories', 'categoriesMenu', 'chatter_editor', 'current_category_id'));

return view('chatter::home', compact('discussions', 'categoriesMenu', 'chatter_editor', 'current_category_id'));
}

public function login()
{
if (!Auth::check()) {
return \Redirect::to('/'.config('chatter.routes.login').'?redirect='.config('chatter.routes.home'))->with('flash_message', 'Please create an account before posting.');
}
}

public function register()
{
if (!Auth::check()) {
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/ChatterDiscussionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function index(Request $request)
if ($request->offset) {
$offset = $request->offset;
}
$discussions = Models::discussion()->with('user')->with('post')->with('postsCount')->with('category')->orderBy('created_at', 'ASC')->take($total)->offset($offset)->get();*/
$discussions = Models::discussion()->with('user')->with('post')->with('category')->orderBy('created_at', 'ASC')->take($total)->offset($offset)->get();*/

// Return an empty array to avoid exposing user data to the public.
// This index function is not being used anywhere.
Expand Down Expand Up @@ -75,9 +75,9 @@ public function store(Request $request)
'body_content.min' => trans('chatter::alert.danger.reason.content_min'),
'chatter_category_id.required' => trans('chatter::alert.danger.reason.category_required'),
]);


Event::fire(new ChatterBeforeNewDiscussion($request, $validator));

Event::dispatch(new ChatterBeforeNewDiscussion($request, $validator));
if (function_exists('chatter_before_new_discussion')) {
chatter_before_new_discussion($request, $validator);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ public function store(Request $request)
$post = Models::post()->create($new_post);

if ($post->id) {
Event::fire(new ChatterAfterNewDiscussion($request, $discussion, $post));
Event::dispatch(new ChatterAfterNewDiscussion($request, $discussion, $post));
if (function_exists('chatter_after_new_discussion')) {
chatter_after_new_discussion($request);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function show($category, $slug = null)
}

$discussion->increment('views');

return view('chatter::discussion', compact('discussion', 'posts', 'chatter_editor'));
}

Expand Down
31 changes: 28 additions & 3 deletions src/Controllers/ChatterPostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function store(Request $request)
'body.min' => trans('chatter::alert.danger.reason.content_min'),
]);

Event::fire(new ChatterBeforeNewResponse($request, $validator));
Event::dispatch(new ChatterBeforeNewResponse($request, $validator));
if (function_exists('chatter_before_new_response')) {
chatter_before_new_response($request, $validator);
}
Expand All @@ -65,6 +65,20 @@ public function store(Request $request)
return back()->withErrors($validator)->withInput();
}

$cleaned_response = $request->input('body');

if (config('chatter.response.strip_tags')) {
$allowed_tags = config('chagger.response.allowed_tags') ?: null;
$cleaned_response = strip_tags($cleaned_response, $allowed_tags);
}

if (config('chatter.response.strip_styles')) {
$cleaned_response = preg_replace('/(<[^>]+) class=".*?"/i', '$1', $cleaned_response); // remove classes
$cleaned_response = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $cleaned_response); // remove styles
}

$request->merge(['body' => $cleaned_response]);

if (config('chatter.security.limit_time_between_posts')) {
if ($this->notEnoughTimeBetweenPosts()) {
$minutes = trans_choice('chatter::messages.words.minutes', config('chatter.security.time_between_posts'));
Expand Down Expand Up @@ -97,8 +111,8 @@ public function store(Request $request)
if ($new_post->id) {
$discussion->last_reply_at = $discussion->freshTimestamp();
$discussion->save();
Event::fire(new ChatterAfterNewResponse($request, $new_post));

Event::dispatch(new ChatterAfterNewResponse($request, $new_post));
if (function_exists('chatter_after_new_response')) {
chatter_after_new_response($request);
}
Expand Down Expand Up @@ -148,6 +162,17 @@ private function sendEmailNotifications($discussion)
}
}

public function show($id)
{
$post = Models::post()->with('discussion')->findOrFail($id);

if ($post) {
return redirect(null, 301)->route('chatter.discussion.showInCategory', [$post->discussion->category->slug, $post->discussion->slug]);
}

abort(404);
}

/**
* Update the specified resource in storage.
*
Expand Down
46 changes: 46 additions & 0 deletions src/Controllers/ChatterSearchController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace DevDojo\Chatter\Controllers;

use DevDojo\Chatter\Helpers\ChatterHelper as Helper;
use DevDojo\Chatter\Models\Models;
use DevDojo\Chatter\Models\Post;
use Illuminate\Routing\Controller as Controller;

class ChatterSearchController extends Controller
{
public function index()
{
$query = request('q');
$orderBy = config('chatter.order_by.discussions.order');
$orderDirection = config('chatter.order_by.discussions.by');
$pagination_results = config('chatter.paginate.num_of_results');

$posts = Post::search($query)->get()->pluck('chatter_discussion_id')->toArray();
$discussionIds = array_values($posts);
$discussions = Models::discussion()
->with('user')
->with('post')
->with('category')
->whereIn('id', $discussionIds)
->groupBy('id')
->orderBy($orderBy, $orderDirection)
->paginate($pagination_results);

$current_category_id = null;

$categories = Models::category()->orderBy('order')->get();
$categoriesMenu = Helper::categoriesMenu(array_filter($categories->toArray(), function ($item) {
return $item['parent_id'] === null;
}));

$chatter_editor = config('chatter.editor');

if ($chatter_editor == 'simplemde') {
// Dynamically register markdown service provider
\App::register('GrahamCampbell\Markdown\MarkdownServiceProvider');
}

return view('chatter::home', compact('discussions', 'categoriesMenu', 'chatter_editor', 'current_category_id', 'query'));
}
}
2 changes: 1 addition & 1 deletion src/Helpers/ChatterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function categoriesMenu($categories)

foreach ($categories as $category) {
$menu .= '<li>';
$menu .= '<a href="/'.config('chatter.routes.home').'/'.config('chatter.routes.category').'/'.$category['slug'].'">';
$menu .= '<a href="'.route('chatter.category.show', $category['slug']).'">';
$menu .= '<div class="chatter-box" style="background-color:'.$category['color'].'"></div>';
$menu .= $category['name'].'</a>';

Expand Down
Loading