blocklist = $blocklist; } /** * @param array $request * @return void * @throws HTTPException\ForbiddenException * @throws HTTPException\FoundException * @throws HTTPException\InternalServerErrorException * @throws HTTPException\MovedPermanentlyException * @throws HTTPException\TemporaryRedirectException * @throws \Exception */ protected function post(array $request = []) { $this->checkModerationAccess(); if (empty($request['page_blocklist_add'])) { return; } self::checkFormSecurityTokenRedirectOnError('/moderation/blocklist/server/add', 'moderation_blocklist_add'); $pattern = trim($request['pattern']); // Add new item to blocklist $this->blocklist->addPattern($pattern, trim($request['reason'])); Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers'); $this->systemMessages->addInfo($this->t('Server domain pattern added to the blocklist.')); if (!empty($request['purge'])) { $gservers = GServer::listByDomainPattern($pattern); foreach (Contact::selectToArray(['id'], ['gsid' => array_column($gservers, 'id')]) as $contact) { Worker::add(Worker::PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']); } $this->systemMessages->addInfo($this->tt('%s server scheduled to be purged.', '%s servers scheduled to be purged.', count($gservers))); } $this->baseUrl->redirect('moderation/blocklist/server'); } /** * @param array $request * @return string * @throws HTTPException\InternalServerErrorException * @throws HTTPException\ServiceUnavailableException * @throws \Exception */ protected function content(array $request = []): string { parent::content(); $gservers = []; if ($pattern = trim($request['pattern'] ?? '')) { $gservers = GServer::listByDomainPattern($pattern); } array_walk($gservers, function (array &$gserver) { $gserver['domain'] = (new Uri($gserver['url']))->getHost(); $gserver['network_svg'] = ContactSelector::networkToSVG($gserver['network']); $gserver['network_name'] = ContactSelector::networkToName($gserver['network']); }); $t = Renderer::getMarkupTemplate('moderation/blocklist/server/add.tpl'); return Renderer::replaceMacros($t, [ '$l10n' => [ 'return_list' => $this->t('← Return to the list'), 'title' => $this->t('Moderation'), 'page' => $this->t('Block A New Server Domain Pattern'), 'syntax' => $this->t('
The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:
*
: Any number of characters?
: Any single character