diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php
index 563fd69..c7c324a 100644
--- a/app/Http/Controllers/AuthController.php
+++ b/app/Http/Controllers/AuthController.php
@@ -19,16 +19,10 @@ class AuthController extends Controller {
}
public function checkSelf(Request $r) { // /api/auth/checkself
- $check = $this->checkLegit($r->kero_token);
+ $check = checkLegit($r->kero_token);
return array($check);
}
- public function checkLegit ($t) {
- if (!isset($t) || empty($t) || is_null($t)) return 0;
- $check = DB::table('users')->select('id')->where('kero_token', $t)->first();
- return $check->id;
- }
-
public function getPerms(Request $r) { // /api/auth/getpermissions
$check = $this->getPermissions($r->kero_token);
@@ -36,7 +30,7 @@ class AuthController extends Controller {
}
public function getPermissions($token) {
- $check = $this->checkLegit($token);
+ $check = checkLegit($token);
$perm = DB::table('usr_perm_id')
->select('perm_id')
diff --git a/app/Http/Controllers/BoardController.php b/app/Http/Controllers/BoardController.php
deleted file mode 100644
index 752aae8..0000000
--- a/app/Http/Controllers/BoardController.php
+++ /dev/null
@@ -1,1914 +0,0 @@
-objAuth = new AuthController();
- $this->objUser = new UserController();
- $this->objPermission = new PermissionController();
- }
-
- public function getCategories() { // /api/rpc/board/category/getcategories
- return DB::table('for_category')
- ->select('*')
- ->orderBy('order', 'asc')
- ->get();
- }
-
- public function getCategory($id) { // /api/rpc/board/category/getcategory/id
- return DB::table('for_category')
- ->select('*')
- ->where('id', $id)
- ->get();
- }
-
- public function getCategoryName($id) { // /api/rpc/board/category/getcategoryname/id
- return DB::table('for_category')
- ->select('title')
- ->where('id', $id)
- ->get();
- }
-
- public function checkRead($for, $top, $kero_token) {
- $check = $this->objAuth->checkLegit($kero_token);
-
- if ($check == 0) {
- $yetToRead = false;
- }
- else {
- $valid = $this->objAuth->getPermissions($kero_token);
- $yetToRead = false;
-
- if ($valid['for_canview']) {
- $isRead = array();
-
- if ($for != 0) {
- $isRead = DB::table('for_threads')
- ->select('id')
- ->where('for_id', $for)
- ->get();
- }
- else {
- $isRead[] = array('id' => $top);
- }
-
- foreach ($isRead as $read) {
- $rid = 0;
-
- if ($for != 0) {
- $rid = $read->id;
- }
- else {
- $rid = $read['id'];
- }
-
- $get = DB::table('for_read')
- ->join('for_posts', 'for_posts.top_id', 'for_read.top_id')
- ->where('for_read.user_id', $check)
- ->where('for_read.top_id', $rid)
- ->get(array(
- 'for_posts.id',
- 'for_posts.user_id',
- 'for_posts.top_id',
- 'for_posts.post_date',
- 'for_read.view_time',
- ));
-
- if (!$get->count()) {
- $yetToRead = true;
- }
- else {
- foreach($get as $g) {
- if ($g->post_date > $g->view_time) {
- $yetToRead = true;
- }
- }
- }
- }
- }
- }
-
- return $yetToRead;
- }
-
- public function markReadAll (Request $r) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Guests can\'t read';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_canview']) {
- $tid = DB::table('for_threads')
- ->select('id')
- ->get();
-
- foreach ($tid as $t) {
- $chk = DB::table('for_read')
- ->where('user_id', $check)
- ->where('top_id', $t->id)
- ->count();
-
- if ($chk) {
- $r->top_id = $t->id;
- $this->readTopic($r);
- }
- else {
- $getPost = DB::table('for_posts')
- ->select('post_date')
- ->where('top_id', $t->id)
- ->orderBy('post_date', 'desc')
- ->limit(1)
- ->first();
-
- DB::table('for_read')
- ->insert([
- 'user_id' => $check,
- 'top_id' => $t->id,
- 'view_time' => $getPost->post_date
- ]);
- }
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function markReadCat (Request $r) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Guests can\'t read';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_canview']) {
- $fid = DB::table('for_forums')
- ->select('id')
- ->where('cat_id', $r->cat_id)
- ->get();
-
- foreach ($fid as $f) {
- $tid = DB::table('for_threads')
- ->select('id')
- ->where('for_id', $f->id)
- ->get();
-
- foreach ($tid as $t) {
- $chk = DB::table('for_read')
- ->where('user_id', $check)
- ->where('top_id', $t->id)
- ->count();
-
- if ($chk) {
- $r->top_id = $t->id;
- $this->readTopic($r);
- }
- else {
- $getPost = DB::table('for_posts')
- ->select('post_date')
- ->where('top_id', $t->id)
- ->orderBy('post_date', 'desc')
- ->limit(1)
- ->first();
-
- DB::table('for_read')
- ->insert([
- 'user_id' => $check,
- 'top_id' => $t->id,
- 'view_time' => $getPost->post_date
- ]);
- }
- }
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function markRead (Request $r) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Guests can\'t read';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_canview']) {
- $tid = DB::table('for_threads')
- ->select('id')
- ->where('for_id', $r->for_id)
- ->get();
-
- foreach ($tid as $t) {
- $chk = DB::table('for_read')
- ->where('user_id', $check)
- ->where('top_id', $t->id)
- ->count();
-
- if ($chk) {
- $r->top_id = $t->id;
- $this->readTopic($r);
- }
- else {
- $getPost = DB::table('for_posts')
- ->select('post_date')
- ->where('top_id', $t->id)
- ->orderBy('post_date', 'desc')
- ->limit(1)
- ->first();
-
- DB::table('for_read')
- ->insert([
- 'user_id' => $check,
- 'top_id' => $t->id,
- 'view_time' => $getPost->post_date
- ]);
- }
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function readTopic(Request $r) { // /api/rpc/board/topic/read
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Guests can\'t read';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_canview']) {
- $getRead = DB::table('for_read')
- ->select('view_time')
- ->where('user_id', $check)
- ->where('top_id', $r->top_id)
- ->first();
-
- $getPost = DB::table('for_posts')
- ->select('post_date')
- ->where('top_id', $r->top_id)
- ->orderBy('post_date', 'desc')
- ->limit(1)
- ->first();
-
- if ($getRead->view_time < $getPost->post_date) {
- DB::table('for_read')
- ->where('user_id', $check)
- ->where('top_id', $r->top_id)
- ->update([
- 'view_time' => $getPost->post_date
- ]);
-
- return 'Read.';
- }
-
- return '';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function addCategory(Request $r) { // /api/rpc/board/category/add
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_catmod'] == 1) {
- $add = DB::table('for_category')
- ->insertGetId([
- 'title' => $r->title,
- 'order' => $r->order
- ]);
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editCategory(Request $r) { // /api/rpc/board/category/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_catmod'] == 1) {
- return DB::table('for_category')
- ->where('id', $r->id)
- ->update([
- 'id' => $r->id,
- 'title' => $r->title
- ]);
- }
- }
- }
-
- public function deleteCategory(Request $r) { // /api/rpc/board/category/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_catmod'] == 1) {
- return DB::table('for_category')->where('id', $r->id)->delete();
- }
- }
- }
-
- public function getForums($id) { // /api/rpc/board/forum/getforums/id
- if ($id == 0) {
- $get = DB::table('for_forums')
- ->select('id', 'last_uid', 'cat_id', 'title', 'description', 'threads', 'posts', 'last_date')
- ->orderBy('order', 'asc')
- ->get();
- }
- else {
- $get = DB::table('for_forums')
- ->select('id', 'last_uid', 'cat_id', 'title', 'description', 'threads', 'posts', 'last_date')
- ->where('cat_id', $id)
- ->orderBy('order', 'asc')
- ->get();
- }
-
- $res = array();
- $key = 0;
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- foreach ($get as $i) {
- array_push($res, [
- 'key' => $key,
- 'id' => $i->id,
- 'last_uid' => $i->last_uid,
- 'cat_id' => $i->cat_id,
- 'title' => $i->title,
- 'description' => $i->description,
- 'threads' => $i->threads,
- 'posts' => $i->posts,
- 'last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->last_date)
- ]);
- $key++;
- }
-
- return $res;
- }
-
- public function getForum($id) { // /api/rpc/board/forum/getforum/id
- return DB::table('for_forums')
- ->select('*')
- ->where('id', $id)
- ->orderBy('order', 'asc')
- ->get();
- }
-
- public function addForum(Request $r) { // /api/rpc/board/forum/add
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_formod'] == 1) {
- $add = DB::table('for_forums')
- ->insertGetId([
- 'last_uid' => 0,
- 'cat_id' => $r->cat_id,
- 'title' => $r->title,
- 'description' => $r->description,
- 'threads' => 0,
- 'posts' => 0,
- 'last_date' => 0,
- 'min_power' => 0,
- 'permission' => 0,
- 'readonly' => $r->ro,
- 'post_count_freeze' => $r->pcf,
- 'order' => $r->order,
- 'parent' => 0
- ]);
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editForum(Request $r) { // /api/rpc/board/forum/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_formod'] == 1) {
- return DB::table('for_forums')
- ->where('id', $r->id)
- ->update([
- 'cat_id' => $r->cat_id,
- 'title' => $r->title,
- 'description' => $r->description,
- 'readonly' => $r->ro,
- 'post_count_freeze' => $r->pcf
- ]);
- }
- }
- }
-
- public function deleteForum(Request $r) { // /api/rpc/board/forum/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_formod'] == 1) {
- return DB::table('for_forums')->where('id', $r->id)->delete();
- }
- }
- }
-
- public function getForumIdFromTopic($id) { // /api/rpc/board/topic/getforumidfromtopic/id
- return DB::table('for_threads')
- ->select('for_id')
- ->where('id', $id)
- ->first()->for_id;
- }
-
- public function getTopicIdFromPost($id) { // /api/rpc/board/post/gettopicidfrompost/id
- return DB::table('for_posts')
- ->select('top_id')
- ->where('id', $id)
- ->first()->top_id;
- }
-
- public function getForumIdFromPost($id) { // /api/rpc/board/post/getforumidfrompost/id
- $top_id = $this->getTopicIdFromPost($id);
-
- return $this->getForumIdFromTopic($top_id);
- }
-
- public function getForumName($id) { // /api/rpc/board/forum/getforumname/id
- return DB::table('for_forums')
- ->select('cat_id', 'title', 'description')
- ->where('id', $id)
- ->orderBy('order', 'asc')
- ->get();
- }
-
- public function getPostCountFreeze($id) { // /api/rpc/board/forum/getpostcountfreeze/id
- return DB::table('for_forums')
- ->select('post_count_freeze')
- ->where('id', $id)
- ->first()->post_count_freeze;
- }
-
- public function getReadOnly($id) { // /api/rpc/board/forum/getreadonly/id
- return DB::table('for_forums')
- ->select('readonly')
- ->where('id', $id)
- ->first()->readonly;
- }
-
- public function getForumsInCategory($cat_id) { // /api/rpc/board/forum/getforumsincategory/cat_id
- $get = DB::table('for_forums')
- ->select('id', 'last_uid', 'cat_id', 'title', 'description', 'threads', 'posts', 'last_date')
- ->where('cat_id', $cat_id)
- ->orderBy('order', 'asc')
- ->get();
-
- $res = array();
- $key = 0;
-
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- foreach ($get as $i) {
- array_push($res, [
- 'key' => $key,
- 'id' => $i->id,
- 'last_uid' => $i->last_uid,
- 'cat_id' => $i->cat_id,
- 'title' => $i->title,
- 'description' => $i->description,
- 'threads' => $i->threads,
- 'posts' => $i->posts,
- 'last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->last_date)
- ]);
- $key++;
- }
-
- return $res;
- }
-
- public function getTopics($for, $from, $to) { // /api/rpc/board/topic/gettopics/for/from/to
- return DB::table('for_threads')
- ->select('*')
- ->where('for_id', $for)
- ->offset($from)
- ->limit($to)
- ->orderBy('last_date', 'desc')
- ->get();
- }
-
- public function getTopicsUnpinned($for, $from, $to) { // /api/rpc/board/topic/gettopicsunpinned/for/from/to
- return DB::table('for_threads')
- ->select('*')
- ->where('for_id', $for)
- ->where('sticky', 0)
- ->offset($from)
- ->limit($to)
- ->orderBy('last_date', 'desc')
- ->get();
- }
-
- public function getTopicsPinned($for, $from, $to) { // /api/rpc/board/topic/gettopicspinned/for/from/to
- return DB::table('for_threads')
- ->select('*')
- ->where('for_id', $for)
- ->where('sticky', 1)
- ->orderBy('last_date', 'desc')
- ->get();
- }
-
- public function getTopicsUser($user, $from, $to) { // /api/rpc/board/topic/gettopicsuser/user/from/to
- return DB::table('for_threads')
- ->select('*')
- ->where('started_by', $user)
- ->orderBy('last_date', 'desc')
- ->get();
- }
-
- public function getTopicStart($top_id) { // /api/rpc/board/post/gettopicstart/top_id
- $uid = DB::table('for_posts')
- ->where('top_id', $top_id)
- ->orderBy('post_date', 'asc')
- ->value('user_id');
-
- $pdt = DB::table('for_posts')
- ->where('top_id', $top_id)
- ->orderBy('post_date', 'asc')
- ->value('post_date');
-
- return array(
- 'uid' => $uid,
- 'date' => $pdt
- );
- }
-
- public function getLastPost($top_id) { // /api/rpc/board/post/getlastpost/top_id
- $uid = DB::table('for_posts')
- ->where('top_id', $top_id)
- ->orderBy('post_date', 'desc')
- ->value('user_id');
-
- $pdt = DB::table('for_posts')
- ->where('top_id', $top_id)
- ->orderBy('post_date', 'desc')
- ->value('post_date');
-
- return array(
- 'uid' => $uid,
- 'date' => $pdt
- );
- }
-
- public function getLastPostOfForum($for_id) {
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- $tid = DB::table('for_threads')
- ->join('for_posts', 'for_posts.top_id', 'for_threads.id')
- ->where('for_id', $for_id)
- ->orderBy('for_posts.post_date', 'desc')
- ->first(array(
- 'for_threads.id as tid',
- 'for_posts.user_id as uid',
- 'for_posts.post_date as date'
- ));
-
- return array(
- 'tid' => ($tid ? $tid->tid : 0),
- 'uid' => ($tid ? $tid->uid : 0),
- 'date' => ($tid ? strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $tid->date) : 'まだ')
- );
- }
-
- public function getFirstAndLastPosts($top_id) { // /api/rpc/board/post/getfirstandlastposts/top_id
- $first = $this->getTopicStart($top_id);
- $last = $this->getLastPost($top_id);
-
- return array(
- 'first' => $first,
- 'last' => $last
- );
- }
-
- public function countUnpinnedTopicsInForum($for_id) { // /api/rpc/board/topic/countunpinnedtopicsinforum/for_id
- return DB::table('for_threads')
- ->where('for_id', $for_id)
- ->where('sticky', 0)
- ->count();
- }
-
- public function getTopic($id, $from, $to) { // /api/rpc/board/topic/gettopic/id/from/to
- return DB::table('for_threads')
- ->select('*')
- ->where('id', $id)
- ->offset($from)
- ->limit($to)
- ->orderBy('last_date', 'desc')
- ->get();
- }
-
- public function getTopicLock($id) { // /api/rpc/board/topic/gettopiclock/id
- return DB::table('for_threads')
- ->select('lock')
- ->where('id', $id)
- ->get();
- }
-
- public function getTopicPin($id) { // /api/rpc/board/topic/gettopicpin/id
- return DB::table('for_threads')
- ->select('sticky')
- ->where('id', $id)
- ->get();
- }
-
- public function getTopicName($id) { // /api/rpc/board/topic/gettopicname/id
- return DB::table('for_threads')
- ->select('for_id', 'title')
- ->where('id', $id)
- ->get();
- }
-
- public function getPostsInTopic($top_id, $from, $to) { // /api/rpc/board/post/getpostsintopic/top_id/from/to
- return DB::table('for_posts')
- ->select('*')
- ->where('top_id', $top_id)
- ->offset($from)
- ->limit($to)
- ->orderBy('post_date', 'asc')
- ->get();
- }
-
- public function countPostsInTopic($top_id) { // /api/rpc/board/post/countpostsintopic/top_id
- return DB::table('for_posts')
- ->where('top_id', $top_id)
- ->count();
- }
-
- public function getPost($id) { // /api/rpc/board/post/getpost/id
- return DB::table('for_posts')
- ->select('*')
- ->where('id', $id)
- ->get();
- }
-
- public function getCurrentPostCount($user_id) { // /api/rpc/board/post/getcurrentpostcount/user_id
- return DB::table('for_posts')->where('user_id', $user_id)->max('postcount');
- }
-
- public function getNextPostCount($user_id) { // /api/rpc/board/post/getnextpostcount/user_id
- $get = DB::table('for_posts')->where('user_id', $user_id)->max('postcount');
- $get++;
-
- return $get;
- }
-
- public function getPostsofUser($user_id, $from, $to, Request $r) {
- $getting = array(
- 'for_posts.id',
- 'top_id',
- 'for_posts.user_id',
- 'post_date',
- 'message',
- 'delete',
- 'lastedit',
- 'ipaddress',
- 'delreason',
- 'nolayout',
- 'postcount',
- 'username',
- 'perm_id',
- 'total_posts',
- 'header',
- 'footer',
- 'member_title',
- 'gender',
- 'avatar',
- 'name_style',
- 'display_name',
- 'country'
- );
-
- // $valid = $this->objAuth->getPermissions($r->kero_token);
-
- return DB::table('for_posts')
- ->join('users', 'for_posts.user_id', '=', 'users.id')
- ->join('usr_details', 'usr_details.user_id', '=', 'for_posts.user_id')
- ->join('usr_profile', 'usr_profile.user_id', '=', 'for_posts.user_id')
- ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'for_posts.user_id')
- ->where('users.id', $user_id)
- ->offset($from)
- ->limit($to)
- ->orderBy('for_posts.post_date', 'asc')
- ->get($getting);
- }
-
- public function getUserPosts($top_id, $from, $to, Request $r) { // /api/rpc/board/post/getuserposts/top/from/to
- $getting = array(
- 'for_posts.id',
- 'top_id',
- 'for_posts.user_id',
- 'post_date',
- 'message',
- 'delete',
- 'lastedit',
- 'ipaddress',
- 'delreason',
- 'nolayout',
- 'post_style',
- 'postcount',
- 'username',
- 'perm_id',
- 'total_posts',
- 'header',
- 'footer',
- 'member_title',
- 'gender',
- 'avatar',
- 'name_style',
- 'display_name',
- 'country'
- );
-
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- return DB::table('for_posts')
- ->join('users', 'for_posts.user_id', '=', 'users.id')
- ->join('usr_details', 'usr_details.user_id', '=', 'for_posts.user_id')
- ->join('usr_profile', 'usr_profile.user_id', '=', 'for_posts.user_id')
- ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'for_posts.user_id')
- ->where('for_posts.top_id', $top_id)
- ->offset($from)
- ->limit($to)
- ->orderBy('for_posts.post_date', 'asc')
- ->get($getting);
- }
-
- public function getUserPost($id, Request $r) { // /api/rpc/board/post/getuserpost/id
- $getting = array(
- 'for_posts.id',
- 'top_id',
- 'for_posts.user_id',
- 'post_date',
- 'message',
- 'delete',
- 'lastedit',
- 'ipaddress',
- 'delreason',
- 'nolayout',
- 'post_style',
- 'postcount',
- 'username',
- 'perm_id',
- 'total_posts',
- 'header',
- 'footer',
- 'member_title',
- 'gender',
- 'avatar',
- 'name_style',
- 'display_name',
- 'country'
- );
-
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- return DB::table('for_posts')
- ->join('users', 'for_posts.user_id', '=', 'users.id')
- ->join('usr_details', 'usr_details.user_id', '=', 'for_posts.user_id')
- ->join('usr_profile', 'usr_profile.user_id', '=', 'for_posts.user_id')
- ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'for_posts.user_id')
- ->where('for_posts.id', $id)
- ->orderBy('for_posts.post_date', 'asc')
- ->get($getting);
- }
-
- public function addTopic(Request $r) { // /api/rpc/board/topic/add
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_post'] == 1) {
- $fpc = $this->getPostCountFreeze($r->for_id);
-
- if ($fpc === 0) {
- $next = $this->getNextPostCount($check);
- }
- else {
- $next = 0;
- }
- $addTopic = DB::table('for_threads')
- ->insertGetId([
- 'for_id' => $r->for_id,
- 'title' => $r->title,
- 'started_by' => $check,
- 'replies' => 0,
- 'views' => 0,
- 'last_date' => time(),
- 'last_uid' => $check,
- 'sticky' => 0,
- 'lock' => 0,
- 'poll' => 0,
- 'read' => '',
- 'lang_id' => 1
- ]);
-
- DB::table('for_posts')
- ->insert([
- 'top_id' => $addTopic,
- 'user_id' => $check,
- 'post_date' => time(),
- 'message' => $r->message,
- 'delete' => 0,
- 'lastedit' => 0,
- 'ipaddress' => $r->ipaddress,
- 'delreason' => '',
- 'nolayout' => $r->nolayout,
- 'postcount' => $next
- ]);
-
- return $addTopic;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function addPost(Request $r) { // /api/rpc/board/post/add
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_post'] == 1) {
- $fid = $this->getForumIdFromTopic($r->top_id);
- $fpc = $this->getPostCountFreeze($fid);
-
- if ($fpc === 0) {
- $next = $this->getNextPostCount($check);
- }
- else {
- $next = 0;
- }
- $add = DB::table('for_posts')
- ->insertGetId([
- 'top_id' => $r->top_id,
- 'user_id' => $check,
- 'post_date' => time(),
- 'message' => $r->message,
- 'delete' => 0,
- 'lastedit' => 0,
- 'ipaddress' => $r->ipaddress,
- 'delreason' => '',
- 'nolayout' => $r->nolayout,
- 'postcount' => $next
- ]);
-
- return $this->browseTopicPosts('p', $add, 0, 15, $r);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editPost(Request $r) { // /api/rpc/board/post/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_editother'] == 1 || $valid['for_editown'] == 1) { // TODO: differenciate own from other.
- return DB::table('for_posts')
- ->where('id', $r->id)
- ->update([
- 'lastedit' => time(),
- 'message' => $r->message,
- 'nolayout' => $r->nolayout
- ]);
- }
- }
- }
-
- public function deletePost(Request $r) { // /api/rpc/board/post/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_del'] == 1) {
- $s = db::table('for_posts')
- ->select('delete')
- ->where('id', $r->id)
- ->first()->delete;
-
- if ($s === 1) {
- $r->delreason = '';
- }
-
- DB::table('for_posts')
- ->where('id', $r->id)
- ->update([
- 'delete' => ($s == 0 ? 1 : 0),
- 'delreason' => $r->delreason
- ]);
-
- return array(
- 'delete' => ($s == 0 ? 1 : 0),
- 'delreason' => $r->delreason
- );
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function lockTopic(Request $r) { // /api/rpc/board/topic/lock
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_locky'] == 1) {
- $s = db::table('for_threads')
- ->select('lock')
- ->where('id', $r->id)
- ->first()->lock;
-
- DB::table('for_threads')
- ->where('id', $r->id)
- ->update([
- 'lock' => ($s == 0 ? 1 : 0)
- ]);
-
- return ($s == 0 ? 1 : 0);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function unlockTopic(Request $r) { // /api/rpc/board/topic/unlock
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_locky'] == 1) {
- return DB::table('for_threads')
- ->where('id', $r->id)
- ->update([
- 'lock' => 0
- ]);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function moveTopic(Request $r) { // /api/rpc/board/topic/move
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_move'] == 1) {
- $res = DB::table('for_threads')
- ->where('id', $r->id)
- ->update([
- 'for_id' => $r->new_id
- ]);
-
- $for = DB::table('for_forums')
- ->select('title', 'cat_id')
- ->where('id', $r->new_id)
- ->first();
-
- $cat = DB::table('for_category')
- ->select('title')
- ->where('id', $for->cat_id)
- ->first();
-
- return array([
- 'fid' => $r->new_id,
- 'ftit' => $for->title,
- 'cid' => $for->cat_id,
- 'ctit' => $cat->title
- ]);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function splitPost(Request $r) { // /api/rpc/board/post/split
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_split'] == 1) {
- $uid = DB::table('for_posts')
- ->select('user_id')
- ->where('id', $r->id)
- ->first();
-
- $add = DB::table('for_threads')
- ->insertGetId([
- 'for_id' => $r->forId,
- 'title' => $r->title,
- 'started_by' => $uid->user_id,
- 'replies' => 0,
- 'views' => 0,
- 'last_date' => 0,
- 'last_uid' => 0,
- 'sticky' => $r->sticky,
- 'poll' => 0,
- 'read' => '',
- 'lock' => $r->lock
- ]);
-
- DB::table('for_posts')
- ->where('id', $r->id)
- ->update([
- 'top_id' => $add,
- ]);
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function mergeTopic(Request $r) { // /api/rpc/board/topic/merge
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_mergepost'] == 1) {
- DB::table('for_posts')
- ->where('top_id', $r->id)
- ->update([
- 'top_id' => $r->alt_id
- ]);
-
- DB::table('for_threads')
- ->where('id', $r->id)
- ->delete();
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function pinTopic(Request $r) { // /api/rpc/board/topic/pin
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_sticky'] == 1) {
- $s = DB::table('for_threads')
- ->select('sticky')
- ->where('id', $r->id)
- ->first();
-
- DB::table('for_threads')
- ->where('id', $r->id)
- ->update([
- 'sticky' => ($s->sticky == 0 ? 1 : 0)
- ]);
-
- return ($s->sticky == 0 ? 1 : 0);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function unpinTopic(Request $r) { // /api/rpc/board/topic/unpin
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_sticky'] == 1) {
- return DB::table('for_threads')
- ->where('id', $r->id)
- ->update([
- 'sticky' => 0
- ]);
- }
- }
- }
-
- public function getReadCategories (Request $r) { // /api/rpc/board/topic/getreadcategories
- }
-
- public function getReadForums (Request $r) { // /api/rpc/board/topic/getreadforums
- }
-
- public function getReadTopics (Request $r) { // /api/rpc/board/topic/getreadtopics
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $i = 0;
- $getTopIdAll = DB::table('for_readposts')
- ->select('top_id', 'last_read')
- ->where('user_id', $check)
- ->get();
-
- $res = array();
-
- foreach($getTopIdAll as $t) {
- $res[] = array(
- 'key' => $i,
- 'uid' => $check,
- 'tid' => $t->top_id,
- 'read' => $t->last_read
- );
-
- $i++;
- }
-
- return $res;
- }
- }
-
- public function markForumRead ($id, Request $r) { // /api/rpc/board/topic/markforumread/fid
- }
-
- public function markTopicRead ($id, Request $r) { // /api/rpc/board/topic/marktopicread/tid
- }
-
- public function undeletePost(Request $r) { // /api/rpc/board/post/undelete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['for_del'] == 1) {
- return DB::table('for_posts')
- ->where('id', $r->id)
- ->update([
- 'delete' => 0,
- 'delreason' => ''
- ]);
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function countPostsInForum($id) {
- return DB::table('for_threads')
- ->join('for_posts', 'for_posts.top_id', 'for_threads.id')
- ->where('for_threads.for_id', $id)
- ->count();
- }
-
- public function browseCategories(Request $r) { // /api/rpc/board/browse/browsecategories
- $cats = $this->getCategories()->toArray();
- $cols = $this->objUser->getGroupColours()->toArray();
-
- $res = array();
- $resC = array();
-
- foreach($cats as $c) {
- $cid = $c->id;
- $ctitle = $c->title;
- $fors = $this->getForumsInCategory($cid);
- $resF = array();
-
- foreach($fors as $f) {
- $read = $this->checkRead($f['id'], 0, $r->kero_token);
- $ldet = $this->getLastPostOfForum($f['id']);
- $topicsuu = DB::table('for_threads')->where('for_id', $f['id'])->count();
- $replysuu = $this->countPostsInForum($f['id']);
-
- if ($ldet['uid'] != 0) {
- $user = $this->objUser->getUser($ldet['uid'], $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- // Compile.
- $resF[] = array(
- 'c_id' => $c->id,
- 'c_name' => $c->title,
- 'f_id' => $f['id'],
- 'u_name' => $showName,
- 'u_col' => $showCol,
- 'f_cat' => $f['cat_id'],
- 'f_last_uid' => $ldet['uid'],
- 'f_name' => $f['title'],
- 'f_desc' => $f['description'],
- 'f_topics' => $topicsuu,
- 'f_posts' => $replysuu,
- 'f_last' => $ldet['date'],
- 'f_read' => $read
- );
- }
-
- $res[] = array(
- 'cats' => array(
- 'id' => $c->id,
- 'name' => $c->title
- ),
- 'fors' => $resF
- );
- }
-
- return $res;
- }
-
- public function browseForums($id, $from, $to, Request $r) { // /api/rpc/board/browse/browseforums/id/from/to
- $fors = $this->getForums($id);
- $cols = $this->objUser->getGroupColours()->toArray();
-
- $res = array();
-
- foreach($fors as $f) {
- $read = $this->checkRead($f['id'], 0, $r->kero_token);
- $ldet = $this->getLastPostOfForum($f['id']);
- $topicsuu = DB::table('for_threads')->where('for_id', $f['id'])->count();
- $replysuu = $this->countPostsInForum($f['id']);
-
- if ($f['last_uid'] != 0) {
- $user = $this->objUser->getUser($ldet['uid'], $r)->toArray();
-
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $catname = $this->getCategoryName($id);
-
- // Compile.
- $res[] = array(
- 'f_id' => $f['id'],
- 'f_last_uid' => $ldet['uid'],
- 'f_cat' => $f['cat_id'],
- 'f_name' => $f['title'],
- 'f_desc' => $f['description'],
- 'f_topics' => $topicsuu,
- 'f_posts' => $replysuu,
- 'f_last' => $ldet['date'],
- 'f_read' => $read,
- 'c_name' => $catname[0]->title,
- 'u_name' => $showName,
- 'u_col' => $showCol
- );
- }
-
- return $res;
- }
-
- public function browseForumInfo($id, $to) { // /api/rpc/board/browse/browseforuminfo/id/to
- $finfo = $this->getForum($id);
-
- return array(
- 'ftit' => $finfo[0]->title,
- 'ro' => $finfo[0]->readonly,
- 'pcf' => $finfo[0]->post_count_freeze
- );
- }
-
- public function browseTopics($mode, $id, $from, $to, Request $r) { // /api/rpc/board/browse/browsetopicsmode/id/from/to
- $topsUP = $this->getTopicsUnpinned($id, $from, $to);
- $topsPN = $this->getTopicsPinned($id, $from, $to);
- $topsUS = $this->getTopicsUser($id, $from, $to);
- $cols = $this->objUser->getGroupColours()->toArray();
-
- $tops = null;
-
- if ($mode === 'unpinned') {
- $tops = $topsUP;
- }
- else if ($mode === 'pinned') {
- $tops = $topsPN;
- }
- else if ($mode === 'user') {
- $tops = $topsUS;
- }
- else {
- return array(
- 'error' => 'Invalid mode.'
- );
- }
-
- $res = array();
- $i = 0;
-
- foreach($tops as $t) {
- $read = $this->checkRead(0, $t->id, $r->kero_token);
- $replysuu = DB::table('for_posts')->where('top_id', $t->id)->count();
-
- $fplp = $this->getFirstAndLastPosts($t->id);
- $userFD = $fplp['first']['date'];
- $userLD = $fplp['last']['date'];
- $userFirst = $this->objUser->getUser($fplp['first']['uid'], $r)->toArray();
- $userLast = $this->objUser->getUser($fplp['last']['uid'], $r)->toArray();
- $showNameF = "";
- $showColF = "";
- $showNameL = "";
- $showColL = "";
-
- if ($userFirst[0]->display_name !== '') {
- $showNameF = $userFirst[0]->display_name;
- }
- else {
- $showNameF = $userFirst[0]->username;
- }
-
- if ($userFirst[0]->name_style !== '') {
- $showColF = $userFirst[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $userFirst[0]->perm_id) {
- if ($userFirst[0]->gender === 1) $showColF = $cl->colour_m;
- else if ($userFirst[0]->gender === 2) $showColF = $cl->colour_f;
- else $showColF = $cl->colour_u;
- }
- }
- }
-
- if ($userLast[0]->display_name !== '') {
- $showNameL = $userLast[0]->display_name;
- }
- else {
- $showNameL = $userLast[0]->username;
- }
-
- if ($userLast[0]->name_style !== '') {
- $showColL = $userLast[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $userLast[0]->perm_id) {
- if ($userLast[0]->gender === 1) $showColL = $cl->colour_m;
- else if ($userLast[0]->gender === 2) $showColL = $cl->colour_f;
- else $showColL = $cl->colour_u;
- }
- }
- }
-
- setlocale(LC_ALL, 'ja_JP.utf8');
- $catname = $this->getCategoryName($id);
-
- // Compile.
- $res[] = array(
- 'key' => $i,
- 't_id' => $t->id,
- 't_for_id' => $t->for_id,
- 't_title' => $t->title,
- 't_replies' => $replysuu,
- 't_views' => $t->views,
- 't_first_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $userFD),
- 't_last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $userLD),
- 't_sticky' => $t->sticky,
- 't_lock' => $t->lock,
- 't_poll' => $t->poll,
- 't_read' => $read,
- 't_lang_id' => $t->lang_id,
- 'u_first_uid' => $t->started_by,
- 'u_last_uid' => $t->last_uid,
- 'u_first_name' => $showNameF,
- 'u_last_name' => $showNameL,
- 'u_first_col' => $showColF,
- 'u_last_col' => $showColL
- );
-
- $i++;
- }
-
- return $res;
- }
-
- public function browseTopicInfo($tp, $id, $to) { // /api/rpc/board/browse/browsetopicinfo/tp/id/to
- if ($tp == 'p') {
- // Get information for the navigation.
- $tid = $this->getTopicIdFromPost($id);
- $tinfo = $this->getTopicName($tid);
- }
- else {
- // Get information for the navigation.
- $tinfo = $this->getTopicName($id);
- }
-
- $finfo = $this->getForumName($tinfo[0]->for_id);
- $cinfo = $this->getCategoryName($finfo[0]->cat_id);
-
- // Count posts for navigation.
- if ($tp == 't') $pcount = $this->countPostsInTopic($id);
-
- // Is this topic locked?
- if ($tp == 't') $tlock = $this->getTopicLock($id);
- else $tlock = $this->getTopicLock($tid);
- $glock = false;
- if ($tlock[0]->lock == 1) $glock = true;
-
- // Is this topic read only?
- $fro = $this->getReadOnly($tinfo[0]->for_id);
- $gro = false;
- if ($fro == 1) $gro = true;
-
- // Is this topic pinned?
- if ($tp == 't') $tpin = $this->getTopicPin($id);
- else $tpin = $this->getTopicPin($tid);
- $gpin = false;
- if ($tpin[0]->sticky == 1) $gpin = true;
-
- if ($tp == 'p') {
- // Compile.
- return array(
- 'topId' => $tid,
- 'forId' => $tinfo[0]->for_id,
- 'topName' => $tinfo[0]->title,
- 'catId' => $finfo[0]->cat_id,
- 'forName' => $finfo[0]->title,
- 'catName' => $cinfo[0]->title,
- 'lock' => $glock,
- 'pin' => $gpin,
- 'ro' => $gro
- );
- }
- else {
- // Compile.
- return array(
- 'forId' => $tinfo[0]->for_id,
- 'topName' => $tinfo[0]->title,
- 'catId' => $finfo[0]->cat_id,
- 'forName' => $finfo[0]->title,
- 'catName' => $cinfo[0]->title,
- 'maxPage' => ceil($pcount / $to),
- 'posts' => $pcount,
- 'lock' => $glock,
- 'pin' => $gpin,
- 'ro' => $gro
- );
- }
- }
-
- public function stripBR($string) {
- return preg_replace('/\
/i', '', $string);
- }
-
- public function autoLink($s) {
- if (strpos($s, '[link=') !== false || strpos($s, '[/link]') !== false) {
- return $s;
- }
- else if (strpos($s, '') !== false) {
- return $s;
- }
- else if (strpos($s, '[img]') !== false || strpos($s, '[/img]') !== false) {
- return $s;
- }
- else {
- return preg_replace('!(\s|^)((https?://|www\.)+[a-z0-9_%./#?=;&-]+)!i', ' $2 ',$s);
- }
- }
-
- function getSmilies() {
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
- $domain = $protocol.'://'.$_SERVER['SERVER_NAME'];
- $kusa = '/assets/smileys/';
-
- $get = DB::table('for_smileys')
- ->select('text', 'image')
- ->get();
-
- $res = array();
-
- foreach ($get as $g) {
- $res[] = array(
- 'val' => $g->text,
- 'url' => $domain.$kusa.$g->image
- );
- }
-
- return $res;
- }
-
- function getSmile($text) {
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
- $domain = $protocol.'://'.$_SERVER['SERVER_NAME'];
- $kusa = '/assets/smileys/';
-
- $get = DB::table('for_smileys')
- ->select('text', 'image')
- ->get();
-
- foreach ($get as $g) {
- $text = str_replace( $g->text, "", $text);
- }
-
- return $text;
- }
-
- function getBBCode($text) {
- $find = array(
- '~\[b\](.*?)\[/b\]~s',
- '~\[i\](.*?)\[/i\]~s',
- '~\[u\](.*?)\[/u\]~s',
- '~\[s\](.*?)\[/s\]~s',
- '~\[o\](.*?)\[/o\]~s',
- '~\[centre\](.*?)\[/centre\]~s',
- '~\[img width=(.*?) height=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
- '~\[img height=(.*?) width=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
- '~\[img width=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
- '~\[img height=(.*?)\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
- '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]~s',
- '~\[yt\](.*?)\[/yt\]~s',
- '~\[link=((?:ftp|https?)://.*?)\](.*?)\[/link\]~s',
- '~\[sound\](https?://.*?\.(?:mp3))\[/sound\]~s',
- '~\[size=(.*?)\](.*?)\[/size\]~s',
- '~\[colour=(.*?)\](.*?)\[/colour\]~s',
- '~\[quote="(.*?)" id="(.*?)"](.*?)\[/quote]~s',
- '~\[quote="(.*?)"](.*?)\[/quote]~s',
- '~\[quote](.*?)\[/quote]~s',
- '~\[code](.*?)\[/code]~s',
- '~\[spoiler=(.*?)](.*?)\[/spoiler]~s',
- '~\[spoiler](.*?)\[/spoiler]~s',
- '~\[rtl](.*?)\[/rtl]~s',
- '~\[gcn](.*?)\[/gcn]~s',
- '~\[miiverse](.*?)\[/miiverse]~s',
- '~\[smb](.*?)\[/smb]~s',
- '~\[video](.*?)\[/video]~s',
- '~\[nico](.*?)\[/nico]~s',
- );
-
- $replace = array(
- '$1',
- '$1',
- '$1',
- '$1',
- '$1',
- '$1',
- '',
- '',
- '',
- '',
- '',
- '
',
- '$2',
- '',
- '$2',
- '$2',
- 'Posted by \'$1\'
$3
',
- 'Posted by \'$1\'
$2
',
- '
$1
',
- '
',
- '',
- '',
- '$1
',
- '$1',
- '$1',
- '$1',
- '',
- '',
- );
-
- return preg_replace($find, $replace, $text);
- }
-
- public function packageMessage($string) {
- $string = $this->stripBR($string);
- $string = $this->autoLink($string);
- $string = $this->getBBCode($string);
- $string = $this->getSmile($string);
-
- return $string;
- }
-
- public function browseTopicPosts($tp, $id, $from, $to, Request $r) { // /api/rpc/board/browse/browsetopicposts/tp/id/from/to
- // Load group colours.
- $ucol = $this->objUser->getGroupColours();
-
- // All the user posts' user IDs.
- if ($tp == 't') $uid = $this->getUserPosts($id, $from, $to, $r);
- else if ($tp == 'p') $uid = $this->getUserPost($id, $r);
- else $uid = $this->getPostsOfUser($id, $from, $to, $r);
- $udat = array();
- $key = 0;
- $ldate = 0;
-
- foreach ($uid as $i) {
- $showName = '';
- $showCol = '';
- $showGroupName = '';
-
- // Display name or username?
- if (!empty($i->display_name)) {
- $showName = $i->display_name;
- }
- else {
- $showName = $i->username;
- }
-
- // Custom name styling or default?
- 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;
- }
- }
- }
-
- // Group names.
- $gname = $this->objUser->getGroupName($i->user_id);
- $showGroupName = $gname[0]->name;
-
- $mess = $this->packageMessage($i->message);
-
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- array_push($udat, [
- 'key' => $key,
- 'id' => $i->id,
- 'tid' => $i->top_id,
- 'uid' => $i->user_id,
- 'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date),
- 'message' => ($i->post_style ? '' : '').$mess,
- 'delete' => $i->delete,
- 'delreason' => $i->delreason,
- 'lastedit' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->lastedit),
- 'lasteditUnix' => $i->lastedit,
- 'ipaddress' => $i->ipaddress,
- 'nolayout' => $i->nolayout,
- 'postcount' => $i->postcount,
- 'total_posts' => $i->total_posts,
- 'header' => $i->header,
- 'footer' => $i->footer,
- 'member_title' => $i->member_title,
- 'gender' => $i->gender,
- 'avatar' => ($i->avatar ? $i->avatar : '/img/noicon.webp'),
- 'showcol' => $showCol,
- 'showname' => $showName,
- 'showgroup' => $showGroupName,
- 'country' => $i->country,
- ]);
-
- $ldate = $i->post_date;
- $key++;
- }
-
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($tp == 't' && $check != 0) {
- $view = DB::table('for_threads')
- ->select('views')
- ->where('id', $id)
- ->first();
-
- DB::table('for_threads')
- ->where('id', $id)
- ->update(['views' => $view->views+1]);
-
- $checkTime = DB::table('for_read')
- ->select('view_time')
- ->where('user_id', $check)
- ->where('top_id', $id)
- ->first();
-
- if (empty($checkTime)) {
- DB::table('for_read')
- ->insert([
- 'user_id' => $check,
- 'top_id' => $id,
- 'view_time' => $ldate
- ]);
- }
- else if ($ldate > $checkTime->view_time) {
- DB::table('for_read')
- ->where('user_id', $check)
- ->where('top_id', $id)
- ->update(['view_time' => $ldate]);
- }
- }
-
- // Assign group names.
- return $udat;
- }
-
- public function browsePermissions($uid, Request $r) { // /api/rpc/board/browse/browsepermissions/uid
- // Get user ID.
- $perm = $this->objUser->getUser($uid, $r);
-
- // Does the user ID exist? Grand the appropriate rights. Otherwise, use guest.
- if ($uid != 0) {
- // Forum permissions.
- $grouppermfor = $this->objPermission->getPermissionGroup('for', $perm[0]->perm_id);
- $userpermfor = $this->objPermission->getPermissionUser('for', $uid);
-
- // User permissions.
- $grouppermusr = $this->objPermission->getPermissionGroup('usr', $perm[0]->perm_id);
- $userpermusr = $this->objPermission->getPermissionUser('usr', $uid);
-
- // Now provide an array of user overwritten permissions if it exists. Otherwise, give its group permissions.
- $forarr = array();
- $usrarr = array();
-
- if (!empty($userpermfor[0])) {
- $forarr = (array)$userpermfor[0];
- }
- else {
- $forarr = (array)$grouppermfor[0];
- }
-
- if (!empty($userpermusr[0])) {
- $usrarr = (array)$userpermusr[0];
- }
- else {
- $usrarr = (array)$grouppermusr[0];
- }
-
- $merge = array();
- $merge = array_merge($forarr, $usrarr);
-
- return $merge;
- }
- else {
- // Forum permissions.
- $grouppermfor = $this->objPermission->getPermissionGroup('for', 6);
-
- // User permissions.
- $grouppermusr = $this->objPermission->getPermissionGroup('usr', 6);
-
- // Since guests don't have user overwritten permissions, simply return the group permissions.
- $merge = array();
- $merge = array_merge((array)$grouppermfor[0], (array)$grouppermusr[0]);
-
- return $merge;
- }
- }
-}
diff --git a/app/Http/Controllers/Home/Comment.php b/app/Http/Controllers/Home/Comment.php
new file mode 100644
index 0000000..08698eb
--- /dev/null
+++ b/app/Http/Controllers/Home/Comment.php
@@ -0,0 +1,46 @@
+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);
+ }
+}
diff --git a/app/Http/Controllers/Home/Content.php b/app/Http/Controllers/Home/Content.php
new file mode 100644
index 0000000..593d0ce
--- /dev/null
+++ b/app/Http/Controllers/Home/Content.php
@@ -0,0 +1,187 @@
+valid = $v;
+ $this->menu = $m;
+ $this->user = $u;
+ }
+
+ public function add (Request $r) {
+ if ($this->user && ($this->user->perm['blg_addpost'] || $this->user->perm['blg_addpage'])) {
+ $err = '';
+ $res = '';
+ $frm = array(
+ 'user_id' => $this->user->id,
+ 'title' => '',
+ 'slug' => '',
+ 'public_status' => 0,
+ 'publish_date' => null,
+ 'isMenu' => null,
+ 'isPost' => 1,
+ 'message' => ''
+ );
+
+ if (isset($r->submit)) {
+ // JS→HTML→PHPの修正
+ $sav = $r->publish_date;
+ if (is_null($r->public_status)) $r->public_status = 0;
+ $r->public_status = (int)$r->public_status;
+ if (is_null($r->isPost)) $r->isPost = 0;
+ $r->isPost = (int)$r->isPost;
+
+ if ($r->public_status == 1 && !is_null($r->publish_date)) {
+ $r->publish_date = str_replace('年', '-', $r->publish_date);
+ $r->publish_date = str_replace('月', '-', $r->publish_date);
+ $r->publish_date = str_replace('日', '', $r->publish_date);
+ $r->publish_date = strtotime($r->publish_date);
+ }
+ else if ($r->public_status == 1 && is_null($r->publish_date)) $r->public_status = 0;
+ else if ($r->public_status != 1 && is_null($r->publish_date)) $r->publish_date = time();
+ if (is_null($r->isMenu)) $r->isMenu = false;
+ if ($r->isMenu == 'on') $r->isMenu = true;
+ else $r->isMenu = false;
+ $r->isMenu = (int)$r->isMenu;
+
+ // フォームの値を保存して
+ $frm['title'] = $r->title;
+ $frm['slug'] = $r->slug;
+ $frm['public_status'] = $r->public_status;
+ $frm['publish_date'] = $r->publish_date;
+ $frm['isMenu'] = $r->isMenu;
+ $frm['isPost'] = $r->isPost;
+ $frm['message'] = $r->message;
+
+ // 件名、文章又はスラッグがなければ、エラーを出て
+ $verify = array('件名' => $r->title, 'スラッグ' => $r->slug, '文章' => $r->message);
+ $incomplete = array();
+ foreach ($verify as $k => $v) { if (is_null($v) || empty($v) || !isset($v)) $incomplete[] = $k; }
+ if (count($incomplete) > 0) $err = implode('、', $incomplete).'をご入力下さい。';
+
+ // スラッグが既に存在したら、エラーを出て
+ $sl = DB::table('blg_content')->select('slug')->where('slug', $r->slug)->first();
+ if ($sl && $sl->slug == $r->slug) $err = 'このスラッグがもう存在しています。';
+
+ // エラーがあったら、フォームに戻って。なければ、データベースに保存したり、ページ又はポストへ移転して
+ if (!empty($err)) return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $frm]);
+ else {
+ // データベースに追加できるには、値を修正して
+ $gs = DB::table('blg_content')->select('sortorder')->orderBy('sortorder', 'desc')->first();
+ if (!isset($r->publish_date)) $frm['publish_date'] = ($r->isPost == 1 ? time() : 0);
+ if (!isset($r->public_status)) $frm['public_status'] = 0;
+ if (!isset($r->isPost)) $frm['isPost'] = 0;
+ if (!isset($r->isMenu)) $frm['isMenu'] = 0;
+ $frm['post_date'] = ($r->isPost == 1 ? time() : 0);
+ $frm['sortorder'] = ($r->isPost == 0 ? $gs->sortorder+1 : 0);
+
+ // できたの?
+ if ($res = $this->objSite->addContent($frm)) return redirect(($r->isPost == 1 ? '/blog/' : '/').$r->slug);
+ else {
+ // やれやれ…
+ $frm['publish_date'] = $sav;
+ unset($frm['post_date']);
+ unset($frm['sortorder']);
+ return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $res['err']]);
+ }
+ }
+ }
+
+ return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $frm]);
+ }
+
+ return redirect('');
+ }
+
+ public function delete (Request $r) {
+ if (($this->valid['blg_delpost'] && $bdl['isPost'] == 1) || ($this->valid['blg_delpage'] && $bdl['isPost'] == 0)) {
+ return DB::table('blg_content')->where('slug', $r->slug)->delete();
+ }
+
+ return 0;
+ }
+
+ public function edit (Request $r) {
+ if ($this->user && ($this->user->perm['blg_editpost'] || $this->user->perm['blg_editpage'])) {
+ $frm = DB::table('blg_content')->where('slug', $r->slug)->first();////////////////////
+ $err = '';
+ $res = '';
+
+ if (isset($r->submit)) {
+ // JS→HTML→PHPの修正
+ $sav = $r->publish_date;
+ if (is_null($r->public_status)) $r->public_status = 0;
+ $r->public_status = (int)$r->public_status;
+ if (is_null($r->isPost)) $r->isPost = 0;
+ $r->isPost = (int)$r->isPost;
+
+ if ($r->public_status == 1 && !is_null($r->publish_date)) {
+ $r->publish_date = str_replace('年', '-', $r->publish_date);
+ $r->publish_date = str_replace('月', '-', $r->publish_date);
+ $r->publish_date = str_replace('日', '', $r->publish_date);
+ $r->publish_date = strtotime($r->publish_date);
+ }
+ else if ($r->public_status == 1 && is_null($r->publish_date)) $r->public_status = 0;
+ else if ($r->public_status != 1 && is_null($r->publish_date)) $r->publish_date = time();
+ if (is_null($r->isMenu)) $r->isMenu = false;
+ if ($r->isMenu == 'on') $r->isMenu = true;
+ else $r->isMenu = false;
+ $r->isMenu = (int)$r->isMenu;
+
+ // フォームの値を保存して
+ $frm['title'] = $r->title;
+ $frm['slug'] = $r->slug;
+ $frm['public_status'] = $r->public_status;
+ $frm['publish_date'] = $r->publish_date;
+ $frm['isMenu'] = $r->isMenu;
+ $frm['isPost'] = $r->isPost;
+ $frm['message'] = $r->message;
+
+ // 件名、文章又はスラッグがなければ、エラーを出て
+ $verify = array('件名' => $r->title, 'スラッグ' => $r->slug, '文章' => $r->message);
+ $incomplete = array();
+ foreach ($verify as $k => $v) { if (is_null($v) || empty($v) || !isset($v)) $incomplete[] = $k; }
+ if (count($incomplete) > 0) $err = implode('、', $incomplete).'をご入力下さい。';
+
+ // スラッグが既に存在したら、エラーを出て
+ $sl = DB::table('blg_content')->select('slug')->where('slug', $r->slug)->first();
+ if ($sl && $sl->slug == $r->slug) $err = 'このスラッグがもう存在しています。';
+
+ // エラーがあったら、フォームに戻って。なければ、データベースに保存したり、ページ又はポストへ移転して
+ if (!empty($err)) return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $frm]);
+ else {
+ // データベースに追加できるには、値を修正して
+ $gs = DB::table('blg_content')->select('sortorder')->orderBy('sortorder', 'desc')->first();
+ if (!isset($r->publish_date)) $frm['publish_date'] = ($r->isPost == 1 ? time() : 0);
+ if (!isset($r->public_status)) $frm['public_status'] = 0;
+ if (!isset($r->isPost)) $frm['isPost'] = 0;
+ if (!isset($r->isMenu)) $frm['isMenu'] = 0;
+ $frm['post_date'] = ($r->isPost == 1 ? time() : 0);
+ $frm['sortorder'] = ($r->isPost == 0 ? $gs->sortorder+1 : 0);
+
+ // できたの?
+ if ($res = $this->objSite->addContent($frm)) return redirect(($r->isPost == 1 ? '/blog/' : '/').$r->slug);
+ else {
+ // やれやれ…
+ $frm['publish_date'] = $sav;
+ unset($frm['post_date']);
+ unset($frm['sortorder']);
+ return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $res['err']]);
+ }
+ }
+ }
+
+ return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err, 'frm' => $frm]);
+ }
+
+ return redirect('');
+ }
+}
diff --git a/app/Http/Controllers/Home/Index.php b/app/Http/Controllers/Home/Index.php
new file mode 100644
index 0000000..28ea46f
--- /dev/null
+++ b/app/Http/Controllers/Home/Index.php
@@ -0,0 +1,102 @@
+objUser = new UserController();
+ $this->valid = $v;
+ $this->menu = $m;
+ $this->user = $u;
+ }
+
+ 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' => $this->menu, 'user' => $this->user]);
+ }
+
+ public function page ($slug) {
+ $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();
+
+ if (!$res) return notfound($this->menu, $this->user, $res);
+ return view('pages.site.page', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+
+ public function post ($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);
+
+ if (!$get) return notfound($this->menu, $this->user, $get);
+ return view('pages.site.post', ['res' => $get, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+}
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 4ec22d8..22d0cc9 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -1,64 +1,65 @@
objAuth = new AuthController();
- $this->objSite = new SiteController();
$this->objUser = new UserController();
+ $this->valid = $this->objAuth->getPermissions((isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : ''));
$this->menu = getPagesInMenu();
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
- $this->id = $this->objAuth->checkLegit($this->cook);
+ $this->id = checkLegit($this->cook);
$this->user = $this->objUser->getLoggedUser($this->id, $this->cook);
}
+ public function index () {
+ $r = new Index($this->valid, $this->menu, $this->user);
+ return $r->index();
+ }
+
public function post ($slug) {
- $res = $this->objSite->getPost($slug, $this->cook);
- if (!$res) return view('pages.site.notfound', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
- return view('pages.site.post', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ $r = new Index($this->valid, $this->menu, $this->user);
+ return $r->post($slug, $this->cook);
}
public function page ($slug) {
- $res = $this->objSite->getPage($slug, $this->cook);
- if (!$res) return view('pages.site.notfound', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
- return view('pages.site.page', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ $r = new Index($this->valid, $this->menu, $this->user);
+ return $r->page($slug);
}
- public function addContent (Request $r) {
- if ($this->user && ($this->user['blg_addpost'] || $this->user['blg_addpage'])) {
- $bdl = array();
- $res = $this->objSite->addContent($bdl);
-
- if ($res) {
- return redirect('/blog/'.$r->slug);
- }
-
- $err = $res['err'];
- return view('pages.site.contentadd', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err]);
- }
-
- return redirect('');
+ public function newComment (Request $rr) {
+ $r = new Comment();
+ return $r->add($rr);
}
- public function notfound () {
- return view('pages.site.notfound', ['menu' => $this->menu, 'user', $this->user]);
+ public function addContent ($bdl) {
+ $r = new Content($this->valid, $this->menu, $this->user);
+ return $r->add($bdl);
+ }
+
+ public function editContent ($bdl) {
+ $r = new Content($this->valid, $this->menu, $this->user);
+ return $r->edit($bdl);
+ }
+
+ public function delContent ($bdl) {
+ $r = new Content($this->valid, $this->menu, $this->user);
+ return $r->delete($bdl);
}
}
diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php
deleted file mode 100644
index 63a55eb..0000000
--- a/app/Http/Controllers/ImageController.php
+++ /dev/null
@@ -1,450 +0,0 @@
-objAuth = new AuthController();
- $this->objUser = new UserController();
- }
-
- public function getUserWithUploads(Request $r) { // /api/rpc/image/get/userwithuploads
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $cols = $this->objUser->getGroupColours()->toArray();
- $imgs = File::directories('storage/assets/images');
-
- $res = array();
-
- foreach($imgs as $img) {
- $usr = basename($img);
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if ($usr != 0) {
- $user = $this->objUser->getUser($usr, $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $res[] = array(
- 'id' => basename($img),
- 'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : '/img/noicon.webp'),
- 'userCol' => $showCol,
- 'userName' => $showName
- );
- }
-
- return $res;
- }
- }
-
- public function getAll(Request $r) { // /api/rpc/image/get/all
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $cols = $this->objUser->getGroupColours()->toArray();
- $imgs = File::files('storage/assets/images/*');
-
- $res = array();
-
- foreach ($imgs as $img) {
- $usr = preg_split("#/#", $img->getPathname());
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if ($usr[3] != 0) {
- $user = $this->objUser->getUser($usr[3], $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $res[] = array(
- 'id' => $usr[3],
- 'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : '/img/noicon.webp'),
- 'name' => $img->getFilename(),
- 'userCol' => $showCol,
- 'userName' => $showName,
- 'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
- );
- }
-
- return $res;
- }
- }
-
- public function getOwn(Request $r) { // /api/rpc/image/get/own
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $cols = $this->objUser->getGroupColours()->toArray();
- $imgs = File::files('storage/assets/images/'.$check);
-
- $res = array();
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- foreach ($imgs as $img) {
- $usr = preg_split("#/#", $img->getPathname());
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if ($usr[3] == $check) {
- $user = $this->objUser->getUser($usr[3], $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $res[] = array(
- 'id' => $usr[3],
- 'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : '/img/noicon.webp'),
- 'name' => $img->getFilename(),
- 'userCol' => $showCol,
- 'userName' => $showName,
- 'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
- );
- }
- }
-
- return $res;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getUser($id, Request $r) { // /api/rpc/image/get/user/id
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $cols = $this->objUser->getGroupColours()->toArray();
- $imgs = File::files('storage/assets/images/'.$id);
-
- $res = array();
-
- foreach ($imgs as $img) {
- $usr = preg_split("#/#", $img->getPathname());
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if ($usr[3] != 0) {
- $user = $this->objUser->getUser($usr[3], $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $res[] = array(
- 'id' => $id,
- 'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : '/img/noicon.webp'),
- 'name' => $img->getFilename(),
- 'userCol' => $showCol,
- 'userName' => $showName,
- 'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
- );
- }
-
- return $res;
- }
- }
-
- public function getOther(Request $r) { // /api/rpc/image/get/other
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $cols = $this->objUser->getGroupColours()->toArray();
- $dirs = File::directories('storage/assets/images');
-
- $res = array();
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- foreach ($dirs as $dir) {
- $usr = 0;
-
- if (basename($dir) != $check) {
- $usr = basename($dir);
- $imgs = File::files('assets/images/'.$usr);
-
- foreach ($imgs as $img) {
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if ($usr != $check) {
- $user = $this->objUser->getUser($usr, $r)->toArray();
- $showName = "";
- $showCol = "";
-
- if ($user[0]->display_name !== '') {
- $showName = $user[0]->display_name;
- }
- else {
- $showName = $user[0]->username;
- }
-
- if ($user[0]->name_style !== '') {
- $showCol = $user[0]->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $user[0]->perm_id) {
- if ($user[0]->gender === 1) $showCol = $cl->colour_m;
- else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
- }
- else {
- $showName = "";
- $showCol = "";
- }
-
- $res[] = array(
- 'id' => $usr,
- 'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : '/img/noicon.webp'),
- 'name' => $img->getFilename(),
- 'userCol' => $showCol,
- 'userName' => $showName,
- 'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
- );
- }
- }
- }
- }
-
- return $res;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function viewImage(Request $r) { // /api/rpc/image/view
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_viewimg'] == 1) {
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- if (!isset($r->id) || !isset($r->name)) {
- return 'Err!';
- }
-
- return $protocol.'://'.$_SERVER['SERVER_NAME'].'/assets/images/'.$r->id.'/'.$r->name;
- }
- else {
- return 'Permission denied.';
- }
- }
-
- public function uploadImage(Request $r) { // /api/rpc/image/upload
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_addimg'] == 1) {
- if (isset($r->filename)) {
- if (!is_dir("assets/images/".$check)) {
- if (!mkdir("assets/images/".$check, 0755, true)) {
- return "Could not make folder ".$check."
";
- }
- }
-
- $img_dir = "assets/images/".$check."/";
- $image = $img_dir . $r->filename;
- $imageFileType = array(
- 'image/png',
- 'image/jpeg',
- 'image/gif'
- );
-
- if (!in_array($r->filetype, $imageFileType)) {
- return "Only JPG, PNG, JPEG, and GIF are allowed.";
- }
-
- $fname = 'assets/images/'.$check.'/'.$r->filename;
- $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $r->thefile));
- Storage::disk('public')->put($fname, $data);
-
- return $r->filename;
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- function is_dir_empty($dir) {
- if (!is_readable($dir)) return NULL;
- return (count(scandir($dir)) == 2);
- }
-
- public function removeImage(Request $r) { // /api/rpc/image/remove
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['img_delotherimg'] == 1) {
- if (isset($r->name)) {
- $fname = 'assets/images/'.$r->id.'/'.$r->name;
- unlink('storage/'.$fname);
- if ($this->is_dir_empty('storage/assets/images/'.$r->id)) rmdir('storage/assets/images/'.$r->id);
-
- return 'Deleted';
- }
- }
- else {
- if (isset($r->name)) {
- if ($check == $r->id) {
- if ($valid['img_delownimg'] == 1) {
- $fname = 'assets/images/'.$check.'/'.$r->name;
- unlink('storage/'.$fname);
- if ($this->is_dir_empty('storage/assets/images/'.$check)) rmdir('storage/assets/images/'.$check);
-
- return 'Deleted';
- }
- else {
- return 'Permission denied.';
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
- }
- }
-}
diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php
deleted file mode 100644
index b4fd69f..0000000
--- a/app/Http/Controllers/InvoiceController.php
+++ /dev/null
@@ -1,1989 +0,0 @@
-objAuth = new AuthController();
- $this->objUser = new UserController();
- $this->objPermission = new PermissionController();
- }
-
- // Company
- public function getCompanies(Request $r) { // /api/rpc/invoice/company/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
- return DB::table('inv_company')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'compreg',
- 'taxnr',
- 'bank_number',
- 'bank_name',
- 'bank_recipient',
- 'logo',
- 'payterm',
- 'date_format'
- )
- ->get();
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getCompany($id, Request $r) { // /api/rpc/invoice/company/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancompany'] == 1) {
- if ($valid['inv_manuser'] == 0) {
- if ($id == $check) {
- return DB::table('inv_company')
- ->select(
- 'name',
- 'compreg',
- 'taxnr',
- 'bank_number',
- 'bank_name',
- 'bank_recipient',
- 'logo',
- 'payterm',
- 'date_format',
- 'comment1',
- 'comment2'
- )
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
- }
- else {
- return 'Permission denied.';
- }
- }
- else if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_company')
- ->select(
- 'user_id',
- 'name',
- 'compreg',
- 'taxnr',
- 'bank_number',
- 'bank_name',
- 'bank_recipient',
- 'logo',
- 'payterm',
- 'date_format',
- 'comment1',
- 'comment2'
- )
- ->where('id', $id)
- ->get();
- }
- else {
- return 'Permission denied.';
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newCompany(Request $r) { // /api/rpc/invoice/company/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
- $add = DB::table('inv_company')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'compreg' => ($r->compreg ? $r->compreg : ''),
- 'taxnr' => ($r->taxnr ? $r->taxnr : ''),
- 'bank_number' => $r->bank_number,
- 'bank_name' => $r->bank_name,
- 'bank_recipient' => $r->bank_recipient,
- 'logo' => ($r->logo ? $r->logo : ''),
- 'payterm' => $r->payterm,
- 'date_format' => $r->date_format,
- 'comment1' => $r->comment1,
- 'comment2' => $r->comment2
- ]);
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editCompany(Request $r) { // /api/rpc/invoice/company/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancompany'] == 1) {
- if ($valid['inv_manuser'] == 0) {
- if ($companyId != 0) {
- DB::table('inv_company')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'name' => $r->name,
- 'compreg' => ($r->compreg ? $r->compreg : ''),
- 'taxnr' => ($r->taxnr ? $r->taxnr : ''),
- 'bank_number' => $r->bank_number,
- 'bank_name' => $r->bank_name,
- 'bank_recipient' => $r->bank_recipient,
- 'logo' => ($r->logo ? $r->logo : ''),
- 'payterm' => $r->payterm,
- 'date_format' => $r->date_format,
- 'comment1' => $r->comment1,
- 'comment2' => $r->comment2
- ]);
- }
- else {
- return 'Permission denied.';
- }
- }
- else if ($valid['inv_manuser'] == 1) {
- DB::table('inv_company')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'compreg' => ($r->compreg ? $r->compreg : ''),
- 'taxnr' => ($r->taxnr ? $r->taxnr : ''),
- 'bank_number' => $r->bank_number,
- 'bank_name' => $r->bank_name,
- 'bank_recipient' => $r->bank_recipient,
- 'logo' => ($r->logo ? $r->logo : ''),
- 'payterm' => $r->payterm,
- 'date_format' => $r->date_format,
- 'comment1' => $r->comment1,
- 'comment2' => $r->comment2
- ]);
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteCompany(Request $r) { // /api/rpc/invoice/company/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
- DB::table('inv_company')->where('id', $r->id)->delete();
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Contacts
- public function getContacts(Request $r) { // /api/rpc/invoice/contacts/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancontact'] == 1) {
- $data = array(
- 'inv_contacts.id',
- 'inv_contacts.user_id',
- 'inv_contacts.company_name',
- 'inv_contacts.name',
- 'inv_contacts.fulladdress',
- 'inv_contacts.phone',
- 'inv_contacts.email'
- );
- if ($valid['inv_manuser'] == 1) {
-
- if (isset($r->emp)) {
- $get = DB::table('inv_contacts')
- ->join('inv_employers', 'inv_employers.contact_id', 'inv_contacts.id')
- ->get($data);
- }
- else if (isset($r->cus)) {
- $get = DB::table('inv_contacts')
- ->join('inv_clients', 'inv_clients.contact_id', 'inv_contacts.id')
- ->get($data);
- }
- else {
- $get = DB::table('inv_contacts')
- ->select(
- 'id',
- 'user_id',
- 'company_name',
- 'name',
- 'fulladdress',
- 'phone',
- 'email'
- )
- ->get();
- }
-
- return $get;
- }
- else {
- $get = DB::table('inv_contacts')
- ->select(
- 'id',
- 'company_name',
- 'name',
- 'fulladdress',
- 'phone',
- 'email'
- )
- ->where('user_id', $check)
- ->get();
-
- return $get;
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getContact($id, Request $r) { // /api/rpc/invoice/contacts/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancontact'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $get = DB::table('inv_contacts')
- ->select(
- 'id',
- 'user_id',
- 'company_name',
- 'name',
- 'fulladdress',
- 'phone',
- 'website',
- 'email',
- 'custom'
- )
- ->where('id', $id)
- ->get();
-
- $emp = DB::table('inv_employers')
- ->select('id')
- ->where('contact_id', $id)
- ->get();
-
- $cus = DB::table('inv_clients')
- ->select('id')
- ->where('contact_id', $id)
- ->get();
- }
- else {
- $get = DB::table('inv_contacts')
- ->select(
- 'id',
- 'company_name',
- 'name',
- 'fulladdress',
- 'phone',
- 'website',
- 'email',
- 'custom'
- )
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
-
- $emp = DB::table('inv_employers')
- ->select('id')
- ->where('contact_id', $id)
- ->where('user_id', $check)
- ->get();
-
- $cus = DB::table('inv_clients')
- ->select('id')
- ->where('contact_id', $id)
- ->where('user_id', $check)
- ->get();
- }
-
- $res = array();
-
- foreach($get as $g) {
- $res[] = array(
- 'id' => $g->id,
- 'user_id' => ($valid['inv_manuser'] === 1 ? $g->user_id : $check),
- 'company_name' => $g->company_name,
- 'name' => $g->name,
- 'fulladdress' => $g->fulladdress,
- 'phone' => $g->phone,
- 'website' => $g->website,
- 'email' => $g->email,
- 'custom' => $g->custom,
- 'isEmployer' => ($emp->count() ? true : false),
- 'isCustomer' => ($cus->count() ? true : false)
- );
- }
-
- return $res;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newContact(Request $r) { // /api/rpc/invoice/contacts/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancontact'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $add = DB::table('inv_contacts')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'company_name' => $r->company_name,
- 'name' => $r->name,
- 'fulladdress' => $r->fulladdress,
- 'phone' => $r->phone,
- 'website' => $r->website,
- 'email' => $r->email,
- 'custom' => $r->custom
- ]);
-
- if ($r->isCustomer) {
- DB::table('inv_clients')
- ->insert([
- 'user_id' => $r->user_id,
- 'contact_id' => $add
- ]);
- }
-
- if ($r->isEmployer) {
- DB::table('inv_employers')
- ->insert([
- 'user_id' => $r->user_id,
- 'contact_id' => $add
- ]);
- }
- }
- else {
- $add = DB::table('inv_contacts')
- ->insertGetId([
- 'company_name' => $r->company_name,
- 'name' => $r->name,
- 'fulladdress' => $r->fulladdress,
- 'phone' => $r->phone,
- 'website' => $r->website,
- 'email' => $r->email,
- 'custom' => $r->custom
- ]);
-
- if ($r->isCustomer) {
- DB::table('inv_clients')
- ->insert([
- 'user_id' => $check,
- 'contact_id' => $add
- ]);
- }
-
- if ($r->isEmployer) {
- DB::table('inv_employers')
- ->insert([
- 'user_id' => $check,
- 'contact_id' => $add
- ]);
- }
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editContact(Request $r) { // /api/rpc/invoice/contacts/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancontact'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_contacts')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'company_name' => $r->company_name,
- 'name' => $r->name,
- 'fulladdress' => $r->fulladdress,
- 'phone' => $r->phone,
- 'website' => $r->website,
- 'email' => $r->email,
- 'custom' => $r->custom
- ]);
-
- $emp = DB::table('inv_employers')
- ->select('id')
- ->where('contact_id', $r->id)
- ->get();
-
- if ($emp->count()) {
- if (!$r->isEmployer) {
- DB::table('inv_employers')->where('contact_id', $r->id)->delete();
- }
- }
- else {
- if ($r->isEmployer) {
- DB::table('inv_employers')
- ->where('id', $r->id)
- ->insert([
- 'user_id' => $r->user_id,
- 'contact_id' => $r->id
- ]);
- }
- }
-
- $cus = DB::table('inv_clients')
- ->select('id')
- ->where('contact_id', $r->id)
- ->get();
-
- if ($cus->count()) {
- if (!$r->isCustomer) {
- DB::table('inv_clients')->where('contact_id', $r->id)->delete();
- }
- }
- else {
- if ($r->isCustomer) {
- DB::table('inv_clients')
- ->where('id', $r->id)
- ->insert([
- 'user_id' => $r->user_id,
- 'contact_id' => $r->id
- ]);
- }
- }
- }
- else {
- DB::table('inv_contacts')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'company_name' => $r->company_name,
- 'name' => $r->name,
- 'fulladdress' => $r->fulladdress,
- 'phone' => $r->phone,
- 'website' => $r->website,
- 'email' => $r->email,
- 'custom' => $r->custom
- ]);
-
- $emp = DB::table('inv_employers')
- ->select('id')
- ->where('user_id', $check)
- ->where('contact_id', $r->id)
- ->get();
-
- if ($emp->count()) {
- if (!$r->isEmployer) {
- DB::table('inv_employers')->where('contact_id', $r->id)->where('user_id', $check)->delete();
- }
- }
- else {
- if ($r->isEmployer) {
- DB::table('inv_employers')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->insert([
- 'contact_id' => $r->id
- ]);
- }
- }
-
- $cus = DB::table('inv_clients')
- ->select('id')
- ->where('user_id', $check)
- ->where('contact_id', $r->id)
- ->get();
-
- if ($cus->count()) {
- if (!$r->isCustomer) {
- DB::table('inv_clients')->where('contact_id', $r->id)->where('user_id', $check)->delete();
- }
- }
- else {
- if ($r->isCustomer) {
- DB::table('inv_clients')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->insert([
- 'contact_id' => $r->id
- ]);
- }
- }
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteContact(Request $r) { // /api/rpc/invoice/contacts/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_mancontact'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_contacts')->where('id', $r->id)->delete();
- DB::table('inv_employers')->where('contact_id', $r->id)->delete();
- DB::table('inv_clients')->where('contact_id', $r->id)->delete();
- }
- else {
- DB::table('inv_contacts')->where('id', $r->id)->where('user_id', $check)->delete();
- DB::table('inv_employers')->where('contact_id', $r->id)->where('user_id', $check)->delete();
- DB::table('inv_clients')->where('contact_id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Invoices
- public function getInvoices(Request $r) { // /api/rpc/invoice/invoices/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- $format = DB::table('inv_company')
- ->select('date_format')
- ->where('user_id', $check)
- ->get();
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $get = DB::table('inv_invoices')
- ->select(
- 'id',
- 'user_id',
- 'employer',
- 'customer',
- 'year',
- 'inv_number',
- 'revision',
- 'make_date'
- )
- ->get();
-
- $res = array();
-
- foreach ($get as $i) {
- $usr = DB::table('inv_contacts')
- ->select('name', 'company_name')
- ->where('user_id', $i->user_id)
- ->get();
-
- $emp = DB::table('inv_contacts')
- ->select('name', 'company_name')
- ->where('id', $i->employer)
- ->get();
-
- $cus = DB::table('inv_contacts')
- ->select('name', 'company_name')
- ->where('id', $i->customer)
- ->get();
-
- $zero = '0000';
- $len = strlen($i->inv_number);
- $num = substr($zero, $len);
- $fin = $num.$i->inv_number;
-
- $res[] = array(
- 'id' => $i->id,
- 'employer' => $emp[0]->name.($emp[0]->company_name != '' ? ' ('.$emp[0]->company_name.')' : ''),
- 'customer' => $cus[0]->name.($cus[0]->company_name != '' ? ' ('.$cus[0]->company_name.')' : ''),
- 'user' => $usr[0]->name.($usr[0]->company_name != '' ? ' ('.$usr[0]->company_name.')' : ''),
- 'invoice' => $i->year.$fin.($i->revision > 0 ? '_R'.$i->revision : ''),
- 'date' => strftime($format[0]->date_format, $i->make_date)
- );
- }
-
- return $res;
- }
- else {
- return DB::table('inv_services')
- ->select(
- 'id',
- 'year',
- 'inv_number',
- 'revision',
- 'make_date'
- )
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getInvoice($id, Request $r) { // /api/rpc/invoice/invoices/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $u = DB::table('inv_invoices')
- ->select('user_id')
- ->where('id', $id)
- ->first();
-
- $format = DB::table('inv_company')
- ->select('date_format')
- ->where('user_id', $u->user_id)
- ->get();
-
- $invoice = DB::table('inv_invoices')
- ->select(
- 'id as id',
- 'user_id as user_id',
- 'employer as employer',
- 'customer as customer',
- 'year as year',
- 'inv_number as inv_number',
- 'revision as revision',
- 'make_date as make_date',
- 'invtype as invtype',
- 'tax_id as tax_id'
- )
- ->where('id', $id)
- ->get();
-
- $inv = array();
- $cus = array();
- $emp = array();
- $com = array();
- $desP = array();
- $desR = array();
- $desS = array();
-
- $self = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $u->user_id)
- ->where('user_id', $u->user_id)
- ->get();
-
- $cus = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $invoice[0]->customer)
- ->where('user_id', $u->user_id)
- ->get();
-
- $emp = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $invoice[0]->employer)
- ->where('user_id', $u->user_id)
- ->get();
-
- $com = DB::table('inv_company')
- ->select('id', 'name', 'compreg', 'taxnr', 'bank_number', 'bank_name', 'bank_recipient', 'logo', 'payterm', 'comment1', 'comment2')
- ->where('user_id', $u->user_id)
- ->get();
-
- $zero = '0000';
- $len = strlen($invoice[0]->inv_number);
- $num = substr($zero, $len);
- $fin = $num.$invoice[0]->inv_number;
-
- $inv[] = array(
- 'id' => $id,
- 'user_id' => $u->user_id,
- 'invoice_year' => strftime('%Y', $invoice[0]->make_date),
- 'invoice_month' => strftime('%B', $invoice[0]->make_date),
- 'invoice_date' => strftime($format[0]->date_format, $invoice[0]->make_date),
- 'invoice' => $invoice[0]->year.$fin.($invoice[0]->revision > 0 ? '_R'.$invoice[0]->revision : ''),
- 'invtype' => $invoice[0]->invtype
- );
-
- $itemsP = DB::table('inv_invoice_items')
- ->join('inv_periods', 'inv_periods.id', 'inv_invoice_items.period_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $u->user_id)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_periods.id as period_id',
- 'inv_periods.name',
- 'inv_periods.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsP as $j) {
- $desP[] = array(
- 'id' => $j->id,
- 'period_id' => $j->period_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- $itemsR = DB::table('inv_invoice_items')
- ->join('inv_products', 'inv_products.id', 'inv_invoice_items.product_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $u->user_id)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_products.id as product_id',
- 'inv_products.name',
- 'inv_products.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsR as $j) {
- $desR[] = array(
- 'id' => $j->id,
- 'product_id' => $j->product_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- $itemsS = DB::table('inv_invoice_items')
- ->join('inv_services', 'inv_services.id', 'inv_invoice_items.service_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $u->user_id)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_services.id as service_id',
- 'inv_services.name',
- 'inv_services.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsS as $j) {
- $desS[] = array(
- 'id' => $j->id,
- 'service_id' => $j->service_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- return array(
- 'invoice' => $inv,
- 'user' => $self,
- 'company' => $com,
- 'employer' => $emp,
- 'customer' => $cus,
- 'periods' => $desP,
- 'products' => $desR,
- 'services' => $desS
- );
- }
- else {
- $format = DB::table('inv_company')
- ->select('date_format')
- ->where('user_id', $check)
- ->get();
-
- $invoice = DB::table('inv_invoices')
- ->select(
- 'id as id',
- 'user_id as user_id',
- 'employer as employer',
- 'customer as customer',
- 'year as year',
- 'inv_number as inv_number',
- 'revision as revision',
- 'make_date as make_date',
- 'invtype as invtype',
- 'tax_id as tax_id'
- )
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
-
- $inv = array();
- $cus = array();
- $emp = array();
- $com = array();
- $desP = array();
- $desR = array();
- $desS = array();
-
- $self = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $check)
- ->where('user_id', $check)
- ->get();
-
- $cus = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $invoice[0]->customer)
- ->where('user_id', $check)
- ->get();
-
- $emp = DB::table('inv_contacts')
- ->select('id', 'company_name', 'name', 'fulladdress', 'phone', 'website', 'email', 'custom')
- ->where('id', $invoice[0]->employer)
- ->where('user_id', $check)
- ->get();
-
- $com = DB::table('inv_company')
- ->select('id', 'name', 'compreg', 'taxnr', 'bank_number', 'bank_name', 'bank_recipient', 'logo', 'payterm', 'comment1', 'comment2')
- ->where('user_id', $check)
- ->get();
-
- $zero = '0000';
- $len = strlen($invoice[0]->inv_number);
- $num = substr($zero, $len);
- $fin = $num.$invoice[0]->inv_number;
-
- $inv[] = array(
- 'id' => $id,
- 'user_id' => $u->user_id,
- 'invoice_year' => strftime('%Y', $invoice[0]->make_date),
- 'invoice_month' => strftime('%B', $invoice[0]->make_date),
- 'invoice_date' => strftime($format[0]->date_format, $invoice[0]->make_date),
- 'invoice' => $invoice[0]->year.$fin.($invoice[0]->revision > 0 ? '_R'.$invoice[0]->revision : ''),
- 'invtype' => $invoice[0]->invtype
- );
-
- $itemsP = DB::table('inv_invoice_items')
- ->join('inv_periods', 'inv_periods.id', 'inv_invoice_items.period_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $check)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_periods.id as period_id',
- 'inv_periods.name',
- 'inv_periods.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsP as $j) {
- $desP[] = array(
- 'id' => $j->id,
- 'period_id' => $j->period_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- $itemsR = DB::table('inv_invoice_items')
- ->join('inv_products', 'inv_products.id', 'inv_invoice_items.product_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $check)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_products.id as product_id',
- 'inv_products.name',
- 'inv_products.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsR as $j) {
- $desR[] = array(
- 'id' => $j->id,
- 'product_id' => $j->product_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- $itemsS = DB::table('inv_invoice_items')
- ->join('inv_services', 'inv_services.id', 'inv_invoice_items.service_id')
- ->where('inv_invoice_items.invoice_id', $id)
- ->where('inv_invoice_items.user_id', $check)
- ->get(array(
- 'inv_invoice_items.id as id',
- 'inv_services.id as service_id',
- 'inv_services.name',
- 'inv_services.price',
- 'inv_invoice_items.from_time',
- 'inv_invoice_items.to_time'
- ));
-
- foreach($itemsS as $j) {
- $desS[] = array(
- 'id' => $j->id,
- 'service_id' => $j->service_id,
- 'name' => $j->name,
- 'price' => $j->price,
- 'work_date' => strftime($format[0]->date_format, $j->from_time),
- 'from_time' => strftime('%H:%M', $j->from_time),
- 'from_time_unix' => $j->from_time,
- 'from_time_js' => $j->from_time * 1000,
- 'to_time' => strftime('%H:%M', $j->to_time),
- 'to_time_unix' => $j->to_time,
- 'to_time_js' => $j->to_time * 1000
- );
- }
-
- return array(
- 'invoice' => $inv,
- 'user' => $self,
- 'company' => $com,
- 'employer' => $emp,
- 'customer' => $cus,
- 'periods' => $desP,
- 'products' => $desR,
- 'services' => $desS
- );
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newInvoiceItem(Request $r) { // /api/rpc/invoice/invoices/newitem
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_invoice_items')
- ->insert([
- 'user_id' => $r->user_id,
- 'invoice_id' => $r->inv,
- 'service_id' => $r->service_id,
- 'period_id' => $r->period_id,
- 'product_id' => $r->product_id,
- 'from_time' => $r->from_time,
- 'to_time' => $r->to_time
- ]);
- }
- else {
- DB::table('inv_invoice_items')
- ->insert([
- 'user_id' => $check,
- 'invoice_id' => $r->inv,
- 'service_id' => $r->service_id,
- 'period_id' => $r->period_id,
- 'product_id' => $r->product_id,
- 'from_time' => $r->from_time,
- 'to_time' => $r->to_time
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newInvoice(Request $r) { // /api/rpc/invoice/invoices/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $lastInv = DB::table('inv_invoices')
- ->where('year', date('Y'))
- ->where('user_id', $r->user_id)
- ->count();
-
- $add = DB::table('inv_invoices')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'customer' => $r->customer,
- 'employer' => $r->employer,
- 'year' => date('Y'),
- 'inv_number' => $lastInv + 1,
- 'revision' => 0,
- 'make_date' => time(),
- 'invtype' => $r->invtype,
- 'tax_id' => 0
- ]);
- }
- else {
- $lastInv = DB::table('inv_invoices')
- ->where('year', date('Y'))
- ->where('user_id', $check)
- ->count();
-
- $add = DB::table('inv_invoices')
- ->insertGetId([
- 'user_id' => $check,
- 'customer' => $r->customer,
- 'employer' => $r->employer,
- 'year' => date('Y'),
- 'inv_number' => $lastInv + 1,
- 'revision' => 0,
- 'make_date' => time(),
- 'invtype' => $r->invtype,
- 'tax_id' => 0
- ]);
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editInvoiceItem(Request $r) { // /api/rpc/invoice/invoices/edititem
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_invoice_items')
- ->where('id', $r->id)
- ->where('invoice_id', $r->inv)
- ->update([
- 'service_id' => $r->service_id,
- 'period_id' => $r->period_id,
- 'product_id' => $r->product_id,
- 'from_time' => $r->from_time,
- 'to_time' => $r->to_time
- ]);
- }
- else {
- DB::table('inv_invoice_items')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->where('invoice_id', $r->inv)
- ->update([
- 'service_id' => $r->service_id,
- 'period_id' => $r->period_id,
- 'product_id' => $r->product_id,
- 'from_time' => $r->from_time,
- 'to_time' => $r->to_time
- ]);
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editInvoice(Request $r) { // /api/rpc/invoice/invoices/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- $rev = DB::table('inv_invoices')
- ->select('revision')
- ->where('id', $r->id)
- ->get();
-
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_invoices')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'customer' => $r->customer,
- 'employer' => $r->employer,
- 'invtype' => $r->invtype,
- 'tax_id' => 0,
- 'revision' => $rev[0]->revision + 1
- ]);
- }
- else {
- DB::table('inv_invoices')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'customer' => $r->customer,
- 'employer' => $r->employer,
- 'invtype' => $r->invtype,
- 'tax_id' => 0,
- 'revision' => $rev[0]->revision + 1
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteInvoice(Request $r) { // /api/rpc/invoice/invoices/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_invoices')->where('id', $r->id)->delete();
- }
- else {
- DB::table('inv_invoices')->where('id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Periods
- public function getPeriods(Request $r) { // /api/rpc/invoice/periods/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_periods')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'price',
- 'intervals',
- 'period'
- )
- ->get();
-
- }
- else {
- return DB::table('inv_periods')
- ->select(
- 'id',
- 'name',
- 'price',
- 'intervals',
- 'period'
- )
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getPeriod($id, Request $r) { // /api/rpc/invoice/periods/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_periods')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'price',
- 'intervals',
- 'period'
- )
- ->where('id', $id)
- ->get();
- }
- else {
- return DB::table('inv_periods')
- ->select(
- 'id',
- 'name',
- 'price',
- 'intervals',
- 'period'
- )
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newPeriod(Request $r) { // /api/rpc/invoice/periods/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $add = DB::table('inv_periods')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price,
- 'intervals' => $r->intervals,
- 'period' => $r->period
- ]);
- }
- else {
- $add = DB::table('inv_periods')
- ->insertGetId([
- 'user_id' => $check,
- 'name' => $r->name,
- 'price' => $r->price,
- 'intervals' => $r->intervals,
- 'period' => $r->period
- ]);
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editPeriod(Request $r) { // /api/rpc/invoice/periods/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_periods')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price,
- 'intervals' => $r->intervals,
- 'period' => $r->period
- ]);
- }
- else {
- DB::table('inv_periods')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'name' => $r->name,
- 'price' => $r->price,
- 'intervals' => $r->intervals,
- 'period' => $r->period
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deletePeriod(Request $r) { // /api/rpc/invoice/periods/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_periods')->where('id', $r->id)->delete();
- }
- else {
- DB::table('inv_periods')->where('id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Products
- public function getProducts(Request $r) { // /api/rpc/invoice/products/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_products')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'price'
- )
- ->get();
-
- }
- else {
- return DB::table('inv_products')
- ->select(
- 'id',
- 'name',
- 'price'
- )
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getProduct($id, Request $r) { // /api/rpc/invoice/products/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $get = DB::table('inv_products')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'price'
- )
- ->where('id', $id)
- ->get();
-
- return $get;
- }
- else {
- $get = DB::table('inv_products')
- ->select(
- 'id',
- 'name',
- 'price'
- )
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
-
- return $get;
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newProduct(Request $r) { // /api/rpc/invoice/products/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $add = DB::table('inv_products')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
- else {
- $add = DB::table('inv_products')
- ->insertGetId([
- 'user_id' => $check,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editProduct(Request $r) { // /api/rpc/invoice/products/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_products')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
- else {
- DB::table('inv_products')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteProduct(Request $r) { // /api/rpc/invoice/products/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_products')->where('id', $r->id)->delete();
- }
- else {
- DB::table('inv_products')->where('id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Services
- public function getServices(Request $r) { // /api/rpc/invoice/services/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_services')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'price'
- )
- ->get();
-
- }
- else {
- return DB::table('inv_services')
- ->select(
- 'id',
- 'name',
- 'price'
- )
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getService($id, Request $r) { // /api/rpc/invoice/services/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_services')
- ->select('*')
- ->where('id', $id)
- ->get();
- }
- else {
- return DB::table('inv_services')
- ->select('*')
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newService(Request $r) { // /api/rpc/invoice/services/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $add = DB::table('inv_services')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
- else {
- $add = DB::table('inv_services')
- ->insertGetId([
- 'user_id' => $check,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editService(Request $r) { // /api/rpc/invoice/services/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_services')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
- else {
- DB::table('inv_services')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'user_id' => $check,
- 'name' => $r->name,
- 'price' => $r->price
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteService(Request $r) { // /api/rpc/invoice/services/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_services')->where('id', $r->id)->delete();
- }
- else {
- DB::table('inv_services')->where('id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- // Tax
- public function getTaxes(Request $r) { // /api/rpc/invoice/taxes/getall
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_taxes')
- ->select(
- 'id',
- 'user_id',
- 'name',
- 'percentage'
- )
- ->get();
-
- }
- else {
- return DB::table('inv_taxes')
- ->select(
- 'id',
- 'name',
- 'percentage'
- )
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function getTax($id, Request $r) { // /api/rpc/invoice/taxes/get/id
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- return DB::table('inv_taxes')
- ->select('*')
- ->where('id', $id)
- ->get();
- }
- else {
- return DB::table('inv_taxes')
- ->select('*')
- ->where('id', $id)
- ->where('user_id', $check)
- ->get();
- }
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function newTax(Request $r) { // /api/rpc/invoice/taxes/new
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- $add = DB::table('inv_taxes')
- ->insertGetId([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'percentage' => $r->percentage
- ]);
- }
- else {
- $add = DB::table('inv_taxes')
- ->insertGetId([
- 'user_id' => $check,
- 'name' => $r->name,
- 'percentage' => $r->percentage
- ]);
- }
-
- return $add;
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function editTax(Request $r) { // /api/rpc/invoice/taxes/edit
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_taxes')
- ->where('id', $r->id)
- ->update([
- 'user_id' => $r->user_id,
- 'name' => $r->name,
- 'percentage' => $r->percentage
- ]);
- }
- else {
- DB::table('inv_taxes')
- ->where('id', $r->id)
- ->where('user_id', $check)
- ->update([
- 'user_id' => $check,
- 'name' => $r->name,
- 'percentage' => $r->percentage
- ]);
- }
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-
- public function deleteTax(Request $r) { // /api/rpc/invoice/taxes/delete
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['inv_makeinvoice'] == 1) {
- if ($valid['inv_manuser'] == 1) {
- DB::table('inv_taxes')->where('id', $r->id)->delete();
- }
- else {
- DB::table('inv_taxes')->where('id', $r->id)->where('user_id', $check)->delete();
- }
-
- return 'Done.';
- }
- else {
- return 'Permission denied.';
- }
- }
- }
-}
diff --git a/app/Http/Controllers/MailController.php b/app/Http/Controllers/MailController.php
deleted file mode 100644
index e69de29..0000000
diff --git a/app/Http/Controllers/PackageController.php b/app/Http/Controllers/PackageController.php
deleted file mode 100644
index 6fc458b..0000000
--- a/app/Http/Controllers/PackageController.php
+++ /dev/null
@@ -1,39 +0,0 @@
-objAuth = new AuthController();
- $this->objUser = new UserController();
- $this->objPermission = new PermissionController();
- }
-
- public function get(Request $r) { // /api/rpc/pack/get
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'err!';
- }
- else {
- return DB::table('pck_tracks')
- ->select('*')
- ->where('user_id', $check)
- ->orderBy('id', 'desc')
- ->get();
- }
- }
-}
diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php
deleted file mode 100644
index 4d1983a..0000000
--- a/app/Http/Controllers/SiteController.php
+++ /dev/null
@@ -1,164 +0,0 @@
-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;
- }
-}
diff --git a/app/Http/Controllers/StoreController.php b/app/Http/Controllers/StoreController.php
deleted file mode 100644
index 7650d69..0000000
--- a/app/Http/Controllers/StoreController.php
+++ /dev/null
@@ -1,611 +0,0 @@
-storePath = storage_path('app/public/store');
- $this->objUser = new UserController();
- $this->objPermission = new PermissionController();
- }
-
- // Game
- public function getGames() { // /api/rpc/store/game/getgames
- return DB::table('str_games_loc')
- ->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
- ->get(array(
- 'str_games.id',
- 'str_games.name',
- 'str_games_loc.name as altname'
- ));
- }
-
- public function getGame($id) { // /api/rpc/store/game/getgame/id
- return DB::table('str_games_loc')
- ->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
- ->where('str_games.id', $id)
- ->get(array(
- 'str_games.id',
- 'str_games.name',
- 'str_games_loc.name as altname'
- ));
- }
-
- public function newGame(Request $r) { // /api/rpc/store/games/newgame
- $add = DB::table('str_games')
- ->insert([
- 'name' => $r->name
- ]);
-
- return \Response::json($add);
- }
-
- public function editGame(Request $r) { // /api/rpc/store/games/editgame
- return DB::table('str_games')
- ->where('id', $r->id)
- ->update([
- 'name' => $r->name
- ]);
- }
-
- // Category
- public function getCategories() { // /api/rpc/store/category/getcategories
- return DB::table('str_category_loc')
- ->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
- ->get(array(
- 'str_category.id',
- 'str_category.name',
- 'str_category_loc.name as altname',
- 'str_category.game_id',
- 'str_category.min_screenshots'
- ));
- }
-
- public function getCategory($id) { // /api/rpc/store/category/getcategory/id
- return DB::table('str_category_loc')
- ->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
- ->where('str_category.id', $id)
- ->get(array(
- 'str_category.id',
- 'str_category.name',
- 'str_category_loc.name as altname',
- 'str_category.game_id',
- 'str_category.min_screenshots'
- ));
- }
-
- public function getCategoriesOfGame($id) { // /api/rpc/store/category/getcategoriesofgame/id
- return DB::table('str_category_loc')
- ->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
- ->join('str_games', 'str_category.game_id', '=', 'str_games.id')
- ->where('str_games.id', $id)
- ->get(array(
- 'str_category.id',
- 'str_category.name',
- 'str_category_loc.name as altname'
- ));
- }
-
- public function getGameOfCategory($id) { // /api/rpc/store/category/getgameofcategory/id
- return DB::table('str_games_loc')
- ->join('str_games', 'str_games.id', '=', 'str_games_loc.ref_id')
- ->join('str_category', 'str_category.game_id', '=', 'str_games.id')
- ->where('str_category.id', $id)
- ->get(array(
- 'str_games.id',
- 'str_games.name',
- 'str_games_loc.name as altname'
- ));
- }
-
- public function getCategoryGame($id) { // /api/rpc/store/category/getcategorygame/id
- return DB::table('str_category')
- ->select('game_id')
- ->where('id', $id)
- ->get();
- }
-
- public function getCategoryMinScreenshots($id) { // /api/rpc/store/category/getcategoryminscrot/id
- return DB::table('str_category')
- ->select('min_screenshots')
- ->where('id', $id)
- ->get();
- }
-
- public function getCategoryName($id) { // /api/rpc/store/category/getcategoryname/id
- return DB::table('str_category_loc')
- ->join('str_category', 'str_category.id', '=', 'str_category_loc.ref_id')
- ->where('str_category.id', $id)
- ->get(array(
- 'str_category.name',
- 'str_category_loc.name as altname'
- ));
- }
-
- public function getCategoryNameOfEntry($id) { // /api/rpc/store/category/getcategorynameofentry/id
- return DB::table('str_file')
- ->join('str_category', 'str_category.id', '=', 'str_file.cat_id')
- ->join('str_category_loc', 'str_category.id', '=', 'str_category_loc.ref_id')
- ->where('str_file.id', $id)
- ->get(array(
- 'str_category.name',
- 'str_category_loc.name as altname'
- ));
- }
-
- public function newCategory(Request $r) { // /api/rpc/store/category/newcategory
- $add = DB::table('str_category')
- ->insert([
- 'name' => $r->name,
- 'game_id' => $r->game_id,
- 'min_screenshots' => $r->min_screenshots
- ]);
-
- return \Response::json($add);
- }
-
- public function editCategory(Request $r) { // /api/rpc/store/category/editcategory
- return DB::table('str_category')
- ->where('id', $r->id)
- ->update([
- 'name' => $r->name,
- 'min_screenshots' => $r->min_screenshots
- ]);
- }
-
- // Entries
- public function getAllEntries() { // /api/rpc/store/entry/getallentries
- return DB::table('str_file')
- ->select('*')
- ->get();
- }
-
- public function getAllApprovedEntries() { // /api/rpc/store/entry/getallapprovedentries
- return DB::table('str_file')
- ->select('*')
- ->where('isApproved', 1)
- ->get();
- }
-
- public function getAllBrokenEntries() { // /api/rpc/store/entry/getallbrokenentries
- return DB::table('str_file')
- ->select('*')
- ->where('isBroken', 1)
- ->get();
- }
-
- public function getAllPendingEntries() { // /api/rpc/store/entry/getallpendingentries
- return DB::table('str_file')
- ->select('*')
- ->where('isApproved', 0)
- ->get();
- }
-
- public function getNewEntries() { // /api/rpc/store/entry/getnewentries
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'submit_date'
- )
- ->where('isApproved', 1)
- ->orderBy('submit_date', 'desc')
- ->limit(5)
- ->get();
- }
-
- public function getHotEntries() { // /api/rpc/store/entry/gethotentries
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'downloads'
- )
- ->where('isApproved', 1)
- ->orderBy('downloads', 'desc')
- ->limit(5)
- ->get();
- }
-
- public function getEntriesPageAll($cat, $from, $to) { // /api/rpc/store/entry/getentriespageall/cat/from/to
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'description',
- 'submit_date',
- 'last_date',
- 'views',
- 'downloads'
- )
- ->where('cat_id', $cat)
- ->offset($from)
- ->limit($to)
- ->get();
- }
-
- public function getEntriesPageApproved($cat, $from, $to) { // /api/rpc/store/entry/getentriespageapproved/cat/from/to
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'description',
- 'submit_date',
- 'last_date',
- 'views',
- 'downloads'
- )
- ->where('cat_id', $cat)
- ->where('isApproved', 1)
- ->offset($from)
- ->limit($to)
- ->get();
- }
-
- public function getEntriesPagePopularView($cat, $from, $to) { // /api/rpc/store/entry/getentriespagepopularview/cat/from/to
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'description',
- 'submit_date',
- 'last_date',
- 'views',
- 'downloads'
- )
- ->where('cat_id', $cat)
- ->where('views', '>', 1000)
- ->offset($from)
- ->limit($to)
- ->get();
- }
-
- public function getEntriesPagePopularDownload($cat, $from, $to) { // /api/rpc/store/entry/getentriespagepopulardownload/cat/from/to
- return DB::table('str_file')
- ->select(
- 'id',
- 'title',
- 'version',
- 'description',
- 'submit_date',
- 'last_date',
- 'views',
- 'downloads'
- )
- ->where('cat_id', $cat)
- ->where('downloads', '>', 1000)
- ->offset($from)
- ->limit($to)
- ->get();
- }
-
- public function getChangelog($id) { // /api/rpc/store/entry/getchangelog/id
- return DB::table('str_file')
- ->select('version', 'changelog')
- ->where('id', $id)
- ->get();
- }
-
- public function getNotice($id) { // /api/rpc/store/entry/getnotice/id
- return DB::table('str_file')
- ->select('title', 'version', 'warningnote')
- ->where('id', $id)
- ->get();
- }
-
- public function getDownloadCount($id) { // /api/rpc/store/entry/getdownloadcount/id
- return DB::table('str_file')
- ->select('downloads')
- ->where('id', $id)
- ->get();
- }
-
- public function updateDownloadCount(Request $r) { // /api/rpc/store/entry/updatedownloadcount
- return DB::table('str_file')
- ->where('id', $r->id)
- ->update(['downloads', $r->downloads]);
- }
-
- public function FileSizeConvert($bytes) {
- $bytes = floatval($bytes);
- $arBytes = array(
- 0 => array(
- // "UNIT" => "TiB",
- // "VALUE" => pow(1024, 4)
- "UNIT" => "TQ",
- "VALUE" => pow(4096, 4)
- ),
- 1 => array(
- // "UNIT" => "GiB",
- // "VALUE" => pow(1024, 3)
- "UNIT" => "GQ",
- "VALUE" => pow(4096, 3)
- ),
- 2 => array(
- // "UNIT" => "MiB",
- // "VALUE" => pow(1024, 2)
- "UNIT" => "MQ",
- "VALUE" => pow(4096, 2)
- ),
- 3 => array(
- // "UNIT" => "KiB",
- // "VALUE" => 1024
- "UNIT" => "KQ",
- "VALUE" => 4096
- ),
- 4 => array(
- // "UNIT" => "B",
- "UNIT" => "Q",
- "VALUE" => 1
- )
- );
-
- foreach($arBytes as $arItem) {
- if($bytes >= $arItem["VALUE"]) {
- $result = $bytes / $arItem["VALUE"];
- $result = strval(round($result, 2))." ".$arItem["UNIT"];
- break;
- }
- }
-
- return $result;
- }
-
- public function getFilesOfEntry($id) { // /api/rpc/store/entry/getfilesofentry/id
- $files = array_map("htmlspecialchars", scandir("assets/store/$id"));
- $files = array_diff($files, array('..', '.', 'screens'));
-
- $result = array();
-
- foreach ($files as $file) {
- array_push($result, [
- 'id' => $id,
- 'file' => $file,
- 'size' => $this->FileSizeConvert(filesize('assets/store/'.$id.'/'.$file))
- ]);
- }
-
- return $result;
- }
-
- public function getNextEntryId() { // /api/rpc/store/entry/getnextentryid
- $get = DB::table('str_file')->max('id');
- $get++;
-
- return $get;
- }
-
- public function getEntry($id, $mode) { // /api/rpc/store/entry/getentry/id/mode
- if ($mode == 'user') {
- return DB::table('str_owners')
- ->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
- ->join('users', 'str_owners.user_id', '=', 'users.id')
- ->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
- ->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
- ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
- ->where('str_owners.user_id', $id)
- ->get(array(
- 'file_id',
- 'str_owners.user_id',
- 'cat_id',
- 'title',
- 'version',
- 'description',
- 'changelog',
- 'views',
- 'downloads',
- 'isApproved',
- 'submit_date',
- 'last_date',
- 'username',
- 'avatar',
- 'perm_id',
- 'gender',
- 'display_name',
- 'name_style',
- ));
- }
- else {
- return DB::table('str_owners')
- ->join('str_file', 'str_owners.file_id', '=', 'str_file.id')
- ->join('users', 'str_owners.user_id', '=', 'users.id')
- ->join('usr_details', 'usr_details.user_id', '=', 'str_owners.user_id')
- ->join('usr_profile', 'usr_profile.user_id', '=', 'str_owners.user_id')
- ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'str_owners.user_id')
- ->where('file_id', $id)
- ->take(1)
- ->get(array(
- 'file_id',
- 'str_owners.user_id',
- 'cat_id',
- 'title',
- 'version',
- 'description',
- 'changelog',
- 'views',
- 'downloads',
- 'isApproved',
- 'submit_date',
- 'last_date',
- 'username',
- 'avatar',
- 'perm_id',
- 'gender',
- 'display_name',
- 'name_style',
- ));
- }
-
- }
-
- public function getEntryName($id) { // /api/rpc/store/entry/getentryname/id
- return DB::table('str_file')
- ->select('title', 'version')
- ->where('id', $id)
- ->get();
- }
-
- public function getEntriesInCategory($cat_id) { // /api/rpc/store/entry/getentriesincategory/cat_id
- return DB::table('str_file')
- ->select('*')
- ->where('cat_id', $cat_id)
- ->get();
- }
-
- public function countEntriesInCategory($cat_id) { // /api/rpc/store/entry/countentriesincategory/cat_id
- // return $this->storePath.'/screens';
- return DB::table('str_file')
- ->where('cat_id', $cat_id)
- ->where('isApproved', 1)
- ->count();
- }
-
- public function countEntriesInCategoryFull($cat_id) { // /api/rpc/store/entry/countentriesincategoryfull/cat_id
- return DB::table('str_file')
- ->where('cat_id', $cat_id)
- ->count();
- }
-
- public function makedir(Request $r) {
- $id = $r->id;
-
- if (!mkdir($this->storePath.'/'.$id, 0755, true)) {
- Log::error('File MKDIR failed: ');
- exit();
- }
-
- if (!mkdir($this->storePath.'/'.$id.'/screens', 0755, true)) {
- Log::error('Asset MKDIR failed: ');
- exit();
- }
- }
-
- public function uploadEntry(Request $r) { // /api/rpc/store/entry/upload
- header('Access-Control-Allow-Origin: *');
- $id = $r->id;
-
- Log::info('Name: '.$r->file('imgfile')); //TMP
- Log::info('Type: '.gettype($r->file('imgfile'))); // TMP
-
- $r->file('upfile')->move(public_path('storage/store'.$id), $r->file('imgfile')->getClientOriginalName);
- $r->file('imgfile')->move(public_path('storage/store'.$id.'/screens'), $r->file('imgfile')->getClientOriginalName);
-
- exit(); // TMP
-
- $add = DB::table('str_file')
- ->insert([
- 'game_id' => intval($r->game_id),
- 'cat_id' => intval($r->cat_id),
- 'title' => $r->title,
- 'version' => $r->version,
- 'video' => (!empty($r->video) ? $r->video : ''),
- 'description' => $r->description,
- 'changelog' => '',
- 'warningnote' => (!empty($r->warningnote) ? $r->warningnote : ''),
- 'submit_date' => intval($r->submit_date),
- 'last_date' => intval(0),
- 'views' => intval(0),
- 'downloads' => intval(0),
- 'isApproved' => intval(1),
- 'isBroken' => intval(0),
- 'failreason' => '',
- 'breakreason' => '',
- 'approveignore' => intval(0),
- 'brokenignore' => intval(0)
- ]);
-
- return \Response::json($add);
- }
-
- public function updateEntry(Request $r) { // /api/rpc/store/entry/update
- return DB::table('str_file')
- ->where('id', $r->id)
- ->update([
- 'cat_id' => $r->cat_id,
- 'title' => $r->title,
- 'version' => $r->version,
- 'description' => $r->description,
- 'changelog' => $r->changelog,
- 'warningnote' => $r->warningnote,
- 'last_date' => $r->last_date
- ]);
- }
-
- public function restoreEntry(Request $r) { // /api/rpc/store/entry/restore
- return DB::table('str_file')
- ->where('id', $r->id)
- ->update(['isApproved' => 1]);
- }
-
- public function removeEntry(Request $r) { // /api/rpc/store/entry/remove
- return DB::table('str_file')
- ->where('id', $r->id)
- ->update(['isApproved' => 0]);
- }
-
- public function browsePermissions($uid) {
- // Get user ID.
- $perm = $this->objUser->getUser($uid);
-
- // Does the user ID exist? Grand the appropriate rights. Otherwise, use guest.
- if ($uid != 0) {
- // Store permissions.
- $grouppermstr = $this->objPermission->getPermissionGroup('str', $perm[0]->perm_id);
- $userpermstr = $this->objPermission->getPermissionUser('str', $uid);
-
- // User permissions.
- $grouppermusr = $this->objPermission->getPermissionGroup('usr', $perm[0]->perm_id);
- $userpermusr = $this->objPermission->getPermissionUser('usr', $uid);
-
- // Now provide an array of user overwritten permissions if it exists. Otherwise, give its group permissions.
- $strarr = array();
- $usrarr = array();
-
- if (!empty($userpermstr[0])) {
- $strarr = (array)$userpermstr[0];
- }
- else {
- $strarr = (array)$grouppermstr[0];
- }
-
- if (!empty($userpermusr[0])) {
- $usrarr = (array)$userpermusr[0];
- }
- else {
- $usrarr = (array)$grouppermusr[0];
- }
-
- $merge = array();
- $merge = array_merge($strarr, $usrarr);
-
- return $merge;
- }
- else {
- // Store permissions.
- $grouppermstr = $this->objPermission->getPermissionGroup('str', 6);
-
- // User permissions.
- $grouppermusr = $this->objPermission->getPermissionGroup('usr', 6);
-
- // Since guests don't have user overwritten permissions, simply return the group permissions.
- $merge = array();
- $merge = array_merge((array)$grouppermstr[0], (array)$grouppermusr[0]);
-
- return $merge;
- }
- }
-
-}
diff --git a/app/Http/Controllers/User/Login.php b/app/Http/Controllers/User/Login.php
new file mode 100644
index 0000000..65b3d8d
--- /dev/null
+++ b/app/Http/Controllers/User/Login.php
@@ -0,0 +1,31 @@
+auth = $a;
+ $this->menu = $m;
+ $this->user = $u;
+ }
+
+ public function index (Request $r) {
+ if (isset($_COOKIE['kero_token'])) return redirect('');
+ $res = array();
+ $err = '';
+
+ if (isset($r->username) && isset($r->password)) {
+ $res = $this->auth->login($r);
+ if (isset($res['kero_token'])) return redirect('');
+ $err = $res['err'];
+ }
+
+ return view('pages.site.login', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err]);
+ }
+}
diff --git a/app/Http/Controllers/User/Notification.php b/app/Http/Controllers/User/Notification.php
new file mode 100644
index 0000000..522bce2
--- /dev/null
+++ b/app/Http/Controllers/User/Notification.php
@@ -0,0 +1,53 @@
+check = checkLegit((isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : ''));
+ }
+
+ public function get () {
+ $res = null;
+
+ if ($this->check != 0) {
+ if (Cache::has('getNotification')) $get = Cache::get('getNotification');
+ else {
+ $get = DB::table('usr_notification')->select('id', 'app_id', 'text', 'section', 'goto')->where('user_id', $this->check)->get();
+ $res = array();
+
+ foreach ($get as $g) {
+ $prot = DB::table('sys_settings')->select('protocol')->first()->protocol;
+ $goto = DB::table('sys_apps')->select('url')->where('id', $g->app_id)->first()->url;
+
+ $res[] = array('id' => $g->id, 'text' => $g->text, 'url' => 'http'.($prot == 1 ? 's' : '').'://'.$goto.'/#/'.$g->section);
+ Cache::put('getNotification', $get);
+ }
+ }
+
+ return $res;
+ }
+ else return array();
+ }
+
+ public function add ($uid, $aid, $txt, $sec, $goto) {
+ if ($this->check != 0) {
+ $add = DB::table('usr_notification')->insert(['user_id' => $uid, 'app_id' => $aid, 'text' => $txt, 'section' => $sec, 'goto' => $goto]);
+ if (Cache::has('getNotification')) Cache::forget('getNotification');
+ return 1;
+ }
+ }
+
+ public function delete ($id) {
+ if ($this->check != 0) {
+ $del = DB::table('usr_notification')->where('id', $id)->where('user_id', $this->check)->delete();
+ if (Cache::has('getNotification')) Cache::forget('getNotification');
+ return $del;
+ }
+ }
+}
diff --git a/app/Http/Controllers/User/Profile.php b/app/Http/Controllers/User/Profile.php
new file mode 100644
index 0000000..2a86e19
--- /dev/null
+++ b/app/Http/Controllers/User/Profile.php
@@ -0,0 +1,110 @@
+auth = $a;
+ $this->get = $g;
+ $this->cntr = $c;
+ $this->menu = $m;
+ $this->user = $u;
+ }
+
+ public function index ($id, $kero) {
+ if (!$this->get) return notfound($this->menu, $this->user, $this->get);
+ return view('pages.site.profile', ['res' => $this->get, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+
+ public function avatarUpload(Request $r) {
+ $check = checkLegit($r->kero_token);
+
+ if ($check == 0) return 'Err!';
+ else {
+ $valid = $this->auth->getPermissions($r->kero_token);
+ $user = 0;
+
+ if ($valid['usr_editother'] == 1) $user = $r->id;
+ else $user = $check;
+
+ if ($valid['usr_editprofile'] == 1) {
+ if (isset($r->filename)) {
+ if (!is_dir('/usericon/'.$check)) {
+ if (!mkdir('/usericon/'.$check, 0755, true)) return 'Could not make folder '.$check.'
';
+ }
+
+ $img_dir = '/usericon/'.$check.'/';
+ $image = $img_dir . $r->filename;
+ $imageFileType = array('image/png', 'image/jpeg', 'image/gif');
+
+ if (!in_array($r->filetype, $imageFileType)) return "Only JPG, PNG, JPEG, and GIF are allowed.";
+
+ $fname = '/usericon/'.$user.'/'.$r->filename;
+ $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $r->thefile));
+ Storage::disk('public')->put($fname, $data);
+
+ return $r->filename;
+ }
+ }
+ else return 'Permission denied.';
+ }
+ }
+
+ public function edit ($id, Request $r) {
+ $err = '';
+ $suc = '';
+
+ if (isset($r->submit)) {
+ if (!is_null($r->password)) {
+ if ($r->password != $r->password_check) $err = '「パスワード」と「パスワード確認」が異なります。';
+ else {
+ $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
+ $passwd = hash('sha256', $r->password . $salt);
+ for ($round = 0; $round < 65536; $round++) { $passwd = hash('sha256', $passwd . $salt); }
+ $eduserp = DB::table('users')->where('id', $id)->update(['password' => $passwd, 'salt' => $salt]);
+ if (!$eduserp) $err = 'パスワードの編集失敗。';
+ }
+ }
+
+ $cheml = DB::table('users')->select('email')->where('id', $id)->first();
+
+ if ($err == '') {
+ if ($cheml->email != $r->email) {
+ $exeml = DB::table('users')->select('email')->where('email', $r->email)->count();
+ if ($exeml > 0) $err = '入力したメールアドレスはもう存在しています。';
+ else {
+ $edusere = DB::table('users')->where('id', $id)->update(['email' => $r->email]);
+ if (!$edusere) $err = 'メールアドレスの編集失敗。';
+ }
+ }
+ }
+
+ if ($err == '') {
+ $p = DB::table('usr_profile')->select('display_name', 'country', 'gender')->where('user_id', $id)->first();
+ $edprofile = 1;
+ if ($p->display_name != $r->display_name || $p->country != $r->country || $p->gender != $r->gender) {
+ $edprofile = DB::table('usr_profile')->where('user_id', $id)->update([
+ 'display_name' => $r->display_name,
+ 'country' => $r->country,
+ 'gender' => $r->gender
+ ]);
+ }
+
+ if (!$edprofile) $err = '表示名、お国、又は性別の編集失敗。';
+ else $suc = '編集しました!';
+ }
+ }
+
+ if ($this->user) return view('pages.site.profileedit', ['res' => $this->get, 'menu' => $this->menu, 'user' => $this->user, 'suc' => $suc, 'err' => $err, 'cnt' => $this->cntr]);
+ return redirect('');
+ }
+}
diff --git a/app/Http/Controllers/User/Register.php b/app/Http/Controllers/User/Register.php
new file mode 100644
index 0000000..767099d
--- /dev/null
+++ b/app/Http/Controllers/User/Register.php
@@ -0,0 +1,32 @@
+auth = $a;
+ $this->cntr = $c;
+ $this->menu = $m;
+ $this->user = $u;
+ }
+
+ public function index (Request $r) {
+ if (isset($_COOKIE['kero_token'])) return redirect('');
+ $err = '';
+
+ if (isset($r->username) && isset($r->password) && isset($r->email) && isset($r->password_check)) {
+ $reg = $this->auth->register($r);
+ if (isset($reg['kero_token'])) return redirect('');
+ $err = $reg['err'];
+ }
+
+ return view('pages.site.register', ['res' => $this->cntr, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err]);
+ }
+}
diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index f3d60b1..ee41d3e 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -1,59 +1,66 @@
objAuth = new AuthController();
$this->menu = getPagesInMenu();
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
- $this->id = $this->objAuth->checkLegit($this->cook);
+ $this->id = checkLegit($this->cook);
$this->user = $this->getLoggedUser($this->id, $this->cook);
}
- public function getLoggedUser ($id, $kero) {
- $check = $this->objAuth->checkLegit($kero);
- if ($check == 0) return 0;
-
- $valid = $this->objAuth->getPermissions($kero);
- $cols = $this->getGroupColours()->toArray();
-
- $get = DB::table('users')->where('id', $id)->first();
- $get->profile = DB::table('usr_profile')->where('user_id', $id)->first();
- $get->profile->showname = (!empty($get->profile->display_name) && !is_null($get->profile->display_name) ? $get->profile->display_name : $get->username);
- $get->perm = $valid;
- if (empty($get->avatar) || $get->avatar == '') $get->avatar = '/img/noicon.webp';
-
- return $get;
+ public function profile ($id) {
+ $r = new Profile($this->objAuth, $this->getUser($id, $this->cook), $this->getCountries(), $this->menu, $this->user);
+ return $r->index($id, $this->cook);
}
- public function getGroupName($id) {
- return DB::table('usr_perm_module')->join('usr_perm_id', 'usr_perm_id.perm_id', '=', 'usr_perm_module.id')->where('user_id', $id)->get(array('name'));
+ public function editProfile ($id, Request $rr) {
+ $r = new Profile($this->objAuth, $this->getUser($id, $this->cook), $this->getCountries(), $this->menu, $this->user);
+ return $r->edit($id, $rr);
}
- public function getGroupColours() {
- return DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
+ public function login (Request $rr) {
+ $r = new Login($this->objAuth, $this->menu, $this->user);
+ return $r->index($rr);
}
- public function getUser ($id, $kero) {
- $check = $this->objAuth->checkLegit($kero);
+ public function register (Request $rr) {
+ $r = new Register($this->objAuth, $this->getCountries(), $this->menu, $this->user);
+ return $r->index($rr);
+ }
+
+ public function getNotification () {
+ $r = new Notification();
+ return $r->get();
+ }
+
+ public function addNotification ($uid, $aid, $txt, $sec, $goto) {
+ $r = new Notification();
+ return $r->add($uid, $aid, $txt, $sec, $goto);
+ }
+
+ public function delNotification ($id) {
+ $r = new Notification();
+ return $r->delete($id);
+ }
+
+ function getUser ($id, $kero) {
+ $check = checkLegit($kero);
$valid = $this->objAuth->getPermissions($kero);
$cols = $this->getGroupColours()->toArray();
@@ -89,7 +96,23 @@ class UserController extends Controller {
return $get;
}
- public function getCountries () {
+ function getLoggedUser ($id, $kero) {
+ $check = checkLegit($kero);
+ if ($check == 0) return 0;
+
+ $valid = $this->objAuth->getPermissions($kero);
+ $cols = $this->getGroupColours()->toArray();
+
+ $get = DB::table('users')->where('id', $id)->first();
+ $get->profile = DB::table('usr_profile')->where('user_id', $id)->first();
+ $get->profile->showname = (!empty($get->profile->display_name) && !is_null($get->profile->display_name) ? $get->profile->display_name : $get->username);
+ $get->perm = $valid;
+ if (empty($get->avatar) || $get->avatar == '') $get->avatar = '/img/noicon.webp';
+
+ return $get;
+ }
+
+ function getCountries () {
$flags = DB::table('nhn_country')->orderBy('id', 'asc')->get();
$res = array();
@@ -105,168 +128,11 @@ class UserController extends Controller {
return $res;
}
- public function avatarUpload(Request $r) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) return 'Err!';
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
- $user = 0;
-
- if ($valid['usr_editother'] == 1) $user = $r->id;
- else $user = $check;
-
- if ($valid['usr_editprofile'] == 1) {
- if (isset($r->filename)) {
- if (!is_dir('/usericon/'.$check)) {
- if (!mkdir('/usericon/'.$check, 0755, true)) return 'Could not make folder '.$check.'
';
- }
-
- $img_dir = '/usericon/'.$check.'/';
- $image = $img_dir . $r->filename;
- $imageFileType = array('image/png', 'image/jpeg', 'image/gif');
-
- if (!in_array($r->filetype, $imageFileType)) return "Only JPG, PNG, JPEG, and GIF are allowed.";
-
- $fname = '/usericon/'.$user.'/'.$r->filename;
- $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $r->thefile));
- Storage::disk('public')->put($fname, $data);
-
- return $r->filename;
- }
- }
- else return 'Permission denied.';
- }
+ function getGroupName($id) {
+ return DB::table('usr_perm_module')->join('usr_perm_id', 'usr_perm_id.perm_id', '=', 'usr_perm_module.id')->where('user_id', $id)->get(array('name'));
}
- public function profile ($id) {
- $res = $this->getUser($id, $this->cook);
- return view('pages.site.profile', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
- }
-
- public function editProfile ($id, Request $r) {
- $err = '';
- $suc = '';
-
- if (isset($r->submit)) {
- if (!is_null($r->password)) {
- if ($r->password != $r->password_check) $err = '「パスワード」と「パスワード確認」が異なります。';
- else {
- $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
- $passwd = hash('sha256', $r->password . $salt);
- for ($round = 0; $round < 65536; $round++) { $passwd = hash('sha256', $passwd . $salt); }
- $eduserp = DB::table('users')->where('id', $id)->update(['password' => $passwd, 'salt' => $salt]);
- if (!$eduserp) $err = 'パスワードの編集失敗。';
- }
- }
-
- $cheml = DB::table('users')->select('email')->where('id', $id)->first();
-
- if ($err == '') {
- if ($cheml->email != $r->email) {
- $exeml = DB::table('users')->select('email')->where('email', $r->email)->count();
- if ($exeml > 0) $err = '入力したメールアドレスはもう存在しています。';
- else {
- $edusere = DB::table('users')->where('id', $id)->update(['email' => $r->email]);
- if (!$edusere) $err = 'メールアドレスの編集失敗。';
- }
- }
- }
-
- if ($err == '') {
- $p = DB::table('usr_profile')->select('display_name', 'country', 'gender')->where('user_id', $id)->first();
- $edprofile = 1;
- if ($p->display_name != $r->display_name || $p->country != $r->country || $p->gender != $r->gender) {
- $edprofile = DB::table('usr_profile')->where('user_id', $id)->update([
- 'display_name' => $r->display_name,
- 'country' => $r->country,
- 'gender' => $r->gender
- ]);
- }
-
- if (!$edprofile) $err = '表示名、お国、又は性別の編集失敗。';
- else $suc = '編集しました!';
- }
- }
-
- if ($this->user) {
- $res = $this->getUser($id, $this->cook);
- $cnt = $this->getCountries();
- return view('pages.site.profileedit', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'suc' => $suc, 'err' => $err, 'cnt' => $cnt]);
- }
-
- return redirect('');
- }
-
- public function login (Request $r) {
- if (isset($_COOKIE['kero_token'])) return redirect('');
- $res = array();
- $err = '';
-
- if (isset($r->username) && isset($r->password)) {
- $res = $this->objAuth->login($r);
- if (isset($res['kero_token'])) return redirect('');
- $err = $res['err'];
- }
-
- return view('pages.site.login', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err]);
- }
-
- public function register (Request $r) {
- if (isset($_COOKIE['kero_token'])) return redirect('');
- $res = $this->getCountries();
- $err = '';
-
- if (isset($r->username) && isset($r->password) && isset($r->email) && isset($r->password_check)) {
- $reg = $this->objAuth->register($r);
- if (isset($reg['kero_token'])) return redirect('');
- $err = $reg['err'];
- }
-
- return view('pages.site.register', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user, 'err' => $err]);
- }
-
- public function getNotification (Request $r) { // /api/rpc/user/notification/get
- $check = $this->objAuth->checkLegit($r->kero_token);
- $res = null;
-
- if ($check != 0) {
- if (Cache::has('getNotification')) $get = Cache::get('getNotification');
- else {
- $get = DB::table('usr_notification')->select('id', 'app_id', 'text', 'section', 'goto')->where('user_id', $check)->get();
- $res = array();
-
- foreach ($get as $g) {
- $prot = DB::table('sys_settings')->select('protocol')->first()->protocol;
- $goto = DB::table('sys_apps')->select('url')->where('id', $g->app_id)->first()->url;
-
- $res[] = array('id' => $g->id, 'text' => $g->text, 'url' => 'http'.($prot == 1 ? 's' : '').'://'.$goto.'/#/'.$g->section);
- Cache::put('getNotification', $get);
- }
- }
-
- return $res;
- }
- else return array();
- }
-
- public function addNotification(Request $r, $uid, $aid, $txt, $sec, $goto) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check != 0) {
- $add = DB::table('usr_notification')->insert(['user_id' => $uid, 'app_id' => $aid, 'text' => $txt, 'section' => $sec, 'goto' => $goto]);
- if (Cache::has('getNotification')) Cache::forget('getNotification');
- return 1;
- }
- }
-
- public function delNotification(Request $r) {
- $check = $this->objAuth->checkLegit($r->kero_token);
-
- if ($check != 0) {
- $del = DB::table('usr_notification')->where('id', $r->id)->where('user_id', $check)->delete();
- if (Cache::has('getNotification')) Cache::forget('getNotification');
- return $del;
- }
+ function getGroupColours() {
+ return DB::table('usr_perm_module')->select('id', 'colour_m', 'colour_f', 'colour_u')->get();
}
}
diff --git a/app/Http/Controllers/Video/Game.php b/app/Http/Controllers/Video/Game.php
new file mode 100644
index 0000000..4086473
--- /dev/null
+++ b/app/Http/Controllers/Video/Game.php
@@ -0,0 +1,21 @@
+menu = $m;
+ $this->user = $u;
+ }
+
+ public function index () {
+ $res = DB::table('vid_game')->get();
+ if (!$res) return notfound($this->menu, $this->user, $res);
+ return view('pages.site.video.game', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+}
diff --git a/app/Http/Controllers/Video/Prayer.php b/app/Http/Controllers/Video/Prayer.php
new file mode 100644
index 0000000..8ae4f24
--- /dev/null
+++ b/app/Http/Controllers/Video/Prayer.php
@@ -0,0 +1,95 @@
+menu = $m;
+ $this->cook = $c;
+ $this->user = $u;
+ }
+
+ public function index ($vid) {
+ $res = DB::table('vid_video')->where('vid', $vid)->first();
+ $game = DB::table('vid_game')->where('id', $res->game_id)->first();
+
+ $res->gametitle = explode('】', $res->title);
+ $res->title = $res->gametitle[1];
+ $res->gametitle = $res->gametitle[0];
+ $res->gametitle = str_replace('【'.$game->name, '', $res->gametitle);
+ $res->mgametitle = $game->name;
+ $slugger = $res->vid;
+ $res->slug = $game->slug;
+ $res->pageslug = $vid;
+
+ if ($res->gametitle == '') $res->gametitle = '初代';
+
+ $comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray();
+ $ytslug = explode('?v=', $res->youtube);
+ $res->ytcomment = $this->getYouTubeCome($ytslug[1]);
+ $res->nicocomment = array();
+ $res->bccomment = array();
+
+ foreach ($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($comments[$k]);
+ }
+ else {
+ unset($c->email);
+ unset($c->ipaddress);
+ unset($c->isShadow);
+ $c->created = date('Y年m月d日 H:i:s', $c->created);
+ }
+ }
+
+ $res->user = userDetail(null, $this->cook);
+ $res->comments = $comments;
+
+ if (!$res) return notfound($this->menu, $this->user, $res);
+ return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+
+ function getYouTubeCome ($slug) {
+ $ch = curl_init();
+ $url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API');
+
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+ $get = curl_exec($ch);
+ curl_close($ch);
+
+ $come = array();
+ $get = json_decode($get, false);
+ if (isset($get->error)) return array();
+
+ foreach ($get->items as $g) {
+ $g->comment = new \stdClass();
+ $g->comment->id = $g->id;
+ $g->comment->name = $g->snippet->topLevelComment->snippet->authorDisplayName;
+ $g->comment->channel = $g->snippet->topLevelComment->snippet->authorChannelUrl;
+ $g->comment->icon = $g->snippet->topLevelComment->snippet->authorProfileImageUrl;
+ $g->comment->created = date('Y年m月d日 H:i:s', strtotime($g->snippet->topLevelComment->snippet->publishedAt));
+ $g->comment->message = $g->snippet->topLevelComment->snippet->textDisplay;
+
+ $come[] = $g->comment;
+ }
+
+ return $come;
+ }
+}
diff --git a/app/Http/Controllers/Video/VideoTable.php b/app/Http/Controllers/Video/VideoTable.php
new file mode 100644
index 0000000..4b7370f
--- /dev/null
+++ b/app/Http/Controllers/Video/VideoTable.php
@@ -0,0 +1,32 @@
+menu = $m;
+ $this->user = $u;
+ }
+
+ public function index ($slug) {
+ $slg = DB::table('vid_game')->select('id', 'name')->where('slug', $slug)->first();
+ $res = DB::table('vid_video')->where('game_id', $slg->id)->orderBy('id', 'desc')->get();
+
+ foreach ($res as $r) {
+ $r->gametitle = explode('】', $r->title);
+ $r->title = $r->gametitle[1];
+ $r->gametitle = $r->gametitle[0];
+ $r->gametitle = str_replace('【'.$slg->name, '', $r->gametitle);
+
+ if ($r->gametitle == '') $r->gametitle = '初代';
+ }
+
+ if (!$res) return notfound($this->menu, $this->user, $res);
+ return view('pages.site.video.videotable', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ }
+}
diff --git a/app/Http/Controllers/VideoController.php b/app/Http/Controllers/VideoController.php
index b0c1381..362bb45 100644
--- a/app/Http/Controllers/VideoController.php
+++ b/app/Http/Controllers/VideoController.php
@@ -1,134 +1,42 @@
objAuth = new AuthController();
$this->objUser = new UserController();
$this->menu = getPagesInMenu();
$this->cook = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
- $this->id = $this->objAuth->checkLegit($this->cook);
+ $this->id = checkLegit($this->cook);
$this->user = $this->objUser->getLoggedUser($this->id, $this->cook);
}
public function index () {
- $res = DB::table('vid_game')->get();
-
- foreach ($res as $r) {
- $p = DB::table('vid_platform')->where('id', $r->platform_id)->first();
- $r->name = $r->name.'('.$p->name.')';
- }
-
- return view('pages.site.video.game', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ $r = new Game($this->menu, $this->user);
+ return $r->index();
}
public function table ($slug) {
- $slg = DB::table('vid_game')->select('id', 'name')->where('slug', $slug)->first();
- $res = DB::table('vid_video')->where('game_id', $slg->id)->orderBy('id', 'desc')->get();
-
- foreach ($res as $r) {
- $r->gametitle = explode('】', $r->title);
- $r->title = $r->gametitle[1];
- $r->gametitle = $r->gametitle[0];
- $r->gametitle = str_replace('【'.$slg->name, '', $r->gametitle);
-
- if ($r->gametitle == '') $r->gametitle = '初代';
- }
-
- return view('pages.site.video.videotable', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
+ $r = new VideoTable($this->menu, $this->user);
+ return $r->index($slug);
}
public function prayer ($vid) {
- $res = DB::table('vid_video')->where('vid', $vid)->first();
- $game = DB::table('vid_game')->where('id', $res->game_id)->first();
-
- $res->gametitle = explode('】', $res->title);
- $res->title = $res->gametitle[1];
- $res->gametitle = $res->gametitle[0];
- $res->gametitle = str_replace('【'.$game->name, '', $res->gametitle);
- $res->mgametitle = $game->name;
- $slugger = $res->vid;
- $res->slug = $game->slug;
- $res->pageslug = $vid;
-
- if ($res->gametitle == '') $res->gametitle = '初代';
-
- $comments = DB::table('blg_comments')->where('video_id', $vid)->orderBy('id', 'asc')->get()->toArray();
- $ytslug = explode('?v=', $res->youtube);
- $res->ytcomment = $this->getYouTubeCome($ytslug[1]);
- $res->nicocomment = array();
- $res->bccomment = array();
-
- foreach ($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($comments[$k]);
- }
- else {
- unset($c->email);
- unset($c->ipaddress);
- unset($c->isShadow);
- $c->created = date('Y年m月d日 H:i:s', $c->created);
- }
- }
-
- $res->user = userDetail(null, $this->cook);
- $res->comments = $comments;
-
- return view('pages.site.video.prayer', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
- }
-
- function getYouTubeCome ($slug) {
- $ch = curl_init();
- $url = 'https://www.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&moderationStatus=published&videoId='.$slug.'&key='.env('YOUTUBE_API');
-
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- $get = curl_exec($ch);
- curl_close($ch);
-
- $come = array();
- $get = json_decode($get, false);
- if (isset($get->error)) return array();
-
- foreach ($get->items as $g) {
- $g->comment = new \stdClass();
- $g->comment->id = $g->id;
- $g->comment->name = $g->snippet->topLevelComment->snippet->authorDisplayName;
- $g->comment->channel = $g->snippet->topLevelComment->snippet->authorChannelUrl;
- $g->comment->icon = $g->snippet->topLevelComment->snippet->authorProfileImageUrl;
- $g->comment->created = date('Y年m月d日 H:i:s', strtotime($g->snippet->topLevelComment->snippet->publishedAt));
- $g->comment->message = $g->snippet->topLevelComment->snippet->textDisplay;
-
- $come[] = $g->comment;
- }
-
- return $come;
+ $r = new Prayer($this->menu, $this->cook, $this->user);
+ return $r->index($vid);
}
}
diff --git a/app/Http/Controllers/VpsController.php b/app/Http/Controllers/VpsController.php
deleted file mode 100644
index 10e55b2..0000000
--- a/app/Http/Controllers/VpsController.php
+++ /dev/null
@@ -1,54 +0,0 @@
-objAuth->checkLegit($r->kero_token);
-
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($r->kero_token);
-
- if ($valid['vps_list'] == 1) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://api.gmocloud.com/jp002/?Action=listNodes&AccessKeyId=HWWS0VHL1QJO59F0MK3E&Version=1.0' );
- // curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
- curl_setopt($ch, CURLOPT_TIMEOUT, 30 );
- // curl_setopt($ch, CURLOPT_POSTFIELDS, array(); );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE );
-
- $res = curl_exec($ch);
- return $res;
- // 'https://api.gmocloud.com/jp002/?Action=listNodes&AccessKeyId=HWWS0VHL1QJO59F0MK3E&Version=1.0'
- }
- else {
- return 'Permission denied.';
- }
- }*/
- }
-
- public function serverView (Request $r) { // /api/rpc/vps/server/view
- }
-
- public function domainList (Request $r) { // /api/rpc/vps/domain/list
- // 許可確認
- // OpenProviderかjp-domainかお名前?
- // 受け取り
- // リターン
- }
-
- public function domainView (Request $r) { // /api/rpc/vps/domain/view
- }
-}
diff --git a/app/helpers.php b/app/helpers.php
index d577c8c..6cc2ab1 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -23,6 +23,12 @@ function getIp () {
return $ip;
}
+function checkLegit ($t) {
+ if (!isset($t) || empty($t) || is_null($t)) return 0;
+ $check = DB::table('users')->select('id')->where('kero_token', $t)->first();
+ return $check->id;
+}
+
function userDetail ($id, $kero=null) {
if ($kero || $id) {
$log_username = null;
@@ -56,4 +62,8 @@ function userDetail ($id, $kero=null) {
return array();
}
+function notfound ($m, $u, $r) {
+ return view('pages.site.notfound', ['res' => $r, 'menu' => $m, 'user', $u]);
+}
+
?>
diff --git a/routes/view/site.php b/routes/view/site.php
index 47f6cd7..5ac1697 100644
--- a/routes/view/site.php
+++ b/routes/view/site.php
@@ -1,10 +1,14 @@