X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModule%2FFriendSuggest.php;h=a4bdb957dc21a82b432fef44edc32cb24ea8485a;hb=706444bdb22b57f18c284044bdbdaeb7610990fe;hp=3256a04c2bbdf865fc7291f25da55479f9ad0fa7;hpb=714f0febc4918f5569eb09f8800b6739cff36347;p=friendica.git diff --git a/src/Module/FriendSuggest.php b/src/Module/FriendSuggest.php index 3256a04c2b..a4bdb957dc 100644 --- a/src/Module/FriendSuggest.php +++ b/src/Module/FriendSuggest.php @@ -1,6 +1,6 @@ t('Permission denied.')); + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + if (!DI::userSession()->getLocalUserId()) { + throw new ForbiddenException($this->t('Permission denied.')); } + + $this->dba = $dba; + $this->friendSuggestRepo = $friendSuggestRepo; + $this->friendSuggestFac = $friendSuggestFac; } - public static function post() + protected function post(array $request = []) { - $cid = intval(static::$parameters['contact']); + $cid = intval($this->parameters['contact']); // We do query the "uid" as well to ensure that it is our contact - if (!DI::dba()->exists('contact', ['id' => $cid, 'uid' => local_user()])) { - throw new NotFoundException(DI::l10n()->t('Contact not found.')); + if (!$this->dba->exists('contact', ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()])) { + throw new NotFoundException($this->t('Contact not found.')); } $suggest_contact_id = intval($_POST['suggest']); @@ -60,16 +77,16 @@ class FriendSuggest extends BaseModule } // We do query the "uid" as well to ensure that it is our contact - $contact = DI::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(DI::l10n()->t('Suggested contact not found.')); + DI::sysmsg()->addNotice($this->t('Suggested contact not found.')); return; } $note = Strings::escapeHtml(trim($_POST['note'] ?? '')); - $suggest = DI::fsuggest()->save(DI::fsuggestFactory()->createNew( - local_user(), + $suggest = $this->friendSuggestRepo->save($this->friendSuggestFac->createNew( + DI::userSession()->getLocalUserId(), $cid, $contact['name'], $contact['url'], @@ -78,19 +95,19 @@ 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(DI::l10n()->t('Friend suggestion sent.')); + DI::sysmsg()->addInfo($this->t('Friend suggestion sent.')); } - public static function content() + protected function content(array $request = []): string { - $cid = intval(static::$parameters['contact']); + $cid = intval($this->parameters['contact']); - $contact = DI::dba()->selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]); + $contact = $this->dba->selectFirst('contact', [], ['id' => $cid, 'uid' => DI::userSession()->getLocalUserId()]); if (empty($contact)) { - notice(DI::l10n()->t('Contact not found.')); - DI::baseUrl()->redirect(); + DI::sysmsg()->addNotice($this->t('Contact not found.')); + $this->baseUrl->redirect(); } $suggestableContacts = ContactModel::selectToArray(['id', 'name'], [ @@ -103,7 +120,7 @@ class FriendSuggest extends BaseModule AND NOT `archive` AND NOT `deleted` AND `notify` != ""', - local_user(), + DI::userSession()->getLocalUserId(), $cid, Protocol::DFRN, ]); @@ -117,15 +134,15 @@ class FriendSuggest extends BaseModule $tpl = Renderer::getMarkupTemplate('fsuggest.tpl'); return Renderer::replaceMacros($tpl, [ '$contact_id' => $cid, - '$fsuggest_title' => DI::l10n()->t('Suggest Friends'), + '$fsuggest_title' => $this->t('Suggest Friends'), '$fsuggest_select' => [ 'suggest', - DI::l10n()->t('Suggest a friend for %s', $contact['name']), + $this->t('Suggest a friend for %s', $contact['name']), '', '', $formattedContacts, ], - '$submit' => DI::l10n()->t('Submit'), + '$submit' => $this->t('Submit'), ]); } }