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, $username, $password) {
$check = $this->objAuth->checkLegit($username, $password);
if ($check == 0) {
$yetToRead = false;
}
else {
$valid = $this->objAuth->getPermissions($username, $password);
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 $r) {
$yetToRead = false;
$rid = 0;
if ($for != 0) {
$rid = $r->id;
}
else {
$rid = $r['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;
}
else {
$yetToRead = false;
}
}
}
}
}
else {
$yetToRead = false;
}
}
return $yetToRead;
}
public function readTopic(Request $request) { // /api/rpc/board/topic/read
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Guests can\'t read';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_canview']) {
$getRead = DB::table('for_read')
->select('view_time')
->where('user_id', $check)
->where('top_id', $request->top_id)
->first();
$getPost = DB::table('for_posts')
->select('post_date')
->where('top_id', $request->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', $request->top_id)
->update([
'view_time' => $getPost->post_date
]);
return 'Read.';
}
return '';
}
else {
return 'Permission denied.';
}
}
}
public function addCategory(Request $request) { // /api/rpc/board/category/add
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_catmod'] == 1) {
$add = DB::table('for_category')
->insertGetId([
'title' => $request->title,
'order' => $request->order
]);
return $add;
}
else {
return 'Permission denied.';
}
}
}
public function editCategory(Request $request) { // /api/rpc/board/category/edit
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_catmod'] == 1) {
return DB::table('for_category')
->where('id', $request->id)
->update([
'id' => $request->id,
'title' => $request->title
]);
}
}
}
public function deleteCategory(Request $request) { // /api/rpc/board/category/delete
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_catmod'] == 1) {
return DB::table('for_category')->where('id', $request->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 getBookmarks(Request $request) { // /api/rpc/board/forum/getbookmarks
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return '';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_canview'] == 1) {
$for = DB::table('for_bookmarks')
->join('for_forums', 'for_forums.id', 'for_bookmarks.for_id')
->join('for_category', 'for_forums.cat_id', 'for_category.id')
->where('for_bookmarks.user_id', $check)
->get(array(
'for_forums.id as fid',
'for_forums.title as ftitle',
'for_category.title as fctitle'
));
$top = DB::table('for_bookmarks')
->join('for_threads', 'for_threads.id', 'for_bookmarks.top_id')
->where('for_bookmarks.user_id', $check)
->get(array(
'for_threads.id as tid',
'for_threads.title as ttitle'
));
$forS = array();
foreach($for as $f) {
$read = $this->checkRead($f->fid, 0, $request->username, $request->password);
$forS[] = array(
'id' => $f->fid,
'type' => 'forum',
'title' => $f->fctitle.'/'.$f->ftitle,
'read' => $read
);
}
foreach($top as $t) {
$read = $this->checkRead(0, $t->tid, $request->username, $request->password);
$forS[] = array(
'id' => $t->tid,
'type' => 'topic',
'title' => $t->ttitle,
'read' => $read
);
}
return $forS;
}
else {
return 'Permission denied!';
}
}
}
public function addBookmark(Request $request) { // /api/rpc/board/forum/addbookmark
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return '';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_editown'] == 1) {
DB::table('for_bookmarks')
->insert([
'user_id' => $check,
'for_id' => $request->for_id,
'top_id' => $request->top_id
]);
return 'Success!';
}
else {
return 'Permission denied!';
}
}
}
public function delBookmark(Request $request) { // /api/rpc/board/forum/delbookmark
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return '';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_editown'] == 1) {
if (isset($request->for_id)) {
DB::table('for_bookmarks')
->where('user_id', $check)
->where('for_id', $request->for_id)
->delete();
return 'Success!';
}
else if (isset($request->top_id)) {
$res = DB::table('for_bookmarks')
->where('user_id', $check)
->where('top_id', $request->top_id)
->delete();
return 'Success!';
}
else {
return 'Cannot do that.';
}
}
else {
return 'Permission denied!';
}
}
}
public function addForum(Request $request) { // /api/rpc/board/forum/add
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_formod'] == 1) {
$add = DB::table('for_forums')
->insertGetId([
'last_uid' => 0,
'cat_id' => $request->cat_id,
'title' => $request->title,
'description' => $request->description,
'threads' => 0,
'posts' => 0,
'last_date' => 0,
'min_power' => 0,
'permission' => 0,
'readonly' => $request->ro,
'post_count_freeze' => $request->pcf,
'order' => $request->order,
'parent' => 0
]);
return $add;
}
else {
return 'Permission denied.';
}
}
}
public function editForum(Request $request) { // /api/rpc/board/forum/edit
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_formod'] == 1) {
return DB::table('for_forums')
->where('id', $request->id)
->update([
'cat_id' => $request->cat_id,
'title' => $request->title,
'description' => $request->description,
'readonly' => $request->ro,
'post_count_freeze' => $request->pcf
]);
}
}
}
public function deleteForum(Request $request) { // /api/rpc/board/forum/delete
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_formod'] == 1) {
return DB::table('for_forums')->where('id', $request->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')
->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,
'uid' => $tid->uid,
'date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($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 $request) {
$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($request->username, $request->password);
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 $request) { // /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',
'postcount',
'username',
'perm_id',
'total_posts',
'header',
'footer',
'member_title',
'gender',
'avatar',
'name_style',
'display_name',
'country'
);
$valid = $this->objAuth->getPermissions($request->username, $request->password);
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 $request) { // /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',
'postcount',
'username',
'perm_id',
'total_posts',
'header',
'footer',
'member_title',
'gender',
'avatar',
'name_style',
'display_name',
'country'
);
$valid = $this->objAuth->getPermissions($request->username, $request->password);
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 $request) { // /api/rpc/board/topic/addtopic
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_post'] == 1) {
$addTopic = DB::table('for_threads')
->insertGetId([
'for_id' => $request->for_id,
'title' => $request->title,
'started_by' => $request->user_id,
'replies' => 0,
'views' => 0,
'last_date' => time(),
'last_uid' => $request->user_id,
'sticky' => 0,
'lock' => 0,
'poll' => 0,
'read' => '',
'lang_id' => 1
]);
DB::table('for_posts')
->insert([
'top_id' => $addTopic,
'user_id' => $request->user_id,
'post_date' => time(),
'message' => $request->message,
'delete' => 0,
'lastedit' => 0,
'ipaddress' => $request->ipaddress,
'delreason' => '',
'nolayout' => $request->nolayout,
'postcount' => $request->postcount,
// Deprecated: remove like and read stuff after full release!
'likes' => 0,
'likers' => '',
'read' => ''
]);
return $addTopic;
}
else {
return 'Permission denied.';
}
}
}
public function addPost(Request $request) { // /api/rpc/board/post/addpost
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_post'] == 1) {
$add = DB::table('for_posts')
->insert([
'top_id' => $request->top_id,
'user_id' => $request->user_id,
'post_date' => $request->post_date,
'message' => $request->message,
'delete' => 0,
'lastedit' => 0,
'ipaddress' => $request->ipaddress,
'delreason' => '',
'nolayout' => $request->nolayout,
'postcount' => $request->postcount,
// Deprecated: remove like and read stuff after full release!
'likes' => 0,
'likers' => '',
'read' => ''
]);
return \Response::json($add);
}
else {
return 'Permission denied.';
}
}
}
public function editPost(Request $request) { // /api/rpc/board/post/editpost
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_editother'] == 1 || $valid['for_editown'] == 1) { // TODO: differenciate own from other.
return DB::table('for_posts')
->where('id', $request->id)
->update([
'lastedit' => $request->lastedit,
'message' => $request->message,
'nolayout' => $request->nolayout
]);
}
}
}
public function deletePost(Request $request) { // /api/rpc/board/post/deletepost
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_del'] == 1) {
return DB::table('for_posts')
->where('id', $request->id)
->update([
'delete' => 1,
'delreason' => $request->delreason
]);
}
}
}
public function lockTopic(Request $request) { // /api/rpc/board/topic/lock
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_locky'] == 1) {
return DB::table('for_threads')
->where('id', $request->id)
->update([
'lock' => 1
]);
}
else {
return 'Permission denied.';
}
}
}
public function unlockTopic(Request $request) { // /api/rpc/board/topic/unlock
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_locky'] == 1) {
return DB::table('for_threads')
->where('id', $request->id)
->update([
'lock' => 0
]);
}
else {
return 'Permission denied.';
}
}
}
public function moveTopic(Request $request) { // /api/rpc/board/topic/move
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_move'] == 1) {
DB::table('for_forums')
->where('id', $request->old_id)
->decrement('threads', 1);
DB::table('for_forums')
->where('id', $request->old_id)
->decrement('posts', 1);
DB::table('for_forums')
->where('id', $request->new_id)
->increment('threads', 1);
DB::table('for_forums')
->where('id', $request->new_id)
->increment('posts', 1);
$getLastTopic = DB::table('for_threads')
->select('last_date', 'last_uid')
->where('for_id', $request->old_id)
->orderBy('last_date', 'desc')
->offset(1)
->limit(1)
->get();
$getCurrentTopic = DB::table('for_threads')
->select('last_date', 'last_uid')
->where('for_id', $request->old_id)
->orderBy('last_date', 'desc')
->offset(0)
->limit(1)
->get();
// Old forum.
DB::table('for_forums')
->where('id', $request->old_id)
->update([
'last_uid' => $getLastTopic[0]->last_uid,
'last_date' => $getLastTopic[0]->last_date
]);
DB::table('for_threads')
->where('id', $request->id)
->update([
'for_id' => $request->new_id
]);
// New forum.
DB::table('for_forums')
->where('id', $request->new_id)
->update([
'last_uid' => $getCurrentTopic[0]->last_uid,
'last_date' => $getCurrentTopic[0]->last_date
]);
return 'Success';
}
else {
return 'Permission denied.';
}
}
}
public function bookmarkForum(Request $request) { // /api/rpc/board/forum/bookmark
/* $check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_canview'] == 1) {
return DB::table('for_forums')
->where('id', $request->id)
->update([
'delete' => 0,
'delreason' => ''
]);
}
} */
}
public function bookmarkTopic(Request $request) { // /api/rpc/board/topic/bookmark
/* $check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_canview'] == 1) {
return DB::table('for_threads')
->where('id', $request->id)
->update([
'delete' => 0,
'delreason' => ''
]);
}
} */
}
public function splitPost(Request $request) { // /api/rpc/board/post/split
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_split'] == 1) {
$add = DB::table('for_threads')
->insertGetId([
'for_id' => $request->forId,
'title' => $request->title,
'started_by' => $request->uid,
'replies' => 0,
'views' => 0,
'last_date' => $request->dtime,
'last_uid' => $request->uid,
'sticky' => $request->sticky,
'poll' => 0,
'read' => '',
'lock' => $request->lock
]);
DB::table('for_posts')
->where('id', $request->id)
->update([
'top_id' => $add,
]);
return 'Success!';
}
else {
return 'Permission denied.';
}
}
}
public function mergeTopic(Request $request) { // /api/rpc/board/topic/merge
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_mergepost'] == 1) {
DB::table('for_posts')
->where('top_id', $request->id)
->update([
'top_id' => $request->alt_id
]);
DB::table('for_threads')
->where('id', $request->id)
->delete();
return 'Success!';
}
else {
return 'Permission denied.';
}
}
}
public function pinTopic(Request $request) { // /api/rpc/board/topic/pin
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_sticky'] == 1) {
return DB::table('for_threads')
->where('id', $request->id)
->update([
'sticky' => 1
]);
}
else {
return 'Permission denied.';
}
}
}
public function unpinTopic(Request $request) { // /api/rpc/board/topic/unpin
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_sticky'] == 1) {
return DB::table('for_threads')
->where('id', $request->id)
->update([
'sticky' => 0
]);
}
}
}
public function getReadCategories (Request $request) { // /api/rpc/board/topic/getreadcategories
}
public function getReadForums (Request $request) { // /api/rpc/board/topic/getreadforums
}
public function getReadTopics (Request $request) { // /api/rpc/board/topic/getreadtopics
$check = $this->objAuth->checkLegit($request->username, $request->password);
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 $request) { // /api/rpc/board/topic/markforumread/fid
}
public function markTopicRead ($id, Request $request) { // /api/rpc/board/topic/marktopicread/tid
}
public function undeletePost(Request $request) { // /api/rpc/board/post/undeletepost
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_del'] == 1) {
return DB::table('for_posts')
->where('id', $request->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 $request) { // /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, $request->username, $request->password);
$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'], $request)->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 $request) { // /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, $request->username, $request->password);
$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'], $request)->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
}
public function browseTopics($mode, $id, $from, $to, Request $request) { // /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, $request->username, $request->password);
$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'], $request)->toArray();
$userLast = $this->objUser->getUser($fplp['last']['uid'], $request)->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', date($userFD)),
't_last_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($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 == 0) $glock = false;
else $glock = true;
// Is this topic pinned?
if ($tp == 't') $tpin = $this->getTopicPin($id);
else $tpin = $this->getTopicPin($tid);
$gpin = false;
if ($tpin[0]->sticky == 0) $gpin = false;
else $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
);
}
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
);
}
}
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 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',
);
$replace = array(
'$1',
'$1',
'$1',
'$1',
'$1',
'$1',
'',
'',
'',
'',
'',
'
Posted by \'$1\'', '
$3
Posted by \'$1\'', '
$2
', '
$1
|