PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.04
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.04
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmTableHTMLGenerator.php +32 -169 6.285.2.04 View file →
@@ -9,9 +9,8 @@
9 9 class FrmTableHTMLGenerator {
10 10
11 11 /**
12 12 * @var string
13 - *
14 13 * @since 2.04
15 14 */
16 15 private $type = '';
17 16
@@ -16,9 +15,8 @@
16 15 private $type = '';
17 16
18 17 /**
19 18 * @var array
20 - *
21 19 * @since 2.04
22 20 */
23 21 private $style_settings = array();
24 22
@@ -23,9 +21,8 @@
23 21 private $style_settings = array();
24 22
25 23 /**
26 24 * @var bool
27 - *
28 25 * @since 2.04
29 26 */
30 27 private $use_inline_style = true;
31 28
@@ -30,9 +27,8 @@
30 27 private $use_inline_style = true;
31 28
32 29 /**
33 30 * @var string
34 - *
35 31 * @since 2.04
36 32 * @since 5.0.16 Changed scope from `private` to `protected`.
37 33 */
38 34 protected $direction = 'ltr';
@@ -38,9 +34,8 @@
38 34 protected $direction = 'ltr';
39 35
40 36 /**
41 37 * @var bool
42 - *
43 38 * @since 2.04
44 39 */
45 40 private $odd = true;
46 41
@@ -45,9 +40,8 @@
45 40 private $odd = true;
46 41
47 42 /**
48 43 * @var string
49 - *
50 44 * @since 2.04
51 45 * @since 5.0.16 Changed scope from `private` to `protected`.
52 46 */
53 47 protected $table_style = '';
@@ -53,9 +47,8 @@
53 47 protected $table_style = '';
54 48
55 49 /**
56 50 * @var string
57 - *
58 51 * @since 2.04
59 52 * @since 5.0.16 Changed scope from `private` to `protected`.
60 53 */
61 54 protected $td_style = '';
@@ -60,51 +53,16 @@
60 53 */
61 54 protected $td_style = '';
62 55
63 56 /**
64 - * Cell padding.
65 - *
66 - * @since 6.25
67 - *
68 - * @var string
69 - */
70 - protected $cell_padding = '7px 9px';
71 -
72 - /**
73 - * Table width.
74 - *
75 - * @since 6.25
76 - *
77 - * @var string
78 - */
79 - protected $width = '';
80 -
81 - /**
82 - * Used to add a class in tables. Set in Pro.
83 - *
84 - * @var bool
85 - *
86 - * @since 5.4.2
87 - */
88 - public $is_child = false;
89 -
90 - /**
91 57 * FrmTableHTMLGenerator constructor.
92 58 *
93 59 * @param string $type
94 - * @param array $atts
60 + * @param array $atts
95 61 */
96 62 public function __construct( $type, $atts = array() ) {
97 - $this->type = $type;
98 63
99 - if ( isset( $atts['cell_padding'] ) ) {
100 - $this->cell_padding = $atts['cell_padding'];
101 - }
102 -
103 - if ( isset( $atts['width'] ) ) {
104 - $this->width = $atts['width'];
105 - }
106 -
64 + $this->type = (string) $type;
107 65 $this->init_style_settings( $atts );
108 66 $this->init_use_inline_style( $atts );
109 67 $this->init_direction( $atts );
110 68 $this->init_table_style();
@@ -116,10 +74,8 @@
116 74 *
117 75 * @since 2.04
118 76 *
119 77 * @param array $atts
120 - *
121 - * @return void
122 78 */
123 79 private function init_style_settings( $atts ) {
124 80 $style_settings = array(
125 81 'border_color' => 'dddddd',
@@ -140,9 +96,9 @@
140 96 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
141 97 }
142 98 }
143 99
144 - $this->style_settings['class'] = $atts['class'] ?? '';
100 + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : '';
145 101 }
146 102
147 103 /**
148 104 * Set the use_inline_style property
@@ -149,10 +105,8 @@
149 105 *
150 106 * @since 2.04
151 107 *
152 108 * @param array $atts
153 - *
154 - * @return void
155 109 */
156 110 private function init_use_inline_style( $atts ) {
157 111 if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) {
158 112 $this->use_inline_style = false;
@@ -164,10 +118,8 @@
164 118 *
165 119 * @since 2.04
166 120 *
167 121 * @param array $atts
168 - *
169 - * @return void
170 122 */
171 123 private function init_direction( $atts ) {
172 124 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
173 125 $this->direction = 'rtl';
@@ -177,24 +129,20 @@
177 129 /**
178 130 * Set the table_style property
179 131 *
180 132 * @since 2.04
181 - *
182 - * @return void
183 133 */
184 134 private function init_table_style() {
185 135 if ( $this->use_inline_style === true ) {
186 - $this->table_style = ' style="' . esc_attr( 'border-spacing:0;font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
136 +
137 + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
187 138 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
139 +
188 140 }
189 141
190 142 if ( ! empty( $this->style_settings['class'] ) ) {
191 143 $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
192 144 }
193 -
194 - if ( ! empty( $this->width ) ) {
195 - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"';
196 - }
197 145 }
198 146
199 147 /**
200 148 * Set the td_style property
@@ -199,62 +147,40 @@
199 147 /**
200 148 * Set the td_style property
201 149 *
202 150 * @since 2.04
203 - *
204 - * @return void
205 151 */
206 152 private function init_td_style() {
207 153 if ( $this->use_inline_style === true ) {
208 - $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';';
209 - $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;';
154 +
155 + $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';';
156 + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;';
210 157 $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
211 158
212 - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"';
159 + $this->td_style = ' style="' . $td_style_attributes . '"';
213 160 }
214 161 }
215 162
216 163 /**
217 - * Removes border CSS from HTML.
164 + * Determine if setting is for a color, e.g. text color, background color, or border color
218 165 *
219 - * @since 6.25
166 + * @param string $setting_key name of setting
220 167 *
221 - * @param string $html The HTML.
222 - * @param string $position The border position. Default is `top`.
223 - *
224 - * @return string
225 - */
226 - public function remove_border( $html, $position = 'top' ) {
227 - $search = sprintf(
228 - 'border-%1$s:%2$s solid %3$s;',
229 - $position,
230 - $this->style_settings['border_width'],
231 - $this->style_settings['border_color']
232 - );
233 -
234 - return str_replace( $search, '', $html );
235 - }
236 -
237 - /**
238 - * Determine if setting is for a color, e.g. text color, background color, or border color
239 - *
240 168 * @since 2.05
241 169 *
242 - * @param string $setting_key Name of setting.
243 - *
244 - * @return bool
170 + * @return boolean
245 171 */
246 172 private function is_color_setting( $setting_key ) {
247 - return str_contains( $setting_key, 'color' );
173 + return strpos( $setting_key, 'color' ) !== false;
248 174 }
249 175
250 176 /**
251 177 * Get color markup from color setting value
252 178 *
179 + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
180 + *
253 181 * @since 2.05
254 182 *
255 - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
256 - *
257 183 * @return string
258 184 */
259 185 private function get_color_markup( $color_markup ) {
260 186 $color_markup = trim( $color_markup );
@@ -260,9 +186,9 @@
260 186 $color_markup = trim( $color_markup );
261 187
262 188 // Check if each character in string is valid hex digit
263 189 if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) {
264 - return '#' . $color_markup;
190 + $color_markup = '#' . $color_markup;
265 191 }
266 192
267 193 return $color_markup;
268 194 }
@@ -274,9 +200,9 @@
274 200 *
275 201 * @return string
276 202 */
277 203 private function table_row_background_color() {
278 - return $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'];
204 + return ( $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'] );
279 205 }
280 206
281 207 /**
282 208 * Get the table row style
@@ -282,13 +208,13 @@
282 208 * Get the table row style
283 209 *
284 210 * @since 2.04
285 211 * @since 5.0.16 Changed scope from `private` to `protected`.
286 - * @since 6.25 Changed scope from `protected` to `public`.
287 212 *
288 213 * @return string
289 214 */
290 - public function tr_style() {
215 + protected function tr_style() {
216 +
291 217 if ( $this->type === 'shortcode' ) {
292 218 $tr_style = ' style="[frm-alt-color]"';
293 219 } elseif ( $this->use_inline_style ) {
294 220 $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
@@ -299,36 +225,12 @@
299 225 return $tr_style;
300 226 }
301 227
302 228 /**
303 - * Gets table style.
304 - *
305 - * @since 6.25
306 - *
307 - * @return string
308 - */
309 - public function get_table_style() {
310 - return $this->table_style;
311 - }
312 -
313 - /**
314 - * Gets td style.
315 - *
316 - * @since 6.25
317 - *
318 - * @return string
319 - */
320 - public function get_td_style() {
321 - return $this->td_style;
322 - }
323 -
324 - /**
325 229 * Switch the odd property from true to false or false to true
326 230 *
327 231 * @since 2.04
328 232 * @since 5.0.16 Changed scope from `private` to `protected`.
329 - *
330 - * @return void
331 233 */
332 234 protected function switch_odd() {
333 235 if ( $this->type !== 'shortcode' ) {
334 236 $this->odd = ! $this->odd;
@@ -342,9 +244,9 @@
342 244 *
343 245 * @return string
344 246 */
345 247 public function generate_table_header() {
346 - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
248 + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n";
347 249 }
348 250
349 251 /**
350 252 * Generate a table footer
@@ -363,20 +265,22 @@
363 265 * @since 2.04
364 266 *
365 267 * @param string $label The label.
366 268 * @param string $value The value.
367 - * @param array $args Additional arguments. May include "field_type" string.
368 269 *
369 270 * @return string
370 271 */
371 - public function generate_two_cell_table_row( $label, $value, $args = array() ) {
372 - $row = '<tr' . $this->tr_style();
373 - $row .= $this->add_row_class( $value === '' );
374 - $row .= '>';
375 - $label = '<th scope="row"' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>';
376 - $value = '<td' . $this->td_style . '>' . $this->filter_value_for_display( $value, $args ) . '</td>';
272 + public function generate_two_cell_table_row( $label, $value ) {
273 + $row = '<tr' . $this->tr_style();
274 + if ( $value === '' ) {
275 + $row .= ' class="frm-empty-row"';
276 + }
277 + $row .= '>';
377 278
378 - if ( 'rtl' === $this->direction ) {
279 + $label = '<th' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>';
280 + $value = '<td' . $this->td_style . '>' . wp_kses_post( $value ) . '</td>';
281 +
282 + if ( 'rtl' == $this->direction ) {
379 283 $row .= $value;
380 284 $row .= $label;
381 285 } else {
382 286 $row .= $label;
@@ -390,23 +294,8 @@
390 294 return $row;
391 295 }
392 296
393 297 /**
394 - * @param string $value
395 - * @param array $args
396 - *
397 - * @return string
398 - */
399 - private function filter_value_for_display( $value, $args ) {
400 - if ( empty( $args['field_type'] ) ) {
401 - return wp_kses_post( $value );
402 - }
403 -
404 - $field_object = FrmFieldFactory::get_field_type( $args['field_type'] );
405 - return $field_object->filter_value_for_table_html( $value );
406 - }
407 -
408 - /**
409 298 * Generate a single cell row for an HTML table
410 299 *
411 300 * @since 2.04
412 301 *
@@ -414,11 +303,9 @@
414 303 *
415 304 * @return string
416 305 */
417 306 public function generate_single_cell_table_row( $value ) {
418 - $row = '<tr' . $this->tr_style();
419 - $row .= $this->add_row_class();
420 - $row .= '>';
307 + $row = '<tr' . $this->tr_style() . '>';
421 308 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
422 309 $row .= '</tr>' . "\r\n";
423 310
424 311 $this->switch_odd();
@@ -423,30 +310,6 @@
423 310
424 311 $this->switch_odd();
425 312
426 313 return $row;
427 - }
428 -
429 - /**
430 - * Add classes to the tr.
431 - *
432 - * @since 5.4.2
433 - *
434 - * @param bool $empty If the value in the row is blank.
435 - *
436 - * @return string
437 - */
438 - protected function add_row_class( $empty = false ) {
439 - $class = '';
440 -
441 - if ( $empty ) {
442 - // Only add this class on two cell rows.
443 - $class .= ' frm-empty-row';
444 - }
445 -
446 - if ( $this->is_child ) {
447 - $class .= ' frm-child-row';
448 - }
449 -
450 - return $class ? ' class="' . trim( $class ) . '"' : $class;
451 314 }
452 315 }