Completed
Push — master ( c86466...ee844c )
by Jamie
04:56
created
classes/models/FrmDb.php 1 patch
Indentation   +339 added lines, -339 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,67 +319,67 @@  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
-    }
332
-
333
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
334
-        $group = '';
335
-        self::get_group_and_table_name( $table, $group );
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
+
333
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
334
+		$group = '';
335
+		self::get_group_and_table_name( $table, $group );
336 336
 		self::convert_options_to_array( $args, '', $limit );
337 337
 
338 338
 		$query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
339 339
 
340 340
 		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) );
341 341
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
342
-        return $results;
343
-    }
342
+		return $results;
343
+	}
344 344
 
345
-    /**
346
-     * @param string $table
347
-     * @param array $where
345
+	/**
346
+	 * @param string $table
347
+	 * @param array $where
348 348
 	 * @param string $field
349 349
 	 * @param array $args
350 350
 	 * @param string $limit
351 351
 	 * @return mixed
352
-     */
353
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
354
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
355
-    }
356
-
357
-    /**
358
-     * @since 2.0
359
-     * @param string $table
352
+	 */
353
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
354
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
355
+	}
356
+
357
+	/**
358
+	 * @since 2.0
359
+	 * @param string $table
360 360
 	 * @param array $where
361 361
 	 * @param string $fields
362 362
 	 * @param array $args
363 363
 	 * @return mixed
364
-     */
365
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
366
-        $args['limit'] = 1;
367
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
368
-    }
369
-
370
-    /**
371
-     * Prepare a key/value array before DB call
364
+	 */
365
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
366
+		$args['limit'] = 1;
367
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
368
+	}
369
+
370
+	/**
371
+	 * Prepare a key/value array before DB call
372 372
 	 *
373
-     * @since 2.0
374
-     * @param string $table
373
+	 * @since 2.0
374
+	 * @param string $table
375 375
 	 * @param array $where
376 376
 	 * @param string $fields
377 377
 	 * @param array $args
378 378
 	 * @return mixed
379
-     */
380
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
381
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
382
-    }
379
+	 */
380
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
381
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
382
+	}
383 383
 
384 384
 	/**
385 385
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -416,59 +416,59 @@  discard block
 block discarded – undo
416 416
 		return '';
417 417
 	}
418 418
 
419
-    /**
420
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
421
-     * Also add the wpdb->prefix to the table if it's missing
422
-     *
423
-     * @param string $table
424
-     * @param string $group
425
-     */
426
-    private static function get_group_and_table_name( &$table, &$group ) {
419
+	/**
420
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
421
+	 * Also add the wpdb->prefix to the table if it's missing
422
+	 *
423
+	 * @param string $table
424
+	 * @param string $group
425
+	 */
426
+	private static function get_group_and_table_name( &$table, &$group ) {
427 427
 		global $wpdb, $wpmuBaseTablePrefix;
428 428
 
429
-        $table_parts = explode(' ', $table);
430
-        $group = reset($table_parts);
431
-        $group = str_replace( $wpdb->prefix, '', $group );
429
+		$table_parts = explode(' ', $table);
430
+		$group = reset($table_parts);
431
+		$group = str_replace( $wpdb->prefix, '', $group );
432 432
 
433 433
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
434 434
 		$group = str_replace( $prefix, '', $group );
435 435
 
436
-        if ( $group == $table ) {
437
-            $table = $wpdb->prefix . $table;
438
-        }
436
+		if ( $group == $table ) {
437
+			$table = $wpdb->prefix . $table;
438
+		}
439 439
 
440 440
 		// switch to singular group name
441 441
 		$group = rtrim( $group, 's' );
442
-    }
442
+	}
443 443
 
444
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
445
-        if ( ! is_array($args) ) {
444
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
445
+		if ( ! is_array($args) ) {
446 446
 			$args = array( 'order_by' => $args );
447
-        }
447
+		}
448 448
 
449
-        if ( ! empty( $order_by ) ) {
450
-            $args['order_by'] = $order_by;
451
-        }
449
+		if ( ! empty( $order_by ) ) {
450
+			$args['order_by'] = $order_by;
451
+		}
452 452
 
453
-        if ( ! empty( $limit ) ) {
454
-            $args['limit'] = $limit;
455
-        }
453
+		if ( ! empty( $limit ) ) {
454
+			$args['limit'] = $limit;
455
+		}
456 456
 
457
-        $temp_args = $args;
458
-        foreach ( $temp_args as $k => $v ) {
459
-            if ( $v == '' ) {
457
+		$temp_args = $args;
458
+		foreach ( $temp_args as $k => $v ) {
459
+			if ( $v == '' ) {
460 460
 				unset( $args[ $k ] );
461
-                continue;
462
-            }
461
+				continue;
462
+			}
463 463
 
464
-            if ( $k == 'limit' ) {
464
+			if ( $k == 'limit' ) {
465 465
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
466
-            }
467
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
468
-            if ( strpos( $v, $db_name ) === false ) {
466
+			}
467
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
468
+			if ( strpos( $v, $db_name ) === false ) {
469 469
 				$args[ $k ] = $db_name . ' ' . $v;
470
-            }
471
-        }
470
+			}
471
+		}
472 472
 
473 473
 		// Make sure LIMIT is the last argument
474 474
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			unset( $args['limit'] );
477 477
 			$args['limit'] = $temp_limit;
478 478
 		}
479
-    }
479
+	}
480 480
 
481 481
 	/**
482 482
 	 * Get the associative array results for the given columns, table, and where query
@@ -529,31 +529,31 @@  discard block
 block discarded – undo
529 529
 		return $query;
530 530
 	}
531 531
 
532
-    public function uninstall() {
532
+	public function uninstall() {
533 533
 		if ( ! current_user_can( 'administrator' ) ) {
534
-            $frm_settings = FrmAppHelper::get_settings();
535
-            wp_die($frm_settings->admin_permission);
536
-        }
534
+			$frm_settings = FrmAppHelper::get_settings();
535
+			wp_die($frm_settings->admin_permission);
536
+		}
537 537
 
538
-        global $wpdb, $wp_roles;
538
+		global $wpdb, $wp_roles;
539 539
 
540 540
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
541 541
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
542 542
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
543 543
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
544 544
 
545
-        delete_option('frm_options');
546
-        delete_option('frm_db_version');
545
+		delete_option('frm_options');
546
+		delete_option('frm_db_version');
547 547
 
548
-        //delete roles
549
-        $frm_roles = FrmAppHelper::frm_capabilities();
550
-        $roles = get_editable_roles();
551
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
552
-            foreach ( $roles as $role => $details ) {
553
-                $wp_roles->remove_cap( $role, $frm_role );
554
-                unset($role, $details);
555
-    		}
556
-    		unset($frm_role, $frm_role_description);
548
+		//delete roles
549
+		$frm_roles = FrmAppHelper::frm_capabilities();
550
+		$roles = get_editable_roles();
551
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
552
+			foreach ( $roles as $role => $details ) {
553
+				$wp_roles->remove_cap( $role, $frm_role );
554
+				unset($role, $details);
555
+			}
556
+			unset($frm_role, $frm_role_description);
557 557
 		}
558 558
 		unset($roles, $frm_roles);
559 559
 
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
 
578 578
 		$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_%' ) );
579 579
 
580
-        do_action('frm_after_uninstall');
581
-        return true;
582
-    }
580
+		do_action('frm_after_uninstall');
581
+		return true;
582
+	}
583 583
 
584 584
 	/**
585 585
 	 * Migrate old styling settings. If sites are using the old
@@ -618,150 +618,150 @@  discard block
 block discarded – undo
618 618
 		}
619 619
 	}
620 620
 
621
-    /**
622
-     * Change field size from character to pixel -- Multiply by 9
623
-     */
624
-    private function migrate_to_17() {
625
-        global $wpdb;
621
+	/**
622
+	 * Change field size from character to pixel -- Multiply by 9
623
+	 */
624
+	private function migrate_to_17() {
625
+		global $wpdb;
626 626
 		$pixel_conversion = 9;
627 627
 
628
-        // Get query arguments
628
+		// Get query arguments
629 629
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
630 630
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
631 631
 
632
-        // Get results
632
+		// Get results
633 633
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
634 634
 
635
-        $updated = 0;
636
-        foreach ( $fields as $f ) {
637
-            $f->field_options = maybe_unserialize($f->field_options);
638
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
639
-                continue;
640
-            }
635
+		$updated = 0;
636
+		foreach ( $fields as $f ) {
637
+			$f->field_options = maybe_unserialize($f->field_options);
638
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
639
+				continue;
640
+			}
641 641
 
642 642
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
643
-            $f->field_options['size'] .= 'px';
644
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
645
-            if ( $u ) {
646
-                $updated++;
647
-            }
648
-            unset($f);
649
-        }
650
-
651
-        // Change the characters in widgets to pixels
652
-        $widgets = get_option('widget_frm_show_form');
653
-        if ( empty($widgets) ) {
654
-            return;
655
-        }
656
-
657
-        $widgets = maybe_unserialize($widgets);
658
-        foreach ( $widgets as $k => $widget ) {
659
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
660
-                continue;
661
-            }
643
+			$f->field_options['size'] .= 'px';
644
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
645
+			if ( $u ) {
646
+				$updated++;
647
+			}
648
+			unset($f);
649
+		}
650
+
651
+		// Change the characters in widgets to pixels
652
+		$widgets = get_option('widget_frm_show_form');
653
+		if ( empty($widgets) ) {
654
+			return;
655
+		}
656
+
657
+		$widgets = maybe_unserialize($widgets);
658
+		foreach ( $widgets as $k => $widget ) {
659
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
660
+				continue;
661
+			}
662 662
 			$size = round( $pixel_conversion * (int) $widget['size'] );
663
-            $size .= 'px';
663
+			$size .= 'px';
664 664
 			$widgets[ $k ]['size'] = $size;
665
-        }
666
-        update_option('widget_frm_show_form', $widgets);
667
-    }
668
-
669
-    /**
670
-     * Migrate post and email notification settings into actions
671
-     */
672
-    private function migrate_to_16() {
673
-        global $wpdb;
674
-
675
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
676
-
677
-        /**
678
-        * Old email settings format:
679
-        * email_to: Email or field id
680
-        * also_email_to: array of fields ids
681
-        * reply_to: Email, field id, 'custom'
682
-        * cust_reply_to: string
683
-        * reply_to_name: field id, 'custom'
684
-        * cust_reply_to_name: string
685
-        * plain_text: 0|1
686
-        * email_message: string or ''
687
-        * email_subject: string or ''
688
-        * inc_user_info: 0|1
689
-        * update_email: 0, 1, 2
690
-        *
691
-        * Old autoresponder settings format:
692
-        * auto_responder: 0|1
693
-        * ar_email_message: string or ''
694
-        * ar_email_to: field id
695
-        * ar_plain_text: 0|1
696
-        * ar_reply_to_name: string
697
-        * ar_reply_to: string
698
-        * ar_email_subject: string
699
-        * ar_update_email: 0, 1, 2
700
-        *
701
-        * New email settings:
702
-        * post_content: json settings
703
-        * post_title: form id
704
-        * post_excerpt: message
705
-        *
706
-        */
707
-
708
-        foreach ( $forms as $form ) {
665
+		}
666
+		update_option('widget_frm_show_form', $widgets);
667
+	}
668
+
669
+	/**
670
+	 * Migrate post and email notification settings into actions
671
+	 */
672
+	private function migrate_to_16() {
673
+		global $wpdb;
674
+
675
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
676
+
677
+		/**
678
+		 * Old email settings format:
679
+		 * email_to: Email or field id
680
+		 * also_email_to: array of fields ids
681
+		 * reply_to: Email, field id, 'custom'
682
+		 * cust_reply_to: string
683
+		 * reply_to_name: field id, 'custom'
684
+		 * cust_reply_to_name: string
685
+		 * plain_text: 0|1
686
+		 * email_message: string or ''
687
+		 * email_subject: string or ''
688
+		 * inc_user_info: 0|1
689
+		 * update_email: 0, 1, 2
690
+		 *
691
+		 * Old autoresponder settings format:
692
+		 * auto_responder: 0|1
693
+		 * ar_email_message: string or ''
694
+		 * ar_email_to: field id
695
+		 * ar_plain_text: 0|1
696
+		 * ar_reply_to_name: string
697
+		 * ar_reply_to: string
698
+		 * ar_email_subject: string
699
+		 * ar_update_email: 0, 1, 2
700
+		 *
701
+		 * New email settings:
702
+		 * post_content: json settings
703
+		 * post_title: form id
704
+		 * post_excerpt: message
705
+		 *
706
+		 */
707
+
708
+		foreach ( $forms as $form ) {
709 709
 			if ( $form->is_template && $form->default_template ) {
710 710
 				// don't migrate the default templates since the email will be added anyway
711 711
 				continue;
712 712
 			}
713 713
 
714
-            // Format form options
715
-            $form_options = maybe_unserialize($form->options);
714
+			// Format form options
715
+			$form_options = maybe_unserialize($form->options);
716 716
 
717
-            // Migrate settings to actions
718
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
719
-        }
720
-    }
717
+			// Migrate settings to actions
718
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
719
+		}
720
+	}
721 721
 
722
-    private function migrate_to_11() {
723
-        global $wpdb;
722
+	private function migrate_to_11() {
723
+		global $wpdb;
724 724
 
725
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
725
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
726 726
 
727
-        $sending = __( 'Sending', 'formidable' );
727
+		$sending = __( 'Sending', 'formidable' );
728 728
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
729
-        $old_default_html = <<<DEFAULT_HTML
729
+		$old_default_html = <<<DEFAULT_HTML
730 730
 <div class="frm_submit">
731 731
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
732 732
 <input type="submit" value="[button_label]" [button_action] />
733 733
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
734 734
 </div>
735 735
 DEFAULT_HTML;
736
-        unset($sending, $img);
736
+		unset($sending, $img);
737 737
 
738
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
739
-        $draft_link = FrmFormsHelper::get_draft_link();
738
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
739
+		$draft_link = FrmFormsHelper::get_draft_link();
740 740
 		foreach ( $forms as $form ) {
741
-            $form->options = maybe_unserialize($form->options);
742
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
743
-                continue;
744
-            }
741
+			$form->options = maybe_unserialize($form->options);
742
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
743
+				continue;
744
+			}
745 745
 
746
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
747
-                $form->options['submit_html'] = $new_default_html;
746
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
747
+				$form->options['submit_html'] = $new_default_html;
748 748
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
749 749
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
750 750
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
751 751
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
752
-            }
753
-            unset($form);
754
-        }
755
-        unset($forms);
756
-    }
752
+			}
753
+			unset($form);
754
+		}
755
+		unset($forms);
756
+	}
757 757
 
758
-    private function migrate_to_6() {
759
-        global $wpdb;
758
+	private function migrate_to_6() {
759
+		global $wpdb;
760 760
 
761 761
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
762 762
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
763 763
 
764
-        $default_html = <<<DEFAULT_HTML
764
+		$default_html = <<<DEFAULT_HTML
765 765
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
766 766
     <label class="frm_pos_[label_position]">[field_name]
767 767
         <span class="frm_required">[required_label]</span>
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 </div>
772 772
 DEFAULT_HTML;
773 773
 
774
-        $old_default_html = <<<DEFAULT_HTML
774
+		$old_default_html = <<<DEFAULT_HTML
775 775
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
776 776
     <label class="frm_pos_[label_position]">[field_name]
777 777
         <span class="frm_required">[required_label]</span>
@@ -781,25 +781,25 @@  discard block
 block discarded – undo
781 781
 </div>
782 782
 DEFAULT_HTML;
783 783
 
784
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
785
-        foreach ( $fields as $field ) {
786
-            $field->field_options = maybe_unserialize($field->field_options);
784
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
785
+		foreach ( $fields as $field ) {
786
+			$field->field_options = maybe_unserialize($field->field_options);
787 787
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
788
-                $field->field_options['custom_html'] = $new_default_html;
788
+				$field->field_options['custom_html'] = $new_default_html;
789 789
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
790
-            }
791
-            unset($field);
792
-        }
793
-        unset($default_html, $old_default_html, $fields);
794
-    }
795
-
796
-    private function migrate_to_4() {
797
-        global $wpdb;
790
+			}
791
+			unset($field);
792
+		}
793
+		unset($default_html, $old_default_html, $fields);
794
+	}
795
+
796
+	private function migrate_to_4() {
797
+		global $wpdb;
798 798
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
799
-        foreach ( $user_ids as $user_id ) {
799
+		foreach ( $user_ids as $user_id ) {
800 800
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
801
-        }
802
-    }
801
+		}
802
+	}
803 803
 
804 804
 	public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
805 805
 		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
Please login to merge, or discard this patch.