55 行
2.2 KiB
PHP
55 行
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Home;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Http\Request;
|
|
// use Illuminate\Support\Facades\Log;
|
|
|
|
class Comment {
|
|
public function add (Request $r) {
|
|
if (!isset($r->submit)) return '';
|
|
if ($r->isvideo == 'f') $id = DB::table('blg_content')->select('id')->where('slug', $r->slug)->first()->id;
|
|
$banned = DB::table('blg_blacklist')->where('isShadow', 0)->get();
|
|
foreach ($banned as $b) {
|
|
$ip = explode('.', getIp());
|
|
$ban = explode('.', $b->ipaddress);
|
|
if (
|
|
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == $ip[2] && $ban[3] == $ip[3]) ||
|
|
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == $ip[2] && $ban[3] == '*') ||
|
|
($ban[0] == $ip[0] && $ban[1] == $ip[1] && $ban[2] == '*' && $ban[3] == '*')
|
|
) return redirect('/bot-trap/');
|
|
}
|
|
|
|
if ($r->user_id == 0 && (str_contains($r->newmessage, 'http://') || str_contains($r->newmessage, 'https://'))) return redirect('/');
|
|
$shadow = DB::table('blg_blacklist')->where('isShadow', 1)->where('ipaddress', getIp())->first();
|
|
|
|
$add = DB::table('blg_comments')->insertGetId([
|
|
'user_id' => ($r->user_id != 0 ?: null),
|
|
'post_id' => ($r->isvideo == 'f' ? $id : 0),
|
|
'video_id' => ($r->isvideo == 't' ? $r->slug : ''),
|
|
'name' => (isset($r->newname) ? $r->newname : null),
|
|
'email' => (isset($r->newmail) ? $r->newmail : null),
|
|
'message' => $r->newmessage,
|
|
'created' => time(),
|
|
'ipaddress' => getIp(),
|
|
'isShadow' => ($shadow ? 0 : 1)
|
|
]);
|
|
|
|
// 返事だったら、メールを送って
|
|
|
|
$res = DB::table('blg_comments')->select('id', 'name', 'created', 'message')->where('id', $add)->first();
|
|
$res->created = date('Y年m月d日 H:i:s', $res->created);
|
|
|
|
if (!is_null($r->user_id) && !empty(userDetail($r->user_id))) {
|
|
$det = userDetail($r->user_id);
|
|
$res->user_id = $det['user_id'];
|
|
$res->showname = $det['showname'];
|
|
$res->showcol = $det['showcol'];
|
|
$res->avatar = $det['avatar'];
|
|
$res->replyCount = 0;
|
|
$res->isvideo = $r->isvideo;
|
|
}
|
|
|
|
return redirect('/'.($r->isvideo == 't' ? 'video/play' : 'blog').'/'.$r->slug.'#comment-'.$add);
|
|
}
|
|
} |