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 +33 -152 6.254.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 */
@@ -28,11 +25,10 @@
28 25
29 26 /**
30 27 * @var string
31 28 * @since 2.04
32 - * @since 5.0.16 Changed scope from `private` to `protected`.
33 29 */
34 - protected $direction = 'ltr';
30 + private $direction = 'ltr';
35 31
36 32 /**
37 33 * @var bool
38 34 * @since 2.04
@@ -41,63 +37,26 @@
41 37
42 38 /**
43 39 * @var string
44 40 * @since 2.04
45 - * @since 5.0.16 Changed scope from `private` to `protected`.
46 41 */
47 - protected $table_style = '';
42 + private $table_style = '';
48 43
49 44 /**
50 45 * @var string
51 46 * @since 2.04
52 - * @since 5.0.16 Changed scope from `private` to `protected`.
53 47 */
54 - protected $td_style = '';
48 + private $td_style = '';
55 49
56 50 /**
57 - * Cell padding.
58 - *
59 - * @since 6.25
60 - *
61 - * @var string
62 - */
63 - protected $cell_padding = '7px 9px';
64 -
65 - /**
66 - * Table width.
67 - *
68 - * @since 6.25
69 - *
70 - * @var string
71 - */
72 - protected $width = '';
73 -
74 - /**
75 - * Used to add a class in tables. Set in Pro.
76 - *
77 - * @var bool
78 - * @since 5.4.2
79 - */
80 - public $is_child = false;
81 -
82 - /**
83 51 * FrmTableHTMLGenerator constructor.
84 52 *
85 53 * @param string $type
86 - * @param array $atts
54 + * @param array $atts
87 55 */
88 56 public function __construct( $type, $atts = array() ) {
89 57
90 58 $this->type = (string) $type;
91 -
92 - if ( isset( $atts['cell_padding'] ) ) {
93 - $this->cell_padding = $atts['cell_padding'];
94 - }
95 -
96 - if ( isset( $atts['width'] ) ) {
97 - $this->width = $atts['width'];
98 - }
99 -
100 59 $this->init_style_settings( $atts );
101 60 $this->init_use_inline_style( $atts );
102 61 $this->init_direction( $atts );
103 62 $this->init_table_style();
@@ -109,9 +68,8 @@
109 68 *
110 69 * @since 2.04
111 70 *
112 71 * @param array $atts
113 - * @return void
114 72 */
115 73 private function init_style_settings( $atts ) {
116 74 $style_settings = array(
117 75 'border_color' => 'dddddd',
@@ -132,9 +90,9 @@
132 90 $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] );
133 91 }
134 92 }
135 93
136 - $this->style_settings['class'] = $atts['class'] ?? '';
94 + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : '';
137 95 }
138 96
139 97 /**
140 98 * Set the use_inline_style property
@@ -141,9 +99,8 @@
141 99 *
142 100 * @since 2.04
143 101 *
144 102 * @param array $atts
145 - * @return void
146 103 */
147 104 private function init_use_inline_style( $atts ) {
148 105 if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) {
149 106 $this->use_inline_style = false;
@@ -155,9 +112,8 @@
155 112 *
156 113 * @since 2.04
157 114 *
158 115 * @param array $atts
159 - * @return void
160 116 */
161 117 private function init_direction( $atts ) {
162 118 if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) {
163 119 $this->direction = 'rtl';
@@ -167,14 +123,13 @@
167 123 /**
168 124 * Set the table_style property
169 125 *
170 126 * @since 2.04
171 - * @return void
172 127 */
173 128 private function init_table_style() {
174 129 if ( $this->use_inline_style === true ) {
175 130
176 - $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%;' );
177 132 $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"';
178 133
179 134 }
180 135
@@ -180,12 +135,8 @@
180 135
181 136 if ( ! empty( $this->style_settings['class'] ) ) {
182 137 $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"';
183 138 }
184 -
185 - if ( ! empty( $this->width ) ) {
186 - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"';
187 - }
188 139 }
189 140
190 141 /**
191 142 * Set the td_style property
@@ -190,48 +141,28 @@
190 141 /**
191 142 * Set the td_style property
192 143 *
193 144 * @since 2.04
194 - * @return void
195 145 */
196 146 private function init_td_style() {
197 147 if ( $this->use_inline_style === true ) {
198 148
199 - $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';';
200 - $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;';
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;';
201 151 $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';';
202 152
203 - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"';
153 + $this->td_style = ' style="' . $td_style_attributes . '"';
204 154 }
205 155 }
206 156
207 157 /**
208 - * Removes border CSS from HTML.
158 + * Determine if setting is for a color, e.g. text color, background color, or border color
209 159 *
210 - * @since 6.25
160 + * @param string $setting_key name of setting
211 161 *
212 - * @param string $html The HTML.
213 - * @param string $position The border position. Default is `top`.
214 - * @return string
215 - */
216 - public function remove_border( $html, $position = 'top' ) {
217 - $search = sprintf(
218 - 'border-%1$s:%2$s solid %3$s;',
219 - $position,
220 - $this->style_settings['border_width'],
221 - $this->style_settings['border_color']
222 - );
223 -
224 - return str_replace( $search, '', $html );
225 - }
226 -
227 - /**
228 - * Determine if setting is for a color, e.g. text color, background color, or border color
229 - *
230 162 * @since 2.05
231 - * @param string $setting_key Name of setting.
232 163 *
233 - * @return bool
164 + * @return boolean
234 165 */
235 166 private function is_color_setting( $setting_key ) {
236 167 return strpos( $setting_key, 'color' ) !== false;
237 168 }
@@ -238,10 +169,11 @@
238 169
239 170 /**
240 171 * Get color markup from color setting value
241 172 *
173 + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
174 + *
242 175 * @since 2.05
243 - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white.
244 176 *
245 177 * @return string
246 178 */
247 179 private function get_color_markup( $color_markup ) {
@@ -246,10 +178,10 @@
246 178 */
247 179 private function get_color_markup( $color_markup ) {
248 180 $color_markup = trim( $color_markup );
249 181
250 - // Check if each character in string is valid hex digit
251 - if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) {
182 + //check if each character in string is valid hex digit
183 + if ( ctype_xdigit( $color_markup ) ) {
252 184 $color_markup = '#' . $color_markup;
253 185 }
254 186
255 187 return $color_markup;
@@ -269,14 +201,12 @@
269 201 /**
270 202 * Get the table row style
271 203 *
272 204 * @since 2.04
273 - * @since 5.0.16 Changed scope from `private` to `protected`.
274 - * @since 6.25 Changed scope from `protected` to `public`.
275 205 *
276 206 * @return string
277 207 */
278 - public function tr_style() {
208 + private function tr_style() {
279 209
280 210 if ( $this->type === 'shortcode' ) {
281 211 $tr_style = ' style="[frm-alt-color]"';
282 212 } elseif ( $this->use_inline_style ) {
@@ -288,38 +218,13 @@
288 218 return $tr_style;
289 219 }
290 220
291 221 /**
292 - * Gets table style.
293 - *
294 - * @since 6.25
295 - *
296 - * @return string
297 - */
298 - public function get_table_style() {
299 - return $this->table_style;
300 - }
301 -
302 - /**
303 - * Gets td style.
304 - *
305 - * @since 6.25
306 - *
307 - * @return string
308 - */
309 - public function get_td_style() {
310 - return $this->td_style;
311 - }
312 -
313 - /**
314 222 * Switch the odd property from true to false or false to true
315 223 *
316 224 * @since 2.04
317 - * @since 5.0.16 Changed scope from `private` to `protected`.
318 - *
319 - * @return void
320 225 */
321 - protected function switch_odd() {
226 + private function switch_odd() {
322 227 if ( $this->type !== 'shortcode' ) {
323 228 $this->odd = ! $this->odd;
324 229 }
325 230 }
@@ -331,9 +236,9 @@
331 236 *
332 237 * @return string
333 238 */
334 239 public function generate_table_header() {
335 - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n";
240 + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n";
336 241 }
337 242
338 243 /**
339 244 * Generate a table footer
@@ -350,29 +255,31 @@
350 255 * Generate a two cell row for an HTML table
351 256 *
352 257 * @since 2.04
353 258 *
354 - * @param string $label The label.
355 - * @param string $value The value.
259 + * @param string $label
260 + * @param string $value
356 261 *
357 262 * @return string
358 263 */
359 264 public function generate_two_cell_table_row( $label, $value ) {
360 - $row = '<tr' . $this->tr_style();
361 - $row .= $this->add_row_class( $value === '' );
265 + $row = '<tr' . $this->tr_style();
266 + if ( $value === '' ) {
267 + $row .= ' class="frm-empty-row"';
268 + }
362 269 $row .= '>';
363 270
364 - $label = '<th scope="row"' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>';
365 - $value = '<td' . $this->td_style . '>' . wp_kses_post( $value ) . '</td>';
366 -
367 271 if ( 'rtl' == $this->direction ) {
368 - $row .= $value;
369 - $row .= $label;
272 + $first = $value;
273 + $second = $label;
370 274 } else {
371 - $row .= $label;
372 - $row .= $value;
275 + $first = $label;
276 + $second = $value;
373 277 }
374 278
279 + $row .= '<td' . $this->td_style . '>' . $first . '</td>';
280 + $row .= '<td' . $this->td_style . '>' . $second . '</td>';
281 +
375 282 $row .= '</tr>' . "\r\n";
376 283
377 284 $this->switch_odd();
378 285
@@ -388,11 +295,9 @@
388 295 *
389 296 * @return string
390 297 */
391 298 public function generate_single_cell_table_row( $value ) {
392 - $row = '<tr' . $this->tr_style();
393 - $row .= $this->add_row_class();
394 - $row .= '>';
299 + $row = '<tr' . $this->tr_style() . '>';
395 300 $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>';
396 301 $row .= '</tr>' . "\r\n";
397 302
398 303 $this->switch_odd();
@@ -397,30 +302,6 @@
397 302
398 303 $this->switch_odd();
399 304
400 305 return $row;
401 - }
402 -
403 - /**
404 - * Add classes to the tr.
405 - *
406 - * @since 5.4.2
407 - *
408 - * @param bool $empty If the value in the row is blank.
409 - *
410 - * @return string
411 - */
412 - protected function add_row_class( $empty = false ) {
413 - $class = '';
414 - if ( $empty ) {
415 - // Only add this class on two cell rows.
416 - $class .= ' frm-empty-row';
417 - }
418 - if ( $this->is_child ) {
419 - $class .= ' frm-child-row';
420 - }
421 - if ( $class ) {
422 - $class = ' class="' . trim( $class ) . '"';
423 - }
424 - return $class;
425 306 }
426 307 }