Skip to content

Commit

Permalink
Удалены старые темы, удален пакет MobileDetect, удалено автоопределен…
Browse files Browse the repository at this point in the history
…ие темы
  • Loading branch information
visavi committed Jan 26, 2020
1 parent 06ab988 commit 2d8b509
Show file tree
Hide file tree
Showing 103 changed files with 348 additions and 3,045 deletions.
71 changes: 15 additions & 56 deletions app/Classes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
namespace App\Classes;

use App\Models\Setting;
use App\Models\User;
use DI\Container;
use FastRoute\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Mobile_Detect;

class Application
{
/** @var array */
public $settings;

/**
* Application constructor
*/
Expand All @@ -30,7 +25,6 @@ public function __construct()
date_default_timezone_set(defaultSetting('timezone'));

$this->cookieAuth();
$this->accessAuth();
$this->setSetting();
}

Expand Down Expand Up @@ -109,80 +103,45 @@ private function cookieAuth(): void
}
}

/**
* Проверяет данные пользователя
*
* @return void
*/
private function accessAuth(): void
{
/** @var User $user */
if ($user = getUser()) {
$request = request();

// Забанен
if ($user->level === User::BANNED && ! $request->is('ban', 'rules', 'logout')) {
redirect('/ban?user=' . $user->login);
}

// Подтверждение регистрации
if ($user->level === User::PENDED && defaultSetting('regkeys') && ! $request->is('key', 'ban', 'login', 'logout')) {
redirect('/key?user=' . $user->login);
}

$user->updatePrivate();

// Получение ежедневного бонуса
if ($user->timebonus < strtotime('-23 hours', SITETIME)) {
$user->increment('money', defaultSetting('bonusmoney'));
$user->update(['timebonus' => SITETIME]);

setFlash('success', __('main.daily_bonus', ['money' => plural(defaultSetting('bonusmoney'), defaultSetting('moneyname'))]));
}
}
}

/**
* Устанавливает настройки
*
* @return void
*/
private function setSetting(): void
{
$userSets = [];
$user = getUser();
$user = getUser();

$browser = new Mobile_Detect();
$isWeb = ! $browser->isMobile() && ! $browser->isTablet();

$userSets['themes'] = $user ? $user['themes'] : 0;
$userSets['language'] = $user ? $user['language'] : defaultSetting('language');
$userSets['themes'] = $user ? $user['themes'] : defaultSetting('themes');

if (empty($userSets['themes']) && defaultSetting('webthemes') && $isWeb) {
$userSets['themes'] = defaultSetting('webthemes');
}

if (! file_exists(HOME . '/themes/' . $userSets['themes'])) {
$userSets['themes'] = 'default';
if (isset($_SESSION['language'])) {
$userSets['language'] = $_SESSION['language'];
}

if (isset($_SESSION['language']) && ! $user) {
$userSets['language'] = $_SESSION['language'];
if (! file_exists(RESOURCES . '/lang/' . $userSets['language'])) {
$userSets['language'] = defaultSetting('language');
}

if (empty($userSets['language']) || ! file_exists(RESOURCES . '/lang/' . $userSets['language'])) {
$userSets['language'] = 'ru';
if (! file_exists(HOME . '/themes/' . $userSets['themes'])) {
$userSets['themes'] = defaultSetting('themes');
}

Setting::setUserSettings($userSets);

if ($user) {
$user->checkAccess();
$user->updatePrivate();
$user->gettingBonus();
}

/* Установка сессионных переменных */
if (empty($_SESSION['token'])) {
$_SESSION['token'] = Str::random(8);
}

if (empty($_SESSION['protect'])) {
$_SESSION['protect'] = mt_rand(1000, 99999);
$_SESSION['protect'] = mt_rand(10000, 99999);
}

if (empty($_SESSION['hits'])) {
Expand Down
38 changes: 36 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function getOnline(): string
{
static $visits;

$online = '<div class="online bg-danger" title="Оффлайн"></div>';
$online = '<div class="user-status bg-danger" title="Оффлайн"></div>';

if (! $visits) {
$visits = Cache::remember('visit', 10, static function () {
Expand All @@ -403,7 +403,7 @@ public function getOnline(): string
}

if (isset($visits[$this->id])) {
$online = '<div class="online bg-success" title="Онлайн"></div>';
$online = '<div class="user-status bg-success" title="Онлайн"></div>';
}

return $online;
Expand Down Expand Up @@ -676,7 +676,41 @@ public function updatePrivate(): void
'sendprivatmail' => 0,
]);
}
}
}

/**
* Check Access
*
* return void
*/
public function checkAccess(): void
{
$request = request();

// Banned
if ($this->level === self::BANNED && ! $request->is('ban', 'rules', 'logout')) {
redirect('/ban?user=' . $this->login);
}

// Confirm registration
if ($this->level === self::PENDED && setting('regkeys') && ! $request->is('key', 'ban', 'login', 'logout')) {
redirect('/key?user=' . $this->login);
}
}

/**
* Getting daily bonus
*
* return void
*/
public function gettingBonus(): void
{
if ($this->timebonus < strtotime('-23 hours', SITETIME)) {
$this->increment('money', setting('bonusmoney'));
$this->update(['timebonus' => SITETIME]);

setFlash('success', __('main.daily_bonus', ['money' => plural(setting('bonusmoney'), setting('moneyname'))]));
}
}
}
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"illuminate/filesystem": "~6.8",
"illuminate/redis": "~6.8",
"illuminate/pagination": "~6.8",
"mobiledetect/mobiledetectlib": "^2.8",
"php-ffmpeg/php-ffmpeg": "~0.14",
"swiftmailer/swiftmailer": "~6.2",
"josegonzalez/dotenv": "^3.2",
Expand Down

0 comments on commit 2d8b509

Please sign in to comment.