PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +19 -135 6.266.0 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,30 +53,11 @@
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 57 * Used to add a class in tables. Set in Pro.
83 58 *
84 59 * @var bool
85 - *
86 60 * @since 5.4.2
87 61 */
88 62 public $is_child = false;
89 63
@@ -90,21 +64,13 @@
90 64 /**
91 65 * FrmTableHTMLGenerator constructor.
92 66 *
93 67 * @param string $type
94 - * @param array $atts
68 + * @param array $atts
95 69 */
96 70 public function __construct( $type, $atts = array() ) {
97 - $this->type = $type;
98 71
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 -
72 + $this->type = (string) $type;
107 73 $this->init_style_settings( $atts );
108 74 $this->init_use_inline_style( $atts );
109 75 $this->init_direction( $atts );
110 76 $this->init_table_style();
@@ -116,10 +82,8 @@
116 82 *
117 83 * @since 2.04
118 84 *
119 85 * @param array $atts
120 - *
121 - * @return void
122 86 */
123 87 private function init_style_settings( $atts ) {
124 88 $style_settings = array(
125 89 'border_color' => 'dddddd',
@@ -140,9 +104,9 @@
140 104 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
141 105 }
142 106 }
143 107
144 - $this->style_settings['class'] = $atts['class'] ?? '';
108 + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : '';
145 109 }
146 110
147 111 /**
148 112 * Set the use_inline_style property
@@ -149,10 +113,8 @@
149 113 *
150 114 * @since 2.04
151 115 *
152 116 * @param array $atts
153 - *
154 - * @return void
155 117 */
156 118 private function init_use_inline_style( $atts ) {
157 119 if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) {
158 120 $this->use_inline_style = false;
@@ -164,10 +126,8 @@
164 126 *
165 127 * @since 2.04
166 128 *
167 129 * @param array $atts
168 - *
169 - * @return void
170 130 */
171 131 private function init_direction( $atts ) {
172 132 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
173 133 $this->direction = 'rtl';
@@ -177,15 +137,13 @@
177 137 /**
178 138 * Set the table_style property
179 139 *
180 140 * @since 2.04
181 - *
182 - * @return void
183 141 */
184 142 private function init_table_style() {
185 143 if ( $this->use_inline_style === true ) {
186 144
187 - $this->table_style = ' style="' . esc_attr( 'border-spacing:0;font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
145 + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
188 146 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
189 147
190 148 }
191 149
@@ -191,12 +149,8 @@
191 149
192 150 if ( ! empty( $this->style_settings['class'] ) ) {
193 151 $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
194 152 }
195 -
196 - if ( ! empty( $this->width ) ) {
197 - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"';
198 - }
199 153 }
200 154
201 155 /**
202 156 * Set the td_style property
@@ -201,51 +155,28 @@
201 155 /**
202 156 * Set the td_style property
203 157 *
204 158 * @since 2.04
205 - *
206 - * @return void
207 159 */
208 160 private function init_td_style() {
209 161 if ( $this->use_inline_style === true ) {
210 162
211 - $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';';
212 - $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;';
163 + $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';';
164 + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;';
213 165 $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
214 166
215 - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"';
167 + $this->td_style = ' style="' . $td_style_attributes . '"';
216 168 }
217 169 }
218 170
219 171 /**
220 - * Removes border CSS from HTML.
172 + * Determine if setting is for a color, e.g. text color, background color, or border color
221 173 *
222 - * @since 6.25
174 + * @param string $setting_key name of setting
223 175 *
224 - * @param string $html The HTML.
225 - * @param string $position The border position. Default is `top`.
226 - *
227 - * @return string
228 - */
229 - public function remove_border( $html, $position = 'top' ) {
230 - $search = sprintf(
231 - 'border-%1$s:%2$s solid %3$s;',
232 - $position,
233 - $this->style_settings['border_width'],
234 - $this->style_settings['border_color']
235 - );
236 -
237 - return str_replace( $search, '', $html );
238 - }
239 -
240 - /**
241 - * Determine if setting is for a color, e.g. text color, background color, or border color
242 - *
243 176 * @since 2.05
244 177 *
245 - * @param string $setting_key Name of setting.
246 - *
247 - * @return bool
178 + * @return boolean
248 179 */
249 180 private function is_color_setting( $setting_key ) {
250 181 return strpos( $setting_key, 'color' ) !== false;
251 182 }
@@ -252,12 +183,12 @@
252 183
253 184 /**
254 185 * Get color markup from color setting value
255 186 *
187 + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
188 + *
256 189 * @since 2.05
257 190 *
258 - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
259 - *
260 191 * @return string
261 192 */
262 193 private function get_color_markup( $color_markup ) {
263 194 $color_markup = trim( $color_markup );
@@ -285,13 +216,12 @@
285 216 * Get the table row style
286 217 *
287 218 * @since 2.04
288 219 * @since 5.0.16 Changed scope from `private` to `protected`.
289 - * @since 6.25 Changed scope from `protected` to `public`.
290 220 *
291 221 * @return string
292 222 */
293 - public function tr_style() {
223 + protected function tr_style() {
294 224
295 225 if ( $this->type === 'shortcode' ) {
296 226 $tr_style = ' style="[frm-alt-color]"';
297 227 } elseif ( $this->use_inline_style ) {
@@ -303,36 +233,12 @@
303 233 return $tr_style;
304 234 }
305 235
306 236 /**
307 - * Gets table style.
308 - *
309 - * @since 6.25
310 - *
311 - * @return string
312 - */
313 - public function get_table_style() {
314 - return $this->table_style;
315 - }
316 -
317 - /**
318 - * Gets td style.
319 - *
320 - * @since 6.25
321 - *
322 - * @return string
323 - */
324 - public function get_td_style() {
325 - return $this->td_style;
326 - }
327 -
328 - /**
329 237 * Switch the odd property from true to false or false to true
330 238 *
331 239 * @since 2.04
332 240 * @since 5.0.16 Changed scope from `private` to `protected`.
333 - *
334 - * @return void
335 241 */
336 242 protected function switch_odd() {
337 243 if ( $this->type !== 'shortcode' ) {
338 244 $this->odd = ! $this->odd;
@@ -346,9 +252,9 @@
346 252 *
347 253 * @return string
348 254 */
349 255 public function generate_table_header() {
350 - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
256 + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n";
351 257 }
352 258
353 259 /**
354 260 * Generate a table footer
@@ -367,19 +273,18 @@
367 273 * @since 2.04
368 274 *
369 275 * @param string $label The label.
370 276 * @param string $value The value.
371 - * @param array $args Additional arguments. May include "field_type" string.
372 277 *
373 278 * @return string
374 279 */
375 - public function generate_two_cell_table_row( $label, $value, $args = array() ) {
376 - $row = '<tr' . $this->tr_style();
280 + public function generate_two_cell_table_row( $label, $value ) {
281 + $row = '<tr' . $this->tr_style();
377 282 $row .= $this->add_row_class( $value === '' );
378 283 $row .= '>';
379 284
380 - $label = '<th scope="row"' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>';
381 - $value = '<td' . $this->td_style . '>' . $this->filter_value_for_display( $value, $args ) . '</td>';
285 + $label = '<th' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>';
286 + $value = '<td' . $this->td_style . '>' . wp_kses_post( $value ) . '</td>';
382 287
383 288 if ( 'rtl' == $this->direction ) {
384 289 $row .= $value;
385 290 $row .= $label;
@@ -395,23 +300,8 @@
395 300 return $row;
396 301 }
397 302
398 303 /**
399 - * @param string $value
400 - * @param array $args
401 - *
402 - * @return string
403 - */
404 - private function filter_value_for_display( $value, $args ) {
405 - if ( empty( $args['field_type'] ) ) {
406 - return wp_kses_post( $value );
407 - }
408 -
409 - $field_object = FrmFieldFactory::get_field_type( $args['field_type'] );
410 - return $field_object->filter_value_for_table_html( $value );
411 - }
412 -
413 - /**
414 304 * Generate a single cell row for an HTML table
415 305 *
416 306 * @since 2.04
417 307 *
@@ -419,9 +309,9 @@
419 309 *
420 310 * @return string
421 311 */
422 312 public function generate_single_cell_table_row( $value ) {
423 - $row = '<tr' . $this->tr_style();
313 + $row = '<tr' . $this->tr_style();
424 314 $row .= $this->add_row_class();
425 315 $row .= '>';
426 316 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
427 317 $row .= '</tr>' . "\r\n";
@@ -434,25 +324,19 @@
434 324 /**
435 325 * Add classes to the tr.
436 326 *
437 327 * @since 5.4.2
438 - *
439 328 * @param bool $empty If the value in the row is blank.
440 - *
441 - * @return string
442 329 */
443 330 protected function add_row_class( $empty = false ) {
444 331 $class = '';
445 -
446 332 if ( $empty ) {
447 333 // Only add this class on two cell rows.
448 334 $class .= ' frm-empty-row';
449 335 }
450 -
451 336 if ( $this->is_child ) {
452 337 $class .= ' frm-child-row';
453 338 }
454 -
455 339 if ( $class ) {
456 340 $class = ' class="' . trim( $class ) . '"';
457 341 }
458 342 return $class;