|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BestServedCold\HTMLBuilder\Html\Node; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Attribute |
|
7
|
|
|
* |
|
8
|
|
|
* @package BestServedCold\HTMLBuilder\Html\Node |
|
9
|
|
|
*/ |
|
10
|
|
|
abstract class Attribute |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var array $global |
|
14
|
|
|
*/ |
|
15
|
|
|
private static $global = [ |
|
16
|
|
|
'accesskey', |
|
17
|
|
|
'class', |
|
18
|
|
|
'contenteditable', |
|
19
|
|
|
'contextmenu', |
|
20
|
|
|
'data', |
|
21
|
|
|
'dir', |
|
22
|
|
|
'draggable', |
|
23
|
|
|
'hidden', |
|
24
|
|
|
'id', |
|
25
|
|
|
'is', |
|
26
|
|
|
'itemid', |
|
27
|
|
|
'itemprop', |
|
28
|
|
|
'itemref', |
|
29
|
|
|
'itemscope', |
|
30
|
|
|
'itemtype', |
|
31
|
|
|
'lang', |
|
32
|
|
|
'onabort', |
|
33
|
|
|
'onautocomplete', |
|
34
|
|
|
'onautocompleteerror', |
|
35
|
|
|
'onblur', |
|
36
|
|
|
'oncancel', |
|
37
|
|
|
'oncanplay', |
|
38
|
|
|
'oncanplaythrough', |
|
39
|
|
|
'onchange', |
|
40
|
|
|
'onclick', |
|
41
|
|
|
'onclose', |
|
42
|
|
|
'oncontextmenu', |
|
43
|
|
|
'oncuechange', |
|
44
|
|
|
'ondblclick', |
|
45
|
|
|
'ondrag', |
|
46
|
|
|
'ondragend', |
|
47
|
|
|
'ondragenter', |
|
48
|
|
|
'ondragexit', |
|
49
|
|
|
'ondragleave', |
|
50
|
|
|
'ondragover', |
|
51
|
|
|
'ondragstart', |
|
52
|
|
|
'ondrop', |
|
53
|
|
|
'ondurationchange', |
|
54
|
|
|
'onemptied', |
|
55
|
|
|
'onended', |
|
56
|
|
|
'onerror', |
|
57
|
|
|
'onfocus', |
|
58
|
|
|
'oninput', |
|
59
|
|
|
'oninvalid', |
|
60
|
|
|
'onkeydown', |
|
61
|
|
|
'onkeypress', |
|
62
|
|
|
'onkeyup', |
|
63
|
|
|
'onload', |
|
64
|
|
|
'onloadeddata', |
|
65
|
|
|
'onloadedmetadata', |
|
66
|
|
|
'onloadstart', |
|
67
|
|
|
'onmousedown', |
|
68
|
|
|
'onmouseenter', |
|
69
|
|
|
'onmouseleave', |
|
70
|
|
|
'onmousemove', |
|
71
|
|
|
'onmouseout', |
|
72
|
|
|
'onmouseover', |
|
73
|
|
|
'onmouseup', |
|
74
|
|
|
'onmousewheel', |
|
75
|
|
|
'onpause', |
|
76
|
|
|
'onplay', |
|
77
|
|
|
'onplaying', |
|
78
|
|
|
'onprogress', |
|
79
|
|
|
'onratechange', |
|
80
|
|
|
'onreset', |
|
81
|
|
|
'onresize', |
|
82
|
|
|
'onscroll', |
|
83
|
|
|
'onseeked', |
|
84
|
|
|
'onseeking', |
|
85
|
|
|
'onselect', |
|
86
|
|
|
'onshow', |
|
87
|
|
|
'onsort', |
|
88
|
|
|
'onstalled', |
|
89
|
|
|
'onsubmit', |
|
90
|
|
|
'onsuspend', |
|
91
|
|
|
'ontimeupdate', |
|
92
|
|
|
'ontoggle', |
|
93
|
|
|
'onvolumechange', |
|
94
|
|
|
'onwaiting', |
|
95
|
|
|
'spellcheck', |
|
96
|
|
|
'style', |
|
97
|
|
|
'tabindex', |
|
98
|
|
|
'title', |
|
99
|
|
|
'translate', |
|
100
|
|
|
'xml:lang', |
|
101
|
|
|
'xml:base' |
|
102
|
|
|
]; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var array $elements |
|
106
|
|
|
*/ |
|
107
|
|
|
private static $elements = [ |
|
108
|
|
|
'accept' => [ 'form', 'input' ], |
|
109
|
|
|
'accesskey' => [ 'form' ], |
|
110
|
|
|
'action' => [ 'form' ], |
|
111
|
|
|
'align' => [ 'applet', 'caption', 'col', 'colgroup', 'hr', 'iframe', 'img', 'table', 'tbody', 'td', |
|
112
|
|
|
'tfoot', 'th', 'thead', 'tr' ], |
|
113
|
|
|
'alt' => [ 'applet', 'area', 'img', 'input' ], |
|
114
|
|
|
'async' => [ 'script' ], |
|
115
|
|
|
'autocomplete' => [ 'form', 'input' ], |
|
116
|
|
|
'autofocus' => [ 'button', 'input', 'keygen', 'select', 'textarea' ], |
|
117
|
|
|
'autoplay' => [ 'audio', 'video' ], |
|
118
|
|
|
'autosave' => [ 'input' ], |
|
119
|
|
|
'bgcolor' => [ 'body', 'col', 'colgroup', 'table', 'tbody', 'tfoot','td', 'th', 'tr' ], |
|
120
|
|
|
'border' => [ 'img', 'object', 'table' ], |
|
121
|
|
|
'buffered' => [ 'audio', 'video' ], |
|
122
|
|
|
'challenge' => [ 'keygen' ], |
|
123
|
|
|
'charset' => [ 'meta', 'script' ], |
|
124
|
|
|
'checked' => [ 'command', 'input' ], |
|
125
|
|
|
'cite' => [ 'blockquote', 'del', 'ins', 'q' ], |
|
126
|
|
|
'code' => [ 'applet' ], |
|
127
|
|
|
'codebase' => [ 'applet' ], |
|
128
|
|
|
'color' => [ 'basefont', 'font', 'hr' ], |
|
129
|
|
|
'cols' => [ 'textarea' ], |
|
130
|
|
|
'colspan' => [ 'td', 'th' ], |
|
131
|
|
|
'content' => [ 'meta' ], |
|
132
|
|
|
'controls' => [ 'audio', 'video' ], |
|
133
|
|
|
'coords' => [ 'area' ], |
|
134
|
|
|
'data' => [ 'object' ], |
|
135
|
|
|
'datetime' => [ 'del', 'ins', 'time' ], |
|
136
|
|
|
'default' => [ 'track' ], |
|
137
|
|
|
'defer' => [ 'script' ], |
|
138
|
|
|
'dirname' => [ 'input', 'textarea' ], |
|
139
|
|
|
'disabled' => [ 'button', 'command', 'fieldset', 'input', 'keygen', 'optgroup', 'option', 'select', |
|
140
|
|
|
'textearea' ], |
|
141
|
|
|
'download' => [ 'a', 'area' ], |
|
142
|
|
|
'enctype' => [ 'form' ], |
|
143
|
|
|
'for' => [ 'label', 'output' ], |
|
144
|
|
|
'form' => [ 'button', 'fieldset', 'input', 'keygen', 'label', 'meter', 'object', 'output', 'prgress', |
|
145
|
|
|
'select', 'textarea' ], |
|
146
|
|
|
'formaction' => [ 'input', 'button' ], |
|
147
|
|
|
'headers' => [ 'td', 'th' ], |
|
148
|
|
|
'height' => [ 'canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video' ], |
|
149
|
|
|
'high' => [ 'meter' ], |
|
150
|
|
|
'href' => [ 'a', 'area', 'base', 'link' ], |
|
151
|
|
|
'hreflang' => [ 'a', 'area', 'link' ], |
|
152
|
|
|
'http-equiv' => [ 'meta' ], |
|
153
|
|
|
'icon' => [ 'command' ], |
|
154
|
|
|
'integrity' => [ 'link', 'script' ], |
|
155
|
|
|
'ismap' => [ 'img' ], |
|
156
|
|
|
'keytype' => [ 'keygen' ], |
|
157
|
|
|
'kind' => [ 'track' ], |
|
158
|
|
|
'label' => [ 'track' ], |
|
159
|
|
|
'lang' => [ 'track' ], |
|
160
|
|
|
'language' => [ 'script' ], |
|
161
|
|
|
'list' => [ 'input' ], |
|
162
|
|
|
'loop' => [ 'audio', 'bgsound', 'video' ], |
|
163
|
|
|
'low' => [ 'meter' ], |
|
164
|
|
|
'manifest' => [ 'html' ], |
|
165
|
|
|
'max' => [ 'input', 'meter', 'progress' ], |
|
166
|
|
|
'maxlength' => [ 'input', 'textarea' ], |
|
167
|
|
|
'media' => [ 'a', 'area', 'link', 'source', 'style' ], |
|
168
|
|
|
'method' => [ 'form' ], |
|
169
|
|
|
'min' => [ 'input', 'meter' ], |
|
170
|
|
|
'multiple' => [ 'input', 'select' ], |
|
171
|
|
|
'muted' => [ 'video' ], |
|
172
|
|
|
'name' => [ 'button', 'form', 'fieldset', 'iframe', 'input', 'keygen', 'object', 'output', 'select', |
|
173
|
|
|
'textarea', 'map', 'meta', 'param' ], |
|
174
|
|
|
'novalidate' => [ 'form' ], |
|
175
|
|
|
'open' => [ 'details' ], |
|
176
|
|
|
'optimum' => [ 'meter' ], |
|
177
|
|
|
'pattern' => [ 'input' ], |
|
178
|
|
|
'ping' => [ 'a', 'area' ], |
|
179
|
|
|
'placeholder' => [ 'input', 'textarea' ], |
|
180
|
|
|
'poster' => [ 'video' ], |
|
181
|
|
|
'preload' => [ 'audio', 'video' ], |
|
182
|
|
|
'radiogroup' => [ 'command' ], |
|
183
|
|
|
'readonly' => [ 'input', 'textarea' ], |
|
184
|
|
|
'rel' => [ 'a', 'area', 'link' ], |
|
185
|
|
|
'required' => [ 'input', 'select', 'textarea' ], |
|
186
|
|
|
'reversed' => [ 'ol' ], |
|
187
|
|
|
'rows' => [ 'textarea' ], |
|
188
|
|
|
'rowspan' => [ 'td', 'th' ], |
|
189
|
|
|
'sandbox' => [ 'iframe' ], |
|
190
|
|
|
'scope' => [ 'th' ], |
|
191
|
|
|
'scoped' => [ 'style' ], |
|
192
|
|
|
'seamless' => [ 'iframe' ], |
|
193
|
|
|
'selected' => [ 'option' ], |
|
194
|
|
|
'shape' => [ 'a', 'area' ], |
|
195
|
|
|
'size' => [ 'input', 'select' ], |
|
196
|
|
|
'sizes' => [ 'link', 'img', 'source' ], |
|
197
|
|
|
'span' => [ 'col', 'colgroup' ], |
|
198
|
|
|
'src' => [ 'audio', 'embed', 'iframe', 'img', 'input', 'script', 'source', 'track', 'video' ], |
|
199
|
|
|
'srcdoc' => [ 'iframe' ], |
|
200
|
|
|
'srclang' => [ 'track' ], |
|
201
|
|
|
'srcset' => [ 'img' ], |
|
202
|
|
|
'start' => [ 'ol' ], |
|
203
|
|
|
'step' => [ 'input' ], |
|
204
|
|
|
'summary' => [ 'table' ], |
|
205
|
|
|
'target' => [ 'a', 'area', 'base', 'form' ], |
|
206
|
|
|
'type' => [ 'button', 'input', 'command', 'embed', 'object', 'script', 'source', 'style', 'menu' ], |
|
207
|
|
|
'usemap' => [ 'img', 'input', 'object' ], |
|
208
|
|
|
'value' => [ 'button', 'option', 'input', 'li', 'meter', 'progress', 'param' ], |
|
209
|
|
|
'width' => [ 'canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video' ], |
|
210
|
|
|
'wrap' => [ 'textarea' ] |
|
211
|
|
|
]; |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param string $attribute |
|
215
|
|
|
* @return bool |
|
216
|
|
|
*/ |
|
217
|
|
|
public static function isAttribute($attribute) |
|
218
|
|
|
{ |
|
219
|
|
|
return in_array($attribute, array_merge(self::$global, array_keys(self::$elements))); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @param string $attribute |
|
224
|
|
|
* @param string $element |
|
225
|
|
|
* @return bool |
|
226
|
|
|
*/ |
|
227
|
|
|
public static function isElementAttribute($attribute, $element) |
|
228
|
|
|
{ |
|
229
|
|
|
return in_array($attribute, self::$global) || in_array($element, self::$elements[ $attribute ]); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|