diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php
index 94525f3..72f8c6a 100644
--- a/app/Http/Controllers/UserController.php
+++ b/app/Http/Controllers/UserController.php
@@ -16,783 +16,829 @@ use Tymon\JWTAuth\Exceptions\JWTException;
use App\Http\Controllers\AuthController;
class UserController extends Controller {
- private $objAuth;
+ private $objAuth;
- public function __construct() {
- $this->objAuth = new AuthController();
- }
+ public function __construct() {
+ $this->objAuth = new AuthController();
+ }
- // User
- public function getUsersOnline() { // /api/rpc/user/user/getusersonline
- $cols = $this->getGroupColours()->toArray();
+ // User
+ public function getUsersOnline() { // /api/rpc/user/user/getusersonline
+ $cols = $this->getGroupColours()->toArray();
- $get = 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')
- ->orderBy('display_name', 'asc')
- ->orderBy('username', 'asc')
- ->get(array(
- 'id',
- 'username',
- 'gender',
- 'perm_id',
- 'avatar',
- 'name_style',
- 'display_name',
- 'ostatus',
- 'ontime'
- ));
+ $get = 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')
+ ->orderBy('display_name', 'asc')
+ ->orderBy('username', 'asc')
+ ->get(array(
+ 'id',
+ 'username',
+ 'gender',
+ 'perm_id',
+ 'avatar',
+ 'name_style',
+ 'display_name',
+ 'ostatus',
+ 'ontime'
+ ));
- $res = array();
+ $res = array();
- foreach ($get as $i) {
- $showName = "";
- $showCol = "";
- $showStatus = "";
- $showAva = "";
+ foreach ($get as $i) {
+ $showName = "";
+ $showCol = "";
+ $showStatus = "";
+ $showAva = "";
- if ($i->display_name !== '') {
- $showName = $i->display_name;
- }
- else {
- $showName = $i->username;
- }
+ if ($i->display_name !== '') {
+ $showName = $i->display_name;
+ }
+ else {
+ $showName = $i->username;
+ }
- if ($i->name_style !== '') {
- $showCol = $i->name_style;
- }
- else {
- foreach($cols as $cl) {
- if ($cl->id === $i->perm_id) {
- if ($i->gender === 1) $showCol = $cl->colour_m;
- else if ($i->gender === 2) $showCol = $cl->colour_f;
- else $showCol = $cl->colour_u;
- }
- }
- }
-
- if ($i->ostatus == 1) {
- $showStatus = "green";
- }
- else if ($i->ostatus == 2) {
- $showStatus = "red";
- }
- else if ($i->ostatus == 3) {
- $showStatus = "yellow";
- }
- else {
- $showStatus = "dark";
- }
-
- if (empty($i->avatar)) {
- $showAva = "assets/avatars/haznoavaz.png";
- }
- else {
- $showAva = $i->avatar;
- }
-
- $res[] = array(
- 'id' => $i->id,
- 'display_name' => $showName,
- 'name_style' => $showCol,
- 'avatar' => $showAva,
- 'status' => $showStatus,
- 'ontime' => $i->ontime
- );
+ if ($i->name_style !== '') {
+ $showCol = $i->name_style;
+ }
+ else {
+ foreach($cols as $cl) {
+ if ($cl->id === $i->perm_id) {
+ if ($i->gender === 1) $showCol = $cl->colour_m;
+ else if ($i->gender === 2) $showCol = $cl->colour_f;
+ else $showCol = $cl->colour_u;
+ }
}
+ }
- return $res;
+ if ($i->ostatus == 1) {
+ $showStatus = "green";
+ }
+ else if ($i->ostatus == 2) {
+ $showStatus = "red";
+ }
+ else if ($i->ostatus == 3) {
+ $showStatus = "yellow";
+ }
+ else {
+ $showStatus = "dark";
+ }
+
+ if (empty($i->avatar)) {
+ $showAva = "assets/avatars/haznoavaz.png";
+ }
+ else {
+ $showAva = $i->avatar;
+ }
+
+ $res[] = array(
+ 'id' => $i->id,
+ 'display_name' => $showName,
+ 'name_style' => $showCol,
+ 'avatar' => $showAva,
+ 'status' => $showStatus,
+ 'ontime' => $i->ontime
+ );
}
- public function updateUserStatus(Request $request) { // /api/rpc/user/user/updateuserstatus
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ return $res;
+ }
- if ($check != 0) {
- return DB::table('usr_profile')
- ->where('user_id', $check)
- ->update([
- 'ostatus' => $request->ostatus
- ]);
- }
+ public function updateUserStatus(Request $request) { // /api/rpc/user/user/updateuserstatus
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
+
+ if ($check != 0) {
+ return DB::table('usr_profile')
+ ->where('user_id', $check)
+ ->update([
+ 'ostatus' => $request->ostatus
+ ]);
+ }
+ }
+
+ public function updateUserOnline(Request $request) { // /api/rpc/user/user/updateuseronline
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
+
+ if ($check != 0) {
+ return DB::table('usr_details')
+ ->where('user_id', $check)
+ ->update([
+ 'ontime' => time()
+ ]);
+ }
+ }
+
+ public function getUsers(Request $request) { // /api/rpc/user/user/getusers
+ $getting = array(
+ 'users.id',
+ 'usr_perm_module.name as group_name',
+ 'users.username',
+ 'usr_perm_id.perm_id',
+ 'usr_details.reg_date',
+ 'usr_profile.gender',
+ 'usr_profile.avatar',
+ 'usr_profile.name_style',
+ 'usr_profile.display_name',
+ 'usr_profile.country'
+ );
+
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
+
+ if ($valid['usr_emailshow'] == 1) {
+ array_push($getting, 'users.email');
}
- public function updateUserOnline(Request $request) { // /api/rpc/user/user/updateuseronline
- $check = $this->objAuth->checkLegit($request->username, $request->password);
-
- if ($check != 0) {
- return DB::table('usr_details')
- ->where('user_id', $check)
- ->update([
- 'ontime' => time()
- ]);
- }
+ if ($valid['usr_ipshow'] == 1) {
+ array_push($getting, 'usr_profile.ip_address');
}
- public function getUsers(Request $request) { // /api/rpc/user/user/getusers
- $getting = array(
- 'users.id',
- 'usr_perm_module.name as group_name',
- 'users.username',
- 'usr_perm_id.perm_id',
- 'usr_details.reg_date',
- 'usr_profile.gender',
- 'usr_profile.avatar',
- 'usr_profile.name_style',
- 'usr_profile.display_name',
- 'usr_profile.country'
- );
+ 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')
+ ->join('usr_perm_module', 'usr_perm_module.id', 'usr_perm_id.perm_id')
+ ->get($getting);
+ }
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
+ public function getUser($id, Request $request) { // /api/rpc/user/user/getuser/id/uid
+ $getting = array(
+ 'users.id',
+ 'users.username',
+ 'usr_perm_module.name as group_name',
+ 'usr_profile.display_name',
+ 'usr_profile.name_style',
+ 'usr_perm_id.perm_id',
+ 'usr_profile.member_title',
+ 'usr_details.total_posts',
+ 'usr_details.total_threads',
+ '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.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'
+ );
- if ($valid['usr_emailshow'] == 1) {
- array_push($getting, 'users.email');
- }
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
+ $cols = $this->getGroupColours()->toArray();
- if ($valid['usr_ipshow'] == 1) {
- array_push($getting, 'usr_profile.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')
- ->join('usr_perm_module', 'usr_perm_module.id', 'usr_perm_id.perm_id')
- ->get($getting);
+ if ($valid['usr_editother'] == 1 || $id == $check) {
+ array_push($getting, 'users.password');
}
- public function getUser($id, Request $request) { // /api/rpc/user/user/getuser/id/uid
- $getting = array(
- 'users.id',
- 'users.username',
- 'usr_perm_module.name as group_name',
- 'usr_profile.display_name',
- 'usr_profile.name_style',
- 'usr_perm_id.perm_id',
- 'usr_profile.member_title',
- 'usr_details.total_posts',
- 'usr_details.total_threads',
- '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.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'
- );
-
- $check = $this->objAuth->checkLegit($request->username, $request->password);
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
- $cols = $this->getGroupColours()->toArray();
-
- if ($valid['usr_editother'] == 1) {
- array_push($getting, 'users.password');
- }
-
- if ($valid['usr_emailshow'] == 1) {
- array_push($getting, 'users.email');
- }
-
- if ($valid['usr_ipshow'] == 1) {
- array_push($getting, 'usr_profile.ip_address');
- }
-
- if ($valid['usr_canwarn'] == 1) {
- array_push($getting, 'usr_details.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')
- ->join('usr_perm_module', 'usr_perm_module.id', 'usr_perm_id.perm_id')
- ->where('users.id', $id)
- ->get($getting);
+ if ($valid['usr_emailshow'] == 1 || $id == $check) {
+ array_push($getting, 'users.email');
}
- 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();
+ if ($valid['usr_ipshow'] == 1 || $id == $check) {
+ array_push($getting, 'usr_profile.ip_address');
}
- public function getPostStyle($id) { // /api/rpc/user/user/getpoststyle/id
- return DB::table('users')
- ->select('header', 'footer')
- ->where('id', $id)
- ->get();
+ if ($valid['usr_canwarn'] == 1 || $id == $check) {
+ array_push($getting, 'usr_details.strikes');
}
- public function getGroups() { // /api/rpc/user/user/getgroups
- return DB::table('usr_perm_module')
- ->select('id', 'name', 'colour_m', 'colour_f', 'colour_u')
- ->get();
+ 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')
+ ->join('usr_perm_module', 'usr_perm_module.id', 'usr_perm_id.perm_id')
+ ->where('users.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 getGroups() { // /api/rpc/user/user/getgroups
+ return DB::table('usr_perm_module')
+ ->select('id', 'name', 'colour_m', 'colour_f', 'colour_u')
+ ->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,
+ ]);
}
- 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!)
- ));
+ 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($check);
+ $getPC++;
+
+ return DB::table('usr_details')
+ ->where('user_id', $check)
+ ->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
+ ]);
+ }
+ }
+
+ public function getCountries() { // /api/rpc/user/user/getcountries
+ $flags = File::files('assets/flags');
+
+ $res = array();
+
+ foreach ($flags as $flag) {
+ $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
+
+ $res[] = array(
+ 'value' => $flag->getBasename('.png'),
+ 'label' => ' '.$flag->getBasename('.png')
+ );
}
- public function getGroupColours() { // /api/rpc/user/user/getgroupcolours
- return DB::table('usr_perm_module')
- ->select(
- 'id',
- 'colour_m',
- 'colour_f',
- 'colour_u'
- )
- ->get();
+ return $res;
+ }
+
+ public function avatarUpload(Request $request) { // /api/rpc/user/user/avatarupload
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
+
+ if ($check == 0) {
+ return 'Err!';
}
+ else {
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
+ $user = 0;
- // 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'));
+ if ($valid['usr_editother'] == 1) $user = $request->id;
+ else $user = $check;
- $result = array();
-
- foreach ($user_data as $u) {
- $name = '';
-
- if (!empty($u->display_name)) {
- $name = $u->display_name;
- }
- else {
- $name = $u->username;
+ if ($valid['usr_editprofile'] == 1) {
+ if (isset($request->filename)) {
+ if (!is_dir("assets/avatars/".$check)) {
+ if (!mkdir("assets/avatars/".$check, 0755, true)) {
+ return "Could not make folder ".$check."
";
}
+ }
- array_push($result, [
- 'value' => $u->id,
- 'label' => $name,
+ $img_dir = "assets/avatars/".$check."/";
+ $image = $img_dir . $request->filename;
+ $imageFileType = array(
+ 'image/png',
+ 'image/jpeg',
+ 'image/gif'
+ );
+
+ if (!in_array($request->filetype, $imageFileType)) {
+ return "Only JPG, PNG, JPEG, and GIF are allowed.";
+ }
+
+ $fname = 'assets/avatars/'.$user.'/'.$request->filename;
+ $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $request->thefile));
+ Storage::disk('public')->put($fname, $data);
+
+ return $request->filename;
+ }
+ }
+ else {
+ return 'Permission denied.';
+ }
+ }
+ }
+
+ public function editUser(Request $request) { // /api/rpc/user/user/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['usr_editprofile'] == 1) {
+ if (isset($request->newPassword)) {
+ DB::table('users')
+ ->where('id', $request->id)
+ ->update([
+ 'password' => $request->newPassword
+ ]);
+ }
+ if (isset($request->email)) {
+ DB::table('users')
+ ->where('id', $request->id)
+ ->update([
+ 'email' => $request->email
]);
}
- return $result;
+ if (
+ isset($request->website_link) ||
+ isset($request->website_name) ||
+ isset($request->youtube_link) ||
+ isset($request->youtube_name) ||
+ isset($request->niconico) ||
+ isset($request->pixiv) ||
+ isset($request->discord) ||
+ isset($request->mastodon) ||
+ isset($request->twitter)
+ ) {
+ DB::table('usr_contacts')
+ ->where('user_id', $request->id)
+ ->update([
+ 'website_link' => ($request->website_link != '' ? $request->website_link : ''),
+ 'website_name' => ($request->website_name != '' ? $request->website_name : ''),
+ 'youtube_link' => ($request->youtube_link != '' ? $request->youtube_link : ''),
+ 'youtube_name' => ($request->youtube_name != '' ? $request->youtube_name : ''),
+ 'niconico' => ($request->niconico != '' ? $request->niconico : ''),
+ 'pixiv' => ($request->pixiv != '' ? $request->pixiv : ''),
+ 'discord' => ($request->discord != '' ? $request->discord : ''),
+ 'mastodon' => ($request->mastodon != '' ? $request->mastodon : ''),
+ 'twitter' => ($request->twitter != '' ? $request->twitter : '')
+ ]);
+ }
+
+ if (isset($request->group) && $valid['usr_editother']) {
+ DB::table('usr_perm_id')
+ ->where('user_id', $request->id)
+ ->update([
+ 'perm_id' => $request->group
+ ]);
+ }
+
+ if (isset($request->avatar)) {
+ DB::table('usr_profile')
+ ->where('user_id', $request->id)
+ ->update([
+ 'avatar' => ($request->avatar != '' ? $request->avatar : '')
+ ]);
+ }
+
+ if (isset($request->avatarRemove)) {
+ if ($request->avatarRemove) {
+ DB::table('usr_profile')
+ ->where('user_id', $request->id)
+ ->update([
+ 'avatar' => ''
+ ]);
+ }
+ }
+
+ if (
+ isset($request->gender) ||
+ isset($request->aboutSelf) ||
+ isset($request->signature) ||
+ isset($request->nameStyle) ||
+ isset($request->displayName) ||
+ isset($request->memberTitle) ||
+ isset($request->birthDay) ||
+ isset($request->country)
+ ) {
+ DB::table('usr_profile')
+ ->where('user_id', $request->id)
+ ->update([
+ 'gender' => $request->gender,
+ 'bio' => ($request->aboutSelf != '' ? $request->aboutSelf : ''),
+ 'signature' => ($request->signature != '' ? $request->signature : ''),
+ 'name_style' => ($request->nameStyle != '' ? $request->nameStyle : ''),
+ 'display_name' => ($request->displayName != '' ? $request->displayName : ''),
+ 'member_title' => ($request->memberTitle != '' ? $request->memberTitle : ''),
+ 'birthday' => ($request->birthDay != 0 ? $request->birthDay : 0),
+ 'country' => $request->country
+ ]);
+ }
+
+ return 'Success!';
+ }
+ else {
+ return 'Permission denied.';
+ }
}
+ }
- public function countOwnersOfEntry($file_id) { // /api/rpc/user/owner/countownersofentry/id
- return DB::table('str_owners')
- ->where('file_id', $file_id)
- ->count();
- }
+ public function countComments($id) { // /api/rpc/user/comment/count/id
+ return DB::table('usr_comments')
+ ->where('profile_id', $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 getComments ($id, Request $request) { // /api/rpc/user/comment/get/id
+ $cols = $this->getGroupColours()->toArray();
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
- public function countEntriesOfOwner($user_id) { // /api/rpc/user/owner/countentriesofowner/id
- return DB::table('str_owners')
- ->where('user_id', $user_id)
- ->count();
- }
+ if ($valid['usr_viewcomment'] == 1) {
+ $come = array();
+ $get = DB::table('usr_comments')
+ ->where('profile_id', $id)
+ ->where('reply_id', 0)
+ ->orderBy('usr_comments.postdate', 'asc')
+ ->get(array(
+ 'usr_comments.id as come_id',
+ 'user_id',
+ 'postdate',
+ 'message',
+ 'isEdit',
+ 'isDel'
+ ));
+ // Foreach, new getter but check on replies, and only if isDel is 0.
+ foreach ($get as $g) {
+ $user = $this->getUser($g->user_id, $request)->toArray();
+ $showName = "";
+ $showCol = "";
- 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!';
+ if ($user[0]->display_name !== '') {
+ $showName = $user[0]->display_name;
}
else {
- $add = DB::table('str_owners')
- ->insert([
- 'user_id' => $request->user_id,
- 'file_id' => $request->file_id
- ]);
-
- return \Response::json($add);
+ $showName = $user[0]->username;
}
- }
- public function updateTotalPostCount(Request $request) { // /api/rpc/user/user/updatetotalpostcount
- $check = $this->objAuth->checkLegit($request->username, $request->password);
-
- if ($check == 0) {
- return 'Err!';
+ if ($user[0]->name_style !== '') {
+ $showCol = $user[0]->name_style;
}
else {
- $getPC = $this->getTotalPostCount($check);
- $getPC++;
-
- return DB::table('usr_details')
- ->where('user_id', $check)
- ->update([
- 'total_posts' => $getPC
- ]);
+ 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;
+ }
+ }
}
+
+ setlocale(LC_ALL, 'ja_JP.utf8');
+
+ $come[] = array(
+ 'come_id' => $g->come_id,
+ 'user_id' => $g->user_id,
+ 'name' => $showName,
+ 'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
+ 'col' => $showCol,
+ 'message' => $g->message,
+ 'postdate' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($g->postdate)),
+ 'isEdit' => $g->isEdit,
+ 'isDel' => $g->isDel
+ );
+ }
+
+ return $come;
}
+ else {
+ return 'Permission denied.';
+ }
+ }
- public function updateTotalTopicCount(Request $request) { // /api/rpc/user/user/updatetotaltopiccount
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ public function getReplies ($id, Request $request) { // /api/rpc/user/comment/reply/id
+ $cols = $this->getGroupColours()->toArray();
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
- if ($check == 0) {
- return 'Err!';
+ if ($valid['usr_viewcomment'] == 1) {
+ $come = array();
+ $get = DB::table('usr_comments')
+ ->where('reply_id', $id)
+ ->orderBy('usr_comments.postdate', 'asc')
+ ->get(array(
+ 'reply_id',
+ 'usr_comments.id as come_id',
+ 'user_id',
+ 'postdate',
+ 'message',
+ 'isEdit',
+ 'isDel'
+ ));
+
+ // Foreach, new getter but check on replies, and only if isDel is 0.
+ foreach ($get as $g) {
+ $user = $this->getUser($g->user_id, $request)->toArray();
+ $showName = "";
+ $showCol = "";
+
+ if ($user[0]->display_name !== '') {
+ $showName = $user[0]->display_name;
}
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
- ]);
- }
- }
-
- public function getCountries() { // /api/rpc/user/user/getcountries
- $flags = File::files('assets/flags');
-
- $res = array();
-
- foreach ($flags as $flag) {
- $protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
-
- $res[] = array(
- 'value' => $flag->getBasename('.png'),
- 'label' => ' '.$flag->getBasename('.png')
- );
+ $showName = $user[0]->username;
}
- return $res;
- }
-
- public function avatarUpload(Request $request) { // /api/rpc/user/user/avatarupload
- $check = $this->objAuth->checkLegit($request->username, $request->password);
-
- if ($check == 0) {
- return 'Err!';
+ if ($user[0]->name_style !== '') {
+ $showCol = $user[0]->name_style;
}
else {
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
-
- if ($valid['usr_editprofile'] == 1) {
- if (isset($request->filename)) {
- if (!is_dir("assets/avatars/".$check)) {
- if (!mkdir("assets/avatars/".$check, 0755, true)) {
- return "Could not make folder ".$check."
";
- }
- }
-
- $img_dir = "assets/avatars/".$check."/";
- $image = $img_dir . $request->filename;
- $imageFileType = array(
- 'image/png',
- 'image/jpeg',
- 'image/gif'
- );
-
- if (!in_array($request->filetype, $imageFileType)) {
- return "Only JPG, PNG, JPEG, and GIF are allowed.";
- }
-
- $fname = 'assets/avatars/'.$check.'/'.$request->filename;
- $data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $request->thefile));
- Storage::disk('public')->put($fname, $data);
-
- return $request->filename;
- }
- }
- else {
- return 'Permission denied.';
+ 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;
}
+ }
}
+
+ setlocale(LC_ALL, 'ja_JP.utf8');
+
+ $come[] = array(
+ 'reply_id' => $g->reply_id,
+ 'come_id' => $g->come_id,
+ 'user_id' => $g->user_id,
+ 'name' => $showName,
+ 'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
+ 'col' => $showCol,
+ 'message' => $g->message,
+ 'postdate' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($g->postdate)),
+ 'isEdit' => $g->isEdit,
+ 'isDel' => $g->isDel
+ );
+ }
+
+ return $come;
}
-
- public function editUser(Request $request) { // /api/rpc/user/user/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['usr_editprofile'] == 1) {
- if (isset($request->newPassword)) {
- DB::table('users')
- ->where('id', $request->id)
- ->update([
- 'password' => $request->newPassword
- ]);
- }
- if (isset($request->email)) {
- DB::table('users')
- ->where('id', $request->id)
- ->update([
- 'email' => $request->email
- ]);
- }
-
- DB::table('usr_contacts')
- ->where('user_id', $request->id)
- ->update([
- 'website_link' => ($request->website_link != '' ? $request->website_link : ''),
- 'website_name' => ($request->website_name != '' ? $request->website_name : ''),
- 'youtube_link' => ($request->youtube_link != '' ? $request->youtube_link : ''),
- 'youtube_name' => ($request->youtube_name != '' ? $request->youtube_name : ''),
- 'niconico' => ($request->niconico != '' ? $request->niconico : ''),
- 'pixiv' => ($request->pixiv != '' ? $request->pixiv : ''),
- 'discord' => ($request->discord != '' ? $request->discord : ''),
- 'mastodon' => ($request->mastodon != '' ? $request->mastodon : ''),
- 'twitter' => ($request->twitter != '' ? $request->twitter : '')
- ]);
-
- DB::table('usr_perm_id')
- ->where('user_id', $request->id)
- ->update([
- 'perm_id' => $request->group
- ]);
-
- DB::table('usr_profile')
- ->where('user_id', $request->id)
- ->update([
- 'gender' => $request->gender,
- 'bio' => ($request->aboutSelf != '' ? $request->aboutSelf : ''),
- 'signature' => ($request->signature != '' ? $request->signature : ''),
- 'avatar' => ($request->avatar != '' ? $request->avatar : ''),
- 'name_style' => ($request->nameStyle != '' ? $request->nameStyle : ''),
- 'display_name' => ($request->displayName != '' ? $request->displayName : ''),
- 'member_title' => ($request->memberTitle != '' ? $request->memberTitle : ''),
- 'birthday' => ($request->birthDay != 0 ? $request->birthDay : 0),
- 'country' => $request->country
- ]);
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
+ else {
+ return 'Permission denied.';
}
+ }
- public function countComments($id) { // /api/rpc/user/comment/count/id
- return DB::table('usr_comments')
- ->where('profile_id', $id)
- ->count();
+ public function addComment (Request $request) { // /api/rpc/user/comment/add
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
+
+ if ($check == 0) {
+ return 'Err!';
}
+ else {
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
- public function getComments ($id, Request $request) { // /api/rpc/user/comment/get/id
- $cols = $this->getGroupColours()->toArray();
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
+ if ($valid['usr_addcomment'] == 1) {
+ $add = DB::table('usr_comments')
+ ->insert([
+ 'user_id' => $check,
+ 'profile_id' => $request->profile_id,
+ 'reply_id' => ($request->reply_id > 0 ? $request->reply_id : 0),
+ 'postdate' => time(),
+ 'message' => $request->message,
+ 'isEdit' => 0,
+ 'isDel' => 0
+ ]);
- if ($valid['usr_viewcomment'] == 1) {
- $come = array();
- $get = DB::table('usr_comments')
- ->where('profile_id', $id)
- ->where('reply_id', 0)
- ->orderBy('usr_comments.postdate', 'asc')
- ->get(array(
- 'usr_comments.id as come_id',
- 'user_id',
- 'postdate',
- 'message',
- 'isEdit',
- 'isDel'
- ));
-
- // Foreach, new getter but check on replies, and only if isDel is 0.
- foreach ($get as $g) {
- $user = $this->getUser($g->user_id, $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;
- }
- }
- }
-
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- $come[] = array(
- 'come_id' => $g->come_id,
- 'user_id' => $g->user_id,
- 'name' => $showName,
- 'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
- 'col' => $showCol,
- 'message' => $g->message,
- 'postdate' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($g->postdate)),
- 'isEdit' => $g->isEdit,
- 'isDel' => $g->isDel
- );
- }
-
- return $come;
- }
- else {
- return 'Permission denied.';
- }
+ return \Response::json($add);
+ }
+ else {
+ return 'Permission denied.';
+ }
}
+ }
- public function getReplies ($id, Request $request) { // /api/rpc/user/comment/reply/id
- $cols = $this->getGroupColours()->toArray();
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
+ public function editComment (Request $request) { // /api/rpc/user/comment/edit
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
- if ($valid['usr_viewcomment'] == 1) {
- $come = array();
- $get = DB::table('usr_comments')
- ->where('reply_id', $id)
- ->orderBy('usr_comments.postdate', 'asc')
- ->get(array(
- 'reply_id',
- 'usr_comments.id as come_id',
- 'user_id',
- 'postdate',
- 'message',
- 'isEdit',
- 'isDel'
- ));
-
- // Foreach, new getter but check on replies, and only if isDel is 0.
- foreach ($get as $g) {
- $user = $this->getUser($g->user_id, $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;
- }
- }
- }
-
- setlocale(LC_ALL, 'ja_JP.utf8');
-
- $come[] = array(
- 'reply_id' => $g->reply_id,
- 'come_id' => $g->come_id,
- 'user_id' => $g->user_id,
- 'name' => $showName,
- 'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
- 'col' => $showCol,
- 'message' => $g->message,
- 'postdate' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', date($g->postdate)),
- 'isEdit' => $g->isEdit,
- 'isDel' => $g->isDel
- );
- }
-
- return $come;
- }
- else {
- return 'Permission denied.';
- }
+ if ($check == 0) {
+ return 'Err!';
}
+ else {
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
- public function addComment (Request $request) { // /api/rpc/user/comment/add
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ if ($valid['usr_editowncomment'] == 1) {
+ DB::table('usr_comments')
+ ->where('profile_id', $request->profile_id)
+ ->update([
+ 'message' => $request->message,
+ 'isEdit' => 1
+ ]);
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
-
- if ($valid['usr_addcomment'] == 1) {
- $add = DB::table('usr_comments')
- ->insert([
- 'user_id' => $check,
- 'profile_id' => $request->profile_id,
- 'reply_id' => ($request->reply_id > 0 ? $request->reply_id : 0),
- 'postdate' => time(),
- 'message' => $request->message,
- 'isEdit' => 0,
- 'isDel' => 0
- ]);
-
- return \Response::json($add);
- }
- else {
- return 'Permission denied.';
- }
- }
+ return 'Success!';
+ }
+ else {
+ return 'Permission denied.';
+ }
}
+ }
- public function editComment (Request $request) { // /api/rpc/user/comment/edit
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ public function deleteComment (Request $request) { // /api/rpc/user/comment/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['usr_editowncomment'] == 1) {
- DB::table('usr_comments')
- ->where('profile_id', $request->profile_id)
- ->update([
- 'message' => $request->message,
- 'isEdit' => 1
- ]);
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
+ if ($check == 0) {
+ return 'Err!';
}
+ else {
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
- public function deleteComment (Request $request) { // /api/rpc/user/comment/delete
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ if ($valid['usr_delcomment'] == 1) {
+ DB::table('usr_comments')
+ ->where('id', $request->id)
+ ->update([
+ 'isDel' => 1
+ ]);
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
-
- if ($valid['usr_delcomment'] == 1) {
- DB::table('usr_comments')
- ->where('id', $request->id)
- ->update([
- 'isDel' => 1
- ]);
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
+ return 'Success!';
+ }
+ else {
+ return 'Permission denied.';
+ }
}
+ }
- public function undeleteComment (Request $request) { // /api/rpc/user/comment/undelete
- $check = $this->objAuth->checkLegit($request->username, $request->password);
+ public function undeleteComment (Request $request) { // /api/rpc/user/comment/undelete
+ $check = $this->objAuth->checkLegit($request->username, $request->password);
- if ($check == 0) {
- return 'Err!';
- }
- else {
- $valid = $this->objAuth->getPermissions($request->username, $request->password);
-
- if ($valid['usr_delcomment'] == 1) {
- DB::table('usr_comments')
- ->where('id', $request->id)
- ->update([
- 'isDel' => 0
- ]);
-
- return 'Success!';
- }
- else {
- return 'Permission denied.';
- }
- }
+ if ($check == 0) {
+ return 'Err!';
}
+ else {
+ $valid = $this->objAuth->getPermissions($request->username, $request->password);
+
+ if ($valid['usr_delcomment'] == 1) {
+ DB::table('usr_comments')
+ ->where('id', $request->id)
+ ->update([
+ 'isDel' => 0
+ ]);
+
+ return 'Success!';
+ }
+ else {
+ return 'Permission denied.';
+ }
+ }
+ }
}
+