objAuth = new AuthController(); } // User public function getUsersOnline() { // /api/rpc/user/user/getusersonline $time = time(); $past = $time - 10; $static = $time + 1; $timeout = $time - $past; return DB::table('users') ->join('usr_details', 'usr_details.user_id', '=', 'users.id') ->join('usr_profile', 'usr_profile.user_id', '=', 'users.id') ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'users.id') ->where('ostatus', '!=', '4') ->where('ontime', '>', $timeout) ->get(array( 'id', 'username', 'perm_id', 'email', 'reg_date', 'gender', 'ip_address', 'avatar', 'name_style', 'display_name', 'country', 'ostatus', 'ontime' )); } public function updateUserOnline(Request $request) { // /api/rpc/user/user/updateuseronline return DB::table('usr_details') ->where('user_id', $request->user_id) ->update([ 'ontime' => time() ]); } public function getUsers(Request $request) { // /api/rpc/user/user/getusers $getting = array( 'users.id', 'username', 'perm_id', 'reg_date', 'gender', 'avatar', 'name_style', 'display_name', 'country' ); $valid = $this->objAuth->getPermissions($request->username, $request->password); if ($valid['usr_emailshow'] == 1) { array_push($getting, 'email'); } if ($valid['usr_ipshow'] == 1) { array_push($getting, 'ip_address'); } return DB::table('users') ->join('usr_details', 'usr_details.user_id', '=', 'users.id') ->join('usr_profile', 'usr_profile.user_id', '=', 'users.id') ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'users.id') ->get($getting); } public function getUser($id, Request $request) { // /api/rpc/user/user/getuser/id/uid $getting = array( 'users.id', 'users.username', 'usr_perm_id.perm_id', 'usr_profile.member_title', 'usr_details.reg_date', 'usr_contacts.website_link', 'usr_contacts.website_name', 'usr_profile.gender', 'usr_profile.location', 'usr_profile.birthday', 'usr_profile.bio', 'usr_profile.avatar', 'usr_profile.name_style', 'usr_profile.display_name', 'usr_profile.country', 'usr_contacts.website_link', 'usr_contacts.website_name', 'usr_contacts.youtube_link', 'usr_contacts.youtube_name', 'usr_contacts.niconico', 'usr_contacts.pixiv', 'usr_contacts.discord', 'usr_contacts.mastodon', 'usr_contacts.twitter' ); $valid = $this->objAuth->getPermissions($request->username, $request->password); if ($valid['usr_emailshow'] == 1) { array_push($getting, 'email'); } if ($valid['usr_ipshow'] == 1) { array_push($getting, 'ip_address'); } if ($valid['usr_canwarn'] == 1) { array_push($getting, 'strikes'); } return DB::table('users') ->join('usr_details', 'usr_details.user_id', '=', 'users.id') ->join('usr_profile', 'usr_profile.user_id', '=', 'users.id') ->join('usr_contacts', 'usr_contacts.user_id', '=', 'users.id') ->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'users.id') ->where('id', $id) ->get($getting); } public function getExist($username, $email) { // /api/rpc/user/user/getexist/username/email $isExist = DB::table('users') ->select('username', 'email') ->where('username', mb_strtolower($username)) ->orWhere('email', mb_strtolower($email)) ->get(); return $isExist->count(); } public function getPostStyle($id) { // /api/rpc/user/user/getpoststyle/id return DB::table('users') ->select('header', 'footer') ->where('id', $id) ->get(); } public function getGroupName($id) { // /api/rpc/user/user/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', // 'badge' (this is a pipeline feature, please don't uncomment for now!) )); } public function getGroupColours() { // /api/rpc/user/user/getgroupcolours return DB::table('usr_perm_module') ->select( 'id', 'colour_m', 'colour_f', 'colour_u' ) ->get(); } // Owner public function getOwnerList() { // /api/rpc/user/owner/getownerlist $user_data = DB::table('users') ->join('usr_profile', 'usr_profile.user_id', '=', 'users.id') ->orderBy('id', 'asc') ->get(array('id', 'username', 'display_name')); $result = array(); foreach ($user_data as $u) { $name = ''; if (!empty($u->display_name)) { $name = $u->display_name; } else { $name = $u->username; } array_push($result, [ 'value' => $u->id, 'label' => $name, ]); } return $result; } public function countOwnersOfEntry($file_id) { // /api/rpc/user/owner/countownersofentry/id return DB::table('str_owners') ->where('file_id', $file_id) ->count(); } public function getOwnersOfEntry($file_id) { // /api/rpc/user/owner/getownersofentry/id 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', $file_id) ->get(array( 'users.id', 'title', 'version', 'views', 'downloads', 'submit_date', 'last_date', 'username', 'avatar', 'perm_id', 'gender', 'display_name', 'name_style', )); } public function countEntriesOfOwner($user_id) { // /api/rpc/user/owner/countentriesofowner/id return DB::table('str_owners') ->where('user_id', $user_id) ->count(); } public function getEntriesOfOwner($user_id) { // /api/rpc/user/owner/getentriesofowner/id 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('user_id', $user_id) ->get(array( 'users.id', 'title', 'version', 'views', 'downloads', 'submit_date', 'last_date', 'username', 'avatar', 'perm_id', 'gender', 'display_name', 'name_style', )); } public function getTotalPostCount($id) { // /api/rpc/user/user/gettotalpostcount/id return DB::table('usr_details') ->select('total_posts') ->where('user_id', $id) ->first()->total_posts; } public function getTotalTopicCount($id) { // /api/rpc/user/user/gettotaltopiccount/id return DB::table('usr_details') ->select('total_threads') ->where('user_id', $id) ->first()->total_threads; } public function addOwner(Request $request) { // /api/rpc/user/owner/addowner $check = $this->objAuth->checkLegit($request->username, $request->password); if ($check == 0) { return 'Err!'; } else { $add = DB::table('str_owners') ->insert([ 'user_id' => $request->user_id, 'file_id' => $request->file_id ]); return \Response::json($add); } } public function updateTotalPostCount(Request $request) { // /api/rpc/user/user/updatetotalpostcount $check = $this->objAuth->checkLegit($request->username, $request->password); if ($check == 0) { return 'Err!'; } else { $getPC = $this->getTotalPostCount($request->user_id); $getPC++; return DB::table('usr_details') ->where('user_id', $request->user_id) ->update([ 'total_posts' => $getPC ]); } } public function updateTotalTopicCount(Request $request) { // /api/rpc/user/user/updatetotaltopiccount $check = $this->objAuth->checkLegit($request->username, $request->password); if ($check == 0) { return 'Err!'; } else { $getPC = $this->getTotalPostCount($request->user_id); $getTC = $this->getTotalTopicCount($request->user_id); $getPC++; $getTC++; return DB::table('usr_details') ->where('user_id', $request->user_id) ->update([ 'total_posts' => $getPC, 'total_threads' => $getTC ]); } } }