| @@ -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,11 +86,9 @@ | ||
| 94 | 86 | * Initialize the form_id property |
| 95 | 87 | * |
| 96 | 88 | * @since 2.04 |
| 97 | 89 | * |
| 98 | - * @param int|string $form_id | |
| 99 | - * | |
| 100 | - * @return void | |
| 90 | + * @param $form_id | |
| 101 | 91 | */ |
| 102 | 92 | protected function init_form_id( $form_id ) { |
| 103 | 93 | $this->form_id = (int) $form_id; |
| 104 | 94 | } |
| @@ -106,10 +96,8 @@ | ||
| 106 | 96 | /** |
| 107 | 97 | * Initialize the fields property |
| 108 | 98 | * |
| 109 | 99 | * @since 2.04 |
| 110 | - * | |
| 111 | - * @return void | |
| 112 | 100 | */ |
| 113 | 101 | protected function init_fields() { |
| 114 | 102 | $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' ); |
| 115 | 103 | } |
| @@ -119,13 +107,11 @@ | ||
| 119 | 107 | * |
| 120 | 108 | * @since 2.05 |
| 121 | 109 | * |
| 122 | 110 | * @param array $atts |
| 123 | - * | |
| 124 | - * @return void | |
| 125 | 111 | */ |
| 126 | 112 | protected function init_plain_text( $atts ) { |
| 127 | - if ( ! empty( $atts['plain_text'] ) ) { | |
| 113 | + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { | |
| 128 | 114 | $this->is_plain_text = true; |
| 129 | 115 | } |
| 130 | 116 | } |
| 131 | 117 | |
| @@ -134,10 +120,8 @@ | ||
| 134 | 120 | * |
| 135 | 121 | * @since 2.04 |
| 136 | 122 | * |
| 137 | 123 | * @param array $atts |
| 138 | - * | |
| 139 | - * @return void | |
| 140 | 124 | */ |
| 141 | 125 | protected function init_format( $atts ) { |
| 142 | 126 | if ( isset( $atts['format'] ) && is_string( $atts['format'] ) && $atts['format'] !== '' ) { |
| 143 | 127 | $this->format = $atts['format']; |
| @@ -149,10 +133,8 @@ | ||
| 149 | 133 | /** |
| 150 | 134 | * Initialize the table_generator property |
| 151 | 135 | * |
| 152 | 136 | * @since 2.04 |
| 153 | - * | |
| 154 | - * @return void | |
| 155 | 137 | */ |
| 156 | 138 | protected function init_table_generator() { |
| 157 | 139 | $this->table_generator = new FrmTableHTMLGenerator( 'shortcode' ); |
| 158 | 140 | } |
| @@ -160,17 +142,15 @@ | ||
| 160 | 142 | /** |
| 161 | 143 | * Return the default HTML for an entry |
| 162 | 144 | * |
| 163 | 145 | * @since 2.04 |
| 164 | - * | |
| 165 | - * @return array|string | |
| 166 | 146 | */ |
| 167 | 147 | public function content() { |
| 168 | - if ( ! $this->form_id || ! $this->fields ) { | |
| 148 | + if ( ! $this->form_id || empty( $this->fields ) ) { | |
| 169 | 149 | return ''; |
| 170 | 150 | } |
| 171 | 151 | |
| 172 | - if ( $this->format === 'array' ) { | |
| 152 | + if ( $this->format == 'array' ) { | |
| 173 | 153 | $content = $this->get_array(); |
| 174 | 154 | } elseif ( $this->is_plain_text_format() ) { |
| 175 | 155 | $content = $this->get_plain_text(); |
| 176 | 156 | } else { |
| @@ -183,10 +163,8 @@ | ||
| 183 | 163 | /** |
| 184 | 164 | * Return the default HTML array |
| 185 | 165 | * |
| 186 | 166 | * @since 2.04 |
| 187 | - * | |
| 188 | - * @return array | |
| 189 | 167 | */ |
| 190 | 168 | protected function get_array() { |
| 191 | 169 | foreach ( $this->fields as $field ) { |
| 192 | 170 | $this->add_field_array( $field ); |
| @@ -198,10 +176,8 @@ | ||
| 198 | 176 | /** |
| 199 | 177 | * Return the default plain text for an email message |
| 200 | 178 | * |
| 201 | 179 | * @since 2.04 |
| 202 | - * | |
| 203 | - * @return string | |
| 204 | 180 | */ |
| 205 | 181 | protected function get_plain_text() { |
| 206 | 182 | return $this->generate_content_for_all_fields(); |
| 207 | 183 | } |
| @@ -209,16 +185,15 @@ | ||
| 209 | 185 | /** |
| 210 | 186 | * Return the default HTML for an email message |
| 211 | 187 | * |
| 212 | 188 | * @since 2.04 |
| 213 | - * | |
| 214 | - * @return string | |
| 215 | 189 | */ |
| 216 | 190 | protected function get_table() { |
| 217 | - $content = $this->table_generator->generate_table_header(); | |
| 191 | + $content = $this->table_generator->generate_table_header(); | |
| 218 | 192 | $content .= $this->generate_content_for_all_fields(); |
| 193 | + $content .= $this->table_generator->generate_table_footer(); | |
| 219 | 194 | |
| 220 | - return $content . $this->table_generator->generate_table_footer(); | |
| 195 | + return $content; | |
| 221 | 196 | } |
| 222 | 197 | |
| 223 | 198 | /** |
| 224 | 199 | * Generate the content for all fields |
| @@ -246,13 +221,15 @@ | ||
| 246 | 221 | * |
| 247 | 222 | * @return string |
| 248 | 223 | */ |
| 249 | 224 | protected function generate_field_content( $field ) { |
| 250 | - if ( in_array( $field->type, $this->skip_fields, true ) ) { | |
| 225 | + if ( in_array( $field->type, $this->skip_fields ) ) { | |
| 251 | 226 | return ''; |
| 252 | 227 | } |
| 253 | 228 | |
| 254 | - return $this->generate_two_cell_shortcode_row( $field ); | |
| 229 | + $row = $this->generate_two_cell_shortcode_row( $field ); | |
| 230 | + | |
| 231 | + return $row; | |
| 255 | 232 | } |
| 256 | 233 | |
| 257 | 234 | /** |
| 258 | 235 | * Generate a two cell row of shortcodes for an HTML or plain text table |
| @@ -259,14 +236,15 @@ | ||
| 259 | 236 | * |
| 260 | 237 | * @since 2.04 |
| 261 | 238 | * |
| 262 | 239 | * @param stdClass $field |
| 263 | - * @param mixed $value | |
| 240 | + * @param mixed $value | |
| 264 | 241 | * |
| 265 | 242 | * @return string |
| 266 | 243 | */ |
| 267 | 244 | protected function generate_two_cell_shortcode_row( $field, $value = null ) { |
| 268 | - $row = '[if ' . $field->id . ']'; | |
| 245 | + $row = '[if ' . $field->id . ']'; | |
| 246 | + | |
| 269 | 247 | $label = '[' . $field->id . ' show=field_label]'; |
| 270 | 248 | |
| 271 | 249 | if ( $value === null ) { |
| 272 | 250 | $value = '[' . $field->id . ']'; |
| @@ -292,13 +270,11 @@ | ||
| 292 | 270 | * |
| 293 | 271 | * @since 2.04 |
| 294 | 272 | * |
| 295 | 273 | * @param stdClass $field |
| 296 | - * | |
| 297 | - * @return void | |
| 298 | 274 | */ |
| 299 | 275 | protected function add_field_array( $field ) { |
| 300 | - if ( in_array( $field->type, $this->skip_fields, true ) ) { | |
| 276 | + if ( in_array( $field->type, $this->skip_fields ) ) { | |
| 301 | 277 | return; |
| 302 | 278 | } |
| 303 | 279 | |
| 304 | 280 | $this->add_single_field_array( $field, $field->id ); |
| @@ -309,11 +285,9 @@ | ||
| 309 | 285 | * |
| 310 | 286 | * @since 2.04 |
| 311 | 287 | * |
| 312 | 288 | * @param stdClass $field |
| 313 | - * @param string $value | |
| 314 | - * | |
| 315 | - * @return void | |
| 289 | + * @param string $value | |
| 316 | 290 | */ |
| 317 | 291 | protected function add_single_field_array( $field, $value ) { |
| 318 | 292 | $array = array( |
| 319 | 293 | 'label' => '[' . $field->id . ' show=field_label]', |
| @@ -331,9 +305,9 @@ | ||
| 331 | 305 | * |
| 332 | 306 | * @return bool |
| 333 | 307 | */ |
| 334 | 308 | protected function is_plain_text_format() { |
| 335 | - return $this->format === 'text' && $this->is_plain_text === true; | |
| 309 | + return ( $this->format === 'text' && $this->is_plain_text === true ); | |
| 336 | 310 | } |
| 337 | 311 | |
| 338 | 312 | /** |
| 339 | 313 | * Check if the format is default HTML |
| @@ -342,7 +316,7 @@ | ||
| 342 | 316 | * |
| 343 | 317 | * @return bool |
| 344 | 318 | */ |
| 345 | 319 | protected function is_table_format() { |
| 346 | - return $this->format === 'text' && $this->is_plain_text === false; | |
| 320 | + return ( $this->format === 'text' && $this->is_plain_text === false ); | |
| 347 | 321 | } |
| 348 | 322 | } |