114 lines
3.1 KiB
PHP
114 lines
3.1 KiB
PHP
<?php
|
||
|
||
namespace ForkBB\Models\Pages;
|
||
|
||
use ForkBB\Core\Validator;
|
||
use ForkBB\Models\Page;
|
||
use ForkBB\Models\User\Model as User;
|
||
|
||
abstract class Profile extends Page
|
||
{
|
||
use CrumbTrait;
|
||
|
||
/**
|
||
* Инициализирует профиль
|
||
*
|
||
* @param string|int $id
|
||
*
|
||
* @return bool
|
||
*/
|
||
protected function initProfile($id)
|
||
{
|
||
$this->curUser = $this->c->users->load((int) $id);
|
||
|
||
if (! $this->curUser instanceof User || ($this->curUser->isUnverified && ! $this->user->isAdmMod)) {
|
||
return false;
|
||
}
|
||
|
||
$this->c->Lang->load('profile');
|
||
|
||
$this->rules = $this->c->ProfileRules->setUser($this->curUser);
|
||
$this->robots = 'noindex';
|
||
$this->fIndex = $this->rules->my ? 'profile' : 'userlist';
|
||
$this->nameTpl = 'profile';
|
||
$this->onlinePos = 'profile-' . $this->curUser->id; // ????
|
||
$this->title = \ForkBB\__('%s\'s profile', $this->curUser->username);
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* Проверяет пароль на совпадение с текущим пользователем
|
||
*
|
||
* @param Validator $v
|
||
* @param string $password
|
||
*
|
||
* @return string
|
||
*/
|
||
public function vCheckPassword(Validator $v, $password)
|
||
{
|
||
if (! \password_verify($password, $this->user->password)) {
|
||
$v->addError('Invalid passphrase');
|
||
}
|
||
|
||
return $password;
|
||
}
|
||
|
||
/**
|
||
* Возвращает хлеьные крошки
|
||
*
|
||
* @param mixed ...$args
|
||
*
|
||
* @return array
|
||
*/
|
||
protected function crumbsExt(...$args)
|
||
{
|
||
$args[] = [$this->curUser->link, \ForkBB\__('User %s', $this->curUser->username)];
|
||
$args[] = [$this->c->Router->link('Userlist'), \ForkBB\__('User list')];
|
||
|
||
return $this->crumbs(...$args);
|
||
}
|
||
|
||
/**
|
||
* Формирует массив кнопок
|
||
*
|
||
* @param string $type
|
||
*
|
||
* @return array
|
||
*/
|
||
protected function btns($type)
|
||
{
|
||
$btns = [];
|
||
if ($this->rules->banUser) {
|
||
$btns['ban-user'] = [
|
||
$this->c->Router->link('', ['id' => $this->curUser->id]),
|
||
\ForkBB\__('Ban user'),
|
||
];
|
||
}
|
||
if ($this->rules->deleteUser) {
|
||
$btns['delete-user'] = [
|
||
$this->c->Router->link('', ['id' => $this->curUser->id]),
|
||
\ForkBB\__('Delete user'),
|
||
];
|
||
}
|
||
if ('edit' != $type && $this->rules->editProfile) {
|
||
$btns['edit-profile'] = [
|
||
$this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]),
|
||
\ForkBB\__('Edit '),
|
||
];
|
||
}
|
||
if ('view' != $type) {
|
||
$btns['view-profile'] = [
|
||
$this->curUser->link,
|
||
\ForkBB\__('View '),
|
||
];
|
||
}
|
||
if ('config' != $type && $this->rules->editConfig) {
|
||
$btns['edit-settings'] = [
|
||
$this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]),
|
||
\ForkBB\__('Configure '),
|
||
];
|
||
}
|
||
return $btns;
|
||
}
|
||
}
|