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