$val) { if (is_array($val) || (!empty($keysOnly) && !in_array($key, $keysOnly))) { continue; } if (is_string($val)) { $value[$key] = static::escapeValue($val, $type); } } return $value; } return $value; } /** * Эскейпим строку * @param string $value данные * @param string $type тип: 'html', 'js' ('javascript') * @return string */ protected static function escapeValue(string $value, string $type = 'html'): string { switch ($type) { case 'html': return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); case 'js': case 'javascript': # escape quotes and backslashes, newlines, etc. return strtr($value, [ '\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', ' '<\/', ]); } return $value; } /** * Формирование простых полей ввода * @param string $tag HTML тег, допустимые: input, hidden, text, number, email, checkbox, radio, textarea, button * @param string|string[]|mixed $value значение * @param array $attributes атрибуты * @return string * @throws Exception */ public static function input(string $tag, $value, array $attributes = []): string { if (in_array($tag, ['hidden','text','number','email','checkbox','radio'], true)) { $attributes['type'] = $tag; $tag = 'input'; } if ($tag === 'input') { $attributes['value'] = $value; return '<' . $tag . static::attributes($attributes) . ' />'; } elseif ($tag === 'textarea' || $tag === 'button') { $value = static::escape($value); if (is_array($value)) { $value = join(' ', $value); } return '<' . $tag . static::attributes($attributes) . '>' . $value . ''; } throw new Exception(_t('html', '[class]: Unsupported HTML tag "[tag]"', [ 'class' => static::class, 'tag' => strval($tag), ])); } /** * Формирование