Misc/Fixups

* use built in function to determine if CLI can use escape codes
 * define _post, _get and _cookie in all cases
 * do not apply 8 regexes to a string that doesn't even contain a UI Sequence
This commit is contained in:
Sarjuuk
2024-03-16 00:17:19 +01:00
parent d37eb9a59b
commit c01c9ce901
3 changed files with 12 additions and 5 deletions

View File

@@ -15,8 +15,8 @@ mb_internal_encoding('UTF-8');
// OS_WIN as per compile info of php
define('OS_WIN', substr(PHP_OS, 0, 3) == 'WIN');
// WIN10 and later support ANSI escape sequences
define('CLI_HAS_E', !OS_WIN || version_compare(php_uname('r'), '10.0') >= 0);
// WIN10 and later usually support ANSI escape sequences
define('CLI_HAS_E', !OS_WIN || (function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)));
require_once 'includes/defines.php';

View File

@@ -22,6 +22,10 @@ trait TrRequestData
public static $PATTERN_TEXT_LINE = '/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui';
public static $PATTERN_TEXT_BLOB = '/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui';
protected $_get = []; // fill with variables you that are going to be used; eg:
protected $_post = []; // 'id' => ['filter' => FILTER_CALLBACK, 'options' => 'AjaxHandler::checkIdList']
protected $_cookie = [];
private $filtered = false;
private function initRequestData() : void
@@ -33,7 +37,7 @@ trait TrRequestData
// only really relevant for INPUT_POST
// manuall set everything null in this case
if (isset($this->_post) && gettype($this->_post) == 'array')
if ($this->_post)
{
if ($_POST)
$this->_post = filter_input_array(INPUT_POST, $this->_post);
@@ -41,7 +45,7 @@ trait TrRequestData
$this->_post = array_fill_keys(array_keys($this->_post), null);
}
if (isset($this->_get) && gettype($this->_get) == 'array')
if ($this->_get)
{
if ($_GET)
$this->_get = filter_input_array(INPUT_GET, $this->_get);
@@ -49,7 +53,7 @@ trait TrRequestData
$this->_get = array_fill_keys(array_keys($this->_get), null);
}
if (isset($this->_cookie) && gettype($this->_cookie) == 'array')
if ($this->_cookie)
{
if ($_COOKIE)
$this->_cookie = filter_input_array(INPUT_COOKIE, $this->_cookie);

View File

@@ -621,6 +621,9 @@ class Lang
public static function unescapeUISequences(string $var, int $fmt = -1) : string
{
if (strpos($var, '|') === false)
return $var;
// line break |n
$var = preg_replace_callback('/\|n/i', function ($m) use ($fmt)
{