]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Index.php
Remove duplicate profile_uid key in App->profile array
[friendica.git] / src / Module / Profile / Index.php
1 <?php
2
3 namespace Friendica\Module\Profile;
4
5 use Friendica\BaseModule;
6 use Friendica\Content\Nav;
7 use Friendica\Core\Hook;
8 use Friendica\Core\Session;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\DI;
12 use Friendica\Model\Profile as ProfileModel;
13 use Friendica\Model\User;
14 use Friendica\Module\Security\Login;
15 use Friendica\Protocol\ActivityPub;
16
17 require_once 'boot.php';
18
19 class Index extends BaseModule
20 {
21         public static function rawContent(array $parameters = [])
22         {
23                 if (ActivityPub::isRequest()) {
24                         $user = DBA::selectFirst('user', ['uid'], ['nickname' => $parameters['nickname']]);
25                         if (DBA::isResult($user)) {
26                                 // The function returns an empty array when the account is removed, expired or blocked
27                                 $data = ActivityPub\Transmitter::getProfile($user['uid']);
28                                 if (!empty($data)) {
29                                         System::jsonExit($data, 'application/activity+json');
30                                 }
31                         }
32
33                         if (DBA::exists('userd', ['username' => $parameters['nickname']])) {
34                                 // Known deleted user
35                                 $data = ActivityPub\Transmitter::getDeletedUser($parameters['nickname']);
36
37                                 System::jsonError(410, $data);
38                         } else {
39                                 // Any other case (unknown, blocked, nverified, expired, no profile, no self contact)
40                                 System::jsonError(404, []);
41                         }
42                 }
43         }
44
45         public static function content(array $parameters = [])
46         {
47                 $a = DI::app();
48
49                 ProfileModel::load($a, $parameters['nickname']);
50
51                 $remote_contact_id = Session::getRemoteContactID($a->profile['uid']);
52
53                 if (DI::config()->get('system', 'block_public') && !local_user() && !$remote_contact_id) {
54                         return Login::form();
55                 }
56
57                 DI::page()['htmlhead'] .= "\n";
58
59                 $blocked   = !local_user() && !$remote_contact_id && DI::config()->get('system', 'block_public');
60                 $userblock = !local_user() && !$remote_contact_id && $a->profile['hidewall'];
61
62                 if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
63                         DI::page()['htmlhead'] .= '<meta name="friendica.community" content="true" />' . "\n";
64                 }
65
66                 if (!empty($a->profile['openidserver'])) {
67                         DI::page()['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\n";
68                 }
69
70                 if (!empty($a->profile['openid'])) {
71                         $delegate = strstr($a->profile['openid'], '://') ? $a->profile['openid'] : 'https://' . $a->profile['openid'];
72                         DI::page()['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
73                 }
74
75                 // site block
76                 if (!$blocked && !$userblock) {
77                         $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $a->profile['pub_keywords'] ?? '');
78                         if (strlen($keywords)) {
79                                 DI::page()['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
80                         }
81                 }
82
83                 DI::page()['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
84
85                 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
86                         DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
87                 }
88
89                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
90                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $a->profile['username']) . '"/>' . "\n";
91                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $a->profile['username']) . '"/>' . "\n";
92                 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
93                 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''));
94                 DI::page()['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . DI::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";
95                 header('Link: <' . DI::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
96
97                 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
98                 foreach ($dfrn_pages as $dfrn) {
99                         DI::page()['htmlhead'] .= '<link rel="dfrn-' . $dfrn . '" href="' . DI::baseUrl() . '/dfrn_' . $dfrn . '/' . $parameters['nickname'] . '" />' . "\n";
100                 }
101                 DI::page()['htmlhead'] .= '<link rel="dfrn-poco" href="' . DI::baseUrl() . '/poco/' . $parameters['nickname'] . '" />' . "\n";
102
103                 $o = '';
104
105                 Nav::setSelected('home');
106
107                 $is_owner = local_user() == $a->profile['uid'];
108
109                 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact_id) {
110                         notice(DI::l10n()->t('Access to this profile has been restricted.'));
111                         return '';
112                 }
113
114                 $o .= ProfileModel::getTabs($a, 'profile', $is_owner, $a->profile['nickname']);
115
116                 $o .= ProfileModel::getAdvanced($a);
117
118                 Hook::callAll('profile_advanced', $o);
119
120                 return $o;
121         }
122 }