Completed
Push — master ( dc9c9f...dbaa47 )
by Jamie
03:10
created
classes/models/FrmForm.php 2 patches
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -1,387 +1,387 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
3
+	die('You are not allowed to call this page directly.');
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14
-        $new_values = array(
14
+		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
-            'name'          => $values['name'],
17
-            'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
16
+			'name'          => $values['name'],
17
+			'description'   => $values['description'],
18
+			'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
+			'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
+			'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
-        );
22
+			'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
+			'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
+			'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
+		);
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
+		$options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
35
+		$new_values['options'] = serialize($options);
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
73
-
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
83
-
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
86
-        }
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70
+			'created_at'    => current_time('mysql', 1),
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73
+
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76
+			$new_options = maybe_unserialize($values->options);
77
+			$new_options['email_to'] = get_option('admin_email');
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83
+
84
+		if ( is_array($new_values['options']) ) {
85
+			$new_values['options'] = serialize($new_values['options']);
86
+		}
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
+			$form_id = $wpdb->insert_id;
95
+			FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106
-        $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+		$new_opts = $values['options'] = maybe_unserialize($values['options']);
107 107
 
108
-        if ( isset($new_opts['success_msg']) ) {
109
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
-        }
108
+		if ( isset($new_opts['success_msg']) ) {
109
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
+		}
111 111
 
112
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113 113
 
114
-        if ( $new_opts != $values['options'] ) {
115
-            global $wpdb;
114
+		if ( $new_opts != $values['options'] ) {
115
+			global $wpdb;
116 116
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
117
-        }
118
-    }
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * @return int|boolean
122
-     */
123
-    public static function update( $id, $values, $create_link = false ) {
124
-        global $wpdb;
120
+	/**
121
+	 * @return int|boolean
122
+	 */
123
+	public static function update( $id, $values, $create_link = false ) {
124
+		global $wpdb;
125 125
 
126
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
-            $values['status'] = 'published';
128
-        }
126
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
+			$values['status'] = 'published';
128
+		}
129 129
 
130
-        if ( isset($values['form_key']) ) {
130
+		if ( isset($values['form_key']) ) {
131 131
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
132
-        }
132
+		}
133 133
 
134
-        $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
134
+		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135 135
 
136
-        $new_values = self::set_update_options( array(), $values);
136
+		$new_values = self::set_update_options( array(), $values);
137 137
 
138
-        foreach ( $values as $value_key => $value ) {
138
+		foreach ( $values as $value_key => $value ) {
139 139
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
140 140
 				$new_values[ $value_key ] = $value;
141
-            }
142
-        }
141
+			}
142
+		}
143 143
 
144
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
-            $new_values['status'] = $values['new_status'];
146
-        }
144
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
+			$new_values['status'] = $values['new_status'];
146
+		}
147 147
 
148
-        if ( ! empty( $new_values ) ) {
148
+		if ( ! empty( $new_values ) ) {
149 149
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
150
-            if ( $query_results ) {
150
+			if ( $query_results ) {
151 151
 				self::clear_form_cache();
152
-            }
153
-        } else {
154
-            $query_results = true;
155
-        }
156
-        unset($new_values);
152
+			}
153
+		} else {
154
+			$query_results = true;
155
+		}
156
+		unset($new_values);
157 157
 
158
-        $values = self::update_fields($id, $values);
158
+		$values = self::update_fields($id, $values);
159 159
 
160 160
 		do_action( 'frm_update_form', $id, $values );
161 161
 		do_action( 'frm_update_form_' . $id, $values );
162 162
 
163
-        return $query_results;
164
-    }
163
+		return $query_results;
164
+	}
165 165
 
166
-    /**
167
-     * @return array
168
-     */
166
+	/**
167
+	 * @return array
168
+	 */
169 169
 	public static function set_update_options( $new_values, $values ) {
170
-        if ( ! isset($values['options']) ) {
171
-            return $new_values;
172
-        }
170
+		if ( ! isset($values['options']) ) {
171
+			return $new_values;
172
+		}
173 173
 
174 174
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
175 175
 		FrmFormsHelper::fill_form_options( $options, $values );
176 176
 
177
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
177
+		$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
+		$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
181 181
 
182
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
183
-        $new_values['options'] = serialize($options);
182
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
183
+		$new_values['options'] = serialize($options);
184 184
 
185
-        return $new_values;
186
-    }
185
+		return $new_values;
186
+	}
187 187
 
188 188
 
189
-    /**
190
-     * @return array
191
-     */
189
+	/**
190
+	 * @return array
191
+	 */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
-            return $values;
196
-        }
194
+		if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+			return $values;
196
+		}
197 197
 
198
-        $all_fields = FrmField::get_all_for_form($id);
199
-        if ( empty($all_fields) ) {
200
-            return $values;
201
-        }
198
+		$all_fields = FrmField::get_all_for_form($id);
199
+		if ( empty($all_fields) ) {
200
+			return $values;
201
+		}
202 202
 
203
-        if ( ! isset($values['item_meta']) ) {
204
-            $values['item_meta'] = array();
205
-        }
203
+		if ( ! isset($values['item_meta']) ) {
204
+			$values['item_meta'] = array();
205
+		}
206 206
 
207
-        $field_array = array();
208
-        $existing_keys = array_keys($values['item_meta']);
209
-        foreach ( $all_fields as $fid ) {
210
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
207
+		$field_array = array();
208
+		$existing_keys = array_keys($values['item_meta']);
209
+		foreach ( $all_fields as $fid ) {
210
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
211 211
 				$values['item_meta'][ $fid->id ] = '';
212
-            }
212
+			}
213 213
 			$field_array[ $fid->id ] = $fid;
214
-        }
215
-        unset($all_fields);
214
+		}
215
+		unset($all_fields);
216 216
 
217
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
217
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
218 218
 			if ( isset( $field_array[ $field_id ] ) ) {
219 219
 				$field = $field_array[ $field_id ];
220
-            } else {
221
-                $field = FrmField::getOne($field_id);
222
-            }
220
+			} else {
221
+				$field = FrmField::getOne($field_id);
222
+			}
223 223
 
224
-            if ( ! $field ) {
225
-                continue;
226
-            }
224
+			if ( ! $field ) {
225
+				continue;
226
+			}
227 227
 
228 228
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229 229
 			if ( $is_settings_page ) {
230
-                //updating the settings page
230
+				//updating the settings page
231 231
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
232 232
 					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
233
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
234 234
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
235
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236
-                    $prev_opts = $field->field_options;
237
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
-                    if ( $prev_opts != $field->field_options ) {
235
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236
+					$prev_opts = $field->field_options;
237
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
+					if ( $prev_opts != $field->field_options ) {
239 239
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
240
-                    }
241
-                    unset($prev_opts);
242
-                }
243
-            }
240
+					}
241
+					unset($prev_opts);
242
+				}
243
+			}
244 244
 
245 245
 			if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) {
246
-                continue;
247
-            }
246
+				continue;
247
+			}
248 248
 
249
-            //updating the form
249
+			//updating the form
250 250
 			$update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true );
251 251
 			unset( $update_options['custom_html'] ); // don't check for POST html
252 252
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
253 253
 
254 254
 			foreach ( $update_options as $opt => $default ) {
255 255
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
256
-            }
256
+			}
257 257
 
258
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
258
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259 259
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
260 260
 			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
261 261
 			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
262 262
 			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
263 263
 			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
264 264
 
265
-            FrmField::update($field_id, array(
266
-                'field_key' => $field_key, 'type' => $field_type,
267
-                'default_value' => $default_value, 'field_options' => $field->field_options,
268
-                'description' => $field_description, 'required' => $required,
269
-            ) );
265
+			FrmField::update($field_id, array(
266
+				'field_key' => $field_key, 'type' => $field_type,
267
+				'default_value' => $default_value, 'field_options' => $field->field_options,
268
+				'description' => $field_description, 'required' => $required,
269
+			) );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
272
-        }
271
+			FrmField::delete_form_transient($field->form_id);
272
+		}
273 273
 		self::clear_form_cache();
274 274
 
275
-        return $values;
276
-    }
275
+		return $values;
276
+	}
277 277
 
278
-    /**
279
-     * @param string $status
280
-     * @return int|boolean
281
-     */
278
+	/**
279
+	 * @param string $status
280
+	 * @return int|boolean
281
+	 */
282 282
 	public static function set_status( $id, $status ) {
283
-        if ( 'trash' == $status ) {
284
-            return self::trash($id);
285
-        }
283
+		if ( 'trash' == $status ) {
284
+			return self::trash($id);
285
+		}
286 286
 
287 287
 		$statuses  = array( 'published', 'draft', 'trash' );
288
-        if ( ! in_array( $status, $statuses ) ) {
289
-            return false;
290
-        }
288
+		if ( ! in_array( $status, $statuses ) ) {
289
+			return false;
290
+		}
291 291
 
292
-        global $wpdb;
292
+		global $wpdb;
293 293
 
294
-        if ( is_array($id) ) {
294
+		if ( is_array($id) ) {
295 295
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
296 296
 			FrmDb::get_where_clause_and_values( $where );
297 297
 			array_unshift( $where['values'], $status );
298 298
 
299 299
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
300
-        } else {
300
+		} else {
301 301
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
302 302
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
303
-        }
303
+		}
304 304
 
305
-        if ( $query_results ) {
305
+		if ( $query_results ) {
306 306
 			self::clear_form_cache();
307
-        }
307
+		}
308 308
 
309
-        return $query_results;
310
-    }
309
+		return $query_results;
310
+	}
311 311
 
312
-    /**
313
-     * @return int|boolean
314
-     */
312
+	/**
313
+	 * @return int|boolean
314
+	 */
315 315
 	public static function trash( $id ) {
316
-        if ( ! EMPTY_TRASH_DAYS ) {
317
-            return self::destroy( $id );
318
-        }
316
+		if ( ! EMPTY_TRASH_DAYS ) {
317
+			return self::destroy( $id );
318
+		}
319 319
 
320
-        $form = self::getOne($id);
321
-        if ( ! $form ) {
322
-            return false;
323
-        }
320
+		$form = self::getOne($id);
321
+		if ( ! $form ) {
322
+			return false;
323
+		}
324 324
 
325
-        $options = $form->options;
326
-        $options['trash_time'] = time();
325
+		$options = $form->options;
326
+		$options['trash_time'] = time();
327 327
 
328
-        global $wpdb;
329
-        $query_results = $wpdb->update(
328
+		global $wpdb;
329
+		$query_results = $wpdb->update(
330 330
 			$wpdb->prefix . 'frm_forms',
331 331
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
332 332
 			array( 'id' => $id )
333
-        );
333
+		);
334 334
 
335
-        $wpdb->update(
335
+		$wpdb->update(
336 336
 			$wpdb->prefix . 'frm_forms',
337 337
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
338 338
 			array( 'parent_form_id' => $id )
339
-        );
339
+		);
340 340
 
341
-        if ( $query_results ) {
341
+		if ( $query_results ) {
342 342
 			self::clear_form_cache();
343
-        }
343
+		}
344 344
 
345
-        return $query_results;
346
-    }
345
+		return $query_results;
346
+	}
347 347
 
348
-    /**
349
-     * @return int|boolean
350
-     */
348
+	/**
349
+	 * @return int|boolean
350
+	 */
351 351
 	public static function destroy( $id ) {
352
-        global $wpdb;
352
+		global $wpdb;
353 353
 
354
-        $form = self::getOne($id);
355
-        if ( ! $form ) {
356
-            return false;
357
-        }
354
+		$form = self::getOne($id);
355
+		if ( ! $form ) {
356
+			return false;
357
+		}
358 358
 		$id = $form->id;
359 359
 
360
-        // Disconnect the entries from this form
360
+		// Disconnect the entries from this form
361 361
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
362
-        foreach ( $entries as $entry_id ) {
363
-            FrmEntry::destroy($entry_id);
364
-            unset($entry_id);
365
-        }
362
+		foreach ( $entries as $entry_id ) {
363
+			FrmEntry::destroy($entry_id);
364
+			unset($entry_id);
365
+		}
366 366
 
367
-        // Disconnect the fields from this form
367
+		// Disconnect the fields from this form
368 368
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
369 369
 
370 370
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
371
-        if ( $query_results ) {
372
-            // Delete all form actions linked to this form
373
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
374
-            $action_control->destroy($id, 'all');
371
+		if ( $query_results ) {
372
+			// Delete all form actions linked to this form
373
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
374
+			$action_control->destroy($id, 'all');
375 375
 
376 376
 			// Clear form caching
377 377
 			self::clear_form_cache();
378 378
 
379 379
 			do_action( 'frm_destroy_form', $id );
380 380
 			do_action( 'frm_destroy_form_' . $id );
381
-        }
381
+		}
382 382
 
383
-        return $query_results;
384
-    }
383
+		return $query_results;
384
+	}
385 385
 
386 386
 	/**
387 387
 	 * Delete trashed forms based on how long they have been trashed
@@ -413,49 +413,49 @@  discard block
 block discarded – undo
413 413
 		return $count;
414 414
 	}
415 415
 
416
-    /**
417
-     * @return string form name
418
-     */
419
-    public static function &getName( $id ) {
420
-        global $wpdb;
421
-
422
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
423
-        if ( $form ) {
424
-            $r = stripslashes($form->name);
425
-            return $r;
426
-        }
427
-
428
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
429
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
-        $r = stripslashes($r);
431
-
432
-        return $r;
433
-    }
434
-
435
-    /**
436
-     * @param string $key
437
-     * @return int form id
438
-     */
416
+	/**
417
+	 * @return string form name
418
+	 */
419
+	public static function &getName( $id ) {
420
+		global $wpdb;
421
+
422
+		$form = FrmAppHelper::check_cache($id, 'frm_form');
423
+		if ( $form ) {
424
+			$r = stripslashes($form->name);
425
+			return $r;
426
+		}
427
+
428
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
429
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
+		$r = stripslashes($r);
431
+
432
+		return $r;
433
+	}
434
+
435
+	/**
436
+	 * @param string $key
437
+	 * @return int form id
438
+	 */
439 439
 	public static function &getIdByKey( $key ) {
440
-        $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
441
-        return $id;
442
-    }
443
-
444
-    /**
445
-     * @param int $id
446
-     * @return string form key
447
-     */
440
+		$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
441
+		return $id;
442
+	}
443
+
444
+	/**
445
+	 * @param int $id
446
+	 * @return string form key
447
+	 */
448 448
 	public static function &getKeyById( $id ) {
449
-        $id = (int) $id;
450
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
451
-        if ( $cache ) {
452
-            return $cache->form_key;
453
-        }
449
+		$id = (int) $id;
450
+		$cache = FrmAppHelper::check_cache($id, 'frm_form');
451
+		if ( $cache ) {
452
+			return $cache->form_key;
453
+		}
454 454
 
455
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
455
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
456 456
 
457
-        return $key;
458
-    }
457
+		return $key;
458
+	}
459 459
 
460 460
 	/**
461 461
 	 * If $form is numeric, get the form object
@@ -468,47 +468,47 @@  discard block
 block discarded – undo
468 468
 		}
469 469
 	}
470 470
 
471
-    /**
472
-     * @return object form
473
-     */
474
-    public static function getOne( $id, $blog_id = false ) {
475
-        global $wpdb;
471
+	/**
472
+	 * @return object form
473
+	 */
474
+	public static function getOne( $id, $blog_id = false ) {
475
+		global $wpdb;
476 476
 
477
-        if ( $blog_id && is_multisite() ) {
478
-            global $wpmuBaseTablePrefix;
477
+		if ( $blog_id && is_multisite() ) {
478
+			global $wpmuBaseTablePrefix;
479 479
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
480 480
 
481 481
 			$table_name = $prefix . 'frm_forms';
482
-        } else {
482
+		} else {
483 483
 			$table_name = $wpdb->prefix . 'frm_forms';
484
-            $cache = wp_cache_get($id, 'frm_form');
485
-            if ( $cache ) {
486
-                if ( isset($cache->options) ) {
487
-                    $cache->options = maybe_unserialize($cache->options);
488
-                }
484
+			$cache = wp_cache_get($id, 'frm_form');
485
+			if ( $cache ) {
486
+				if ( isset($cache->options) ) {
487
+					$cache->options = maybe_unserialize($cache->options);
488
+				}
489 489
 
490
-                return stripslashes_deep($cache);
491
-            }
492
-        }
490
+				return stripslashes_deep($cache);
491
+			}
492
+		}
493 493
 
494
-        if ( is_numeric($id) ) {
495
-            $where = array( 'id' => $id );
496
-        } else {
497
-            $where = array( 'form_key' => $id );
498
-        }
494
+		if ( is_numeric($id) ) {
495
+			$where = array( 'id' => $id );
496
+		} else {
497
+			$where = array( 'form_key' => $id );
498
+		}
499 499
 
500
-        $results = FrmDb::get_row( $table_name, $where );
500
+		$results = FrmDb::get_row( $table_name, $where );
501 501
 
502
-        if ( isset($results->options) ) {
502
+		if ( isset($results->options) ) {
503 503
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
504
-            $results->options = maybe_unserialize($results->options);
505
-        }
506
-        return stripslashes_deep($results);
507
-    }
508
-
509
-    /**
510
-     * @return object|array of objects
511
-     */
504
+			$results->options = maybe_unserialize($results->options);
505
+		}
506
+		return stripslashes_deep($results);
507
+	}
508
+
509
+	/**
510
+	 * @return object|array of objects
511
+	 */
512 512
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
513 513
 		if ( is_array( $where ) && ! empty( $where ) ) {
514 514
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 			$results = reset( $results );
533 533
 		}
534 534
 
535
-        return stripslashes_deep($results);
536
-    }
535
+		return stripslashes_deep($results);
536
+	}
537 537
 
538 538
 	/**
539 539
 	 * Get all published forms
@@ -551,47 +551,47 @@  discard block
 block discarded – undo
551 551
 		return $forms;
552 552
 	}
553 553
 
554
-    /**
555
-     * @return int count of forms
556
-     */
557
-    public static function &get_count() {
558
-    	global $wpdb;
554
+	/**
555
+	 * @return int count of forms
556
+	 */
557
+	public static function &get_count() {
558
+		global $wpdb;
559 559
 
560
-    	$cache_key = 'frm_form_counts';
560
+		$cache_key = 'frm_form_counts';
561 561
 
562
-    	$counts = wp_cache_get( $cache_key, 'frm_form' );
563
-    	if ( false !== $counts ) {
564
-    	    return $counts;
565
-    	}
562
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
563
+		if ( false !== $counts ) {
564
+			return $counts;
565
+		}
566 566
 
567
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
567
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
568 568
 
569 569
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
570
-    	$counts = array_fill_keys( $statuses, 0 );
570
+		$counts = array_fill_keys( $statuses, 0 );
571 571
 
572
-    	foreach ( $results as $row ) {
573
-            if ( 'trash' != $row->status ) {
574
-    	        if ( $row->is_template ) {
572
+		foreach ( $results as $row ) {
573
+			if ( 'trash' != $row->status ) {
574
+				if ( $row->is_template ) {
575 575
 					$counts['template']++;
576
-    	        } else {
576
+				} else {
577 577
 					$counts['published']++;
578
-    	        }
579
-    	    } else {
578
+				}
579
+			} else {
580 580
 				$counts['trash']++;
581
-        	}
581
+			}
582 582
 
583
-    	    if ( 'draft' == $row->status ) {
583
+			if ( 'draft' == $row->status ) {
584 584
 				$counts['draft']++;
585
-    	    }
585
+			}
586 586
 
587
-    		unset($row);
588
-    	}
587
+			unset($row);
588
+		}
589 589
 
590
-    	$counts = (object) $counts;
590
+		$counts = (object) $counts;
591 591
 		FrmAppHelper::set_cache( $cache_key, $counts, 'frm_form' );
592 592
 
593
-    	return $counts;
594
-    }
593
+		return $counts;
594
+	}
595 595
 
596 596
 	/**
597 597
 	 * Clear form caching
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 		FrmAppHelper::cache_delete_group( 'frm_form' );
605 605
 	}
606 606
 
607
-    /**
608
-     * @return array of errors
609
-     */
607
+	/**
608
+	 * @return array of errors
609
+	 */
610 610
 	public static function validate( $values ) {
611
-        $errors = array();
611
+		$errors = array();
612 612
 
613
-        return apply_filters('frm_validate_form', $errors, $values);
614
-    }
613
+		return apply_filters('frm_validate_form', $errors, $values);
614
+	}
615 615
 
616 616
 	public static function get_params( $form = null ) {
617 617
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16 16
             'name'          => $values['name'],
17 17
             'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
18
+            'status'        => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+            'logged_in'     => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+            'is_template'   => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
22
+            'editable'      => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+            'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0,
24
+            'created_at'    => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
25 25
         );
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
31
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
32
+        $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
35
+        $new_values['options'] = serialize( $options );
36 36
 
37 37
         //if(isset($values['id']) && is_numeric($values['id']))
38 38
         //    $new_values['id'] = $values['id'];
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
             'status'        => $template ? 'published' : 'draft',
68 68
             'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69 69
             'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
70
+            'created_at'    => current_time( 'mysql', 1 ),
71 71
             'is_template'   => $template ? 1 : 0,
72 72
         );
73 73
 
74 74
         if ( $blog_id ) {
75 75
             $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
76
+            $new_options = maybe_unserialize( $values->options );
77
+            $new_options['email_to'] = get_option( 'admin_email' );
78 78
             $new_options['copy'] = false;
79 79
             $new_values['options'] = $new_options;
80 80
         } else {
81 81
             $new_values['options'] = $values->options;
82 82
         }
83 83
 
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
84
+        if ( is_array( $new_values['options'] ) ) {
85
+            $new_values['options'] = serialize( $new_values['options'] );
86 86
         }
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			self::clear_form_cache();
93 93
 
94 94
             $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+            FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97 97
             // update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
     }
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106
-        $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+        $new_opts = $values['options'] = maybe_unserialize( $values['options'] );
107 107
 
108
-        if ( isset($new_opts['success_msg']) ) {
109
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
108
+        if ( isset( $new_opts['success_msg'] ) ) {
109
+            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] );
110 110
         }
111 111
 
112
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+        $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
113 113
 
114 114
         if ( $new_opts != $values['options'] ) {
115 115
             global $wpdb;
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
             $values['status'] = 'published';
128 128
         }
129 129
 
130
-        if ( isset($values['form_key']) ) {
130
+        if ( isset( $values['form_key'] ) ) {
131 131
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
132 132
         }
133 133
 
134 134
         $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135 135
 
136
-        $new_values = self::set_update_options( array(), $values);
136
+        $new_values = self::set_update_options( array(), $values );
137 137
 
138 138
         foreach ( $values as $value_key => $value ) {
139 139
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
140
-				$new_values[ $value_key ] = $value;
140
+				$new_values[$value_key] = $value;
141 141
             }
142 142
         }
143 143
 
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
         } else {
154 154
             $query_results = true;
155 155
         }
156
-        unset($new_values);
156
+        unset( $new_values );
157 157
 
158
-        $values = self::update_fields($id, $values);
158
+        $values = self::update_fields( $id, $values );
159 159
 
160 160
 		do_action( 'frm_update_form', $id, $values );
161 161
 		do_action( 'frm_update_form_' . $id, $values );
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
      * @return array
168 168
      */
169 169
 	public static function set_update_options( $new_values, $values ) {
170
-        if ( ! isset($values['options']) ) {
170
+        if ( ! isset( $values['options'] ) ) {
171 171
             return $new_values;
172 172
         }
173 173
 
174 174
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
175 175
 		FrmFormsHelper::fill_form_options( $options, $values );
176 176
 
177
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
177
+        $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
178
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
179
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
180
+        $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
181 181
 
182
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
183
-        $new_values['options'] = serialize($options);
182
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
183
+        $new_values['options'] = serialize( $options );
184 184
 
185 185
         return $new_values;
186 186
     }
@@ -191,54 +191,54 @@  discard block
 block discarded – undo
191 191
      */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
194
+        if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
195 195
             return $values;
196 196
         }
197 197
 
198
-        $all_fields = FrmField::get_all_for_form($id);
199
-        if ( empty($all_fields) ) {
198
+        $all_fields = FrmField::get_all_for_form( $id );
199
+        if ( empty( $all_fields ) ) {
200 200
             return $values;
201 201
         }
202 202
 
203
-        if ( ! isset($values['item_meta']) ) {
203
+        if ( ! isset( $values['item_meta'] ) ) {
204 204
             $values['item_meta'] = array();
205 205
         }
206 206
 
207 207
         $field_array = array();
208
-        $existing_keys = array_keys($values['item_meta']);
208
+        $existing_keys = array_keys( $values['item_meta'] );
209 209
         foreach ( $all_fields as $fid ) {
210
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
211
-				$values['item_meta'][ $fid->id ] = '';
210
+            if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
211
+				$values['item_meta'][$fid->id] = '';
212 212
             }
213
-			$field_array[ $fid->id ] = $fid;
213
+			$field_array[$fid->id] = $fid;
214 214
         }
215
-        unset($all_fields);
215
+        unset( $all_fields );
216 216
 
217 217
         foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
-			if ( isset( $field_array[ $field_id ] ) ) {
219
-				$field = $field_array[ $field_id ];
218
+			if ( isset( $field_array[$field_id] ) ) {
219
+				$field = $field_array[$field_id];
220 220
             } else {
221
-                $field = FrmField::getOne($field_id);
221
+                $field = FrmField::getOne( $field_id );
222 222
             }
223 223
 
224 224
             if ( ! $field ) {
225 225
                 continue;
226 226
             }
227 227
 
228
-			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
228
+			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) );
229 229
 			if ( $is_settings_page ) {
230 230
                 //updating the settings page
231
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
232
-					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
231
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
232
+					$field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
234 234
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
235 235
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236 236
                     $prev_opts = $field->field_options;
237
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
238 238
                     if ( $prev_opts != $field->field_options ) {
239 239
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
240 240
                     }
241
-                    unset($prev_opts);
241
+                    unset( $prev_opts );
242 242
                 }
243 243
             }
244 244
 
@@ -252,23 +252,23 @@  discard block
 block discarded – undo
252 252
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
253 253
 
254 254
 			foreach ( $update_options as $opt => $default ) {
255
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
255
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default;
256 256
             }
257 257
 
258
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
260
-			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
261
-			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
262
-			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
263
-			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
258
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
259
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
260
+			$field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key;
261
+			$required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false;
262
+			$field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type;
263
+			$field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description;
264 264
 
265
-            FrmField::update($field_id, array(
265
+            FrmField::update( $field_id, array(
266 266
                 'field_key' => $field_key, 'type' => $field_type,
267 267
                 'default_value' => $default_value, 'field_options' => $field->field_options,
268 268
                 'description' => $field_description, 'required' => $required,
269 269
             ) );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
271
+            FrmField::delete_form_transient( $field->form_id );
272 272
         }
273 273
 		self::clear_form_cache();
274 274
 
@@ -281,17 +281,17 @@  discard block
 block discarded – undo
281 281
      */
282 282
 	public static function set_status( $id, $status ) {
283 283
         if ( 'trash' == $status ) {
284
-            return self::trash($id);
284
+            return self::trash( $id );
285 285
         }
286 286
 
287
-		$statuses  = array( 'published', 'draft', 'trash' );
287
+		$statuses = array( 'published', 'draft', 'trash' );
288 288
         if ( ! in_array( $status, $statuses ) ) {
289 289
             return false;
290 290
         }
291 291
 
292 292
         global $wpdb;
293 293
 
294
-        if ( is_array($id) ) {
294
+        if ( is_array( $id ) ) {
295 295
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
296 296
 			FrmDb::get_where_clause_and_values( $where );
297 297
 			array_unshift( $where['values'], $status );
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             return self::destroy( $id );
318 318
         }
319 319
 
320
-        $form = self::getOne($id);
320
+        $form = self::getOne( $id );
321 321
         if ( ! $form ) {
322 322
             return false;
323 323
         }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	public static function destroy( $id ) {
352 352
         global $wpdb;
353 353
 
354
-        $form = self::getOne($id);
354
+        $form = self::getOne( $id );
355 355
         if ( ! $form ) {
356 356
             return false;
357 357
         }
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
         // Disconnect the entries from this form
361 361
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
362 362
         foreach ( $entries as $entry_id ) {
363
-            FrmEntry::destroy($entry_id);
364
-            unset($entry_id);
363
+            FrmEntry::destroy( $entry_id );
364
+            unset( $entry_id );
365 365
         }
366 366
 
367 367
         // Disconnect the fields from this form
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         if ( $query_results ) {
372 372
             // Delete all form actions linked to this form
373 373
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
374
-            $action_control->destroy($id, 'all');
374
+            $action_control->destroy( $id, 'all' );
375 375
 
376 376
 			// Clear form caching
377 377
 			self::clear_form_cache();
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 			$form->options = maybe_unserialize( $form->options );
406 406
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
407 407
 				self::destroy( $form->id );
408
-				$count++;
408
+				$count ++;
409 409
 			}
410 410
 
411 411
 			unset( $form );
@@ -419,15 +419,15 @@  discard block
 block discarded – undo
419 419
     public static function &getName( $id ) {
420 420
         global $wpdb;
421 421
 
422
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
422
+        $form = FrmAppHelper::check_cache( $id, 'frm_form' );
423 423
         if ( $form ) {
424
-            $r = stripslashes($form->name);
424
+            $r = stripslashes( $form->name );
425 425
             return $r;
426 426
         }
427 427
 
428 428
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
429 429
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
-        $r = stripslashes($r);
430
+        $r = stripslashes( $r );
431 431
 
432 432
         return $r;
433 433
     }
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
      */
448 448
 	public static function &getKeyById( $id ) {
449 449
         $id = (int) $id;
450
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
450
+        $cache = FrmAppHelper::check_cache( $id, 'frm_form' );
451 451
         if ( $cache ) {
452 452
             return $cache->form_key;
453 453
         }
@@ -481,17 +481,17 @@  discard block
 block discarded – undo
481 481
 			$table_name = $prefix . 'frm_forms';
482 482
         } else {
483 483
 			$table_name = $wpdb->prefix . 'frm_forms';
484
-            $cache = wp_cache_get($id, 'frm_form');
484
+            $cache = wp_cache_get( $id, 'frm_form' );
485 485
             if ( $cache ) {
486
-                if ( isset($cache->options) ) {
487
-                    $cache->options = maybe_unserialize($cache->options);
486
+                if ( isset( $cache->options ) ) {
487
+                    $cache->options = maybe_unserialize( $cache->options );
488 488
                 }
489 489
 
490
-                return stripslashes_deep($cache);
490
+                return stripslashes_deep( $cache );
491 491
             }
492 492
         }
493 493
 
494
-        if ( is_numeric($id) ) {
494
+        if ( is_numeric( $id ) ) {
495 495
             $where = array( 'id' => $id );
496 496
         } else {
497 497
             $where = array( 'form_key' => $id );
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
 
500 500
         $results = FrmDb::get_row( $table_name, $where );
501 501
 
502
-        if ( isset($results->options) ) {
502
+        if ( isset( $results->options ) ) {
503 503
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
504
-            $results->options = maybe_unserialize($results->options);
504
+            $results->options = maybe_unserialize( $results->options );
505 505
         }
506
-        return stripslashes_deep($results);
506
+        return stripslashes_deep( $results );
507 507
     }
508 508
 
509 509
     /**
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 			$results = reset( $results );
533 533
 		}
534 534
 
535
-        return stripslashes_deep($results);
535
+        return stripslashes_deep( $results );
536 536
     }
537 537
 
538 538
 	/**
@@ -572,19 +572,19 @@  discard block
 block discarded – undo
572 572
     	foreach ( $results as $row ) {
573 573
             if ( 'trash' != $row->status ) {
574 574
     	        if ( $row->is_template ) {
575
-					$counts['template']++;
575
+					$counts['template'] ++;
576 576
     	        } else {
577
-					$counts['published']++;
577
+					$counts['published'] ++;
578 578
     	        }
579 579
     	    } else {
580
-				$counts['trash']++;
580
+				$counts['trash'] ++;
581 581
         	}
582 582
 
583 583
     	    if ( 'draft' == $row->status ) {
584
-				$counts['draft']++;
584
+				$counts['draft'] ++;
585 585
     	    }
586 586
 
587
-    		unset($row);
587
+    		unset( $row );
588 588
     	}
589 589
 
590 590
     	$counts = (object) $counts;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 	public static function validate( $values ) {
611 611
         $errors = array();
612 612
 
613
-        return apply_filters('frm_validate_form', $errors, $values);
613
+        return apply_filters( 'frm_validate_form', $errors, $values );
614 614
     }
615 615
 
616 616
 	public static function get_params( $form = null ) {
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
 			self::maybe_get_form( $form );
623 623
 		}
624 624
 
625
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
626
-			return $frm_vars['form_params'][ $form->id ];
625
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
626
+			return $frm_vars['form_params'][$form->id];
627 627
 		}
628 628
 
629
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
629
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
630 630
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
631 631
 
632 632
 		$default_values = array(
@@ -644,15 +644,15 @@  discard block
 block discarded – undo
644 644
 			//if there are two forms on the same page, make sure not to submit both
645 645
 			foreach ( $default_values as $var => $default ) {
646 646
 				if ( $var == 'action' ) {
647
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
647
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
648 648
 				} else {
649
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default );
649
+					$values[$var] = FrmAppHelper::get_param( $var, $default );
650 650
 				}
651 651
 				unset( $var, $default );
652 652
 			}
653 653
 		} else {
654 654
 			foreach ( $default_values as $var => $default ) {
655
-				$values[ $var ] = $default;
655
+				$values[$var] = $default;
656 656
 				unset( $var, $default );
657 657
 			}
658 658
 		}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 	public static function list_page_params() {
668 668
 		$values = array();
669 669
 		foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
670
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
670
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
671 671
 		}
672 672
 
673 673
 		return $values;
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
688 688
 			'keep_post' => '',
689 689
 		) as $var => $default ) {
690
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
690
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
691 691
 		}
692 692
 
693 693
 		return $values;
@@ -729,16 +729,16 @@  discard block
 block discarded – undo
729 729
 		$small_form = new stdClass();
730 730
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
731 731
 			$small_form->{$var} = $form->{$var};
732
-			unset($var);
732
+			unset( $var );
733 733
 		}
734 734
 
735 735
 		$frm_vars['forms_loaded'][] = $small_form;
736 736
 
737
-		if ( $this_load && empty($global_load) ) {
737
+		if ( $this_load && empty( $global_load ) ) {
738 738
 			$global_load = $frm_vars['load_css'] = true;
739 739
 		}
740 740
 
741
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
741
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
742 742
 	}
743 743
 
744 744
 	public static function show_submit( $form ) {
Please login to merge, or discard this patch.
classes/models/FrmNotification.php 2 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -2,128 +2,128 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmNotification {
4 4
 	public function __construct() {
5
-        if ( ! defined('ABSPATH') ) {
6
-            die('You are not allowed to call this page directly.');
7
-        }
8
-        add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
9
-    }
5
+		if ( ! defined('ABSPATH') ) {
6
+			die('You are not allowed to call this page directly.');
7
+		}
8
+		add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
9
+	}
10 10
 
11 11
 	public static function trigger_email( $action, $entry, $form ) {
12
-        $notification = $action->post_content;
13
-        $email_key = $action->ID;
14
-
15
-        // Set the subject
16
-        if ( empty($notification['email_subject']) ) {
17
-            $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
18
-        }
19
-
20
-        $plain_text = $notification['plain_text'] ? true : false;
21
-
22
-        //Filter these fields
23
-        $filter_fields = array(
24
-            'email_to', 'cc', 'bcc',
25
-            'reply_to', 'from',
26
-            'email_subject', 'email_message',
27
-        );
28
-
29
-        add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
30
-
31
-        //Get all values in entry in order to get User ID field ID
32
-        $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
33
-        $user_id_field = $user_id_key = '';
34
-        foreach ( $values as $value ) {
35
-            if ( $value->field_type == 'user_id' ) {
36
-                $user_id_field = $value->field_id;
37
-                $user_id_key = $value->field_key;
38
-                break;
39
-            }
40
-            unset($value);
41
-        }
42
-
43
-        //Filter and prepare the email fields
44
-        foreach ( $filter_fields as $f ) {
45
-            //Don't allow empty From
12
+		$notification = $action->post_content;
13
+		$email_key = $action->ID;
14
+
15
+		// Set the subject
16
+		if ( empty($notification['email_subject']) ) {
17
+			$notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
18
+		}
19
+
20
+		$plain_text = $notification['plain_text'] ? true : false;
21
+
22
+		//Filter these fields
23
+		$filter_fields = array(
24
+			'email_to', 'cc', 'bcc',
25
+			'reply_to', 'from',
26
+			'email_subject', 'email_message',
27
+		);
28
+
29
+		add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
30
+
31
+		//Get all values in entry in order to get User ID field ID
32
+		$values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
33
+		$user_id_field = $user_id_key = '';
34
+		foreach ( $values as $value ) {
35
+			if ( $value->field_type == 'user_id' ) {
36
+				$user_id_field = $value->field_id;
37
+				$user_id_key = $value->field_key;
38
+				break;
39
+			}
40
+			unset($value);
41
+		}
42
+
43
+		//Filter and prepare the email fields
44
+		foreach ( $filter_fields as $f ) {
45
+			//Don't allow empty From
46 46
 			if ( $f == 'from' && empty( $notification[ $f ] ) ) {
47 47
 				$notification[ $f ] = '[admin_email]';
48 48
 			} else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) {
49 49
 				//Remove brackets
50
-                //Add a space in case there isn't one
50
+				//Add a space in case there isn't one
51 51
 				$notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] );
52 52
 				$notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] );
53 53
 
54
-                //Switch userID shortcode to email address
54
+				//Switch userID shortcode to email address
55 55
 				if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) {
56 56
 					$user_data = get_userdata( $entry->metas[ $user_id_field ] );
57
-                    $user_email = $user_data->user_email;
57
+					$user_email = $user_data->user_email;
58 58
 					$notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] );
59
-                }
60
-            }
59
+				}
60
+			}
61 61
 
62 62
 			$notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry );
63
-        }
63
+		}
64 64
 
65
-        //Put recipients, cc, and bcc into an array if they aren't empty
65
+		//Put recipients, cc, and bcc into an array if they aren't empty
66 66
 		$to_emails = self::explode_emails( $notification['email_to'] );
67 67
 		$cc = self::explode_emails( $notification['cc'] );
68 68
 		$bcc = self::explode_emails( $notification['bcc'] );
69 69
 
70
-        $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form'));
70
+		$to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form'));
71 71
 
72
-        // Stop now if there aren't any recipients
73
-        if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
74
-            return;
75
-        }
72
+		// Stop now if there aren't any recipients
73
+		if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
74
+			return;
75
+		}
76 76
 
77
-        $to_emails = array_unique( (array) $to_emails );
77
+		$to_emails = array_unique( (array) $to_emails );
78 78
 
79
-        $prev_mail_body = $mail_body = $notification['email_message'];
80
-        $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
81
-            'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
82
-            'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
83
-        ) );
79
+		$prev_mail_body = $mail_body = $notification['email_message'];
80
+		$mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
81
+			'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
82
+			'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
83
+		) );
84 84
 
85
-        // Add the user info if it isn't already included
86
-        if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
87
-            $data = maybe_unserialize($entry->description);
85
+		// Add the user info if it isn't already included
86
+		if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
87
+			$data = maybe_unserialize($entry->description);
88 88
 			$mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
89 89
 			$mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n";
90 90
 			$mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n";
91 91
 			$mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
92
-        }
93
-        unset($prev_mail_body);
94
-
95
-        // Add attachments
96
-        $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
97
-
98
-        if ( ! empty($notification['email_subject']) ) {
99
-            $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
100
-        }
101
-
102
-        // check for a phone number
103
-        foreach ( (array) $to_emails as $email_key => $e ) {
104
-            if ( $e != '[admin_email]' && ! is_email($e) ) {
105
-                $e = explode(' ', $e);
106
-
107
-                //If to_email has name <[email protected]> format
108
-                if ( is_email(end($e)) ) {
109
-                    continue;
110
-                }
111
-
112
-                do_action('frm_send_to_not_email', array(
113
-                    'e'         => $e,
114
-                    'subject'   => $notification['email_subject'],
115
-                    'mail_body' => $mail_body,
116
-                    'reply_to'  => $notification['reply_to'],
117
-                    'from'      => $notification['from'],
118
-                    'plain_text' => $plain_text,
119
-                    'attachments' => $attachments,
120
-                    'form'      => $form,
121
-                    'email_key' => $email_key,
122
-                ) );
92
+		}
93
+		unset($prev_mail_body);
94
+
95
+		// Add attachments
96
+		$attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
97
+
98
+		if ( ! empty($notification['email_subject']) ) {
99
+			$notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
100
+		}
101
+
102
+		// check for a phone number
103
+		foreach ( (array) $to_emails as $email_key => $e ) {
104
+			if ( $e != '[admin_email]' && ! is_email($e) ) {
105
+				$e = explode(' ', $e);
106
+
107
+				//If to_email has name <[email protected]> format
108
+				if ( is_email(end($e)) ) {
109
+					continue;
110
+				}
111
+
112
+				do_action('frm_send_to_not_email', array(
113
+					'e'         => $e,
114
+					'subject'   => $notification['email_subject'],
115
+					'mail_body' => $mail_body,
116
+					'reply_to'  => $notification['reply_to'],
117
+					'from'      => $notification['from'],
118
+					'plain_text' => $plain_text,
119
+					'attachments' => $attachments,
120
+					'form'      => $form,
121
+					'email_key' => $email_key,
122
+				) );
123 123
 
124 124
 				unset( $to_emails[ $email_key ] );
125
-            }
126
-        }
125
+			}
126
+		}
127 127
 
128 128
 		/**
129 129
 		 * Send a separate email for email address in the "to" section
@@ -131,38 +131,38 @@  discard block
 block discarded – undo
131 131
 		 */
132 132
 		$send_single_recipient = apply_filters( 'frm_send_separate_emails', false, compact( 'action', 'entry', 'form' ) );
133 133
 
134
-        // Send the email now
135
-        $sent_to = self::send_email( array(
136
-            'to_email'      => $to_emails,
137
-            'subject'       => $notification['email_subject'],
138
-            'message'       => $mail_body,
139
-            'from'          => $notification['from'],
140
-            'plain_text'    => $plain_text,
141
-            'reply_to'      => $notification['reply_to'],
142
-            'attachments'   => $attachments,
143
-            'cc'            => $cc,
144
-            'bcc'           => $bcc,
134
+		// Send the email now
135
+		$sent_to = self::send_email( array(
136
+			'to_email'      => $to_emails,
137
+			'subject'       => $notification['email_subject'],
138
+			'message'       => $mail_body,
139
+			'from'          => $notification['from'],
140
+			'plain_text'    => $plain_text,
141
+			'reply_to'      => $notification['reply_to'],
142
+			'attachments'   => $attachments,
143
+			'cc'            => $cc,
144
+			'bcc'           => $bcc,
145 145
 			'single_recipient' => $send_single_recipient,
146
-        ) );
146
+		) );
147 147
 
148
-        return $sent_to;
149
-    }
148
+		return $sent_to;
149
+	}
150 150
 
151 151
 	public function entry_created( $entry_id, $form_id ) {
152 152
 		$new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")';
153 153
 		_deprecated_function( __FUNCTION__, '2.0', $new_function );
154
-        FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
155
-    }
154
+		FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
155
+	}
156 156
 
157 157
 	public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) {
158
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
158
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
159 159
 
160
-        return self::send_email(compact(
161
-            'to_email', 'subject', 'message',
162
-            'from', 'from_name', 'plain_text',
163
-            'attachments', 'reply_to'
164
-        ));
165
-    }
160
+		return self::send_email(compact(
161
+			'to_email', 'subject', 'message',
162
+			'from', 'from_name', 'plain_text',
163
+			'attachments', 'reply_to'
164
+		));
165
+	}
166 166
 
167 167
 	/**
168 168
 	 * Extract the emails from cc and bcc. Allow separation by , or ;.
@@ -180,53 +180,53 @@  discard block
 block discarded – undo
180 180
 		return $emails;
181 181
 	}
182 182
 
183
-    /**
184
-    * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format
185
-    * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>,
186
-    * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]>
187
-    * "First Last" <[email protected]>
188
-    *
189
-    * Things that won't work: First Last (with no email entered)
190
-    * @since 2.0
191
-    * @param array $atts array of email fields, pass by reference
192
-    * @param $admin_email
193
-    */
194
-    private static function format_email_fields( &$atts, $admin_email ) {
195
-
196
-        // If from is empty or is set to admin_email, set it now
197
-        $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
198
-
199
-        // Filter values in these fields
183
+	/**
184
+	 * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format
185
+	 * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>,
186
+	 * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]>
187
+	 * "First Last" <[email protected]>
188
+	 *
189
+	 * Things that won't work: First Last (with no email entered)
190
+	 * @since 2.0
191
+	 * @param array $atts array of email fields, pass by reference
192
+	 * @param $admin_email
193
+	 */
194
+	private static function format_email_fields( &$atts, $admin_email ) {
195
+
196
+		// If from is empty or is set to admin_email, set it now
197
+		$atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
198
+
199
+		// Filter values in these fields
200 200
 		$filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' );
201 201
 
202
-        foreach ( $filter_fields as $f ) {
203
-            // If empty, just skip it
202
+		foreach ( $filter_fields as $f ) {
203
+			// If empty, just skip it
204 204
 			if ( empty( $atts[ $f ] ) ) {
205
-                continue;
206
-            }
205
+				continue;
206
+			}
207 207
 
208
-            // to_email, cc, and bcc can be an array
208
+			// to_email, cc, and bcc can be an array
209 209
 			if ( is_array( $atts[ $f ] ) ) {
210 210
 				foreach ( $atts[ $f ] as $key => $val ) {
211
-                    self::format_single_field( $atts, $f, $val, $key );
212
-                    unset( $key, $val );
213
-                }
214
-                unset($f);
215
-                continue;
216
-            }
211
+					self::format_single_field( $atts, $f, $val, $key );
212
+					unset( $key, $val );
213
+				}
214
+				unset($f);
215
+				continue;
216
+			}
217 217
 
218 218
 			self::format_single_field( $atts, $f, $atts[ $f ] );
219
-        }
219
+		}
220 220
 
221
-        // If reply-to isn't set, make it match the from settings
222
-        if ( empty( $atts['reply_to'] ) ) {
223
-            $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] );
224
-        }
221
+		// If reply-to isn't set, make it match the from settings
222
+		if ( empty( $atts['reply_to'] ) ) {
223
+			$atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] );
224
+		}
225 225
 
226
-        if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
227
-            $atts['to_email'] = $admin_email;
228
-        }
229
-    }
226
+		if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
227
+			$atts['to_email'] = $admin_email;
228
+		}
229
+	}
230 230
 
231 231
 	private static function get_email_from_formatted_string( $value ) {
232 232
 		if ( strpos( $value, '<' ) !== false ) {
@@ -236,48 +236,48 @@  discard block
 block discarded – undo
236 236
 		return $value;
237 237
 	}
238 238
 
239
-    /**
240
-    * Format individual email fields
241
-    *
242
-    * @since 2.0
243
-    * @param array $atts pass by reference
244
-    * @param string $f (to, from, reply_to, etc)
245
-    * @param string $val value saved in field
246
-    * @param int $key if in array, this will be set
247
-    */
248
-    private static function format_single_field( &$atts, $f, $val, $key = false ) {
249
-        $val = trim($val);
250
-
251
-        // If just a plain email is used
252
-        if ( is_email($val) ) {
253
-            // add sender's name if not included in $from
254
-            if ( $f == 'from' ) {
239
+	/**
240
+	 * Format individual email fields
241
+	 *
242
+	 * @since 2.0
243
+	 * @param array $atts pass by reference
244
+	 * @param string $f (to, from, reply_to, etc)
245
+	 * @param string $val value saved in field
246
+	 * @param int $key if in array, this will be set
247
+	 */
248
+	private static function format_single_field( &$atts, $f, $val, $key = false ) {
249
+		$val = trim($val);
250
+
251
+		// If just a plain email is used
252
+		if ( is_email($val) ) {
253
+			// add sender's name if not included in $from
254
+			if ( $f == 'from' ) {
255 255
 				$part_2 = $atts[ $f ];
256
-                $part_1  = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
257
-            } else {
258
-                return;
259
-            }
260
-        } else {
261
-            $parts = explode(' ', $val);
262
-            $part_2 = end($parts);
263
-
264
-            // If inputted correcly, $part_2 should be an email
265
-            if ( is_email( $part_2 ) ) {
266
-                $part_1 = trim( str_replace( $part_2, '', $val ) );
267
-            } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
256
+				$part_1  = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
257
+			} else {
258
+				return;
259
+			}
260
+		} else {
261
+			$parts = explode(' ', $val);
262
+			$part_2 = end($parts);
263
+
264
+			// If inputted correcly, $part_2 should be an email
265
+			if ( is_email( $part_2 ) ) {
266
+				$part_1 = trim( str_replace( $part_2, '', $val ) );
267
+			} else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
268 268
 				// In case someone just puts a name in the From or Reply To field
269 269
 				$part_1 = $val;
270
-                $part_2 = get_option('admin_email');
271
-            } else {
270
+				$part_2 = get_option('admin_email');
271
+			} else {
272 272
 				// In case someone just puts a name in any other email field
273
-                if ( false !== $key ) {
273
+				if ( false !== $key ) {
274 274
 					unset( $atts[ $f ][ $key ] );
275
-                    return;
276
-                }
275
+					return;
276
+				}
277 277
 				$atts[ $f ] = '';
278
-                return;
279
-            }
280
-        }
278
+				return;
279
+			}
280
+		}
281 281
 
282 282
 		// if sending the email from a yahoo address, change it to the WordPress default
283 283
 		if ( $f == 'from' && strpos( $part_2, '@yahoo.com' ) ) {
@@ -290,60 +290,60 @@  discard block
 block discarded – undo
290 290
 			$part_2 = 'wordpress@' . $sitename;
291 291
 		}
292 292
 
293
-        // Set up formatted value
293
+		// Set up formatted value
294 294
 		$final_val = str_replace( '"', '', $part_1 ) . ' <' . $part_2 . '>';
295 295
 
296
-        // If value is an array
297
-        if ( false !== $key ) {
296
+		// If value is an array
297
+		if ( false !== $key ) {
298 298
 			$atts[ $f ][ $key ] = $final_val;
299
-            return;
300
-        }
299
+			return;
300
+		}
301 301
 		$atts[ $f ] = $final_val;
302
-    }
302
+	}
303 303
 
304 304
 	public static function send_email( $atts ) {
305
-        $admin_email = get_option('admin_email');
306
-        $defaults = array(
307
-            'to_email'      => $admin_email,
308
-            'subject'       => '',
309
-            'message'       => '',
310
-            'from'          => $admin_email,
311
-            'from_name'     => '',
312
-            'cc'            => '',
313
-            'bcc'           => '',
314
-            'plain_text'    => true,
315
-            'reply_to'      => $admin_email,
316
-            'attachments'   => array(),
305
+		$admin_email = get_option('admin_email');
306
+		$defaults = array(
307
+			'to_email'      => $admin_email,
308
+			'subject'       => '',
309
+			'message'       => '',
310
+			'from'          => $admin_email,
311
+			'from_name'     => '',
312
+			'cc'            => '',
313
+			'bcc'           => '',
314
+			'plain_text'    => true,
315
+			'reply_to'      => $admin_email,
316
+			'attachments'   => array(),
317 317
 			'single_recipient' => false,
318
-        );
319
-        $atts = wp_parse_args($atts, $defaults);
318
+		);
319
+		$atts = wp_parse_args($atts, $defaults);
320 320
 
321
-        // Put To, BCC, CC, Reply To, and From fields in the correct format
322
-        self::format_email_fields( $atts, $admin_email );
321
+		// Put To, BCC, CC, Reply To, and From fields in the correct format
322
+		self::format_email_fields( $atts, $admin_email );
323 323
 
324
-        $header         = array();
325
-        $header[]       = 'From: ' . $atts['from'];
324
+		$header         = array();
325
+		$header[]       = 'From: ' . $atts['from'];
326 326
 
327
-        //Allow for cc and bcc arrays
327
+		//Allow for cc and bcc arrays
328 328
 		$array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] );
329 329
 		$cc = array( 'CC' => array(), 'BCC' => array() );
330
-        foreach ( $array_fields as $key => $a_field ) {
331
-            if ( empty($a_field) ) {
332
-                continue;
333
-            }
330
+		foreach ( $array_fields as $key => $a_field ) {
331
+			if ( empty($a_field) ) {
332
+				continue;
333
+			}
334 334
 
335 335
 			foreach ( (array) $a_field as $email ) {
336 336
 				$cc[ $key ][] = $email;
337
-            }
338
-            unset($key, $a_field);
339
-        }
337
+			}
338
+			unset($key, $a_field);
339
+		}
340 340
 		$cc = array_filter( $cc ); // remove cc and bcc if they are empty
341 341
 
342 342
 		foreach ( $cc as $k => $v ) {
343 343
 			$header[] = $k . ': ' . implode( ',', $v );
344 344
 		}
345 345
 
346
-        $content_type   = $atts['plain_text'] ? 'text/plain' : 'text/html';
346
+		$content_type   = $atts['plain_text'] ? 'text/plain' : 'text/html';
347 347
 		$atts['charset'] = get_option('blog_charset');
348 348
 
349 349
 		$header[]       = 'Reply-To: ' . $atts['reply_to'];
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
 
353 353
 		$atts['message'] = do_shortcode( $atts['message'] );
354 354
 
355
-        if ( $atts['plain_text'] ) {
355
+		if ( $atts['plain_text'] ) {
356 356
 			$atts['message'] = wp_specialchars_decode( strip_tags( $atts['message'] ), ENT_QUOTES );
357
-        } else {
357
+		} else {
358 358
 			// remove line breaks in HTML emails to prevent conflicts with Mandrill
359
-        	add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
360
-        }
359
+			add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
360
+		}
361 361
 		$atts['message'] = apply_filters( 'frm_email_message', $atts['message'], $atts );
362 362
 
363 363
 		/**
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 		// remove the filter now so other emails can still use it
387 387
 		remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' );
388 388
 
389
-        if ( $sent ) {
389
+		if ( $sent ) {
390 390
 			return self::return_emails_sent( $atts );
391
-        }
392
-    }
391
+		}
392
+	}
393 393
 
394 394
 	private static function send_single_email( $recipient, $atts, $header ) {
395 395
 		$header = apply_filters( 'frm_email_header', $header, array(
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmNotification {
4 4
 	public function __construct() {
5
-        if ( ! defined('ABSPATH') ) {
6
-            die('You are not allowed to call this page directly.');
5
+        if ( ! defined( 'ABSPATH' ) ) {
6
+            die( 'You are not allowed to call this page directly.' );
7 7
         }
8
-        add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3);
8
+        add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 );
9 9
     }
10 10
 
11 11
 	public static function trigger_email( $action, $entry, $form ) {
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
         $email_key = $action->ID;
14 14
 
15 15
         // Set the subject
16
-        if ( empty($notification['email_subject']) ) {
17
-            $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]');
16
+        if ( empty( $notification['email_subject'] ) ) {
17
+            $notification['email_subject'] = sprintf( __( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]' );
18 18
         }
19 19
 
20 20
         $plain_text = $notification['plain_text'] ? true : false;
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
             'email_subject', 'email_message',
27 27
         );
28 28
 
29
-        add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false'));
29
+        add_filter( 'frm_plain_text_email', ( $plain_text ? '__return_true' : '__return_false' ) );
30 30
 
31 31
         //Get all values in entry in order to get User ID field ID
32 32
         $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' );
@@ -37,29 +37,29 @@  discard block
 block discarded – undo
37 37
                 $user_id_key = $value->field_key;
38 38
                 break;
39 39
             }
40
-            unset($value);
40
+            unset( $value );
41 41
         }
42 42
 
43 43
         //Filter and prepare the email fields
44 44
         foreach ( $filter_fields as $f ) {
45 45
             //Don't allow empty From
46
-			if ( $f == 'from' && empty( $notification[ $f ] ) ) {
47
-				$notification[ $f ] = '[admin_email]';
46
+			if ( $f == 'from' && empty( $notification[$f] ) ) {
47
+				$notification[$f] = '[admin_email]';
48 48
 			} else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) {
49 49
 				//Remove brackets
50 50
                 //Add a space in case there isn't one
51
-				$notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] );
52
-				$notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] );
51
+				$notification[$f] = str_replace( '<', ' ', $notification[$f] );
52
+				$notification[$f] = str_replace( array( '"', '>' ), '', $notification[$f] );
53 53
 
54 54
                 //Switch userID shortcode to email address
55
-				if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) {
56
-					$user_data = get_userdata( $entry->metas[ $user_id_field ] );
55
+				if ( strpos( $notification[$f], '[' . $user_id_field . ']' ) !== false || strpos( $notification[$f], '[' . $user_id_key . ']' ) !== false ) {
56
+					$user_data = get_userdata( $entry->metas[$user_id_field] );
57 57
                     $user_email = $user_data->user_email;
58
-					$notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] );
58
+					$notification[$f] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[$f] );
59 59
                 }
60 60
             }
61 61
 
62
-			$notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry );
62
+			$notification[$f] = FrmFieldsHelper::basic_replace_shortcodes( $notification[$f], $form, $entry );
63 63
         }
64 64
 
65 65
         //Put recipients, cc, and bcc into an array if they aren't empty
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$cc = self::explode_emails( $notification['cc'] );
68 68
 		$bcc = self::explode_emails( $notification['bcc'] );
69 69
 
70
-        $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form'));
70
+        $to_emails = apply_filters( 'frm_to_email', $to_emails, $values, $form->id, compact( 'email_key', 'entry', 'form' ) );
71 71
 
72 72
         // Stop now if there aren't any recipients
73 73
         if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
         $to_emails = array_unique( (array) $to_emails );
78 78
 
79 79
         $prev_mail_body = $mail_body = $notification['email_message'];
80
-        $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array(
80
+        $mail_body = FrmEntriesHelper::replace_default_message( $mail_body, array(
81 81
             'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text,
82
-            'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false),
82
+            'user_info' => ( isset( $notification['inc_user_info'] ) ? $notification['inc_user_info'] : false ),
83 83
         ) );
84 84
 
85 85
         // Add the user info if it isn't already included
86 86
         if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) {
87
-            $data = maybe_unserialize($entry->description);
87
+            $data = maybe_unserialize( $entry->description );
88 88
 			$mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n";
89 89
 			$mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n";
90 90
 			$mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n";
91 91
 			$mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n";
92 92
         }
93
-        unset($prev_mail_body);
93
+        unset( $prev_mail_body );
94 94
 
95 95
         // Add attachments
96
-        $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') );
96
+        $attachments = apply_filters( 'frm_notification_attachment', array(), $form, compact( 'entry', 'email_key' ) );
97 97
 
98
-        if ( ! empty($notification['email_subject']) ) {
99
-            $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key'));
98
+        if ( ! empty( $notification['email_subject'] ) ) {
99
+            $notification['email_subject'] = apply_filters( 'frm_email_subject', $notification['email_subject'], compact( 'form', 'entry', 'email_key' ) );
100 100
         }
101 101
 
102 102
         // check for a phone number
103 103
         foreach ( (array) $to_emails as $email_key => $e ) {
104
-            if ( $e != '[admin_email]' && ! is_email($e) ) {
105
-                $e = explode(' ', $e);
104
+            if ( $e != '[admin_email]' && ! is_email( $e ) ) {
105
+                $e = explode( ' ', $e );
106 106
 
107 107
                 //If to_email has name <[email protected]> format
108
-                if ( is_email(end($e)) ) {
108
+                if ( is_email( end( $e ) ) ) {
109 109
                     continue;
110 110
                 }
111 111
 
112
-                do_action('frm_send_to_not_email', array(
112
+                do_action( 'frm_send_to_not_email', array(
113 113
                     'e'         => $e,
114 114
                     'subject'   => $notification['email_subject'],
115 115
                     'mail_body' => $mail_body,
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                     'email_key' => $email_key,
122 122
                 ) );
123 123
 
124
-				unset( $to_emails[ $email_key ] );
124
+				unset( $to_emails[$email_key] );
125 125
             }
126 126
         }
127 127
 
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
 	public function entry_created( $entry_id, $form_id ) {
152 152
 		$new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")';
153 153
 		_deprecated_function( __FUNCTION__, '2.0', $new_function );
154
-        FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email');
154
+        FrmFormActionsController::trigger_actions( 'create', $form_id, $entry_id, 'email' );
155 155
     }
156 156
 
157 157
 	public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) {
158 158
         _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' );
159 159
 
160
-        return self::send_email(compact(
160
+        return self::send_email( compact(
161 161
             'to_email', 'subject', 'message',
162 162
             'from', 'from_name', 'plain_text',
163 163
             'attachments', 'reply_to'
164
-        ));
164
+        ) );
165 165
     }
166 166
 
167 167
 	/**
@@ -194,28 +194,28 @@  discard block
 block discarded – undo
194 194
     private static function format_email_fields( &$atts, $admin_email ) {
195 195
 
196 196
         // If from is empty or is set to admin_email, set it now
197
-        $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
197
+        $atts['from'] = ( empty( $atts['from'] ) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from'];
198 198
 
199 199
         // Filter values in these fields
200 200
 		$filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' );
201 201
 
202 202
         foreach ( $filter_fields as $f ) {
203 203
             // If empty, just skip it
204
-			if ( empty( $atts[ $f ] ) ) {
204
+			if ( empty( $atts[$f] ) ) {
205 205
                 continue;
206 206
             }
207 207
 
208 208
             // to_email, cc, and bcc can be an array
209
-			if ( is_array( $atts[ $f ] ) ) {
210
-				foreach ( $atts[ $f ] as $key => $val ) {
209
+			if ( is_array( $atts[$f] ) ) {
210
+				foreach ( $atts[$f] as $key => $val ) {
211 211
                     self::format_single_field( $atts, $f, $val, $key );
212 212
                     unset( $key, $val );
213 213
                 }
214
-                unset($f);
214
+                unset( $f );
215 215
                 continue;
216 216
             }
217 217
 
218
-			self::format_single_field( $atts, $f, $atts[ $f ] );
218
+			self::format_single_field( $atts, $f, $atts[$f] );
219 219
         }
220 220
 
221 221
         // If reply-to isn't set, make it match the from settings
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] );
224 224
         }
225 225
 
226
-        if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) {
226
+        if ( ! is_array( $atts['to_email'] ) && '[admin_email]' == $atts['to_email'] ) {
227 227
             $atts['to_email'] = $admin_email;
228 228
         }
229 229
     }
@@ -246,20 +246,20 @@  discard block
 block discarded – undo
246 246
     * @param int $key if in array, this will be set
247 247
     */
248 248
     private static function format_single_field( &$atts, $f, $val, $key = false ) {
249
-        $val = trim($val);
249
+        $val = trim( $val );
250 250
 
251 251
         // If just a plain email is used
252
-        if ( is_email($val) ) {
252
+        if ( is_email( $val ) ) {
253 253
             // add sender's name if not included in $from
254 254
             if ( $f == 'from' ) {
255
-				$part_2 = $atts[ $f ];
256
-                $part_1  = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
255
+				$part_2 = $atts[$f];
256
+                $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
257 257
             } else {
258 258
                 return;
259 259
             }
260 260
         } else {
261
-            $parts = explode(' ', $val);
262
-            $part_2 = end($parts);
261
+            $parts = explode( ' ', $val );
262
+            $part_2 = end( $parts );
263 263
 
264 264
             // If inputted correcly, $part_2 should be an email
265 265
             if ( is_email( $part_2 ) ) {
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
             } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) {
268 268
 				// In case someone just puts a name in the From or Reply To field
269 269
 				$part_1 = $val;
270
-                $part_2 = get_option('admin_email');
270
+                $part_2 = get_option( 'admin_email' );
271 271
             } else {
272 272
 				// In case someone just puts a name in any other email field
273 273
                 if ( false !== $key ) {
274
-					unset( $atts[ $f ][ $key ] );
274
+					unset( $atts[$f][$key] );
275 275
                     return;
276 276
                 }
277
-				$atts[ $f ] = '';
277
+				$atts[$f] = '';
278 278
                 return;
279 279
             }
280 280
         }
@@ -295,14 +295,14 @@  discard block
 block discarded – undo
295 295
 
296 296
         // If value is an array
297 297
         if ( false !== $key ) {
298
-			$atts[ $f ][ $key ] = $final_val;
298
+			$atts[$f][$key] = $final_val;
299 299
             return;
300 300
         }
301
-		$atts[ $f ] = $final_val;
301
+		$atts[$f] = $final_val;
302 302
     }
303 303
 
304 304
 	public static function send_email( $atts ) {
305
-        $admin_email = get_option('admin_email');
305
+        $admin_email = get_option( 'admin_email' );
306 306
         $defaults = array(
307 307
             'to_email'      => $admin_email,
308 308
             'subject'       => '',
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
             'attachments'   => array(),
317 317
 			'single_recipient' => false,
318 318
         );
319
-        $atts = wp_parse_args($atts, $defaults);
319
+        $atts = wp_parse_args( $atts, $defaults );
320 320
 
321 321
         // Put To, BCC, CC, Reply To, and From fields in the correct format
322 322
         self::format_email_fields( $atts, $admin_email );
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 		$array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] );
329 329
 		$cc = array( 'CC' => array(), 'BCC' => array() );
330 330
         foreach ( $array_fields as $key => $a_field ) {
331
-            if ( empty($a_field) ) {
331
+            if ( empty( $a_field ) ) {
332 332
                 continue;
333 333
             }
334 334
 
335 335
 			foreach ( (array) $a_field as $email ) {
336
-				$cc[ $key ][] = $email;
336
+				$cc[$key][] = $email;
337 337
             }
338
-            unset($key, $a_field);
338
+            unset( $key, $a_field );
339 339
         }
340 340
 		$cc = array_filter( $cc ); // remove cc and bcc if they are empty
341 341
 
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 			$header[] = $k . ': ' . implode( ',', $v );
344 344
 		}
345 345
 
346
-        $content_type   = $atts['plain_text'] ? 'text/plain' : 'text/html';
347
-		$atts['charset'] = get_option('blog_charset');
346
+        $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html';
347
+		$atts['charset'] = get_option( 'blog_charset' );
348 348
 
349 349
 		$header[]       = 'Reply-To: ' . $atts['reply_to'];
350 350
 		$header[]       = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $atts['charset'] ) . '"';
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	}
412 412
 
413 413
 	private static function encode_subject( $charset, &$subject ) {
414
-		if ( apply_filters('frm_encode_subject', 1, $subject ) ) {
414
+		if ( apply_filters( 'frm_encode_subject', 1, $subject ) ) {
415 415
 			$subject = '=?' . $charset . '?B?' . base64_encode( $subject ) . '?=';
416 416
 		}
417 417
 	}
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 
428 428
 		if ( apply_filters( 'frm_echo_emails', false ) ) {
429 429
 			$temp = str_replace( '<', '&lt;', $sent_to );
430
-			echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) );
430
+			echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) );
431 431
 		}
432 432
 		return $sent_to;
433 433
 	}
Please login to merge, or discard this patch.