adjust Request-class methods to be more flexible
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -53,8 +53,8 @@ class Ajax
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->action = $_GET['action'] ?? $_POST['action'] ?? null;
|
||||
$this->theme = $_GET['theme'] ?? 'Froxlor';
|
||||
$this->action = Request::any('action');
|
||||
$this->theme = Request::any('theme', 'Froxlor');
|
||||
|
||||
UI::sendHeaders();
|
||||
UI::sendSslHeaders();
|
||||
@@ -112,7 +112,8 @@ class Ajax
|
||||
$feed = "https://inside.froxlor.org/news/";
|
||||
|
||||
// Set custom feed if provided
|
||||
if (isset($_GET['role']) && $_GET['role'] == "customer") {
|
||||
$role = Request::get('role');
|
||||
if ($role == "customer") {
|
||||
$custom_feed = Settings::Get("customer.news_feed_url");
|
||||
if (!empty(trim($custom_feed))) {
|
||||
$feed = $custom_feed;
|
||||
@@ -140,7 +141,7 @@ class Ajax
|
||||
|
||||
if ($news === false) {
|
||||
$err = [];
|
||||
foreach(libxml_get_errors() as $error) {
|
||||
foreach (libxml_get_errors() as $error) {
|
||||
$err[] = $error->message;
|
||||
}
|
||||
return $this->errorResponse(
|
||||
@@ -205,7 +206,7 @@ class Ajax
|
||||
} catch (Exception $e) {
|
||||
// don't display anything if just not allowed due to permissions
|
||||
if ($e->getCode() != 403) {
|
||||
Response::dynamicError($e->getMessage());
|
||||
return $this->errorResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +216,7 @@ class Ajax
|
||||
*/
|
||||
private function searchGlobal()
|
||||
{
|
||||
$searchtext = Request::get('searchtext');
|
||||
$searchtext = Request::any('searchtext');
|
||||
|
||||
$result = [];
|
||||
|
||||
@@ -236,11 +237,11 @@ class Ajax
|
||||
private function updateTablelisting()
|
||||
{
|
||||
$columns = [];
|
||||
foreach ((Request::get('columns') ?? []) as $value) {
|
||||
foreach ((Request::any('columns') ?? []) as $value) {
|
||||
$columns[] = $value;
|
||||
}
|
||||
if (!empty($columns)) {
|
||||
Listing::storeColumnListingForUser([Request::get('listing') => $columns]);
|
||||
Listing::storeColumnListingForUser([Request::any('listing') => $columns]);
|
||||
return $this->jsonResponse($columns);
|
||||
}
|
||||
return $this->errorResponse('At least one column must be selected', 406);
|
||||
@@ -248,15 +249,15 @@ class Ajax
|
||||
|
||||
private function resetTablelisting()
|
||||
{
|
||||
Listing::deleteColumnListingForUser([Request::get('listing') => []]);
|
||||
Listing::deleteColumnListingForUser([Request::any('listing') => []]);
|
||||
return $this->jsonResponse([]);
|
||||
}
|
||||
|
||||
private function editApiKey()
|
||||
{
|
||||
$keyid = isset($_POST['id']) ? (int)$_POST['id'] : 0;
|
||||
$allowed_from = isset($_POST['allowed_from']) ? $_POST['allowed_from'] : "";
|
||||
$valid_until = isset($_POST['valid_until']) ? $_POST['valid_until'] : "";
|
||||
$keyid = Request::post('id', 0);
|
||||
$allowed_from = Request::post('allowed_from', "");
|
||||
$valid_until = Request::post('valid_until', "");
|
||||
|
||||
if (empty($keyid)) {
|
||||
return $this->errorResponse('Invalid call', 406);
|
||||
@@ -318,9 +319,9 @@ class Ajax
|
||||
private function getConfigDetails()
|
||||
{
|
||||
if (isset($this->userinfo['adminsession']) && $this->userinfo['adminsession'] == 1 && $this->userinfo['change_serversettings'] == 1) {
|
||||
$distribution = isset($_POST['distro']) ? $_POST['distro'] : "";
|
||||
$section = isset($_POST['section']) ? $_POST['section'] : "";
|
||||
$daemon = isset($_POST['daemon']) ? $_POST['daemon'] : "";
|
||||
$distribution = Request::post('distro', "");
|
||||
$section = Request::post('section', "");
|
||||
$daemon = Request::post('daemon', "");
|
||||
|
||||
// validate distribution config-xml exists
|
||||
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
|
||||
@@ -375,7 +376,7 @@ class Ajax
|
||||
*/
|
||||
private function loadLanguageString()
|
||||
{
|
||||
$langid = isset($_POST['langid']) ? $_POST['langid'] : "";
|
||||
$langid = Request::post('langid', "");
|
||||
if (preg_match('/^([a-zA-Z\.]+)$/', $langid)) {
|
||||
return $this->jsonResponse(lng($langid));
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ class Install
|
||||
$this->formfield = require dirname(__DIR__, 3) . '/lib/formfields/install/formfield.install.php';
|
||||
|
||||
// set actual step
|
||||
$this->currentStep = $cliData['step'] ?? Request::get('step', 0);
|
||||
$this->extendedView = $cliData['extended'] ?? Request::get('extended', 0);
|
||||
$this->currentStep = $cliData['step'] ?? Request::any('step', 0);
|
||||
$this->extendedView = $cliData['extended'] ?? Request::any('extended', 0);
|
||||
$this->maxSteps = count($this->formfield['install']['sections']);
|
||||
|
||||
// set actual php version and extensions
|
||||
@@ -114,7 +114,7 @@ class Install
|
||||
public function handle(): void
|
||||
{
|
||||
// handle form data
|
||||
if (!is_null(Request::get('submit')) && $this->currentStep) {
|
||||
if (!is_null(Request::any('submit')) && $this->currentStep) {
|
||||
try {
|
||||
$this->handleFormData($this->formfield['install']);
|
||||
} catch (Exception $e) {
|
||||
@@ -266,7 +266,7 @@ class Install
|
||||
{
|
||||
$attributes = [];
|
||||
foreach ($fields as $name => $field) {
|
||||
$attributes[$name] = $this->validateAttribute(Request::get($name), $field);
|
||||
$attributes[$name] = $this->validateAttribute(Request::any($name), $field);
|
||||
if (isset($field['next_to'])) {
|
||||
$attributes = array_merge($attributes, $this->validateRequest($field['next_to']));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,21 @@ use voku\helper\AntiXSS;
|
||||
class Request
|
||||
{
|
||||
/**
|
||||
* Get key from current request.
|
||||
* Get key from current $_GET or $_POST request.
|
||||
*
|
||||
* @param $key
|
||||
* @param string|null $default
|
||||
* @return mixed|string|null
|
||||
*/
|
||||
public static function any($key, string $default = null)
|
||||
{
|
||||
self::cleanAll();
|
||||
|
||||
return $_GET[$key] ?? $_POST[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key from current $_GET request.
|
||||
*
|
||||
* @param $key
|
||||
* @param string|null $default
|
||||
@@ -41,7 +55,21 @@ class Request
|
||||
{
|
||||
self::cleanAll();
|
||||
|
||||
return $_GET[$key] ?? $_POST[$key] ?? $default;
|
||||
return $_GET[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get key from current $_POST request.
|
||||
*
|
||||
* @param $key
|
||||
* @param string|null $default
|
||||
* @return mixed|string|null
|
||||
*/
|
||||
public static function post($key, string $default = null)
|
||||
{
|
||||
self::cleanAll();
|
||||
|
||||
return $_POST[$key] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,5 +42,6 @@ require_once dirname(__DIR__) . '/lib/tables.inc.php';
|
||||
try {
|
||||
echo (new Ajax)->handle();
|
||||
} catch (Exception $e) {
|
||||
header("Content-Type: application/json");
|
||||
echo \Froxlor\Api\Response::jsonErrorResponse($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
@@ -43,5 +43,5 @@ function old(string $identifier, string $default = null, string $session = null)
|
||||
if ($session && isset($_SESSION[$session])) {
|
||||
return $_SESSION[$session][$identifier] ?? $default;
|
||||
}
|
||||
return Request::get($identifier, $default);
|
||||
return Request::any($identifier, $default);
|
||||
}
|
||||
|
||||
@@ -295,9 +295,9 @@ UI::twig()->addGlobal('theme_css', $css);
|
||||
unset($js);
|
||||
unset($css);
|
||||
|
||||
$action = Request::get('action');
|
||||
$page = Request::get('page', 'overview');
|
||||
$gSearchText = Request::get('searchtext');
|
||||
$action = Request::any('action');
|
||||
$page = Request::any('page', 'overview');
|
||||
$gSearchText = Request::any('searchtext');
|
||||
|
||||
// clear request data
|
||||
if (!$action && isset($_SESSION)) {
|
||||
|
||||
Reference in New Issue
Block a user