49 行
1.7 KiB
PHP
49 行
1.7 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 __construct () {
|
|
}
|
|
|
|
public function add (Request $r) {
|
|
$com = $r->comment;
|
|
if ($r->isvideo == 'f') $id = DB::table('blg_content')->select('id')->where('slug', $r->slug)->first()->id;
|
|
$shadow = DB::table('blg_blacklist')->where('ipaddress', getIp())->first();
|
|
if ($shadow && !$shadow->isShadow) return array('status' => '0101FF', 'message' => '失礼しますが、あなたはBANされていましたので、コメントを保存できません。');
|
|
|
|
$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($com['name']) ? $com['name'] : null),
|
|
'email' => (isset($com['mail']) ? $com['mail'] : null),
|
|
'message' => $com['text'],
|
|
'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 array('status' => '010100', 'message' => 'OK', 'result' => $res);
|
|
}
|
|
}
|