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 defined("\102\101\x53\x45\120\101\124\110") or die("\x4e\x6f\x20\x64\x69\x72\x65\x6..

Decoded Output download

<?php
 defined("BASEPATH") or die("No direct script access allowed"); class CI_Form_validation { protected $CI; protected $_field_data = array(); protected $_config_rules = array(); protected $_error_array = array(); protected $_error_messages = array(); protected $_error_prefix = "<p>"; protected $_error_suffix = "</p>"; protected $error_string = ''; public $validation_data = array(); public function __construct($rules = array()) { $this->CI =& get_instance(); if (isset($rules["error_prefix"])) { $this->_error_prefix = $rules["error_prefix"]; unset($rules["error_prefix"]); } if (isset($rules["error_suffix"])) { $this->_error_suffix = $rules["error_suffix"]; unset($rules["error_suffix"]); } $this->_config_rules = $rules; $this->CI->load->helper("form"); log_message("info", "Form Validation Class Initialized"); } public function set_rules($field, $label = null, $rules = null, $errors = array()) { if ($this->CI->input->method() !== "post" && empty($this->validation_data)) { return $this; } if (is_array($field)) { foreach ($field as $row) { if (!isset($row["field"], $row["rules"])) { continue; } $label = isset($row["label"]) ? $row["label"] : $row["field"]; $errors = isset($row["errors"]) && is_array($row["errors"]) ? $row["errors"] : array(); $this->set_rules($row["field"], $label, $row["rules"], $errors); } return $this; } elseif (!isset($rules)) { throw new BadMethodCallException("Form_validation: set_rules() called without a $rules parameter"); } if (!is_string($field) or $field === '' or empty($rules)) { throw new RuntimeException("Form_validation: set_rules() called with an empty $rules parameter"); } elseif (!is_array($rules)) { if (!is_string($rules)) { throw new InvalidArgumentException("Form_validation: set_rules() expect $rules to be string or array; " . gettype($rules) . " given"); } $rules = preg_split("/\|(?![^\[]*\])/", $rules); } $label = $label === '' ? $field : $label; $indexes = array(); if (($is_array = (bool) preg_match_all("/\[(.*?)\]/", $field, $matches)) === TRUE) { sscanf($field, "%[^[][", $indexes[0]); for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { if ($matches[1][$i] !== '') { $indexes[] = $matches[1][$i]; } } } $this->_field_data[$field] = array("field" => $field, "label" => $label, "rules" => $rules, "errors" => $errors, "is_array" => $is_array, "keys" => $indexes, "postdata" => NULL, "error" => ''); return $this; } public function set_data(array $data) { if (!empty($data)) { $this->validation_data = $data; } return $this; } public function set_message($lang, $val = '') { if (!is_array($lang)) { $lang = array($lang => $val); } $this->_error_messages = array_merge($this->_error_messages, $lang); return $this; } public function set_error_delimiters($prefix = "<p>", $suffix = "</p>") { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; return $this; } public function error($field, $prefix = '', $suffix = '') { if (empty($this->_field_data[$field]["error"])) { return ''; } if ($prefix === '') { $prefix = $this->_error_prefix; } if ($suffix === '') { $suffix = $this->_error_suffix; } return $prefix . $this->_field_data[$field]["error"] . $suffix; } public function error_array() { return $this->_error_array; } public function error_string($prefix = '', $suffix = '') { if (count($this->_error_array) === 0) { return ''; } if ($prefix === '') { $prefix = $this->_error_prefix; } if ($suffix === '') { $suffix = $this->_error_suffix; } $str = ''; foreach ($this->_error_array as $val) { if ($val !== '') { $str .= $prefix . $val . $suffix . "
"; } } return $str; } public function run($config = NULL, &$data = NULL) { $validation_array = empty($this->validation_data) ? $_POST : $this->validation_data; if (count($this->_field_data) === 0) { if (empty($this->_config_rules)) { return FALSE; } if (empty($config)) { $config = trim($this->CI->uri->ruri_string(), "/"); isset($this->_config_rules[$config]) or $config = $this->CI->router->class . "/" . $this->CI->router->method; } $this->set_rules(isset($this->_config_rules[$config]) ? $this->_config_rules[$config] : $this->_config_rules); if (count($this->_field_data) === 0) { log_message("debug", "Unable to find validation rules"); return FALSE; } } $this->CI->lang->load("form_validation"); foreach ($this->_field_data as $field => &$row) { if ($row["is_array"] === TRUE) { $this->_field_data[$field]["postdata"] = $this->_reduce_array($validation_array, $row["keys"]); } elseif (isset($validation_array[$field])) { $this->_field_data[$field]["postdata"] = $validation_array[$field]; } } foreach ($this->_field_data as $field => &$row) { if (empty($row["rules"])) { continue; } $this->_execute($row, $row["rules"], $row["postdata"]); } if (!empty($this->_error_array)) { return FALSE; } if (func_num_args() >= 2) { $data = empty($this->validation_data) ? $_POST : $this->validation_data; $this->_reset_data_array($data); return TRUE; } empty($this->validation_data) && $this->_reset_data_array($_POST); return TRUE; } protected function _prepare_rules($rules) { $new_rules = array(); $callbacks = array(); foreach ($rules as &$rule) { if ($rule === "required") { array_unshift($new_rules, "required"); } elseif ($rule === "isset" && (empty($new_rules) or $new_rules[0] !== "required")) { array_unshift($new_rules, "isset"); } elseif (is_string($rule) && strncmp("callback_", $rule, 9) === 0) { $callbacks[] = $rule; } elseif (is_callable($rule)) { $callbacks[] = $rule; } elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1])) { $callbacks[] = $rule; } else { $new_rules[] = $rule; } } return array_merge($callbacks, $new_rules); } protected function _reduce_array($array, $keys, $i = 0) { if (is_array($array) && isset($keys[$i])) { return isset($array[$keys[$i]]) ? $this->_reduce_array($array[$keys[$i]], $keys, $i + 1) : NULL; } return $array === '' ? NULL : $array; } protected function _reset_data_array(&$data) { foreach ($this->_field_data as $field => $row) { if ($row["postdata"] !== NULL) { if ($row["is_array"] === FALSE) { isset($data[$field]) && ($data[$field] = is_array($row["postdata"]) ? NULL : $row["postdata"]); } else { $data_ref =& $data; if (count($row["keys"]) === 1) { $data_ref =& $data[current($row["keys"])]; } else { foreach ($row["keys"] as $val) { $data_ref =& $data_ref[$val]; } } $data_ref = $row["postdata"]; } } } } protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) { $allow_arrays = in_array("is_array", $rules, TRUE); if ($allow_arrays === FALSE && is_array($postdata) && !empty($postdata)) { foreach ($postdata as $key => $val) { $this->_execute($row, $rules, $val, $key); } return; } $rules = $this->_prepare_rules($rules); foreach ($rules as $rule) { $_in_array = FALSE; if ($row["is_array"] === TRUE && is_array($this->_field_data[$row["field"]]["postdata"])) { if (!isset($this->_field_data[$row["field"]]["postdata"][$cycles])) { continue; } $postdata = $this->_field_data[$row["field"]]["postdata"][$cycles]; $_in_array = TRUE; } elseif ($allow_arrays === FALSE && is_array($this->_field_data[$row["field"]]["postdata"])) { $postdata = NULL; } else { $postdata = $this->_field_data[$row["field"]]["postdata"]; } $callback = $callable = FALSE; if (is_string($rule)) { if (strpos($rule, "callback_") === 0) { $rule = substr($rule, 9); $callback = TRUE; } } elseif (is_callable($rule)) { $callable = TRUE; } elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1])) { $callable = $rule[0]; $rule = $rule[1]; } $param = FALSE; if (!$callable && preg_match("/(.*?)\[(.*)\]/", $rule, $match)) { $rule = $match[1]; $param = $match[2]; } if (($postdata === NULL or $allow_arrays === FALSE && $postdata === '') && $callback === FALSE && $callable === FALSE && !in_array($rule, array("required", "isset", "matches"), TRUE)) { continue; } if ($callback or $callable !== FALSE) { if ($callback) { if (!method_exists($this->CI, $rule)) { log_message("debug", "Unable to find callback validation rule: " . $rule); $result = FALSE; } else { $result = $this->CI->{$rule}($postdata, $param); } } else { $result = is_array($rule) ? $rule[0]->{$rule[1]}($postdata) : $rule($postdata); if ($callable !== FALSE) { $rule = $callable; } } if ($_in_array === TRUE) { $this->_field_data[$row["field"]]["postdata"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["field"]]["postdata"] = is_bool($result) ? $postdata : $result; } } elseif (!method_exists($this, $rule)) { if (function_exists($rule)) { $result = $param !== FALSE ? $rule($postdata, $param) : $rule($postdata); if ($_in_array === TRUE) { $this->_field_data[$row["field"]]["postdata"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["field"]]["postdata"] = is_bool($result) ? $postdata : $result; } } else { log_message("debug", "Unable to find validation rule: " . $rule); $result = FALSE; } } else { $result = $this->{$rule}($postdata, $param); if ($_in_array === TRUE) { $this->_field_data[$row["field"]]["postdata"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["field"]]["postdata"] = is_bool($result) ? $postdata : $result; } } if ($result === FALSE) { if (!is_string($rule)) { $line = $this->CI->lang->line("form_validation_error_message_not_set") . "(Anonymous function)"; } else { $line = $this->_get_error_message($rule, $row["field"]); } if (isset($this->_field_data[$param], $this->_field_data[$param]["label"])) { $param = $this->_translate_fieldname($this->_field_data[$param]["label"]); } $message = $this->_build_error_msg($line, $this->_translate_fieldname($row["label"]), $param); $this->_field_data[$row["field"]]["error"] = $message; if (!isset($this->_error_array[$row["field"]])) { $this->_error_array[$row["field"]] = $message; } return; } } } protected function _get_error_message($rule, $field) { if (isset($this->_field_data[$field]["errors"][$rule])) { return $this->_field_data[$field]["errors"][$rule]; } elseif (isset($this->_error_messages[$rule])) { return $this->_error_messages[$rule]; } elseif (FALSE !== ($line = $this->CI->lang->line("form_validation_" . $rule))) { return $line; } return $this->CI->lang->line("form_validation_error_message_not_set") . "(" . $rule . ")"; } protected function _translate_fieldname($fieldname) { if (sscanf($fieldname, "lang:%s", $line) === 1 && FALSE === ($fieldname = $this->CI->lang->line($line, FALSE))) { return $line; } return $fieldname; } protected function _build_error_msg($line, $field = '', $param = '') { if (strpos($line, "%s") !== FALSE) { return sprintf($line, $field, $param); } return str_replace(array("{field}", "{param}"), array($field, $param), $line); } public function has_rule($field) { return isset($this->_field_data[$field]); } public function set_value($field = '', $default = '') { if (!isset($this->_field_data[$field], $this->_field_data[$field]["postdata"])) { return $default; } if (is_array($this->_field_data[$field]["postdata"])) { return array_shift($this->_field_data[$field]["postdata"]); } return $this->_field_data[$field]["postdata"]; } public function set_select($field = '', $value = '', $default = FALSE) { if (!isset($this->_field_data[$field], $this->_field_data[$field]["postdata"])) { return $default === TRUE && count($this->_field_data) === 0 ? " selected="selected"" : ''; } $field = $this->_field_data[$field]["postdata"]; $value = (string) $value; if (is_array($field)) { foreach ($field as &$v) { if ($value === $v) { return " selected="selected""; } } return ''; } elseif ($field === '' or $value === '' or $field !== $value) { return ''; } return " selected="selected""; } public function set_radio($field = '', $value = '', $default = FALSE) { if (!isset($this->_field_data[$field], $this->_field_data[$field]["postdata"])) { return $default === TRUE && count($this->_field_data) === 0 ? " checked="checked"" : ''; } $field = $this->_field_data[$field]["postdata"]; $value = (string) $value; if (is_array($field)) { foreach ($field as &$v) { if ($value === $v) { return " checked="checked""; } } return ''; } elseif ($field === '' or $value === '' or $field !== $value) { return ''; } return " checked="checked""; } public function set_checkbox($field = '', $value = '', $default = FALSE) { return $this->set_radio($field, $value, $default); } public function required($str) { return is_array($str) ? empty($str) === FALSE : trim((string) $str) !== ''; } public function regex_match($str, $regex) { return (bool) preg_match($regex, $str); } public function matches($str, $field) { return isset($this->_field_data[$field], $this->_field_data[$field]["postdata"]) ? $str === $this->_field_data[$field]["postdata"] : FALSE; } public function differs($str, $field) { return !(isset($this->_field_data[$field]) && $this->_field_data[$field]["postdata"] === $str); } public function is_unique($str, $field) { sscanf($field, "%[^.].%[^.]", $table, $field); return isset($this->CI->db) ? $this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0 : FALSE; } public function min_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return $val <= mb_strlen($str); } public function max_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return $val >= mb_strlen($str); } public function exact_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return mb_strlen($str) === (int) $val; } public function valid_url($str) { if (empty($str)) { return FALSE; } elseif (preg_match("/^(?:([^:]*)\:)?\/\/(.+)$/", $str, $matches)) { if (empty($matches[2])) { return FALSE; } elseif (!in_array(strtolower($matches[1]), array("http", "https"), TRUE)) { return FALSE; } $str = $matches[2]; } if (ctype_digit($str)) { return FALSE; } if (preg_match("/^\[([^\]]+)\]/", $str, $matches) && !is_php("7") && filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { $str = "ipv6.host" . substr($str, strlen($matches[1]) + 2); } return filter_var("http://" . $str, FILTER_VALIDATE_URL) !== FALSE; } public function valid_email($str) { if (function_exists("idn_to_ascii") && preg_match("#\A([^@]+)@(.+)\z#", $str, $matches)) { $domain = defined("INTL_IDNA_VARIANT_UTS46") ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($matches[2]); if ($domain !== FALSE) { $str = $matches[1] . "@" . $domain; } } return (bool) filter_var($str, FILTER_VALIDATE_EMAIL); } public function valid_emails($str) { if (strpos($str, ",") === FALSE) { return $this->valid_email(trim($str)); } foreach (explode(",", $str) as $email) { if (trim($email) !== '' && $this->valid_email(trim($email)) === FALSE) { return FALSE; } } return TRUE; } public function valid_ip($ip, $which = '') { return $this->CI->input->valid_ip($ip, $which); } public function valid_mac($mac) { if (!is_php("5.5")) { if (preg_match("#\A[0-9a-f]{2}(?<delimiter>[:-])([0-9a-f]{2}(?P=delimiter)){4}[0-9a-f]{2}\z#i", $mac)) { return TRUE; } return (bool) preg_match("#((\A|\.)[0-9a-f]{4}){3}\z#i", $mac); } return (bool) filter_var($mac, FILTER_VALIDATE_MAC); } public function alpha($str) { return ctype_alpha($str); } public function alpha_numeric($str) { return ctype_alnum((string) $str); } public function alpha_numeric_spaces($str) { return (bool) preg_match("/^[A-Z0-9 ]+$/i", $str); } public function alpha_dash($str) { return (bool) preg_match("/^[a-z0-9_-]+$/i", $str); } public function numeric($str) { return (bool) preg_match("/^[\-+]?[0-9]*\.?[0-9]+$/", $str); } public function integer($str) { return (bool) preg_match("/^[\-+]?[0-9]+$/", $str); } public function decimal($str) { return (bool) preg_match("/^[\-+]?[0-9]+\.[0-9]+$/", $str); } public function greater_than($str, $min) { return is_numeric($str) ? $str > $min : FALSE; } public function greater_than_equal_to($str, $min) { return is_numeric($str) ? $str >= $min : FALSE; } public function less_than($str, $max) { return is_numeric($str) ? $str < $max : FALSE; } public function less_than_equal_to($str, $max) { return is_numeric($str) ? $str <= $max : FALSE; } public function in_list($value, $list) { return in_array($value, explode(",", $list), TRUE); } public function is_natural($str) { return ctype_digit((string) $str); } public function is_natural_no_zero($str) { return $str != 0 && ctype_digit((string) $str); } public function valid_base64($str) { return base64_encode(base64_decode($str)) === $str; } public function prep_url($str = '') { if ($str !== '' && stripos($str, "http://") !== 0 && stripos($str, "https://") !== 0) { return "http://" . $str; } return $str; } public function strip_image_tags($str) { return $this->CI->security->strip_image_tags($str); } public function encode_php_tags($str) { return str_replace(array("<?", "?>"), array("&lt;?", "?&gt;"), $str); } public function reset_validation() { $this->_field_data = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; return $this; } } ?>

Did this file decode correctly?

Original Code

<?php
 defined("\102\101\x53\x45\120\101\124\110") or die("\x4e\x6f\x20\x64\x69\x72\x65\x63\x74\x20\x73\143\162\151\160\x74\x20\141\x63\143\145\x73\163\x20\141\x6c\154\157\167\x65\144"); class CI_Form_validation { protected $CI; protected $_field_data = array(); protected $_config_rules = array(); protected $_error_array = array(); protected $_error_messages = array(); protected $_error_prefix = "\74\160\76"; protected $_error_suffix = "\74\x2f\160\x3e"; protected $error_string = ''; public $validation_data = array(); public function __construct($rules = array()) { $this->CI =& get_instance(); if (isset($rules["\x65\x72\162\157\x72\137\x70\x72\x65\x66\151\x78"])) { $this->_error_prefix = $rules["\x65\x72\x72\x6f\x72\137\160\x72\145\x66\151\x78"]; unset($rules["\145\162\162\157\162\x5f\x70\x72\x65\146\151\170"]); } if (isset($rules["\x65\x72\x72\x6f\x72\x5f\163\165\x66\x66\151\170"])) { $this->_error_suffix = $rules["\145\162\x72\157\162\x5f\x73\165\146\146\x69\x78"]; unset($rules["\145\162\162\157\162\137\163\165\146\146\x69\x78"]); } $this->_config_rules = $rules; $this->CI->load->helper("\x66\x6f\x72\x6d"); log_message("\151\156\146\x6f", "\106\157\x72\x6d\x20\x56\141\x6c\151\x64\141\164\151\157\156\40\103\154\141\x73\x73\x20\x49\156\x69\x74\x69\141\154\x69\172\x65\x64"); } public function set_rules($field, $label = null, $rules = null, $errors = array()) { if ($this->CI->input->method() !== "\x70\x6f\163\x74" && empty($this->validation_data)) { return $this; } if (is_array($field)) { foreach ($field as $row) { if (!isset($row["\146\x69\x65\154\x64"], $row["\x72\x75\x6c\x65\x73"])) { continue; } $label = isset($row["\154\x61\142\x65\x6c"]) ? $row["\154\141\142\x65\154"] : $row["\x66\151\x65\x6c\144"]; $errors = isset($row["\145\x72\162\x6f\162\x73"]) && is_array($row["\145\162\162\x6f\x72\x73"]) ? $row["\145\x72\162\x6f\x72\163"] : array(); $this->set_rules($row["\x66\x69\145\154\x64"], $label, $row["\162\165\154\x65\163"], $errors); } return $this; } elseif (!isset($rules)) { throw new BadMethodCallException("\106\157\162\x6d\137\166\141\154\x69\144\x61\x74\x69\157\156\x3a\40\x73\145\x74\x5f\162\165\x6c\145\163\50\51\x20\x63\x61\x6c\154\x65\144\40\167\151\x74\150\x6f\x75\164\x20\141\40\44\162\165\154\145\163\x20\160\141\162\x61\155\x65\x74\145\162"); } if (!is_string($field) or $field === '' or empty($rules)) { throw new RuntimeException("\106\157\x72\x6d\x5f\x76\x61\x6c\151\144\141\x74\x69\x6f\x6e\x3a\40\163\145\164\137\162\165\x6c\x65\163\x28\51\x20\x63\x61\x6c\x6c\x65\x64\40\167\x69\x74\x68\x20\141\156\x20\x65\x6d\x70\x74\171\x20\44\162\x75\x6c\x65\x73\x20\160\x61\162\x61\155\145\164\145\162"); } elseif (!is_array($rules)) { if (!is_string($rules)) { throw new InvalidArgumentException("\106\157\162\155\137\x76\141\x6c\x69\144\141\164\151\x6f\x6e\x3a\40\x73\145\164\137\x72\x75\x6c\x65\163\x28\51\x20\145\x78\x70\x65\143\164\x20\x24\x72\165\154\145\x73\x20\164\x6f\40\142\145\x20\163\x74\x72\151\x6e\147\x20\x6f\x72\40\x61\162\162\x61\171\73\x20" . gettype($rules) . "\40\x67\x69\166\x65\156"); } $rules = preg_split("\x2f\x5c\174\50\x3f\x21\133\x5e\134\133\135\52\x5c\x5d\51\57", $rules); } $label = $label === '' ? $field : $label; $indexes = array(); if (($is_array = (bool) preg_match_all("\x2f\134\133\x28\56\52\77\51\x5c\x5d\57", $field, $matches)) === TRUE) { sscanf($field, "\x25\x5b\136\133\x5d\x5b", $indexes[0]); for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { if ($matches[1][$i] !== '') { $indexes[] = $matches[1][$i]; } } } $this->_field_data[$field] = array("\146\151\145\154\x64" => $field, "\154\x61\x62\x65\154" => $label, "\x72\165\x6c\145\x73" => $rules, "\x65\x72\162\x6f\162\163" => $errors, "\x69\x73\137\x61\x72\x72\x61\171" => $is_array, "\153\x65\171\163" => $indexes, "\160\157\x73\164\x64\x61\x74\141" => NULL, "\x65\162\162\x6f\x72" => ''); return $this; } public function set_data(array $data) { if (!empty($data)) { $this->validation_data = $data; } return $this; } public function set_message($lang, $val = '') { if (!is_array($lang)) { $lang = array($lang => $val); } $this->_error_messages = array_merge($this->_error_messages, $lang); return $this; } public function set_error_delimiters($prefix = "\74\160\x3e", $suffix = "\x3c\x2f\x70\76") { $this->_error_prefix = $prefix; $this->_error_suffix = $suffix; return $this; } public function error($field, $prefix = '', $suffix = '') { if (empty($this->_field_data[$field]["\145\162\x72\x6f\162"])) { return ''; } if ($prefix === '') { $prefix = $this->_error_prefix; } if ($suffix === '') { $suffix = $this->_error_suffix; } return $prefix . $this->_field_data[$field]["\x65\162\x72\157\162"] . $suffix; } public function error_array() { return $this->_error_array; } public function error_string($prefix = '', $suffix = '') { if (count($this->_error_array) === 0) { return ''; } if ($prefix === '') { $prefix = $this->_error_prefix; } if ($suffix === '') { $suffix = $this->_error_suffix; } $str = ''; foreach ($this->_error_array as $val) { if ($val !== '') { $str .= $prefix . $val . $suffix . "\12"; } } return $str; } public function run($config = NULL, &$data = NULL) { $validation_array = empty($this->validation_data) ? $_POST : $this->validation_data; if (count($this->_field_data) === 0) { if (empty($this->_config_rules)) { return FALSE; } if (empty($config)) { $config = trim($this->CI->uri->ruri_string(), "\57"); isset($this->_config_rules[$config]) or $config = $this->CI->router->class . "\57" . $this->CI->router->method; } $this->set_rules(isset($this->_config_rules[$config]) ? $this->_config_rules[$config] : $this->_config_rules); if (count($this->_field_data) === 0) { log_message("\x64\145\x62\165\147", "\x55\x6e\x61\x62\x6c\x65\x20\164\x6f\x20\x66\x69\x6e\144\40\x76\141\154\x69\x64\x61\x74\151\x6f\156\x20\x72\x75\x6c\145\x73"); return FALSE; } } $this->CI->lang->load("\146\157\x72\155\137\x76\x61\154\151\144\x61\164\151\x6f\156"); foreach ($this->_field_data as $field => &$row) { if ($row["\151\163\137\x61\162\162\x61\171"] === TRUE) { $this->_field_data[$field]["\160\x6f\x73\164\144\141\164\141"] = $this->_reduce_array($validation_array, $row["\153\145\171\163"]); } elseif (isset($validation_array[$field])) { $this->_field_data[$field]["\160\x6f\x73\x74\144\141\164\141"] = $validation_array[$field]; } } foreach ($this->_field_data as $field => &$row) { if (empty($row["\x72\x75\x6c\x65\163"])) { continue; } $this->_execute($row, $row["\162\165\154\145\163"], $row["\160\x6f\163\x74\x64\x61\x74\141"]); } if (!empty($this->_error_array)) { return FALSE; } if (func_num_args() >= 2) { $data = empty($this->validation_data) ? $_POST : $this->validation_data; $this->_reset_data_array($data); return TRUE; } empty($this->validation_data) && $this->_reset_data_array($_POST); return TRUE; } protected function _prepare_rules($rules) { $new_rules = array(); $callbacks = array(); foreach ($rules as &$rule) { if ($rule === "\x72\x65\x71\165\x69\162\145\x64") { array_unshift($new_rules, "\162\145\161\x75\x69\x72\x65\x64"); } elseif ($rule === "\151\163\163\x65\164" && (empty($new_rules) or $new_rules[0] !== "\162\145\161\x75\151\162\x65\x64")) { array_unshift($new_rules, "\x69\x73\163\x65\164"); } elseif (is_string($rule) && strncmp("\x63\141\154\x6c\142\141\x63\x6b\x5f", $rule, 9) === 0) { $callbacks[] = $rule; } elseif (is_callable($rule)) { $callbacks[] = $rule; } elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1])) { $callbacks[] = $rule; } else { $new_rules[] = $rule; } } return array_merge($callbacks, $new_rules); } protected function _reduce_array($array, $keys, $i = 0) { if (is_array($array) && isset($keys[$i])) { return isset($array[$keys[$i]]) ? $this->_reduce_array($array[$keys[$i]], $keys, $i + 1) : NULL; } return $array === '' ? NULL : $array; } protected function _reset_data_array(&$data) { foreach ($this->_field_data as $field => $row) { if ($row["\x70\x6f\163\164\144\141\x74\141"] !== NULL) { if ($row["\x69\x73\x5f\141\162\162\x61\x79"] === FALSE) { isset($data[$field]) && ($data[$field] = is_array($row["\x70\x6f\x73\x74\x64\141\164\141"]) ? NULL : $row["\x70\157\163\164\x64\141\164\141"]); } else { $data_ref =& $data; if (count($row["\153\145\171\x73"]) === 1) { $data_ref =& $data[current($row["\x6b\x65\x79\163"])]; } else { foreach ($row["\x6b\145\x79\163"] as $val) { $data_ref =& $data_ref[$val]; } } $data_ref = $row["\x70\x6f\163\x74\144\x61\x74\141"]; } } } } protected function _execute($row, $rules, $postdata = NULL, $cycles = 0) { $allow_arrays = in_array("\x69\x73\x5f\141\x72\162\141\171", $rules, TRUE); if ($allow_arrays === FALSE && is_array($postdata) && !empty($postdata)) { foreach ($postdata as $key => $val) { $this->_execute($row, $rules, $val, $key); } return; } $rules = $this->_prepare_rules($rules); foreach ($rules as $rule) { $_in_array = FALSE; if ($row["\x69\163\137\x61\162\162\x61\x79"] === TRUE && is_array($this->_field_data[$row["\146\151\145\x6c\x64"]]["\160\157\x73\164\144\141\x74\141"])) { if (!isset($this->_field_data[$row["\146\x69\x65\x6c\144"]]["\160\157\x73\x74\x64\141\x74\x61"][$cycles])) { continue; } $postdata = $this->_field_data[$row["\146\151\x65\x6c\x64"]]["\160\x6f\x73\164\x64\x61\x74\x61"][$cycles]; $_in_array = TRUE; } elseif ($allow_arrays === FALSE && is_array($this->_field_data[$row["\146\151\145\x6c\x64"]]["\160\157\x73\x74\x64\x61\164\141"])) { $postdata = NULL; } else { $postdata = $this->_field_data[$row["\x66\x69\x65\x6c\144"]]["\160\157\x73\x74\144\x61\164\141"]; } $callback = $callable = FALSE; if (is_string($rule)) { if (strpos($rule, "\143\141\154\x6c\x62\x61\x63\153\x5f") === 0) { $rule = substr($rule, 9); $callback = TRUE; } } elseif (is_callable($rule)) { $callable = TRUE; } elseif (is_array($rule) && isset($rule[0], $rule[1]) && is_callable($rule[1])) { $callable = $rule[0]; $rule = $rule[1]; } $param = FALSE; if (!$callable && preg_match("\x2f\50\x2e\52\77\x29\x5c\x5b\50\56\52\51\134\x5d\57", $rule, $match)) { $rule = $match[1]; $param = $match[2]; } if (($postdata === NULL or $allow_arrays === FALSE && $postdata === '') && $callback === FALSE && $callable === FALSE && !in_array($rule, array("\162\145\x71\x75\x69\162\x65\144", "\151\163\163\x65\x74", "\155\141\x74\x63\150\145\163"), TRUE)) { continue; } if ($callback or $callable !== FALSE) { if ($callback) { if (!method_exists($this->CI, $rule)) { log_message("\144\x65\x62\x75\x67", "\x55\x6e\x61\142\x6c\x65\x20\164\x6f\40\x66\151\156\144\x20\x63\141\x6c\x6c\x62\141\x63\x6b\40\x76\x61\x6c\151\x64\x61\x74\x69\157\156\40\162\x75\154\x65\72\40" . $rule); $result = FALSE; } else { $result = $this->CI->{$rule}($postdata, $param); } } else { $result = is_array($rule) ? $rule[0]->{$rule[1]}($postdata) : $rule($postdata); if ($callable !== FALSE) { $rule = $callable; } } if ($_in_array === TRUE) { $this->_field_data[$row["\x66\151\145\154\x64"]]["\160\x6f\163\164\x64\141\164\141"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["\146\x69\145\154\144"]]["\x70\x6f\x73\164\144\141\164\x61"] = is_bool($result) ? $postdata : $result; } } elseif (!method_exists($this, $rule)) { if (function_exists($rule)) { $result = $param !== FALSE ? $rule($postdata, $param) : $rule($postdata); if ($_in_array === TRUE) { $this->_field_data[$row["\146\x69\x65\154\x64"]]["\x70\x6f\163\x74\x64\141\x74\141"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["\146\151\x65\154\144"]]["\x70\x6f\x73\x74\144\141\164\x61"] = is_bool($result) ? $postdata : $result; } } else { log_message("\144\x65\x62\165\x67", "\125\x6e\141\142\154\x65\x20\164\157\40\146\x69\x6e\144\x20\x76\141\154\x69\x64\x61\164\151\x6f\x6e\40\x72\x75\154\x65\72\x20" . $rule); $result = FALSE; } } else { $result = $this->{$rule}($postdata, $param); if ($_in_array === TRUE) { $this->_field_data[$row["\146\x69\x65\154\x64"]]["\x70\x6f\163\164\x64\x61\x74\141"][$cycles] = is_bool($result) ? $postdata : $result; } else { $this->_field_data[$row["\146\151\x65\154\144"]]["\160\157\163\164\x64\141\x74\x61"] = is_bool($result) ? $postdata : $result; } } if ($result === FALSE) { if (!is_string($rule)) { $line = $this->CI->lang->line("\146\x6f\162\x6d\137\x76\x61\x6c\151\144\141\164\x69\x6f\156\137\145\x72\x72\157\x72\137\x6d\x65\x73\163\x61\147\145\x5f\156\157\x74\137\163\x65\164") . "\x28\x41\156\157\x6e\x79\155\157\165\163\40\146\x75\156\x63\164\x69\157\x6e\x29"; } else { $line = $this->_get_error_message($rule, $row["\x66\x69\x65\154\144"]); } if (isset($this->_field_data[$param], $this->_field_data[$param]["\x6c\x61\x62\145\x6c"])) { $param = $this->_translate_fieldname($this->_field_data[$param]["\154\141\x62\x65\x6c"]); } $message = $this->_build_error_msg($line, $this->_translate_fieldname($row["\154\141\142\145\x6c"]), $param); $this->_field_data[$row["\x66\151\x65\x6c\144"]]["\x65\162\162\x6f\x72"] = $message; if (!isset($this->_error_array[$row["\x66\x69\x65\154\144"]])) { $this->_error_array[$row["\x66\x69\145\x6c\x64"]] = $message; } return; } } } protected function _get_error_message($rule, $field) { if (isset($this->_field_data[$field]["\x65\162\162\x6f\x72\x73"][$rule])) { return $this->_field_data[$field]["\x65\x72\x72\157\162\163"][$rule]; } elseif (isset($this->_error_messages[$rule])) { return $this->_error_messages[$rule]; } elseif (FALSE !== ($line = $this->CI->lang->line("\146\157\162\x6d\x5f\166\x61\154\151\x64\141\164\151\x6f\x6e\137" . $rule))) { return $line; } return $this->CI->lang->line("\x66\x6f\162\x6d\x5f\x76\x61\154\x69\x64\x61\164\x69\157\156\x5f\x65\162\162\157\162\x5f\155\x65\x73\163\141\147\x65\137\156\x6f\164\x5f\163\x65\x74") . "\50" . $rule . "\51"; } protected function _translate_fieldname($fieldname) { if (sscanf($fieldname, "\154\x61\x6e\x67\x3a\x25\163", $line) === 1 && FALSE === ($fieldname = $this->CI->lang->line($line, FALSE))) { return $line; } return $fieldname; } protected function _build_error_msg($line, $field = '', $param = '') { if (strpos($line, "\x25\163") !== FALSE) { return sprintf($line, $field, $param); } return str_replace(array("\x7b\x66\x69\x65\154\144\x7d", "\x7b\x70\x61\x72\141\x6d\x7d"), array($field, $param), $line); } public function has_rule($field) { return isset($this->_field_data[$field]); } public function set_value($field = '', $default = '') { if (!isset($this->_field_data[$field], $this->_field_data[$field]["\160\x6f\x73\164\x64\x61\x74\x61"])) { return $default; } if (is_array($this->_field_data[$field]["\160\x6f\163\x74\x64\x61\164\x61"])) { return array_shift($this->_field_data[$field]["\x70\x6f\x73\x74\144\141\x74\x61"]); } return $this->_field_data[$field]["\x70\x6f\163\x74\144\x61\164\x61"]; } public function set_select($field = '', $value = '', $default = FALSE) { if (!isset($this->_field_data[$field], $this->_field_data[$field]["\x70\157\163\x74\144\141\x74\x61"])) { return $default === TRUE && count($this->_field_data) === 0 ? "\x20\x73\145\x6c\145\143\x74\145\144\x3d\x22\x73\145\154\x65\x63\164\145\x64\42" : ''; } $field = $this->_field_data[$field]["\x70\157\x73\164\x64\x61\x74\x61"]; $value = (string) $value; if (is_array($field)) { foreach ($field as &$v) { if ($value === $v) { return "\x20\163\x65\x6c\145\143\x74\x65\x64\x3d\42\163\145\154\x65\143\164\x65\x64\42"; } } return ''; } elseif ($field === '' or $value === '' or $field !== $value) { return ''; } return "\x20\x73\145\x6c\145\x63\x74\x65\144\x3d\x22\163\145\154\145\143\164\x65\144\42"; } public function set_radio($field = '', $value = '', $default = FALSE) { if (!isset($this->_field_data[$field], $this->_field_data[$field]["\160\157\163\x74\x64\x61\164\x61"])) { return $default === TRUE && count($this->_field_data) === 0 ? "\x20\x63\150\x65\x63\x6b\145\x64\x3d\x22\143\x68\x65\x63\x6b\x65\144\x22" : ''; } $field = $this->_field_data[$field]["\x70\157\163\164\144\x61\x74\141"]; $value = (string) $value; if (is_array($field)) { foreach ($field as &$v) { if ($value === $v) { return "\x20\143\x68\x65\143\153\145\144\x3d\x22\x63\x68\x65\143\x6b\x65\x64\42"; } } return ''; } elseif ($field === '' or $value === '' or $field !== $value) { return ''; } return "\x20\143\x68\145\x63\153\145\x64\x3d\x22\x63\x68\145\143\153\145\144\x22"; } public function set_checkbox($field = '', $value = '', $default = FALSE) { return $this->set_radio($field, $value, $default); } public function required($str) { return is_array($str) ? empty($str) === FALSE : trim((string) $str) !== ''; } public function regex_match($str, $regex) { return (bool) preg_match($regex, $str); } public function matches($str, $field) { return isset($this->_field_data[$field], $this->_field_data[$field]["\x70\x6f\163\164\x64\141\x74\x61"]) ? $str === $this->_field_data[$field]["\x70\x6f\163\164\144\141\164\141"] : FALSE; } public function differs($str, $field) { return !(isset($this->_field_data[$field]) && $this->_field_data[$field]["\x70\157\163\x74\144\141\164\141"] === $str); } public function is_unique($str, $field) { sscanf($field, "\x25\x5b\x5e\x2e\135\x2e\45\x5b\x5e\x2e\x5d", $table, $field); return isset($this->CI->db) ? $this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0 : FALSE; } public function min_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return $val <= mb_strlen($str); } public function max_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return $val >= mb_strlen($str); } public function exact_length($str, $val) { if (!is_numeric($val)) { return FALSE; } return mb_strlen($str) === (int) $val; } public function valid_url($str) { if (empty($str)) { return FALSE; } elseif (preg_match("\57\x5e\50\x3f\72\x28\x5b\136\72\135\x2a\51\x5c\x3a\51\77\x5c\57\x5c\x2f\x28\x2e\x2b\51\x24\57", $str, $matches)) { if (empty($matches[2])) { return FALSE; } elseif (!in_array(strtolower($matches[1]), array("\x68\164\164\x70", "\x68\164\164\160\163"), TRUE)) { return FALSE; } $str = $matches[2]; } if (ctype_digit($str)) { return FALSE; } if (preg_match("\57\x5e\x5c\x5b\x28\133\x5e\x5c\135\x5d\x2b\x29\134\x5d\x2f", $str, $matches) && !is_php("\x37") && filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) { $str = "\151\160\x76\x36\x2e\150\157\x73\x74" . substr($str, strlen($matches[1]) + 2); } return filter_var("\150\164\164\x70\x3a\x2f\57" . $str, FILTER_VALIDATE_URL) !== FALSE; } public function valid_email($str) { if (function_exists("\x69\x64\156\x5f\164\157\137\141\163\x63\151\x69") && preg_match("\x23\134\x41\x28\133\136\100\135\53\51\x40\x28\56\x2b\x29\134\172\x23", $str, $matches)) { $domain = defined("\111\116\x54\114\x5f\x49\x44\116\101\137\126\101\x52\111\101\x4e\x54\x5f\x55\x54\x53\x34\66") ? idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46) : idn_to_ascii($matches[2]); if ($domain !== FALSE) { $str = $matches[1] . "\100" . $domain; } } return (bool) filter_var($str, FILTER_VALIDATE_EMAIL); } public function valid_emails($str) { if (strpos($str, "\54") === FALSE) { return $this->valid_email(trim($str)); } foreach (explode("\54", $str) as $email) { if (trim($email) !== '' && $this->valid_email(trim($email)) === FALSE) { return FALSE; } } return TRUE; } public function valid_ip($ip, $which = '') { return $this->CI->input->valid_ip($ip, $which); } public function valid_mac($mac) { if (!is_php("\65\56\x35")) { if (preg_match("\x23\134\x41\x5b\x30\55\71\141\55\x66\135\173\x32\x7d\x28\x3f\x3c\144\145\x6c\x69\x6d\x69\x74\145\x72\x3e\133\x3a\55\135\x29\50\x5b\60\55\71\x61\55\146\135\173\x32\x7d\x28\x3f\x50\75\144\145\154\x69\x6d\151\164\145\x72\51\51\173\64\175\x5b\x30\x2d\x39\141\x2d\x66\135\x7b\62\175\134\x7a\43\x69", $mac)) { return TRUE; } return (bool) preg_match("\43\x28\x28\x5c\101\x7c\134\56\x29\x5b\60\55\x39\x61\x2d\146\x5d\x7b\64\175\x29\x7b\63\x7d\x5c\x7a\x23\151", $mac); } return (bool) filter_var($mac, FILTER_VALIDATE_MAC); } public function alpha($str) { return ctype_alpha($str); } public function alpha_numeric($str) { return ctype_alnum((string) $str); } public function alpha_numeric_spaces($str) { return (bool) preg_match("\57\x5e\x5b\x41\x2d\x5a\x30\x2d\x39\40\x5d\x2b\x24\x2f\151", $str); } public function alpha_dash($str) { return (bool) preg_match("\57\x5e\133\141\55\172\x30\55\71\x5f\x2d\135\x2b\x24\57\151", $str); } public function numeric($str) { return (bool) preg_match("\57\136\x5b\134\55\x2b\x5d\77\133\x30\x2d\x39\x5d\52\134\56\x3f\133\60\55\71\x5d\53\44\57", $str); } public function integer($str) { return (bool) preg_match("\x2f\x5e\x5b\134\55\53\x5d\77\x5b\x30\x2d\71\x5d\53\44\x2f", $str); } public function decimal($str) { return (bool) preg_match("\x2f\136\133\134\x2d\53\135\77\133\x30\55\x39\135\x2b\x5c\x2e\x5b\x30\x2d\71\135\53\44\x2f", $str); } public function greater_than($str, $min) { return is_numeric($str) ? $str > $min : FALSE; } public function greater_than_equal_to($str, $min) { return is_numeric($str) ? $str >= $min : FALSE; } public function less_than($str, $max) { return is_numeric($str) ? $str < $max : FALSE; } public function less_than_equal_to($str, $max) { return is_numeric($str) ? $str <= $max : FALSE; } public function in_list($value, $list) { return in_array($value, explode("\54", $list), TRUE); } public function is_natural($str) { return ctype_digit((string) $str); } public function is_natural_no_zero($str) { return $str != 0 && ctype_digit((string) $str); } public function valid_base64($str) { return base64_encode(base64_decode($str)) === $str; } public function prep_url($str = '') { if ($str !== '' && stripos($str, "\150\x74\164\160\x3a\57\57") !== 0 && stripos($str, "\150\x74\164\160\163\x3a\57\x2f") !== 0) { return "\150\x74\x74\x70\x3a\x2f\x2f" . $str; } return $str; } public function strip_image_tags($str) { return $this->CI->security->strip_image_tags($str); } public function encode_php_tags($str) { return str_replace(array("\x3c\x3f", "\77\76"), array("\x26\x6c\164\73\x3f", "\x3f\46\x67\164\x3b"), $str); } public function reset_validation() { $this->_field_data = array(); $this->_error_array = array(); $this->_error_messages = array(); $this->error_string = ''; return $this; } }

Function Calls

None

Variables

None

Stats

MD5 533684acdca7f1da1c15adda415a2f17
Eval Count 0
Decode Time 121 ms