| @@ -9,9 +9,8 @@ | ||
| 9 | 9 | class FrmEntryShortcodeFormatter { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @var int |
| 13 | - * | |
| 14 | 13 | * @since 2.04 |
| 15 | 14 | */ |
| 16 | 15 | protected $form_id = 0; |
| 17 | 16 | |
| @@ -16,9 +15,8 @@ | ||
| 16 | 15 | protected $form_id = 0; |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | 18 | * @var array |
| 20 | - * | |
| 21 | 19 | * @since 2.04 |
| 22 | 20 | */ |
| 23 | 21 | protected $skip_fields = array( 'captcha', 'html' ); |
| 24 | 22 | |
| @@ -23,9 +21,8 @@ | ||
| 23 | 21 | protected $skip_fields = array( 'captcha', 'html' ); |
| 24 | 22 | |
| 25 | 23 | /** |
| 26 | 24 | * @var array |
| 27 | - * | |
| 28 | 25 | * @since 3.0 |
| 29 | 26 | */ |
| 30 | 27 | protected $single_cell_fields = array( 'html' ); |
| 31 | 28 | |
| @@ -30,9 +27,8 @@ | ||
| 30 | 27 | protected $single_cell_fields = array( 'html' ); |
| 31 | 28 | |
| 32 | 29 | /** |
| 33 | 30 | * @var array |
| 34 | - * | |
| 35 | 31 | * @since 2.04 |
| 36 | 32 | */ |
| 37 | 33 | protected $fields = array(); |
| 38 | 34 | |
| @@ -37,9 +33,8 @@ | ||
| 37 | 33 | protected $fields = array(); |
| 38 | 34 | |
| 39 | 35 | /** |
| 40 | 36 | * @var bool |
| 41 | - * | |
| 42 | 37 | * @since 2.05 |
| 43 | 38 | */ |
| 44 | 39 | protected $is_plain_text = false; |
| 45 | 40 | |
| @@ -44,23 +39,20 @@ | ||
| 44 | 39 | protected $is_plain_text = false; |
| 45 | 40 | |
| 46 | 41 | /** |
| 47 | 42 | * @var string |
| 48 | - * | |
| 49 | 43 | * @since 2.04 |
| 50 | 44 | */ |
| 51 | 45 | protected $format = 'text'; |
| 52 | 46 | |
| 53 | 47 | /** |
| 54 | - * @var FrmTableHTMLGenerator|null | |
| 55 | - * | |
| 48 | + * @var FrmTableHTMLGenerator | |
| 56 | 49 | * @since 2.04 |
| 57 | 50 | */ |
| 58 | - protected $table_generator; | |
| 51 | + protected $table_generator = null; | |
| 59 | 52 | |
| 60 | 53 | /** |
| 61 | 54 | * @var array |
| 62 | - * | |
| 63 | 55 | * @since 2.04 |
| 64 | 56 | */ |
| 65 | 57 | protected $array_content = array(); |
| 66 | 58 | |
| @@ -67,9 +59,9 @@ | ||
| 67 | 59 | /** |
| 68 | 60 | * FrmEntryShortcodeFormatter constructor |
| 69 | 61 | * |
| 70 | 62 | * @param int|string $form_id |
| 71 | - * @param array $atts | |
| 63 | + * @param array $atts | |
| 72 | 64 | */ |
| 73 | 65 | public function __construct( $form_id, $atts ) { |
| 74 | 66 | if ( ! $form_id ) { |
| 75 | 67 | return; |
| @@ -77,9 +69,9 @@ | ||
| 77 | 69 | |
| 78 | 70 | $this->init_form_id( $form_id ); |
| 79 | 71 | $this->init_fields(); |
| 80 | 72 | |
| 81 | - if ( ! $this->fields ) { | |
| 73 | + if ( empty( $this->fields ) ) { | |
| 82 | 74 | return; |
| 83 | 75 | } |
| 84 | 76 | |
| 85 | 77 | $this->init_plain_text( $atts ); |
| @@ -94,8 +86,9 @@ | ||
| 94 | 86 | * Initialize the form_id property |
| 95 | 87 | * |
| 96 | 88 | * @since 2.04 |
| 97 | 89 | * |
| 90 | + * @param $form_id | |
| 98 | 91 | * @param int|string $form_id |
| 99 | 92 | * |
| 100 | 93 | * @return void |
| 101 | 94 | */ |
| @@ -123,9 +116,9 @@ | ||
| 123 | 116 | * |
| 124 | 117 | * @return void |
| 125 | 118 | */ |
| 126 | 119 | protected function init_plain_text( $atts ) { |
| 127 | - if ( ! empty( $atts['plain_text'] ) ) { | |
| 120 | + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { | |
| 128 | 121 | $this->is_plain_text = true; |
| 129 | 122 | } |
| 130 | 123 | } |
| 131 | 124 | |
| @@ -160,17 +153,15 @@ | ||
| 160 | 153 | /** |
| 161 | 154 | * Return the default HTML for an entry |
| 162 | 155 | * |
| 163 | 156 | * @since 2.04 |
| 164 | - * | |
| 165 | - * @return array|string | |
| 166 | 157 | */ |
| 167 | 158 | public function content() { |
| 168 | - if ( ! $this->form_id || ! $this->fields ) { | |
| 159 | + if ( ! $this->form_id || empty( $this->fields ) ) { | |
| 169 | 160 | return ''; |
| 170 | 161 | } |
| 171 | 162 | |
| 172 | - if ( $this->format === 'array' ) { | |
| 163 | + if ( $this->format == 'array' ) { | |
| 173 | 164 | $content = $this->get_array(); |
| 174 | 165 | } elseif ( $this->is_plain_text_format() ) { |
| 175 | 166 | $content = $this->get_plain_text(); |
| 176 | 167 | } else { |
| @@ -213,12 +204,13 @@ | ||
| 213 | 204 | * |
| 214 | 205 | * @return string |
| 215 | 206 | */ |
| 216 | 207 | protected function get_table() { |
| 217 | - $content = $this->table_generator->generate_table_header(); | |
| 208 | + $content = $this->table_generator->generate_table_header(); | |
| 218 | 209 | $content .= $this->generate_content_for_all_fields(); |
| 210 | + $content .= $this->table_generator->generate_table_footer(); | |
| 219 | 211 | |
| 220 | - return $content . $this->table_generator->generate_table_footer(); | |
| 212 | + return $content; | |
| 221 | 213 | } |
| 222 | 214 | |
| 223 | 215 | /** |
| 224 | 216 | * Generate the content for all fields |
| @@ -246,13 +238,15 @@ | ||
| 246 | 238 | * |
| 247 | 239 | * @return string |
| 248 | 240 | */ |
| 249 | 241 | protected function generate_field_content( $field ) { |
| 250 | - if ( in_array( $field->type, $this->skip_fields, true ) ) { | |
| 242 | + if ( in_array( $field->type, $this->skip_fields ) ) { | |
| 251 | 243 | return ''; |
| 252 | 244 | } |
| 253 | 245 | |
| 254 | - return $this->generate_two_cell_shortcode_row( $field ); | |
| 246 | + $row = $this->generate_two_cell_shortcode_row( $field ); | |
| 247 | + | |
| 248 | + return $row; | |
| 255 | 249 | } |
| 256 | 250 | |
| 257 | 251 | /** |
| 258 | 252 | * Generate a two cell row of shortcodes for an HTML or plain text table |
| @@ -259,14 +253,15 @@ | ||
| 259 | 253 | * |
| 260 | 254 | * @since 2.04 |
| 261 | 255 | * |
| 262 | 256 | * @param stdClass $field |
| 263 | - * @param mixed $value | |
| 257 | + * @param mixed $value | |
| 264 | 258 | * |
| 265 | 259 | * @return string |
| 266 | 260 | */ |
| 267 | 261 | protected function generate_two_cell_shortcode_row( $field, $value = null ) { |
| 268 | - $row = '[if ' . $field->id . ']'; | |
| 262 | + $row = '[if ' . $field->id . ']'; | |
| 263 | + | |
| 269 | 264 | $label = '[' . $field->id . ' show=field_label]'; |
| 270 | 265 | |
| 271 | 266 | if ( $value === null ) { |
| 272 | 267 | $value = '[' . $field->id . ']'; |
| @@ -296,9 +291,9 @@ | ||
| 296 | 291 | * |
| 297 | 292 | * @return void |
| 298 | 293 | */ |
| 299 | 294 | protected function add_field_array( $field ) { |
| 300 | - if ( in_array( $field->type, $this->skip_fields, true ) ) { | |
| 295 | + if ( in_array( $field->type, $this->skip_fields ) ) { | |
| 301 | 296 | return; |
| 302 | 297 | } |
| 303 | 298 | |
| 304 | 299 | $this->add_single_field_array( $field, $field->id ); |
| @@ -309,9 +304,9 @@ | ||
| 309 | 304 | * |
| 310 | 305 | * @since 2.04 |
| 311 | 306 | * |
| 312 | 307 | * @param stdClass $field |
| 313 | - * @param string $value | |
| 308 | + * @param string $value | |
| 314 | 309 | * |
| 315 | 310 | * @return void |
| 316 | 311 | */ |
| 317 | 312 | protected function add_single_field_array( $field, $value ) { |
| @@ -331,9 +326,9 @@ | ||
| 331 | 326 | * |
| 332 | 327 | * @return bool |
| 333 | 328 | */ |
| 334 | 329 | protected function is_plain_text_format() { |
| 335 | - return $this->format === 'text' && $this->is_plain_text === true; | |
| 330 | + return ( $this->format === 'text' && $this->is_plain_text === true ); | |
| 336 | 331 | } |
| 337 | 332 | |
| 338 | 333 | /** |
| 339 | 334 | * Check if the format is default HTML |
| @@ -342,7 +337,7 @@ | ||
| 342 | 337 | * |
| 343 | 338 | * @return bool |
| 344 | 339 | */ |
| 345 | 340 | protected function is_table_format() { |
| 346 | - return $this->format === 'text' && $this->is_plain_text === false; | |
| 341 | + return ( $this->format === 'text' && $this->is_plain_text === false ); | |
| 347 | 342 | } |
| 348 | 343 | } |