strangefate/commenthandler
Composer 安装命令:
composer require strangefate/commenthandler
包简介
A service provider to add comments and likes to Laravel Models.
README 文档
README
This comment handler is a basic package for adding quick comments and likes to your project. It includes a profanity filter and users can report inappropriate posts. Posts that reach a configured report thresh hold will automatically be suspended from the site.
Package Installation
Require package
composer require strangefate/commenthandler
Run migration to add the required table for comments, likes and reports to the database
php artisan migrate
Add the relationship for Users and their comments in app\User.php
use StrangeFate\CommentHandler\Comment;
...
public function comments() {
return $this->hasMany(Comment::class);
}
Configuration
By default, all options are turned on for comments (Like, Report, and Reply to comments). Publish the config file to configure the platforms you want.
php artisan vendor:publish --provider=StrangeFate\CommentHandler\CommentHandlerServiceProvider --tag=config
This will publish the comment config file to your config directory:
app\config\comments.php
Once you have your configuration set, you will need to make your Models to have comments or likes. Simply go into your model and add the interfaces HasComment or HasLike to attach those features.
<?php
namespace App;
use StrangeFate\CommentHandler\Interfaces\HasLikes;
use StrangeFate\CommentHandler\Interfaces\HasComments;
class MyNewClass extends Model
{
use HasComments, HasLikes;
}
This will add all the necessary relationship for your model to accept comments and/or likes. Comments will automatically have the routes for likes built in, but you will need to create the routes and logic to attach for your models to accept them.
Route::post('mynewclasses/{mynewclass}/comment', function(Request $request, MyNewClass $mynewclass) {
$comment = $request->validate(['message' => 'required']);
$comment['user_id'] = auth()->id();
$mynewclass->comments()->create($comment);
return redirect("/mynewclass/$mynewclass->id");
});
Route::post('mynewclasses/{mynewclass}/like', function(Request $request, MyNewClass $mynewclass) {
$mynewclass->like( auth()->id() ); //The like() function will detect if the user has already liked the item
return redirect("/mynewclass/$mynewclass->id");
});
Comments automatically accept likes and appropriate routing logic. If you do not wish to have a like function on your comments, you can turn it off in the config\comments.php file.
View templates
The comment handler comes with some pre-made templates for you to include in your project.
@include('comment::comments', ['comments' => $module->comments->show()->get(), 'url' => 'post/route/for/submitting/comments']) {-- A general output for comments --}
@include('comment::comment_list', ['comments' => $comments] ) {-- for defining the format in which post are laid out. --}
@include('comment::create', ['url' => 'post/route/for/submitting/comments']) {-- The form for submitting a comment --}
@include('comment::schema', ['comments' => $comments]) {-- The schema.org json for dumping comments into your page for scrapping --}
You can publish the views to your views\vendor folder to customize the views for the site
php artisan vendor:publish --provider=StrangeFate\CommentHandler\CommentHandlerServiceProvider --tag=views
Publishing the views will also dump a sass file with all the predefined classes used in the template for you to style comments for your site. Simply include it in your app.scss and add your css.
@import "comments";
Reporting Post
This module contains some logic to allow users to moderate the board by reporting inappropriate comments. You can disable this feature all together by setting the report option to false in the config\comments.php file after publishing it.
You can set the limits for reports to automatically hide a post by configuring the report array in the same config file.
'report' => [
'auto_hide' => true, //automatically hide a comment after it his been reported so many times
'report_limit' => 10 //the number of times a post can be reported before it is automatically hidden
],
You can check the reported comments by using a query scope, and the list of users that have reported a comment through it's relationship methods.
$comments = Comment::reported()->get() //gets a list of all comments that have been reported.
$comments->first()->reports()->pluck('name') //gets a list of users that have reported the comment.
Profanity filter
The Comment Handler comes with a profanity filter for obscuring vile language that might come through the comments. You can expand on this list by adding words to the curses array in the config\comments.php
'curses' => [
['curse' => 'badword', 'filter' => 'replacement'],
],
The profanity filter will also pick up attempts to bypass the filter by replacing characters with symbols. You can add to this by expanding on the alias array in the config\comment.php to add regex expressions to catch additional characters.
'alias' => [
'a' => '[a|@]',
'i' => '[i|!]',
'o' => '[o|0]',
's' => '[s|\$]',
'#' => '+[\s\W_]?' //spaced curse words. DO NOT REMOVE!
]
The above array with catch the strings 'b@dword', 'badw0rd', 'b@dw0rd', 'b a d w o r d' and more.
You can use the profanity filter anywhere in your project you wish to filter potential obscenities.
<div>
{{ \StrangeFate\CommentHandler\Interfaces\CommentHelperFunctions::profanity_filter( $filtertext ) }}
</div>
strangefate/commenthandler 适用场景与选型建议
strangefate/commenthandler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「comments」 「laravel」 「Profanity Filter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 strangefate/commenthandler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 strangefate/commenthandler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 strangefate/commenthandler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Twig extension for Timber which outputs HTML comments before and after the `include` tag
A Laravel Validation Rule to Help Catch Profanity.
Laravel Profanity Filter - Powerful PHP package for detecting, filtering, and masking profanity in multiple languages. Supports leet speak, custom word lists, case sensitivity, and seamless Laravel integration.
Laravel comment system
Comments system for your Laravel application. Features: can be used to comment on any model, HTML filter customization (HTMLPurifier), API, comment rating, replies, events, auth rules ...
A Laravel package to find and remove profanity from text strings.
统计信息
- 总下载量: 50
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-16