| @@ -53,51 +53,16 @@ | ||
| 53 | 53 | */ |
| 54 | 54 | protected $td_style = ''; |
| 55 | 55 | |
| 56 | 56 | /** |
| 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 | 57 | * FrmTableHTMLGenerator constructor. |
| 84 | 58 | * |
| 85 | 59 | * @param string $type |
| 86 | - * @param array $atts | |
| 60 | + * @param array $atts | |
| 87 | 61 | */ |
| 88 | 62 | public function __construct( $type, $atts = array() ) { |
| 89 | 63 | |
| 90 | 64 | $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 | 65 | $this->init_style_settings( $atts ); |
| 101 | 66 | $this->init_use_inline_style( $atts ); |
| 102 | 67 | $this->init_direction( $atts ); |
| 103 | 68 | $this->init_table_style(); |
| @@ -109,9 +74,8 @@ | ||
| 109 | 74 | * |
| 110 | 75 | * @since 2.04 |
| 111 | 76 | * |
| 112 | 77 | * @param array $atts |
| 113 | - * @return void | |
| 114 | 78 | */ |
| 115 | 79 | private function init_style_settings( $atts ) { |
| 116 | 80 | $style_settings = array( |
| 117 | 81 | 'border_color' => 'dddddd', |
| @@ -132,9 +96,9 @@ | ||
| 132 | 96 | $this->style_settings[ $key ] = $this->get_color_markup( $this->style_settings[ $key ] ); |
| 133 | 97 | } |
| 134 | 98 | } |
| 135 | 99 | |
| 136 | - $this->style_settings['class'] = $atts['class'] ?? ''; | |
| 100 | + $this->style_settings['class'] = isset( $atts['class'] ) ? $atts['class'] : ''; | |
| 137 | 101 | } |
| 138 | 102 | |
| 139 | 103 | /** |
| 140 | 104 | * Set the use_inline_style property |
| @@ -141,9 +105,8 @@ | ||
| 141 | 105 | * |
| 142 | 106 | * @since 2.04 |
| 143 | 107 | * |
| 144 | 108 | * @param array $atts |
| 145 | - * @return void | |
| 146 | 109 | */ |
| 147 | 110 | private function init_use_inline_style( $atts ) { |
| 148 | 111 | if ( isset( $atts['inline_style'] ) && ! $atts['inline_style'] ) { |
| 149 | 112 | $this->use_inline_style = false; |
| @@ -155,9 +118,8 @@ | ||
| 155 | 118 | * |
| 156 | 119 | * @since 2.04 |
| 157 | 120 | * |
| 158 | 121 | * @param array $atts |
| 159 | - * @return void | |
| 160 | 122 | */ |
| 161 | 123 | private function init_direction( $atts ) { |
| 162 | 124 | if ( isset( $atts['direction'] ) && $atts['direction'] === 'rtl' ) { |
| 163 | 125 | $this->direction = 'rtl'; |
| @@ -167,14 +129,13 @@ | ||
| 167 | 129 | /** |
| 168 | 130 | * Set the table_style property |
| 169 | 131 | * |
| 170 | 132 | * @since 2.04 |
| 171 | - * @return void | |
| 172 | 133 | */ |
| 173 | 134 | private function init_table_style() { |
| 174 | 135 | if ( $this->use_inline_style === true ) { |
| 175 | 136 | |
| 176 | - $this->table_style = ' style="' . esc_attr( 'border-spacing:0;font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' ); | |
| 137 | + $this->table_style = ' style="' . esc_attr( 'font-size:' . $this->style_settings['font_size'] . ';line-height:135%;' ); | |
| 177 | 138 | $this->table_style .= esc_attr( 'border-bottom:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';' ) . '"'; |
| 178 | 139 | |
| 179 | 140 | } |
| 180 | 141 | |
| @@ -180,12 +141,8 @@ | ||
| 180 | 141 | |
| 181 | 142 | if ( ! empty( $this->style_settings['class'] ) ) { |
| 182 | 143 | $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"'; |
| 183 | 144 | } |
| 184 | - | |
| 185 | - if ( ! empty( $this->width ) ) { | |
| 186 | - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"'; | |
| 187 | - } | |
| 188 | 145 | } |
| 189 | 146 | |
| 190 | 147 | /** |
| 191 | 148 | * Set the td_style property |
| @@ -190,48 +147,28 @@ | ||
| 190 | 147 | /** |
| 191 | 148 | * Set the td_style property |
| 192 | 149 | * |
| 193 | 150 | * @since 2.04 |
| 194 | - * @return void | |
| 195 | 151 | */ |
| 196 | 152 | private function init_td_style() { |
| 197 | 153 | if ( $this->use_inline_style === true ) { |
| 198 | 154 | |
| 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;'; | |
| 155 | + $td_style_attributes = 'text-align:' . ( $this->direction == 'rtl' ? 'right' : 'left' ) . ';'; | |
| 156 | + $td_style_attributes .= 'color:' . $this->style_settings['text_color'] . ';padding:7px 9px;vertical-align:top;'; | |
| 201 | 157 | $td_style_attributes .= 'border-top:' . $this->style_settings['border_width'] . ' solid ' . $this->style_settings['border_color'] . ';'; |
| 202 | 158 | |
| 203 | - $this->td_style = ' style="' . esc_attr( $td_style_attributes ) . '"'; | |
| 159 | + $this->td_style = ' style="' . $td_style_attributes . '"'; | |
| 204 | 160 | } |
| 205 | 161 | } |
| 206 | 162 | |
| 207 | 163 | /** |
| 208 | - * Removes border CSS from HTML. | |
| 164 | + * Determine if setting is for a color, e.g. text color, background color, or border color | |
| 209 | 165 | * |
| 210 | - * @since 6.25 | |
| 166 | + * @param string $setting_key name of setting | |
| 211 | 167 | * |
| 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 | 168 | * @since 2.05 |
| 231 | - * @param string $setting_key Name of setting. | |
| 232 | 169 | * |
| 233 | - * @return bool | |
| 170 | + * @return boolean | |
| 234 | 171 | */ |
| 235 | 172 | private function is_color_setting( $setting_key ) { |
| 236 | 173 | return strpos( $setting_key, 'color' ) !== false; |
| 237 | 174 | } |
| @@ -238,10 +175,11 @@ | ||
| 238 | 175 | |
| 239 | 176 | /** |
| 240 | 177 | * Get color markup from color setting value |
| 241 | 178 | * |
| 179 | + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white. | |
| 180 | + * | |
| 242 | 181 | * @since 2.05 |
| 243 | - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white. | |
| 244 | 182 | * |
| 245 | 183 | * @return string |
| 246 | 184 | */ |
| 247 | 185 | private function get_color_markup( $color_markup ) { |
| @@ -270,13 +208,12 @@ | ||
| 270 | 208 | * Get the table row style |
| 271 | 209 | * |
| 272 | 210 | * @since 2.04 |
| 273 | 211 | * @since 5.0.16 Changed scope from `private` to `protected`. |
| 274 | - * @since 6.25 Changed scope from `protected` to `public`. | |
| 275 | 212 | * |
| 276 | 213 | * @return string |
| 277 | 214 | */ |
| 278 | - public function tr_style() { | |
| 215 | + protected function tr_style() { | |
| 279 | 216 | |
| 280 | 217 | if ( $this->type === 'shortcode' ) { |
| 281 | 218 | $tr_style = ' style="[frm-alt-color]"'; |
| 282 | 219 | } elseif ( $this->use_inline_style ) { |
| @@ -288,36 +225,12 @@ | ||
| 288 | 225 | return $tr_style; |
| 289 | 226 | } |
| 290 | 227 | |
| 291 | 228 | /** |
| 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 | 229 | * Switch the odd property from true to false or false to true |
| 315 | 230 | * |
| 316 | 231 | * @since 2.04 |
| 317 | 232 | * @since 5.0.16 Changed scope from `private` to `protected`. |
| 318 | - * | |
| 319 | - * @return void | |
| 320 | 233 | */ |
| 321 | 234 | protected function switch_odd() { |
| 322 | 235 | if ( $this->type !== 'shortcode' ) { |
| 323 | 236 | $this->odd = ! $this->odd; |
| @@ -331,9 +244,9 @@ | ||
| 331 | 244 | * |
| 332 | 245 | * @return string |
| 333 | 246 | */ |
| 334 | 247 | public function generate_table_header() { |
| 335 | - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n"; | |
| 248 | + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n"; | |
| 336 | 249 | } |
| 337 | 250 | |
| 338 | 251 | /** |
| 339 | 252 | * Generate a table footer |
| @@ -356,13 +269,15 @@ | ||
| 356 | 269 | * |
| 357 | 270 | * @return string |
| 358 | 271 | */ |
| 359 | 272 | public function generate_two_cell_table_row( $label, $value ) { |
| 360 | - $row = '<tr' . $this->tr_style(); | |
| 361 | - $row .= $this->add_row_class( $value === '' ); | |
| 273 | + $row = '<tr' . $this->tr_style(); | |
| 274 | + if ( $value === '' ) { | |
| 275 | + $row .= ' class="frm-empty-row"'; | |
| 276 | + } | |
| 362 | 277 | $row .= '>'; |
| 363 | 278 | |
| 364 | - $label = '<th scope="row"' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>'; | |
| 279 | + $label = '<th' . $this->td_style . '>' . wp_kses_post( $label ) . '</th>'; | |
| 365 | 280 | $value = '<td' . $this->td_style . '>' . wp_kses_post( $value ) . '</td>'; |
| 366 | 281 | |
| 367 | 282 | if ( 'rtl' == $this->direction ) { |
| 368 | 283 | $row .= $value; |
| @@ -388,11 +303,9 @@ | ||
| 388 | 303 | * |
| 389 | 304 | * @return string |
| 390 | 305 | */ |
| 391 | 306 | public function generate_single_cell_table_row( $value ) { |
| 392 | - $row = '<tr' . $this->tr_style(); | |
| 393 | - $row .= $this->add_row_class(); | |
| 394 | - $row .= '>'; | |
| 307 | + $row = '<tr' . $this->tr_style() . '>'; | |
| 395 | 308 | $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>'; |
| 396 | 309 | $row .= '</tr>' . "\r\n"; |
| 397 | 310 | |
| 398 | 311 | $this->switch_odd(); |
| @@ -397,30 +310,6 @@ | ||
| 397 | 310 | |
| 398 | 311 | $this->switch_odd(); |
| 399 | 312 | |
| 400 | 313 | 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 | 314 | } |
| 426 | 315 | } |