]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Profile/Profile.php
Merge pull request #9397 from vinzv/9238-red-color-unread-messages-faded
[friendica.git] / src / Module / Profile / Profile.php
index bbf0da38218588d418028d031c1def9913af7c80..b1e0673b242496ce8366511466dfbb4a5ff5b92c 100644 (file)
@@ -35,7 +35,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile as ProfileModel;
-use Friendica\Model\Term;
+use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
 use Friendica\Module\Security\Login;
@@ -54,6 +54,8 @@ class Profile extends BaseProfile
                                // The function returns an empty array when the account is removed, expired or blocked
                                $data = ActivityPub\Transmitter::getProfile($user['uid']);
                                if (!empty($data)) {
+                                       header('Access-Control-Allow-Origin: *');
+                                       header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
                                        System::jsonExit($data, 'application/activity+json');
                                }
                        }
@@ -110,6 +112,7 @@ class Profile extends BaseProfile
 
                $view_as_contacts = [];
                $view_as_contact_id = 0;
+               $view_as_contact_alert = '';
                if ($is_owner) {
                        $view_as_contact_id = intval($_GET['viewas'] ?? 0);
 
@@ -120,10 +123,20 @@ class Profile extends BaseProfile
                                'blocked' => false,
                        ]);
 
+                       $view_as_contact_ids = array_column($view_as_contacts, 'id');
+
                        // User manually provided a contact ID they aren't privy to, silently defaulting to their own view
-                       if (!in_array($view_as_contact_id, array_column($view_as_contacts, 'id'))) {
+                       if (!in_array($view_as_contact_id, $view_as_contact_ids)) {
                                $view_as_contact_id = 0;
                        }
+
+                       if (($key = array_search($view_as_contact_id, $view_as_contact_ids)) !== false) {
+                               $view_as_contact_alert = DI::l10n()->t(
+                                       'You\'re currently viewing your profile as <b>%s</b> <a href="%s" class="btn btn-sm pull-right">Cancel</a>',
+                                       htmlentities($view_as_contacts[$key]['name'], ENT_COMPAT, 'UTF-8'),
+                                       'profile/' . $parameters['nickname'] . '/profile'
+                               );
+                       }
                }
 
                $basic_fields = [];
@@ -182,7 +195,7 @@ class Profile extends BaseProfile
                        foreach (explode(',', $a->profile['pub_keywords']) as $tag_label) {
                                $tags[] = [
                                        'url' => '/search?tag=' . $tag_label,
-                                       'label' => Term::TAG_CHARACTER[Term::HASHTAG] . $tag_label,
+                                       'label' => Tag::TAG_CHARACTER[Tag::HASHTAG] . $tag_label,
                                ];
                        }
 
@@ -223,7 +236,9 @@ class Profile extends BaseProfile
                        '$title' => DI::l10n()->t('Profile'),
                        '$view_as_contacts' => $view_as_contacts,
                        '$view_as_contact_id' => $view_as_contact_id,
+                       '$view_as_contact_alert' => $view_as_contact_alert,
                        '$view_as' => DI::l10n()->t('View profile as:'),
+                       '$submit' => DI::l10n()->t('Submit'),
                        '$basic' => DI::l10n()->t('Basic'),
                        '$advanced' => DI::l10n()->t('Advanced'),
                        '$is_owner' => $a->profile_uid == local_user(),
@@ -236,6 +251,11 @@ class Profile extends BaseProfile
                                'title' => '',
                                'label' => DI::l10n()->t('Edit profile')
                        ],
+                       '$viewas_link' => [
+                               'url' =>  DI::args()->getQueryString() . '#viewas',
+                               'title' => '',
+                               'label' => DI::l10n()->t('View as')
+                       ],
                ]);
 
                Hook::callAll('profile_advanced', $o);
@@ -297,10 +317,10 @@ class Profile extends BaseProfile
                        $htmlhead .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
                }
 
-               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/dfrn_poll/' . $nickname . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
-               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['username']) . '"/>' . "\n";
-               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['username']) . '"/>' . "\n";
-               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['username']) . '"/>' . "\n";
+               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/dfrn_poll/' . $nickname . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
+               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
+               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
+               $htmlhead .= '<link rel="alternate" type="application/atom+xml" href="' . $baseUrl . '/feed/' . $nickname . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
                $uri = urlencode('acct:' . $profile['nickname'] . '@' . $baseUrl->getHostname() . ($baseUrl->getUrlPath() ? '/' . $baseUrl->getUrlPath() : ''));
                $htmlhead .= '<link rel="lrdd" type="application/xrd+xml" href="' . $baseUrl . '/xrd/?uri=' . $uri . '" />' . "\n";
                header('Link: <' . $baseUrl . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);