PHP8/AjaxHandler

* filter callback function must be defined static
 * fixed some typos
 * fixed commentbody filter callback eating \n chars
This commit is contained in:
Sarjuuk
2021-10-24 19:23:53 +02:00
parent f9ed75d5af
commit 57864d2544
6 changed files with 19 additions and 19 deletions

View File

@@ -73,12 +73,12 @@ class AjaxHandler
return true; return true;
} }
protected function checkEmptySet(string $val) : bool protected static function checkEmptySet(string $val) : bool
{ {
return $val === ''; // parameter is expected to be empty return $val === ''; // parameter is expected to be empty
} }
protected function checkLocale(string $val) : int protected static function checkLocale(string $val) : int
{ {
if (preg_match('/^'.implode('|', array_keys(array_filter(Util::$localeStrings))).'$/', $val)) if (preg_match('/^'.implode('|', array_keys(array_filter(Util::$localeStrings))).'$/', $val))
return intVal($val); return intVal($val);
@@ -86,7 +86,7 @@ class AjaxHandler
return -1; return -1;
} }
protected function checkInt(string $val) : int protected static function checkInt(string $val) : int
{ {
if (preg_match('/^-?\d+$/', $val)) if (preg_match('/^-?\d+$/', $val))
return intVal($val); return intVal($val);
@@ -94,7 +94,7 @@ class AjaxHandler
return 0; return 0;
} }
protected function checkIdList(string $val) : array protected static function checkIdList(string $val) : array
{ {
if (preg_match('/^-?\d+(,-?\d+)*$/', $val)) if (preg_match('/^-?\d+(,-?\d+)*$/', $val))
return array_map('intVal', explode(',', $val)); return array_map('intVal', explode(',', $val));
@@ -102,7 +102,7 @@ class AjaxHandler
return []; return [];
} }
protected function checkIdListUnsigned(string $val) : array protected static function checkIdListUnsigned(string $val) : array
{ {
if (preg_match('/\d+(,\d+)*/', $val)) if (preg_match('/\d+(,\d+)*/', $val))
return array_map('intVal', explode(',', $val)); return array_map('intVal', explode(',', $val));
@@ -110,10 +110,10 @@ class AjaxHandler
return []; return [];
} }
protected function checkFulltext(string $val) : string protected static function checkFulltext(string $val) : string
{ {
// trim non-printable chars // trim non-printable chars
return preg_replace('/[\p{C}]/ui', '', $val); return preg_replace('/[\p{Cf} \p{Co} \p{Cs} \p{Cn}]/ui', '', $val);
} }
} }
?> ?>

View File

@@ -165,7 +165,7 @@ class AjaxAccount extends AjaxHandler
DB::Aowow()->query('DELETE FROM ?_account_favorites WHERE `userId` = ?d AND `type` = ?d AND `typeId` = ?d', User::$id, $type, $typeId); DB::Aowow()->query('DELETE FROM ?_account_favorites WHERE `userId` = ?d AND `type` = ?d AND `typeId` = ?d', User::$id, $type, $typeId);
} }
protected function checkScale(string $val) : string protected static function checkScale(string $val) : string
{ {
if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val)) if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val))
return $val; return $val;
@@ -173,7 +173,7 @@ class AjaxAccount extends AjaxHandler
return ''; return '';
} }
protected function checkName(string $val) : string protected static function checkName(string $val) : string
{ {
$var = trim(urldecode($val)); $var = trim(urldecode($val));

View File

@@ -467,7 +467,7 @@ class AjaxAdmin extends AjaxHandler
return '-1'; return '-1';
} }
protected function checkKey(string $val) : string protected static function checkKey(string $val) : string
{ {
// expecting string // expecting string
if (preg_match('/[^a-z0-9_\.\-]/i', $val)) if (preg_match('/[^a-z0-9_\.\-]/i', $val))
@@ -476,7 +476,7 @@ class AjaxAdmin extends AjaxHandler
return strtolower($val); return strtolower($val);
} }
protected function checkUser($val) : string protected static function checkUser($val) : string
{ {
$n = Util::lower(trim(urldecode($val))); $n = Util::lower(trim(urldecode($val)));
@@ -486,7 +486,7 @@ class AjaxAdmin extends AjaxHandler
return ''; return '';
} }
protected function checkScale($val) : string protected static function checkScale($val) : string
{ {
if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val)) if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val))
return $val; return $val;
@@ -494,7 +494,7 @@ class AjaxAdmin extends AjaxHandler
return ''; return '';
} }
private function confOnChange(string $key, string $val, string &$msg) : bool private static function confOnChange(string $key, string $val, string &$msg) : bool
{ {
$fn = $buildList = null; $fn = $buildList = null;

View File

@@ -92,7 +92,7 @@ class AjaxComment extends AjaxHandler
// trim to max length // trim to max length
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['commentbody']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1))) if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['commentbody']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)))
$this->post['commentbody'] = mb_substr($this->_post['commentbody'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1))); $this->_post['commentbody'] = mb_substr($this->_post['commentbody'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)));
if (User::canComment()) if (User::canComment())
{ {
@@ -144,7 +144,7 @@ class AjaxComment extends AjaxHandler
// trim to max length // trim to max length
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['body']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1))) if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['body']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)))
$this->post['body'] = mb_substr($this->_post['body'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1))); $this->_post['body'] = mb_substr($this->_post['body'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)));
$update = array( $update = array(
'body' => $this->_post['body'], 'body' => $this->_post['body'],

View File

@@ -117,12 +117,12 @@ class AjaxData extends AjaxHandler
return $result; return $result;
} }
protected function checkSkill(string $val) : array protected static function checkSkill(string $val) : array
{ {
return array_intersect([171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356], explode(',', $val)); return array_intersect([171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356], explode(',', $val));
} }
protected function checkCallback(string $val) : bool protected static function checkCallback(string $val) : bool
{ {
return substr($val, 0, 29) === '$WowheadProfiler.loadOnDemand'; return substr($val, 0, 29) === '$WowheadProfiler.loadOnDemand';
} }

View File

@@ -746,7 +746,7 @@ class AjaxProfile extends AjaxHandler
*/ */
protected function handlePurge() : void { } // removes completion data (as uploaded by the wowhead client) Just fail silently if someone triggers this manually protected function handlePurge() : void { } // removes completion data (as uploaded by the wowhead client) Just fail silently if someone triggers this manually
protected function checkItemList($val) : array protected static function checkItemList($val) : array
{ {
// expecting item-list // expecting item-list
if (preg_match('/\d+(:\d+)*/', $val)) if (preg_match('/\d+(:\d+)*/', $val))
@@ -755,7 +755,7 @@ class AjaxProfile extends AjaxHandler
return []; return [];
} }
protected function checkUser(string $val) : string protected static function checkUser(string $val) : string
{ {
if (User::isValidName($val)) if (User::isValidName($val))
return $val; return $val;