このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/Home/Comment.php

45 行
1.9 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 '';
$isvideo = false;
if (!$cont = DB::table('blg_content')->where('slug', $r->slug)->first()) { if ($cont = DB::table('vid_video')->where('vid', $r->slug)->first()) $isvideo = true; }
$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('/');
}
$user = null;
if (isset($_COOKIE['kero_token'])) $user = DB::table('users')->select('id')->where('kero_token', $_COOKIE['kero_token'])->first()->id;
if ($user == 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' => $user,
'post_id' => (!$isvideo ? $cont->id : 0),
'video_id' => ($isvideo ? $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)
]);
// 返事だったら、メールを送って
return redirect('/'.($isvideo ? 'video/play' : 'blog').'/'.$r->slug.'#comment-'.$add);
}
}