objAuth = new AuthController(); $this->objUser = new UserController(); $this->objPermission = new PermissionController(); $this->valid = $this->objAuth->getPermissions((isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '')); $this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : ''); $this->id = $this->objAuth->checkLegit($this->cook); $this->user = $this->objUser->getLoggedUser($this->id, $this->cook); } public function index () { $get = DB::table('blg_content')->where('isPost', 1); if ($this->valid['blg_addpost'] == 0 && $this->valid['blg_editpost'] == 0) $get = $get->where('public_status', 0); $get = $get->orderBy('publish_date', 'desc')->get(); setlocale(LC_ALL, 'ja_JP.utf8'); return view('pages.site.index', ['res' => $get, 'menu' => getPagesInMenu(), 'user' => $this->user]); } public function getPost ($slug, $kero) { $get = DB::table('blg_content'); if ($this->valid['blg_editpost'] == 0) $get = $get->where('public_status', 0); $get = $get->where('isPost', 1)->where('slug', $slug)->first(); $ucol = $this->objUser->getGroupColours(); setlocale(LC_ALL, 'ja_JP.utf8'); $get->showName = ''; $get->showCol = ''; $get->comments = DB::table('blg_comments')->where('post_id', $get->id)->orderBy('id', 'asc')->get(); $get->username = DB::table('users')->select('username')->where('id', $get->user_id)->first()->username; $get->perm_id = DB::table('usr_perm_id')->select('perm_id')->where('user_id', $get->user_id)->first()->perm_id; $p = DB::table('usr_profile')->select('gender', 'avatar', 'name_style', 'display_name')->where('user_id', $get->user_id)->first(); $get->gender = $p->gender; $get->avatar = $p->avatar; $get->name_style = $p->name_style; $get->display_name = $p->display_name; foreach ($get->comments as $k => $c) { if (count(userDetail($c->user_id)) > 0) { $det = userDetail($c->user_id); $c->user_id = $det['user_id']; $c->showname = $det['showname']; $c->showcol = $det['showcol']; $c->avatar = $det['avatar']; } if ($c->isShadow == 0) { if (getIp() != $c->ipaddress) unset($get->comments[$k]); } else { unset($c->email); unset($c->ipaddress); unset($c->isShadow); $c->created = date('Y年m月d日 H:i:s', $c->created); } } if (!empty($get->display_name)) $get->showname = $get->display_name; else $get->showname = $get->username; if (!empty($get->name_style)) $get->showcol = $get->name_style; else { foreach ($ucol as $j) { if ($j->id == $get->perm_id) { if ($get->gender == 1) $get->showcol = $j->colour_m; else if ($get->gender == 2) $get->showcol = $j->colour_f; else $get->showcol = $j->colour_u; } } } $get->user = userDetail(null, $kero); $get->post_date = strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $get->post_date); $get->publish_date = strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $get->publish_date); return $get; } public function newComment (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' => $com['name'], 'email' => $com['mail'], '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 (count(userDetail($r->user_id)) > 0) { $det = userDetail($r->user_id); $res->user_id = $det['user_id']; $res->showname = $det['showname']; $res->showcol = $det['showcol']; $res->avatar = $det['avatar']; } return array('status' => '010100', 'message' => 'OK', 'result' => $res); } public function getPage ($slug, $kero) { $sel = array('id', 'title', 'slug', 'isMenu', 'public_status', 'message'); $res = DB::table('blg_content')->select($sel); if ($this->valid['blg_editpage'] == 0) $res = $res->where('public_status', 0); $res = $res->where('isPost', 0)->where('slug', $slug)->orderBy('sortorder', 'asc')->first(); return $res; } public function addContent ($bdl) { if (($this->valid['blg_addpost'] && $bdl['isPost'] == 1) || ($this->valid['blg_addpage'] && $bdl['isPost'] == 0)) { return DB::table('blg_content')->insert($bdl); } return 0; } public function editContent ($bdl) { if (($this->valid['blg_editpost'] && $bdl['isPost'] == 1) || ($this->valid['blg_editpage'] && $bdl['isPost'] == 0)) { return DB::table('blg_content')->where('slug', $bdl['slug'])->update($bdl); } return 0; } public function delContent ($bdl) { if (($this->valid['blg_delpost'] && $bdl['isPost'] == 1) || ($this->valid['blg_delpage'] && $bdl['isPost'] == 0)) { return DB::table('blg_content')->where('slug', $bdl['slug'])->delete(); } return 0; } }