Completed
Push — master ( 12d0cd...254d14 )
by Jamie
03:48
created
classes/models/FrmDb.php 1 patch
Indentation   +356 added lines, -356 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,39 +146,39 @@  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
162
-     */
160
+	/**
161
+	 * @param integer $frm_db_version
162
+	 */
163 163
 	private function migrate_data( $frm_db_version, $old_db_version ) {
164 164
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
165
-        foreach ( $migrations as $migration ) {
166
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
165
+		foreach ( $migrations as $migration ) {
166
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167 167
 				$function_name = 'migrate_to_' . $migration;
168
-                $this->$function_name();
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * Change array into format $wpdb->prepare can use
175
-     */
176
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
-        if ( empty($args) ) {
168
+				$this->$function_name();
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * Change array into format $wpdb->prepare can use
175
+	 */
176
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
+		if ( empty($args) ) {
178 178
 			// add an arg to prevent prepare from failing
179 179
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
180 180
 			return;
181
-        }
181
+		}
182 182
 
183 183
 		$where = '';
184 184
 		$values = array();
@@ -189,60 +189,60 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 
191 191
 		$args = compact( 'where', 'values' );
192
-    }
193
-
194
-    /**
195
-     * @param string $base_where
196
-     * @param string $where
197
-     */
198
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
-        $condition = ' AND';
200
-        if ( isset( $args['or'] ) ) {
201
-            $condition = ' OR';
202
-            unset( $args['or'] );
203
-        }
204
-
205
-        foreach ( $args as $key => $value ) {
206
-            $where .= empty( $where ) ? $base_where : $condition;
207
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
-            if ( is_numeric( $key ) || $array_inc_null ) {
209
-                $where .= ' ( ';
210
-                $nested_where = '';
211
-                if ( $array_inc_null ) {
212
-                    foreach ( $value as $val ) {
213
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
-                    }
215
-                } else {
216
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
217
-                }
218
-                $where .= $nested_where;
219
-                $where .= ' ) ';
220
-            } else {
221
-                self::interpret_array_to_sql( $key, $value, $where, $values );
222
-            }
223
-        }
224
-    }
225
-
226
-    /**
227
-     * @param string $key
228
-     * @param string $where
229
-     */
230
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
192
+	}
193
+
194
+	/**
195
+	 * @param string $base_where
196
+	 * @param string $where
197
+	 */
198
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
+		$condition = ' AND';
200
+		if ( isset( $args['or'] ) ) {
201
+			$condition = ' OR';
202
+			unset( $args['or'] );
203
+		}
204
+
205
+		foreach ( $args as $key => $value ) {
206
+			$where .= empty( $where ) ? $base_where : $condition;
207
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
+			if ( is_numeric( $key ) || $array_inc_null ) {
209
+				$where .= ' ( ';
210
+				$nested_where = '';
211
+				if ( $array_inc_null ) {
212
+					foreach ( $value as $val ) {
213
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
+					}
215
+				} else {
216
+					self::parse_where_from_array( $value, '', $nested_where, $values );
217
+				}
218
+				$where .= $nested_where;
219
+				$where .= ' ) ';
220
+			} else {
221
+				self::interpret_array_to_sql( $key, $value, $where, $values );
222
+			}
223
+		}
224
+	}
225
+
226
+	/**
227
+	 * @param string $key
228
+	 * @param string $where
229
+	 */
230
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
231 231
 		$key = trim( $key );
232 232
 
233
-        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
-            $k = explode(' ', $key);
235
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
-            $values[] = '%Y-%m-%d %H:%i:%s';
237
-        } else {
233
+		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
+			$k = explode(' ', $key);
235
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
+			$values[] = '%Y-%m-%d %H:%i:%s';
237
+		} else {
238 238
 			$where .= ' ' . $key;
239
-        }
239
+		}
240 240
 
241 241
 		$lowercase_key = explode( ' ', strtolower( $key ) );
242 242
 		$lowercase_key = end( $lowercase_key );
243 243
 
244
-        if ( is_array( $value ) ) {
245
-            // translate array of values to "in"
244
+		if ( is_array( $value ) ) {
245
+			// translate array of values to "in"
246 246
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
247 247
 				$where = rtrim( $where, $key );
248 248
 				$where .= '(';
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 				$where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')';
261 261
 				$values = array_merge( $values, $value );
262 262
 			}
263
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
263
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
264 264
 			/**
265 265
 			 * Allow string to start or end with the value
266 266
 			 * If the key is like% then skip the first % for starts with
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 			$where .= ' %s';
280 280
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
281 281
 
282
-        } else if ( $value === null ) {
283
-            $where .= ' IS NULL';
284
-        } else {
282
+		} else if ( $value === null ) {
283
+			$where .= ' IS NULL';
284
+		} else {
285 285
 			// allow a - to prevent = from being added
286 286
 			if ( substr( $key, -1 ) == '-' ) {
287 287
 				$where = rtrim( $where, '-' );
@@ -289,28 +289,28 @@  discard block
 block discarded – undo
289 289
 				$where .= '=';
290 290
 			}
291 291
 
292
-            $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
-            $values[] = $value;
294
-        }
295
-    }
296
-
297
-    /**
298
-     * @param string $table
299
-     */
300
-    public static function get_count( $table, $where = array(), $args = array() ) {
301
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
-        return $count;
303
-    }
304
-
305
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
-        $group = '';
307
-        self::get_group_and_table_name( $table, $group );
292
+			$where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
+			$values[] = $value;
294
+		}
295
+	}
296
+
297
+	/**
298
+	 * @param string $table
299
+	 */
300
+	public static function get_count( $table, $where = array(), $args = array() ) {
301
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
+		return $count;
303
+	}
304
+
305
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
+		$group = '';
307
+		self::get_group_and_table_name( $table, $group );
308 308
 		self::convert_options_to_array( $args, '', $limit );
309 309
 
310 310
 		$query = 'SELECT ' . $field . ' FROM ' . $table;
311 311
 		if ( is_array( $where ) || empty( $where ) ) {
312 312
 			// only separate into array values and query string if is array
313
-        	self::get_where_clause_and_values( $where );
313
+			self::get_where_clause_and_values( $where );
314 314
 			global $wpdb;
315 315
 			$query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
316 316
 		} else {
@@ -324,47 +324,47 @@  discard block
 block discarded – undo
324 324
 
325 325
 		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) );
326 326
 		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
327
-        return $results;
328
-    }
329
-
330
-    /**
331
-     * @param string $table
332
-     * @param array $where
333
-     */
334
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
-    }
337
-
338
-    /**
339
-     * @since 2.0
340
-     * @param string $table
341
-     */
342
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
-        $args['limit'] = 1;
344
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
-    }
346
-
347
-    /**
348
-     * @param string $table
349
-     */
350
-    public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
327
+		return $results;
328
+	}
329
+
330
+	/**
331
+	 * @param string $table
332
+	 * @param array $where
333
+	 */
334
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
+	}
337
+
338
+	/**
339
+	 * @since 2.0
340
+	 * @param string $table
341
+	 */
342
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
+		$args['limit'] = 1;
344
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
+	}
346
+
347
+	/**
348
+	 * @param string $table
349
+	 */
350
+	public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
352 352
 		return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1 ), '', 'row' );
353
-    }
354
-
355
-    public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
-        return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
-    }
359
-
360
-    /**
361
-     * Prepare a key/value array before DB call
362
-     * @since 2.0
363
-     * @param string $table
364
-     */
365
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
-    }
353
+	}
354
+
355
+	public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
+		return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
+	}
359
+
360
+	/**
361
+	 * Prepare a key/value array before DB call
362
+	 * @since 2.0
363
+	 * @param string $table
364
+	 */
365
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
+	}
368 368
 
369 369
 	/**
370 370
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -400,59 +400,59 @@  discard block
 block discarded – undo
400 400
 		return '';
401 401
 	}
402 402
 
403
-    /**
404
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
-     * Also add the wpdb->prefix to the table if it's missing
406
-     *
407
-     * @param string $table
408
-     * @param string $group
409
-     */
410
-    private static function get_group_and_table_name( &$table, &$group ) {
403
+	/**
404
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
+	 * Also add the wpdb->prefix to the table if it's missing
406
+	 *
407
+	 * @param string $table
408
+	 * @param string $group
409
+	 */
410
+	private static function get_group_and_table_name( &$table, &$group ) {
411 411
 		global $wpdb, $wpmuBaseTablePrefix;
412 412
 
413
-        $table_parts = explode(' ', $table);
414
-        $group = reset($table_parts);
415
-        $group = str_replace( $wpdb->prefix, '', $group );
413
+		$table_parts = explode(' ', $table);
414
+		$group = reset($table_parts);
415
+		$group = str_replace( $wpdb->prefix, '', $group );
416 416
 
417 417
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
418 418
 		$group = str_replace( $prefix, '', $group );
419 419
 
420
-        if ( $group == $table ) {
421
-            $table = $wpdb->prefix . $table;
422
-        }
420
+		if ( $group == $table ) {
421
+			$table = $wpdb->prefix . $table;
422
+		}
423 423
 
424 424
 		// switch to singular group name
425 425
 		$group = rtrim( $group, 's' );
426
-    }
426
+	}
427 427
 
428
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
-        if ( ! is_array($args) ) {
428
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
+		if ( ! is_array($args) ) {
430 430
 			$args = array( 'order_by' => $args );
431
-        }
431
+		}
432 432
 
433
-        if ( ! empty( $order_by ) ) {
434
-            $args['order_by'] = $order_by;
435
-        }
433
+		if ( ! empty( $order_by ) ) {
434
+			$args['order_by'] = $order_by;
435
+		}
436 436
 
437
-        if ( ! empty( $limit ) ) {
438
-            $args['limit'] = $limit;
439
-        }
437
+		if ( ! empty( $limit ) ) {
438
+			$args['limit'] = $limit;
439
+		}
440 440
 
441
-        $temp_args = $args;
442
-        foreach ( $temp_args as $k => $v ) {
443
-            if ( $v == '' ) {
441
+		$temp_args = $args;
442
+		foreach ( $temp_args as $k => $v ) {
443
+			if ( $v == '' ) {
444 444
 				unset( $args[ $k ] );
445
-                continue;
446
-            }
445
+				continue;
446
+			}
447 447
 
448
-            if ( $k == 'limit' ) {
448
+			if ( $k == 'limit' ) {
449 449
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
450
-            }
451
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
-            if ( strpos( $v, $db_name ) === false ) {
450
+			}
451
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
+			if ( strpos( $v, $db_name ) === false ) {
453 453
 				$args[ $k ] = $db_name . ' ' . $v;
454
-            }
455
-        }
454
+			}
455
+		}
456 456
 
457 457
 		// Make sure LIMIT is the last argument
458 458
 		if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
@@ -460,33 +460,33 @@  discard block
 block discarded – undo
460 460
 			unset( $args['limit'] );
461 461
 			$args['limit'] = $temp_limit;
462 462
 		}
463
-    }
463
+	}
464 464
 
465
-    public function uninstall() {
465
+	public function uninstall() {
466 466
 		if ( ! current_user_can( 'administrator' ) ) {
467
-            $frm_settings = FrmAppHelper::get_settings();
468
-            wp_die($frm_settings->admin_permission);
469
-        }
467
+			$frm_settings = FrmAppHelper::get_settings();
468
+			wp_die($frm_settings->admin_permission);
469
+		}
470 470
 
471
-        global $wpdb, $wp_roles;
471
+		global $wpdb, $wp_roles;
472 472
 
473 473
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
474 474
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
475 475
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
476 476
 		$wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
477 477
 
478
-        delete_option('frm_options');
479
-        delete_option('frm_db_version');
478
+		delete_option('frm_options');
479
+		delete_option('frm_db_version');
480 480
 
481
-        //delete roles
482
-        $frm_roles = FrmAppHelper::frm_capabilities();
483
-        $roles = get_editable_roles();
484
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
485
-            foreach ( $roles as $role => $details ) {
486
-                $wp_roles->remove_cap( $role, $frm_role );
487
-                unset($role, $details);
488
-    		}
489
-    		unset($frm_role, $frm_role_description);
481
+		//delete roles
482
+		$frm_roles = FrmAppHelper::frm_capabilities();
483
+		$roles = get_editable_roles();
484
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
485
+			foreach ( $roles as $role => $details ) {
486
+				$wp_roles->remove_cap( $role, $frm_role );
487
+				unset($role, $details);
488
+			}
489
+			unset($frm_role, $frm_role_description);
490 490
 		}
491 491
 		unset($roles, $frm_roles);
492 492
 
@@ -510,9 +510,9 @@  discard block
 block discarded – undo
510 510
 
511 511
 		$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_%' ) );
512 512
 
513
-        do_action('frm_after_uninstall');
514
-        return true;
515
-    }
513
+		do_action('frm_after_uninstall');
514
+		return true;
515
+	}
516 516
 
517 517
 	/**
518 518
 	 * Migrate old styling settings. If sites are using the old
@@ -551,150 +551,150 @@  discard block
 block discarded – undo
551 551
 		}
552 552
 	}
553 553
 
554
-    /**
555
-     * Change field size from character to pixel -- Multiply by 9
556
-     */
557
-    private function migrate_to_17() {
558
-        global $wpdb;
554
+	/**
555
+	 * Change field size from character to pixel -- Multiply by 9
556
+	 */
557
+	private function migrate_to_17() {
558
+		global $wpdb;
559 559
 		$pixel_conversion = 9;
560 560
 
561
-        // Get query arguments
561
+		// Get query arguments
562 562
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
563 563
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
564 564
 
565
-        // Get results
565
+		// Get results
566 566
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
567 567
 
568
-        $updated = 0;
569
-        foreach ( $fields as $f ) {
570
-            $f->field_options = maybe_unserialize($f->field_options);
571
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
572
-                continue;
573
-            }
568
+		$updated = 0;
569
+		foreach ( $fields as $f ) {
570
+			$f->field_options = maybe_unserialize($f->field_options);
571
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
572
+				continue;
573
+			}
574 574
 
575 575
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
576
-            $f->field_options['size'] .= 'px';
577
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
578
-            if ( $u ) {
579
-                $updated++;
580
-            }
581
-            unset($f);
582
-        }
583
-
584
-        // Change the characters in widgets to pixels
585
-        $widgets = get_option('widget_frm_show_form');
586
-        if ( empty($widgets) ) {
587
-            return;
588
-        }
589
-
590
-        $widgets = maybe_unserialize($widgets);
591
-        foreach ( $widgets as $k => $widget ) {
592
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
593
-                continue;
594
-            }
576
+			$f->field_options['size'] .= 'px';
577
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
578
+			if ( $u ) {
579
+				$updated++;
580
+			}
581
+			unset($f);
582
+		}
583
+
584
+		// Change the characters in widgets to pixels
585
+		$widgets = get_option('widget_frm_show_form');
586
+		if ( empty($widgets) ) {
587
+			return;
588
+		}
589
+
590
+		$widgets = maybe_unserialize($widgets);
591
+		foreach ( $widgets as $k => $widget ) {
592
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
593
+				continue;
594
+			}
595 595
 			$size = round( $pixel_conversion * (int) $widget['size'] );
596
-            $size .= 'px';
596
+			$size .= 'px';
597 597
 			$widgets[ $k ]['size'] = $size;
598
-        }
599
-        update_option('widget_frm_show_form', $widgets);
600
-    }
601
-
602
-    /**
603
-     * Migrate post and email notification settings into actions
604
-     */
605
-    private function migrate_to_16() {
606
-        global $wpdb;
607
-
608
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
609
-
610
-        /**
611
-        * Old email settings format:
612
-        * email_to: Email or field id
613
-        * also_email_to: array of fields ids
614
-        * reply_to: Email, field id, 'custom'
615
-        * cust_reply_to: string
616
-        * reply_to_name: field id, 'custom'
617
-        * cust_reply_to_name: string
618
-        * plain_text: 0|1
619
-        * email_message: string or ''
620
-        * email_subject: string or ''
621
-        * inc_user_info: 0|1
622
-        * update_email: 0, 1, 2
623
-        *
624
-        * Old autoresponder settings format:
625
-        * auto_responder: 0|1
626
-        * ar_email_message: string or ''
627
-        * ar_email_to: field id
628
-        * ar_plain_text: 0|1
629
-        * ar_reply_to_name: string
630
-        * ar_reply_to: string
631
-        * ar_email_subject: string
632
-        * ar_update_email: 0, 1, 2
633
-        *
634
-        * New email settings:
635
-        * post_content: json settings
636
-        * post_title: form id
637
-        * post_excerpt: message
638
-        *
639
-        */
640
-
641
-        foreach ( $forms as $form ) {
598
+		}
599
+		update_option('widget_frm_show_form', $widgets);
600
+	}
601
+
602
+	/**
603
+	 * Migrate post and email notification settings into actions
604
+	 */
605
+	private function migrate_to_16() {
606
+		global $wpdb;
607
+
608
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
609
+
610
+		/**
611
+		 * Old email settings format:
612
+		 * email_to: Email or field id
613
+		 * also_email_to: array of fields ids
614
+		 * reply_to: Email, field id, 'custom'
615
+		 * cust_reply_to: string
616
+		 * reply_to_name: field id, 'custom'
617
+		 * cust_reply_to_name: string
618
+		 * plain_text: 0|1
619
+		 * email_message: string or ''
620
+		 * email_subject: string or ''
621
+		 * inc_user_info: 0|1
622
+		 * update_email: 0, 1, 2
623
+		 *
624
+		 * Old autoresponder settings format:
625
+		 * auto_responder: 0|1
626
+		 * ar_email_message: string or ''
627
+		 * ar_email_to: field id
628
+		 * ar_plain_text: 0|1
629
+		 * ar_reply_to_name: string
630
+		 * ar_reply_to: string
631
+		 * ar_email_subject: string
632
+		 * ar_update_email: 0, 1, 2
633
+		 *
634
+		 * New email settings:
635
+		 * post_content: json settings
636
+		 * post_title: form id
637
+		 * post_excerpt: message
638
+		 *
639
+		 */
640
+
641
+		foreach ( $forms as $form ) {
642 642
 			if ( $form->is_template && $form->default_template ) {
643 643
 				// don't migrate the default templates since the email will be added anyway
644 644
 				continue;
645 645
 			}
646 646
 
647
-            // Format form options
648
-            $form_options = maybe_unserialize($form->options);
647
+			// Format form options
648
+			$form_options = maybe_unserialize($form->options);
649 649
 
650
-            // Migrate settings to actions
651
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
652
-        }
653
-    }
650
+			// Migrate settings to actions
651
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
652
+		}
653
+	}
654 654
 
655
-    private function migrate_to_11() {
656
-        global $wpdb;
655
+	private function migrate_to_11() {
656
+		global $wpdb;
657 657
 
658
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
658
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
659 659
 
660
-        $sending = __( 'Sending', 'formidable' );
660
+		$sending = __( 'Sending', 'formidable' );
661 661
 		$img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
662
-        $old_default_html = <<<DEFAULT_HTML
662
+		$old_default_html = <<<DEFAULT_HTML
663 663
 <div class="frm_submit">
664 664
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
665 665
 <input type="submit" value="[button_label]" [button_action] />
666 666
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
667 667
 </div>
668 668
 DEFAULT_HTML;
669
-        unset($sending, $img);
669
+		unset($sending, $img);
670 670
 
671
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
672
-        $draft_link = FrmFormsHelper::get_draft_link();
671
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
672
+		$draft_link = FrmFormsHelper::get_draft_link();
673 673
 		foreach ( $forms as $form ) {
674
-            $form->options = maybe_unserialize($form->options);
675
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
676
-                continue;
677
-            }
674
+			$form->options = maybe_unserialize($form->options);
675
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
676
+				continue;
677
+			}
678 678
 
679
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
680
-                $form->options['submit_html'] = $new_default_html;
679
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
680
+				$form->options['submit_html'] = $new_default_html;
681 681
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
682 682
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
683 683
 				$form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
684 684
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
685
-            }
686
-            unset($form);
687
-        }
688
-        unset($forms);
689
-    }
685
+			}
686
+			unset($form);
687
+		}
688
+		unset($forms);
689
+	}
690 690
 
691
-    private function migrate_to_6() {
692
-        global $wpdb;
691
+	private function migrate_to_6() {
692
+		global $wpdb;
693 693
 
694 694
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
695 695
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
696 696
 
697
-        $default_html = <<<DEFAULT_HTML
697
+		$default_html = <<<DEFAULT_HTML
698 698
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
699 699
     <label class="frm_pos_[label_position]">[field_name]
700 700
         <span class="frm_required">[required_label]</span>
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 </div>
705 705
 DEFAULT_HTML;
706 706
 
707
-        $old_default_html = <<<DEFAULT_HTML
707
+		$old_default_html = <<<DEFAULT_HTML
708 708
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
709 709
     <label class="frm_pos_[label_position]">[field_name]
710 710
         <span class="frm_required">[required_label]</span>
@@ -714,23 +714,23 @@  discard block
 block discarded – undo
714 714
 </div>
715 715
 DEFAULT_HTML;
716 716
 
717
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
718
-        foreach ( $fields as $field ) {
719
-            $field->field_options = maybe_unserialize($field->field_options);
717
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
718
+		foreach ( $fields as $field ) {
719
+			$field->field_options = maybe_unserialize($field->field_options);
720 720
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
721
-                $field->field_options['custom_html'] = $new_default_html;
721
+				$field->field_options['custom_html'] = $new_default_html;
722 722
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
723
-            }
724
-            unset($field);
725
-        }
726
-        unset($default_html, $old_default_html, $fields);
727
-    }
728
-
729
-    private function migrate_to_4() {
730
-        global $wpdb;
723
+			}
724
+			unset($field);
725
+		}
726
+		unset($default_html, $old_default_html, $fields);
727
+	}
728
+
729
+	private function migrate_to_4() {
730
+		global $wpdb;
731 731
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
732
-        foreach ( $user_ids as $user_id ) {
732
+		foreach ( $user_ids as $user_id ) {
733 733
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
734
-        }
735
-    }
734
+		}
735
+	}
736 736
 }
Please login to merge, or discard this patch.