@@ -1,875 +1,875 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EEH_HTML |
|
5 | - * |
|
3 | + * |
|
4 | + * Class EEH_HTML |
|
5 | + * |
|
6 | 6 | * Sometimes when writing PHP you need to generate some standard HTML, |
7 | 7 | * but either not enough to warrant creating a template file, |
8 | 8 | * or the amount of PHP conditionals and/or loops peppered throughout the HTML |
9 | 9 | * just make it really ugly and difficult to read. |
10 | 10 | * This class simply adds a bunch of methods for generating basic HTML tags. |
11 | 11 | * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters. |
12 | - * |
|
13 | - * @package Event Espresso |
|
14 | - * @subpackage core |
|
15 | - * @author Brent Christensen |
|
16 | - * |
|
17 | - * |
|
18 | - */ |
|
12 | + * |
|
13 | + * @package Event Espresso |
|
14 | + * @subpackage core |
|
15 | + * @author Brent Christensen |
|
16 | + * |
|
17 | + * |
|
18 | + */ |
|
19 | 19 | class EEH_HTML |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * instance of the EEH_Autoloader object |
|
24 | - * @var $_instance |
|
25 | - * @access private |
|
26 | - */ |
|
27 | - private static $_instance; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var array $_indent |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - private static $_indent = array(); |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @singleton method used to instantiate class object |
|
39 | - * @access public |
|
40 | - * @return EEH_HTML |
|
41 | - */ |
|
42 | - public static function instance() |
|
43 | - { |
|
44 | - // check if class object is instantiated, and instantiated properly |
|
45 | - if (! self::$_instance instanceof EEH_HTML) { |
|
46 | - self::$_instance = new EEH_HTML(); |
|
47 | - } |
|
48 | - return self::$_instance; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * class constructor |
|
55 | - * |
|
56 | - * @access private |
|
57 | - * @return \EEH_HTML |
|
58 | - */ |
|
59 | - private function __construct() |
|
60 | - { |
|
61 | - // set some initial formatting for table indentation |
|
62 | - EEH_HTML::$_indent = array( |
|
63 | - 'table' => 0, |
|
64 | - 'thead' => 1, |
|
65 | - 'tbody' => 1, |
|
66 | - 'tr' => 2, |
|
67 | - 'th' => 3, |
|
68 | - 'td' => 3, |
|
69 | - 'div' => 0, |
|
70 | - 'h1' => 0, |
|
71 | - 'h2' => 0, |
|
72 | - 'h3' => 0, |
|
73 | - 'h4' => 0, |
|
74 | - 'h5' => 0, |
|
75 | - 'h6' => 0, |
|
76 | - 'p' => 0, |
|
77 | - 'ul' => 0, |
|
78 | - 'li' => 1 |
|
79 | - ); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Generates an opening HTML <XX> tag and adds any passed attributes |
|
86 | - * if passed content, it will also add that, as well as the closing </XX> tag |
|
87 | - * |
|
88 | - * @access protected |
|
89 | - * @param string $tag |
|
90 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
91 | - * @param string $id - html id attribute |
|
92 | - * @param string $class - html class attribute |
|
93 | - * @param string $style - html style attribute for applying inline styles |
|
94 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
95 | - * @param bool $force_close |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - protected static function _open_tag( |
|
99 | - $tag = 'div', |
|
100 | - $content = '', |
|
101 | - $id = '', |
|
102 | - $class = '', |
|
103 | - $style = '', |
|
104 | - $other_attributes = '', |
|
105 | - $force_close = false |
|
106 | - ) { |
|
107 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
108 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
109 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
110 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
111 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
112 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
113 | - $indent = ! empty($content) || $force_close ? true : false; |
|
114 | - $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
115 | - return $html; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
122 | - * used for the opening tag, will append a comment |
|
123 | - * |
|
22 | + /** |
|
23 | + * instance of the EEH_Autoloader object |
|
24 | + * @var $_instance |
|
25 | + * @access private |
|
26 | + */ |
|
27 | + private static $_instance; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var array $_indent |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + private static $_indent = array(); |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @singleton method used to instantiate class object |
|
39 | + * @access public |
|
40 | + * @return EEH_HTML |
|
41 | + */ |
|
42 | + public static function instance() |
|
43 | + { |
|
44 | + // check if class object is instantiated, and instantiated properly |
|
45 | + if (! self::$_instance instanceof EEH_HTML) { |
|
46 | + self::$_instance = new EEH_HTML(); |
|
47 | + } |
|
48 | + return self::$_instance; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * class constructor |
|
55 | + * |
|
56 | + * @access private |
|
57 | + * @return \EEH_HTML |
|
58 | + */ |
|
59 | + private function __construct() |
|
60 | + { |
|
61 | + // set some initial formatting for table indentation |
|
62 | + EEH_HTML::$_indent = array( |
|
63 | + 'table' => 0, |
|
64 | + 'thead' => 1, |
|
65 | + 'tbody' => 1, |
|
66 | + 'tr' => 2, |
|
67 | + 'th' => 3, |
|
68 | + 'td' => 3, |
|
69 | + 'div' => 0, |
|
70 | + 'h1' => 0, |
|
71 | + 'h2' => 0, |
|
72 | + 'h3' => 0, |
|
73 | + 'h4' => 0, |
|
74 | + 'h5' => 0, |
|
75 | + 'h6' => 0, |
|
76 | + 'p' => 0, |
|
77 | + 'ul' => 0, |
|
78 | + 'li' => 1 |
|
79 | + ); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Generates an opening HTML <XX> tag and adds any passed attributes |
|
86 | + * if passed content, it will also add that, as well as the closing </XX> tag |
|
87 | + * |
|
88 | + * @access protected |
|
89 | + * @param string $tag |
|
90 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
91 | + * @param string $id - html id attribute |
|
92 | + * @param string $class - html class attribute |
|
93 | + * @param string $style - html style attribute for applying inline styles |
|
94 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
95 | + * @param bool $force_close |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + protected static function _open_tag( |
|
99 | + $tag = 'div', |
|
100 | + $content = '', |
|
101 | + $id = '', |
|
102 | + $class = '', |
|
103 | + $style = '', |
|
104 | + $other_attributes = '', |
|
105 | + $force_close = false |
|
106 | + ) { |
|
107 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
108 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
109 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
110 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
111 | + $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
112 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
113 | + $indent = ! empty($content) || $force_close ? true : false; |
|
114 | + $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
115 | + return $html; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Generates HTML closing </XX> tag - if passed the id or class attribute |
|
122 | + * used for the opening tag, will append a comment |
|
123 | + * |
|
124 | 124 | *@access protected |
125 | - * @param string $tag |
|
126 | - * @param string $id - html id attribute |
|
127 | - * @param string $class - html class attribute |
|
128 | - * @param bool $indent |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
132 | - { |
|
133 | - $comment = ''; |
|
134 | - if ($id) { |
|
135 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
136 | - } elseif ($class) { |
|
137 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
138 | - } |
|
139 | - $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
140 | - $html .= '</' . $tag . '>' . $comment; |
|
141 | - return $html; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * div - generates HTML opening <div> tag and adds any passed attributes |
|
148 | - * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
149 | - * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
150 | - * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
151 | - * |
|
152 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
153 | - * @param string $id - html id attribute |
|
154 | - * @param string $class - html class attribute |
|
155 | - * @param string $style - html style attribute for applying inline styles |
|
156 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
160 | - { |
|
161 | - return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
168 | - * usage: echo EEH_HTML::divx(); |
|
169 | - * |
|
170 | - * @param string $id - html id attribute |
|
171 | - * @param string $class - html class attribute |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public static function divx($id = '', $class = '') |
|
175 | - { |
|
176 | - return EEH_HTML::_close_tag('div', $id, $class); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
183 | - * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
184 | - * |
|
185 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
186 | - * @param string $id - html id attribute |
|
187 | - * @param string $class - html class attribute |
|
188 | - * @param string $style - html style attribute for applying inline styles |
|
189 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
193 | - { |
|
194 | - return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
201 | - * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
202 | - * |
|
203 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
204 | - * @param string $id - html id attribute |
|
205 | - * @param string $class - html class attribute |
|
206 | - * @param string $style - html style attribute for applying inline styles |
|
207 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
211 | - { |
|
212 | - return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
219 | - * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
220 | - * |
|
221 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
222 | - * @param string $id - html id attribute |
|
223 | - * @param string $class - html class attribute |
|
224 | - * @param string $style - html style attribute for applying inline styles |
|
225 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
229 | - { |
|
230 | - return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
237 | - * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
238 | - * |
|
239 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
240 | - * @param string $id - html id attribute |
|
241 | - * @param string $class - html class attribute |
|
242 | - * @param string $style - html style attribute for applying inline styles |
|
243 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
247 | - { |
|
248 | - return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
255 | - * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
256 | - * |
|
257 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
258 | - * @param string $id - html id attribute |
|
259 | - * @param string $class - html class attribute |
|
260 | - * @param string $style - html style attribute for applying inline styles |
|
261 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
265 | - { |
|
266 | - return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
273 | - * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
274 | - * |
|
275 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
276 | - * @param string $id - html id attribute |
|
277 | - * @param string $class - html class attribute |
|
278 | - * @param string $style - html style attribute for applying inline styles |
|
279 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
283 | - { |
|
284 | - return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
291 | - * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
292 | - * |
|
293 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
294 | - * @param string $id - html id attribute |
|
295 | - * @param string $class - html class attribute |
|
296 | - * @param string $style - html style attribute for applying inline styles |
|
297 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
298 | - * @return string |
|
299 | - */ |
|
300 | - public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
301 | - { |
|
302 | - return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
309 | - * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
310 | - * |
|
311 | - * @param string $id - html id attribute |
|
312 | - * @param string $class - html class attribute |
|
313 | - * @param string $style - html style attribute for applying inline styles |
|
314 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
315 | - * @return string |
|
316 | - */ |
|
317 | - public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
318 | - { |
|
319 | - return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
326 | - * usage: echo EEH_HTML::ulx(); |
|
327 | - * |
|
328 | - * @param string $id - html id attribute |
|
329 | - * @param string $class - html class attribute |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - public static function ulx($id = '', $class = '') |
|
333 | - { |
|
334 | - return EEH_HTML::_close_tag('ul', $id, $class); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
341 | - * if passed content, it will also add that, as well as the closing </li> tag |
|
342 | - * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
343 | - * |
|
344 | - * @param string $id - html id attribute |
|
345 | - * @param string $class - html class attribute |
|
346 | - * @param string $style - html style attribute for applying inline styles |
|
347 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
348 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
349 | - * @return string |
|
350 | - */ |
|
351 | - public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
352 | - { |
|
353 | - return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
360 | - * usage: echo EEH_HTML::lix(); |
|
361 | - * |
|
362 | - * @param string $id - html id attribute |
|
363 | - * @param string $class - html class attribute |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public static function lix($id = '', $class = '') |
|
367 | - { |
|
368 | - return EEH_HTML::_close_tag('li', $id, $class); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * table - generates an HTML <table> tag and adds any passed attributes |
|
375 | - * usage: echo EEH_HTML::table(); |
|
376 | - * |
|
377 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
378 | - * @param string $id - html id attribute |
|
379 | - * @param string $class - html class attribute |
|
380 | - * @param string $style - html style attribute for applying inline styles |
|
381 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
385 | - { |
|
386 | - return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
393 | - * |
|
394 | - * @param string $id - html id attribute |
|
395 | - * @param string $class - html class attribute |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public static function tablex($id = '', $class = '') |
|
399 | - { |
|
400 | - return EEH_HTML::_close_tag('table', $id, $class); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * thead - generates an HTML <thead> tag and adds any passed attributes |
|
407 | - * usage: echo EEH_HTML::thead(); |
|
408 | - * |
|
409 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
410 | - * @param string $id - html id attribute |
|
411 | - * @param string $class - html class attribute |
|
412 | - * @param string $style - html style attribute for applying inline styles |
|
413 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
417 | - { |
|
418 | - return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
425 | - * |
|
426 | - * @param string $id - html id attribute |
|
427 | - * @param string $class - html class attribute |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public static function theadx($id = '', $class = '') |
|
431 | - { |
|
432 | - return EEH_HTML::_close_tag('thead', $id, $class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
439 | - * usage: echo EEH_HTML::tbody(); |
|
440 | - * |
|
441 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
442 | - * @param string $id - html id attribute |
|
443 | - * @param string $class - html class attribute |
|
444 | - * @param string $style - html style attribute for applying inline styles |
|
445 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
449 | - { |
|
450 | - return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
457 | - * |
|
458 | - * @param string $id - html id attribute |
|
459 | - * @param string $class - html class attribute |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public static function tbodyx($id = '', $class = '') |
|
463 | - { |
|
464 | - return EEH_HTML::_close_tag('tbody', $id, $class); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * tr - generates an HTML <tr> tag and adds any passed attributes |
|
471 | - * usage: echo EEH_HTML::tr(); |
|
472 | - * |
|
473 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
474 | - * @param string $id - html id attribute |
|
475 | - * @param string $class - html class attribute |
|
476 | - * @param string $style - html style attribute for applying inline styles |
|
477 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
481 | - { |
|
482 | - return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
489 | - * |
|
490 | - * @param string $id - html id attribute |
|
491 | - * @param string $class - html class attribute |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public static function trx($id = '', $class = '') |
|
495 | - { |
|
496 | - return EEH_HTML::_close_tag('tr', $id, $class); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * th - generates an HTML <th> tag and adds any passed attributes |
|
503 | - * usage: echo EEH_HTML::th(); |
|
504 | - * |
|
505 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
506 | - * @param string $id - html id attribute |
|
507 | - * @param string $class - html class attribute |
|
508 | - * @param string $style - html style attribute for applying inline styles |
|
509 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
510 | - * @return string |
|
511 | - */ |
|
512 | - public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
513 | - { |
|
514 | - return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
521 | - * |
|
522 | - * @param string $id - html id attribute |
|
523 | - * @param string $class - html class attribute |
|
524 | - * @return string |
|
525 | - */ |
|
526 | - public static function thx($id = '', $class = '') |
|
527 | - { |
|
528 | - return EEH_HTML::_close_tag('th', $id, $class); |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * td - generates an HTML <td> tag and adds any passed attributes |
|
535 | - * usage: echo EEH_HTML::td(); |
|
536 | - * |
|
537 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
538 | - * @param string $id - html id attribute |
|
539 | - * @param string $class - html class attribute |
|
540 | - * @param string $style - html style attribute for applying inline styles |
|
541 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
542 | - * @return string |
|
543 | - */ |
|
544 | - public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
545 | - { |
|
546 | - return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
553 | - * |
|
554 | - * @param string $id - html id attribute |
|
555 | - * @param string $class - html class attribute |
|
556 | - * @return string |
|
557 | - */ |
|
558 | - public static function tdx($id = '', $class = '') |
|
559 | - { |
|
560 | - return EEH_HTML::_close_tag('td', $id, $class); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
567 | - * generates a new table row with one td cell that spans however many columns you set |
|
568 | - * removes all styles from the tr and td |
|
569 | - * |
|
570 | - * @param string $content |
|
571 | - * @param int $colspan |
|
572 | - * @return string |
|
573 | - */ |
|
574 | - public static function no_row($content = '', $colspan = 2) |
|
575 | - { |
|
576 | - return EEH_HTML::tr( |
|
577 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
578 | - '', |
|
579 | - '', |
|
580 | - 'padding:0; border:none;' |
|
581 | - ); |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
588 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
589 | - * |
|
590 | - * @access public |
|
591 | - * @param string $href URL to link to |
|
592 | - * @param string $link_text - the text that will become "hyperlinked" |
|
593 | - * @param string $title - html title attribute |
|
594 | - * @param string $id - html id attribute |
|
595 | - * @param string $class - html class attribute |
|
596 | - * @param string $style - html style attribute for applying inline styles |
|
597 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
598 | - * @return string |
|
599 | - */ |
|
600 | - public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
601 | - { |
|
602 | - $link_text = ! empty($link_text) ? $link_text : $href; |
|
603 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
604 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
605 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
606 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
607 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
608 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
609 | - return "<a{$attributes}>{$link_text}</a>"; |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * img - generates an HTML <img> tag and adds any passed attributes |
|
616 | - * usage: echo EEH_HTML::img(); |
|
617 | - * |
|
618 | - * @param string $src - html src attribute ie: the path or URL to the image |
|
619 | - * @param string $alt - html alt attribute |
|
620 | - * @param string $id - html id attribute |
|
621 | - * @param string $class - html class attribute |
|
622 | - * @param string $style - html style attribute for applying inline styles |
|
623 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
624 | - * @return string |
|
625 | - */ |
|
626 | - public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
627 | - { |
|
628 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
629 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
630 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
631 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
632 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
633 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
634 | - return '<img' . $attributes . '/>'; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
641 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
642 | - * |
|
643 | - * @access protected |
|
644 | - * @param string $tag |
|
645 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
646 | - * @param string $id - html id attribute |
|
647 | - * @param string $class - html class attribute |
|
648 | - * @param string $style - html style attribute for applying inline styles |
|
649 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
650 | - * @return string |
|
651 | - */ |
|
652 | - protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
653 | - { |
|
654 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
655 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
656 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
657 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
658 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
665 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
666 | - * |
|
667 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
668 | - * @param string $id - html id attribute |
|
669 | - * @param string $class - html class attribute |
|
670 | - * @param string $style - html style attribute for applying inline styles |
|
671 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
675 | - { |
|
676 | - return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
683 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
684 | - * |
|
685 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
686 | - * @param string $id - html id attribute |
|
687 | - * @param string $class - html class attribute |
|
688 | - * @param string $style - html style attribute for applying inline styles |
|
689 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
693 | - { |
|
694 | - return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
701 | - * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
702 | - * |
|
703 | - * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
704 | - * @param string $id - html id attribute |
|
705 | - * @param string $class - html class attribute |
|
706 | - * @param string $style - html style attribute for applying inline styles |
|
707 | - * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
708 | - * @return string |
|
709 | - */ |
|
710 | - public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
711 | - { |
|
712 | - return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - |
|
717 | - /** |
|
718 | - * Generates an html <-- comment --> tag |
|
719 | - * usage: echo comment( 'this is a comment' ); |
|
720 | - * |
|
721 | - * @param string $comment |
|
722 | - * @return string |
|
723 | - */ |
|
724 | - public static function comment($comment = '') |
|
725 | - { |
|
726 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * br - generates a line break |
|
733 | - * |
|
734 | - * @param int $nmbr - the number of line breaks to return |
|
735 | - * @return string |
|
736 | - */ |
|
737 | - public static function br($nmbr = 1) |
|
738 | - { |
|
739 | - return str_repeat('<br />', $nmbr); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - |
|
744 | - /** |
|
745 | - * nbsp - generates non-breaking space entities based on number supplied |
|
746 | - * |
|
747 | - * @param int $nmbr - the number of non-breaking spaces to return |
|
748 | - * @return string |
|
749 | - */ |
|
750 | - public static function nbsp($nmbr = 1) |
|
751 | - { |
|
752 | - return str_repeat(' ', $nmbr); |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * sanitize_id |
|
759 | - * |
|
760 | - * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
761 | - * strtolower and allows capitals. |
|
762 | - * |
|
763 | - * @param string $id |
|
764 | - * @return string |
|
765 | - */ |
|
766 | - public static function sanitize_id($id = '') |
|
767 | - { |
|
768 | - $key = str_replace(' ', '-', trim($id)); |
|
769 | - return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * return a newline and tabs ("nl" stands for "new line") |
|
776 | - * |
|
777 | - * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
778 | - * @param string $tag |
|
779 | - * @return string - newline character plus # of indents passed (can be + or -) |
|
780 | - */ |
|
781 | - public static function nl($indent = 0, $tag = 'none') |
|
782 | - { |
|
783 | - $html = "\n"; |
|
784 | - EEH_HTML::indent($indent, $tag); |
|
785 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
786 | - $html .= "\t"; |
|
787 | - } |
|
788 | - return $html; |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
795 | - * the indentation level without actually creating a new line |
|
796 | - * |
|
797 | - * @param int $indent can be negative to decrease the indentation level |
|
798 | - * @param string $tag |
|
799 | - */ |
|
800 | - public static function indent($indent, $tag = 'none') |
|
801 | - { |
|
802 | - static $default_indentation = false; |
|
803 | - if (! $default_indentation) { |
|
804 | - EEH_HTML::_set_default_indentation(); |
|
805 | - $default_indentation = true; |
|
806 | - } |
|
807 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
808 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
809 | - } |
|
810 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
811 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * class _set_default_indentation |
|
817 | - * |
|
818 | - * @access private |
|
819 | - */ |
|
820 | - private static function _set_default_indentation() |
|
821 | - { |
|
822 | - // set some initial formatting for table indentation |
|
823 | - EEH_HTML::$_indent = array( |
|
824 | - 'none' => 0, |
|
825 | - 'form' => 0, |
|
826 | - 'radio' => 0, |
|
827 | - 'checkbox' => 0, |
|
828 | - 'select' => 0, |
|
829 | - 'option' => 0, |
|
830 | - 'optgroup' => 0, |
|
831 | - 'table' => 1, |
|
832 | - 'thead' => 2, |
|
833 | - 'tbody' => 2, |
|
834 | - 'tr' => 3, |
|
835 | - 'th' => 4, |
|
836 | - 'td' => 4, |
|
837 | - 'div' => 0, |
|
838 | - 'h1' => 0, |
|
839 | - 'h2' => 0, |
|
840 | - 'h3' => 0, |
|
841 | - 'h4' => 0, |
|
842 | - 'h5' => 0, |
|
843 | - 'h6' => 0, |
|
844 | - 'p' => 0, |
|
845 | - 'ul' => 0, |
|
846 | - 'li' => 1 |
|
847 | - ); |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * Retrieves the list of tags considered "simple", that are probably safe for |
|
854 | - * use in inputs |
|
855 | - * @global array $allowedtags |
|
856 | - * @return array |
|
857 | - */ |
|
858 | - public static function get_simple_tags() |
|
859 | - { |
|
860 | - global $allowedtags; |
|
861 | - $tags_we_allow['p']=array(); |
|
862 | - $tags_we_allow = array_merge_recursive( |
|
863 | - $allowedtags, |
|
864 | - array( |
|
865 | - 'ol' => array(), |
|
866 | - 'ul' => array(), |
|
867 | - 'li' => array(), |
|
868 | - 'br' => array(), |
|
869 | - 'p' => array(), |
|
870 | - 'a' => array('target') |
|
871 | - ) |
|
872 | - ); |
|
873 | - return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
874 | - } |
|
125 | + * @param string $tag |
|
126 | + * @param string $id - html id attribute |
|
127 | + * @param string $class - html class attribute |
|
128 | + * @param bool $indent |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true) |
|
132 | + { |
|
133 | + $comment = ''; |
|
134 | + if ($id) { |
|
135 | + $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
136 | + } elseif ($class) { |
|
137 | + $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
138 | + } |
|
139 | + $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
|
140 | + $html .= '</' . $tag . '>' . $comment; |
|
141 | + return $html; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * div - generates HTML opening <div> tag and adds any passed attributes |
|
148 | + * to add an id use: echo EEH_HTML::div( 'this is some content', 'footer' ); |
|
149 | + * to add a class use: echo EEH_HTML::div( 'this is some content', '', 'float_left' ); |
|
150 | + * to add a both an id and a class use: echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' ); |
|
151 | + * |
|
152 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
153 | + * @param string $id - html id attribute |
|
154 | + * @param string $class - html class attribute |
|
155 | + * @param string $style - html style attribute for applying inline styles |
|
156 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
160 | + { |
|
161 | + return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment |
|
168 | + * usage: echo EEH_HTML::divx(); |
|
169 | + * |
|
170 | + * @param string $id - html id attribute |
|
171 | + * @param string $class - html class attribute |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public static function divx($id = '', $class = '') |
|
175 | + { |
|
176 | + return EEH_HTML::_close_tag('div', $id, $class); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes |
|
183 | + * usage: echo EEH_HTML::h1( 'This is a Heading' ); |
|
184 | + * |
|
185 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
186 | + * @param string $id - html id attribute |
|
187 | + * @param string $class - html class attribute |
|
188 | + * @param string $style - html style attribute for applying inline styles |
|
189 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
193 | + { |
|
194 | + return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true); |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes |
|
201 | + * usage: echo EEH_HTML::h2( 'This is a Heading' ); |
|
202 | + * |
|
203 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
204 | + * @param string $id - html id attribute |
|
205 | + * @param string $class - html class attribute |
|
206 | + * @param string $style - html style attribute for applying inline styles |
|
207 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
211 | + { |
|
212 | + return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes |
|
219 | + * usage: echo EEH_HTML::h3( 'This is a Heading' ); |
|
220 | + * |
|
221 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
222 | + * @param string $id - html id attribute |
|
223 | + * @param string $class - html class attribute |
|
224 | + * @param string $style - html style attribute for applying inline styles |
|
225 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
229 | + { |
|
230 | + return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes |
|
237 | + * usage: echo EEH_HTML::h4( 'This is a Heading' ); |
|
238 | + * |
|
239 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
240 | + * @param string $id - html id attribute |
|
241 | + * @param string $class - html class attribute |
|
242 | + * @param string $style - html style attribute for applying inline styles |
|
243 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
247 | + { |
|
248 | + return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes |
|
255 | + * usage: echo EEH_HTML::h5( 'This is a Heading' ); |
|
256 | + * |
|
257 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
258 | + * @param string $id - html id attribute |
|
259 | + * @param string $class - html class attribute |
|
260 | + * @param string $style - html style attribute for applying inline styles |
|
261 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
265 | + { |
|
266 | + return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes |
|
273 | + * usage: echo EEH_HTML::h6( 'This is a Heading' ); |
|
274 | + * |
|
275 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
276 | + * @param string $id - html id attribute |
|
277 | + * @param string $class - html class attribute |
|
278 | + * @param string $style - html style attribute for applying inline styles |
|
279 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
283 | + { |
|
284 | + return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Generates HTML <p></p> tags, inserts content, and adds any passed attributes |
|
291 | + * usage: echo EEH_HTML::p( 'this is a paragraph' ); |
|
292 | + * |
|
293 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
294 | + * @param string $id - html id attribute |
|
295 | + * @param string $class - html class attribute |
|
296 | + * @param string $style - html style attribute for applying inline styles |
|
297 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
298 | + * @return string |
|
299 | + */ |
|
300 | + public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
301 | + { |
|
302 | + return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true); |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * ul - generates HTML opening <ul> tag and adds any passed attributes |
|
309 | + * usage: echo EEH_HTML::ul( 'my-list-id', 'my-list-class' ); |
|
310 | + * |
|
311 | + * @param string $id - html id attribute |
|
312 | + * @param string $class - html class attribute |
|
313 | + * @param string $style - html style attribute for applying inline styles |
|
314 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
315 | + * @return string |
|
316 | + */ |
|
317 | + public static function ul($id = '', $class = '', $style = '', $other_attributes = '') |
|
318 | + { |
|
319 | + return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
326 | + * usage: echo EEH_HTML::ulx(); |
|
327 | + * |
|
328 | + * @param string $id - html id attribute |
|
329 | + * @param string $class - html class attribute |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + public static function ulx($id = '', $class = '') |
|
333 | + { |
|
334 | + return EEH_HTML::_close_tag('ul', $id, $class); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Generates HTML <li> tag, inserts content, and adds any passed attributes |
|
341 | + * if passed content, it will also add that, as well as the closing </li> tag |
|
342 | + * usage: echo EEH_HTML::li( 'this is a line item' ); |
|
343 | + * |
|
344 | + * @param string $id - html id attribute |
|
345 | + * @param string $class - html class attribute |
|
346 | + * @param string $style - html style attribute for applying inline styles |
|
347 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
348 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
349 | + * @return string |
|
350 | + */ |
|
351 | + public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
352 | + { |
|
353 | + return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
360 | + * usage: echo EEH_HTML::lix(); |
|
361 | + * |
|
362 | + * @param string $id - html id attribute |
|
363 | + * @param string $class - html class attribute |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public static function lix($id = '', $class = '') |
|
367 | + { |
|
368 | + return EEH_HTML::_close_tag('li', $id, $class); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * table - generates an HTML <table> tag and adds any passed attributes |
|
375 | + * usage: echo EEH_HTML::table(); |
|
376 | + * |
|
377 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
378 | + * @param string $id - html id attribute |
|
379 | + * @param string $class - html class attribute |
|
380 | + * @param string $style - html style attribute for applying inline styles |
|
381 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
385 | + { |
|
386 | + return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
393 | + * |
|
394 | + * @param string $id - html id attribute |
|
395 | + * @param string $class - html class attribute |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public static function tablex($id = '', $class = '') |
|
399 | + { |
|
400 | + return EEH_HTML::_close_tag('table', $id, $class); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * thead - generates an HTML <thead> tag and adds any passed attributes |
|
407 | + * usage: echo EEH_HTML::thead(); |
|
408 | + * |
|
409 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
410 | + * @param string $id - html id attribute |
|
411 | + * @param string $class - html class attribute |
|
412 | + * @param string $style - html style attribute for applying inline styles |
|
413 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
417 | + { |
|
418 | + return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
425 | + * |
|
426 | + * @param string $id - html id attribute |
|
427 | + * @param string $class - html class attribute |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public static function theadx($id = '', $class = '') |
|
431 | + { |
|
432 | + return EEH_HTML::_close_tag('thead', $id, $class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * tbody - generates an HTML <tbody> tag and adds any passed attributes |
|
439 | + * usage: echo EEH_HTML::tbody(); |
|
440 | + * |
|
441 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
442 | + * @param string $id - html id attribute |
|
443 | + * @param string $class - html class attribute |
|
444 | + * @param string $style - html style attribute for applying inline styles |
|
445 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
449 | + { |
|
450 | + return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
457 | + * |
|
458 | + * @param string $id - html id attribute |
|
459 | + * @param string $class - html class attribute |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public static function tbodyx($id = '', $class = '') |
|
463 | + { |
|
464 | + return EEH_HTML::_close_tag('tbody', $id, $class); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * tr - generates an HTML <tr> tag and adds any passed attributes |
|
471 | + * usage: echo EEH_HTML::tr(); |
|
472 | + * |
|
473 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
474 | + * @param string $id - html id attribute |
|
475 | + * @param string $class - html class attribute |
|
476 | + * @param string $style - html style attribute for applying inline styles |
|
477 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
481 | + { |
|
482 | + return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
489 | + * |
|
490 | + * @param string $id - html id attribute |
|
491 | + * @param string $class - html class attribute |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public static function trx($id = '', $class = '') |
|
495 | + { |
|
496 | + return EEH_HTML::_close_tag('tr', $id, $class); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * th - generates an HTML <th> tag and adds any passed attributes |
|
503 | + * usage: echo EEH_HTML::th(); |
|
504 | + * |
|
505 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
506 | + * @param string $id - html id attribute |
|
507 | + * @param string $class - html class attribute |
|
508 | + * @param string $style - html style attribute for applying inline styles |
|
509 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
510 | + * @return string |
|
511 | + */ |
|
512 | + public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
513 | + { |
|
514 | + return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
521 | + * |
|
522 | + * @param string $id - html id attribute |
|
523 | + * @param string $class - html class attribute |
|
524 | + * @return string |
|
525 | + */ |
|
526 | + public static function thx($id = '', $class = '') |
|
527 | + { |
|
528 | + return EEH_HTML::_close_tag('th', $id, $class); |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * td - generates an HTML <td> tag and adds any passed attributes |
|
535 | + * usage: echo EEH_HTML::td(); |
|
536 | + * |
|
537 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
538 | + * @param string $id - html id attribute |
|
539 | + * @param string $class - html class attribute |
|
540 | + * @param string $style - html style attribute for applying inline styles |
|
541 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
542 | + * @return string |
|
543 | + */ |
|
544 | + public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
545 | + { |
|
546 | + return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment |
|
553 | + * |
|
554 | + * @param string $id - html id attribute |
|
555 | + * @param string $class - html class attribute |
|
556 | + * @return string |
|
557 | + */ |
|
558 | + public static function tdx($id = '', $class = '') |
|
559 | + { |
|
560 | + return EEH_HTML::_close_tag('td', $id, $class); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * no_row - for generating a "hidden" table row, good for embedding tables within tables |
|
567 | + * generates a new table row with one td cell that spans however many columns you set |
|
568 | + * removes all styles from the tr and td |
|
569 | + * |
|
570 | + * @param string $content |
|
571 | + * @param int $colspan |
|
572 | + * @return string |
|
573 | + */ |
|
574 | + public static function no_row($content = '', $colspan = 2) |
|
575 | + { |
|
576 | + return EEH_HTML::tr( |
|
577 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
578 | + '', |
|
579 | + '', |
|
580 | + 'padding:0; border:none;' |
|
581 | + ); |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
588 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
589 | + * |
|
590 | + * @access public |
|
591 | + * @param string $href URL to link to |
|
592 | + * @param string $link_text - the text that will become "hyperlinked" |
|
593 | + * @param string $title - html title attribute |
|
594 | + * @param string $id - html id attribute |
|
595 | + * @param string $class - html class attribute |
|
596 | + * @param string $style - html style attribute for applying inline styles |
|
597 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
598 | + * @return string |
|
599 | + */ |
|
600 | + public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
601 | + { |
|
602 | + $link_text = ! empty($link_text) ? $link_text : $href; |
|
603 | + $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
604 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
605 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
606 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
607 | + $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
608 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
609 | + return "<a{$attributes}>{$link_text}</a>"; |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * img - generates an HTML <img> tag and adds any passed attributes |
|
616 | + * usage: echo EEH_HTML::img(); |
|
617 | + * |
|
618 | + * @param string $src - html src attribute ie: the path or URL to the image |
|
619 | + * @param string $alt - html alt attribute |
|
620 | + * @param string $id - html id attribute |
|
621 | + * @param string $class - html class attribute |
|
622 | + * @param string $style - html style attribute for applying inline styles |
|
623 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
624 | + * @return string |
|
625 | + */ |
|
626 | + public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
627 | + { |
|
628 | + $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
629 | + $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
630 | + $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
631 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
632 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
633 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
634 | + return '<img' . $attributes . '/>'; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
641 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
642 | + * |
|
643 | + * @access protected |
|
644 | + * @param string $tag |
|
645 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
646 | + * @param string $id - html id attribute |
|
647 | + * @param string $class - html class attribute |
|
648 | + * @param string $style - html style attribute for applying inline styles |
|
649 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
650 | + * @return string |
|
651 | + */ |
|
652 | + protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
653 | + { |
|
654 | + $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
655 | + $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
656 | + $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
657 | + $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
658 | + return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Generates HTML <label></label> tags, inserts content, and adds any passed attributes |
|
665 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
666 | + * |
|
667 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
668 | + * @param string $id - html id attribute |
|
669 | + * @param string $class - html class attribute |
|
670 | + * @param string $style - html style attribute for applying inline styles |
|
671 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
675 | + { |
|
676 | + return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
683 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
684 | + * |
|
685 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
686 | + * @param string $id - html id attribute |
|
687 | + * @param string $class - html class attribute |
|
688 | + * @param string $style - html style attribute for applying inline styles |
|
689 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
693 | + { |
|
694 | + return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * Generates HTML <span></span> tags, inserts content, and adds any passed attributes |
|
701 | + * usage: echo EEH_HTML::span( 'this is some inline text' ); |
|
702 | + * |
|
703 | + * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open |
|
704 | + * @param string $id - html id attribute |
|
705 | + * @param string $class - html class attribute |
|
706 | + * @param string $style - html style attribute for applying inline styles |
|
707 | + * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
|
708 | + * @return string |
|
709 | + */ |
|
710 | + public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
|
711 | + { |
|
712 | + return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + |
|
717 | + /** |
|
718 | + * Generates an html <-- comment --> tag |
|
719 | + * usage: echo comment( 'this is a comment' ); |
|
720 | + * |
|
721 | + * @param string $comment |
|
722 | + * @return string |
|
723 | + */ |
|
724 | + public static function comment($comment = '') |
|
725 | + { |
|
726 | + return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * br - generates a line break |
|
733 | + * |
|
734 | + * @param int $nmbr - the number of line breaks to return |
|
735 | + * @return string |
|
736 | + */ |
|
737 | + public static function br($nmbr = 1) |
|
738 | + { |
|
739 | + return str_repeat('<br />', $nmbr); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + |
|
744 | + /** |
|
745 | + * nbsp - generates non-breaking space entities based on number supplied |
|
746 | + * |
|
747 | + * @param int $nmbr - the number of non-breaking spaces to return |
|
748 | + * @return string |
|
749 | + */ |
|
750 | + public static function nbsp($nmbr = 1) |
|
751 | + { |
|
752 | + return str_repeat(' ', $nmbr); |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * sanitize_id |
|
759 | + * |
|
760 | + * functionally does the same as the wp_core function sanitize_key except it does NOT use |
|
761 | + * strtolower and allows capitals. |
|
762 | + * |
|
763 | + * @param string $id |
|
764 | + * @return string |
|
765 | + */ |
|
766 | + public static function sanitize_id($id = '') |
|
767 | + { |
|
768 | + $key = str_replace(' ', '-', trim($id)); |
|
769 | + return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * return a newline and tabs ("nl" stands for "new line") |
|
776 | + * |
|
777 | + * @param int $indent the number of tabs to ADD to the current indent (can be negative or zero) |
|
778 | + * @param string $tag |
|
779 | + * @return string - newline character plus # of indents passed (can be + or -) |
|
780 | + */ |
|
781 | + public static function nl($indent = 0, $tag = 'none') |
|
782 | + { |
|
783 | + $html = "\n"; |
|
784 | + EEH_HTML::indent($indent, $tag); |
|
785 | + for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
786 | + $html .= "\t"; |
|
787 | + } |
|
788 | + return $html; |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * Changes the indents used in EEH_HTML::nl. Often its convenient to change |
|
795 | + * the indentation level without actually creating a new line |
|
796 | + * |
|
797 | + * @param int $indent can be negative to decrease the indentation level |
|
798 | + * @param string $tag |
|
799 | + */ |
|
800 | + public static function indent($indent, $tag = 'none') |
|
801 | + { |
|
802 | + static $default_indentation = false; |
|
803 | + if (! $default_indentation) { |
|
804 | + EEH_HTML::_set_default_indentation(); |
|
805 | + $default_indentation = true; |
|
806 | + } |
|
807 | + if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
808 | + EEH_HTML::$_indent[ $tag ] = 0; |
|
809 | + } |
|
810 | + EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
811 | + EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * class _set_default_indentation |
|
817 | + * |
|
818 | + * @access private |
|
819 | + */ |
|
820 | + private static function _set_default_indentation() |
|
821 | + { |
|
822 | + // set some initial formatting for table indentation |
|
823 | + EEH_HTML::$_indent = array( |
|
824 | + 'none' => 0, |
|
825 | + 'form' => 0, |
|
826 | + 'radio' => 0, |
|
827 | + 'checkbox' => 0, |
|
828 | + 'select' => 0, |
|
829 | + 'option' => 0, |
|
830 | + 'optgroup' => 0, |
|
831 | + 'table' => 1, |
|
832 | + 'thead' => 2, |
|
833 | + 'tbody' => 2, |
|
834 | + 'tr' => 3, |
|
835 | + 'th' => 4, |
|
836 | + 'td' => 4, |
|
837 | + 'div' => 0, |
|
838 | + 'h1' => 0, |
|
839 | + 'h2' => 0, |
|
840 | + 'h3' => 0, |
|
841 | + 'h4' => 0, |
|
842 | + 'h5' => 0, |
|
843 | + 'h6' => 0, |
|
844 | + 'p' => 0, |
|
845 | + 'ul' => 0, |
|
846 | + 'li' => 1 |
|
847 | + ); |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * Retrieves the list of tags considered "simple", that are probably safe for |
|
854 | + * use in inputs |
|
855 | + * @global array $allowedtags |
|
856 | + * @return array |
|
857 | + */ |
|
858 | + public static function get_simple_tags() |
|
859 | + { |
|
860 | + global $allowedtags; |
|
861 | + $tags_we_allow['p']=array(); |
|
862 | + $tags_we_allow = array_merge_recursive( |
|
863 | + $allowedtags, |
|
864 | + array( |
|
865 | + 'ol' => array(), |
|
866 | + 'ul' => array(), |
|
867 | + 'li' => array(), |
|
868 | + 'br' => array(), |
|
869 | + 'p' => array(), |
|
870 | + 'a' => array('target') |
|
871 | + ) |
|
872 | + ); |
|
873 | + return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow); |
|
874 | + } |
|
875 | 875 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public static function instance() |
43 | 43 | { |
44 | 44 | // check if class object is instantiated, and instantiated properly |
45 | - if (! self::$_instance instanceof EEH_HTML) { |
|
45 | + if ( ! self::$_instance instanceof EEH_HTML) { |
|
46 | 46 | self::$_instance = new EEH_HTML(); |
47 | 47 | } |
48 | 48 | return self::$_instance; |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | $other_attributes = '', |
105 | 105 | $force_close = false |
106 | 106 | ) { |
107 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
108 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
109 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
110 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
111 | - $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>'; |
|
112 | - $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : ''; |
|
107 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
108 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
109 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
110 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
111 | + $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>'; |
|
112 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : ''; |
|
113 | 113 | $indent = ! empty($content) || $force_close ? true : false; |
114 | 114 | $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
115 | 115 | return $html; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | { |
133 | 133 | $comment = ''; |
134 | 134 | if ($id) { |
135 | - $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag); |
|
135 | + $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag); |
|
136 | 136 | } elseif ($class) { |
137 | - $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag); |
|
137 | + $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag); |
|
138 | 138 | } |
139 | 139 | $html = $indent ? EEH_HTML::nl(-1, $tag) : ''; |
140 | - $html .= '</' . $tag . '>' . $comment; |
|
140 | + $html .= '</'.$tag.'>'.$comment; |
|
141 | 141 | return $html; |
142 | 142 | } |
143 | 143 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | public static function no_row($content = '', $colspan = 2) |
575 | 575 | { |
576 | 576 | return EEH_HTML::tr( |
577 | - EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'), |
|
577 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'), |
|
578 | 578 | '', |
579 | 579 | '', |
580 | 580 | 'padding:0; border:none;' |
@@ -600,12 +600,12 @@ discard block |
||
600 | 600 | public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') |
601 | 601 | { |
602 | 602 | $link_text = ! empty($link_text) ? $link_text : $href; |
603 | - $attributes = ! empty($href) ? ' href="' . $href . '"' : ''; |
|
604 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
605 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
606 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
607 | - $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : ''; |
|
608 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
603 | + $attributes = ! empty($href) ? ' href="'.$href.'"' : ''; |
|
604 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
605 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
606 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
607 | + $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : ''; |
|
608 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
609 | 609 | return "<a{$attributes}>{$link_text}</a>"; |
610 | 610 | } |
611 | 611 | |
@@ -625,13 +625,13 @@ discard block |
||
625 | 625 | */ |
626 | 626 | public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') |
627 | 627 | { |
628 | - $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : ''; |
|
629 | - $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : ''; |
|
630 | - $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
631 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
632 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
633 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
634 | - return '<img' . $attributes . '/>'; |
|
628 | + $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : ''; |
|
629 | + $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : ''; |
|
630 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
631 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
632 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
633 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
634 | + return '<img'.$attributes.'/>'; |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | |
@@ -651,11 +651,11 @@ discard block |
||
651 | 651 | */ |
652 | 652 | protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') |
653 | 653 | { |
654 | - $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : ''; |
|
655 | - $attributes .= ! empty($class) ? ' class="' . $class . '"' : ''; |
|
656 | - $attributes .= ! empty($style) ? ' style="' . $style . '"' : ''; |
|
657 | - $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : ''; |
|
658 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
654 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
655 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
656 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
657 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
658 | + return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>'; |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | */ |
724 | 724 | public static function comment($comment = '') |
725 | 725 | { |
726 | - return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
726 | + return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : ''; |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | { |
783 | 783 | $html = "\n"; |
784 | 784 | EEH_HTML::indent($indent, $tag); |
785 | - for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) { |
|
785 | + for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { |
|
786 | 786 | $html .= "\t"; |
787 | 787 | } |
788 | 788 | return $html; |
@@ -800,15 +800,15 @@ discard block |
||
800 | 800 | public static function indent($indent, $tag = 'none') |
801 | 801 | { |
802 | 802 | static $default_indentation = false; |
803 | - if (! $default_indentation) { |
|
803 | + if ( ! $default_indentation) { |
|
804 | 804 | EEH_HTML::_set_default_indentation(); |
805 | 805 | $default_indentation = true; |
806 | 806 | } |
807 | - if (! isset(EEH_HTML::$_indent[ $tag ])) { |
|
808 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
807 | + if ( ! isset(EEH_HTML::$_indent[$tag])) { |
|
808 | + EEH_HTML::$_indent[$tag] = 0; |
|
809 | 809 | } |
810 | - EEH_HTML::$_indent[ $tag ] += (int) $indent; |
|
811 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
810 | + EEH_HTML::$_indent[$tag] += (int) $indent; |
|
811 | + EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0; |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | public static function get_simple_tags() |
859 | 859 | { |
860 | 860 | global $allowedtags; |
861 | - $tags_we_allow['p']=array(); |
|
861 | + $tags_we_allow['p'] = array(); |
|
862 | 862 | $tags_we_allow = array_merge_recursive( |
863 | 863 | $allowedtags, |
864 | 864 | array( |
@@ -3,4 +3,4 @@ |
||
3 | 3 | * @var EE_Checkbox_Multi_Input $input |
4 | 4 | */ |
5 | 5 | ?> |
6 | -<div class="ee-privacy-consent-assertion"><?php echo $input->get_html_for_input();?></div> |
|
6 | +<div class="ee-privacy-consent-assertion"><?php echo $input->get_html_for_input(); ?></div> |
@@ -14,62 +14,62 @@ |
||
14 | 14 | class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param null $validation_error_message |
|
19 | - */ |
|
20 | - public function __construct($validation_error_message = null) |
|
21 | - { |
|
22 | - if (! $validation_error_message) { |
|
23 | - $validation_error_message = sprintf( |
|
24 | - __('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
25 | - '<br />', |
|
26 | - $this->get_list_of_allowed_tags() |
|
27 | - ); |
|
28 | - } |
|
29 | - parent::__construct($validation_error_message); |
|
30 | - } |
|
17 | + /** |
|
18 | + * @param null $validation_error_message |
|
19 | + */ |
|
20 | + public function __construct($validation_error_message = null) |
|
21 | + { |
|
22 | + if (! $validation_error_message) { |
|
23 | + $validation_error_message = sprintf( |
|
24 | + __('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
25 | + '<br />', |
|
26 | + $this->get_list_of_allowed_tags() |
|
27 | + ); |
|
28 | + } |
|
29 | + parent::__construct($validation_error_message); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * get_list_of_allowed_tags |
|
35 | - * |
|
36 | - * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function get_list_of_allowed_tags() |
|
41 | - { |
|
42 | - $tags_we_allow = $this->getAllowedTags(); |
|
43 | - ksort($tags_we_allow); |
|
44 | - return implode(', ', array_keys($tags_we_allow)); |
|
45 | - } |
|
33 | + /** |
|
34 | + * get_list_of_allowed_tags |
|
35 | + * |
|
36 | + * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function get_list_of_allowed_tags() |
|
41 | + { |
|
42 | + $tags_we_allow = $this->getAllowedTags(); |
|
43 | + ksort($tags_we_allow); |
|
44 | + return implode(', ', array_keys($tags_we_allow)); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Returns an array whose keys are allowed tags and values are an array of allowed attributes |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - protected function getAllowedTags() |
|
54 | - { |
|
55 | - global $allowedposttags; |
|
56 | - return array_merge_recursive( |
|
57 | - $allowedposttags, |
|
58 | - EEH_HTML::get_simple_tags() |
|
59 | - ); |
|
60 | - } |
|
48 | + /** |
|
49 | + * Returns an array whose keys are allowed tags and values are an array of allowed attributes |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + protected function getAllowedTags() |
|
54 | + { |
|
55 | + global $allowedposttags; |
|
56 | + return array_merge_recursive( |
|
57 | + $allowedposttags, |
|
58 | + EEH_HTML::get_simple_tags() |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param $normalized_value |
|
65 | - * @throws \EE_Validation_Error |
|
66 | - */ |
|
67 | - public function validate($normalized_value) |
|
68 | - { |
|
69 | - parent::validate($normalized_value); |
|
70 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $this->getAllowedTags()); |
|
71 | - if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
72 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
73 | - } |
|
74 | - } |
|
63 | + /** |
|
64 | + * @param $normalized_value |
|
65 | + * @throws \EE_Validation_Error |
|
66 | + */ |
|
67 | + public function validate($normalized_value) |
|
68 | + { |
|
69 | + parent::validate($normalized_value); |
|
70 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $this->getAllowedTags()); |
|
71 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
72 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = sprintf( |
24 | 24 | __('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
25 | 25 | '<br />', |
@@ -18,1423 +18,1423 @@ |
||
18 | 18 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @type bool $_print_copy_info |
|
23 | - */ |
|
24 | - private $_print_copy_info = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type array $_attendee_data |
|
28 | - */ |
|
29 | - private $_attendee_data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @type array $_required_questions |
|
33 | - */ |
|
34 | - private $_required_questions = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * @type array $_registration_answers |
|
38 | - */ |
|
39 | - private $_registration_answers = array(); |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * class constructor |
|
44 | - * |
|
45 | - * @access public |
|
46 | - * @param EE_Checkout $checkout |
|
47 | - */ |
|
48 | - public function __construct(EE_Checkout $checkout) |
|
49 | - { |
|
50 | - $this->_slug = 'attendee_information'; |
|
51 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
52 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
53 | - $this->checkout = $checkout; |
|
54 | - $this->_reset_success_message(); |
|
55 | - $this->set_instructions( |
|
56 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
57 | - ); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - public function translate_js_strings() |
|
62 | - { |
|
63 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
64 | - ' is a required question.', |
|
65 | - 'event_espresso' |
|
66 | - ); |
|
67 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
68 | - ' is a required question. Please enter a value for at least one of the options.', |
|
69 | - 'event_espresso' |
|
70 | - ); |
|
71 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
72 | - 'Please answer all required questions correctly before proceeding.', |
|
73 | - 'event_espresso' |
|
74 | - ); |
|
75 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
76 | - esc_html_x( |
|
77 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
78 | - 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - '<br/>' |
|
82 | - ); |
|
83 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
84 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
85 | - 'event_espresso' |
|
86 | - ); |
|
87 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
88 | - 'You must enter a valid email address.', |
|
89 | - 'event_espresso' |
|
90 | - ); |
|
91 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
92 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
93 | - 'event_espresso' |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - public function enqueue_styles_and_scripts() |
|
99 | - { |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return boolean |
|
105 | - */ |
|
106 | - public function initialize_reg_step() |
|
107 | - { |
|
108 | - return true; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return EE_Form_Section_Proper |
|
114 | - * @throws DomainException |
|
115 | - * @throws EE_Error |
|
116 | - * @throws InvalidArgumentException |
|
117 | - * @throws ReflectionException |
|
118 | - * @throws EntityNotFoundException |
|
119 | - * @throws InvalidDataTypeException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - */ |
|
122 | - public function generate_reg_form() |
|
123 | - { |
|
124 | - $this->_print_copy_info = false; |
|
125 | - $primary_registrant = null; |
|
126 | - // autoload Line_Item_Display classes |
|
127 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
128 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
129 | - // calculate taxes |
|
130 | - $Line_Item_Display->display_line_item( |
|
131 | - $this->checkout->cart->get_grand_total(), |
|
132 | - array('set_tax_rate' => true) |
|
133 | - ); |
|
134 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
135 | - $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
136 | - $subsections = array( |
|
137 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
138 | - ); |
|
139 | - |
|
140 | - /** |
|
141 | - * @var $reg_config EE_Registration_Config |
|
142 | - */ |
|
143 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
144 | - // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
145 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
146 | - $extra_inputs_section->add_subsections( |
|
147 | - array( |
|
148 | - 'consent_box' => new EE_Form_Section_Proper( |
|
149 | - array( |
|
150 | - 'layout_strategy' => |
|
151 | - new EE_Template_Layout( |
|
152 | - array( |
|
153 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . DS . 'privacy_consent.template.php', |
|
154 | - ) |
|
155 | - ), |
|
156 | - 'subsections' => array( |
|
157 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
158 | - array( |
|
159 | - 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
160 | - ), |
|
161 | - array( |
|
162 | - 'required' => true, |
|
163 | - 'required_validation_error_message' => esc_html__( |
|
164 | - 'You must consent to these terms in order to register.', |
|
165 | - 'event_espresso' |
|
166 | - ), |
|
167 | - 'html_label_text' => '', |
|
168 | - ) |
|
169 | - ), |
|
170 | - ), |
|
171 | - ) |
|
172 | - ), |
|
173 | - ), |
|
174 | - null, |
|
175 | - false |
|
176 | - ); |
|
177 | - } |
|
178 | - $template_args = array( |
|
179 | - 'revisit' => $this->checkout->revisit, |
|
180 | - 'registrations' => array(), |
|
181 | - 'ticket_count' => array(), |
|
182 | - ); |
|
183 | - // grab the saved registrations from the transaction |
|
184 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
185 | - if ($registrations) { |
|
186 | - foreach ($registrations as $registration) { |
|
187 | - // can this registration be processed during this visit ? |
|
188 | - if ($registration instanceof EE_Registration |
|
189 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
190 | - ) { |
|
191 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
192 | - if (! $this->checkout->admin_request) { |
|
193 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
194 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
195 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
196 | - ) |
|
197 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
198 | - : 1; |
|
199 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
200 | - $this->checkout->cart->get_grand_total(), |
|
201 | - 'Ticket', |
|
202 | - array($registration->ticket()->ID()) |
|
203 | - ); |
|
204 | - $ticket_line_item = is_array($ticket_line_item) |
|
205 | - ? reset($ticket_line_item) |
|
206 | - : $ticket_line_item; |
|
207 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
208 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
209 | - } |
|
210 | - if ($registration->is_primary_registrant()) { |
|
211 | - $primary_registrant = $registration->reg_url_link(); |
|
212 | - } |
|
213 | - } |
|
214 | - } |
|
215 | - // print_copy_info ? |
|
216 | - if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
217 | - // TODO: add admin option for toggling copy attendee info, |
|
218 | - // then use that value to change $this->_print_copy_info |
|
219 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
220 | - ? $this->_copy_attendee_info_form() |
|
221 | - : $this->_auto_copy_attendee_info(); |
|
222 | - // generate hidden input |
|
223 | - if (isset($subsections[ $primary_registrant ]) |
|
224 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
225 | - ) { |
|
226 | - $subsections[ $primary_registrant ]->add_subsections( |
|
227 | - $copy_options, |
|
228 | - 'primary_registrant', |
|
229 | - false |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - return new EE_Form_Section_Proper( |
|
235 | - array( |
|
236 | - 'name' => $this->reg_form_name(), |
|
237 | - 'html_id' => $this->reg_form_name(), |
|
238 | - 'subsections' => $subsections, |
|
239 | - 'layout_strategy' => $this->checkout->admin_request |
|
240 | - ? |
|
241 | - new EE_Div_Per_Section_Layout() |
|
242 | - : |
|
243 | - new EE_Template_Layout( |
|
244 | - array( |
|
245 | - 'layout_template_file' => $this->_template, // layout_template |
|
246 | - 'template_args' => $template_args, |
|
247 | - ) |
|
248 | - ), |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param EE_Registration $registration |
|
256 | - * @return EE_Form_Section_Base |
|
257 | - * @throws EE_Error |
|
258 | - * @throws InvalidArgumentException |
|
259 | - * @throws EntityNotFoundException |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidInterfaceException |
|
262 | - * @throws ReflectionException |
|
263 | - */ |
|
264 | - private function _registrations_reg_form(EE_Registration $registration) |
|
265 | - { |
|
266 | - static $attendee_nmbr = 1; |
|
267 | - $form_args = array(); |
|
268 | - // verify that registration has valid event |
|
269 | - if ($registration->event() instanceof EE_Event) { |
|
270 | - $question_groups = $registration->event()->question_groups( |
|
271 | - apply_filters( |
|
272 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
273 | - array( |
|
274 | - array( |
|
275 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
276 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1, |
|
277 | - ), |
|
278 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
279 | - ), |
|
280 | - $registration, |
|
281 | - $this |
|
282 | - ) |
|
283 | - ); |
|
284 | - if ($question_groups) { |
|
285 | - // array of params to pass to parent constructor |
|
286 | - $form_args = array( |
|
287 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
288 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
289 | - 'html_style' => $this->checkout->admin_request |
|
290 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
291 | - : '', |
|
292 | - 'subsections' => array(), |
|
293 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
294 | - array( |
|
295 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
296 | - 'legend_text' => sprintf( |
|
297 | - esc_html_x( |
|
298 | - 'Attendee %d', |
|
299 | - 'Attendee 123', |
|
300 | - 'event_espresso' |
|
301 | - ), |
|
302 | - $attendee_nmbr |
|
303 | - ), |
|
304 | - ) |
|
305 | - ), |
|
306 | - ); |
|
307 | - foreach ($question_groups as $question_group) { |
|
308 | - if ($question_group instanceof EE_Question_Group) { |
|
309 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
310 | - $registration, |
|
311 | - $question_group |
|
312 | - ); |
|
313 | - } |
|
314 | - } |
|
315 | - // add hidden input |
|
316 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
317 | - $registration |
|
318 | - ); |
|
319 | - // if we have question groups for additional attendees, then display the copy options |
|
320 | - $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
321 | - if ($registration->is_primary_registrant()) { |
|
322 | - // generate hidden input |
|
323 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
324 | - $registration |
|
325 | - ); |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - $attendee_nmbr++; |
|
330 | - return ! empty($form_args) |
|
331 | - ? new EE_Form_Section_Proper($form_args) |
|
332 | - : new EE_Form_Section_HTML(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param EE_Registration $registration |
|
338 | - * @param bool $additional_attendee_reg_info |
|
339 | - * @return EE_Form_Input_Base |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - private function _additional_attendee_reg_info_input( |
|
343 | - EE_Registration $registration, |
|
344 | - $additional_attendee_reg_info = true |
|
345 | - ) { |
|
346 | - // generate hidden input |
|
347 | - return new EE_Hidden_Input( |
|
348 | - array( |
|
349 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
350 | - 'default' => $additional_attendee_reg_info, |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @param EE_Registration $registration |
|
358 | - * @param EE_Question_Group $question_group |
|
359 | - * @return EE_Form_Section_Proper |
|
360 | - * @throws EE_Error |
|
361 | - * @throws InvalidArgumentException |
|
362 | - * @throws InvalidDataTypeException |
|
363 | - * @throws InvalidInterfaceException |
|
364 | - * @throws ReflectionException |
|
365 | - */ |
|
366 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
367 | - { |
|
368 | - // array of params to pass to parent constructor |
|
369 | - $form_args = array( |
|
370 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
371 | - 'html_class' => $this->checkout->admin_request |
|
372 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
373 | - : 'ee-reg-form-qstn-grp-dv', |
|
374 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
375 | - . $registration->ID() . '-lbl', |
|
376 | - 'subsections' => array( |
|
377 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
378 | - ), |
|
379 | - 'layout_strategy' => $this->checkout->admin_request |
|
380 | - ? new EE_Admin_Two_Column_Layout() |
|
381 | - : new EE_Div_Per_Section_Layout(), |
|
382 | - ); |
|
383 | - // where params |
|
384 | - $query_params = array('QST_deleted' => 0); |
|
385 | - // don't load admin only questions on the frontend |
|
386 | - if (! $this->checkout->admin_request) { |
|
387 | - $query_params['QST_admin_only'] = array('!=', true); |
|
388 | - } |
|
389 | - $questions = $question_group->get_many_related( |
|
390 | - 'Question', |
|
391 | - apply_filters( |
|
392 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
393 | - array( |
|
394 | - $query_params, |
|
395 | - 'order_by' => array( |
|
396 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
397 | - ), |
|
398 | - ), |
|
399 | - $question_group, |
|
400 | - $registration, |
|
401 | - $this |
|
402 | - ) |
|
403 | - ); |
|
404 | - // filter for additional content before questions |
|
405 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
406 | - apply_filters( |
|
407 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
408 | - '', |
|
409 | - $registration, |
|
410 | - $question_group, |
|
411 | - $this |
|
412 | - ) |
|
413 | - ); |
|
414 | - // loop thru questions |
|
415 | - foreach ($questions as $question) { |
|
416 | - if ($question instanceof EE_Question) { |
|
417 | - $identifier = $question->is_system_question() |
|
418 | - ? $question->system_ID() |
|
419 | - : $question->ID(); |
|
420 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
421 | - } |
|
422 | - } |
|
423 | - $form_args['subsections'] = apply_filters( |
|
424 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
425 | - $form_args['subsections'], |
|
426 | - $registration, |
|
427 | - $question_group, |
|
428 | - $this |
|
429 | - ); |
|
430 | - // filter for additional content after questions |
|
431 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
432 | - apply_filters( |
|
433 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
434 | - '', |
|
435 | - $registration, |
|
436 | - $question_group, |
|
437 | - $this |
|
438 | - ) |
|
439 | - ); |
|
440 | - // d($form_args); |
|
441 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
442 | - return apply_filters( |
|
443 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
444 | - $question_group_reg_form, |
|
445 | - $registration, |
|
446 | - $question_group, |
|
447 | - $this |
|
448 | - ); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * @param EE_Question_Group $question_group |
|
454 | - * @return EE_Form_Section_HTML |
|
455 | - */ |
|
456 | - private function _question_group_header(EE_Question_Group $question_group) |
|
457 | - { |
|
458 | - $html = ''; |
|
459 | - // group_name |
|
460 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
461 | - if ($this->checkout->admin_request) { |
|
462 | - $html .= EEH_HTML::br(); |
|
463 | - $html .= EEH_HTML::h3( |
|
464 | - $question_group->name(), |
|
465 | - '', |
|
466 | - 'ee-reg-form-qstn-grp-title title', |
|
467 | - 'font-size: 1.3em; padding-left:0;' |
|
468 | - ); |
|
469 | - } else { |
|
470 | - $html .= EEH_HTML::h4( |
|
471 | - $question_group->name(), |
|
472 | - '', |
|
473 | - 'ee-reg-form-qstn-grp-title section-title' |
|
474 | - ); |
|
475 | - } |
|
476 | - } |
|
477 | - // group_desc |
|
478 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
479 | - $html .= EEH_HTML::p( |
|
480 | - $question_group->desc(), |
|
481 | - '', |
|
482 | - $this->checkout->admin_request |
|
483 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
484 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
485 | - ); |
|
486 | - } |
|
487 | - return new EE_Form_Section_HTML($html); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * @return EE_Form_Section_Proper |
|
493 | - * @throws EE_Error |
|
494 | - * @throws InvalidArgumentException |
|
495 | - * @throws ReflectionException |
|
496 | - * @throws InvalidDataTypeException |
|
497 | - * @throws InvalidInterfaceException |
|
498 | - */ |
|
499 | - private function _copy_attendee_info_form() |
|
500 | - { |
|
501 | - // array of params to pass to parent constructor |
|
502 | - return new EE_Form_Section_Proper( |
|
503 | - array( |
|
504 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
505 | - 'layout_strategy' => new EE_Template_Layout( |
|
506 | - array( |
|
507 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
508 | - . $this->_slug |
|
509 | - . DS |
|
510 | - . 'copy_attendee_info.template.php', |
|
511 | - 'begin_template_file' => null, |
|
512 | - 'input_template_file' => null, |
|
513 | - 'subsection_template_file' => null, |
|
514 | - 'end_template_file' => null, |
|
515 | - ) |
|
516 | - ), |
|
517 | - ) |
|
518 | - ); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @return EE_Form_Section_HTML |
|
524 | - * @throws DomainException |
|
525 | - * @throws InvalidArgumentException |
|
526 | - * @throws InvalidDataTypeException |
|
527 | - * @throws InvalidInterfaceException |
|
528 | - */ |
|
529 | - private function _auto_copy_attendee_info() |
|
530 | - { |
|
531 | - return new EE_Form_Section_HTML( |
|
532 | - EEH_Template::locate_template( |
|
533 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
534 | - apply_filters( |
|
535 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
536 | - array() |
|
537 | - ), |
|
538 | - true, |
|
539 | - true |
|
540 | - ) |
|
541 | - ); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * @return array |
|
547 | - * @throws EE_Error |
|
548 | - * @throws InvalidArgumentException |
|
549 | - * @throws ReflectionException |
|
550 | - * @throws InvalidDataTypeException |
|
551 | - * @throws InvalidInterfaceException |
|
552 | - */ |
|
553 | - private function _copy_attendee_info_inputs() |
|
554 | - { |
|
555 | - $copy_attendee_info_inputs = array(); |
|
556 | - $prev_ticket = null; |
|
557 | - // grab the saved registrations from the transaction |
|
558 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
559 | - foreach ($registrations as $registration) { |
|
560 | - // for all attendees other than the primary attendee |
|
561 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
562 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
563 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
564 | - $item_name = $registration->ticket()->name(); |
|
565 | - $item_name .= $registration->ticket()->description() !== '' |
|
566 | - ? ' - ' . $registration->ticket()->description() |
|
567 | - : ''; |
|
568 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
569 | - ) . ']' ] = |
|
570 | - new EE_Form_Section_HTML( |
|
571 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
572 | - ); |
|
573 | - $prev_ticket = $registration->ticket()->ID(); |
|
574 | - } |
|
575 | - |
|
576 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
577 | - new EE_Checkbox_Multi_Input( |
|
578 | - array( |
|
579 | - $registration->ID() => sprintf( |
|
580 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
581 | - $registration->count() |
|
582 | - ), |
|
583 | - ), |
|
584 | - array( |
|
585 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
586 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
587 | - 'display_html_label_text' => false, |
|
588 | - ) |
|
589 | - ); |
|
590 | - } |
|
591 | - } |
|
592 | - return $copy_attendee_info_inputs; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * @param EE_Registration $registration |
|
598 | - * @return EE_Form_Input_Base |
|
599 | - * @throws EE_Error |
|
600 | - */ |
|
601 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
602 | - { |
|
603 | - // generate hidden input |
|
604 | - return new EE_Hidden_Input( |
|
605 | - array( |
|
606 | - 'html_id' => 'primary_registrant', |
|
607 | - 'default' => $registration->reg_url_link(), |
|
608 | - ) |
|
609 | - ); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * @param EE_Registration $registration |
|
615 | - * @param EE_Question $question |
|
616 | - * @return EE_Form_Input_Base |
|
617 | - * @throws EE_Error |
|
618 | - * @throws InvalidArgumentException |
|
619 | - * @throws InvalidDataTypeException |
|
620 | - * @throws InvalidInterfaceException |
|
621 | - * @throws ReflectionException |
|
622 | - */ |
|
623 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
624 | - { |
|
625 | - |
|
626 | - // if this question was for an attendee detail, then check for that answer |
|
627 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
628 | - $registration, |
|
629 | - $question->system_ID() |
|
630 | - ); |
|
631 | - $answer = $answer_value === null |
|
632 | - ? EEM_Answer::instance()->get_one( |
|
633 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
634 | - ) |
|
635 | - : null; |
|
636 | - // if NOT returning to edit an existing registration |
|
637 | - // OR if this question is for an attendee property |
|
638 | - // OR we still don't have an EE_Answer object |
|
639 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
640 | - // create an EE_Answer object for storing everything in |
|
641 | - $answer = EE_Answer::new_instance( |
|
642 | - array( |
|
643 | - 'QST_ID' => $question->ID(), |
|
644 | - 'REG_ID' => $registration->ID(), |
|
645 | - ) |
|
646 | - ); |
|
647 | - } |
|
648 | - // verify instance |
|
649 | - if ($answer instanceof EE_Answer) { |
|
650 | - if (! empty($answer_value)) { |
|
651 | - $answer->set('ANS_value', $answer_value); |
|
652 | - } |
|
653 | - $answer->cache('Question', $question); |
|
654 | - // remember system ID had a bug where sometimes it could be null |
|
655 | - $answer_cache_id = $question->is_system_question() |
|
656 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
657 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
658 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
659 | - } |
|
660 | - return $this->_generate_question_input($registration, $question, $answer); |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * @param EE_Registration $registration |
|
666 | - * @param EE_Question $question |
|
667 | - * @param $answer |
|
668 | - * @return EE_Form_Input_Base |
|
669 | - * @throws EE_Error |
|
670 | - * @throws InvalidArgumentException |
|
671 | - * @throws ReflectionException |
|
672 | - * @throws InvalidDataTypeException |
|
673 | - * @throws InvalidInterfaceException |
|
674 | - */ |
|
675 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
676 | - { |
|
677 | - $identifier = $question->is_system_question() |
|
678 | - ? $question->system_ID() |
|
679 | - : $question->ID(); |
|
680 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
681 | - add_filter( |
|
682 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
683 | - array($this, 'use_cached_countries_for_form_input'), |
|
684 | - 10, |
|
685 | - 4 |
|
686 | - ); |
|
687 | - add_filter( |
|
688 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
689 | - array($this, 'use_cached_states_for_form_input'), |
|
690 | - 10, |
|
691 | - 4 |
|
692 | - ); |
|
693 | - $input_constructor_args = array( |
|
694 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
695 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
696 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
697 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
698 | - 'html_label_class' => 'ee-reg-qstn', |
|
699 | - ); |
|
700 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
701 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
702 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
703 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
704 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
705 | - } |
|
706 | - $form_input = $question->generate_form_input( |
|
707 | - $registration, |
|
708 | - $answer, |
|
709 | - $input_constructor_args |
|
710 | - ); |
|
711 | - remove_filter( |
|
712 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | - array($this, 'use_cached_countries_for_form_input') |
|
714 | - ); |
|
715 | - remove_filter( |
|
716 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
717 | - array($this, 'use_cached_states_for_form_input') |
|
718 | - ); |
|
719 | - return $form_input; |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * Gets the list of countries for the form input |
|
725 | - * |
|
726 | - * @param array|null $countries_list |
|
727 | - * @param EE_Question $question |
|
728 | - * @param EE_Registration $registration |
|
729 | - * @param EE_Answer $answer |
|
730 | - * @return array 2d keys are country IDs, values are their names |
|
731 | - * @throws EE_Error |
|
732 | - * @throws InvalidArgumentException |
|
733 | - * @throws InvalidDataTypeException |
|
734 | - * @throws InvalidInterfaceException |
|
735 | - * @throws ReflectionException |
|
736 | - */ |
|
737 | - public function use_cached_countries_for_form_input( |
|
738 | - $countries_list, |
|
739 | - EE_Question $question = null, |
|
740 | - EE_Registration $registration = null, |
|
741 | - EE_Answer $answer = null |
|
742 | - ) { |
|
743 | - $country_options = array('' => ''); |
|
744 | - // get possibly cached list of countries |
|
745 | - $countries = $this->checkout->action === 'process_reg_step' |
|
746 | - ? EEM_Country::instance()->get_all_countries() |
|
747 | - : EEM_Country::instance()->get_all_active_countries(); |
|
748 | - if (! empty($countries)) { |
|
749 | - foreach ($countries as $country) { |
|
750 | - if ($country instanceof EE_Country) { |
|
751 | - $country_options[ $country->ID() ] = $country->name(); |
|
752 | - } |
|
753 | - } |
|
754 | - } |
|
755 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
756 | - $answer = EEM_Answer::instance()->get_one( |
|
757 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
758 | - ); |
|
759 | - } else { |
|
760 | - $answer = EE_Answer::new_instance(); |
|
761 | - } |
|
762 | - $country_options = apply_filters( |
|
763 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
764 | - $country_options, |
|
765 | - $this, |
|
766 | - $registration, |
|
767 | - $question, |
|
768 | - $answer |
|
769 | - ); |
|
770 | - return $country_options; |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * Gets the list of states for the form input |
|
776 | - * |
|
777 | - * @param array|null $states_list |
|
778 | - * @param EE_Question $question |
|
779 | - * @param EE_Registration $registration |
|
780 | - * @param EE_Answer $answer |
|
781 | - * @return array 2d keys are state IDs, values are their names |
|
782 | - * @throws EE_Error |
|
783 | - * @throws InvalidArgumentException |
|
784 | - * @throws InvalidDataTypeException |
|
785 | - * @throws InvalidInterfaceException |
|
786 | - * @throws ReflectionException |
|
787 | - */ |
|
788 | - public function use_cached_states_for_form_input( |
|
789 | - $states_list, |
|
790 | - EE_Question $question = null, |
|
791 | - EE_Registration $registration = null, |
|
792 | - EE_Answer $answer = null |
|
793 | - ) { |
|
794 | - $state_options = array('' => array('' => '')); |
|
795 | - $states = $this->checkout->action === 'process_reg_step' |
|
796 | - ? EEM_State::instance()->get_all_states() |
|
797 | - : EEM_State::instance()->get_all_active_states(); |
|
798 | - if (! empty($states)) { |
|
799 | - foreach ($states as $state) { |
|
800 | - if ($state instanceof EE_State) { |
|
801 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
802 | - } |
|
803 | - } |
|
804 | - } |
|
805 | - $state_options = apply_filters( |
|
806 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
807 | - $state_options, |
|
808 | - $this, |
|
809 | - $registration, |
|
810 | - $question, |
|
811 | - $answer |
|
812 | - ); |
|
813 | - return $state_options; |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - /********************************************************************************************************/ |
|
818 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
819 | - /********************************************************************************************************/ |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * @return bool |
|
824 | - * @throws EE_Error |
|
825 | - * @throws InvalidArgumentException |
|
826 | - * @throws ReflectionException |
|
827 | - * @throws RuntimeException |
|
828 | - * @throws InvalidDataTypeException |
|
829 | - * @throws InvalidInterfaceException |
|
830 | - */ |
|
831 | - public function process_reg_step() |
|
832 | - { |
|
833 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
834 | - // grab validated data from form |
|
835 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
836 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
837 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
838 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
839 | - if (empty($valid_data)) { |
|
840 | - EE_Error::add_error( |
|
841 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
842 | - __FILE__, |
|
843 | - __FUNCTION__, |
|
844 | - __LINE__ |
|
845 | - ); |
|
846 | - return false; |
|
847 | - } |
|
848 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
849 | - EE_Error::add_error( |
|
850 | - esc_html__( |
|
851 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
852 | - 'event_espresso' |
|
853 | - ), |
|
854 | - __FILE__, |
|
855 | - __FUNCTION__, |
|
856 | - __LINE__ |
|
857 | - ); |
|
858 | - return false; |
|
859 | - } |
|
860 | - // get cached registrations |
|
861 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
862 | - // verify we got the goods |
|
863 | - if (empty($registrations)) { |
|
864 | - // combine the old translated string with a new one, in order to not break translations |
|
865 | - $error_message = esc_html__( |
|
866 | - 'Your form data could not be applied to any valid registrations.', |
|
867 | - 'event_espresso' |
|
868 | - ) |
|
869 | - . sprintf( |
|
870 | - esc_html_x( |
|
871 | - '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
872 | - '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
873 | - 'event_espresso' |
|
874 | - ), |
|
875 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
876 | - '</a>', |
|
877 | - '<br />' |
|
878 | - ); |
|
879 | - EE_Error::add_error( |
|
880 | - $error_message, |
|
881 | - __FILE__, |
|
882 | - __FUNCTION__, |
|
883 | - __LINE__ |
|
884 | - ); |
|
885 | - return false; |
|
886 | - } |
|
887 | - // extract attendee info from form data and save to model objects |
|
888 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
889 | - // if first pass thru SPCO, |
|
890 | - // then let's check processed registrations against the total number of tickets in the cart |
|
891 | - if ($registrations_processed === false) { |
|
892 | - // but return immediately if the previous step exited early due to errors |
|
893 | - return false; |
|
894 | - } |
|
895 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
896 | - // generate a correctly translated string for all possible singular/plural combinations |
|
897 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
898 | - $error_msg = sprintf( |
|
899 | - esc_html_x( |
|
900 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
901 | - 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
902 | - 'event_espresso' |
|
903 | - ), |
|
904 | - $this->checkout->total_ticket_count, |
|
905 | - $registrations_processed |
|
906 | - ); |
|
907 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
908 | - $error_msg = sprintf( |
|
909 | - esc_html_x( |
|
910 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
911 | - 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
912 | - 'event_espresso' |
|
913 | - ), |
|
914 | - $this->checkout->total_ticket_count, |
|
915 | - $registrations_processed |
|
916 | - ); |
|
917 | - } else { |
|
918 | - $error_msg = sprintf( |
|
919 | - esc_html__( |
|
920 | - 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
921 | - 'event_espresso' |
|
922 | - ), |
|
923 | - $this->checkout->total_ticket_count, |
|
924 | - $registrations_processed |
|
925 | - ); |
|
926 | - } |
|
927 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
928 | - return false; |
|
929 | - } |
|
930 | - // mark this reg step as completed |
|
931 | - $this->set_completed(); |
|
932 | - $this->_set_success_message( |
|
933 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
934 | - ); |
|
935 | - // do action in case a plugin wants to do something with the data submitted in step 1. |
|
936 | - // passes EE_Single_Page_Checkout, and it's posted data |
|
937 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
938 | - return true; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * _process_registrations |
|
944 | - * |
|
945 | - * @param EE_Registration[] $registrations |
|
946 | - * @param array[][] $valid_data |
|
947 | - * @return bool|int |
|
948 | - * @throws EntityNotFoundException |
|
949 | - * @throws EE_Error |
|
950 | - * @throws InvalidArgumentException |
|
951 | - * @throws ReflectionException |
|
952 | - * @throws RuntimeException |
|
953 | - * @throws InvalidDataTypeException |
|
954 | - * @throws InvalidInterfaceException |
|
955 | - */ |
|
956 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
957 | - { |
|
958 | - // load resources and set some defaults |
|
959 | - EE_Registry::instance()->load_model('Attendee'); |
|
960 | - // holder for primary registrant attendee object |
|
961 | - $this->checkout->primary_attendee_obj = null; |
|
962 | - // array for tracking reg form data for the primary registrant |
|
963 | - $primary_registrant = array( |
|
964 | - 'line_item_id' => null, |
|
965 | - ); |
|
966 | - $copy_primary = false; |
|
967 | - // reg form sections that do not contain inputs |
|
968 | - $non_input_form_sections = array( |
|
969 | - 'primary_registrant', |
|
970 | - 'additional_attendee_reg_info', |
|
971 | - 'spco_copy_attendee_chk', |
|
972 | - ); |
|
973 | - // attendee counter |
|
974 | - $att_nmbr = 0; |
|
975 | - // grab the saved registrations from the transaction |
|
976 | - foreach ($registrations as $registration) { |
|
977 | - // verify EE_Registration object |
|
978 | - if (! $registration instanceof EE_Registration) { |
|
979 | - EE_Error::add_error( |
|
980 | - esc_html__( |
|
981 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
982 | - 'event_espresso' |
|
983 | - ), |
|
984 | - __FILE__, |
|
985 | - __FUNCTION__, |
|
986 | - __LINE__ |
|
987 | - ); |
|
988 | - return false; |
|
989 | - } |
|
990 | - /** @var string $reg_url_link */ |
|
991 | - $reg_url_link = $registration->reg_url_link(); |
|
992 | - // reg_url_link exists ? |
|
993 | - if (! empty($reg_url_link)) { |
|
994 | - // should this registration be processed during this visit ? |
|
995 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
996 | - // if NOT revisiting, then let's save the registration now, |
|
997 | - // so that we have a REG_ID to use when generating other objects |
|
998 | - if (! $this->checkout->revisit) { |
|
999 | - $registration->save(); |
|
1000 | - } |
|
1001 | - /** |
|
1002 | - * This allows plugins to trigger a fail on processing of a |
|
1003 | - * registration for any conditions they may have for it to pass. |
|
1004 | - * |
|
1005 | - * @var bool if true is returned by the plugin then the |
|
1006 | - * registration processing is halted. |
|
1007 | - */ |
|
1008 | - if (apply_filters( |
|
1009 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1010 | - false, |
|
1011 | - $att_nmbr, |
|
1012 | - $registration, |
|
1013 | - $registrations, |
|
1014 | - $valid_data, |
|
1015 | - $this |
|
1016 | - )) { |
|
1017 | - return false; |
|
1018 | - } |
|
1019 | - |
|
1020 | - // Houston, we have a registration! |
|
1021 | - $att_nmbr++; |
|
1022 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
1023 | - // grab any existing related answer objects |
|
1024 | - $this->_registration_answers = $registration->answers(); |
|
1025 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1026 | - if (isset($valid_data[ $reg_url_link ])) { |
|
1027 | - // do we need to copy basic info from primary attendee ? |
|
1028 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1029 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1030 | - // filter form input data for this registration |
|
1031 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1032 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1033 | - $valid_data[ $reg_url_link ] |
|
1034 | - ); |
|
1035 | - if (isset($valid_data['primary_attendee'])) { |
|
1036 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1037 | - ? $valid_data['primary_attendee'] |
|
1038 | - : false; |
|
1039 | - unset($valid_data['primary_attendee']); |
|
1040 | - } |
|
1041 | - // now loop through our array of valid post data && process attendee reg forms |
|
1042 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1043 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1044 | - foreach ($form_inputs as $form_input => $input_value) { |
|
1045 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1046 | - // check for critical inputs |
|
1047 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1048 | - $form_input, |
|
1049 | - $input_value |
|
1050 | - ) |
|
1051 | - ) { |
|
1052 | - return false; |
|
1053 | - } |
|
1054 | - // store a bit of data about the primary attendee |
|
1055 | - if ($att_nmbr === 1 |
|
1056 | - && ! empty($input_value) |
|
1057 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
1058 | - ) { |
|
1059 | - $primary_registrant[ $form_input ] = $input_value; |
|
1060 | - } elseif ($copy_primary |
|
1061 | - && $input_value === null |
|
1062 | - && isset($primary_registrant[ $form_input ]) |
|
1063 | - ) { |
|
1064 | - $input_value = $primary_registrant[ $form_input ]; |
|
1065 | - } |
|
1066 | - // now attempt to save the input data |
|
1067 | - if (! $this->_save_registration_form_input( |
|
1068 | - $registration, |
|
1069 | - $form_input, |
|
1070 | - $input_value |
|
1071 | - ) |
|
1072 | - ) { |
|
1073 | - EE_Error::add_error( |
|
1074 | - sprintf( |
|
1075 | - esc_html_x( |
|
1076 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1077 | - 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1078 | - 'event_espresso' |
|
1079 | - ), |
|
1080 | - $form_input, |
|
1081 | - $input_value |
|
1082 | - ), |
|
1083 | - __FILE__, |
|
1084 | - __FUNCTION__, |
|
1085 | - __LINE__ |
|
1086 | - ); |
|
1087 | - return false; |
|
1088 | - } |
|
1089 | - } |
|
1090 | - } |
|
1091 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1092 | - } |
|
1093 | - // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1094 | - // this registration does not require additional attendee information ? |
|
1095 | - if ($copy_primary |
|
1096 | - && $att_nmbr > 1 |
|
1097 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1098 | - ) { |
|
1099 | - // just copy the primary registrant |
|
1100 | - $attendee = $this->checkout->primary_attendee_obj; |
|
1101 | - } else { |
|
1102 | - // ensure critical details are set for additional attendees |
|
1103 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1104 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1105 | - $this->_attendee_data[ $reg_url_link ] |
|
1106 | - ) |
|
1107 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1108 | - // execute create attendee command (which may return an existing attendee) |
|
1109 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
1110 | - new CreateAttendeeCommand( |
|
1111 | - $this->_attendee_data[ $reg_url_link ], |
|
1112 | - $registration |
|
1113 | - ) |
|
1114 | - ); |
|
1115 | - // who's #1 ? |
|
1116 | - if ($att_nmbr === 1) { |
|
1117 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1121 | - // add relation to registration, set attendee ID, and cache attendee |
|
1122 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
1123 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1124 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1125 | - EE_Error::add_error( |
|
1126 | - sprintf( |
|
1127 | - esc_html_x( |
|
1128 | - 'Registration %s has an invalid or missing Attendee object.', |
|
1129 | - 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1130 | - 'event_espresso' |
|
1131 | - ), |
|
1132 | - $reg_url_link |
|
1133 | - ), |
|
1134 | - __FILE__, |
|
1135 | - __FUNCTION__, |
|
1136 | - __LINE__ |
|
1137 | - ); |
|
1138 | - return false; |
|
1139 | - } |
|
1140 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1141 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1142 | - // at this point, we should have enough details about the registrant to consider the registration |
|
1143 | - // NOT incomplete |
|
1144 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1145 | - $registration, |
|
1146 | - false, |
|
1147 | - new Context( |
|
1148 | - 'spco_reg_step_attendee_information_process_registrations', |
|
1149 | - esc_html__( |
|
1150 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1151 | - 'event_espresso' |
|
1152 | - ) |
|
1153 | - ) |
|
1154 | - ); |
|
1155 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1156 | - // abandoned |
|
1157 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1158 | - // if we've gotten this far, then let's save what we have |
|
1159 | - $registration->save(); |
|
1160 | - // add relation between TXN and registration |
|
1161 | - $this->_associate_registration_with_transaction($registration); |
|
1162 | - } |
|
1163 | - } else { |
|
1164 | - EE_Error::add_error( |
|
1165 | - esc_html__( |
|
1166 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1167 | - 'event_espresso' |
|
1168 | - ), |
|
1169 | - __FILE__, |
|
1170 | - __FUNCTION__, |
|
1171 | - __LINE__ |
|
1172 | - ); |
|
1173 | - // remove malformed data |
|
1174 | - unset($valid_data[ $reg_url_link ]); |
|
1175 | - return false; |
|
1176 | - } |
|
1177 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1178 | - return $att_nmbr; |
|
1179 | - } |
|
1180 | - |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * _save_registration_form_input |
|
1184 | - * |
|
1185 | - * @param EE_Registration $registration |
|
1186 | - * @param string $form_input |
|
1187 | - * @param string $input_value |
|
1188 | - * @return bool |
|
1189 | - * @throws EE_Error |
|
1190 | - * @throws InvalidArgumentException |
|
1191 | - * @throws InvalidDataTypeException |
|
1192 | - * @throws InvalidInterfaceException |
|
1193 | - * @throws ReflectionException |
|
1194 | - */ |
|
1195 | - private function _save_registration_form_input( |
|
1196 | - EE_Registration $registration, |
|
1197 | - $form_input = '', |
|
1198 | - $input_value = '' |
|
1199 | - ) { |
|
1200 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1201 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1202 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1203 | - // allow for plugins to hook in and do their own processing of the form input. |
|
1204 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1205 | - if (apply_filters( |
|
1206 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1207 | - false, |
|
1208 | - $registration, |
|
1209 | - $form_input, |
|
1210 | - $input_value, |
|
1211 | - $this |
|
1212 | - )) { |
|
1213 | - return true; |
|
1214 | - } |
|
1215 | - /* |
|
21 | + /** |
|
22 | + * @type bool $_print_copy_info |
|
23 | + */ |
|
24 | + private $_print_copy_info = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type array $_attendee_data |
|
28 | + */ |
|
29 | + private $_attendee_data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @type array $_required_questions |
|
33 | + */ |
|
34 | + private $_required_questions = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * @type array $_registration_answers |
|
38 | + */ |
|
39 | + private $_registration_answers = array(); |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * class constructor |
|
44 | + * |
|
45 | + * @access public |
|
46 | + * @param EE_Checkout $checkout |
|
47 | + */ |
|
48 | + public function __construct(EE_Checkout $checkout) |
|
49 | + { |
|
50 | + $this->_slug = 'attendee_information'; |
|
51 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
52 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
53 | + $this->checkout = $checkout; |
|
54 | + $this->_reset_success_message(); |
|
55 | + $this->set_instructions( |
|
56 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
57 | + ); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + public function translate_js_strings() |
|
62 | + { |
|
63 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
64 | + ' is a required question.', |
|
65 | + 'event_espresso' |
|
66 | + ); |
|
67 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
68 | + ' is a required question. Please enter a value for at least one of the options.', |
|
69 | + 'event_espresso' |
|
70 | + ); |
|
71 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
72 | + 'Please answer all required questions correctly before proceeding.', |
|
73 | + 'event_espresso' |
|
74 | + ); |
|
75 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
76 | + esc_html_x( |
|
77 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
78 | + 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + '<br/>' |
|
82 | + ); |
|
83 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
84 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
85 | + 'event_espresso' |
|
86 | + ); |
|
87 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
88 | + 'You must enter a valid email address.', |
|
89 | + 'event_espresso' |
|
90 | + ); |
|
91 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
92 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
93 | + 'event_espresso' |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + public function enqueue_styles_and_scripts() |
|
99 | + { |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return boolean |
|
105 | + */ |
|
106 | + public function initialize_reg_step() |
|
107 | + { |
|
108 | + return true; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return EE_Form_Section_Proper |
|
114 | + * @throws DomainException |
|
115 | + * @throws EE_Error |
|
116 | + * @throws InvalidArgumentException |
|
117 | + * @throws ReflectionException |
|
118 | + * @throws EntityNotFoundException |
|
119 | + * @throws InvalidDataTypeException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + */ |
|
122 | + public function generate_reg_form() |
|
123 | + { |
|
124 | + $this->_print_copy_info = false; |
|
125 | + $primary_registrant = null; |
|
126 | + // autoload Line_Item_Display classes |
|
127 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
128 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
129 | + // calculate taxes |
|
130 | + $Line_Item_Display->display_line_item( |
|
131 | + $this->checkout->cart->get_grand_total(), |
|
132 | + array('set_tax_rate' => true) |
|
133 | + ); |
|
134 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
135 | + $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
136 | + $subsections = array( |
|
137 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
138 | + ); |
|
139 | + |
|
140 | + /** |
|
141 | + * @var $reg_config EE_Registration_Config |
|
142 | + */ |
|
143 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
144 | + // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
145 | + if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
146 | + $extra_inputs_section->add_subsections( |
|
147 | + array( |
|
148 | + 'consent_box' => new EE_Form_Section_Proper( |
|
149 | + array( |
|
150 | + 'layout_strategy' => |
|
151 | + new EE_Template_Layout( |
|
152 | + array( |
|
153 | + 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . DS . 'privacy_consent.template.php', |
|
154 | + ) |
|
155 | + ), |
|
156 | + 'subsections' => array( |
|
157 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
158 | + array( |
|
159 | + 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
160 | + ), |
|
161 | + array( |
|
162 | + 'required' => true, |
|
163 | + 'required_validation_error_message' => esc_html__( |
|
164 | + 'You must consent to these terms in order to register.', |
|
165 | + 'event_espresso' |
|
166 | + ), |
|
167 | + 'html_label_text' => '', |
|
168 | + ) |
|
169 | + ), |
|
170 | + ), |
|
171 | + ) |
|
172 | + ), |
|
173 | + ), |
|
174 | + null, |
|
175 | + false |
|
176 | + ); |
|
177 | + } |
|
178 | + $template_args = array( |
|
179 | + 'revisit' => $this->checkout->revisit, |
|
180 | + 'registrations' => array(), |
|
181 | + 'ticket_count' => array(), |
|
182 | + ); |
|
183 | + // grab the saved registrations from the transaction |
|
184 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
185 | + if ($registrations) { |
|
186 | + foreach ($registrations as $registration) { |
|
187 | + // can this registration be processed during this visit ? |
|
188 | + if ($registration instanceof EE_Registration |
|
189 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
190 | + ) { |
|
191 | + $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
192 | + if (! $this->checkout->admin_request) { |
|
193 | + $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
194 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
195 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
196 | + ) |
|
197 | + ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
198 | + : 1; |
|
199 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
200 | + $this->checkout->cart->get_grand_total(), |
|
201 | + 'Ticket', |
|
202 | + array($registration->ticket()->ID()) |
|
203 | + ); |
|
204 | + $ticket_line_item = is_array($ticket_line_item) |
|
205 | + ? reset($ticket_line_item) |
|
206 | + : $ticket_line_item; |
|
207 | + $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
208 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
209 | + } |
|
210 | + if ($registration->is_primary_registrant()) { |
|
211 | + $primary_registrant = $registration->reg_url_link(); |
|
212 | + } |
|
213 | + } |
|
214 | + } |
|
215 | + // print_copy_info ? |
|
216 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
217 | + // TODO: add admin option for toggling copy attendee info, |
|
218 | + // then use that value to change $this->_print_copy_info |
|
219 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
220 | + ? $this->_copy_attendee_info_form() |
|
221 | + : $this->_auto_copy_attendee_info(); |
|
222 | + // generate hidden input |
|
223 | + if (isset($subsections[ $primary_registrant ]) |
|
224 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
225 | + ) { |
|
226 | + $subsections[ $primary_registrant ]->add_subsections( |
|
227 | + $copy_options, |
|
228 | + 'primary_registrant', |
|
229 | + false |
|
230 | + ); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + return new EE_Form_Section_Proper( |
|
235 | + array( |
|
236 | + 'name' => $this->reg_form_name(), |
|
237 | + 'html_id' => $this->reg_form_name(), |
|
238 | + 'subsections' => $subsections, |
|
239 | + 'layout_strategy' => $this->checkout->admin_request |
|
240 | + ? |
|
241 | + new EE_Div_Per_Section_Layout() |
|
242 | + : |
|
243 | + new EE_Template_Layout( |
|
244 | + array( |
|
245 | + 'layout_template_file' => $this->_template, // layout_template |
|
246 | + 'template_args' => $template_args, |
|
247 | + ) |
|
248 | + ), |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param EE_Registration $registration |
|
256 | + * @return EE_Form_Section_Base |
|
257 | + * @throws EE_Error |
|
258 | + * @throws InvalidArgumentException |
|
259 | + * @throws EntityNotFoundException |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidInterfaceException |
|
262 | + * @throws ReflectionException |
|
263 | + */ |
|
264 | + private function _registrations_reg_form(EE_Registration $registration) |
|
265 | + { |
|
266 | + static $attendee_nmbr = 1; |
|
267 | + $form_args = array(); |
|
268 | + // verify that registration has valid event |
|
269 | + if ($registration->event() instanceof EE_Event) { |
|
270 | + $question_groups = $registration->event()->question_groups( |
|
271 | + apply_filters( |
|
272 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
273 | + array( |
|
274 | + array( |
|
275 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
276 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1, |
|
277 | + ), |
|
278 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
279 | + ), |
|
280 | + $registration, |
|
281 | + $this |
|
282 | + ) |
|
283 | + ); |
|
284 | + if ($question_groups) { |
|
285 | + // array of params to pass to parent constructor |
|
286 | + $form_args = array( |
|
287 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
288 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
289 | + 'html_style' => $this->checkout->admin_request |
|
290 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
291 | + : '', |
|
292 | + 'subsections' => array(), |
|
293 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
294 | + array( |
|
295 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
296 | + 'legend_text' => sprintf( |
|
297 | + esc_html_x( |
|
298 | + 'Attendee %d', |
|
299 | + 'Attendee 123', |
|
300 | + 'event_espresso' |
|
301 | + ), |
|
302 | + $attendee_nmbr |
|
303 | + ), |
|
304 | + ) |
|
305 | + ), |
|
306 | + ); |
|
307 | + foreach ($question_groups as $question_group) { |
|
308 | + if ($question_group instanceof EE_Question_Group) { |
|
309 | + $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
310 | + $registration, |
|
311 | + $question_group |
|
312 | + ); |
|
313 | + } |
|
314 | + } |
|
315 | + // add hidden input |
|
316 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
317 | + $registration |
|
318 | + ); |
|
319 | + // if we have question groups for additional attendees, then display the copy options |
|
320 | + $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
321 | + if ($registration->is_primary_registrant()) { |
|
322 | + // generate hidden input |
|
323 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
324 | + $registration |
|
325 | + ); |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + $attendee_nmbr++; |
|
330 | + return ! empty($form_args) |
|
331 | + ? new EE_Form_Section_Proper($form_args) |
|
332 | + : new EE_Form_Section_HTML(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param EE_Registration $registration |
|
338 | + * @param bool $additional_attendee_reg_info |
|
339 | + * @return EE_Form_Input_Base |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + private function _additional_attendee_reg_info_input( |
|
343 | + EE_Registration $registration, |
|
344 | + $additional_attendee_reg_info = true |
|
345 | + ) { |
|
346 | + // generate hidden input |
|
347 | + return new EE_Hidden_Input( |
|
348 | + array( |
|
349 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
350 | + 'default' => $additional_attendee_reg_info, |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @param EE_Registration $registration |
|
358 | + * @param EE_Question_Group $question_group |
|
359 | + * @return EE_Form_Section_Proper |
|
360 | + * @throws EE_Error |
|
361 | + * @throws InvalidArgumentException |
|
362 | + * @throws InvalidDataTypeException |
|
363 | + * @throws InvalidInterfaceException |
|
364 | + * @throws ReflectionException |
|
365 | + */ |
|
366 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
367 | + { |
|
368 | + // array of params to pass to parent constructor |
|
369 | + $form_args = array( |
|
370 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
371 | + 'html_class' => $this->checkout->admin_request |
|
372 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
373 | + : 'ee-reg-form-qstn-grp-dv', |
|
374 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
375 | + . $registration->ID() . '-lbl', |
|
376 | + 'subsections' => array( |
|
377 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
378 | + ), |
|
379 | + 'layout_strategy' => $this->checkout->admin_request |
|
380 | + ? new EE_Admin_Two_Column_Layout() |
|
381 | + : new EE_Div_Per_Section_Layout(), |
|
382 | + ); |
|
383 | + // where params |
|
384 | + $query_params = array('QST_deleted' => 0); |
|
385 | + // don't load admin only questions on the frontend |
|
386 | + if (! $this->checkout->admin_request) { |
|
387 | + $query_params['QST_admin_only'] = array('!=', true); |
|
388 | + } |
|
389 | + $questions = $question_group->get_many_related( |
|
390 | + 'Question', |
|
391 | + apply_filters( |
|
392 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
393 | + array( |
|
394 | + $query_params, |
|
395 | + 'order_by' => array( |
|
396 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
397 | + ), |
|
398 | + ), |
|
399 | + $question_group, |
|
400 | + $registration, |
|
401 | + $this |
|
402 | + ) |
|
403 | + ); |
|
404 | + // filter for additional content before questions |
|
405 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
406 | + apply_filters( |
|
407 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
408 | + '', |
|
409 | + $registration, |
|
410 | + $question_group, |
|
411 | + $this |
|
412 | + ) |
|
413 | + ); |
|
414 | + // loop thru questions |
|
415 | + foreach ($questions as $question) { |
|
416 | + if ($question instanceof EE_Question) { |
|
417 | + $identifier = $question->is_system_question() |
|
418 | + ? $question->system_ID() |
|
419 | + : $question->ID(); |
|
420 | + $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
421 | + } |
|
422 | + } |
|
423 | + $form_args['subsections'] = apply_filters( |
|
424 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
425 | + $form_args['subsections'], |
|
426 | + $registration, |
|
427 | + $question_group, |
|
428 | + $this |
|
429 | + ); |
|
430 | + // filter for additional content after questions |
|
431 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
432 | + apply_filters( |
|
433 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
434 | + '', |
|
435 | + $registration, |
|
436 | + $question_group, |
|
437 | + $this |
|
438 | + ) |
|
439 | + ); |
|
440 | + // d($form_args); |
|
441 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
442 | + return apply_filters( |
|
443 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
444 | + $question_group_reg_form, |
|
445 | + $registration, |
|
446 | + $question_group, |
|
447 | + $this |
|
448 | + ); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * @param EE_Question_Group $question_group |
|
454 | + * @return EE_Form_Section_HTML |
|
455 | + */ |
|
456 | + private function _question_group_header(EE_Question_Group $question_group) |
|
457 | + { |
|
458 | + $html = ''; |
|
459 | + // group_name |
|
460 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
461 | + if ($this->checkout->admin_request) { |
|
462 | + $html .= EEH_HTML::br(); |
|
463 | + $html .= EEH_HTML::h3( |
|
464 | + $question_group->name(), |
|
465 | + '', |
|
466 | + 'ee-reg-form-qstn-grp-title title', |
|
467 | + 'font-size: 1.3em; padding-left:0;' |
|
468 | + ); |
|
469 | + } else { |
|
470 | + $html .= EEH_HTML::h4( |
|
471 | + $question_group->name(), |
|
472 | + '', |
|
473 | + 'ee-reg-form-qstn-grp-title section-title' |
|
474 | + ); |
|
475 | + } |
|
476 | + } |
|
477 | + // group_desc |
|
478 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
479 | + $html .= EEH_HTML::p( |
|
480 | + $question_group->desc(), |
|
481 | + '', |
|
482 | + $this->checkout->admin_request |
|
483 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
484 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
485 | + ); |
|
486 | + } |
|
487 | + return new EE_Form_Section_HTML($html); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * @return EE_Form_Section_Proper |
|
493 | + * @throws EE_Error |
|
494 | + * @throws InvalidArgumentException |
|
495 | + * @throws ReflectionException |
|
496 | + * @throws InvalidDataTypeException |
|
497 | + * @throws InvalidInterfaceException |
|
498 | + */ |
|
499 | + private function _copy_attendee_info_form() |
|
500 | + { |
|
501 | + // array of params to pass to parent constructor |
|
502 | + return new EE_Form_Section_Proper( |
|
503 | + array( |
|
504 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
505 | + 'layout_strategy' => new EE_Template_Layout( |
|
506 | + array( |
|
507 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
508 | + . $this->_slug |
|
509 | + . DS |
|
510 | + . 'copy_attendee_info.template.php', |
|
511 | + 'begin_template_file' => null, |
|
512 | + 'input_template_file' => null, |
|
513 | + 'subsection_template_file' => null, |
|
514 | + 'end_template_file' => null, |
|
515 | + ) |
|
516 | + ), |
|
517 | + ) |
|
518 | + ); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @return EE_Form_Section_HTML |
|
524 | + * @throws DomainException |
|
525 | + * @throws InvalidArgumentException |
|
526 | + * @throws InvalidDataTypeException |
|
527 | + * @throws InvalidInterfaceException |
|
528 | + */ |
|
529 | + private function _auto_copy_attendee_info() |
|
530 | + { |
|
531 | + return new EE_Form_Section_HTML( |
|
532 | + EEH_Template::locate_template( |
|
533 | + SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
534 | + apply_filters( |
|
535 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
536 | + array() |
|
537 | + ), |
|
538 | + true, |
|
539 | + true |
|
540 | + ) |
|
541 | + ); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * @return array |
|
547 | + * @throws EE_Error |
|
548 | + * @throws InvalidArgumentException |
|
549 | + * @throws ReflectionException |
|
550 | + * @throws InvalidDataTypeException |
|
551 | + * @throws InvalidInterfaceException |
|
552 | + */ |
|
553 | + private function _copy_attendee_info_inputs() |
|
554 | + { |
|
555 | + $copy_attendee_info_inputs = array(); |
|
556 | + $prev_ticket = null; |
|
557 | + // grab the saved registrations from the transaction |
|
558 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
559 | + foreach ($registrations as $registration) { |
|
560 | + // for all attendees other than the primary attendee |
|
561 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
562 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
563 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
564 | + $item_name = $registration->ticket()->name(); |
|
565 | + $item_name .= $registration->ticket()->description() !== '' |
|
566 | + ? ' - ' . $registration->ticket()->description() |
|
567 | + : ''; |
|
568 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
569 | + ) . ']' ] = |
|
570 | + new EE_Form_Section_HTML( |
|
571 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
572 | + ); |
|
573 | + $prev_ticket = $registration->ticket()->ID(); |
|
574 | + } |
|
575 | + |
|
576 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
577 | + new EE_Checkbox_Multi_Input( |
|
578 | + array( |
|
579 | + $registration->ID() => sprintf( |
|
580 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
581 | + $registration->count() |
|
582 | + ), |
|
583 | + ), |
|
584 | + array( |
|
585 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
586 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
587 | + 'display_html_label_text' => false, |
|
588 | + ) |
|
589 | + ); |
|
590 | + } |
|
591 | + } |
|
592 | + return $copy_attendee_info_inputs; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * @param EE_Registration $registration |
|
598 | + * @return EE_Form_Input_Base |
|
599 | + * @throws EE_Error |
|
600 | + */ |
|
601 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
602 | + { |
|
603 | + // generate hidden input |
|
604 | + return new EE_Hidden_Input( |
|
605 | + array( |
|
606 | + 'html_id' => 'primary_registrant', |
|
607 | + 'default' => $registration->reg_url_link(), |
|
608 | + ) |
|
609 | + ); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * @param EE_Registration $registration |
|
615 | + * @param EE_Question $question |
|
616 | + * @return EE_Form_Input_Base |
|
617 | + * @throws EE_Error |
|
618 | + * @throws InvalidArgumentException |
|
619 | + * @throws InvalidDataTypeException |
|
620 | + * @throws InvalidInterfaceException |
|
621 | + * @throws ReflectionException |
|
622 | + */ |
|
623 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
624 | + { |
|
625 | + |
|
626 | + // if this question was for an attendee detail, then check for that answer |
|
627 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
628 | + $registration, |
|
629 | + $question->system_ID() |
|
630 | + ); |
|
631 | + $answer = $answer_value === null |
|
632 | + ? EEM_Answer::instance()->get_one( |
|
633 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
634 | + ) |
|
635 | + : null; |
|
636 | + // if NOT returning to edit an existing registration |
|
637 | + // OR if this question is for an attendee property |
|
638 | + // OR we still don't have an EE_Answer object |
|
639 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
640 | + // create an EE_Answer object for storing everything in |
|
641 | + $answer = EE_Answer::new_instance( |
|
642 | + array( |
|
643 | + 'QST_ID' => $question->ID(), |
|
644 | + 'REG_ID' => $registration->ID(), |
|
645 | + ) |
|
646 | + ); |
|
647 | + } |
|
648 | + // verify instance |
|
649 | + if ($answer instanceof EE_Answer) { |
|
650 | + if (! empty($answer_value)) { |
|
651 | + $answer->set('ANS_value', $answer_value); |
|
652 | + } |
|
653 | + $answer->cache('Question', $question); |
|
654 | + // remember system ID had a bug where sometimes it could be null |
|
655 | + $answer_cache_id = $question->is_system_question() |
|
656 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
657 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
658 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
659 | + } |
|
660 | + return $this->_generate_question_input($registration, $question, $answer); |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * @param EE_Registration $registration |
|
666 | + * @param EE_Question $question |
|
667 | + * @param $answer |
|
668 | + * @return EE_Form_Input_Base |
|
669 | + * @throws EE_Error |
|
670 | + * @throws InvalidArgumentException |
|
671 | + * @throws ReflectionException |
|
672 | + * @throws InvalidDataTypeException |
|
673 | + * @throws InvalidInterfaceException |
|
674 | + */ |
|
675 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
676 | + { |
|
677 | + $identifier = $question->is_system_question() |
|
678 | + ? $question->system_ID() |
|
679 | + : $question->ID(); |
|
680 | + $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
681 | + add_filter( |
|
682 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
683 | + array($this, 'use_cached_countries_for_form_input'), |
|
684 | + 10, |
|
685 | + 4 |
|
686 | + ); |
|
687 | + add_filter( |
|
688 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
689 | + array($this, 'use_cached_states_for_form_input'), |
|
690 | + 10, |
|
691 | + 4 |
|
692 | + ); |
|
693 | + $input_constructor_args = array( |
|
694 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
695 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
696 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
697 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
698 | + 'html_label_class' => 'ee-reg-qstn', |
|
699 | + ); |
|
700 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
701 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
702 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
703 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
704 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
705 | + } |
|
706 | + $form_input = $question->generate_form_input( |
|
707 | + $registration, |
|
708 | + $answer, |
|
709 | + $input_constructor_args |
|
710 | + ); |
|
711 | + remove_filter( |
|
712 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | + array($this, 'use_cached_countries_for_form_input') |
|
714 | + ); |
|
715 | + remove_filter( |
|
716 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
717 | + array($this, 'use_cached_states_for_form_input') |
|
718 | + ); |
|
719 | + return $form_input; |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * Gets the list of countries for the form input |
|
725 | + * |
|
726 | + * @param array|null $countries_list |
|
727 | + * @param EE_Question $question |
|
728 | + * @param EE_Registration $registration |
|
729 | + * @param EE_Answer $answer |
|
730 | + * @return array 2d keys are country IDs, values are their names |
|
731 | + * @throws EE_Error |
|
732 | + * @throws InvalidArgumentException |
|
733 | + * @throws InvalidDataTypeException |
|
734 | + * @throws InvalidInterfaceException |
|
735 | + * @throws ReflectionException |
|
736 | + */ |
|
737 | + public function use_cached_countries_for_form_input( |
|
738 | + $countries_list, |
|
739 | + EE_Question $question = null, |
|
740 | + EE_Registration $registration = null, |
|
741 | + EE_Answer $answer = null |
|
742 | + ) { |
|
743 | + $country_options = array('' => ''); |
|
744 | + // get possibly cached list of countries |
|
745 | + $countries = $this->checkout->action === 'process_reg_step' |
|
746 | + ? EEM_Country::instance()->get_all_countries() |
|
747 | + : EEM_Country::instance()->get_all_active_countries(); |
|
748 | + if (! empty($countries)) { |
|
749 | + foreach ($countries as $country) { |
|
750 | + if ($country instanceof EE_Country) { |
|
751 | + $country_options[ $country->ID() ] = $country->name(); |
|
752 | + } |
|
753 | + } |
|
754 | + } |
|
755 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
756 | + $answer = EEM_Answer::instance()->get_one( |
|
757 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
758 | + ); |
|
759 | + } else { |
|
760 | + $answer = EE_Answer::new_instance(); |
|
761 | + } |
|
762 | + $country_options = apply_filters( |
|
763 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
764 | + $country_options, |
|
765 | + $this, |
|
766 | + $registration, |
|
767 | + $question, |
|
768 | + $answer |
|
769 | + ); |
|
770 | + return $country_options; |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * Gets the list of states for the form input |
|
776 | + * |
|
777 | + * @param array|null $states_list |
|
778 | + * @param EE_Question $question |
|
779 | + * @param EE_Registration $registration |
|
780 | + * @param EE_Answer $answer |
|
781 | + * @return array 2d keys are state IDs, values are their names |
|
782 | + * @throws EE_Error |
|
783 | + * @throws InvalidArgumentException |
|
784 | + * @throws InvalidDataTypeException |
|
785 | + * @throws InvalidInterfaceException |
|
786 | + * @throws ReflectionException |
|
787 | + */ |
|
788 | + public function use_cached_states_for_form_input( |
|
789 | + $states_list, |
|
790 | + EE_Question $question = null, |
|
791 | + EE_Registration $registration = null, |
|
792 | + EE_Answer $answer = null |
|
793 | + ) { |
|
794 | + $state_options = array('' => array('' => '')); |
|
795 | + $states = $this->checkout->action === 'process_reg_step' |
|
796 | + ? EEM_State::instance()->get_all_states() |
|
797 | + : EEM_State::instance()->get_all_active_states(); |
|
798 | + if (! empty($states)) { |
|
799 | + foreach ($states as $state) { |
|
800 | + if ($state instanceof EE_State) { |
|
801 | + $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
802 | + } |
|
803 | + } |
|
804 | + } |
|
805 | + $state_options = apply_filters( |
|
806 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
807 | + $state_options, |
|
808 | + $this, |
|
809 | + $registration, |
|
810 | + $question, |
|
811 | + $answer |
|
812 | + ); |
|
813 | + return $state_options; |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + /********************************************************************************************************/ |
|
818 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
819 | + /********************************************************************************************************/ |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * @return bool |
|
824 | + * @throws EE_Error |
|
825 | + * @throws InvalidArgumentException |
|
826 | + * @throws ReflectionException |
|
827 | + * @throws RuntimeException |
|
828 | + * @throws InvalidDataTypeException |
|
829 | + * @throws InvalidInterfaceException |
|
830 | + */ |
|
831 | + public function process_reg_step() |
|
832 | + { |
|
833 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
834 | + // grab validated data from form |
|
835 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
836 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
837 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
838 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
839 | + if (empty($valid_data)) { |
|
840 | + EE_Error::add_error( |
|
841 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
842 | + __FILE__, |
|
843 | + __FUNCTION__, |
|
844 | + __LINE__ |
|
845 | + ); |
|
846 | + return false; |
|
847 | + } |
|
848 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
849 | + EE_Error::add_error( |
|
850 | + esc_html__( |
|
851 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
852 | + 'event_espresso' |
|
853 | + ), |
|
854 | + __FILE__, |
|
855 | + __FUNCTION__, |
|
856 | + __LINE__ |
|
857 | + ); |
|
858 | + return false; |
|
859 | + } |
|
860 | + // get cached registrations |
|
861 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
862 | + // verify we got the goods |
|
863 | + if (empty($registrations)) { |
|
864 | + // combine the old translated string with a new one, in order to not break translations |
|
865 | + $error_message = esc_html__( |
|
866 | + 'Your form data could not be applied to any valid registrations.', |
|
867 | + 'event_espresso' |
|
868 | + ) |
|
869 | + . sprintf( |
|
870 | + esc_html_x( |
|
871 | + '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
872 | + '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
873 | + 'event_espresso' |
|
874 | + ), |
|
875 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
876 | + '</a>', |
|
877 | + '<br />' |
|
878 | + ); |
|
879 | + EE_Error::add_error( |
|
880 | + $error_message, |
|
881 | + __FILE__, |
|
882 | + __FUNCTION__, |
|
883 | + __LINE__ |
|
884 | + ); |
|
885 | + return false; |
|
886 | + } |
|
887 | + // extract attendee info from form data and save to model objects |
|
888 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
889 | + // if first pass thru SPCO, |
|
890 | + // then let's check processed registrations against the total number of tickets in the cart |
|
891 | + if ($registrations_processed === false) { |
|
892 | + // but return immediately if the previous step exited early due to errors |
|
893 | + return false; |
|
894 | + } |
|
895 | + if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
896 | + // generate a correctly translated string for all possible singular/plural combinations |
|
897 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
898 | + $error_msg = sprintf( |
|
899 | + esc_html_x( |
|
900 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
901 | + 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
902 | + 'event_espresso' |
|
903 | + ), |
|
904 | + $this->checkout->total_ticket_count, |
|
905 | + $registrations_processed |
|
906 | + ); |
|
907 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
908 | + $error_msg = sprintf( |
|
909 | + esc_html_x( |
|
910 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
911 | + 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
912 | + 'event_espresso' |
|
913 | + ), |
|
914 | + $this->checkout->total_ticket_count, |
|
915 | + $registrations_processed |
|
916 | + ); |
|
917 | + } else { |
|
918 | + $error_msg = sprintf( |
|
919 | + esc_html__( |
|
920 | + 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
921 | + 'event_espresso' |
|
922 | + ), |
|
923 | + $this->checkout->total_ticket_count, |
|
924 | + $registrations_processed |
|
925 | + ); |
|
926 | + } |
|
927 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
928 | + return false; |
|
929 | + } |
|
930 | + // mark this reg step as completed |
|
931 | + $this->set_completed(); |
|
932 | + $this->_set_success_message( |
|
933 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
934 | + ); |
|
935 | + // do action in case a plugin wants to do something with the data submitted in step 1. |
|
936 | + // passes EE_Single_Page_Checkout, and it's posted data |
|
937 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
938 | + return true; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * _process_registrations |
|
944 | + * |
|
945 | + * @param EE_Registration[] $registrations |
|
946 | + * @param array[][] $valid_data |
|
947 | + * @return bool|int |
|
948 | + * @throws EntityNotFoundException |
|
949 | + * @throws EE_Error |
|
950 | + * @throws InvalidArgumentException |
|
951 | + * @throws ReflectionException |
|
952 | + * @throws RuntimeException |
|
953 | + * @throws InvalidDataTypeException |
|
954 | + * @throws InvalidInterfaceException |
|
955 | + */ |
|
956 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
957 | + { |
|
958 | + // load resources and set some defaults |
|
959 | + EE_Registry::instance()->load_model('Attendee'); |
|
960 | + // holder for primary registrant attendee object |
|
961 | + $this->checkout->primary_attendee_obj = null; |
|
962 | + // array for tracking reg form data for the primary registrant |
|
963 | + $primary_registrant = array( |
|
964 | + 'line_item_id' => null, |
|
965 | + ); |
|
966 | + $copy_primary = false; |
|
967 | + // reg form sections that do not contain inputs |
|
968 | + $non_input_form_sections = array( |
|
969 | + 'primary_registrant', |
|
970 | + 'additional_attendee_reg_info', |
|
971 | + 'spco_copy_attendee_chk', |
|
972 | + ); |
|
973 | + // attendee counter |
|
974 | + $att_nmbr = 0; |
|
975 | + // grab the saved registrations from the transaction |
|
976 | + foreach ($registrations as $registration) { |
|
977 | + // verify EE_Registration object |
|
978 | + if (! $registration instanceof EE_Registration) { |
|
979 | + EE_Error::add_error( |
|
980 | + esc_html__( |
|
981 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
982 | + 'event_espresso' |
|
983 | + ), |
|
984 | + __FILE__, |
|
985 | + __FUNCTION__, |
|
986 | + __LINE__ |
|
987 | + ); |
|
988 | + return false; |
|
989 | + } |
|
990 | + /** @var string $reg_url_link */ |
|
991 | + $reg_url_link = $registration->reg_url_link(); |
|
992 | + // reg_url_link exists ? |
|
993 | + if (! empty($reg_url_link)) { |
|
994 | + // should this registration be processed during this visit ? |
|
995 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
996 | + // if NOT revisiting, then let's save the registration now, |
|
997 | + // so that we have a REG_ID to use when generating other objects |
|
998 | + if (! $this->checkout->revisit) { |
|
999 | + $registration->save(); |
|
1000 | + } |
|
1001 | + /** |
|
1002 | + * This allows plugins to trigger a fail on processing of a |
|
1003 | + * registration for any conditions they may have for it to pass. |
|
1004 | + * |
|
1005 | + * @var bool if true is returned by the plugin then the |
|
1006 | + * registration processing is halted. |
|
1007 | + */ |
|
1008 | + if (apply_filters( |
|
1009 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1010 | + false, |
|
1011 | + $att_nmbr, |
|
1012 | + $registration, |
|
1013 | + $registrations, |
|
1014 | + $valid_data, |
|
1015 | + $this |
|
1016 | + )) { |
|
1017 | + return false; |
|
1018 | + } |
|
1019 | + |
|
1020 | + // Houston, we have a registration! |
|
1021 | + $att_nmbr++; |
|
1022 | + $this->_attendee_data[ $reg_url_link ] = array(); |
|
1023 | + // grab any existing related answer objects |
|
1024 | + $this->_registration_answers = $registration->answers(); |
|
1025 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1026 | + if (isset($valid_data[ $reg_url_link ])) { |
|
1027 | + // do we need to copy basic info from primary attendee ? |
|
1028 | + $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1029 | + && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1030 | + // filter form input data for this registration |
|
1031 | + $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1032 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1033 | + $valid_data[ $reg_url_link ] |
|
1034 | + ); |
|
1035 | + if (isset($valid_data['primary_attendee'])) { |
|
1036 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1037 | + ? $valid_data['primary_attendee'] |
|
1038 | + : false; |
|
1039 | + unset($valid_data['primary_attendee']); |
|
1040 | + } |
|
1041 | + // now loop through our array of valid post data && process attendee reg forms |
|
1042 | + foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1043 | + if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1044 | + foreach ($form_inputs as $form_input => $input_value) { |
|
1045 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1046 | + // check for critical inputs |
|
1047 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1048 | + $form_input, |
|
1049 | + $input_value |
|
1050 | + ) |
|
1051 | + ) { |
|
1052 | + return false; |
|
1053 | + } |
|
1054 | + // store a bit of data about the primary attendee |
|
1055 | + if ($att_nmbr === 1 |
|
1056 | + && ! empty($input_value) |
|
1057 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
1058 | + ) { |
|
1059 | + $primary_registrant[ $form_input ] = $input_value; |
|
1060 | + } elseif ($copy_primary |
|
1061 | + && $input_value === null |
|
1062 | + && isset($primary_registrant[ $form_input ]) |
|
1063 | + ) { |
|
1064 | + $input_value = $primary_registrant[ $form_input ]; |
|
1065 | + } |
|
1066 | + // now attempt to save the input data |
|
1067 | + if (! $this->_save_registration_form_input( |
|
1068 | + $registration, |
|
1069 | + $form_input, |
|
1070 | + $input_value |
|
1071 | + ) |
|
1072 | + ) { |
|
1073 | + EE_Error::add_error( |
|
1074 | + sprintf( |
|
1075 | + esc_html_x( |
|
1076 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1077 | + 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1078 | + 'event_espresso' |
|
1079 | + ), |
|
1080 | + $form_input, |
|
1081 | + $input_value |
|
1082 | + ), |
|
1083 | + __FILE__, |
|
1084 | + __FUNCTION__, |
|
1085 | + __LINE__ |
|
1086 | + ); |
|
1087 | + return false; |
|
1088 | + } |
|
1089 | + } |
|
1090 | + } |
|
1091 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1092 | + } |
|
1093 | + // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1094 | + // this registration does not require additional attendee information ? |
|
1095 | + if ($copy_primary |
|
1096 | + && $att_nmbr > 1 |
|
1097 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1098 | + ) { |
|
1099 | + // just copy the primary registrant |
|
1100 | + $attendee = $this->checkout->primary_attendee_obj; |
|
1101 | + } else { |
|
1102 | + // ensure critical details are set for additional attendees |
|
1103 | + $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1104 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1105 | + $this->_attendee_data[ $reg_url_link ] |
|
1106 | + ) |
|
1107 | + : $this->_attendee_data[ $reg_url_link ]; |
|
1108 | + // execute create attendee command (which may return an existing attendee) |
|
1109 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
1110 | + new CreateAttendeeCommand( |
|
1111 | + $this->_attendee_data[ $reg_url_link ], |
|
1112 | + $registration |
|
1113 | + ) |
|
1114 | + ); |
|
1115 | + // who's #1 ? |
|
1116 | + if ($att_nmbr === 1) { |
|
1117 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1121 | + // add relation to registration, set attendee ID, and cache attendee |
|
1122 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1123 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1124 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
1125 | + EE_Error::add_error( |
|
1126 | + sprintf( |
|
1127 | + esc_html_x( |
|
1128 | + 'Registration %s has an invalid or missing Attendee object.', |
|
1129 | + 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1130 | + 'event_espresso' |
|
1131 | + ), |
|
1132 | + $reg_url_link |
|
1133 | + ), |
|
1134 | + __FILE__, |
|
1135 | + __FUNCTION__, |
|
1136 | + __LINE__ |
|
1137 | + ); |
|
1138 | + return false; |
|
1139 | + } |
|
1140 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1141 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1142 | + // at this point, we should have enough details about the registrant to consider the registration |
|
1143 | + // NOT incomplete |
|
1144 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1145 | + $registration, |
|
1146 | + false, |
|
1147 | + new Context( |
|
1148 | + 'spco_reg_step_attendee_information_process_registrations', |
|
1149 | + esc_html__( |
|
1150 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1151 | + 'event_espresso' |
|
1152 | + ) |
|
1153 | + ) |
|
1154 | + ); |
|
1155 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1156 | + // abandoned |
|
1157 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1158 | + // if we've gotten this far, then let's save what we have |
|
1159 | + $registration->save(); |
|
1160 | + // add relation between TXN and registration |
|
1161 | + $this->_associate_registration_with_transaction($registration); |
|
1162 | + } |
|
1163 | + } else { |
|
1164 | + EE_Error::add_error( |
|
1165 | + esc_html__( |
|
1166 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1167 | + 'event_espresso' |
|
1168 | + ), |
|
1169 | + __FILE__, |
|
1170 | + __FUNCTION__, |
|
1171 | + __LINE__ |
|
1172 | + ); |
|
1173 | + // remove malformed data |
|
1174 | + unset($valid_data[ $reg_url_link ]); |
|
1175 | + return false; |
|
1176 | + } |
|
1177 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1178 | + return $att_nmbr; |
|
1179 | + } |
|
1180 | + |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * _save_registration_form_input |
|
1184 | + * |
|
1185 | + * @param EE_Registration $registration |
|
1186 | + * @param string $form_input |
|
1187 | + * @param string $input_value |
|
1188 | + * @return bool |
|
1189 | + * @throws EE_Error |
|
1190 | + * @throws InvalidArgumentException |
|
1191 | + * @throws InvalidDataTypeException |
|
1192 | + * @throws InvalidInterfaceException |
|
1193 | + * @throws ReflectionException |
|
1194 | + */ |
|
1195 | + private function _save_registration_form_input( |
|
1196 | + EE_Registration $registration, |
|
1197 | + $form_input = '', |
|
1198 | + $input_value = '' |
|
1199 | + ) { |
|
1200 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1201 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1202 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1203 | + // allow for plugins to hook in and do their own processing of the form input. |
|
1204 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1205 | + if (apply_filters( |
|
1206 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1207 | + false, |
|
1208 | + $registration, |
|
1209 | + $form_input, |
|
1210 | + $input_value, |
|
1211 | + $this |
|
1212 | + )) { |
|
1213 | + return true; |
|
1214 | + } |
|
1215 | + /* |
|
1216 | 1216 | * $answer_cache_id is the key used to find the EE_Answer we want |
1217 | 1217 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1218 | 1218 | */ |
1219 | - $answer_cache_id = $this->checkout->reg_url_link |
|
1220 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1221 | - : $form_input; |
|
1222 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1223 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1224 | - // rename form_inputs if they are EE_Attendee properties |
|
1225 | - switch ((string) $form_input) { |
|
1226 | - case 'state': |
|
1227 | - case 'STA_ID': |
|
1228 | - $attendee_property = true; |
|
1229 | - $form_input = 'STA_ID'; |
|
1230 | - break; |
|
1231 | - |
|
1232 | - case 'country': |
|
1233 | - case 'CNT_ISO': |
|
1234 | - $attendee_property = true; |
|
1235 | - $form_input = 'CNT_ISO'; |
|
1236 | - break; |
|
1237 | - |
|
1238 | - default: |
|
1239 | - $ATT_input = 'ATT_' . $form_input; |
|
1240 | - // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1241 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1242 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1243 | - } |
|
1244 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1245 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1246 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1247 | - // if this form input has a corresponding attendee property |
|
1248 | - if ($attendee_property) { |
|
1249 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1250 | - if ($answer_is_obj) { |
|
1251 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
1252 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1253 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1254 | - } |
|
1255 | - return true; |
|
1256 | - } |
|
1257 | - if ($answer_is_obj) { |
|
1258 | - // save this data to the answer object |
|
1259 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1260 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1261 | - return $result !== false; |
|
1262 | - } |
|
1263 | - foreach ($this->_registration_answers as $answer) { |
|
1264 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1265 | - $answer->set_value($input_value); |
|
1266 | - $result = $answer->save(); |
|
1267 | - return $result !== false; |
|
1268 | - } |
|
1269 | - } |
|
1270 | - return false; |
|
1271 | - } |
|
1272 | - |
|
1273 | - |
|
1274 | - /** |
|
1275 | - * _verify_critical_attendee_details_are_set |
|
1276 | - * |
|
1277 | - * @param string $form_input |
|
1278 | - * @param string $input_value |
|
1279 | - * @return boolean |
|
1280 | - */ |
|
1281 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1282 | - $form_input = '', |
|
1283 | - $input_value = '' |
|
1284 | - ) { |
|
1285 | - if (empty($input_value)) { |
|
1286 | - // if the form input isn't marked as being required, then just return |
|
1287 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1288 | - return true; |
|
1289 | - } |
|
1290 | - switch ($form_input) { |
|
1291 | - case 'fname': |
|
1292 | - EE_Error::add_error( |
|
1293 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
1294 | - __FILE__, |
|
1295 | - __FUNCTION__, |
|
1296 | - __LINE__ |
|
1297 | - ); |
|
1298 | - return false; |
|
1299 | - break; |
|
1300 | - case 'lname': |
|
1301 | - EE_Error::add_error( |
|
1302 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1303 | - __FILE__, |
|
1304 | - __FUNCTION__, |
|
1305 | - __LINE__ |
|
1306 | - ); |
|
1307 | - return false; |
|
1308 | - break; |
|
1309 | - case 'email': |
|
1310 | - EE_Error::add_error( |
|
1311 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1312 | - __FILE__, |
|
1313 | - __FUNCTION__, |
|
1314 | - __LINE__ |
|
1315 | - ); |
|
1316 | - return false; |
|
1317 | - break; |
|
1318 | - } |
|
1319 | - } |
|
1320 | - return true; |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * _associate_attendee_with_registration |
|
1326 | - * |
|
1327 | - * @param EE_Registration $registration |
|
1328 | - * @param EE_Attendee $attendee |
|
1329 | - * @return void |
|
1330 | - * @throws EE_Error |
|
1331 | - * @throws InvalidArgumentException |
|
1332 | - * @throws ReflectionException |
|
1333 | - * @throws RuntimeException |
|
1334 | - * @throws InvalidDataTypeException |
|
1335 | - * @throws InvalidInterfaceException |
|
1336 | - */ |
|
1337 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1338 | - { |
|
1339 | - // add relation to attendee |
|
1340 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1341 | - $registration->set_attendee_id($attendee->ID()); |
|
1342 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1343 | - } |
|
1344 | - |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * _associate_registration_with_transaction |
|
1348 | - * |
|
1349 | - * @param EE_Registration $registration |
|
1350 | - * @return void |
|
1351 | - * @throws EE_Error |
|
1352 | - * @throws InvalidArgumentException |
|
1353 | - * @throws ReflectionException |
|
1354 | - * @throws InvalidDataTypeException |
|
1355 | - * @throws InvalidInterfaceException |
|
1356 | - */ |
|
1357 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1358 | - { |
|
1359 | - // add relation to registration |
|
1360 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1361 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1362 | - } |
|
1363 | - |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * _copy_critical_attendee_details_from_primary_registrant |
|
1367 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
1368 | - * |
|
1369 | - * @param array $attendee_data |
|
1370 | - * @return array |
|
1371 | - * @throws EE_Error |
|
1372 | - * @throws InvalidArgumentException |
|
1373 | - * @throws ReflectionException |
|
1374 | - * @throws InvalidDataTypeException |
|
1375 | - * @throws InvalidInterfaceException |
|
1376 | - */ |
|
1377 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1378 | - { |
|
1379 | - // bare minimum critical details include first name, last name, email address |
|
1380 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1381 | - // add address info to critical details? |
|
1382 | - if (apply_filters( |
|
1383 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1384 | - false |
|
1385 | - )) { |
|
1386 | - $address_details = array( |
|
1387 | - 'ATT_address', |
|
1388 | - 'ATT_address2', |
|
1389 | - 'ATT_city', |
|
1390 | - 'STA_ID', |
|
1391 | - 'CNT_ISO', |
|
1392 | - 'ATT_zip', |
|
1393 | - 'ATT_phone', |
|
1394 | - ); |
|
1395 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1396 | - } |
|
1397 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1398 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1399 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
1400 | - ) { |
|
1401 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1402 | - $critical_attendee_detail |
|
1403 | - ); |
|
1404 | - } |
|
1405 | - } |
|
1406 | - return $attendee_data; |
|
1407 | - } |
|
1408 | - |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * update_reg_step |
|
1412 | - * this is the final step after a user revisits the site to edit their attendee information |
|
1413 | - * this gets called AFTER the process_reg_step() method above |
|
1414 | - * |
|
1415 | - * @return bool |
|
1416 | - * @throws EE_Error |
|
1417 | - * @throws InvalidArgumentException |
|
1418 | - * @throws ReflectionException |
|
1419 | - * @throws RuntimeException |
|
1420 | - * @throws InvalidDataTypeException |
|
1421 | - * @throws InvalidInterfaceException |
|
1422 | - */ |
|
1423 | - public function update_reg_step() |
|
1424 | - { |
|
1425 | - // save everything |
|
1426 | - if ($this->process_reg_step()) { |
|
1427 | - $this->checkout->redirect = true; |
|
1428 | - $this->checkout->redirect_url = add_query_arg( |
|
1429 | - array( |
|
1430 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1431 | - 'revisit' => true, |
|
1432 | - ), |
|
1433 | - $this->checkout->thank_you_page_url |
|
1434 | - ); |
|
1435 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1436 | - return true; |
|
1437 | - } |
|
1438 | - return false; |
|
1439 | - } |
|
1219 | + $answer_cache_id = $this->checkout->reg_url_link |
|
1220 | + ? $form_input . '-' . $registration->reg_url_link() |
|
1221 | + : $form_input; |
|
1222 | + $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1223 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1224 | + // rename form_inputs if they are EE_Attendee properties |
|
1225 | + switch ((string) $form_input) { |
|
1226 | + case 'state': |
|
1227 | + case 'STA_ID': |
|
1228 | + $attendee_property = true; |
|
1229 | + $form_input = 'STA_ID'; |
|
1230 | + break; |
|
1231 | + |
|
1232 | + case 'country': |
|
1233 | + case 'CNT_ISO': |
|
1234 | + $attendee_property = true; |
|
1235 | + $form_input = 'CNT_ISO'; |
|
1236 | + break; |
|
1237 | + |
|
1238 | + default: |
|
1239 | + $ATT_input = 'ATT_' . $form_input; |
|
1240 | + // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1241 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1242 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1243 | + } |
|
1244 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1245 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1246 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1247 | + // if this form input has a corresponding attendee property |
|
1248 | + if ($attendee_property) { |
|
1249 | + $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1250 | + if ($answer_is_obj) { |
|
1251 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
1252 | + $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1253 | + $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1254 | + } |
|
1255 | + return true; |
|
1256 | + } |
|
1257 | + if ($answer_is_obj) { |
|
1258 | + // save this data to the answer object |
|
1259 | + $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1260 | + $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1261 | + return $result !== false; |
|
1262 | + } |
|
1263 | + foreach ($this->_registration_answers as $answer) { |
|
1264 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1265 | + $answer->set_value($input_value); |
|
1266 | + $result = $answer->save(); |
|
1267 | + return $result !== false; |
|
1268 | + } |
|
1269 | + } |
|
1270 | + return false; |
|
1271 | + } |
|
1272 | + |
|
1273 | + |
|
1274 | + /** |
|
1275 | + * _verify_critical_attendee_details_are_set |
|
1276 | + * |
|
1277 | + * @param string $form_input |
|
1278 | + * @param string $input_value |
|
1279 | + * @return boolean |
|
1280 | + */ |
|
1281 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1282 | + $form_input = '', |
|
1283 | + $input_value = '' |
|
1284 | + ) { |
|
1285 | + if (empty($input_value)) { |
|
1286 | + // if the form input isn't marked as being required, then just return |
|
1287 | + if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1288 | + return true; |
|
1289 | + } |
|
1290 | + switch ($form_input) { |
|
1291 | + case 'fname': |
|
1292 | + EE_Error::add_error( |
|
1293 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
1294 | + __FILE__, |
|
1295 | + __FUNCTION__, |
|
1296 | + __LINE__ |
|
1297 | + ); |
|
1298 | + return false; |
|
1299 | + break; |
|
1300 | + case 'lname': |
|
1301 | + EE_Error::add_error( |
|
1302 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1303 | + __FILE__, |
|
1304 | + __FUNCTION__, |
|
1305 | + __LINE__ |
|
1306 | + ); |
|
1307 | + return false; |
|
1308 | + break; |
|
1309 | + case 'email': |
|
1310 | + EE_Error::add_error( |
|
1311 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1312 | + __FILE__, |
|
1313 | + __FUNCTION__, |
|
1314 | + __LINE__ |
|
1315 | + ); |
|
1316 | + return false; |
|
1317 | + break; |
|
1318 | + } |
|
1319 | + } |
|
1320 | + return true; |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * _associate_attendee_with_registration |
|
1326 | + * |
|
1327 | + * @param EE_Registration $registration |
|
1328 | + * @param EE_Attendee $attendee |
|
1329 | + * @return void |
|
1330 | + * @throws EE_Error |
|
1331 | + * @throws InvalidArgumentException |
|
1332 | + * @throws ReflectionException |
|
1333 | + * @throws RuntimeException |
|
1334 | + * @throws InvalidDataTypeException |
|
1335 | + * @throws InvalidInterfaceException |
|
1336 | + */ |
|
1337 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1338 | + { |
|
1339 | + // add relation to attendee |
|
1340 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1341 | + $registration->set_attendee_id($attendee->ID()); |
|
1342 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1343 | + } |
|
1344 | + |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * _associate_registration_with_transaction |
|
1348 | + * |
|
1349 | + * @param EE_Registration $registration |
|
1350 | + * @return void |
|
1351 | + * @throws EE_Error |
|
1352 | + * @throws InvalidArgumentException |
|
1353 | + * @throws ReflectionException |
|
1354 | + * @throws InvalidDataTypeException |
|
1355 | + * @throws InvalidInterfaceException |
|
1356 | + */ |
|
1357 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1358 | + { |
|
1359 | + // add relation to registration |
|
1360 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1361 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1362 | + } |
|
1363 | + |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * _copy_critical_attendee_details_from_primary_registrant |
|
1367 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
1368 | + * |
|
1369 | + * @param array $attendee_data |
|
1370 | + * @return array |
|
1371 | + * @throws EE_Error |
|
1372 | + * @throws InvalidArgumentException |
|
1373 | + * @throws ReflectionException |
|
1374 | + * @throws InvalidDataTypeException |
|
1375 | + * @throws InvalidInterfaceException |
|
1376 | + */ |
|
1377 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1378 | + { |
|
1379 | + // bare minimum critical details include first name, last name, email address |
|
1380 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1381 | + // add address info to critical details? |
|
1382 | + if (apply_filters( |
|
1383 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1384 | + false |
|
1385 | + )) { |
|
1386 | + $address_details = array( |
|
1387 | + 'ATT_address', |
|
1388 | + 'ATT_address2', |
|
1389 | + 'ATT_city', |
|
1390 | + 'STA_ID', |
|
1391 | + 'CNT_ISO', |
|
1392 | + 'ATT_zip', |
|
1393 | + 'ATT_phone', |
|
1394 | + ); |
|
1395 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1396 | + } |
|
1397 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1398 | + if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1399 | + || empty($attendee_data[ $critical_attendee_detail ]) |
|
1400 | + ) { |
|
1401 | + $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1402 | + $critical_attendee_detail |
|
1403 | + ); |
|
1404 | + } |
|
1405 | + } |
|
1406 | + return $attendee_data; |
|
1407 | + } |
|
1408 | + |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * update_reg_step |
|
1412 | + * this is the final step after a user revisits the site to edit their attendee information |
|
1413 | + * this gets called AFTER the process_reg_step() method above |
|
1414 | + * |
|
1415 | + * @return bool |
|
1416 | + * @throws EE_Error |
|
1417 | + * @throws InvalidArgumentException |
|
1418 | + * @throws ReflectionException |
|
1419 | + * @throws RuntimeException |
|
1420 | + * @throws InvalidDataTypeException |
|
1421 | + * @throws InvalidInterfaceException |
|
1422 | + */ |
|
1423 | + public function update_reg_step() |
|
1424 | + { |
|
1425 | + // save everything |
|
1426 | + if ($this->process_reg_step()) { |
|
1427 | + $this->checkout->redirect = true; |
|
1428 | + $this->checkout->redirect_url = add_query_arg( |
|
1429 | + array( |
|
1430 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1431 | + 'revisit' => true, |
|
1432 | + ), |
|
1433 | + $this->checkout->thank_you_page_url |
|
1434 | + ); |
|
1435 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1436 | + return true; |
|
1437 | + } |
|
1438 | + return false; |
|
1439 | + } |
|
1440 | 1440 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->_slug = 'attendee_information'; |
51 | 51 | $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
52 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
52 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
53 | 53 | $this->checkout = $checkout; |
54 | 54 | $this->_reset_success_message(); |
55 | 55 | $this->set_instructions( |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
144 | 144 | // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
145 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
145 | + if ( ! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
146 | 146 | $extra_inputs_section->add_subsections( |
147 | 147 | array( |
148 | 148 | 'consent_box' => new EE_Form_Section_Proper( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'layout_strategy' => |
151 | 151 | new EE_Template_Layout( |
152 | 152 | array( |
153 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . DS . 'privacy_consent.template.php', |
|
153 | + 'input_template_file' => SPCO_REG_STEPS_PATH.$this->_slug.DS.'privacy_consent.template.php', |
|
154 | 154 | ) |
155 | 155 | ), |
156 | 156 | 'subsections' => array( |
@@ -188,13 +188,13 @@ discard block |
||
188 | 188 | if ($registration instanceof EE_Registration |
189 | 189 | && $this->checkout->visit_allows_processing_of_this_registration($registration) |
190 | 190 | ) { |
191 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
192 | - if (! $this->checkout->admin_request) { |
|
193 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
194 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
195 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
191 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
192 | + if ( ! $this->checkout->admin_request) { |
|
193 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
194 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
195 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
196 | 196 | ) |
197 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
197 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
198 | 198 | : 1; |
199 | 199 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
200 | 200 | $this->checkout->cart->get_grand_total(), |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $ticket_line_item = is_array($ticket_line_item) |
205 | 205 | ? reset($ticket_line_item) |
206 | 206 | : $ticket_line_item; |
207 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
207 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
208 | 208 | $Line_Item_Display->display_line_item($ticket_line_item); |
209 | 209 | } |
210 | 210 | if ($registration->is_primary_registrant()) { |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | ? $this->_copy_attendee_info_form() |
221 | 221 | : $this->_auto_copy_attendee_info(); |
222 | 222 | // generate hidden input |
223 | - if (isset($subsections[ $primary_registrant ]) |
|
224 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
223 | + if (isset($subsections[$primary_registrant]) |
|
224 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
225 | 225 | ) { |
226 | - $subsections[ $primary_registrant ]->add_subsections( |
|
226 | + $subsections[$primary_registrant]->add_subsections( |
|
227 | 227 | $copy_options, |
228 | 228 | 'primary_registrant', |
229 | 229 | false |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | if ($question_groups) { |
285 | 285 | // array of params to pass to parent constructor |
286 | 286 | $form_args = array( |
287 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
287 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
288 | 288 | 'html_class' => 'ee-reg-form-attendee-dv', |
289 | 289 | 'html_style' => $this->checkout->admin_request |
290 | 290 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | ); |
307 | 307 | foreach ($question_groups as $question_group) { |
308 | 308 | if ($question_group instanceof EE_Question_Group) { |
309 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
309 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
310 | 310 | $registration, |
311 | 311 | $question_group |
312 | 312 | ); |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | // generate hidden input |
347 | 347 | return new EE_Hidden_Input( |
348 | 348 | array( |
349 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
349 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
350 | 350 | 'default' => $additional_attendee_reg_info, |
351 | 351 | ) |
352 | 352 | ); |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | { |
368 | 368 | // array of params to pass to parent constructor |
369 | 369 | $form_args = array( |
370 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
370 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(), |
|
371 | 371 | 'html_class' => $this->checkout->admin_request |
372 | 372 | ? 'form-table ee-reg-form-qstn-grp-dv' |
373 | 373 | : 'ee-reg-form-qstn-grp-dv', |
374 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
375 | - . $registration->ID() . '-lbl', |
|
374 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-' |
|
375 | + . $registration->ID().'-lbl', |
|
376 | 376 | 'subsections' => array( |
377 | 377 | 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
378 | 378 | ), |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | // where params |
384 | 384 | $query_params = array('QST_deleted' => 0); |
385 | 385 | // don't load admin only questions on the frontend |
386 | - if (! $this->checkout->admin_request) { |
|
386 | + if ( ! $this->checkout->admin_request) { |
|
387 | 387 | $query_params['QST_admin_only'] = array('!=', true); |
388 | 388 | } |
389 | 389 | $questions = $question_group->get_many_related( |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | $identifier = $question->is_system_question() |
418 | 418 | ? $question->system_ID() |
419 | 419 | : $question->ID(); |
420 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
420 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | $form_args['subsections'] = apply_filters( |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | { |
531 | 531 | return new EE_Form_Section_HTML( |
532 | 532 | EEH_Template::locate_template( |
533 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
533 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
534 | 534 | apply_filters( |
535 | 535 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
536 | 536 | array() |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | if ($registration->ticket()->ID() !== $prev_ticket) { |
564 | 564 | $item_name = $registration->ticket()->name(); |
565 | 565 | $item_name .= $registration->ticket()->description() !== '' |
566 | - ? ' - ' . $registration->ticket()->description() |
|
566 | + ? ' - '.$registration->ticket()->description() |
|
567 | 567 | : ''; |
568 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
569 | - ) . ']' ] = |
|
568 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID( |
|
569 | + ).']'] = |
|
570 | 570 | new EE_Form_Section_HTML( |
571 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
571 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
572 | 572 | ); |
573 | 573 | $prev_ticket = $registration->ticket()->ID(); |
574 | 574 | } |
575 | 575 | |
576 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
576 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = |
|
577 | 577 | new EE_Checkbox_Multi_Input( |
578 | 578 | array( |
579 | 579 | $registration->ID() => sprintf( |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | ), |
583 | 583 | ), |
584 | 584 | array( |
585 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
585 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
586 | 586 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
587 | 587 | 'display_html_label_text' => false, |
588 | 588 | ) |
@@ -647,14 +647,14 @@ discard block |
||
647 | 647 | } |
648 | 648 | // verify instance |
649 | 649 | if ($answer instanceof EE_Answer) { |
650 | - if (! empty($answer_value)) { |
|
650 | + if ( ! empty($answer_value)) { |
|
651 | 651 | $answer->set('ANS_value', $answer_value); |
652 | 652 | } |
653 | 653 | $answer->cache('Question', $question); |
654 | 654 | // remember system ID had a bug where sometimes it could be null |
655 | 655 | $answer_cache_id = $question->is_system_question() |
656 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
657 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
656 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
657 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
658 | 658 | $registration->cache('Answer', $answer, $answer_cache_id); |
659 | 659 | } |
660 | 660 | return $this->_generate_question_input($registration, $question, $answer); |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | $identifier = $question->is_system_question() |
678 | 678 | ? $question->system_ID() |
679 | 679 | : $question->ID(); |
680 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
680 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
681 | 681 | add_filter( |
682 | 682 | 'FHEE__EE_Question__generate_form_input__country_options', |
683 | 683 | array($this, 'use_cached_countries_for_form_input'), |
@@ -691,17 +691,17 @@ discard block |
||
691 | 691 | 4 |
692 | 692 | ); |
693 | 693 | $input_constructor_args = array( |
694 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
695 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
696 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
697 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
694 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
695 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
696 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
697 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
698 | 698 | 'html_label_class' => 'ee-reg-qstn', |
699 | 699 | ); |
700 | 700 | $input_constructor_args['html_label_id'] .= '-lbl'; |
701 | 701 | if ($answer instanceof EE_Answer && $answer->ID()) { |
702 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
703 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
704 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
702 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
703 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
704 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
705 | 705 | } |
706 | 706 | $form_input = $question->generate_form_input( |
707 | 707 | $registration, |
@@ -745,10 +745,10 @@ discard block |
||
745 | 745 | $countries = $this->checkout->action === 'process_reg_step' |
746 | 746 | ? EEM_Country::instance()->get_all_countries() |
747 | 747 | : EEM_Country::instance()->get_all_active_countries(); |
748 | - if (! empty($countries)) { |
|
748 | + if ( ! empty($countries)) { |
|
749 | 749 | foreach ($countries as $country) { |
750 | 750 | if ($country instanceof EE_Country) { |
751 | - $country_options[ $country->ID() ] = $country->name(); |
|
751 | + $country_options[$country->ID()] = $country->name(); |
|
752 | 752 | } |
753 | 753 | } |
754 | 754 | } |
@@ -795,10 +795,10 @@ discard block |
||
795 | 795 | $states = $this->checkout->action === 'process_reg_step' |
796 | 796 | ? EEM_State::instance()->get_all_states() |
797 | 797 | : EEM_State::instance()->get_all_active_states(); |
798 | - if (! empty($states)) { |
|
798 | + if ( ! empty($states)) { |
|
799 | 799 | foreach ($states as $state) { |
800 | 800 | if ($state instanceof EE_State) { |
801 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
801 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
802 | 802 | } |
803 | 803 | } |
804 | 804 | } |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | ); |
846 | 846 | return false; |
847 | 847 | } |
848 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
848 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
849 | 849 | EE_Error::add_error( |
850 | 850 | esc_html__( |
851 | 851 | 'A valid transaction could not be initiated for processing your registrations.', |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
873 | 873 | 'event_espresso' |
874 | 874 | ), |
875 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
875 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
876 | 876 | '</a>', |
877 | 877 | '<br />' |
878 | 878 | ); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | // but return immediately if the previous step exited early due to errors |
893 | 893 | return false; |
894 | 894 | } |
895 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
895 | + if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
896 | 896 | // generate a correctly translated string for all possible singular/plural combinations |
897 | 897 | if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
898 | 898 | $error_msg = sprintf( |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | // grab the saved registrations from the transaction |
976 | 976 | foreach ($registrations as $registration) { |
977 | 977 | // verify EE_Registration object |
978 | - if (! $registration instanceof EE_Registration) { |
|
978 | + if ( ! $registration instanceof EE_Registration) { |
|
979 | 979 | EE_Error::add_error( |
980 | 980 | esc_html__( |
981 | 981 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -990,12 +990,12 @@ discard block |
||
990 | 990 | /** @var string $reg_url_link */ |
991 | 991 | $reg_url_link = $registration->reg_url_link(); |
992 | 992 | // reg_url_link exists ? |
993 | - if (! empty($reg_url_link)) { |
|
993 | + if ( ! empty($reg_url_link)) { |
|
994 | 994 | // should this registration be processed during this visit ? |
995 | 995 | if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
996 | 996 | // if NOT revisiting, then let's save the registration now, |
997 | 997 | // so that we have a REG_ID to use when generating other objects |
998 | - if (! $this->checkout->revisit) { |
|
998 | + if ( ! $this->checkout->revisit) { |
|
999 | 999 | $registration->save(); |
1000 | 1000 | } |
1001 | 1001 | /** |
@@ -1019,18 +1019,18 @@ discard block |
||
1019 | 1019 | |
1020 | 1020 | // Houston, we have a registration! |
1021 | 1021 | $att_nmbr++; |
1022 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
1022 | + $this->_attendee_data[$reg_url_link] = array(); |
|
1023 | 1023 | // grab any existing related answer objects |
1024 | 1024 | $this->_registration_answers = $registration->answers(); |
1025 | 1025 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
1026 | - if (isset($valid_data[ $reg_url_link ])) { |
|
1026 | + if (isset($valid_data[$reg_url_link])) { |
|
1027 | 1027 | // do we need to copy basic info from primary attendee ? |
1028 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1029 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1028 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
1029 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0; |
|
1030 | 1030 | // filter form input data for this registration |
1031 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1031 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
1032 | 1032 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
1033 | - $valid_data[ $reg_url_link ] |
|
1033 | + $valid_data[$reg_url_link] |
|
1034 | 1034 | ); |
1035 | 1035 | if (isset($valid_data['primary_attendee'])) { |
1036 | 1036 | $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
@@ -1039,12 +1039,12 @@ discard block |
||
1039 | 1039 | unset($valid_data['primary_attendee']); |
1040 | 1040 | } |
1041 | 1041 | // now loop through our array of valid post data && process attendee reg forms |
1042 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1043 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1042 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
1043 | + if ( ! in_array($form_section, $non_input_form_sections, true)) { |
|
1044 | 1044 | foreach ($form_inputs as $form_input => $input_value) { |
1045 | 1045 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
1046 | 1046 | // check for critical inputs |
1047 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1047 | + if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1048 | 1048 | $form_input, |
1049 | 1049 | $input_value |
1050 | 1050 | ) |
@@ -1056,15 +1056,15 @@ discard block |
||
1056 | 1056 | && ! empty($input_value) |
1057 | 1057 | && $reg_url_link === $primary_registrant['line_item_id'] |
1058 | 1058 | ) { |
1059 | - $primary_registrant[ $form_input ] = $input_value; |
|
1059 | + $primary_registrant[$form_input] = $input_value; |
|
1060 | 1060 | } elseif ($copy_primary |
1061 | 1061 | && $input_value === null |
1062 | - && isset($primary_registrant[ $form_input ]) |
|
1062 | + && isset($primary_registrant[$form_input]) |
|
1063 | 1063 | ) { |
1064 | - $input_value = $primary_registrant[ $form_input ]; |
|
1064 | + $input_value = $primary_registrant[$form_input]; |
|
1065 | 1065 | } |
1066 | 1066 | // now attempt to save the input data |
1067 | - if (! $this->_save_registration_form_input( |
|
1067 | + if ( ! $this->_save_registration_form_input( |
|
1068 | 1068 | $registration, |
1069 | 1069 | $form_input, |
1070 | 1070 | $input_value |
@@ -1100,15 +1100,15 @@ discard block |
||
1100 | 1100 | $attendee = $this->checkout->primary_attendee_obj; |
1101 | 1101 | } else { |
1102 | 1102 | // ensure critical details are set for additional attendees |
1103 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1103 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1104 | 1104 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
1105 | - $this->_attendee_data[ $reg_url_link ] |
|
1105 | + $this->_attendee_data[$reg_url_link] |
|
1106 | 1106 | ) |
1107 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1107 | + : $this->_attendee_data[$reg_url_link]; |
|
1108 | 1108 | // execute create attendee command (which may return an existing attendee) |
1109 | 1109 | $attendee = EE_Registry::instance()->BUS->execute( |
1110 | 1110 | new CreateAttendeeCommand( |
1111 | - $this->_attendee_data[ $reg_url_link ], |
|
1111 | + $this->_attendee_data[$reg_url_link], |
|
1112 | 1112 | $registration |
1113 | 1113 | ) |
1114 | 1114 | ); |
@@ -1121,7 +1121,7 @@ discard block |
||
1121 | 1121 | // add relation to registration, set attendee ID, and cache attendee |
1122 | 1122 | $this->_associate_attendee_with_registration($registration, $attendee); |
1123 | 1123 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
1124 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1124 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
1125 | 1125 | EE_Error::add_error( |
1126 | 1126 | sprintf( |
1127 | 1127 | esc_html_x( |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | __LINE__ |
1172 | 1172 | ); |
1173 | 1173 | // remove malformed data |
1174 | - unset($valid_data[ $reg_url_link ]); |
|
1174 | + unset($valid_data[$reg_url_link]); |
|
1175 | 1175 | return false; |
1176 | 1176 | } |
1177 | 1177 | } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
@@ -1217,10 +1217,10 @@ discard block |
||
1217 | 1217 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1218 | 1218 | */ |
1219 | 1219 | $answer_cache_id = $this->checkout->reg_url_link |
1220 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1220 | + ? $form_input.'-'.$registration->reg_url_link() |
|
1221 | 1221 | : $form_input; |
1222 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1223 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1222 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1223 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer; |
|
1224 | 1224 | // rename form_inputs if they are EE_Attendee properties |
1225 | 1225 | switch ((string) $form_input) { |
1226 | 1226 | case 'state': |
@@ -1236,28 +1236,28 @@ discard block |
||
1236 | 1236 | break; |
1237 | 1237 | |
1238 | 1238 | default: |
1239 | - $ATT_input = 'ATT_' . $form_input; |
|
1239 | + $ATT_input = 'ATT_'.$form_input; |
|
1240 | 1240 | // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1241 | 1241 | $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
1242 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1242 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1243 | 1243 | } |
1244 | 1244 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1245 | 1245 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
1246 | 1246 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
1247 | 1247 | // if this form input has a corresponding attendee property |
1248 | 1248 | if ($attendee_property) { |
1249 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1249 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1250 | 1250 | if ($answer_is_obj) { |
1251 | 1251 | // and delete the corresponding answer since we won't be storing this data in that object |
1252 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1253 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1252 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1253 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1254 | 1254 | } |
1255 | 1255 | return true; |
1256 | 1256 | } |
1257 | 1257 | if ($answer_is_obj) { |
1258 | 1258 | // save this data to the answer object |
1259 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1260 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1259 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1260 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1261 | 1261 | return $result !== false; |
1262 | 1262 | } |
1263 | 1263 | foreach ($this->_registration_answers as $answer) { |
@@ -1284,7 +1284,7 @@ discard block |
||
1284 | 1284 | ) { |
1285 | 1285 | if (empty($input_value)) { |
1286 | 1286 | // if the form input isn't marked as being required, then just return |
1287 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1287 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1288 | 1288 | return true; |
1289 | 1289 | } |
1290 | 1290 | switch ($form_input) { |
@@ -1395,10 +1395,10 @@ discard block |
||
1395 | 1395 | $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
1396 | 1396 | } |
1397 | 1397 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
1398 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1399 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
1398 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1399 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1400 | 1400 | ) { |
1401 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1401 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1402 | 1402 | $critical_attendee_detail |
1403 | 1403 | ); |
1404 | 1404 | } |
@@ -13,7 +13,6 @@ |
||
13 | 13 | use EEH_HTML; |
14 | 14 | use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
15 | 15 | use EventEspresso\core\libraries\form_sections\form_handlers\FormHandler; |
16 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
17 | 16 | |
18 | 17 | /** |
19 | 18 | * Class PrivacySettingsFormHandler |
@@ -28,112 +28,112 @@ |
||
28 | 28 | class PrivacySettingsFormHandler extends FormHandler |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var EE_Config |
|
33 | - */ |
|
34 | - protected $config; |
|
31 | + /** |
|
32 | + * @var EE_Config |
|
33 | + */ |
|
34 | + protected $config; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * PrivacySettingsFormHandler constructor. |
|
39 | - * |
|
40 | - * @param EE_Registry $registry |
|
41 | - * @param EE_Config $config |
|
42 | - */ |
|
43 | - public function __construct(EE_Registry $registry, EE_Config $config) |
|
44 | - { |
|
45 | - $this->config = $config; |
|
46 | - parent::__construct( |
|
47 | - esc_html__('Privacy Settings', 'event_espresso'), |
|
48 | - esc_html__('Privacy Settings', 'event_espresso'), |
|
49 | - 'privacy-settings', |
|
50 | - '', |
|
51 | - FormHandler::DO_NOT_SETUP_FORM, |
|
52 | - $registry |
|
53 | - ); |
|
54 | - } |
|
37 | + /** |
|
38 | + * PrivacySettingsFormHandler constructor. |
|
39 | + * |
|
40 | + * @param EE_Registry $registry |
|
41 | + * @param EE_Config $config |
|
42 | + */ |
|
43 | + public function __construct(EE_Registry $registry, EE_Config $config) |
|
44 | + { |
|
45 | + $this->config = $config; |
|
46 | + parent::__construct( |
|
47 | + esc_html__('Privacy Settings', 'event_espresso'), |
|
48 | + esc_html__('Privacy Settings', 'event_espresso'), |
|
49 | + 'privacy-settings', |
|
50 | + '', |
|
51 | + FormHandler::DO_NOT_SETUP_FORM, |
|
52 | + $registry |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * creates and returns the actual form |
|
59 | - * |
|
60 | - * @return EE_Form_Section_Proper |
|
61 | - */ |
|
62 | - public function generate() |
|
63 | - { |
|
64 | - // this form makes use of the session for passing around invalid form submission data, so make sure its enabled |
|
65 | - add_filter('FHEE__EE_Session___save_session_to_db__abort_session_save', '__return_false'); |
|
66 | - /** |
|
67 | - * @var $reg_config EE_Registration_Config |
|
68 | - */ |
|
69 | - $reg_config = $this->config->registration; |
|
70 | - return new EE_Form_Section_Proper( |
|
71 | - array( |
|
72 | - 'name' => 'privacy_consent_settings', |
|
73 | - 'subsections' => array( |
|
74 | - 'privacy_consent_form_hdr' => new EE_Form_Section_HTML( |
|
75 | - EEH_HTML::h2(esc_html__('Privacy Policy Consent Settings', 'event_espresso')) |
|
76 | - ), |
|
77 | - 'enable' => new EE_Select_Reveal_Input( |
|
78 | - array( |
|
79 | - 'enable-privacy-consent' => esc_html__('Enabled', 'event_espresso'), |
|
80 | - 'disable' => esc_html__('Disabled', 'event_espresso'), |
|
81 | - ), |
|
82 | - array( |
|
83 | - 'default' => $reg_config->isConsentCheckboxEnabled() |
|
84 | - ? 'enable-privacy-consent' |
|
85 | - : 'disable', |
|
86 | - 'html_label_text' => esc_html__('Privacy Consent Checkbox', 'event_espresso'), |
|
87 | - 'html_help_text' => esc_html__( |
|
88 | - 'When enabled, a checkbox appears in the registration form requiring users to consent to your site\'s privacy policy.', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - ) |
|
92 | - ), |
|
93 | - 'enable-privacy-consent' => new EE_Form_Section_Proper( |
|
94 | - array( |
|
95 | - 'subsections' => array( |
|
96 | - 'consent_assertion' => new EE_Text_Area_Input( |
|
97 | - array( |
|
98 | - 'default' => $reg_config->getConsentCheckboxLabelText(), |
|
99 | - 'html_label_text' => esc_html__('Consent Text', 'event_espresso'), |
|
100 | - 'html_help_text' => esc_html__( |
|
101 | - 'Text describing what the registrant is consenting to by submitting their personal data in the registration form. To reset to default value, remove all this text and save.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
105 | - ) |
|
106 | - ), |
|
107 | - ), |
|
108 | - ) |
|
109 | - ), |
|
110 | - ), |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
57 | + /** |
|
58 | + * creates and returns the actual form |
|
59 | + * |
|
60 | + * @return EE_Form_Section_Proper |
|
61 | + */ |
|
62 | + public function generate() |
|
63 | + { |
|
64 | + // this form makes use of the session for passing around invalid form submission data, so make sure its enabled |
|
65 | + add_filter('FHEE__EE_Session___save_session_to_db__abort_session_save', '__return_false'); |
|
66 | + /** |
|
67 | + * @var $reg_config EE_Registration_Config |
|
68 | + */ |
|
69 | + $reg_config = $this->config->registration; |
|
70 | + return new EE_Form_Section_Proper( |
|
71 | + array( |
|
72 | + 'name' => 'privacy_consent_settings', |
|
73 | + 'subsections' => array( |
|
74 | + 'privacy_consent_form_hdr' => new EE_Form_Section_HTML( |
|
75 | + EEH_HTML::h2(esc_html__('Privacy Policy Consent Settings', 'event_espresso')) |
|
76 | + ), |
|
77 | + 'enable' => new EE_Select_Reveal_Input( |
|
78 | + array( |
|
79 | + 'enable-privacy-consent' => esc_html__('Enabled', 'event_espresso'), |
|
80 | + 'disable' => esc_html__('Disabled', 'event_espresso'), |
|
81 | + ), |
|
82 | + array( |
|
83 | + 'default' => $reg_config->isConsentCheckboxEnabled() |
|
84 | + ? 'enable-privacy-consent' |
|
85 | + : 'disable', |
|
86 | + 'html_label_text' => esc_html__('Privacy Consent Checkbox', 'event_espresso'), |
|
87 | + 'html_help_text' => esc_html__( |
|
88 | + 'When enabled, a checkbox appears in the registration form requiring users to consent to your site\'s privacy policy.', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + ) |
|
92 | + ), |
|
93 | + 'enable-privacy-consent' => new EE_Form_Section_Proper( |
|
94 | + array( |
|
95 | + 'subsections' => array( |
|
96 | + 'consent_assertion' => new EE_Text_Area_Input( |
|
97 | + array( |
|
98 | + 'default' => $reg_config->getConsentCheckboxLabelText(), |
|
99 | + 'html_label_text' => esc_html__('Consent Text', 'event_espresso'), |
|
100 | + 'html_help_text' => esc_html__( |
|
101 | + 'Text describing what the registrant is consenting to by submitting their personal data in the registration form. To reset to default value, remove all this text and save.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
105 | + ) |
|
106 | + ), |
|
107 | + ), |
|
108 | + ) |
|
109 | + ), |
|
110 | + ), |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * After validating the form data, update the registration config |
|
118 | - * |
|
119 | - * @param array $submitted_form_data |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function process($submitted_form_data = array()) |
|
123 | - { |
|
124 | - try { |
|
125 | - $valid_data = parent::process($submitted_form_data); |
|
126 | - $reg_config = $this->config->registration; |
|
127 | - $reg_config->setConsentCheckboxEnabled($valid_data['enable'] === 'enable-privacy-consent'); |
|
128 | - $reg_config->setConsentCheckboxLabelText( |
|
129 | - $valid_data['enable-privacy-consent']['consent_assertion'] |
|
130 | - ); |
|
131 | - return $this->config->update_espresso_config(false, false); |
|
132 | - } catch (InvalidFormSubmissionException $e) { |
|
133 | - // the form was invalid, it should be re-displayed with errors |
|
134 | - return false; |
|
135 | - } |
|
136 | - } |
|
116 | + /** |
|
117 | + * After validating the form data, update the registration config |
|
118 | + * |
|
119 | + * @param array $submitted_form_data |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function process($submitted_form_data = array()) |
|
123 | + { |
|
124 | + try { |
|
125 | + $valid_data = parent::process($submitted_form_data); |
|
126 | + $reg_config = $this->config->registration; |
|
127 | + $reg_config->setConsentCheckboxEnabled($valid_data['enable'] === 'enable-privacy-consent'); |
|
128 | + $reg_config->setConsentCheckboxLabelText( |
|
129 | + $valid_data['enable-privacy-consent']['consent_assertion'] |
|
130 | + ); |
|
131 | + return $this->config->update_espresso_config(false, false); |
|
132 | + } catch (InvalidFormSubmissionException $e) { |
|
133 | + // the form was invalid, it should be re-displayed with errors |
|
134 | + return false; |
|
135 | + } |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | // End of file PrivacySettingsFormHandler.php |
139 | 139 | // Location: EventEspresso\core\domain\services\admin\privacy\forms/PrivacySettingsFormHandler.php |
@@ -13,116 +13,116 @@ |
||
13 | 13 | interface RequestTypeContextCheckerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * true if the current request involves some form of activation |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActivation(); |
|
16 | + /** |
|
17 | + * true if the current request involves some form of activation |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActivation(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param $is_activation |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function setIsActivation($is_activation); |
|
24 | + /** |
|
25 | + * @param $is_activation |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function setIsActivation($is_activation); |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * true if the current request is for the admin and is not being made via AJAX |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isAdmin(); |
|
31 | + /** |
|
32 | + * true if the current request is for the admin and is not being made via AJAX |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isAdmin(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * true if the current request is for the admin AND is being made via AJAX |
|
41 | - * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isAdminAjax(); |
|
39 | + /** |
|
40 | + * true if the current request is for the admin AND is being made via AJAX |
|
41 | + * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isAdminAjax(); |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * true if the current request is being made via AJAX... any AJAX |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function isAjax(); |
|
48 | + /** |
|
49 | + * true if the current request is being made via AJAX... any AJAX |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function isAjax(); |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * true if the current request is for the EE REST API |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isApi(); |
|
56 | + /** |
|
57 | + * true if the current request is for the EE REST API |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isApi(); |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * true if the current request is from the command line |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isCli(); |
|
64 | + /** |
|
65 | + * true if the current request is from the command line |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isCli(); |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * true if the current request is for a WP_Cron |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isCron(); |
|
72 | + /** |
|
73 | + * true if the current request is for a WP_Cron |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isCron(); |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isEeAjax(); |
|
80 | + /** |
|
81 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isEeAjax(); |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * true if the current request is for a feed (ie: RSS) |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function isFeed(); |
|
88 | + /** |
|
89 | + * true if the current request is for a feed (ie: RSS) |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function isFeed(); |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * true if the current request is for the frontend and is not being made via AJAX |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function isFrontend(); |
|
96 | + /** |
|
97 | + * true if the current request is for the frontend and is not being made via AJAX |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function isFrontend(); |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function isFrontAjax(); |
|
104 | + /** |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function isFrontAjax(); |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isIframe(); |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isIframe(); |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | - * |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function isOtherAjax(); |
|
116 | + /** |
|
117 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | + * |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function isOtherAjax(); |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function slug(); |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function slug(); |
|
128 | 128 | } |
@@ -28,616 +28,616 @@ |
||
28 | 28 | abstract class FormHandler implements FormHandlerInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * will add opening and closing HTML form tags as well as a submit button |
|
33 | - */ |
|
34 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
35 | - |
|
36 | - /** |
|
37 | - * will add opening and closing HTML form tags but NOT a submit button |
|
38 | - */ |
|
39 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
40 | - |
|
41 | - /** |
|
42 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
43 | - */ |
|
44 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
45 | - |
|
46 | - /** |
|
47 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
48 | - */ |
|
49 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
50 | - |
|
51 | - /** |
|
52 | - * if set to false, then this form has no displayable content, |
|
53 | - * and will only be used for processing data sent passed via GET or POST |
|
54 | - * defaults to true ( ie: form has displayable content ) |
|
55 | - * |
|
56 | - * @var boolean $displayable |
|
57 | - */ |
|
58 | - private $displayable = true; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var string $form_name |
|
62 | - */ |
|
63 | - private $form_name; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var string $admin_name |
|
67 | - */ |
|
68 | - private $admin_name; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var string $slug |
|
72 | - */ |
|
73 | - private $slug; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var string $submit_btn_text |
|
77 | - */ |
|
78 | - private $submit_btn_text; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string $form_action |
|
82 | - */ |
|
83 | - private $form_action; |
|
84 | - |
|
85 | - /** |
|
86 | - * form params in key value pairs |
|
87 | - * can be added to form action URL or as hidden inputs |
|
88 | - * |
|
89 | - * @var array $form_args |
|
90 | - */ |
|
91 | - private $form_args = array(); |
|
92 | - |
|
93 | - /** |
|
94 | - * value of one of the string constant above |
|
95 | - * |
|
96 | - * @var string $form_config |
|
97 | - */ |
|
98 | - private $form_config; |
|
99 | - |
|
100 | - /** |
|
101 | - * whether or not the form was determined to be invalid |
|
102 | - * |
|
103 | - * @var boolean $form_has_errors |
|
104 | - */ |
|
105 | - private $form_has_errors; |
|
106 | - |
|
107 | - /** |
|
108 | - * the absolute top level form section being used on the page |
|
109 | - * |
|
110 | - * @var EE_Form_Section_Proper $form |
|
111 | - */ |
|
112 | - private $form; |
|
113 | - |
|
114 | - /** |
|
115 | - * @var EE_Registry $registry |
|
116 | - */ |
|
117 | - protected $registry; |
|
118 | - |
|
119 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
120 | - /** |
|
121 | - * Form constructor. |
|
122 | - * |
|
123 | - * @param string $form_name |
|
124 | - * @param string $admin_name |
|
125 | - * @param string $slug |
|
126 | - * @param string $form_action |
|
127 | - * @param string $form_config |
|
128 | - * @param EE_Registry $registry |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - * @throws DomainException |
|
131 | - * @throws InvalidArgumentException |
|
132 | - */ |
|
133 | - public function __construct( |
|
134 | - $form_name, |
|
135 | - $admin_name, |
|
136 | - $slug, |
|
137 | - $form_action = '', |
|
138 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
139 | - EE_Registry $registry |
|
140 | - ) { |
|
141 | - $this->setFormName($form_name); |
|
142 | - $this->setAdminName($admin_name); |
|
143 | - $this->setSlug($slug); |
|
144 | - $this->setFormAction($form_action); |
|
145 | - $this->setFormConfig($form_config); |
|
146 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
147 | - $this->registry = $registry; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public static function getFormConfigConstants() |
|
155 | - { |
|
156 | - return array( |
|
157 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
158 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
159 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
160 | - FormHandler::DO_NOT_SETUP_FORM, |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param bool $for_display |
|
167 | - * @return EE_Form_Section_Proper |
|
168 | - * @throws EE_Error |
|
169 | - * @throws LogicException |
|
170 | - */ |
|
171 | - public function form($for_display = false) |
|
172 | - { |
|
173 | - if (! $this->formIsValid()) { |
|
174 | - return null; |
|
175 | - } |
|
176 | - if ($for_display) { |
|
177 | - $form_config = $this->formConfig(); |
|
178 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
179 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
180 | - ) { |
|
181 | - $this->appendSubmitButton(); |
|
182 | - $this->clearFormButtonFloats(); |
|
183 | - } |
|
184 | - } |
|
185 | - return $this->form; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @return boolean |
|
191 | - * @throws LogicException |
|
192 | - */ |
|
193 | - public function formIsValid() |
|
194 | - { |
|
195 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
196 | - return true; |
|
197 | - } |
|
198 | - $form = apply_filters( |
|
199 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
200 | - $this->generate(), |
|
201 | - $this |
|
202 | - ); |
|
203 | - if ($this->verifyForm($form)) { |
|
204 | - $this->setForm($form); |
|
205 | - } |
|
206 | - return true; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param EE_Form_Section_Proper|null $form |
|
212 | - * @return bool |
|
213 | - * @throws LogicException |
|
214 | - */ |
|
215 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
216 | - { |
|
217 | - $form = $form !== null ? $form : $this->form; |
|
218 | - if ($form instanceof EE_Form_Section_Proper) { |
|
219 | - return true; |
|
220 | - } |
|
221 | - throw new LogicException( |
|
222 | - sprintf( |
|
223 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
224 | - $this->form_name, |
|
225 | - var_export($form, true) |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @param EE_Form_Section_Proper $form |
|
233 | - */ |
|
234 | - public function setForm(EE_Form_Section_Proper $form) |
|
235 | - { |
|
236 | - $this->form = $form; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @return boolean |
|
242 | - */ |
|
243 | - public function displayable() |
|
244 | - { |
|
245 | - return $this->displayable; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param boolean $displayable |
|
251 | - */ |
|
252 | - public function setDisplayable($displayable = false) |
|
253 | - { |
|
254 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * a public name for the form that can be displayed on the frontend of a site |
|
260 | - * |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function formName() |
|
264 | - { |
|
265 | - return $this->form_name; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $form_name |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - */ |
|
273 | - public function setFormName($form_name) |
|
274 | - { |
|
275 | - if (! is_string($form_name)) { |
|
276 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
277 | - } |
|
278 | - $this->form_name = $form_name; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * a public name for the form that can be displayed, but only in the admin |
|
284 | - * |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function adminName() |
|
288 | - { |
|
289 | - return $this->admin_name; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $admin_name |
|
295 | - * @throws InvalidDataTypeException |
|
296 | - */ |
|
297 | - public function setAdminName($admin_name) |
|
298 | - { |
|
299 | - if (! is_string($admin_name)) { |
|
300 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
301 | - } |
|
302 | - $this->admin_name = $admin_name; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * a URL friendly string that can be used for identifying the form |
|
308 | - * |
|
309 | - * @return string |
|
310 | - */ |
|
311 | - public function slug() |
|
312 | - { |
|
313 | - return $this->slug; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string $slug |
|
319 | - * @throws InvalidDataTypeException |
|
320 | - */ |
|
321 | - public function setSlug($slug) |
|
322 | - { |
|
323 | - if (! is_string($slug)) { |
|
324 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
325 | - } |
|
326 | - $this->slug = $slug; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function submitBtnText() |
|
334 | - { |
|
335 | - return $this->submit_btn_text; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @param string $submit_btn_text |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidArgumentException |
|
343 | - */ |
|
344 | - public function setSubmitBtnText($submit_btn_text) |
|
345 | - { |
|
346 | - if (! is_string($submit_btn_text)) { |
|
347 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
348 | - } |
|
349 | - if (empty($submit_btn_text)) { |
|
350 | - throw new InvalidArgumentException( |
|
351 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
352 | - ); |
|
353 | - } |
|
354 | - $this->submit_btn_text = $submit_btn_text; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public function formAction() |
|
362 | - { |
|
363 | - return ! empty($this->form_args) |
|
364 | - ? add_query_arg($this->form_args, $this->form_action) |
|
365 | - : $this->form_action; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @param string $form_action |
|
371 | - * @throws InvalidDataTypeException |
|
372 | - */ |
|
373 | - public function setFormAction($form_action) |
|
374 | - { |
|
375 | - if (! is_string($form_action)) { |
|
376 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
377 | - } |
|
378 | - $this->form_action = $form_action; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @param array $form_args |
|
384 | - * @throws InvalidDataTypeException |
|
385 | - * @throws InvalidArgumentException |
|
386 | - */ |
|
387 | - public function addFormActionArgs($form_args = array()) |
|
388 | - { |
|
389 | - if (is_object($form_args)) { |
|
390 | - throw new InvalidDataTypeException( |
|
391 | - '$form_args', |
|
392 | - $form_args, |
|
393 | - 'anything other than an object was expected.' |
|
394 | - ); |
|
395 | - } |
|
396 | - if (empty($form_args)) { |
|
397 | - throw new InvalidArgumentException( |
|
398 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
399 | - ); |
|
400 | - } |
|
401 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public function formConfig() |
|
409 | - { |
|
410 | - return $this->form_config; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @param string $form_config |
|
416 | - * @throws DomainException |
|
417 | - */ |
|
418 | - public function setFormConfig($form_config) |
|
419 | - { |
|
420 | - if (! in_array( |
|
421 | - $form_config, |
|
422 | - array( |
|
423 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
424 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
425 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
426 | - FormHandler::DO_NOT_SETUP_FORM, |
|
427 | - ), |
|
428 | - true |
|
429 | - ) |
|
430 | - ) { |
|
431 | - throw new DomainException( |
|
432 | - sprintf( |
|
433 | - esc_html__( |
|
434 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
435 | - 'event_espresso' |
|
436 | - ), |
|
437 | - $form_config |
|
438 | - ) |
|
439 | - ); |
|
440 | - } |
|
441 | - $this->form_config = $form_config; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * called after the form is instantiated |
|
447 | - * and used for performing any logic that needs to occur early |
|
448 | - * before any of the other methods are called. |
|
449 | - * returns true if everything is ok to proceed, |
|
450 | - * and false if no further form logic should be implemented |
|
451 | - * |
|
452 | - * @return boolean |
|
453 | - */ |
|
454 | - public function initialize() |
|
455 | - { |
|
456 | - $this->form_has_errors = EE_Error::has_error(true); |
|
457 | - return true; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * used for setting up css and js |
|
463 | - * |
|
464 | - * @return void |
|
465 | - * @throws LogicException |
|
466 | - * @throws EE_Error |
|
467 | - */ |
|
468 | - public function enqueueStylesAndScripts() |
|
469 | - { |
|
470 | - $this->form()->enqueue_js(); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * creates and returns the actual form |
|
476 | - * |
|
477 | - * @return EE_Form_Section_Proper |
|
478 | - */ |
|
479 | - abstract public function generate(); |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
484 | - * |
|
485 | - * @param string $text |
|
486 | - * @return EE_Submit_Input |
|
487 | - */ |
|
488 | - public function generateSubmitButton($text = '') |
|
489 | - { |
|
490 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
491 | - return new EE_Submit_Input( |
|
492 | - array( |
|
493 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
494 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
495 | - 'html_class' => 'ee-form-submit', |
|
496 | - 'html_label' => ' ', |
|
497 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
498 | - 'default' => $text, |
|
499 | - ) |
|
500 | - ); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
506 | - * |
|
507 | - * @param string $text |
|
508 | - * @return void |
|
509 | - * @throws EE_Error |
|
510 | - */ |
|
511 | - public function appendSubmitButton($text = '') |
|
512 | - { |
|
513 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
514 | - return; |
|
515 | - } |
|
516 | - $this->form->add_subsections( |
|
517 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
518 | - null, |
|
519 | - false |
|
520 | - ); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
526 | - * |
|
527 | - * @param string $text |
|
528 | - * @return EE_Submit_Input |
|
529 | - */ |
|
530 | - public function generateCancelButton($text = '') |
|
531 | - { |
|
532 | - $cancel_button = new EE_Submit_Input( |
|
533 | - array( |
|
534 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
535 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
536 | - 'html_class' => 'ee-cancel-form', |
|
537 | - 'html_label' => ' ', |
|
538 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
539 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
540 | - ) |
|
541 | - ); |
|
542 | - $cancel_button->set_button_css_attributes(false); |
|
543 | - return $cancel_button; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * appends a float clearing div onto end of form |
|
549 | - * |
|
550 | - * @return void |
|
551 | - * @throws EE_Error |
|
552 | - */ |
|
553 | - public function clearFormButtonFloats() |
|
554 | - { |
|
555 | - $this->form->add_subsections( |
|
556 | - array( |
|
557 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
558 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
559 | - ), |
|
560 | - ), |
|
561 | - null, |
|
562 | - false |
|
563 | - ); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
569 | - * returns a string of HTML that can be directly echoed in a template |
|
570 | - * |
|
571 | - * @return string |
|
572 | - * @throws \InvalidArgumentException |
|
573 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
574 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
575 | - * @throws LogicException |
|
576 | - * @throws EE_Error |
|
577 | - */ |
|
578 | - public function display() |
|
579 | - { |
|
580 | - $form_html = apply_filters( |
|
581 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
582 | - '' |
|
583 | - ); |
|
584 | - $form_config = $this->formConfig(); |
|
585 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
586 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
587 | - ) { |
|
588 | - $form_html .= $this->form()->form_open($this->formAction()); |
|
589 | - } |
|
590 | - $form_html .= $this->form(true)->get_html(); |
|
591 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
592 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
593 | - ) { |
|
594 | - $form_html .= $this->form()->form_close(); |
|
595 | - } |
|
596 | - $form_html .= apply_filters( |
|
597 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
598 | - '' |
|
599 | - ); |
|
600 | - return $form_html; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * handles processing the form submission |
|
606 | - * returns true or false depending on whether the form was processed successfully or not |
|
607 | - * |
|
608 | - * @param array $submitted_form_data |
|
609 | - * @return array |
|
610 | - * @throws \InvalidArgumentException |
|
611 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
612 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
613 | - * @throws EE_Error |
|
614 | - * @throws LogicException |
|
615 | - * @throws InvalidFormSubmissionException |
|
616 | - */ |
|
617 | - public function process($submitted_form_data = array()) |
|
618 | - { |
|
619 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
620 | - throw new InvalidFormSubmissionException($this->form_name); |
|
621 | - } |
|
622 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
623 | - if (! $this->form()->is_valid()) { |
|
624 | - throw new InvalidFormSubmissionException( |
|
625 | - $this->form_name, |
|
626 | - sprintf( |
|
627 | - esc_html__( |
|
628 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
629 | - 'event_espresso' |
|
630 | - ), |
|
631 | - $this->form_name, |
|
632 | - '<br />', |
|
633 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
634 | - ) |
|
635 | - ); |
|
636 | - } |
|
637 | - return apply_filters( |
|
638 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
639 | - $this->form()->valid_data(), |
|
640 | - $this |
|
641 | - ); |
|
642 | - } |
|
31 | + /** |
|
32 | + * will add opening and closing HTML form tags as well as a submit button |
|
33 | + */ |
|
34 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
35 | + |
|
36 | + /** |
|
37 | + * will add opening and closing HTML form tags but NOT a submit button |
|
38 | + */ |
|
39 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
40 | + |
|
41 | + /** |
|
42 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
43 | + */ |
|
44 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
45 | + |
|
46 | + /** |
|
47 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
48 | + */ |
|
49 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
50 | + |
|
51 | + /** |
|
52 | + * if set to false, then this form has no displayable content, |
|
53 | + * and will only be used for processing data sent passed via GET or POST |
|
54 | + * defaults to true ( ie: form has displayable content ) |
|
55 | + * |
|
56 | + * @var boolean $displayable |
|
57 | + */ |
|
58 | + private $displayable = true; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var string $form_name |
|
62 | + */ |
|
63 | + private $form_name; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var string $admin_name |
|
67 | + */ |
|
68 | + private $admin_name; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var string $slug |
|
72 | + */ |
|
73 | + private $slug; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var string $submit_btn_text |
|
77 | + */ |
|
78 | + private $submit_btn_text; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string $form_action |
|
82 | + */ |
|
83 | + private $form_action; |
|
84 | + |
|
85 | + /** |
|
86 | + * form params in key value pairs |
|
87 | + * can be added to form action URL or as hidden inputs |
|
88 | + * |
|
89 | + * @var array $form_args |
|
90 | + */ |
|
91 | + private $form_args = array(); |
|
92 | + |
|
93 | + /** |
|
94 | + * value of one of the string constant above |
|
95 | + * |
|
96 | + * @var string $form_config |
|
97 | + */ |
|
98 | + private $form_config; |
|
99 | + |
|
100 | + /** |
|
101 | + * whether or not the form was determined to be invalid |
|
102 | + * |
|
103 | + * @var boolean $form_has_errors |
|
104 | + */ |
|
105 | + private $form_has_errors; |
|
106 | + |
|
107 | + /** |
|
108 | + * the absolute top level form section being used on the page |
|
109 | + * |
|
110 | + * @var EE_Form_Section_Proper $form |
|
111 | + */ |
|
112 | + private $form; |
|
113 | + |
|
114 | + /** |
|
115 | + * @var EE_Registry $registry |
|
116 | + */ |
|
117 | + protected $registry; |
|
118 | + |
|
119 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
120 | + /** |
|
121 | + * Form constructor. |
|
122 | + * |
|
123 | + * @param string $form_name |
|
124 | + * @param string $admin_name |
|
125 | + * @param string $slug |
|
126 | + * @param string $form_action |
|
127 | + * @param string $form_config |
|
128 | + * @param EE_Registry $registry |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + * @throws DomainException |
|
131 | + * @throws InvalidArgumentException |
|
132 | + */ |
|
133 | + public function __construct( |
|
134 | + $form_name, |
|
135 | + $admin_name, |
|
136 | + $slug, |
|
137 | + $form_action = '', |
|
138 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
139 | + EE_Registry $registry |
|
140 | + ) { |
|
141 | + $this->setFormName($form_name); |
|
142 | + $this->setAdminName($admin_name); |
|
143 | + $this->setSlug($slug); |
|
144 | + $this->setFormAction($form_action); |
|
145 | + $this->setFormConfig($form_config); |
|
146 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
147 | + $this->registry = $registry; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public static function getFormConfigConstants() |
|
155 | + { |
|
156 | + return array( |
|
157 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
158 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
159 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
160 | + FormHandler::DO_NOT_SETUP_FORM, |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param bool $for_display |
|
167 | + * @return EE_Form_Section_Proper |
|
168 | + * @throws EE_Error |
|
169 | + * @throws LogicException |
|
170 | + */ |
|
171 | + public function form($for_display = false) |
|
172 | + { |
|
173 | + if (! $this->formIsValid()) { |
|
174 | + return null; |
|
175 | + } |
|
176 | + if ($for_display) { |
|
177 | + $form_config = $this->formConfig(); |
|
178 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
179 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
180 | + ) { |
|
181 | + $this->appendSubmitButton(); |
|
182 | + $this->clearFormButtonFloats(); |
|
183 | + } |
|
184 | + } |
|
185 | + return $this->form; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @return boolean |
|
191 | + * @throws LogicException |
|
192 | + */ |
|
193 | + public function formIsValid() |
|
194 | + { |
|
195 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
196 | + return true; |
|
197 | + } |
|
198 | + $form = apply_filters( |
|
199 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
200 | + $this->generate(), |
|
201 | + $this |
|
202 | + ); |
|
203 | + if ($this->verifyForm($form)) { |
|
204 | + $this->setForm($form); |
|
205 | + } |
|
206 | + return true; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param EE_Form_Section_Proper|null $form |
|
212 | + * @return bool |
|
213 | + * @throws LogicException |
|
214 | + */ |
|
215 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
216 | + { |
|
217 | + $form = $form !== null ? $form : $this->form; |
|
218 | + if ($form instanceof EE_Form_Section_Proper) { |
|
219 | + return true; |
|
220 | + } |
|
221 | + throw new LogicException( |
|
222 | + sprintf( |
|
223 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
224 | + $this->form_name, |
|
225 | + var_export($form, true) |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @param EE_Form_Section_Proper $form |
|
233 | + */ |
|
234 | + public function setForm(EE_Form_Section_Proper $form) |
|
235 | + { |
|
236 | + $this->form = $form; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @return boolean |
|
242 | + */ |
|
243 | + public function displayable() |
|
244 | + { |
|
245 | + return $this->displayable; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param boolean $displayable |
|
251 | + */ |
|
252 | + public function setDisplayable($displayable = false) |
|
253 | + { |
|
254 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * a public name for the form that can be displayed on the frontend of a site |
|
260 | + * |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function formName() |
|
264 | + { |
|
265 | + return $this->form_name; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $form_name |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + */ |
|
273 | + public function setFormName($form_name) |
|
274 | + { |
|
275 | + if (! is_string($form_name)) { |
|
276 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
277 | + } |
|
278 | + $this->form_name = $form_name; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * a public name for the form that can be displayed, but only in the admin |
|
284 | + * |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function adminName() |
|
288 | + { |
|
289 | + return $this->admin_name; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $admin_name |
|
295 | + * @throws InvalidDataTypeException |
|
296 | + */ |
|
297 | + public function setAdminName($admin_name) |
|
298 | + { |
|
299 | + if (! is_string($admin_name)) { |
|
300 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
301 | + } |
|
302 | + $this->admin_name = $admin_name; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * a URL friendly string that can be used for identifying the form |
|
308 | + * |
|
309 | + * @return string |
|
310 | + */ |
|
311 | + public function slug() |
|
312 | + { |
|
313 | + return $this->slug; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string $slug |
|
319 | + * @throws InvalidDataTypeException |
|
320 | + */ |
|
321 | + public function setSlug($slug) |
|
322 | + { |
|
323 | + if (! is_string($slug)) { |
|
324 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
325 | + } |
|
326 | + $this->slug = $slug; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function submitBtnText() |
|
334 | + { |
|
335 | + return $this->submit_btn_text; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @param string $submit_btn_text |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidArgumentException |
|
343 | + */ |
|
344 | + public function setSubmitBtnText($submit_btn_text) |
|
345 | + { |
|
346 | + if (! is_string($submit_btn_text)) { |
|
347 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
348 | + } |
|
349 | + if (empty($submit_btn_text)) { |
|
350 | + throw new InvalidArgumentException( |
|
351 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
352 | + ); |
|
353 | + } |
|
354 | + $this->submit_btn_text = $submit_btn_text; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public function formAction() |
|
362 | + { |
|
363 | + return ! empty($this->form_args) |
|
364 | + ? add_query_arg($this->form_args, $this->form_action) |
|
365 | + : $this->form_action; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @param string $form_action |
|
371 | + * @throws InvalidDataTypeException |
|
372 | + */ |
|
373 | + public function setFormAction($form_action) |
|
374 | + { |
|
375 | + if (! is_string($form_action)) { |
|
376 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
377 | + } |
|
378 | + $this->form_action = $form_action; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @param array $form_args |
|
384 | + * @throws InvalidDataTypeException |
|
385 | + * @throws InvalidArgumentException |
|
386 | + */ |
|
387 | + public function addFormActionArgs($form_args = array()) |
|
388 | + { |
|
389 | + if (is_object($form_args)) { |
|
390 | + throw new InvalidDataTypeException( |
|
391 | + '$form_args', |
|
392 | + $form_args, |
|
393 | + 'anything other than an object was expected.' |
|
394 | + ); |
|
395 | + } |
|
396 | + if (empty($form_args)) { |
|
397 | + throw new InvalidArgumentException( |
|
398 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
399 | + ); |
|
400 | + } |
|
401 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public function formConfig() |
|
409 | + { |
|
410 | + return $this->form_config; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @param string $form_config |
|
416 | + * @throws DomainException |
|
417 | + */ |
|
418 | + public function setFormConfig($form_config) |
|
419 | + { |
|
420 | + if (! in_array( |
|
421 | + $form_config, |
|
422 | + array( |
|
423 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
424 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
425 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
426 | + FormHandler::DO_NOT_SETUP_FORM, |
|
427 | + ), |
|
428 | + true |
|
429 | + ) |
|
430 | + ) { |
|
431 | + throw new DomainException( |
|
432 | + sprintf( |
|
433 | + esc_html__( |
|
434 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
435 | + 'event_espresso' |
|
436 | + ), |
|
437 | + $form_config |
|
438 | + ) |
|
439 | + ); |
|
440 | + } |
|
441 | + $this->form_config = $form_config; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * called after the form is instantiated |
|
447 | + * and used for performing any logic that needs to occur early |
|
448 | + * before any of the other methods are called. |
|
449 | + * returns true if everything is ok to proceed, |
|
450 | + * and false if no further form logic should be implemented |
|
451 | + * |
|
452 | + * @return boolean |
|
453 | + */ |
|
454 | + public function initialize() |
|
455 | + { |
|
456 | + $this->form_has_errors = EE_Error::has_error(true); |
|
457 | + return true; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * used for setting up css and js |
|
463 | + * |
|
464 | + * @return void |
|
465 | + * @throws LogicException |
|
466 | + * @throws EE_Error |
|
467 | + */ |
|
468 | + public function enqueueStylesAndScripts() |
|
469 | + { |
|
470 | + $this->form()->enqueue_js(); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * creates and returns the actual form |
|
476 | + * |
|
477 | + * @return EE_Form_Section_Proper |
|
478 | + */ |
|
479 | + abstract public function generate(); |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
484 | + * |
|
485 | + * @param string $text |
|
486 | + * @return EE_Submit_Input |
|
487 | + */ |
|
488 | + public function generateSubmitButton($text = '') |
|
489 | + { |
|
490 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
491 | + return new EE_Submit_Input( |
|
492 | + array( |
|
493 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
494 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
495 | + 'html_class' => 'ee-form-submit', |
|
496 | + 'html_label' => ' ', |
|
497 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
498 | + 'default' => $text, |
|
499 | + ) |
|
500 | + ); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
506 | + * |
|
507 | + * @param string $text |
|
508 | + * @return void |
|
509 | + * @throws EE_Error |
|
510 | + */ |
|
511 | + public function appendSubmitButton($text = '') |
|
512 | + { |
|
513 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
514 | + return; |
|
515 | + } |
|
516 | + $this->form->add_subsections( |
|
517 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
518 | + null, |
|
519 | + false |
|
520 | + ); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
526 | + * |
|
527 | + * @param string $text |
|
528 | + * @return EE_Submit_Input |
|
529 | + */ |
|
530 | + public function generateCancelButton($text = '') |
|
531 | + { |
|
532 | + $cancel_button = new EE_Submit_Input( |
|
533 | + array( |
|
534 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
535 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
536 | + 'html_class' => 'ee-cancel-form', |
|
537 | + 'html_label' => ' ', |
|
538 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
539 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
540 | + ) |
|
541 | + ); |
|
542 | + $cancel_button->set_button_css_attributes(false); |
|
543 | + return $cancel_button; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * appends a float clearing div onto end of form |
|
549 | + * |
|
550 | + * @return void |
|
551 | + * @throws EE_Error |
|
552 | + */ |
|
553 | + public function clearFormButtonFloats() |
|
554 | + { |
|
555 | + $this->form->add_subsections( |
|
556 | + array( |
|
557 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
558 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
559 | + ), |
|
560 | + ), |
|
561 | + null, |
|
562 | + false |
|
563 | + ); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
569 | + * returns a string of HTML that can be directly echoed in a template |
|
570 | + * |
|
571 | + * @return string |
|
572 | + * @throws \InvalidArgumentException |
|
573 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
574 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
575 | + * @throws LogicException |
|
576 | + * @throws EE_Error |
|
577 | + */ |
|
578 | + public function display() |
|
579 | + { |
|
580 | + $form_html = apply_filters( |
|
581 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
582 | + '' |
|
583 | + ); |
|
584 | + $form_config = $this->formConfig(); |
|
585 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
586 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
587 | + ) { |
|
588 | + $form_html .= $this->form()->form_open($this->formAction()); |
|
589 | + } |
|
590 | + $form_html .= $this->form(true)->get_html(); |
|
591 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
592 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
593 | + ) { |
|
594 | + $form_html .= $this->form()->form_close(); |
|
595 | + } |
|
596 | + $form_html .= apply_filters( |
|
597 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
598 | + '' |
|
599 | + ); |
|
600 | + return $form_html; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * handles processing the form submission |
|
606 | + * returns true or false depending on whether the form was processed successfully or not |
|
607 | + * |
|
608 | + * @param array $submitted_form_data |
|
609 | + * @return array |
|
610 | + * @throws \InvalidArgumentException |
|
611 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
612 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
613 | + * @throws EE_Error |
|
614 | + * @throws LogicException |
|
615 | + * @throws InvalidFormSubmissionException |
|
616 | + */ |
|
617 | + public function process($submitted_form_data = array()) |
|
618 | + { |
|
619 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
620 | + throw new InvalidFormSubmissionException($this->form_name); |
|
621 | + } |
|
622 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
623 | + if (! $this->form()->is_valid()) { |
|
624 | + throw new InvalidFormSubmissionException( |
|
625 | + $this->form_name, |
|
626 | + sprintf( |
|
627 | + esc_html__( |
|
628 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
629 | + 'event_espresso' |
|
630 | + ), |
|
631 | + $this->form_name, |
|
632 | + '<br />', |
|
633 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
634 | + ) |
|
635 | + ); |
|
636 | + } |
|
637 | + return apply_filters( |
|
638 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
639 | + $this->form()->valid_data(), |
|
640 | + $this |
|
641 | + ); |
|
642 | + } |
|
643 | 643 | } |
@@ -14,1528 +14,1528 @@ |
||
14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
15 | 15 | { |
16 | 16 | |
17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | - |
|
19 | - /** |
|
20 | - * Subsections |
|
21 | - * |
|
22 | - * @var EE_Form_Section_Validatable[] |
|
23 | - */ |
|
24 | - protected $_subsections = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Strategy for laying out the form |
|
28 | - * |
|
29 | - * @var EE_Form_Section_Layout_Base |
|
30 | - */ |
|
31 | - protected $_layout_strategy; |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether or not this form has received and validated a form submission yet |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_received_submission = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * message displayed to users upon successful form submission |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_form_submission_success_message = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * message displayed to users upon unsuccessful form submission |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_form_submission_error_message = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array like $_REQUEST |
|
56 | - */ |
|
57 | - protected $cached_request_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | - * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | - * @var boolean|null |
|
63 | - */ |
|
64 | - protected $is_valid; |
|
65 | - |
|
66 | - /** |
|
67 | - * Stores all the data that will localized for form validation |
|
68 | - * |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - static protected $_js_localization = array(); |
|
72 | - |
|
73 | - /** |
|
74 | - * whether or not the form's localized validation JS vars have been set |
|
75 | - * |
|
76 | - * @type boolean |
|
77 | - */ |
|
78 | - static protected $_scripts_localized = false; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * when constructing a proper form section, calls _construct_finalize on children |
|
83 | - * so that they know who their parent is, and what name they've been given. |
|
84 | - * |
|
85 | - * @param array[] $options_array { |
|
86 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | - * and in that order. This is handy if you want |
|
89 | - * the subsections to be ordered differently than the default, and if you override |
|
90 | - * which fields are shown |
|
91 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | - * items from that list of inclusions) |
|
95 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | - * } @see EE_Form_Section_Validatable::__construct() |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public function __construct($options_array = array()) |
|
100 | - { |
|
101 | - $options_array = (array) apply_filters( |
|
102 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | - $options_array, |
|
104 | - $this |
|
105 | - ); |
|
106 | - // call parent first, as it may be setting the name |
|
107 | - parent::__construct($options_array); |
|
108 | - // if they've included subsections in the constructor, add them now |
|
109 | - if (isset($options_array['include'])) { |
|
110 | - // we are going to make sure we ONLY have those subsections to include |
|
111 | - // AND we are going to make sure they're in that specified order |
|
112 | - $reordered_subsections = array(); |
|
113 | - foreach ($options_array['include'] as $input_name) { |
|
114 | - if (isset($this->_subsections[ $input_name ])) { |
|
115 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | - } |
|
117 | - } |
|
118 | - $this->_subsections = $reordered_subsections; |
|
119 | - } |
|
120 | - if (isset($options_array['exclude'])) { |
|
121 | - $exclude = $options_array['exclude']; |
|
122 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | - } |
|
124 | - if (isset($options_array['layout_strategy'])) { |
|
125 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | - } |
|
127 | - if (! $this->_layout_strategy) { |
|
128 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | - } |
|
130 | - $this->_layout_strategy->_construct_finalize($this); |
|
131 | - // ok so we are definitely going to want the forms JS, |
|
132 | - // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | - // ok so they've constructed this object after when they should have. |
|
135 | - // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | - } else { |
|
138 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | - } |
|
141 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | - /** |
|
143 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | - * The form probably doesn't yet have a parent form section. |
|
145 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | - * |
|
149 | - * @since 4.9.32 |
|
150 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | - * except maybe calling _construct_finalize has been done |
|
152 | - * @param array $options_array options passed into the constructor |
|
153 | - */ |
|
154 | - do_action( |
|
155 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | - $this, |
|
157 | - $options_array |
|
158 | - ); |
|
159 | - if (isset($options_array['name'])) { |
|
160 | - $this->_construct_finalize(null, $options_array['name']); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Finishes construction given the parent form section and this form section's name |
|
167 | - * |
|
168 | - * @param EE_Form_Section_Proper $parent_form_section |
|
169 | - * @param string $name |
|
170 | - * @throws EE_Error |
|
171 | - */ |
|
172 | - public function _construct_finalize($parent_form_section, $name) |
|
173 | - { |
|
174 | - parent::_construct_finalize($parent_form_section, $name); |
|
175 | - $this->_set_default_name_if_empty(); |
|
176 | - $this->_set_default_html_id_if_empty(); |
|
177 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | - $subsection->_construct_finalize($this, $subsection_name); |
|
180 | - } else { |
|
181 | - throw new EE_Error( |
|
182 | - sprintf( |
|
183 | - esc_html__( |
|
184 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - $subsection_name, |
|
188 | - get_class($this), |
|
189 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | - ) |
|
191 | - ); |
|
192 | - } |
|
193 | - } |
|
194 | - /** |
|
195 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | - * ensured it has a name, HTML IDs, etc |
|
201 | - * |
|
202 | - * @param EE_Form_Section_Proper $this |
|
203 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | - * @param string $name |
|
205 | - */ |
|
206 | - do_action( |
|
207 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | - $this, |
|
209 | - $parent_form_section, |
|
210 | - $name |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Gets the layout strategy for this form section |
|
217 | - * |
|
218 | - * @return EE_Form_Section_Layout_Base |
|
219 | - */ |
|
220 | - public function get_layout_strategy() |
|
221 | - { |
|
222 | - return $this->_layout_strategy; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Gets the HTML for a single input for this form section according |
|
228 | - * to the layout strategy |
|
229 | - * |
|
230 | - * @param EE_Form_Input_Base $input |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function get_html_for_input($input) |
|
234 | - { |
|
235 | - return $this->_layout_strategy->layout_input($input); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * was_submitted - checks if form inputs are present in request data |
|
241 | - * Basically an alias for form_data_present_in() (which is used by both |
|
242 | - * proper form sections and form inputs) |
|
243 | - * |
|
244 | - * @param null $form_data |
|
245 | - * @return boolean |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function was_submitted($form_data = null) |
|
249 | - { |
|
250 | - return $this->form_data_present_in($form_data); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | - * something different, refresh the cache, and then return it |
|
256 | - * @param null $req_data |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - protected function getCachedRequest($req_data = null) |
|
260 | - { |
|
261 | - if ($this->cached_request_data === null |
|
262 | - || ( |
|
263 | - $req_data !== null && |
|
264 | - $req_data !== $this->cached_request_data |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $req_data = apply_filters( |
|
268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | - $req_data, |
|
270 | - $this |
|
271 | - ); |
|
272 | - if ($req_data === null) { |
|
273 | - $req_data = array_merge($_GET, $_POST); |
|
274 | - } |
|
275 | - $req_data = apply_filters( |
|
276 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | - $req_data, |
|
278 | - $this |
|
279 | - ); |
|
280 | - $this->cached_request_data = (array) $req_data; |
|
281 | - } |
|
282 | - return $this->cached_request_data; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | - * |
|
290 | - * @param array|null $req_data should usually be $_POST (the default). |
|
291 | - * However, you CAN supply a different array. |
|
292 | - * Consider using set_defaults() instead however. |
|
293 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | - * the inputs will have the correct name in the request data for this function |
|
295 | - * to find them and populate the form with them. |
|
296 | - * If you have a flat form (with only input subsections), |
|
297 | - * you can supply a flat array where keys |
|
298 | - * are the form input names and values are their values) |
|
299 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | - * of course, to validate that data, and set errors on the invalid values. |
|
301 | - * But if the data has already been validated |
|
302 | - * (eg you validated the data then stored it in the DB) |
|
303 | - * you may want to skip this step. |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws InvalidInterfaceException |
|
306 | - * @throws InvalidDataTypeException |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function receive_form_submission($req_data = null, $validate = true) |
|
310 | - { |
|
311 | - $req_data = $this->getCachedRequest($req_data); |
|
312 | - $this->_normalize($req_data); |
|
313 | - if ($validate) { |
|
314 | - $this->_validate(); |
|
315 | - // if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | - if (! $this->is_valid()) { |
|
317 | - $this->store_submitted_form_data_in_session(); |
|
318 | - } |
|
319 | - } |
|
320 | - if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | - $this->set_submission_error_message(); |
|
322 | - } |
|
323 | - do_action( |
|
324 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | - $req_data, |
|
326 | - $this, |
|
327 | - $validate |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * caches the originally submitted input values in the session |
|
334 | - * so that they can be used to repopulate the form if it failed validation |
|
335 | - * |
|
336 | - * @return boolean whether or not the data was successfully stored in the session |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws InvalidInterfaceException |
|
339 | - * @throws InvalidDataTypeException |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - protected function store_submitted_form_data_in_session() |
|
343 | - { |
|
344 | - return EE_Registry::instance()->SSN->set_session_data( |
|
345 | - array( |
|
346 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | - ) |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * retrieves the originally submitted input values in the session |
|
354 | - * so that they can be used to repopulate the form if it failed validation |
|
355 | - * |
|
356 | - * @return array |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidInterfaceException |
|
359 | - * @throws InvalidDataTypeException |
|
360 | - */ |
|
361 | - protected function get_submitted_form_data_from_session() |
|
362 | - { |
|
363 | - $session = EE_Registry::instance()->SSN; |
|
364 | - if ($session instanceof EE_Session) { |
|
365 | - return $session->get_session_data( |
|
366 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | - ); |
|
368 | - } |
|
369 | - return array(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * flushed the originally submitted input values from the session |
|
375 | - * |
|
376 | - * @return boolean whether or not the data was successfully removed from the session |
|
377 | - * @throws InvalidArgumentException |
|
378 | - * @throws InvalidInterfaceException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - */ |
|
381 | - public static function flush_submitted_form_data_from_session() |
|
382 | - { |
|
383 | - return EE_Registry::instance()->SSN->reset_data( |
|
384 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Populates this form and its subsections with data from the session. |
|
391 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | - * validation errors when displaying too) |
|
393 | - * Returns true if the form was populated from the session, false otherwise |
|
394 | - * |
|
395 | - * @return boolean |
|
396 | - * @throws InvalidArgumentException |
|
397 | - * @throws InvalidInterfaceException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws EE_Error |
|
400 | - */ |
|
401 | - public function populate_from_session() |
|
402 | - { |
|
403 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | - if (empty($form_data_in_session)) { |
|
405 | - return false; |
|
406 | - } |
|
407 | - $this->receive_form_submission($form_data_in_session); |
|
408 | - add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
409 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | - return true; |
|
411 | - } |
|
412 | - return false; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Populates the default data for the form, given an array where keys are |
|
418 | - * the input names, and values are their values (preferably normalized to be their |
|
419 | - * proper PHP types, not all strings... although that should be ok too). |
|
420 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | - * the value being an array formatted in teh same way |
|
422 | - * |
|
423 | - * @param array $default_data |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function populate_defaults($default_data) |
|
427 | - { |
|
428 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | - if (isset($default_data[ $subsection_name ])) { |
|
430 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | - } |
|
435 | - } |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * returns true if subsection exists |
|
442 | - * |
|
443 | - * @param string $name |
|
444 | - * @return boolean |
|
445 | - */ |
|
446 | - public function subsection_exists($name) |
|
447 | - { |
|
448 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Gets the subsection specified by its name |
|
454 | - * |
|
455 | - * @param string $name |
|
456 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | - * so that the inputs will be properly configured. |
|
458 | - * However, some client code may be ok |
|
459 | - * with construction finalize being called later |
|
460 | - * (realizing that the subsections' html names |
|
461 | - * might not be set yet, etc.) |
|
462 | - * @return EE_Form_Section_Base |
|
463 | - * @throws EE_Error |
|
464 | - */ |
|
465 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | - { |
|
467 | - if ($require_construction_to_be_finalized) { |
|
468 | - $this->ensure_construct_finalized_called(); |
|
469 | - } |
|
470 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Gets all the validatable subsections of this form section |
|
476 | - * |
|
477 | - * @return EE_Form_Section_Validatable[] |
|
478 | - * @throws EE_Error |
|
479 | - */ |
|
480 | - public function get_validatable_subsections() |
|
481 | - { |
|
482 | - $validatable_subsections = array(); |
|
483 | - foreach ($this->subsections() as $name => $obj) { |
|
484 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | - $validatable_subsections[ $name ] = $obj; |
|
486 | - } |
|
487 | - } |
|
488 | - return $validatable_subsections; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | - * throw an EE_Error. |
|
495 | - * |
|
496 | - * @param string $name |
|
497 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | - * leave this as TRUE so that the inputs will be properly |
|
499 | - * configured. However, some client code may be ok with |
|
500 | - * construction finalize being called later |
|
501 | - * (realizing that the subsections' html names might not be |
|
502 | - * set yet, etc.) |
|
503 | - * @return EE_Form_Input_Base |
|
504 | - * @throws EE_Error |
|
505 | - */ |
|
506 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | - { |
|
508 | - $subsection = $this->get_subsection( |
|
509 | - $name, |
|
510 | - $require_construction_to_be_finalized |
|
511 | - ); |
|
512 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | - throw new EE_Error( |
|
514 | - sprintf( |
|
515 | - esc_html__( |
|
516 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | - 'event_espresso' |
|
518 | - ), |
|
519 | - $name, |
|
520 | - get_class($this), |
|
521 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | - ) |
|
523 | - ); |
|
524 | - } |
|
525 | - return $subsection; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | - * otherwise throws an EE_Error |
|
532 | - * |
|
533 | - * @param string $name |
|
534 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | - * leave this as TRUE so that the inputs will be properly |
|
536 | - * configured. However, some client code may be ok with |
|
537 | - * construction finalize being called later |
|
538 | - * (realizing that the subsections' html names might not be |
|
539 | - * set yet, etc.) |
|
540 | - * @return EE_Form_Section_Proper |
|
541 | - * @throws EE_Error |
|
542 | - */ |
|
543 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | - { |
|
545 | - $subsection = $this->get_subsection( |
|
546 | - $name, |
|
547 | - $require_construction_to_be_finalized |
|
548 | - ); |
|
549 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | - throw new EE_Error( |
|
551 | - sprintf( |
|
552 | - esc_html__( |
|
553 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - $name, |
|
557 | - get_class($this) |
|
558 | - ) |
|
559 | - ); |
|
560 | - } |
|
561 | - return $subsection; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | - * |
|
569 | - * @param string $name |
|
570 | - * @return mixed depending on the input's type and its normalization strategy |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - public function get_input_value($name) |
|
574 | - { |
|
575 | - $input = $this->get_input($name); |
|
576 | - return $input->normalized_value(); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Checks if this form section itself is valid, and then checks its subsections |
|
582 | - * |
|
583 | - * @throws EE_Error |
|
584 | - * @return boolean |
|
585 | - */ |
|
586 | - public function is_valid() |
|
587 | - { |
|
588 | - if ($this->is_valid === null) { |
|
589 | - if (! $this->has_received_submission()) { |
|
590 | - throw new EE_Error( |
|
591 | - sprintf( |
|
592 | - esc_html__( |
|
593 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | - 'event_espresso' |
|
595 | - ) |
|
596 | - ) |
|
597 | - ); |
|
598 | - } |
|
599 | - if (! parent::is_valid()) { |
|
600 | - $this->is_valid = false; |
|
601 | - } else { |
|
602 | - // ok so no general errors to this entire form section. |
|
603 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | - $this->is_valid = true; |
|
605 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | - if (! $subsection->is_valid()) { |
|
607 | - $this->is_valid = false; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - return $this->is_valid; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * gets the default name of this form section if none is specified |
|
618 | - * |
|
619 | - * @return void |
|
620 | - */ |
|
621 | - protected function _set_default_name_if_empty() |
|
622 | - { |
|
623 | - if (! $this->_name) { |
|
624 | - $classname = get_class($this); |
|
625 | - $default_name = str_replace('EE_', '', $classname); |
|
626 | - $this->_name = $default_name; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | - * any CSS. |
|
639 | - * |
|
640 | - * @throws InvalidArgumentException |
|
641 | - * @throws InvalidInterfaceException |
|
642 | - * @throws InvalidDataTypeException |
|
643 | - * @throws EE_Error |
|
644 | - */ |
|
645 | - public function get_html_and_js() |
|
646 | - { |
|
647 | - $this->enqueue_js(); |
|
648 | - return $this->get_html(); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | - * |
|
655 | - * @param bool $display_previously_submitted_data |
|
656 | - * @return string |
|
657 | - * @throws InvalidArgumentException |
|
658 | - * @throws InvalidInterfaceException |
|
659 | - * @throws InvalidDataTypeException |
|
660 | - * @throws EE_Error |
|
661 | - * @throws EE_Error |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function get_html($display_previously_submitted_data = true) |
|
665 | - { |
|
666 | - $this->ensure_construct_finalized_called(); |
|
667 | - if ($display_previously_submitted_data) { |
|
668 | - $this->populate_from_session(); |
|
669 | - } |
|
670 | - return $this->_form_html_filter |
|
671 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | - : $this->_layout_strategy->layout_form(); |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * enqueues JS and CSS for the form. |
|
678 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | - * scripts and styles can be put in the header, but if called later |
|
680 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | - * only be in the header; but in HTML5 its ok in the body. |
|
682 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | - * |
|
685 | - * @return void |
|
686 | - * @throws EE_Error |
|
687 | - */ |
|
688 | - public function enqueue_js() |
|
689 | - { |
|
690 | - $this->_enqueue_and_localize_form_js(); |
|
691 | - foreach ($this->subsections() as $subsection) { |
|
692 | - $subsection->enqueue_js(); |
|
693 | - } |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | - * the wp_enqueue_scripts hook. |
|
701 | - * However, registering the form js and localizing it can happen when we |
|
702 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | - * could change until it's actually outputted) |
|
704 | - * |
|
705 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | - * to be triggered automatically or not |
|
707 | - * @return void |
|
708 | - */ |
|
709 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | - { |
|
711 | - wp_register_script( |
|
712 | - 'ee_form_section_validation', |
|
713 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | - EVENT_ESPRESSO_VERSION, |
|
716 | - true |
|
717 | - ); |
|
718 | - wp_localize_script( |
|
719 | - 'ee_form_section_validation', |
|
720 | - 'ee_form_section_validation_init', |
|
721 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | - ); |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * gets the variables used by form_section_validation.js. |
|
728 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | - * but before the wordpress hook wp_loaded |
|
730 | - * |
|
731 | - * @throws EE_Error |
|
732 | - */ |
|
733 | - public function _enqueue_and_localize_form_js() |
|
734 | - { |
|
735 | - $this->ensure_construct_finalized_called(); |
|
736 | - // actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | - // so we need to add our form section data to a static variable accessible by all form sections |
|
738 | - // and localize it just before the footer |
|
739 | - $this->localize_validation_rules(); |
|
740 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * add our form section data to a static variable accessible by all form sections |
|
747 | - * |
|
748 | - * @param bool $return_for_subsection |
|
749 | - * @return void |
|
750 | - * @throws EE_Error |
|
751 | - */ |
|
752 | - public function localize_validation_rules($return_for_subsection = false) |
|
753 | - { |
|
754 | - // we only want to localize vars ONCE for the entire form, |
|
755 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | - 'form_section_id' => $this->html_id(true), |
|
759 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | - 'other_data' => $this->get_other_js_data(), |
|
761 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | - ); |
|
763 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | - * This is primarily data added by inputs and forms in addition to any |
|
771 | - * scripts they might enqueue |
|
772 | - * |
|
773 | - * @param array $form_other_js_data |
|
774 | - * @return array |
|
775 | - * @throws EE_Error |
|
776 | - */ |
|
777 | - public function get_other_js_data($form_other_js_data = array()) |
|
778 | - { |
|
779 | - foreach ($this->subsections() as $subsection) { |
|
780 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | - } |
|
782 | - return $form_other_js_data; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Gets a flat array of inputs for this form section and its subsections. |
|
788 | - * Keys are their form names, and values are the inputs themselves |
|
789 | - * |
|
790 | - * @return EE_Form_Input_Base |
|
791 | - * @throws EE_Error |
|
792 | - */ |
|
793 | - public function inputs_in_subsections() |
|
794 | - { |
|
795 | - $inputs = array(); |
|
796 | - foreach ($this->subsections() as $subsection) { |
|
797 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | - $inputs += $subsection->inputs_in_subsections(); |
|
801 | - } |
|
802 | - } |
|
803 | - return $inputs; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * Gets a flat array of all the validation errors. |
|
809 | - * Keys are html names (because those should be unique) |
|
810 | - * and values are a string of all their validation errors |
|
811 | - * |
|
812 | - * @return string[] |
|
813 | - * @throws EE_Error |
|
814 | - */ |
|
815 | - public function subsection_validation_errors_by_html_name() |
|
816 | - { |
|
817 | - $inputs = $this->inputs(); |
|
818 | - $errors = array(); |
|
819 | - foreach ($inputs as $form_input) { |
|
820 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | - } |
|
823 | - } |
|
824 | - return $errors; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | - * |
|
832 | - * @throws InvalidArgumentException |
|
833 | - * @throws InvalidInterfaceException |
|
834 | - * @throws InvalidDataTypeException |
|
835 | - */ |
|
836 | - public static function localize_script_for_all_forms() |
|
837 | - { |
|
838 | - // allow inputs and stuff to hook in their JS and stuff here |
|
839 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | - : 'wp_default'; |
|
844 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | - wp_enqueue_script('ee_form_section_validation'); |
|
846 | - wp_localize_script( |
|
847 | - 'ee_form_section_validation', |
|
848 | - 'ee_form_section_vars', |
|
849 | - EE_Form_Section_Proper::$_js_localization |
|
850 | - ); |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * ensure_scripts_localized |
|
856 | - * |
|
857 | - * @throws EE_Error |
|
858 | - */ |
|
859 | - public function ensure_scripts_localized() |
|
860 | - { |
|
861 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | - $this->_enqueue_and_localize_form_js(); |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | - * |
|
871 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | - */ |
|
873 | - private static function _get_localized_error_messages() |
|
874 | - { |
|
875 | - return array( |
|
876 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | - ); |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * @return array |
|
884 | - */ |
|
885 | - public static function js_localization() |
|
886 | - { |
|
887 | - return self::$_js_localization; |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * @return void |
|
893 | - */ |
|
894 | - public static function reset_js_localization() |
|
895 | - { |
|
896 | - self::$_js_localization = array(); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | - * See parent function for more... |
|
903 | - * |
|
904 | - * @return array |
|
905 | - * @throws EE_Error |
|
906 | - */ |
|
907 | - public function get_jquery_validation_rules() |
|
908 | - { |
|
909 | - $jquery_validation_rules = array(); |
|
910 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | - $jquery_validation_rules = array_merge( |
|
912 | - $jquery_validation_rules, |
|
913 | - $subsection->get_jquery_validation_rules() |
|
914 | - ); |
|
915 | - } |
|
916 | - return $jquery_validation_rules; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Sanitizes all the data and sets the sanitized value of each field |
|
922 | - * |
|
923 | - * @param array $req_data like $_POST |
|
924 | - * @return void |
|
925 | - * @throws EE_Error |
|
926 | - */ |
|
927 | - protected function _normalize($req_data) |
|
928 | - { |
|
929 | - $this->_received_submission = true; |
|
930 | - $this->_validation_errors = array(); |
|
931 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | - try { |
|
933 | - $subsection->_normalize($req_data); |
|
934 | - } catch (EE_Validation_Error $e) { |
|
935 | - $subsection->add_validation_error($e); |
|
936 | - } |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - /** |
|
942 | - * Performs validation on this form section and its subsections. |
|
943 | - * For each subsection, |
|
944 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | - * and passes it the subsection, then calls _validate on that subsection. |
|
946 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | - * you would be best to override this _validate method, |
|
948 | - * calling parent::_validate() first. |
|
949 | - * |
|
950 | - * @throws EE_Error |
|
951 | - */ |
|
952 | - protected function _validate() |
|
953 | - { |
|
954 | - // reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | - $this->is_valid = null; |
|
956 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | - } |
|
960 | - $subsection->_validate(); |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * Gets all the validated inputs for the form section |
|
967 | - * |
|
968 | - * @return array |
|
969 | - * @throws EE_Error |
|
970 | - */ |
|
971 | - public function valid_data() |
|
972 | - { |
|
973 | - $inputs = array(); |
|
974 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | - } |
|
980 | - } |
|
981 | - return $inputs; |
|
982 | - } |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * Gets all the inputs on this form section |
|
987 | - * |
|
988 | - * @return EE_Form_Input_Base[] |
|
989 | - * @throws EE_Error |
|
990 | - */ |
|
991 | - public function inputs() |
|
992 | - { |
|
993 | - $inputs = array(); |
|
994 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | - $inputs[ $subsection_name ] = $subsection; |
|
997 | - } |
|
998 | - } |
|
999 | - return $inputs; |
|
1000 | - } |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * Gets all the subsections which are a proper form |
|
1005 | - * |
|
1006 | - * @return EE_Form_Section_Proper[] |
|
1007 | - * @throws EE_Error |
|
1008 | - */ |
|
1009 | - public function subforms() |
|
1010 | - { |
|
1011 | - $form_sections = array(); |
|
1012 | - foreach ($this->subsections() as $name => $obj) { |
|
1013 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | - $form_sections[ $name ] = $obj; |
|
1015 | - } |
|
1016 | - } |
|
1017 | - return $form_sections; |
|
1018 | - } |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | - * Consider using inputs() or subforms() |
|
1024 | - * if you only want form inputs or proper form sections. |
|
1025 | - * |
|
1026 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | - * leave this as TRUE so that the inputs will be properly |
|
1028 | - * configured. However, some client code may be ok with |
|
1029 | - * construction finalize being called later |
|
1030 | - * (realizing that the subsections' html names might not be |
|
1031 | - * set yet, etc.) |
|
1032 | - * @return EE_Form_Section_Proper[] |
|
1033 | - * @throws EE_Error |
|
1034 | - */ |
|
1035 | - public function subsections($require_construction_to_be_finalized = true) |
|
1036 | - { |
|
1037 | - if ($require_construction_to_be_finalized) { |
|
1038 | - $this->ensure_construct_finalized_called(); |
|
1039 | - } |
|
1040 | - return $this->_subsections; |
|
1041 | - } |
|
1042 | - |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Returns whether this form has any subforms or inputs |
|
1046 | - * @return bool |
|
1047 | - */ |
|
1048 | - public function hasSubsections() |
|
1049 | - { |
|
1050 | - return ! empty($this->_subsections); |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | - * values. (Similar to calling get_input_value on inputs) |
|
1057 | - * |
|
1058 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | - * or just this forms' direct children inputs |
|
1060 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | - * or allow multidimensional array |
|
1062 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | - * with array keys being input names |
|
1064 | - * (regardless of whether they are from a subsection or not), |
|
1065 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | - * where keys are always subsection names and values are either |
|
1067 | - * the input's normalized value, or an array like the top-level array |
|
1068 | - * @throws EE_Error |
|
1069 | - */ |
|
1070 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | - { |
|
1072 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | - * is not necessarily the value we want to display to users. This creates an array |
|
1080 | - * where keys are the input names, and values are their display values |
|
1081 | - * |
|
1082 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | - * or just this forms' direct children inputs |
|
1084 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | - * or allow multidimensional array |
|
1086 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | - * with array keys being input names |
|
1088 | - * (regardless of whether they are from a subsection or not), |
|
1089 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | - * where keys are always subsection names and values are either |
|
1091 | - * the input's normalized value, or an array like the top-level array |
|
1092 | - * @throws EE_Error |
|
1093 | - */ |
|
1094 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | - { |
|
1096 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Gets the input values from the form |
|
1102 | - * |
|
1103 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | - * or just the normalized value |
|
1105 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | - * or just this forms' direct children inputs |
|
1107 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | - * or allow multidimensional array |
|
1109 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | - * input names (regardless of whether they are from a subsection or not), |
|
1111 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | - * where keys are always subsection names and values are either |
|
1113 | - * the input's normalized value, or an array like the top-level array |
|
1114 | - * @throws EE_Error |
|
1115 | - */ |
|
1116 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | - { |
|
1118 | - $input_values = array(); |
|
1119 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | - $input_values[ $subsection_name ] = $pretty |
|
1122 | - ? $subsection->pretty_value() |
|
1123 | - : $subsection->normalized_value(); |
|
1124 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | - $subform_input_values = $subsection->_input_values( |
|
1126 | - $pretty, |
|
1127 | - $include_subform_inputs, |
|
1128 | - $flatten |
|
1129 | - ); |
|
1130 | - if ($flatten) { |
|
1131 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | - } else { |
|
1133 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | - } |
|
1135 | - } |
|
1136 | - } |
|
1137 | - return $input_values; |
|
1138 | - } |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Gets the originally submitted input values from the form |
|
1143 | - * |
|
1144 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | - * or just this forms' direct children inputs |
|
1146 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | - * with array keys being input names |
|
1148 | - * (regardless of whether they are from a subsection or not), |
|
1149 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | - * where keys are always subsection names and values are either |
|
1151 | - * the input's normalized value, or an array like the top-level array |
|
1152 | - * @throws EE_Error |
|
1153 | - */ |
|
1154 | - public function submitted_values($include_subforms = false) |
|
1155 | - { |
|
1156 | - $submitted_values = array(); |
|
1157 | - foreach ($this->subsections() as $subsection) { |
|
1158 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | - // is this input part of an array of inputs? |
|
1160 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | - explode( |
|
1163 | - '[', |
|
1164 | - str_replace(']', '', $subsection->html_name()) |
|
1165 | - ), |
|
1166 | - $subsection->raw_value() |
|
1167 | - ); |
|
1168 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | - } else { |
|
1170 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | - } |
|
1172 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - return $submitted_values; |
|
1178 | - } |
|
1179 | - |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Indicates whether or not this form has received a submission yet |
|
1183 | - * (ie, had receive_form_submission called on it yet) |
|
1184 | - * |
|
1185 | - * @return boolean |
|
1186 | - * @throws EE_Error |
|
1187 | - */ |
|
1188 | - public function has_received_submission() |
|
1189 | - { |
|
1190 | - $this->ensure_construct_finalized_called(); |
|
1191 | - return $this->_received_submission; |
|
1192 | - } |
|
1193 | - |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | - * Removes the listed inputs from the form |
|
1198 | - * |
|
1199 | - * @param array $inputs_to_exclude values are the input names |
|
1200 | - * @return void |
|
1201 | - */ |
|
1202 | - public function exclude(array $inputs_to_exclude = array()) |
|
1203 | - { |
|
1204 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | - } |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | - * @param array $inputs_to_hide |
|
1213 | - * @throws EE_Error |
|
1214 | - */ |
|
1215 | - public function hide(array $inputs_to_hide = array()) |
|
1216 | - { |
|
1217 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | - $input = $this->get_input($input_to_hide); |
|
1219 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * add_subsections |
|
1226 | - * Adds the listed subsections to the form section. |
|
1227 | - * If $subsection_name_to_target is provided, |
|
1228 | - * then new subsections are added before or after that subsection, |
|
1229 | - * otherwise to the start or end of the entire subsections array. |
|
1230 | - * |
|
1231 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | - * where keys are their names |
|
1233 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | - * should be added before or after |
|
1235 | - * IF $subsection_name_to_target is null, |
|
1236 | - * then $new_subsections will be added to |
|
1237 | - * the beginning or end of the entire subsections array |
|
1238 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | - * $subsection_name_to_target, |
|
1240 | - * or if $subsection_name_to_target is null, |
|
1241 | - * before or after entire subsections array |
|
1242 | - * @return void |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | - { |
|
1247 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | - EE_Error::add_error( |
|
1250 | - sprintf( |
|
1251 | - esc_html__( |
|
1252 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | - 'event_espresso' |
|
1254 | - ), |
|
1255 | - get_class($subsection), |
|
1256 | - $subsection_name, |
|
1257 | - $this->name() |
|
1258 | - ) |
|
1259 | - ); |
|
1260 | - unset($new_subsections[ $subsection_name ]); |
|
1261 | - } |
|
1262 | - } |
|
1263 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | - $this->_subsections, |
|
1265 | - $new_subsections, |
|
1266 | - $subsection_name_to_target, |
|
1267 | - $add_before |
|
1268 | - ); |
|
1269 | - if ($this->_construction_finalized) { |
|
1270 | - foreach ($this->_subsections as $name => $subsection) { |
|
1271 | - $subsection->_construct_finalize($this, $name); |
|
1272 | - } |
|
1273 | - } |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @param string $subsection_name |
|
1279 | - * @param bool $recursive |
|
1280 | - * @return bool |
|
1281 | - */ |
|
1282 | - public function has_subsection($subsection_name, $recursive = false) |
|
1283 | - { |
|
1284 | - foreach ($this->_subsections as $name => $subsection) { |
|
1285 | - if ($name === $subsection_name |
|
1286 | - || ( |
|
1287 | - $recursive |
|
1288 | - && $subsection instanceof EE_Form_Section_Proper |
|
1289 | - && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | - ) |
|
1291 | - ) { |
|
1292 | - return true; |
|
1293 | - } |
|
1294 | - } |
|
1295 | - return false; |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * Just gets all validatable subsections to clean their sensitive data |
|
1302 | - * |
|
1303 | - * @throws EE_Error |
|
1304 | - */ |
|
1305 | - public function clean_sensitive_data() |
|
1306 | - { |
|
1307 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | - $subsection->clean_sensitive_data(); |
|
1309 | - } |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | - * @param string $form_submission_error_message |
|
1316 | - * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | - * @throws EE_Error |
|
1318 | - */ |
|
1319 | - public function set_submission_error_message( |
|
1320 | - $form_submission_error_message = '' |
|
1321 | - ) { |
|
1322 | - $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | - ? $form_submission_error_message |
|
1324 | - : $this->getAllValidationErrorsString(); |
|
1325 | - } |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | - * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | - * set_submission_error_message |
|
1332 | - * |
|
1333 | - * @return string |
|
1334 | - */ |
|
1335 | - public function submission_error_message() |
|
1336 | - { |
|
1337 | - return $this->_form_submission_error_message; |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Sets a message to display if the data submitted to the form was valid. |
|
1343 | - * @param string $form_submission_success_message |
|
1344 | - */ |
|
1345 | - public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | - { |
|
1347 | - $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | - ? $form_submission_success_message |
|
1349 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | - } |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | - * @return string |
|
1356 | - */ |
|
1357 | - public function submission_success_message() |
|
1358 | - { |
|
1359 | - return $this->_form_submission_success_message; |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Returns the prefix that should be used on child of this form section for |
|
1365 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | - * prefix onto this form section's prefix. Used primarily by |
|
1367 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | - * |
|
1369 | - * @return string |
|
1370 | - * @throws EE_Error |
|
1371 | - */ |
|
1372 | - public function html_name_prefix() |
|
1373 | - { |
|
1374 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | - } |
|
1377 | - return $this->name(); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | - * was set, which is probably nothing, or the classname) |
|
1385 | - * |
|
1386 | - * @return string |
|
1387 | - * @throws EE_Error |
|
1388 | - */ |
|
1389 | - public function name() |
|
1390 | - { |
|
1391 | - $this->ensure_construct_finalized_called(); |
|
1392 | - return parent::name(); |
|
1393 | - } |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * @return EE_Form_Section_Proper |
|
1398 | - * @throws EE_Error |
|
1399 | - */ |
|
1400 | - public function parent_section() |
|
1401 | - { |
|
1402 | - $this->ensure_construct_finalized_called(); |
|
1403 | - return parent::parent_section(); |
|
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | - * |
|
1410 | - * @return void |
|
1411 | - * @throws EE_Error |
|
1412 | - */ |
|
1413 | - public function ensure_construct_finalized_called() |
|
1414 | - { |
|
1415 | - if (! $this->_construction_finalized) { |
|
1416 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | - } |
|
1418 | - } |
|
1419 | - |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | - * are in teh form data. If any are found, returns true. Else false |
|
1424 | - * |
|
1425 | - * @param array $req_data |
|
1426 | - * @return boolean |
|
1427 | - * @throws EE_Error |
|
1428 | - */ |
|
1429 | - public function form_data_present_in($req_data = null) |
|
1430 | - { |
|
1431 | - $req_data = $this->getCachedRequest($req_data); |
|
1432 | - foreach ($this->subsections() as $subsection) { |
|
1433 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | - if ($subsection->form_data_present_in($req_data)) { |
|
1435 | - return true; |
|
1436 | - } |
|
1437 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | - if ($subsection->form_data_present_in($req_data)) { |
|
1439 | - return true; |
|
1440 | - } |
|
1441 | - } |
|
1442 | - } |
|
1443 | - return false; |
|
1444 | - } |
|
1445 | - |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * Gets validation errors for this form section and subsections |
|
1449 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | - * gets the validation errors for ALL subsection |
|
1451 | - * |
|
1452 | - * @return EE_Validation_Error[] |
|
1453 | - * @throws EE_Error |
|
1454 | - */ |
|
1455 | - public function get_validation_errors_accumulated() |
|
1456 | - { |
|
1457 | - $validation_errors = $this->get_validation_errors(); |
|
1458 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | - } else { |
|
1462 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | - } |
|
1464 | - if ($validation_errors_on_this_subsection) { |
|
1465 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | - } |
|
1467 | - } |
|
1468 | - return $validation_errors; |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | - * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | - * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | - * |
|
1476 | - * @return string |
|
1477 | - * @since 4.9.59.p |
|
1478 | - */ |
|
1479 | - protected function getAllValidationErrorsString() |
|
1480 | - { |
|
1481 | - $submission_error_messages = array(); |
|
1482 | - // bad, bad, bad registrant |
|
1483 | - foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | - $form_section = $validation_error->get_form_section(); |
|
1486 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | - $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | - } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | - $label = $validation_error->get_form_section()->name(); |
|
1490 | - } else { |
|
1491 | - $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | - } |
|
1493 | - $submission_error_messages[] = sprintf( |
|
1494 | - __('%s : %s', 'event_espresso'), |
|
1495 | - $label, |
|
1496 | - $validation_error->getMessage() |
|
1497 | - ); |
|
1498 | - } |
|
1499 | - } |
|
1500 | - return implode('<br', $submission_error_messages); |
|
1501 | - } |
|
1502 | - |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | - * which will be returned. |
|
1510 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | - * Etc |
|
1515 | - * |
|
1516 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | - * @return EE_Form_Section_Base |
|
1518 | - * @throws EE_Error |
|
1519 | - */ |
|
1520 | - public function find_section_from_path($form_section_path) |
|
1521 | - { |
|
1522 | - // check if we can find the input from purely going straight up the tree |
|
1523 | - $input = parent::find_section_from_path($form_section_path); |
|
1524 | - if ($input instanceof EE_Form_Section_Base) { |
|
1525 | - return $input; |
|
1526 | - } |
|
1527 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | - if ($next_slash_pos !== false) { |
|
1529 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | - } else { |
|
1532 | - $child_section_name = $form_section_path; |
|
1533 | - $subpath = ''; |
|
1534 | - } |
|
1535 | - $child_section = $this->get_subsection($child_section_name); |
|
1536 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | - return $child_section->find_section_from_path($subpath); |
|
1538 | - } |
|
1539 | - return null; |
|
1540 | - } |
|
17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | + |
|
19 | + /** |
|
20 | + * Subsections |
|
21 | + * |
|
22 | + * @var EE_Form_Section_Validatable[] |
|
23 | + */ |
|
24 | + protected $_subsections = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Strategy for laying out the form |
|
28 | + * |
|
29 | + * @var EE_Form_Section_Layout_Base |
|
30 | + */ |
|
31 | + protected $_layout_strategy; |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether or not this form has received and validated a form submission yet |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_received_submission = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * message displayed to users upon successful form submission |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_form_submission_success_message = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * message displayed to users upon unsuccessful form submission |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_form_submission_error_message = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array like $_REQUEST |
|
56 | + */ |
|
57 | + protected $cached_request_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * Stores whether this form (and its sub-sections) were found to be valid or not. |
|
61 | + * Starts off as null, but once the form is validated, it set to either true or false |
|
62 | + * @var boolean|null |
|
63 | + */ |
|
64 | + protected $is_valid; |
|
65 | + |
|
66 | + /** |
|
67 | + * Stores all the data that will localized for form validation |
|
68 | + * |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + static protected $_js_localization = array(); |
|
72 | + |
|
73 | + /** |
|
74 | + * whether or not the form's localized validation JS vars have been set |
|
75 | + * |
|
76 | + * @type boolean |
|
77 | + */ |
|
78 | + static protected $_scripts_localized = false; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * when constructing a proper form section, calls _construct_finalize on children |
|
83 | + * so that they know who their parent is, and what name they've been given. |
|
84 | + * |
|
85 | + * @param array[] $options_array { |
|
86 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
87 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
88 | + * and in that order. This is handy if you want |
|
89 | + * the subsections to be ordered differently than the default, and if you override |
|
90 | + * which fields are shown |
|
91 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
92 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
93 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
94 | + * items from that list of inclusions) |
|
95 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
96 | + * } @see EE_Form_Section_Validatable::__construct() |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public function __construct($options_array = array()) |
|
100 | + { |
|
101 | + $options_array = (array) apply_filters( |
|
102 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
103 | + $options_array, |
|
104 | + $this |
|
105 | + ); |
|
106 | + // call parent first, as it may be setting the name |
|
107 | + parent::__construct($options_array); |
|
108 | + // if they've included subsections in the constructor, add them now |
|
109 | + if (isset($options_array['include'])) { |
|
110 | + // we are going to make sure we ONLY have those subsections to include |
|
111 | + // AND we are going to make sure they're in that specified order |
|
112 | + $reordered_subsections = array(); |
|
113 | + foreach ($options_array['include'] as $input_name) { |
|
114 | + if (isset($this->_subsections[ $input_name ])) { |
|
115 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
116 | + } |
|
117 | + } |
|
118 | + $this->_subsections = $reordered_subsections; |
|
119 | + } |
|
120 | + if (isset($options_array['exclude'])) { |
|
121 | + $exclude = $options_array['exclude']; |
|
122 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
123 | + } |
|
124 | + if (isset($options_array['layout_strategy'])) { |
|
125 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
126 | + } |
|
127 | + if (! $this->_layout_strategy) { |
|
128 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
129 | + } |
|
130 | + $this->_layout_strategy->_construct_finalize($this); |
|
131 | + // ok so we are definitely going to want the forms JS, |
|
132 | + // so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
133 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
134 | + // ok so they've constructed this object after when they should have. |
|
135 | + // just enqueue the generic form scripts and initialize the form immediately in the JS |
|
136 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
137 | + } else { |
|
138 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
139 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
140 | + } |
|
141 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
142 | + /** |
|
143 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
144 | + * The form probably doesn't yet have a parent form section. |
|
145 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
146 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
147 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
148 | + * |
|
149 | + * @since 4.9.32 |
|
150 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
151 | + * except maybe calling _construct_finalize has been done |
|
152 | + * @param array $options_array options passed into the constructor |
|
153 | + */ |
|
154 | + do_action( |
|
155 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
156 | + $this, |
|
157 | + $options_array |
|
158 | + ); |
|
159 | + if (isset($options_array['name'])) { |
|
160 | + $this->_construct_finalize(null, $options_array['name']); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Finishes construction given the parent form section and this form section's name |
|
167 | + * |
|
168 | + * @param EE_Form_Section_Proper $parent_form_section |
|
169 | + * @param string $name |
|
170 | + * @throws EE_Error |
|
171 | + */ |
|
172 | + public function _construct_finalize($parent_form_section, $name) |
|
173 | + { |
|
174 | + parent::_construct_finalize($parent_form_section, $name); |
|
175 | + $this->_set_default_name_if_empty(); |
|
176 | + $this->_set_default_html_id_if_empty(); |
|
177 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
178 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
179 | + $subsection->_construct_finalize($this, $subsection_name); |
|
180 | + } else { |
|
181 | + throw new EE_Error( |
|
182 | + sprintf( |
|
183 | + esc_html__( |
|
184 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + $subsection_name, |
|
188 | + get_class($this), |
|
189 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
190 | + ) |
|
191 | + ); |
|
192 | + } |
|
193 | + } |
|
194 | + /** |
|
195 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
196 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
197 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
198 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
199 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
200 | + * ensured it has a name, HTML IDs, etc |
|
201 | + * |
|
202 | + * @param EE_Form_Section_Proper $this |
|
203 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
204 | + * @param string $name |
|
205 | + */ |
|
206 | + do_action( |
|
207 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
208 | + $this, |
|
209 | + $parent_form_section, |
|
210 | + $name |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Gets the layout strategy for this form section |
|
217 | + * |
|
218 | + * @return EE_Form_Section_Layout_Base |
|
219 | + */ |
|
220 | + public function get_layout_strategy() |
|
221 | + { |
|
222 | + return $this->_layout_strategy; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Gets the HTML for a single input for this form section according |
|
228 | + * to the layout strategy |
|
229 | + * |
|
230 | + * @param EE_Form_Input_Base $input |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function get_html_for_input($input) |
|
234 | + { |
|
235 | + return $this->_layout_strategy->layout_input($input); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * was_submitted - checks if form inputs are present in request data |
|
241 | + * Basically an alias for form_data_present_in() (which is used by both |
|
242 | + * proper form sections and form inputs) |
|
243 | + * |
|
244 | + * @param null $form_data |
|
245 | + * @return boolean |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function was_submitted($form_data = null) |
|
249 | + { |
|
250 | + return $this->form_data_present_in($form_data); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Gets the cached request data; but if there is none, or $req_data was set with |
|
255 | + * something different, refresh the cache, and then return it |
|
256 | + * @param null $req_data |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + protected function getCachedRequest($req_data = null) |
|
260 | + { |
|
261 | + if ($this->cached_request_data === null |
|
262 | + || ( |
|
263 | + $req_data !== null && |
|
264 | + $req_data !== $this->cached_request_data |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $req_data = apply_filters( |
|
268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | + $req_data, |
|
270 | + $this |
|
271 | + ); |
|
272 | + if ($req_data === null) { |
|
273 | + $req_data = array_merge($_GET, $_POST); |
|
274 | + } |
|
275 | + $req_data = apply_filters( |
|
276 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
277 | + $req_data, |
|
278 | + $this |
|
279 | + ); |
|
280 | + $this->cached_request_data = (array) $req_data; |
|
281 | + } |
|
282 | + return $this->cached_request_data; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
288 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
289 | + * |
|
290 | + * @param array|null $req_data should usually be $_POST (the default). |
|
291 | + * However, you CAN supply a different array. |
|
292 | + * Consider using set_defaults() instead however. |
|
293 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
294 | + * the inputs will have the correct name in the request data for this function |
|
295 | + * to find them and populate the form with them. |
|
296 | + * If you have a flat form (with only input subsections), |
|
297 | + * you can supply a flat array where keys |
|
298 | + * are the form input names and values are their values) |
|
299 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
300 | + * of course, to validate that data, and set errors on the invalid values. |
|
301 | + * But if the data has already been validated |
|
302 | + * (eg you validated the data then stored it in the DB) |
|
303 | + * you may want to skip this step. |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws InvalidInterfaceException |
|
306 | + * @throws InvalidDataTypeException |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function receive_form_submission($req_data = null, $validate = true) |
|
310 | + { |
|
311 | + $req_data = $this->getCachedRequest($req_data); |
|
312 | + $this->_normalize($req_data); |
|
313 | + if ($validate) { |
|
314 | + $this->_validate(); |
|
315 | + // if it's invalid, we're going to want to re-display so remember what they submitted |
|
316 | + if (! $this->is_valid()) { |
|
317 | + $this->store_submitted_form_data_in_session(); |
|
318 | + } |
|
319 | + } |
|
320 | + if ($this->submission_error_message() === '' && ! $this->is_valid()) { |
|
321 | + $this->set_submission_error_message(); |
|
322 | + } |
|
323 | + do_action( |
|
324 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
325 | + $req_data, |
|
326 | + $this, |
|
327 | + $validate |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * caches the originally submitted input values in the session |
|
334 | + * so that they can be used to repopulate the form if it failed validation |
|
335 | + * |
|
336 | + * @return boolean whether or not the data was successfully stored in the session |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws InvalidInterfaceException |
|
339 | + * @throws InvalidDataTypeException |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + protected function store_submitted_form_data_in_session() |
|
343 | + { |
|
344 | + return EE_Registry::instance()->SSN->set_session_data( |
|
345 | + array( |
|
346 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * retrieves the originally submitted input values in the session |
|
354 | + * so that they can be used to repopulate the form if it failed validation |
|
355 | + * |
|
356 | + * @return array |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidInterfaceException |
|
359 | + * @throws InvalidDataTypeException |
|
360 | + */ |
|
361 | + protected function get_submitted_form_data_from_session() |
|
362 | + { |
|
363 | + $session = EE_Registry::instance()->SSN; |
|
364 | + if ($session instanceof EE_Session) { |
|
365 | + return $session->get_session_data( |
|
366 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
367 | + ); |
|
368 | + } |
|
369 | + return array(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * flushed the originally submitted input values from the session |
|
375 | + * |
|
376 | + * @return boolean whether or not the data was successfully removed from the session |
|
377 | + * @throws InvalidArgumentException |
|
378 | + * @throws InvalidInterfaceException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + */ |
|
381 | + public static function flush_submitted_form_data_from_session() |
|
382 | + { |
|
383 | + return EE_Registry::instance()->SSN->reset_data( |
|
384 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Populates this form and its subsections with data from the session. |
|
391 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
392 | + * validation errors when displaying too) |
|
393 | + * Returns true if the form was populated from the session, false otherwise |
|
394 | + * |
|
395 | + * @return boolean |
|
396 | + * @throws InvalidArgumentException |
|
397 | + * @throws InvalidInterfaceException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws EE_Error |
|
400 | + */ |
|
401 | + public function populate_from_session() |
|
402 | + { |
|
403 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
404 | + if (empty($form_data_in_session)) { |
|
405 | + return false; |
|
406 | + } |
|
407 | + $this->receive_form_submission($form_data_in_session); |
|
408 | + add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session')); |
|
409 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
410 | + return true; |
|
411 | + } |
|
412 | + return false; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Populates the default data for the form, given an array where keys are |
|
418 | + * the input names, and values are their values (preferably normalized to be their |
|
419 | + * proper PHP types, not all strings... although that should be ok too). |
|
420 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
421 | + * the value being an array formatted in teh same way |
|
422 | + * |
|
423 | + * @param array $default_data |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function populate_defaults($default_data) |
|
427 | + { |
|
428 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
429 | + if (isset($default_data[ $subsection_name ])) { |
|
430 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
431 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
432 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
433 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
434 | + } |
|
435 | + } |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * returns true if subsection exists |
|
442 | + * |
|
443 | + * @param string $name |
|
444 | + * @return boolean |
|
445 | + */ |
|
446 | + public function subsection_exists($name) |
|
447 | + { |
|
448 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Gets the subsection specified by its name |
|
454 | + * |
|
455 | + * @param string $name |
|
456 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
457 | + * so that the inputs will be properly configured. |
|
458 | + * However, some client code may be ok |
|
459 | + * with construction finalize being called later |
|
460 | + * (realizing that the subsections' html names |
|
461 | + * might not be set yet, etc.) |
|
462 | + * @return EE_Form_Section_Base |
|
463 | + * @throws EE_Error |
|
464 | + */ |
|
465 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
466 | + { |
|
467 | + if ($require_construction_to_be_finalized) { |
|
468 | + $this->ensure_construct_finalized_called(); |
|
469 | + } |
|
470 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Gets all the validatable subsections of this form section |
|
476 | + * |
|
477 | + * @return EE_Form_Section_Validatable[] |
|
478 | + * @throws EE_Error |
|
479 | + */ |
|
480 | + public function get_validatable_subsections() |
|
481 | + { |
|
482 | + $validatable_subsections = array(); |
|
483 | + foreach ($this->subsections() as $name => $obj) { |
|
484 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
485 | + $validatable_subsections[ $name ] = $obj; |
|
486 | + } |
|
487 | + } |
|
488 | + return $validatable_subsections; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
494 | + * throw an EE_Error. |
|
495 | + * |
|
496 | + * @param string $name |
|
497 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
498 | + * leave this as TRUE so that the inputs will be properly |
|
499 | + * configured. However, some client code may be ok with |
|
500 | + * construction finalize being called later |
|
501 | + * (realizing that the subsections' html names might not be |
|
502 | + * set yet, etc.) |
|
503 | + * @return EE_Form_Input_Base |
|
504 | + * @throws EE_Error |
|
505 | + */ |
|
506 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
507 | + { |
|
508 | + $subsection = $this->get_subsection( |
|
509 | + $name, |
|
510 | + $require_construction_to_be_finalized |
|
511 | + ); |
|
512 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
513 | + throw new EE_Error( |
|
514 | + sprintf( |
|
515 | + esc_html__( |
|
516 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
517 | + 'event_espresso' |
|
518 | + ), |
|
519 | + $name, |
|
520 | + get_class($this), |
|
521 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
522 | + ) |
|
523 | + ); |
|
524 | + } |
|
525 | + return $subsection; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
531 | + * otherwise throws an EE_Error |
|
532 | + * |
|
533 | + * @param string $name |
|
534 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
535 | + * leave this as TRUE so that the inputs will be properly |
|
536 | + * configured. However, some client code may be ok with |
|
537 | + * construction finalize being called later |
|
538 | + * (realizing that the subsections' html names might not be |
|
539 | + * set yet, etc.) |
|
540 | + * @return EE_Form_Section_Proper |
|
541 | + * @throws EE_Error |
|
542 | + */ |
|
543 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
544 | + { |
|
545 | + $subsection = $this->get_subsection( |
|
546 | + $name, |
|
547 | + $require_construction_to_be_finalized |
|
548 | + ); |
|
549 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
550 | + throw new EE_Error( |
|
551 | + sprintf( |
|
552 | + esc_html__( |
|
553 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + $name, |
|
557 | + get_class($this) |
|
558 | + ) |
|
559 | + ); |
|
560 | + } |
|
561 | + return $subsection; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
567 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
568 | + * |
|
569 | + * @param string $name |
|
570 | + * @return mixed depending on the input's type and its normalization strategy |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + public function get_input_value($name) |
|
574 | + { |
|
575 | + $input = $this->get_input($name); |
|
576 | + return $input->normalized_value(); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Checks if this form section itself is valid, and then checks its subsections |
|
582 | + * |
|
583 | + * @throws EE_Error |
|
584 | + * @return boolean |
|
585 | + */ |
|
586 | + public function is_valid() |
|
587 | + { |
|
588 | + if ($this->is_valid === null) { |
|
589 | + if (! $this->has_received_submission()) { |
|
590 | + throw new EE_Error( |
|
591 | + sprintf( |
|
592 | + esc_html__( |
|
593 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
594 | + 'event_espresso' |
|
595 | + ) |
|
596 | + ) |
|
597 | + ); |
|
598 | + } |
|
599 | + if (! parent::is_valid()) { |
|
600 | + $this->is_valid = false; |
|
601 | + } else { |
|
602 | + // ok so no general errors to this entire form section. |
|
603 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
604 | + $this->is_valid = true; |
|
605 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
606 | + if (! $subsection->is_valid()) { |
|
607 | + $this->is_valid = false; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + return $this->is_valid; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * gets the default name of this form section if none is specified |
|
618 | + * |
|
619 | + * @return void |
|
620 | + */ |
|
621 | + protected function _set_default_name_if_empty() |
|
622 | + { |
|
623 | + if (! $this->_name) { |
|
624 | + $classname = get_class($this); |
|
625 | + $default_name = str_replace('EE_', '', $classname); |
|
626 | + $this->_name = $default_name; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
633 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
634 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
635 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
636 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
637 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
638 | + * any CSS. |
|
639 | + * |
|
640 | + * @throws InvalidArgumentException |
|
641 | + * @throws InvalidInterfaceException |
|
642 | + * @throws InvalidDataTypeException |
|
643 | + * @throws EE_Error |
|
644 | + */ |
|
645 | + public function get_html_and_js() |
|
646 | + { |
|
647 | + $this->enqueue_js(); |
|
648 | + return $this->get_html(); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
654 | + * |
|
655 | + * @param bool $display_previously_submitted_data |
|
656 | + * @return string |
|
657 | + * @throws InvalidArgumentException |
|
658 | + * @throws InvalidInterfaceException |
|
659 | + * @throws InvalidDataTypeException |
|
660 | + * @throws EE_Error |
|
661 | + * @throws EE_Error |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function get_html($display_previously_submitted_data = true) |
|
665 | + { |
|
666 | + $this->ensure_construct_finalized_called(); |
|
667 | + if ($display_previously_submitted_data) { |
|
668 | + $this->populate_from_session(); |
|
669 | + } |
|
670 | + return $this->_form_html_filter |
|
671 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
672 | + : $this->_layout_strategy->layout_form(); |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * enqueues JS and CSS for the form. |
|
678 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
679 | + * scripts and styles can be put in the header, but if called later |
|
680 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
681 | + * only be in the header; but in HTML5 its ok in the body. |
|
682 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
683 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
684 | + * |
|
685 | + * @return void |
|
686 | + * @throws EE_Error |
|
687 | + */ |
|
688 | + public function enqueue_js() |
|
689 | + { |
|
690 | + $this->_enqueue_and_localize_form_js(); |
|
691 | + foreach ($this->subsections() as $subsection) { |
|
692 | + $subsection->enqueue_js(); |
|
693 | + } |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
699 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
700 | + * the wp_enqueue_scripts hook. |
|
701 | + * However, registering the form js and localizing it can happen when we |
|
702 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
703 | + * could change until it's actually outputted) |
|
704 | + * |
|
705 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
706 | + * to be triggered automatically or not |
|
707 | + * @return void |
|
708 | + */ |
|
709 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
710 | + { |
|
711 | + wp_register_script( |
|
712 | + 'ee_form_section_validation', |
|
713 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
714 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
715 | + EVENT_ESPRESSO_VERSION, |
|
716 | + true |
|
717 | + ); |
|
718 | + wp_localize_script( |
|
719 | + 'ee_form_section_validation', |
|
720 | + 'ee_form_section_validation_init', |
|
721 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
722 | + ); |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * gets the variables used by form_section_validation.js. |
|
728 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
729 | + * but before the wordpress hook wp_loaded |
|
730 | + * |
|
731 | + * @throws EE_Error |
|
732 | + */ |
|
733 | + public function _enqueue_and_localize_form_js() |
|
734 | + { |
|
735 | + $this->ensure_construct_finalized_called(); |
|
736 | + // actually, we don't want to localize just yet. There may be other forms on the page. |
|
737 | + // so we need to add our form section data to a static variable accessible by all form sections |
|
738 | + // and localize it just before the footer |
|
739 | + $this->localize_validation_rules(); |
|
740 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
741 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * add our form section data to a static variable accessible by all form sections |
|
747 | + * |
|
748 | + * @param bool $return_for_subsection |
|
749 | + * @return void |
|
750 | + * @throws EE_Error |
|
751 | + */ |
|
752 | + public function localize_validation_rules($return_for_subsection = false) |
|
753 | + { |
|
754 | + // we only want to localize vars ONCE for the entire form, |
|
755 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
756 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
757 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
758 | + 'form_section_id' => $this->html_id(true), |
|
759 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
760 | + 'other_data' => $this->get_other_js_data(), |
|
761 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
762 | + ); |
|
763 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
770 | + * This is primarily data added by inputs and forms in addition to any |
|
771 | + * scripts they might enqueue |
|
772 | + * |
|
773 | + * @param array $form_other_js_data |
|
774 | + * @return array |
|
775 | + * @throws EE_Error |
|
776 | + */ |
|
777 | + public function get_other_js_data($form_other_js_data = array()) |
|
778 | + { |
|
779 | + foreach ($this->subsections() as $subsection) { |
|
780 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
781 | + } |
|
782 | + return $form_other_js_data; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Gets a flat array of inputs for this form section and its subsections. |
|
788 | + * Keys are their form names, and values are the inputs themselves |
|
789 | + * |
|
790 | + * @return EE_Form_Input_Base |
|
791 | + * @throws EE_Error |
|
792 | + */ |
|
793 | + public function inputs_in_subsections() |
|
794 | + { |
|
795 | + $inputs = array(); |
|
796 | + foreach ($this->subsections() as $subsection) { |
|
797 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
798 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
799 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
800 | + $inputs += $subsection->inputs_in_subsections(); |
|
801 | + } |
|
802 | + } |
|
803 | + return $inputs; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * Gets a flat array of all the validation errors. |
|
809 | + * Keys are html names (because those should be unique) |
|
810 | + * and values are a string of all their validation errors |
|
811 | + * |
|
812 | + * @return string[] |
|
813 | + * @throws EE_Error |
|
814 | + */ |
|
815 | + public function subsection_validation_errors_by_html_name() |
|
816 | + { |
|
817 | + $inputs = $this->inputs(); |
|
818 | + $errors = array(); |
|
819 | + foreach ($inputs as $form_input) { |
|
820 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
821 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
822 | + } |
|
823 | + } |
|
824 | + return $errors; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
830 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
831 | + * |
|
832 | + * @throws InvalidArgumentException |
|
833 | + * @throws InvalidInterfaceException |
|
834 | + * @throws InvalidDataTypeException |
|
835 | + */ |
|
836 | + public static function localize_script_for_all_forms() |
|
837 | + { |
|
838 | + // allow inputs and stuff to hook in their JS and stuff here |
|
839 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
840 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
841 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
842 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
843 | + : 'wp_default'; |
|
844 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
845 | + wp_enqueue_script('ee_form_section_validation'); |
|
846 | + wp_localize_script( |
|
847 | + 'ee_form_section_validation', |
|
848 | + 'ee_form_section_vars', |
|
849 | + EE_Form_Section_Proper::$_js_localization |
|
850 | + ); |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * ensure_scripts_localized |
|
856 | + * |
|
857 | + * @throws EE_Error |
|
858 | + */ |
|
859 | + public function ensure_scripts_localized() |
|
860 | + { |
|
861 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
862 | + $this->_enqueue_and_localize_form_js(); |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
869 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
870 | + * |
|
871 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
872 | + */ |
|
873 | + private static function _get_localized_error_messages() |
|
874 | + { |
|
875 | + return array( |
|
876 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
877 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
878 | + ); |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * @return array |
|
884 | + */ |
|
885 | + public static function js_localization() |
|
886 | + { |
|
887 | + return self::$_js_localization; |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * @return void |
|
893 | + */ |
|
894 | + public static function reset_js_localization() |
|
895 | + { |
|
896 | + self::$_js_localization = array(); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
902 | + * See parent function for more... |
|
903 | + * |
|
904 | + * @return array |
|
905 | + * @throws EE_Error |
|
906 | + */ |
|
907 | + public function get_jquery_validation_rules() |
|
908 | + { |
|
909 | + $jquery_validation_rules = array(); |
|
910 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
911 | + $jquery_validation_rules = array_merge( |
|
912 | + $jquery_validation_rules, |
|
913 | + $subsection->get_jquery_validation_rules() |
|
914 | + ); |
|
915 | + } |
|
916 | + return $jquery_validation_rules; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Sanitizes all the data and sets the sanitized value of each field |
|
922 | + * |
|
923 | + * @param array $req_data like $_POST |
|
924 | + * @return void |
|
925 | + * @throws EE_Error |
|
926 | + */ |
|
927 | + protected function _normalize($req_data) |
|
928 | + { |
|
929 | + $this->_received_submission = true; |
|
930 | + $this->_validation_errors = array(); |
|
931 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
932 | + try { |
|
933 | + $subsection->_normalize($req_data); |
|
934 | + } catch (EE_Validation_Error $e) { |
|
935 | + $subsection->add_validation_error($e); |
|
936 | + } |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + /** |
|
942 | + * Performs validation on this form section and its subsections. |
|
943 | + * For each subsection, |
|
944 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
945 | + * and passes it the subsection, then calls _validate on that subsection. |
|
946 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
947 | + * you would be best to override this _validate method, |
|
948 | + * calling parent::_validate() first. |
|
949 | + * |
|
950 | + * @throws EE_Error |
|
951 | + */ |
|
952 | + protected function _validate() |
|
953 | + { |
|
954 | + // reset the cache of whether this form is valid or not- we're re-validating it now |
|
955 | + $this->is_valid = null; |
|
956 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
957 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
958 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
959 | + } |
|
960 | + $subsection->_validate(); |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * Gets all the validated inputs for the form section |
|
967 | + * |
|
968 | + * @return array |
|
969 | + * @throws EE_Error |
|
970 | + */ |
|
971 | + public function valid_data() |
|
972 | + { |
|
973 | + $inputs = array(); |
|
974 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
975 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
976 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
977 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
978 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
979 | + } |
|
980 | + } |
|
981 | + return $inputs; |
|
982 | + } |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * Gets all the inputs on this form section |
|
987 | + * |
|
988 | + * @return EE_Form_Input_Base[] |
|
989 | + * @throws EE_Error |
|
990 | + */ |
|
991 | + public function inputs() |
|
992 | + { |
|
993 | + $inputs = array(); |
|
994 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
995 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
996 | + $inputs[ $subsection_name ] = $subsection; |
|
997 | + } |
|
998 | + } |
|
999 | + return $inputs; |
|
1000 | + } |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * Gets all the subsections which are a proper form |
|
1005 | + * |
|
1006 | + * @return EE_Form_Section_Proper[] |
|
1007 | + * @throws EE_Error |
|
1008 | + */ |
|
1009 | + public function subforms() |
|
1010 | + { |
|
1011 | + $form_sections = array(); |
|
1012 | + foreach ($this->subsections() as $name => $obj) { |
|
1013 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
1014 | + $form_sections[ $name ] = $obj; |
|
1015 | + } |
|
1016 | + } |
|
1017 | + return $form_sections; |
|
1018 | + } |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
1023 | + * Consider using inputs() or subforms() |
|
1024 | + * if you only want form inputs or proper form sections. |
|
1025 | + * |
|
1026 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
1027 | + * leave this as TRUE so that the inputs will be properly |
|
1028 | + * configured. However, some client code may be ok with |
|
1029 | + * construction finalize being called later |
|
1030 | + * (realizing that the subsections' html names might not be |
|
1031 | + * set yet, etc.) |
|
1032 | + * @return EE_Form_Section_Proper[] |
|
1033 | + * @throws EE_Error |
|
1034 | + */ |
|
1035 | + public function subsections($require_construction_to_be_finalized = true) |
|
1036 | + { |
|
1037 | + if ($require_construction_to_be_finalized) { |
|
1038 | + $this->ensure_construct_finalized_called(); |
|
1039 | + } |
|
1040 | + return $this->_subsections; |
|
1041 | + } |
|
1042 | + |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Returns whether this form has any subforms or inputs |
|
1046 | + * @return bool |
|
1047 | + */ |
|
1048 | + public function hasSubsections() |
|
1049 | + { |
|
1050 | + return ! empty($this->_subsections); |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1056 | + * values. (Similar to calling get_input_value on inputs) |
|
1057 | + * |
|
1058 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1059 | + * or just this forms' direct children inputs |
|
1060 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1061 | + * or allow multidimensional array |
|
1062 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1063 | + * with array keys being input names |
|
1064 | + * (regardless of whether they are from a subsection or not), |
|
1065 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1066 | + * where keys are always subsection names and values are either |
|
1067 | + * the input's normalized value, or an array like the top-level array |
|
1068 | + * @throws EE_Error |
|
1069 | + */ |
|
1070 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1071 | + { |
|
1072 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1078 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1079 | + * is not necessarily the value we want to display to users. This creates an array |
|
1080 | + * where keys are the input names, and values are their display values |
|
1081 | + * |
|
1082 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1083 | + * or just this forms' direct children inputs |
|
1084 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1085 | + * or allow multidimensional array |
|
1086 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1087 | + * with array keys being input names |
|
1088 | + * (regardless of whether they are from a subsection or not), |
|
1089 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1090 | + * where keys are always subsection names and values are either |
|
1091 | + * the input's normalized value, or an array like the top-level array |
|
1092 | + * @throws EE_Error |
|
1093 | + */ |
|
1094 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1095 | + { |
|
1096 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Gets the input values from the form |
|
1102 | + * |
|
1103 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1104 | + * or just the normalized value |
|
1105 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1106 | + * or just this forms' direct children inputs |
|
1107 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1108 | + * or allow multidimensional array |
|
1109 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1110 | + * input names (regardless of whether they are from a subsection or not), |
|
1111 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1112 | + * where keys are always subsection names and values are either |
|
1113 | + * the input's normalized value, or an array like the top-level array |
|
1114 | + * @throws EE_Error |
|
1115 | + */ |
|
1116 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1117 | + { |
|
1118 | + $input_values = array(); |
|
1119 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1120 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1121 | + $input_values[ $subsection_name ] = $pretty |
|
1122 | + ? $subsection->pretty_value() |
|
1123 | + : $subsection->normalized_value(); |
|
1124 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1125 | + $subform_input_values = $subsection->_input_values( |
|
1126 | + $pretty, |
|
1127 | + $include_subform_inputs, |
|
1128 | + $flatten |
|
1129 | + ); |
|
1130 | + if ($flatten) { |
|
1131 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1132 | + } else { |
|
1133 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1134 | + } |
|
1135 | + } |
|
1136 | + } |
|
1137 | + return $input_values; |
|
1138 | + } |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Gets the originally submitted input values from the form |
|
1143 | + * |
|
1144 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1145 | + * or just this forms' direct children inputs |
|
1146 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1147 | + * with array keys being input names |
|
1148 | + * (regardless of whether they are from a subsection or not), |
|
1149 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1150 | + * where keys are always subsection names and values are either |
|
1151 | + * the input's normalized value, or an array like the top-level array |
|
1152 | + * @throws EE_Error |
|
1153 | + */ |
|
1154 | + public function submitted_values($include_subforms = false) |
|
1155 | + { |
|
1156 | + $submitted_values = array(); |
|
1157 | + foreach ($this->subsections() as $subsection) { |
|
1158 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1159 | + // is this input part of an array of inputs? |
|
1160 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1161 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1162 | + explode( |
|
1163 | + '[', |
|
1164 | + str_replace(']', '', $subsection->html_name()) |
|
1165 | + ), |
|
1166 | + $subsection->raw_value() |
|
1167 | + ); |
|
1168 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1169 | + } else { |
|
1170 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1171 | + } |
|
1172 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1173 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1174 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + return $submitted_values; |
|
1178 | + } |
|
1179 | + |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Indicates whether or not this form has received a submission yet |
|
1183 | + * (ie, had receive_form_submission called on it yet) |
|
1184 | + * |
|
1185 | + * @return boolean |
|
1186 | + * @throws EE_Error |
|
1187 | + */ |
|
1188 | + public function has_received_submission() |
|
1189 | + { |
|
1190 | + $this->ensure_construct_finalized_called(); |
|
1191 | + return $this->_received_submission; |
|
1192 | + } |
|
1193 | + |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1197 | + * Removes the listed inputs from the form |
|
1198 | + * |
|
1199 | + * @param array $inputs_to_exclude values are the input names |
|
1200 | + * @return void |
|
1201 | + */ |
|
1202 | + public function exclude(array $inputs_to_exclude = array()) |
|
1203 | + { |
|
1204 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1205 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1206 | + } |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1212 | + * @param array $inputs_to_hide |
|
1213 | + * @throws EE_Error |
|
1214 | + */ |
|
1215 | + public function hide(array $inputs_to_hide = array()) |
|
1216 | + { |
|
1217 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1218 | + $input = $this->get_input($input_to_hide); |
|
1219 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * add_subsections |
|
1226 | + * Adds the listed subsections to the form section. |
|
1227 | + * If $subsection_name_to_target is provided, |
|
1228 | + * then new subsections are added before or after that subsection, |
|
1229 | + * otherwise to the start or end of the entire subsections array. |
|
1230 | + * |
|
1231 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1232 | + * where keys are their names |
|
1233 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1234 | + * should be added before or after |
|
1235 | + * IF $subsection_name_to_target is null, |
|
1236 | + * then $new_subsections will be added to |
|
1237 | + * the beginning or end of the entire subsections array |
|
1238 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1239 | + * $subsection_name_to_target, |
|
1240 | + * or if $subsection_name_to_target is null, |
|
1241 | + * before or after entire subsections array |
|
1242 | + * @return void |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1246 | + { |
|
1247 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1248 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1249 | + EE_Error::add_error( |
|
1250 | + sprintf( |
|
1251 | + esc_html__( |
|
1252 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1253 | + 'event_espresso' |
|
1254 | + ), |
|
1255 | + get_class($subsection), |
|
1256 | + $subsection_name, |
|
1257 | + $this->name() |
|
1258 | + ) |
|
1259 | + ); |
|
1260 | + unset($new_subsections[ $subsection_name ]); |
|
1261 | + } |
|
1262 | + } |
|
1263 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1264 | + $this->_subsections, |
|
1265 | + $new_subsections, |
|
1266 | + $subsection_name_to_target, |
|
1267 | + $add_before |
|
1268 | + ); |
|
1269 | + if ($this->_construction_finalized) { |
|
1270 | + foreach ($this->_subsections as $name => $subsection) { |
|
1271 | + $subsection->_construct_finalize($this, $name); |
|
1272 | + } |
|
1273 | + } |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @param string $subsection_name |
|
1279 | + * @param bool $recursive |
|
1280 | + * @return bool |
|
1281 | + */ |
|
1282 | + public function has_subsection($subsection_name, $recursive = false) |
|
1283 | + { |
|
1284 | + foreach ($this->_subsections as $name => $subsection) { |
|
1285 | + if ($name === $subsection_name |
|
1286 | + || ( |
|
1287 | + $recursive |
|
1288 | + && $subsection instanceof EE_Form_Section_Proper |
|
1289 | + && $subsection->has_subsection($subsection_name, $recursive) |
|
1290 | + ) |
|
1291 | + ) { |
|
1292 | + return true; |
|
1293 | + } |
|
1294 | + } |
|
1295 | + return false; |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * Just gets all validatable subsections to clean their sensitive data |
|
1302 | + * |
|
1303 | + * @throws EE_Error |
|
1304 | + */ |
|
1305 | + public function clean_sensitive_data() |
|
1306 | + { |
|
1307 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1308 | + $subsection->clean_sensitive_data(); |
|
1309 | + } |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * Sets the submission error message (aka validation error message for this form section and all sub-sections) |
|
1315 | + * @param string $form_submission_error_message |
|
1316 | + * @param EE_Form_Section_Validatable $form_section unused |
|
1317 | + * @throws EE_Error |
|
1318 | + */ |
|
1319 | + public function set_submission_error_message( |
|
1320 | + $form_submission_error_message = '' |
|
1321 | + ) { |
|
1322 | + $this->_form_submission_error_message = ! empty($form_submission_error_message) |
|
1323 | + ? $form_submission_error_message |
|
1324 | + : $this->getAllValidationErrorsString(); |
|
1325 | + } |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Returns the cached error message. A default value is set for this during _validate(), |
|
1330 | + * (called during receive_form_submission) but it can be explicitly set using |
|
1331 | + * set_submission_error_message |
|
1332 | + * |
|
1333 | + * @return string |
|
1334 | + */ |
|
1335 | + public function submission_error_message() |
|
1336 | + { |
|
1337 | + return $this->_form_submission_error_message; |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Sets a message to display if the data submitted to the form was valid. |
|
1343 | + * @param string $form_submission_success_message |
|
1344 | + */ |
|
1345 | + public function set_submission_success_message($form_submission_success_message = '') |
|
1346 | + { |
|
1347 | + $this->_form_submission_success_message = ! empty($form_submission_success_message) |
|
1348 | + ? $form_submission_success_message |
|
1349 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1350 | + } |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Gets a message appropriate for display when the form is correctly submitted |
|
1355 | + * @return string |
|
1356 | + */ |
|
1357 | + public function submission_success_message() |
|
1358 | + { |
|
1359 | + return $this->_form_submission_success_message; |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Returns the prefix that should be used on child of this form section for |
|
1365 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1366 | + * prefix onto this form section's prefix. Used primarily by |
|
1367 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1368 | + * |
|
1369 | + * @return string |
|
1370 | + * @throws EE_Error |
|
1371 | + */ |
|
1372 | + public function html_name_prefix() |
|
1373 | + { |
|
1374 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1375 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1376 | + } |
|
1377 | + return $this->name(); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1383 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1384 | + * was set, which is probably nothing, or the classname) |
|
1385 | + * |
|
1386 | + * @return string |
|
1387 | + * @throws EE_Error |
|
1388 | + */ |
|
1389 | + public function name() |
|
1390 | + { |
|
1391 | + $this->ensure_construct_finalized_called(); |
|
1392 | + return parent::name(); |
|
1393 | + } |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * @return EE_Form_Section_Proper |
|
1398 | + * @throws EE_Error |
|
1399 | + */ |
|
1400 | + public function parent_section() |
|
1401 | + { |
|
1402 | + $this->ensure_construct_finalized_called(); |
|
1403 | + return parent::parent_section(); |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1409 | + * |
|
1410 | + * @return void |
|
1411 | + * @throws EE_Error |
|
1412 | + */ |
|
1413 | + public function ensure_construct_finalized_called() |
|
1414 | + { |
|
1415 | + if (! $this->_construction_finalized) { |
|
1416 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1417 | + } |
|
1418 | + } |
|
1419 | + |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1423 | + * are in teh form data. If any are found, returns true. Else false |
|
1424 | + * |
|
1425 | + * @param array $req_data |
|
1426 | + * @return boolean |
|
1427 | + * @throws EE_Error |
|
1428 | + */ |
|
1429 | + public function form_data_present_in($req_data = null) |
|
1430 | + { |
|
1431 | + $req_data = $this->getCachedRequest($req_data); |
|
1432 | + foreach ($this->subsections() as $subsection) { |
|
1433 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1434 | + if ($subsection->form_data_present_in($req_data)) { |
|
1435 | + return true; |
|
1436 | + } |
|
1437 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1438 | + if ($subsection->form_data_present_in($req_data)) { |
|
1439 | + return true; |
|
1440 | + } |
|
1441 | + } |
|
1442 | + } |
|
1443 | + return false; |
|
1444 | + } |
|
1445 | + |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * Gets validation errors for this form section and subsections |
|
1449 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1450 | + * gets the validation errors for ALL subsection |
|
1451 | + * |
|
1452 | + * @return EE_Validation_Error[] |
|
1453 | + * @throws EE_Error |
|
1454 | + */ |
|
1455 | + public function get_validation_errors_accumulated() |
|
1456 | + { |
|
1457 | + $validation_errors = $this->get_validation_errors(); |
|
1458 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1459 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1460 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1461 | + } else { |
|
1462 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1463 | + } |
|
1464 | + if ($validation_errors_on_this_subsection) { |
|
1465 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1466 | + } |
|
1467 | + } |
|
1468 | + return $validation_errors; |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Fetch validation errors from children and grandchildren and puts them in a single string. |
|
1473 | + * This traverses the form section tree to generate this, but you probably want to instead use |
|
1474 | + * get_form_submission_error_message() which is usually this message cached (or a custom validation error message) |
|
1475 | + * |
|
1476 | + * @return string |
|
1477 | + * @since 4.9.59.p |
|
1478 | + */ |
|
1479 | + protected function getAllValidationErrorsString() |
|
1480 | + { |
|
1481 | + $submission_error_messages = array(); |
|
1482 | + // bad, bad, bad registrant |
|
1483 | + foreach ($this->get_validation_errors_accumulated() as $validation_error) { |
|
1484 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1485 | + $form_section = $validation_error->get_form_section(); |
|
1486 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1487 | + $label = $validation_error->get_form_section()->html_label_text(); |
|
1488 | + } elseif ($form_section instanceof EE_Form_Section_Validatable) { |
|
1489 | + $label = $validation_error->get_form_section()->name(); |
|
1490 | + } else { |
|
1491 | + $label = esc_html__('Unknown', 'event_espresso'); |
|
1492 | + } |
|
1493 | + $submission_error_messages[] = sprintf( |
|
1494 | + __('%s : %s', 'event_espresso'), |
|
1495 | + $label, |
|
1496 | + $validation_error->getMessage() |
|
1497 | + ); |
|
1498 | + } |
|
1499 | + } |
|
1500 | + return implode('<br', $submission_error_messages); |
|
1501 | + } |
|
1502 | + |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1506 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1507 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1508 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1509 | + * which will be returned. |
|
1510 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1511 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1512 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1513 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1514 | + * Etc |
|
1515 | + * |
|
1516 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1517 | + * @return EE_Form_Section_Base |
|
1518 | + * @throws EE_Error |
|
1519 | + */ |
|
1520 | + public function find_section_from_path($form_section_path) |
|
1521 | + { |
|
1522 | + // check if we can find the input from purely going straight up the tree |
|
1523 | + $input = parent::find_section_from_path($form_section_path); |
|
1524 | + if ($input instanceof EE_Form_Section_Base) { |
|
1525 | + return $input; |
|
1526 | + } |
|
1527 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1528 | + if ($next_slash_pos !== false) { |
|
1529 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1530 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1531 | + } else { |
|
1532 | + $child_section_name = $form_section_path; |
|
1533 | + $subpath = ''; |
|
1534 | + } |
|
1535 | + $child_section = $this->get_subsection($child_section_name); |
|
1536 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1537 | + return $child_section->find_section_from_path($subpath); |
|
1538 | + } |
|
1539 | + return null; |
|
1540 | + } |
|
1541 | 1541 | } |
@@ -24,70 +24,70 @@ |
||
24 | 24 | class PrivacyPolicyManager |
25 | 25 | { |
26 | 26 | |
27 | - public function __construct() |
|
28 | - { |
|
29 | - add_action('current_screen', array($this, 'addPrivacyPolicy'), 9); |
|
30 | - } |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + add_action('current_screen', array($this, 'addPrivacyPolicy'), 9); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * For all the registered `PrivacyPolicyInterface`s, add their privacy policy content |
|
35 | - * |
|
36 | - * @param WP_Screen $screen |
|
37 | - * @throws InvalidClassException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidEntityException |
|
40 | - * @throws InvalidFilePathException |
|
41 | - * @throws InvalidIdentifierException |
|
42 | - * @throws InvalidInterfaceException |
|
43 | - */ |
|
44 | - public function addPrivacyPolicy(WP_Screen $screen) |
|
45 | - { |
|
46 | - if ($screen instanceof WP_Screen |
|
47 | - && $screen->id === 'tools' |
|
48 | - && isset($_GET['wp-privacy-policy-guide'])) { |
|
49 | - // load all the privacy policy stuff |
|
50 | - // add post policy text |
|
51 | - foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) { |
|
52 | - wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent()); |
|
53 | - } |
|
54 | - } |
|
55 | - } |
|
33 | + /** |
|
34 | + * For all the registered `PrivacyPolicyInterface`s, add their privacy policy content |
|
35 | + * |
|
36 | + * @param WP_Screen $screen |
|
37 | + * @throws InvalidClassException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidEntityException |
|
40 | + * @throws InvalidFilePathException |
|
41 | + * @throws InvalidIdentifierException |
|
42 | + * @throws InvalidInterfaceException |
|
43 | + */ |
|
44 | + public function addPrivacyPolicy(WP_Screen $screen) |
|
45 | + { |
|
46 | + if ($screen instanceof WP_Screen |
|
47 | + && $screen->id === 'tools' |
|
48 | + && isset($_GET['wp-privacy-policy-guide'])) { |
|
49 | + // load all the privacy policy stuff |
|
50 | + // add post policy text |
|
51 | + foreach ($this->loadPrivacyPolicyCollection() as $privacy_policy) { |
|
52 | + wp_add_privacy_policy_content($privacy_policy->getName(), $privacy_policy->getContent()); |
|
53 | + } |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * @return CollectionInterface|PrivacyPolicyInterface[] |
|
60 | - * @throws InvalidIdentifierException |
|
61 | - * @throws InvalidInterfaceException |
|
62 | - * @throws InvalidFilePathException |
|
63 | - * @throws InvalidEntityException |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidClassException |
|
66 | - */ |
|
67 | - protected function loadPrivacyPolicyCollection() |
|
68 | - { |
|
69 | - $loader = new CollectionLoader( |
|
70 | - new CollectionDetails( |
|
71 | - // collection name |
|
72 | - 'privacy_policies', |
|
73 | - // collection interface |
|
74 | - 'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface', |
|
75 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
76 | - apply_filters( |
|
77 | - 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
78 | - array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy') |
|
79 | - ), |
|
80 | - // filepaths to classes to add |
|
81 | - array(), |
|
82 | - // file mask to use if parsing folder for files to add |
|
83 | - '', |
|
84 | - // what to use as identifier for collection entities |
|
85 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
86 | - CollectionDetails::ID_CLASS_NAME |
|
87 | - ) |
|
88 | - ); |
|
89 | - return $loader->getCollection(); |
|
90 | - } |
|
58 | + /** |
|
59 | + * @return CollectionInterface|PrivacyPolicyInterface[] |
|
60 | + * @throws InvalidIdentifierException |
|
61 | + * @throws InvalidInterfaceException |
|
62 | + * @throws InvalidFilePathException |
|
63 | + * @throws InvalidEntityException |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidClassException |
|
66 | + */ |
|
67 | + protected function loadPrivacyPolicyCollection() |
|
68 | + { |
|
69 | + $loader = new CollectionLoader( |
|
70 | + new CollectionDetails( |
|
71 | + // collection name |
|
72 | + 'privacy_policies', |
|
73 | + // collection interface |
|
74 | + 'EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface', |
|
75 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
76 | + apply_filters( |
|
77 | + 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
78 | + array('EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy') |
|
79 | + ), |
|
80 | + // filepaths to classes to add |
|
81 | + array(), |
|
82 | + // file mask to use if parsing folder for files to add |
|
83 | + '', |
|
84 | + // what to use as identifier for collection entities |
|
85 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
86 | + CollectionDetails::ID_CLASS_NAME |
|
87 | + ) |
|
88 | + ); |
|
89 | + return $loader->getCollection(); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | // End of file PrivacyPolicyManager.php |
93 | 93 | // Location: EventEspresso\core\domain\services\admin/PrivacyPolicyManager.php |