]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact/Profile.php
Removed redundant maximagesize = INF statements
[friendica.git] / src / Module / Contact / Profile.php
index 1fc702edfa739c606af06ef7c63be05bdcfd04d6..eadc67818d506751551aa1fcae08200afd1c7b62 100644 (file)
@@ -34,7 +34,6 @@ use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -75,7 +74,7 @@ class Profile extends BaseModule
 
        protected function post(array $request = [])
        {
-               if (!Session::getLocalUser()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        return;
                }
 
@@ -83,7 +82,7 @@ class Profile extends BaseModule
 
                // Backward compatibility: The update still needs a user-specific contact ID
                // Change to user-contact table check by version 2022.03
-               $cdata = Contact::getPublicAndUserContactID($contact_id, Session::getLocalUser());
+               $cdata = Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
                if (empty($cdata['user']) || !DBA::exists('contact', ['id' => $cdata['user'], 'deleted' => false])) {
                        return;
                }
@@ -125,20 +124,20 @@ class Profile extends BaseModule
                        $fields['info'] = $_POST['info'];
                }
 
-               if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => Session::getLocalUser()])) {
+               if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => DI::userSession()->getLocalUserId()])) {
                        DI::sysmsg()->addNotice($this->t('Failed to update contact record.'));
                }
        }
 
        protected function content(array $request = []): string
        {
-               if (!Session::getLocalUser()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        return Module\Security\Login::form($_SERVER['REQUEST_URI']);
                }
 
                // Backward compatibility: Ensure to use the public contact when the user contact is provided
                // Remove by version 2022.03
-               $data = Contact::getPublicAndUserContactID(intval($this->parameters['id']), Session::getLocalUser());
+               $data = Contact::getPublicAndUserContactID(intval($this->parameters['id']), DI::userSession()->getLocalUserId());
                if (empty($data)) {
                        throw new HTTPException\NotFoundException($this->t('Contact not found.'));
                }
@@ -153,7 +152,7 @@ class Profile extends BaseModule
                        throw new HTTPException\NotFoundException($this->t('Contact not found.'));
                }
 
-               $localRelationship = $this->localRelationship->getForUserContact(Session::getLocalUser(), $contact['id']);
+               $localRelationship = $this->localRelationship->getForUserContact(DI::userSession()->getLocalUserId(), $contact['id']);
 
                if ($localRelationship->rel === Contact::SELF) {
                        $this->baseUrl->redirect('profile/' . $contact['nick'] . '/profile');
@@ -174,12 +173,12 @@ class Profile extends BaseModule
                        if ($cmd === 'block') {
                                if ($localRelationship->blocked) {
                                        // @TODO Backward compatibility, replace with $localRelationship->unblock()
-                                       Contact\User::setBlocked($contact['id'], Session::getLocalUser(), false);
+                                       Contact\User::setBlocked($contact['id'], DI::userSession()->getLocalUserId(), false);
 
                                        $message = $this->t('Contact has been unblocked');
                                } else {
                                        // @TODO Backward compatibility, replace with $localRelationship->block()
-                                       Contact\User::setBlocked($contact['id'], Session::getLocalUser(), true);
+                                       Contact\User::setBlocked($contact['id'], DI::userSession()->getLocalUserId(), true);
                                        $message = $this->t('Contact has been blocked');
                                }
 
@@ -190,12 +189,12 @@ class Profile extends BaseModule
                        if ($cmd === 'ignore') {
                                if ($localRelationship->ignored) {
                                        // @TODO Backward compatibility, replace with $localRelationship->unblock()
-                                       Contact\User::setIgnored($contact['id'], Session::getLocalUser(), false);
+                                       Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), false);
 
                                        $message = $this->t('Contact has been unignored');
                                } else {
                                        // @TODO Backward compatibility, replace with $localRelationship->block()
-                                       Contact\User::setIgnored($contact['id'], Session::getLocalUser(), true);
+                                       Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), true);
                                        $message = $this->t('Contact has been ignored');
                                }
 
@@ -224,8 +223,8 @@ class Profile extends BaseModule
                        '$baseurl' => $this->baseUrl->get(true),
                ]);
 
-               $contact['blocked']  = Contact\User::isBlocked($contact['id'], Session::getLocalUser());
-               $contact['readonly'] = Contact\User::isIgnored($contact['id'], Session::getLocalUser());
+               $contact['blocked']  = Contact\User::isBlocked($contact['id'], DI::userSession()->getLocalUserId());
+               $contact['readonly'] = Contact\User::isIgnored($contact['id'], DI::userSession()->getLocalUserId());
 
                switch ($localRelationship->rel) {
                        case Contact::FRIEND:   $relation_text = $this->t('You are mutual friends with %s', $contact['name']); break;
@@ -240,7 +239,7 @@ class Profile extends BaseModule
                }
 
                $url = Contact::magicLinkByContact($contact);
-               if (strpos($url, 'redir/') === 0) {
+               if (strpos($url, 'contact/redir/') === 0) {
                        $sparkle = ' class="sparkle" ';
                } else {
                        $sparkle = '';
@@ -286,7 +285,6 @@ class Profile extends BaseModule
                if ($contact['network'] == Protocol::FEED) {
                        $remote_self_options = [
                                Contact::MIRROR_DEACTIVATED => $this->t('No mirroring'),
-                               Contact::MIRROR_FORWARDED   => $this->t('Mirror as forwarded posting'),
                                Contact::MIRROR_OWN_POST    => $this->t('Mirror as my own posting')
                        ];
                } elseif ($contact['network'] == Protocol::ACTIVITYPUB) {
@@ -329,7 +327,7 @@ class Profile extends BaseModule
                        '$submit'                    => $this->t('Submit'),
                        '$lbl_info1'                 => $lbl_info1,
                        '$lbl_info2'                 => $this->t('Their personal note'),
-                       '$reason'                    => trim($contact['reason']),
+                       '$reason'                    => trim($contact['reason'] ?? ''),
                        '$infedit'                   => $this->t('Edit contact notes'),
                        '$common_link'               => 'contact/' . $contact['id'] . '/contacts/common',
                        '$relation_text'             => $relation_text,
@@ -416,6 +414,24 @@ class Profile extends BaseModule
 
                $formSecurityToken = self::getFormSecurityToken('contact_action');
 
+               if ($localRelationship->rel & Contact::SHARING) {
+                       $contact_actions['unfollow'] = [
+                               'label' => $this->t('Unfollow'),
+                               'url'   => 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1',
+                               'title' => '',
+                               'sel'   => '',
+                               'id'    => 'unfollow',
+                       ];
+               } else {
+                       $contact_actions['follow'] = [
+                               'label' => $this->t('Follow'),
+                               'url'   => 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1',
+                               'title' => '',
+                               'sel'   => '',
+                               'id'    => 'follow',
+                       ];
+               }
+
                // Provide friend suggestion only for Friendica contacts
                if ($contact['network'] === Protocol::DFRN) {
                        $contact_actions['suggest'] = [
@@ -486,7 +502,7 @@ class Profile extends BaseModule
         */
        private static function updateContactFromProbe(int $contact_id)
        {
-               $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, Session::getLocalUser()], 'deleted' => false]);
+               $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, DI::userSession()->getLocalUserId()], 'deleted' => false]);
                if (!DBA::isResult($contact)) {
                        return;
                }