Completed
Push — master ( 7ee0df...32d997 )
by Jamie
03:01
created
classes/models/FrmDb.php 1 patch
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -1,70 +1,70 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmDb {
4
-    var $fields;
5
-    var $forms;
6
-    var $entries;
7
-    var $entry_metas;
8
-
9
-    public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
12
-        }
13
-
14
-        global $wpdb;
15
-        $this->fields         = $wpdb->prefix . 'frm_fields';
16
-        $this->forms          = $wpdb->prefix . 'frm_forms';
17
-        $this->entries        = $wpdb->prefix . 'frm_items';
18
-        $this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
-    }
20
-
21
-    public function upgrade( $old_db_version = false ) {
22
-	    do_action( 'frm_before_install' );
23
-
24
-        global $wpdb;
25
-        //$frm_db_version is the version of the database we're moving to
26
-        $frm_db_version = FrmAppHelper::$db_version;
27
-        $old_db_version = (float) $old_db_version;
28
-        if ( ! $old_db_version ) {
29
-            $old_db_version = get_option('frm_db_version');
30
-        }
31
-
32
-        if ( $frm_db_version != $old_db_version ) {
4
+	var $fields;
5
+	var $forms;
6
+	var $entries;
7
+	var $entry_metas;
8
+
9
+	public function __construct() {
10
+		if ( ! defined('ABSPATH') ) {
11
+			die('You are not allowed to call this page directly.');
12
+		}
13
+
14
+		global $wpdb;
15
+		$this->fields         = $wpdb->prefix . 'frm_fields';
16
+		$this->forms          = $wpdb->prefix . 'frm_forms';
17
+		$this->entries        = $wpdb->prefix . 'frm_items';
18
+		$this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
+	}
20
+
21
+	public function upgrade( $old_db_version = false ) {
22
+		do_action( 'frm_before_install' );
23
+
24
+		global $wpdb;
25
+		//$frm_db_version is the version of the database we're moving to
26
+		$frm_db_version = FrmAppHelper::$db_version;
27
+		$old_db_version = (float) $old_db_version;
28
+		if ( ! $old_db_version ) {
29
+			$old_db_version = get_option('frm_db_version');
30
+		}
31
+
32
+		if ( $frm_db_version != $old_db_version ) {
33 33
 			// update rewrite rules for views and other custom post types
34 34
 			flush_rewrite_rules();
35 35
 
36 36
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
37 37
 
38
-            $this->create_tables();
39
-            $this->migrate_data($frm_db_version, $old_db_version);
38
+			$this->create_tables();
39
+			$this->migrate_data($frm_db_version, $old_db_version);
40 40
 
41
-            /***** SAVE DB VERSION *****/
42
-            update_option('frm_db_version', $frm_db_version);
41
+			/***** SAVE DB VERSION *****/
42
+			update_option('frm_db_version', $frm_db_version);
43 43
 
44
-            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
45
-            FrmXMLController::add_default_templates();
44
+			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
45
+			FrmXMLController::add_default_templates();
46 46
 
47 47
 			if ( ! $old_db_version ) {
48 48
 				$this->maybe_create_contact_form();
49 49
 			}
50
-        }
50
+		}
51 51
 
52
-        do_action('frm_after_install');
52
+		do_action('frm_after_install');
53 53
 
54
-        /**** update the styling settings ****/
54
+		/**** update the styling settings ****/
55 55
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
56 56
 			$frm_style = new FrmStyle();
57 57
 			$frm_style->update( 'default' );
58 58
 		}
59
-    }
59
+	}
60 60
 
61
-    public function collation() {
62
-        global $wpdb;
63
-        if ( ! $wpdb->has_cap( 'collation' ) ) {
64
-            return '';
65
-        }
61
+	public function collation() {
62
+		global $wpdb;
63
+		if ( ! $wpdb->has_cap( 'collation' ) ) {
64
+			return '';
65
+		}
66 66
 
67
-        $charset_collate = '';
67
+		$charset_collate = '';
68 68
 		if ( ! empty( $wpdb->charset ) ) {
69 69
 			$charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset;
70 70
 		}
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
 			$charset_collate .= ' COLLATE ' . $wpdb->collate;
74 74
 		}
75 75
 
76
-        return $charset_collate;
77
-    }
76
+		return $charset_collate;
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,32 +177,32 @@  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
-    /**
195
-     * Change array into format $wpdb->prepare can use
194
+	/**
195
+	 * Change array into format $wpdb->prepare can use
196 196
 	 *
197 197
 	 * @param array $args
198 198
 	 * @param string $starts_with
199
-     */
200
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
201
-        if ( empty($args) ) {
199
+	 */
200
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
201
+		if ( empty($args) ) {
202 202
 			// add an arg to prevent prepare from failing
203 203
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
204 204
 			return;
205
-        }
205
+		}
206 206
 
207 207
 		$where = '';
208 208
 		$values = array();
@@ -213,64 +213,64 @@  discard block
 block discarded – undo
213 213
 		}
214 214
 
215 215
 		$args = compact( 'where', 'values' );
216
-    }
216
+	}
217 217
 
218
-    /**
218
+	/**
219 219
 	 * @param array $args
220
-     * @param string $base_where
221
-     * @param string $where
220
+	 * @param string $base_where
221
+	 * @param string $where
222 222
 	 * @param array $values
223
-     */
224
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
225
-        $condition = ' AND';
226
-        if ( isset( $args['or'] ) ) {
227
-            $condition = ' OR';
228
-            unset( $args['or'] );
229
-        }
230
-
231
-        foreach ( $args as $key => $value ) {
232
-            $where .= empty( $where ) ? $base_where : $condition;
233
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
234
-            if ( is_numeric( $key ) || $array_inc_null ) {
235
-                $where .= ' ( ';
236
-                $nested_where = '';
237
-                if ( $array_inc_null ) {
238
-                    foreach ( $value as $val ) {
239
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
240
-                    }
241
-                } else {
242
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
243
-                }
244
-                $where .= $nested_where;
245
-                $where .= ' ) ';
246
-            } else {
247
-                self::interpret_array_to_sql( $key, $value, $where, $values );
248
-            }
249
-        }
250
-    }
251
-
252
-    /**
253
-     * @param string $key
223
+	 */
224
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
225
+		$condition = ' AND';
226
+		if ( isset( $args['or'] ) ) {
227
+			$condition = ' OR';
228
+			unset( $args['or'] );
229
+		}
230
+
231
+		foreach ( $args as $key => $value ) {
232
+			$where .= empty( $where ) ? $base_where : $condition;
233
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
234
+			if ( is_numeric( $key ) || $array_inc_null ) {
235
+				$where .= ' ( ';
236
+				$nested_where = '';
237
+				if ( $array_inc_null ) {
238
+					foreach ( $value as $val ) {
239
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
240
+					}
241
+				} else {
242
+					self::parse_where_from_array( $value, '', $nested_where, $values );
243
+				}
244
+				$where .= $nested_where;
245
+				$where .= ' ) ';
246
+			} else {
247
+				self::interpret_array_to_sql( $key, $value, $where, $values );
248
+			}
249
+		}
250
+	}
251
+
252
+	/**
253
+	 * @param string $key
254 254
 	 * @param string|array $value
255
-     * @param string $where
255
+	 * @param string $where
256 256
 	 * @param array $values
257
-     */
258
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
257
+	 */
258
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
259 259
 		$key = trim( $key );
260 260
 
261 261
 		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
262
-            $k = explode(' ', $key);
263
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
264
-            $values[] = '%Y-%m-%d %H:%i:%s';
265
-        } else {
262
+			$k = explode(' ', $key);
263
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
264
+			$values[] = '%Y-%m-%d %H:%i:%s';
265
+		} else {
266 266
 			$where .= ' ' . $key;
267
-        }
267
+		}
268 268
 
269 269
 		$lowercase_key = explode( ' ', strtolower( $key ) );
270 270
 		$lowercase_key = end( $lowercase_key );
271 271
 
272
-        if ( is_array( $value ) ) {
273
-            // translate array of values to "in"
272
+		if ( is_array( $value ) ) {
273
+			// translate array of values to "in"
274 274
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
275 275
 				$where = preg_replace('/' . $key . '$/', '', $where);
276 276
 				$where .= '(';
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 				$where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')';
289 289
 				$values = array_merge( $values, $value );
290 290
 			}
291
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
291
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
292 292
 			/**
293 293
 			 * Allow string to start or end with the value
294 294
 			 * If the key is like% then skip the first % for starts with
@@ -308,9 +308,9 @@  discard block
 block discarded – undo
308 308
 			$where .= ' %s';
309 309
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
310 310
 
311
-        } else if ( $value === null ) {
312
-            $where .= ' IS NULL';
313
-        } else {
311
+		} else if ( $value === null ) {
312
+			$where .= ' IS NULL';
313
+		} else {
314 314
 			// allow a - to prevent = from being added
315 315
 			if ( substr( $key, -1 ) == '-' ) {
316 316
 				$where = rtrim( $where, '-' );
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 
321 321
 			self::add_query_placeholder( $key, $value, $where );
322 322
 
323
-            $values[] = $value;
324
-        }
325
-    }
323
+			$values[] = $value;
324
+		}
325
+	}
326 326
 
327 327
 	/**
328 328
 	 * Add %d, or %s to query
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 	 * @param int|string $value
333 333
 	 * @param string $where
334 334
 	 */
335
-    private static function add_query_placeholder( $key, $value, &$where ) {
335
+	private static function add_query_placeholder( $key, $value, &$where ) {
336 336
 		if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
337 337
 			$where .= '%d';
338 338
 		} else {
@@ -340,16 +340,16 @@  discard block
 block discarded – undo
340 340
 		}
341 341
 	}
342 342
 
343
-    /**
344
-     * @param string $table
343
+	/**
344
+	 * @param string $table
345 345
 	 * @param array $where
346 346
 	 * @param array $args
347 347
 	 * @return int
348
-     */
349
-    public static function get_count( $table, $where = array(), $args = array() ) {
350
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
351
-        return $count;
352
-    }
348
+	 */
349
+	public static function get_count( $table, $where = array(), $args = array() ) {
350
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
351
+		return $count;
352
+	}
353 353
 
354 354
 	/**
355 355
 	 * @param string $table
@@ -360,17 +360,17 @@  discard block
 block discarded – undo
360 360
 	 * @param string $type
361 361
 	 * @return array|null|string|object
362 362
 	 */
363
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
364
-        $group = '';
365
-        self::get_group_and_table_name( $table, $group );
363
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
364
+		$group = '';
365
+		self::get_group_and_table_name( $table, $group );
366 366
 		self::convert_options_to_array( $args, '', $limit );
367 367
 
368 368
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
369 369
 
370 370
 		$cache_key = self::generate_cache_key( $where, $args, $field, $type );
371 371
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
372
-        return $results;
373
-    }
372
+		return $results;
373
+	}
374 374
 
375 375
 	/**
376 376
 	 * Generate a cache key from the where query, field, type, and other arguments
@@ -396,44 +396,44 @@  discard block
 block discarded – undo
396 396
 		return $cache_key;
397 397
 	}
398 398
 
399
-    /**
400
-     * @param string $table
401
-     * @param array $where
399
+	/**
400
+	 * @param string $table
401
+	 * @param array $where
402 402
 	 * @param string $field
403 403
 	 * @param array $args
404 404
 	 * @param string $limit
405 405
 	 * @return mixed
406
-     */
407
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
408
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
409
-    }
410
-
411
-    /**
412
-     * @since 2.0
413
-     * @param string $table
406
+	 */
407
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
408
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
409
+	}
410
+
411
+	/**
412
+	 * @since 2.0
413
+	 * @param string $table
414 414
 	 * @param array $where
415 415
 	 * @param string $fields
416 416
 	 * @param array $args
417 417
 	 * @return mixed
418
-     */
419
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
420
-        $args['limit'] = 1;
421
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
422
-    }
423
-
424
-    /**
425
-     * Prepare a key/value array before DB call
418
+	 */
419
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
420
+		$args['limit'] = 1;
421
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
422
+	}
423
+
424
+	/**
425
+	 * Prepare a key/value array before DB call
426 426
 	 *
427
-     * @since 2.0
428
-     * @param string $table
427
+	 * @since 2.0
428
+	 * @param string $table
429 429
 	 * @param array $where
430 430
 	 * @param string $fields
431 431
 	 * @param array $args
432 432
 	 * @return mixed
433
-     */
434
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
435
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
436
-    }
433
+	 */
434
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
435
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
436
+	}
437 437
 
438 438
 	/**
439 439
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -470,59 +470,59 @@  discard block
 block discarded – undo
470 470
 		return '';
471 471
 	}
472 472
 
473
-    /**
474
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
475
-     * Also add the wpdb->prefix to the table if it's missing
476
-     *
477
-     * @param string $table
478
-     * @param string $group
479
-     */
480
-    private static function get_group_and_table_name( &$table, &$group ) {
473
+	/**
474
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
475
+	 * Also add the wpdb->prefix to the table if it's missing
476
+	 *
477
+	 * @param string $table
478
+	 * @param string $group
479
+	 */
480
+	private static function get_group_and_table_name( &$table, &$group ) {
481 481
 		global $wpdb, $wpmuBaseTablePrefix;
482 482
 
483
-        $table_parts = explode(' ', $table);
484
-        $group = reset($table_parts);
485
-        $group = str_replace( $wpdb->prefix, '', $group );
483
+		$table_parts = explode(' ', $table);
484
+		$group = reset($table_parts);
485
+		$group = str_replace( $wpdb->prefix, '', $group );
486 486
 
487 487
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
488 488
 		$group = str_replace( $prefix, '', $group );
489 489
 
490
-        if ( $group == $table ) {
491
-            $table = $wpdb->prefix . $table;
492
-        }
490
+		if ( $group == $table ) {
491
+			$table = $wpdb->prefix . $table;
492
+		}
493 493
 
494 494
 		// switch to singular group name
495 495
 		$group = rtrim( $group, 's' );
496
-    }
496
+	}
497 497
 
498
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
499
-        if ( ! is_array($args) ) {
498
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
499
+		if ( ! is_array($args) ) {
500 500
 			$args = array( 'order_by' => $args );
501
-        }
501
+		}
502 502
 
503
-        if ( ! empty( $order_by ) ) {
504
-            $args['order_by'] = $order_by;
505
-        }
503
+		if ( ! empty( $order_by ) ) {
504
+			$args['order_by'] = $order_by;
505
+		}
506 506
 
507
-        if ( ! empty( $limit ) ) {
508
-            $args['limit'] = $limit;
509
-        }
507
+		if ( ! empty( $limit ) ) {
508
+			$args['limit'] = $limit;
509
+		}
510 510
 
511
-        $temp_args = $args;
512
-        foreach ( $temp_args as $k => $v ) {
513
-            if ( $v == '' ) {
511
+		$temp_args = $args;
512
+		foreach ( $temp_args as $k => $v ) {
513
+			if ( $v == '' ) {
514 514
 				unset( $args[ $k ] );
515
-                continue;
516
-            }
515
+				continue;
516
+			}
517 517
 
518
-            if ( $k == 'limit' ) {
518
+			if ( $k == 'limit' ) {
519 519
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
520
-            }
521
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
522
-            if ( strpos( $v, $db_name ) === false ) {
520
+			}
521
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
522
+			if ( strpos( $v, $db_name ) === false ) {
523 523
 				$args[ $k ] = $db_name . ' ' . $v;
524
-            }
525
-        }
524
+			}
525
+		}
526 526
 
527 527
 		// Make sure LIMIT is the last argument
528 528
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 			unset( $args['limit'] );
531 531
 			$args['limit'] = $temp_limit;
532 532
 		}
533
-    }
533
+	}
534 534
 
535 535
 	/**
536 536
 	 * Get the associative array results for the given columns, table, and where query
@@ -583,31 +583,31 @@  discard block
 block discarded – undo
583 583
 		return $query;
584 584
 	}
585 585
 
586
-    public function uninstall() {
586
+	public function uninstall() {
587 587
 		if ( ! current_user_can( 'administrator' ) ) {
588
-            $frm_settings = FrmAppHelper::get_settings();
589
-            wp_die($frm_settings->admin_permission);
590
-        }
588
+			$frm_settings = FrmAppHelper::get_settings();
589
+			wp_die($frm_settings->admin_permission);
590
+		}
591 591
 
592
-        global $wpdb, $wp_roles;
592
+		global $wpdb, $wp_roles;
593 593
 
594 594
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
595 595
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
596 596
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
597 597
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
598 598
 
599
-        delete_option('frm_options');
600
-        delete_option('frm_db_version');
599
+		delete_option('frm_options');
600
+		delete_option('frm_db_version');
601 601
 
602
-        //delete roles
603
-        $frm_roles = FrmAppHelper::frm_capabilities();
604
-        $roles = get_editable_roles();
605
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
606
-            foreach ( $roles as $role => $details ) {
607
-                $wp_roles->remove_cap( $role, $frm_role );
608
-                unset($role, $details);
609
-    		}
610
-    		unset($frm_role, $frm_role_description);
602
+		//delete roles
603
+		$frm_roles = FrmAppHelper::frm_capabilities();
604
+		$roles = get_editable_roles();
605
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
606
+			foreach ( $roles as $role => $details ) {
607
+				$wp_roles->remove_cap( $role, $frm_role );
608
+				unset($role, $details);
609
+			}
610
+			unset($frm_role, $frm_role_description);
611 611
 		}
612 612
 		unset($roles, $frm_roles);
613 613
 
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
 
632 632
 		$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_%' ) );
633 633
 
634
-        do_action('frm_after_uninstall');
635
-        return true;
636
-    }
634
+		do_action('frm_after_uninstall');
635
+		return true;
636
+	}
637 637
 
638 638
 	/**
639 639
 	 * Migrate old styling settings. If sites are using the old
@@ -672,150 +672,150 @@  discard block
 block discarded – undo
672 672
 		}
673 673
 	}
674 674
 
675
-    /**
676
-     * Change field size from character to pixel -- Multiply by 9
677
-     */
678
-    private function migrate_to_17() {
679
-        global $wpdb;
675
+	/**
676
+	 * Change field size from character to pixel -- Multiply by 9
677
+	 */
678
+	private function migrate_to_17() {
679
+		global $wpdb;
680 680
 		$pixel_conversion = 9;
681 681
 
682
-        // Get query arguments
682
+		// Get query arguments
683 683
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
684 684
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
685 685
 
686
-        // Get results
686
+		// Get results
687 687
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
688 688
 
689
-        $updated = 0;
690
-        foreach ( $fields as $f ) {
691
-            $f->field_options = maybe_unserialize($f->field_options);
692
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
693
-                continue;
694
-            }
689
+		$updated = 0;
690
+		foreach ( $fields as $f ) {
691
+			$f->field_options = maybe_unserialize($f->field_options);
692
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
693
+				continue;
694
+			}
695 695
 
696 696
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
697
-            $f->field_options['size'] .= 'px';
698
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
699
-            if ( $u ) {
700
-                $updated++;
701
-            }
702
-            unset($f);
703
-        }
704
-
705
-        // Change the characters in widgets to pixels
706
-        $widgets = get_option('widget_frm_show_form');
707
-        if ( empty($widgets) ) {
708
-            return;
709
-        }
710
-
711
-        $widgets = maybe_unserialize($widgets);
712
-        foreach ( $widgets as $k => $widget ) {
713
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
714
-                continue;
715
-            }
697
+			$f->field_options['size'] .= 'px';
698
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
699
+			if ( $u ) {
700
+				$updated++;
701
+			}
702
+			unset($f);
703
+		}
704
+
705
+		// Change the characters in widgets to pixels
706
+		$widgets = get_option('widget_frm_show_form');
707
+		if ( empty($widgets) ) {
708
+			return;
709
+		}
710
+
711
+		$widgets = maybe_unserialize($widgets);
712
+		foreach ( $widgets as $k => $widget ) {
713
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
714
+				continue;
715
+			}
716 716
 			$size = round( $pixel_conversion * (int) $widget['size'] );
717
-            $size .= 'px';
717
+			$size .= 'px';
718 718
 			$widgets[ $k ]['size'] = $size;
719
-        }
720
-        update_option('widget_frm_show_form', $widgets);
721
-    }
722
-
723
-    /**
724
-     * Migrate post and email notification settings into actions
725
-     */
726
-    private function migrate_to_16() {
727
-        global $wpdb;
728
-
729
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
730
-
731
-        /**
732
-        * Old email settings format:
733
-        * email_to: Email or field id
734
-        * also_email_to: array of fields ids
735
-        * reply_to: Email, field id, 'custom'
736
-        * cust_reply_to: string
737
-        * reply_to_name: field id, 'custom'
738
-        * cust_reply_to_name: string
739
-        * plain_text: 0|1
740
-        * email_message: string or ''
741
-        * email_subject: string or ''
742
-        * inc_user_info: 0|1
743
-        * update_email: 0, 1, 2
744
-        *
745
-        * Old autoresponder settings format:
746
-        * auto_responder: 0|1
747
-        * ar_email_message: string or ''
748
-        * ar_email_to: field id
749
-        * ar_plain_text: 0|1
750
-        * ar_reply_to_name: string
751
-        * ar_reply_to: string
752
-        * ar_email_subject: string
753
-        * ar_update_email: 0, 1, 2
754
-        *
755
-        * New email settings:
756
-        * post_content: json settings
757
-        * post_title: form id
758
-        * post_excerpt: message
759
-        *
760
-        */
761
-
762
-        foreach ( $forms as $form ) {
719
+		}
720
+		update_option('widget_frm_show_form', $widgets);
721
+	}
722
+
723
+	/**
724
+	 * Migrate post and email notification settings into actions
725
+	 */
726
+	private function migrate_to_16() {
727
+		global $wpdb;
728
+
729
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
730
+
731
+		/**
732
+		 * Old email settings format:
733
+		 * email_to: Email or field id
734
+		 * also_email_to: array of fields ids
735
+		 * reply_to: Email, field id, 'custom'
736
+		 * cust_reply_to: string
737
+		 * reply_to_name: field id, 'custom'
738
+		 * cust_reply_to_name: string
739
+		 * plain_text: 0|1
740
+		 * email_message: string or ''
741
+		 * email_subject: string or ''
742
+		 * inc_user_info: 0|1
743
+		 * update_email: 0, 1, 2
744
+		 *
745
+		 * Old autoresponder settings format:
746
+		 * auto_responder: 0|1
747
+		 * ar_email_message: string or ''
748
+		 * ar_email_to: field id
749
+		 * ar_plain_text: 0|1
750
+		 * ar_reply_to_name: string
751
+		 * ar_reply_to: string
752
+		 * ar_email_subject: string
753
+		 * ar_update_email: 0, 1, 2
754
+		 *
755
+		 * New email settings:
756
+		 * post_content: json settings
757
+		 * post_title: form id
758
+		 * post_excerpt: message
759
+		 *
760
+		 */
761
+
762
+		foreach ( $forms as $form ) {
763 763
 			if ( $form->is_template && $form->default_template ) {
764 764
 				// don't migrate the default templates since the email will be added anyway
765 765
 				continue;
766 766
 			}
767 767
 
768
-            // Format form options
769
-            $form_options = maybe_unserialize($form->options);
768
+			// Format form options
769
+			$form_options = maybe_unserialize($form->options);
770 770
 
771
-            // Migrate settings to actions
772
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
773
-        }
774
-    }
771
+			// Migrate settings to actions
772
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
773
+		}
774
+	}
775 775
 
776
-    private function migrate_to_11() {
777
-        global $wpdb;
776
+	private function migrate_to_11() {
777
+		global $wpdb;
778 778
 
779
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
779
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
780 780
 
781
-        $sending = __( 'Sending', 'formidable' );
781
+		$sending = __( 'Sending', 'formidable' );
782 782
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
783
-        $old_default_html = <<<DEFAULT_HTML
783
+		$old_default_html = <<<DEFAULT_HTML
784 784
 <div class="frm_submit">
785 785
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
786 786
 <input type="submit" value="[button_label]" [button_action] />
787 787
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
788 788
 </div>
789 789
 DEFAULT_HTML;
790
-        unset($sending, $img);
790
+		unset($sending, $img);
791 791
 
792
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
793
-        $draft_link = FrmFormsHelper::get_draft_link();
792
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
793
+		$draft_link = FrmFormsHelper::get_draft_link();
794 794
 		foreach ( $forms as $form ) {
795
-            $form->options = maybe_unserialize($form->options);
796
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
797
-                continue;
798
-            }
795
+			$form->options = maybe_unserialize($form->options);
796
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
797
+				continue;
798
+			}
799 799
 
800
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
801
-                $form->options['submit_html'] = $new_default_html;
800
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
801
+				$form->options['submit_html'] = $new_default_html;
802 802
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
803 803
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
804 804
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
805 805
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
806
-            }
807
-            unset($form);
808
-        }
809
-        unset($forms);
810
-    }
806
+			}
807
+			unset($form);
808
+		}
809
+		unset($forms);
810
+	}
811 811
 
812
-    private function migrate_to_6() {
813
-        global $wpdb;
812
+	private function migrate_to_6() {
813
+		global $wpdb;
814 814
 
815 815
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
816 816
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
817 817
 
818
-        $default_html = <<<DEFAULT_HTML
818
+		$default_html = <<<DEFAULT_HTML
819 819
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
820 820
     <label class="frm_pos_[label_position]">[field_name]
821 821
         <span class="frm_required">[required_label]</span>
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
 </div>
826 826
 DEFAULT_HTML;
827 827
 
828
-        $old_default_html = <<<DEFAULT_HTML
828
+		$old_default_html = <<<DEFAULT_HTML
829 829
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
830 830
     <label class="frm_pos_[label_position]">[field_name]
831 831
         <span class="frm_required">[required_label]</span>
@@ -835,23 +835,23 @@  discard block
 block discarded – undo
835 835
 </div>
836 836
 DEFAULT_HTML;
837 837
 
838
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
839
-        foreach ( $fields as $field ) {
840
-            $field->field_options = maybe_unserialize($field->field_options);
838
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
839
+		foreach ( $fields as $field ) {
840
+			$field->field_options = maybe_unserialize($field->field_options);
841 841
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
842
-                $field->field_options['custom_html'] = $new_default_html;
842
+				$field->field_options['custom_html'] = $new_default_html;
843 843
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
844
-            }
845
-            unset($field);
846
-        }
847
-        unset($default_html, $old_default_html, $fields);
848
-    }
849
-
850
-    private function migrate_to_4() {
851
-        global $wpdb;
844
+			}
845
+			unset($field);
846
+		}
847
+		unset($default_html, $old_default_html, $fields);
848
+	}
849
+
850
+	private function migrate_to_4() {
851
+		global $wpdb;
852 852
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
853
-        foreach ( $user_ids as $user_id ) {
853
+		foreach ( $user_ids as $user_id ) {
854 854
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
855
-        }
856
-    }
855
+		}
856
+	}
857 857
 }
Please login to merge, or discard this patch.