| @@ -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,15 +123,13 @@ | ||
| 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 | 135 | |
| @@ -191,12 +135,8 @@ | ||
| 191 | 135 | |
| 192 | 136 | if ( ! empty( $this->style_settings['class'] ) ) { |
| 193 | 137 | $this->table_style .= ' class="' . esc_attr( $this->style_settings['class'] ) . '"'; |
| 194 | 138 | } |
| 195 | - | |
| 196 | - if ( ! empty( $this->width ) ) { | |
| 197 | - $this->table_style .= ' width="' . esc_attr( $this->width ) . '"'; | |
| 198 | - } | |
| 199 | 139 | } |
| 200 | 140 | |
| 201 | 141 | /** |
| 202 | 142 | * Set the td_style property |
| @@ -201,51 +141,28 @@ | ||
| 201 | 141 | /** |
| 202 | 142 | * Set the td_style property |
| 203 | 143 | * |
| 204 | 144 | * @since 2.04 |
| 205 | - * | |
| 206 | - * @return void | |
| 207 | 145 | */ |
| 208 | 146 | private function init_td_style() { |
| 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;'; | |
| 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;'; | |
| 213 | 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 . '"'; | |
| 216 | 154 | } |
| 217 | 155 | } |
| 218 | 156 | |
| 219 | 157 | /** |
| 220 | - * Removes border CSS from HTML. | |
| 158 | + * Determine if setting is for a color, e.g. text color, background color, or border color | |
| 221 | 159 | * |
| 222 | - * @since 6.25 | |
| 160 | + * @param string $setting_key name of setting | |
| 223 | 161 | * |
| 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 | 162 | * @since 2.05 |
| 244 | 163 | * |
| 245 | - * @param string $setting_key Name of setting. | |
| 246 | - * | |
| 247 | - * @return bool | |
| 164 | + * @return boolean | |
| 248 | 165 | */ |
| 249 | 166 | private function is_color_setting( $setting_key ) { |
| 250 | 167 | return strpos( $setting_key, 'color' ) !== false; |
| 251 | 168 | } |
| @@ -252,19 +169,19 @@ | ||
| 252 | 169 | |
| 253 | 170 | /** |
| 254 | 171 | * Get color markup from color setting value |
| 255 | 172 | * |
| 173 | + * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white. | |
| 174 | + * | |
| 256 | 175 | * @since 2.05 |
| 257 | 176 | * |
| 258 | - * @param string $color_markup value of a color setting, with format #FFFFF, FFFFFF, or white. | |
| 259 | - * | |
| 260 | 177 | * @return string |
| 261 | 178 | */ |
| 262 | 179 | private function get_color_markup( $color_markup ) { |
| 263 | 180 | $color_markup = trim( $color_markup ); |
| 264 | 181 | |
| 265 | - // Check if each character in string is valid hex digit | |
| 266 | - if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) { | |
| 182 | + //check if each character in string is valid hex digit | |
| 183 | + if ( ctype_xdigit( $color_markup ) ) { | |
| 267 | 184 | $color_markup = '#' . $color_markup; |
| 268 | 185 | } |
| 269 | 186 | |
| 270 | 187 | return $color_markup; |
| @@ -284,14 +201,12 @@ | ||
| 284 | 201 | /** |
| 285 | 202 | * Get the table row style |
| 286 | 203 | * |
| 287 | 204 | * @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 | 205 | * |
| 291 | 206 | * @return string |
| 292 | 207 | */ |
| 293 | - public function tr_style() { | |
| 208 | + private function tr_style() { | |
| 294 | 209 | |
| 295 | 210 | if ( $this->type === 'shortcode' ) { |
| 296 | 211 | $tr_style = ' style="[frm-alt-color]"'; |
| 297 | 212 | } elseif ( $this->use_inline_style ) { |
| @@ -303,38 +218,13 @@ | ||
| 303 | 218 | return $tr_style; |
| 304 | 219 | } |
| 305 | 220 | |
| 306 | 221 | /** |
| 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 | 222 | * Switch the odd property from true to false or false to true |
| 330 | 223 | * |
| 331 | 224 | * @since 2.04 |
| 332 | - * @since 5.0.16 Changed scope from `private` to `protected`. | |
| 333 | - * | |
| 334 | - * @return void | |
| 335 | 225 | */ |
| 336 | - protected function switch_odd() { | |
| 226 | + private function switch_odd() { | |
| 337 | 227 | if ( $this->type !== 'shortcode' ) { |
| 338 | 228 | $this->odd = ! $this->odd; |
| 339 | 229 | } |
| 340 | 230 | } |
| @@ -346,9 +236,9 @@ | ||
| 346 | 236 | * |
| 347 | 237 | * @return string |
| 348 | 238 | */ |
| 349 | 239 | public function generate_table_header() { |
| 350 | - return '<table cellspacing="0"' . $this->table_style . '><tbody>' . "\r\n"; | |
| 240 | + return '<table cellspacing="0" ' . $this->table_style . '><tbody>' . "\r\n"; | |
| 351 | 241 | } |
| 352 | 242 | |
| 353 | 243 | /** |
| 354 | 244 | * Generate a table footer |
| @@ -365,30 +255,31 @@ | ||
| 365 | 255 | * Generate a two cell row for an HTML table |
| 366 | 256 | * |
| 367 | 257 | * @since 2.04 |
| 368 | 258 | * |
| 369 | - * @param string $label The label. | |
| 370 | - * @param string $value The value. | |
| 371 | - * @param array $args Additional arguments. May include "field_type" string. | |
| 259 | + * @param string $label | |
| 260 | + * @param string $value | |
| 372 | 261 | * |
| 373 | 262 | * @return string |
| 374 | 263 | */ |
| 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 === '' ); | |
| 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 | + } | |
| 378 | 269 | $row .= '>'; |
| 379 | 270 | |
| 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 | 271 | if ( 'rtl' == $this->direction ) { |
| 384 | - $row .= $value; | |
| 385 | - $row .= $label; | |
| 272 | + $first = $value; | |
| 273 | + $second = $label; | |
| 386 | 274 | } else { |
| 387 | - $row .= $label; | |
| 388 | - $row .= $value; | |
| 275 | + $first = $label; | |
| 276 | + $second = $value; | |
| 389 | 277 | } |
| 390 | 278 | |
| 279 | + $row .= '<td' . $this->td_style . '>' . $first . '</td>'; | |
| 280 | + $row .= '<td' . $this->td_style . '>' . $second . '</td>'; | |
| 281 | + | |
| 391 | 282 | $row .= '</tr>' . "\r\n"; |
| 392 | 283 | |
| 393 | 284 | $this->switch_odd(); |
| 394 | 285 | |
| @@ -395,23 +286,8 @@ | ||
| 395 | 286 | return $row; |
| 396 | 287 | } |
| 397 | 288 | |
| 398 | 289 | /** |
| 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 | 290 | * Generate a single cell row for an HTML table |
| 415 | 291 | * |
| 416 | 292 | * @since 2.04 |
| 417 | 293 | * |
| @@ -419,11 +295,9 @@ | ||
| 419 | 295 | * |
| 420 | 296 | * @return string |
| 421 | 297 | */ |
| 422 | 298 | public function generate_single_cell_table_row( $value ) { |
| 423 | - $row = '<tr' . $this->tr_style(); | |
| 424 | - $row .= $this->add_row_class(); | |
| 425 | - $row .= '>'; | |
| 299 | + $row = '<tr' . $this->tr_style() . '>'; | |
| 426 | 300 | $row .= '<td colspan="2"' . $this->td_style . '>' . $value . '</td>'; |
| 427 | 301 | $row .= '</tr>' . "\r\n"; |
| 428 | 302 | |
| 429 | 303 | $this->switch_odd(); |
| @@ -428,33 +302,6 @@ | ||
| 428 | 302 | |
| 429 | 303 | $this->switch_odd(); |
| 430 | 304 | |
| 431 | 305 | 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 | 306 | } |
| 460 | 307 | } |