Browse Source

add userPost filter, allow mixed data input

main
ghost 3 years ago
parent
commit
a596be9eb4
  1. 78
      src/system/helper/filter.php

78
src/system/helper/filter.php

@ -4,7 +4,7 @@ class Filter { @@ -4,7 +4,7 @@ class Filter {
public static function userName(mixed $string) {
$string = preg_replace('/[^a-zA-Z0-9_]+/u', '', $string);
$string = preg_replace('/[^a-zA-Z0-9_]+/u', '', (string) $string);
$string = mb_substr($string, 0, 16);
@ -13,71 +13,76 @@ class Filter { @@ -13,71 +13,76 @@ class Filter {
public static function userPrivateKey(mixed $string) {
return preg_replace('/[^a-zA-Z0-9_]+/u', '', $string);
return preg_replace('/[^a-zA-Z0-9_]+/u', '', (string) $string);
}
public static function blockHash(mixed $string) {
return preg_replace('/[^a-zA-Z0-9]+/u', '', $string);
return preg_replace('/[^a-zA-Z0-9]+/u', '', (string) $string);
}
public static function fullName(string $string) {
public static function fullName(mixed $string) {
$string = preg_replace('/[^\s\w]+/u', '', $string);
$string = preg_replace('/[^\s\w]+/u', '', (string) $string);
$string = mb_substr($string, 0, 200);
return $string;
}
public static function location(string $string) {
public static function sigUserPost(mixed $string) {
$string = preg_replace('/[^\s\w\.\,]+/u', '', $string);
return preg_replace('/[^a-zA-Z0-9]+/u', '', (string) $string);
}
public static function location(mixed $string) {
$string = preg_replace('/[^\s\w\.\,]+/u', '', (string) $string);
$string = mb_substr($string, 0, 200);
return $string;
}
public static function url(string $string) {
public static function url(mixed $string) {
$string = preg_replace('/[^\w\?\&\=\.\:\/]+/u', '', $string);
$string = preg_replace('/[^\w\?\&\=\.\:\/]+/u', '', (string) $string);
$string = mb_substr($string, 0, 200);
return $string;
}
public static function bitMessage(string $string) {
public static function bitMessage(mixed $string) {
$string = preg_replace('/[^\w\-]+/u', '', $string);
$string = preg_replace('/[^\w\-]+/u', '', (string) $string);
$string = mb_substr($string, 0, 200);
return $string;
}
public static function tox(string $string) {
public static function tox(mixed $string) {
$string = preg_replace('/[^\w]+/u', '', $string);
$string = preg_replace('/[^\w]+/u', '', (string) $string);
$string = mb_substr($string, 0, 200);
return $string;
}
public static function bio(string $string) {
public static function bio(mixed $string) {
$string = preg_replace('/[^\s\w\.\,\:\;\@\?\!\+\`\&\^\%\#\=\-\_\~\*\/\(\)\[\]\<\>\"\']+/u', '', $string);
$string = preg_replace('/[^\s\w\.\,\:\;\@\?\!\+\`\&\^\%\#\=\-\_\~\*\/\(\)\[\]\<\>\"\']+/u', '', (string) $string);
$string = mb_substr($string, 0, 500);
return $string;
}
public static function post(string $string) {
public static function post(mixed $string) {
$string = preg_replace('/[^\s\w\.\,\:\;\@\?\!\+\`\&\^\%\#\=\-\_\~\*\/\(\)\[\]\<\>\"\']+/u', '', $string);
$string = preg_replace('/[^\s\w\.\,\:\;\@\?\!\+\`\&\^\%\#\=\-\_\~\*\/\(\)\[\]\<\>\"\']+/u', '', (string) $string);
$string = mb_substr($string, 0, 140);
@ -93,4 +98,43 @@ class Filter { @@ -93,4 +98,43 @@ class Filter {
return (int) $int;
}
public static function userPost(mixed $userPost) {
$result = [];
foreach ((array) $userPost as $key => $value) {
switch ($key) {
case 'height':
$result[$key] = self::int($value);
break;
case 'time':
$result[$key] = self::int($value);
break;
case 'k':
$result[$key] = self::int($value);
break;
case 'lastk':
$result[$key] = self::int($value);
break;
case 'n':
$result[$key] = self::userName($value);
break;
case 'msg':
$result[$key] = self::post($value);
break;
case 'msg2':
$result[$key] = self::post($value);
break;
case 'sig_rt':
$result[$key] = self::sigUserPost($value);
break;
case 'rt':
$result[$key] = self::userPost($value);
break;
}
}
return $result;
}
}

Loading…
Cancel
Save