+ if (!local_user()) {
+ return Login::form($_SERVER['REQUEST_URI']);
+ }
+
+ $a = DI::app();
+
+ $nets = $_GET['nets'] ?? '';
+ $rel = $_GET['rel'] ?? '';
+
+ if (empty($a->page['aside'])) {
+ $a->page['aside'] = '';
+ }
+
+ $contact_id = null;
+ $contact = null;
+ // @TODO: Replace with parameter from router
+ if ($a->argc == 2 && intval($a->argv[1])
+ || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
+ ) {
+ $contact_id = intval($a->argv[1]);
+ $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
+
+ if (!DBA::isResult($contact)) {
+ $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0, 'deleted' => false]);
+ }
+
+ // Don't display contacts that are about to be deleted
+ if ($contact['network'] == Protocol::PHANTOM) {
+ $contact = false;
+ }
+ }
+
+ if (DBA::isResult($contact)) {
+ if ($contact['self']) {
+ // @TODO: Replace with parameter from router
+ if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
+ DI::baseUrl()->redirect('profile/' . $contact['nick']);
+ } else {
+ DI::baseUrl()->redirect('profile/' . $contact['nick'] . '?tab=profile');
+ }
+ }
+
+ $a->data['contact'] = $contact;
+
+ if (($contact['network'] != '') && ($contact['network'] != Protocol::DFRN)) {
+ $network_link = Strings::formatNetworkName($contact['network'], $contact['url']);
+ } else {
+ $network_link = '';
+ }
+
+ $follow_link = '';
+ $unfollow_link = '';
+ if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
+ if ($contact['uid'] && in_array($contact['rel'], [Model\Contact::SHARING, Model\Contact::FRIEND])) {
+ $unfollow_link = 'unfollow?url=' . urlencode($contact['url']);
+ } elseif(!$contact['pending']) {
+ $follow_link = 'follow?url=' . urlencode($contact['url']);
+ }
+ }
+
+ $wallmessage_link = '';
+ if ($contact['uid'] && Model\Contact::canReceivePrivateMessages($contact)) {
+ $wallmessage_link = 'message/new/' . $contact['id'];
+ }
+
+ $vcard_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/vcard.tpl'), [
+ '$name' => $contact['name'],
+ '$photo' => $contact['photo'],
+ '$url' => Model\Contact::magicLinkByContact($contact, $contact['url']),
+ '$addr' => $contact['addr'] ?? '',
+ '$network_link' => $network_link,
+ '$network' => L10n::t('Network:'),
+ '$account_type' => Model\Contact::getAccountType($contact),
+ '$follow' => L10n::t('Follow'),
+ '$follow_link' => $follow_link,
+ '$unfollow' => L10n::t('Unfollow'),
+ '$unfollow_link' => $unfollow_link,
+ '$wallmessage' => L10n::t('Message'),
+ '$wallmessage_link' => $wallmessage_link,
+ ]);
+
+ $findpeople_widget = '';
+ $follow_widget = '';
+ $networks_widget = '';
+ $rel_widget = '';
+ } else {
+ $vcard_widget = '';
+ $findpeople_widget = Widget::findPeople();
+ if (isset($_GET['add'])) {
+ $follow_widget = Widget::follow($_GET['add']);
+ } else {
+ $follow_widget = Widget::follow();
+ }
+
+ $networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
+ $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
+ }
+
+ if ($contact['uid'] != 0) {
+ $groups_widget = Model\Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact_id);
+ } else {
+ $groups_widget = null;
+ }
+
+ $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget;
+
+ $tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
+ $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
+ '$baseurl' => DI::baseUrl()->get(true),
+ ]);
+