2022-05-18 23:54:22 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Hleb\Constructor\Handlers\Request;
|
2022-05-22 09:21:31 +02:00
|
|
|
|
use App\Models\ActionModel;
|
2022-05-18 23:54:22 +02:00
|
|
|
|
|
|
|
|
|
class Access
|
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
public static function limitForMiddleware()
|
2022-05-18 23:54:22 +02:00
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
$type = Request::get('type');
|
|
|
|
|
|
2022-05-18 23:54:22 +02:00
|
|
|
|
if (UserData::checkAdmin()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-05-19 10:26:15 +02:00
|
|
|
|
|
2022-05-23 17:42:24 +02:00
|
|
|
|
if (self::limitingMode() === false) {
|
2022-05-29 09:33:58 +02:00
|
|
|
|
Msg::add(__('msg.silent_mode',), 'error');
|
2022-05-23 17:42:24 +02:00
|
|
|
|
redirect('/');
|
|
|
|
|
}
|
2022-05-19 10:26:15 +02:00
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
// TODO: Изменим поля в DB, чтобы использовать limitContent для messages и invites:
|
|
|
|
|
if (in_array($type, ['post', 'amswer', 'comment', 'item', 'team'])) {
|
|
|
|
|
if (self::limitContent($type) === false) {
|
2022-05-29 09:33:58 +02:00
|
|
|
|
Msg::add(__('msg.limit_day'), 'error');
|
2022-05-22 09:21:31 +02:00
|
|
|
|
redirect('/');
|
|
|
|
|
}
|
2022-05-18 23:54:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Stop changing (adding) content if the user is frozen (silent mode)
|
|
|
|
|
*
|
|
|
|
|
* Остановим изменение (добавление) контента если пользователь заморожен (немой режим)
|
|
|
|
|
*/
|
|
|
|
|
public static function limitingMode()
|
2022-05-18 23:54:22 +02:00
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
if (UserData::getLimitingMode() == 1) {
|
2022-05-23 17:42:24 +02:00
|
|
|
|
return false;
|
2022-05-18 23:54:22 +02:00
|
|
|
|
}
|
2022-05-22 09:21:31 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-05-19 10:26:15 +02:00
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* From what TL level is it possible to create content.
|
|
|
|
|
*
|
|
|
|
|
* In config: tl_add_post
|
|
|
|
|
*/
|
|
|
|
|
public static function limitContent($type)
|
2022-05-29 09:33:58 +02:00
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* From what TL level is it possible to create content.
|
|
|
|
|
*
|
|
|
|
|
* С какого уровня TL возможно создавать контент.
|
|
|
|
|
*
|
|
|
|
|
* In config: tl_add_post
|
|
|
|
|
*/
|
|
|
|
|
if (self::trustLevels(config('trust-levels.tl_add_' . $type)) == false) {
|
2022-05-18 23:54:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Limit per day for the level of confidence, taking into account coefficients.
|
|
|
|
|
*
|
|
|
|
|
* Лимит за сутки для уровня доверия с учетом коэффициентов.
|
|
|
|
|
*
|
|
|
|
|
* In config: perDay_post
|
|
|
|
|
*/
|
2022-05-23 23:58:39 +02:00
|
|
|
|
$сount = ActionModel::getSpeedDay(UserData::getUserId(), $type);
|
2022-05-22 09:21:31 +02:00
|
|
|
|
|
|
|
|
|
$total = config('trust-levels.perDay_' . $type) * config('trust-levels.multiplier_' . UserData::getUserTl());
|
2022-05-18 23:54:22 +02:00
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
if ($сount >= floor($total)) {
|
2022-05-18 23:54:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Trust Level Sharing.
|
|
|
|
|
*
|
|
|
|
|
* Общий доступ для уровня доверия.
|
|
|
|
|
*/
|
|
|
|
|
public static function trustLevels($trust_level)
|
2022-05-18 23:54:22 +02:00
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
if (UserData::getUserTl() < $trust_level) {
|
2022-05-18 23:54:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 17:42:24 +02:00
|
|
|
|
/**
|
|
|
|
|
* Time limits after posting.
|
|
|
|
|
*
|
|
|
|
|
* Лимиты на время после публикации.
|
|
|
|
|
*/
|
|
|
|
|
public static function limiTime($adding_time, $limit_time = false)
|
|
|
|
|
{
|
|
|
|
|
if ($limit_time == true) {
|
|
|
|
|
$diff = strtotime(date("Y-m-d H:i:s")) - strtotime($adding_time);
|
|
|
|
|
$time = floor($diff / 60);
|
|
|
|
|
|
|
|
|
|
if ($time > $limit_time) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Content type, content author, time added and how much time can be edited.
|
|
|
|
|
*
|
|
|
|
|
* Тип контента, автор контента, время добавления и сколько времени можно редактировать.
|
|
|
|
|
*/
|
|
|
|
|
public static function author($type_content, $author_id, $adding_time, $limit_time = false)
|
2022-05-18 23:54:22 +02:00
|
|
|
|
{
|
2022-05-22 09:21:31 +02:00
|
|
|
|
if (UserData::checkAdmin()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 17:42:24 +02:00
|
|
|
|
/**
|
|
|
|
|
* If the author's Tl has been downgraded.
|
|
|
|
|
*
|
|
|
|
|
* Если Tl автора было изменено на понижение.
|
|
|
|
|
*
|
|
|
|
|
* In config: tl_add_post
|
|
|
|
|
*/
|
|
|
|
|
if (self::trustLevels(config('trust-levels.tl_add_' . $type_content)) == false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only the author has access.
|
|
|
|
|
*
|
|
|
|
|
* Доступ получает только автор.
|
|
|
|
|
*/
|
2022-05-22 09:21:31 +02:00
|
|
|
|
if ($author_id != UserData::getUserId()) {
|
2022-05-18 23:54:22 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 09:21:31 +02:00
|
|
|
|
self::limiTime($adding_time, $limit_time);
|
|
|
|
|
|
2022-05-18 23:54:22 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|