Contacts Block * @copyright Tamaranga * @property ProfilePage $parent */ class ContactsBlock extends Block { 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->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->errors->reloadPage(); 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(); } }