Image permission.
このコミットが含まれているのは:
コミット
e144e79d48
|
@ -24,125 +24,74 @@ class ImageController extends Controller {
|
|||
}
|
||||
|
||||
public function getUserWithUploads(Request $request) { // /api/rpc/image/get/userwithuploads
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::directories('storage/assets/images');
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
$res = array();
|
||||
if ($valid['img_view'] == 1) {
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::directories('storage/assets/images');
|
||||
|
||||
foreach($imgs as $img) {
|
||||
$usr = basename($img);
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
$res = array();
|
||||
|
||||
if ($usr != 0) {
|
||||
$user = $this->objUser->getUser($usr, $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
foreach($imgs as $img) {
|
||||
$usr = basename($img);
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($user[0]->display_name !== '') {
|
||||
$showName = $user[0]->display_name;
|
||||
}
|
||||
else {
|
||||
$showName = $user[0]->username;
|
||||
}
|
||||
if ($usr != 0) {
|
||||
$user = $this->objUser->getUser($usr, $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
|
||||
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;
|
||||
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 = "";
|
||||
else {
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => basename($img),
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName
|
||||
);
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => basename($img),
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName
|
||||
);
|
||||
return $res;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getAll(Request $request) { // /api/rpc/image/get/all
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/*');
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
$res = array();
|
||||
if ($valid['img_view'] == 1) {
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/*');
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
$res = array();
|
||||
|
||||
if ($usr[3] != 0) {
|
||||
$user = $this->objUser->getUser($usr[3], $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 = "";
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $usr[3],
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'name' => $img->getFilename(),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName,
|
||||
'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getOwn(Request $request) { // /api/rpc/image/get/own
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/'.$check);
|
||||
|
||||
$res = array();
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr[3] == $check) {
|
||||
if ($usr[3] != 0) {
|
||||
$user = $this->objUser->getUser($usr[3], $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
|
@ -181,87 +130,36 @@ class ImageController extends Controller {
|
|||
'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function getUser($id, Request $request) { // /api/rpc/image/get/user/id
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/'.$id);
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr[3] != 0) {
|
||||
$user = $this->objUser->getUser($usr[3], $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 = "";
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $id,
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'name' => $img->getFilename(),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName,
|
||||
'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getOther(Request $request) { // /api/rpc/image/get/other
|
||||
public function getOwn(Request $request) { // /api/rpc/image/get/own
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$dirs = File::directories('storage/assets/images');
|
||||
|
||||
$res = array();
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
foreach ($dirs as $dir) {
|
||||
$usr = 0;
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if (basename($dir) != $check) {
|
||||
$usr = basename($dir);
|
||||
$imgs = File::files('assets/images/'.$usr);
|
||||
if ($valid['img_view'] == 1) {
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/'.$check);
|
||||
|
||||
$res = array();
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr != $check) {
|
||||
$user = $this->objUser->getUser($usr, $request)->toArray();
|
||||
if ($usr[3] == $check) {
|
||||
$user = $this->objUser->getUser($usr[3], $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
|
||||
|
@ -291,7 +189,7 @@ class ImageController extends Controller {
|
|||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $usr,
|
||||
'id' => $usr[3],
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'name' => $img->getFilename(),
|
||||
'userCol' => $showCol,
|
||||
|
@ -300,20 +198,167 @@ class ImageController extends Controller {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
public function getUser($id, Request $request) { // /api/rpc/image/get/user/id
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['img_view'] == 1) {
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('storage/assets/images/'.$id);
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr[3] != 0) {
|
||||
$user = $this->objUser->getUser($usr[3], $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 = "";
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $id,
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'name' => $img->getFilename(),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName,
|
||||
'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function getOther(Request $request) { // /api/rpc/image/get/other
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['img_view'] == 1) {
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$dirs = File::directories('storage/assets/images');
|
||||
|
||||
$res = array();
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
foreach ($dirs as $dir) {
|
||||
$usr = 0;
|
||||
|
||||
if (basename($dir) != $check) {
|
||||
$usr = basename($dir);
|
||||
$imgs = File::files('assets/images/'.$usr);
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr != $check) {
|
||||
$user = $this->objUser->getUser($usr, $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 = "";
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $usr,
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'name' => $img->getFilename(),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName,
|
||||
'image' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.$img->getPathname()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function viewImage(Request $request) { // /api/rpc/image/view
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if (!isset($request->id) || !isset($request->name)) {
|
||||
return 'Err!';
|
||||
if ($valid['img_view'] == 1) {
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if (!isset($request->id) || !isset($request->name)) {
|
||||
return 'Err!';
|
||||
}
|
||||
|
||||
return $protocol.'://'.$_SERVER['SERVER_NAME'].'/assets/images/'.$request->id.'/'.$request->name;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
|
||||
return $protocol.'://'.$_SERVER['SERVER_NAME'].'/assets/images/'.$request->id.'/'.$request->name;
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request) { // /api/rpc/image/upload
|
||||
|
@ -325,7 +370,7 @@ class ImageController extends Controller {
|
|||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_editprofile'] == 1) {
|
||||
if ($valid['img_add'] == 1) {
|
||||
if (isset($request->filename)) {
|
||||
if (!is_dir("assets/images/".$check)) {
|
||||
if (!mkdir("assets/images/".$check, 0755, true)) {
|
||||
|
@ -372,7 +417,7 @@ class ImageController extends Controller {
|
|||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_editother'] == 1) {
|
||||
if ($valid['img_delother'] == 1) {
|
||||
if (isset($request->name)) {
|
||||
$fname = 'assets/images/'.$request->id.'/'.$request->name;
|
||||
unlink('storage/'.$fname);
|
||||
|
@ -384,11 +429,16 @@ class ImageController extends Controller {
|
|||
else {
|
||||
if (isset($request->name)) {
|
||||
if ($check == $request->id) {
|
||||
$fname = 'assets/images/'.$check.'/'.$request->name;
|
||||
unlink('storage/'.$fname);
|
||||
if ($this->is_dir_empty('storage/assets/images/'.$check)) rmdir('storage/assets/images/'.$check);
|
||||
if ($valid['img_delown'] == 1) {
|
||||
$fname = 'assets/images/'.$check.'/'.$request->name;
|
||||
unlink('storage/'.$fname);
|
||||
if ($this->is_dir_empty('storage/assets/images/'.$check)) rmdir('storage/assets/images/'.$check);
|
||||
|
||||
return 'Deleted';
|
||||
return 'Deleted';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
|
|
新しいイシューから参照