PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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 +34 -195 6.263.06.06 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,71 +36,34 @@
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 - /**
64 - * Cell padding.
65 - *
66 - * @since 6.25
67 - *
68 - * @var string
69 - */
70 - protected $cell_padding = '7px 9px';
71 50
72 51 /**
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 52 * FrmTableHTMLGenerator constructor.
92 53 *
93 54 * @param string $type
94 - * @param array $atts
55 + * @param array $atts
95 56 */
96 57 public function __construct( $type, $atts = array() ) {
97 - $this->type = $type;
98 58
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 -
59 + $this->type = (string) $type;
107 60 $this->init_style_settings( $atts );
108 61 $this->init_use_inline_style( $atts );
109 62 $this->init_direction( $atts );
110 63 $this->init_table_style();
111 64 $this->init_td_style();
65 +
112 66 }
113 67
114 68 /**
115 69 * Set the style_settings property
@@ -116,13 +70,11 @@
116 70 *
117 71 * @since 2.04
118 72 *
119 73 * @param array $atts
120 - *
121 - * @return void
122 74 */
123 75 private function init_style_settings( $atts ) {
124 - $style_settings = array(
76 + $style_settings = array(
125 77 'border_color' => 'dddddd',
126 78 'bg_color' => 'f7f7f7',
127 79 'text_color' => '444444',
128 80 'font_size' => '12px',
@@ -139,10 +91,8 @@
139 91 if ( $this->is_color_setting( $key ) ) {
140 92 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
141 93 }
142 94 }
143 -
144 - $this->style_settings['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,26 +123,16 @@
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 130
187 - $this->table_style = ' style="' . esc_attr( 'border-spacing:0;font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
131 + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' );
188 132 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
189 133
190 134 }
191 -
192 - if ( ! empty( $this->style_settings['class'] ) ) {
193 - $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
194 - }
195 -
196 - if ( ! empty( $this->width ) ) {
197 - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"';
198 - }
199 135 }
200 136
201 137 /**
202 138 * Set the td_style property
@@ -201,51 +137,28 @@
201 137 /**
202 138 * Set the td_style property
203 139 *
204 140 * @since 2.04
205 - *
206 - * @return void
207 141 */
208 142 private function init_td_style() {
209 143 if ( $this->use_inline_style === true ) {
210 144
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;';
145 + $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';';
146 + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;';
213 147 $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
214 148
215 - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"';
149 + $this->td_style = ' style="' . $td_style_attributes . '"';
216 150 }
217 151 }
218 152
219 153 /**
220 - * Removes border CSS from HTML.
154 + * Determine if setting is for a color, e.g. text color, background color, or border color
221 155 *
222 - * @since 6.25
156 + * @param string $setting_key name of setting
223 157 *
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 158 * @since 2.05
244 159 *
245 - * @param string $setting_key Name of setting.
246 - *
247 - * @return bool
160 + * @return boolean
248 161 */
249 162 private function is_color_setting( $setting_key ) {
250 163 return strpos( $setting_key, 'color' ) !== false;
251 164 }
@@ -252,19 +165,19 @@
252 165
253 166 /**
254 167 * Get color markup from color setting value
255 168 *
169 + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
170 + *
256 171 * @since 2.05
257 172 *
258 - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
259 - *
260 173 * @return string
261 174 */
262 175 private function get_color_markup( $color_markup ) {
263 176 $color_markup = trim( $color_markup );
264 177
265 - // Check if each character in string is valid hex digit
266 - if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) {
178 + //check if each character in string is valid hex digit
179 + if ( ctype_xdigit( $color_markup ) ) {
267 180 $color_markup = '#' . $color_markup;
268 181 }
269 182
270 183 return $color_markup;
@@ -284,18 +197,16 @@
284 197 /**
285 198 * Get the table row style
286 199 *
287 200 * @since 2.04
288 - * @since 5.0.16 Changed scope from `private` to `protected`.
289 - * @since 6.25 Changed scope from `protected` to `public`.
290 201 *
291 202 * @return string
292 203 */
293 - public function tr_style() {
204 + private function tr_style() {
294 205
295 206 if ( $this->type === 'shortcode' ) {
296 207 $tr_style = ' style="[frm-alt-color]"';
297 - } elseif ( $this->use_inline_style ) {
208 + } else if ( $this->use_inline_style ) {
298 209 $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"';
299 210 } else {
300 211 $tr_style = '';
301 212 }
@@ -303,38 +214,13 @@
303 214 return $tr_style;
304 215 }
305 216
306 217 /**
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 218 * Switch the odd property from true to false or false to true
330 219 *
331 220 * @since 2.04
332 - * @since 5.0.16 Changed scope from `private` to `protected`.
333 - *
334 - * @return void
335 221 */
336 - protected function switch_odd() {
222 + private function switch_odd() {
337 223 if ( $this->type !== 'shortcode' ) {
338 224 $this->odd = ! $this->odd;
339 225 }
340 226 }
@@ -346,9 +232,9 @@
346 232 *
347 233 * @return string
348 234 */
349 235 public function generate_table_header() {
350 - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
236 + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n";
351 237 }
352 238
353 239 /**
354 240 * Generate a table footer
@@ -365,30 +251,27 @@
365 251 * Generate a two cell row for an HTML table
366 252 *
367 253 * @since 2.04
368 254 *
369 - * @param string $label The label.
370 - * @param string $value The value.
371 - * @param array $args Additional arguments. May include "field_type" string.
255 + * @param string $label
256 + * @param string $value
372 257 *
373 258 * @return string
374 259 */
375 - public function generate_two_cell_table_row( $label, $value, $args = array() ) {
376 - $row = '<tr' . $this->tr_style();
377 - $row .= $this->add_row_class( $value === '' );
378 - $row .= '>';
260 + public function generate_two_cell_table_row( $label, $value ) {
261 + $row = '<tr' . $this->tr_style() . '>';
379 262
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>';
382 -
383 263 if ( 'rtl' == $this->direction ) {
384 - $row .= $value;
385 - $row .= $label;
264 + $first = $value;
265 + $second = $label;
386 266 } else {
387 - $row .= $label;
388 - $row .= $value;
267 + $first = $label;
268 + $second = $value;
389 269 }
390 270
271 + $row .= '<td' . $this->td_style . '>' . $first . '</td>';
272 + $row .= '<td' . $this->td_style . '>' . $second . '</td>';
273 +
391 274 $row .= '</tr>' . "\r\n";
392 275
393 276 $this->switch_odd();
394 277
@@ -395,23 +278,8 @@
395 278 return $row;
396 279 }
397 280
398 281 /**
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 282 * Generate a single cell row for an HTML table
415 283 *
416 284 * @since 2.04
417 285 *
@@ -419,11 +287,9 @@
419 287 *
420 288 * @return string
421 289 */
422 290 public function generate_single_cell_table_row( $value ) {
423 - $row = '<tr' . $this->tr_style();
424 - $row .= $this->add_row_class();
425 - $row .= '>';
291 + $row = '<tr' . $this->tr_style() . '>';
426 292 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
427 293 $row .= '</tr>' . "\r\n";
428 294
429 295 $this->switch_odd();
@@ -428,33 +294,6 @@
428 294
429 295 $this->switch_odd();
430 296
431 297 return $row;
432 - }
433 -
434 - /**
435 - * Add classes to the tr.
436 - *
437 - * @since 5.4.2
438 - *
439 - * @param bool $empty If the value in the row is blank.
440 - *
441 - * @return string
442 - */
443 - protected function add_row_class( $empty = false ) {
444 - $class = '';
445 -
446 - if ( $empty ) {
447 - // Only add this class on two cell rows.
448 - $class .= ' frm-empty-row';
449 - }
450 -
451 - if ( $this->is_child ) {
452 - $class .= ' frm-child-row';
453 - }
454 -
455 - if ( $class ) {
456 - $class = ' class="' . trim( $class ) . '"';
457 - }
458 - return $class;
459 298 }
460 299 }