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