?=-` '; if ($unicode_chars) { $len = strlen($chars) / 10; for ($n = 0; $n < $len; $n++) $chars .= mb_convert_encoding('&#' . random_int(0x2600, 0x26FF) . ';', 'UTF-8', 'HTML-ENTITIES'); } $chars = preg_split('//u', $chars, -1, PREG_SPLIT_NO_EMPTY); $ch = []; // fill up $ch until we reach $length while (count($ch) < $length) { $n = $length - count($ch); $keys = array_rand($chars, $n > (is_countable($chars) ? count($chars) : 0) ? count($chars) : $n); if ($n == 1) { $ch[] = $chars[$keys]; break; } shuffle($keys); foreach ($keys as $key) $ch[] = $chars[$key]; } $chars = $ch; return implode('', $chars); } public static function make_confusing($string) { $chars = preg_split('//u', (string) $string, -1, PREG_SPLIT_NO_EMPTY); foreach ($chars as &$c) { if (random_int(0, 3) != 0) $c = utf8tohtml($c); else $c = mb_encode_numericentity((string) $c, [0, 0xffff, 0, 0xffff], 'UTF-8'); } return implode('', $chars); } public function __construct(array $salt = []) { global $config; if (!empty($salt)) { // create a salted hash of the "extra salt" $this->salt = implode(':', $salt); } else { $this->salt = ''; } shuffle($config['spam']['hidden_input_names']); $input_count = random_int($config['spam']['hidden_inputs_min'], $config['spam']['hidden_inputs_max']); $hidden_input_names_x = 0; for ($x = 0; $x < $input_count ; $x++) { if ($hidden_input_names_x === false || random_int(0, 2) == 0) { // Use an obscure name $name = static::randomString(random_int(10, 40), false, false, $config['spam']['unicode']); } else { // Use a pre-defined confusing name $name = $config['spam']['hidden_input_names'][$hidden_input_names_x++]; if ($hidden_input_names_x >= (is_countable($config['spam']['hidden_input_names']) ? count($config['spam']['hidden_input_names']) : 0)) $hidden_input_names_x = false; } if (random_int(0, 2) == 0) { // Value must be null $this->inputs[$name] = ''; } elseif (random_int(0, 4) == 0) { // Numeric value $this->inputs[$name] = (string)random_int(0, 100000); } else { // Obscure value $this->inputs[$name] = static::randomString(random_int(5, 100), true, true, $config['spam']['unicode']); } } } public static function space() { if (random_int(0, 3) != 0) return ' '; return str_repeat(' ', random_int(1, 3)); } public function html($count = false) { global $config; $elements = ['', '', '', '', '', '', '', '
', '
', '', '']; $html = ''; if ($count === false) { $count = random_int(1, (int)abs((is_countable($this->inputs) ? count($this->inputs) : 0) / 15) + 1); } if ($count === true) { // all elements $inputs = array_slice($this->inputs, $this->index); } else { $inputs = array_slice($this->inputs, $this->index, $count); } $this->index += count($inputs); foreach ($inputs as $name => $value) { $element = false; while (!$element) { $element = $elements[array_rand($elements)]; $element = str_replace(' ', self::space(), $element); if (random_int(0, 5) == 0) $element = str_replace('>', self::space() . '>', $element); if (str_contains($element, 'textarea') && $value == '') { // There have been some issues with mobile web browsers and empty