diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index b92befd..131d895 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -102,6 +102,18 @@ class SiteController extends Controller { $showName = ''; $showCol = ''; $showGroupName = ''; + $comments = DB::table('blg_comments')->where('post_id', $i->id)->orderBy('id', 'asc')->get(); + + foreach ($comments as $k => $c) { + if ($c->isShadow == 0) { + if ($this->getIp() != $c->ipaddress) unset($comments[$k]); + } + else { + unset($c->ipaddress); + unset($c->isShadow); + $c->created = date('Y年m月d日 H:i:s', $c->created); + } + } if (!empty($i->display_name)) $showName = $i->display_name; else $showName = $i->username; @@ -128,6 +140,7 @@ class SiteController extends Controller { 'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date), 'publish_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->publish_date), 'public_status' => $i->public_status, + 'comments' => $comments, 'message' => $i->message, 'gender' => $i->gender, 'avatar' => $i->avatar, @@ -139,246 +152,36 @@ class SiteController extends Controller { return $res; } - public function getComments ($id) { - $ucol = $this->objUser->getGroupColours(); - - $get = DB::table('blg_comments') - ->join('users', 'blg_comments.user_id', '=', 'users.id') - ->join('usr_details', 'usr_details.user_id', '=', 'blg_comments.user_id') - ->join('usr_profile', 'usr_profile.user_id', '=', 'blg_comments.user_id') - ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_comments.user_id') - ->where('content_id', $id) - ->orderBy('post_date', 'asc') - ->get(array( - 'blg_comments.id', - 'blg_comments.user_id', - 'votes', - 'post_date', - 'last_date', - 'isDeleted', - 'message', - 'blg_comments.ip_address', - 'username', - 'perm_id', - 'gender', - 'avatar', - 'name_style', - 'display_name' - )); - - $res = array(); - $key = 1; - setlocale(LC_ALL, 'ja_JP.utf8'); - - foreach ($get as $i) { - $showName = ''; - $showCol = ''; - $showGroupName = ''; - - if (!empty($i->display_name)) $showName = $i->display_name; - else $showName = $i->username; - - if (!empty($i->name_style)) $showCol = $i->name_style; - else { - foreach ($ucol as $j) { - if ($j->id == $i->perm_id) { - if ($i->gender == 1) $showCol = $j->colour_m; - else if ($i->gender == 2) $showCol = $j->colour_f; - else $showCol = $j->colour_u; - } - } - } - - $gname = $this->objUser->getGroupName($i->user_id); - $showGroupName = $gname[0]->name; - - array_push($res, [ - 'key' => $key, - 'id' => $i->id, - 'user_id' => $i->user_id, - 'votes' => $i->votes, - 'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date), - 'last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->last_date), - 'last_unix' => $i->last_date, - 'isDeleted' => $i->isDeleted, - 'message' => $i->message, - 'ip_address' => $i->ip_address, - 'avatar' => $i->avatar, - 'showcol' => $showCol, - 'showname' => $showName - ]); - $key++; - } - - return $res; - } - - public function getComment ($id) { - $ucol = $this->objUser->getGroupColours(); - - $get = DB::table('blg_comments') - ->join('users', 'blg_comments.user_id', '=', 'users.id') - ->join('usr_details', 'usr_details.user_id', '=', 'blg_comments.user_id') - ->join('usr_profile', 'usr_profile.user_id', '=', 'blg_comments.user_id') - ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_comments.user_id') - ->where('blg_comments.content_id', $id) - ->orderBy('post_date', 'asc') - ->get(array( - 'blg_comments.id', - 'blg_comments.user_id', - 'content_id', - 'votes', - 'post_date', - 'last_date', - 'isDeleted', - 'message', - 'blg_comments.ip_address', - 'username', - 'perm_id', - 'gender', - 'avatar', - 'name_style', - 'display_name' - )); - - $res = array(); - setlocale(LC_ALL, 'ja_JP.utf8'); - - foreach ($get as $i) { - $showName = ''; - $showCol = ''; - $showGroupName = ''; - - if (!empty($i->display_name)) $showName = $i->display_name; - else $showName = $i->username; - - if (!empty($i->name_style)) $showCol = $i->name_style; - else { - foreach ($ucol as $j) { - if ($j->id == $i->perm_id) { - if ($i->gender == 1) $showCol = $j->colour_m; - else if ($i->gender == 2) $showCol = $j->colour_f; - else $showCol = $j->colour_u; - } - } - } - - $gname = $this->objUser->getGroupName($i->user_id); - $showGroupName = $gname[0]->name; - - array_push($res, [ - 'id' => $i->id, - 'user_id' => $i->user_id, - 'content_id' => $i->content_id, - 'votes' => $i->votes, - 'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date), - 'last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->last_date), - 'last_unix' => $i->last_date, - 'isDeleted' => $i->isDeleted, - 'message' => $i->message, - 'ip_address' => $i->ip_address, - 'avatar' => ($i->avatar ? $i->avatar : '/img/noicon.webp'), - 'showcol' => $showCol, - 'showname' => $showName - ]); - } - - return $res; - } - public function newComment (Request $r) { - $check = $this->objAuth->checkLegit($r->kero_token); + $com = $r->comment; + $id = DB::table('blg_content')->select('id')->where('slug', $r->slug)->first()->id; + $shadow = DB::table('blg_blacklist')->where('ipaddress', $this->getIp())->first(); - if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。')); - else { - $valid = $this->objAuth->getPermissions($r->kero_token); + if ($shadow && !$shadow->isShadow) return array('status' => '0101FF', 'message' => '失礼しますが、あなたはBANされていましたので、コメントを保存できません。'); + $shadow = ($shadow ? 0 : 1); - if ($valid['blg_addcomment'] == 1) { - $add = DB::table('blg_comments') - ->insertGetId([ - 'user_id' => $check, - 'content_id' => $r->content_id, - 'votes' => 0, - 'post_date' => time(), - 'last_date' => 0, - 'isDeleted' => 0, - 'message' => $r->message, - 'ip_address' => $r->ip_address - ]); + $add = DB::table('blg_comments') + ->insertGetId([ + 'post_id' => $id, + 'name' => $com['name'], + 'message' => $com['text'], + 'created' => time(), + 'ipaddress' => $this->getIp(), + 'isShadow' => $shadow + ]); - $g = DB::table('blg_content')->select('slug', 'user_id')->where('id', $r->content_id)->first(); - if ($check != $g->user_id) $this->objUser->addNotification($r, $g->user_id, 1, '新規ブログコメント', 'blog/'.$g->slug, 'comment-'.$add); - return \Response::json($add); - } - else return \Response::json(array('error' => '不許可。')); - } + // 返事だったら、メールを送って + + $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); + return array('status' => '010100', 'message' => 'OK', 'result' => $res); } - public function editComment (Request $r) { - $check = $this->objAuth->checkLegit($r->kero_token); - - if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。')); - else { - $owner = DB::table('blg_comments')->select('user_id')->where('id', $r->id)->where('user_id', $r->user)->get()->toArray(); - $valid = $this->objAuth->getPermissions($r->kero_token); - - if ($valid['blg_editcomment'] == 1) { - return DB::table('blg_comments') - ->where('id', $r->id) - ->update(['last_date' => time(), 'message' => $r->message]); - } - else if ($valid['blg_delcomment'] == 1 && $owner[0]->user_id == $check) { - return DB::table('blg_comments') - ->where('id', $r->id) - ->update(['last_date' => time(), 'message' => $r->message]); - } - else return \Response::json(array('error' => '不許可。')); - } - } - - public function removeComment (Request $r) { - $check = $this->objAuth->checkLegit($r->kero_token); - - if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。')); - else { - $owner = DB::table('blg_comments')->select('user_id')->where('id', $r->id)->where('user_id', $r->user)->get()->toArray(); - $valid = $this->objAuth->getPermissions($r->kero_token); - - if ($valid['blg_delcomment'] == 1) { - $get = DB::table('blg_comments')->select('isDeleted')->where('id', $r->id)->get(); - $mod = 0; - - foreach ($get as $i) { - if ($i->isDeleted == 1) $mod = 0; - else $mod = 1; - } - - return DB::table('blg_comments')->where('id', $r->id)->update(['isDeleted' => $mod]); - } - else if ($valid['blg_delowncomment'] == 1 && $owner[0]->user_id == $check) { - $get = DB::table('blg_comments')->select('isDeleted')->where('id', $r->id)->get(); - foreach ($get as $i) if ($i->isDeleted == 1) return "不許可"; - return DB::table('blg_comments')->where('id', $r->id)->update(['isDeleted' => 1]); - } - else return \Response::json(array('error' => '不許可。')); - } - } - - public function voteComment (Request $r) { - $check = $this->objAuth->checkLegit($r->kero_token); - - if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。')); - else { - $valid = $this->objAuth->getPermissions($r->kero_token); - - if ($valid['blg_addcomment'] == 1) { - $get = DB::table('blg_comments')->select('votes')->where('id', $r->id)->get(); - $mod = 0; - foreach ($get as $i) { $mod = $i->votes; } - return DB::table('blg_comments')->where('id', $r->id)->update(['votes' => $r->votemod]); - } - else return \Response::json(array('error' => '不許可。')); - } + public function getIp () { + if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; + elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + else $ip = $_SERVER['REMOTE_ADDR']; + return $ip; } public function getPagesInMenu () { diff --git a/config/database.php b/config/database.php index b42d9b3..f8c241f 100644 --- a/config/database.php +++ b/config/database.php @@ -63,6 +63,26 @@ return [ ]) : [], ], + 'mysqlvmail' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_VMAIL_URL'), + 'host' => env('DB_HOST_VMAIL', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [], + ], + 'pgsql' => [ 'driver' => 'pgsql', 'url' => env('DATABASE_URL'), diff --git a/public/img/noicon.webp b/public/img/noicon.webp new file mode 100644 index 0000000..87601e8 Binary files /dev/null and b/public/img/noicon.webp differ diff --git a/resources/js/bootstrap.js b/resources/js/bootstrap.js index e957d54..f1ff2f1 100644 --- a/resources/js/bootstrap.js +++ b/resources/js/bootstrap.js @@ -18,6 +18,7 @@ try { window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; Vue.component('appbar', require('./components/appbar.vue').default); +Vue.component('comments', require('./components/comments.vue').default); Vue.component('discord', require('./components/discord.vue').default); const app = new Vue({ el: '#app' }); diff --git a/resources/js/components/comments.vue b/resources/js/components/comments.vue new file mode 100644 index 0000000..57b3d21 --- /dev/null +++ b/resources/js/components/comments.vue @@ -0,0 +1,107 @@ + + + + + diff --git a/resources/views/pages/site/post.blade.php b/resources/views/pages/site/post.blade.php index 60a84a6..4ea646d 100644 --- a/resources/views/pages/site/post.blade.php +++ b/resources/views/pages/site/post.blade.php @@ -17,7 +17,9 @@
-
コメントがありません。
+
+ +
diff --git a/routes/api/site.php b/routes/api/site.php index e9bbb6d..9df49fe 100644 --- a/routes/api/site.php +++ b/routes/api/site.php @@ -1,8 +1,3 @@