このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
076server/app/Http/Controllers/ImageController.php

317 行
11 KiB
PHP
Raw 通常表示 履歴

2018-08-02 12:29:10 +09:00
<?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
}
}