PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.02
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEntryShortcodeFormatter.php +22 -51 6.314.01.02 View file →
@@ -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 FrmEntryShortcodeFormatter {
10 7
11 8 /**
12 9 * @var int
13 - *
14 10 * @since 2.04
15 11 */
16 12 protected $form_id = 0;
17 13
@@ -16,9 +12,8 @@
16 12 protected $form_id = 0;
17 13
18 14 /**
19 15 * @var array
20 - *
21 16 * @since 2.04
22 17 */
23 18 protected $skip_fields = array( 'captcha', 'html' );
24 19
@@ -23,9 +18,8 @@
23 18 protected $skip_fields = array( 'captcha', 'html' );
24 19
25 20 /**
26 21 * @var array
27 - *
28 22 * @since 3.0
29 23 */
30 24 protected $single_cell_fields = array( 'html' );
31 25
@@ -30,9 +24,8 @@
30 24 protected $single_cell_fields = array( 'html' );
31 25
32 26 /**
33 27 * @var array
34 - *
35 28 * @since 2.04
36 29 */
37 30 protected $fields = array();
38 31
@@ -37,9 +30,8 @@
37 30 protected $fields = array();
38 31
39 32 /**
40 33 * @var bool
41 - *
42 34 * @since 2.05
43 35 */
44 36 protected $is_plain_text = false;
45 37
@@ -44,23 +36,20 @@
44 36 protected $is_plain_text = false;
45 37
46 38 /**
47 39 * @var string
48 - *
49 40 * @since 2.04
50 41 */
51 42 protected $format = 'text';
52 43
53 44 /**
54 - * @var FrmTableHTMLGenerator|null
55 - *
45 + * @var FrmTableHTMLGenerator
56 46 * @since 2.04
57 47 */
58 - protected $table_generator;
48 + protected $table_generator = null;
59 49
60 50 /**
61 51 * @var array
62 - *
63 52 * @since 2.04
64 53 */
65 54 protected $array_content = array();
66 55
@@ -67,9 +56,9 @@
67 56 /**
68 57 * FrmEntryShortcodeFormatter constructor
69 58 *
70 59 * @param int|string $form_id
71 - * @param array $atts
60 + * @param array $atts
72 61 */
73 62 public function __construct( $form_id, $atts ) {
74 63 if ( ! $form_id ) {
75 64 return;
@@ -77,9 +66,9 @@
77 66
78 67 $this->init_form_id( $form_id );
79 68 $this->init_fields();
80 69
81 - if ( ! $this->fields ) {
70 + if ( empty( $this->fields ) ) {
82 71 return;
83 72 }
84 73
85 74 $this->init_plain_text( $atts );
@@ -94,11 +83,9 @@
94 83 * Initialize the form_id property
95 84 *
96 85 * @since 2.04
97 86 *
98 - * @param int|string $form_id
99 - *
100 - * @return void
87 + * @param $form_id
101 88 */
102 89 protected function init_form_id( $form_id ) {
103 90 $this->form_id = (int) $form_id;
104 91 }
@@ -106,10 +93,8 @@
106 93 /**
107 94 * Initialize the fields property
108 95 *
109 96 * @since 2.04
110 - *
111 - * @return void
112 97 */
113 98 protected function init_fields() {
114 99 $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' );
115 100 }
@@ -119,13 +104,11 @@
119 104 *
120 105 * @since 2.05
121 106 *
122 107 * @param array $atts
123 - *
124 - * @return void
125 108 */
126 109 protected function init_plain_text( $atts ) {
127 - if ( ! empty( $atts['plain_text'] ) ) {
110 + if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) {
128 111 $this->is_plain_text = true;
129 112 }
130 113 }
131 114
@@ -134,10 +117,8 @@
134 117 *
135 118 * @since 2.04
136 119 *
137 120 * @param array $atts
138 - *
139 - * @return void
140 121 */
141 122 protected function init_format( $atts ) {
142 123 if ( isset( $atts['format'] ) && is_string( $atts['format'] ) && $atts['format'] !== '' ) {
143 124 $this->format = $atts['format'];
@@ -149,10 +130,8 @@
149 130 /**
150 131 * Initialize the table_generator property
151 132 *
152 133 * @since 2.04
153 - *
154 - * @return void
155 134 */
156 135 protected function init_table_generator() {
157 136 $this->table_generator = new FrmTableHTMLGenerator( 'shortcode' );
158 137 }
@@ -160,17 +139,15 @@
160 139 /**
161 140 * Return the default HTML for an entry
162 141 *
163 142 * @since 2.04
164 - *
165 - * @return array|string
166 143 */
167 144 public function content() {
168 - if ( ! $this->form_id || ! $this->fields ) {
145 + if ( ! $this->form_id || empty( $this->fields ) ) {
169 146 return '';
170 147 }
171 148
172 - if ( $this->format === 'array' ) {
149 + if ( $this->format == 'array' ) {
173 150 $content = $this->get_array();
174 151 } elseif ( $this->is_plain_text_format() ) {
175 152 $content = $this->get_plain_text();
176 153 } else {
@@ -183,10 +160,8 @@
183 160 /**
184 161 * Return the default HTML array
185 162 *
186 163 * @since 2.04
187 - *
188 - * @return array
189 164 */
190 165 protected function get_array() {
191 166 foreach ( $this->fields as $field ) {
192 167 $this->add_field_array( $field );
@@ -198,10 +173,8 @@
198 173 /**
199 174 * Return the default plain text for an email message
200 175 *
201 176 * @since 2.04
202 - *
203 - * @return string
204 177 */
205 178 protected function get_plain_text() {
206 179 return $this->generate_content_for_all_fields();
207 180 }
@@ -209,16 +182,15 @@
209 182 /**
210 183 * Return the default HTML for an email message
211 184 *
212 185 * @since 2.04
213 - *
214 - * @return string
215 186 */
216 187 protected function get_table() {
217 - $content = $this->table_generator->generate_table_header();
188 + $content = $this->table_generator->generate_table_header();
218 189 $content .= $this->generate_content_for_all_fields();
190 + $content .= $this->table_generator->generate_table_footer();
219 191
220 - return $content . $this->table_generator->generate_table_footer();
192 + return $content;
221 193 }
222 194
223 195 /**
224 196 * Generate the content for all fields
@@ -246,13 +218,15 @@
246 218 *
247 219 * @return string
248 220 */
249 221 protected function generate_field_content( $field ) {
250 - if ( in_array( $field->type, $this->skip_fields, true ) ) {
222 + if ( in_array( $field->type, $this->skip_fields ) ) {
251 223 return '';
252 224 }
253 225
254 - return $this->generate_two_cell_shortcode_row( $field );
226 + $row = $this->generate_two_cell_shortcode_row( $field );
227 +
228 + return $row;
255 229 }
256 230
257 231 /**
258 232 * Generate a two cell row of shortcodes for an HTML or plain text table
@@ -259,14 +233,15 @@
259 233 *
260 234 * @since 2.04
261 235 *
262 236 * @param stdClass $field
263 - * @param mixed $value
237 + * @param mixed $value
264 238 *
265 239 * @return string
266 240 */
267 241 protected function generate_two_cell_shortcode_row( $field, $value = null ) {
268 - $row = '[if ' . $field->id . ']';
242 + $row = '[if ' . $field->id . ']';
243 +
269 244 $label = '[' . $field->id . ' show=field_label]';
270 245
271 246 if ( $value === null ) {
272 247 $value = '[' . $field->id . ']';
@@ -292,13 +267,11 @@
292 267 *
293 268 * @since 2.04
294 269 *
295 270 * @param stdClass $field
296 - *
297 - * @return void
298 271 */
299 272 protected function add_field_array( $field ) {
300 - if ( in_array( $field->type, $this->skip_fields, true ) ) {
273 + if ( in_array( $field->type, $this->skip_fields ) ) {
301 274 return;
302 275 }
303 276
304 277 $this->add_single_field_array( $field, $field->id );
@@ -309,11 +282,9 @@
309 282 *
310 283 * @since 2.04
311 284 *
312 285 * @param stdClass $field
313 - * @param string $value
314 - *
315 - * @return void
286 + * @param string $value
316 287 */
317 288 protected function add_single_field_array( $field, $value ) {
318 289 $array = array(
319 290 'label' => '[' . $field->id . ' show=field_label]',
@@ -331,9 +302,9 @@
331 302 *
332 303 * @return bool
333 304 */
334 305 protected function is_plain_text_format() {
335 - return $this->format === 'text' && $this->is_plain_text === true;
306 + return ( $this->format === 'text' && $this->is_plain_text === true );
336 307 }
337 308
338 309 /**
339 310 * Check if the format is default HTML
@@ -342,7 +313,7 @@
342 313 *
343 314 * @return bool
344 315 */
345 316 protected function is_table_format() {
346 - return $this->format === 'text' && $this->is_plain_text === false;
317 + return ( $this->format === 'text' && $this->is_plain_text === false );
347 318 }
348 319 }