| @@ -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 | |
| @@ -93,18 +67,10 @@ | ||
| 93 | 67 | * @param string $type |
| 94 | 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,9 +82,8 @@ | ||
| 116 | 82 | * |
| 117 | 83 | * @since 2.04 |
| 118 | 84 | * |
| 119 | 85 | * @param array $atts |
| 120 | - * | |
| 121 | 86 | * @return void |
| 122 | 87 | */ |
| 123 | 88 | private function init_style_settings( $atts ) { |
| 124 | 89 | $style_settings = array( |
| @@ -140,9 +105,9 @@ | ||
| 140 | 105 | $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] ); |
| 141 | 106 | } |
| 142 | 107 | } |
| 143 | 108 | |
| 144 | - $this->style_settings['class'] = $atts['class'] ?? ''; | |
| 109 | + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : ''; | |
| 145 | 110 | } |
| 146 | 111 | |
| 147 | 112 | /** |
| 148 | 113 | * Set the use_inline_style property |
| @@ -149,9 +114,8 @@ | ||
| 149 | 114 | * |
| 150 | 115 | * @since 2.04 |
| 151 | 116 | * |
| 152 | 117 | * @param array $atts |
| 153 | - * | |
| 154 | 118 | * @return void |
| 155 | 119 | */ |
| 156 | 120 | private function init_use_inline_style( $atts ) { |
| 157 | 121 | if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) { |
| @@ -164,9 +128,8 @@ | ||
| 164 | 128 | * |
| 165 | 129 | * @since 2.04 |
| 166 | 130 | * |
| 167 | 131 | * @param array $atts |
| 168 | - * | |
| 169 | 132 | * @return void |
| 170 | 133 | */ |
| 171 | 134 | private function init_direction( $atts ) { |
| 172 | 135 | if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) { |
| @@ -177,24 +140,21 @@ | ||
| 177 | 140 | /** |
| 178 | 141 | * Set the table_style property |
| 179 | 142 | * |
| 180 | 143 | * @since 2.04 |
| 181 | - * | |
| 182 | 144 | * @return void |
| 183 | 145 | */ |
| 184 | 146 | private function init_table_style() { |
| 185 | 147 | 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%;' ); | |
| 148 | + | |
| 149 | + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' ); | |
| 187 | 150 | $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"'; |
| 151 | + | |
| 188 | 152 | } |
| 189 | 153 | |
| 190 | 154 | if ( ! empty( $this->style_settings['class'] ) ) { |
| 191 | 155 | $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"'; |
| 192 | 156 | } |
| 193 | - | |
| 194 | - if ( ! empty( $this->width ) ) { | |
| 195 | - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"'; | |
| 196 | - } | |
| 197 | 157 | } |
| 198 | 158 | |
| 199 | 159 | /** |
| 200 | 160 | * Set the td_style property |
| @@ -199,53 +159,31 @@ | ||
| 199 | 159 | /** |
| 200 | 160 | * Set the td_style property |
| 201 | 161 | * |
| 202 | 162 | * @since 2.04 |
| 203 | - * | |
| 204 | 163 | * @return void |
| 205 | 164 | */ |
| 206 | 165 | private function init_td_style() { |
| 207 | 166 | if ( $this->use_inline_style === true ) { |
| 167 | + | |
| 208 | 168 | $td_style_attributes = 'text-align:' . ( $this->direction === 'rtl' ? 'right' : 'left' ) . ';'; |
| 209 | - $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:' . $this->cell_padding . ';vertical-align:top;'; | |
| 169 | + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;'; | |
| 210 | 170 | $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';'; |
| 211 | 171 | |
| 212 | - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"'; | |
| 172 | + $this->td_style = ' style="' . $td_style_attributes . '"'; | |
| 213 | 173 | } |
| 214 | 174 | } |
| 215 | 175 | |
| 216 | 176 | /** |
| 217 | - * Removes border CSS from HTML. | |
| 218 | - * | |
| 219 | - * @since 6.25 | |
| 220 | - * | |
| 221 | - * @param string $html The HTML. | |
| 222 | - * @param string $position The border position. Default is `top`. | |
| 223 | - * | |
| 224 | - * @return string | |
| 225 | - */ | |
| 226 | - public function remove_border( $html, $position = 'top' ) { | |
| 227 | - $search = sprintf( | |
| 228 | - 'border-%1$s:%2$s solid %3$s;', | |
| 229 | - $position, | |
| 230 | - $this->style_settings['border_width'], | |
| 231 | - $this->style_settings['border_color'] | |
| 232 | - ); | |
| 233 | - | |
| 234 | - return str_replace( $search, '', $html ); | |
| 235 | - } | |
| 236 | - | |
| 237 | - /** | |
| 238 | 177 | * Determine if setting is for a color, e.g. text color, background color, or border color |
| 239 | 178 | * |
| 240 | 179 | * @since 2.05 |
| 241 | - * | |
| 242 | 180 | * @param string $setting_key Name of setting. |
| 243 | 181 | * |
| 244 | 182 | * @return bool |
| 245 | 183 | */ |
| 246 | 184 | private function is_color_setting( $setting_key ) { |
| 247 | - return str_contains( $setting_key, 'color' ); | |
| 185 | + return strpos( $setting_key, 'color' ) !== false; | |
| 248 | 186 | } |
| 249 | 187 | |
| 250 | 188 | /** |
| 251 | 189 | * Get color markup from color setting value |
| @@ -250,9 +188,8 @@ | ||
| 250 | 188 | /** |
| 251 | 189 | * Get color markup from color setting value |
| 252 | 190 | * |
| 253 | 191 | * @since 2.05 |
| 254 | - * | |
| 255 | 192 | * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white. |
| 256 | 193 | * |
| 257 | 194 | * @return string |
| 258 | 195 | */ |
| @@ -274,9 +211,9 @@ | ||
| 274 | 211 | * |
| 275 | 212 | * @return string |
| 276 | 213 | */ |
| 277 | 214 | private function table_row_background_color() { |
| 278 | - return $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color']; | |
| 215 | + return ( $this->odd ? $this->style_settings['bg_color'] : $this->style_settings['alt_bg_color'] ); | |
| 279 | 216 | } |
| 280 | 217 | |
| 281 | 218 | /** |
| 282 | 219 | * Get the table row style |
| @@ -282,13 +219,13 @@ | ||
| 282 | 219 | * Get the table row style |
| 283 | 220 | * |
| 284 | 221 | * @since 2.04 |
| 285 | 222 | * @since 5.0.16 Changed scope from `private` to `protected`. |
| 286 | - * @since 6.25 Changed scope from `protected` to `public`. | |
| 287 | 223 | * |
| 288 | 224 | * @return string |
| 289 | 225 | */ |
| 290 | - public function tr_style() { | |
| 226 | + protected function tr_style() { | |
| 227 | + | |
| 291 | 228 | if ( $this->type === 'shortcode' ) { |
| 292 | 229 | $tr_style = ' style="[frm-alt-color]"'; |
| 293 | 230 | } elseif ( $this->use_inline_style ) { |
| 294 | 231 | $tr_style = ' style="background-color:' . $this->table_row_background_color() . ';"'; |
| @@ -299,30 +236,8 @@ | ||
| 299 | 236 | return $tr_style; |
| 300 | 237 | } |
| 301 | 238 | |
| 302 | 239 | /** |
| 303 | - * Gets table style. | |
| 304 | - * | |
| 305 | - * @since 6.25 | |
| 306 | - * | |
| 307 | - * @return string | |
| 308 | - */ | |
| 309 | - public function get_table_style() { | |
| 310 | - return $this->table_style; | |
| 311 | - } | |
| 312 | - | |
| 313 | - /** | |
| 314 | - * Gets td style. | |
| 315 | - * | |
| 316 | - * @since 6.25 | |
| 317 | - * | |
| 318 | - * @return string | |
| 319 | - */ | |
| 320 | - public function get_td_style() { | |
| 321 | - return $this->td_style; | |
| 322 | - } | |
| 323 | - | |
| 324 | - /** | |
| 325 | 240 | * Switch the odd property from true to false or false to true |
| 326 | 241 | * |
| 327 | 242 | * @since 2.04 |
| 328 | 243 | * @since 5.0.16 Changed scope from `private` to `protected`. |
| @@ -342,9 +257,9 @@ | ||
| 342 | 257 | * |
| 343 | 258 | * @return string |
| 344 | 259 | */ |
| 345 | 260 | public function generate_table_header() { |
| 346 | - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n"; | |
| 261 | + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n"; | |
| 347 | 262 | } |
| 348 | 263 | |
| 349 | 264 | /** |
| 350 | 265 | * Generate a table footer |
| @@ -363,20 +278,20 @@ | ||
| 363 | 278 | * @since 2.04 |
| 364 | 279 | * |
| 365 | 280 | * @param string $label The label. |
| 366 | 281 | * @param string $value The value. |
| 367 | - * @param array $args Additional arguments. May include "field_type" string. | |
| 368 | 282 | * |
| 369 | 283 | * @return string |
| 370 | 284 | */ |
| 371 | - public function generate_two_cell_table_row( $label, $value, $args = array() ) { | |
| 372 | - $row = '<tr' . $this->tr_style(); | |
| 373 | - $row .= $this->add_row_class( $value === '' ); | |
| 374 | - $row .= '>'; | |
| 375 | - $label = '<th scope="row"' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>'; | |
| 376 | - $value = '<td' . $this->td_style . '>' . $this->filter_value_for_display( $value, $args ) . '</td>'; | |
| 285 | + public function generate_two_cell_table_row( $label, $value ) { | |
| 286 | + $row = '<tr' . $this->tr_style(); | |
| 287 | + $row .= $this->add_row_class( $value === '' ); | |
| 288 | + $row .= '>'; | |
| 377 | 289 | |
| 378 | - if ( 'rtl' === $this->direction ) { | |
| 290 | + $label = '<th' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>'; | |
| 291 | + $value = '<td' . $this->td_style . '>' . wp_kses_post( $value ) . '</td>'; | |
| 292 | + | |
| 293 | + if ( 'rtl' == $this->direction ) { | |
| 379 | 294 | $row .= $value; |
| 380 | 295 | $row .= $label; |
| 381 | 296 | } else { |
| 382 | 297 | $row .= $label; |
| @@ -390,23 +305,8 @@ | ||
| 390 | 305 | return $row; |
| 391 | 306 | } |
| 392 | 307 | |
| 393 | 308 | /** |
| 394 | - * @param string $value | |
| 395 | - * @param array $args | |
| 396 | - * | |
| 397 | - * @return string | |
| 398 | - */ | |
| 399 | - private function filter_value_for_display( $value, $args ) { | |
| 400 | - if ( empty( $args['field_type'] ) ) { | |
| 401 | - return wp_kses_post( $value ); | |
| 402 | - } | |
| 403 | - | |
| 404 | - $field_object = FrmFieldFactory::get_field_type( $args['field_type'] ); | |
| 405 | - return $field_object->filter_value_for_table_html( $value ); | |
| 406 | - } | |
| 407 | - | |
| 408 | - /** | |
| 409 | 309 | * Generate a single cell row for an HTML table |
| 410 | 310 | * |
| 411 | 311 | * @since 2.04 |
| 412 | 312 | * |
| @@ -436,21 +336,17 @@ | ||
| 436 | 336 | * @return string |
| 437 | 337 | */ |
| 438 | 338 | protected function add_row_class( $empty = false ) { |
| 439 | 339 | $class = ''; |
| 440 | - | |
| 441 | 340 | if ( $empty ) { |
| 442 | 341 | // Only add this class on two cell rows. |
| 443 | 342 | $class .= ' frm-empty-row'; |
| 444 | 343 | } |
| 445 | - | |
| 446 | 344 | if ( $this->is_child ) { |
| 447 | 345 | $class .= ' frm-child-row'; |
| 448 | 346 | } |
| 449 | - | |
| 450 | 347 | if ( $class ) { |
| 451 | 348 | $class = ' class="' . trim( $class ) . '"'; |
| 452 | 349 | } |
| 453 | - | |
| 454 | 350 | return $class; |
| 455 | 351 | } |
| 456 | 352 | } |