FIX:: URL поста в результате поиска

+ EDIT: Class Restrictions (для работы)...
This commit is contained in:
Evg 2022-05-21 12:09:34 +03:00
parent 4ad3943579
commit 79207619a1
2 changed files with 8 additions and 82 deletions

View file

@ -3,92 +3,18 @@
namespace App\Middleware\Before;
use Hleb\Scheme\App\Middleware\MainMiddleware;
use Hleb\Constructor\Handlers\Request;
use App\Models\ActionModel;
use UserData, Html;
use Access;
class Restrictions extends MainMiddleware
{
private $user;
private $type;
public function __construct()
{
$this->user = UserData::get();
$this->type = Request::get('type');
}
/**
* Check for limits and general freezing of the participant (silent mode)
*
* Проверим на лимиты и общую заморозку участника (немой режим)
*/
function index()
{
self::limitingMode();
// TODO: Изменим поля в DB, чтобы использовать limitContentDay для message и item:
if (!in_array($this->type, ['message', 'item'])) {
if ($this->limitContentDay($this->type) === false) {
Html::addMsg(__('msg.limit_day', ['tl' => UserData::getUserTl()]), 'error');
redirect('/');
}
}
return true;
Access::limitForMiddleware();
}
// Stop changing (adding) content if the user is "frozen"
// Остановим изменение (добавление) контента если пользователь "заморожен"
public function limitingMode()
{
if ($this->user['limiting_mode'] == 1) {
Html::addMsg(__('msg.silent_mode',), 'error');
redirect('/');
}
return true;
}
// Лимит за сутки для всех TL и лимит за день
// + лимит по уровню доверия
public function limitContentDay($type)
{
if (UserData::checkAdmin()) {
return true;
}
// По уровню доверия на доступ
// Пример config: tl_add_post
if ($this->trustLevels(config('trust-levels.tl_add_' . $type)) == false) {
return false;
}
$сount = ActionModel::getSpeedDay($this->user['id'], $type);
// Лимит за день для ВСЕХ уровней доверия
// Пример config: all_limit
if ($сount >= config('trust-levels.all_limit')) {
return false;
}
// Если TL меньше 2 (начальный уровень после регистрации)
// Пример config: perDay_post
if (UserData::getUserTl() < UserData::USER_SECOND_LEVEL) {
$сount = ActionModel::allContentUserCount($this->user['id']);
if ($сount >= config('trust-levels.perDay_' . $type)) {
return false;
}
}
return true;
}
// Общий доступ для уровня доверия
public function trustLevels($allowed_tl)
{
if ($allowed_tl === true) {
return true;
}
if (UserData::getUserTl() < $allowed_tl) {
return false;
}
return true;
}
}

View file

@ -28,7 +28,7 @@ $sw = $sw ?? '?';
if ($type == 'website') {
$url_content = $result['item_url'];
} else {
$url_content = '/post/' . $result['id'];
$url_content = '/post/' . $result['post_id'];
}
?>