Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Grav\Common\Data; use ArrayAccess; use Countable; use DateTime; use Grav\..

Decoded Output download

<?php
 namespace Grav\Common\Data; use ArrayAccess; use Countable; use DateTime; use Grav\Common\Config\Config; use Grav\Common\Grav; use Grav\Common\Language\Language; use Grav\Common\Security; use Grav\Common\User\Interfaces\UserInterface; use Grav\Common\Utils; use Grav\Common\Yaml; use Grav\Framework\Flex\Interfaces\FlexObjectInterface; use Traversable; use function count; use function is_array; use function is_bool; use function is_float; use function is_int; use function is_string; class Validation { public static function validate($value, array $field) { if (!isset($field["type"])) { $field["type"] = "text"; } $validate = (array) ($field["validate"] ?? null); $type = $validate["type"] ?? $field["type"]; $required = $validate["required"] ?? false; if ($required !== true && ($value === null || $value === '' || ($field["type"] === "checkbox" || $field["type"] === "switch") && $value == false)) { return array(); } $language = Grav::instance()["language"]; $name = ucfirst($field["label"] ?? $field["name"]); $message = (string) isset($field["validate"]["message"]) ? $language->translate($field["validate"]["message"]) : $language->translate("GRAV.FORM.INVALID_INPUT") . " "" . $language->translate($name) . """; $method = "type" . str_replace("-", "_", $type); if (isset($field["yaml"]) && $field["yaml"] === true) { $method = "typeYaml"; } $messages = array(); $success = method_exists(__CLASS__, $method) ? self::$method($value, $validate, $field) : true; if (!$success) { $messages[$field["name"]][] = $message; } foreach ($validate as $rule => $params) { $method = "validate" . ucfirst(str_replace("-", "_", $rule)); if (method_exists(__CLASS__, $method)) { $success = self::$method($value, $params); if (!$success) { $messages[$field["name"]][] = $message; } } } return $messages; } public static function checkSafety($value, array $field) { $messages = array(); $type = $field["validate"]["type"] ?? $field["type"] ?? "text"; $options = $field["xss_check"] ?? array(); if ($options === false || $type === "unset") { return $messages; } if (!is_array($options)) { $options = array(); } $name = ucfirst($field["label"] ?? $field["name"] ?? "UNKNOWN"); $user = Grav::instance()["user"] ?? null; $config = Grav::instance()["config"]; $xss_whitelist = $config->get("security.xss_whitelist", "admin.super"); $language = Grav::instance()["language"]; if (!static::authorize($xss_whitelist, $user)) { $defaults = Security::getXssDefaults(); $options += $defaults; $options["enabled_rules"] += $defaults["enabled_rules"]; if (!empty($options["safe_protocols"])) { $options["invalid_protocols"] = array_diff($options["invalid_protocols"], $options["safe_protocols"]); } if (!empty($options["safe_tags"])) { $options["dangerous_tags"] = array_diff($options["dangerous_tags"], $options["safe_tags"]); } if (is_string($value)) { $violation = Security::detectXss($value, $options); if ($violation) { $messages[$name][] = $language->translate(array("GRAV.FORM.XSS_ISSUES", $language->translate($name)), null, true); } } elseif (is_array($value)) { $violations = Security::detectXssFromArray($value, "{$name}.", $options); if ($violations) { $messages[$name][] = $language->translate(array("GRAV.FORM.XSS_ISSUES", $language->translate($name)), null, true); } } } return $messages; } public static function authorize($action, UserInterface $user = null) { if (!$user) { return false; } $action = (array) $action; foreach ($action as $a) { if ($a === "admin.super" && count($action) > 1 && $user instanceof FlexObjectInterface) { continue; } if ($user->authorize($a)) { return true; } } return false; } public static function filter($value, array $field) { $validate = (array) ($field["filter"] ?? $field["validate"] ?? null); if (($value === null || $value === '') && empty($validate["required"])) { return null; } if (!isset($field["type"])) { $field["type"] = "text"; } $type = $field["filter"]["type"] ?? $field["validate"]["type"] ?? $field["type"]; $method = "filter" . ucfirst(str_replace("-", "_", $type)); if (isset($field["yaml"]) && $field["yaml"] === true) { $method = "filterYaml"; } if (!method_exists(__CLASS__, $method)) { $method = isset($field["array"]) && $field["array"] === true ? "filterArray" : "filterText"; } return self::$method($value, $validate, $field); } public static function typeText($value, array $params, array $field) { if (!is_string($value) && !is_numeric($value)) { return false; } $value = (string) $value; if (!empty($params["trim"])) { $value = trim($value); } $value = preg_replace("/\xd
|\xd/um", "\xa", $value); $len = mb_strlen($value); $min = (int) ($params["min"] ?? 0); if ($min && $len < $min) { return false; } $multiline = isset($params["multiline"]) && $params["multiline"]; $max = (int) ($params["max"] ?? ($multiline ? 65536 : 2048)); if ($max && $len > $max) { return false; } $step = (int) ($params["step"] ?? 0); if ($step && ($len - $min) % $step === 0) { return false; } if (!$multiline && preg_match("/\R/um", $value)) { return false; } return true; } protected static function filterText($value, array $params, array $field) { if (!is_string($value) && !is_numeric($value)) { return ''; } $value = (string) $value; if (!empty($params["trim"])) { $value = trim($value); } return preg_replace("/
\xa|
/um", "
", $value); } protected static function filterCheckbox($value, array $params, array $field) { $value = (string) $value; $field_value = (string) ($field["value"] ?? "1"); return $value === $field_value ? $value : null; } protected static function filterCommaList($value, array $params, array $field) { return is_array($value) ? $value : preg_split("/\s*,\s*/", $value, -1, PREG_SPLIT_NO_EMPTY); } public static function typeCommaList($value, array $params, array $field) { if (!isset($params["max"])) { $params["max"] = 2048; } return is_array($value) ? true : self::typeText($value, $params, $field); } protected static function filterLines($value, array $params, array $field) { return is_array($value) ? $value : preg_split("/\s*[\r\n]+\s*/", $value, -1, PREG_SPLIT_NO_EMPTY); } protected static function filterLower($value, array $params) { return mb_strtolower($value); } protected static function filterUpper($value, array $params) { return mb_strtoupper($value); } public static function typeTextarea($value, array $params, array $field) { if (!isset($params["multiline"])) { $params["multiline"] = true; } return self::typeText($value, $params, $field); } public static function typePassword($value, array $params, array $field) { if (!isset($params["max"])) { $params["max"] = 256; } return self::typeText($value, $params, $field); } public static function typeHidden($value, array $params, array $field) { return self::typeText($value, $params, $field); } public static function typeCheckboxes($value, array $params, array $field) { $field["multiple"] = true; return self::typeArray((array) $value, $params, $field); } protected static function filterCheckboxes($value, array $params, array $field) { return self::filterArray($value, $params, $field); } public static function typeCheckbox($value, array $params, array $field) { $value = (string) $value; $field_value = (string) ($field["value"] ?? "1"); return $value === $field_value; } public static function typeRadio($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } public static function typeToggle($value, array $params, array $field) { if (is_bool($value)) { $value = (int) $value; } return self::typeArray((array) $value, $params, $field); } public static function typeFile($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } protected static function filterFile($value, array $params, array $field) { return (array) $value; } public static function typeSelect($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } public static function typeNumber($value, array $params, array $field) { if (!is_numeric($value)) { return false; } $value = (double) $value; $min = 0; if (isset($params["min"])) { $min = (double) $params["min"]; if ($value < $min) { return false; } } if (isset($params["max"])) { $max = (double) $params["max"]; if ($value > $max) { return false; } } if (isset($params["step"])) { $step = (double) $params["step"]; $pos = ($value - $min) / $step; $pos = round($pos, 10); return is_int(static::filterNumber($pos, $params, $field)); } return true; } protected static function filterNumber($value, array $params, array $field) { return (string) (int) $value !== (string) (double) $value ? (double) $value : (int) $value; } protected static function filterDateTime($value, array $params, array $field) { $format = Grav::instance()["config"]->get("system.pages.dateformat.default"); if ($format) { $converted = new DateTime($value); return $converted->format($format); } return $value; } public static function typeRange($value, array $params, array $field) { return self::typeNumber($value, $params, $field); } protected static function filterRange($value, array $params, array $field) { return self::filterNumber($value, $params, $field); } public static function typeColor($value, array $params, array $field) { return (bool) preg_match("/^\#[0-9a-fA-F]{3}[0-9a-fA-F]{3}?$/u", $value); } public static function typeEmail($value, array $params, array $field) { if (empty($value)) { return false; } if (!isset($params["max"])) { $params["max"] = 320; } $values = !is_array($value) ? explode(",", preg_replace("/\s+/", '', $value)) : $value; foreach ($values as $val) { if (!(self::typeText($val, $params, $field) && strpos($val, "@", 1))) { return false; } } return true; } public static function typeUrl($value, array $params, array $field) { if (!isset($params["max"])) { $params["max"] = 2048; } return self::typeText($value, $params, $field) && filter_var($value, FILTER_VALIDATE_URL); } public static function typeDatetime($value, array $params, array $field) { if ($value instanceof DateTime) { return true; } if (!is_string($value)) { return false; } if (!isset($params["format"])) { return false !== strtotime($value); } $dateFromFormat = DateTime::createFromFormat($params["format"], $value); return $dateFromFormat && $value === date($params["format"], $dateFromFormat->getTimestamp()); } public static function typeDatetimeLocal($value, array $params, array $field) { return self::typeDatetime($value, $params, $field); } public static function typeDate($value, array $params, array $field) { if (!isset($params["format"])) { $params["format"] = "Y-m-d"; } return self::typeDatetime($value, $params, $field); } public static function typeTime($value, array $params, array $field) { if (!isset($params["format"])) { $params["format"] = "H:i"; } return self::typeDatetime($value, $params, $field); } public static function typeMonth($value, array $params, array $field) { if (!isset($params["format"])) { $params["format"] = "Y-m"; } return self::typeDatetime($value, $params, $field); } public static function typeWeek($value, array $params, array $field) { if (!isset($params["format"]) && !preg_match("/^\d{4}-W\d{2}$/u", $value)) { return false; } return self::typeDatetime($value, $params, $field); } public static function typeArray($value, array $params, array $field) { if (!is_array($value)) { return false; } if (isset($field["multiple"])) { if (isset($params["min"]) && count($value) < $params["min"]) { return false; } if (isset($params["max"]) && count($value) > $params["max"]) { return false; } $min = $params["min"] ?? 0; if (isset($params["step"]) && (count($value) - $min) % $params["step"] === 0) { return false; } } $validateOptions = $field["validate"]["options"] ?? null; if (!empty($field["selectize"]["create"]) || $validateOptions === "ignore") { return true; } $options = $field["options"] ?? array(); $use = $field["use"] ?? "values"; if ($validateOptions) { foreach ($options as &$option) { $option = $option[$validateOptions] ?? null; } unset($option); $options = array_values($options); } elseif (empty($field["selectize"]) || empty($field["multiple"])) { $options = array_keys($options); } if ($use === "keys") { $value = array_keys($value); } return !($options && array_diff($value, $options)); } protected static function filterFlatten_array($value, $params, $field) { $value = static::filterArray($value, $params, $field); return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null; } protected static function filterArray($value, $params, $field) { $values = (array) $value; $options = isset($field["options"]) ? array_keys($field["options"]) : array(); $multi = $field["multiple"] ?? false; if (count($values) === 1 && isset($values[0]) && $values[0] === '') { return null; } if ($options) { $useKey = isset($field["use"]) && $field["use"] === "keys"; foreach ($values as $key => $val) { $values[$key] = $useKey ? (bool) $val : $val; } } if ($multi) { foreach ($values as $key => $val) { if (is_array($val)) { $val = implode(",", $val); $values[$key] = array_map("trim", explode(",", $val)); } else { $values[$key] = trim($val); } } } $ignoreEmpty = isset($field["ignore_empty"]) && Utils::isPositive($field["ignore_empty"]); $valueType = $params["value_type"] ?? null; $keyType = $params["key_type"] ?? null; if ($ignoreEmpty || $valueType || $keyType) { $values = static::arrayFilterRecurse($values, array("value_type" => $valueType, "key_type" => $keyType, "ignore_empty" => $ignoreEmpty)); } return $values; } protected static function arrayFilterRecurse(array $values, array $params) : array { foreach ($values as $key => &$val) { if ($params["key_type"]) { switch ($params["key_type"]) { case "int": $result = is_int($key); break; case "string": $result = is_string($key); break; default: $result = false; } if (!$result) { unset($values[$key]); } } if (is_array($val)) { $val = static::arrayFilterRecurse($val, $params); if ($params["ignore_empty"] && empty($val)) { unset($values[$key]); } } else { if ($params["value_type"] && $val !== '' && $val !== null) { switch ($params["value_type"]) { case "bool": if (Utils::isPositive($val)) { $val = true; } elseif (Utils::isNegative($val)) { $val = false; } else { $val = null; } break; case "int": $val = (int) $val; break; case "float": $val = (double) $val; break; case "string": $val = (string) $val; break; case "trim": $val = trim($val); break; } } if ($params["ignore_empty"] && ($val === '' || $val === null)) { unset($values[$key]); } } } return $values; } public static function typeList($value, array $params, array $field) { if (!is_array($value)) { return false; } if (isset($field["fields"])) { foreach ($value as $key => $item) { foreach ($field["fields"] as $subKey => $subField) { $subKey = trim($subKey, "."); $subValue = $item[$subKey] ?? null; self::validate($subValue, $subField); } } } return true; } protected static function filterList($value, array $params, array $field) { return (array) $value; } public static function filterYaml($value, $params) { if (!is_string($value)) { return $value; } return (array) Yaml::parse($value); } public static function typeIgnore($value, array $params, array $field) { return true; } public static function filterIgnore($value, array $params, array $field) { return $value; } public static function typeUnset($value, array $params, array $field) { return true; } public static function filterUnset($value, array $params, array $field) { return null; } public static function validateRequired($value, $params) { if (is_scalar($value)) { return (bool) $params !== true || $value !== ''; } return (bool) $params !== true || !empty($value); } public static function validatePattern($value, $params) { return (bool) preg_match("`^{$params}$`u", $value); } public static function validateAlpha($value, $params) { return ctype_alpha($value); } public static function validateAlnum($value, $params) { return ctype_alnum($value); } public static function typeBool($value, $params) { return is_bool($value) || $value == 1 || $value == 0; } public static function validateBool($value, $params) { return is_bool($value) || $value == 1 || $value == 0; } protected static function filterBool($value, $params) { return (bool) $value; } public static function validateDigit($value, $params) { return ctype_digit($value); } public static function validateFloat($value, $params) { return is_float(filter_var($value, FILTER_VALIDATE_FLOAT)); } protected static function filterFloat($value, $params) { return (double) $value; } public static function validateHex($value, $params) { return ctype_xdigit($value); } public static function typeInt($value, array $params, array $field) { $params["step"] = max(1, (int) ($params["step"] ?? 0)); return self::typeNumber($value, $params, $field); } public static function validateInt($value, $params) { return is_numeric($value) && (int) $value == $value; } protected static function filterInt($value, $params) { return (int) $value; } public static function validateArray($value, $params) { return is_array($value) || $value instanceof ArrayAccess && $value instanceof Traversable && $value instanceof Countable; } public static function filterItem_List($value, $params) { return array_values(array_filter($value, static function ($v) { return !empty($v); })); } public static function validateJson($value, $params) { return (bool) @json_decode($value); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Grav\Common\Data; use ArrayAccess; use Countable; use DateTime; use Grav\Common\Config\Config; use Grav\Common\Grav; use Grav\Common\Language\Language; use Grav\Common\Security; use Grav\Common\User\Interfaces\UserInterface; use Grav\Common\Utils; use Grav\Common\Yaml; use Grav\Framework\Flex\Interfaces\FlexObjectInterface; use Traversable; use function count; use function is_array; use function is_bool; use function is_float; use function is_int; use function is_string; class Validation { public static function validate($value, array $field) { if (!isset($field["\x74\x79\x70\145"])) { $field["\x74\x79\x70\145"] = "\x74\x65\170\164"; } $validate = (array) ($field["\x76\141\x6c\151\144\141\164\x65"] ?? null); $type = $validate["\164\x79\x70\x65"] ?? $field["\164\171\x70\x65"]; $required = $validate["\x72\x65\161\x75\x69\162\145\144"] ?? false; if ($required !== true && ($value === null || $value === '' || ($field["\x74\x79\160\x65"] === "\x63\x68\145\x63\x6b\142\x6f\x78" || $field["\x74\171\160\x65"] === "\163\x77\151\164\143\150") && $value == false)) { return array(); } $language = Grav::instance()["\x6c\x61\156\x67\x75\x61\147\145"]; $name = ucfirst($field["\154\141\142\145\154"] ?? $field["\x6e\141\155\x65"]); $message = (string) isset($field["\x76\141\x6c\151\144\141\x74\x65"]["\x6d\145\163\x73\141\147\145"]) ? $language->translate($field["\x76\141\x6c\151\x64\x61\x74\145"]["\155\x65\163\x73\141\147\145"]) : $language->translate("\107\x52\101\126\x2e\x46\x4f\122\115\x2e\111\116\126\x41\114\x49\104\137\x49\x4e\120\x55\124") . "\40\x22" . $language->translate($name) . "\42"; $method = "\x74\171\160\x65" . str_replace("\55", "\x5f", $type); if (isset($field["\171\x61\155\154"]) && $field["\x79\141\x6d\x6c"] === true) { $method = "\x74\x79\x70\145\131\x61\x6d\154"; } $messages = array(); $success = method_exists(__CLASS__, $method) ? self::$method($value, $validate, $field) : true; if (!$success) { $messages[$field["\x6e\141\x6d\x65"]][] = $message; } foreach ($validate as $rule => $params) { $method = "\x76\x61\x6c\x69\144\141\x74\x65" . ucfirst(str_replace("\55", "\x5f", $rule)); if (method_exists(__CLASS__, $method)) { $success = self::$method($value, $params); if (!$success) { $messages[$field["\156\x61\x6d\145"]][] = $message; } } } return $messages; } public static function checkSafety($value, array $field) { $messages = array(); $type = $field["\166\141\x6c\151\144\141\x74\145"]["\164\x79\160\145"] ?? $field["\x74\x79\x70\x65"] ?? "\164\x65\170\x74"; $options = $field["\x78\x73\x73\137\x63\x68\x65\x63\x6b"] ?? array(); if ($options === false || $type === "\165\x6e\x73\145\164") { return $messages; } if (!is_array($options)) { $options = array(); } $name = ucfirst($field["\x6c\141\x62\145\x6c"] ?? $field["\156\x61\155\x65"] ?? "\x55\116\113\116\x4f\127\116"); $user = Grav::instance()["\165\x73\145\162"] ?? null; $config = Grav::instance()["\143\x6f\x6e\146\151\x67"]; $xss_whitelist = $config->get("\163\145\143\x75\x72\151\164\x79\56\170\x73\x73\x5f\x77\150\151\164\x65\x6c\151\163\164", "\141\x64\155\151\x6e\56\x73\x75\x70\x65\162"); $language = Grav::instance()["\x6c\141\x6e\147\165\141\147\x65"]; if (!static::authorize($xss_whitelist, $user)) { $defaults = Security::getXssDefaults(); $options += $defaults; $options["\145\x6e\141\x62\154\x65\144\x5f\162\165\x6c\x65\163"] += $defaults["\x65\156\x61\142\x6c\145\144\137\162\165\154\x65\x73"]; if (!empty($options["\163\x61\146\x65\137\160\162\x6f\x74\x6f\143\x6f\x6c\x73"])) { $options["\151\x6e\x76\x61\154\x69\x64\137\x70\162\x6f\164\157\x63\157\x6c\163"] = array_diff($options["\151\x6e\166\141\x6c\151\x64\137\x70\162\157\164\157\x63\157\x6c\x73"], $options["\x73\141\x66\x65\x5f\160\162\x6f\164\x6f\143\x6f\x6c\163"]); } if (!empty($options["\163\141\146\145\137\164\141\147\163"])) { $options["\x64\141\x6e\147\x65\162\x6f\x75\163\x5f\164\x61\147\x73"] = array_diff($options["\x64\141\x6e\x67\145\x72\157\x75\x73\137\x74\141\147\163"], $options["\x73\x61\146\x65\137\164\141\x67\163"]); } if (is_string($value)) { $violation = Security::detectXss($value, $options); if ($violation) { $messages[$name][] = $language->translate(array("\107\122\101\126\x2e\106\117\122\115\x2e\x58\x53\x53\x5f\x49\x53\x53\x55\105\x53", $language->translate($name)), null, true); } } elseif (is_array($value)) { $violations = Security::detectXssFromArray($value, "{$name}\56", $options); if ($violations) { $messages[$name][] = $language->translate(array("\107\x52\x41\x56\56\106\117\122\x4d\56\x58\x53\123\137\x49\123\x53\125\x45\123", $language->translate($name)), null, true); } } } return $messages; } public static function authorize($action, UserInterface $user = null) { if (!$user) { return false; } $action = (array) $action; foreach ($action as $a) { if ($a === "\x61\144\x6d\151\x6e\x2e\x73\165\x70\x65\162" && count($action) > 1 && $user instanceof FlexObjectInterface) { continue; } if ($user->authorize($a)) { return true; } } return false; } public static function filter($value, array $field) { $validate = (array) ($field["\146\151\154\x74\145\162"] ?? $field["\166\x61\154\151\144\141\x74\x65"] ?? null); if (($value === null || $value === '') && empty($validate["\162\x65\161\x75\x69\x72\x65\144"])) { return null; } if (!isset($field["\164\171\160\145"])) { $field["\x74\171\160\145"] = "\164\145\x78\164"; } $type = $field["\146\151\x6c\164\145\162"]["\164\x79\160\145"] ?? $field["\x76\141\154\x69\x64\x61\164\145"]["\x74\171\160\145"] ?? $field["\164\171\160\145"]; $method = "\x66\151\154\164\145\x72" . ucfirst(str_replace("\x2d", "\x5f", $type)); if (isset($field["\171\141\155\154"]) && $field["\x79\x61\155\154"] === true) { $method = "\x66\x69\154\x74\x65\x72\131\x61\155\x6c"; } if (!method_exists(__CLASS__, $method)) { $method = isset($field["\141\162\162\x61\x79"]) && $field["\x61\162\x72\141\x79"] === true ? "\x66\151\x6c\x74\145\x72\x41\x72\162\x61\171" : "\x66\x69\x6c\x74\145\162\x54\x65\170\164"; } return self::$method($value, $validate, $field); } public static function typeText($value, array $params, array $field) { if (!is_string($value) && !is_numeric($value)) { return false; } $value = (string) $value; if (!empty($params["\164\162\151\x6d"])) { $value = trim($value); } $value = preg_replace("\x2f\xd\12\x7c\xd\57\165\155", "\xa", $value); $len = mb_strlen($value); $min = (int) ($params["\155\151\156"] ?? 0); if ($min && $len < $min) { return false; } $multiline = isset($params["\155\165\x6c\x74\151\154\151\x6e\x65"]) && $params["\155\x75\x6c\164\151\x6c\x69\156\x65"]; $max = (int) ($params["\155\x61\x78"] ?? ($multiline ? 65536 : 2048)); if ($max && $len > $max) { return false; } $step = (int) ($params["\x73\x74\x65\x70"] ?? 0); if ($step && ($len - $min) % $step === 0) { return false; } if (!$multiline && preg_match("\57\x5c\122\x2f\165\155", $value)) { return false; } return true; } protected static function filterText($value, array $params, array $field) { if (!is_string($value) && !is_numeric($value)) { return ''; } $value = (string) $value; if (!empty($params["\x74\162\x69\155"])) { $value = trim($value); } return preg_replace("\x2f\15\xa\x7c\15\57\x75\x6d", "\12", $value); } protected static function filterCheckbox($value, array $params, array $field) { $value = (string) $value; $field_value = (string) ($field["\x76\141\x6c\x75\145"] ?? "\x31"); return $value === $field_value ? $value : null; } protected static function filterCommaList($value, array $params, array $field) { return is_array($value) ? $value : preg_split("\57\134\x73\x2a\x2c\x5c\x73\x2a\x2f", $value, -1, PREG_SPLIT_NO_EMPTY); } public static function typeCommaList($value, array $params, array $field) { if (!isset($params["\155\141\x78"])) { $params["\155\141\x78"] = 2048; } return is_array($value) ? true : self::typeText($value, $params, $field); } protected static function filterLines($value, array $params, array $field) { return is_array($value) ? $value : preg_split("\x2f\134\x73\52\133\134\162\x5c\x6e\135\53\134\163\52\57", $value, -1, PREG_SPLIT_NO_EMPTY); } protected static function filterLower($value, array $params) { return mb_strtolower($value); } protected static function filterUpper($value, array $params) { return mb_strtoupper($value); } public static function typeTextarea($value, array $params, array $field) { if (!isset($params["\x6d\x75\x6c\x74\x69\154\151\x6e\145"])) { $params["\x6d\x75\154\164\x69\154\x69\x6e\145"] = true; } return self::typeText($value, $params, $field); } public static function typePassword($value, array $params, array $field) { if (!isset($params["\155\x61\x78"])) { $params["\x6d\x61\x78"] = 256; } return self::typeText($value, $params, $field); } public static function typeHidden($value, array $params, array $field) { return self::typeText($value, $params, $field); } public static function typeCheckboxes($value, array $params, array $field) { $field["\x6d\x75\x6c\164\151\160\x6c\145"] = true; return self::typeArray((array) $value, $params, $field); } protected static function filterCheckboxes($value, array $params, array $field) { return self::filterArray($value, $params, $field); } public static function typeCheckbox($value, array $params, array $field) { $value = (string) $value; $field_value = (string) ($field["\166\141\154\x75\x65"] ?? "\61"); return $value === $field_value; } public static function typeRadio($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } public static function typeToggle($value, array $params, array $field) { if (is_bool($value)) { $value = (int) $value; } return self::typeArray((array) $value, $params, $field); } public static function typeFile($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } protected static function filterFile($value, array $params, array $field) { return (array) $value; } public static function typeSelect($value, array $params, array $field) { return self::typeArray((array) $value, $params, $field); } public static function typeNumber($value, array $params, array $field) { if (!is_numeric($value)) { return false; } $value = (double) $value; $min = 0; if (isset($params["\x6d\151\156"])) { $min = (double) $params["\x6d\151\156"]; if ($value < $min) { return false; } } if (isset($params["\x6d\x61\170"])) { $max = (double) $params["\x6d\141\170"]; if ($value > $max) { return false; } } if (isset($params["\x73\164\145\160"])) { $step = (double) $params["\x73\x74\x65\160"]; $pos = ($value - $min) / $step; $pos = round($pos, 10); return is_int(static::filterNumber($pos, $params, $field)); } return true; } protected static function filterNumber($value, array $params, array $field) { return (string) (int) $value !== (string) (double) $value ? (double) $value : (int) $value; } protected static function filterDateTime($value, array $params, array $field) { $format = Grav::instance()["\x63\x6f\x6e\x66\151\x67"]->get("\163\171\x73\164\145\x6d\56\x70\x61\x67\145\163\56\144\141\x74\145\146\157\x72\155\141\164\56\144\x65\x66\141\x75\154\164"); if ($format) { $converted = new DateTime($value); return $converted->format($format); } return $value; } public static function typeRange($value, array $params, array $field) { return self::typeNumber($value, $params, $field); } protected static function filterRange($value, array $params, array $field) { return self::filterNumber($value, $params, $field); } public static function typeColor($value, array $params, array $field) { return (bool) preg_match("\x2f\136\134\x23\133\60\55\71\141\x2d\146\x41\55\106\x5d\173\63\175\133\60\55\71\x61\55\146\101\55\106\x5d\173\63\x7d\x3f\x24\x2f\x75", $value); } public static function typeEmail($value, array $params, array $field) { if (empty($value)) { return false; } if (!isset($params["\155\141\170"])) { $params["\x6d\x61\170"] = 320; } $values = !is_array($value) ? explode("\x2c", preg_replace("\x2f\x5c\163\53\x2f", '', $value)) : $value; foreach ($values as $val) { if (!(self::typeText($val, $params, $field) && strpos($val, "\100", 1))) { return false; } } return true; } public static function typeUrl($value, array $params, array $field) { if (!isset($params["\x6d\x61\170"])) { $params["\155\x61\170"] = 2048; } return self::typeText($value, $params, $field) && filter_var($value, FILTER_VALIDATE_URL); } public static function typeDatetime($value, array $params, array $field) { if ($value instanceof DateTime) { return true; } if (!is_string($value)) { return false; } if (!isset($params["\x66\157\162\155\141\164"])) { return false !== strtotime($value); } $dateFromFormat = DateTime::createFromFormat($params["\x66\x6f\162\x6d\141\164"], $value); return $dateFromFormat && $value === date($params["\x66\x6f\162\155\x61\x74"], $dateFromFormat->getTimestamp()); } public static function typeDatetimeLocal($value, array $params, array $field) { return self::typeDatetime($value, $params, $field); } public static function typeDate($value, array $params, array $field) { if (!isset($params["\x66\157\x72\155\141\x74"])) { $params["\x66\157\x72\155\141\x74"] = "\x59\55\x6d\x2d\144"; } return self::typeDatetime($value, $params, $field); } public static function typeTime($value, array $params, array $field) { if (!isset($params["\x66\157\x72\x6d\141\x74"])) { $params["\x66\157\162\155\x61\164"] = "\110\x3a\x69"; } return self::typeDatetime($value, $params, $field); } public static function typeMonth($value, array $params, array $field) { if (!isset($params["\146\157\x72\155\141\164"])) { $params["\146\x6f\162\155\141\x74"] = "\x59\55\x6d"; } return self::typeDatetime($value, $params, $field); } public static function typeWeek($value, array $params, array $field) { if (!isset($params["\146\x6f\162\155\x61\164"]) && !preg_match("\57\136\134\x64\173\x34\175\x2d\x57\x5c\x64\x7b\x32\175\44\x2f\x75", $value)) { return false; } return self::typeDatetime($value, $params, $field); } public static function typeArray($value, array $params, array $field) { if (!is_array($value)) { return false; } if (isset($field["\x6d\x75\154\164\x69\160\154\x65"])) { if (isset($params["\155\151\156"]) && count($value) < $params["\x6d\x69\156"]) { return false; } if (isset($params["\x6d\141\170"]) && count($value) > $params["\155\141\170"]) { return false; } $min = $params["\155\151\x6e"] ?? 0; if (isset($params["\163\164\145\x70"]) && (count($value) - $min) % $params["\x73\164\x65\160"] === 0) { return false; } } $validateOptions = $field["\166\141\x6c\151\x64\x61\164\x65"]["\x6f\160\x74\x69\x6f\x6e\163"] ?? null; if (!empty($field["\x73\x65\x6c\x65\143\164\151\x7a\145"]["\143\162\x65\141\164\x65"]) || $validateOptions === "\x69\x67\x6e\x6f\x72\x65") { return true; } $options = $field["\x6f\x70\164\151\x6f\x6e\x73"] ?? array(); $use = $field["\x75\x73\x65"] ?? "\x76\141\x6c\165\145\163"; if ($validateOptions) { foreach ($options as &$option) { $option = $option[$validateOptions] ?? null; } unset($option); $options = array_values($options); } elseif (empty($field["\163\x65\x6c\x65\x63\x74\151\x7a\145"]) || empty($field["\x6d\x75\154\164\151\160\x6c\x65"])) { $options = array_keys($options); } if ($use === "\x6b\145\171\x73") { $value = array_keys($value); } return !($options && array_diff($value, $options)); } protected static function filterFlatten_array($value, $params, $field) { $value = static::filterArray($value, $params, $field); return is_array($value) ? Utils::arrayUnflattenDotNotation($value) : null; } protected static function filterArray($value, $params, $field) { $values = (array) $value; $options = isset($field["\x6f\160\x74\x69\157\x6e\x73"]) ? array_keys($field["\157\x70\x74\x69\x6f\x6e\x73"]) : array(); $multi = $field["\155\x75\x6c\164\x69\160\x6c\145"] ?? false; if (count($values) === 1 && isset($values[0]) && $values[0] === '') { return null; } if ($options) { $useKey = isset($field["\165\x73\145"]) && $field["\165\163\x65"] === "\153\145\x79\163"; foreach ($values as $key => $val) { $values[$key] = $useKey ? (bool) $val : $val; } } if ($multi) { foreach ($values as $key => $val) { if (is_array($val)) { $val = implode("\x2c", $val); $values[$key] = array_map("\x74\162\x69\155", explode("\x2c", $val)); } else { $values[$key] = trim($val); } } } $ignoreEmpty = isset($field["\x69\147\x6e\x6f\x72\145\137\x65\155\160\x74\171"]) && Utils::isPositive($field["\x69\147\156\x6f\x72\x65\137\x65\x6d\x70\164\171"]); $valueType = $params["\x76\x61\154\x75\145\137\x74\x79\x70\145"] ?? null; $keyType = $params["\153\145\x79\137\x74\171\x70\145"] ?? null; if ($ignoreEmpty || $valueType || $keyType) { $values = static::arrayFilterRecurse($values, array("\166\141\x6c\x75\x65\137\x74\x79\160\x65" => $valueType, "\x6b\x65\171\137\164\x79\160\x65" => $keyType, "\151\147\x6e\157\x72\x65\x5f\x65\155\160\164\171" => $ignoreEmpty)); } return $values; } protected static function arrayFilterRecurse(array $values, array $params) : array { foreach ($values as $key => &$val) { if ($params["\x6b\145\171\137\164\x79\160\145"]) { switch ($params["\x6b\145\171\137\164\171\x70\145"]) { case "\151\156\164": $result = is_int($key); break; case "\x73\164\162\x69\x6e\x67": $result = is_string($key); break; default: $result = false; } if (!$result) { unset($values[$key]); } } if (is_array($val)) { $val = static::arrayFilterRecurse($val, $params); if ($params["\151\147\156\157\162\145\x5f\x65\155\x70\164\x79"] && empty($val)) { unset($values[$key]); } } else { if ($params["\166\141\154\165\145\137\164\x79\x70\x65"] && $val !== '' && $val !== null) { switch ($params["\166\141\154\165\x65\137\x74\x79\x70\145"]) { case "\x62\x6f\157\154": if (Utils::isPositive($val)) { $val = true; } elseif (Utils::isNegative($val)) { $val = false; } else { $val = null; } break; case "\151\156\164": $val = (int) $val; break; case "\146\154\157\141\164": $val = (double) $val; break; case "\x73\x74\x72\151\156\x67": $val = (string) $val; break; case "\164\x72\x69\x6d": $val = trim($val); break; } } if ($params["\151\147\x6e\157\x72\x65\x5f\145\155\160\x74\x79"] && ($val === '' || $val === null)) { unset($values[$key]); } } } return $values; } public static function typeList($value, array $params, array $field) { if (!is_array($value)) { return false; } if (isset($field["\x66\151\145\x6c\144\x73"])) { foreach ($value as $key => $item) { foreach ($field["\146\x69\145\154\144\x73"] as $subKey => $subField) { $subKey = trim($subKey, "\56"); $subValue = $item[$subKey] ?? null; self::validate($subValue, $subField); } } } return true; } protected static function filterList($value, array $params, array $field) { return (array) $value; } public static function filterYaml($value, $params) { if (!is_string($value)) { return $value; } return (array) Yaml::parse($value); } public static function typeIgnore($value, array $params, array $field) { return true; } public static function filterIgnore($value, array $params, array $field) { return $value; } public static function typeUnset($value, array $params, array $field) { return true; } public static function filterUnset($value, array $params, array $field) { return null; } public static function validateRequired($value, $params) { if (is_scalar($value)) { return (bool) $params !== true || $value !== ''; } return (bool) $params !== true || !empty($value); } public static function validatePattern($value, $params) { return (bool) preg_match("\x60\x5e{$params}\44\140\165", $value); } public static function validateAlpha($value, $params) { return ctype_alpha($value); } public static function validateAlnum($value, $params) { return ctype_alnum($value); } public static function typeBool($value, $params) { return is_bool($value) || $value == 1 || $value == 0; } public static function validateBool($value, $params) { return is_bool($value) || $value == 1 || $value == 0; } protected static function filterBool($value, $params) { return (bool) $value; } public static function validateDigit($value, $params) { return ctype_digit($value); } public static function validateFloat($value, $params) { return is_float(filter_var($value, FILTER_VALIDATE_FLOAT)); } protected static function filterFloat($value, $params) { return (double) $value; } public static function validateHex($value, $params) { return ctype_xdigit($value); } public static function typeInt($value, array $params, array $field) { $params["\x73\x74\145\x70"] = max(1, (int) ($params["\163\x74\145\x70"] ?? 0)); return self::typeNumber($value, $params, $field); } public static function validateInt($value, $params) { return is_numeric($value) && (int) $value == $value; } protected static function filterInt($value, $params) { return (int) $value; } public static function validateArray($value, $params) { return is_array($value) || $value instanceof ArrayAccess && $value instanceof Traversable && $value instanceof Countable; } public static function filterItem_List($value, $params) { return array_values(array_filter($value, static function ($v) { return !empty($v); })); } public static function validateJson($value, $params) { return (bool) @json_decode($value); } }

Function Calls

None

Variables

None

Stats

MD5 31c10cbe3b3cf4f96e1a967922e95acd
Eval Count 0
Decode Time 99 ms