aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/src/FunctionHandler/HtmlBase.php
blob: 99f8e6c77fb6f7d95fa3200161291e5c3e79688d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php

namespace Smarty\FunctionHandler;

class HtmlBase extends Base {

	/**
	 * @param $inputType
	 * @param      $name
	 * @param      $value
	 * @param      $output
	 * @param $ismultiselect
	 * @param      $selected
	 * @param      $extra
	 * @param      $separator
	 * @param      $labels
	 * @param      $label_ids
	 * @param bool $escape
	 *
	 * @return string
	 */
	protected function getHtmlForInput(
		$inputType,
		$name,
		$value,
		$output,
		$ismultiselect,
		$selected,
		$extra,
		$separator,
		$labels,
		$label_ids,
		$escape = true
	) {

		$_output = '';
		if (is_object($value)) {
			if (method_exists($value, '__toString')) {
				$value = (string)$value->__toString();
			} else {
				trigger_error(
					'value is an object of class \'' . get_class($value) .
					'\' without __toString() method',
					E_USER_NOTICE
				);
				return '';
			}
		} else {
			$value = (string)$value;
		}
		if (is_object($output)) {
			if (method_exists($output, '__toString')) {
				$output = (string)$output->__toString();
			} else {
				trigger_error(
					'output is an object of class \'' . get_class($output) .
					'\' without __toString() method',
					E_USER_NOTICE
				);
				return '';
			}
		} else {
			$output = (string)$output;
		}
		if ($labels) {
			if ($label_ids) {
				$_id = smarty_function_escape_special_chars(
					preg_replace(
						'![^\w\-\.]!' . \Smarty\Smarty::$_UTF8_MODIFIER,
						'_',
						$name . '_' . $value
					)
				);
				$_output .= '<label for="' . $_id . '">';
			} else {
				$_output .= '<label>';
			}
		}
		$name = smarty_function_escape_special_chars($name);
		$value = smarty_function_escape_special_chars($value);
		if ($escape) {
			$output = smarty_function_escape_special_chars($output);
		}
		$_output .= '<input type="' . $inputType . '" name="' . $name;
		if ($ismultiselect) {
			$_output .= '[]';
		}
		$_output .= '" value="' . $value . '"';
		if ($labels && $label_ids) {
			$_output .= ' id="' . $_id . '"';
		}
		if ($ismultiselect && is_array($selected)) {
			if (isset($selected[ $value ])) {
				$_output .= ' checked="checked"';
			}
		} elseif ($value === $selected) {
			$_output .= ' checked="checked"';
		}
		$_output .= $extra . ' />' . $output;
		if ($labels) {
			$_output .= '</label>';
		}
		$_output .= $separator;
		return $_output;
	}

}