Adjust code style due to my OCD

This commit is contained in:
printempw 2018-02-16 17:31:04 +08:00
parent e05d2064b8
commit dd3f645e80
41 changed files with 265 additions and 262 deletions

View File

@ -52,7 +52,7 @@ class KeyRandomCommand extends Command
protected function setKeyInEnvironmentFile($key)
{
// Unlike Illuminate\Foundation\Console\KeyGenerateCommand,
// I add soame spaces to the replace pattern.
// I add some spaces to the replace pattern.
file_put_contents($this->laravel->environmentFilePath(), str_replace(
'APP_KEY = '.$this->laravel['config']['app.key'],
'APP_KEY = '.$key,

View File

@ -3,6 +3,7 @@
namespace App\Exceptions;
use Exception;
use Illuminate\Http\Response;
use App\Exceptions\PrettyPageException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Validation\ValidationException;
@ -29,9 +30,7 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @param Exception $e
* @return void
*/
public function report(Exception $e)
@ -42,9 +41,9 @@ class Handler extends ExceptionHandler
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
* @param \Illuminate\Http\Request $request
* @param Exception $e
* @return Response
*/
public function render($request, Exception $e)
{
@ -61,7 +60,7 @@ class Handler extends ExceptionHandler
}
if ($e instanceof ValidationException) {
// quick fix for returning 422
// Quick fix for returning 422
// @see https://prinzeugen.net/custom-responses-of-laravel-validations/
return $e->getResponse()->setStatusCode(200);
}
@ -70,7 +69,7 @@ class Handler extends ExceptionHandler
if ($e instanceof $type) {
return parent::render($request, $e);
} else {
// hide exception details if not in debug mode
// Hide exception details if we are not in debug mode
if (config('app.debug') && !$request->ajax()) {
return $this->renderExceptionWithWhoops($e);
} else {
@ -83,10 +82,10 @@ class Handler extends ExceptionHandler
/**
* Render an exception using Whoops.
*
* @param \Exception $e
* @param int $code
* @param array $headers
* @return \Illuminate\Http\Response
* @param Exception $e
* @param int $code
* @param array $headers
* @return Response
*/
protected function renderExceptionWithWhoops(Exception $e, $code = 200, $headers = [])
{
@ -95,7 +94,7 @@ class Handler extends ExceptionHandler
new \Whoops\Handler\PrettyPageHandler : new \Whoops\Handler\PlainTextHandler;
$whoops->pushHandler($handler);
return new \Illuminate\Http\Response(
return new Response(
$whoops->handleException($e),
$code,
$headers
@ -105,8 +104,8 @@ class Handler extends ExceptionHandler
/**
* Render an exception in a short word.
*
* @param \Exception $e
* @return \Illuminate\Http\Response
* @param Exception $e
* @return Response
*/
protected function renderExceptionInBrief(Exception $e)
{

View File

@ -5,11 +5,12 @@ namespace App\Exceptions;
class PrettyPageException extends \Exception
{
/**
* Custom error handler
* Custom error handler.
*
* @param string $message
* @param integer $code
* @param boolean $render, to show a error page
* @param string $message
* @param int $code
* @param bool $render Whether to show a error page.
* @return void
*/
public function __construct($message = "Error occured.", $code = -1, $render = false)
{

View File

@ -350,7 +350,7 @@ class AdminController extends Controller
'tid' => 'required|integer'
]);
if (!Texture::find($request->tid) && $request->tid != 0)
if (! Texture::find($request->tid) && $request->tid != 0)
return json(trans('admin.players.textures.non-existent', ['tid' => $request->tid]), 1);
$player->setTexture(['tid_'.$request->model => $request->tid]);
@ -364,7 +364,7 @@ class AdminController extends Controller
$user = $users->get($request->input('uid'));
if (!$user)
if (! $user)
return json(trans('admin.users.operations.non-existent'), 1);
$player->setOwner($request->input('uid'));

View File

@ -33,22 +33,22 @@ class AuthController extends Controller
$identification = $request->input('identification');
// guess type of identification
$auth_type = (validate($identification, 'email')) ? "email" : "username";
// Guess type of identification
$authType = (validate($identification, 'email')) ? "email" : "username";
event(new Events\UserTryToLogin($identification, $auth_type));
event(new Events\UserTryToLogin($identification, $authType));
// Get user instance from repository.
// If the given identification is not registered yet,
// it will return a null value.
$user = $users->get($identification, $auth_type);
$user = $users->get($identification, $authType);
if (session('login_fails', 0) > 3) {
if (strtolower($request->input('captcha')) != strtolower(session('phrase')))
return json(trans('auth.validation.captcha'), 1);
}
if (!$user) {
if (! $user) {
return json(trans('auth.validation.user'), 2);
} else {
if ($user->verifyPassword($request->input('password'))) {
@ -57,7 +57,7 @@ class AuthController extends Controller
Session::put('uid' , $user->uid);
Session::put('token', $user->getToken());
// time in minutes
// Time in minutes
$time = $request->input('keep') == true ? 10080 : 60;
event(new Events\UserLoggedIn($user));
@ -66,7 +66,7 @@ class AuthController extends Controller
return json(trans('auth.login.success'), 0, [
'token' => $user->getToken()
]) // set cookies
]) // Set cookies
->withCookie('uid', $user->uid, $time)
->withCookie('token', $user->getToken(), $time);
} else {
@ -82,10 +82,10 @@ class AuthController extends Controller
public function logout(Request $request)
{
if (Session::has('uid') && Session::has('token')) {
// flush sessions
// Flush sessions
Session::flush();
// delete cookies
// Delete cookies
return json(trans('auth.logout.success'), 0)
->withCookie(Cookie::forget('uid'))
->withCookie(Cookie::forget('token'));
@ -105,7 +105,7 @@ class AuthController extends Controller
public function handleRegister(Request $request, UserRepository $users)
{
if (!$this->checkCaptcha($request))
if (! $this->checkCaptcha($request))
return json(trans('auth.validation.captcha'), 1);
$this->validate($request, [
@ -114,7 +114,7 @@ class AuthController extends Controller
'nickname' => 'required|nickname|max:255'
]);
if (!option('user_can_register')) {
if (! option('user_can_register')) {
return json(trans('auth.register.close'), 7);
}
@ -137,7 +137,7 @@ class AuthController extends Controller
$user->nickname = $request->input('nickname');
});
if (!$user) {
if (! $user) {
return json(trans('auth.register.registered'), 5);
}
@ -147,8 +147,8 @@ class AuthController extends Controller
$redirect = true;
if ($request->input('addPlayer') == 'add') {
if (!Player::where('player_name', $request->nickname)->first()) {
if (!Validator::make(
if (! Player::where('player_name', $request->nickname)->first()) {
if (! Validator::make(
['name' => $request->nickname],
['name' => option('allow_chinese_playername') ? 'pname_chinese' : 'playername']
)->fails()) {
@ -175,7 +175,7 @@ class AuthController extends Controller
'msg' => $msg,
'token' => $user->getToken(),
'redirect' => $redirect,
]) // set cookies
]) // Set cookies
->withCookie('uid', $user->uid, 60)
->withCookie('token', $user->getToken(), 60);
@ -195,7 +195,7 @@ class AuthController extends Controller
public function handleForgot(Request $request, UserRepository $users)
{
if (!$this->checkCaptcha($request))
if (! $this->checkCaptcha($request))
return json(trans('auth.validation.captcha'), 1);
if (config('mail.host') == "")
@ -204,14 +204,14 @@ class AuthController extends Controller
if (Session::has('last_mail_time') && (time() - session('last_mail_time')) < 60)
return json(trans('auth.forgot.frequent-mail'), 1);
// get user instance
// Get user instance
$user = $users->get($request->input('email'), 'email');
if (!$user)
if (! $user)
return json(trans('auth.forgot.unregistered'), 1);
$uid = $user->uid;
// generate token for password resetting
// Generate token for password resetting
$token = base64_encode($user->getToken().substr(time(), 4, 6).str_random(16));
$url = Option::get('site_url')."/auth/reset?uid=$uid&token=$token";
@ -237,13 +237,13 @@ class AuthController extends Controller
public function reset(UserRepository $users, Request $request)
{
if ($request->has('uid') && $request->has('token')) {
// get user instance from repository
// Get user instance from repository
$user = $users->get($request->input('uid'));
if (!$user)
if (! $user)
return redirect('auth/forgot')->with('msg', trans('auth.reset.invalid'));
// unpack to get user token & timestamp
// Unpack to get user token & timestamp
$decoded = base64_decode($request->input('token'));
$token = substr($decoded, 0, -22);
$timestamp = substr($decoded, strlen($token), 6);
@ -252,7 +252,7 @@ class AuthController extends Controller
return redirect('auth/forgot')->with('msg', trans('auth.reset.invalid'));
}
// more than 1 hour
// More than 1 hour
if ((substr(time(), 4, 6) - $timestamp) > 3600) {
return redirect('auth/forgot')->with('msg', trans('auth.reset.expired'));
}
@ -276,14 +276,14 @@ class AuthController extends Controller
$timestamp = intval(substr($decoded, strlen($token), 6));
$user = $users->get($request->input('uid'));
if (!$user)
if (! $user)
return json(trans('auth.reset.invalid'), 1);
if ($user->getToken() != $token) {
return json(trans('auth.reset.invalid'), 1);
}
// more than 1 hour
// More than 1 hour
if ((intval(substr(time(), 4, 6)) - $timestamp) > 3600) {
return json(trans('auth.reset.expired'), 1);
}

View File

@ -42,7 +42,7 @@ class ClosetController extends Controller
$items = collect();
if ($q) {
// do search
// Do search
$items = $this->closet->getItems($category)->filter(function ($item) use ($q) {
return stristr($item['name'], $q);
});
@ -50,7 +50,7 @@ class ClosetController extends Controller
$items = $this->closet->getItems($category);
}
// pagination
// Pagination
$total_pages = ceil($items->count() / $per_page);
return response()->json([
@ -72,7 +72,7 @@ class ClosetController extends Controller
}
$tid = $request->tid;
if (!Texture::find($tid)) {
if (! Texture::find($tid)) {
return json(trans('user.closet.add.not-found'), 1);
}

View File

@ -12,5 +12,4 @@ class HomeController extends Controller
return view('index')->with('user', $users->getCurrentUser())
->with('home_pic_url', option('home_pic_url') ?: config('options.home_pic_url'));
}
}

View File

@ -46,11 +46,9 @@ class PlayerController extends Controller
}
}
$this->middleware(
[CheckPlayerExist::class, CheckPlayerOwner::class],
[
'only' => ['delete', 'rename', 'setTexture', 'clearTexture', 'setPreference']
]);
$this->middleware([CheckPlayerExist::class, CheckPlayerOwner::class], [
'only' => ['delete', 'rename', 'setTexture', 'clearTexture', 'setPreference']
]);
}
public function index()
@ -66,7 +64,7 @@ class PlayerController extends Controller
event(new CheckPlayerExists($request->input('player_name')));
if (!Player::where('player_name', $request->input('player_name'))->get()->isEmpty()) {
if (! Player::where('player_name', $request->input('player_name'))->get()->isEmpty()) {
return json(trans('user.player.add.repeated'), 6);
}
@ -93,18 +91,19 @@ class PlayerController extends Controller
public function delete(Request $request)
{
$player_name = $this->player->player_name;
$playerName = $this->player->player_name;
event(new PlayerWillBeDeleted($this->player));
$this->player->delete();
if (option('return_score'))
if (option('return_score')) {
$this->user->setScore(Option::get('score_per_player'), 'plus');
}
event(new PlayerWasDeleted($player_name));
event(new PlayerWasDeleted($playerName));
return json(trans('user.player.delete.success', ['name' => $player_name]), 0);
return json(trans('user.player.delete.success', ['name' => $playerName]), 0);
}
public function show()
@ -118,21 +117,21 @@ class PlayerController extends Controller
'new_player_name' => 'required|'.(option('allow_chinese_playername') ? 'pname_chinese' : 'playername')
]);
$new_name = $request->input('new_player_name');
$newName = $request->input('new_player_name');
if (!Player::where('player_name', $new_name)->get()->isEmpty()) {
if (! Player::where('player_name', $newName)->get()->isEmpty()) {
return json(trans('user.player.rename.repeated'), 6);
}
$old_name = $this->player->player_name;
$oldName = $this->player->player_name;
$this->player->rename($new_name);
$this->player->rename($newName);
return json(trans('user.player.rename.success', ['old' => $old_name, 'new' => $new_name]), 0);
return json(trans('user.player.rename.success', ['old' => $oldName, 'new' => $newName]), 0);
}
/**
* A wrapper of Player::setTexture()
* A wrapper of Player::setTexture().
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
@ -140,12 +139,15 @@ class PlayerController extends Controller
public function setTexture(Request $request)
{
foreach ($request->input('tid') as $key => $value) {
if (!($texture = Texture::find($value)))
$texture = Texture::find($value);
if (! $texture) {
return json(trans('skinlib.un-existent'), 6);
}
$field_name = "tid_{$texture->type}";
$fieldName = "tid_{$texture->type}";
$this->player->setTexture([$field_name => $value]);
$this->player->setTexture([$fieldName => $value]);
}
return json(trans('user.player.set.success', ['name' => $this->player->player_name]), 0);

View File

@ -41,7 +41,7 @@ class PluginController extends Controller
$plugin = plugin($name = $request->get('name'));
if ($plugin) {
// pass the plugin title through the translator
// Pass the plugin title through the translator.
$plugin->title = trans($plugin->title);
switch ($request->get('action')) {

View File

@ -38,7 +38,7 @@ class SetupController extends Controller
]);
if ($request->has('generate_random')) {
// generate new APP_KEY & SALT randomly
// Generate new APP_KEY & SALT randomly
if (is_writable(app()->environmentFile())) {
Artisan::call('key:random');
Artisan::call('salt:random');
@ -68,7 +68,7 @@ class SetupController extends Controller
Option::set('site_url', $siteUrl);
// register super admin
// Register super admin
$user = User::register(
$request->input('email'),
$request->input('password'), function ($user)
@ -93,7 +93,7 @@ class SetupController extends Controller
public function update()
{
if (Utils::versionCompare(config('app.version'), option('version', ''), '<=')) {
// no updates available
// No updates available
return view('setup.locked');
}
@ -111,8 +111,8 @@ class SetupController extends Controller
if ($filename != "." && $filename != "..") {
preg_match('/update-(.*)-to-(.*).php/', $filename, $matches);
// skip if the file is not valid or expired
if (!isset($matches[2]) ||
// Skip if the file is not valid or expired
if (! isset($matches[2]) ||
Utils::versionCompare($matches[2], config('app.version'), '<')) {
continue;
}
@ -120,7 +120,7 @@ class SetupController extends Controller
$result = require database_path('update_scripts')."/$filename";
if (is_array($result)) {
// push tip to array
// Push the tip into array
foreach ($result as $tip) {
$tips[] = $tip;
}
@ -132,16 +132,17 @@ class SetupController extends Controller
closedir($resource);
foreach (config('options') as $key => $value) {
if (!Option::has($key))
if (! Option::has($key)) {
Option::set($key, $value);
}
}
if (!$updateScriptExist) {
// if update script is not given
if (! $updateScriptExist) {
// If there is no update script given
Option::set('version', config('app.version'));
}
// clear all compiled view files
// Clear all compiled view files
try {
Artisan::call('view:clear');
} catch (\Exception $e) {
@ -164,13 +165,13 @@ class SetupController extends Controller
* @param array $tables
* @return bool
*/
public static function checkTablesExist($tables = [
'users', 'closets', 'players', 'textures', 'options'
]) {
public static function checkTablesExist($tables = null) {
$totalTables = 0;
$tables = $tables ?: ['users', 'closets', 'players', 'textures', 'options'];
foreach ($tables as $tableName) {
// prefix will be added automatically
// Table prefix will be added automatically
if (Schema::hasTable($tableName)) {
$totalTables++;
}
@ -179,7 +180,7 @@ class SetupController extends Controller
if ($totalTables == count($tables)) {
return true;
} else {
// not installed completely
// Not installed completely
foreach (array_merge($tables, ['migrations']) as $tableName) {
Schema::dropIfExists($tableName);
}
@ -193,10 +194,11 @@ class SetupController extends Controller
try {
foreach ($directories as $dir) {
if (!Storage::disk('root')->has($dir)) {
// mkdir
if (!Storage::disk('root')->makeDirectory($dir))
if (! Storage::disk('root')->has($dir)) {
// Try to mkdir
if (! Storage::disk('root')->makeDirectory($dir)) {
return false;
}
}
}
@ -218,5 +220,4 @@ class SetupController extends Controller
{
return $validator->errors()->all();
}
}

View File

@ -18,7 +18,7 @@ use App\Services\Repositories\UserRepository;
class SkinlibController extends Controller
{
private $user = null;
protected $user = null;
public function __construct(UserRepository $users)
{
@ -120,7 +120,7 @@ class SkinlibController extends Controller
{
$texture = Texture::find($tid);
if (!$texture || $texture && !Storage::disk('textures')->has($texture->hash)) {
if (! $texture || $texture && !Storage::disk('textures')->has($texture->hash)) {
if (option('auto_del_invalid_texture')) {
if ($texture) {
$texture->delete();
@ -177,7 +177,7 @@ class SkinlibController extends Controller
$results = Texture::where('hash', $t->hash)->get();
if (!$results->isEmpty()) {
if (! $results->isEmpty()) {
foreach ($results as $result) {
// if the texture already uploaded was set to private,
// then allow to re-upload it.
@ -204,7 +204,7 @@ class SkinlibController extends Controller
{
$result = Texture::find($request->tid);
if (!$result) {
if (! $result) {
return json(trans('skinlib.non-existent'), 1);
}
@ -240,7 +240,7 @@ class SkinlibController extends Controller
{
$t = Texture::find($request->input('tid'));
if (!$t)
if (! $t)
return json(trans('skinlib.non-existent'), 1);
if ($t->uploader != $this->user->uid && !$this->user->isAdmin())
@ -278,7 +278,7 @@ class SkinlibController extends Controller
$t = Texture::find($request->input('tid'));
if (!$t)
if (! $t)
return json(trans('skinlib.non-existent'), 1);
if ($t->uploader != $this->user->uid && !$this->user->isAdmin())
@ -297,7 +297,7 @@ class SkinlibController extends Controller
* @param Request $request
* @return JsonResponse
*/
private function checkUpload(Request $request)
protected function checkUpload(Request $request)
{
if ($file = $request->files->get('file')) {
if ($file->getError() !== UPLOAD_ERR_OK) {

View File

@ -134,7 +134,6 @@ class TextureController extends Controller
public function preview($tid, $size = 250)
{
// output image directly
if ($t = Texture::find($tid)) {
if (Storage::disk('textures')->has($t->hash)) {
$responses = event(new GetSkinPreview($t, $size));
@ -165,6 +164,7 @@ class TextureController extends Controller
}
}
// Show this if given texture is invalid.
$png = imagecreatefromstring(base64_decode(static::getBrokenPreview()));
ob_start();
imagepng($png);

View File

@ -37,12 +37,12 @@ class UpdateController extends Controller
'release_note' => '',
'release_url' => '',
'pre_release' => false,
// fallback to current time
// Fallback to current time
'release_time' => '',
'new_version_available' => false
];
// if current update source is available
// If current update source is available
if ($this->getUpdateInfo()) {
$info['latest_version'] = $this->getUpdateInfo('latest_version');
@ -63,7 +63,7 @@ class UpdateController extends Controller
$info['new_version_available'] = false;
}
if (!$info['new_version_available']) {
if (! $info['new_version_available']) {
$info['release_time'] = Arr::get($this->getReleaseInfo($this->currentVersion), 'release_time');
}
}
@ -103,7 +103,7 @@ class UpdateController extends Controller
{
$action = $request->input('action');
if (!$this->newVersionAvailable()) return;
if (! $this->newVersionAvailable()) return;
$release_url = $this->getReleaseInfo($this->latestVersion)['release_url'];
$file_size = Utils::getRemoteFileSize($release_url);
@ -114,7 +114,7 @@ class UpdateController extends Controller
$update_cache = storage_path('update_cache');
if (!is_dir($update_cache)) {
if (! is_dir($update_cache)) {
if (false === Storage::disk('storage')->makeDirectory('update_cache')) {
return response(trans('admin.update.errors.write-permission'));
}
@ -128,7 +128,9 @@ class UpdateController extends Controller
case 'start-download':
if (!session()->has('tmp_path')) return "No temp path is set.";
if (! session()->has('tmp_path')) {
return "No temp path is set.";
}
try {
Utils::download($release_url, $tmp_path);
@ -143,7 +145,9 @@ class UpdateController extends Controller
case 'get-file-size':
if (!session()->has('tmp_path')) return "No temp path is set.";
if (! session()->has('tmp_path')) {
return "No temp path is set.";
}
if (file_exists($tmp_path)) {
return json(['size' => filesize($tmp_path)]);
@ -151,8 +155,9 @@ class UpdateController extends Controller
case 'extract':
if (!file_exists($tmp_path))
if (! file_exists($tmp_path)) {
return response('No file available');
}
$extract_dir = storage_path("update_cache/{$this->latestVersion}");
@ -205,8 +210,8 @@ class UpdateController extends Controller
protected function getUpdateInfo($key = null)
{
if (!$this->updateInfo) {
// add timestamp to control cdn cache
if (! $this->updateInfo) {
// Add timestamp to control cdn cache
$url = starts_with($this->updateSource, 'http')
? $this->updateSource."?v=".substr(time(), 0, -3)
: $this->updateSource;
@ -225,7 +230,7 @@ class UpdateController extends Controller
$this->latestVersion = Arr::get($this->updateInfo, 'latest_version', $this->currentVersion);
if (!is_null($key)) {
if (! is_null($key)) {
return Arr::get($this->updateInfo, $key);
}

View File

@ -46,7 +46,7 @@ class UserController extends Controller
*/
protected function calculatePercentageUsed($used, $rate)
{
// init default value to avoid division by zero
// Initialize default value to avoid division by zero.
$result['used'] = $used;
$result['total'] = 'UNLIMITED';
$result['percentage'] = 0;
@ -131,7 +131,7 @@ class UserController extends Controller
'new_password' => 'required|min:8|max:16'
]);
if (!$this->user->verifyPassword($request->input('current_password')))
if (! $this->user->verifyPassword($request->input('current_password')))
return json(trans('user.profile.password.wrong-password'), 1);
if ($this->user->changePasswd($request->input('new_password'))) {
@ -151,7 +151,7 @@ class UserController extends Controller
return json(trans('user.profile.email.existed'), 1);
}
if (!$this->user->verifyPassword($request->input('password')))
if (! $this->user->verifyPassword($request->input('password')))
return json(trans('user.profile.email.wrong-password'), 1);
if ($this->user->setEmail($request->input('new_email'))) {
@ -166,7 +166,7 @@ class UserController extends Controller
'password' => 'required|min:6|max:16'
]);
if (!$this->user->verifyPassword($request->input('password')))
if (! $this->user->verifyPassword($request->input('password')))
return json(trans('user.profile.delete.wrong-password'), 1);
if ($this->user->delete()) {

View File

@ -30,5 +30,4 @@ class AfterSessionBooted
return $next($request);
}
}

View File

@ -12,7 +12,7 @@ class CheckAdministrator
return $result;
}
if (!$result->isAdmin()) {
if (! $result->isAdmin()) {
abort(403, trans('auth.check.admin'));
}

View File

@ -17,8 +17,8 @@ class CheckAuthenticated
{
if (Session::has('uid')) {
if (!app()->bound('user.current')) {
// bind current user to container
if (! app()->bound('user.current')) {
// Bind current user to container
$user = app('users')->get(session('uid'));
app()->instance('user.current', $user);
} else {
@ -37,7 +37,7 @@ class CheckAuthenticated
abort(403, trans('auth.check.banned'));
}
// ask for filling email
// Ask for filling email
if ($user->email == "") {
return $this->askForFillingEmail($request, $next);
}
@ -64,7 +64,7 @@ class CheckAuthenticated
if (User::where('email', $request->email)->get()->isEmpty()) {
$user->setEmail($request->email);
// refresh token
// Refresh token
Session::put('token', $user->getToken(true));
Cookie::queue('token', $user->getToken(), 60);
@ -83,7 +83,7 @@ class CheckAuthenticated
protected function flashLastRequestedPath($path = null)
{
$path = $path ?: app('request')->path();
return session(['last_requested_path' => $path]);
}
}

View File

@ -35,7 +35,7 @@ class CheckPlayerExist
if ($r) return $next($request); // @codeCoverageIgnore
}
if (!Player::where('player_name', $player_name)->get()->isEmpty())
if (! Player::where('player_name', $player_name)->get()->isEmpty())
return $next($request);
if (option('return_200_when_notfound')) {
@ -47,6 +47,5 @@ class CheckPlayerExist
} else {
return abort(404, trans('general.unexistent-player'));
}
}
}

View File

@ -11,7 +11,7 @@ class CheckSessionUserValid
{
public function handle($request, \Closure $next)
{
// load session from cookie
// Load session from cookie
if ($request->cookie('uid') && $request->cookie('token')) {
Session::put('uid' , $request->cookie('uid'));
Session::put('token', $request->cookie('token'));
@ -21,12 +21,12 @@ class CheckSessionUserValid
$user = User::find(session('uid'));
if ($user && $user->getToken() == session('token')) {
// push user instance to repository
// Push user instance into repository
app('users')->set($user->uid, $user);
// bind current user to container
// Bind current user to container
app()->instance('user.current', $user);
} else {
// remove sessions & cookies
// Remove sessions & cookies
delete_sessions();
delete_cookies();

View File

@ -21,11 +21,13 @@ class DetectLanguagePrefer
public function detect(Request $request)
{
$locale = $request->input('lang') ?: ($request->cookie('locale') ?: $request->getPreferredLanguage());
if ($locale == 'zh_HANS_CN') { // For Microsoft Edge and IE
// For Microsoft Edge and IE
if ($locale == 'zh_HANS_CN') {
$locale = 'zh_CN';
}
// if current locale is an alias of other locale
// If current locale is an alias of other locale
if (($info = array_get(config('locales'), $locale)) && ($alias = array_get($info, 'alias'))) {
$locale = $alias;
}

View File

@ -16,5 +16,4 @@ class EncryptCookies extends BaseEncrypter
protected $except = [
'locale',
];
}

View File

@ -11,7 +11,7 @@ class RedirectIfUrlEndsWithSlash
if (substr($request->getRequestUri(), -1) == '/') {
$baseUrl = $request->getBaseUrl();
// try to remove slash at the end of current url
// Try to remove slash at the end of current url
$newUrl = substr($request->getRequestUri(), 0, -1);
if ($newUrl != $baseUrl) {

View File

@ -40,25 +40,25 @@ class Closet
$this->uid = $uid;
$this->db = DB::table('closets');
// create a new closet if not exists
if (!$this->db->where('uid', $uid)->get()) {
// Create a new closet if not exists
if (! $this->db->where('uid', $uid)->get()) {
$this->db->insert([
'uid' => $uid,
'textures' => '[]'
]);
}
// load items from json string
// Load items from json string
$this->textures = collect(json_decode(
$this->db->where('uid', $uid)->first()->textures,
true
));
// traverse items in the closet
// Traverse items in the closet
$removedCount = $this->textures->filter(function ($texture) use ($uid) {
$t = Texture::find($texture['tid']);
// if the texture was deleted
// If the texture was deleted
if (is_null($t)) {
return true;
}
@ -72,7 +72,7 @@ class Closet
$this->remove($texture['tid']);
})->count();
// return scores if the texture was deleted or set as private
// Return scores if the texture was deleted or set as private
if (option('return_score')) {
app('users')->get($uid)->setScore(
option('score_per_closet_item') * $removedCount,
@ -84,7 +84,7 @@ class Closet
/**
* Get array of instances of App\Models\Texture.
*
* @param string $category skin|cape|all
* @param string $category "skin" or "cape" or "all".
* @return array
*/
public function getItems($category = "all")
@ -119,7 +119,7 @@ class Closet
/**
* Add an item to the closet.
*
* @param int $tid
* @param int $tid
* @param string $name
* @return bool
*/
@ -154,7 +154,7 @@ class Closet
/**
* Get one texture info
*
* @param $tid Texture ID
* @param int $tid
* @return array|null Result
*/
public function get($tid)
@ -166,18 +166,18 @@ class Closet
* Rename closet item.
*
* @param integer $tid
* @param string $new_name
* @param string $newName
* @return bool
*/
public function rename($tid, $new_name)
public function rename($tid, $newName)
{
if (!$this->has($tid)) {
if (! $this->has($tid)) {
return false;
}
$this->textures->transform(function ($texture) use ($tid, $new_name) {
$this->textures->transform(function ($texture) use ($tid, $newName) {
if ($texture['tid'] == $tid) {
$texture['name'] = $new_name;
$texture['name'] = $newName;
}
return $texture;
});
@ -189,12 +189,13 @@ class Closet
/**
* Remove a texture from closet.
*
* @param int $tid
* @return boolean
* @return bool
*/
public function remove($tid)
{
if (!$this->has($tid)) {
if (! $this->has($tid)) {
return false;
}
$this->textures = $this->textures->reject(function ($texture) use ($tid) {
@ -223,13 +224,17 @@ class Closet
*/
public function save()
{
if (!$this->closet_modified) return false;
if (! $this->closet_modified) {
return false;
}
return $this->setTextures($this->textures->values()->toJson());
}
/**
* Save when the object will be destructed.
*
* @return void
*/
public function __destruct()
{
@ -249,5 +254,4 @@ class Closet
}
return $result;
}
}

View File

@ -56,8 +56,8 @@ class Player extends Model
/**
* Get specific texture of player.
*
* @param string $type steve|alex|cape
* @return string Sha256-hash of texture file.
* @param string $type "steve" or "alex" or "cape".
* @return string The sha256 hash of texture file.
*/
public function getTexture($type)
{
@ -99,20 +99,22 @@ class Player extends Model
/**
* Check and delete invalid textures from player profile.
*
* @return mixed
* @return $this
*/
public function checkForInvalidTextures()
{
foreach (self::$models as $model) {
$property = "tid_$model";
if (!Texture::find($this->$property)) {
if (! Texture::find($this->$property)) {
// reset texture
$this->$property = 0;
}
}
return $this->save();
$this->save();
return $this;
}
/**
@ -165,8 +167,7 @@ class Player extends Model
/**
* Set preferred model for the player.
*
* @param string $type slim|default
*
* @param string $type "slim" or "default".
* @return $this
*/
public function setPreference($type)
@ -194,17 +195,17 @@ class Player extends Model
/**
* Rename the player.
*
* @param string $new_name
* @return $this;
* @param string $newName
* @return $this
*/
public function rename($new_name)
public function rename($newName)
{
$this->update([
'player_name' => $new_name,
'player_name' => $newName,
'last_modified' => Utils::getTimeFormatted()
]);
$this->player_name = $new_name;
$this->player_name = $newName;
event(new PlayerProfileUpdated($this));
@ -214,8 +215,7 @@ class Player extends Model
/**
* Set a new owner for the player.
*
* @param int $uid
*
* @param int $uid
* @return $this
*/
public function setOwner($uid) {
@ -239,7 +239,7 @@ class Player extends Model
$responses = Event::fire(new GetPlayerJson($this, $api_type));
// if listeners return nothing
// If listeners return nothing
if (isset($responses[0]) && $responses[0] !== null) {
return $responses[0]; // @codeCoverageIgnore
} else {
@ -300,5 +300,4 @@ class Player extends Model
{
return strtotime($this['last_modified']);
}
}

View File

@ -61,7 +61,7 @@ class User extends Model
*/
public function getCloset()
{
if (!$this->closet) {
if (! $this->closet) {
$this->closet = new Closet($this->uid);
}
@ -76,7 +76,7 @@ class User extends Model
*/
public function verifyPassword($rawPasswd)
{
// compare directly if any responses is returned by event dispatcher
// Compare directly if any responses is returned by event dispatcher
if ($result = static::getEncryptedPwdFromEvent($rawPasswd, $this)) {
return hash_equals($this->password, $result); // @codeCoverageIgnore
}
@ -109,16 +109,16 @@ class User extends Model
public static function register($email, $password, \Closure $callback) {
$user = static::firstOrNew(['email' => $email]);
// if the email is already registered
// If the email is already registered
if ($user->uid) return false;
// pass the user instance to the callback
// Pass the user instance to the callback
call_user_func($callback, $user);
// save to get uid
// Save to get uid
$user->save();
// save again with password
// Save again with password
$user->password = static::getEncryptedPwdFromEvent($password, $user) ?: app('cipher')->hash($password, config('secure.salt'));
$user->save();
@ -184,7 +184,7 @@ class User extends Model
*/
public function getNickName()
{
if (!$this->uid) {
if (! $this->uid) {
return trans('general.unexistent-user');
} else {
return ($this->nickname == "") ? $this->email : $this->nickname;
@ -194,12 +194,12 @@ class User extends Model
/**
* Set nickname for the user.
*
* @param string $new_nickname
* @param string $newNickName
* @return bool
*/
public function setNickName($new_nickname)
public function setNickName($newNickName)
{
$this->nickname = $new_nickname;
$this->nickname = $newNickName;
return $this->save();
}
@ -211,7 +211,7 @@ class User extends Model
*/
public function getToken($refresh = false)
{
if (!$this->token || $refresh) {
if (! $this->token || $refresh) {
$this->token = md5($this->email . $this->password . config('secure.salt'));
}
@ -303,7 +303,7 @@ class User extends Model
*/
public function getSignRemainingTime()
{
// convert to timestamp
// Convert to timestamp
$lastSignTime = Carbon::parse($this->getLastSignTime());
if (option('sign_after_zero')) {
@ -364,9 +364,9 @@ class User extends Model
*/
public function delete()
{
// delete the players he owned
// Delete the players he owned
Player::where('uid', $this->uid)->delete();
// delete his closet
// Delete his closet
DB::table('closets')->where('uid', $this->uid)->delete();
return parent::delete();
@ -389,5 +389,4 @@ class User extends Model
{
return $query->where($field, 'LIKE', "%$value%");
}
}

View File

@ -16,8 +16,8 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
// replace HTTP_HOST with site url setted in options to prevent CDN source problems
if (!option('auto_detect_asset_url')) {
// Replace HTTP_HOST with site url setted in options to prevent CDN source problems
if (! option('auto_detect_asset_url')) {
$rootUrl = option('site_url');
if ($this->app['url']->isValidUrl($rootUrl)) {
@ -30,7 +30,7 @@ class AppServiceProvider extends ServiceProvider
}
Event::listen(Events\RenderingHeader::class, function($event) {
// provide some application information for javascript
// Provide some application information for javascript
$blessing = array_merge(array_except(config('app'), ['key', 'providers', 'aliases', 'cipher', 'log', 'url']), [
'base_url' => url('/'),
'site_name' => option('site_name')
@ -47,7 +47,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
// register default cipher
// Register default cipher
$className = "App\Services\Cipher\\".config('secure.cipher');
if (class_exists($className)) {

View File

@ -20,31 +20,31 @@ class BootServiceProvider extends ServiceProvider
*/
public function boot(Request $request)
{
// detect current locale
// Detect current locale
$this->app->call('App\Http\Middleware\DetectLanguagePrefer@detect');
$this->checkFilePermissions();
$this->checkDatabaseConnection();
// skip the installation check when setup or under CLI
if (!$request->is('setup*') && PHP_SAPI != "cli") {
// Skip the installation check when setup or under CLI
if (! $request->is('setup*') && PHP_SAPI != "cli") {
$this->checkInstallation();
}
}
protected function checkFilePermissions()
{
// check dotenv
if (!file_exists(app()->environmentFile())) {
// Check dotenv file
if (! file_exists(app()->environmentFile())) {
throw new PrettyPageException(trans('setup.file.no-dot-env'), -1);
}
// check permissions of storage path
if (!is_writable(storage_path())) {
// Check permissions of storage path
if (! is_writable(storage_path())) {
throw new PrettyPageException(trans('setup.permissions.storage'), -1);
}
if (!SetupController::checkDirectories()) {
if (! SetupController::checkDirectories()) {
throw new PrettyPageException(trans('setup.file.permission-error'), -1);
}
}
@ -52,11 +52,11 @@ class BootServiceProvider extends ServiceProvider
protected function checkDatabaseConnection()
{
try {
// check database config
// Check database config
Database::prepareConnection();
} catch (\Exception $e) {
if ($this->app->runningInConsole()) {
// dump some useful information for debugging
// Dump some useful information for debugging
dump([
'APP_ENV' => app()->environment(),
'DOTENV_FILE' => app()->environmentFile(),
@ -73,8 +73,8 @@ class BootServiceProvider extends ServiceProvider
protected function checkInstallation()
{
// redirect to setup wizard
if (!SetupController::checkTablesExist()) {
// Redirect to setup wizard
if (! SetupController::checkTablesExist()) {
return redirect('/setup')->send();
}

View File

@ -19,13 +19,11 @@ class EventServiceProvider extends ServiceProvider
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}

View File

@ -11,7 +11,7 @@ class MemoryServiceProvider extends ServiceProvider
{
public function boot()
{
Storage::extend('memory', function($app, $config) {
Storage::extend('memory', function ($app, $config) {
return new Filesystem(new MemoryAdapter());
});
}

View File

@ -17,21 +17,21 @@ class PluginServiceProvider extends ServiceProvider
*/
public function boot(PluginManager $plugins)
{
// store paths of class files of plugins
// Store paths of class files of plugins
$src_paths = [];
$loader = $this->app->make('translation.loader');
// make view instead of view.finder since the finder is defined as not a singleton
// Make view instead of view.finder since the finder is defined as not a singleton
$finder = $this->app->make('view');
foreach ($plugins->getPlugins() as $plugin) {
if ($plugin->isEnabled()) {
$src_paths[$plugin->getNameSpace()] = $plugin->getPath()."/src";
// add paths of views
// Add paths of views
$finder->addNamespace($plugin->getNameSpace(), $plugin->getPath()."/views");
}
// always add paths of translation files for namespace hints
// Always add paths of translation files for namespace hints
$loader->addNamespace($plugin->getNameSpace(), $plugin->getPath()."/lang");
}
@ -42,7 +42,7 @@ class PluginServiceProvider extends ServiceProvider
foreach ($bootstrappers as $file) {
$bootstrapper = require $file;
// call closure using service container
// Call closure using service container
$this->app->call($bootstrapper);
}
}
@ -54,7 +54,7 @@ class PluginServiceProvider extends ServiceProvider
Events\PluginWasDeleted::class,
Events\PluginWasDisabled::class,
], function ($event) {
// call callback functions of plugin
// Call callback functions of plugin
if (file_exists($filename = $event->plugin->getPath()."/callbacks.php")) {
$callbacks = require $filename;
@ -83,15 +83,15 @@ class PluginServiceProvider extends ServiceProvider
protected function registerClassAutoloader($paths)
{
spl_autoload_register(function ($class) use ($paths) {
// traverse in registered plugin paths
// Traverse in registered plugin paths
foreach ((array) array_keys($paths) as $namespace) {
if ($namespace != '' && mb_strpos($class, $namespace) === 0) {
// parse real file path
// Parse real file path
$path = $paths[$namespace].Str::replaceFirst($namespace, '', $class).".php";
$path = str_replace('\\', '/', $path);
if (file_exists($path)) {
// include class file if it exists
// Include class file if it exists
include $path;
}
}

View File

@ -19,5 +19,4 @@ abstract class BaseCipher implements EncryptInterface
{
return hash_equals($hash, $this->hash($password, $salt));
}
}

View File

@ -11,5 +11,4 @@ class SALTED2SHA512 extends BaseCipher
{
return hash('sha512', hash('sha512', $value).$salt);
}
}

View File

@ -225,7 +225,7 @@ class Database
public function __destruct()
{
if (!is_null($this->connection)) {
if (! is_null($this->connection)) {
$this->connection->close();
}
}

View File

@ -31,7 +31,7 @@ class Hook
$offset = 0;
foreach ($event->menu[$category] as $item) {
// push new menu items at the given position
// Push new menu items at the given position
if ($offset == $position) {
$new[] = $menu;
}
@ -77,7 +77,7 @@ class Hook
Event::listen(Events\RenderingHeader::class, function($event) use ($urls, $pages)
{
foreach ($pages as $pattern) {
if (!app('request')->is($pattern))
if (! app('request')->is($pattern))
continue;
foreach ((array) $urls as $url) {
@ -95,7 +95,7 @@ class Hook
Event::listen(Events\RenderingFooter::class, function($event) use ($urls, $pages)
{
foreach ($pages as $pattern) {
if (!app('request')->is($pattern))
if (! app('request')->is($pattern))
continue;
foreach ((array) $urls as $url) {

View File

@ -62,7 +62,7 @@ class Minecraft
$transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127);
imagefill($dest, 0, 0, $transparent);
if (!$side or $side === 'front') {
if (! $side or $side === 'front') {
imagecopy($dest, $src, 4 * $ratio, 0 * $ratio, 8 * $ratio, 8 * $ratio, 8 * $ratio, 8 * $ratio); // Head - 1
imagecopy($dest, $src, 4 * $ratio, 0 * $ratio, 40 * $ratio, 8 * $ratio, 8 * $ratio, 8 * $ratio); // Head - 2
imagecopy($dest, $src, 4 * $ratio, 8 * $ratio, 20 * $ratio, 20 * $ratio, 8 * $ratio, 12 * $ratio); // Body - 1
@ -106,12 +106,12 @@ class Minecraft
}
if (!$side or $side === 'back') {
if (! $side or $side === 'back') {
imagecopy($dest, $src, $half_width + 4 * $ratio, 8 * $ratio, 32 * $ratio, 20 * $ratio, 8 * $ratio, 12 * $ratio); // Body
imagecopy($dest, $src, $half_width + 4 * $ratio, 0 * $ratio, 24 * $ratio, 8 * $ratio, 8 * $ratio, 8 * $ratio); // Head
imagecopy($dest, $src, $half_width + 8 * $ratio, 20 * $ratio, 12 * $ratio, 20 * $ratio, 4 * $ratio, 12 * $ratio); // Right Leg
imagecopy($dest, $src, $half_width + 4 * $ratio, 0 * $ratio, 56 * $ratio, 8 * $ratio, 8 * $ratio, 8 * $ratio); // Headwear
if ($alex) {
imagecopy($dest, $src, $half_width + 12 * $ratio, 8 * $ratio, 51 * $ratio, 20 * $ratio, 3 * $ratio, 12 * $ratio); // Right Arm

View File

@ -65,17 +65,17 @@ class OptionForm
*/
public function __call($method, $params)
{
if (!in_array($method, ['text', 'checkbox', 'textarea', 'select', 'group'])) {
if (! in_array($method, ['text', 'checkbox', 'textarea', 'select', 'group'])) {
throw new BadMethodCallException("Method [$method] does not exist on option form.");
}
// assign name for option item
if (!isset($params[1]) || Arr::get($params, 1) == OptionForm::AUTO_DETECT) {
// Assign name for option item
if (! isset($params[1]) || Arr::get($params, 1) == OptionForm::AUTO_DETECT) {
$params[1] = Arr::get(trans("options.$this->id.$params[0]"), 'title', trans("options.$this->id.$params[0]"));
}
$class = new ReflectionClass('App\Services\OptionForm'.Str::title($method));
// use ReflectionClass to create a new OptionFormItem instance
// Use ReflectionClass to create a new OptionFormItem instance
$item = $class->newInstanceArgs($params);
$item->setParentId($this->id);
$this->items[] = $item;
@ -248,11 +248,11 @@ class OptionForm
$allPostData = $request->all();
if ($request->isMethod('POST') && Arr::get($allPostData, 'option') == $this->id) {
if (!is_null($callback)) {
if (! is_null($callback)) {
call_user_func($callback, $this);
}
if (!is_null($this->hookBefore)) {
if (! is_null($this->hookBefore)) {
call_user_func($this->hookBefore, $this);
}
@ -268,7 +268,7 @@ class OptionForm
}
continue;
}
// push item to the queue
// Push item to the queue
$postOptionQueue[] = $item;
}
@ -287,7 +287,7 @@ class OptionForm
continue;
}
// compare with raw option value
// Compare with raw option value
if (($data = Arr::get($allPostData, $item->id)) != option($item->id, null, true)) {
$formatted = is_null($item->format) ? $data : call_user_func($item->format, $data);
Option::set($item->id, $formatted);
@ -298,7 +298,7 @@ class OptionForm
Option::set($key, serialize($value));
}
if (!is_null($this->hookAfter)) {
if (! is_null($this->hookAfter)) {
call_user_func($this->hookAfter, $this);
}
@ -322,7 +322,7 @@ class OptionForm
$option = Arr::get(
$this->values,
$result['id'],
// fallback to load from options
// Fallback to load from options
@unserialize(option($result['id']))
);
@ -337,7 +337,7 @@ class OptionForm
*/
protected function assignValues()
{
// load values for items if not set manually
// Load values for items if not set manually
foreach ($this->items as $item) {
if ($item instanceof OptionFormGroup) {
foreach ($item->items as &$groupItem) {
@ -382,12 +382,12 @@ class OptionForm
*/
public function render()
{
if (!is_null($this->alwaysCallback)) {
if (! is_null($this->alwaysCallback)) {
call_user_func($this->alwaysCallback, $this);
}
// attach submit button to the form
if (!$this->renderWithOutSubmitButton) {
if (! $this->renderWithOutSubmitButton) {
$this->addButton([
'style' => 'primary',
'text' => trans('general.submit'),

View File

@ -30,14 +30,14 @@ class OptionRepository extends Repository
/**
* Get the specified option value.
*
* @param string $key
* @param mixed $default
* @param raw $raw return raw value without convertion
* @param string $key
* @param mixed $default
* @param bool $raw Return raw value without convertion.
* @return mixed
*/
public function get($key, $default = null, $raw = false)
{
if (!$this->has($key) && Arr::has(config('options'), $key)) {
if (! $this->has($key) && Arr::has(config('options'), $key)) {
$this->set($key, config("options.$key"));
}
@ -67,8 +67,8 @@ class OptionRepository extends Repository
/**
* Set a given option value.
*
* @param array|string $key
* @param mixed $value
* @param array|string $key
* @param mixed $value
* @return void
*/
public function set($key, $value = null)
@ -93,7 +93,7 @@ class OptionRepository extends Repository
protected function doSetOption($key, $value)
{
try {
if (!DB::table('options')->where('option_name', $key)->first()) {
if (! DB::table('options')->where('option_name', $key)->first()) {
DB::table('options')
->insert(['option_name' => $key, 'option_value' => $value]);
} else {
@ -118,7 +118,7 @@ class OptionRepository extends Repository
try {
foreach ($this->itemsModified as $key) {
if (!DB::table('options')->where('option_name', $key)->first()) {
if (! DB::table('options')->where('option_name', $key)->first()) {
DB::table('options')
->insert(['option_name' => $key, 'option_value' => $this[$key]]);
} else {
@ -128,7 +128,7 @@ class OptionRepository extends Repository
}
}
// clear the list
// Clear the list
$this->itemsModified = [];
} catch (QueryException $e) {
return;
@ -161,5 +161,4 @@ class OptionRepository extends Repository
{
$this->save();
}
}

View File

@ -38,7 +38,7 @@ class UserRepository extends Repository
*/
public function get($identification, $type = 'uid')
{
if (!$this->has($identification, $type)) {
if (! $this->has($identification, $type)) {
if ($type == "username") {
$player = Player::where('player_name', $identification)->first();
@ -67,7 +67,7 @@ class UserRepository extends Repository
return ($value->$type == $identification);
});
// return first element
// Return first element
reset($result);
return current($result);
}

View File

@ -21,7 +21,7 @@ class Utils
public static function getClientIp()
{
if (option('ip_get_method') == "0") {
// fallback to REMOTE_ADDR
// Fallback to REMOTE_ADDR
$ip = array_get(
$_SERVER, 'HTTP_X_FORWARDED_FOR',
array_get($_SERVER, 'HTTP_CLIENT_IP', $_SERVER['REMOTE_ADDR'])
@ -47,10 +47,10 @@ class Utils
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
return true;
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
if (! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
return true;
if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
if (! empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
return true;
return false;
@ -74,7 +74,7 @@ class Utils
{
$versions = [$version1, $version2];
// pre-processing for version contains hyphen
// Pre-processing for version contains hyphen
foreach ([0, 1] as $offset) {
if (false !== ($result = self::parseVersionWithHyphen($versions[$offset]))) {
$versions[$offset] = $result;
@ -89,12 +89,12 @@ class Utils
// v3.2-pr < v3.2
if ($sub1 != "" || $sub2 != "") {
// if both of sub-versions are not empty
// If both of sub-versions are not empty
if ($sub1 != "" && $sub2 != "") {
return version_compare($sub1, $sub2, $operator);
} else {
$result = version_compare($sub1, $sub2, $operator);
// reverse the result since version_compare() will determine that "beta" > ""
// Reverse the result since version_compare() will determine that "beta" > ""
return ($operator == "=") ? $result : !$result;
}
}
@ -120,8 +120,8 @@ class Utils
/**
* Rename uploaded file
*
* @param \Illuminate\Http\UploadedFile $file files uploaded via HTTP POST
* @return string $hash sha256 hash of file
* @param \Illuminate\Http\UploadedFile $file The Files uploaded via HTTP POST
* @return string $hash The sha256 hash of file
* @throws \Exception
*/
public static function upload($file)
@ -129,7 +129,7 @@ class Utils
$hash = hash_file('sha256', $file);
try {
$storage = Storage::disk('textures');
if (!$storage->exists($hash)) {
if (! $storage->exists($hash)) {
$storage->put($hash, file_get_contents($file));
}
} catch (\Exception $e) {
@ -150,14 +150,14 @@ class Utils
if ($fp = fopen($url, "rb")) {
if (!$download_fp = fopen($path, "wb")) {
if (! $download_fp = fopen($path, "wb")) {
return false;
}
while (!feof($fp)) {
if (!file_exists($path)) {
// cancel downloading if destination is no longer available
if (! file_exists($path)) {
// Cancel downloading if destination is no longer available
fclose($download_fp);
return false;
@ -183,7 +183,7 @@ class Utils
{
$regex = '/^Content-Length: *+\K\d++$/im';
if (!$fp = @fopen($url, 'rb')) {
if (! $fp = @fopen($url, 'rb')) {
return false;
}

View File

@ -38,7 +38,7 @@ if (! function_exists('assets')) {
function assets($relativeUri)
{
// add query string to fresh cache
// Add query string to fresh cache
if (Str::startsWith($relativeUri, 'css') || Str::startsWith($relativeUri, 'js')) {
return url("resources/assets/dist/$relativeUri")."?v=".config('app.version');
} elseif (Str::startsWith($relativeUri, 'lang')) {
@ -82,7 +82,7 @@ if (! function_exists('json')) {
if (count($args) == 1 && is_array($args[0])) {
return Response::json($args[0]);
} elseif (count($args) == 3 && is_array($args[2])) {
// the third argument is array of extra fields
// The third argument is array of extra fields
return Response::json(array_merge([
'errno' => $args[1],
'msg' => $args[0]
@ -124,7 +124,7 @@ if (! function_exists('bs_favicon')) {
function bs_favicon()
{
// fallback to default favicon
// Fallback to default favicon
$url = Str::startsWith($url = (option('favicon_url') ?: config('options.favicon_url')), 'http') ? $url : assets($url);
return <<< ICONS
@ -144,7 +144,7 @@ if (! function_exists('bs_menu')) {
Event::fire($type == "user" ? new App\Events\ConfigureUserMenu($menu)
: new App\Events\ConfigureAdminMenu($menu));
if (!isset($menu[$type])) {
if (! isset($menu[$type])) {
throw new InvalidArgumentException;
}
@ -367,7 +367,7 @@ if (! function_exists('runtime_check')) {
function runtime_check(array $requirements)
{
foreach ($requirements['extensions'] as $extension) {
if (!extension_loaded($extension)) {
if (! extension_loaded($extension)) {
exit(
"[Error] You have not installed the $extension extension <br>".
"[错误] 你尚未安装 $extension 扩展!安装方法请自行搜索,蟹蟹。"
@ -378,7 +378,7 @@ if (! function_exists('runtime_check')) {
foreach (array_get($requirements, 'write_permission', []) as $dir) {
$realPath = realpath(__DIR__."/../$dir");
if (!is_writable($realPath)) {
if (! is_writable($realPath)) {
exit(
"[Error] The program lacks write permission to directory $dir <br>".
"[错误] 程序缺少对 $dir 目录的写权限或目录不存在,请手动授权/创建"

@ -1 +1 @@
Subproject commit 8f50ab68b2a0690d79ac8c8bc265823a3973031e
Subproject commit fd91442db6bd86de7629ef3c4b6e99d6410518aa