aowow/endpoints/filter/filter.php
Sarjuuk 715c1534eb Core/Endpoints
* don't use raw input to recreate subcategories for filter urls and
   external links
 * if a page does not expect categories it will now error out if it is
   called with parameters
 * fixed infite redirect loop that could occur if the pageName was an
   invalid string
 * added lost filter string for external page call to NPCs Page
2026-01-01 01:26:35 +01:00

64 lines
1.6 KiB
PHP

<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class FilterBaseResponse extends TextResponse
{
private array $catg = [];
private string $page = '';
private ?Filter $filter = null;
public function __construct(string $rawParam)
{
if (!$rawParam)
return;
parent::__construct($rawParam);
$catg = null;
if (strstr($rawParam, '='))
[$this->page, $catg] = explode('=', $rawParam);
else
$this->page = $rawParam;
if ($catg !== null)
$this->catg = explode('.', $catg);
$opts = ['parentCats' => $this->catg];
// so usually the page call is just the DBTypes file string with a plural 's' .. but then there are currencies
$fileStr = match ($this->page)
{
'currencies' => 'currency',
default => substr($this->page, 0, -1)
};
// yes, the whole _POST! .. should the input fields be exposed and static so they can be evaluated via BaseResponse::initRequestData() ?
$this->filter = Type::newFilter($fileStr, $_POST, $opts);
}
protected function generate() : void
{
$url = '?'.$this->page;
$this->filter?->mergeCat($this->catg);
if ($this->catg)
$url .= '='.implode('.', $this->catg);
if ($x = $this->filter?->buildGETParam())
$url .= '&filter='.$x;
if ($this->filter?->error)
$_SESSION['error']['fi'] = $this->filter::class;
// do get request
$this->redirectTo = $url;
}
}
?>