やっとコメント機能性は再開!!

このコミットが含まれているのは:
テクニカル諏訪子 2020-07-14 14:19:15 +09:00
コミット 7d6a55ed21
8個のファイルの変更170行の追加242行の削除

ファイルの表示

@ -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 () {

ファイルの表示

@ -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'),

バイナリ
public/img/noicon.webp ノーマルファイル

バイナリファイルは表示されません。

変更後

幅:  |  高さ:  |  サイズ: 1.3 KiB

ファイルの表示

@ -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' });

107
resources/js/components/comments.vue ノーマルファイル
ファイルの表示

@ -0,0 +1,107 @@
<template>
<div id="comments" class="comments-area clearfix">
<h3 class="comments-count section-heading uppercase"><span>{{ total }} コメント</span></h3>
<div v-if="total === 0">コメントがありません</div>
<span v-else>
<ul class="commentlist" v-for="(c, i) in comment" :key="`comment-${i}`">
<li class="comment even thread-even depth-1" :id="`li-comment-${c.id}`">
<div class="commentnumber">{{ i+1 }}</div>
<div :id="`comment-${c.id}`">
<div>
<cite class="fn">{{ (c.name || '名無しのテクニシャン') }}</cite> <span class="says">より:</span>
<span class="comment-meta commentmetadata"> <a :href="`/blog/${slug}#comment-${c.id}`">{{ c.created }}</a></span>
</div>
<p>{{ c.message }}</p>
<div class="reply">返信</div>
</div>
</li>
</ul>
</span>
<hr />
<div v-if="err" class="alert alert-danger">{{ err }}</div>
<div class="form-group row">
<div class="col-md-4 col-lg-3">名前</div>
<div class="input-group col-md col-lg">
<input type="text" id="new-name" class="form-control" v-model="newComment.name" placeholder="ご入力しない場合、名前は「名無しのテクニシャン」になります。" />
</div>
</div>
<div class="form-group row">
<div class="col-md-4 col-lg-3">メールアドレス</div>
<div class="input-group col-md col-lg">
<input type="text" id="new-mail" class="form-control" v-model="newComment.mail" placeholder="返信される場合、メールに通知を送ります。" />
</div>
</div>
<div class="row">
<div class="col-md-4 col-lg-3">本文</div>
<div class="col-md col-lg">
<textarea class="form-control" id="new-message" rows="16" v-model="newComment.text"></textarea>
</div>
</div>
<div class="row" style="margin-top: 16px;">
<div class="col">
<button type="button" class="btn btn-block btn-primary" @click="send">送信</button>
</div>
</div>
</div>
</template>
<script>
export default {
props: { slug: '', comments: Array },
data: function () { return { comment: this.comments, newComment: {}, err: '', loading: true, sending: false } },
computed: {
total: function () {
return this.comment.length;
}
},
created: function () { this.reset(); },
methods: {
reset () {
this.loading = false;
this.newComment.name = '';
this.newComment.mail = '';
this.newComment.text = '';
},
send () {
this.err = '';
this.sending = true;
axios.post('/api/comment/new', {
comment: this.newComment,
slug: this.slug
}).then(res => {
this.sending = false;
if (res.data.status === '010100') { this.comment.push(res.data.result); this.reset(); }
else this.err = 'エラーコード【' + res.data.status + '】' + res.data.message;
}).catch(err => {
this.sending = false;
this.err = 'サーバーエラーコード【' + err.response.status + '】' + err.response.data.message;
});
}
}
}
</script>
<style scoped>
.fn {
font-size: 16px;
font-style: normal;
color: #20ec77;
}
.comment-meta a {
color: #bdc3c7;
}
.commentlist p {
margin: 0 0 10px;
padding: 10px 0 40px 0;
font-size: 20px;
}
.commentnumber {
float: left;
margin-right: 5px;
font-size: 16px;
}
ul {
list-style: none;
}
</style>

ファイルの表示

@ -17,7 +17,9 @@
<div class="comment">
<div class="container-fluid">
<div class="row">
<div class="col">コメントがありません。</div>
<div class="col">
<comments slug="{{$res[0]['slug']}}" :comments="{{json_encode($res[0]['comments'])}}" />
</div>
</div>
</div>
</div>

ファイルの表示

@ -1,8 +1,3 @@
<?php
Route::get('/api/rpc/site/comment/get/all/{id}', 'SiteController@getComments');
Route::get('/api/rpc/site/comment/get/one/{id}', 'SiteController@getComment');
Route::post('/api/rpc/site/comment/new', 'SiteController@newComment');
Route::post('/api/rpc/site/comment/edit', 'SiteController@editComment');
Route::post('/api/rpc/site/comment/remove', 'SiteController@removeComment');
Route::post('/api/rpc/site/comment/vote', 'SiteController@voteComment');
Route::post('/api/comment/new', 'SiteController@newComment');

ファイルの表示

@ -10,4 +10,4 @@ Route::post('/register', 'HomeController@register');
Route::get('/profile/{id}', 'HomeController@profile');
Route::get('/{slug}', 'HomeController@page');
Route::get('/{slug}', 'HomeController@page');