objAuth = new AuthController(); $this->objUser = new UserController(); $this->objPermission = new PermissionController(); } public function getPosts ($ispost=1) { $kero_token = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : ''); $check = $this->objAuth->checkLegit($kero_token); $ucol = $this->objUser->getGroupColours(); $valid = $this->objAuth->getPermissions($kero_token); $get = DB::table('blg_content')->where('isPost', $ispost)->orderBy('publish_date', 'desc')->get(); setlocale(LC_ALL, 'ja_JP.utf8'); foreach ($get as $g) { if ($valid['blg_addpost'] == 0 && $valid['blg_editpost'] == 0 && $g->public_status != 0) unset($g); } return $get; } public function getPost ($slug, $kero) { $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 = ''; 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, '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, 'showname' => $showName ]); } 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 : '/usericon/haznoavaz.png'), 'showcol' => $showCol, 'showname' => $showName ]); } return $res; } public function newComment (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) { $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 ]); $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' => '不許可。')); } } 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 getPagesInMenu () { $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) { array_push($res, ['key' => $key, 'title' => $i->title, 'slug' => $i->slug]); $key++; } return $res; } public function getPage ($slug, $kero) { $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(); } } }