setTemplate('profile/page', 'users'); $this->setKey('user-profile'); $this->withSeoSettings('user-profile', 'users'); $this->initFilterViewOptions(); } public static function handleTabs(string $login, string $tab = '') { # Tab => Menu Item Id => Page return Site::menu(static::MENU)->forwardToPage( trim($tab, ' /'), func_get_args() ); } public function handle(string $login, string $tab = '') { $this->userLogin = $login; $this->tab = $tab; $this->loadUser(); if (! $this->user) { return $this->errors->error404(); } } public function blocks() { $this->addMenu(static::MENU); $this->addBlock('contactsBlock', ContactsBlock::class); $this->addBlock('onlineBlock', OnlineBlock::class, function (OnlineBlock $block) { $block->lastActivity = $this->user['last_activity'] ?? false; }); $this->addBanner('bannerRight', 'users_profile_right'); } /** * Main content block * @param mixed $block * @param mixed $callback */ public function setContentBlock($block, $callback = null) { $this->addBlock('content', $block, function (Block $block) use ($callback) { $block->with([ 'userId' => $this->userId, 'user' => &$this->user, ]); if ($callback) { $callback($block); } }); } /** * Get main content block * @return Block|null */ public function getContentBlock() { return $this->getBlock('content'); } public function data() { $data = parent::data(); if ($this->user['blocked']) { $this->setTemplate(function () { return Users::showInlineMessage(_t('users', 'User account was blocked due to:
[reason]', [ 'reason' => $this->user['blocked_reason'], ])); }); } $this->view->setPageData([ 'users_profile_id' => $this->userId, 'users_profile_data' => &$this->user, ]); $data['is_owner'] = ($this->request->user() && $this->request->user()->isCurrent($this->userId)); $data['avatarBlock'] = UsersAvatar::block($this->userId, $this->user); # Finalize menu urls foreach ($this->getMenu() as $item) { $item->url(str_replace('{user}', $this->user['profile_url'] ?? '', $item->url())); } $this->buildFilterView(); return $data; } public function loadUser() { if (! $this->userLogin) { return false; } if (! $this->user) { $this->user = Users::model()->userData(['login' => $this->userLogin], $this->userFields); if ($this->user) { $this->userId = $this->user['user_id']; # No name => use login if (empty($this->user['name'])) { $this->user['name'] = $this->user['login']; } # Avatar Url $this->user['avatar_url'] = UsersAvatar::url( $this->userId, $this->user['avatar'], null, $this->user['sex'] ); # Phones $this->user['phones'] = (!empty($this->user['phones']) ? func::unserialize($this->user['phones']) : []); # Add account phone number as first if (Users::registerPhoneContacts() && $this->user['phone_number'] && $this->user['phone_number_verified']) { array_unshift($this->user['phones'], [ 'v' => $this->user['phone_number'], 'm' => Users::phoneMask($this->user['phone_number']), ]); } $this->user['has_contacts'] = ($this->user['phones'] || !empty($this->user['contacts'])); # Geo if (!empty($this->user['geo_city'])) { $this->user['region_title'] = Geo::regionTitle($this->user['geo_city']); # geo_city => geo_region1, geo_region2, geo_region3, geo_region4 $regions = Geo::regionParents($this->user['geo_city']); $this->user = array_merge($this->user, $regions['db']); $this->user['country_title'] = Geo::regionTitle($this->user['geo_region1']); } # Link $this->user['profile_url'] = Users::urlProfile($this->userLogin); } } return $this->user; } public function seo() { $this->request->urlCorrection(Users::urlProfile($this->userLogin, $this->tab)); $this->seo->canonicalUrl(Users::urlProfile($this->userLogin, $this->tab, [], true)); if ($this->user['blocked']) { $this->seo->index(false, 'users profile page: user blocked'); } $this->seo->with('name', $this->user['name']); $this->seoMacrosRegionsData($this->user['geo_city']); $this->seoApply(); $this->titleh1 = $this->titleh1 ?: _t('users', 'User Profile [name]', ['name' => $this->user['name']]); } public function seoSettings() { $this->seo->placeholder('name', _t('users', 'User Name')); $this->seoMacrosRegions(); } public function settingsForm($form) { $this->initFilterViewSettings($form); } }