]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/FriendSuggest.php
Option to automatically add links as attachment via API
[friendica.git] / src / Module / FriendSuggest.php
index 940e6ff9ce661fcceac00bd018b85eaeaf2c39c4..a4bdb957dc21a82b432fef44edc32cb24ea8485a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module;
 
-use Friendica\App\BaseURL;
+use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\Worker;
 use Friendica\Database\Database;
+use Friendica\DI;
 use Friendica\Model\Contact as ContactModel;
 use Friendica\Network\HTTPException\ForbiddenException;
 use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Protocol\Delivery;
+use Friendica\Util\Profiler;
 use Friendica\Util\Strings;
-use Friendica\Worker\Delivery;
+use Psr\Log\LoggerInterface;
 
 /**
  * Suggest friends to a known contact
  */
 class FriendSuggest extends BaseModule
 {
-       /** @var BaseURL */
-       protected $baseUrl;
        /** @var Database */
        protected $dba;
        /** @var \Friendica\Contact\FriendSuggest\Repository\FriendSuggest */
@@ -48,26 +49,25 @@ class FriendSuggest extends BaseModule
        /** @var \Friendica\Contact\FriendSuggest\Factory\FriendSuggest */
        protected $friendSuggestFac;
 
-       public function __construct(BaseURL $baseUrl, Database $dba, \Friendica\Contact\FriendSuggest\Repository\FriendSuggest $friendSuggestRepo, \Friendica\Contact\FriendSuggest\Factory\FriendSuggest $friendSuggestFac, L10n $l10n, array $parameters = [])
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, \Friendica\Contact\FriendSuggest\Repository\FriendSuggest $friendSuggestRepo, \Friendica\Contact\FriendSuggest\Factory\FriendSuggest $friendSuggestFac, array $server, array $parameters = [])
        {
-               parent::__construct($l10n, $parameters);
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        throw new ForbiddenException($this->t('Permission denied.'));
                }
 
-               $this->baseUrl           = $baseUrl;
                $this->dba               = $dba;
                $this->friendSuggestRepo = $friendSuggestRepo;
                $this->friendSuggestFac  = $friendSuggestFac;
        }
 
-       public function post()
+       protected function post(array $request = [])
        {
                $cid = intval($this->parameters['contact']);
 
                // We do query the "uid" as well to ensure that it is our contact
-               if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => local_user()])) {
+               if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()])) {
                        throw new NotFoundException($this->t('Contact not found.'));
                }
 
@@ -77,16 +77,16 @@ class FriendSuggest extends BaseModule
                }
 
                // We do query the "uid" as well to ensure that it is our contact
-               $contact = $this->dba->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]);
+               $contact = $this->dba->selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => DI::userSession()->getLocalUserId()]);
                if (empty($contact)) {
-                       notice($this->t('Suggested contact not found.'));
+                       DI::sysmsg()->addNotice($this->t('Suggested contact not found.'));
                        return;
                }
 
                $note = Strings::escapeHtml(trim($_POST['note'] ?? ''));
 
                $suggest = $this->friendSuggestRepo->save($this->friendSuggestFac->createNew(
-                       local_user(),
+                       DI::userSession()->getLocalUserId(),
                        $cid,
                        $contact['name'],
                        $contact['url'],
@@ -95,18 +95,18 @@ class FriendSuggest extends BaseModule
                        $note
                ));
 
-               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id);
+               Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id);
 
-               info($this->t('Friend suggestion sent.'));
+               DI::sysmsg()->addInfo($this->t('Friend suggestion sent.'));
        }
 
-       public function content(): string
+       protected function content(array $request = []): string
        {
                $cid = intval($this->parameters['contact']);
 
-               $contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
+               $contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]);
                if (empty($contact)) {
-                       notice($this->t('Contact not found.'));
+                       DI::sysmsg()->addNotice($this->t('Contact not found.'));
                        $this->baseUrl->redirect();
                }
 
@@ -120,7 +120,7 @@ class FriendSuggest extends BaseModule
                        AND NOT `archive` 
                        AND NOT `deleted` 
                        AND `notify` != ""',
-                       local_user(),
+                       DI::userSession()->getLocalUserId(),
                        $cid,
                        Protocol::DFRN,
                ]);