]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Contact/Profile.php
Merge remote-tracking branch 'upstream/2021.12-rc' into api-fixes
[friendica.git] / src / Module / Contact / Profile.php
index 95d4a59f9a4bfdf1d0962b9a811dff7bcbea462c..88f927c40f6c7d9087de0d355b06e364fad35287 100644 (file)
@@ -38,8 +38,11 @@ use Friendica\Database\DBA;
 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,35 +53,25 @@ 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()) {
                        return;
@@ -101,8 +94,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'])) {
@@ -135,7 +128,7 @@ class Profile extends BaseModule
                }
        }
 
-       public function content(): string
+       protected function content(array $request = []): string
        {
                if (!local_user()) {
                        return Module\Security\Login::form($_SERVER['REQUEST_URI']);
@@ -164,11 +157,58 @@ class Profile extends BaseModule
                        $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' && $localRelationship->rel !== Contact::NOTHING) {
+                               self::updateContactFromProbe($contact['id']);
+                       }
+
+                       if ($cmd === 'block') {
+                               if ($localRelationship->blocked) {
+                                       // @TODO Backward compatibility, replace with $localRelationship->unblock()
+                                       Contact\User::setBlocked($contact['id'], local_user(), false);
+
+                                       $message = $this->t('Contact has been unblocked');
+                               } else {
+                                       // @TODO Backward compatibility, replace with $localRelationship->block()
+                                       Contact\User::setBlocked($contact['id'], local_user(), true);
+                                       $message = $this->t('Contact has been blocked');
+                               }
+
+                               // @TODO: add $this->localRelationship->save($localRelationship);
+                               info($message);
+                       }
+
+                       if ($cmd === 'ignore') {
+                               if ($localRelationship->ignored) {
+                                       // @TODO Backward compatibility, replace with $localRelationship->unblock()
+                                       Contact\User::setIgnored($contact['id'], local_user(), false);
+
+                                       $message = $this->t('Contact has been unignored');
+                               } else {
+                                       // @TODO Backward compatibility, replace with $localRelationship->block()
+                                       Contact\User::setIgnored($contact['id'], local_user(), true);
+                                       $message = $this->t('Contact has been ignored');
+                               }
+
+                               // @TODO: add $this->localRelationship->save($localRelationship);
+                               info($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;
@@ -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),
@@ -433,4 +473,20 @@ class Profile extends BaseModule
 
                return $contact_actions;
        }
+
+       /**
+        * @param int $contact_id Id of the contact with uid != 0
+        * @throws HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function updateContactFromProbe(int $contact_id)
+       {
+               $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
+               if (!DBA::isResult($contact)) {
+                       return;
+               }
+
+               // Update the entry in the contact table
+               Contact::updateFromProbe($contact_id);
+       }
 }