PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.02
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 +46 -193 6.294.01.02 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 /**
7 4 * @since 2.04
8 5 */
@@ -9,9 +6,8 @@
9 6 class FrmTableHTMLGenerator {
10 7
11 8 /**
12 9 * @var string
13 - *
14 10 * @since 2.04
15 11 */
16 12 private $type = '';
17 13
@@ -16,9 +12,8 @@
16 12 private $type = '';
17 13
18 14 /**
19 15 * @var array
20 - *
21 16 * @since 2.04
22 17 */
23 18 private $style_settings = array();
24 19
@@ -23,9 +18,8 @@
23 18 private $style_settings = array();
24 19
25 20 /**
26 21 * @var bool
27 - *
28 22 * @since 2.04
29 23 */
30 24 private $use_inline_style = true;
31 25
@@ -30,17 +24,14 @@
30 24 private $use_inline_style = true;
31 25
32 26 /**
33 27 * @var string
34 - *
35 28 * @since 2.04
36 - * @since 5.0.16 Changed scope from `private` to `protected`.
37 29 */
38 - protected $direction = 'ltr';
30 + private $direction = 'ltr';
39 31
40 32 /**
41 33 * @var bool
42 - *
43 34 * @since 2.04
44 35 */
45 36 private $odd = true;
46 37
@@ -45,66 +36,27 @@
45 36 private $odd = true;
46 37
47 38 /**
48 39 * @var string
49 - *
50 40 * @since 2.04
51 - * @since 5.0.16 Changed scope from `private` to `protected`.
52 41 */
53 - protected $table_style = '';
42 + private $table_style = '';
54 43
55 44 /**
56 45 * @var string
57 - *
58 46 * @since 2.04
59 - * @since 5.0.16 Changed scope from `private` to `protected`.
60 47 */
61 - protected $td_style = '';
48 + private $td_style = '';
62 49
63 50 /**
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 51 * FrmTableHTMLGenerator constructor.
92 52 *
93 53 * @param string $type
94 - * @param array $atts
54 + * @param array $atts
95 55 */
96 56 public function __construct( $type, $atts = array() ) {
97 - $this->type = $type;
98 57
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 -
58 + $this->type = (string) $type;
107 59 $this->init_style_settings( $atts );
108 60 $this->init_use_inline_style( $atts );
109 61 $this->init_direction( $atts );
110 62 $this->init_table_style();
@@ -116,10 +68,8 @@
116 68 *
117 69 * @since 2.04
118 70 *
119 71 * @param array $atts
120 - *
121 - * @return void
122 72 */
123 73 private function init_style_settings( $atts ) {
124 74 $style_settings = array(
125 75 'border_color' => 'dddddd',
@@ -140,9 +90,9 @@
140 90 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
141 91 }
142 92 }
143 93
144 - $this->style_settings['class'] = $atts['class'] ?? '';
94 + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : '';
145 95 }
146 96
147 97 /**
148 98 * Set the use_inline_style property
@@ -149,10 +99,8 @@
149 99 *
150 100 * @since 2.04
151 101 *
152 102 * @param array $atts
153 - *
154 - * @return void
155 103 */
156 104 private function init_use_inline_style( $atts ) {
157 105 if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) {
158 106 $this->use_inline_style = false;
@@ -164,10 +112,8 @@
164 112 *
165 113 * @since 2.04
166 114 *
167 115 * @param array $atts
168 - *
169 - * @return void
170 116 */
171 117 private function init_direction( $atts ) {
172 118 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
173 119 $this->direction = 'rtl';
@@ -177,24 +123,20 @@
177 123 /**
178 124 * Set the table_style property
179 125 *
180 126 * @since 2.04
181 - *
182 - * @return void
183 127 */
184 128 private function init_table_style() {
185 129 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%;' );
130 +
131 + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
187 132 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
133 +
188 134 }
189 135
190 136 if ( ! empty( $this->style_settings['class'] ) ) {
191 137 $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
192 138 }
193 -
194 - if ( $this->width ) {
195 - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"';
196 - }
197 139 }
198 140
199 141 /**
200 142 * Set the td_style property
@@ -199,72 +141,48 @@
199 141 /**
200 142 * Set the td_style property
201 143 *
202 144 * @since 2.04
203 - *
204 - * @return void
205 145 */
206 146 private function init_td_style() {
207 - if ( $this->use_inline_style !== true ) {
208 - return;
209 - }
147 + if ( $this->use_inline_style === true ) {
210 148
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'] . ';';
149 + $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';';
150 + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;';
151 + $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
214 152
215 - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"';
153 + $this->td_style = ' style="' . $td_style_attributes . '"';
154 + }
216 155 }
217 156
218 157 /**
219 - * Removes border CSS from HTML.
158 + * Determine if setting is for a color, e.g. text color, background color, or border color
220 159 *
221 - * @since 6.25
160 + * @param string $setting_key name of setting
222 161 *
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 162 * @since 2.05
243 163 *
244 - * @param string $setting_key Name of setting.
245 - *
246 - * @return bool
164 + * @return boolean
247 165 */
248 166 private function is_color_setting( $setting_key ) {
249 - return str_contains( $setting_key, 'color' );
167 + return strpos( $setting_key, 'color' ) !== false;
250 168 }
251 169
252 170 /**
253 171 * Get color markup from color setting value
254 172 *
173 + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
174 + *
255 175 * @since 2.05
256 176 *
257 - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
258 - *
259 177 * @return string
260 178 */
261 179 private function get_color_markup( $color_markup ) {
262 180 $color_markup = trim( $color_markup );
263 181
264 - // Check if each character in string is valid hex digit
265 - if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) {
266 - return '#' . $color_markup;
182 + //check if each character in string is valid hex digit
183 + if ( ctype_xdigit( $color_markup ) ) {
184 + $color_markup = '#' . $color_markup;
267 185 }
268 186
269 187 return $color_markup;
270 188 }
@@ -276,9 +194,9 @@
276 194 *
277 195 * @return string
278 196 */
279 197 private function table_row_background_color() {
280 - return $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'];
198 + return ( $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'] );
281 199 }
282 200
283 201 /**
284 202 * Get the table row style
@@ -283,14 +201,13 @@
283 201 /**
284 202 * Get the table row style
285 203 *
286 204 * @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 205 *
290 206 * @return string
291 207 */
292 - public function tr_style() {
208 + private function tr_style() {
209 +
293 210 if ( $this->type === 'shortcode' ) {
294 211 $tr_style = ' style="[frm-alt-color]"';
295 212 } elseif ( $this->use_inline_style ) {
296 213 $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
@@ -301,38 +218,13 @@
301 218 return $tr_style;
302 219 }
303 220
304 221 /**
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 222 * Switch the odd property from true to false or false to true
328 223 *
329 224 * @since 2.04
330 - * @since 5.0.16 Changed scope from `private` to `protected`.
331 - *
332 - * @return void
333 225 */
334 - protected function switch_odd() {
226 + private function switch_odd() {
335 227 if ( $this->type !== 'shortcode' ) {
336 228 $this->odd = ! $this->odd;
337 229 }
338 230 }
@@ -344,9 +236,9 @@
344 236 *
345 237 * @return string
346 238 */
347 239 public function generate_table_header() {
348 - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
240 + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n";
349 241 }
350 242
351 243 /**
352 244 * Generate a table footer
@@ -363,29 +255,31 @@
363 255 * Generate a two cell row for an HTML table
364 256 *
365 257 * @since 2.04
366 258 *
367 - * @param string $label The label.
368 - * @param string $value The value.
369 - * @param array $args Additional arguments. May include "field_type" string.
259 + * @param string $label
260 + * @param string $value
370 261 *
371 262 * @return string
372 263 */
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>';
264 + public function generate_two_cell_table_row( $label, $value ) {
265 + $row = '<tr' . $this->tr_style();
266 + if ( $value === '' ) {
267 + $row .= ' class="frm-empty-row"';
268 + }
269 + $row .= '>';
379 270
380 - if ( 'rtl' === $this->direction ) {
381 - $row .= $value;
382 - $row .= $label;
271 + if ( 'rtl' == $this->direction ) {
272 + $first = $value;
273 + $second = $label;
383 274 } else {
384 - $row .= $label;
385 - $row .= $value;
275 + $first = $label;
276 + $second = $value;
386 277 }
387 278
279 + $row .= '<td' . $this->td_style . '>' . $first . '</td>';
280 + $row .= '<td' . $this->td_style . '>' . $second . '</td>';
281 +
388 282 $row .= '</tr>' . "\r\n";
389 283
390 284 $this->switch_odd();
391 285
@@ -392,23 +286,8 @@
392 286 return $row;
393 287 }
394 288
395 289 /**
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 290 * Generate a single cell row for an HTML table
412 291 *
413 292 * @since 2.04
414 293 *
@@ -416,11 +295,9 @@
416 295 *
417 296 * @return string
418 297 */
419 298 public function generate_single_cell_table_row( $value ) {
420 - $row = '<tr' . $this->tr_style();
421 - $row .= $this->add_row_class();
422 - $row .= '>';
299 + $row = '<tr' . $this->tr_style() . '>';
423 300 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
424 301 $row .= '</tr>' . "\r\n";
425 302
426 303 $this->switch_odd();
@@ -425,30 +302,6 @@
425 302
426 303 $this->switch_odd();
427 304
428 305 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 306 }
454 307 }