X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModule%2FFriendSuggest.php;h=3cebd72cea580a01607e00fb199c200b21a281a2;hb=d7df0825db598012871d8555de04575d0c30247a;hp=e8e0fc2f09eeaef514b8d173c88c700d28f19c6e;hpb=82a6c7803318fc43ccb0bbd32ba3d18f7cc9f76e;p=friendica.git diff --git a/src/Module/FriendSuggest.php b/src/Module/FriendSuggest.php index e8e0fc2f09..3cebd72cea 100644 --- a/src/Module/FriendSuggest.php +++ b/src/Module/FriendSuggest.php @@ -1,6 +1,6 @@ t('Permission denied.')); + throw new ForbiddenException($this->t('Permission denied.')); } + + $this->dba = $dba; + $this->friendSuggestRepo = $friendSuggestRepo; + $this->friendSuggestFac = $friendSuggestFac; } - public static function post(array $parameters = []) + protected function post(array $request = []) { - $cid = intval($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' => local_user()])) { + throw new NotFoundException($this->t('Contact not found.')); } $suggest_contact_id = intval($_POST['suggest']); @@ -60,15 +76,15 @@ 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' => local_user()]); if (empty($contact)) { - notice(DI::l10n()->t('Suggested contact not found.')); + notice($this->t('Suggested contact not found.')); return; } $note = Strings::escapeHtml(trim($_POST['note'] ?? '')); - $suggest = DI::fsuggest()->save(DI::fsuggestFactory()->createNew( + $suggest = $this->friendSuggestRepo->save($this->friendSuggestFac->createNew( local_user(), $cid, $contact['name'], @@ -80,20 +96,20 @@ class FriendSuggest extends BaseModule Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id); - info(DI::l10n()->t('Friend suggestion sent.')); + info($this->t('Friend suggestion sent.')); } - public static function content(array $parameters = []) + protected function content(array $request = []): string { - $cid = intval($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' => local_user()]); if (empty($contact)) { - notice(DI::l10n()->t('Contact not found.')); - DI::baseUrl()->redirect(); + notice($this->t('Contact not found.')); + $this->baseUrl->redirect(); } - $contacts = ContactModel::selectToArray(['id', 'name'], [ + $suggestableContacts = ContactModel::selectToArray(['id', 'name'], [ '`uid` = ? AND `id` != ? AND `network` = ? @@ -110,22 +126,22 @@ class FriendSuggest extends BaseModule $formattedContacts = []; - foreach ($contacts as $contact) { - $formattedContacts[$contact['id']] = $contact['name']; + foreach ($suggestableContacts as $suggestableContact) { + $formattedContacts[$suggestableContact['id']] = $suggestableContact['name']; } $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'), ]); } }