Pulled lots of code from the frontend. #6
|
@ -7,7 +7,18 @@ use Illuminate\Http\Request;
|
||||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use App\Http\Controllers\UserController;
|
||||||
|
use App\Http\Controllers\PermissionController;
|
||||||
|
|
||||||
class BoardController extends Controller {
|
class BoardController extends Controller {
|
||||||
|
private $objUser;
|
||||||
|
private $objPermission;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->objUser = new UserController();
|
||||||
|
$this->objPermission = new PermissionController();
|
||||||
|
}
|
||||||
|
|
||||||
public function getCategories() { // /api/rpc/board/category/getcategories
|
public function getCategories() { // /api/rpc/board/category/getcategories
|
||||||
return DB::table('for_category')
|
return DB::table('for_category')
|
||||||
->select('*')
|
->select('*')
|
||||||
|
@ -351,4 +362,180 @@ class BoardController extends Controller {
|
||||||
'delreason' => ''
|
'delreason' => ''
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function 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;
|
||||||
|
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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),
|
||||||
|
'lock' => $glock,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function 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);
|
||||||
|
else $uid = $this->getUserPost($id);
|
||||||
|
$udat = array();
|
||||||
|
$key = 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;
|
||||||
|
|
||||||
|
array_push($udat, [
|
||||||
|
'key' => $key,
|
||||||
|
'id' => $i->id,
|
||||||
|
'tid' => $i->top_id,
|
||||||
|
'uid' => $i->user_id,
|
||||||
|
'post_date' => date('Y/m/d, G:i:s T', $i->post_date),
|
||||||
|
'message' => $i->message,
|
||||||
|
'delete' => $i->delete,
|
||||||
|
'delreason' => $i->delreason,
|
||||||
|
'lastedit' => date('Y/m/d, G:i:s T', $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,
|
||||||
|
'showcol' => $showCol,
|
||||||
|
'showname' => $showName,
|
||||||
|
'showgroup' => $showGroupName,
|
||||||
|
'country' => $i->country,
|
||||||
|
]);
|
||||||
|
$key++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign group names.
|
||||||
|
return $udat;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ use Tymon\JWTAuth\Facades\JWTAuth;
|
||||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||||
|
|
||||||
class UserController extends Controller {
|
class UserController extends Controller {
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
// User
|
// User
|
||||||
public function getUsers() { // /api/rpc/user/user/getusers
|
public function getUsers() { // /api/rpc/user/user/getusers
|
||||||
return DB::table('users')
|
return DB::table('users')
|
||||||
|
|
|
@ -49,4 +49,9 @@ Route::get('/api/rpc/board/post/getfirstandlastposts/{top_id}', 'BoardController
|
||||||
Route::post('/api/rpc/board/post/addpost', 'BoardController@addPost');
|
Route::post('/api/rpc/board/post/addpost', 'BoardController@addPost');
|
||||||
Route::post('/api/rpc/board/post/editpost', 'BoardController@editPost');
|
Route::post('/api/rpc/board/post/editpost', 'BoardController@editPost');
|
||||||
Route::post('/api/rpc/board/post/deletepost', 'BoardController@deletePost');
|
Route::post('/api/rpc/board/post/deletepost', 'BoardController@deletePost');
|
||||||
Route::post('/api/rpc/board/post/undeletepost', 'BoardController@undeletePost');
|
Route::post('/api/rpc/board/post/undeletepost', 'BoardController@undeletePost');
|
||||||
|
|
||||||
|
// Compiled routes.
|
||||||
|
Route::get('/api/rpc/board/browse/browsetopicinfo/{tp}/{id}/{to}', 'BoardController@browseTopicInfo');
|
||||||
|
Route::get('/api/rpc/board/browse/browsetopicposts/{tp}/{id}/{from}/{to}', 'BoardController@browseTopicPosts');
|
||||||
|
Route::get('/api/rpc/board/browse/browsepermissions/{uid}', 'BoardController@browsePermissions');
|
新しいイシューから参照