Completed
Push — master ( 7edec6...b07f11 )
by Jamie
03:40
created
classes/models/FrmDb.php 1 patch
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -1,64 +1,64 @@  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
-        global $wpdb;
23
-        //$frm_db_version is the version of the database we're moving to
24
-        $frm_db_version = FrmAppHelper::$db_version;
25
-        $old_db_version = (float) $old_db_version;
26
-        if ( ! $old_db_version ) {
27
-            $old_db_version = get_option('frm_db_version');
28
-        }
29
-
30
-        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
+		global $wpdb;
23
+		//$frm_db_version is the version of the database we're moving to
24
+		$frm_db_version = FrmAppHelper::$db_version;
25
+		$old_db_version = (float) $old_db_version;
26
+		if ( ! $old_db_version ) {
27
+			$old_db_version = get_option('frm_db_version');
28
+		}
29
+
30
+		if ( $frm_db_version != $old_db_version ) {
31 31
 			// update rewrite rules for views and other custom post types
32 32
 			flush_rewrite_rules();
33 33
 
34 34
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
35 35
 
36
-            $this->create_tables();
37
-            $this->migrate_data($frm_db_version, $old_db_version);
36
+			$this->create_tables();
37
+			$this->migrate_data($frm_db_version, $old_db_version);
38 38
 
39
-            /***** SAVE DB VERSION *****/
40
-            update_option('frm_db_version', $frm_db_version);
39
+			/***** SAVE DB VERSION *****/
40
+			update_option('frm_db_version', $frm_db_version);
41 41
 
42
-            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
-            FrmXMLController::add_default_templates();
44
-        }
42
+			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
+			FrmXMLController::add_default_templates();
44
+		}
45 45
 
46
-        do_action('frm_after_install');
46
+		do_action('frm_after_install');
47 47
 
48
-        /**** update the styling settings ****/
48
+		/**** update the styling settings ****/
49 49
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
50 50
 			$frm_style = new FrmStyle();
51 51
 			$frm_style->update( 'default' );
52 52
 		}
53
-    }
53
+	}
54 54
 
55
-    public function collation() {
56
-        global $wpdb;
57
-        if ( ! $wpdb->has_cap( 'collation' ) ) {
58
-            return '';
59
-        }
55
+	public function collation() {
56
+		global $wpdb;
57
+		if ( ! $wpdb->has_cap( 'collation' ) ) {
58
+			return '';
59
+		}
60 60
 
61
-        $charset_collate = '';
61
+		$charset_collate = '';
62 62
 		if ( ! empty( $wpdb->charset ) ) {
63 63
 			$charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset;
64 64
 		}
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
 			$charset_collate .= ' COLLATE ' . $wpdb->collate;
68 68
 		}
69 69
 
70
-        return $charset_collate;
71
-    }
70
+		return $charset_collate;
71
+	}
72 72
 
73
-    private function create_tables() {
74
-        $charset_collate = $this->collation();
75
-        $sql = array();
73
+	private function create_tables() {
74
+		$charset_collate = $this->collation();
75
+		$sql = array();
76 76
 
77
-        /* Create/Upgrade Fields Table */
77
+		/* Create/Upgrade Fields Table */
78 78
 		$sql[] = 'CREATE TABLE ' . $this->fields . ' (
79 79
                 id int(11) NOT NULL auto_increment,
80 80
 				field_key varchar(100) default NULL,
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
                 UNIQUE KEY field_key (field_key)
94 94
         )';
95 95
 
96
-        /* Create/Upgrade Forms Table */
96
+		/* Create/Upgrade Forms Table */
97 97
 		$sql[] = 'CREATE TABLE ' . $this->forms . ' (
98 98
                 id int(11) NOT NULL auto_increment,
99 99
 				form_key varchar(100) default NULL,
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                 UNIQUE KEY form_key (form_key)
112 112
         )';
113 113
 
114
-        /* Create/Upgrade Items Table */
114
+		/* Create/Upgrade Items Table */
115 115
 		$sql[] = 'CREATE TABLE ' . $this->entries . ' (
116 116
                 id int(11) NOT NULL auto_increment,
117 117
 				item_key varchar(100) default NULL,
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 UNIQUE KEY item_key (item_key)
135 135
         )';
136 136
 
137
-        /* Create/Upgrade Meta Table */
137
+		/* Create/Upgrade Meta Table */
138 138
 		$sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
139 139
                 id int(11) NOT NULL auto_increment,
140 140
                 meta_value longtext default NULL,
@@ -146,43 +146,43 @@  discard block
 block discarded – undo
146 146
                 KEY item_id (item_id)
147 147
         )';
148 148
 
149
-        foreach ( $sql as $q ) {
149
+		foreach ( $sql as $q ) {
150 150
 			if ( function_exists( 'dbDelta' ) ) {
151 151
 				dbDelta( $q . $charset_collate . ';' );
152 152
 			} else {
153 153
 				global $wpdb;
154 154
 				$wpdb->query( $q . $charset_collate );
155 155
 			}
156
-            unset($q);
157
-        }
158
-    }
156
+			unset($q);
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * @param integer $frm_db_version
160
+	/**
161
+	 * @param integer $frm_db_version
162 162
 	 * @param int $old_db_version
163
-     */
163
+	 */
164 164
 	private function migrate_data( $frm_db_version, $old_db_version ) {
165 165
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
166
-        foreach ( $migrations as $migration ) {
167
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
166
+		foreach ( $migrations as $migration ) {
167
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
168 168
 				$function_name = 'migrate_to_' . $migration;
169
-                $this->$function_name();
170
-            }
171
-        }
172
-    }
169
+				$this->$function_name();
170
+			}
171
+		}
172
+	}
173 173
 
174
-    /**
175
-     * Change array into format $wpdb->prepare can use
174
+	/**
175
+	 * Change array into format $wpdb->prepare can use
176 176
 	 *
177 177
 	 * @param array $args
178 178
 	 * @param string $starts_with
179
-     */
180
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
181
-        if ( empty($args) ) {
179
+	 */
180
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
181
+		if ( empty($args) ) {
182 182
 			// add an arg to prevent prepare from failing
183 183
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
184 184
 			return;
185
-        }
185
+		}
186 186
 
187 187
 		$where = '';
188 188
 		$values = array();
@@ -193,64 +193,64 @@  discard block
 block discarded – undo
193 193
 		}
194 194
 
195 195
 		$args = compact( 'where', 'values' );
196
-    }
196
+	}
197 197
 
198
-    /**
198
+	/**
199 199
 	 * @param array $args
200
-     * @param string $base_where
201
-     * @param string $where
200
+	 * @param string $base_where
201
+	 * @param string $where
202 202
 	 * @param array $values
203
-     */
204
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
205
-        $condition = ' AND';
206
-        if ( isset( $args['or'] ) ) {
207
-            $condition = ' OR';
208
-            unset( $args['or'] );
209
-        }
210
-
211
-        foreach ( $args as $key => $value ) {
212
-            $where .= empty( $where ) ? $base_where : $condition;
213
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
214
-            if ( is_numeric( $key ) || $array_inc_null ) {
215
-                $where .= ' ( ';
216
-                $nested_where = '';
217
-                if ( $array_inc_null ) {
218
-                    foreach ( $value as $val ) {
219
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
220
-                    }
221
-                } else {
222
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
223
-                }
224
-                $where .= $nested_where;
225
-                $where .= ' ) ';
226
-            } else {
227
-                self::interpret_array_to_sql( $key, $value, $where, $values );
228
-            }
229
-        }
230
-    }
231
-
232
-    /**
233
-     * @param string $key
203
+	 */
204
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
205
+		$condition = ' AND';
206
+		if ( isset( $args['or'] ) ) {
207
+			$condition = ' OR';
208
+			unset( $args['or'] );
209
+		}
210
+
211
+		foreach ( $args as $key => $value ) {
212
+			$where .= empty( $where ) ? $base_where : $condition;
213
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
214
+			if ( is_numeric( $key ) || $array_inc_null ) {
215
+				$where .= ' ( ';
216
+				$nested_where = '';
217
+				if ( $array_inc_null ) {
218
+					foreach ( $value as $val ) {
219
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
220
+					}
221
+				} else {
222
+					self::parse_where_from_array( $value, '', $nested_where, $values );
223
+				}
224
+				$where .= $nested_where;
225
+				$where .= ' ) ';
226
+			} else {
227
+				self::interpret_array_to_sql( $key, $value, $where, $values );
228
+			}
229
+		}
230
+	}
231
+
232
+	/**
233
+	 * @param string $key
234 234
 	 * @param string|array $value
235
-     * @param string $where
235
+	 * @param string $where
236 236
 	 * @param array $values
237
-     */
238
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
237
+	 */
238
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
239 239
 		$key = trim( $key );
240 240
 
241
-        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
242
-            $k = explode(' ', $key);
243
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
244
-            $values[] = '%Y-%m-%d %H:%i:%s';
245
-        } else {
241
+		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
242
+			$k = explode(' ', $key);
243
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
244
+			$values[] = '%Y-%m-%d %H:%i:%s';
245
+		} else {
246 246
 			$where .= ' ' . $key;
247
-        }
247
+		}
248 248
 
249 249
 		$lowercase_key = explode( ' ', strtolower( $key ) );
250 250
 		$lowercase_key = end( $lowercase_key );
251 251
 
252
-        if ( is_array( $value ) ) {
253
-            // translate array of values to "in"
252
+		if ( is_array( $value ) ) {
253
+			// translate array of values to "in"
254 254
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
255 255
 				$where = preg_replace('/' . $key . '$/', '', $where);
256 256
 				$where .= '(';
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 				$where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')';
269 269
 				$values = array_merge( $values, $value );
270 270
 			}
271
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
271
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
272 272
 			/**
273 273
 			 * Allow string to start or end with the value
274 274
 			 * If the key is like% then skip the first % for starts with
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 			$where .= ' %s';
288 288
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
289 289
 
290
-        } else if ( $value === null ) {
291
-            $where .= ' IS NULL';
292
-        } else {
290
+		} else if ( $value === null ) {
291
+			$where .= ' IS NULL';
292
+		} else {
293 293
 			// allow a - to prevent = from being added
294 294
 			if ( substr( $key, -1 ) == '-' ) {
295 295
 				$where = rtrim( $where, '-' );
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
 
300 300
 			self::add_query_placeholder( $key, $value, $where );
301 301
 
302
-            $values[] = $value;
303
-        }
304
-    }
302
+			$values[] = $value;
303
+		}
304
+	}
305 305
 
306 306
 	/**
307 307
 	 * Add %d, or %s to query
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 * @param int|string $value
312 312
 	 * @param string $where
313 313
 	 */
314
-    private static function add_query_placeholder( $key, $value, &$where ) {
314
+	private static function add_query_placeholder( $key, $value, &$where ) {
315 315
 		if ( is_numeric( $value ) && strpos( $key, 'meta_value' ) === false ) {
316 316
 			$where .= '%d';
317 317
 		} else {
@@ -319,16 +319,16 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 	}
321 321
 
322
-    /**
323
-     * @param string $table
322
+	/**
323
+	 * @param string $table
324 324
 	 * @param array $where
325 325
 	 * @param array $args
326 326
 	 * @return int
327
-     */
328
-    public static function get_count( $table, $where = array(), $args = array() ) {
329
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
330
-        return $count;
331
-    }
327
+	 */
328
+	public static function get_count( $table, $where = array(), $args = array() ) {
329
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
330
+		return $count;
331
+	}
332 332
 
333 333
 	/**
334 334
 	 * @param string $table
@@ -339,56 +339,56 @@  discard block
 block discarded – undo
339 339
 	 * @param string $type
340 340
 	 * @return array|null|string|object
341 341
 	 */
342
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
343
-        $group = '';
344
-        self::get_group_and_table_name( $table, $group );
342
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
343
+		$group = '';
344
+		self::get_group_and_table_name( $table, $group );
345 345
 		self::convert_options_to_array( $args, '', $limit );
346 346
 
347 347
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
348 348
 
349 349
 		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) );
350 350
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
351
-        return $results;
352
-    }
351
+		return $results;
352
+	}
353 353
 
354
-    /**
355
-     * @param string $table
356
-     * @param array $where
354
+	/**
355
+	 * @param string $table
356
+	 * @param array $where
357 357
 	 * @param string $field
358 358
 	 * @param array $args
359 359
 	 * @param string $limit
360 360
 	 * @return mixed
361
-     */
362
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
363
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
364
-    }
365
-
366
-    /**
367
-     * @since 2.0
368
-     * @param string $table
361
+	 */
362
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
363
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
364
+	}
365
+
366
+	/**
367
+	 * @since 2.0
368
+	 * @param string $table
369 369
 	 * @param array $where
370 370
 	 * @param string $fields
371 371
 	 * @param array $args
372 372
 	 * @return mixed
373
-     */
374
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
375
-        $args['limit'] = 1;
376
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
377
-    }
378
-
379
-    /**
380
-     * Prepare a key/value array before DB call
373
+	 */
374
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
375
+		$args['limit'] = 1;
376
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
377
+	}
378
+
379
+	/**
380
+	 * Prepare a key/value array before DB call
381 381
 	 *
382
-     * @since 2.0
383
-     * @param string $table
382
+	 * @since 2.0
383
+	 * @param string $table
384 384
 	 * @param array $where
385 385
 	 * @param string $fields
386 386
 	 * @param array $args
387 387
 	 * @return mixed
388
-     */
389
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
390
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
391
-    }
388
+	 */
389
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
390
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
391
+	}
392 392
 
393 393
 	/**
394 394
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -425,59 +425,59 @@  discard block
 block discarded – undo
425 425
 		return '';
426 426
 	}
427 427
 
428
-    /**
429
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
430
-     * Also add the wpdb->prefix to the table if it's missing
431
-     *
432
-     * @param string $table
433
-     * @param string $group
434
-     */
435
-    private static function get_group_and_table_name( &$table, &$group ) {
428
+	/**
429
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
430
+	 * Also add the wpdb->prefix to the table if it's missing
431
+	 *
432
+	 * @param string $table
433
+	 * @param string $group
434
+	 */
435
+	private static function get_group_and_table_name( &$table, &$group ) {
436 436
 		global $wpdb, $wpmuBaseTablePrefix;
437 437
 
438
-        $table_parts = explode(' ', $table);
439
-        $group = reset($table_parts);
440
-        $group = str_replace( $wpdb->prefix, '', $group );
438
+		$table_parts = explode(' ', $table);
439
+		$group = reset($table_parts);
440
+		$group = str_replace( $wpdb->prefix, '', $group );
441 441
 
442 442
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
443 443
 		$group = str_replace( $prefix, '', $group );
444 444
 
445
-        if ( $group == $table ) {
446
-            $table = $wpdb->prefix . $table;
447
-        }
445
+		if ( $group == $table ) {
446
+			$table = $wpdb->prefix . $table;
447
+		}
448 448
 
449 449
 		// switch to singular group name
450 450
 		$group = rtrim( $group, 's' );
451
-    }
451
+	}
452 452
 
453
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
454
-        if ( ! is_array($args) ) {
453
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
454
+		if ( ! is_array($args) ) {
455 455
 			$args = array( 'order_by' => $args );
456
-        }
456
+		}
457 457
 
458
-        if ( ! empty( $order_by ) ) {
459
-            $args['order_by'] = $order_by;
460
-        }
458
+		if ( ! empty( $order_by ) ) {
459
+			$args['order_by'] = $order_by;
460
+		}
461 461
 
462
-        if ( ! empty( $limit ) ) {
463
-            $args['limit'] = $limit;
464
-        }
462
+		if ( ! empty( $limit ) ) {
463
+			$args['limit'] = $limit;
464
+		}
465 465
 
466
-        $temp_args = $args;
467
-        foreach ( $temp_args as $k => $v ) {
468
-            if ( $v == '' ) {
466
+		$temp_args = $args;
467
+		foreach ( $temp_args as $k => $v ) {
468
+			if ( $v == '' ) {
469 469
 				unset( $args[ $k ] );
470
-                continue;
471
-            }
470
+				continue;
471
+			}
472 472
 
473
-            if ( $k == 'limit' ) {
473
+			if ( $k == 'limit' ) {
474 474
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
475
-            }
476
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
477
-            if ( strpos( $v, $db_name ) === false ) {
475
+			}
476
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
477
+			if ( strpos( $v, $db_name ) === false ) {
478 478
 				$args[ $k ] = $db_name . ' ' . $v;
479
-            }
480
-        }
479
+			}
480
+		}
481 481
 
482 482
 		// Make sure LIMIT is the last argument
483 483
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 			unset( $args['limit'] );
486 486
 			$args['limit'] = $temp_limit;
487 487
 		}
488
-    }
488
+	}
489 489
 
490 490
 	/**
491 491
 	 * Get the associative array results for the given columns, table, and where query
@@ -538,31 +538,31 @@  discard block
 block discarded – undo
538 538
 		return $query;
539 539
 	}
540 540
 
541
-    public function uninstall() {
541
+	public function uninstall() {
542 542
 		if ( ! current_user_can( 'administrator' ) ) {
543
-            $frm_settings = FrmAppHelper::get_settings();
544
-            wp_die($frm_settings->admin_permission);
545
-        }
543
+			$frm_settings = FrmAppHelper::get_settings();
544
+			wp_die($frm_settings->admin_permission);
545
+		}
546 546
 
547
-        global $wpdb, $wp_roles;
547
+		global $wpdb, $wp_roles;
548 548
 
549 549
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
550 550
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
551 551
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
552 552
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
553 553
 
554
-        delete_option('frm_options');
555
-        delete_option('frm_db_version');
554
+		delete_option('frm_options');
555
+		delete_option('frm_db_version');
556 556
 
557
-        //delete roles
558
-        $frm_roles = FrmAppHelper::frm_capabilities();
559
-        $roles = get_editable_roles();
560
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
561
-            foreach ( $roles as $role => $details ) {
562
-                $wp_roles->remove_cap( $role, $frm_role );
563
-                unset($role, $details);
564
-    		}
565
-    		unset($frm_role, $frm_role_description);
557
+		//delete roles
558
+		$frm_roles = FrmAppHelper::frm_capabilities();
559
+		$roles = get_editable_roles();
560
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
561
+			foreach ( $roles as $role => $details ) {
562
+				$wp_roles->remove_cap( $role, $frm_role );
563
+				unset($role, $details);
564
+			}
565
+			unset($frm_role, $frm_role_description);
566 566
 		}
567 567
 		unset($roles, $frm_roles);
568 568
 
@@ -586,9 +586,9 @@  discard block
 block discarded – undo
586 586
 
587 587
 		$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_%' ) );
588 588
 
589
-        do_action('frm_after_uninstall');
590
-        return true;
591
-    }
589
+		do_action('frm_after_uninstall');
590
+		return true;
591
+	}
592 592
 
593 593
 	/**
594 594
 	 * Migrate old styling settings. If sites are using the old
@@ -627,150 +627,150 @@  discard block
 block discarded – undo
627 627
 		}
628 628
 	}
629 629
 
630
-    /**
631
-     * Change field size from character to pixel -- Multiply by 9
632
-     */
633
-    private function migrate_to_17() {
634
-        global $wpdb;
630
+	/**
631
+	 * Change field size from character to pixel -- Multiply by 9
632
+	 */
633
+	private function migrate_to_17() {
634
+		global $wpdb;
635 635
 		$pixel_conversion = 9;
636 636
 
637
-        // Get query arguments
637
+		// Get query arguments
638 638
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
639 639
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
640 640
 
641
-        // Get results
641
+		// Get results
642 642
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
643 643
 
644
-        $updated = 0;
645
-        foreach ( $fields as $f ) {
646
-            $f->field_options = maybe_unserialize($f->field_options);
647
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
648
-                continue;
649
-            }
644
+		$updated = 0;
645
+		foreach ( $fields as $f ) {
646
+			$f->field_options = maybe_unserialize($f->field_options);
647
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
648
+				continue;
649
+			}
650 650
 
651 651
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
652
-            $f->field_options['size'] .= 'px';
653
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
654
-            if ( $u ) {
655
-                $updated++;
656
-            }
657
-            unset($f);
658
-        }
659
-
660
-        // Change the characters in widgets to pixels
661
-        $widgets = get_option('widget_frm_show_form');
662
-        if ( empty($widgets) ) {
663
-            return;
664
-        }
665
-
666
-        $widgets = maybe_unserialize($widgets);
667
-        foreach ( $widgets as $k => $widget ) {
668
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
669
-                continue;
670
-            }
652
+			$f->field_options['size'] .= 'px';
653
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
654
+			if ( $u ) {
655
+				$updated++;
656
+			}
657
+			unset($f);
658
+		}
659
+
660
+		// Change the characters in widgets to pixels
661
+		$widgets = get_option('widget_frm_show_form');
662
+		if ( empty($widgets) ) {
663
+			return;
664
+		}
665
+
666
+		$widgets = maybe_unserialize($widgets);
667
+		foreach ( $widgets as $k => $widget ) {
668
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
669
+				continue;
670
+			}
671 671
 			$size = round( $pixel_conversion * (int) $widget['size'] );
672
-            $size .= 'px';
672
+			$size .= 'px';
673 673
 			$widgets[ $k ]['size'] = $size;
674
-        }
675
-        update_option('widget_frm_show_form', $widgets);
676
-    }
677
-
678
-    /**
679
-     * Migrate post and email notification settings into actions
680
-     */
681
-    private function migrate_to_16() {
682
-        global $wpdb;
683
-
684
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
685
-
686
-        /**
687
-        * Old email settings format:
688
-        * email_to: Email or field id
689
-        * also_email_to: array of fields ids
690
-        * reply_to: Email, field id, 'custom'
691
-        * cust_reply_to: string
692
-        * reply_to_name: field id, 'custom'
693
-        * cust_reply_to_name: string
694
-        * plain_text: 0|1
695
-        * email_message: string or ''
696
-        * email_subject: string or ''
697
-        * inc_user_info: 0|1
698
-        * update_email: 0, 1, 2
699
-        *
700
-        * Old autoresponder settings format:
701
-        * auto_responder: 0|1
702
-        * ar_email_message: string or ''
703
-        * ar_email_to: field id
704
-        * ar_plain_text: 0|1
705
-        * ar_reply_to_name: string
706
-        * ar_reply_to: string
707
-        * ar_email_subject: string
708
-        * ar_update_email: 0, 1, 2
709
-        *
710
-        * New email settings:
711
-        * post_content: json settings
712
-        * post_title: form id
713
-        * post_excerpt: message
714
-        *
715
-        */
716
-
717
-        foreach ( $forms as $form ) {
674
+		}
675
+		update_option('widget_frm_show_form', $widgets);
676
+	}
677
+
678
+	/**
679
+	 * Migrate post and email notification settings into actions
680
+	 */
681
+	private function migrate_to_16() {
682
+		global $wpdb;
683
+
684
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
685
+
686
+		/**
687
+		 * Old email settings format:
688
+		 * email_to: Email or field id
689
+		 * also_email_to: array of fields ids
690
+		 * reply_to: Email, field id, 'custom'
691
+		 * cust_reply_to: string
692
+		 * reply_to_name: field id, 'custom'
693
+		 * cust_reply_to_name: string
694
+		 * plain_text: 0|1
695
+		 * email_message: string or ''
696
+		 * email_subject: string or ''
697
+		 * inc_user_info: 0|1
698
+		 * update_email: 0, 1, 2
699
+		 *
700
+		 * Old autoresponder settings format:
701
+		 * auto_responder: 0|1
702
+		 * ar_email_message: string or ''
703
+		 * ar_email_to: field id
704
+		 * ar_plain_text: 0|1
705
+		 * ar_reply_to_name: string
706
+		 * ar_reply_to: string
707
+		 * ar_email_subject: string
708
+		 * ar_update_email: 0, 1, 2
709
+		 *
710
+		 * New email settings:
711
+		 * post_content: json settings
712
+		 * post_title: form id
713
+		 * post_excerpt: message
714
+		 *
715
+		 */
716
+
717
+		foreach ( $forms as $form ) {
718 718
 			if ( $form->is_template && $form->default_template ) {
719 719
 				// don't migrate the default templates since the email will be added anyway
720 720
 				continue;
721 721
 			}
722 722
 
723
-            // Format form options
724
-            $form_options = maybe_unserialize($form->options);
723
+			// Format form options
724
+			$form_options = maybe_unserialize($form->options);
725 725
 
726
-            // Migrate settings to actions
727
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
728
-        }
729
-    }
726
+			// Migrate settings to actions
727
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
728
+		}
729
+	}
730 730
 
731
-    private function migrate_to_11() {
732
-        global $wpdb;
731
+	private function migrate_to_11() {
732
+		global $wpdb;
733 733
 
734
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
734
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
735 735
 
736
-        $sending = __( 'Sending', 'formidable' );
736
+		$sending = __( 'Sending', 'formidable' );
737 737
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
738
-        $old_default_html = <<<DEFAULT_HTML
738
+		$old_default_html = <<<DEFAULT_HTML
739 739
 <div class="frm_submit">
740 740
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
741 741
 <input type="submit" value="[button_label]" [button_action] />
742 742
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
743 743
 </div>
744 744
 DEFAULT_HTML;
745
-        unset($sending, $img);
745
+		unset($sending, $img);
746 746
 
747
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
748
-        $draft_link = FrmFormsHelper::get_draft_link();
747
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
748
+		$draft_link = FrmFormsHelper::get_draft_link();
749 749
 		foreach ( $forms as $form ) {
750
-            $form->options = maybe_unserialize($form->options);
751
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
752
-                continue;
753
-            }
750
+			$form->options = maybe_unserialize($form->options);
751
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
752
+				continue;
753
+			}
754 754
 
755
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
756
-                $form->options['submit_html'] = $new_default_html;
755
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
756
+				$form->options['submit_html'] = $new_default_html;
757 757
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
758 758
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
759 759
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
760 760
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
761
-            }
762
-            unset($form);
763
-        }
764
-        unset($forms);
765
-    }
761
+			}
762
+			unset($form);
763
+		}
764
+		unset($forms);
765
+	}
766 766
 
767
-    private function migrate_to_6() {
768
-        global $wpdb;
767
+	private function migrate_to_6() {
768
+		global $wpdb;
769 769
 
770 770
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
771 771
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
772 772
 
773
-        $default_html = <<<DEFAULT_HTML
773
+		$default_html = <<<DEFAULT_HTML
774 774
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
775 775
     <label class="frm_pos_[label_position]">[field_name]
776 776
         <span class="frm_required">[required_label]</span>
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 </div>
781 781
 DEFAULT_HTML;
782 782
 
783
-        $old_default_html = <<<DEFAULT_HTML
783
+		$old_default_html = <<<DEFAULT_HTML
784 784
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
785 785
     <label class="frm_pos_[label_position]">[field_name]
786 786
         <span class="frm_required">[required_label]</span>
@@ -790,25 +790,25 @@  discard block
 block discarded – undo
790 790
 </div>
791 791
 DEFAULT_HTML;
792 792
 
793
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
794
-        foreach ( $fields as $field ) {
795
-            $field->field_options = maybe_unserialize($field->field_options);
793
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
794
+		foreach ( $fields as $field ) {
795
+			$field->field_options = maybe_unserialize($field->field_options);
796 796
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
797
-                $field->field_options['custom_html'] = $new_default_html;
797
+				$field->field_options['custom_html'] = $new_default_html;
798 798
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
799
-            }
800
-            unset($field);
801
-        }
802
-        unset($default_html, $old_default_html, $fields);
803
-    }
804
-
805
-    private function migrate_to_4() {
806
-        global $wpdb;
799
+			}
800
+			unset($field);
801
+		}
802
+		unset($default_html, $old_default_html, $fields);
803
+	}
804
+
805
+	private function migrate_to_4() {
806
+		global $wpdb;
807 807
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
808
-        foreach ( $user_ids as $user_id ) {
808
+		foreach ( $user_ids as $user_id ) {
809 809
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
810
-        }
811
-    }
810
+		}
811
+	}
812 812
 
813 813
 	public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
814 814
 		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
Please login to merge, or discard this patch.