Contacts Block * @copyright Tamaranga * @property ProfilePage $parent */ class ContactsBlock extends Block { /** @var int */ public $available = 1; public function init() { parent::init(); $this->setTemplate('profile/contacts.block', 'users'); $this->setKey('user-profile-contacts'); $this->setTitle(_t('user', 'User profile contacts')); } public function data() { $data = parent::data(); if (! $this->available) { return false; } if (! $this->parent->user) { return false; } $data['user'] = &$this->parent->user; $data['phones'] = $this->parent->user['phones'] ?? []; $data['contacts'] = Users::contactsFields($this->parent->user['contacts'] ?? []); foreach ($data['contacts'] as &$contact) { $contact['value'] = tpl::contactMask($contact['value']); } if (empty($data['phones']) && empty($data['contacts'])) { return false; } return $data; } public function onUserProfileContactsShowAction() { do { $ex = $this->input->post('ex', TYPE_STR); if (empty($ex) || ! $this->available) { $this->errors->reloadPage(); break; } if ($this->available == 2 && ! $this->request->user()) { $this->errors->set(_t('', 'Log In or Sign Up', [ 'link_login' => 'href="' . Users::url('login') . '"', 'link_register' => 'href="' . Users::url('register') . '"', ])); break; } if ( ! $this->parent->user || $this->parent->user['user_id_ex'] != $ex || ! $this->parent->user['activated'] || $this->parent->user['blocked'] || ! $this->isRequestValid() ) { $this->errors->reloadPage(); break; } # Phones $this->respond('phones', Users::phonesView($this->parent->user['phones'])); # Contacts if (! empty($this->parent->user['contacts'])) { $contacts = []; foreach (Users::contactsFields($this->parent->user['contacts']) as $contact) { $contacts[$contact['key']] = (isset($contact['view']) ? tpl::renderMacro($contact['value'], $contact['view'], 'value') : HTML::obfuscate($contact['value'])); } $this->respond('contacts', $contacts); } } while (false); return $this->getActionResponse(); } public function settingsForm($form) { $form->select('available', _t('@', 'Available'), 1, function () { return [ ['id' => 1, 'title' => _t('@listings', 'To All')], ['id' => 2, 'title' => _t('@listings', 'Logged In')], ['id' => 0, 'title' => _t('@listings', 'Nobody')], ]; }); } }