]> 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 95d4a59f9a4bfdf1d0962b9a811dff7bcbea462c..eadc67818d506751551aa1fcae08200afd1c7b62 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
- * @license   GNU AGPL version 3 or any later version
+ * @license GNU AGPL version 3 or any later version
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -35,11 +35,15 @@ use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Module;
+use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
 
 /**
  *  Show a contact profile
@@ -50,37 +54,27 @@ class Profile extends BaseModule
         * @var Repository\LocalRelationship
         */
        private $localRelationship;
-       /**
-        * @var App\BaseURL
-        */
-       private $baseUrl;
        /**
         * @var App\Page
         */
        private $page;
-       /**
-        * @var App\Arguments
-        */
-       private $args;
        /**
         * @var IManageConfigValues
         */
        private $config;
 
-       public function __construct(L10n $l10n, Repository\LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Page $page, App\Arguments $args, IManageConfigValues $config, array $parameters = [])
+       public function __construct(L10n $l10n, Repository\LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, IManageConfigValues $config, array $server, array $parameters = [])
        {
-               parent::__construct($l10n, $parameters);
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
                $this->localRelationship = $localRelationship;
-               $this->baseUrl           = $baseUrl;
                $this->page              = $page;
-               $this->args              = $args;
                $this->config            = $config;
        }
 
-       public function post()
+       protected function post(array $request = [])
        {
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        return;
                }
 
@@ -88,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, local_user());
+               $cdata = Contact::getPublicAndUserContactID($contact_id, DI::userSession()->getLocalUserId());
                if (empty($cdata['user']) || !DBA::exists('contact', ['id' => $cdata['user'], 'deleted' => false])) {
                        return;
                }
@@ -101,8 +95,8 @@ class Profile extends BaseModule
                        $fields['hidden'] = !empty($_POST['hidden']);
                }
 
-               if (isset($_POST['notify'])) {
-                       $fields['notify'] = !empty($_POST['notify']);
+               if (isset($_POST['notify_new_posts'])) {
+                       $fields['notify_new_posts'] = !empty($_POST['notify_new_posts']);
                }
 
                if (isset($_POST['fetch_further_information'])) {
@@ -130,20 +124,20 @@ class Profile extends BaseModule
                        $fields['info'] = $_POST['info'];
                }
 
-               if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => local_user()])) {
-                       notice($this->t('Failed to update contact record.'));
+               if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => DI::userSession()->getLocalUserId()])) {
+                       DI::sysmsg()->addNotice($this->t('Failed to update contact record.'));
                }
        }
 
-       public function content(): string
+       protected function content(array $request = []): string
        {
-               if (!local_user()) {
+               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']), local_user());
+               $data = Contact::getPublicAndUserContactID(intval($this->parameters['id']), DI::userSession()->getLocalUserId());
                if (empty($data)) {
                        throw new HTTPException\NotFoundException($this->t('Contact not found.'));
                }
@@ -158,17 +152,64 @@ class Profile extends BaseModule
                        throw new HTTPException\NotFoundException($this->t('Contact not found.'));
                }
 
-               $localRelationship = $this->localRelationship->getForUserContact(local_user(), $contact['id']);
+               $localRelationship = $this->localRelationship->getForUserContact(DI::userSession()->getLocalUserId(), $contact['id']);
 
                if ($localRelationship->rel === Contact::SELF) {
                        $this->baseUrl->redirect('profile/' . $contact['nick'] . '/profile');
                }
 
+               if (isset($this->parameters['action'])) {
+                       self::checkFormSecurityTokenRedirectOnError('contact/' . $contact['id'], 'contact_action', 't');
+
+                       $cmd = $this->parameters['action'];
+                       if ($cmd === 'update' && $localRelationship->rel !== Contact::NOTHING) {
+                               Module\Contact::updateContactFromPoll($contact['id']);
+                       }
+
+                       if ($cmd === 'updateprofile') {
+                               self::updateContactFromProbe($contact['id']);
+                       }
+
+                       if ($cmd === 'block') {
+                               if ($localRelationship->blocked) {
+                                       // @TODO Backward compatibility, replace with $localRelationship->unblock()
+                                       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'], DI::userSession()->getLocalUserId(), true);
+                                       $message = $this->t('Contact has been blocked');
+                               }
+
+                               // @TODO: add $this->localRelationship->save($localRelationship);
+                               DI::sysmsg()->addInfo($message);
+                       }
+
+                       if ($cmd === 'ignore') {
+                               if ($localRelationship->ignored) {
+                                       // @TODO Backward compatibility, replace with $localRelationship->unblock()
+                                       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'], DI::userSession()->getLocalUserId(), true);
+                                       $message = $this->t('Contact has been ignored');
+                               }
+
+                               // @TODO: add $this->localRelationship->save($localRelationship);
+                               DI::sysmsg()->addInfo($message);
+                       }
+
+                       $this->baseUrl->redirect('contact/' . $contact['id']);
+               }
+
                $vcard_widget  = Widget\VCard::getHTML($contact);
                $groups_widget = '';
 
                if (!in_array($localRelationship->rel, [Contact::NOTHING, Contact::SELF])) {
-                       $groups_widget = Group::sidebarWidget('contact', 'group', 'full', 'everyone', $contact['id']);
+                       $groups_widget = Group::sidebarWidget('contact', 'group', 'full', 'everyone', $data['user']);
                }
 
                $this->page['aside'] .= $vcard_widget . $groups_widget;
@@ -182,8 +223,8 @@ class Profile extends BaseModule
                        '$baseurl' => $this->baseUrl->get(true),
                ]);
 
-               $contact['blocked']  = Contact\User::isBlocked($contact['id'], local_user());
-               $contact['readonly'] = Contact\User::isIgnored($contact['id'], local_user());
+               $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;
@@ -198,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 = '';
@@ -244,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) {
@@ -287,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,
@@ -315,7 +355,7 @@ class Profile extends BaseModule
                        '$archived'                  => ($contact['archive'] ? $this->t('Currently archived') : ''),
                        '$pending'                   => ($contact['pending'] ? $this->t('Awaiting connection acknowledge') : ''),
                        '$hidden'                    => ['hidden', $this->t('Hide this contact from others'), $localRelationship->hidden, $this->t('Replies/likes to your public posts <strong>may</strong> still be visible')],
-                       '$notify'                    => ['notify', $this->t('Notification for new posts'), ($contact['notify_new_posts'] == 1), $this->t('Send a notification of every new post of this contact')],
+                       '$notify_new_posts'          => ['notify_new_posts', $this->t('Notification for new posts'), ($localRelationship->notifyNewPosts), $this->t('Send a notification of every new post of this contact')],
                        '$fetch_further_information' => $fetch_further_information,
                        '$ffi_keyword_denylist'      => ['ffi_keyword_denylist', $this->t('Keyword Deny List'), $localRelationship->ffiKeywordDenylist, $this->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')],
                        '$photo'                     => Contact::getPhoto($contact),
@@ -324,7 +364,7 @@ class Profile extends BaseModule
                        '$url'                       => $url,
                        '$profileurllabel'           => $this->t('Profile URL'),
                        '$profileurl'                => $contact['url'],
-                       '$account_type'              => Contact::getAccountType($contact),
+                       '$account_type'              => Contact::getAccountType($contact['contact-type']),
                        '$location'                  => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['location']),
                        '$location_label'            => $this->t('Location:'),
                        '$xmpp'                      => BBCode::convertForUriId($contact['uri-id'] ?? 0, $contact['xmpp']),
@@ -374,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'] = [
@@ -433,4 +491,23 @@ class Profile extends BaseModule
 
                return $contact_actions;
        }
+
+       /**
+        * Updates contact from probing
+        *
+        * @param int $contact_id Id of the contact with uid != 0
+        * @return void
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function updateContactFromProbe(int $contact_id)
+       {
+               $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, DI::userSession()->getLocalUserId()], 'deleted' => false]);
+               if (!DBA::isResult($contact)) {
+                       return;
+               }
+
+               // Update the entry in the contact table
+               Contact::updateFromProbe($contact_id);
+       }
 }