Completed
Push — master ( b3ff26...a88860 )
by Stephanie
02:55
created
classes/models/FrmMigrate.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 		return $charset_collate;
77 77
 	}
78 78
 
79
-    private function create_tables() {
80
-        $charset_collate = $this->collation();
81
-        $sql = array();
79
+	private function create_tables() {
80
+		$charset_collate = $this->collation();
81
+		$sql = array();
82 82
 
83
-        /* Create/Upgrade Fields Table */
83
+		/* Create/Upgrade Fields Table */
84 84
 		$sql[] = 'CREATE TABLE ' . $this->fields . ' (
85 85
 				id BIGINT(20) NOT NULL auto_increment,
86 86
 				field_key varchar(100) default NULL,
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 UNIQUE KEY field_key (field_key)
100 100
         )';
101 101
 
102
-        /* Create/Upgrade Forms Table */
102
+		/* Create/Upgrade Forms Table */
103 103
 		$sql[] = 'CREATE TABLE ' . $this->forms . ' (
104 104
                 id int(11) NOT NULL auto_increment,
105 105
 				form_key varchar(100) default NULL,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 UNIQUE KEY form_key (form_key)
118 118
         )';
119 119
 
120
-        /* Create/Upgrade Items Table */
120
+		/* Create/Upgrade Items Table */
121 121
 		$sql[] = 'CREATE TABLE ' . $this->entries . ' (
122 122
 				id BIGINT(20) NOT NULL auto_increment,
123 123
 				item_key varchar(100) default NULL,
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                 UNIQUE KEY item_key (item_key)
141 141
         )';
142 142
 
143
-        /* Create/Upgrade Meta Table */
143
+		/* Create/Upgrade Meta Table */
144 144
 		$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
145 145
 				id BIGINT(20) NOT NULL auto_increment,
146 146
 				meta_value longtext default NULL,
@@ -152,16 +152,16 @@  discard block
 block discarded – undo
152 152
                 KEY item_id (item_id)
153 153
         )';
154 154
 
155
-        foreach ( $sql as $q ) {
155
+		foreach ( $sql as $q ) {
156 156
 			if ( function_exists( 'dbDelta' ) ) {
157 157
 				dbDelta( $q . $charset_collate . ';' );
158 158
 			} else {
159 159
 				global $wpdb;
160 160
 				$wpdb->query( $q . $charset_collate );
161 161
 			}
162
-            unset($q);
163
-        }
164
-    }
162
+			unset($q);
163
+		}
164
+	}
165 165
 
166 166
 	private function maybe_create_contact_form() {
167 167
 		$template_id = FrmForm::getIdByKey( 'contact' );
@@ -177,45 +177,45 @@  discard block
 block discarded – undo
177 177
 		}
178 178
 	}
179 179
 
180
-    /**
181
-     * @param integer $frm_db_version
180
+	/**
181
+	 * @param integer $frm_db_version
182 182
 	 * @param int $old_db_version
183
-     */
183
+	 */
184 184
 	private function migrate_data( $frm_db_version, $old_db_version ) {
185 185
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
186
-        foreach ( $migrations as $migration ) {
187
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
186
+		foreach ( $migrations as $migration ) {
187
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
188 188
 				$function_name = 'migrate_to_' . $migration;
189
-                $this->$function_name();
190
-            }
191
-        }
192
-    }
189
+				$this->$function_name();
190
+			}
191
+		}
192
+	}
193 193
 
194
-    public function uninstall() {
194
+	public function uninstall() {
195 195
 		if ( ! current_user_can( 'administrator' ) ) {
196
-            $frm_settings = FrmAppHelper::get_settings();
197
-            wp_die($frm_settings->admin_permission);
198
-        }
196
+			$frm_settings = FrmAppHelper::get_settings();
197
+			wp_die($frm_settings->admin_permission);
198
+		}
199 199
 
200
-        global $wpdb, $wp_roles;
200
+		global $wpdb, $wp_roles;
201 201
 
202 202
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
203 203
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
204 204
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
205 205
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
206 206
 
207
-        delete_option('frm_options');
208
-        delete_option('frm_db_version');
209
-
210
-        //delete roles
211
-        $frm_roles = FrmAppHelper::frm_capabilities();
212
-        $roles = get_editable_roles();
213
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
214
-            foreach ( $roles as $role => $details ) {
215
-                $wp_roles->remove_cap( $role, $frm_role );
216
-                unset($role, $details);
217
-    		}
218
-    		unset($frm_role, $frm_role_description);
207
+		delete_option('frm_options');
208
+		delete_option('frm_db_version');
209
+
210
+		//delete roles
211
+		$frm_roles = FrmAppHelper::frm_capabilities();
212
+		$roles = get_editable_roles();
213
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
214
+			foreach ( $roles as $role => $details ) {
215
+				$wp_roles->remove_cap( $role, $frm_role );
216
+				unset($role, $details);
217
+			}
218
+			unset($frm_role, $frm_role_description);
219 219
 		}
220 220
 		unset($roles, $frm_roles);
221 221
 
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 
240 240
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
241 241
 
242
-        do_action('frm_after_uninstall');
243
-        return true;
244
-    }
242
+		do_action('frm_after_uninstall');
243
+		return true;
244
+	}
245 245
 
246 246
 	/**
247 247
 	 * Migrate old styling settings. If sites are using the old
@@ -280,14 +280,14 @@  discard block
 block discarded – undo
280 280
 		}
281 281
 	}
282 282
 
283
-    /**
284
-     * Change field size from character to pixel -- Multiply by 9
285
-     */
286
-    private function migrate_to_17() {
287
-        global $wpdb;
283
+	/**
284
+	 * Change field size from character to pixel -- Multiply by 9
285
+	 */
286
+	private function migrate_to_17() {
287
+		global $wpdb;
288 288
 		$pixel_conversion = 9;
289 289
 
290
-        // Get query arguments
290
+		// Get query arguments
291 291
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
292 292
 		$query = array(
293 293
 			'type' => $field_types,
@@ -295,139 +295,139 @@  discard block
 block discarded – undo
295 295
 			'field_options not like' => 's:4:"size";s:0:',
296 296
 		);
297 297
 
298
-        // Get results
298
+		// Get results
299 299
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
300 300
 
301
-        $updated = 0;
302
-        foreach ( $fields as $f ) {
303
-            $f->field_options = maybe_unserialize($f->field_options);
304
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
305
-                continue;
306
-            }
301
+		$updated = 0;
302
+		foreach ( $fields as $f ) {
303
+			$f->field_options = maybe_unserialize($f->field_options);
304
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
305
+				continue;
306
+			}
307 307
 
308 308
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
309
-            $f->field_options['size'] .= 'px';
310
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
311
-            if ( $u ) {
312
-                $updated++;
313
-            }
314
-            unset($f);
315
-        }
316
-
317
-        // Change the characters in widgets to pixels
318
-        $widgets = get_option('widget_frm_show_form');
319
-        if ( empty($widgets) ) {
320
-            return;
321
-        }
322
-
323
-        $widgets = maybe_unserialize($widgets);
324
-        foreach ( $widgets as $k => $widget ) {
325
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
326
-                continue;
327
-            }
309
+			$f->field_options['size'] .= 'px';
310
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
311
+			if ( $u ) {
312
+				$updated++;
313
+			}
314
+			unset($f);
315
+		}
316
+
317
+		// Change the characters in widgets to pixels
318
+		$widgets = get_option('widget_frm_show_form');
319
+		if ( empty($widgets) ) {
320
+			return;
321
+		}
322
+
323
+		$widgets = maybe_unserialize($widgets);
324
+		foreach ( $widgets as $k => $widget ) {
325
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
326
+				continue;
327
+			}
328 328
 			$size = round( $pixel_conversion * (int) $widget['size'] );
329
-            $size .= 'px';
329
+			$size .= 'px';
330 330
 			$widgets[ $k ]['size'] = $size;
331
-        }
332
-        update_option('widget_frm_show_form', $widgets);
333
-    }
334
-
335
-    /**
336
-     * Migrate post and email notification settings into actions
337
-     */
338
-    private function migrate_to_16() {
339
-        global $wpdb;
340
-
341
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
342
-
343
-        /**
344
-        * Old email settings format:
345
-        * email_to: Email or field id
346
-        * also_email_to: array of fields ids
347
-        * reply_to: Email, field id, 'custom'
348
-        * cust_reply_to: string
349
-        * reply_to_name: field id, 'custom'
350
-        * cust_reply_to_name: string
351
-        * plain_text: 0|1
352
-        * email_message: string or ''
353
-        * email_subject: string or ''
354
-        * inc_user_info: 0|1
355
-        * update_email: 0, 1, 2
356
-        *
357
-        * Old autoresponder settings format:
358
-        * auto_responder: 0|1
359
-        * ar_email_message: string or ''
360
-        * ar_email_to: field id
361
-        * ar_plain_text: 0|1
362
-        * ar_reply_to_name: string
363
-        * ar_reply_to: string
364
-        * ar_email_subject: string
365
-        * ar_update_email: 0, 1, 2
366
-        *
367
-        * New email settings:
368
-        * post_content: json settings
369
-        * post_title: form id
370
-        * post_excerpt: message
371
-        *
372
-        */
373
-
374
-        foreach ( $forms as $form ) {
331
+		}
332
+		update_option('widget_frm_show_form', $widgets);
333
+	}
334
+
335
+	/**
336
+	 * Migrate post and email notification settings into actions
337
+	 */
338
+	private function migrate_to_16() {
339
+		global $wpdb;
340
+
341
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
342
+
343
+		/**
344
+		 * Old email settings format:
345
+		 * email_to: Email or field id
346
+		 * also_email_to: array of fields ids
347
+		 * reply_to: Email, field id, 'custom'
348
+		 * cust_reply_to: string
349
+		 * reply_to_name: field id, 'custom'
350
+		 * cust_reply_to_name: string
351
+		 * plain_text: 0|1
352
+		 * email_message: string or ''
353
+		 * email_subject: string or ''
354
+		 * inc_user_info: 0|1
355
+		 * update_email: 0, 1, 2
356
+		 *
357
+		 * Old autoresponder settings format:
358
+		 * auto_responder: 0|1
359
+		 * ar_email_message: string or ''
360
+		 * ar_email_to: field id
361
+		 * ar_plain_text: 0|1
362
+		 * ar_reply_to_name: string
363
+		 * ar_reply_to: string
364
+		 * ar_email_subject: string
365
+		 * ar_update_email: 0, 1, 2
366
+		 *
367
+		 * New email settings:
368
+		 * post_content: json settings
369
+		 * post_title: form id
370
+		 * post_excerpt: message
371
+		 *
372
+		 */
373
+
374
+		foreach ( $forms as $form ) {
375 375
 			if ( $form->is_template && $form->default_template ) {
376 376
 				// don't migrate the default templates since the email will be added anyway
377 377
 				continue;
378 378
 			}
379 379
 
380
-            // Format form options
381
-            $form_options = maybe_unserialize($form->options);
380
+			// Format form options
381
+			$form_options = maybe_unserialize($form->options);
382 382
 
383
-            // Migrate settings to actions
384
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
385
-        }
386
-    }
383
+			// Migrate settings to actions
384
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
385
+		}
386
+	}
387 387
 
388
-    private function migrate_to_11() {
389
-        global $wpdb;
388
+	private function migrate_to_11() {
389
+		global $wpdb;
390 390
 
391
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
391
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
392 392
 
393
-        $sending = __( 'Sending', 'formidable' );
393
+		$sending = __( 'Sending', 'formidable' );
394 394
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
395
-        $old_default_html = <<<DEFAULT_HTML
395
+		$old_default_html = <<<DEFAULT_HTML
396 396
 <div class="frm_submit">
397 397
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
398 398
 <input type="submit" value="[button_label]" [button_action] />
399 399
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
400 400
 </div>
401 401
 DEFAULT_HTML;
402
-        unset($sending, $img);
402
+		unset($sending, $img);
403 403
 
404
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
405
-        $draft_link = FrmFormsHelper::get_draft_link();
404
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
405
+		$draft_link = FrmFormsHelper::get_draft_link();
406 406
 		foreach ( $forms as $form ) {
407
-            $form->options = maybe_unserialize($form->options);
408
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
409
-                continue;
410
-            }
407
+			$form->options = maybe_unserialize($form->options);
408
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
409
+				continue;
410
+			}
411 411
 
412
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
413
-                $form->options['submit_html'] = $new_default_html;
412
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
413
+				$form->options['submit_html'] = $new_default_html;
414 414
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
415 415
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
416 416
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
417 417
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
418
-            }
419
-            unset($form);
420
-        }
421
-        unset($forms);
422
-    }
418
+			}
419
+			unset($form);
420
+		}
421
+		unset($forms);
422
+	}
423 423
 
424
-    private function migrate_to_6() {
425
-        global $wpdb;
424
+	private function migrate_to_6() {
425
+		global $wpdb;
426 426
 
427 427
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
428 428
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
429 429
 
430
-        $default_html = <<<DEFAULT_HTML
430
+		$default_html = <<<DEFAULT_HTML
431 431
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
432 432
     <label class="frm_pos_[label_position]">[field_name]
433 433
         <span class="frm_required">[required_label]</span>
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 </div>
438 438
 DEFAULT_HTML;
439 439
 
440
-        $old_default_html = <<<DEFAULT_HTML
440
+		$old_default_html = <<<DEFAULT_HTML
441 441
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
442 442
     <label class="frm_pos_[label_position]">[field_name]
443 443
         <span class="frm_required">[required_label]</span>
@@ -447,24 +447,24 @@  discard block
 block discarded – undo
447 447
 </div>
448 448
 DEFAULT_HTML;
449 449
 
450
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
451
-        foreach ( $fields as $field ) {
452
-            $field->field_options = maybe_unserialize($field->field_options);
450
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
451
+		foreach ( $fields as $field ) {
452
+			$field->field_options = maybe_unserialize($field->field_options);
453 453
 			$html = FrmField::get_option( $field, 'custom_html' );
454 454
 			if ( $html == $default_html || $html == $old_default_html ) {
455
-                $field->field_options['custom_html'] = $new_default_html;
455
+				$field->field_options['custom_html'] = $new_default_html;
456 456
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
457
-            }
458
-            unset($field);
459
-        }
460
-        unset($default_html, $old_default_html, $fields);
461
-    }
462
-
463
-    private function migrate_to_4() {
464
-        global $wpdb;
457
+			}
458
+			unset($field);
459
+		}
460
+		unset($default_html, $old_default_html, $fields);
461
+	}
462
+
463
+	private function migrate_to_4() {
464
+		global $wpdb;
465 465
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
466
-        foreach ( $user_ids as $user_id ) {
466
+		foreach ( $user_ids as $user_id ) {
467 467
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
468
-        }
469
-    }
468
+		}
469
+	}
470 470
 }
Please login to merge, or discard this patch.
classes/models/FrmForm.php 2 patches
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -1,176 +1,176 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
3
+	die('You are not allowed to call this page directly.');
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14
-        $new_values = array(
14
+		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
-            'name'          => $values['name'],
17
-            'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
16
+			'name'          => $values['name'],
17
+			'description'   => $values['description'],
18
+			'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
+			'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
+			'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
-        );
22
+			'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
+			'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
+			'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
+		);
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
+		$options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
35
+		$new_values['options'] = serialize($options);
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
73
-
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
83
-
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
86
-        }
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70
+			'created_at'    => current_time('mysql', 1),
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73
+
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76
+			$new_options = maybe_unserialize($values->options);
77
+			$new_options['email_to'] = get_option('admin_email');
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83
+
84
+		if ( is_array($new_values['options']) ) {
85
+			$new_values['options'] = serialize($new_values['options']);
86
+		}
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
+			$form_id = $wpdb->insert_id;
95
+			FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
-        }
109
+		if ( isset($new_opts['success_msg']) ) {
110
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
111
+		}
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
114 114
 
115
-        if ( $new_opts != $values['options'] ) {
116
-            global $wpdb;
115
+		if ( $new_opts != $values['options'] ) {
116
+			global $wpdb;
117 117
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
118
-        }
119
-    }
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * @return int|boolean
123
-     */
124
-    public static function update( $id, $values, $create_link = false ) {
125
-        global $wpdb;
121
+	/**
122
+	 * @return int|boolean
123
+	 */
124
+	public static function update( $id, $values, $create_link = false ) {
125
+		global $wpdb;
126 126
 
127
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
-            $values['status'] = 'published';
129
-        }
127
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
128
+			$values['status'] = 'published';
129
+		}
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+		if ( isset($values['form_key']) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133
-        }
133
+		}
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+		$new_values = self::set_update_options( array(), $values);
138 138
 
139
-        foreach ( $values as $value_key => $value ) {
139
+		foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141 141
 				$new_values[ $value_key ] = $value;
142
-            }
143
-        }
142
+			}
143
+		}
144 144
 
145
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
-            $new_values['status'] = $values['new_status'];
147
-        }
145
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
146
+			$new_values['status'] = $values['new_status'];
147
+		}
148 148
 
149
-        if ( ! empty( $new_values ) ) {
149
+		if ( ! empty( $new_values ) ) {
150 150
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
151
-            if ( $query_results ) {
151
+			if ( $query_results ) {
152 152
 				self::clear_form_cache();
153
-            }
154
-        } else {
155
-            $query_results = true;
156
-        }
157
-        unset($new_values);
153
+			}
154
+		} else {
155
+			$query_results = true;
156
+		}
157
+		unset($new_values);
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+		$values = self::update_fields($id, $values);
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
163 163
 
164
-        return $query_results;
165
-    }
164
+		return $query_results;
165
+	}
166 166
 
167
-    /**
168
-     * @return array
169
-     */
167
+	/**
168
+	 * @return array
169
+	 */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
172
-            return $new_values;
173
-        }
171
+		if ( ! isset($values['options']) ) {
172
+			return $new_values;
173
+		}
174 174
 
175 175
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
176 176
 		FrmFormsHelper::fill_form_options( $options, $values );
@@ -184,79 +184,79 @@  discard block
 block discarded – undo
184 184
 		$new_values['options'] = serialize( $options );
185 185
 
186 186
 		return $new_values;
187
-    }
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @return array
192
-     */
190
+	/**
191
+	 * @return array
192
+	 */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
-            return $values;
197
-        }
195
+		if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
196
+			return $values;
197
+		}
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
201
-            return $values;
202
-        }
199
+		$all_fields = FrmField::get_all_for_form($id);
200
+		if ( empty($all_fields) ) {
201
+			return $values;
202
+		}
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
205
-            $values['item_meta'] = array();
206
-        }
204
+		if ( ! isset($values['item_meta']) ) {
205
+			$values['item_meta'] = array();
206
+		}
207 207
 
208
-        $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
210
-        foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
208
+		$field_array = array();
209
+		$existing_keys = array_keys($values['item_meta']);
210
+		foreach ( $all_fields as $fid ) {
211
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212 212
 				$values['item_meta'][ $fid->id ] = '';
213
-            }
213
+			}
214 214
 			$field_array[ $fid->id ] = $fid;
215
-        }
216
-        unset($all_fields);
215
+		}
216
+		unset($all_fields);
217 217
 
218
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
219 219
 			if ( isset( $field_array[ $field_id ] ) ) {
220 220
 				$field = $field_array[ $field_id ];
221
-            } else {
222
-                $field = FrmField::getOne($field_id);
223
-            }
221
+			} else {
222
+				$field = FrmField::getOne($field_id);
223
+			}
224 224
 
225
-            if ( ! $field ) {
226
-                continue;
227
-            }
225
+			if ( ! $field ) {
226
+				continue;
227
+			}
228 228
 
229 229
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
230 230
 			if ( $is_settings_page ) {
231
-                //updating the settings page
231
+				//updating the settings page
232 232
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233 233
 					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
234
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
-                    $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
-                    if ( $prev_opts != $field->field_options ) {
236
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237
+					$prev_opts = $field->field_options;
238
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
239
+					if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241
-                    }
242
-                    unset($prev_opts);
243
-                }
244
-            }
241
+					}
242
+					unset($prev_opts);
243
+				}
244
+			}
245 245
 
246 246
 			if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) {
247
-                continue;
248
-            }
247
+				continue;
248
+			}
249 249
 
250
-            //updating the form
250
+			//updating the form
251 251
 			$update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true );
252 252
 			unset( $update_options['custom_html'] ); // don't check for POST html
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256 256
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
257
-            }
257
+			}
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260 260
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
261 261
 
262 262
 			$new_field = array(
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
272
-        }
271
+			FrmField::delete_form_transient($field->form_id);
272
+		}
273 273
 		self::clear_form_cache();
274 274
 
275
-        return $values;
276
-    }
275
+		return $values;
276
+	}
277 277
 
278 278
 	private static function prepare_field_update_values( $field, $values, &$new_field ) {
279 279
 		$field_cols = array(
@@ -289,23 +289,23 @@  discard block
 block discarded – undo
289 289
 		}
290 290
 	}
291 291
 
292
-    /**
293
-     * @param string $status
294
-     * @return int|boolean
295
-     */
292
+	/**
293
+	 * @param string $status
294
+	 * @return int|boolean
295
+	 */
296 296
 	public static function set_status( $id, $status ) {
297
-        if ( 'trash' == $status ) {
298
-            return self::trash($id);
299
-        }
297
+		if ( 'trash' == $status ) {
298
+			return self::trash($id);
299
+		}
300 300
 
301 301
 		$statuses  = array( 'published', 'draft', 'trash' );
302
-        if ( ! in_array( $status, $statuses ) ) {
303
-            return false;
304
-        }
302
+		if ( ! in_array( $status, $statuses ) ) {
303
+			return false;
304
+		}
305 305
 
306
-        global $wpdb;
306
+		global $wpdb;
307 307
 
308
-        if ( is_array($id) ) {
308
+		if ( is_array($id) ) {
309 309
 			$where = array(
310 310
 				'id' => $id,
311 311
 				'parent_form_id' => $id,
@@ -315,33 +315,33 @@  discard block
 block discarded – undo
315 315
 			array_unshift( $where['values'], $status );
316 316
 
317 317
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
318
-        } else {
318
+		} else {
319 319
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
320 320
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
321
-        }
321
+		}
322 322
 
323
-        if ( $query_results ) {
323
+		if ( $query_results ) {
324 324
 			self::clear_form_cache();
325
-        }
325
+		}
326 326
 
327
-        return $query_results;
328
-    }
327
+		return $query_results;
328
+	}
329 329
 
330
-    /**
331
-     * @return int|boolean
332
-     */
330
+	/**
331
+	 * @return int|boolean
332
+	 */
333 333
 	public static function trash( $id ) {
334
-        if ( ! EMPTY_TRASH_DAYS ) {
335
-            return self::destroy( $id );
336
-        }
334
+		if ( ! EMPTY_TRASH_DAYS ) {
335
+			return self::destroy( $id );
336
+		}
337 337
 
338
-        $form = self::getOne($id);
339
-        if ( ! $form ) {
340
-            return false;
341
-        }
338
+		$form = self::getOne($id);
339
+		if ( ! $form ) {
340
+			return false;
341
+		}
342 342
 
343
-        $options = $form->options;
344
-        $options['trash_time'] = time();
343
+		$options = $form->options;
344
+		$options['trash_time'] = time();
345 345
 
346 346
 		global $wpdb;
347 347
 		$query_results = $wpdb->update(
@@ -366,50 +366,50 @@  discard block
 block discarded – undo
366 366
 			)
367 367
 		);
368 368
 
369
-        if ( $query_results ) {
369
+		if ( $query_results ) {
370 370
 			self::clear_form_cache();
371
-        }
371
+		}
372 372
 
373
-        return $query_results;
374
-    }
373
+		return $query_results;
374
+	}
375 375
 
376
-    /**
377
-     * @return int|boolean
378
-     */
376
+	/**
377
+	 * @return int|boolean
378
+	 */
379 379
 	public static function destroy( $id ) {
380
-        global $wpdb;
380
+		global $wpdb;
381 381
 
382
-        $form = self::getOne($id);
383
-        if ( ! $form ) {
384
-            return false;
385
-        }
382
+		$form = self::getOne($id);
383
+		if ( ! $form ) {
384
+			return false;
385
+		}
386 386
 		$id = $form->id;
387 387
 
388
-        // Disconnect the entries from this form
388
+		// Disconnect the entries from this form
389 389
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
390
-        foreach ( $entries as $entry_id ) {
391
-            FrmEntry::destroy($entry_id);
392
-            unset($entry_id);
393
-        }
390
+		foreach ( $entries as $entry_id ) {
391
+			FrmEntry::destroy($entry_id);
392
+			unset($entry_id);
393
+		}
394 394
 
395
-        // Disconnect the fields from this form
395
+		// Disconnect the fields from this form
396 396
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
397 397
 
398 398
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
399
-        if ( $query_results ) {
400
-            // Delete all form actions linked to this form
401
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
402
-            $action_control->destroy($id, 'all');
399
+		if ( $query_results ) {
400
+			// Delete all form actions linked to this form
401
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
402
+			$action_control->destroy($id, 'all');
403 403
 
404 404
 			// Clear form caching
405 405
 			self::clear_form_cache();
406 406
 
407 407
 			do_action( 'frm_destroy_form', $id );
408 408
 			do_action( 'frm_destroy_form_' . $id );
409
-        }
409
+		}
410 410
 
411
-        return $query_results;
412
-    }
411
+		return $query_results;
412
+	}
413 413
 
414 414
 	/**
415 415
 	 * Delete trashed forms based on how long they have been trashed
@@ -441,46 +441,46 @@  discard block
 block discarded – undo
441 441
 		return $count;
442 442
 	}
443 443
 
444
-    /**
445
-     * @return string form name
446
-     */
447
-    public static function getName( $id ) {
444
+	/**
445
+	 * @return string form name
446
+	 */
447
+	public static function getName( $id ) {
448 448
 		$form = FrmDb::check_cache( $id, 'frm_form' );
449
-        if ( $form ) {
450
-            $r = stripslashes($form->name);
451
-            return $r;
452
-        }
453
-
454
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
455
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
456
-        $r = stripslashes($r);
457
-
458
-        return $r;
459
-    }
460
-
461
-    /**
462
-     * @param string $key
463
-     * @return int form id
464
-     */
449
+		if ( $form ) {
450
+			$r = stripslashes($form->name);
451
+			return $r;
452
+		}
453
+
454
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
455
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
456
+		$r = stripslashes($r);
457
+
458
+		return $r;
459
+	}
460
+
461
+	/**
462
+	 * @param string $key
463
+	 * @return int form id
464
+	 */
465 465
 	public static function getIdByKey( $key ) {
466 466
 		return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
467
-    }
467
+	}
468 468
 
469
-    /**
470
-     * @param int $id
471
-     * @return string form key
472
-     */
469
+	/**
470
+	 * @param int $id
471
+	 * @return string form key
472
+	 */
473 473
 	public static function getKeyById( $id ) {
474
-        $id = (int) $id;
474
+		$id = (int) $id;
475 475
 		$cache = FrmDb::check_cache( $id, 'frm_form' );
476
-        if ( $cache ) {
477
-            return $cache->form_key;
478
-        }
476
+		if ( $cache ) {
477
+			return $cache->form_key;
478
+		}
479 479
 
480
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
480
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
481 481
 
482
-        return $key;
483
-    }
482
+		return $key;
483
+	}
484 484
 
485 485
 	/**
486 486
 	 * If $form is numeric, get the form object
@@ -493,47 +493,47 @@  discard block
 block discarded – undo
493 493
 		}
494 494
 	}
495 495
 
496
-    /**
497
-     * @return object form
498
-     */
499
-    public static function getOne( $id, $blog_id = false ) {
500
-        global $wpdb;
496
+	/**
497
+	 * @return object form
498
+	 */
499
+	public static function getOne( $id, $blog_id = false ) {
500
+		global $wpdb;
501 501
 
502
-        if ( $blog_id && is_multisite() ) {
503
-            global $wpmuBaseTablePrefix;
502
+		if ( $blog_id && is_multisite() ) {
503
+			global $wpmuBaseTablePrefix;
504 504
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
505 505
 
506 506
 			$table_name = $prefix . 'frm_forms';
507
-        } else {
507
+		} else {
508 508
 			$table_name = $wpdb->prefix . 'frm_forms';
509
-            $cache = wp_cache_get($id, 'frm_form');
510
-            if ( $cache ) {
511
-                if ( isset($cache->options) ) {
512
-                    $cache->options = maybe_unserialize($cache->options);
513
-                }
509
+			$cache = wp_cache_get($id, 'frm_form');
510
+			if ( $cache ) {
511
+				if ( isset($cache->options) ) {
512
+					$cache->options = maybe_unserialize($cache->options);
513
+				}
514 514
 
515
-                return stripslashes_deep($cache);
516
-            }
517
-        }
515
+				return stripslashes_deep($cache);
516
+			}
517
+		}
518 518
 
519
-        if ( is_numeric($id) ) {
520
-            $where = array( 'id' => $id );
521
-        } else {
522
-            $where = array( 'form_key' => $id );
523
-        }
519
+		if ( is_numeric($id) ) {
520
+			$where = array( 'id' => $id );
521
+		} else {
522
+			$where = array( 'form_key' => $id );
523
+		}
524 524
 
525
-        $results = FrmDb::get_row( $table_name, $where );
525
+		$results = FrmDb::get_row( $table_name, $where );
526 526
 
527
-        if ( isset($results->options) ) {
527
+		if ( isset($results->options) ) {
528 528
 			FrmDb::set_cache( $results->id, $results, 'frm_form' );
529
-            $results->options = maybe_unserialize($results->options);
530
-        }
531
-        return stripslashes_deep($results);
532
-    }
533
-
534
-    /**
535
-     * @return object|array of objects
536
-     */
529
+			$results->options = maybe_unserialize($results->options);
530
+		}
531
+		return stripslashes_deep($results);
532
+	}
533
+
534
+	/**
535
+	 * @return object|array of objects
536
+	 */
537 537
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
538 538
 		if ( is_array( $where ) && ! empty( $where ) ) {
539 539
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array(
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 			$results = reset( $results );
561 561
 		}
562 562
 
563
-        return stripslashes_deep($results);
564
-    }
563
+		return stripslashes_deep($results);
564
+	}
565 565
 
566 566
 	/**
567 567
 	 * Get all published forms
@@ -579,18 +579,18 @@  discard block
 block discarded – undo
579 579
 		return $forms;
580 580
 	}
581 581
 
582
-    /**
583
-     * @return int count of forms
584
-     */
585
-    public static function get_count() {
586
-    	global $wpdb;
582
+	/**
583
+	 * @return int count of forms
584
+	 */
585
+	public static function get_count() {
586
+		global $wpdb;
587 587
 
588
-    	$cache_key = 'frm_form_counts';
588
+		$cache_key = 'frm_form_counts';
589 589
 
590
-    	$counts = wp_cache_get( $cache_key, 'frm_form' );
591
-    	if ( false !== $counts ) {
592
-    	    return $counts;
593
-    	}
590
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
591
+		if ( false !== $counts ) {
592
+			return $counts;
593
+		}
594 594
 
595 595
 		$results = (array) FrmDb::get_results( 'frm_forms', array(
596 596
 			'or' => 1,
@@ -599,31 +599,31 @@  discard block
 block discarded – undo
599 599
 		), 'status, is_template' );
600 600
 
601 601
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
602
-    	$counts = array_fill_keys( $statuses, 0 );
602
+		$counts = array_fill_keys( $statuses, 0 );
603 603
 
604
-    	foreach ( $results as $row ) {
605
-            if ( 'trash' != $row->status ) {
606
-    	        if ( $row->is_template ) {
604
+		foreach ( $results as $row ) {
605
+			if ( 'trash' != $row->status ) {
606
+				if ( $row->is_template ) {
607 607
 					$counts['template']++;
608
-    	        } else {
608
+				} else {
609 609
 					$counts['published']++;
610
-    	        }
611
-    	    } else {
610
+				}
611
+			} else {
612 612
 				$counts['trash']++;
613
-        	}
613
+			}
614 614
 
615
-    	    if ( 'draft' == $row->status ) {
615
+			if ( 'draft' == $row->status ) {
616 616
 				$counts['draft']++;
617
-    	    }
617
+			}
618 618
 
619
-    		unset($row);
620
-    	}
619
+			unset($row);
620
+		}
621 621
 
622
-    	$counts = (object) $counts;
622
+		$counts = (object) $counts;
623 623
 		FrmDb::set_cache( $cache_key, $counts, 'frm_form' );
624 624
 
625
-    	return $counts;
626
-    }
625
+		return $counts;
626
+	}
627 627
 
628 628
 	/**
629 629
 	 * Clear form caching
@@ -636,14 +636,14 @@  discard block
 block discarded – undo
636 636
 		FrmDb::cache_delete_group( 'frm_form' );
637 637
 	}
638 638
 
639
-    /**
640
-     * @return array of errors
641
-     */
639
+	/**
640
+	 * @return array of errors
641
+	 */
642 642
 	public static function validate( $values ) {
643
-        $errors = array();
643
+		$errors = array();
644 644
 
645
-        return apply_filters('frm_validate_form', $errors, $values);
646
-    }
645
+		return apply_filters('frm_validate_form', $errors, $values);
646
+	}
647 647
 
648 648
 	public static function get_params( $form = null ) {
649 649
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16 16
             'name'          => $values['name'],
17 17
             'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
18
+            'status'        => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+            'logged_in'     => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+            'is_template'   => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
22
+            'editable'      => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+            'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0,
24
+            'created_at'    => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
25 25
         );
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
31
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
32
+        $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
35
+        $new_values['options'] = serialize( $options );
36 36
 
37 37
         //if(isset($values['id']) && is_numeric($values['id']))
38 38
         //    $new_values['id'] = $values['id'];
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
             'status'        => $template ? 'published' : 'draft',
68 68
             'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69 69
             'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
70
+            'created_at'    => current_time( 'mysql', 1 ),
71 71
             'is_template'   => $template ? 1 : 0,
72 72
         );
73 73
 
74 74
         if ( $blog_id ) {
75 75
             $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
76
+            $new_options = maybe_unserialize( $values->options );
77
+            $new_options['email_to'] = get_option( 'admin_email' );
78 78
             $new_options['copy'] = false;
79 79
             $new_values['options'] = $new_options;
80 80
         } else {
81 81
             $new_values['options'] = $values->options;
82 82
         }
83 83
 
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
84
+        if ( is_array( $new_values['options'] ) ) {
85
+            $new_values['options'] = serialize( $new_values['options'] );
86 86
         }
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			self::clear_form_cache();
93 93
 
94 94
             $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+            FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97 97
             // update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 		$new_opts = maybe_unserialize( $values['options'] );
107 107
 		$values['options'] = $new_opts;
108 108
 
109
-        if ( isset($new_opts['success_msg']) ) {
110
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
109
+        if ( isset( $new_opts['success_msg'] ) ) {
110
+            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] );
111 111
         }
112 112
 
113
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113
+        $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
114 114
 
115 115
         if ( $new_opts != $values['options'] ) {
116 116
             global $wpdb;
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
             $values['status'] = 'published';
129 129
         }
130 130
 
131
-        if ( isset($values['form_key']) ) {
131
+        if ( isset( $values['form_key'] ) ) {
132 132
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
133 133
         }
134 134
 
135 135
 		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
136 136
 
137
-        $new_values = self::set_update_options( array(), $values);
137
+        $new_values = self::set_update_options( array(), $values );
138 138
 
139 139
         foreach ( $values as $value_key => $value ) {
140 140
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
141
-				$new_values[ $value_key ] = $value;
141
+				$new_values[$value_key] = $value;
142 142
             }
143 143
         }
144 144
 
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
         } else {
155 155
             $query_results = true;
156 156
         }
157
-        unset($new_values);
157
+        unset( $new_values );
158 158
 
159
-        $values = self::update_fields($id, $values);
159
+        $values = self::update_fields( $id, $values );
160 160
 
161 161
 		do_action( 'frm_update_form', $id, $values );
162 162
 		do_action( 'frm_update_form_' . $id, $values );
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      * @return array
169 169
      */
170 170
 	public static function set_update_options( $new_values, $values ) {
171
-        if ( ! isset($values['options']) ) {
171
+        if ( ! isset( $values['options'] ) ) {
172 172
             return $new_values;
173 173
         }
174 174
 
@@ -192,54 +192,54 @@  discard block
 block discarded – undo
192 192
      */
193 193
 	public static function update_fields( $id, $values ) {
194 194
 
195
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+        if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
196 196
             return $values;
197 197
         }
198 198
 
199
-        $all_fields = FrmField::get_all_for_form($id);
200
-        if ( empty($all_fields) ) {
199
+        $all_fields = FrmField::get_all_for_form( $id );
200
+        if ( empty( $all_fields ) ) {
201 201
             return $values;
202 202
         }
203 203
 
204
-        if ( ! isset($values['item_meta']) ) {
204
+        if ( ! isset( $values['item_meta'] ) ) {
205 205
             $values['item_meta'] = array();
206 206
         }
207 207
 
208 208
         $field_array = array();
209
-        $existing_keys = array_keys($values['item_meta']);
209
+        $existing_keys = array_keys( $values['item_meta'] );
210 210
         foreach ( $all_fields as $fid ) {
211
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
212
-				$values['item_meta'][ $fid->id ] = '';
211
+            if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
212
+				$values['item_meta'][$fid->id] = '';
213 213
             }
214
-			$field_array[ $fid->id ] = $fid;
214
+			$field_array[$fid->id] = $fid;
215 215
         }
216
-        unset($all_fields);
216
+        unset( $all_fields );
217 217
 
218 218
         foreach ( $values['item_meta'] as $field_id => $default_value ) {
219
-			if ( isset( $field_array[ $field_id ] ) ) {
220
-				$field = $field_array[ $field_id ];
219
+			if ( isset( $field_array[$field_id] ) ) {
220
+				$field = $field_array[$field_id];
221 221
             } else {
222
-                $field = FrmField::getOne($field_id);
222
+                $field = FrmField::getOne( $field_id );
223 223
             }
224 224
 
225 225
             if ( ! $field ) {
226 226
                 continue;
227 227
             }
228 228
 
229
-			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229
+			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) );
230 230
 			if ( $is_settings_page ) {
231 231
                 //updating the settings page
232
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
233
-					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
232
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
233
+					$field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
234
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
235 235
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
236 236
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
237 237
                     $prev_opts = $field->field_options;
238
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
239 239
                     if ( $prev_opts != $field->field_options ) {
240 240
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
241 241
                     }
242
-                    unset($prev_opts);
242
+                    unset( $prev_opts );
243 243
                 }
244 244
             }
245 245
 
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
254 254
 
255 255
 			foreach ( $update_options as $opt => $default ) {
256
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
256
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default;
257 257
             }
258 258
 
259
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
260
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
259
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
260
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
261 261
 
262 262
 			$new_field = array(
263 263
 				'field_options' => $field->field_options,
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 			FrmField::update( $field_id, $new_field );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
271
+            FrmField::delete_form_transient( $field->form_id );
272 272
         }
273 273
 		self::clear_form_cache();
274 274
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		);
286 286
 		foreach ( $field_cols as $col => $default ) {
287 287
 			$default = ( $default === '' ) ? $field->{$col} : $default;
288
-			$new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default;
288
+			$new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default;
289 289
 		}
290 290
 	}
291 291
 
@@ -295,17 +295,17 @@  discard block
 block discarded – undo
295 295
      */
296 296
 	public static function set_status( $id, $status ) {
297 297
         if ( 'trash' == $status ) {
298
-            return self::trash($id);
298
+            return self::trash( $id );
299 299
         }
300 300
 
301
-		$statuses  = array( 'published', 'draft', 'trash' );
301
+		$statuses = array( 'published', 'draft', 'trash' );
302 302
         if ( ! in_array( $status, $statuses ) ) {
303 303
             return false;
304 304
         }
305 305
 
306 306
         global $wpdb;
307 307
 
308
-        if ( is_array($id) ) {
308
+        if ( is_array( $id ) ) {
309 309
 			$where = array(
310 310
 				'id' => $id,
311 311
 				'parent_form_id' => $id,
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
             return self::destroy( $id );
336 336
         }
337 337
 
338
-        $form = self::getOne($id);
338
+        $form = self::getOne( $id );
339 339
         if ( ! $form ) {
340 340
             return false;
341 341
         }
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 	public static function destroy( $id ) {
380 380
         global $wpdb;
381 381
 
382
-        $form = self::getOne($id);
382
+        $form = self::getOne( $id );
383 383
         if ( ! $form ) {
384 384
             return false;
385 385
         }
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
         // Disconnect the entries from this form
389 389
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
390 390
         foreach ( $entries as $entry_id ) {
391
-            FrmEntry::destroy($entry_id);
392
-            unset($entry_id);
391
+            FrmEntry::destroy( $entry_id );
392
+            unset( $entry_id );
393 393
         }
394 394
 
395 395
         // Disconnect the fields from this form
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
         if ( $query_results ) {
400 400
             // Delete all form actions linked to this form
401 401
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
402
-            $action_control->destroy($id, 'all');
402
+            $action_control->destroy( $id, 'all' );
403 403
 
404 404
 			// Clear form caching
405 405
 			self::clear_form_cache();
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 			$form->options = maybe_unserialize( $form->options );
434 434
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
435 435
 				self::destroy( $form->id );
436
-				$count++;
436
+				$count ++;
437 437
 			}
438 438
 
439 439
 			unset( $form );
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
     public static function getName( $id ) {
448 448
 		$form = FrmDb::check_cache( $id, 'frm_form' );
449 449
         if ( $form ) {
450
-            $r = stripslashes($form->name);
450
+            $r = stripslashes( $form->name );
451 451
             return $r;
452 452
         }
453 453
 
454 454
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
455 455
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
456
-        $r = stripslashes($r);
456
+        $r = stripslashes( $r );
457 457
 
458 458
         return $r;
459 459
     }
@@ -506,17 +506,17 @@  discard block
 block discarded – undo
506 506
 			$table_name = $prefix . 'frm_forms';
507 507
         } else {
508 508
 			$table_name = $wpdb->prefix . 'frm_forms';
509
-            $cache = wp_cache_get($id, 'frm_form');
509
+            $cache = wp_cache_get( $id, 'frm_form' );
510 510
             if ( $cache ) {
511
-                if ( isset($cache->options) ) {
512
-                    $cache->options = maybe_unserialize($cache->options);
511
+                if ( isset( $cache->options ) ) {
512
+                    $cache->options = maybe_unserialize( $cache->options );
513 513
                 }
514 514
 
515
-                return stripslashes_deep($cache);
515
+                return stripslashes_deep( $cache );
516 516
             }
517 517
         }
518 518
 
519
-        if ( is_numeric($id) ) {
519
+        if ( is_numeric( $id ) ) {
520 520
             $where = array( 'id' => $id );
521 521
         } else {
522 522
             $where = array( 'form_key' => $id );
@@ -524,11 +524,11 @@  discard block
 block discarded – undo
524 524
 
525 525
         $results = FrmDb::get_row( $table_name, $where );
526 526
 
527
-        if ( isset($results->options) ) {
527
+        if ( isset( $results->options ) ) {
528 528
 			FrmDb::set_cache( $results->id, $results, 'frm_form' );
529
-            $results->options = maybe_unserialize($results->options);
529
+            $results->options = maybe_unserialize( $results->options );
530 530
         }
531
-        return stripslashes_deep($results);
531
+        return stripslashes_deep( $results );
532 532
     }
533 533
 
534 534
     /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
 			$results = reset( $results );
561 561
 		}
562 562
 
563
-        return stripslashes_deep($results);
563
+        return stripslashes_deep( $results );
564 564
     }
565 565
 
566 566
 	/**
@@ -604,19 +604,19 @@  discard block
 block discarded – undo
604 604
     	foreach ( $results as $row ) {
605 605
             if ( 'trash' != $row->status ) {
606 606
     	        if ( $row->is_template ) {
607
-					$counts['template']++;
607
+					$counts['template'] ++;
608 608
     	        } else {
609
-					$counts['published']++;
609
+					$counts['published'] ++;
610 610
     	        }
611 611
     	    } else {
612
-				$counts['trash']++;
612
+				$counts['trash'] ++;
613 613
         	}
614 614
 
615 615
     	    if ( 'draft' == $row->status ) {
616
-				$counts['draft']++;
616
+				$counts['draft'] ++;
617 617
     	    }
618 618
 
619
-    		unset($row);
619
+    		unset( $row );
620 620
     	}
621 621
 
622 622
     	$counts = (object) $counts;
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 	public static function validate( $values ) {
643 643
         $errors = array();
644 644
 
645
-        return apply_filters('frm_validate_form', $errors, $values);
645
+        return apply_filters( 'frm_validate_form', $errors, $values );
646 646
     }
647 647
 
648 648
 	public static function get_params( $form = null ) {
@@ -654,11 +654,11 @@  discard block
 block discarded – undo
654 654
 			self::maybe_get_form( $form );
655 655
 		}
656 656
 
657
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
658
-			return $frm_vars['form_params'][ $form->id ];
657
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
658
+			return $frm_vars['form_params'][$form->id];
659 659
 		}
660 660
 
661
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
661
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
662 662
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
663 663
 
664 664
 		$default_values = array(
@@ -684,15 +684,15 @@  discard block
 block discarded – undo
684 684
 			//if there are two forms on the same page, make sure not to submit both
685 685
 			foreach ( $default_values as $var => $default ) {
686 686
 				if ( $var == 'action' ) {
687
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
687
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
688 688
 				} else {
689
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
689
+					$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
690 690
 				}
691 691
 				unset( $var, $default );
692 692
 			}
693 693
 		} else {
694 694
 			foreach ( $default_values as $var => $default ) {
695
-				$values[ $var ] = $default;
695
+				$values[$var] = $default;
696 696
 				unset( $var, $default );
697 697
 			}
698 698
 		}
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 			'sdir'   => '',
717 717
 		);
718 718
 		foreach ( $defaults as $var => $default ) {
719
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
719
+			$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
720 720
 		}
721 721
 
722 722
 		return $values;
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 			'keep_post' => '',
745 745
 		);
746 746
 		foreach ( $defaults as $var => $default ) {
747
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
747
+			$values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
748 748
 		}
749 749
 
750 750
 		return $values;
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 		$small_form = new stdClass();
802 802
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
803 803
 			$small_form->{$var} = $form->{$var};
804
-			unset($var);
804
+			unset( $var );
805 805
 		}
806 806
 
807 807
 		$frm_vars['forms_loaded'][] = $small_form;
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 			$frm_vars['load_css'] = true;
812 812
 		}
813 813
 
814
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
814
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
815 815
 	}
816 816
 
817 817
 	public static function show_submit( $form ) {
@@ -825,6 +825,6 @@  discard block
 block discarded – undo
825 825
 	 */
826 826
 	public static function get_option( $atts ) {
827 827
 		$form = $atts['form'];
828
-		return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default'];
828
+		return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default'];
829 829
 	}
830 830
 }
Please login to merge, or discard this patch.
classes/models/FrmCreateFile.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
 		$this->file_name = $atts['file_name'];
19 19
 		$this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : '';
20 20
 		$this->uploads = wp_upload_dir();
21
-		$this->chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
22
-		$this->chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
21
+		$this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
22
+		$this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
23 23
 	}
24 24
 
25 25
 	public function create_file( $file_content ) {
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
 			'username' => '',
89 89
 		) );
90 90
 
91
-		$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : $credentials['hostname'];
92
-		$credentials['username'] = defined('FTP_USER') ? FTP_USER : $credentials['username'];
93
-		$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : '';
91
+		$credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname'];
92
+		$credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username'];
93
+		$credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : '';
94 94
 
95 95
 		// Check to see if we are setting the public/private keys for ssh
96
-		$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : '';
97
-		$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : '';
96
+		$credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : '';
97
+		$credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : '';
98 98
 
99 99
 		// Sanitize the hostname, Some people might pass in odd-data:
100 100
 		$credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off
Please login to merge, or discard this patch.
classes/models/FrmStyle.php 2 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -7,46 +7,46 @@  discard block
 block discarded – undo
7 7
 	 * @param int|string $id The id of the stylsheet or 'default'
8 8
 	 */
9 9
 	public function __construct( $id = 0 ) {
10
-        $this->id = $id;
11
-    }
10
+		$this->id = $id;
11
+	}
12 12
 
13
-    public function get_new() {
13
+	public function get_new() {
14 14
 		$this->id = 0;
15 15
 
16
-        $max_slug_value = 2147483647;
17
-        $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
19
-
20
-        $style = array(
21
-            'post_type'     => FrmStylesController::$post_type,
22
-            'ID'            => '',
23
-            'post_title'    => __( 'New Style', 'formidable' ),
24
-            'post_name'     => $key,
25
-            'post_content'  => $this->get_defaults(),
26
-            'menu_order'    => '',
27
-            'post_status'   => 'publish',
28
-        );
16
+		$max_slug_value = 2147483647;
17
+		$min_slug_value = 37; // we want to have at least 2 characters in the slug
18
+		$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
19
+
20
+		$style = array(
21
+			'post_type'     => FrmStylesController::$post_type,
22
+			'ID'            => '',
23
+			'post_title'    => __( 'New Style', 'formidable' ),
24
+			'post_name'     => $key,
25
+			'post_content'  => $this->get_defaults(),
26
+			'menu_order'    => '',
27
+			'post_status'   => 'publish',
28
+		);
29 29
 
30
-        return (object) $style;
31
-    }
30
+		return (object) $style;
31
+	}
32 32
 
33 33
 	public function save( $settings ) {
34 34
 		return FrmDb::save_settings( $settings, 'frm_styles' );
35
-    }
35
+	}
36 36
 
37 37
 	public function duplicate( $id ) {
38
-        // duplicating is a pro feature
39
-    }
38
+		// duplicating is a pro feature
39
+	}
40 40
 
41
-    public function update( $id = 'default' ) {
41
+	public function update( $id = 'default' ) {
42 42
  		$all_instances = $this->get_all();
43 43
 
44 44
  		if ( empty($id) ) {
45
- 		     $new_style = (array) $this->get_new();
46
- 		     $all_instances[] = $new_style;
45
+ 			 $new_style = (array) $this->get_new();
46
+ 			 $all_instances[] = $new_style;
47 47
  		}
48 48
 
49
-        $action_ids = array();
49
+		$action_ids = array();
50 50
 
51 51
  		foreach ( $all_instances as $number => $new_instance ) {
52 52
  			$new_instance = stripslashes_deep( (array) $new_instance);
@@ -54,46 +54,46 @@  discard block
 block discarded – undo
54 54
  			if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
55 55
 				$all_instances[ $number ] = $new_instance;
56 56
 
57
- 			    if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
58
- 			        // this style was set to default, so remove default setting on previous default style
59
- 			        $new_instance['menu_order'] = 0;
60
- 			        $action_ids[] = $this->save($new_instance);
61
- 			    }
57
+ 				if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
58
+ 					// this style was set to default, so remove default setting on previous default style
59
+ 					$new_instance['menu_order'] = 0;
60
+ 					$action_ids[] = $this->save($new_instance);
61
+ 				}
62 62
 
63
- 			    // don't continue if not saving this style
64
- 			    continue;
63
+ 				// don't continue if not saving this style
64
+ 				continue;
65 65
  			}
66 66
 
67 67
  			$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
68 68
  			$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
69 69
  			$new_instance['post_type']  = FrmStylesController::$post_type;
70
-            $new_instance['post_status']  = 'publish';
70
+			$new_instance['post_status']  = 'publish';
71 71
 			$new_instance['menu_order']  = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72 72
 
73
-            if ( empty($id) ) {
74
-                $new_instance['post_name'] = $new_instance['post_title'];
75
-            }
73
+			if ( empty($id) ) {
74
+				$new_instance['post_name'] = $new_instance['post_title'];
75
+			}
76 76
 
77
-            $default_settings = $this->get_defaults();
77
+			$default_settings = $this->get_defaults();
78 78
 
79
-            foreach ( $default_settings as $setting => $default ) {
79
+			foreach ( $default_settings as $setting => $default ) {
80 80
 				if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81 81
 					$new_instance['post_content'][ $setting ] = $default;
82 82
 				}
83 83
 
84 84
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
85
-                    //if is a color
85
+					//if is a color
86 86
 					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87 87
 				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
88 88
 					$new_instance['post_content'][ $setting ] = 0;
89
-                } else if ( $setting == 'font' ) {
90
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
91
-                }
92
-            }
89
+				} else if ( $setting == 'font' ) {
90
+					$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
91
+				}
92
+			}
93 93
 
94 94
 			$all_instances[ $number ] = $new_instance;
95 95
 
96
-            $action_ids[] = $this->save($new_instance);
96
+			$action_ids[] = $this->save($new_instance);
97 97
 
98 98
  		}
99 99
 
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
  		return $action_ids;
103 103
  	}
104 104
 
105
-    /**
106
-     * Create static css file
107
-     */
105
+	/**
106
+	 * Create static css file
107
+	 */
108 108
 	public function save_settings() {
109 109
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
110 110
 		update_option( 'frm_last_style_update', date('njGi') );
111 111
 
112
-        if ( ! is_file($filename) ) {
113
-            return;
114
-        }
112
+		if ( ! is_file($filename) ) {
113
+			return;
114
+		}
115 115
 
116 116
 		$this->clear_cache();
117 117
 
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 		) );
124 124
 		$create_file->create_file( $css );
125 125
 
126
-        update_option('frmpro_css', $css);
126
+		update_option('frmpro_css', $css);
127 127
 
128
-        set_transient('frmpro_css', $css);
128
+		set_transient('frmpro_css', $css);
129 129
 	}
130 130
 
131 131
 	private function get_css_content( $filename ) {
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 		$saving = true;
135 135
 		$frm_style = $this;
136 136
 
137
-        ob_start();
138
-        include( $filename );
137
+		ob_start();
138
+		include( $filename );
139 139
 		$css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", '    ' ), '', ob_get_contents() ) );
140
-        ob_end_clean();
140
+		ob_end_clean();
141 141
 
142 142
 		return $css;
143 143
 	}
@@ -157,269 +157,269 @@  discard block
 block discarded – undo
157 157
 	}
158 158
 
159 159
 	public function destroy( $id ) {
160
-        return wp_delete_post($id);
161
-    }
160
+		return wp_delete_post($id);
161
+	}
162 162
 
163
-    public function get_one() {
164
-        if ( 'default' == $this->id ) {
165
-            $style = $this->get_default_style();
166
-            if ( $style ) {
167
-                $this->id = $style->ID;
168
-            } else {
169
-                $this->id = 0;
170
-            }
171
-            return $style;
172
-        }
163
+	public function get_one() {
164
+		if ( 'default' == $this->id ) {
165
+			$style = $this->get_default_style();
166
+			if ( $style ) {
167
+				$this->id = $style->ID;
168
+			} else {
169
+				$this->id = 0;
170
+			}
171
+			return $style;
172
+		}
173 173
 
174
-        $style = get_post($this->id);
174
+		$style = get_post($this->id);
175 175
 
176
-        if ( ! $style ) {
177
-            return $style;
178
-        }
176
+		if ( ! $style ) {
177
+			return $style;
178
+		}
179 179
 
180
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
180
+		$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
181 181
 
182
-        $default_values = $this->get_defaults();
182
+		$default_values = $this->get_defaults();
183 183
 
184
-        // fill default values
185
-        $style->post_content = $this->override_defaults($style->post_content);
186
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
184
+		// fill default values
185
+		$style->post_content = $this->override_defaults($style->post_content);
186
+		$style->post_content = wp_parse_args( $style->post_content, $default_values);
187 187
 
188
-        return $style;
189
-    }
188
+		return $style;
189
+	}
190 190
 
191
-    public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
192
-        $post_atts = array(
191
+	public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) {
192
+		$post_atts = array(
193 193
 			'post_type'   => FrmStylesController::$post_type,
194 194
 			'post_status' => 'publish',
195 195
 			'numberposts' => $limit,
196 196
 			'orderby'     => $orderby,
197 197
 			'order'       => $order,
198
-        );
198
+		);
199 199
 
200 200
 		$temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
201 201
 
202
-        if ( empty($temp_styles) ) {
203
-            global $wpdb;
204
-            // make sure there wasn't a conflict with the query
202
+		if ( empty($temp_styles) ) {
203
+			global $wpdb;
204
+			// make sure there wasn't a conflict with the query
205 205
 			$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
206
-            $temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
206
+			$temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
207 207
 
208
-            if ( empty($temp_styles) ) {
209
-                // create a new style if there are none
210
-         		$new = $this->get_new();
208
+			if ( empty($temp_styles) ) {
209
+				// create a new style if there are none
210
+		 		$new = $this->get_new();
211 211
 				$new->post_title = __( 'Formidable Style', 'formidable' );
212 212
 				$new->post_name = $new->post_title;
213
-         		$new->menu_order = 1;
214
-         		$new = $this->save( (array) $new);
215
-         		$this->update('default');
216
-
217
-                $post_atts['include'] = $new;
218
-
219
-                $temp_styles = get_posts( $post_atts );
220
-            }
221
-        }
222
-
223
-        $default_values = $this->get_defaults();
224
-        $default_style = false;
225
-
226
-        $styles = array();
227
-        foreach ( $temp_styles as $style ) {
228
-            $this->id = $style->ID;
229
-            if ( $style->menu_order ) {
230
-                if ( $default_style ) {
231
-                    // only return one default
232
-                    $style->menu_order = 0;
233
-                } else {
234
-                    // check for a default style
235
-                    $default_style = $style->ID;
236
-                }
237
-            }
238
-
239
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
240
-
241
-            // fill default values
242
-            $style->post_content = $this->override_defaults($style->post_content);
243
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
213
+		 		$new->menu_order = 1;
214
+		 		$new = $this->save( (array) $new);
215
+		 		$this->update('default');
216
+
217
+				$post_atts['include'] = $new;
218
+
219
+				$temp_styles = get_posts( $post_atts );
220
+			}
221
+		}
222
+
223
+		$default_values = $this->get_defaults();
224
+		$default_style = false;
225
+
226
+		$styles = array();
227
+		foreach ( $temp_styles as $style ) {
228
+			$this->id = $style->ID;
229
+			if ( $style->menu_order ) {
230
+				if ( $default_style ) {
231
+					// only return one default
232
+					$style->menu_order = 0;
233
+				} else {
234
+					// check for a default style
235
+					$default_style = $style->ID;
236
+				}
237
+			}
238
+
239
+			$style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
240
+
241
+			// fill default values
242
+			$style->post_content = $this->override_defaults($style->post_content);
243
+			$style->post_content = wp_parse_args( $style->post_content, $default_values);
244 244
 
245 245
 			$styles[ $style->ID ] = $style;
246
-        }
246
+		}
247 247
 
248
-        if ( ! $default_style ) {
249
-            $default_style = reset($styles);
248
+		if ( ! $default_style ) {
249
+			$default_style = reset($styles);
250 250
 			$styles[ $default_style->ID ]->menu_order = 1;
251
-        }
251
+		}
252 252
 
253
-        return $styles;
254
-    }
253
+		return $styles;
254
+	}
255 255
 
256 256
 	public function get_default_style( $styles = null ) {
257
-        if ( ! isset($styles) ) {
257
+		if ( ! isset($styles) ) {
258 258
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
259
-        }
259
+		}
260 260
 
261
-        foreach ( $styles as $style ) {
262
-            if ( $style->menu_order ) {
263
-                return $style;
264
-            }
265
-        }
266
-    }
261
+		foreach ( $styles as $style ) {
262
+			if ( $style->menu_order ) {
263
+				return $style;
264
+			}
265
+		}
266
+	}
267 267
 
268 268
 	public function override_defaults( $settings ) {
269
-	    if ( ! is_array($settings) ) {
270
-	        return $settings;
271
-	    }
269
+		if ( ! is_array($settings) ) {
270
+			return $settings;
271
+		}
272 272
 
273 273
 		$settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
274 274
 
275
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
276
-	        $settings['form_desc_size'] = $settings['description_font_size'];
277
-	        $settings['form_desc_color'] = $settings['description_color'];
278
-	        $settings['title_color'] = $settings['label_color'];
279
-	    }
275
+		if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
276
+			$settings['form_desc_size'] = $settings['description_font_size'];
277
+			$settings['form_desc_color'] = $settings['description_color'];
278
+			$settings['title_color'] = $settings['label_color'];
279
+		}
280 280
 
281
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
282
-	        $settings['section_color'] = $settings['label_color'];
283
-	        $settings['section_border_color'] = $settings['border_color'];
284
-	    }
281
+		if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
282
+			$settings['section_color'] = $settings['label_color'];
283
+			$settings['section_border_color'] = $settings['border_color'];
284
+		}
285 285
 
286
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
287
-	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
288
-	        $settings['submit_hover_color'] = $settings['submit_text_color'];
289
-	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
286
+		if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
287
+			$settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
288
+			$settings['submit_hover_color'] = $settings['submit_text_color'];
289
+			$settings['submit_hover_border_color'] = $settings['submit_border_color'];
290 290
 
291
-	        $settings['submit_active_bg_color'] = $settings['submit_bg_color'];
292
-	        $settings['submit_active_color'] = $settings['submit_text_color'];
293
-            $settings['submit_active_border_color'] = $settings['submit_border_color'];
294
-	    }
291
+			$settings['submit_active_bg_color'] = $settings['submit_bg_color'];
292
+			$settings['submit_active_color'] = $settings['submit_text_color'];
293
+			$settings['submit_active_border_color'] = $settings['submit_border_color'];
294
+		}
295 295
 
296
-	    return $settings;
296
+		return $settings;
297 297
 	}
298 298
 
299 299
 	public function get_defaults() {
300
-        return array(
301
-            'theme_css'         => 'ui-lightness',
302
-            'theme_name'        => 'UI Lightness',
300
+		return array(
301
+			'theme_css'         => 'ui-lightness',
302
+			'theme_name'        => 'UI Lightness',
303 303
 
304 304
 			'center_form'       => '',
305
-            'form_width'        => '100%',
306
-            'form_align'        => 'left',
307
-            'direction'         => is_rtl() ? 'rtl' : 'ltr',
308
-            'fieldset'          => '0px',
309
-            'fieldset_color'    => '000000',
310
-            'fieldset_padding'  => '0 0 15px 0',
311
-            'fieldset_bg_color' => '',
312
-
313
-            'title_size'        => '20px',
314
-            'title_color'       => '444444',
305
+			'form_width'        => '100%',
306
+			'form_align'        => 'left',
307
+			'direction'         => is_rtl() ? 'rtl' : 'ltr',
308
+			'fieldset'          => '0px',
309
+			'fieldset_color'    => '000000',
310
+			'fieldset_padding'  => '0 0 15px 0',
311
+			'fieldset_bg_color' => '',
312
+
313
+			'title_size'        => '20px',
314
+			'title_color'       => '444444',
315 315
 			'title_margin_top'  => '10px',
316 316
 			'title_margin_bottom' => '10px',
317
-            'form_desc_size'    => '14px',
318
-            'form_desc_color'   => '666666',
317
+			'form_desc_size'    => '14px',
318
+			'form_desc_color'   => '666666',
319 319
 			'form_desc_margin_top' => '10px',
320 320
 			'form_desc_margin_bottom' => '25px',
321 321
 
322
-            'font'              => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
323
-            'font_size'         => '14px',
324
-            'label_color'       => '444444',
325
-            'weight'            => 'bold',
326
-            'position'          => 'none',
327
-            'align'             => 'left',
328
-            'width'             => '150px',
329
-            'required_color'    => 'B94A48',
330
-            'required_weight'   => 'bold',
331
-            'label_padding'     => '0 0 3px 0',
332
-
333
-            'description_font_size' => '12px',
334
-            'description_color' => '666666',
335
-            'description_weight' => 'normal',
336
-            'description_style' => 'normal',
337
-            'description_align' => 'left',
322
+			'font'              => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif',
323
+			'font_size'         => '14px',
324
+			'label_color'       => '444444',
325
+			'weight'            => 'bold',
326
+			'position'          => 'none',
327
+			'align'             => 'left',
328
+			'width'             => '150px',
329
+			'required_color'    => 'B94A48',
330
+			'required_weight'   => 'bold',
331
+			'label_padding'     => '0 0 3px 0',
332
+
333
+			'description_font_size' => '12px',
334
+			'description_color' => '666666',
335
+			'description_weight' => 'normal',
336
+			'description_style' => 'normal',
337
+			'description_align' => 'left',
338 338
 			'description_margin' => '0',
339 339
 
340
-            'field_font_size'   => '14px',
341
-            'field_height'      => '32px',
342
-            'line_height'       => 'normal',
343
-            'field_width'       => '100%',
344
-            'auto_width'        => false,
345
-            'field_pad'         => '6px 10px',
346
-            'field_margin'      => '20px',
340
+			'field_font_size'   => '14px',
341
+			'field_height'      => '32px',
342
+			'line_height'       => 'normal',
343
+			'field_width'       => '100%',
344
+			'auto_width'        => false,
345
+			'field_pad'         => '6px 10px',
346
+			'field_margin'      => '20px',
347 347
 			'field_weight' => 'normal',
348
-            'text_color'        => '555555',
349
-            //'border_color_hv'   => 'cccccc',
350
-            'border_color'      => 'cccccc',
351
-            'field_border_width' => '1px',
352
-            'field_border_style' => 'solid',
353
-
354
-            'bg_color'          => 'ffffff',
355
-            //'bg_color_hv'       => 'ffffff',
348
+			'text_color'        => '555555',
349
+			//'border_color_hv'   => 'cccccc',
350
+			'border_color'      => 'cccccc',
351
+			'field_border_width' => '1px',
352
+			'field_border_style' => 'solid',
353
+
354
+			'bg_color'          => 'ffffff',
355
+			//'bg_color_hv'       => 'ffffff',
356 356
 			'remove_box_shadow' => '',
357
-            'bg_color_active'   => 'ffffff',
357
+			'bg_color_active'   => 'ffffff',
358 358
 			'border_color_active' => '66afe9',
359 359
 			'remove_box_shadow_active' => '',
360
-            'text_color_error'  => '444444',
361
-            'bg_color_error'    => 'ffffff',
360
+			'text_color_error'  => '444444',
361
+			'bg_color_error'    => 'ffffff',
362 362
 			'border_color_error' => 'B94A48',
363 363
 			'border_width_error' => '1px',
364 364
 			'border_style_error' => 'solid',
365
-            'bg_color_disabled' => 'ffffff',
366
-            'border_color_disabled' => 'E5E5E5',
367
-            'text_color_disabled' => 'A1A1A1',
368
-
369
-            'radio_align'       => 'block',
370
-            'check_align'       => 'block',
371
-            'check_font_size'   => '13px',
372
-            'check_label_color' => '444444',
373
-            'check_weight'      => 'normal',
374
-
375
-            'section_font_size' => '18px',
376
-            'section_color'     => '444444',
377
-            'section_weight'    => 'bold',
378
-            'section_pad'       => '15px 0 3px 0',
379
-            'section_mar_top'   => '15px',
365
+			'bg_color_disabled' => 'ffffff',
366
+			'border_color_disabled' => 'E5E5E5',
367
+			'text_color_disabled' => 'A1A1A1',
368
+
369
+			'radio_align'       => 'block',
370
+			'check_align'       => 'block',
371
+			'check_font_size'   => '13px',
372
+			'check_label_color' => '444444',
373
+			'check_weight'      => 'normal',
374
+
375
+			'section_font_size' => '18px',
376
+			'section_color'     => '444444',
377
+			'section_weight'    => 'bold',
378
+			'section_pad'       => '15px 0 3px 0',
379
+			'section_mar_top'   => '15px',
380 380
 			'section_mar_bottom' => '12px',
381
-            'section_bg_color'  => '',
382
-            'section_border_color' => 'e8e8e8',
383
-            'section_border_width' => '2px',
384
-            'section_border_style' => 'solid',
385
-            'section_border_loc' => '-top',
386
-            'collapse_icon'     => '6',
387
-            'collapse_pos'      => 'after',
388
-            'repeat_icon'       => '1',
389
-
390
-            'submit_style'      => false,
391
-            'submit_font_size'  => '14px',
392
-            'submit_width'      => 'auto',
393
-            'submit_height'     => 'auto',
394
-            'submit_bg_color'   => 'ffffff',
395
-            'submit_border_color' => 'cccccc',
396
-            'submit_border_width' => '1px',
397
-            'submit_text_color' => '444444',
398
-            'submit_weight'     => 'normal',
399
-            'submit_border_radius' => '4px',
400
-            'submit_bg_img'     => '',
401
-            'submit_margin'     => '10px',
402
-            'submit_padding'    => '6px 11px',
403
-            'submit_shadow_color' => 'eeeeee',
404
-            'submit_hover_bg_color' => 'efefef',
405
-            'submit_hover_color' => '444444',
406
-            'submit_hover_border_color' => 'cccccc',
407
-            'submit_active_bg_color' => 'efefef',
408
-            'submit_active_color' => '444444',
409
-            'submit_active_border_color' => 'cccccc',
410
-
411
-            'border_radius'     => '4px',
412
-            'error_bg'          => 'F2DEDE',
413
-            'error_border'      => 'EBCCD1',
414
-            'error_text'        => 'B94A48',
415
-            'error_font_size'   => '14px',
416
-
417
-            'success_bg_color'  => 'DFF0D8',
418
-            'success_border_color' => 'D6E9C6',
419
-            'success_text_color' => '468847',
420
-            'success_font_size' => '14px',
421
-
422
-            'important_style'   => false,
381
+			'section_bg_color'  => '',
382
+			'section_border_color' => 'e8e8e8',
383
+			'section_border_width' => '2px',
384
+			'section_border_style' => 'solid',
385
+			'section_border_loc' => '-top',
386
+			'collapse_icon'     => '6',
387
+			'collapse_pos'      => 'after',
388
+			'repeat_icon'       => '1',
389
+
390
+			'submit_style'      => false,
391
+			'submit_font_size'  => '14px',
392
+			'submit_width'      => 'auto',
393
+			'submit_height'     => 'auto',
394
+			'submit_bg_color'   => 'ffffff',
395
+			'submit_border_color' => 'cccccc',
396
+			'submit_border_width' => '1px',
397
+			'submit_text_color' => '444444',
398
+			'submit_weight'     => 'normal',
399
+			'submit_border_radius' => '4px',
400
+			'submit_bg_img'     => '',
401
+			'submit_margin'     => '10px',
402
+			'submit_padding'    => '6px 11px',
403
+			'submit_shadow_color' => 'eeeeee',
404
+			'submit_hover_bg_color' => 'efefef',
405
+			'submit_hover_color' => '444444',
406
+			'submit_hover_border_color' => 'cccccc',
407
+			'submit_active_bg_color' => 'efefef',
408
+			'submit_active_color' => '444444',
409
+			'submit_active_border_color' => 'cccccc',
410
+
411
+			'border_radius'     => '4px',
412
+			'error_bg'          => 'F2DEDE',
413
+			'error_border'      => 'EBCCD1',
414
+			'error_text'        => 'B94A48',
415
+			'error_font_size'   => '14px',
416
+
417
+			'success_bg_color'  => 'DFF0D8',
418
+			'success_border_color' => 'D6E9C6',
419
+			'success_text_color' => '468847',
420
+			'success_font_size' => '14px',
421
+
422
+			'important_style'   => false,
423 423
 
424 424
 			'progress_bg_color'     => 'dddddd',
425 425
 			'progress_active_color' => 'ffffff',
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 			'progress_border_size'  => '2px',
430 430
 			'progress_size'         => '30px',
431 431
 
432
-            'custom_css'        => '',
433
-        );
434
-    }
432
+			'custom_css'        => '',
433
+		);
434
+	}
435 435
 
436 436
 	public function get_field_name( $field_name, $post_field = 'post_content' ) {
437 437
 		return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
         $max_slug_value = 2147483647;
17 17
         $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
18
+        $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
19 19
 
20 20
         $style = array(
21 21
             'post_type'     => FrmStylesController::$post_type,
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public function update( $id = 'default' ) {
42 42
  		$all_instances = $this->get_all();
43 43
 
44
- 		if ( empty($id) ) {
44
+ 		if ( empty( $id ) ) {
45 45
  		     $new_style = (array) $this->get_new();
46 46
  		     $all_instances[] = $new_style;
47 47
  		}
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         $action_ids = array();
50 50
 
51 51
  		foreach ( $all_instances as $number => $new_instance ) {
52
- 			$new_instance = stripslashes_deep( (array) $new_instance);
52
+ 			$new_instance = stripslashes_deep( (array) $new_instance );
53 53
  			$this->id = $new_instance['ID'];
54
- 			if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
55
-				$all_instances[ $number ] = $new_instance;
54
+ 			if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
55
+				$all_instances[$number] = $new_instance;
56 56
 
57
- 			    if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
57
+ 			    if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
58 58
  			        // this style was set to default, so remove default setting on previous default style
59 59
  			        $new_instance['menu_order'] = 0;
60
- 			        $action_ids[] = $this->save($new_instance);
60
+ 			        $action_ids[] = $this->save( $new_instance );
61 61
  			    }
62 62
 
63 63
  			    // don't continue if not saving this style
@@ -67,33 +67,33 @@  discard block
 block discarded – undo
67 67
  			$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
68 68
  			$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
69 69
  			$new_instance['post_type']  = FrmStylesController::$post_type;
70
-            $new_instance['post_status']  = 'publish';
70
+            $new_instance['post_status'] = 'publish';
71 71
 			$new_instance['menu_order']  = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72 72
 
73
-            if ( empty($id) ) {
73
+            if ( empty( $id ) ) {
74 74
                 $new_instance['post_name'] = $new_instance['post_title'];
75 75
             }
76 76
 
77 77
             $default_settings = $this->get_defaults();
78 78
 
79 79
             foreach ( $default_settings as $setting => $default ) {
80
-				if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81
-					$new_instance['post_content'][ $setting ] = $default;
80
+				if ( ! isset( $new_instance['post_content'][$setting] ) ) {
81
+					$new_instance['post_content'][$setting] = $default;
82 82
 				}
83 83
 
84 84
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
85 85
                     //if is a color
86
-					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87
-				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
88
-					$new_instance['post_content'][ $setting ] = 0;
86
+					$new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] );
87
+				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) {
88
+					$new_instance['post_content'][$setting] = 0;
89 89
                 } else if ( $setting == 'font' ) {
90
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
90
+                	$new_instance['post_content'][$setting] = $this->force_balanced_quotation( $new_instance['post_content'][$setting] );
91 91
                 }
92 92
             }
93 93
 
94
-			$all_instances[ $number ] = $new_instance;
94
+			$all_instances[$number] = $new_instance;
95 95
 
96
-            $action_ids[] = $this->save($new_instance);
96
+            $action_ids[] = $this->save( $new_instance );
97 97
 
98 98
  		}
99 99
 
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
      */
108 108
 	public function save_settings() {
109 109
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
110
-		update_option( 'frm_last_style_update', date('njGi') );
110
+		update_option( 'frm_last_style_update', date( 'njGi' ) );
111 111
 
112
-        if ( ! is_file($filename) ) {
112
+        if ( ! is_file( $filename ) ) {
113 113
             return;
114 114
         }
115 115
 
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 		) );
124 124
 		$create_file->create_file( $css );
125 125
 
126
-        update_option('frmpro_css', $css);
126
+        update_option( 'frmpro_css', $css );
127 127
 
128
-        set_transient('frmpro_css', $css);
128
+        set_transient( 'frmpro_css', $css );
129 129
 	}
130 130
 
131 131
 	private function get_css_content( $filename ) {
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	}
158 158
 
159 159
 	public function destroy( $id ) {
160
-        return wp_delete_post($id);
160
+        return wp_delete_post( $id );
161 161
     }
162 162
 
163 163
     public function get_one() {
@@ -171,19 +171,19 @@  discard block
 block discarded – undo
171 171
             return $style;
172 172
         }
173 173
 
174
-        $style = get_post($this->id);
174
+        $style = get_post( $this->id );
175 175
 
176 176
         if ( ! $style ) {
177 177
             return $style;
178 178
         }
179 179
 
180
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
180
+        $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
181 181
 
182 182
         $default_values = $this->get_defaults();
183 183
 
184 184
         // fill default values
185
-        $style->post_content = $this->override_defaults($style->post_content);
186
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
185
+        $style->post_content = $this->override_defaults( $style->post_content );
186
+        $style->post_content = wp_parse_args( $style->post_content, $default_values );
187 187
 
188 188
         return $style;
189 189
     }
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 
200 200
 		$temp_styles = FrmDb::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
201 201
 
202
-        if ( empty($temp_styles) ) {
202
+        if ( empty( $temp_styles ) ) {
203 203
             global $wpdb;
204 204
             // make sure there wasn't a conflict with the query
205 205
 			$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
206
-            $temp_styles = FrmDb::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
206
+            $temp_styles = FrmDb::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
207 207
 
208
-            if ( empty($temp_styles) ) {
208
+            if ( empty( $temp_styles ) ) {
209 209
                 // create a new style if there are none
210 210
          		$new = $this->get_new();
211 211
 				$new->post_title = __( 'Formidable Style', 'formidable' );
212 212
 				$new->post_name = $new->post_title;
213 213
          		$new->menu_order = 1;
214
-         		$new = $this->save( (array) $new);
215
-         		$this->update('default');
214
+         		$new = $this->save( (array) $new );
215
+         		$this->update( 'default' );
216 216
 
217 217
                 $post_atts['include'] = $new;
218 218
 
@@ -236,25 +236,25 @@  discard block
 block discarded – undo
236 236
                 }
237 237
             }
238 238
 
239
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
239
+            $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
240 240
 
241 241
             // fill default values
242
-            $style->post_content = $this->override_defaults($style->post_content);
243
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
242
+            $style->post_content = $this->override_defaults( $style->post_content );
243
+            $style->post_content = wp_parse_args( $style->post_content, $default_values );
244 244
 
245
-			$styles[ $style->ID ] = $style;
245
+			$styles[$style->ID] = $style;
246 246
         }
247 247
 
248 248
         if ( ! $default_style ) {
249
-            $default_style = reset($styles);
250
-			$styles[ $default_style->ID ]->menu_order = 1;
249
+            $default_style = reset( $styles );
250
+			$styles[$default_style->ID]->menu_order = 1;
251 251
         }
252 252
 
253 253
         return $styles;
254 254
     }
255 255
 
256 256
 	public function get_default_style( $styles = null ) {
257
-        if ( ! isset($styles) ) {
257
+        if ( ! isset( $styles ) ) {
258 258
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
259 259
         }
260 260
 
@@ -266,24 +266,24 @@  discard block
 block discarded – undo
266 266
     }
267 267
 
268 268
 	public function override_defaults( $settings ) {
269
-	    if ( ! is_array($settings) ) {
269
+	    if ( ! is_array( $settings ) ) {
270 270
 	        return $settings;
271 271
 	    }
272 272
 
273 273
 		$settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
274 274
 
275
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
275
+	    if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
276 276
 	        $settings['form_desc_size'] = $settings['description_font_size'];
277 277
 	        $settings['form_desc_color'] = $settings['description_color'];
278 278
 	        $settings['title_color'] = $settings['label_color'];
279 279
 	    }
280 280
 
281
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
281
+	    if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
282 282
 	        $settings['section_color'] = $settings['label_color'];
283 283
 	        $settings['section_border_color'] = $settings['border_color'];
284 284
 	    }
285 285
 
286
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
286
+	    if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
287 287
 	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
288 288
 	        $settings['submit_hover_color'] = $settings['submit_text_color'];
289 289
 	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
Please login to merge, or discard this patch.
classes/models/FrmFormAction.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	}
30 30
 
31 31
 	/**
32
-     * Echo the settings update form
32
+	 * Echo the settings update form
33 33
 	 *
34 34
 	 * @param array $instance Current settings
35 35
 	 */
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 	 * @return array of the default options
43 43
 	 */
44 44
 	public function get_defaults() {
45
-	    return array();
45
+		return array();
46 46
 	}
47 47
 
48 48
 	public function get_switch_fields() {
49
-	    return array();
49
+		return array();
50 50
 	}
51 51
 
52 52
 	public function migrate_values( $action, $form ) {
53
-	    return $action;
53
+		return $action;
54 54
 	}
55 55
 
56 56
 	// Functions you'll need to call.
@@ -69,24 +69,24 @@  discard block
 block discarded – undo
69 69
 	 *   - height: currently not used but may be needed in the future
70 70
 	 */
71 71
 	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
-	    if ( ! defined('ABSPATH') ) {
73
-            die('You are not allowed to call this page directly.');
74
-        }
72
+		if ( ! defined('ABSPATH') ) {
73
+			die('You are not allowed to call this page directly.');
74
+		}
75 75
 
76 76
 		$this->id_base = strtolower($id_base);
77 77
 		$this->name = $name;
78 78
 		$this->option_name = 'frm_' . $this->id_base . '_action';
79 79
 
80
-        $default_options = array(
81
-            'classes'   => '',
82
-            'active'    => true,
80
+		$default_options = array(
81
+			'classes'   => '',
82
+			'active'    => true,
83 83
 			'event'     => array( 'create' ),
84
-            'limit'     => 1,
85
-            'force_event' => false,
86
-            'priority'  => 20,
87
-            'ajax_load' => true,
88
-            'tooltip'   => $name,
89
-        );
84
+			'limit'     => 1,
85
+			'force_event' => false,
86
+			'priority'  => 20,
87
+			'ajax_load' => true,
88
+			'tooltip'   => $name,
89
+		);
90 90
 
91 91
 		$action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
92 92
 		$this->action_options = wp_parse_args( $action_options, $default_options );
@@ -135,132 +135,132 @@  discard block
 block discarded – undo
135 135
 	}
136 136
 
137 137
 	public function prepare_new( $form_id = false ) {
138
-        if ( $form_id ) {
139
-            $this->form_id = $form_id;
140
-        }
141
-
142
-        $post_content = array();
143
-        $default_values = $this->get_global_defaults();
144
-
145
-        // fill default values
146
-        $post_content = wp_parse_args( $post_content, $default_values);
147
-
148
-        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
149
-            $post_content['event'] = array( reset($this->action_options['event']) );
150
-        }
151
-
152
-        $form_action = array(
153
-            'post_title'    => $this->name,
154
-            'post_content'  => $post_content,
155
-            'post_excerpt'  => $this->id_base,
156
-            'ID'            => '',
157
-            'post_status'   => 'publish',
158
-            'post_type'     => FrmFormActionsController::$action_post_type,
138
+		if ( $form_id ) {
139
+			$this->form_id = $form_id;
140
+		}
141
+
142
+		$post_content = array();
143
+		$default_values = $this->get_global_defaults();
144
+
145
+		// fill default values
146
+		$post_content = wp_parse_args( $post_content, $default_values);
147
+
148
+		if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
149
+			$post_content['event'] = array( reset($this->action_options['event']) );
150
+		}
151
+
152
+		$form_action = array(
153
+			'post_title'    => $this->name,
154
+			'post_content'  => $post_content,
155
+			'post_excerpt'  => $this->id_base,
156
+			'ID'            => '',
157
+			'post_status'   => 'publish',
158
+			'post_type'     => FrmFormActionsController::$action_post_type,
159 159
 			'post_name'     => $this->form_id . '_' . $this->id_base . '_' . $this->number,
160
-            'menu_order'    => $this->form_id,
161
-        );
162
-        unset($post_content);
160
+			'menu_order'    => $this->form_id,
161
+		);
162
+		unset($post_content);
163 163
 
164
-        return (object) $form_action;
165
-    }
164
+		return (object) $form_action;
165
+	}
166 166
 
167 167
 	public function create( $form_id ) {
168
-        $this->form_id = $form_id;
168
+		$this->form_id = $form_id;
169 169
 
170
-        $action = $this->prepare_new();
170
+		$action = $this->prepare_new();
171 171
 
172
-        return $this->save_settings($action);
173
-    }
172
+		return $this->save_settings($action);
173
+	}
174 174
 
175 175
 	public function duplicate_form_actions( $form_id, $old_id ) {
176
-        if ( $form_id == $old_id ) {
177
-            // don't duplicate the actions if this is a template getting updated
178
-            return;
179
-        }
180
-
181
-        $this->form_id = $old_id;
182
-        $actions = $this->get_all( $old_id );
183
-
184
-        $this->form_id = $form_id;
185
-        foreach ( $actions as $action ) {
186
-            $this->duplicate_one($action, $form_id);
187
-            unset($action);
188
-        }
189
-    }
190
-
191
-    /* Check if imported action should be created or updated
176
+		if ( $form_id == $old_id ) {
177
+			// don't duplicate the actions if this is a template getting updated
178
+			return;
179
+		}
180
+
181
+		$this->form_id = $old_id;
182
+		$actions = $this->get_all( $old_id );
183
+
184
+		$this->form_id = $form_id;
185
+		foreach ( $actions as $action ) {
186
+			$this->duplicate_one($action, $form_id);
187
+			unset($action);
188
+		}
189
+	}
190
+
191
+	/* Check if imported action should be created or updated
192 192
     *
193 193
     * Since 2.0
194 194
     *
195 195
     * @param array $action
196 196
     * @return integer $post_id
197 197
     */
198
-    public function maybe_create_action( $action, $forms ) {
198
+	public function maybe_create_action( $action, $forms ) {
199 199
 		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
200
-            // Update action only
201
-            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202
-            $post_id = $this->save_settings( $action );
203
-        } else {
204
-            // Create action
205
-            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
206
-            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
207
-        }
208
-        return $post_id;
209
-    }
200
+			// Update action only
201
+			$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202
+			$post_id = $this->save_settings( $action );
203
+		} else {
204
+			// Create action
205
+			$action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
206
+			$post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
207
+		}
208
+		return $post_id;
209
+	}
210 210
 
211 211
 	public function duplicate_one( $action, $form_id ) {
212
-        global $frm_duplicate_ids;
212
+		global $frm_duplicate_ids;
213 213
 
214
-        $action->menu_order = $form_id;
215
-        $switch = $this->get_global_switch_fields();
216
-        foreach ( (array) $action->post_content as $key => $val ) {
214
+		$action->menu_order = $form_id;
215
+		$switch = $this->get_global_switch_fields();
216
+		foreach ( (array) $action->post_content as $key => $val ) {
217 217
 			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
218 218
 				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
219
-            } else if ( ! is_array( $val ) ) {
219
+			} else if ( ! is_array( $val ) ) {
220 220
 				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
221 221
 			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
222
-                // loop through each value if empty
222
+				// loop through each value if empty
223 223
 				if ( empty( $switch[ $key ] ) ) {
224 224
 					$switch[ $key ] = array_keys( $val );
225 225
 				}
226 226
 
227 227
 				foreach ( $switch[ $key ] as $subkey ) {
228 228
 					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
229
-                }
230
-            }
229
+				}
230
+			}
231 231
 
232
-            unset($key, $val);
233
-        }
234
-        unset($action->ID);
232
+			unset($key, $val);
233
+		}
234
+		unset($action->ID);
235 235
 
236
-        return $this->save_settings($action);
237
-    }
236
+		return $this->save_settings($action);
237
+	}
238 238
 
239 239
 	private function duplicate_array_walk( $action, $subkey, $val ) {
240
-        global $frm_duplicate_ids;
240
+		global $frm_duplicate_ids;
241 241
 
242
-        if ( is_array($subkey) ) {
243
-            foreach ( $subkey as $subkey2 ) {
244
-                foreach ( (array) $val as $ck => $cv ) {
245
-                    if ( is_array($cv) ) {
242
+		if ( is_array($subkey) ) {
243
+			foreach ( $subkey as $subkey2 ) {
244
+				foreach ( (array) $val as $ck => $cv ) {
245
+					if ( is_array($cv) ) {
246 246
 						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
247 247
 					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248 248
 						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
249
-                    }
250
-                }
251
-            }
252
-        } else {
253
-            foreach ( (array) $val as $ck => $cv ) {
254
-                if ( is_array($cv) ) {
249
+					}
250
+				}
251
+			}
252
+		} else {
253
+			foreach ( (array) $val as $ck => $cv ) {
254
+				if ( is_array($cv) ) {
255 255
 					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
256 256
 				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257 257
 					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
258
-                }
259
-            }
260
-        }
258
+				}
259
+			}
260
+		}
261 261
 
262
-        return $action;
263
-    }
262
+		return $action;
263
+	}
264 264
 
265 265
 	/**
266 266
 	 * Deal with changed settings.
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 */
271 271
  	public function update_callback( $form_id ) {
272
-        $this->form_id = $form_id;
272
+		$this->form_id = $form_id;
273 273
 
274 274
  		$all_instances = $this->get_settings();
275 275
 
@@ -284,25 +284,25 @@  discard block
 block discarded – undo
284 284
  			return;
285 285
  		}
286 286
 
287
-        $action_ids = array();
287
+		$action_ids = array();
288 288
 
289 289
  		foreach ( $settings as $number => $new_instance ) {
290 290
  			$this->_set($number);
291 291
 
292 292
  			if ( ! isset($new_instance['post_title']) ) {
293
- 			    // settings were never opened, so don't update
294
- 			    $action_ids[] = $new_instance['ID'];
295
-         		$this->updated = true;
296
-         		continue;
293
+ 				// settings were never opened, so don't update
294
+ 				$action_ids[] = $new_instance['ID'];
295
+		 		$this->updated = true;
296
+		 		continue;
297 297
  			}
298 298
 
299 299
 			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
300 300
 
301 301
  			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
302 302
 			$new_instance['post_name']  = $this->form_id . '_' . $this->id_base . '_' . $this->number;
303
-            $new_instance['menu_order']   = $this->form_id;
304
-            $new_instance['post_status']  = 'publish';
305
-            $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
303
+			$new_instance['menu_order']   = $this->form_id;
304
+			$new_instance['post_status']  = 'publish';
305
+			$new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
306 306
 
307 307
  			$instance = $this->update( $new_instance, $old_instance );
308 308
 
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
 				$all_instances[ $number ] = $instance;
329 329
 			}
330 330
 
331
-            $action_ids[] = $this->save_settings($instance);
331
+			$action_ids[] = $this->save_settings($instance);
332 332
 
333
-     		$this->updated = true;
333
+	 		$this->updated = true;
334 334
  		}
335 335
 
336 336
  		return $action_ids;
@@ -342,61 +342,61 @@  discard block
 block discarded – undo
342 342
 	}
343 343
 
344 344
 	public function get_single_action( $id ) {
345
-	    $action = get_post($id);
345
+		$action = get_post($id);
346 346
 		if ( $action ) {
347 347
 			$action = $this->prepare_action( $action );
348 348
 			$this->_set( $id );
349 349
 		}
350
-	    return $action;
350
+		return $action;
351 351
 	}
352 352
 
353 353
 	public function get_one( $form_id ) {
354
-	    return $this->get_all($form_id, 1);
354
+		return $this->get_all($form_id, 1);
355 355
 	}
356 356
 
357
-    public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
358
-        $action_controls = FrmFormActionsController::get_form_actions( $type );
359
-        if ( empty($action_controls) ) {
360
-            // don't continue if there are no available actions
361
-            return array();
362
-        }
357
+	public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
358
+		$action_controls = FrmFormActionsController::get_form_actions( $type );
359
+		if ( empty($action_controls) ) {
360
+			// don't continue if there are no available actions
361
+			return array();
362
+		}
363 363
 
364 364
 		$limit = apply_filters( 'frm_form_action_limit', $limit, compact( 'type', 'form_id' ) );
365 365
 
366
-        if ( 'all' != $type ) {
367
-            return $action_controls->get_all( $form_id, $limit );
368
-        }
366
+		if ( 'all' != $type ) {
367
+			return $action_controls->get_all( $form_id, $limit );
368
+		}
369 369
 
370 370
 		$args = self::action_args( $form_id, $limit );
371 371
 		$actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
372 372
 
373
-        if ( ! $actions ) {
374
-            return array();
375
-        }
373
+		if ( ! $actions ) {
374
+			return array();
375
+		}
376 376
 
377
-        $settings = array();
378
-        foreach ( $actions as $action ) {
377
+		$settings = array();
378
+		foreach ( $actions as $action ) {
379 379
 			// some plugins/themes are formatting the post_excerpt
380 380
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
381 381
 
382 382
 			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
383
-                continue;
384
-            }
383
+				continue;
384
+			}
385 385
 
386
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
386
+			$action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
387 387
 			$settings[ $action->ID ] = $action;
388 388
 
389 389
 			if ( count( $settings ) >= $limit ) {
390 390
 				break;
391 391
 			}
392
-        }
392
+		}
393 393
 
394
-        if ( 1 === $limit ) {
395
-            $settings = reset($settings);
396
-        }
394
+		if ( 1 === $limit ) {
395
+			$settings = reset($settings);
396
+		}
397 397
 
398
-        return $settings;
399
-    }
398
+		return $settings;
399
+	}
400 400
 
401 401
 	/**
402 402
 	 * @param int $action_id
@@ -419,45 +419,45 @@  discard block
 block discarded – undo
419 419
 	}
420 420
 
421 421
 	public function get_all( $form_id = false, $limit = 99 ) {
422
-	    if ( $form_id ) {
423
-	        $this->form_id = $form_id;
424
-	    }
422
+		if ( $form_id ) {
423
+			$this->form_id = $form_id;
424
+		}
425 425
 
426
-	    $type = $this->id_base;
426
+		$type = $this->id_base;
427 427
 
428
-	    global $frm_vars;
429
-	    $frm_vars['action_type'] = $type;
428
+		global $frm_vars;
429
+		$frm_vars['action_type'] = $type;
430 430
 
431 431
 		add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
432 432
 		$query = self::action_args( $form_id, $limit );
433
-        $query['post_status']      = 'any';
434
-        $query['suppress_filters'] = false;
433
+		$query['post_status']      = 'any';
434
+		$query['suppress_filters'] = false;
435 435
 
436 436
 		$actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
437
-        unset($query);
437
+		unset($query);
438 438
 
439 439
 		remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
440 440
 
441
-        if ( empty($actions) ) {
442
-            return array();
443
-        }
441
+		if ( empty($actions) ) {
442
+			return array();
443
+		}
444 444
 
445
-        $settings = array();
446
-        foreach ( $actions as $action ) {
447
-            if ( count($settings) >= $limit ) {
448
-                continue;
449
-            }
445
+		$settings = array();
446
+		foreach ( $actions as $action ) {
447
+			if ( count($settings) >= $limit ) {
448
+				continue;
449
+			}
450 450
 
451
-            $action = $this->prepare_action($action);
451
+			$action = $this->prepare_action($action);
452 452
 
453 453
 			$settings[ $action->ID ] = $action;
454
-        }
454
+		}
455 455
 
456
-        if ( 1 === $limit ) {
457
-            $settings = reset($settings);
458
-        }
456
+		if ( 1 === $limit ) {
457
+			$settings = reset($settings);
458
+		}
459 459
 
460
-        return $settings;
460
+		return $settings;
461 461
 	}
462 462
 
463 463
 	public static function action_args( $form_id = 0, $limit = 99 ) {
@@ -480,45 +480,45 @@  discard block
 block discarded – undo
480 480
 		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
481 481
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
482 482
 
483
-        $default_values = $this->get_global_defaults();
483
+		$default_values = $this->get_global_defaults();
484 484
 
485
-        // fill default values
486
-        $action->post_content += $default_values;
485
+		// fill default values
486
+		$action->post_content += $default_values;
487 487
 
488
-        foreach ( $default_values as $k => $vals ) {
489
-            if ( is_array($vals) && ! empty($vals) ) {
488
+		foreach ( $default_values as $k => $vals ) {
489
+			if ( is_array($vals) && ! empty($vals) ) {
490 490
 				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
491
-                    continue;
492
-                }
491
+					continue;
492
+				}
493 493
 				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
494
-            }
495
-        }
494
+			}
495
+		}
496 496
 
497
-        if ( ! is_array($action->post_content['event']) ) {
498
-            $action->post_content['event'] = explode(',', $action->post_content['event']);
499
-        }
497
+		if ( ! is_array($action->post_content['event']) ) {
498
+			$action->post_content['event'] = explode(',', $action->post_content['event']);
499
+		}
500 500
 
501
-        return $action;
501
+		return $action;
502 502
 	}
503 503
 
504 504
 	public function destroy( $form_id = false, $type = 'default' ) {
505
-	    global $wpdb;
505
+		global $wpdb;
506 506
 
507
-	    $this->form_id = $form_id;
507
+		$this->form_id = $form_id;
508 508
 
509
-	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
510
-	    if ( $form_id ) {
511
-	        $query['menu_order'] = $form_id;
512
-	    }
513
-	    if ( 'all' != $type ) {
514
-	        $query['post_excerpt'] = $this->id_base;
515
-	    }
509
+		$query = array( 'post_type' => FrmFormActionsController::$action_post_type );
510
+		if ( $form_id ) {
511
+			$query['menu_order'] = $form_id;
512
+		}
513
+		if ( 'all' != $type ) {
514
+			$query['post_excerpt'] = $this->id_base;
515
+		}
516 516
 
517
-        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
517
+		$post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
518 518
 
519
-        foreach ( $post_ids as $id ) {
520
-            wp_delete_post($id);
521
-        }
519
+		foreach ( $post_ids as $id ) {
520
+			wp_delete_post($id);
521
+		}
522 522
 		self::clear_cache();
523 523
 	}
524 524
 
@@ -536,69 +536,69 @@  discard block
 block discarded – undo
536 536
 	}
537 537
 
538 538
 	public function get_global_defaults() {
539
-	    $defaults = $this->get_defaults();
539
+		$defaults = $this->get_defaults();
540 540
 
541
-	    if ( ! isset($defaults['event']) ) {
541
+		if ( ! isset($defaults['event']) ) {
542 542
 			$defaults['event'] = array( 'create' );
543
-	    }
543
+		}
544 544
 
545
-	    if ( ! isset($defaults['conditions']) ) {
546
-	        $defaults['conditions'] = array(
547
-                'send_stop' => '',
548
-                'any_all'   => '',
549
-            );
550
-        }
545
+		if ( ! isset($defaults['conditions']) ) {
546
+			$defaults['conditions'] = array(
547
+				'send_stop' => '',
548
+				'any_all'   => '',
549
+			);
550
+		}
551 551
 
552
-        return $defaults;
552
+		return $defaults;
553 553
 	}
554 554
 
555 555
 	public function get_global_switch_fields() {
556
-	    $switch = $this->get_switch_fields();
556
+		$switch = $this->get_switch_fields();
557 557
 		$switch['conditions'] = array( 'hide_field' );
558
-	    return $switch;
558
+		return $switch;
559 559
 	}
560 560
 
561 561
 	/**
562 562
 	 * Migrate settings from form->options into new action.
563 563
 	 */
564 564
 	public function migrate_to_2( $form, $update = 'update' ) {
565
-        $action = $this->prepare_new($form->id);
566
-        $form->options = maybe_unserialize($form->options);
565
+		$action = $this->prepare_new($form->id);
566
+		$form->options = maybe_unserialize($form->options);
567 567
 
568
-        // fill with existing options
569
-        foreach ( $action->post_content as $name => $val ) {
568
+		// fill with existing options
569
+		foreach ( $action->post_content as $name => $val ) {
570 570
 			if ( isset( $form->options[ $name ] ) ) {
571 571
 				$action->post_content[ $name ] = $form->options[ $name ];
572 572
 				unset( $form->options[ $name ] );
573
-            }
574
-        }
573
+			}
574
+		}
575 575
 
576
-        $action = $this->migrate_values($action, $form);
576
+		$action = $this->migrate_values($action, $form);
577 577
 
578
-        // check if action already exists
579
-        $post_id = get_posts( array(
580
-            'name'          => $action->post_name,
581
-            'post_type'     => FrmFormActionsController::$action_post_type,
582
-            'post_status'   => $action->post_status,
583
-            'numberposts'   => 1,
584
-        ) );
578
+		// check if action already exists
579
+		$post_id = get_posts( array(
580
+			'name'          => $action->post_name,
581
+			'post_type'     => FrmFormActionsController::$action_post_type,
582
+			'post_status'   => $action->post_status,
583
+			'numberposts'   => 1,
584
+		) );
585 585
 
586
-        if ( empty($post_id) ) {
587
-            // create action now
588
-            $post_id = $this->save_settings($action);
589
-        }
586
+		if ( empty($post_id) ) {
587
+			// create action now
588
+			$post_id = $this->save_settings($action);
589
+		}
590 590
 
591
-        if ( $post_id && 'update' == $update ) {
592
-            global $wpdb;
593
-            $form->options = maybe_serialize($form->options);
591
+		if ( $post_id && 'update' == $update ) {
592
+			global $wpdb;
593
+			$form->options = maybe_serialize($form->options);
594 594
 
595
-            // update form options
595
+			// update form options
596 596
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
597
-	        FrmForm::clear_form_cache();
598
-        }
597
+			FrmForm::clear_form_cache();
598
+		}
599 599
 
600
-        return $post_id;
601
-    }
600
+		return $post_id;
601
+	}
602 602
 
603 603
 	public static function action_conditions_met( $action, $entry ) {
604 604
 		$notification = $action->post_content;
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmFormAction {
4 4
 
5
-	public $id_base;         // Root id for all actions of this type.
6
-	public $name;            // Name for this action type.
5
+	public $id_base; // Root id for all actions of this type.
6
+	public $name; // Name for this action type.
7 7
 	public $option_name;
8
-	public $action_options;  // Option array passed to wp_register_sidebar_widget()
8
+	public $action_options; // Option array passed to wp_register_sidebar_widget()
9 9
 	public $control_options; // Option array passed to wp_register_widget_control()
10 10
 
11
-	public $form_id;         // The ID of the form to evaluate
12
-	public $number = false;  // Unique ID number of the current instance.
13
-	public $id = '';         // Unique ID string of the current instance (id_base-number)
11
+	public $form_id; // The ID of the form to evaluate
12
+	public $number = false; // Unique ID number of the current instance.
13
+	public $id = ''; // Unique ID string of the current instance (id_base-number)
14 14
 	public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
15 15
 
16 16
 	// Member functions that you must over-ride.
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
 	 *   - height: currently not used but may be needed in the future
70 70
 	 */
71 71
 	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
-	    if ( ! defined('ABSPATH') ) {
73
-            die('You are not allowed to call this page directly.');
72
+	    if ( ! defined( 'ABSPATH' ) ) {
73
+            die( 'You are not allowed to call this page directly.' );
74 74
         }
75 75
 
76
-		$this->id_base = strtolower($id_base);
76
+		$this->id_base = strtolower( $id_base );
77 77
 		$this->name = $name;
78 78
 		$this->option_name = 'frm_' . $this->id_base . '_action';
79 79
 
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
         $default_values = $this->get_global_defaults();
144 144
 
145 145
         // fill default values
146
-        $post_content = wp_parse_args( $post_content, $default_values);
146
+        $post_content = wp_parse_args( $post_content, $default_values );
147 147
 
148
-        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
149
-            $post_content['event'] = array( reset($this->action_options['event']) );
148
+        if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
149
+            $post_content['event'] = array( reset( $this->action_options['event'] ) );
150 150
         }
151 151
 
152 152
         $form_action = array(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			'post_name'     => $this->form_id . '_' . $this->id_base . '_' . $this->number,
160 160
             'menu_order'    => $this->form_id,
161 161
         );
162
-        unset($post_content);
162
+        unset( $post_content );
163 163
 
164 164
         return (object) $form_action;
165 165
     }
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 
170 170
         $action = $this->prepare_new();
171 171
 
172
-        return $this->save_settings($action);
172
+        return $this->save_settings( $action );
173 173
     }
174 174
 
175 175
 	public function duplicate_form_actions( $form_id, $old_id ) {
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 
184 184
         $this->form_id = $form_id;
185 185
         foreach ( $actions as $action ) {
186
-            $this->duplicate_one($action, $form_id);
187
-            unset($action);
186
+            $this->duplicate_one( $action, $form_id );
187
+            unset( $action );
188 188
         }
189 189
     }
190 190
 
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
     * @return integer $post_id
197 197
     */
198 198
     public function maybe_create_action( $action, $forms ) {
199
-		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
199
+		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) {
200 200
             // Update action only
201 201
             $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
202 202
             $post_id = $this->save_settings( $action );
203 203
         } else {
204 204
             // Create action
205
-            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
206
-            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
205
+            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
206
+            $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
207 207
         }
208 208
         return $post_id;
209 209
     }
@@ -214,47 +214,47 @@  discard block
 block discarded – undo
214 214
         $action->menu_order = $form_id;
215 215
         $switch = $this->get_global_switch_fields();
216 216
         foreach ( (array) $action->post_content as $key => $val ) {
217
-			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
218
-				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
217
+			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) {
218
+				$action->post_content[$key] = $frm_duplicate_ids[$val];
219 219
             } else if ( ! is_array( $val ) ) {
220
-				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
221
-			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
220
+				$action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val );
221
+			} else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) {
222 222
                 // loop through each value if empty
223
-				if ( empty( $switch[ $key ] ) ) {
224
-					$switch[ $key ] = array_keys( $val );
223
+				if ( empty( $switch[$key] ) ) {
224
+					$switch[$key] = array_keys( $val );
225 225
 				}
226 226
 
227
-				foreach ( $switch[ $key ] as $subkey ) {
228
-					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
227
+				foreach ( $switch[$key] as $subkey ) {
228
+					$action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val );
229 229
                 }
230 230
             }
231 231
 
232
-            unset($key, $val);
232
+            unset( $key, $val );
233 233
         }
234
-        unset($action->ID);
234
+        unset( $action->ID );
235 235
 
236
-        return $this->save_settings($action);
236
+        return $this->save_settings( $action );
237 237
     }
238 238
 
239 239
 	private function duplicate_array_walk( $action, $subkey, $val ) {
240 240
         global $frm_duplicate_ids;
241 241
 
242
-        if ( is_array($subkey) ) {
242
+        if ( is_array( $subkey ) ) {
243 243
             foreach ( $subkey as $subkey2 ) {
244 244
                 foreach ( (array) $val as $ck => $cv ) {
245
-                    if ( is_array($cv) ) {
246
-						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
247
-					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248
-						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
245
+                    if ( is_array( $cv ) ) {
246
+						$action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv );
247
+					} else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) {
248
+						$action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]];
249 249
                     }
250 250
                 }
251 251
             }
252 252
         } else {
253 253
             foreach ( (array) $val as $ck => $cv ) {
254
-                if ( is_array($cv) ) {
255
-					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
256
-				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257
-					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
254
+                if ( is_array( $cv ) ) {
255
+					$action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv );
256
+				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) {
257
+					$action[$ck] = $frm_duplicate_ids[$cv];
258 258
                 }
259 259
             }
260 260
         }
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
  			return;
279 279
  		}
280 280
 
281
-		if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
282
-			$settings = $_POST[ $this->option_name ];
281
+		if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) {
282
+			$settings = $_POST[$this->option_name];
283 283
  		} else {
284 284
  			return;
285 285
  		}
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
         $action_ids = array();
288 288
 
289 289
  		foreach ( $settings as $number => $new_instance ) {
290
- 			$this->_set($number);
290
+ 			$this->_set( $number );
291 291
 
292
- 			if ( ! isset($new_instance['post_title']) ) {
292
+ 			if ( ! isset( $new_instance['post_title'] ) ) {
293 293
  			    // settings were never opened, so don't update
294 294
  			    $action_ids[] = $new_instance['ID'];
295 295
          		$this->updated = true;
296 296
          		continue;
297 297
  			}
298 298
 
299
-			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
299
+			$old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array();
300 300
 
301
- 			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
302
-			$new_instance['post_name']  = $this->form_id . '_' . $this->id_base . '_' . $this->number;
301
+ 			$new_instance['post_type'] = FrmFormActionsController::$action_post_type;
302
+			$new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
303 303
             $new_instance['menu_order']   = $this->form_id;
304 304
             $new_instance['post_status']  = 'publish';
305 305
             $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
@@ -321,14 +321,14 @@  discard block
 block discarded – undo
321 321
 			 */
322 322
 			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
323 323
 
324
-			$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
324
+			$instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
325 325
 			$instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
326 326
 
327 327
 			if ( false !== $instance ) {
328
-				$all_instances[ $number ] = $instance;
328
+				$all_instances[$number] = $instance;
329 329
 			}
330 330
 
331
-            $action_ids[] = $this->save_settings($instance);
331
+            $action_ids[] = $this->save_settings( $instance );
332 332
 
333 333
      		$this->updated = true;
334 334
  		}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	}
343 343
 
344 344
 	public function get_single_action( $id ) {
345
-	    $action = get_post($id);
345
+	    $action = get_post( $id );
346 346
 		if ( $action ) {
347 347
 			$action = $this->prepare_action( $action );
348 348
 			$this->_set( $id );
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	}
352 352
 
353 353
 	public function get_one( $form_id ) {
354
-	    return $this->get_all($form_id, 1);
354
+	    return $this->get_all( $form_id, 1 );
355 355
 	}
356 356
 
357 357
     public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
358 358
         $action_controls = FrmFormActionsController::get_form_actions( $type );
359
-        if ( empty($action_controls) ) {
359
+        if ( empty( $action_controls ) ) {
360 360
             // don't continue if there are no available actions
361 361
             return array();
362 362
         }
@@ -379,12 +379,12 @@  discard block
 block discarded – undo
379 379
 			// some plugins/themes are formatting the post_excerpt
380 380
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
381 381
 
382
-			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
382
+			if ( ! isset( $action_controls[$action->post_excerpt] ) ) {
383 383
                 continue;
384 384
             }
385 385
 
386
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
387
-			$settings[ $action->ID ] = $action;
386
+            $action = $action_controls[$action->post_excerpt]->prepare_action( $action );
387
+			$settings[$action->ID] = $action;
388 388
 
389 389
 			if ( count( $settings ) >= $limit ) {
390 390
 				break;
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
         }
393 393
 
394 394
         if ( 1 === $limit ) {
395
-            $settings = reset($settings);
395
+            $settings = reset( $settings );
396 396
         }
397 397
 
398 398
         return $settings;
@@ -434,27 +434,27 @@  discard block
 block discarded – undo
434 434
         $query['suppress_filters'] = false;
435 435
 
436 436
 		$actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
437
-        unset($query);
437
+        unset( $query );
438 438
 
439 439
 		remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
440 440
 
441
-        if ( empty($actions) ) {
441
+        if ( empty( $actions ) ) {
442 442
             return array();
443 443
         }
444 444
 
445 445
         $settings = array();
446 446
         foreach ( $actions as $action ) {
447
-            if ( count($settings) >= $limit ) {
447
+            if ( count( $settings ) >= $limit ) {
448 448
                 continue;
449 449
             }
450 450
 
451
-            $action = $this->prepare_action($action);
451
+            $action = $this->prepare_action( $action );
452 452
 
453
-			$settings[ $action->ID ] = $action;
453
+			$settings[$action->ID] = $action;
454 454
         }
455 455
 
456 456
         if ( 1 === $limit ) {
457
-            $settings = reset($settings);
457
+            $settings = reset( $settings );
458 458
         }
459 459
 
460 460
         return $settings;
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	}
478 478
 
479 479
 	public function prepare_action( $action ) {
480
-		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
480
+		$action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
481 481
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
482 482
 
483 483
         $default_values = $this->get_global_defaults();
@@ -486,16 +486,16 @@  discard block
 block discarded – undo
486 486
         $action->post_content += $default_values;
487 487
 
488 488
         foreach ( $default_values as $k => $vals ) {
489
-            if ( is_array($vals) && ! empty($vals) ) {
490
-				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
489
+            if ( is_array( $vals ) && ! empty( $vals ) ) {
490
+				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) {
491 491
                     continue;
492 492
                 }
493
-				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
493
+				$action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals );
494 494
             }
495 495
         }
496 496
 
497
-        if ( ! is_array($action->post_content['event']) ) {
498
-            $action->post_content['event'] = explode(',', $action->post_content['event']);
497
+        if ( ! is_array( $action->post_content['event'] ) ) {
498
+            $action->post_content['event'] = explode( ',', $action->post_content['event'] );
499 499
         }
500 500
 
501 501
         return $action;
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
518 518
 
519 519
         foreach ( $post_ids as $id ) {
520
-            wp_delete_post($id);
520
+            wp_delete_post( $id );
521 521
         }
522 522
 		self::clear_cache();
523 523
 	}
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
 	public function get_global_defaults() {
539 539
 	    $defaults = $this->get_defaults();
540 540
 
541
-	    if ( ! isset($defaults['event']) ) {
541
+	    if ( ! isset( $defaults['event'] ) ) {
542 542
 			$defaults['event'] = array( 'create' );
543 543
 	    }
544 544
 
545
-	    if ( ! isset($defaults['conditions']) ) {
545
+	    if ( ! isset( $defaults['conditions'] ) ) {
546 546
 	        $defaults['conditions'] = array(
547 547
                 'send_stop' => '',
548 548
                 'any_all'   => '',
@@ -562,18 +562,18 @@  discard block
 block discarded – undo
562 562
 	 * Migrate settings from form->options into new action.
563 563
 	 */
564 564
 	public function migrate_to_2( $form, $update = 'update' ) {
565
-        $action = $this->prepare_new($form->id);
566
-        $form->options = maybe_unserialize($form->options);
565
+        $action = $this->prepare_new( $form->id );
566
+        $form->options = maybe_unserialize( $form->options );
567 567
 
568 568
         // fill with existing options
569 569
         foreach ( $action->post_content as $name => $val ) {
570
-			if ( isset( $form->options[ $name ] ) ) {
571
-				$action->post_content[ $name ] = $form->options[ $name ];
572
-				unset( $form->options[ $name ] );
570
+			if ( isset( $form->options[$name] ) ) {
571
+				$action->post_content[$name] = $form->options[$name];
572
+				unset( $form->options[$name] );
573 573
             }
574 574
         }
575 575
 
576
-        $action = $this->migrate_values($action, $form);
576
+        $action = $this->migrate_values( $action, $form );
577 577
 
578 578
         // check if action already exists
579 579
         $post_id = get_posts( array(
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
             'numberposts'   => 1,
584 584
         ) );
585 585
 
586
-        if ( empty($post_id) ) {
586
+        if ( empty( $post_id ) ) {
587 587
             // create action now
588
-            $post_id = $this->save_settings($action);
588
+            $post_id = $this->save_settings( $action );
589 589
         }
590 590
 
591 591
         if ( $post_id && 'update' == $update ) {
592 592
             global $wpdb;
593
-            $form->options = maybe_serialize($form->options);
593
+            $form->options = maybe_serialize( $form->options );
594 594
 
595 595
             // update form options
596 596
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
@@ -622,18 +622,18 @@  discard block
 block discarded – undo
622 622
 
623 623
 			$observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
624 624
 
625
-			$stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
625
+			$stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
626 626
 
627 627
 			if ( $notification['conditions']['send_stop'] == 'send' ) {
628 628
 				$stop = $stop ? false : true;
629 629
 			}
630 630
 
631
-			$met[ $stop ] = $stop;
631
+			$met[$stop] = $stop;
632 632
 		}
633 633
 
634 634
 		if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
635 635
 			$stop = ( $notification['conditions']['send_stop'] == 'send' );
636
-		} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
636
+		} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
637 637
 			$stop = false;
638 638
 		}
639 639
 
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
 	private static function get_value_from_entry( $entry, $field_id ) {
669 669
 		$observed_value = '';
670 670
 
671
-		if ( isset( $entry->metas[ $field_id ] ) ) {
672
-			$observed_value = $entry->metas[ $field_id ];
671
+		if ( isset( $entry->metas[$field_id] ) ) {
672
+			$observed_value = $entry->metas[$field_id];
673 673
 		} else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
674 674
 			$field = FrmField::getOne( $field_id );
675 675
 			$observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( $entry, $field, array(
Please login to merge, or discard this patch.
classes/models/FrmEntryMeta.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmEntryMeta {
7 7
 
8
-    /**
9
-     * @param string $meta_key
10
-     */
8
+	/**
9
+	 * @param string $meta_key
10
+	 */
11 11
 	public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
-        global $wpdb;
12
+		global $wpdb;
13 13
 
14
-        if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
-            // don't save blank fields
16
-            return 0;
17
-        }
14
+		if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
+			// don't save blank fields
16
+			return 0;
17
+		}
18 18
 
19
-        $new_values = array(
19
+		$new_values = array(
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
-            'item_id'       => $entry_id,
22
-            'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
24
-        );
21
+			'item_id'       => $entry_id,
22
+			'field_id'      => $field_id,
23
+			'created_at'    => current_time('mysql', 1),
24
+		);
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+		$new_values = apply_filters('frm_add_entry_meta', $new_values);
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -35,46 +35,46 @@  discard block
 block discarded – undo
35 35
 			$id = 0;
36 36
 		}
37 37
 
38
-        return $id;
39
-    }
38
+		return $id;
39
+	}
40 40
 
41
-    /**
42
-     * @param string $meta_key
43
-     */
41
+	/**
42
+	 * @param string $meta_key
43
+	 */
44 44
 	public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
45
-        if ( ! $field_id ) {
46
-            return false;
47
-        }
45
+		if ( ! $field_id ) {
46
+			return false;
47
+		}
48 48
 
49
-        global $wpdb;
49
+		global $wpdb;
50 50
 
51 51
 		$values = array(
52 52
 			'item_id'  => $entry_id,
53 53
 			'field_id' => $field_id,
54 54
 		);
55 55
 		$where_values = $values;
56
-        $values['meta_value'] = $meta_value;
57
-        $values = apply_filters('frm_update_entry_meta', $values);
56
+		$values['meta_value'] = $meta_value;
57
+		$values = apply_filters('frm_update_entry_meta', $values);
58 58
 		if ( is_array($values['meta_value']) ) {
59 59
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
60 60
 		}
61
-        $meta_value = maybe_serialize($values['meta_value']);
61
+		$meta_value = maybe_serialize($values['meta_value']);
62 62
 
63
-        wp_cache_delete( $entry_id, 'frm_entry');
63
+		wp_cache_delete( $entry_id, 'frm_entry');
64 64
 		self::clear_cache();
65 65
 
66 66
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
67
-    }
67
+	}
68 68
 
69 69
 	public static function update_entry_metas( $entry_id, $values ) {
70
-        global $wpdb;
70
+		global $wpdb;
71 71
 
72 72
 		$prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array(
73 73
 			'item_id'    => $entry_id,
74 74
 			'field_id !' => 0,
75 75
 		), 'field_id' );
76 76
 
77
-        foreach ( $values as $field_id => $meta_value ) {
77
+		foreach ( $values as $field_id => $meta_value ) {
78 78
 			$field = false;
79 79
 			if ( ! empty( $field_id ) ) {
80 80
 				$field = FrmField::getOne( $field_id );
@@ -98,15 +98,15 @@  discard block
 block discarded – undo
98 98
 			}
99 99
 		}
100 100
 
101
-        if ( empty($prev_values) ) {
102
-            return;
103
-        }
101
+		if ( empty($prev_values) ) {
102
+			return;
103
+		}
104 104
 
105
-        $prev_values = array_diff($prev_values, array_keys($values));
105
+		$prev_values = array_diff($prev_values, array_keys($values));
106 106
 
107
-        if ( empty($prev_values) ) {
108
-            return;
109
-        }
107
+		if ( empty($prev_values) ) {
108
+			return;
109
+		}
110 110
 
111 111
 		// prepare the query
112 112
 		$where = array(
@@ -115,25 +115,25 @@  discard block
 block discarded – undo
115 115
 		);
116 116
 		FrmDb::get_where_clause_and_values( $where );
117 117
 
118
-        // Delete any leftovers
119
-        $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
118
+		// Delete any leftovers
119
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
120 120
 		self::clear_cache();
121
-    }
121
+	}
122 122
 
123 123
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
124
-        $metas = self::get_entry_meta_info($old_id);
125
-        foreach ( $metas as $meta ) {
126
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
127
-            unset($meta);
128
-        }
124
+		$metas = self::get_entry_meta_info($old_id);
125
+		foreach ( $metas as $meta ) {
126
+			self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
127
+			unset($meta);
128
+		}
129 129
 		self::clear_cache();
130
-    }
130
+	}
131 131
 
132 132
 	public static function delete_entry_meta( $entry_id, $field_id ) {
133
-        global $wpdb;
133
+		global $wpdb;
134 134
 		self::clear_cache();
135
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
136
-    }
135
+		return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
136
+	}
137 137
 
138 138
 	/**
139 139
 	 * Clear entry meta caching
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	}
159 159
 
160 160
 	public static function get_entry_meta_by_field( $entry_id, $field_id ) {
161
-        global $wpdb;
161
+		global $wpdb;
162 162
 
163 163
 		if ( is_object( $entry_id ) ) {
164 164
 			$entry = $entry_id;
@@ -171,93 +171,93 @@  discard block
 block discarded – undo
171 171
 
172 172
 		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
173 173
 			$result = $cached->metas[ $field_id ];
174
-            return stripslashes_deep($result);
175
-        }
174
+			return stripslashes_deep($result);
175
+		}
176 176
 
177 177
 		$get_table = $wpdb->prefix . 'frm_item_metas';
178 178
 		$query = array( 'item_id' => $entry_id );
179
-        if ( is_numeric($field_id) ) {
179
+		if ( is_numeric($field_id) ) {
180 180
 			$query['field_id'] = $field_id;
181
-        } else {
181
+		} else {
182 182
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
183 183
 			$query['fi.field_key'] = $field_id;
184
-        }
184
+		}
185 185
 
186 186
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
187
-        $result = maybe_unserialize($result);
188
-        $result = stripslashes_deep($result);
187
+		$result = maybe_unserialize($result);
188
+		$result = stripslashes_deep($result);
189 189
 
190
-        return $result;
191
-    }
190
+		return $result;
191
+	}
192 192
 
193
-    public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
193
+	public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
194 194
 		$defaults = array(
195 195
 			'value'    => false,
196 196
 			'unique'   => false,
197 197
 			'stripslashes' => true,
198 198
 			'is_draft' => false,
199 199
 		);
200
-        $args = wp_parse_args( $args, $defaults );
200
+		$args = wp_parse_args( $args, $defaults );
201 201
 
202
-        $query = array();
203
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
204
-        $query = implode(' ', $query);
202
+		$query = array();
203
+		self::meta_field_query($field_id, $order, $limit, $args, $query);
204
+		$query = implode(' ', $query);
205 205
 
206 206
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
207
-        $values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
207
+		$values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
208 208
 
209
-        if ( ! $args['stripslashes'] ) {
210
-            return $values;
211
-        }
209
+		if ( ! $args['stripslashes'] ) {
210
+			return $values;
211
+		}
212 212
 
213 213
 		foreach ( $values as $k => $v ) {
214 214
 			$values[ $k ] = maybe_unserialize( $v );
215
-            unset($k, $v);
216
-        }
215
+			unset($k, $v);
216
+		}
217 217
 
218
-        return stripslashes_deep($values);
219
-    }
218
+		return stripslashes_deep($values);
219
+	}
220 220
 
221
-    /**
222
-     * @param string $order
223
-     * @param string $limit
224
-     */
221
+	/**
222
+	 * @param string $order
223
+	 * @param string $limit
224
+	 */
225 225
 	private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
226
-        global $wpdb;
227
-        $query[] = 'SELECT';
228
-        $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
226
+		global $wpdb;
227
+		$query[] = 'SELECT';
228
+		$query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
229 229
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
230 230
 
231
-        if ( ! $args['is_draft'] ) {
231
+		if ( ! $args['is_draft'] ) {
232 232
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
233
-        }
233
+		}
234 234
 
235
-        if ( is_numeric($field_id) ) {
236
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
237
-        } else {
235
+		if ( is_numeric($field_id) ) {
236
+			$query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
237
+		} else {
238 238
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
239
-        }
239
+		}
240 240
 
241
-        if ( ! $args['is_draft'] ) {
242
-            $query[] = 'AND e.is_draft=0';
243
-        }
241
+		if ( ! $args['is_draft'] ) {
242
+			$query[] = 'AND e.is_draft=0';
243
+		}
244 244
 
245
-        if ( $args['value'] ) {
246
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
247
-        }
248
-        $query[] = $order . $limit;
249
-    }
245
+		if ( $args['value'] ) {
246
+			$query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
247
+		}
248
+		$query[] = $order . $limit;
249
+	}
250 250
 
251 251
 	public static function get_entry_meta_info( $entry_id ) {
252 252
 		return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
253
-    }
253
+	}
254 254
 
255 255
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
256
-        global $wpdb;
257
-        $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
256
+		global $wpdb;
257
+		$query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
258 258
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
259 259
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
260
-            FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
260
+			FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
261 261
 
262 262
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
263 263
 		$results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
@@ -272,32 +272,32 @@  discard block
 block discarded – undo
272 272
 		}
273 273
 
274 274
 		return $results;
275
-    }
275
+	}
276 276
 
277
-    public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
277
+	public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
278 278
 		$defaults = array(
279 279
 			'is_draft' => false,
280 280
 			'user_id'  => '',
281 281
 			'group_by' => '',
282 282
 		);
283
-        $args = wp_parse_args($args, $defaults);
283
+		$args = wp_parse_args($args, $defaults);
284 284
 
285
-        $query = array();
286
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
287
-        $query = implode(' ', $query);
285
+		$query = array();
286
+		self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
287
+		$query = implode(' ', $query);
288 288
 
289 289
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
290 290
 		return FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
291
-    }
291
+	}
292 292
 
293
-    /**
294
-     * @param string|array $where
295
-     * @param string $order_by
296
-     * @param string $limit
297
-     */
293
+	/**
294
+	 * @param string|array $where
295
+	 * @param string $order_by
296
+	 * @param string $limit
297
+	 */
298 298
 	private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
299
-        global $wpdb;
300
-        $query[] = 'SELECT';
299
+		global $wpdb;
300
+		$query[] = 'SELECT';
301 301
 
302 302
 		$defaults = array( 'return_parent_id' => false );
303 303
 		$args = array_merge( $defaults, $args );
@@ -311,89 +311,89 @@  discard block
 block discarded – undo
311 311
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
312 312
 
313 313
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
314
-        if ( is_array($where) ) {
315
-            if ( ! $args['is_draft'] ) {
316
-                $where['e.is_draft'] = 0;
317
-            } else if ( $args['is_draft'] == 1 ) {
318
-                $where['e.is_draft'] = 1;
319
-            }
320
-
321
-            if ( ! empty($args['user_id']) ) {
322
-                $where['e.user_id'] = $args['user_id'];
323
-            }
324
-            $query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
314
+		if ( is_array($where) ) {
315
+			if ( ! $args['is_draft'] ) {
316
+				$where['e.is_draft'] = 0;
317
+			} else if ( $args['is_draft'] == 1 ) {
318
+				$where['e.is_draft'] = 1;
319
+			}
320
+
321
+			if ( ! empty($args['user_id']) ) {
322
+				$where['e.user_id'] = $args['user_id'];
323
+			}
324
+			$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
325 325
 
326 326
 			if ( $args['group_by'] ) {
327 327
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
328 328
 			}
329
-            return;
330
-        }
329
+			return;
330
+		}
331 331
 
332 332
 		$draft_where = '';
333 333
 		$user_where = '';
334
-        if ( ! $args['is_draft'] ) {
334
+		if ( ! $args['is_draft'] ) {
335 335
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
336
-        } else if ( $args['is_draft'] == 1 ) {
336
+		} else if ( $args['is_draft'] == 1 ) {
337 337
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
338
-        }
338
+		}
339 339
 
340
-        if ( ! empty($args['user_id']) ) {
341
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
342
-        }
340
+		if ( ! empty($args['user_id']) ) {
341
+			$user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
342
+		}
343 343
 
344
-        if ( strpos($where, ' GROUP BY ') ) {
345
-            // don't inject WHERE filtering after GROUP BY
346
-            $parts = explode(' GROUP BY ', $where);
347
-            $where = $parts[0];
348
-            $where .= $draft_where . $user_where;
344
+		if ( strpos($where, ' GROUP BY ') ) {
345
+			// don't inject WHERE filtering after GROUP BY
346
+			$parts = explode(' GROUP BY ', $where);
347
+			$where = $parts[0];
348
+			$where .= $draft_where . $user_where;
349 349
 			$where .= ' GROUP BY ' . $parts[1];
350
-        } else {
351
-            $where .= $draft_where . $user_where;
352
-        }
350
+		} else {
351
+			$where .= $draft_where . $user_where;
352
+		}
353 353
 
354 354
 		// The query has already been prepared
355 355
 		$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
356
-    }
356
+	}
357 357
 
358
-    public static function search_entry_metas( $search, $field_id = '', $operator ) {
358
+	public static function search_entry_metas( $search, $field_id = '', $operator ) {
359 359
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
360
-        $results = wp_cache_get($cache_key, 'frm_entry');
361
-        if ( false !== $results ) {
362
-            return $results;
363
-        }
360
+		$results = wp_cache_get($cache_key, 'frm_entry');
361
+		if ( false !== $results ) {
362
+			return $results;
363
+		}
364 364
 
365
-        global $wpdb;
365
+		global $wpdb;
366 366
 		if ( is_array( $search ) ) {
367
-            $where = '';
367
+			$where = '';
368 368
 			foreach ( $search as $field => $value ) {
369 369
 				if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
370
-                    continue;
371
-                }
370
+					continue;
371
+				}
372 372
 
373
-                switch ( $field ) {
374
-                    case 'year':
373
+				switch ( $field ) {
374
+					case 'year':
375 375
 						$value = '%' . $value;
376 376
 						break;
377
-                    case 'month':
378
-                        $value .= '%';
377
+					case 'month':
378
+						$value .= '%';
379 379
 						break;
380
-                    case 'day':
380
+					case 'day':
381 381
 						$value = '%' . $value . '%';
382
-                }
382
+				}
383 383
 				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
384
-            }
385
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
384
+			}
385
+			$where .= $wpdb->prepare(' field_id=%d', $field_id);
386 386
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
387
-        } else {
387
+		} else {
388 388
 			if ( $operator == 'LIKE' ) {
389
-                $search = '%' . $search . '%';
389
+				$search = '%' . $search . '%';
390 390
 			}
391
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
392
-        }
391
+			$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
392
+		}
393 393
 
394
-        $results = $wpdb->get_col($query, 0);
394
+		$results = $wpdb->get_col($query, 0);
395 395
 		FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
396 396
 
397
-        return $results;
398
-    }
397
+		return $results;
398
+	}
399 399
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21 21
             'item_id'       => $entry_id,
22 22
             'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
23
+            'created_at'    => current_time( 'mysql', 1 ),
24 24
         );
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+        $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 		);
55 55
 		$where_values = $values;
56 56
         $values['meta_value'] = $meta_value;
57
-        $values = apply_filters('frm_update_entry_meta', $values);
58
-		if ( is_array($values['meta_value']) ) {
57
+        $values = apply_filters( 'frm_update_entry_meta', $values );
58
+		if ( is_array( $values['meta_value'] ) ) {
59 59
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
60 60
 		}
61
-        $meta_value = maybe_serialize($values['meta_value']);
61
+        $meta_value = maybe_serialize( $values['meta_value'] );
62 62
 
63
-        wp_cache_delete( $entry_id, 'frm_entry');
63
+        wp_cache_delete( $entry_id, 'frm_entry' );
64 64
 		self::clear_cache();
65 65
 
66 66
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			// set the value for the file upload field and add new tags (in Pro version)
84 84
 			$meta_value = apply_filters( 'frm_prepare_data_before_db', $meta_value, $field_id, $entry_id, compact( 'field' ) );
85 85
 
86
-			if ( $prev_values && in_array($field_id, $prev_values) ) {
86
+			if ( $prev_values && in_array( $field_id, $prev_values ) ) {
87 87
 
88 88
 				if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
89 89
 					// remove blank fields
90
-					unset( $values[ $field_id ] );
90
+					unset( $values[$field_id] );
91 91
 				} else {
92 92
 					// if value exists, then update it
93 93
 					self::update_entry_meta( $entry_id, $field_id, '', $meta_value );
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 			}
99 99
 		}
100 100
 
101
-        if ( empty($prev_values) ) {
101
+        if ( empty( $prev_values ) ) {
102 102
             return;
103 103
         }
104 104
 
105
-        $prev_values = array_diff($prev_values, array_keys($values));
105
+        $prev_values = array_diff( $prev_values, array_keys( $values ) );
106 106
 
107
-        if ( empty($prev_values) ) {
107
+        if ( empty( $prev_values ) ) {
108 108
             return;
109 109
         }
110 110
 
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
     }
122 122
 
123 123
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
124
-        $metas = self::get_entry_meta_info($old_id);
124
+        $metas = self::get_entry_meta_info( $old_id );
125 125
         foreach ( $metas as $meta ) {
126
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
127
-            unset($meta);
126
+            self::add_entry_meta( $new_id, $meta->field_id, null, $meta->meta_value );
127
+            unset( $meta );
128 128
         }
129 129
 		self::clear_cache();
130 130
     }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	public static function delete_entry_meta( $entry_id, $field_id ) {
133 133
         global $wpdb;
134 134
 		self::clear_cache();
135
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
135
+        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
136 136
     }
137 137
 
138 138
 	/**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 */
152 152
 	public static function get_meta_value( $entry, $field_id ) {
153 153
 		if ( isset( $entry->metas ) ) {
154
-			return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
154
+			return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false;
155 155
 		} else {
156 156
 			return self::get_entry_meta_by_field( $entry->id, $field_id );
157 157
 		}
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 			$cached = FrmDb::check_cache( $entry_id, 'frm_entry' );
170 170
 		}
171 171
 
172
-		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
173
-			$result = $cached->metas[ $field_id ];
174
-            return stripslashes_deep($result);
172
+		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) {
173
+			$result = $cached->metas[$field_id];
174
+            return stripslashes_deep( $result );
175 175
         }
176 176
 
177 177
 		$get_table = $wpdb->prefix . 'frm_item_metas';
178 178
 		$query = array( 'item_id' => $entry_id );
179
-        if ( is_numeric($field_id) ) {
179
+        if ( is_numeric( $field_id ) ) {
180 180
 			$query['field_id'] = $field_id;
181 181
         } else {
182 182
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
         }
185 185
 
186 186
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
187
-        $result = maybe_unserialize($result);
188
-        $result = stripslashes_deep($result);
187
+        $result = maybe_unserialize( $result );
188
+        $result = stripslashes_deep( $result );
189 189
 
190 190
         return $result;
191 191
     }
@@ -200,22 +200,22 @@  discard block
 block discarded – undo
200 200
         $args = wp_parse_args( $args, $defaults );
201 201
 
202 202
         $query = array();
203
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
204
-        $query = implode(' ', $query);
203
+        self::meta_field_query( $field_id, $order, $limit, $args, $query );
204
+        $query = implode( ' ', $query );
205 205
 
206 206
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
207
-        $values = FrmDb::check_cache($cache_key, 'frm_entry', $query, 'get_col');
207
+        $values = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
208 208
 
209 209
         if ( ! $args['stripslashes'] ) {
210 210
             return $values;
211 211
         }
212 212
 
213 213
 		foreach ( $values as $k => $v ) {
214
-			$values[ $k ] = maybe_unserialize( $v );
215
-            unset($k, $v);
214
+			$values[$k] = maybe_unserialize( $v );
215
+            unset( $k, $v );
216 216
         }
217 217
 
218
-        return stripslashes_deep($values);
218
+        return stripslashes_deep( $values );
219 219
     }
220 220
 
221 221
     /**
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
233 233
         }
234 234
 
235
-        if ( is_numeric($field_id) ) {
236
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
235
+        if ( is_numeric( $field_id ) ) {
236
+            $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
237 237
         } else {
238 238
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
239 239
         }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         }
244 244
 
245 245
         if ( $args['value'] ) {
246
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
246
+            $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
247 247
         }
248 248
         $query[] = $order . $limit;
249 249
     }
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
258 258
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
259 259
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
260
-            FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
260
+            FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
261 261
 
262 262
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
263 263
 		$results = FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		}
268 268
 
269 269
 		foreach ( $results as $k => $result ) {
270
-			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
270
+			$results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
271 271
 			unset( $k, $result );
272 272
 		}
273 273
 
@@ -280,11 +280,11 @@  discard block
 block discarded – undo
280 280
 			'user_id'  => '',
281 281
 			'group_by' => '',
282 282
 		);
283
-        $args = wp_parse_args($args, $defaults);
283
+        $args = wp_parse_args( $args, $defaults );
284 284
 
285 285
         $query = array();
286
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
287
-        $query = implode(' ', $query);
286
+        self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
287
+        $query = implode( ' ', $query );
288 288
 
289 289
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
290 290
 		return FrmDb::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
@@ -311,17 +311,17 @@  discard block
 block discarded – undo
311 311
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
312 312
 
313 313
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
314
-        if ( is_array($where) ) {
314
+        if ( is_array( $where ) ) {
315 315
             if ( ! $args['is_draft'] ) {
316 316
                 $where['e.is_draft'] = 0;
317 317
             } else if ( $args['is_draft'] == 1 ) {
318 318
                 $where['e.is_draft'] = 1;
319 319
             }
320 320
 
321
-            if ( ! empty($args['user_id']) ) {
321
+            if ( ! empty( $args['user_id'] ) ) {
322 322
                 $where['e.user_id'] = $args['user_id'];
323 323
             }
324
-            $query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
324
+            $query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
325 325
 
326 326
 			if ( $args['group_by'] ) {
327 327
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
338 338
         }
339 339
 
340
-        if ( ! empty($args['user_id']) ) {
341
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
340
+        if ( ! empty( $args['user_id'] ) ) {
341
+            $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
342 342
         }
343 343
 
344
-        if ( strpos($where, ' GROUP BY ') ) {
344
+        if ( strpos( $where, ' GROUP BY ' ) ) {
345 345
             // don't inject WHERE filtering after GROUP BY
346
-            $parts = explode(' GROUP BY ', $where);
346
+            $parts = explode( ' GROUP BY ', $where );
347 347
             $where = $parts[0];
348 348
             $where .= $draft_where . $user_where;
349 349
 			$where .= ' GROUP BY ' . $parts[1];
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
         }
353 353
 
354 354
 		// The query has already been prepared
355
-		$query[] = FrmDb::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
355
+		$query[] = FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
356 356
     }
357 357
 
358 358
     public static function search_entry_metas( $search, $field_id = '', $operator ) {
359 359
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
360
-        $results = wp_cache_get($cache_key, 'frm_entry');
360
+        $results = wp_cache_get( $cache_key, 'frm_entry' );
361 361
         if ( false !== $results ) {
362 362
             return $results;
363 363
         }
@@ -380,18 +380,18 @@  discard block
 block discarded – undo
380 380
                     case 'day':
381 381
 						$value = '%' . $value . '%';
382 382
                 }
383
-				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
383
+				$where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value );
384 384
             }
385
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
385
+            $where .= $wpdb->prepare( ' field_id=%d', $field_id );
386 386
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where );
387 387
         } else {
388 388
 			if ( $operator == 'LIKE' ) {
389 389
                 $search = '%' . $search . '%';
390 390
 			}
391
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
391
+            $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id );
392 392
         }
393 393
 
394
-        $results = $wpdb->get_col($query, 0);
394
+        $results = $wpdb->get_col( $query, 0 );
395 395
 		FrmDb::set_cache( $cache_key, $results, 'frm_entry' );
396 396
 
397 397
         return $results;
Please login to merge, or discard this patch.
classes/models/FrmField.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmField {
7 7
 
8
-    static $use_cache = true;
8
+	static $use_cache = true;
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
@@ -52,39 +52,39 @@  discard block
 block discarded – undo
52 52
 		));
53 53
 	}
54 54
 
55
-    public static function create( $values, $return = true ) {
56
-        global $wpdb, $frm_duplicate_ids;
55
+	public static function create( $values, $return = true ) {
56
+		global $wpdb, $frm_duplicate_ids;
57 57
 
58
-        $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
58
+		$new_values = array();
59
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63 63
 			$new_values[ $col ] = $values[ $col ];
64
-        }
64
+		}
65 65
 
66
-        $new_values['options'] = $values['options'];
66
+		$new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
-        $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
68
+		$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
+		$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
+		$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
+		$new_values['field_options'] = $values['field_options'];
72
+		$new_values['created_at'] = current_time('mysql', 1);
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75 75
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
77
-        }
76
+			$new_values = apply_filters('frm_duplicated_field', $new_values);
77
+		}
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80
-            if ( is_array( $v ) ) {
80
+			if ( is_array( $v ) ) {
81 81
 				$new_values[ $k ] = serialize( $v );
82 82
 			}
83
-            unset( $k, $v );
84
-        }
83
+			unset( $k, $v );
84
+		}
85 85
 
86
-        //if(isset($values['id']) and is_numeric($values['id']))
87
-        //    $new_values['id'] = $values['id'];
86
+		//if(isset($values['id']) and is_numeric($values['id']))
87
+		//    $new_values['id'] = $values['id'];
88 88
 
89 89
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
90 90
 		$new_id = 0;
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
 		} else {
106 106
 			return false;
107 107
 		}
108
-    }
108
+	}
109 109
 
110
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
-        global $frm_duplicate_ids;
110
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
+		global $frm_duplicate_ids;
112 112
 
113 113
 		$where = array( array(
114 114
 			'or' => 1,
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 		) );
118 118
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
119 119
 
120
-        foreach ( (array) $fields as $field ) {
120
+		foreach ( (array) $fields as $field ) {
121 121
 			$new_key = $copy_keys ? $field->field_key : '';
122
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
123
-                $new_key = rtrim($new_key, 2);
124
-            }
122
+			if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
123
+				$new_key = rtrim($new_key, 2);
124
+			}
125 125
 
126
-            $values = array();
127
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
126
+			$values = array();
127
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
128 128
 
129 129
 			// If this is a repeating section, create new form
130 130
 			if ( self::is_repeating_field( $field ) ) {
@@ -146,16 +146,16 @@  discard block
 block discarded – undo
146 146
 				$values['form_id'] = $new_repeat_form_id;
147 147
 			}
148 148
 
149
-            $values = apply_filters('frm_duplicated_field', $values);
150
-            $new_id = self::create($values);
151
-            $frm_duplicate_ids[ $field->id ] = $new_id;
152
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
153
-            unset($field);
154
-        }
155
-    }
149
+			$values = apply_filters('frm_duplicated_field', $values);
150
+			$new_id = self::create($values);
151
+			$frm_duplicate_ids[ $field->id ] = $new_id;
152
+			$frm_duplicate_ids[ $field->field_key ] = $new_id;
153
+			unset($field);
154
+		}
155
+	}
156 156
 
157 157
 	public static function update( $id, $values ) {
158
-        global $wpdb;
158
+		global $wpdb;
159 159
 
160 160
 		$id = absint( $id );
161 161
 
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
164 164
 		}
165 165
 
166
-        if ( isset($values['required']) ) {
167
-            $values['required'] = (int) $values['required'];
168
-        }
166
+		if ( isset($values['required']) ) {
167
+			$values['required'] = (int) $values['required'];
168
+		}
169 169
 
170 170
 		self::preserve_format_option_backslashes( $values );
171 171
 
@@ -187,41 +187,41 @@  discard block
 block discarded – undo
187 187
 
188 188
 		$query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
189 189
 
190
-        $form_id = 0;
190
+		$form_id = 0;
191 191
 		if ( isset( $values['form_id'] ) ) {
192
-            $form_id = absint( $values['form_id'] );
192
+			$form_id = absint( $values['form_id'] );
193 193
 		} else {
194
-            $field = self::getOne($id);
195
-            if ( $field ) {
196
-                $form_id = $field->form_id;
197
-            }
198
-            unset($field);
199
-        }
200
-        unset($values);
194
+			$field = self::getOne($id);
195
+			if ( $field ) {
196
+				$form_id = $field->form_id;
197
+			}
198
+			unset($field);
199
+		}
200
+		unset($values);
201 201
 
202 202
 		if ( $query_results ) {
203
-            wp_cache_delete( $id, 'frm_field' );
204
-            if ( $form_id ) {
205
-                self::delete_form_transient( $form_id );
206
-            }
207
-        }
203
+			wp_cache_delete( $id, 'frm_field' );
204
+			if ( $form_id ) {
205
+				self::delete_form_transient( $form_id );
206
+			}
207
+		}
208 208
 
209
-        return $query_results;
210
-    }
209
+		return $query_results;
210
+	}
211 211
 
212 212
 	/**
213
-	* Keep backslashes in the phone format option
214
-	*
215
-	* @since 2.0.8
216
-	* @param $values array - pass by reference
217
-	*/
213
+	 * Keep backslashes in the phone format option
214
+	 *
215
+	 * @since 2.0.8
216
+	 * @param $values array - pass by reference
217
+	 */
218 218
 	private static function preserve_format_option_backslashes( &$values ) {
219 219
 		if ( isset( $values['field_options']['format'] ) ) {
220 220
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
221 221
 		}
222 222
 	}
223 223
 
224
-    public static function destroy( $id ) {
224
+	public static function destroy( $id ) {
225 225
 		global $wpdb;
226 226
 
227 227
 		do_action( 'frm_before_destroy_field', $id );
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 
237 237
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
238 238
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
239
-    }
239
+	}
240 240
 
241 241
 	public static function delete_form_transient( $form_id ) {
242 242
 		$form_id = absint( $form_id );
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 
251 251
 		FrmDb::cache_delete_group( 'frm_field' );
252 252
 
253
-        $form = FrmForm::getOne($form_id);
254
-        if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
255
-            self::delete_form_transient( $form->parent_form_id );
256
-        }
257
-    }
253
+		$form = FrmForm::getOne($form_id);
254
+		if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
255
+			self::delete_form_transient( $form->parent_form_id );
256
+		}
257
+	}
258 258
 
259 259
 	/**
260 260
 	 * If $field is numeric, get the field object
@@ -270,83 +270,83 @@  discard block
 block discarded – undo
270 270
 			return null;
271 271
 		}
272 272
 
273
-        global $wpdb;
273
+		global $wpdb;
274 274
 
275
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
275
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
276 276
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
277 277
 
278
-        $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
278
+		$results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
279 279
 
280
-        if ( empty($results) ) {
281
-            return $results;
282
-        }
280
+		if ( empty($results) ) {
281
+			return $results;
282
+		}
283 283
 
284
-        if ( is_numeric($id) ) {
284
+		if ( is_numeric($id) ) {
285 285
 			FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
286
-        } else if ( $results ) {
286
+		} else if ( $results ) {
287 287
 			FrmDb::set_cache( $results->id, $results, 'frm_field' );
288
-        }
288
+		}
289 289
 
290 290
 		self::prepare_options( $results );
291 291
 
292
-        return stripslashes_deep($results);
293
-    }
292
+		return stripslashes_deep($results);
293
+	}
294 294
 
295
-    /**
296
-     * Get the field type by key or id
297
-     * @param int|string The field id or key
295
+	/**
296
+	 * Get the field type by key or id
297
+	 * @param int|string The field id or key
298 298
 	 * @param mixed $col The name of the column in the fields database table
299
-     */
300
-    public static function get_type( $id, $col = 'type' ) {
301
-        $field = FrmDb::check_cache( $id, 'frm_field' );
302
-        if ( $field ) {
303
-            $type = $field->{$col};
304
-        } else {
299
+	 */
300
+	public static function get_type( $id, $col = 'type' ) {
301
+		$field = FrmDb::check_cache( $id, 'frm_field' );
302
+		if ( $field ) {
303
+			$type = $field->{$col};
304
+		} else {
305 305
 			$where = array(
306 306
 				'or'        => 1,
307 307
 				'id'        => $id,
308 308
 				'field_key' => $id,
309 309
 			);
310 310
 			$type = FrmDb::get_var( 'frm_fields', $where, $col );
311
-        }
311
+		}
312 312
 
313
-        return $type;
314
-    }
313
+		return $type;
314
+	}
315 315
 
316 316
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
317
-        if ( ! $form_id ) {
318
-            return array();
319
-        }
317
+		if ( ! $form_id ) {
318
+			return array();
319
+		}
320 320
 
321 321
 		$results = self::get_fields_from_transients( $form_id, array(
322 322
 			'inc_embed'  => $inc_sub,
323 323
 			'inc_repeat' => $inc_sub,
324 324
 		) );
325 325
 		if ( ! empty( $results ) ) {
326
-            $fields = array();
327
-            $count = 0;
328
-            foreach ( $results as $result ) {
329
-                if ( $type != $result->type ) {
330
-                    continue;
331
-                }
326
+			$fields = array();
327
+			$count = 0;
328
+			foreach ( $results as $result ) {
329
+				if ( $type != $result->type ) {
330
+					continue;
331
+				}
332 332
 
333 333
 				$fields[ $result->id ] = $result;
334
-                $count++;
335
-                if ( $limit == 1 ) {
336
-                    $fields = $result;
337
-                    break;
338
-                }
334
+				$count++;
335
+				if ( $limit == 1 ) {
336
+					$fields = $result;
337
+					break;
338
+				}
339 339
 
340
-                if ( ! empty($limit) && $count >= $limit ) {
341
-                    break;
342
-                }
340
+				if ( ! empty($limit) && $count >= $limit ) {
341
+					break;
342
+				}
343 343
 
344
-                unset($result);
345
-            }
346
-            return stripslashes_deep($fields);
347
-        }
344
+				unset($result);
345
+			}
346
+			return stripslashes_deep($fields);
347
+		}
348 348
 
349
-        self::$use_cache = false;
349
+		self::$use_cache = false;
350 350
 
351 351
 		$where = array(
352 352
 			'fi.form_id' => (int) $form_id,
@@ -354,64 +354,64 @@  discard block
 block discarded – undo
354 354
 		);
355 355
 		self::maybe_include_repeating_fields( $inc_sub, $where );
356 356
 		$results = self::getAll( $where, 'field_order', $limit );
357
-        self::$use_cache = true;
358
-        self::include_sub_fields($results, $inc_sub, $type);
357
+		self::$use_cache = true;
358
+		self::include_sub_fields($results, $inc_sub, $type);
359 359
 
360
-        return $results;
361
-    }
360
+		return $results;
361
+	}
362 362
 
363 363
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
364
-        if ( ! (int) $form_id ) {
365
-            return array();
366
-        }
364
+		if ( ! (int) $form_id ) {
365
+			return array();
366
+		}
367 367
 
368 368
 		$results = self::get_fields_from_transients( $form_id, array(
369 369
 			'inc_embed'  => $inc_embed,
370 370
 			'inc_repeat' => $inc_repeat,
371 371
 		) );
372 372
 		if ( ! empty( $results ) ) {
373
-            if ( empty($limit) ) {
373
+			if ( empty($limit) ) {
374 374
 				return $results;
375
-            }
375
+			}
376 376
 
377
-            $fields = array();
378
-            $count = 0;
379
-            foreach ( $results as $result ) {
377
+			$fields = array();
378
+			$count = 0;
379
+			foreach ( $results as $result ) {
380 380
 				$fields[ $result->id ] = $result;
381
-                if ( ! empty($limit) && $count >= $limit ) {
382
-                    break;
383
-                }
384
-            }
381
+				if ( ! empty($limit) && $count >= $limit ) {
382
+					break;
383
+				}
384
+			}
385 385
 
386 386
 			return $fields;
387
-        }
387
+		}
388 388
 
389
-        self::$use_cache = false;
389
+		self::$use_cache = false;
390 390
 
391 391
 		$where = array( 'fi.form_id' => absint( $form_id ) );
392 392
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
393 393
 		$results = self::getAll( $where, 'field_order', $limit );
394 394
 
395
-        self::$use_cache = true;
395
+		self::$use_cache = true;
396 396
 
397 397
 		self::include_sub_fields( $results, $inc_embed, 'all' );
398 398
 
399
-        if ( empty($limit) ) {
399
+		if ( empty($limit) ) {
400 400
 			self::set_field_transient( $results, $form_id, 0, array(
401 401
 				'inc_embed'  => $inc_embed,
402 402
 				'inc_repeat' => $inc_repeat,
403 403
 			) );
404
-        }
404
+		}
405 405
 
406 406
 		return $results;
407
-    }
407
+	}
408 408
 
409 409
 	/**
410
-	* If repeating fields should be included, adjust $where accordingly
411
-	*
412
-	* @param string $inc_repeat
413
-	* @param array $where - pass by reference
414
-	*/
410
+	 * If repeating fields should be included, adjust $where accordingly
411
+	 *
412
+	 * @param string $inc_repeat
413
+	 * @param array $where - pass by reference
414
+	 */
415 415
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
416 416
 		if ( $inc_repeat == 'include' ) {
417 417
 			$form_id = $where['fi.form_id'];
@@ -426,57 +426,57 @@  discard block
 block discarded – undo
426 426
 
427 427
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
428 428
 		if ( 'include' != $inc_embed || empty( $results ) ) {
429
-            return;
430
-        }
429
+			return;
430
+		}
431 431
 
432
-        $form_fields = $results;
432
+		$form_fields = $results;
433 433
 		$index_offset = 1;
434
-        foreach ( $form_fields as $k => $field ) {
435
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
436
-                continue;
437
-            }
438
-
439
-            if ( $type == 'all' ) {
440
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
441
-            } else {
442
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
443
-            }
444
-
445
-            if ( ! empty($sub_fields) ) {
434
+		foreach ( $form_fields as $k => $field ) {
435
+			if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
436
+				continue;
437
+			}
438
+
439
+			if ( $type == 'all' ) {
440
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
441
+			} else {
442
+				$sub_fields = self::get_all_types_in_form($field->form_id, $type);
443
+			}
444
+
445
+			if ( ! empty($sub_fields) ) {
446 446
 				$index = $k + $index_offset;
447 447
 				$index_offset += count( $sub_fields );
448 448
 				array_splice($results, $index, 0, $sub_fields);
449
-            }
450
-            unset($field, $sub_fields);
451
-        }
452
-    }
449
+			}
450
+			unset($field, $sub_fields);
451
+		}
452
+	}
453 453
 
454 454
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
455 455
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
456
-        if ( self::$use_cache ) {
457
-            // make sure old cache doesn't get saved as a transient
458
-            $results = wp_cache_get($cache_key, 'frm_field');
459
-            if ( false !== $results ) {
460
-                return stripslashes_deep($results);
461
-            }
462
-        }
463
-
464
-        global $wpdb;
465
-
466
-        if ( $blog_id && is_multisite() ) {
467
-            global $wpmuBaseTablePrefix;
468
-            if ( $wpmuBaseTablePrefix ) {
456
+		if ( self::$use_cache ) {
457
+			// make sure old cache doesn't get saved as a transient
458
+			$results = wp_cache_get($cache_key, 'frm_field');
459
+			if ( false !== $results ) {
460
+				return stripslashes_deep($results);
461
+			}
462
+		}
463
+
464
+		global $wpdb;
465
+
466
+		if ( $blog_id && is_multisite() ) {
467
+			global $wpmuBaseTablePrefix;
468
+			if ( $wpmuBaseTablePrefix ) {
469 469
 				$prefix = $wpmuBaseTablePrefix . $blog_id . '_';
470
-            } else {
471
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
472
-            }
470
+			} else {
471
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
472
+			}
473 473
 
474 474
 			$table_name = $prefix . 'frm_fields';
475 475
 			$form_table_name = $prefix . 'frm_forms';
476 476
 		} else {
477 477
 			$table_name = $wpdb->prefix . 'frm_fields';
478 478
 			$form_table_name = $wpdb->prefix . 'frm_forms';
479
-        }
479
+		}
480 480
 
481 481
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
482 482
 			$order_by = ' ORDER BY ' . $order_by;
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 
485 485
 		$limit = FrmDb::esc_limit( $limit );
486 486
 
487
-        $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
488
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
487
+		$query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
488
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
489 489
 
490 490
 		if ( is_array( $where ) ) {
491 491
 			$args = array(
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 
500 500
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
501 501
 			$results = $wpdb->$function_name( $query );
502
-        }
503
-        unset( $where );
502
+		}
503
+		unset( $where );
504 504
 
505 505
 		self::format_field_results( $results );
506 506
 
@@ -733,8 +733,8 @@  discard block
 block discarded – undo
733 733
 	}
734 734
 
735 735
 	/**
736
-	* @since 2.0.09
737
-	*/
736
+	 * @since 2.0.09
737
+	 */
738 738
 	public static function is_repeating_field( $field ) {
739 739
 		if ( is_array( $field ) ) {
740 740
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -744,14 +744,14 @@  discard block
 block discarded – undo
744 744
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
745 745
 	}
746 746
 
747
-    /**
748
-     * @param string $key
749
-     * @return int field id
750
-     */
747
+	/**
748
+	 * @param string $key
749
+	 * @return int field id
750
+	 */
751 751
 	public static function get_id_by_key( $key ) {
752
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
753
-        return $id;
754
-    }
752
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
753
+		return $id;
754
+	}
755 755
 
756 756
 	/**
757 757
 	 * @param string $id
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 	static $transient_size = 200;
10 10
 
11 11
 	public static function field_selection() {
12
-		$fields = apply_filters('frm_available_fields', array(
12
+		$fields = apply_filters( 'frm_available_fields', array(
13 13
 			'text'      => __( 'Single Line Text', 'formidable' ),
14 14
 			'textarea'  => __( 'Paragraph Text', 'formidable' ),
15 15
 			'checkbox'  => __( 'Checkboxes', 'formidable' ),
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
 			'email'     => __( 'Email Address', 'formidable' ),
19 19
 			'url'       => __( 'Website/URL', 'formidable' ),
20 20
 			'captcha'   => __( 'reCAPTCHA', 'formidable' ),
21
-		));
21
+		) );
22 22
 
23 23
 		return $fields;
24 24
 	}
25 25
 
26 26
 	public static function pro_field_selection() {
27
-		return apply_filters('frm_pro_available_fields', array(
27
+		return apply_filters( 'frm_pro_available_fields', array(
28 28
 			'end_divider' => array(
29 29
 				'name'  => __( 'End Section', 'formidable' ),
30 30
 				'switch_from' => 'divider',
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
 			'tag'       => __( 'Tags', 'formidable' ),
50 50
 			'credit_card' => __( 'Credit Card', 'formidable' ),
51 51
 			'address'   => __( 'Address', 'formidable' ),
52
-		));
52
+		) );
53 53
 	}
54 54
 
55 55
     public static function create( $values, $return = true ) {
56 56
         global $wpdb, $frm_duplicate_ids;
57 57
 
58 58
         $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
59
+        $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
60 60
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63
-			$new_values[ $col ] = $values[ $col ];
63
+			$new_values[$col] = $values[$col];
64 64
         }
65 65
 
66 66
         $new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
68
+        $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
69
+        $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
70
+        $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
71 71
         $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
72
+        $new_values['created_at'] = current_time( 'mysql', 1 );
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75
-			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
75
+			$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
76
+            $new_values = apply_filters( 'frm_duplicated_field', $new_values );
77 77
         }
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80 80
             if ( is_array( $v ) ) {
81
-				$new_values[ $k ] = serialize( $v );
81
+				$new_values[$k] = serialize( $v );
82 82
 			}
83 83
             unset( $k, $v );
84 84
         }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		if ( $query_results ) {
101 101
 			if ( isset( $values['id'] ) ) {
102
-				$frm_duplicate_ids[ $values['id'] ] = $new_id;
102
+				$frm_duplicate_ids[$values['id']] = $new_id;
103 103
 			}
104 104
 			return $new_id;
105 105
 		} else {
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 
120 120
         foreach ( (array) $fields as $field ) {
121 121
 			$new_key = $copy_keys ? $field->field_key : '';
122
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
123
-                $new_key = rtrim($new_key, 2);
122
+            if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
123
+                $new_key = rtrim( $new_key, 2 );
124 124
             }
125 125
 
126 126
             $values = array();
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
 				$values['form_id'] = $new_repeat_form_id;
147 147
 			}
148 148
 
149
-            $values = apply_filters('frm_duplicated_field', $values);
150
-            $new_id = self::create($values);
151
-            $frm_duplicate_ids[ $field->id ] = $new_id;
152
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
153
-            unset($field);
149
+            $values = apply_filters( 'frm_duplicated_field', $values );
150
+            $new_id = self::create( $values );
151
+            $frm_duplicate_ids[$field->id] = $new_id;
152
+            $frm_duplicate_ids[$field->field_key] = $new_id;
153
+            unset( $field );
154 154
         }
155 155
     }
156 156
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
164 164
 		}
165 165
 
166
-        if ( isset($values['required']) ) {
166
+        if ( isset( $values['required'] ) ) {
167 167
             $values['required'] = (int) $values['required'];
168 168
         }
169 169
 
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 
181 181
 		// serialize array values
182 182
 		foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
183
-			if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
184
-				$values[ $opt ] = serialize( $values[ $opt ] );
183
+			if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) {
184
+				$values[$opt] = serialize( $values[$opt] );
185 185
 			}
186 186
 		}
187 187
 
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
 		if ( isset( $values['form_id'] ) ) {
192 192
             $form_id = absint( $values['form_id'] );
193 193
 		} else {
194
-            $field = self::getOne($id);
194
+            $field = self::getOne( $id );
195 195
             if ( $field ) {
196 196
                 $form_id = $field->form_id;
197 197
             }
198
-            unset($field);
198
+            unset( $field );
199 199
         }
200
-        unset($values);
200
+        unset( $values );
201 201
 
202 202
 		if ( $query_results ) {
203 203
             wp_cache_delete( $id, 'frm_field' );
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 
251 251
 		FrmDb::cache_delete_group( 'frm_field' );
252 252
 
253
-        $form = FrmForm::getOne($form_id);
253
+        $form = FrmForm::getOne( $form_id );
254 254
         if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
255 255
             self::delete_form_transient( $form->parent_form_id );
256 256
         }
@@ -272,16 +272,16 @@  discard block
 block discarded – undo
272 272
 
273 273
         global $wpdb;
274 274
 
275
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
275
+        $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
276 276
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
277 277
 
278 278
         $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
279 279
 
280
-        if ( empty($results) ) {
280
+        if ( empty( $results ) ) {
281 281
             return $results;
282 282
         }
283 283
 
284
-        if ( is_numeric($id) ) {
284
+        if ( is_numeric( $id ) ) {
285 285
 			FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
286 286
         } else if ( $results ) {
287 287
 			FrmDb::set_cache( $results->id, $results, 'frm_field' );
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
 		self::prepare_options( $results );
291 291
 
292
-        return stripslashes_deep($results);
292
+        return stripslashes_deep( $results );
293 293
     }
294 294
 
295 295
     /**
@@ -330,20 +330,20 @@  discard block
 block discarded – undo
330 330
                     continue;
331 331
                 }
332 332
 
333
-				$fields[ $result->id ] = $result;
334
-                $count++;
333
+				$fields[$result->id] = $result;
334
+                $count ++;
335 335
                 if ( $limit == 1 ) {
336 336
                     $fields = $result;
337 337
                     break;
338 338
                 }
339 339
 
340
-                if ( ! empty($limit) && $count >= $limit ) {
340
+                if ( ! empty( $limit ) && $count >= $limit ) {
341 341
                     break;
342 342
                 }
343 343
 
344
-                unset($result);
344
+                unset( $result );
345 345
             }
346
-            return stripslashes_deep($fields);
346
+            return stripslashes_deep( $fields );
347 347
         }
348 348
 
349 349
         self::$use_cache = false;
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 		self::maybe_include_repeating_fields( $inc_sub, $where );
356 356
 		$results = self::getAll( $where, 'field_order', $limit );
357 357
         self::$use_cache = true;
358
-        self::include_sub_fields($results, $inc_sub, $type);
358
+        self::include_sub_fields( $results, $inc_sub, $type );
359 359
 
360 360
         return $results;
361 361
     }
@@ -370,15 +370,15 @@  discard block
 block discarded – undo
370 370
 			'inc_repeat' => $inc_repeat,
371 371
 		) );
372 372
 		if ( ! empty( $results ) ) {
373
-            if ( empty($limit) ) {
373
+            if ( empty( $limit ) ) {
374 374
 				return $results;
375 375
             }
376 376
 
377 377
             $fields = array();
378 378
             $count = 0;
379 379
             foreach ( $results as $result ) {
380
-				$fields[ $result->id ] = $result;
381
-                if ( ! empty($limit) && $count >= $limit ) {
380
+				$fields[$result->id] = $result;
381
+                if ( ! empty( $limit ) && $count >= $limit ) {
382 382
                     break;
383 383
                 }
384 384
             }
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 
397 397
 		self::include_sub_fields( $results, $inc_embed, 'all' );
398 398
 
399
-        if ( empty($limit) ) {
399
+        if ( empty( $limit ) ) {
400 400
 			self::set_field_transient( $results, $form_id, 0, array(
401 401
 				'inc_embed'  => $inc_embed,
402 402
 				'inc_repeat' => $inc_repeat,
@@ -432,22 +432,22 @@  discard block
 block discarded – undo
432 432
         $form_fields = $results;
433 433
 		$index_offset = 1;
434 434
         foreach ( $form_fields as $k => $field ) {
435
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
435
+            if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
436 436
                 continue;
437 437
             }
438 438
 
439 439
             if ( $type == 'all' ) {
440 440
                 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
441 441
             } else {
442
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
442
+                $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
443 443
             }
444 444
 
445
-            if ( ! empty($sub_fields) ) {
445
+            if ( ! empty( $sub_fields ) ) {
446 446
 				$index = $k + $index_offset;
447 447
 				$index_offset += count( $sub_fields );
448
-				array_splice($results, $index, 0, $sub_fields);
448
+				array_splice( $results, $index, 0, $sub_fields );
449 449
             }
450
-            unset($field, $sub_fields);
450
+            unset( $field, $sub_fields );
451 451
         }
452 452
     }
453 453
 
@@ -455,9 +455,9 @@  discard block
 block discarded – undo
455 455
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
456 456
         if ( self::$use_cache ) {
457 457
             // make sure old cache doesn't get saved as a transient
458
-            $results = wp_cache_get($cache_key, 'frm_field');
458
+            $results = wp_cache_get( $cache_key, 'frm_field' );
459 459
             if ( false !== $results ) {
460
-                return stripslashes_deep($results);
460
+                return stripslashes_deep( $results );
461 461
             }
462 462
         }
463 463
 
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 			$results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', $args, '', $query_type );
496 496
 		} else {
497 497
 			// if the query is not an array, then it has already been prepared
498
-			$query .= FrmDb::prepend_and_or_where(' WHERE ', $where ) . $order_by . $limit;
498
+			$query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
499 499
 
500 500
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
501 501
 			$results = $wpdb->$function_name( $query );
@@ -518,9 +518,9 @@  discard block
 block discarded – undo
518 518
 				FrmDb::set_cache( $result->id, $result, 'frm_field' );
519 519
 				FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
520 520
 
521
-				$results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
522
-				$results[ $r_key ]->options = maybe_unserialize( $result->options );
523
-				$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
521
+				$results[$r_key]->field_options = maybe_unserialize( $result->field_options );
522
+				$results[$r_key]->options = maybe_unserialize( $result->options );
523
+				$results[$r_key]->default_value = maybe_unserialize( $result->default_value );
524 524
 
525 525
 				unset( $r_key, $result );
526 526
 			}
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
 	private static function prepare_options( &$results ) {
540 540
 		$results->field_options = maybe_unserialize( $results->field_options );
541 541
 
542
-		$results->options = maybe_unserialize($results->options);
543
-		$results->default_value = maybe_unserialize($results->default_value);
542
+		$results->options = maybe_unserialize( $results->options );
543
+		$results->default_value = maybe_unserialize( $results->default_value );
544 544
 	}
545 545
 
546 546
 	/**
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 
568 568
 			if ( count( $next_fields ) >= self::$transient_size ) {
569 569
 				// if this transient is full, check for another
570
-				$next++;
570
+				$next ++;
571 571
 				self::get_next_transient( $fields, $base_name, $next );
572 572
 			}
573 573
 		}
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 				return;
594 594
 			}
595 595
 
596
-			$next++;
596
+			$next ++;
597 597
 		}
598 598
 	}
599 599
 
@@ -693,23 +693,23 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	public static function is_option_true_in_array( $field, $option ) {
696
-		return isset( $field[ $option ] ) && $field[ $option ];
696
+		return isset( $field[$option] ) && $field[$option];
697 697
 	}
698 698
 
699 699
 	public static function is_option_true_in_object( $field, $option ) {
700
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
700
+		return isset( $field->field_options[$option] ) && $field->field_options[$option];
701 701
 	}
702 702
 
703 703
 	public static function is_option_empty_in_array( $field, $option ) {
704
-		return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
704
+		return ! isset( $field[$option] ) || empty( $field[$option] );
705 705
 	}
706 706
 
707 707
 	public static function is_option_empty_in_object( $field, $option ) {
708
-		return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
708
+		return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] );
709 709
 	}
710 710
 
711 711
 	public static function is_option_value_in_object( $field, $option ) {
712
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
712
+		return isset( $field->field_options[$option] ) && $field->field_options[$option] != '';
713 713
 	}
714 714
 
715 715
 	/**
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
 	}
726 726
 
727 727
 	public static function get_option_in_array( $field, $option ) {
728
-		return isset( $field[ $option ] ) ? $field[ $option ] : '';
728
+		return isset( $field[$option] ) ? $field[$option] : '';
729 729
 	}
730 730
 
731 731
 	public static function get_option_in_object( $field, $option ) {
732
-		return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
732
+		return isset( $field->field_options[$option] ) ? $field->field_options[$option] : '';
733 733
 	}
734 734
 
735 735
 	/**
Please login to merge, or discard this patch.
classes/models/FrmDb.php 2 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmDb {
4
-    public $fields;
5
-    public $forms;
6
-    public $entries;
7
-    public $entry_metas;
8
-
9
-    public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
12
-        }
4
+	public $fields;
5
+	public $forms;
6
+	public $entries;
7
+	public $entry_metas;
8
+
9
+	public function __construct() {
10
+		if ( ! defined('ABSPATH') ) {
11
+			die('You are not allowed to call this page directly.');
12
+		}
13 13
 
14 14
 		_deprecated_function( __METHOD__, '2.05.06', 'FrmMigrate' );
15
-        global $wpdb;
16
-        $this->fields         = $wpdb->prefix . 'frm_fields';
17
-        $this->forms          = $wpdb->prefix . 'frm_forms';
18
-        $this->entries        = $wpdb->prefix . 'frm_items';
19
-        $this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
20
-    }
21
-
22
-    /**
23
-     * Change array into format $wpdb->prepare can use
15
+		global $wpdb;
16
+		$this->fields         = $wpdb->prefix . 'frm_fields';
17
+		$this->forms          = $wpdb->prefix . 'frm_forms';
18
+		$this->entries        = $wpdb->prefix . 'frm_items';
19
+		$this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
20
+	}
21
+
22
+	/**
23
+	 * Change array into format $wpdb->prepare can use
24 24
 	 *
25 25
 	 * @param array $args
26 26
 	 * @param string $starts_with
27
-     */
28
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
-        if ( empty($args) ) {
27
+	 */
28
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
+		if ( empty($args) ) {
30 30
 			// add an arg to prevent prepare from failing
31 31
 			$args = array(
32 32
 				'where' => $starts_with . '1=%d',
33 33
 				'values' => array( 1 ),
34 34
 			);
35 35
 			return;
36
-        }
36
+		}
37 37
 
38 38
 		$where = '';
39 39
 		$values = array();
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
 		}
45 45
 
46 46
 		$args = compact( 'where', 'values' );
47
-    }
47
+	}
48 48
 
49
-    /**
49
+	/**
50 50
 	 * @param array $args
51
-     * @param string $base_where
52
-     * @param string $where
51
+	 * @param string $base_where
52
+	 * @param string $where
53 53
 	 * @param array $values
54
-     */
55
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
56
-        $condition = ' AND';
57
-        if ( isset( $args['or'] ) ) {
58
-            $condition = ' OR';
59
-            unset( $args['or'] );
60
-        }
54
+	 */
55
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
56
+		$condition = ' AND';
57
+		if ( isset( $args['or'] ) ) {
58
+			$condition = ' OR';
59
+			unset( $args['or'] );
60
+		}
61 61
 
62 62
 		foreach ( $args as $key => $value ) {
63 63
 			$where .= empty( $where ) ? $base_where : $condition;
@@ -84,28 +84,28 @@  discard block
 block discarded – undo
84 84
 		}
85 85
 	}
86 86
 
87
-    /**
88
-     * @param string $key
87
+	/**
88
+	 * @param string $key
89 89
 	 * @param string|array $value
90
-     * @param string $where
90
+	 * @param string $where
91 91
 	 * @param array $values
92
-     */
93
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
92
+	 */
93
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
94 94
 		$key = trim( $key );
95 95
 
96 96
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
97
-            $k = explode(' ', $key);
98
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
99
-            $values[] = '%Y-%m-%d %H:%i:%s';
100
-        } else {
97
+			$k = explode(' ', $key);
98
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
99
+			$values[] = '%Y-%m-%d %H:%i:%s';
100
+		} else {
101 101
 			$where .= ' ' . $key;
102
-        }
102
+		}
103 103
 
104 104
 		$lowercase_key = explode( ' ', strtolower( $key ) );
105 105
 		$lowercase_key = end( $lowercase_key );
106 106
 
107
-        if ( is_array( $value ) ) {
108
-            // translate array of values to "in"
107
+		if ( is_array( $value ) ) {
108
+			// translate array of values to "in"
109 109
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
110 110
 				$where = preg_replace('/' . $key . '$/', '', $where);
111 111
 				$where .= '(';
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 				$where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
124 124
 				$values = array_merge( $values, $value );
125 125
 			}
126
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
126
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
127 127
 			/**
128 128
 			 * Allow string to start or end with the value
129 129
 			 * If the key is like% then skip the first % for starts with
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 			$where .= ' %s';
144 144
 			$values[] = $start . self::esc_like( $value ) . $end;
145 145
 
146
-        } else if ( $value === null ) {
147
-            $where .= ' IS NULL';
148
-        } else {
146
+		} else if ( $value === null ) {
147
+			$where .= ' IS NULL';
148
+		} else {
149 149
 			// allow a - to prevent = from being added
150 150
 			if ( substr( $key, -1 ) == '-' ) {
151 151
 				$where = rtrim( $where, '-' );
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 
156 156
 			self::add_query_placeholder( $key, $value, $where );
157 157
 
158
-            $values[] = $value;
159
-        }
160
-    }
158
+			$values[] = $value;
159
+		}
160
+	}
161 161
 
162 162
 	/**
163 163
 	 * Add %d, or %s to query
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @param int|string $value
168 168
 	 * @param string $where
169 169
 	 */
170
-    private static function add_query_placeholder( $key, $value, &$where ) {
170
+	private static function add_query_placeholder( $key, $value, &$where ) {
171 171
 		if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
172 172
 			$where .= '%d';
173 173
 		} else {
@@ -175,16 +175,16 @@  discard block
 block discarded – undo
175 175
 		}
176 176
 	}
177 177
 
178
-    /**
179
-     * @param string $table
178
+	/**
179
+	 * @param string $table
180 180
 	 * @param array $where
181 181
 	 * @param array $args
182 182
 	 * @return int
183
-     */
184
-    public static function get_count( $table, $where = array(), $args = array() ) {
185
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
186
-        return $count;
187
-    }
183
+	 */
184
+	public static function get_count( $table, $where = array(), $args = array() ) {
185
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
186
+		return $count;
187
+	}
188 188
 
189 189
 	/**
190 190
 	 * @param string $table
@@ -195,17 +195,17 @@  discard block
 block discarded – undo
195 195
 	 * @param string $type
196 196
 	 * @return array|null|string|object
197 197
 	 */
198
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
199
-        $group = '';
200
-        self::get_group_and_table_name( $table, $group );
198
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
199
+		$group = '';
200
+		self::get_group_and_table_name( $table, $group );
201 201
 		self::convert_options_to_array( $args, '', $limit );
202 202
 
203 203
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
204 204
 
205 205
 		$cache_key = self::generate_cache_key( $where, $args, $field, $type );
206 206
 		$results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
207
-        return $results;
208
-    }
207
+		return $results;
208
+	}
209 209
 
210 210
 	/**
211 211
 	 * Generate a cache key from the where query, field, type, and other arguments
@@ -231,44 +231,44 @@  discard block
 block discarded – undo
231 231
 		return $cache_key;
232 232
 	}
233 233
 
234
-    /**
235
-     * @param string $table
236
-     * @param array $where
234
+	/**
235
+	 * @param string $table
236
+	 * @param array $where
237 237
 	 * @param string $field
238 238
 	 * @param array $args
239 239
 	 * @param string $limit
240 240
 	 * @return mixed
241
-     */
242
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
243
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
244
-    }
245
-
246
-    /**
247
-     * @since 2.0
248
-     * @param string $table
241
+	 */
242
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
243
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
244
+	}
245
+
246
+	/**
247
+	 * @since 2.0
248
+	 * @param string $table
249 249
 	 * @param array $where
250 250
 	 * @param string $fields
251 251
 	 * @param array $args
252 252
 	 * @return mixed
253
-     */
254
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
255
-        $args['limit'] = 1;
256
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
257
-    }
258
-
259
-    /**
260
-     * Prepare a key/value array before DB call
253
+	 */
254
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
255
+		$args['limit'] = 1;
256
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
257
+	}
258
+
259
+	/**
260
+	 * Prepare a key/value array before DB call
261 261
 	 *
262
-     * @since 2.0
263
-     * @param string $table
262
+	 * @since 2.0
263
+	 * @param string $table
264 264
 	 * @param array $where
265 265
 	 * @param string $fields
266 266
 	 * @param array $args
267 267
 	 * @return mixed
268
-     */
269
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
270
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
271
-    }
268
+	 */
269
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
270
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
271
+	}
272 272
 
273 273
 	/**
274 274
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -305,56 +305,56 @@  discard block
 block discarded – undo
305 305
 		return '';
306 306
 	}
307 307
 
308
-    /**
309
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
310
-     * Also add the wpdb->prefix to the table if it's missing
311
-     *
312
-     * @param string $table
313
-     * @param string $group
314
-     */
315
-    private static function get_group_and_table_name( &$table, &$group ) {
308
+	/**
309
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
310
+	 * Also add the wpdb->prefix to the table if it's missing
311
+	 *
312
+	 * @param string $table
313
+	 * @param string $group
314
+	 */
315
+	private static function get_group_and_table_name( &$table, &$group ) {
316 316
 		global $wpdb, $wpmuBaseTablePrefix;
317 317
 
318
-        $table_parts = explode(' ', $table);
319
-        $group = reset($table_parts);
320
-        $group = str_replace( $wpdb->prefix, '', $group );
318
+		$table_parts = explode(' ', $table);
319
+		$group = reset($table_parts);
320
+		$group = str_replace( $wpdb->prefix, '', $group );
321 321
 
322 322
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
323 323
 		$group = str_replace( $prefix, '', $group );
324 324
 
325
-        if ( $group == $table ) {
326
-            $table = $wpdb->prefix . $table;
327
-        }
325
+		if ( $group == $table ) {
326
+			$table = $wpdb->prefix . $table;
327
+		}
328 328
 
329 329
 		// switch to singular group name
330 330
 		$group = rtrim( $group, 's' );
331
-    }
331
+	}
332 332
 
333
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
334
-        if ( ! is_array($args) ) {
333
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
334
+		if ( ! is_array($args) ) {
335 335
 			$args = array( 'order_by' => $args );
336
-        }
336
+		}
337 337
 
338
-        if ( ! empty( $order_by ) ) {
339
-            $args['order_by'] = $order_by;
340
-        }
338
+		if ( ! empty( $order_by ) ) {
339
+			$args['order_by'] = $order_by;
340
+		}
341 341
 
342
-        if ( ! empty( $limit ) ) {
343
-            $args['limit'] = $limit;
344
-        }
342
+		if ( ! empty( $limit ) ) {
343
+			$args['limit'] = $limit;
344
+		}
345 345
 
346
-        $temp_args = $args;
347
-        foreach ( $temp_args as $k => $v ) {
348
-            if ( $v == '' ) {
346
+		$temp_args = $args;
347
+		foreach ( $temp_args as $k => $v ) {
348
+			if ( $v == '' ) {
349 349
 				unset( $args[ $k ] );
350
-                continue;
351
-            }
350
+				continue;
351
+			}
352 352
 
353
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
354
-            if ( strpos( $v, $db_name ) === false ) {
353
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
354
+			if ( strpos( $v, $db_name ) === false ) {
355 355
 				$args[ $k ] = $db_name . ' ' . $v;
356
-            }
357
-        }
356
+			}
357
+		}
358 358
 
359 359
 		// Make sure LIMIT is the last argument
360 360
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 			unset( $args['limit'] );
363 363
 			$args['limit'] = $temp_limit;
364 364
 		}
365
-    }
365
+	}
366 366
 
367 367
 	/**
368 368
 	 * Get the associative array results for the given columns, table, and where query
@@ -434,25 +434,25 @@  discard block
 block discarded – undo
434 434
 		}
435 435
 	}
436 436
 
437
-    /**
438
-     * Added for < WP 4.0 compatability
439
-     *
440
-     * @since 2.05.06
441
-     *
442
-     * @param string $term The value to escape
443
-     * @return string The escaped value
444
-     */
437
+	/**
438
+	 * Added for < WP 4.0 compatability
439
+	 *
440
+	 * @since 2.05.06
441
+	 *
442
+	 * @param string $term The value to escape
443
+	 * @return string The escaped value
444
+	 */
445 445
 	public static function esc_like( $term ) {
446
-        global $wpdb;
447
-        if ( method_exists( $wpdb, 'esc_like' ) ) {
446
+		global $wpdb;
447
+		if ( method_exists( $wpdb, 'esc_like' ) ) {
448 448
 			// WP 4.0
449
-            $term = $wpdb->esc_like( $term );
450
-        } else {
451
-            $term = like_escape( $term );
452
-        }
449
+			$term = $wpdb->esc_like( $term );
450
+		} else {
451
+			$term = like_escape( $term );
452
+		}
453 453
 
454
-        return $term;
455
-    }
454
+		return $term;
455
+	}
456 456
 
457 457
 	/**
458 458
 	 * @since 2.05.06
@@ -522,10 +522,10 @@  discard block
 block discarded – undo
522 522
 		return ' LIMIT ' . $limit;
523 523
 	}
524 524
 
525
-    /**
526
-     * Get an array of values ready to go through $wpdb->prepare
527
-     * @since 2.05.06
528
-     */
525
+	/**
526
+	 * Get an array of values ready to go through $wpdb->prepare
527
+	 * @since 2.05.06
528
+	 */
529 529
 	public static function prepare_array_values( $array, $type = '%s' ) {
530 530
 		$placeholders = array_fill( 0, count( $array ), $type );
531 531
 		return implode( ', ', $placeholders );
@@ -596,17 +596,17 @@  discard block
 block discarded – undo
596 596
 		return $post;
597 597
 	}
598 598
 
599
-    /**
600
-     * Check cache before fetching values and saving to cache
601
-     *
602
-     * @since 2.05.06
603
-     *
604
-     * @param string $cache_key The unique name for this cache
605
-     * @param string $group The name of the cache group
606
-     * @param string $query If blank, don't run a db call
607
-     * @param string $type The wpdb function to use with this query
608
-     * @return mixed $results The cache or query results
609
-     */
599
+	/**
600
+	 * Check cache before fetching values and saving to cache
601
+	 *
602
+	 * @since 2.05.06
603
+	 *
604
+	 * @param string $cache_key The unique name for this cache
605
+	 * @param string $group The name of the cache group
606
+	 * @param string $query If blank, don't run a db call
607
+	 * @param string $type The wpdb function to use with this query
608
+	 * @return mixed $results The cache or query results
609
+	 */
610 610
 	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
611 611
 		$results = wp_cache_get( $cache_key, $group );
612 612
 		if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
@@ -670,13 +670,13 @@  discard block
 block discarded – undo
670 670
 		wp_cache_delete( $cache_key, $group );
671 671
 	}
672 672
 
673
-    /**
674
-     * Delete all caching in a single group
675
-     *
676
-     * @since 2.05.06
677
-     *
678
-     * @param string $group The name of the cache group
679
-     */
673
+	/**
674
+	 * Delete all caching in a single group
675
+	 *
676
+	 * @since 2.05.06
677
+	 *
678
+	 * @param string $group The name of the cache group
679
+	 */
680 680
 	public static function cache_delete_group( $group ) {
681 681
 		$cached_keys = self::get_group_cached_keys( $group );
682 682
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
     public $entry_metas;
8 8
 
9 9
     public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
10
+        if ( ! defined( 'ABSPATH' ) ) {
11
+            die( 'You are not allowed to call this page directly.' );
12 12
         }
13 13
 
14 14
 		_deprecated_function( __METHOD__, '2.05.06', 'FrmMigrate' );
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 * @param string $starts_with
27 27
      */
28 28
     public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
29
-        if ( empty($args) ) {
29
+        if ( empty( $args ) ) {
30 30
 			// add an arg to prevent prepare from failing
31 31
 			$args = array(
32 32
 				'where' => $starts_with . '1=%d',
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		$key = trim( $key );
95 95
 
96 96
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
97
-            $k = explode(' ', $key);
97
+            $k = explode( ' ', $key );
98 98
             $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
99 99
             $values[] = '%Y-%m-%d %H:%i:%s';
100 100
         } else {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if ( is_array( $value ) ) {
108 108
             // translate array of values to "in"
109 109
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
110
-				$where = preg_replace('/' . $key . '$/', '', $where);
110
+				$where = preg_replace( '/' . $key . '$/', '', $where );
111 111
 				$where .= '(';
112 112
 				$start = true;
113 113
 				foreach ( $value as $v ) {
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 		);
293 293
 
294 294
 		$where_is = strtolower( $where_is );
295
-		if ( isset( $switch_to[ $where_is ] ) ) {
296
-			return ' ' . $switch_to[ $where_is ];
295
+		if ( isset( $switch_to[$where_is] ) ) {
296
+			return ' ' . $switch_to[$where_is];
297 297
 		}
298 298
 
299 299
 		// > and < need a little more work since we don't want them switched to >= and <=
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
     private static function get_group_and_table_name( &$table, &$group ) {
316 316
 		global $wpdb, $wpmuBaseTablePrefix;
317 317
 
318
-        $table_parts = explode(' ', $table);
319
-        $group = reset($table_parts);
318
+        $table_parts = explode( ' ', $table );
319
+        $group = reset( $table_parts );
320 320
         $group = str_replace( $wpdb->prefix, '', $group );
321 321
 
322 322
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
     }
332 332
 
333 333
     private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
334
-        if ( ! is_array($args) ) {
334
+        if ( ! is_array( $args ) ) {
335 335
 			$args = array( 'order_by' => $args );
336 336
         }
337 337
 
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
         $temp_args = $args;
347 347
         foreach ( $temp_args as $k => $v ) {
348 348
             if ( $v == '' ) {
349
-				unset( $args[ $k ] );
349
+				unset( $args[$k] );
350 350
                 continue;
351 351
             }
352 352
 
353 353
             $db_name = strtoupper( str_replace( '_', ' ', $k ) );
354 354
             if ( strpos( $v, $db_name ) === false ) {
355
-				$args[ $k ] = $db_name . ' ' . $v;
355
+				$args[$k] = $db_name . ' ' . $v;
356 356
             }
357 357
         }
358 358
 
@@ -423,13 +423,13 @@  discard block
 block discarded – undo
423 423
 	private static function esc_query_args( &$args ) {
424 424
 		foreach ( $args as $param => $value ) {
425 425
 			if ( $param == 'order_by' ) {
426
-				$args[ $param ] = self::esc_order( $value );
426
+				$args[$param] = self::esc_order( $value );
427 427
 			} elseif ( $param == 'limit' ) {
428
-				$args[ $param ] = self::esc_limit( $value );
428
+				$args[$param] = self::esc_limit( $value );
429 429
 			}
430 430
 
431
-			if ( $args[ $param ] == '' ) {
432
-				unset( $args[ $param ] );
431
+			if ( $args[$param] == '' ) {
432
+				unset( $args[$param] );
433 433
 			}
434 434
 		}
435 435
 	}
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 		$limit = explode( ',', trim( $limit ) );
515 515
 		foreach ( $limit as $k => $l ) {
516 516
 			if ( is_numeric( $l ) ) {
517
-				$limit[ $k ] = $l;
517
+				$limit[$k] = $l;
518 518
 			}
519 519
 		}
520 520
 
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	 */
646 646
 	public static function add_key_to_group_cache( $key, $group ) {
647 647
 		$cached = self::get_group_cached_keys( $group );
648
-		$cached[ $key ] = $key;
648
+		$cached[$key] = $key;
649 649
 		wp_cache_set( 'cached_keys', $cached, $group, 300 );
650 650
 	}
651 651
 
Please login to merge, or discard this patch.
classes/models/FrmEntryValues.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -154,12 +154,12 @@  discard block
 block discarded – undo
154 154
 	 * @return array
155 155
 	 */
156 156
 	private function prepare_array_property( $index, $atts ) {
157
-		if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) {
157
+		if ( isset( $atts[$index] ) && ! empty( $atts[$index] ) ) {
158 158
 
159
-			if ( is_array( $atts[ $index ] ) ) {
160
-				$property = $atts[ $index ];
159
+			if ( is_array( $atts[$index] ) ) {
160
+				$property = $atts[$index];
161 161
 			} else {
162
-				$property = explode( ',', $atts[ $index ] );
162
+				$property = explode( ',', $atts[$index] );
163 163
 			}
164 164
 		} else {
165 165
 			$property = array();
@@ -292,6 +292,6 @@  discard block
 block discarded – undo
292 292
 	 * @param stdClass $field
293 293
 	 */
294 294
 	protected function add_field_values( $field ) {
295
-		$this->field_values[ $field->id ] = new FrmFieldValue( $field, $this->entry, array( 'source' => $this->source ) );
295
+		$this->field_values[$field->id] = new FrmFieldValue( $field, $this->entry, array( 'source' => $this->source ) );
296 296
 	}
297 297
 }
Please login to merge, or discard this patch.