@@ -102,8 +102,11 @@ discard block |
||
102 | 102 | name="archived_ticket[TKT_start_date]" |
103 | 103 | value="<?php echo esc_attr($TKT_start_date); ?>" |
104 | 104 | /> |
105 | - <?php else : ?> |
|
106 | - <label class='screen-reader-text' for="edit-ticket-TKT_start_date-<?php echo esc_attr($tkt_row); ?>"> |
|
105 | + <?php else { |
|
106 | + : ?> |
|
107 | + <label class='screen-reader-text' for="edit-ticket-TKT_start_date-<?php echo esc_attr($tkt_row); |
|
108 | +} |
|
109 | +?>"> |
|
107 | 110 | <?php esc_html_e('Sale Starts', 'event_espresso') ?> |
108 | 111 | </label> |
109 | 112 | <input type='text' |
@@ -136,8 +139,11 @@ discard block |
||
136 | 139 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_end_date]" |
137 | 140 | value="<?php echo esc_attr($TKT_end_date); ?>" |
138 | 141 | /> |
139 | - <?php else : ?> |
|
140 | - <label class='screen-reader-text' for='edit-ticket-TKT_end_date-<?php echo esc_attr($tkt_row); ?>'> |
|
142 | + <?php else { |
|
143 | + : ?> |
|
144 | + <label class='screen-reader-text' for='edit-ticket-TKT_end_date-<?php echo esc_attr($tkt_row); |
|
145 | +} |
|
146 | +?>'> |
|
141 | 147 | <?php esc_html_e('Sell Until', 'event_espresso') ?> |
142 | 148 | </label> |
143 | 149 | <input type='text' |
@@ -169,8 +175,11 @@ discard block |
||
169 | 175 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_base_price]" |
170 | 176 | value="<?php echo esc_attr($TKT_base_price); ?>" |
171 | 177 | /> |
172 | - <?php else : ?> |
|
173 | - <label class='screen-reader-text' for='edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); ?>'> |
|
178 | + <?php else { |
|
179 | + : ?> |
|
180 | + <label class='screen-reader-text' for='edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); |
|
181 | +} |
|
182 | +?>'> |
|
174 | 183 | <?php esc_html_e('Price', 'event_espresso') ?> |
175 | 184 | </label> |
176 | 185 | <input id="edit-ticket-TKT_base_price-<?php echo esc_attr($tkt_row); ?>" type="text" |
@@ -200,8 +209,11 @@ discard block |
||
200 | 209 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_qty]" |
201 | 210 | value="<?php echo esc_attr($TKT_qty_for_input); ?>" |
202 | 211 | /> |
203 | - <?php else : ?> |
|
204 | - <label class='screen-reader-text' for='edit-ticket-TKT_qty-<?php echo esc_attr($tkt_row); ?>'> |
|
212 | + <?php else { |
|
213 | + : ?> |
|
214 | + <label class='screen-reader-text' for='edit-ticket-TKT_qty-<?php echo esc_attr($tkt_row); |
|
215 | +} |
|
216 | +?>'> |
|
205 | 217 | <?php esc_html_e('Qty', 'event_espresso') ?> |
206 | 218 | </label> |
207 | 219 | <input type="text" |
@@ -321,9 +333,12 @@ discard block |
||
321 | 333 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_uses]" |
322 | 334 | value="<?php echo esc_attr($TKT_uses); ?>" |
323 | 335 | /> |
324 | - <?php else : ?> |
|
336 | + <?php else { |
|
337 | + : ?> |
|
325 | 338 | <label class='screen-reader-text' |
326 | - for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); ?>' |
|
339 | + for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); |
|
340 | +} |
|
341 | +?>' |
|
327 | 342 | > |
328 | 343 | <?php |
329 | 344 | esc_html_e('Ticket Uses', 'event_espresso') ?> |
@@ -353,8 +368,11 @@ discard block |
||
353 | 368 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_min]" |
354 | 369 | value="<?php echo esc_attr($TKT_min); ?>" |
355 | 370 | /> |
356 | - <?php else : ?> |
|
357 | - <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
|
371 | + <?php else { |
|
372 | + : ?> |
|
373 | + <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row); |
|
374 | +} |
|
375 | +?>'> |
|
358 | 376 | <?php esc_html_e('Minimum Quantity', 'event_espresso') ?> |
359 | 377 | </label> |
360 | 378 | <input type="text" |
@@ -380,8 +398,11 @@ discard block |
||
380 | 398 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_max]" |
381 | 399 | value="<?php echo esc_attr($TKT_max); ?>" |
382 | 400 | /> |
383 | - <?php else : ?> |
|
384 | - <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>'> |
|
401 | + <?php else { |
|
402 | + : ?> |
|
403 | + <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row); |
|
404 | +} |
|
405 | +?>'> |
|
385 | 406 | <?php esc_html_e('Maximum Quantity', 'event_espresso') ?> |
386 | 407 | </label> |
387 | 408 | <input type="text" |
@@ -434,10 +455,13 @@ discard block |
||
434 | 455 | value="1" |
435 | 456 | <?php echo esc_attr($TKT_taxable); ?> |
436 | 457 | /> |
437 | - <?php else : ?> |
|
458 | + <?php else { |
|
459 | + : ?> |
|
438 | 460 | <input type='checkbox' |
439 | 461 | class="TKT-taxable-checkbox" |
440 | - id="edit-ticket-TKT_taxable-<?php echo esc_attr($tkt_row); ?>" |
|
462 | + id="edit-ticket-TKT_taxable-<?php echo esc_attr($tkt_row); |
|
463 | +} |
|
464 | +?>" |
|
441 | 465 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_taxable]" |
442 | 466 | value="1" |
443 | 467 | <?php echo esc_attr($TKT_taxable); ?> |
@@ -11,60 +11,60 @@ |
||
11 | 11 | */ |
12 | 12 | class ServerSanitizer |
13 | 13 | { |
14 | - /** |
|
15 | - * @param string $key |
|
16 | - * @param string $value |
|
17 | - * @return mixed|string |
|
18 | - */ |
|
19 | - public function clean($key, $value) |
|
20 | - { |
|
21 | - switch ($key) { |
|
22 | - case 'AUTH_TYPE': |
|
23 | - $valid_types = [ |
|
24 | - 'Basic', |
|
25 | - 'Bearer', |
|
26 | - 'Digest', |
|
27 | - 'HOBA', |
|
28 | - 'Mutual', |
|
29 | - 'Negotiate', |
|
30 | - 'OAuth', |
|
31 | - 'SCRAM-SHA-1', |
|
32 | - 'SCRAM-SHA-256', |
|
33 | - 'vapid', |
|
34 | - ]; |
|
35 | - return in_array($value, $valid_types, true) ? $value : 'Basic'; |
|
36 | - case 'argc': |
|
37 | - case 'HTTP_DNT': |
|
38 | - case 'HTTP_UPGRADE_INSECURE_REQUESTS': |
|
39 | - case 'SERVER_PORT': |
|
40 | - case 'REMOTE_PORT': |
|
41 | - case 'REQUEST_TIME': |
|
42 | - return (int) filter_var($value, FILTER_SANITIZE_NUMBER_INT); |
|
43 | - case 'REQUEST_TIME_FLOAT': |
|
44 | - return (float) filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
45 | - case 'REQUEST_METHOD': |
|
46 | - $valid_types = [ |
|
47 | - 'CONNECT', |
|
48 | - 'DELETE', |
|
49 | - 'GET', |
|
50 | - 'HEAD', |
|
51 | - 'OPTIONS', |
|
52 | - 'PATCH', |
|
53 | - 'POST', |
|
54 | - 'PUT', |
|
55 | - 'TRACE', |
|
56 | - ]; |
|
57 | - return in_array($value, $valid_types, true) ? $value : 'GET'; |
|
58 | - case 'HTTP_HOST': |
|
59 | - case 'QUERY_STRING': |
|
60 | - case 'REQUEST_URI': |
|
61 | - case 'SCRIPT_NAME': |
|
62 | - case 'SERVER_NAME': |
|
63 | - return filter_var($value, FILTER_SANITIZE_URL); |
|
64 | - case 'SERVER_ADMIN': |
|
65 | - return filter_var($value, FILTER_SANITIZE_EMAIL); |
|
66 | - default: |
|
67 | - return filter_var($value, FILTER_SANITIZE_STRING); |
|
68 | - } |
|
69 | - } |
|
14 | + /** |
|
15 | + * @param string $key |
|
16 | + * @param string $value |
|
17 | + * @return mixed|string |
|
18 | + */ |
|
19 | + public function clean($key, $value) |
|
20 | + { |
|
21 | + switch ($key) { |
|
22 | + case 'AUTH_TYPE': |
|
23 | + $valid_types = [ |
|
24 | + 'Basic', |
|
25 | + 'Bearer', |
|
26 | + 'Digest', |
|
27 | + 'HOBA', |
|
28 | + 'Mutual', |
|
29 | + 'Negotiate', |
|
30 | + 'OAuth', |
|
31 | + 'SCRAM-SHA-1', |
|
32 | + 'SCRAM-SHA-256', |
|
33 | + 'vapid', |
|
34 | + ]; |
|
35 | + return in_array($value, $valid_types, true) ? $value : 'Basic'; |
|
36 | + case 'argc': |
|
37 | + case 'HTTP_DNT': |
|
38 | + case 'HTTP_UPGRADE_INSECURE_REQUESTS': |
|
39 | + case 'SERVER_PORT': |
|
40 | + case 'REMOTE_PORT': |
|
41 | + case 'REQUEST_TIME': |
|
42 | + return (int) filter_var($value, FILTER_SANITIZE_NUMBER_INT); |
|
43 | + case 'REQUEST_TIME_FLOAT': |
|
44 | + return (float) filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); |
|
45 | + case 'REQUEST_METHOD': |
|
46 | + $valid_types = [ |
|
47 | + 'CONNECT', |
|
48 | + 'DELETE', |
|
49 | + 'GET', |
|
50 | + 'HEAD', |
|
51 | + 'OPTIONS', |
|
52 | + 'PATCH', |
|
53 | + 'POST', |
|
54 | + 'PUT', |
|
55 | + 'TRACE', |
|
56 | + ]; |
|
57 | + return in_array($value, $valid_types, true) ? $value : 'GET'; |
|
58 | + case 'HTTP_HOST': |
|
59 | + case 'QUERY_STRING': |
|
60 | + case 'REQUEST_URI': |
|
61 | + case 'SCRIPT_NAME': |
|
62 | + case 'SERVER_NAME': |
|
63 | + return filter_var($value, FILTER_SANITIZE_URL); |
|
64 | + case 'SERVER_ADMIN': |
|
65 | + return filter_var($value, FILTER_SANITIZE_EMAIL); |
|
66 | + default: |
|
67 | + return filter_var($value, FILTER_SANITIZE_STRING); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |
@@ -11,25 +11,25 @@ |
||
11 | 11 | */ |
12 | 12 | class AttributesSanitizer |
13 | 13 | { |
14 | - /** |
|
15 | - * @param string $attributes |
|
16 | - * @param array $allowed_tags |
|
17 | - * @param string $tag |
|
18 | - * @return mixed|string |
|
19 | - */ |
|
20 | - public static function clean(string $attributes, array $allowed_tags, string $tag = 'div') |
|
21 | - { |
|
22 | - if (trim($attributes) === '') { |
|
23 | - return ''; |
|
24 | - } |
|
25 | - $html = '<' . $tag . ' ' . $attributes . '>'; |
|
26 | - $escaped = wp_kses($html, $allowed_tags); |
|
27 | - $start = strpos($escaped, ' '); |
|
28 | - $end = strpos($escaped, '>'); |
|
29 | - if ($start === false || $end === false) { |
|
30 | - return ''; |
|
31 | - } |
|
32 | - $length = $end - $start; |
|
33 | - return trim(substr($escaped, $start, $length)); |
|
34 | - } |
|
14 | + /** |
|
15 | + * @param string $attributes |
|
16 | + * @param array $allowed_tags |
|
17 | + * @param string $tag |
|
18 | + * @return mixed|string |
|
19 | + */ |
|
20 | + public static function clean(string $attributes, array $allowed_tags, string $tag = 'div') |
|
21 | + { |
|
22 | + if (trim($attributes) === '') { |
|
23 | + return ''; |
|
24 | + } |
|
25 | + $html = '<' . $tag . ' ' . $attributes . '>'; |
|
26 | + $escaped = wp_kses($html, $allowed_tags); |
|
27 | + $start = strpos($escaped, ' '); |
|
28 | + $end = strpos($escaped, '>'); |
|
29 | + if ($start === false || $end === false) { |
|
30 | + return ''; |
|
31 | + } |
|
32 | + $length = $end - $start; |
|
33 | + return trim(substr($escaped, $start, $length)); |
|
34 | + } |
|
35 | 35 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | if (trim($attributes) === '') { |
23 | 23 | return ''; |
24 | 24 | } |
25 | - $html = '<' . $tag . ' ' . $attributes . '>'; |
|
25 | + $html = '<'.$tag.' '.$attributes.'>'; |
|
26 | 26 | $escaped = wp_kses($html, $allowed_tags); |
27 | 27 | $start = strpos($escaped, ' '); |
28 | 28 | $end = strpos($escaped, '>'); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | <?php echo $eei18n; ?> |
37 | 37 | </script> |
38 | 38 | <?php foreach ($header_js as $key => $url) :?> |
39 | - <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?> |
|
39 | + <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?> |
|
40 | 40 | <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($header_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script> |
41 | 41 | <?php endforeach; ?> |
42 | 42 | <?php endif; ?> |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | <?php echo wp_kses($content, AllowedTags::getWithFormTags()); ?> |
48 | 48 | </div> |
49 | 49 | <?php foreach ($footer_js as $key => $url) : ?> |
50 | - <?php $footer_attributes = isset($footer_js_attributes[ $key ]) ? $footer_js_attributes[ $key ] : ''; ?> |
|
50 | + <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?> |
|
51 | 51 | <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($footer_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script> |
52 | 52 | <?php endforeach; ?> |
53 | 53 | <?php if ($enqueue_wp_assets) : ?> |
@@ -49,42 +49,42 @@ discard block |
||
49 | 49 | '-dv' |
50 | 50 | ); |
51 | 51 | if ($input instanceof EE_Hidden_Input) { |
52 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | + $html .= EEH_HTML::nl().$input->get_html_for_input(); |
|
53 | 53 | } elseif ($input instanceof EE_Submit_Input) { |
54 | 54 | $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
55 | 55 | $html .= EEH_HTML::div( |
56 | 56 | $input->get_html_for_input(), |
57 | - $html_id . '-submit-dv', |
|
57 | + $html_id.'-submit-dv', |
|
58 | 58 | "$input_class $html_class" |
59 | 59 | ); |
60 | 60 | } elseif ($input instanceof EE_Select_Input) { |
61 | 61 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
62 | 62 | $html .= EEH_HTML::div( |
63 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
64 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
65 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
66 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
67 | - $html_id . '-input-dv', |
|
63 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
64 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
65 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
66 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
67 | + $html_id.'-input-dv', |
|
68 | 68 | "$input_class $html_class" |
69 | 69 | ); |
70 | 70 | } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
71 | 71 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
72 | 72 | $html .= EEH_HTML::div( |
73 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
74 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
75 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
76 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
77 | - $html_id . '-input-dv', |
|
73 | + EEH_HTML::nl().$this->_display_label_for_option_type_question($input). |
|
74 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
75 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
76 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
77 | + $html_id.'-input-dv', |
|
78 | 78 | "$input_class $html_class" |
79 | 79 | ); |
80 | 80 | } else { |
81 | 81 | $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
82 | 82 | $html .= EEH_HTML::div( |
83 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
84 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
85 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
86 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
87 | - $html_id . '-input-dv', |
|
83 | + EEH_HTML::nl(1).$input->get_html_for_label(). |
|
84 | + EEH_HTML::nl().$input->get_html_for_errors(). |
|
85 | + EEH_HTML::nl().$input->get_html_for_input(). |
|
86 | + EEH_HTML::nl().$input->get_html_for_help(), |
|
87 | + $html_id.'-input-dv', |
|
88 | 88 | "$input_class $html_class" |
89 | 89 | ); |
90 | 90 | } |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | $html_label_text = $input->html_label_text(); |
132 | 132 | $label_html = EEH_HTML::div( |
133 | 133 | $input->required() |
134 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
134 | + ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk') |
|
135 | 135 | : $html_label_text, |
136 | 136 | $input->html_label_id(), |
137 | 137 | $input->required() |
138 | - ? 'ee-required-label ' . $input->html_label_class() |
|
138 | + ? 'ee-required-label '.$input->html_label_class() |
|
139 | 139 | : $input->html_label_class(), |
140 | 140 | $input->html_label_style(), |
141 | 141 | $input->other_html_attributes() |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function layout_subsection($form_section) |
162 | 162 | { |
163 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
163 | + return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 |
@@ -11,166 +11,166 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * opening div tag for a form |
|
16 | - * |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - public function layout_form_begin() |
|
20 | - { |
|
21 | - return EEH_HTML::div( |
|
22 | - '', |
|
23 | - $this->_form_section->html_id(), |
|
24 | - $this->_form_section->html_class(), |
|
25 | - $this->_form_section->html_style() |
|
26 | - ); |
|
27 | - } |
|
14 | + /** |
|
15 | + * opening div tag for a form |
|
16 | + * |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + public function layout_form_begin() |
|
20 | + { |
|
21 | + return EEH_HTML::div( |
|
22 | + '', |
|
23 | + $this->_form_section->html_id(), |
|
24 | + $this->_form_section->html_class(), |
|
25 | + $this->_form_section->html_style() |
|
26 | + ); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * Lays out the row for the input, including label and errors |
|
33 | - * |
|
34 | - * @param EE_Form_Input_Base $input |
|
35 | - * @return string |
|
36 | - * @throws \EE_Error |
|
37 | - */ |
|
38 | - public function layout_input($input) |
|
39 | - { |
|
40 | - $html = ''; |
|
41 | - // set something unique for the id |
|
42 | - $html_id = (string) $input->html_id() !== '' |
|
43 | - ? (string) $input->html_id() |
|
44 | - : spl_object_hash($input); |
|
45 | - // and add a generic input type class |
|
46 | - $html_class = $this->processHtmlClasses( |
|
47 | - sanitize_key(str_replace('_', '-', get_class($input))), |
|
48 | - '-dv' |
|
49 | - ); |
|
50 | - if ($input instanceof EE_Hidden_Input) { |
|
51 | - $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | - } elseif ($input instanceof EE_Submit_Input) { |
|
53 | - $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
|
54 | - $html .= EEH_HTML::div( |
|
55 | - $input->get_html_for_input(), |
|
56 | - $html_id . '-submit-dv', |
|
57 | - "$input_class $html_class" |
|
58 | - ); |
|
59 | - } elseif ($input instanceof EE_Select_Input) { |
|
60 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
61 | - $html .= EEH_HTML::div( |
|
62 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
63 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
64 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
65 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
66 | - $html_id . '-input-dv', |
|
67 | - "$input_class $html_class" |
|
68 | - ); |
|
69 | - } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
70 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
71 | - $html .= EEH_HTML::div( |
|
72 | - EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
73 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
74 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
75 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
76 | - $html_id . '-input-dv', |
|
77 | - "$input_class $html_class" |
|
78 | - ); |
|
79 | - } else { |
|
80 | - $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
81 | - $html .= EEH_HTML::div( |
|
82 | - EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
83 | - EEH_HTML::nl() . $input->get_html_for_errors() . |
|
84 | - EEH_HTML::nl() . $input->get_html_for_input() . |
|
85 | - EEH_HTML::nl() . $input->get_html_for_help(), |
|
86 | - $html_id . '-input-dv', |
|
87 | - "$input_class $html_class" |
|
88 | - ); |
|
89 | - } |
|
90 | - return $html; |
|
91 | - } |
|
31 | + /** |
|
32 | + * Lays out the row for the input, including label and errors |
|
33 | + * |
|
34 | + * @param EE_Form_Input_Base $input |
|
35 | + * @return string |
|
36 | + * @throws \EE_Error |
|
37 | + */ |
|
38 | + public function layout_input($input) |
|
39 | + { |
|
40 | + $html = ''; |
|
41 | + // set something unique for the id |
|
42 | + $html_id = (string) $input->html_id() !== '' |
|
43 | + ? (string) $input->html_id() |
|
44 | + : spl_object_hash($input); |
|
45 | + // and add a generic input type class |
|
46 | + $html_class = $this->processHtmlClasses( |
|
47 | + sanitize_key(str_replace('_', '-', get_class($input))), |
|
48 | + '-dv' |
|
49 | + ); |
|
50 | + if ($input instanceof EE_Hidden_Input) { |
|
51 | + $html .= EEH_HTML::nl() . $input->get_html_for_input(); |
|
52 | + } elseif ($input instanceof EE_Submit_Input) { |
|
53 | + $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv'); |
|
54 | + $html .= EEH_HTML::div( |
|
55 | + $input->get_html_for_input(), |
|
56 | + $html_id . '-submit-dv', |
|
57 | + "$input_class $html_class" |
|
58 | + ); |
|
59 | + } elseif ($input instanceof EE_Select_Input) { |
|
60 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
61 | + $html .= EEH_HTML::div( |
|
62 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
63 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
64 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
65 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
66 | + $html_id . '-input-dv', |
|
67 | + "$input_class $html_class" |
|
68 | + ); |
|
69 | + } elseif ($input instanceof EE_Form_Input_With_Options_Base) { |
|
70 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
71 | + $html .= EEH_HTML::div( |
|
72 | + EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) . |
|
73 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
74 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
75 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
76 | + $html_id . '-input-dv', |
|
77 | + "$input_class $html_class" |
|
78 | + ); |
|
79 | + } else { |
|
80 | + $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv'); |
|
81 | + $html .= EEH_HTML::div( |
|
82 | + EEH_HTML::nl(1) . $input->get_html_for_label() . |
|
83 | + EEH_HTML::nl() . $input->get_html_for_errors() . |
|
84 | + EEH_HTML::nl() . $input->get_html_for_input() . |
|
85 | + EEH_HTML::nl() . $input->get_html_for_help(), |
|
86 | + $html_id . '-input-dv', |
|
87 | + "$input_class $html_class" |
|
88 | + ); |
|
89 | + } |
|
90 | + return $html; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * appends one or more css classes in a string with the provided suffix |
|
96 | - * |
|
97 | - * @param array|string $classes |
|
98 | - * @param string $suffix |
|
99 | - * @return string |
|
100 | - * @since $VID:$ |
|
101 | - */ |
|
102 | - private function processHtmlClasses($classes, string $suffix): string |
|
103 | - { |
|
104 | - $html_classes = []; |
|
105 | - $classes = is_string($classes) ? explode(' ', $classes) : $classes; |
|
106 | - $classes = (array) $classes; |
|
107 | - foreach ($classes as $class) { |
|
108 | - // don't append suffix if class already has "-js" suffix |
|
109 | - $html_classes[] = strpos($class, '-js') !== strlen($class) - 3 |
|
110 | - ? "$class$suffix" |
|
111 | - : $class; |
|
112 | - } |
|
113 | - return implode(' ', $html_classes); |
|
114 | - } |
|
94 | + /** |
|
95 | + * appends one or more css classes in a string with the provided suffix |
|
96 | + * |
|
97 | + * @param array|string $classes |
|
98 | + * @param string $suffix |
|
99 | + * @return string |
|
100 | + * @since $VID:$ |
|
101 | + */ |
|
102 | + private function processHtmlClasses($classes, string $suffix): string |
|
103 | + { |
|
104 | + $html_classes = []; |
|
105 | + $classes = is_string($classes) ? explode(' ', $classes) : $classes; |
|
106 | + $classes = (array) $classes; |
|
107 | + foreach ($classes as $class) { |
|
108 | + // don't append suffix if class already has "-js" suffix |
|
109 | + $html_classes[] = strpos($class, '-js') !== strlen($class) - 3 |
|
110 | + ? "$class$suffix" |
|
111 | + : $class; |
|
112 | + } |
|
113 | + return implode(' ', $html_classes); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * |
|
120 | - * _display_label_for_option_type_question |
|
121 | - * Gets the HTML for the 'label', which is just text for this (because labels |
|
122 | - * should be for each input) |
|
123 | - * |
|
124 | - * @param EE_Form_Input_With_Options_Base $input |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
128 | - { |
|
129 | - if ($input->display_html_label_text()) { |
|
130 | - $html_label_text = $input->html_label_text(); |
|
131 | - $label_html = EEH_HTML::div( |
|
132 | - $input->required() |
|
133 | - ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
134 | - : $html_label_text, |
|
135 | - $input->html_label_id(), |
|
136 | - $input->required() |
|
137 | - ? 'ee-required-label ' . $input->html_label_class() |
|
138 | - : $input->html_label_class(), |
|
139 | - $input->html_label_style(), |
|
140 | - $input->other_html_attributes() |
|
141 | - ); |
|
142 | - // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
143 | - // then we need to close the div manually |
|
144 | - if (empty($html_label_text)) { |
|
145 | - $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
146 | - } |
|
147 | - return $label_html; |
|
148 | - } |
|
149 | - return ''; |
|
150 | - } |
|
118 | + /** |
|
119 | + * |
|
120 | + * _display_label_for_option_type_question |
|
121 | + * Gets the HTML for the 'label', which is just text for this (because labels |
|
122 | + * should be for each input) |
|
123 | + * |
|
124 | + * @param EE_Form_Input_With_Options_Base $input |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input) |
|
128 | + { |
|
129 | + if ($input->display_html_label_text()) { |
|
130 | + $html_label_text = $input->html_label_text(); |
|
131 | + $label_html = EEH_HTML::div( |
|
132 | + $input->required() |
|
133 | + ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk') |
|
134 | + : $html_label_text, |
|
135 | + $input->html_label_id(), |
|
136 | + $input->required() |
|
137 | + ? 'ee-required-label ' . $input->html_label_class() |
|
138 | + : $input->html_label_class(), |
|
139 | + $input->html_label_style(), |
|
140 | + $input->other_html_attributes() |
|
141 | + ); |
|
142 | + // if no content was provided to EEH_HTML::div() above (ie: an empty label), |
|
143 | + // then we need to close the div manually |
|
144 | + if (empty($html_label_text)) { |
|
145 | + $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class()); |
|
146 | + } |
|
147 | + return $label_html; |
|
148 | + } |
|
149 | + return ''; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * Lays out a row for the subsection |
|
156 | - * |
|
157 | - * @param EE_Form_Section_Proper $form_section |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function layout_subsection($form_section) |
|
161 | - { |
|
162 | - return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
163 | - } |
|
154 | + /** |
|
155 | + * Lays out a row for the subsection |
|
156 | + * |
|
157 | + * @param EE_Form_Section_Proper $form_section |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function layout_subsection($form_section) |
|
161 | + { |
|
162 | + return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * closing div tag for a form |
|
169 | - * |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function layout_form_end() |
|
173 | - { |
|
174 | - return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
175 | - } |
|
167 | + /** |
|
168 | + * closing div tag for a form |
|
169 | + * |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function layout_form_end() |
|
173 | + { |
|
174 | + return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class()); |
|
175 | + } |
|
176 | 176 | } |
@@ -1,905 +1,905 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * |
|
5 | - * Class EEH_HTML |
|
6 | - * |
|
4 | + * |
|
5 | + * Class EEH_HTML |
|
6 | + * |
|
7 | 7 | * Sometimes when writing PHP you need to generate some standard HTML, |
8 | 8 | * but either not enough to warrant creating a template file, |
9 | 9 | * or the amount of PHP conditionals and/or loops peppered throughout the HTML |
10 | 10 | * just make it really ugly and difficult to read. |
11 | 11 | * This class simply adds a bunch of methods for generating basic HTML tags. |
12 | 12 | * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters. |
13 | - * |
|
14 | - * @package Event Espresso |
|
15 | - * @subpackage core |
|
16 | - * @author Brent Christensen |
|
17 | - * |
|
18 | - * |
|
19 | - */ |
|
13 | + * |
|
14 | + * @package Event Espresso |
|
15 | + * @subpackage core |
|
16 | + * @author Brent Christensen |
|
17 | + * |
|
18 | + * |
|
19 | + */ |
|
20 | 20 | class EEH_HTML |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * instance of the EEH_Autoloader object |
|
25 | - * @var $_instance |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array $_indent |
|
32 | - * @access private |
|
33 | - */ |
|
34 | - private static $_indent = array(); |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @singleton method used to instantiate class object |
|
40 | - * @access public |
|
41 | - * @return EEH_HTML |
|
42 | - */ |
|
43 | - public static function instance() |
|
44 | - { |
|
45 | - // check if class object is instantiated, and instantiated properly |
|
46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
47 | - self::$_instance = new EEH_HTML(); |
|
48 | - } |
|
49 | - return self::$_instance; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * class constructor |
|
56 | - * |
|
57 | - * @access private |
|
58 | - * @return \EEH_HTML |
|
59 | - */ |
|
60 | - private function __construct() |
|
61 | - { |
|
62 | - // set some initial formatting for table indentation |
|
63 | - EEH_HTML::$_indent = array( |
|
64 | - 'table' => 0, |
|
65 | - 'thead' => 1, |
|
66 | - 'tbody' => 1, |
|
67 | - 'tr' => 2, |
|
68 | - 'th' => 3, |
|
69 | - 'td' => 3, |
|
70 | - 'div' => 0, |
|
71 | - 'h1' => 0, |
|
72 | - 'h2' => 0, |
|
73 | - 'h3' => 0, |
|
74 | - 'h4' => 0, |
|
75 | - 'h5' => 0, |
|
76 | - 'h6' => 0, |
|
77 | - 'p' => 0, |
|
78 | - 'ul' => 0, |
|
79 | - 'li' => 1 |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Generates an opening HTML <XX> tag and adds any passed attributes |
|
87 | - * if passed content, it will also add that, as well as the closing </XX> tag |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @param string $tag |
|
91 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
92 | - * @param string $id - html id attribute |
|
93 | - * @param string $class - html class attribute |
|
94 | - * @param string $style - html style attribute for applying inline styles |
|
95 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
96 | - * @param bool $force_close |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - protected static function _open_tag( |
|
100 | - $tag = 'div', |
|
101 | - $content = '', |
|
102 | - $id = '', |
|
103 | - $class = '', |
|
104 | - $style = '', |
|
105 | - $other_attributes = '', |
|
106 | - $force_close = false |
|
107 | - ) { |
|
108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
114 | - $indent = ! empty($content) || $force_close ? true : false; |
|
115 | - $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
116 | - return $html; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
123 | - * used for the opening tag, will append a comment |
|
124 | - * |
|
23 | + /** |
|
24 | + * instance of the EEH_Autoloader object |
|
25 | + * @var $_instance |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array $_indent |
|
32 | + * @access private |
|
33 | + */ |
|
34 | + private static $_indent = array(); |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @singleton method used to instantiate class object |
|
40 | + * @access public |
|
41 | + * @return EEH_HTML |
|
42 | + */ |
|
43 | + public static function instance() |
|
44 | + { |
|
45 | + // check if class object is instantiated, and instantiated properly |
|
46 | + if (! self::$_instance instanceof EEH_HTML) { |
|
47 | + self::$_instance = new EEH_HTML(); |
|
48 | + } |
|
49 | + return self::$_instance; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * class constructor |
|
56 | + * |
|
57 | + * @access private |
|
58 | + * @return \EEH_HTML |
|
59 | + */ |
|
60 | + private function __construct() |
|
61 | + { |
|
62 | + // set some initial formatting for table indentation |
|
63 | + EEH_HTML::$_indent = array( |
|
64 | + 'table' => 0, |
|
65 | + 'thead' => 1, |
|
66 | + 'tbody' => 1, |
|
67 | + 'tr' => 2, |
|
68 | + 'th' => 3, |
|
69 | + 'td' => 3, |
|
70 | + 'div' => 0, |
|
71 | + 'h1' => 0, |
|
72 | + 'h2' => 0, |
|
73 | + 'h3' => 0, |
|
74 | + 'h4' => 0, |
|
75 | + 'h5' => 0, |
|
76 | + 'h6' => 0, |
|
77 | + 'p' => 0, |
|
78 | + 'ul' => 0, |
|
79 | + 'li' => 1 |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Generates an opening HTML <XX> tag and adds any passed attributes |
|
87 | + * if passed content, it will also add that, as well as the closing </XX> tag |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @param string $tag |
|
91 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
92 | + * @param string $id - html id attribute |
|
93 | + * @param string $class - html class attribute |
|
94 | + * @param string $style - html style attribute for applying inline styles |
|
95 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
96 | + * @param bool $force_close |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + protected static function _open_tag( |
|
100 | + $tag = 'div', |
|
101 | + $content = '', |
|
102 | + $id = '', |
|
103 | + $class = '', |
|
104 | + $style = '', |
|
105 | + $other_attributes = '', |
|
106 | + $force_close = false |
|
107 | + ) { |
|
108 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | + $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
114 | + $indent = ! empty($content) || $force_close ? true : false; |
|
115 | + $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
116 | + return $html; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
123 | + * used for the opening tag, will append a comment |
|
124 | + * |
|
125 | 125 | *@access protected |
126 | - * @param string $tag |
|
127 | - * @param string $id - html id attribute |
|
128 | - * @param string $class - html class attribute |
|
129 | - * @param bool $indent |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
133 | - { |
|
134 | - $comment = ''; |
|
135 | - if ($id) { |
|
136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
137 | - } elseif ($class) { |
|
138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
139 | - } |
|
140 | - $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
141 | - $html .= '</' . $tag . '>' . $comment; |
|
142 | - return $html; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * div - generates HTML opening <div> tag and adds any passed attributes |
|
149 | - * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
150 | - * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
151 | - * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
152 | - * |
|
153 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
154 | - * @param string $id - html id attribute |
|
155 | - * @param string $class - html class attribute |
|
156 | - * @param string $style - html style attribute for applying inline styles |
|
157 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
161 | - { |
|
162 | - return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
169 | - * usage: echo EEH_HTML::divx(); |
|
170 | - * |
|
171 | - * @param string $id - html id attribute |
|
172 | - * @param string $class - html class attribute |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public static function divx($id = '', $class = '') |
|
176 | - { |
|
177 | - return EEH_HTML::_close_tag('div', $id, $class); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
184 | - * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
185 | - * |
|
186 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
187 | - * @param string $id - html id attribute |
|
188 | - * @param string $class - html class attribute |
|
189 | - * @param string $style - html style attribute for applying inline styles |
|
190 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
194 | - { |
|
195 | - return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
202 | - * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
203 | - * |
|
204 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
205 | - * @param string $id - html id attribute |
|
206 | - * @param string $class - html class attribute |
|
207 | - * @param string $style - html style attribute for applying inline styles |
|
208 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
212 | - { |
|
213 | - return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
220 | - * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
221 | - * |
|
222 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
223 | - * @param string $id - html id attribute |
|
224 | - * @param string $class - html class attribute |
|
225 | - * @param string $style - html style attribute for applying inline styles |
|
226 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
230 | - { |
|
231 | - return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
238 | - * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
239 | - * |
|
240 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
241 | - * @param string $id - html id attribute |
|
242 | - * @param string $class - html class attribute |
|
243 | - * @param string $style - html style attribute for applying inline styles |
|
244 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
248 | - { |
|
249 | - return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
256 | - * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
257 | - * |
|
258 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
259 | - * @param string $id - html id attribute |
|
260 | - * @param string $class - html class attribute |
|
261 | - * @param string $style - html style attribute for applying inline styles |
|
262 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
266 | - { |
|
267 | - return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
274 | - * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
275 | - * |
|
276 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
277 | - * @param string $id - html id attribute |
|
278 | - * @param string $class - html class attribute |
|
279 | - * @param string $style - html style attribute for applying inline styles |
|
280 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
284 | - { |
|
285 | - return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
292 | - * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
293 | - * |
|
294 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
295 | - * @param string $id - html id attribute |
|
296 | - * @param string $class - html class attribute |
|
297 | - * @param string $style - html style attribute for applying inline styles |
|
298 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
302 | - { |
|
303 | - return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
310 | - * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
311 | - * |
|
312 | - * @param string $id - html id attribute |
|
313 | - * @param string $class - html class attribute |
|
314 | - * @param string $style - html style attribute for applying inline styles |
|
315 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
319 | - { |
|
320 | - return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
327 | - * usage: echo EEH_HTML::ulx(); |
|
328 | - * |
|
329 | - * @param string $id - html id attribute |
|
330 | - * @param string $class - html class attribute |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public static function ulx($id = '', $class = '') |
|
334 | - { |
|
335 | - return EEH_HTML::_close_tag('ul', $id, $class); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
342 | - * if passed content, it will also add that, as well as the closing </li> tag |
|
343 | - * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
344 | - * |
|
345 | - * @param string $id - html id attribute |
|
346 | - * @param string $class - html class attribute |
|
347 | - * @param string $style - html style attribute for applying inline styles |
|
348 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
349 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
353 | - { |
|
354 | - return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
361 | - * usage: echo EEH_HTML::lix(); |
|
362 | - * |
|
363 | - * @param string $id - html id attribute |
|
364 | - * @param string $class - html class attribute |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public static function lix($id = '', $class = '') |
|
368 | - { |
|
369 | - return EEH_HTML::_close_tag('li', $id, $class); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * table - generates an HTML <table> tag and adds any passed attributes |
|
376 | - * usage: echo EEH_HTML::table(); |
|
377 | - * |
|
378 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
379 | - * @param string $id - html id attribute |
|
380 | - * @param string $class - html class attribute |
|
381 | - * @param string $style - html style attribute for applying inline styles |
|
382 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
386 | - { |
|
387 | - return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
394 | - * |
|
395 | - * @param string $id - html id attribute |
|
396 | - * @param string $class - html class attribute |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - public static function tablex($id = '', $class = '') |
|
400 | - { |
|
401 | - return EEH_HTML::_close_tag('table', $id, $class); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * thead - generates an HTML <thead> tag and adds any passed attributes |
|
408 | - * usage: echo EEH_HTML::thead(); |
|
409 | - * |
|
410 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
411 | - * @param string $id - html id attribute |
|
412 | - * @param string $class - html class attribute |
|
413 | - * @param string $style - html style attribute for applying inline styles |
|
414 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
418 | - { |
|
419 | - return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
426 | - * |
|
427 | - * @param string $id - html id attribute |
|
428 | - * @param string $class - html class attribute |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public static function theadx($id = '', $class = '') |
|
432 | - { |
|
433 | - return EEH_HTML::_close_tag('thead', $id, $class); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
440 | - * usage: echo EEH_HTML::tbody(); |
|
441 | - * |
|
442 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
443 | - * @param string $id - html id attribute |
|
444 | - * @param string $class - html class attribute |
|
445 | - * @param string $style - html style attribute for applying inline styles |
|
446 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
450 | - { |
|
451 | - return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
458 | - * |
|
459 | - * @param string $id - html id attribute |
|
460 | - * @param string $class - html class attribute |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - public static function tbodyx($id = '', $class = '') |
|
464 | - { |
|
465 | - return EEH_HTML::_close_tag('tbody', $id, $class); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * tr - generates an HTML <tr> tag and adds any passed attributes |
|
472 | - * usage: echo EEH_HTML::tr(); |
|
473 | - * |
|
474 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
475 | - * @param string $id - html id attribute |
|
476 | - * @param string $class - html class attribute |
|
477 | - * @param string $style - html style attribute for applying inline styles |
|
478 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
482 | - { |
|
483 | - return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
490 | - * |
|
491 | - * @param string $id - html id attribute |
|
492 | - * @param string $class - html class attribute |
|
493 | - * @return string |
|
494 | - */ |
|
495 | - public static function trx($id = '', $class = '') |
|
496 | - { |
|
497 | - return EEH_HTML::_close_tag('tr', $id, $class); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * th - generates an HTML <th> tag and adds any passed attributes |
|
504 | - * usage: echo EEH_HTML::th(); |
|
505 | - * |
|
506 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
507 | - * @param string $id - html id attribute |
|
508 | - * @param string $class - html class attribute |
|
509 | - * @param string $style - html style attribute for applying inline styles |
|
510 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
511 | - * @return string |
|
512 | - */ |
|
513 | - public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
514 | - { |
|
515 | - return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
522 | - * |
|
523 | - * @param string $id - html id attribute |
|
524 | - * @param string $class - html class attribute |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public static function thx($id = '', $class = '') |
|
528 | - { |
|
529 | - return EEH_HTML::_close_tag('th', $id, $class); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * td - generates an HTML <td> tag and adds any passed attributes |
|
536 | - * usage: echo EEH_HTML::td(); |
|
537 | - * |
|
538 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
539 | - * @param string $id - html id attribute |
|
540 | - * @param string $class - html class attribute |
|
541 | - * @param string $style - html style attribute for applying inline styles |
|
542 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
543 | - * @return string |
|
544 | - */ |
|
545 | - public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
546 | - { |
|
547 | - return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
554 | - * |
|
555 | - * @param string $id - html id attribute |
|
556 | - * @param string $class - html class attribute |
|
557 | - * @return string |
|
558 | - */ |
|
559 | - public static function tdx($id = '', $class = '') |
|
560 | - { |
|
561 | - return EEH_HTML::_close_tag('td', $id, $class); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
568 | - * generates a new table row with one td cell that spans however many columns you set |
|
569 | - * removes all styles from the tr and td |
|
570 | - * |
|
571 | - * @param string $content |
|
572 | - * @param int $colspan |
|
573 | - * @return string |
|
574 | - */ |
|
575 | - public static function no_row($content = '', $colspan = 2) |
|
576 | - { |
|
577 | - return EEH_HTML::tr( |
|
578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
579 | - '', |
|
580 | - '', |
|
581 | - 'padding:0; border:none;' |
|
582 | - ); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes |
|
589 | - * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' ); |
|
590 | - * |
|
591 | - * @access public |
|
592 | - * @param string $href URL to link to |
|
593 | - * @param string $link_text - the text that will become "hyperlinked" |
|
594 | - * @param string $title - html title attribute |
|
595 | - * @param string $id - html id attribute |
|
596 | - * @param string $class - html class attribute |
|
597 | - * @param string $style - html style attribute for applying inline styles |
|
598 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
599 | - * @return string |
|
600 | - */ |
|
601 | - public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
602 | - { |
|
603 | - $link_text = ! empty($link_text) ? $link_text : $href; |
|
604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
610 | - return "<a{$attributes}>{$link_text}</a>"; |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes |
|
617 | - * usage: echo EEH_HTML::button( 'this is a button' ); |
|
618 | - * |
|
619 | - * @param string $btn_text - the text that will become "hyperlinked" |
|
620 | - * @param string $class - html class attribute |
|
621 | - * @param string $aria_label - aria-label attribute |
|
622 | - * @param string $id - html id attribute |
|
623 | - * @param string $style - html style attribute for applying inline styles |
|
624 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
625 | - * @return string |
|
626 | - */ |
|
627 | - public static function button( |
|
628 | - $btn_text = '', |
|
629 | - $class = '', |
|
630 | - $aria_label = '', |
|
631 | - $id = '', |
|
632 | - $style = '', |
|
633 | - $other_attributes = '' |
|
634 | - ) { |
|
635 | - $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
636 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
637 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
638 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
639 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
640 | - return "<button type='button' {$attributes}>{$btn_text}</button>"; |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - |
|
645 | - /** |
|
646 | - * img - generates an HTML <img> tag and adds any passed attributes |
|
647 | - * usage: echo EEH_HTML::img(); |
|
648 | - * |
|
649 | - * @param string $src - html src attribute ie: the path or URL to the image |
|
650 | - * @param string $alt - html alt attribute |
|
651 | - * @param string $id - html id attribute |
|
652 | - * @param string $class - html class attribute |
|
653 | - * @param string $style - html style attribute for applying inline styles |
|
654 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
655 | - * @return string |
|
656 | - */ |
|
657 | - public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
658 | - { |
|
659 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
660 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
661 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
662 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
663 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
664 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
665 | - return '<img' . $attributes . '/>'; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
672 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
673 | - * |
|
674 | - * @access protected |
|
675 | - * @param string $tag |
|
676 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
677 | - * @param string $id - html id attribute |
|
678 | - * @param string $class - html class attribute |
|
679 | - * @param string $style - html style attribute for applying inline styles |
|
680 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
681 | - * @return string |
|
682 | - */ |
|
683 | - protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
684 | - { |
|
685 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
686 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
687 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
688 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
689 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
696 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
697 | - * |
|
698 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
699 | - * @param string $id - html id attribute |
|
700 | - * @param string $class - html class attribute |
|
701 | - * @param string $style - html style attribute for applying inline styles |
|
702 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
703 | - * @return string |
|
704 | - */ |
|
705 | - public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
706 | - { |
|
707 | - return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
714 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
715 | - * |
|
716 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
717 | - * @param string $id - html id attribute |
|
718 | - * @param string $class - html class attribute |
|
719 | - * @param string $style - html style attribute for applying inline styles |
|
720 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
721 | - * @return string |
|
722 | - */ |
|
723 | - public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
724 | - { |
|
725 | - return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
732 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
733 | - * |
|
734 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
735 | - * @param string $id - html id attribute |
|
736 | - * @param string $class - html class attribute |
|
737 | - * @param string $style - html style attribute for applying inline styles |
|
738 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
739 | - * @return string |
|
740 | - */ |
|
741 | - public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
742 | - { |
|
743 | - return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Generates an html <-- comment --> tag |
|
750 | - * usage: echo comment( 'this is a comment' ); |
|
751 | - * |
|
752 | - * @param string $comment |
|
753 | - * @return string |
|
754 | - */ |
|
755 | - public static function comment($comment = '') |
|
756 | - { |
|
757 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
758 | - } |
|
759 | - |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * br - generates a line break |
|
764 | - * |
|
765 | - * @param int $nmbr - the number of line breaks to return |
|
766 | - * @return string |
|
767 | - */ |
|
768 | - public static function br($nmbr = 1) |
|
769 | - { |
|
770 | - return str_repeat('<br />', $nmbr); |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * nbsp - generates non-breaking space entities based on number supplied |
|
777 | - * |
|
778 | - * @param int $nmbr - the number of non-breaking spaces to return |
|
779 | - * @return string |
|
780 | - */ |
|
781 | - public static function nbsp($nmbr = 1) |
|
782 | - { |
|
783 | - return str_repeat(' ', $nmbr); |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * sanitize_id |
|
790 | - * |
|
791 | - * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
792 | - * strtolower and allows capitals. |
|
793 | - * |
|
794 | - * @param string $id |
|
795 | - * @return string |
|
796 | - */ |
|
797 | - public static function sanitize_id($id = '') |
|
798 | - { |
|
799 | - $key = str_replace(' ', '-', trim($id)); |
|
800 | - return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * return a newline and tabs ("nl" stands for "new line") |
|
807 | - * |
|
808 | - * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
809 | - * @param string $tag |
|
810 | - * @return string - newline character plus # of indents passed (can be + or -) |
|
811 | - */ |
|
812 | - public static function nl($indent = 0, $tag = 'none') |
|
813 | - { |
|
814 | - $html = "\n"; |
|
815 | - EEH_HTML::indent($indent, $tag); |
|
816 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
817 | - $html .= "\t"; |
|
818 | - } |
|
819 | - return $html; |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
826 | - * the indentation level without actually creating a new line |
|
827 | - * |
|
828 | - * @param int $indent can be negative to decrease the indentation level |
|
829 | - * @param string $tag |
|
830 | - */ |
|
831 | - public static function indent($indent, $tag = 'none') |
|
832 | - { |
|
833 | - static $default_indentation = false; |
|
834 | - if (! $default_indentation) { |
|
835 | - EEH_HTML::_set_default_indentation(); |
|
836 | - $default_indentation = true; |
|
837 | - } |
|
838 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
839 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
840 | - } |
|
841 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
842 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
843 | - } |
|
844 | - |
|
845 | - |
|
846 | - /** |
|
847 | - * class _set_default_indentation |
|
848 | - * |
|
849 | - * @access private |
|
850 | - */ |
|
851 | - private static function _set_default_indentation() |
|
852 | - { |
|
853 | - // set some initial formatting for table indentation |
|
854 | - EEH_HTML::$_indent = array( |
|
855 | - 'none' => 0, |
|
856 | - 'form' => 0, |
|
857 | - 'radio' => 0, |
|
858 | - 'checkbox' => 0, |
|
859 | - 'select' => 0, |
|
860 | - 'option' => 0, |
|
861 | - 'optgroup' => 0, |
|
862 | - 'table' => 1, |
|
863 | - 'thead' => 2, |
|
864 | - 'tbody' => 2, |
|
865 | - 'tr' => 3, |
|
866 | - 'th' => 4, |
|
867 | - 'td' => 4, |
|
868 | - 'div' => 0, |
|
869 | - 'h1' => 0, |
|
870 | - 'h2' => 0, |
|
871 | - 'h3' => 0, |
|
872 | - 'h4' => 0, |
|
873 | - 'h5' => 0, |
|
874 | - 'h6' => 0, |
|
875 | - 'p' => 0, |
|
876 | - 'ul' => 0, |
|
877 | - 'li' => 1 |
|
878 | - ); |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * Retrieves the list of tags considered "simple", that are probably safe for |
|
885 | - * use in inputs |
|
886 | - * @global array $allowedtags |
|
887 | - * @return array |
|
888 | - */ |
|
889 | - public static function get_simple_tags() |
|
890 | - { |
|
891 | - global $allowedtags; |
|
892 | - $tags_we_allow = array_merge_recursive( |
|
893 | - $allowedtags, |
|
894 | - [ |
|
895 | - 'ol' => [], |
|
896 | - 'ul' => [], |
|
897 | - 'li' => [], |
|
898 | - 'br' => [], |
|
899 | - 'p' => [], |
|
900 | - 'a' => ['target'] |
|
901 | - ] |
|
902 | - ); |
|
903 | - return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
904 | - } |
|
126 | + * @param string $tag |
|
127 | + * @param string $id - html id attribute |
|
128 | + * @param string $class - html class attribute |
|
129 | + * @param bool $indent |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
133 | + { |
|
134 | + $comment = ''; |
|
135 | + if ($id) { |
|
136 | + $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
137 | + } elseif ($class) { |
|
138 | + $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
139 | + } |
|
140 | + $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
141 | + $html .= '</' . $tag . '>' . $comment; |
|
142 | + return $html; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * div - generates HTML opening <div> tag and adds any passed attributes |
|
149 | + * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
150 | + * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
151 | + * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
152 | + * |
|
153 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
154 | + * @param string $id - html id attribute |
|
155 | + * @param string $class - html class attribute |
|
156 | + * @param string $style - html style attribute for applying inline styles |
|
157 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
161 | + { |
|
162 | + return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
169 | + * usage: echo EEH_HTML::divx(); |
|
170 | + * |
|
171 | + * @param string $id - html id attribute |
|
172 | + * @param string $class - html class attribute |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public static function divx($id = '', $class = '') |
|
176 | + { |
|
177 | + return EEH_HTML::_close_tag('div', $id, $class); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
184 | + * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
185 | + * |
|
186 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
187 | + * @param string $id - html id attribute |
|
188 | + * @param string $class - html class attribute |
|
189 | + * @param string $style - html style attribute for applying inline styles |
|
190 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
194 | + { |
|
195 | + return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
202 | + * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
203 | + * |
|
204 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
205 | + * @param string $id - html id attribute |
|
206 | + * @param string $class - html class attribute |
|
207 | + * @param string $style - html style attribute for applying inline styles |
|
208 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
212 | + { |
|
213 | + return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
220 | + * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
221 | + * |
|
222 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
223 | + * @param string $id - html id attribute |
|
224 | + * @param string $class - html class attribute |
|
225 | + * @param string $style - html style attribute for applying inline styles |
|
226 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
230 | + { |
|
231 | + return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
238 | + * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
239 | + * |
|
240 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
241 | + * @param string $id - html id attribute |
|
242 | + * @param string $class - html class attribute |
|
243 | + * @param string $style - html style attribute for applying inline styles |
|
244 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
248 | + { |
|
249 | + return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
256 | + * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
257 | + * |
|
258 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
259 | + * @param string $id - html id attribute |
|
260 | + * @param string $class - html class attribute |
|
261 | + * @param string $style - html style attribute for applying inline styles |
|
262 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
266 | + { |
|
267 | + return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
274 | + * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
275 | + * |
|
276 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
277 | + * @param string $id - html id attribute |
|
278 | + * @param string $class - html class attribute |
|
279 | + * @param string $style - html style attribute for applying inline styles |
|
280 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
284 | + { |
|
285 | + return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
292 | + * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
293 | + * |
|
294 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
295 | + * @param string $id - html id attribute |
|
296 | + * @param string $class - html class attribute |
|
297 | + * @param string $style - html style attribute for applying inline styles |
|
298 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
302 | + { |
|
303 | + return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
310 | + * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
311 | + * |
|
312 | + * @param string $id - html id attribute |
|
313 | + * @param string $class - html class attribute |
|
314 | + * @param string $style - html style attribute for applying inline styles |
|
315 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
319 | + { |
|
320 | + return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
327 | + * usage: echo EEH_HTML::ulx(); |
|
328 | + * |
|
329 | + * @param string $id - html id attribute |
|
330 | + * @param string $class - html class attribute |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public static function ulx($id = '', $class = '') |
|
334 | + { |
|
335 | + return EEH_HTML::_close_tag('ul', $id, $class); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
342 | + * if passed content, it will also add that, as well as the closing </li> tag |
|
343 | + * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
344 | + * |
|
345 | + * @param string $id - html id attribute |
|
346 | + * @param string $class - html class attribute |
|
347 | + * @param string $style - html style attribute for applying inline styles |
|
348 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
349 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
353 | + { |
|
354 | + return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
361 | + * usage: echo EEH_HTML::lix(); |
|
362 | + * |
|
363 | + * @param string $id - html id attribute |
|
364 | + * @param string $class - html class attribute |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public static function lix($id = '', $class = '') |
|
368 | + { |
|
369 | + return EEH_HTML::_close_tag('li', $id, $class); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * table - generates an HTML <table> tag and adds any passed attributes |
|
376 | + * usage: echo EEH_HTML::table(); |
|
377 | + * |
|
378 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
379 | + * @param string $id - html id attribute |
|
380 | + * @param string $class - html class attribute |
|
381 | + * @param string $style - html style attribute for applying inline styles |
|
382 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
386 | + { |
|
387 | + return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
394 | + * |
|
395 | + * @param string $id - html id attribute |
|
396 | + * @param string $class - html class attribute |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + public static function tablex($id = '', $class = '') |
|
400 | + { |
|
401 | + return EEH_HTML::_close_tag('table', $id, $class); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * thead - generates an HTML <thead> tag and adds any passed attributes |
|
408 | + * usage: echo EEH_HTML::thead(); |
|
409 | + * |
|
410 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
411 | + * @param string $id - html id attribute |
|
412 | + * @param string $class - html class attribute |
|
413 | + * @param string $style - html style attribute for applying inline styles |
|
414 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
418 | + { |
|
419 | + return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
426 | + * |
|
427 | + * @param string $id - html id attribute |
|
428 | + * @param string $class - html class attribute |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public static function theadx($id = '', $class = '') |
|
432 | + { |
|
433 | + return EEH_HTML::_close_tag('thead', $id, $class); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
440 | + * usage: echo EEH_HTML::tbody(); |
|
441 | + * |
|
442 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
443 | + * @param string $id - html id attribute |
|
444 | + * @param string $class - html class attribute |
|
445 | + * @param string $style - html style attribute for applying inline styles |
|
446 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
450 | + { |
|
451 | + return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
458 | + * |
|
459 | + * @param string $id - html id attribute |
|
460 | + * @param string $class - html class attribute |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + public static function tbodyx($id = '', $class = '') |
|
464 | + { |
|
465 | + return EEH_HTML::_close_tag('tbody', $id, $class); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * tr - generates an HTML <tr> tag and adds any passed attributes |
|
472 | + * usage: echo EEH_HTML::tr(); |
|
473 | + * |
|
474 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
475 | + * @param string $id - html id attribute |
|
476 | + * @param string $class - html class attribute |
|
477 | + * @param string $style - html style attribute for applying inline styles |
|
478 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
482 | + { |
|
483 | + return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
490 | + * |
|
491 | + * @param string $id - html id attribute |
|
492 | + * @param string $class - html class attribute |
|
493 | + * @return string |
|
494 | + */ |
|
495 | + public static function trx($id = '', $class = '') |
|
496 | + { |
|
497 | + return EEH_HTML::_close_tag('tr', $id, $class); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * th - generates an HTML <th> tag and adds any passed attributes |
|
504 | + * usage: echo EEH_HTML::th(); |
|
505 | + * |
|
506 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
507 | + * @param string $id - html id attribute |
|
508 | + * @param string $class - html class attribute |
|
509 | + * @param string $style - html style attribute for applying inline styles |
|
510 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
511 | + * @return string |
|
512 | + */ |
|
513 | + public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
514 | + { |
|
515 | + return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
522 | + * |
|
523 | + * @param string $id - html id attribute |
|
524 | + * @param string $class - html class attribute |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public static function thx($id = '', $class = '') |
|
528 | + { |
|
529 | + return EEH_HTML::_close_tag('th', $id, $class); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * td - generates an HTML <td> tag and adds any passed attributes |
|
536 | + * usage: echo EEH_HTML::td(); |
|
537 | + * |
|
538 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
539 | + * @param string $id - html id attribute |
|
540 | + * @param string $class - html class attribute |
|
541 | + * @param string $style - html style attribute for applying inline styles |
|
542 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
543 | + * @return string |
|
544 | + */ |
|
545 | + public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
546 | + { |
|
547 | + return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
554 | + * |
|
555 | + * @param string $id - html id attribute |
|
556 | + * @param string $class - html class attribute |
|
557 | + * @return string |
|
558 | + */ |
|
559 | + public static function tdx($id = '', $class = '') |
|
560 | + { |
|
561 | + return EEH_HTML::_close_tag('td', $id, $class); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
568 | + * generates a new table row with one td cell that spans however many columns you set |
|
569 | + * removes all styles from the tr and td |
|
570 | + * |
|
571 | + * @param string $content |
|
572 | + * @param int $colspan |
|
573 | + * @return string |
|
574 | + */ |
|
575 | + public static function no_row($content = '', $colspan = 2) |
|
576 | + { |
|
577 | + return EEH_HTML::tr( |
|
578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
579 | + '', |
|
580 | + '', |
|
581 | + 'padding:0; border:none;' |
|
582 | + ); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes |
|
589 | + * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' ); |
|
590 | + * |
|
591 | + * @access public |
|
592 | + * @param string $href URL to link to |
|
593 | + * @param string $link_text - the text that will become "hyperlinked" |
|
594 | + * @param string $title - html title attribute |
|
595 | + * @param string $id - html id attribute |
|
596 | + * @param string $class - html class attribute |
|
597 | + * @param string $style - html style attribute for applying inline styles |
|
598 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
599 | + * @return string |
|
600 | + */ |
|
601 | + public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
602 | + { |
|
603 | + $link_text = ! empty($link_text) ? $link_text : $href; |
|
604 | + $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | + $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
610 | + return "<a{$attributes}>{$link_text}</a>"; |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes |
|
617 | + * usage: echo EEH_HTML::button( 'this is a button' ); |
|
618 | + * |
|
619 | + * @param string $btn_text - the text that will become "hyperlinked" |
|
620 | + * @param string $class - html class attribute |
|
621 | + * @param string $aria_label - aria-label attribute |
|
622 | + * @param string $id - html id attribute |
|
623 | + * @param string $style - html style attribute for applying inline styles |
|
624 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
625 | + * @return string |
|
626 | + */ |
|
627 | + public static function button( |
|
628 | + $btn_text = '', |
|
629 | + $class = '', |
|
630 | + $aria_label = '', |
|
631 | + $id = '', |
|
632 | + $style = '', |
|
633 | + $other_attributes = '' |
|
634 | + ) { |
|
635 | + $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
636 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
637 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
638 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
639 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
640 | + return "<button type='button' {$attributes}>{$btn_text}</button>"; |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + |
|
645 | + /** |
|
646 | + * img - generates an HTML <img> tag and adds any passed attributes |
|
647 | + * usage: echo EEH_HTML::img(); |
|
648 | + * |
|
649 | + * @param string $src - html src attribute ie: the path or URL to the image |
|
650 | + * @param string $alt - html alt attribute |
|
651 | + * @param string $id - html id attribute |
|
652 | + * @param string $class - html class attribute |
|
653 | + * @param string $style - html style attribute for applying inline styles |
|
654 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
655 | + * @return string |
|
656 | + */ |
|
657 | + public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
658 | + { |
|
659 | + $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
660 | + $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
661 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
662 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
663 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
664 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
665 | + return '<img' . $attributes . '/>'; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
672 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
673 | + * |
|
674 | + * @access protected |
|
675 | + * @param string $tag |
|
676 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
677 | + * @param string $id - html id attribute |
|
678 | + * @param string $class - html class attribute |
|
679 | + * @param string $style - html style attribute for applying inline styles |
|
680 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
681 | + * @return string |
|
682 | + */ |
|
683 | + protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
684 | + { |
|
685 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
686 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
687 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
688 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
689 | + return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
696 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
697 | + * |
|
698 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
699 | + * @param string $id - html id attribute |
|
700 | + * @param string $class - html class attribute |
|
701 | + * @param string $style - html style attribute for applying inline styles |
|
702 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
703 | + * @return string |
|
704 | + */ |
|
705 | + public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
706 | + { |
|
707 | + return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
714 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
715 | + * |
|
716 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
717 | + * @param string $id - html id attribute |
|
718 | + * @param string $class - html class attribute |
|
719 | + * @param string $style - html style attribute for applying inline styles |
|
720 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
721 | + * @return string |
|
722 | + */ |
|
723 | + public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
724 | + { |
|
725 | + return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
732 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
733 | + * |
|
734 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
735 | + * @param string $id - html id attribute |
|
736 | + * @param string $class - html class attribute |
|
737 | + * @param string $style - html style attribute for applying inline styles |
|
738 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
739 | + * @return string |
|
740 | + */ |
|
741 | + public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
742 | + { |
|
743 | + return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Generates an html <-- comment --> tag |
|
750 | + * usage: echo comment( 'this is a comment' ); |
|
751 | + * |
|
752 | + * @param string $comment |
|
753 | + * @return string |
|
754 | + */ |
|
755 | + public static function comment($comment = '') |
|
756 | + { |
|
757 | + return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
758 | + } |
|
759 | + |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * br - generates a line break |
|
764 | + * |
|
765 | + * @param int $nmbr - the number of line breaks to return |
|
766 | + * @return string |
|
767 | + */ |
|
768 | + public static function br($nmbr = 1) |
|
769 | + { |
|
770 | + return str_repeat('<br />', $nmbr); |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * nbsp - generates non-breaking space entities based on number supplied |
|
777 | + * |
|
778 | + * @param int $nmbr - the number of non-breaking spaces to return |
|
779 | + * @return string |
|
780 | + */ |
|
781 | + public static function nbsp($nmbr = 1) |
|
782 | + { |
|
783 | + return str_repeat(' ', $nmbr); |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * sanitize_id |
|
790 | + * |
|
791 | + * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
792 | + * strtolower and allows capitals. |
|
793 | + * |
|
794 | + * @param string $id |
|
795 | + * @return string |
|
796 | + */ |
|
797 | + public static function sanitize_id($id = '') |
|
798 | + { |
|
799 | + $key = str_replace(' ', '-', trim($id)); |
|
800 | + return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * return a newline and tabs ("nl" stands for "new line") |
|
807 | + * |
|
808 | + * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
809 | + * @param string $tag |
|
810 | + * @return string - newline character plus # of indents passed (can be + or -) |
|
811 | + */ |
|
812 | + public static function nl($indent = 0, $tag = 'none') |
|
813 | + { |
|
814 | + $html = "\n"; |
|
815 | + EEH_HTML::indent($indent, $tag); |
|
816 | + for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
817 | + $html .= "\t"; |
|
818 | + } |
|
819 | + return $html; |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
826 | + * the indentation level without actually creating a new line |
|
827 | + * |
|
828 | + * @param int $indent can be negative to decrease the indentation level |
|
829 | + * @param string $tag |
|
830 | + */ |
|
831 | + public static function indent($indent, $tag = 'none') |
|
832 | + { |
|
833 | + static $default_indentation = false; |
|
834 | + if (! $default_indentation) { |
|
835 | + EEH_HTML::_set_default_indentation(); |
|
836 | + $default_indentation = true; |
|
837 | + } |
|
838 | + if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
839 | + EEH_HTML::$_indent[ $tag ] = 0; |
|
840 | + } |
|
841 | + EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
842 | + EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
843 | + } |
|
844 | + |
|
845 | + |
|
846 | + /** |
|
847 | + * class _set_default_indentation |
|
848 | + * |
|
849 | + * @access private |
|
850 | + */ |
|
851 | + private static function _set_default_indentation() |
|
852 | + { |
|
853 | + // set some initial formatting for table indentation |
|
854 | + EEH_HTML::$_indent = array( |
|
855 | + 'none' => 0, |
|
856 | + 'form' => 0, |
|
857 | + 'radio' => 0, |
|
858 | + 'checkbox' => 0, |
|
859 | + 'select' => 0, |
|
860 | + 'option' => 0, |
|
861 | + 'optgroup' => 0, |
|
862 | + 'table' => 1, |
|
863 | + 'thead' => 2, |
|
864 | + 'tbody' => 2, |
|
865 | + 'tr' => 3, |
|
866 | + 'th' => 4, |
|
867 | + 'td' => 4, |
|
868 | + 'div' => 0, |
|
869 | + 'h1' => 0, |
|
870 | + 'h2' => 0, |
|
871 | + 'h3' => 0, |
|
872 | + 'h4' => 0, |
|
873 | + 'h5' => 0, |
|
874 | + 'h6' => 0, |
|
875 | + 'p' => 0, |
|
876 | + 'ul' => 0, |
|
877 | + 'li' => 1 |
|
878 | + ); |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * Retrieves the list of tags considered "simple", that are probably safe for |
|
885 | + * use in inputs |
|
886 | + * @global array $allowedtags |
|
887 | + * @return array |
|
888 | + */ |
|
889 | + public static function get_simple_tags() |
|
890 | + { |
|
891 | + global $allowedtags; |
|
892 | + $tags_we_allow = array_merge_recursive( |
|
893 | + $allowedtags, |
|
894 | + [ |
|
895 | + 'ol' => [], |
|
896 | + 'ul' => [], |
|
897 | + 'li' => [], |
|
898 | + 'br' => [], |
|
899 | + 'p' => [], |
|
900 | + 'a' => ['target'] |
|
901 | + ] |
|
902 | + ); |
|
903 | + return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
904 | + } |
|
905 | 905 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public static function instance() |
44 | 44 | { |
45 | 45 | // check if class object is instantiated, and instantiated properly |
46 | - if (! self::$_instance instanceof EEH_HTML) { |
|
46 | + if ( ! self::$_instance instanceof EEH_HTML) { |
|
47 | 47 | self::$_instance = new EEH_HTML(); |
48 | 48 | } |
49 | 49 | return self::$_instance; |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | $other_attributes = '', |
106 | 106 | $force_close = false |
107 | 107 | ) { |
108 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
109 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
110 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
111 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
112 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
113 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
108 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
109 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
110 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
111 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
112 | + $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>'; |
|
113 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : ''; |
|
114 | 114 | $indent = ! empty($content) || $force_close ? true : false; |
115 | 115 | $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
116 | 116 | return $html; |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | { |
134 | 134 | $comment = ''; |
135 | 135 | if ($id) { |
136 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
136 | + $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag); |
|
137 | 137 | } elseif ($class) { |
138 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
138 | + $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag); |
|
139 | 139 | } |
140 | 140 | $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
141 | - $html .= '</' . $tag . '>' . $comment; |
|
141 | + $html .= '</'.$tag.'>'.$comment; |
|
142 | 142 | return $html; |
143 | 143 | } |
144 | 144 | |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | public static function no_row($content = '', $colspan = 2) |
576 | 576 | { |
577 | 577 | return EEH_HTML::tr( |
578 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
578 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'), |
|
579 | 579 | '', |
580 | 580 | '', |
581 | 581 | 'padding:0; border:none;' |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
602 | 602 | { |
603 | 603 | $link_text = ! empty($link_text) ? $link_text : $href; |
604 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
605 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
606 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
607 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
608 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
609 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
604 | + $attributes = ! empty($href) ? ' href="'.$href.'"' : ''; |
|
605 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
606 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
607 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
608 | + $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : ''; |
|
609 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
610 | 610 | return "<a{$attributes}>{$link_text}</a>"; |
611 | 611 | } |
612 | 612 | |
@@ -632,11 +632,11 @@ discard block |
||
632 | 632 | $style = '', |
633 | 633 | $other_attributes = '' |
634 | 634 | ) { |
635 | - $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : ''; |
|
636 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
637 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
638 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
639 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
635 | + $attributes = ! empty($aria_label) ? ' aria-label="'.$aria_label.'"' : ''; |
|
636 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
637 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
638 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
639 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
640 | 640 | return "<button type='button' {$attributes}>{$btn_text}</button>"; |
641 | 641 | } |
642 | 642 | |
@@ -656,13 +656,13 @@ discard block |
||
656 | 656 | */ |
657 | 657 | public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
658 | 658 | { |
659 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
660 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
661 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
662 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
663 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
664 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
665 | - return '<img' . $attributes . '/>'; |
|
659 | + $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : ''; |
|
660 | + $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : ''; |
|
661 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
662 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
663 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
664 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
665 | + return '<img'.$attributes.'/>'; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | |
@@ -682,11 +682,11 @@ discard block |
||
682 | 682 | */ |
683 | 683 | protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
684 | 684 | { |
685 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
686 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
687 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
688 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
689 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
685 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
686 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
687 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
688 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
689 | + return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>'; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | */ |
755 | 755 | public static function comment($comment = '') |
756 | 756 | { |
757 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
757 | + return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : ''; |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | { |
814 | 814 | $html = "\n"; |
815 | 815 | EEH_HTML::indent($indent, $tag); |
816 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
816 | + for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { |
|
817 | 817 | $html .= "\t"; |
818 | 818 | } |
819 | 819 | return $html; |
@@ -831,15 +831,15 @@ discard block |
||
831 | 831 | public static function indent($indent, $tag = 'none') |
832 | 832 | { |
833 | 833 | static $default_indentation = false; |
834 | - if (! $default_indentation) { |
|
834 | + if ( ! $default_indentation) { |
|
835 | 835 | EEH_HTML::_set_default_indentation(); |
836 | 836 | $default_indentation = true; |
837 | 837 | } |
838 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
839 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
838 | + if ( ! isset(EEH_HTML::$_indent[$tag])) { |
|
839 | + EEH_HTML::$_indent[$tag] = 0; |
|
840 | 840 | } |
841 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
842 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
841 | + EEH_HTML::$_indent[$tag] += (int) $indent; |
|
842 | + EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0; |
|
843 | 843 | } |
844 | 844 | |
845 | 845 |
@@ -24,151 +24,151 @@ |
||
24 | 24 | */ |
25 | 25 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
26 | 26 | { |
27 | - /** |
|
28 | - * @var EE_Transaction $transaction |
|
29 | - */ |
|
30 | - private $transaction; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Ticket $ticket |
|
34 | - */ |
|
35 | - private $ticket; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Line_Item $ticket_line_item |
|
39 | - */ |
|
40 | - private $ticket_line_item; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int $reg_count |
|
44 | - */ |
|
45 | - private $reg_count; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int $reg_group_size |
|
49 | - */ |
|
50 | - private $reg_group_size; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $reg_status |
|
54 | - */ |
|
55 | - private $reg_status; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EE_Registration $registration |
|
59 | - */ |
|
60 | - protected $registration; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * CreateRegistrationCommand constructor. |
|
65 | - * |
|
66 | - * @param EE_Transaction $transaction |
|
67 | - * @param EE_Line_Item $ticket_line_item |
|
68 | - * @param int $reg_count |
|
69 | - * @param int $reg_group_size |
|
70 | - * @param string $reg_status |
|
71 | - * @throws InvalidEntityException |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EE_Transaction $transaction, |
|
75 | - EE_Line_Item $ticket_line_item, |
|
76 | - $reg_count = 1, |
|
77 | - $reg_group_size = 0, |
|
78 | - $reg_status = EEM_Registration::status_id_incomplete |
|
79 | - ) { |
|
80 | - // grab the related ticket object for this line_item |
|
81 | - $this->ticket = $ticket_line_item->ticket(); |
|
82 | - if (! $this->ticket instanceof EE_Ticket) { |
|
83 | - throw new InvalidEntityException( |
|
84 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
85 | - 'EE_Ticket', |
|
86 | - sprintf( |
|
87 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
88 | - $ticket_line_item->ID() |
|
89 | - ) |
|
90 | - ); |
|
91 | - } |
|
92 | - $this->transaction = $transaction; |
|
93 | - $this->ticket_line_item = $ticket_line_item; |
|
94 | - $this->reg_count = absint($reg_count); |
|
95 | - $this->reg_group_size = absint($reg_group_size); |
|
96 | - $this->reg_status = $reg_status; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return CapCheckInterface |
|
102 | - * @throws InvalidDataTypeException |
|
103 | - */ |
|
104 | - public function getCapCheck() |
|
105 | - { |
|
106 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
107 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
108 | - } |
|
109 | - return $this->cap_check; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return EE_Transaction |
|
115 | - */ |
|
116 | - public function transaction() |
|
117 | - { |
|
118 | - return $this->transaction; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return EE_Ticket |
|
124 | - */ |
|
125 | - public function ticket() |
|
126 | - { |
|
127 | - return $this->ticket; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return EE_Line_Item |
|
133 | - */ |
|
134 | - public function ticketLineItem() |
|
135 | - { |
|
136 | - return $this->ticket_line_item; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - public function regCount() |
|
144 | - { |
|
145 | - return $this->reg_count; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return int |
|
151 | - */ |
|
152 | - public function regGroupSize() |
|
153 | - { |
|
154 | - return $this->reg_group_size; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function regStatus() |
|
162 | - { |
|
163 | - return $this->reg_status; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return EE_Registration |
|
169 | - */ |
|
170 | - public function registration() |
|
171 | - { |
|
172 | - return $this->registration; |
|
173 | - } |
|
27 | + /** |
|
28 | + * @var EE_Transaction $transaction |
|
29 | + */ |
|
30 | + private $transaction; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Ticket $ticket |
|
34 | + */ |
|
35 | + private $ticket; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Line_Item $ticket_line_item |
|
39 | + */ |
|
40 | + private $ticket_line_item; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int $reg_count |
|
44 | + */ |
|
45 | + private $reg_count; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int $reg_group_size |
|
49 | + */ |
|
50 | + private $reg_group_size; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $reg_status |
|
54 | + */ |
|
55 | + private $reg_status; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EE_Registration $registration |
|
59 | + */ |
|
60 | + protected $registration; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * CreateRegistrationCommand constructor. |
|
65 | + * |
|
66 | + * @param EE_Transaction $transaction |
|
67 | + * @param EE_Line_Item $ticket_line_item |
|
68 | + * @param int $reg_count |
|
69 | + * @param int $reg_group_size |
|
70 | + * @param string $reg_status |
|
71 | + * @throws InvalidEntityException |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EE_Transaction $transaction, |
|
75 | + EE_Line_Item $ticket_line_item, |
|
76 | + $reg_count = 1, |
|
77 | + $reg_group_size = 0, |
|
78 | + $reg_status = EEM_Registration::status_id_incomplete |
|
79 | + ) { |
|
80 | + // grab the related ticket object for this line_item |
|
81 | + $this->ticket = $ticket_line_item->ticket(); |
|
82 | + if (! $this->ticket instanceof EE_Ticket) { |
|
83 | + throw new InvalidEntityException( |
|
84 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
85 | + 'EE_Ticket', |
|
86 | + sprintf( |
|
87 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
88 | + $ticket_line_item->ID() |
|
89 | + ) |
|
90 | + ); |
|
91 | + } |
|
92 | + $this->transaction = $transaction; |
|
93 | + $this->ticket_line_item = $ticket_line_item; |
|
94 | + $this->reg_count = absint($reg_count); |
|
95 | + $this->reg_group_size = absint($reg_group_size); |
|
96 | + $this->reg_status = $reg_status; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return CapCheckInterface |
|
102 | + * @throws InvalidDataTypeException |
|
103 | + */ |
|
104 | + public function getCapCheck() |
|
105 | + { |
|
106 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
107 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
108 | + } |
|
109 | + return $this->cap_check; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return EE_Transaction |
|
115 | + */ |
|
116 | + public function transaction() |
|
117 | + { |
|
118 | + return $this->transaction; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return EE_Ticket |
|
124 | + */ |
|
125 | + public function ticket() |
|
126 | + { |
|
127 | + return $this->ticket; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return EE_Line_Item |
|
133 | + */ |
|
134 | + public function ticketLineItem() |
|
135 | + { |
|
136 | + return $this->ticket_line_item; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + public function regCount() |
|
144 | + { |
|
145 | + return $this->reg_count; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return int |
|
151 | + */ |
|
152 | + public function regGroupSize() |
|
153 | + { |
|
154 | + return $this->reg_group_size; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function regStatus() |
|
162 | + { |
|
163 | + return $this->reg_status; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return EE_Registration |
|
169 | + */ |
|
170 | + public function registration() |
|
171 | + { |
|
172 | + return $this->registration; |
|
173 | + } |
|
174 | 174 | } |
@@ -13,8 +13,8 @@ |
||
13 | 13 | */ |
14 | 14 | interface CommandRequiresCapCheckInterface |
15 | 15 | { |
16 | - /** |
|
17 | - * @return CapCheckInterface |
|
18 | - */ |
|
19 | - public function getCapCheck(); |
|
16 | + /** |
|
17 | + * @return CapCheckInterface |
|
18 | + */ |
|
19 | + public function getCapCheck(); |
|
20 | 20 | } |
@@ -21,182 +21,182 @@ |
||
21 | 21 | */ |
22 | 22 | class RouteHandler |
23 | 23 | { |
24 | - /** |
|
25 | - * @var CapabilitiesCheckerInterface $capabilities_checker |
|
26 | - */ |
|
27 | - private $capabilities_checker; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var JsonDataNodeHandler $data_node_handler |
|
31 | - */ |
|
32 | - private $data_node_handler; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var LoaderInterface $loader |
|
36 | - */ |
|
37 | - private $loader; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var RequestInterface $request |
|
41 | - */ |
|
42 | - protected $request; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var RouteCollection $routes |
|
46 | - */ |
|
47 | - private $routes; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var boolean $print_data_nodes |
|
51 | - */ |
|
52 | - private $print_data_nodes = true; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $route_request_type |
|
56 | - */ |
|
57 | - protected $route_request_type = ''; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * RouteHandler constructor. |
|
62 | - * |
|
63 | - * @param CapabilitiesCheckerInterface $capabilities_checker |
|
64 | - * @param JsonDataNodeHandler $data_node_handler |
|
65 | - * @param LoaderInterface $loader |
|
66 | - * @param RequestInterface $request |
|
67 | - * @param RouteCollection $routes |
|
68 | - */ |
|
69 | - public function __construct( |
|
70 | - CapabilitiesCheckerInterface $capabilities_checker, |
|
71 | - JsonDataNodeHandler $data_node_handler, |
|
72 | - LoaderInterface $loader, |
|
73 | - RequestInterface $request, |
|
74 | - RouteCollection $routes |
|
75 | - ) { |
|
76 | - $this->capabilities_checker = $capabilities_checker; |
|
77 | - $this->data_node_handler = $data_node_handler; |
|
78 | - $this->loader = $loader; |
|
79 | - $this->request = $request; |
|
80 | - $this->routes = $routes; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $fqcn Fully Qualified Class Name for Route |
|
86 | - * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() after adding |
|
87 | - * @throws Exception |
|
88 | - */ |
|
89 | - public function addRoute(string $fqcn, bool $handle = true) |
|
90 | - { |
|
91 | - try { |
|
92 | - $route = $this->loader->getShared($fqcn); |
|
93 | - $this->validateRoute($route, $fqcn); |
|
94 | - if ($this->capabilities_checker->processCapCheck($route->getCapCheck(), true)) { |
|
95 | - $this->routes->add($route); |
|
96 | - $this->handle($route, $handle); |
|
97 | - } |
|
98 | - } catch (Exception $exception) { |
|
99 | - new ExceptionStackTraceDisplay( |
|
100 | - new DomainException( |
|
101 | - sprintf( |
|
102 | - esc_html__( |
|
103 | - 'The following error occurred while trying to handle the "%1$s" route:%2$s%3$s', |
|
104 | - 'event_espresso' |
|
105 | - ), |
|
106 | - $fqcn, |
|
107 | - '<br />', |
|
108 | - $exception->getMessage() |
|
109 | - ) |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function getRouteRequestType(): string |
|
120 | - { |
|
121 | - return $this->route_request_type; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $route_request_type |
|
127 | - */ |
|
128 | - public function setRouteRequestType(string $route_request_type = '') |
|
129 | - { |
|
130 | - $this->route_request_type = ! empty($route_request_type) ? $route_request_type : $this->route_request_type; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RouteInterface $route |
|
136 | - * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() |
|
137 | - */ |
|
138 | - public function handle(RouteInterface $route, bool $handle = true) |
|
139 | - { |
|
140 | - if ($handle && $route->isNotHandled()) { |
|
141 | - $route->handleRequest(); |
|
142 | - if ($route instanceof PrimaryRoute) { |
|
143 | - $this->setRouteRequestType($route->getRouteRequestType()); |
|
144 | - } |
|
145 | - $data_node = $route->dataNode(); |
|
146 | - if ($data_node instanceof JsonDataNode) { |
|
147 | - $this->data_node_handler->addDataNode($data_node); |
|
148 | - $this->printDataNodes(); |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * calls RouteInterface::handleRequest() on all Routes that |
|
156 | - * - match current request |
|
157 | - * - have yet to be handled |
|
158 | - * |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - public function handleRoutesForCurrentRequest() |
|
162 | - { |
|
163 | - $this->routes->handleRoutesForCurrentRequest(); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - private function printDataNodes() |
|
171 | - { |
|
172 | - if ($this->print_data_nodes) { |
|
173 | - add_action('admin_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
174 | - add_action('wp_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
175 | - $this->print_data_nodes = false; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @param RouteInterface|null $route |
|
182 | - * @param string $fqcn |
|
183 | - */ |
|
184 | - private function validateRoute(?RouteInterface $route, string $fqcn = '') |
|
185 | - { |
|
186 | - if (! $route instanceof RouteInterface) { |
|
187 | - throw new InvalidClassException( |
|
188 | - sprintf( |
|
189 | - /* |
|
24 | + /** |
|
25 | + * @var CapabilitiesCheckerInterface $capabilities_checker |
|
26 | + */ |
|
27 | + private $capabilities_checker; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var JsonDataNodeHandler $data_node_handler |
|
31 | + */ |
|
32 | + private $data_node_handler; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var LoaderInterface $loader |
|
36 | + */ |
|
37 | + private $loader; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var RequestInterface $request |
|
41 | + */ |
|
42 | + protected $request; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var RouteCollection $routes |
|
46 | + */ |
|
47 | + private $routes; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var boolean $print_data_nodes |
|
51 | + */ |
|
52 | + private $print_data_nodes = true; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $route_request_type |
|
56 | + */ |
|
57 | + protected $route_request_type = ''; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * RouteHandler constructor. |
|
62 | + * |
|
63 | + * @param CapabilitiesCheckerInterface $capabilities_checker |
|
64 | + * @param JsonDataNodeHandler $data_node_handler |
|
65 | + * @param LoaderInterface $loader |
|
66 | + * @param RequestInterface $request |
|
67 | + * @param RouteCollection $routes |
|
68 | + */ |
|
69 | + public function __construct( |
|
70 | + CapabilitiesCheckerInterface $capabilities_checker, |
|
71 | + JsonDataNodeHandler $data_node_handler, |
|
72 | + LoaderInterface $loader, |
|
73 | + RequestInterface $request, |
|
74 | + RouteCollection $routes |
|
75 | + ) { |
|
76 | + $this->capabilities_checker = $capabilities_checker; |
|
77 | + $this->data_node_handler = $data_node_handler; |
|
78 | + $this->loader = $loader; |
|
79 | + $this->request = $request; |
|
80 | + $this->routes = $routes; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $fqcn Fully Qualified Class Name for Route |
|
86 | + * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() after adding |
|
87 | + * @throws Exception |
|
88 | + */ |
|
89 | + public function addRoute(string $fqcn, bool $handle = true) |
|
90 | + { |
|
91 | + try { |
|
92 | + $route = $this->loader->getShared($fqcn); |
|
93 | + $this->validateRoute($route, $fqcn); |
|
94 | + if ($this->capabilities_checker->processCapCheck($route->getCapCheck(), true)) { |
|
95 | + $this->routes->add($route); |
|
96 | + $this->handle($route, $handle); |
|
97 | + } |
|
98 | + } catch (Exception $exception) { |
|
99 | + new ExceptionStackTraceDisplay( |
|
100 | + new DomainException( |
|
101 | + sprintf( |
|
102 | + esc_html__( |
|
103 | + 'The following error occurred while trying to handle the "%1$s" route:%2$s%3$s', |
|
104 | + 'event_espresso' |
|
105 | + ), |
|
106 | + $fqcn, |
|
107 | + '<br />', |
|
108 | + $exception->getMessage() |
|
109 | + ) |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function getRouteRequestType(): string |
|
120 | + { |
|
121 | + return $this->route_request_type; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $route_request_type |
|
127 | + */ |
|
128 | + public function setRouteRequestType(string $route_request_type = '') |
|
129 | + { |
|
130 | + $this->route_request_type = ! empty($route_request_type) ? $route_request_type : $this->route_request_type; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RouteInterface $route |
|
136 | + * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() |
|
137 | + */ |
|
138 | + public function handle(RouteInterface $route, bool $handle = true) |
|
139 | + { |
|
140 | + if ($handle && $route->isNotHandled()) { |
|
141 | + $route->handleRequest(); |
|
142 | + if ($route instanceof PrimaryRoute) { |
|
143 | + $this->setRouteRequestType($route->getRouteRequestType()); |
|
144 | + } |
|
145 | + $data_node = $route->dataNode(); |
|
146 | + if ($data_node instanceof JsonDataNode) { |
|
147 | + $this->data_node_handler->addDataNode($data_node); |
|
148 | + $this->printDataNodes(); |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * calls RouteInterface::handleRequest() on all Routes that |
|
156 | + * - match current request |
|
157 | + * - have yet to be handled |
|
158 | + * |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + public function handleRoutesForCurrentRequest() |
|
162 | + { |
|
163 | + $this->routes->handleRoutesForCurrentRequest(); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + private function printDataNodes() |
|
171 | + { |
|
172 | + if ($this->print_data_nodes) { |
|
173 | + add_action('admin_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
174 | + add_action('wp_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
175 | + $this->print_data_nodes = false; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @param RouteInterface|null $route |
|
182 | + * @param string $fqcn |
|
183 | + */ |
|
184 | + private function validateRoute(?RouteInterface $route, string $fqcn = '') |
|
185 | + { |
|
186 | + if (! $route instanceof RouteInterface) { |
|
187 | + throw new InvalidClassException( |
|
188 | + sprintf( |
|
189 | + /* |
|
190 | 190 | * translators: |
191 | 191 | * The supplied FQCN (Fully\Qualified\Class\Name) must be an instance of RouteInterface. |
192 | 192 | */ |
193 | - esc_html__( |
|
194 | - 'The supplied FQCN (%1$s) must be an instance of RouteInterface.', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $fqcn |
|
198 | - ) |
|
199 | - ); |
|
200 | - } |
|
201 | - } |
|
193 | + esc_html__( |
|
194 | + 'The supplied FQCN (%1$s) must be an instance of RouteInterface.', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $fqcn |
|
198 | + ) |
|
199 | + ); |
|
200 | + } |
|
201 | + } |
|
202 | 202 | } |
@@ -183,7 +183,7 @@ |
||
183 | 183 | */ |
184 | 184 | private function validateRoute(?RouteInterface $route, string $fqcn = '') |
185 | 185 | { |
186 | - if (! $route instanceof RouteInterface) { |
|
186 | + if ( ! $route instanceof RouteInterface) { |
|
187 | 187 | throw new InvalidClassException( |
188 | 188 | sprintf( |
189 | 189 | /* |