Image controller, show images.
このコミットが含まれているのは:
コミット
2bb1f1d856
|
@ -0,0 +1,316 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ForUser;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use App\Http\Controllers\UserController;
|
||||
|
||||
class ImageController extends Controller {
|
||||
private $objAuth;
|
||||
private $objUser;
|
||||
|
||||
public function __construct() {
|
||||
$this->objAuth = new AuthController();
|
||||
$this->objUser = new UserController();
|
||||
}
|
||||
|
||||
public function getUserWithUploads(Request $request) { // /api/rpc/image/get/userwithuploads
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::directories('assets/images');
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach($imgs as $img) {
|
||||
$usr = basename($img);
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr != 0) {
|
||||
$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' => basename($img),
|
||||
'avatar' => $protocol.'://'.$_SERVER['SERVER_NAME'].'/'.($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'userCol' => $showCol,
|
||||
'userName' => $showName
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getAll(Request $request) { // /api/rpc/image/get/all
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('assets/images/*');
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr[2] != 0) {
|
||||
$user = $this->objUser->getUser($usr[2], $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[2],
|
||||
'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('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[2] == $check) {
|
||||
$user = $this->objUser->getUser($usr[2], $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[2],
|
||||
'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 getUser($id, Request $request) { // /api/rpc/image/get/user/id
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$imgs = File::files('assets/images/'.$id);
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach ($imgs as $img) {
|
||||
$usr = preg_split("#/#", $img->getPathname());
|
||||
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
|
||||
|
||||
if ($usr[2] != 0) {
|
||||
$user = $this->objUser->getUser($usr[2], $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);
|
||||
$cols = $this->objUser->getGroupColours()->toArray();
|
||||
$dirs = File::directories('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;
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request) { // /api/rpc/image/upload
|
||||
|
||||
}
|
||||
|
||||
public function removeImage(Request $request) { // /api/rpc/image/remove
|
||||
|
||||
}
|
||||
}
|
|
@ -8,3 +8,11 @@
|
|||
| These are the API routes corresponding to image.
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get('/api/rpc/image/get/userwithuploads', 'ImageController@getUserWithUploads');
|
||||
Route::get('/api/rpc/image/get/all', 'ImageController@getAll');
|
||||
Route::get('/api/rpc/image/get/own', 'ImageController@getOwn');
|
||||
Route::get('/api/rpc/image/get/user/{id}', 'ImageController@getUser');
|
||||
Route::get('/api/rpc/image/get/other', 'ImageController@getOther');
|
||||
Route::post('/api/rpc/image/upload', 'ImageController@uploadImage');
|
||||
Route::post('/api/rpc/image/remove', 'ImageController@removeImage');
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
require(__DIR__.'/class/board.php');
|
||||
// require(__DIR__.'/class/image.php');
|
||||
require(__DIR__.'/class/image.php');
|
||||
require(__DIR__.'/class/invoice.php');
|
||||
require(__DIR__.'/class/site.php');
|
||||
require(__DIR__.'/class/store.php');
|
||||
|
|
新しいイシューから参照