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