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

426 行
13 KiB
PHP
Raw 通常表示 履歴

2018-03-13 22:28:14 +09:00
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\PermissionController;
class SiteController extends Controller {
2018-12-14 18:01:00 +09:00
private $objAuth;
private $objUser;
private $objPermission;
public function __construct() {
$this->objAuth = new AuthController();
$this->objUser = new UserController();
$this->objPermission = new PermissionController();
}
2020-02-24 22:23:51 +09:00
public function getPosts ($ispost=1) {
2020-01-06 18:24:32 +09:00
$kero_token = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
2019-12-05 18:32:20 +09:00
$check = $this->objAuth->checkLegit($kero_token);
$ucol = $this->objUser->getGroupColours();
$valid = $this->objAuth->getPermissions($kero_token);
2020-02-24 22:23:51 +09:00
$get = DB::table('blg_content')->where('isPost', $ispost)->orderBy('publish_date', 'desc')->get();
2019-12-05 18:32:20 +09:00
setlocale(LC_ALL, 'ja_JP.utf8');
2020-02-24 22:23:51 +09:00
foreach ($get as $g) { if ($valid['blg_addpost'] == 0 && $valid['blg_editpost'] == 0 && $g->public_status != 0) unset($g); }
2019-12-05 18:32:20 +09:00
2020-02-24 22:23:51 +09:00
return $get;
2018-12-14 18:01:00 +09:00
}
2020-02-02 14:21:33 +09:00
public function getPost ($slug, $kero) {
2020-01-06 18:24:32 +09:00
$check = $this->objAuth->checkLegit($kero);
$valid = $this->objAuth->getPermissions($kero);
$ucol = $this->objUser->getGroupColours();
if ($valid['blg_editpost']) {
$get = DB::table('blg_content')
->join('users', 'blg_content.user_id', '=', 'users.id')
->join('usr_details', 'usr_details.user_id', '=', 'blg_content.user_id')
->join('usr_profile', 'usr_profile.user_id', '=', 'blg_content.user_id')
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_content.user_id')
->where('isPost', 1)
->where('slug', $slug)
->get(array(
'blg_content.id',
'blg_content.user_id',
'title',
'slug',
'post_date',
'publish_date',
'public_status',
'message',
'username',
'perm_id',
'gender',
'avatar',
'name_style',
'display_name'
));
}
else {
$get = DB::table('blg_content')
->join('users', 'blg_content.user_id', '=', 'users.id')
->join('usr_details', 'usr_details.user_id', '=', 'blg_content.user_id')
->join('usr_profile', 'usr_profile.user_id', '=', 'blg_content.user_id')
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_content.user_id')
->where('public_status', 0)
->where('isPost', 1)
->where('slug', $slug)
->get(array(
'blg_content.id',
'blg_content.user_id',
'title',
'slug',
'post_date',
'publish_date',
'public_status',
'message',
'username',
'perm_id',
'gender',
'avatar',
'name_style',
'display_name'
));
}
$res = array();
setlocale(LC_ALL, 'ja_JP.utf8');
foreach ($get as $i) {
$showName = '';
$showCol = '';
$showGroupName = '';
2020-02-02 14:21:33 +09:00
if (!empty($i->display_name)) $showName = $i->display_name;
else $showName = $i->username;
2020-01-06 18:24:32 +09:00
2020-02-02 14:21:33 +09:00
if (!empty($i->name_style)) $showCol = $i->name_style;
2020-01-06 18:24:32 +09:00
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,
'title' => $i->title,
'slug' => $i->slug,
'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,
'message' => $i->message,
'gender' => $i->gender,
'avatar' => $i->avatar,
'showcol' => $showCol,
2020-02-24 22:23:51 +09:00
'showname' => $showName
2020-01-06 18:24:32 +09:00
]);
}
return $res;
}
2020-02-02 14:21:33 +09:00
public function getComments ($id) {
2018-12-14 18:01:00 +09:00
$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 = '';
2020-02-02 14:21:33 +09:00
if (!empty($i->display_name)) $showName = $i->display_name;
else $showName = $i->username;
2018-12-14 18:01:00 +09:00
2020-02-02 14:21:33 +09:00
if (!empty($i->name_style)) $showCol = $i->name_style;
2018-12-14 18:01:00 +09:00
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;
}
2018-03-15 19:11:44 +09:00
}
2018-12-14 18:01:00 +09:00
}
$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;
}
2020-02-02 14:21:33 +09:00
public function getComment ($id) {
2018-12-14 18:01:00 +09:00
$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')
2018-12-25 19:03:21 +09:00
->where('blg_comments.content_id', $id)
2018-12-14 18:01:00 +09:00
->orderBy('post_date', 'asc')
->get(array(
2019-01-28 18:14:31 +09:00
'blg_comments.id',
2018-12-14 18:01:00 +09:00
'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 = '';
2020-02-02 14:21:33 +09:00
if (!empty($i->display_name)) $showName = $i->display_name;
else $showName = $i->username;
2018-12-14 18:01:00 +09:00
2020-02-02 14:21:33 +09:00
if (!empty($i->name_style)) $showCol = $i->name_style;
2018-12-14 18:01:00 +09:00
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;
}
2018-03-13 23:36:01 +09:00
}
2018-12-14 18:01:00 +09:00
}
$gname = $this->objUser->getGroupName($i->user_id);
$showGroupName = $gname[0]->name;
array_push($res, [
2019-01-28 18:14:31 +09:00
'id' => $i->id,
2018-12-14 18:01:00 +09:00
'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 : '/usericon/haznoavaz.png'),
2018-12-14 18:01:00 +09:00
'showcol' => $showCol,
'showname' => $showName
]);
}
return $res;
}
2020-02-02 14:21:33 +09:00
public function newComment (Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2018-12-14 18:01:00 +09:00
2020-02-02 14:21:33 +09:00
if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。'));
2018-12-25 19:03:21 +09:00
else {
2019-05-25 09:52:37 +09:00
$valid = $this->objAuth->getPermissions($r->kero_token);
2018-12-25 19:03:21 +09:00
if ($valid['blg_addcomment'] == 1) {
$add = DB::table('blg_comments')
2019-03-17 07:00:22 +09:00
->insertGetId([
2018-12-25 19:03:21 +09:00
'user_id' => $check,
2019-05-25 09:52:37 +09:00
'content_id' => $r->content_id,
2018-12-25 19:03:21 +09:00
'votes' => 0,
'post_date' => time(),
'last_date' => 0,
'isDeleted' => 0,
2019-05-25 09:52:37 +09:00
'message' => $r->message,
'ip_address' => $r->ip_address
2018-12-25 19:03:21 +09:00
]);
2019-05-25 09:52:37 +09:00
$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);
2018-12-25 19:03:21 +09:00
return \Response::json($add);
}
2020-02-02 14:21:33 +09:00
else return \Response::json(array('error' => '不許可。'));
2018-12-25 19:03:21 +09:00
}
2018-12-14 18:01:00 +09:00
}
2020-02-02 14:21:33 +09:00
public function editComment (Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2018-12-25 19:03:21 +09:00
2020-02-02 14:21:33 +09:00
if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。'));
2018-12-25 19:03:21 +09:00
else {
2019-05-25 09:52:37 +09:00
$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);
2018-12-25 19:03:21 +09:00
if ($valid['blg_editcomment'] == 1) {
return DB::table('blg_comments')
2019-05-25 09:52:37 +09:00
->where('id', $r->id)
2020-02-02 14:21:33 +09:00
->update(['last_date' => time(), 'message' => $r->message]);
2018-12-25 19:03:21 +09:00
}
else if ($valid['blg_delcomment'] == 1 && $owner[0]->user_id == $check) {
return DB::table('blg_comments')
2019-05-25 09:52:37 +09:00
->where('id', $r->id)
2020-02-02 14:21:33 +09:00
->update(['last_date' => time(), 'message' => $r->message]);
2018-12-25 19:03:21 +09:00
}
2020-02-02 14:21:33 +09:00
else return \Response::json(array('error' => '不許可。'));
2018-12-25 19:03:21 +09:00
}
2018-12-14 18:01:00 +09:00
}
2020-02-02 14:21:33 +09:00
public function removeComment (Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2018-12-14 18:01:00 +09:00
2020-02-02 14:21:33 +09:00
if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。'));
2018-12-25 19:03:21 +09:00
else {
2019-05-25 09:52:37 +09:00
$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);
2018-12-14 18:01:00 +09:00
2018-12-25 19:03:21 +09:00
if ($valid['blg_delcomment'] == 1) {
2020-02-02 14:21:33 +09:00
$get = DB::table('blg_comments')->select('isDeleted')->where('id', $r->id)->get();
2018-12-25 19:03:21 +09:00
$mod = 0;
foreach ($get as $i) {
if ($i->isDeleted == 1) $mod = 0;
else $mod = 1;
}
2020-02-02 14:21:33 +09:00
return DB::table('blg_comments')->where('id', $r->id)->update(['isDeleted' => $mod]);
2018-12-25 19:03:21 +09:00
}
else if ($valid['blg_delowncomment'] == 1 && $owner[0]->user_id == $check) {
2020-02-02 14:21:33 +09:00
$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]);
2018-12-25 19:03:21 +09:00
}
2020-02-02 14:21:33 +09:00
else return \Response::json(array('error' => '不許可。'));
2018-12-25 19:03:21 +09:00
}
2018-12-14 18:01:00 +09:00
}
2020-02-02 14:21:33 +09:00
public function voteComment (Request $r) {
2019-05-25 09:52:37 +09:00
$check = $this->objAuth->checkLegit($r->kero_token);
2018-12-14 18:01:00 +09:00
2020-02-02 14:21:33 +09:00
if ($check == 0) return \Response::json(array('error' => 'ログインされませんでした。'));
2018-12-25 19:03:21 +09:00
else {
2019-05-25 09:52:37 +09:00
$valid = $this->objAuth->getPermissions($r->kero_token);
2018-12-14 18:01:00 +09:00
2018-12-25 19:03:21 +09:00
if ($valid['blg_addcomment'] == 1) {
2020-02-02 14:21:33 +09:00
$get = DB::table('blg_comments')->select('votes')->where('id', $r->id)->get();
2018-12-25 19:03:21 +09:00
$mod = 0;
2020-02-02 14:21:33 +09:00
foreach ($get as $i) { $mod = $i->votes; }
return DB::table('blg_comments')->where('id', $r->id)->update(['votes' => $r->votemod]);
2018-12-25 19:03:21 +09:00
}
2020-02-02 14:21:33 +09:00
else return \Response::json(array('error' => '不許可。'));
2018-12-25 19:03:21 +09:00
}
2018-12-14 18:01:00 +09:00
}
2020-02-02 14:21:33 +09:00
public function getPagesInMenu () {
2018-12-14 18:01:00 +09:00
$get = DB::table('blg_content')
->select('title', 'slug')
->where('public_status', 0)
->where('isPost', 0)
->where('isMenu', 1)
->orderBy('sortorder', 'asc')
->get();
$res = array();
$key = 0;
foreach ($get as $i) {
2020-02-02 14:21:33 +09:00
array_push($res, ['key' => $key, 'title' => $i->title, 'slug' => $i->slug]);
2018-12-14 18:01:00 +09:00
$key++;
}
return $res;
}
2020-02-02 14:21:33 +09:00
public function getPage ($slug, $kero) {
2020-01-06 18:24:32 +09:00
$valid = $this->objAuth->getPermissions($kero);
if ($valid['blg_editpage'] == 1) {
return DB::table('blg_content')
->select('id', 'title', 'slug', 'isMenu', 'public_status', 'message')
->where('isPost', 0)
->where('slug', $slug)
->orderBy('sortorder', 'asc')
->first();
}
else {
return DB::table('blg_content')
->select('id', 'title', 'slug', 'isMenu', 'public_status', 'message')
->where('public_status', 0)
->where('isPost', 0)
->where('slug', $slug)
->orderBy('sortorder', 'asc')
->first();
}
}
2018-03-13 22:28:14 +09:00
}