Completed
Push — master ( f2f906...67fde7 )
by Jamie
03:44
created
classes/helpers/FrmFormsListHelper.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 }
5 5
 
6 6
 class FrmFormsListHelper extends FrmListHelper {
7
-    var $status = '';
7
+	var $status = '';
8 8
 
9 9
 	public function __construct( $args ) {
10 10
 		$this->status = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
@@ -13,14 +13,14 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function prepare_items() {
16
-	    global $wpdb, $per_page, $mode;
16
+		global $wpdb, $per_page, $mode;
17 17
 
18
-	    $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
18
+		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
19 19
 
20 20
 		$default_orderby = 'name';
21 21
 		$default_order = 'ASC';
22 22
 
23
-        $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
23
+		$orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby;
24 24
 		$order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order;
25 25
 
26 26
 		$page = $this->get_pagenum();
@@ -28,40 +28,40 @@  discard block
 block discarded – undo
28 28
 
29 29
 		$start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
30 30
 
31
-        $s_query = array();
32
-        $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 );
31
+		$s_query = array();
32
+		$s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 );
33 33
 		switch ( $this->status ) {
34
-		    case 'template':
35
-                $s_query['is_template'] = 1;
36
-                $s_query['status !'] = 'trash';
37
-		        break;
38
-		    case 'draft':
39
-                $s_query['is_template'] = 0;
40
-                $s_query['status'] = 'draft';
41
-		        break;
42
-		    case 'trash':
43
-                $s_query['status'] = 'trash';
44
-		        break;
45
-		    default:
46
-                $s_query['is_template'] = 0;
47
-                $s_query['status !'] = 'trash';
48
-		        break;
34
+			case 'template':
35
+				$s_query['is_template'] = 1;
36
+				$s_query['status !'] = 'trash';
37
+				break;
38
+			case 'draft':
39
+				$s_query['is_template'] = 0;
40
+				$s_query['status'] = 'draft';
41
+				break;
42
+			case 'trash':
43
+				$s_query['status'] = 'trash';
44
+				break;
45
+			default:
46
+				$s_query['is_template'] = 0;
47
+				$s_query['status !'] = 'trash';
48
+				break;
49 49
 		}
50 50
 
51
-        $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
52
-	    if ( $s != '' ) {
53
-	        preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
54
-		    $search_terms = array_map('trim', $matches[0]);
55
-	        foreach ( (array) $search_terms as $term ) {
56
-                $s_query[] = array(
57
-                    'or'    => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term,
58
-                );
59
-	            unset($term);
60
-            }
61
-	    }
62
-
63
-        $this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
64
-        $total_items = FrmDb::get_count( 'frm_forms', $s_query );
51
+		$s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
52
+		if ( $s != '' ) {
53
+			preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
54
+			$search_terms = array_map('trim', $matches[0]);
55
+			foreach ( (array) $search_terms as $term ) {
56
+				$s_query[] = array(
57
+					'or'    => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term,
58
+				);
59
+				unset($term);
60
+			}
61
+		}
62
+
63
+		$this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
64
+		$total_items = FrmDb::get_count( 'frm_forms', $s_query );
65 65
 
66 66
 		$this->set_pagination_args( array(
67 67
 			'total_items' => $total_items,
@@ -70,69 +70,69 @@  discard block
 block discarded – undo
70 70
 	}
71 71
 
72 72
 	public function no_items() {
73
-	    if ( 'template' == $this->status ) {
74
-            _e( 'No Templates Found.', 'formidable' ) ?>
73
+		if ( 'template' == $this->status ) {
74
+			_e( 'No Templates Found.', 'formidable' ) ?>
75 75
             <br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?>
76 76
             <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li>
77 77
                 <li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li>
78 78
                 <li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li>
79 79
             </ol>
80 80
 <?php   } else {
81
-            _e( 'No Forms Found.', 'formidable' ) ?>
81
+			_e( 'No Forms Found.', 'formidable' ) ?>
82 82
             <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>"><?php _e( 'Add New', 'formidable' ); ?></a>
83 83
 <?php   }
84 84
 	}
85 85
 
86 86
 	public function get_bulk_actions() {
87
-	    $actions = array();
87
+		$actions = array();
88 88
 
89 89
 		if ( in_array( $this->status, array( '', 'published' ) ) ) {
90
-	        $actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
91
-	    }
92
-
93
-	    if ( 'trash' == $this->status ) {
94
-	        if ( current_user_can('frm_edit_forms') ) {
95
-	            $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
96
-	        }
97
-
98
-	        if ( current_user_can('frm_delete_forms') ) {
99
-	            $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
100
-	        }
101
-	    } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
102
-	        $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
103
-	    } else if ( current_user_can('frm_delete_forms') ) {
104
-	        $actions['bulk_delete'] = __( 'Delete');
105
-	    }
106
-
107
-        return $actions;
108
-    }
90
+			$actions['bulk_create_template'] = __( 'Create Template', 'formidable' );
91
+		}
92
+
93
+		if ( 'trash' == $this->status ) {
94
+			if ( current_user_can('frm_edit_forms') ) {
95
+				$actions['bulk_untrash'] = __( 'Restore', 'formidable' );
96
+			}
97
+
98
+			if ( current_user_can('frm_delete_forms') ) {
99
+				$actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
100
+			}
101
+		} else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
102
+			$actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
103
+		} else if ( current_user_can('frm_delete_forms') ) {
104
+			$actions['bulk_delete'] = __( 'Delete');
105
+		}
106
+
107
+		return $actions;
108
+	}
109 109
 
110 110
 	public function extra_tablenav( $which ) {
111
-        if ( 'top' != $which ) {
112
-            return;
113
-        }
111
+		if ( 'top' != $which ) {
112
+			return;
113
+		}
114 114
 
115
-        if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
115
+		if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
116 116
 ?>
117 117
             <div class="alignleft actions frm_visible_overflow">
118 118
 			<?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
119 119
             </div>
120 120
 <?php
121
-            return;
122
-        }
121
+			return;
122
+		}
123 123
 
124
-        if ( 'template' != $this->status ) {
125
-            return;
126
-        }
124
+		if ( 'template' != $this->status ) {
125
+			return;
126
+		}
127 127
 
128 128
 		$where = apply_filters( 'frm_forms_dropdown', array(), '' );
129 129
 		$forms = FrmForm::get_published_forms( $where );
130 130
 
131
-        $base = admin_url('admin.php?page=formidable&form_type=template');
132
-        $args = array(
133
-            'frm_action'    => 'duplicate',
134
-            'template'      => true,
135
-        );
131
+		$base = admin_url('admin.php?page=formidable&form_type=template');
132
+		$args = array(
133
+			'frm_action'    => 'duplicate',
134
+			'template'      => true,
135
+		);
136 136
 
137 137
 ?>
138 138
     <div class="alignleft actions frm_visible_overflow">
@@ -140,18 +140,18 @@  discard block
 block discarded – undo
140 140
         <a href="#" id="frm-templateDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Create New Template', 'formidable' ) ?> <b class="caret"></b></a>
141 141
 		<ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop">
142 142
 		<?php
143
-        if ( empty( $forms ) ) { ?>
143
+		if ( empty( $forms ) ) { ?>
144 144
             <li class="frm_dropdown_li"><?php _e( 'You have not created any forms yet. <br/>You must create a form before you can make a template.', 'formidable' ) ?></li>
145 145
         <?php
146
-        } else {
147
-            foreach ( $forms as $form ) {
148
-		        $args['id'] = $form->id; ?>
146
+		} else {
147
+			foreach ( $forms as $form ) {
148
+				$args['id'] = $form->id; ?>
149 149
 			<li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li>
150 150
 			<?php
151
-			    unset($form);
151
+				unset($form);
152 152
 			}
153
-        }
154
-        ?>
153
+		}
154
+		?>
155 155
 		</ul>
156 156
 	</div>
157 157
 	</div>
@@ -161,30 +161,30 @@  discard block
 block discarded – undo
161 161
 	public function get_views() {
162 162
 
163 163
 		$statuses = array(
164
-		    'published' => __( 'My Forms', 'formidable' ),
165
-		    'template'  => __( 'Templates', 'formidable' ),
166
-		    'draft'     => __( 'Drafts', 'formidable' ),
167
-		    'trash'     => __( 'Trash', 'formidable' ),
164
+			'published' => __( 'My Forms', 'formidable' ),
165
+			'template'  => __( 'Templates', 'formidable' ),
166
+			'draft'     => __( 'Drafts', 'formidable' ),
167
+			'trash'     => __( 'Trash', 'formidable' ),
168 168
 		);
169 169
 
170
-	    $links = array();
171
-	    $counts = FrmForm::get_count();
172
-        $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published';
170
+		$links = array();
171
+		$counts = FrmForm::get_count();
172
+		$form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published';
173 173
 
174
-	    foreach ( $statuses as $status => $name ) {
174
+		foreach ( $statuses as $status => $name ) {
175 175
 
176
-	        if ( $status == $form_type ) {
177
-    			$class = ' class="current"';
178
-    		} else {
179
-    		    $class = '';
180
-    		}
176
+			if ( $status == $form_type ) {
177
+				$class = ' class="current"';
178
+			} else {
179
+				$class = '';
180
+			}
181 181
 
182
-    		if ( $counts->{$status} || 'published' == $status ) {
182
+			if ( $counts->{$status} || 'published' == $status ) {
183 183
 				$links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
184
-		    }
184
+			}
185 185
 
186
-		    unset($status, $name);
187
-	    }
186
+			unset($status, $name);
187
+		}
188 188
 
189 189
 		return $links;
190 190
 	}
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
 	}
201 201
 
202 202
 	public function single_row( $item, $style = '' ) {
203
-	    global $frm_vars, $mode;
203
+		global $frm_vars, $mode;
204 204
 
205 205
 		// Set up the hover actions for this user
206 206
 		$actions = array();
207
-        $edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
208
-	    $duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
207
+		$edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
208
+		$duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
209 209
 
210
-        $this->get_actions($actions, $item, $edit_link, $duplicate_link);
210
+		$this->get_actions($actions, $item, $edit_link, $duplicate_link);
211 211
 
212
-        $action_links = $this->row_actions( $actions );
212
+		$action_links = $this->row_actions( $actions );
213 213
 
214 214
 		// Set up the checkbox ( because the user is editable, otherwise its empty )
215 215
 		$checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />';
@@ -218,17 +218,17 @@  discard block
 block discarded – undo
218 218
 
219 219
 		list( $columns, $hidden ) = $this->get_column_info();
220 220
 
221
-        $format = 'Y/m/d';
222
-        if ( 'list' != $mode ) {
223
-            $format .= ' \<\b\r \/\> g:i:s a';
221
+		$format = 'Y/m/d';
222
+		if ( 'list' != $mode ) {
223
+			$format .= ' \<\b\r \/\> g:i:s a';
224 224
 		}
225 225
 
226 226
 		foreach ( $columns as $column_name => $column_display_name ) {
227
-            $class = $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' );
227
+			$class = $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' );
228 228
 
229 229
 			$style = '';
230 230
 			if ( in_array( $column_name, $hidden ) ) {
231
-                $class .= ' frm_hidden';
231
+				$class .= ' frm_hidden';
232 232
 			}
233 233
 
234 234
 			$class = 'class="' . esc_attr( $class ) . '"';
@@ -241,41 +241,41 @@  discard block
 block discarded – undo
241 241
 					break;
242 242
 				case 'id':
243 243
 				case 'form_key':
244
-				    $val = $item->{$column_name};
245
-				    break;
244
+					$val = $item->{$column_name};
245
+					break;
246 246
 				case 'name':
247
-				    $val = $this->get_form_name( $item, $actions, $edit_link, $mode );
248
-			        $val .= $action_links;
247
+					$val = $this->get_form_name( $item, $actions, $edit_link, $mode );
248
+					$val .= $action_links;
249 249
 
250
-				    break;
250
+					break;
251 251
 				case 'created_at':
252
-				    $date = date($format, strtotime($item->created_at));
252
+					$date = date($format, strtotime($item->created_at));
253 253
 					$val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
254 254
 					break;
255 255
 				case 'shortcode':
256 256
 					$val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id .']' ) . '" /><br/>';
257
-				    if ( 'excerpt' == $mode ) {
257
+					if ( 'excerpt' == $mode ) {
258 258
 						$val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
259
-				    }
260
-			        break;
261
-			    case 'entries':
259
+					}
260
+					break;
261
+				case 'entries':
262 262
 					if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
263
-			            $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable' ) .'"></i>';
264
-			        } else {
265
-			            $text = FrmEntry::getRecordCount($item->id);
266
-                        $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
267
-                        unset($text);
268
-                    }
269
-			        break;
270
-                case 'type':
271
-                    $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
272
-                    break;
263
+						$val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable' ) .'"></i>';
264
+					} else {
265
+						$text = FrmEntry::getRecordCount($item->id);
266
+						$val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
267
+						unset($text);
268
+					}
269
+					break;
270
+				case 'type':
271
+					$val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' );
272
+					break;
273 273
 			}
274 274
 
275 275
 			if ( isset($val) ) {
276
-			    $r .= "<td $attributes>";
277
-			    $r .= $val;
278
-			    $r .= '</td>';
276
+				$r .= "<td $attributes>";
277
+				$r .= $val;
278
+				$r .= '</td>';
279 279
 			}
280 280
 			unset($val);
281 281
 		}
@@ -284,37 +284,37 @@  discard block
 block discarded – undo
284 284
 		return $r;
285 285
 	}
286 286
 
287
-    /**
288
-     * @param string $edit_link
289
-     * @param string $duplicate_link
290
-     */
291
-    private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
287
+	/**
288
+	 * @param string $edit_link
289
+	 * @param string $duplicate_link
290
+	 */
291
+	private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
292 292
 		if ( 'trash' == $this->status ) {
293 293
 			if ( current_user_can('frm_edit_forms') ) {
294 294
 				$actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
295 295
 			}
296 296
 
297
-		    if ( current_user_can('frm_delete_forms') ) {
298
-    		    $actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete"  onclick="return confirm(\''. __( 'Are you sure you want to permanently delete that?', 'formidable' ) .'\')">' . __( 'Delete Permanently' ) . '</a>';
299
-    		}
300
-            return;
297
+			if ( current_user_can('frm_delete_forms') ) {
298
+				$actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete"  onclick="return confirm(\''. __( 'Are you sure you want to permanently delete that?', 'formidable' ) .'\')">' . __( 'Delete Permanently' ) . '</a>';
299
+			}
300
+			return;
301 301
 		}
302 302
 
303 303
 		if ( current_user_can('frm_edit_forms') ) {
304
-            if ( ! $item->is_template || ! $item->default_template ) {
305
-		        $actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __( 'Edit') .'</a>';
306
-            }
304
+			if ( ! $item->is_template || ! $item->default_template ) {
305
+				$actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __( 'Edit') .'</a>';
306
+			}
307 307
 
308
-		    if ( $item->is_template ) {
308
+			if ( $item->is_template ) {
309 309
 				$actions['frm_duplicate'] = '<a href="'. esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Create Form from Template', 'formidable' ) . '</a>';
310
-            } else {
311
-    		    $actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __( 'Settings', 'formidable' ) .'</a>';
310
+			} else {
311
+				$actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __( 'Settings', 'formidable' ) .'</a>';
312 312
 
313
-    		    if ( FrmAppHelper::pro_is_installed() ) {
313
+				if ( FrmAppHelper::pro_is_installed() ) {
314 314
 					$actions['duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Duplicate', 'formidable' ) . '</a>';
315
-        	    }
316
-        	}
317
-        }
315
+				}
316
+			}
317
+		}
318 318
 
319 319
 		$actions['trash'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
320 320
 		if ( empty( $actions['trash'] ) ) {
@@ -323,52 +323,52 @@  discard block
 block discarded – undo
323 323
 		}
324 324
 
325 325
 		$actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview') . '</a>';
326
-    }
326
+	}
327 327
 
328
-    /**
329
-     * @param string $edit_link
330
-     */
328
+	/**
329
+	 * @param string $edit_link
330
+	 */
331 331
 	private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
332
-        $form_name = $item->name;
333
-        if ( trim($form_name) == '' ) {
334
-            $form_name = __( '(no title)');
335
-        }
332
+		$form_name = $item->name;
333
+		if ( trim($form_name) == '' ) {
334
+			$form_name = __( '(no title)');
335
+		}
336 336
 		$form_name = FrmAppHelper::kses( $form_name );
337 337
 		if ( 'excerpt' != $mode ) {
338 338
 			$form_name = FrmAppHelper::truncate( $form_name, 50 );
339 339
 		}
340 340
 
341
-        $val = '<strong>';
342
-        if ( 'trash' == $this->status ) {
343
-            $val .= $form_name;
344
-        } else {
341
+		$val = '<strong>';
342
+		if ( 'trash' == $this->status ) {
343
+			$val .= $form_name;
344
+		} else {
345 345
 			$val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> ';
346
-        }
347
-
348
-        $this->add_draft_label( $item, $val );
349
-        $val .= '</strong>';
350
-
351
-        $this->add_form_description( $item, $val );
352
-
353
-        return $val;
354
-    }
355
-
356
-    /**
357
-     * @param string $val
358
-     */
359
-    private function add_draft_label( $item, &$val ) {
360
-        if ( 'draft' == $item->status && 'draft' != $this->status ) {
361
-            $val .= ' - <span class="post-state">'. __( 'Draft', 'formidable' ) .'</span>';
362
-        }
363
-    }
364
-
365
-    /**
366
-     * @param string $val
367
-     */
368
-    private function add_form_description( $item, &$val ) {
369
-        global $mode;
370
-        if ( 'excerpt' == $mode ) {
371
-            $val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
372
-        }
373
-    }
346
+		}
347
+
348
+		$this->add_draft_label( $item, $val );
349
+		$val .= '</strong>';
350
+
351
+		$this->add_form_description( $item, $val );
352
+
353
+		return $val;
354
+	}
355
+
356
+	/**
357
+	 * @param string $val
358
+	 */
359
+	private function add_draft_label( $item, &$val ) {
360
+		if ( 'draft' == $item->status && 'draft' != $this->status ) {
361
+			$val .= ' - <span class="post-state">'. __( 'Draft', 'formidable' ) .'</span>';
362
+		}
363
+	}
364
+
365
+	/**
366
+	 * @param string $val
367
+	 */
368
+	private function add_form_description( $item, &$val ) {
369
+		global $mode;
370
+		if ( 'excerpt' == $mode ) {
371
+			$val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
372
+		}
373
+	}
374 374
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 		$page = $this->get_pagenum();
27 27
 		$per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' );
28 28
 
29
-		$start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page);
29
+		$start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : ( ( $page - 1 ) * $per_page );
30 30
 
31 31
         $s_query = array();
32 32
         $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 );
@@ -48,19 +48,19 @@  discard block
 block discarded – undo
48 48
 		        break;
49 49
 		}
50 50
 
51
-        $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : '';
51
+        $s = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
52 52
 	    if ( $s != '' ) {
53
-	        preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
54
-		    $search_terms = array_map('trim', $matches[0]);
53
+	        preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
54
+		    $search_terms = array_map( 'trim', $matches[0] );
55 55
 	        foreach ( (array) $search_terms as $term ) {
56 56
                 $s_query[] = array(
57 57
                     'or'    => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term,
58 58
                 );
59
-	            unset($term);
59
+	            unset( $term );
60 60
             }
61 61
 	    }
62 62
 
63
-        $this->items = FrmForm::getAll($s_query, $orderby .' '. $order, $start .','. $per_page);
63
+        $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page );
64 64
         $total_items = FrmDb::get_count( 'frm_forms', $s_query );
65 65
 
66 66
 		$this->set_pagination_args( array(
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	    if ( 'template' == $this->status ) {
74 74
             _e( 'No Templates Found.', 'formidable' ) ?>
75 75
             <br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?>
76
-            <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="'. esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li>
77
-                <li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li>
76
+            <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li>
77
+                <li><?php printf( __( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>' ) ?></li>
78 78
                 <li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li>
79 79
             </ol>
80 80
 <?php   } else {
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
 	    }
92 92
 
93 93
 	    if ( 'trash' == $this->status ) {
94
-	        if ( current_user_can('frm_edit_forms') ) {
94
+	        if ( current_user_can( 'frm_edit_forms' ) ) {
95 95
 	            $actions['bulk_untrash'] = __( 'Restore', 'formidable' );
96 96
 	        }
97 97
 
98
-	        if ( current_user_can('frm_delete_forms') ) {
98
+	        if ( current_user_can( 'frm_delete_forms' ) ) {
99 99
 	            $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' );
100 100
 	        }
101
-	    } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) {
101
+	    } else if ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) {
102 102
 	        $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' );
103
-	    } else if ( current_user_can('frm_delete_forms') ) {
104
-	        $actions['bulk_delete'] = __( 'Delete');
103
+	    } else if ( current_user_can( 'frm_delete_forms' ) ) {
104
+	        $actions['bulk_delete'] = __( 'Delete' );
105 105
 	    }
106 106
 
107 107
         return $actions;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
             return;
113 113
         }
114 114
 
115
-        if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) {
115
+        if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) {
116 116
 ?>
117 117
             <div class="alignleft actions frm_visible_overflow">
118 118
 			<?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?>
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 		$where = apply_filters( 'frm_forms_dropdown', array(), '' );
129 129
 		$forms = FrmForm::get_published_forms( $where );
130 130
 
131
-        $base = admin_url('admin.php?page=formidable&form_type=template');
131
+        $base = admin_url( 'admin.php?page=formidable&form_type=template' );
132 132
         $args = array(
133 133
             'frm_action'    => 'duplicate',
134 134
             'template'      => true,
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		        $args['id'] = $form->id; ?>
149 149
 			<li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li>
150 150
 			<?php
151
-			    unset($form);
151
+			    unset( $form );
152 152
 			}
153 153
         }
154 154
         ?>
@@ -180,10 +180,10 @@  discard block
 block discarded – undo
180 180
     		}
181 181
 
182 182
     		if ( $counts->{$status} || 'published' == $status ) {
183
-				$links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
183
+				$links[$status] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>';
184 184
 		    }
185 185
 
186
-		    unset($status, $name);
186
+		    unset( $status, $name );
187 187
 	    }
188 188
 
189 189
 		return $links;
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 
205 205
 		// Set up the hover actions for this user
206 206
 		$actions = array();
207
-        $edit_link = '?page=formidable&frm_action=edit&id='. $item->id;
208
-	    $duplicate_link = '?page=formidable&frm_action=duplicate&id='. $item->id;
207
+        $edit_link = '?page=formidable&frm_action=edit&id=' . $item->id;
208
+	    $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $item->id;
209 209
 
210
-        $this->get_actions($actions, $item, $edit_link, $duplicate_link);
210
+        $this->get_actions( $actions, $item, $edit_link, $duplicate_link );
211 211
 
212 212
         $action_links = $this->row_actions( $actions );
213 213
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		}
225 225
 
226 226
 		foreach ( $columns as $column_name => $column_display_name ) {
227
-            $class = $column_name .' column-'. $column_name . ( ('name' == $column_name) ? ' post-title page-title column-title' : '' );
227
+            $class = $column_name . ' column-' . $column_name . ( ( 'name' == $column_name ) ? ' post-title page-title column-title' : '' );
228 228
 
229 229
 			$style = '';
230 230
 			if ( in_array( $column_name, $hidden ) ) {
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
 			switch ( $column_name ) {
239 239
 				case 'cb':
240
-					$r .= '<th scope="row" class="check-column">'. $checkbox .'</th>';
240
+					$r .= '<th scope="row" class="check-column">' . $checkbox . '</th>';
241 241
 					break;
242 242
 				case 'id':
243 243
 				case 'form_key':
@@ -249,22 +249,22 @@  discard block
 block discarded – undo
249 249
 
250 250
 				    break;
251 251
 				case 'created_at':
252
-				    $date = date($format, strtotime($item->created_at));
252
+				    $date = date( $format, strtotime( $item->created_at ) );
253 253
 					$val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>';
254 254
 					break;
255 255
 				case 'shortcode':
256
-					$val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id .']' ) . '" /><br/>';
256
+					$val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>';
257 257
 				    if ( 'excerpt' == $mode ) {
258 258
 						$val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />';
259 259
 				    }
260 260
 			        break;
261 261
 			    case 'entries':
262 262
 					if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) {
263
-			            $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="'. esc_attr('Entries are not being saved', 'formidable' ) .'"></i>';
263
+			            $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr( 'Entries are not being saved', 'formidable' ) . '"></i>';
264 264
 			        } else {
265
-			            $text = FrmEntry::getRecordCount($item->id);
266
-                        $val = (current_user_can('frm_view_entries')) ? '<a href="'. esc_url(admin_url('admin.php') .'?page=formidable-entries&form='. $item->id ) .'">'. $text .'</a>' : $text;
267
-                        unset($text);
265
+			            $text = FrmEntry::getRecordCount( $item->id );
266
+                        $val = ( current_user_can( 'frm_view_entries' ) ) ? '<a href="' . esc_url( admin_url( 'admin.php' ) . '?page=formidable-entries&form=' . $item->id ) . '">' . $text . '</a>' : $text;
267
+                        unset( $text );
268 268
                     }
269 269
 			        break;
270 270
                 case 'type':
@@ -272,12 +272,12 @@  discard block
 block discarded – undo
272 272
                     break;
273 273
 			}
274 274
 
275
-			if ( isset($val) ) {
275
+			if ( isset( $val ) ) {
276 276
 			    $r .= "<td $attributes>";
277 277
 			    $r .= $val;
278 278
 			    $r .= '</td>';
279 279
 			}
280
-			unset($val);
280
+			unset( $val );
281 281
 		}
282 282
 		$r .= '</tr>';
283 283
 
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
      */
291 291
     private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) {
292 292
 		if ( 'trash' == $this->status ) {
293
-			if ( current_user_can('frm_edit_forms') ) {
293
+			if ( current_user_can( 'frm_edit_forms' ) ) {
294 294
 				$actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' );
295 295
 			}
296 296
 
297
-		    if ( current_user_can('frm_delete_forms') ) {
298
-    		    $actions['trash'] = '<a href="' . esc_url(wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id='. $item->id, 'destroy_form_'. $item->id )) .'" class="submitdelete"  onclick="return confirm(\''. __( 'Are you sure you want to permanently delete that?', 'formidable' ) .'\')">' . __( 'Delete Permanently' ) . '</a>';
297
+		    if ( current_user_can( 'frm_delete_forms' ) ) {
298
+    		    $actions['trash'] = '<a href="' . esc_url( wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id=' . $item->id, 'destroy_form_' . $item->id ) ) . '" class="submitdelete"  onclick="return confirm(\'' . __( 'Are you sure you want to permanently delete that?', 'formidable' ) . '\')">' . __( 'Delete Permanently' ) . '</a>';
299 299
     		}
300 300
             return;
301 301
 		}
302 302
 
303
-		if ( current_user_can('frm_edit_forms') ) {
303
+		if ( current_user_can( 'frm_edit_forms' ) ) {
304 304
             if ( ! $item->is_template || ! $item->default_template ) {
305
-		        $actions['frm_edit'] = '<a href="'. esc_url( $edit_link ) . '">'. __( 'Edit') .'</a>';
305
+		        $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit' ) . '</a>';
306 306
             }
307 307
 
308 308
 		    if ( $item->is_template ) {
309
-				$actions['frm_duplicate'] = '<a href="'. esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Create Form from Template', 'formidable' ) . '</a>';
309
+				$actions['frm_duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Create Form from Template', 'formidable' ) . '</a>';
310 310
             } else {
311
-    		    $actions['frm_settings'] = '<a href="'. esc_url('?page=formidable&frm_action=settings&id='. $item->id ) . '">'. __( 'Settings', 'formidable' ) .'</a>';
311
+    		    $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>';
312 312
 
313 313
     		    if ( FrmAppHelper::pro_is_installed() ) {
314 314
 					$actions['duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Duplicate', 'formidable' ) . '</a>';
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 			unset( $actions['trash'] );
323 323
 		}
324 324
 
325
-		$actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview') . '</a>';
325
+		$actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview' ) . '</a>';
326 326
     }
327 327
 
328 328
     /**
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
      */
331 331
 	private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) {
332 332
         $form_name = $item->name;
333
-        if ( trim($form_name) == '' ) {
334
-            $form_name = __( '(no title)');
333
+        if ( trim( $form_name ) == '' ) {
334
+            $form_name = __( '(no title)' );
335 335
         }
336 336
 		$form_name = FrmAppHelper::kses( $form_name );
337 337
 		if ( 'excerpt' != $mode ) {
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
      */
359 359
     private function add_draft_label( $item, &$val ) {
360 360
         if ( 'draft' == $item->status && 'draft' != $this->status ) {
361
-            $val .= ' - <span class="post-state">'. __( 'Draft', 'formidable' ) .'</span>';
361
+            $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>';
362 362
         }
363 363
     }
364 364
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
     private function add_form_description( $item, &$val ) {
369 369
         global $mode;
370 370
         if ( 'excerpt' == $mode ) {
371
-            $val .= FrmAppHelper::truncate(strip_tags($item->description), 50);
371
+            $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 );
372 372
         }
373 373
     }
374 374
 }
Please login to merge, or discard this patch.
classes/helpers/FrmStylesHelper.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -1,67 +1,67 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class FrmStylesHelper {
3 3
 
4
-    public static function jquery_themes() {
5
-        $themes = array(
6
-            'ui-lightness'  => 'UI Lightness',
7
-            'ui-darkness'   => 'UI Darkness',
8
-            'smoothness'    => 'Smoothness',
9
-            'start'         => 'Start',
10
-            'redmond'       => 'Redmond',
11
-            'sunny'         => 'Sunny',
12
-            'overcast'      => 'Overcast',
13
-            'le-frog'       => 'Le Frog',
14
-            'flick'         => 'Flick',
4
+	public static function jquery_themes() {
5
+		$themes = array(
6
+			'ui-lightness'  => 'UI Lightness',
7
+			'ui-darkness'   => 'UI Darkness',
8
+			'smoothness'    => 'Smoothness',
9
+			'start'         => 'Start',
10
+			'redmond'       => 'Redmond',
11
+			'sunny'         => 'Sunny',
12
+			'overcast'      => 'Overcast',
13
+			'le-frog'       => 'Le Frog',
14
+			'flick'         => 'Flick',
15 15
 			'pepper-grinder' => 'Pepper Grinder',
16
-            'eggplant'      => 'Eggplant',
17
-            'dark-hive'     => 'Dark Hive',
18
-            'cupertino'     => 'Cupertino',
19
-            'south-street'  => 'South Street',
20
-            'blitzer'       => 'Blitzer',
21
-            'humanity'      => 'Humanity',
22
-            'hot-sneaks'    => 'Hot Sneaks',
23
-            'excite-bike'   => 'Excite Bike',
24
-            'vader'         => 'Vader',
25
-            'dot-luv'       => 'Dot Luv',
26
-            'mint-choc'     => 'Mint Choc',
27
-            'black-tie'     => 'Black Tie',
28
-            'trontastic'    => 'Trontastic',
29
-            'swanky-purse'  => 'Swanky Purse',
30
-        );
31
-
32
-        $themes = apply_filters('frm_jquery_themes', $themes);
33
-        return $themes;
34
-    }
16
+			'eggplant'      => 'Eggplant',
17
+			'dark-hive'     => 'Dark Hive',
18
+			'cupertino'     => 'Cupertino',
19
+			'south-street'  => 'South Street',
20
+			'blitzer'       => 'Blitzer',
21
+			'humanity'      => 'Humanity',
22
+			'hot-sneaks'    => 'Hot Sneaks',
23
+			'excite-bike'   => 'Excite Bike',
24
+			'vader'         => 'Vader',
25
+			'dot-luv'       => 'Dot Luv',
26
+			'mint-choc'     => 'Mint Choc',
27
+			'black-tie'     => 'Black Tie',
28
+			'trontastic'    => 'Trontastic',
29
+			'swanky-purse'  => 'Swanky Purse',
30
+		);
31
+
32
+		$themes = apply_filters('frm_jquery_themes', $themes);
33
+		return $themes;
34
+	}
35 35
 
36 36
 	public static function jquery_css_url( $theme_css ) {
37
-        if ( $theme_css == -1 ) {
38
-            return;
39
-        }
40
-
41
-        if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
-            $css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
-        } else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
-            $css_file = $theme_css;
45
-        } else {
46
-            $uploads = self::get_upload_base();
47
-            $file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
-            if ( file_exists($uploads['basedir'] . $file_path) ) {
49
-                $css_file = $uploads['baseurl'] . $file_path;
50
-            } else {
51
-                $css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.min.css';
52
-            }
53
-        }
54
-
55
-        return $css_file;
56
-    }
57
-
58
-    public static function enqueue_jquery_css() {
37
+		if ( $theme_css == -1 ) {
38
+			return;
39
+		}
40
+
41
+		if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42
+			$css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
+		} else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
44
+			$css_file = $theme_css;
45
+		} else {
46
+			$uploads = self::get_upload_base();
47
+			$file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
+			if ( file_exists($uploads['basedir'] . $file_path) ) {
49
+				$css_file = $uploads['baseurl'] . $file_path;
50
+			} else {
51
+				$css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.min.css';
52
+			}
53
+		}
54
+
55
+		return $css_file;
56
+	}
57
+
58
+	public static function enqueue_jquery_css() {
59 59
 		$form = self::get_form_for_page();
60 60
 		$theme_css = FrmStylesController::get_style_val( 'theme_css', $form );
61
-        if ( $theme_css != -1 ) {
62
-            wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
63
-        }
64
-    }
61
+		if ( $theme_css != -1 ) {
62
+			wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
63
+		}
64
+	}
65 65
 
66 66
 	public static function get_form_for_page() {
67 67
 		global $frm_vars;
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 		return $form_id;
78 78
 	}
79 79
 
80
-    public static function get_upload_base() {
81
-        $uploads = wp_upload_dir();
82
-        if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
83
-            $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
84
-        }
80
+	public static function get_upload_base() {
81
+		$uploads = wp_upload_dir();
82
+		if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
83
+			$uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
84
+		}
85 85
 
86
-        return $uploads;
87
-    }
86
+		return $uploads;
87
+	}
88 88
 
89 89
 	public static function style_menu( $active = '' ) {
90 90
 ?>
@@ -94,22 +94,22 @@  discard block
 block discarded – undo
94 94
 			<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-styles&frm_action=custom_css' ) ) ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
95 95
         </h2>
96 96
 <?php
97
-    }
97
+	}
98 98
 
99
-    public static function minus_icons() {
100
-        return array(
99
+	public static function minus_icons() {
100
+		return array(
101 101
 			0 => array( '-' => '62e', '+' => '62f' ),
102 102
 			1 => array( '-' => '600', '+' => '602' ),
103 103
 			2 => array( '-' => '604', '+' => '603' ),
104 104
 			3 => array( '-' => '633', '+' => '632' ),
105 105
 			4 => array( '-' => '613', '+' => '60f' ),
106
-        );
107
-    }
106
+		);
107
+	}
108 108
 
109
-    public static function arrow_icons() {
110
-        $minus_icons = self::minus_icons();
109
+	public static function arrow_icons() {
110
+		$minus_icons = self::minus_icons();
111 111
 
112
-        return array(
112
+		return array(
113 113
 			6 => array( '-' => '62d', '+' => '62a' ),
114 114
 			0 => array( '-' => '60d', '+' => '609' ),
115 115
 			1 => array( '-' => '60e', '+' => '60c' ),
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
 			3 => array( '-' => '62b', '+' => '628' ),
118 118
 			4 => array( '-' => '62c', '+' => '629' ),
119 119
 			5 => array( '-' => '635', '+' => '634' ),
120
-            'p0' => $minus_icons[0],
121
-            'p1' => $minus_icons[1],
122
-            'p2' => $minus_icons[2],
123
-            'p3' => $minus_icons[3],
124
-            'p4' => $minus_icons[4],
125
-        );
126
-    }
127
-
128
-    /**
129
-     * @since 2.0
130
-     * @return The class for this icon
131
-     */
120
+			'p0' => $minus_icons[0],
121
+			'p1' => $minus_icons[1],
122
+			'p2' => $minus_icons[2],
123
+			'p3' => $minus_icons[3],
124
+			'p4' => $minus_icons[4],
125
+		);
126
+	}
127
+
128
+	/**
129
+	 * @since 2.0
130
+	 * @return The class for this icon
131
+	 */
132 132
 	public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
133
-        if ( 'arrow' == $type && is_numeric($key) ) {
134
-            //frm_arrowup6_icon
133
+		if ( 'arrow' == $type && is_numeric($key) ) {
134
+			//frm_arrowup6_icon
135 135
 			$arrow = array( '-' => 'down', '+' => 'up' );
136 136
 			$class = 'frm_arrow' . $arrow[ $icon ];
137
-        } else {
138
-            //frm_minus1_icon
139
-            $key = str_replace('p', '', $key);
137
+		} else {
138
+			//frm_minus1_icon
139
+			$key = str_replace('p', '', $key);
140 140
 			$plus = array( '-' => 'minus', '+' => 'plus' );
141 141
 			$class = 'frm_' . $plus[ $icon ];
142
-        }
142
+		}
143 143
 
144
-        if ( $key ) {
145
-            $class .= $key;
146
-        }
147
-        $class .= '_icon';
144
+		if ( $key ) {
145
+			$class .= $key;
146
+		}
147
+		$class .= '_icon';
148 148
 
149
-        return $class;
150
-    }
149
+		return $class;
150
+	}
151 151
 
152 152
 	public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
153 153
 		$function_name = $type . '_icons';
154 154
 		$icons = self::$function_name();
155 155
 		unset( $function_name );
156 156
 
157
-        $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
157
+		$name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
158 158
 ?>
159 159
     	<select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
160 160
             <?php foreach ( $icons as $key => $icon ) { ?>
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
             </ul>
188 188
         </div>
189 189
 <?php
190
-    }
190
+	}
191 191
 
192 192
 	public static function hex2rgb( $hex ) {
193
-        $hex = str_replace('#', '', $hex);
194
-
195
-        if ( strlen($hex) == 3 ) {
196
-            $r = hexdec( substr($hex,0,1).substr($hex,0,1) );
197
-            $g = hexdec( substr($hex,1,1).substr($hex,1,1) );
198
-            $b = hexdec( substr($hex,2,1).substr($hex,2,1) );
199
-        } else {
200
-            $r = hexdec( substr($hex,0,2) );
201
-            $g = hexdec( substr($hex,2,2) );
202
-            $b = hexdec( substr($hex,4,2) );
203
-        }
193
+		$hex = str_replace('#', '', $hex);
194
+
195
+		if ( strlen($hex) == 3 ) {
196
+			$r = hexdec( substr($hex,0,1).substr($hex,0,1) );
197
+			$g = hexdec( substr($hex,1,1).substr($hex,1,1) );
198
+			$b = hexdec( substr($hex,2,1).substr($hex,2,1) );
199
+		} else {
200
+			$r = hexdec( substr($hex,0,2) );
201
+			$g = hexdec( substr($hex,2,2) );
202
+			$b = hexdec( substr($hex,4,2) );
203
+		}
204 204
 		$rgb = array( $r, $g, $b );
205
-        return implode(',', $rgb); // returns the rgb values separated by commas
206
-        //return $rgb; // returns an array with the rgb values
207
-    }
205
+		return implode(',', $rgb); // returns the rgb values separated by commas
206
+		//return $rgb; // returns an array with the rgb values
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             'swanky-purse'  => 'Swanky Purse',
30 30
         );
31 31
 
32
-        $themes = apply_filters('frm_jquery_themes', $themes);
32
+        $themes = apply_filters( 'frm_jquery_themes', $themes );
33 33
         return $themes;
34 34
     }
35 35
 
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 
41 41
         if ( ! $theme_css || $theme_css == '' || $theme_css == 'ui-lightness' ) {
42 42
             $css_file = FrmAppHelper::plugin_url() . '/css/ui-lightness/jquery-ui.css';
43
-        } else if ( preg_match('/^http.?:\/\/.*\..*$/', $theme_css) ) {
43
+        } else if ( preg_match( '/^http.?:\/\/.*\..*$/', $theme_css ) ) {
44 44
             $css_file = $theme_css;
45 45
         } else {
46 46
             $uploads = self::get_upload_base();
47
-            $file_path = '/formidable/css/'. $theme_css . '/jquery-ui.css';
48
-            if ( file_exists($uploads['basedir'] . $file_path) ) {
47
+            $file_path = '/formidable/css/' . $theme_css . '/jquery-ui.css';
48
+            if ( file_exists( $uploads['basedir'] . $file_path ) ) {
49 49
                 $css_file = $uploads['baseurl'] . $file_path;
50 50
             } else {
51
-                $css_file = FrmAppHelper::jquery_ui_base_url() .'/themes/'. $theme_css . '/jquery-ui.min.css';
51
+                $css_file = FrmAppHelper::jquery_ui_base_url() . '/themes/' . $theme_css . '/jquery-ui.min.css';
52 52
             }
53 53
         }
54 54
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$form = self::get_form_for_page();
60 60
 		$theme_css = FrmStylesController::get_style_val( 'theme_css', $form );
61 61
         if ( $theme_css != -1 ) {
62
-            wp_enqueue_style('jquery-theme', self::jquery_css_url($theme_css), array(), FrmAppHelper::plugin_version());
62
+            wp_enqueue_style( 'jquery-theme', self::jquery_css_url( $theme_css ), array(), FrmAppHelper::plugin_version() );
63 63
         }
64 64
     }
65 65
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 
80 80
     public static function get_upload_base() {
81 81
         $uploads = wp_upload_dir();
82
-        if ( is_ssl() && ! preg_match('/^https:\/\/.*\..*$/', $uploads['baseurl']) ) {
83
-            $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']);
82
+        if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) {
83
+            $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
84 84
         }
85 85
 
86 86
         return $uploads;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         <h2 class="nav-tab-wrapper">
92 92
 			<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ) ?>" class="nav-tab <?php echo ( '' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Edit Styles', 'formidable' ) ?></a>
93 93
 			<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ) ?>" class="nav-tab <?php echo ( 'manage' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Manage Form Styles', 'formidable' ) ?></a>
94
-			<a href="<?php echo esc_url( admin_url('admin.php?page=formidable-styles&frm_action=custom_css' ) ) ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
94
+			<a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=custom_css' ) ) ?>" class="nav-tab <?php echo ( 'custom_css' == $active ) ? 'nav-tab-active' : '' ?>"><?php _e( 'Custom CSS', 'formidable' ) ?></a>
95 95
         </h2>
96 96
 <?php
97 97
     }
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
      * @return The class for this icon
131 131
      */
132 132
 	public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
133
-        if ( 'arrow' == $type && is_numeric($key) ) {
133
+        if ( 'arrow' == $type && is_numeric( $key ) ) {
134 134
             //frm_arrowup6_icon
135 135
 			$arrow = array( '-' => 'down', '+' => 'up' );
136
-			$class = 'frm_arrow' . $arrow[ $icon ];
136
+			$class = 'frm_arrow' . $arrow[$icon];
137 137
         } else {
138 138
             //frm_minus1_icon
139
-            $key = str_replace('p', '', $key);
139
+            $key = str_replace( 'p', '', $key );
140 140
 			$plus = array( '-' => 'minus', '+' => 'plus' );
141
-			$class = 'frm_' . $plus[ $icon ];
141
+			$class = 'frm_' . $plus[$icon];
142 142
         }
143 143
 
144 144
         if ( $key ) {
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
 
157 157
         $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
158 158
 ?>
159
-    	<select name="<?php echo esc_attr( $frm_style->get_field_name($name) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
159
+    	<select name="<?php echo esc_attr( $frm_style->get_field_name( $name ) ) ?>" id="frm_<?php echo esc_attr( $name ) ?>" class="frm_icon_font frm_multiselect hide-if-js">
160 160
             <?php foreach ( $icons as $key => $icon ) { ?>
161
-			<option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[ $name ], $key ) ?>>
162
-                <?php echo '&#xe'. $icon['+'] .'; &#xe'. $icon['-'] .';'; ?>
161
+			<option value="<?php echo esc_attr( $key ) ?>" <?php selected( $style->post_content[$name], $key ) ?>>
162
+                <?php echo '&#xe' . $icon['+'] . '; &#xe' . $icon['-'] . ';'; ?>
163 163
             </option>
164 164
             <?php } ?>
165 165
     	</select>
166 166
 
167 167
         <div class="btn-group hide-if-no-js" id="frm_<?php echo esc_attr( $name ) ?>_select">
168 168
             <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
169
-				<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ) ?>"></i>
170
-				<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ) ?>"></i>
169
+				<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '+', $type ) ) ?>"></i>
170
+				<i class="frm_icon_font <?php echo esc_attr( self::icon_key_to_class( $style->post_content[$name], '-', $type ) ) ?>"></i>
171 171
                 <b class="caret"></b>
172 172
             </button>
173 173
             <ul class="multiselect-container frm-dropdown-menu">
@@ -190,19 +190,19 @@  discard block
 block discarded – undo
190 190
     }
191 191
 
192 192
 	public static function hex2rgb( $hex ) {
193
-        $hex = str_replace('#', '', $hex);
193
+        $hex = str_replace( '#', '', $hex );
194 194
 
195
-        if ( strlen($hex) == 3 ) {
196
-            $r = hexdec( substr($hex,0,1).substr($hex,0,1) );
197
-            $g = hexdec( substr($hex,1,1).substr($hex,1,1) );
198
-            $b = hexdec( substr($hex,2,1).substr($hex,2,1) );
195
+        if ( strlen( $hex ) == 3 ) {
196
+            $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) );
197
+            $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) );
198
+            $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) );
199 199
         } else {
200
-            $r = hexdec( substr($hex,0,2) );
201
-            $g = hexdec( substr($hex,2,2) );
202
-            $b = hexdec( substr($hex,4,2) );
200
+            $r = hexdec( substr( $hex, 0, 2 ) );
201
+            $g = hexdec( substr( $hex, 2, 2 ) );
202
+            $b = hexdec( substr( $hex, 4, 2 ) );
203 203
         }
204 204
 		$rgb = array( $r, $g, $b );
205
-        return implode(',', $rgb); // returns the rgb values separated by commas
205
+        return implode( ',', $rgb ); // returns the rgb values separated by commas
206 206
         //return $rgb; // returns an array with the rgb values
207 207
     }
208 208
 }
Please login to merge, or discard this patch.
classes/helpers/FrmXMLHelper.php 2 patches
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 				echo "\n" . $padding;
12 12
 				$tag = ( is_numeric( $ok ) ? 'key:' : '' ) . $ok;
13 13
 				echo '<' . $tag . '>';
14
-				self::get_xml_values( $ov, $padding .'    ' );
14
+				self::get_xml_values( $ov, $padding . '    ' );
15 15
 				if ( is_array( $ov ) ) {
16 16
 					echo "\n" . $padding;
17 17
 				}
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
 			'terms'    => array(),
37 37
         );
38 38
 
39
-        unset($defaults);
39
+        unset( $defaults );
40 40
 
41 41
 		if ( ! defined( 'WP_IMPORTING' ) ) {
42
-            define('WP_IMPORTING', true);
42
+            define( 'WP_IMPORTING', true );
43 43
         }
44 44
 
45 45
 		if ( ! class_exists( 'DOMDocument' ) ) {
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
53 53
 		}
54 54
 
55
-		if ( ! function_exists('simplexml_import_dom') ) {
55
+		if ( ! function_exists( 'simplexml_import_dom' ) ) {
56 56
 			return new WP_Error( 'SimpleXML_parse_error', __( 'Your server is missing the simplexml_import_dom function', 'formidable' ), libxml_get_errors() );
57 57
 		}
58 58
 
@@ -67,21 +67,21 @@  discard block
 block discarded – undo
67 67
         // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
68 68
 		foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
69 69
             // grab cats, tags, and terms, or forms or posts
70
-            if ( isset($xml->{$item_type} ) ) {
70
+            if ( isset( $xml->{$item_type} ) ) {
71 71
 				$function_name = 'import_xml_' . $item_type . 's';
72 72
 				$imported = self::$function_name( $xml->{$item_type}, $imported );
73 73
 				unset( $function_name, $xml->{$item_type} );
74 74
             }
75 75
         }
76 76
 
77
-	    $return = apply_filters('frm_importing_xml', $imported, $xml );
77
+	    $return = apply_filters( 'frm_importing_xml', $imported, $xml );
78 78
 
79 79
 	    return $return;
80 80
     }
81 81
 
82 82
 	public static function import_xml_terms( $terms, $imported ) {
83 83
         foreach ( $terms as $t ) {
84
-			if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
84
+			if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
85 85
 			    continue;
86 86
 			}
87 87
 
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
                 'description'   => (string) $t->term_description,
93 93
 				'parent'        => empty( $parent ) ? 0 : $parent,
94 94
                 'slug'          => (string) $t->term_slug,
95
-            ));
95
+            ) );
96 96
 
97 97
 			if ( $term && is_array( $term ) ) {
98
-                $imported['imported']['terms']++;
99
-				$imported['terms'][ (int) $t->term_id ] = $term['term_id'];
98
+                $imported['imported']['terms'] ++;
99
+				$imported['terms'][(int) $t->term_id] = $term['term_id'];
100 100
             }
101 101
 
102 102
 			unset( $term, $t );
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
                 'default_template' => (int) $item->default_template,
140 140
                 'editable'      => (int) $item->editable,
141 141
                 'status'        => (string) $item->status,
142
-                'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
143
-                'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
142
+                'parent_form_id' => isset( $item->parent_form_id ) ? (int) $item->parent_form_id : 0,
143
+                'created_at'    => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ),
144 144
             );
145 145
 
146
-            $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
146
+            $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
147 147
 
148 148
             // if template, allow to edit if form keys match, otherwise, creation date must also match
149 149
 			$edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template'] );
@@ -151,35 +151,35 @@  discard block
 block discarded – undo
151 151
                 $edit_query['created_at'] = $form['created_at'];
152 152
             }
153 153
 
154
-            $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
154
+            $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
155 155
 
156
-            $this_form = FrmForm::getAll($edit_query, '', 1);
157
-            unset($edit_query);
156
+            $this_form = FrmForm::getAll( $edit_query, '', 1 );
157
+            unset( $edit_query );
158 158
 
159 159
             if ( ! empty( $this_form ) ) {
160 160
                 $old_id = $form_id = $this_form->id;
161
-                FrmForm::update($form_id, $form );
162
-                $imported['updated']['forms']++;
161
+                FrmForm::update( $form_id, $form );
162
+                $imported['updated']['forms'] ++;
163 163
                 // Keep track of whether this specific form was updated or not
164
-				$imported['form_status'][ $form_id ] = 'updated';
164
+				$imported['form_status'][$form_id] = 'updated';
165 165
 
166 166
 				$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
167 167
                 $old_fields = array();
168 168
                 foreach ( $form_fields as $f ) {
169
-					$old_fields[ $f->id ] = $f;
170
-					$old_fields[ $f->field_key ] = $f->id;
171
-                    unset($f);
169
+					$old_fields[$f->id] = $f;
170
+					$old_fields[$f->field_key] = $f->id;
171
+                    unset( $f );
172 172
                 }
173 173
                 $form_fields = $old_fields;
174
-                unset($old_fields);
174
+                unset( $old_fields );
175 175
             } else {
176 176
                 $old_id = false;
177 177
                 //form does not exist, so create it
178 178
 				$form_id = FrmForm::create( $form );
179 179
                 if ( $form_id ) {
180
-                    $imported['imported']['forms']++;
180
+                    $imported['imported']['forms'] ++;
181 181
                     // Keep track of whether this specific form was updated or not
182
-					$imported['form_status'][ $form_id ] = 'imported';
182
+					$imported['form_status'][$form_id] = 'imported';
183 183
 					self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
184 184
                 }
185 185
             }
@@ -189,23 +189,23 @@  discard block
 block discarded – undo
189 189
     		// Delete any fields attached to this form that were not included in the template
190 190
     		if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
191 191
 				foreach ( $form_fields as $field ) {
192
-                    if ( is_object($field) ) {
193
-                        FrmField::destroy($field->id);
192
+                    if ( is_object( $field ) ) {
193
+                        FrmField::destroy( $field->id );
194 194
                     }
195
-                    unset($field);
195
+                    unset( $field );
196 196
                 }
197
-                unset($form_fields);
197
+                unset( $form_fields );
198 198
             }
199 199
 
200 200
 		    // Update field ids/keys to new ones
201 201
 			do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
202 202
 
203
-			$imported['forms'][ (int) $item->id ] = $form_id;
203
+			$imported['forms'][(int) $item->id] = $form_id;
204 204
 
205 205
             // Send pre 2.0 form options through function that creates actions
206 206
             self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
207 207
 
208
-		    unset($form, $item);
208
+		    unset( $form, $item );
209 209
 		}
210 210
 
211 211
 		self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		$regular_forms = array();
225 225
 
226 226
 		foreach ( $forms as $form ) {
227
-			$parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0;
227
+			$parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0;
228 228
 
229 229
 			if ( $parent_form_id ) {
230 230
 				$child_forms[] = $form;
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 	*/
247 247
 	private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
248 248
 		if ( $parent_form_id ) {
249
-			$child_forms[ $form_id ] = $parent_form_id;
249
+			$child_forms[$form_id] = $parent_form_id;
250 250
 		}
251 251
 	}
252 252
 
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
262 262
 		foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
263 263
 
264
-			if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) {
264
+			if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) {
265 265
 				// Update all children with this old parent_form_id
266
-				$new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ];
266
+				$new_parent_form_id = (int) $imported_forms[$old_parent_form_id];
267 267
 
268 268
 				FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) );
269 269
 			}
@@ -284,51 +284,51 @@  discard block
 block discarded – undo
284 284
 		        'name'          => (string) $field->name,
285 285
 		        'description'   => (string) $field->description,
286 286
 		        'type'          => (string) $field->type,
287
-		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
287
+		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ),
288 288
 		        'field_order'   => (int) $field->field_order,
289 289
 		        'form_id'       => (int) $form_id,
290 290
 		        'required'      => (int) $field->required,
291
-		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
291
+		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options ),
292 292
 				'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
293 293
 		    );
294 294
 
295
-		    if ( is_array($f['default_value']) && in_array($f['type'], array(
295
+		    if ( is_array( $f['default_value'] ) && in_array( $f['type'], array(
296 296
 		        'text', 'email', 'url', 'textarea',
297
-		        'number','phone', 'date', 'time',
297
+		        'number', 'phone', 'date', 'time',
298 298
 		        'hidden', 'password', 'tag', 'image',
299
-		    )) ) {
300
-		        if ( count($f['default_value']) === 1 ) {
301
-		            $f['default_value'] = '['. reset($f['default_value']) .']';
299
+		    ) ) ) {
300
+		        if ( count( $f['default_value'] ) === 1 ) {
301
+		            $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
302 302
 		        } else {
303
-		            $f['default_value'] = reset($f['default_value']);
303
+		            $f['default_value'] = reset( $f['default_value'] );
304 304
 		        }
305 305
 		    }
306 306
 
307
-		    $f = apply_filters('frm_duplicated_field', $f);
307
+		    $f = apply_filters( 'frm_duplicated_field', $f );
308 308
 
309 309
 			self::maybe_update_form_select( $f, $imported );
310 310
 
311
-		    if ( ! empty($this_form) ) {
311
+		    if ( ! empty( $this_form ) ) {
312 312
 		        // check for field to edit by field id
313
-				if ( isset( $form_fields[ $f['id'] ] ) ) {
313
+				if ( isset( $form_fields[$f['id']] ) ) {
314 314
 		            FrmField::update( $f['id'], $f );
315
-		            $imported['updated']['fields']++;
315
+		            $imported['updated']['fields'] ++;
316 316
 
317
-					unset( $form_fields[ $f['id'] ] );
317
+					unset( $form_fields[$f['id']] );
318 318
 
319 319
 		            //unset old field key
320
-					if ( isset( $form_fields[ $f['field_key'] ] ) ) {
321
-						unset( $form_fields[ $f['field_key'] ] );
320
+					if ( isset( $form_fields[$f['field_key']] ) ) {
321
+						unset( $form_fields[$f['field_key']] );
322 322
 					}
323
-				} else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
323
+				} else if ( isset( $form_fields[$f['field_key']] ) ) {
324 324
 		            // check for field to edit by field key
325
-		            unset($f['id']);
325
+		            unset( $f['id'] );
326 326
 
327
-					FrmField::update( $form_fields[ $f['field_key'] ], $f );
328
-		            $imported['updated']['fields']++;
327
+					FrmField::update( $form_fields[$f['field_key']], $f );
328
+		            $imported['updated']['fields'] ++;
329 329
 
330
-					unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
331
-					unset( $form_fields[ $f['field_key'] ] ); //unset old field key
330
+					unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id
331
+					unset( $form_fields[$f['field_key']] ); //unset old field key
332 332
 				} else {
333 333
 					$new_id = FrmField::create( $f );
334 334
 					if ( $new_id == false ) {
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 					}
337 337
 
338 338
 		            // if no matching field id or key in this form, create the field
339
-		            $imported['imported']['fields']++;
339
+		            $imported['imported']['fields'] ++;
340 340
 		        }
341 341
 			} else {
342 342
 				$new_id = FrmField::create( $f );
@@ -344,10 +344,10 @@  discard block
 block discarded – undo
344 344
 					continue;
345 345
 				}
346 346
 
347
-	            $imported['imported']['fields']++;
347
+	            $imported['imported']['fields'] ++;
348 348
 		    }
349 349
 
350
-			unset($field, $new_id);
350
+			unset( $field, $new_id );
351 351
 		}
352 352
 	}
353 353
 
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 		if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
367 367
 			if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
368 368
 				$form_select = $f['field_options']['form_select'];
369
-				if ( isset( $imported['forms'][ $form_select ] ) ) {
370
-					$f['field_options']['form_select'] = $imported['forms'][ $form_select ];
369
+				if ( isset( $imported['forms'][$form_select] ) ) {
370
+					$f['field_options']['form_select'] = $imported['forms'][$form_select];
371 371
 				}
372 372
 			}
373 373
 		}
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 				'post_id'       => (int) $item->post_id,
396 396
 				'post_parent'   => (int) $item->post_parent,
397 397
 				'menu_order'    => (int) $item->menu_order,
398
-				'post_content'  => FrmFieldsHelper::switch_field_ids((string) $item->content),
399
-				'post_excerpt'  => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
398
+				'post_content'  => FrmFieldsHelper::switch_field_ids( (string) $item->content ),
399
+				'post_excerpt'  => FrmFieldsHelper::switch_field_ids( (string) $item->excerpt ),
400 400
 				'is_sticky'     => (string) $item->is_sticky,
401 401
 				'comment_status' => (string) $item->comment_status,
402 402
 				'post_date'     => (string) $item->post_date,
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 			);
408 408
 
409 409
             $old_id = $post['post_id'];
410
-            self::populate_post($post, $item, $imported);
410
+            self::populate_post( $post, $item, $imported );
411 411
 
412
-			unset($item);
412
+			unset( $item );
413 413
 
414 414
 			$post_id = false;
415 415
             if ( $post['post_type'] == $form_action_type ) {
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 				if ( $action_control ) {
418 418
 					$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
419 419
 				}
420
-                unset($action_control);
420
+                unset( $action_control );
421 421
             } else if ( $post['post_type'] == 'frm_styles' ) {
422 422
                 // Properly encode post content before inserting the post
423 423
                 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
@@ -430,26 +430,26 @@  discard block
 block discarded – undo
430 430
                 $post_id = wp_insert_post( $post );
431 431
             }
432 432
 
433
-            if ( ! is_numeric($post_id) ) {
433
+            if ( ! is_numeric( $post_id ) ) {
434 434
                 continue;
435 435
             }
436 436
 
437
-            self::update_postmeta($post, $post_id);
437
+            self::update_postmeta( $post, $post_id );
438 438
 
439 439
             $this_type = 'posts';
440
-			if ( isset( $post_types[ $post['post_type'] ] ) ) {
441
-				$this_type = $post_types[ $post['post_type'] ];
440
+			if ( isset( $post_types[$post['post_type']] ) ) {
441
+				$this_type = $post_types[$post['post_type']];
442 442
             }
443 443
 
444
-            if ( isset($post['ID']) && $post_id == $post['ID'] ) {
445
-                $imported['updated'][ $this_type ]++;
444
+            if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
445
+                $imported['updated'][$this_type] ++;
446 446
             } else {
447
-                $imported['imported'][ $this_type ]++;
447
+                $imported['imported'][$this_type] ++;
448 448
             }
449 449
 
450
-            unset($post);
450
+            unset( $post );
451 451
 
452
-			$imported['posts'][ (int) $old_id ] = $post_id;
452
+			$imported['posts'][(int) $old_id] = $post_id;
453 453
 		}
454 454
 
455 455
 		self::maybe_update_stylesheet( $imported );
@@ -458,23 +458,23 @@  discard block
 block discarded – undo
458 458
     }
459 459
 
460 460
     private static function populate_post( &$post, $item, $imported ) {
461
-		if ( isset($item->attachment_url) ) {
461
+		if ( isset( $item->attachment_url ) ) {
462 462
 			$post['attachment_url'] = (string) $item->attachment_url;
463 463
 		}
464 464
 
465
-		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
465
+		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) {
466 466
 		    // update to new form id
467
-		    $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
467
+		    $post['menu_order'] = $imported['forms'][(int) $post['menu_order']];
468 468
 		}
469 469
 
470 470
 		foreach ( $item->postmeta as $meta ) {
471
-		    self::populate_postmeta($post, $meta, $imported);
472
-			unset($meta);
471
+		    self::populate_postmeta( $post, $meta, $imported );
472
+			unset( $meta );
473 473
 		}
474 474
 
475
-        self::populate_taxonomies($post, $item);
475
+        self::populate_taxonomies( $post, $item );
476 476
 
477
-        self::maybe_editing_post($post);
477
+        self::maybe_editing_post( $post );
478 478
     }
479 479
 
480 480
     private static function populate_postmeta( &$post, $meta, $imported ) {
@@ -486,27 +486,27 @@  discard block
 block discarded – undo
486 486
 		);
487 487
 
488 488
 		//switch old form and field ids to new ones
489
-		if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
490
-		    $m['value'] = $imported['forms'][ (int) $m['value'] ];
489
+		if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) {
490
+		    $m['value'] = $imported['forms'][(int) $m['value']];
491 491
 		} else {
492
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
492
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
493 493
 
494
-		    if ( ! empty($frm_duplicate_ids) ) {
494
+		    if ( ! empty( $frm_duplicate_ids ) ) {
495 495
 
496 496
 		        if ( $m['key'] == 'frm_dyncontent' ) {
497
-		            $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
497
+		            $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
498 498
     		    } else if ( $m['key'] == 'frm_options' ) {
499 499
 
500 500
 					foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
501
-						if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
502
-							$m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
501
+						if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) {
502
+							$m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
503 503
     		            }
504 504
     		        }
505 505
 
506 506
                     $check_dup_array = array();
507 507
     		        if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
508
-    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
509
-    		                $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
508
+    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) {
509
+    		                $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']];
510 510
     		            } else if ( is_array( $m['value']['order_by'] ) ) {
511 511
                             $check_dup_array[] = 'order_by';
512 512
     		            }
@@ -517,22 +517,22 @@  discard block
 block discarded – undo
517 517
     		        }
518 518
 
519 519
                     foreach ( $check_dup_array as $check_k ) {
520
-						foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
521
-							if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
522
-								$m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
520
+						foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
521
+							if ( isset( $frm_duplicate_ids[$mv] ) ) {
522
+								$m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
523 523
 		                    }
524
-		                    unset($mk, $mv);
524
+		                    unset( $mk, $mv );
525 525
 		                }
526 526
                     }
527 527
     		    }
528 528
 		    }
529 529
 		}
530 530
 
531
-		if ( ! is_array($m['value']) ) {
532
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
531
+		if ( ! is_array( $m['value'] ) ) {
532
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
533 533
 		}
534 534
 
535
-		$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
535
+		$post['postmeta'][(string) $meta->meta_key] = $m['value'];
536 536
     }
537 537
 
538 538
     /**
@@ -548,23 +548,23 @@  discard block
 block discarded – undo
548 548
             }
549 549
 
550 550
 		    $taxonomy = (string) $att['domain'];
551
-		    if ( is_taxonomy_hierarchical($taxonomy) ) {
551
+		    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
552 552
 		        $name = (string) $att['nicename'];
553
-		        $h_term = get_term_by('slug', $name, $taxonomy);
553
+		        $h_term = get_term_by( 'slug', $name, $taxonomy );
554 554
 		        if ( $h_term ) {
555 555
 		            $name = $h_term->term_id;
556 556
 		        }
557
-		        unset($h_term);
557
+		        unset( $h_term );
558 558
 		    } else {
559 559
 		        $name = (string) $c;
560 560
 		    }
561 561
 
562
-			if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
563
-				$post['tax_input'][ $taxonomy ] = array();
562
+			if ( ! isset( $post['tax_input'][$taxonomy] ) ) {
563
+				$post['tax_input'][$taxonomy] = array();
564 564
 			}
565 565
 
566
-			$post['tax_input'][ $taxonomy ][] = $name;
567
-		    unset($name);
566
+			$post['tax_input'][$taxonomy][] = $name;
567
+		    unset( $name );
568 568
 		}
569 569
     }
570 570
 
@@ -581,29 +581,29 @@  discard block
 block discarded – undo
581 581
 
582 582
 		if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
583 583
 		    $match_by['include'] = $post['post_id'];
584
-		    unset($match_by['name']);
584
+		    unset( $match_by['name'] );
585 585
 		}
586 586
 
587
-		$editing = get_posts($match_by);
587
+		$editing = get_posts( $match_by );
588 588
 
589
-        if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
589
+        if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) {
590 590
             // set the id of the post to edit
591
-            $post['ID'] = current($editing)->ID;
591
+            $post['ID'] = current( $editing )->ID;
592 592
         }
593 593
     }
594 594
 
595 595
     private static function update_postmeta( &$post, $post_id ) {
596 596
         foreach ( $post['postmeta'] as $k => $v ) {
597 597
             if ( '_edit_last' == $k ) {
598
-                $v = FrmAppHelper::get_user_id_param($v);
598
+                $v = FrmAppHelper::get_user_id_param( $v );
599 599
             } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
600 600
                 //change the attachment ID
601
-                $v = FrmProXMLHelper::get_file_id($v);
601
+                $v = FrmProXMLHelper::get_file_id( $v );
602 602
             }
603 603
 
604
-            update_post_meta($post_id, $k, $v);
604
+            update_post_meta( $post_id, $k, $v );
605 605
 
606
-            unset($k, $v);
606
+            unset( $k, $v );
607 607
         }
608 608
     }
609 609
 
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
      * @param string $message
621 621
      */
622 622
 	public static function parse_message( $result, &$message, &$errors ) {
623
-        if ( is_wp_error($result) ) {
623
+        if ( is_wp_error( $result ) ) {
624 624
             $errors[] = $result->get_error_message();
625 625
         } else if ( ! $result ) {
626 626
             return;
627 627
         }
628 628
 
629
-        if ( ! is_array($result) ) {
629
+        if ( ! is_array( $result ) ) {
630 630
             $message = is_string( $result ) ? $result : print_r( $result, 1 );
631 631
             return;
632 632
         }
@@ -638,20 +638,20 @@  discard block
 block discarded – undo
638 638
 
639 639
         $message = '<ul>';
640 640
         foreach ( $result as $type => $results ) {
641
-			if ( ! isset( $t_strings[ $type ] ) ) {
641
+			if ( ! isset( $t_strings[$type] ) ) {
642 642
                 // only print imported and updated
643 643
                 continue;
644 644
             }
645 645
 
646 646
             $s_message = array();
647 647
             foreach ( $results as $k => $m ) {
648
-                self::item_count_message($m, $k, $s_message);
649
-                unset($k, $m);
648
+                self::item_count_message( $m, $k, $s_message );
649
+                unset( $k, $m );
650 650
             }
651 651
 
652
-            if ( ! empty($s_message) ) {
653
-				$message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
654
-                $message .= implode(', ', $s_message);
652
+            if ( ! empty( $s_message ) ) {
653
+				$message .= '<li><strong>' . $t_strings[$type] . ':</strong> ';
654
+                $message .= implode( ', ', $s_message );
655 655
                 $message .= '</li>';
656 656
             }
657 657
         }
@@ -680,18 +680,18 @@  discard block
 block discarded – undo
680 680
             'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
681 681
         );
682 682
 
683
-		$s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
683
+		$s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type );
684 684
     }
685 685
 
686 686
 	public static function cdata( $str ) {
687
-	    $str = maybe_unserialize($str);
688
-	    if ( is_array($str) ) {
689
-	        $str = json_encode($str);
687
+	    $str = maybe_unserialize( $str );
688
+	    if ( is_array( $str ) ) {
689
+	        $str = json_encode( $str );
690 690
 		} else if ( seems_utf8( $str ) == false ) {
691 691
 			$str = utf8_encode( $str );
692 692
 		}
693 693
 
694
-        if ( is_numeric($str) ) {
694
+        if ( is_numeric( $str ) ) {
695 695
             return $str;
696 696
         }
697 697
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
     * @param string $post_type
724 724
     */
725 725
     private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
726
-        if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
726
+        if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
727 727
             return;
728 728
         }
729 729
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
             'menu_order'    => $form_id,
735 735
             'post_status'   => 'publish',
736 736
             'post_content'  => array(),
737
-            'post_name'     => $form_id .'_wppost_1',
737
+            'post_name'     => $form_id . '_wppost_1',
738 738
         );
739 739
 
740 740
         $post_settings = array(
@@ -744,10 +744,10 @@  discard block
 block discarded – undo
744 744
         );
745 745
 
746 746
         foreach ( $post_settings as $post_setting ) {
747
-			if ( isset( $form_options[ $post_setting ] ) ) {
748
-				$new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
747
+			if ( isset( $form_options[$post_setting] ) ) {
748
+				$new_action['post_content'][$post_setting] = $form_options[$post_setting];
749 749
             }
750
-            unset($post_setting);
750
+            unset( $post_setting );
751 751
         }
752 752
 
753 753
 		$new_action['event'] = array( 'create', 'update' );
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 
762 762
 			$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
763 763
         }
764
-        $new_action['post_content'] = json_encode($new_action['post_content']);
764
+        $new_action['post_content'] = json_encode( $new_action['post_content'] );
765 765
 
766 766
         $exists = get_posts( array(
767 767
             'name'          => $new_action['post_name'],
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
         if ( ! $exists ) {
774 774
 			// this isn't an email, but we need to use a class that will always be included
775 775
 			FrmAppHelper::save_json_post( $new_action );
776
-            $imported['imported']['actions']++;
776
+            $imported['imported']['actions'] ++;
777 777
         }
778 778
     }
779 779
 
@@ -805,11 +805,11 @@  discard block
 block discarded – undo
805 805
         foreach ( $post_content as $key => $setting ) {
806 806
             if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
807 807
                 // Replace old IDs with new IDs
808
-				$post_content[ $key ] = str_replace( $old, $new, $setting );
808
+				$post_content[$key] = str_replace( $old, $new, $setting );
809 809
             } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
810 810
                 foreach ( $setting as $k => $val ) {
811 811
                     // Replace old IDs with new IDs
812
-					$post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
812
+					$post_content[$key][$k] = str_replace( $old, $new, $val );
813 813
                 }
814 814
             }
815 815
             unset( $key, $setting );
@@ -832,14 +832,14 @@  discard block
 block discarded – undo
832 832
         // Migrate autoresponders
833 833
         self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
834 834
 
835
-        if (  empty( $notifications ) ) {
835
+        if ( empty( $notifications ) ) {
836 836
             return;
837 837
         }
838 838
 
839 839
         foreach ( $notifications as $new_notification ) {
840 840
             $new_notification['post_type']      = $post_type;
841 841
             $new_notification['post_excerpt']   = 'email';
842
-			$new_notification['post_title']     = __( 'Email Notification', 'formidable' );
842
+			$new_notification['post_title'] = __( 'Email Notification', 'formidable' );
843 843
             $new_notification['menu_order']     = $form_id;
844 844
             $new_notification['post_status']    = 'publish';
845 845
 
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 				// Switch all other field IDs in email
853 853
                 $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
854 854
             }
855
-            $new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
855
+            $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
856 856
 
857 857
             $exists = get_posts( array(
858 858
                 'name'          => $new_notification['post_name'],
@@ -861,11 +861,11 @@  discard block
 block discarded – undo
861 861
                 'numberposts'   => 1,
862 862
             ) );
863 863
 
864
-            if ( empty($exists) ) {
864
+            if ( empty( $exists ) ) {
865 865
 				FrmAppHelper::save_json_post( $new_notification );
866
-                $imported['imported']['actions']++;
866
+                $imported['imported']['actions'] ++;
867 867
             }
868
-            unset($new_notification);
868
+            unset( $new_notification );
869 869
         }
870 870
     }
871 871
 
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 			$form_options['notification'] = array( 0 => $form_options['notification'] );
879 879
         }
880 880
 
881
-        if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
881
+        if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
882 882
             foreach ( $form_options['notification'] as $email_key => $notification ) {
883 883
 
884 884
                 $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
@@ -906,12 +906,12 @@  discard block
 block discarded – undo
906 906
         // Format the reply to email and name
907 907
         $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
908 908
         foreach ( $reply_fields as $f => $val ) {
909
-			if ( isset( $notification[ $f ] ) ) {
910
-				$atts[ $f ] = $notification[ $f ];
911
-				if ( 'custom' == $notification[ $f ] ) {
912
-					$atts[ $f ] = $notification[ 'cust_' . $f ];
913
-				} else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
914
-					$atts[ $f ] = '[' . $atts[ $f ] . ']';
909
+			if ( isset( $notification[$f] ) ) {
910
+				$atts[$f] = $notification[$f];
911
+				if ( 'custom' == $notification[$f] ) {
912
+					$atts[$f] = $notification['cust_' . $f];
913
+				} else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) {
914
+					$atts[$f] = '[' . $atts[$f] . ']';
915 915
                 }
916 916
             }
917 917
             unset( $f, $val );
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 		$atts['event'] = array( 'create' );
922 922
         if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
923 923
             $atts['event'][] = 'update';
924
-        } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
924
+        } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
925 925
 			$atts['event'] = array( 'update' );
926 926
         }
927 927
     }
@@ -942,18 +942,18 @@  discard block
 block discarded – undo
942 942
         foreach ( $atts['email_to'] as $key => $email_field ) {
943 943
 
944 944
             if ( is_numeric( $email_field ) ) {
945
-				$atts['email_to'][ $key ] = '[' . $email_field . ']';
945
+				$atts['email_to'][$key] = '[' . $email_field . ']';
946 946
             }
947 947
 
948
-            if ( strpos( $email_field, '|') ) {
948
+            if ( strpos( $email_field, '|' ) ) {
949 949
                 $email_opt = explode( '|', $email_field );
950 950
                 if ( isset( $email_opt[0] ) ) {
951
-					$atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
951
+					$atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
952 952
                 }
953 953
                 unset( $email_opt );
954 954
             }
955 955
         }
956
-        $atts['email_to'] = implode(', ', $atts['email_to']);
956
+        $atts['email_to'] = implode( ', ', $atts['email_to'] );
957 957
     }
958 958
 
959 959
     private static function setup_new_notification( &$new_notification, $notification, $atts ) {
@@ -963,18 +963,18 @@  discard block
 block discarded – undo
963 963
                 'email_to'      => $atts['email_to'],
964 964
                 'event'         => $atts['event'],
965 965
             ),
966
-            'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
966
+            'post_name'         => $atts['form_id'] . '_email_' . $atts['email_key'],
967 967
         );
968 968
 
969 969
         // Add more fields to the new notification
970 970
         $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
971 971
         foreach ( $add_fields as $add_field ) {
972
-			if ( isset( $notification[ $add_field ] ) ) {
973
-				$new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
972
+			if ( isset( $notification[$add_field] ) ) {
973
+				$new_notification['post_content'][$add_field] = $notification[$add_field];
974 974
             } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
975
-				$new_notification['post_content'][ $add_field ] = 0;
975
+				$new_notification['post_content'][$add_field] = 0;
976 976
             } else {
977
-				$new_notification['post_content'][ $add_field ] = '';
977
+				$new_notification['post_content'][$add_field] = '';
978 978
             }
979 979
             unset( $add_field );
980 980
         }
@@ -984,7 +984,7 @@  discard block
 block discarded – undo
984 984
 
985 985
         // Set from
986 986
 		if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
987
-            $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
987
+            $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>';
988 988
         }
989 989
     }
990 990
 
@@ -998,50 +998,50 @@  discard block
 block discarded – undo
998 998
 		if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
999 999
 			foreach ( $post_content['conditions'] as $email_key => $val ) {
1000 1000
 				if ( is_numeric( $email_key ) ) {
1001
-					$post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1001
+					$post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1002 1002
 				}
1003
-				unset( $email_key, $val);
1003
+				unset( $email_key, $val );
1004 1004
 			}
1005 1005
 		}
1006 1006
 	}
1007 1007
 
1008 1008
     private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1009
-        if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1009
+        if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1010 1010
             // migrate autoresponder
1011 1011
 
1012
-            $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1013
-            if ( strpos($email_field, '|') ) {
1012
+            $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
1013
+            if ( strpos( $email_field, '|' ) ) {
1014 1014
                 // data from entries field
1015
-                $email_field = explode('|', $email_field);
1016
-                if ( isset($email_field[1]) ) {
1015
+                $email_field = explode( '|', $email_field );
1016
+                if ( isset( $email_field[1] ) ) {
1017 1017
                     $email_field = $email_field[1];
1018 1018
                 }
1019 1019
             }
1020
-            if ( is_numeric($email_field) && ! empty($email_field) ) {
1021
-                $email_field = '['. $email_field .']';
1020
+            if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
1021
+                $email_field = '[' . $email_field . ']';
1022 1022
             }
1023 1023
 
1024 1024
             $notification = $form_options;
1025 1025
             $new_notification2 = array(
1026 1026
                 'post_content'  => array(
1027 1027
                     'email_message' => $notification['ar_email_message'],
1028
-                    'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1028
+                    'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1029 1029
                     'email_to'      => $email_field,
1030
-                    'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1030
+                    'plain_text'    => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1031 1031
                     'inc_user_info' => 0,
1032 1032
                 ),
1033
-                'post_name'     => $form_id .'_email_'. count( $notifications ),
1033
+                'post_name'     => $form_id . '_email_' . count( $notifications ),
1034 1034
             );
1035 1035
 
1036
-            $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1037
-            $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1036
+            $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1037
+            $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
1038 1038
 
1039 1039
 			if ( ! empty( $reply_to ) ) {
1040 1040
 				$new_notification2['post_content']['reply_to'] = $reply_to;
1041 1041
 			}
1042 1042
 
1043 1043
 			if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
1044
-                $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1044
+                $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>';
1045 1045
 			}
1046 1046
 
1047 1047
             $notifications[] = $new_notification2;
Please login to merge, or discard this patch.
Indentation   +595 added lines, -595 removed lines patch added patch discarded remove patch
@@ -23,30 +23,30 @@  discard block
 block discarded – undo
23 23
 	}
24 24
 
25 25
 	public static function import_xml( $file ) {
26
-        $defaults = array(
27
-            'forms' => 0, 'fields' => 0, 'terms' => 0,
28
-            'posts' => 0, 'views' => 0, 'actions' => 0,
29
-            'styles' => 0,
30
-        );
31
-
32
-        $imported = array(
33
-            'imported' => $defaults,
26
+		$defaults = array(
27
+			'forms' => 0, 'fields' => 0, 'terms' => 0,
28
+			'posts' => 0, 'views' => 0, 'actions' => 0,
29
+			'styles' => 0,
30
+		);
31
+
32
+		$imported = array(
33
+			'imported' => $defaults,
34 34
 			'updated'  => $defaults,
35 35
 			'forms'    => array(),
36 36
 			'terms'    => array(),
37
-        );
37
+		);
38 38
 
39
-        unset($defaults);
39
+		unset($defaults);
40 40
 
41 41
 		if ( ! defined( 'WP_IMPORTING' ) ) {
42
-            define('WP_IMPORTING', true);
43
-        }
42
+			define('WP_IMPORTING', true);
43
+		}
44 44
 
45 45
 		if ( ! class_exists( 'DOMDocument' ) ) {
46
-            return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
47
-        }
46
+			return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
47
+		}
48 48
 
49
-        $dom = new DOMDocument;
49
+		$dom = new DOMDocument;
50 50
 		$success = $dom->loadXML( file_get_contents( $file ) );
51 51
 		if ( ! $success ) {
52 52
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
@@ -64,45 +64,45 @@  discard block
 block discarded – undo
64 64
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
65 65
 		}
66 66
 
67
-        // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
67
+		// add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
68 68
 		foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
69
-            // grab cats, tags, and terms, or forms or posts
70
-            if ( isset($xml->{$item_type} ) ) {
69
+			// grab cats, tags, and terms, or forms or posts
70
+			if ( isset($xml->{$item_type} ) ) {
71 71
 				$function_name = 'import_xml_' . $item_type . 's';
72 72
 				$imported = self::$function_name( $xml->{$item_type}, $imported );
73 73
 				unset( $function_name, $xml->{$item_type} );
74
-            }
75
-        }
74
+			}
75
+		}
76 76
 
77
-	    $return = apply_filters('frm_importing_xml', $imported, $xml );
77
+		$return = apply_filters('frm_importing_xml', $imported, $xml );
78 78
 
79
-	    return $return;
80
-    }
79
+		return $return;
80
+	}
81 81
 
82 82
 	public static function import_xml_terms( $terms, $imported ) {
83
-        foreach ( $terms as $t ) {
83
+		foreach ( $terms as $t ) {
84 84
 			if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
85
-			    continue;
85
+				continue;
86 86
 			}
87 87
 
88 88
 			$parent = self::get_term_parent_id( $t );
89 89
 
90 90
 			$term = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
91
-                'slug'          => (string) $t->term_slug,
92
-                'description'   => (string) $t->term_description,
91
+				'slug'          => (string) $t->term_slug,
92
+				'description'   => (string) $t->term_description,
93 93
 				'parent'        => empty( $parent ) ? 0 : $parent,
94
-            ));
94
+			));
95 95
 
96 96
 			if ( $term && is_array( $term ) ) {
97
-                $imported['imported']['terms']++;
97
+				$imported['imported']['terms']++;
98 98
 				$imported['terms'][ (int) $t->term_id ] = $term['term_id'];
99
-            }
99
+			}
100 100
 
101 101
 			unset( $term, $t );
102 102
 		}
103 103
 
104 104
 		return $imported;
105
-    }
105
+	}
106 106
 
107 107
 	/**
108 108
 	 * @since 2.0.8
@@ -127,99 +127,99 @@  discard block
 block discarded – undo
127 127
 		self::put_child_forms_first( $forms );
128 128
 
129 129
 		foreach ( $forms as $item ) {
130
-            $form = array(
131
-                'id'            => (int) $item->id,
132
-                'form_key'      => (string) $item->form_key,
133
-                'name'          => (string) $item->name,
134
-                'description'   => (string) $item->description,
135
-                'options'       => (string) $item->options,
136
-                'logged_in'     => (int) $item->logged_in,
137
-                'is_template'   => (int) $item->is_template,
138
-                'default_template' => (int) $item->default_template,
139
-                'editable'      => (int) $item->editable,
140
-                'status'        => (string) $item->status,
141
-                'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
142
-                'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
143
-            );
144
-
145
-            $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
130
+			$form = array(
131
+				'id'            => (int) $item->id,
132
+				'form_key'      => (string) $item->form_key,
133
+				'name'          => (string) $item->name,
134
+				'description'   => (string) $item->description,
135
+				'options'       => (string) $item->options,
136
+				'logged_in'     => (int) $item->logged_in,
137
+				'is_template'   => (int) $item->is_template,
138
+				'default_template' => (int) $item->default_template,
139
+				'editable'      => (int) $item->editable,
140
+				'status'        => (string) $item->status,
141
+				'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
142
+				'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
143
+			);
144
+
145
+			$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
146 146
 
147 147
 			self::update_custom_style_setting_on_import( $form );
148 148
 
149
-            // if template, allow to edit if form keys match, otherwise, creation date must also match
149
+			// if template, allow to edit if form keys match, otherwise, creation date must also match
150 150
 			$edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template'] );
151
-            if ( ! $form['is_template'] ) {
152
-                $edit_query['created_at'] = $form['created_at'];
153
-            }
151
+			if ( ! $form['is_template'] ) {
152
+				$edit_query['created_at'] = $form['created_at'];
153
+			}
154 154
 
155
-            $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
155
+			$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
156 156
 
157
-            $this_form = FrmForm::getAll($edit_query, '', 1);
158
-            unset($edit_query);
157
+			$this_form = FrmForm::getAll($edit_query, '', 1);
158
+			unset($edit_query);
159 159
 
160
-            if ( ! empty( $this_form ) ) {
161
-                $old_id = $form_id = $this_form->id;
162
-                FrmForm::update($form_id, $form );
163
-                $imported['updated']['forms']++;
164
-                // Keep track of whether this specific form was updated or not
160
+			if ( ! empty( $this_form ) ) {
161
+				$old_id = $form_id = $this_form->id;
162
+				FrmForm::update($form_id, $form );
163
+				$imported['updated']['forms']++;
164
+				// Keep track of whether this specific form was updated or not
165 165
 				$imported['form_status'][ $form_id ] = 'updated';
166 166
 
167 167
 				$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
168
-                $old_fields = array();
169
-                foreach ( $form_fields as $f ) {
168
+				$old_fields = array();
169
+				foreach ( $form_fields as $f ) {
170 170
 					$old_fields[ $f->id ] = $f;
171 171
 					$old_fields[ $f->field_key ] = $f->id;
172
-                    unset($f);
173
-                }
174
-                $form_fields = $old_fields;
175
-                unset($old_fields);
176
-            } else {
177
-                $old_id = false;
178
-                //form does not exist, so create it
172
+					unset($f);
173
+				}
174
+				$form_fields = $old_fields;
175
+				unset($old_fields);
176
+			} else {
177
+				$old_id = false;
178
+				//form does not exist, so create it
179 179
 				$form_id = FrmForm::create( $form );
180
-                if ( $form_id ) {
181
-                    $imported['imported']['forms']++;
182
-                    // Keep track of whether this specific form was updated or not
180
+				if ( $form_id ) {
181
+					$imported['imported']['forms']++;
182
+					// Keep track of whether this specific form was updated or not
183 183
 					$imported['form_status'][ $form_id ] = 'imported';
184 184
 					self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
185
-                }
186
-            }
185
+				}
186
+			}
187 187
 
188
-    		self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
188
+			self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
189 189
 
190
-    		// Delete any fields attached to this form that were not included in the template
191
-    		if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
190
+			// Delete any fields attached to this form that were not included in the template
191
+			if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
192 192
 				foreach ( $form_fields as $field ) {
193
-                    if ( is_object($field) ) {
194
-                        FrmField::destroy($field->id);
195
-                    }
196
-                    unset($field);
197
-                }
198
-                unset($form_fields);
199
-            }
200
-
201
-		    // Update field ids/keys to new ones
193
+					if ( is_object($field) ) {
194
+						FrmField::destroy($field->id);
195
+					}
196
+					unset($field);
197
+				}
198
+				unset($form_fields);
199
+			}
200
+
201
+			// Update field ids/keys to new ones
202 202
 			do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
203 203
 
204 204
 			$imported['forms'][ (int) $item->id ] = $form_id;
205 205
 
206
-            // Send pre 2.0 form options through function that creates actions
207
-            self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
206
+			// Send pre 2.0 form options through function that creates actions
207
+			self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
208 208
 
209
-		    unset($form, $item);
209
+			unset($form, $item);
210 210
 		}
211 211
 
212 212
 		self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
213 213
 
214 214
 		return $imported;
215
-    }
215
+	}
216 216
 
217 217
 	/**
218
-	* Put child forms first so they will be imported before parents
219
-	*
220
-	* @since 2.0.16
221
-	* @param array $forms
222
-	*/
218
+	 * Put child forms first so they will be imported before parents
219
+	 *
220
+	 * @since 2.0.16
221
+	 * @param array $forms
222
+	 */
223 223
 	private static function put_child_forms_first( &$forms ) {
224 224
 		$child_forms = array();
225 225
 		$regular_forms = array();
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
 	}
239 239
 
240 240
 	/**
241
-	* Keep track of all imported child forms
242
-	*
243
-	* @since 2.0.16
244
-	* @param int $form_id
245
-	* @param int $parent_form_id
246
-	* @param array $child_forms
247
-	*/
241
+	 * Keep track of all imported child forms
242
+	 *
243
+	 * @since 2.0.16
244
+	 * @param int $form_id
245
+	 * @param int $parent_form_id
246
+	 * @param array $child_forms
247
+	 */
248 248
 	private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
249 249
 		if ( $parent_form_id ) {
250 250
 			$child_forms[ $form_id ] = $parent_form_id;
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
 	}
253 253
 
254 254
 	/**
255
-	* Update the parent_form_id on imported child forms
256
-	* Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
257
-	*
258
-	* @since 2.0.6
259
-	* @param array $imported_forms
260
-	* @param array $child_forms
261
-	*/
255
+	 * Update the parent_form_id on imported child forms
256
+	 * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
257
+	 *
258
+	 * @since 2.0.6
259
+	 * @param array $imported_forms
260
+	 * @param array $child_forms
261
+	 */
262 262
 	private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
263 263
 		foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
264 264
 
@@ -272,61 +272,61 @@  discard block
 block discarded – undo
272 272
 	}
273 273
 
274 274
 	/**
275
-	* Import all fields for a form
276
-	* @since 2.0.13
277
-	*
278
-	* TODO: Cut down on params
279
-	*/
275
+	 * Import all fields for a form
276
+	 * @since 2.0.13
277
+	 *
278
+	 * TODO: Cut down on params
279
+	 */
280 280
 	private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
281 281
 		foreach ( $xml_fields as $field ) {
282
-		    $f = array(
283
-		        'id'            => (int) $field->id,
284
-		        'field_key'     => (string) $field->field_key,
285
-		        'name'          => (string) $field->name,
286
-		        'description'   => (string) $field->description,
287
-		        'type'          => (string) $field->type,
288
-		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
289
-		        'field_order'   => (int) $field->field_order,
290
-		        'form_id'       => (int) $form_id,
291
-		        'required'      => (int) $field->required,
292
-		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
282
+			$f = array(
283
+				'id'            => (int) $field->id,
284
+				'field_key'     => (string) $field->field_key,
285
+				'name'          => (string) $field->name,
286
+				'description'   => (string) $field->description,
287
+				'type'          => (string) $field->type,
288
+				'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
289
+				'field_order'   => (int) $field->field_order,
290
+				'form_id'       => (int) $form_id,
291
+				'required'      => (int) $field->required,
292
+				'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
293 293
 				'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
294
-		    );
295
-
296
-		    if ( is_array($f['default_value']) && in_array($f['type'], array(
297
-		        'text', 'email', 'url', 'textarea',
298
-		        'number','phone', 'date', 'time',
299
-		        'hidden', 'password', 'tag', 'image',
300
-		    )) ) {
301
-		        if ( count($f['default_value']) === 1 ) {
302
-		            $f['default_value'] = '['. reset($f['default_value']) .']';
303
-		        } else {
304
-		            $f['default_value'] = reset($f['default_value']);
305
-		        }
306
-		    }
307
-
308
-		    $f = apply_filters('frm_duplicated_field', $f);
294
+			);
295
+
296
+			if ( is_array($f['default_value']) && in_array($f['type'], array(
297
+				'text', 'email', 'url', 'textarea',
298
+				'number','phone', 'date', 'time',
299
+				'hidden', 'password', 'tag', 'image',
300
+			)) ) {
301
+				if ( count($f['default_value']) === 1 ) {
302
+					$f['default_value'] = '['. reset($f['default_value']) .']';
303
+				} else {
304
+					$f['default_value'] = reset($f['default_value']);
305
+				}
306
+			}
307
+
308
+			$f = apply_filters('frm_duplicated_field', $f);
309 309
 
310 310
 			self::maybe_update_form_select( $f, $imported );
311 311
 
312
-		    if ( ! empty($this_form) ) {
313
-		        // check for field to edit by field id
312
+			if ( ! empty($this_form) ) {
313
+				// check for field to edit by field id
314 314
 				if ( isset( $form_fields[ $f['id'] ] ) ) {
315
-		            FrmField::update( $f['id'], $f );
316
-		            $imported['updated']['fields']++;
315
+					FrmField::update( $f['id'], $f );
316
+					$imported['updated']['fields']++;
317 317
 
318 318
 					unset( $form_fields[ $f['id'] ] );
319 319
 
320
-		            //unset old field key
320
+					//unset old field key
321 321
 					if ( isset( $form_fields[ $f['field_key'] ] ) ) {
322 322
 						unset( $form_fields[ $f['field_key'] ] );
323 323
 					}
324 324
 				} else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
325
-		            // check for field to edit by field key
326
-		            unset($f['id']);
325
+					// check for field to edit by field key
326
+					unset($f['id']);
327 327
 
328 328
 					FrmField::update( $form_fields[ $f['field_key'] ], $f );
329
-		            $imported['updated']['fields']++;
329
+					$imported['updated']['fields']++;
330 330
 
331 331
 					unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
332 332
 					unset( $form_fields[ $f['field_key'] ] ); //unset old field key
@@ -336,29 +336,29 @@  discard block
 block discarded – undo
336 336
 						continue;
337 337
 					}
338 338
 
339
-		            // if no matching field id or key in this form, create the field
340
-		            $imported['imported']['fields']++;
341
-		        }
339
+					// if no matching field id or key in this form, create the field
340
+					$imported['imported']['fields']++;
341
+				}
342 342
 			} else {
343 343
 				$new_id = FrmField::create( $f );
344 344
 				if ( $new_id == false ) {
345 345
 					continue;
346 346
 				}
347 347
 
348
-	            $imported['imported']['fields']++;
349
-		    }
348
+				$imported['imported']['fields']++;
349
+			}
350 350
 
351 351
 			unset($field, $new_id);
352 352
 		}
353 353
 	}
354 354
 
355 355
 	/**
356
-	* Switch the form_select on a repeating field or embedded form if it needs to be switched
357
-	*
358
-	* @since 2.0.16
359
-	* @param array $f
360
-	* @param array $imported
361
-	*/
356
+	 * Switch the form_select on a repeating field or embedded form if it needs to be switched
357
+	 *
358
+	 * @since 2.0.16
359
+	 * @param array $f
360
+	 * @param array $imported
361
+	 */
362 362
 	private static function maybe_update_form_select( &$f, $imported ) {
363 363
 		if ( ! isset( $imported['forms'] ) ) {
364 364
 			return;
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
 	}
376 376
 
377 377
 	/**
378
-	* Updates the custom style setting on import
379
-	*
380
-	* @since 2.0.19
381
-	* @param array $form
382
-	*
383
-	*/
378
+	 * Updates the custom style setting on import
379
+	 *
380
+	 * @since 2.0.19
381
+	 * @param array $form
382
+	 *
383
+	 */
384 384
 	private static function update_custom_style_setting_on_import( &$form ) {
385 385
 		if ( is_numeric( $form['options']['custom_style'] ) ) {
386 386
 			// Set to default
@@ -407,16 +407,16 @@  discard block
 block discarded – undo
407 407
 	}
408 408
 
409 409
 	public static function import_xml_views( $views, $imported ) {
410
-        $imported['posts'] = array();
411
-        $form_action_type = FrmFormActionsController::$action_post_type;
410
+		$imported['posts'] = array();
411
+		$form_action_type = FrmFormActionsController::$action_post_type;
412 412
 
413
-        $post_types = array(
414
-            'frm_display' => 'views',
415
-            $form_action_type => 'actions',
416
-            'frm_styles'    => 'styles',
417
-        );
413
+		$post_types = array(
414
+			'frm_display' => 'views',
415
+			$form_action_type => 'actions',
416
+			'frm_styles'    => 'styles',
417
+		);
418 418
 
419
-        foreach ( $views as $item ) {
419
+		foreach ( $views as $item ) {
420 420
 			$post = array(
421 421
 				'post_title'    => (string) $item->title,
422 422
 				'post_name'     => (string) $item->post_name,
@@ -435,52 +435,52 @@  discard block
 block discarded – undo
435 435
 				'post_date'     => (string) $item->post_date,
436 436
 				'post_date_gmt' => (string) $item->post_date_gmt,
437 437
 				'ping_status'   => (string) $item->ping_status,
438
-                'postmeta'      => array(),
439
-                'tax_input'     => array(),
438
+				'postmeta'      => array(),
439
+				'tax_input'     => array(),
440 440
 			);
441 441
 
442
-            $old_id = $post['post_id'];
443
-            self::populate_post($post, $item, $imported);
442
+			$old_id = $post['post_id'];
443
+			self::populate_post($post, $item, $imported);
444 444
 
445 445
 			unset($item);
446 446
 
447 447
 			$post_id = false;
448
-            if ( $post['post_type'] == $form_action_type ) {
449
-                $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
448
+			if ( $post['post_type'] == $form_action_type ) {
449
+				$action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
450 450
 				if ( $action_control ) {
451 451
 					$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
452 452
 				}
453
-                unset($action_control);
454
-            } else if ( $post['post_type'] == 'frm_styles' ) {
455
-                // Properly encode post content before inserting the post
456
-                $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
457
-                $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
458
-
459
-                // Create/update post now
460
-                $post_id = wp_insert_post( $post );
461
-            } else {
462
-                // Create/update post now
463
-                $post_id = wp_insert_post( $post );
464
-            }
465
-
466
-            if ( ! is_numeric($post_id) ) {
467
-                continue;
468
-            }
469
-
470
-            self::update_postmeta($post, $post_id);
471
-
472
-            $this_type = 'posts';
453
+				unset($action_control);
454
+			} else if ( $post['post_type'] == 'frm_styles' ) {
455
+				// Properly encode post content before inserting the post
456
+				$post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
457
+				$post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
458
+
459
+				// Create/update post now
460
+				$post_id = wp_insert_post( $post );
461
+			} else {
462
+				// Create/update post now
463
+				$post_id = wp_insert_post( $post );
464
+			}
465
+
466
+			if ( ! is_numeric($post_id) ) {
467
+				continue;
468
+			}
469
+
470
+			self::update_postmeta($post, $post_id);
471
+
472
+			$this_type = 'posts';
473 473
 			if ( isset( $post_types[ $post['post_type'] ] ) ) {
474 474
 				$this_type = $post_types[ $post['post_type'] ];
475
-            }
475
+			}
476 476
 
477
-            if ( isset($post['ID']) && $post_id == $post['ID'] ) {
478
-                $imported['updated'][ $this_type ]++;
479
-            } else {
480
-                $imported['imported'][ $this_type ]++;
481
-            }
477
+			if ( isset($post['ID']) && $post_id == $post['ID'] ) {
478
+				$imported['updated'][ $this_type ]++;
479
+			} else {
480
+				$imported['imported'][ $this_type ]++;
481
+			}
482 482
 
483
-            unset($post);
483
+			unset($post);
484 484
 
485 485
 			$imported['posts'][ (int) $old_id ] = $post_id;
486 486
 		}
@@ -488,157 +488,157 @@  discard block
 block discarded – undo
488 488
 		self::maybe_update_stylesheet( $imported );
489 489
 
490 490
 		return $imported;
491
-    }
491
+	}
492 492
 
493
-    private static function populate_post( &$post, $item, $imported ) {
493
+	private static function populate_post( &$post, $item, $imported ) {
494 494
 		if ( isset($item->attachment_url) ) {
495 495
 			$post['attachment_url'] = (string) $item->attachment_url;
496 496
 		}
497 497
 
498 498
 		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
499
-		    // update to new form id
500
-		    $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
499
+			// update to new form id
500
+			$post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
501 501
 		}
502 502
 
503 503
 		foreach ( $item->postmeta as $meta ) {
504
-		    self::populate_postmeta($post, $meta, $imported);
504
+			self::populate_postmeta($post, $meta, $imported);
505 505
 			unset($meta);
506 506
 		}
507 507
 
508
-        self::populate_taxonomies($post, $item);
508
+		self::populate_taxonomies($post, $item);
509 509
 
510
-        self::maybe_editing_post($post);
511
-    }
510
+		self::maybe_editing_post($post);
511
+	}
512 512
 
513
-    private static function populate_postmeta( &$post, $meta, $imported ) {
514
-        global $frm_duplicate_ids;
513
+	private static function populate_postmeta( &$post, $meta, $imported ) {
514
+		global $frm_duplicate_ids;
515 515
 
516
-	    $m = array(
516
+		$m = array(
517 517
 			'key'   => (string) $meta->meta_key,
518 518
 			'value' => (string) $meta->meta_value,
519 519
 		);
520 520
 
521 521
 		//switch old form and field ids to new ones
522 522
 		if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
523
-		    $m['value'] = $imported['forms'][ (int) $m['value'] ];
523
+			$m['value'] = $imported['forms'][ (int) $m['value'] ];
524 524
 		} else {
525
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
525
+			$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
526 526
 
527
-		    if ( ! empty($frm_duplicate_ids) ) {
527
+			if ( ! empty($frm_duplicate_ids) ) {
528 528
 
529
-		        if ( $m['key'] == 'frm_dyncontent' ) {
530
-		            $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
531
-    		    } else if ( $m['key'] == 'frm_options' ) {
529
+				if ( $m['key'] == 'frm_dyncontent' ) {
530
+					$m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
531
+				} else if ( $m['key'] == 'frm_options' ) {
532 532
 
533 533
 					foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
534 534
 						if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
535 535
 							$m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
536
-    		            }
537
-    		        }
538
-
539
-                    $check_dup_array = array();
540
-    		        if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
541
-    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
542
-    		                $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
543
-    		            } else if ( is_array( $m['value']['order_by'] ) ) {
544
-                            $check_dup_array[] = 'order_by';
545
-    		            }
546
-    		        }
547
-
548
-    		        if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
549
-    		            $check_dup_array[] = 'where';
550
-    		        }
551
-
552
-                    foreach ( $check_dup_array as $check_k ) {
536
+						}
537
+					}
538
+
539
+					$check_dup_array = array();
540
+					if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
541
+						if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
542
+							$m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
543
+						} else if ( is_array( $m['value']['order_by'] ) ) {
544
+							$check_dup_array[] = 'order_by';
545
+						}
546
+					}
547
+
548
+					if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
549
+						$check_dup_array[] = 'where';
550
+					}
551
+
552
+					foreach ( $check_dup_array as $check_k ) {
553 553
 						foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
554 554
 							if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
555 555
 								$m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
556
-		                    }
557
-		                    unset($mk, $mv);
558
-		                }
559
-                    }
560
-    		    }
561
-		    }
556
+							}
557
+							unset($mk, $mv);
558
+						}
559
+					}
560
+				}
561
+			}
562 562
 		}
563 563
 
564 564
 		if ( ! is_array($m['value']) ) {
565
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
565
+			$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
566 566
 		}
567 567
 
568 568
 		$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
569
-    }
570
-
571
-    /**
572
-     * Add terms to post
573
-     * @param array $post by reference
574
-     * @param object $item The XML object data
575
-     */
576
-    private static function populate_taxonomies( &$post, $item ) {
569
+	}
570
+
571
+	/**
572
+	 * Add terms to post
573
+	 * @param array $post by reference
574
+	 * @param object $item The XML object data
575
+	 */
576
+	private static function populate_taxonomies( &$post, $item ) {
577 577
 		foreach ( $item->category as $c ) {
578 578
 			$att = $c->attributes();
579 579
 			if ( ! isset( $att['nicename'] ) ) {
580
-                continue;
581
-            }
582
-
583
-		    $taxonomy = (string) $att['domain'];
584
-		    if ( is_taxonomy_hierarchical($taxonomy) ) {
585
-		        $name = (string) $att['nicename'];
586
-		        $h_term = get_term_by('slug', $name, $taxonomy);
587
-		        if ( $h_term ) {
588
-		            $name = $h_term->term_id;
589
-		        }
590
-		        unset($h_term);
591
-		    } else {
592
-		        $name = (string) $c;
593
-		    }
580
+				continue;
581
+			}
582
+
583
+			$taxonomy = (string) $att['domain'];
584
+			if ( is_taxonomy_hierarchical($taxonomy) ) {
585
+				$name = (string) $att['nicename'];
586
+				$h_term = get_term_by('slug', $name, $taxonomy);
587
+				if ( $h_term ) {
588
+					$name = $h_term->term_id;
589
+				}
590
+				unset($h_term);
591
+			} else {
592
+				$name = (string) $c;
593
+			}
594 594
 
595 595
 			if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
596 596
 				$post['tax_input'][ $taxonomy ] = array();
597 597
 			}
598 598
 
599 599
 			$post['tax_input'][ $taxonomy ][] = $name;
600
-		    unset($name);
600
+			unset($name);
601 601
 		}
602
-    }
602
+	}
603 603
 
604
-    /**
605
-     * Edit post if the key and created time match
606
-     */
607
-    private static function maybe_editing_post( &$post ) {
604
+	/**
605
+	 * Edit post if the key and created time match
606
+	 */
607
+	private static function maybe_editing_post( &$post ) {
608 608
 		$match_by = array(
609
-		    'post_type'     => $post['post_type'],
610
-		    'name'          => $post['post_name'],
611
-		    'post_status'   => $post['post_status'],
612
-		    'posts_per_page' => 1,
609
+			'post_type'     => $post['post_type'],
610
+			'name'          => $post['post_name'],
611
+			'post_status'   => $post['post_status'],
612
+			'posts_per_page' => 1,
613 613
 		);
614 614
 
615 615
 		if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
616
-		    $match_by['include'] = $post['post_id'];
617
-		    unset($match_by['name']);
616
+			$match_by['include'] = $post['post_id'];
617
+			unset($match_by['name']);
618 618
 		}
619 619
 
620 620
 		$editing = get_posts($match_by);
621 621
 
622
-        if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
623
-            // set the id of the post to edit
624
-            $post['ID'] = current($editing)->ID;
625
-        }
626
-    }
622
+		if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
623
+			// set the id of the post to edit
624
+			$post['ID'] = current($editing)->ID;
625
+		}
626
+	}
627 627
 
628
-    private static function update_postmeta( &$post, $post_id ) {
629
-        foreach ( $post['postmeta'] as $k => $v ) {
630
-            if ( '_edit_last' == $k ) {
631
-                $v = FrmAppHelper::get_user_id_param($v);
632
-            } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
633
-                //change the attachment ID
634
-                $v = FrmProXMLHelper::get_file_id($v);
635
-            }
628
+	private static function update_postmeta( &$post, $post_id ) {
629
+		foreach ( $post['postmeta'] as $k => $v ) {
630
+			if ( '_edit_last' == $k ) {
631
+				$v = FrmAppHelper::get_user_id_param($v);
632
+			} else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
633
+				//change the attachment ID
634
+				$v = FrmProXMLHelper::get_file_id($v);
635
+			}
636 636
 
637
-            update_post_meta($post_id, $k, $v);
637
+			update_post_meta($post_id, $k, $v);
638 638
 
639
-            unset($k, $v);
640
-        }
641
-    }
639
+			unset($k, $v);
640
+		}
641
+	}
642 642
 
643 643
 	private static function maybe_update_stylesheet( $imported ) {
644 644
 		if ( ( isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ) ) || ( isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] ) ) ) {
@@ -649,72 +649,72 @@  discard block
 block discarded – undo
649 649
 		}
650 650
 	}
651 651
 
652
-    /**
653
-     * @param string $message
654
-     */
652
+	/**
653
+	 * @param string $message
654
+	 */
655 655
 	public static function parse_message( $result, &$message, &$errors ) {
656
-        if ( is_wp_error($result) ) {
657
-            $errors[] = $result->get_error_message();
658
-        } else if ( ! $result ) {
659
-            return;
660
-        }
661
-
662
-        if ( ! is_array($result) ) {
663
-            $message = is_string( $result ) ? $result : print_r( $result, 1 );
664
-            return;
665
-        }
666
-
667
-        $t_strings = array(
668
-            'imported'  => __( 'Imported', 'formidable' ),
669
-            'updated'   => __( 'Updated', 'formidable' ),
670
-        );
671
-
672
-        $message = '<ul>';
673
-        foreach ( $result as $type => $results ) {
656
+		if ( is_wp_error($result) ) {
657
+			$errors[] = $result->get_error_message();
658
+		} else if ( ! $result ) {
659
+			return;
660
+		}
661
+
662
+		if ( ! is_array($result) ) {
663
+			$message = is_string( $result ) ? $result : print_r( $result, 1 );
664
+			return;
665
+		}
666
+
667
+		$t_strings = array(
668
+			'imported'  => __( 'Imported', 'formidable' ),
669
+			'updated'   => __( 'Updated', 'formidable' ),
670
+		);
671
+
672
+		$message = '<ul>';
673
+		foreach ( $result as $type => $results ) {
674 674
 			if ( ! isset( $t_strings[ $type ] ) ) {
675
-                // only print imported and updated
676
-                continue;
677
-            }
675
+				// only print imported and updated
676
+				continue;
677
+			}
678 678
 
679
-            $s_message = array();
680
-            foreach ( $results as $k => $m ) {
681
-                self::item_count_message($m, $k, $s_message);
682
-                unset($k, $m);
683
-            }
679
+			$s_message = array();
680
+			foreach ( $results as $k => $m ) {
681
+				self::item_count_message($m, $k, $s_message);
682
+				unset($k, $m);
683
+			}
684 684
 
685
-            if ( ! empty($s_message) ) {
685
+			if ( ! empty($s_message) ) {
686 686
 				$message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
687
-                $message .= implode(', ', $s_message);
688
-                $message .= '</li>';
689
-            }
690
-        }
691
-
692
-        if ( $message == '<ul>' ) {
693
-            $message = '';
694
-            $errors[] = __( 'Nothing was imported or updated', 'formidable' );
695
-        } else {
696
-            $message .= '</ul>';
697
-        }
698
-    }
687
+				$message .= implode(', ', $s_message);
688
+				$message .= '</li>';
689
+			}
690
+		}
691
+
692
+		if ( $message == '<ul>' ) {
693
+			$message = '';
694
+			$errors[] = __( 'Nothing was imported or updated', 'formidable' );
695
+		} else {
696
+			$message .= '</ul>';
697
+		}
698
+	}
699 699
 
700 700
 	public static function item_count_message( $m, $type, &$s_message ) {
701
-        if ( ! $m ) {
702
-            return;
703
-        }
704
-
705
-        $strings = array(
706
-            'forms'     => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
707
-            'fields'    => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
708
-            'items'     => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
709
-            'views'     => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
710
-            'posts'     => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
711
-            'styles'     => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
712
-            'terms'     => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
713
-            'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
714
-        );
701
+		if ( ! $m ) {
702
+			return;
703
+		}
704
+
705
+		$strings = array(
706
+			'forms'     => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
707
+			'fields'    => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
708
+			'items'     => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
709
+			'views'     => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
710
+			'posts'     => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
711
+			'styles'     => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
712
+			'terms'     => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
713
+			'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
714
+		);
715 715
 
716 716
 		$s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
717
-    }
717
+	}
718 718
 
719 719
 	/**
720 720
 	 * Prepare the form options for export
@@ -745,16 +745,16 @@  discard block
 block discarded – undo
745 745
 	}
746 746
 
747 747
 	public static function cdata( $str ) {
748
-	    $str = maybe_unserialize($str);
749
-	    if ( is_array($str) ) {
750
-	        $str = json_encode($str);
748
+		$str = maybe_unserialize($str);
749
+		if ( is_array($str) ) {
750
+			$str = json_encode($str);
751 751
 		} else if ( seems_utf8( $str ) == false ) {
752 752
 			$str = utf8_encode( $str );
753 753
 		}
754 754
 
755
-        if ( is_numeric($str) ) {
756
-            return $str;
757
-        }
755
+		if ( is_numeric($str) ) {
756
+			return $str;
757
+		}
758 758
 
759 759
 		// $str = ent2ncr(esc_html($str));
760 760
 		$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
@@ -762,58 +762,58 @@  discard block
 block discarded – undo
762 762
 		return $str;
763 763
 	}
764 764
 
765
-    public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
766
-        // Get post type
767
-        $post_type = FrmFormActionsController::$action_post_type;
768
-
769
-        // Set up imported index, if not set up yet
770
-        if ( ! isset( $imported['imported']['actions'] ) ) {
771
-            $imported['imported']['actions'] = 0;
772
-        }
773
-
774
-        // Migrate post settings to action
775
-        self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
776
-
777
-        // Migrate email settings to action
778
-        self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
779
-    }
780
-
781
-    /**
782
-    * Migrate post settings to form action
783
-    *
784
-    * @param string $post_type
785
-    */
786
-    private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
787
-        if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
788
-            return;
789
-        }
790
-
791
-        $new_action = array(
792
-            'post_type'     => $post_type,
793
-            'post_excerpt'  => 'wppost',
765
+	public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
766
+		// Get post type
767
+		$post_type = FrmFormActionsController::$action_post_type;
768
+
769
+		// Set up imported index, if not set up yet
770
+		if ( ! isset( $imported['imported']['actions'] ) ) {
771
+			$imported['imported']['actions'] = 0;
772
+		}
773
+
774
+		// Migrate post settings to action
775
+		self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
776
+
777
+		// Migrate email settings to action
778
+		self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
779
+	}
780
+
781
+	/**
782
+	 * Migrate post settings to form action
783
+	 *
784
+	 * @param string $post_type
785
+	 */
786
+	private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
787
+		if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
788
+			return;
789
+		}
790
+
791
+		$new_action = array(
792
+			'post_type'     => $post_type,
793
+			'post_excerpt'  => 'wppost',
794 794
 			'post_title'    => __( 'Create Posts', 'formidable' ),
795
-            'menu_order'    => $form_id,
796
-            'post_status'   => 'publish',
797
-            'post_content'  => array(),
798
-            'post_name'     => $form_id .'_wppost_1',
799
-        );
800
-
801
-        $post_settings = array(
802
-            'post_type', 'post_category', 'post_content',
803
-            'post_excerpt', 'post_title', 'post_name', 'post_date',
795
+			'menu_order'    => $form_id,
796
+			'post_status'   => 'publish',
797
+			'post_content'  => array(),
798
+			'post_name'     => $form_id .'_wppost_1',
799
+		);
800
+
801
+		$post_settings = array(
802
+			'post_type', 'post_category', 'post_content',
803
+			'post_excerpt', 'post_title', 'post_name', 'post_date',
804 804
 			'post_status', 'post_custom_fields', 'post_password',
805
-        );
805
+		);
806 806
 
807
-        foreach ( $post_settings as $post_setting ) {
807
+		foreach ( $post_settings as $post_setting ) {
808 808
 			if ( isset( $form_options[ $post_setting ] ) ) {
809 809
 				$new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
810
-            }
811
-            unset($post_setting);
812
-        }
810
+			}
811
+			unset($post_setting);
812
+		}
813 813
 
814 814
 		$new_action['event'] = array( 'create', 'update' );
815 815
 
816
-        if ( $switch ) {
816
+		if ( $switch ) {
817 817
 			// Fields with string or int saved
818 818
 			$basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' );
819 819
 
@@ -821,22 +821,22 @@  discard block
 block discarded – undo
821 821
 			$array_fields = array( 'post_category', 'post_custom_fields' );
822 822
 
823 823
 			$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
824
-        }
825
-        $new_action['post_content'] = json_encode($new_action['post_content']);
824
+		}
825
+		$new_action['post_content'] = json_encode($new_action['post_content']);
826 826
 
827
-        $exists = get_posts( array(
828
-            'name'          => $new_action['post_name'],
829
-            'post_type'     => $new_action['post_type'],
830
-            'post_status'   => $new_action['post_status'],
831
-            'numberposts'   => 1,
832
-        ) );
827
+		$exists = get_posts( array(
828
+			'name'          => $new_action['post_name'],
829
+			'post_type'     => $new_action['post_type'],
830
+			'post_status'   => $new_action['post_status'],
831
+			'numberposts'   => 1,
832
+		) );
833 833
 
834
-        if ( ! $exists ) {
834
+		if ( ! $exists ) {
835 835
 			// this isn't an email, but we need to use a class that will always be included
836 836
 			FrmAppHelper::save_json_post( $new_action );
837
-            $imported['imported']['actions']++;
838
-        }
839
-    }
837
+			$imported['imported']['actions']++;
838
+		}
839
+	}
840 840
 
841 841
 	/**
842 842
 	 * Switch old field IDs for new field IDs in emails and post
@@ -849,211 +849,211 @@  discard block
 block discarded – undo
849 849
 	 * @return string $post_content - new field IDs
850 850
 	 */
851 851
 	private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
852
-        global $frm_duplicate_ids;
852
+		global $frm_duplicate_ids;
853 853
 
854
-        // If there aren't IDs that were switched, end now
855
-        if ( ! $frm_duplicate_ids ) {
856
-            return;
857
-        }
854
+		// If there aren't IDs that were switched, end now
855
+		if ( ! $frm_duplicate_ids ) {
856
+			return;
857
+		}
858 858
 
859
-        // Get old IDs
860
-        $old = array_keys( $frm_duplicate_ids );
859
+		// Get old IDs
860
+		$old = array_keys( $frm_duplicate_ids );
861 861
 
862
-        // Get new IDs
863
-        $new = array_values( $frm_duplicate_ids );
862
+		// Get new IDs
863
+		$new = array_values( $frm_duplicate_ids );
864 864
 
865
-        // Do a str_replace with each item to set the new IDs
866
-        foreach ( $post_content as $key => $setting ) {
867
-            if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
868
-                // Replace old IDs with new IDs
865
+		// Do a str_replace with each item to set the new IDs
866
+		foreach ( $post_content as $key => $setting ) {
867
+			if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
868
+				// Replace old IDs with new IDs
869 869
 				$post_content[ $key ] = str_replace( $old, $new, $setting );
870
-            } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
871
-                foreach ( $setting as $k => $val ) {
872
-                    // Replace old IDs with new IDs
870
+			} else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
871
+				foreach ( $setting as $k => $val ) {
872
+					// Replace old IDs with new IDs
873 873
 					$post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
874
-                }
875
-            }
876
-            unset( $key, $setting );
877
-        }
878
-        return $post_content;
879
-    }
880
-
881
-    private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
882
-        // No old notifications or autoresponders to carry over
874
+				}
875
+			}
876
+			unset( $key, $setting );
877
+		}
878
+		return $post_content;
879
+	}
880
+
881
+	private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
882
+		// No old notifications or autoresponders to carry over
883 883
 		if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
884
-            return;
885
-        }
884
+			return;
885
+		}
886 886
 
887
-        // Initialize notifications array
888
-        $notifications = array();
887
+		// Initialize notifications array
888
+		$notifications = array();
889 889
 
890
-        // Migrate regular notifications
891
-        self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
890
+		// Migrate regular notifications
891
+		self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
892 892
 
893
-        // Migrate autoresponders
894
-        self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
893
+		// Migrate autoresponders
894
+		self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
895 895
 
896
-        if (  empty( $notifications ) ) {
897
-            return;
898
-        }
896
+		if (  empty( $notifications ) ) {
897
+			return;
898
+		}
899 899
 
900
-        foreach ( $notifications as $new_notification ) {
901
-            $new_notification['post_type']      = $post_type;
902
-            $new_notification['post_excerpt']   = 'email';
900
+		foreach ( $notifications as $new_notification ) {
901
+			$new_notification['post_type']      = $post_type;
902
+			$new_notification['post_excerpt']   = 'email';
903 903
 			$new_notification['post_title']     = __( 'Email Notification', 'formidable' );
904
-            $new_notification['menu_order']     = $form_id;
905
-            $new_notification['post_status']    = 'publish';
904
+			$new_notification['menu_order']     = $form_id;
905
+			$new_notification['post_status']    = 'publish';
906 906
 
907
-            // Switch field IDs and keys, if needed
908
-            if ( $switch ) {
907
+			// Switch field IDs and keys, if needed
908
+			if ( $switch ) {
909 909
 
910 910
 				// Switch field IDs in email conditional logic
911 911
 				self::switch_email_contition_field_ids( $new_notification['post_content'] );
912 912
 
913 913
 				// Switch all other field IDs in email
914
-                $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
915
-            }
916
-            $new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
917
-
918
-            $exists = get_posts( array(
919
-                'name'          => $new_notification['post_name'],
920
-                'post_type'     => $new_notification['post_type'],
921
-                'post_status'   => $new_notification['post_status'],
922
-                'numberposts'   => 1,
923
-            ) );
924
-
925
-            if ( empty($exists) ) {
914
+				$new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
915
+			}
916
+			$new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
917
+
918
+			$exists = get_posts( array(
919
+				'name'          => $new_notification['post_name'],
920
+				'post_type'     => $new_notification['post_type'],
921
+				'post_status'   => $new_notification['post_status'],
922
+				'numberposts'   => 1,
923
+			) );
924
+
925
+			if ( empty($exists) ) {
926 926
 				FrmAppHelper::save_json_post( $new_notification );
927
-                $imported['imported']['actions']++;
928
-            }
929
-            unset($new_notification);
930
-        }
931
-    }
932
-
933
-    private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
934
-        if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
935
-            // add old settings into notification array
927
+				$imported['imported']['actions']++;
928
+			}
929
+			unset($new_notification);
930
+		}
931
+	}
932
+
933
+	private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
934
+		if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
935
+			// add old settings into notification array
936 936
 			$form_options['notification'] = array( 0 => $form_options );
937
-        } else if ( isset( $form_options['notification']['email_to'] ) ) {
938
-            // make sure it's in the correct format
937
+		} else if ( isset( $form_options['notification']['email_to'] ) ) {
938
+			// make sure it's in the correct format
939 939
 			$form_options['notification'] = array( 0 => $form_options['notification'] );
940
-        }
940
+		}
941 941
 
942
-        if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
943
-            foreach ( $form_options['notification'] as $email_key => $notification ) {
942
+		if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
943
+			foreach ( $form_options['notification'] as $email_key => $notification ) {
944 944
 
945
-                $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
945
+				$atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
946 946
 
947
-                // Format the email data
948
-                self::format_email_data( $atts, $notification );
947
+				// Format the email data
948
+				self::format_email_data( $atts, $notification );
949 949
 
950 950
 				if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
951 951
 					do_action( 'frm_create_twilio_action', $atts, $notification );
952 952
 				}
953 953
 
954
-                // Setup the new notification
955
-                $new_notification = array();
956
-                self::setup_new_notification( $new_notification, $notification, $atts );
954
+				// Setup the new notification
955
+				$new_notification = array();
956
+				self::setup_new_notification( $new_notification, $notification, $atts );
957 957
 
958
-                $notifications[] = $new_notification;
959
-            }
960
-        }
961
-    }
958
+				$notifications[] = $new_notification;
959
+			}
960
+		}
961
+	}
962 962
 
963
-    private static function format_email_data( &$atts, $notification ) {
964
-        // Format email_to
965
-        self::format_email_to_data( $atts, $notification );
963
+	private static function format_email_data( &$atts, $notification ) {
964
+		// Format email_to
965
+		self::format_email_to_data( $atts, $notification );
966 966
 
967
-        // Format the reply to email and name
968
-        $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
969
-        foreach ( $reply_fields as $f => $val ) {
967
+		// Format the reply to email and name
968
+		$reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
969
+		foreach ( $reply_fields as $f => $val ) {
970 970
 			if ( isset( $notification[ $f ] ) ) {
971 971
 				$atts[ $f ] = $notification[ $f ];
972 972
 				if ( 'custom' == $notification[ $f ] ) {
973 973
 					$atts[ $f ] = $notification[ 'cust_' . $f ];
974 974
 				} else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
975 975
 					$atts[ $f ] = '[' . $atts[ $f ] . ']';
976
-                }
977
-            }
978
-            unset( $f, $val );
979
-        }
976
+				}
977
+			}
978
+			unset( $f, $val );
979
+		}
980 980
 
981
-        // Format event
981
+		// Format event
982 982
 		$atts['event'] = array( 'create' );
983
-        if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
984
-            $atts['event'][] = 'update';
985
-        } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
983
+		if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
984
+			$atts['event'][] = 'update';
985
+		} else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
986 986
 			$atts['event'] = array( 'update' );
987
-        }
988
-    }
987
+		}
988
+	}
989 989
 
990
-    private static function format_email_to_data( &$atts, $notification ) {
991
-        if ( isset( $notification['email_to'] ) ) {
990
+	private static function format_email_to_data( &$atts, $notification ) {
991
+		if ( isset( $notification['email_to'] ) ) {
992 992
 			$atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
993
-        } else {
994
-            $atts['email_to'] = array();
995
-        }
993
+		} else {
994
+			$atts['email_to'] = array();
995
+		}
996 996
 
997
-        if ( isset( $notification['also_email_to'] ) ) {
998
-            $email_fields = (array) $notification['also_email_to'];
999
-            $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1000
-            unset( $email_fields );
1001
-        }
997
+		if ( isset( $notification['also_email_to'] ) ) {
998
+			$email_fields = (array) $notification['also_email_to'];
999
+			$atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1000
+			unset( $email_fields );
1001
+		}
1002 1002
 
1003
-        foreach ( $atts['email_to'] as $key => $email_field ) {
1003
+		foreach ( $atts['email_to'] as $key => $email_field ) {
1004 1004
 
1005
-            if ( is_numeric( $email_field ) ) {
1005
+			if ( is_numeric( $email_field ) ) {
1006 1006
 				$atts['email_to'][ $key ] = '[' . $email_field . ']';
1007
-            }
1007
+			}
1008 1008
 
1009
-            if ( strpos( $email_field, '|') ) {
1010
-                $email_opt = explode( '|', $email_field );
1011
-                if ( isset( $email_opt[0] ) ) {
1009
+			if ( strpos( $email_field, '|') ) {
1010
+				$email_opt = explode( '|', $email_field );
1011
+				if ( isset( $email_opt[0] ) ) {
1012 1012
 					$atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1013
-                }
1014
-                unset( $email_opt );
1015
-            }
1016
-        }
1017
-        $atts['email_to'] = implode(', ', $atts['email_to']);
1018
-    }
1019
-
1020
-    private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1021
-        // Set up new notification
1022
-        $new_notification = array(
1023
-            'post_content'  => array(
1024
-                'email_to'      => $atts['email_to'],
1025
-                'event'         => $atts['event'],
1026
-            ),
1027
-            'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
1028
-        );
1029
-
1030
-        // Add more fields to the new notification
1031
-        $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1032
-        foreach ( $add_fields as $add_field ) {
1013
+				}
1014
+				unset( $email_opt );
1015
+			}
1016
+		}
1017
+		$atts['email_to'] = implode(', ', $atts['email_to']);
1018
+	}
1019
+
1020
+	private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1021
+		// Set up new notification
1022
+		$new_notification = array(
1023
+			'post_content'  => array(
1024
+				'email_to'      => $atts['email_to'],
1025
+				'event'         => $atts['event'],
1026
+			),
1027
+			'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
1028
+		);
1029
+
1030
+		// Add more fields to the new notification
1031
+		$add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1032
+		foreach ( $add_fields as $add_field ) {
1033 1033
 			if ( isset( $notification[ $add_field ] ) ) {
1034 1034
 				$new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1035
-            } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1035
+			} else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1036 1036
 				$new_notification['post_content'][ $add_field ] = 0;
1037
-            } else {
1037
+			} else {
1038 1038
 				$new_notification['post_content'][ $add_field ] = '';
1039
-            }
1040
-            unset( $add_field );
1041
-        }
1039
+			}
1040
+			unset( $add_field );
1041
+		}
1042 1042
 
1043 1043
 		// Set reply to
1044 1044
 		$new_notification['post_content']['reply_to'] = $atts['reply_to'];
1045 1045
 
1046
-        // Set from
1046
+		// Set from
1047 1047
 		if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
1048
-            $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
1049
-        }
1050
-    }
1048
+			$new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
1049
+		}
1050
+	}
1051 1051
 
1052 1052
 	/**
1053
-	* Switch field IDs in pre-2.0 email conditional logic
1054
-	*
1055
-	* @param $post_content array, pass by reference
1056
-	*/
1053
+	 * Switch field IDs in pre-2.0 email conditional logic
1054
+	 *
1055
+	 * @param $post_content array, pass by reference
1056
+	 */
1057 1057
 	private static function switch_email_contition_field_ids( &$post_content ) {
1058 1058
 		// Switch field IDs in conditional logic
1059 1059
 		if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -1066,48 +1066,48 @@  discard block
 block discarded – undo
1066 1066
 		}
1067 1067
 	}
1068 1068
 
1069
-    private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1070
-        if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1071
-            // migrate autoresponder
1072
-
1073
-            $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1074
-            if ( strpos($email_field, '|') ) {
1075
-                // data from entries field
1076
-                $email_field = explode('|', $email_field);
1077
-                if ( isset($email_field[1]) ) {
1078
-                    $email_field = $email_field[1];
1079
-                }
1080
-            }
1081
-            if ( is_numeric($email_field) && ! empty($email_field) ) {
1082
-                $email_field = '['. $email_field .']';
1083
-            }
1084
-
1085
-            $notification = $form_options;
1086
-            $new_notification2 = array(
1087
-                'post_content'  => array(
1088
-                    'email_message' => $notification['ar_email_message'],
1089
-                    'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1090
-                    'email_to'      => $email_field,
1091
-                    'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1092
-                    'inc_user_info' => 0,
1093
-                ),
1094
-                'post_name'     => $form_id .'_email_'. count( $notifications ),
1095
-            );
1096
-
1097
-            $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1098
-            $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1069
+	private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1070
+		if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1071
+			// migrate autoresponder
1072
+
1073
+			$email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1074
+			if ( strpos($email_field, '|') ) {
1075
+				// data from entries field
1076
+				$email_field = explode('|', $email_field);
1077
+				if ( isset($email_field[1]) ) {
1078
+					$email_field = $email_field[1];
1079
+				}
1080
+			}
1081
+			if ( is_numeric($email_field) && ! empty($email_field) ) {
1082
+				$email_field = '['. $email_field .']';
1083
+			}
1084
+
1085
+			$notification = $form_options;
1086
+			$new_notification2 = array(
1087
+				'post_content'  => array(
1088
+					'email_message' => $notification['ar_email_message'],
1089
+					'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1090
+					'email_to'      => $email_field,
1091
+					'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1092
+					'inc_user_info' => 0,
1093
+				),
1094
+				'post_name'     => $form_id .'_email_'. count( $notifications ),
1095
+			);
1096
+
1097
+			$reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1098
+			$reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1099 1099
 
1100 1100
 			if ( ! empty( $reply_to ) ) {
1101 1101
 				$new_notification2['post_content']['reply_to'] = $reply_to;
1102 1102
 			}
1103 1103
 
1104 1104
 			if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
1105
-                $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1105
+				$new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1106 1106
 			}
1107 1107
 
1108
-            $notifications[] = $new_notification2;
1109
-            unset( $new_notification2 );
1110
-        }
1111
-    }
1108
+			$notifications[] = $new_notification2;
1109
+			unset( $new_notification2 );
1110
+		}
1111
+	}
1112 1112
 }
1113 1113
 
Please login to merge, or discard this patch.
classes/models/FrmDb.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -1,81 +1,81 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmDb {
4
-    var $fields;
5
-    var $forms;
6
-    var $entries;
7
-    var $entry_metas;
8
-
9
-    public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
12
-        }
13
-
14
-        global $wpdb;
15
-        $this->fields         = $wpdb->prefix . 'frm_fields';
16
-        $this->forms          = $wpdb->prefix . 'frm_forms';
17
-        $this->entries        = $wpdb->prefix . 'frm_items';
18
-        $this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
-    }
20
-
21
-    public function upgrade( $old_db_version = false ) {
22
-        global $wpdb;
23
-        //$frm_db_version is the version of the database we're moving to
24
-        $frm_db_version = FrmAppHelper::$db_version;
25
-        $old_db_version = (float) $old_db_version;
26
-        if ( ! $old_db_version ) {
27
-            $old_db_version = get_option('frm_db_version');
28
-        }
29
-
30
-        if ( $frm_db_version != $old_db_version ) {
4
+	var $fields;
5
+	var $forms;
6
+	var $entries;
7
+	var $entry_metas;
8
+
9
+	public function __construct() {
10
+		if ( ! defined('ABSPATH') ) {
11
+			die('You are not allowed to call this page directly.');
12
+		}
13
+
14
+		global $wpdb;
15
+		$this->fields         = $wpdb->prefix . 'frm_fields';
16
+		$this->forms          = $wpdb->prefix . 'frm_forms';
17
+		$this->entries        = $wpdb->prefix . 'frm_items';
18
+		$this->entry_metas    = $wpdb->prefix . 'frm_item_metas';
19
+	}
20
+
21
+	public function upgrade( $old_db_version = false ) {
22
+		global $wpdb;
23
+		//$frm_db_version is the version of the database we're moving to
24
+		$frm_db_version = FrmAppHelper::$db_version;
25
+		$old_db_version = (float) $old_db_version;
26
+		if ( ! $old_db_version ) {
27
+			$old_db_version = get_option('frm_db_version');
28
+		}
29
+
30
+		if ( $frm_db_version != $old_db_version ) {
31 31
 			// update rewrite rules for views and other custom post types
32 32
 			flush_rewrite_rules();
33 33
 
34 34
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
35 35
 
36
-            $this->create_tables();
37
-            $this->migrate_data($frm_db_version, $old_db_version);
36
+			$this->create_tables();
37
+			$this->migrate_data($frm_db_version, $old_db_version);
38 38
 
39
-            /***** SAVE DB VERSION *****/
40
-            update_option('frm_db_version', $frm_db_version);
39
+			/***** SAVE DB VERSION *****/
40
+			update_option('frm_db_version', $frm_db_version);
41 41
 
42
-            /**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
-            FrmXMLController::add_default_templates();
44
-        }
42
+			/**** ADD/UPDATE DEFAULT TEMPLATES ****/
43
+			FrmXMLController::add_default_templates();
44
+		}
45 45
 
46
-        do_action('frm_after_install');
46
+		do_action('frm_after_install');
47 47
 
48
-        /**** update the styling settings ****/
48
+		/**** update the styling settings ****/
49 49
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
50 50
 			$frm_style = new FrmStyle();
51 51
 			$frm_style->update( 'default' );
52 52
 		}
53
-    }
53
+	}
54 54
 
55
-    public function collation() {
56
-        global $wpdb;
57
-        if ( ! $wpdb->has_cap( 'collation' ) ) {
58
-            return '';
59
-        }
55
+	public function collation() {
56
+		global $wpdb;
57
+		if ( ! $wpdb->has_cap( 'collation' ) ) {
58
+			return '';
59
+		}
60 60
 
61
-        $charset_collate = '';
61
+		$charset_collate = '';
62 62
 		if ( ! empty( $wpdb->charset ) ) {
63 63
 			$charset_collate .= ' DEFAULT CHARACTER SET '. $wpdb->charset;
64 64
 		}
65 65
 
66
-        if ( ! empty($wpdb->collate) ) {
67
-            $charset_collate .= ' COLLATE '. $wpdb->collate;
68
-        }
66
+		if ( ! empty($wpdb->collate) ) {
67
+			$charset_collate .= ' COLLATE '. $wpdb->collate;
68
+		}
69 69
 
70
-        return $charset_collate;
71
-    }
70
+		return $charset_collate;
71
+	}
72 72
 
73
-    private function create_tables() {
74
-        $charset_collate = $this->collation();
75
-        $sql = array();
73
+	private function create_tables() {
74
+		$charset_collate = $this->collation();
75
+		$sql = array();
76 76
 
77
-        /* Create/Upgrade Fields Table */
78
-        $sql[] = 'CREATE TABLE '. $this->fields .' (
77
+		/* Create/Upgrade Fields Table */
78
+		$sql[] = 'CREATE TABLE '. $this->fields .' (
79 79
                 id int(11) NOT NULL auto_increment,
80 80
 				field_key varchar(100) default NULL,
81 81
                 name text default NULL,
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
                 UNIQUE KEY field_key (field_key)
94 94
         )';
95 95
 
96
-        /* Create/Upgrade Forms Table */
97
-        $sql[] = 'CREATE TABLE '. $this->forms .' (
96
+		/* Create/Upgrade Forms Table */
97
+		$sql[] = 'CREATE TABLE '. $this->forms .' (
98 98
                 id int(11) NOT NULL auto_increment,
99 99
 				form_key varchar(100) default NULL,
100 100
                 name varchar(255) default NULL,
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
                 UNIQUE KEY form_key (form_key)
112 112
         )';
113 113
 
114
-        /* Create/Upgrade Items Table */
115
-        $sql[] = 'CREATE TABLE '. $this->entries .' (
114
+		/* Create/Upgrade Items Table */
115
+		$sql[] = 'CREATE TABLE '. $this->entries .' (
116 116
                 id int(11) NOT NULL auto_increment,
117 117
 				item_key varchar(100) default NULL,
118 118
                 name varchar(255) default NULL,
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
                 UNIQUE KEY item_key (item_key)
135 135
         )';
136 136
 
137
-        /* Create/Upgrade Meta Table */
138
-        $sql[] = 'CREATE TABLE '. $this->entry_metas .' (
137
+		/* Create/Upgrade Meta Table */
138
+		$sql[] = 'CREATE TABLE '. $this->entry_metas .' (
139 139
                 id int(11) NOT NULL auto_increment,
140 140
                 meta_value longtext default NULL,
141 141
                 field_id int(11) NOT NULL,
@@ -146,39 +146,39 @@  discard block
 block discarded – undo
146 146
                 KEY item_id (item_id)
147 147
         )';
148 148
 
149
-        foreach ( $sql as $q ) {
149
+		foreach ( $sql as $q ) {
150 150
 			if ( function_exists( 'dbDelta' ) ) {
151 151
 				dbDelta( $q . $charset_collate .';' );
152 152
 			} else {
153 153
 				global $wpdb;
154 154
 				$wpdb->query( $q . $charset_collate );
155 155
 			}
156
-            unset($q);
157
-        }
158
-    }
156
+			unset($q);
157
+		}
158
+	}
159 159
 
160
-    /**
161
-     * @param integer $frm_db_version
162
-     */
160
+	/**
161
+	 * @param integer $frm_db_version
162
+	 */
163 163
 	private function migrate_data( $frm_db_version, $old_db_version ) {
164 164
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
165
-        foreach ( $migrations as $migration ) {
166
-            if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167
-                $function_name = 'migrate_to_'. $migration;
168
-                $this->$function_name();
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * Change array into format $wpdb->prepare can use
175
-     */
176
-    public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
-        if ( empty($args) ) {
165
+		foreach ( $migrations as $migration ) {
166
+			if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167
+				$function_name = 'migrate_to_'. $migration;
168
+				$this->$function_name();
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * Change array into format $wpdb->prepare can use
175
+	 */
176
+	public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
+		if ( empty($args) ) {
178 178
 			// add an arg to prevent prepare from failing
179 179
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
180 180
 			return;
181
-        }
181
+		}
182 182
 
183 183
 		$where = '';
184 184
 		$values = array();
@@ -189,60 +189,60 @@  discard block
 block discarded – undo
189 189
 		}
190 190
 
191 191
 		$args = compact( 'where', 'values' );
192
-    }
193
-
194
-    /**
195
-     * @param string $base_where
196
-     * @param string $where
197
-     */
198
-    public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
-        $condition = ' AND';
200
-        if ( isset( $args['or'] ) ) {
201
-            $condition = ' OR';
202
-            unset( $args['or'] );
203
-        }
204
-
205
-        foreach ( $args as $key => $value ) {
206
-            $where .= empty( $where ) ? $base_where : $condition;
207
-            $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
-            if ( is_numeric( $key ) || $array_inc_null ) {
209
-                $where .= ' ( ';
210
-                $nested_where = '';
211
-                if ( $array_inc_null ) {
212
-                    foreach ( $value as $val ) {
213
-                        self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
-                    }
215
-                } else {
216
-                    self::parse_where_from_array( $value, '', $nested_where, $values );
217
-                }
218
-                $where .= $nested_where;
219
-                $where .= ' ) ';
220
-            } else {
221
-                self::interpret_array_to_sql( $key, $value, $where, $values );
222
-            }
223
-        }
224
-    }
225
-
226
-    /**
227
-     * @param string $key
228
-     * @param string $where
229
-     */
230
-    private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
192
+	}
193
+
194
+	/**
195
+	 * @param string $base_where
196
+	 * @param string $where
197
+	 */
198
+	public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
199
+		$condition = ' AND';
200
+		if ( isset( $args['or'] ) ) {
201
+			$condition = ' OR';
202
+			unset( $args['or'] );
203
+		}
204
+
205
+		foreach ( $args as $key => $value ) {
206
+			$where .= empty( $where ) ? $base_where : $condition;
207
+			$array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
208
+			if ( is_numeric( $key ) || $array_inc_null ) {
209
+				$where .= ' ( ';
210
+				$nested_where = '';
211
+				if ( $array_inc_null ) {
212
+					foreach ( $value as $val ) {
213
+						self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values );
214
+					}
215
+				} else {
216
+					self::parse_where_from_array( $value, '', $nested_where, $values );
217
+				}
218
+				$where .= $nested_where;
219
+				$where .= ' ) ';
220
+			} else {
221
+				self::interpret_array_to_sql( $key, $value, $where, $values );
222
+			}
223
+		}
224
+	}
225
+
226
+	/**
227
+	 * @param string $key
228
+	 * @param string $where
229
+	 */
230
+	private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
231 231
 		$key = trim( $key );
232 232
 
233
-        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
-            $k = explode(' ', $key);
235
-            $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
-            $values[] = '%Y-%m-%d %H:%i:%s';
237
-        } else {
238
-            $where .= ' '. $key;
239
-        }
233
+		if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
+			$k = explode(' ', $key);
235
+			$where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236
+			$values[] = '%Y-%m-%d %H:%i:%s';
237
+		} else {
238
+			$where .= ' '. $key;
239
+		}
240 240
 
241 241
 		$lowercase_key = explode( ' ', strtolower( $key ) );
242 242
 		$lowercase_key = end( $lowercase_key );
243 243
 
244
-        if ( is_array( $value ) ) {
245
-            // translate array of values to "in"
244
+		if ( is_array( $value ) ) {
245
+			// translate array of values to "in"
246 246
 			if ( strpos( $lowercase_key, 'like' ) !== false ) {
247 247
 				$where = rtrim( $where, $key );
248 248
 				$where .= '(';
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 				}
258 258
 				$where .= ')';
259 259
 			} else if ( ! empty( $value ) ) {
260
-            	$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
260
+				$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
261 261
 				$values = array_merge( $values, $value );
262 262
 			}
263
-        } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
263
+		} else if ( strpos( $lowercase_key, 'like' ) !== false ) {
264 264
 			/**
265 265
 			 * Allow string to start or end with the value
266 266
 			 * If the key is like% then skip the first % for starts with
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 			$where .= ' %s';
280 280
 			$values[] = $start . FrmAppHelper::esc_like( $value ) . $end;
281 281
 
282
-        } else if ( $value === null ) {
283
-            $where .= ' IS NULL';
284
-        } else {
282
+		} else if ( $value === null ) {
283
+			$where .= ' IS NULL';
284
+		} else {
285 285
 			// allow a - to prevent = from being added
286 286
 			if ( substr( $key, -1 ) == '-' ) {
287 287
 				$where = rtrim( $where, '-' );
@@ -289,28 +289,28 @@  discard block
 block discarded – undo
289 289
 				$where .= '=';
290 290
 			}
291 291
 
292
-            $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
-            $values[] = $value;
294
-        }
295
-    }
296
-
297
-    /**
298
-     * @param string $table
299
-     */
300
-    public static function get_count( $table, $where = array(), $args = array() ) {
301
-        $count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
-        return $count;
303
-    }
304
-
305
-    public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
-        $group = '';
307
-        self::get_group_and_table_name( $table, $group );
292
+			$where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s';
293
+			$values[] = $value;
294
+		}
295
+	}
296
+
297
+	/**
298
+	 * @param string $table
299
+	 */
300
+	public static function get_count( $table, $where = array(), $args = array() ) {
301
+		$count = self::get_var( $table, $where, 'COUNT(*)', $args );
302
+		return $count;
303
+	}
304
+
305
+	public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
306
+		$group = '';
307
+		self::get_group_and_table_name( $table, $group );
308 308
 		self::convert_options_to_array( $args, '', $limit );
309 309
 
310 310
 		$query = 'SELECT ' . $field . ' FROM ' . $table;
311 311
 		if ( is_array( $where ) || empty( $where ) ) {
312 312
 			// only separate into array values and query string if is array
313
-        	self::get_where_clause_and_values( $where );
313
+			self::get_where_clause_and_values( $where );
314 314
 			global $wpdb;
315 315
 			$query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
316 316
 		} else {
@@ -322,49 +322,49 @@  discard block
 block discarded – undo
322 322
 			$query .= $where . ' ' . implode( ' ', $args );
323 323
 		}
324 324
 
325
-        $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
326
-        $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
327
-        return $results;
328
-    }
329
-
330
-    /**
331
-     * @param string $table
332
-     * @param array $where
333
-     */
334
-    public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
-        return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
-    }
337
-
338
-    /**
339
-     * @since 2.0
340
-     * @param string $table
341
-     */
342
-    public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
-        $args['limit'] = 1;
344
-        return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
-    }
346
-
347
-    /**
348
-     * @param string $table
349
-     */
350
-    public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
325
+		$cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
326
+		$results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
327
+		return $results;
328
+	}
329
+
330
+	/**
331
+	 * @param string $table
332
+	 * @param array $where
333
+	 */
334
+	public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
335
+		return self::get_var( $table, $where, $field, $args, $limit, 'col' );
336
+	}
337
+
338
+	/**
339
+	 * @since 2.0
340
+	 * @param string $table
341
+	 */
342
+	public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
343
+		$args['limit'] = 1;
344
+		return self::get_var( $table, $where, $fields, $args, '', 'row' );
345
+	}
346
+
347
+	/**
348
+	 * @param string $table
349
+	 */
350
+	public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) {
351
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' );
352 352
 		return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1 ), '', 'row' );
353
-    }
354
-
355
-    public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
-        _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
-        return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
-    }
359
-
360
-    /**
361
-     * Prepare a key/value array before DB call
362
-     * @since 2.0
363
-     * @param string $table
364
-     */
365
-    public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
-        return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
-    }
353
+	}
354
+
355
+	public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356
+		_deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
+		return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
358
+	}
359
+
360
+	/**
361
+	 * Prepare a key/value array before DB call
362
+	 * @since 2.0
363
+	 * @param string $table
364
+	 */
365
+	public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
366
+		return self::get_var( $table, $where, $fields, $args, '', 'results' );
367
+	}
368 368
 
369 369
 	/**
370 370
 	 * Check for like, not like, in, not in, =, !=, >, <, <=, >=
@@ -400,86 +400,86 @@  discard block
 block discarded – undo
400 400
 		return '';
401 401
 	}
402 402
 
403
-    /**
404
-     * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
-     * Also add the wpdb->prefix to the table if it's missing
406
-     *
407
-     * @param string $table
408
-     * @param string $group
409
-     */
410
-    private static function get_group_and_table_name( &$table, &$group ) {
403
+	/**
404
+	 * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join
405
+	 * Also add the wpdb->prefix to the table if it's missing
406
+	 *
407
+	 * @param string $table
408
+	 * @param string $group
409
+	 */
410
+	private static function get_group_and_table_name( &$table, &$group ) {
411 411
 		global $wpdb, $wpmuBaseTablePrefix;
412 412
 
413
-        $table_parts = explode(' ', $table);
414
-        $group = reset($table_parts);
415
-        $group = str_replace( $wpdb->prefix, '', $group );
413
+		$table_parts = explode(' ', $table);
414
+		$group = reset($table_parts);
415
+		$group = str_replace( $wpdb->prefix, '', $group );
416 416
 
417 417
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
418 418
 		$group = str_replace( $prefix, '', $group );
419 419
 
420
-        if ( $group == $table ) {
421
-            $table = $wpdb->prefix . $table;
422
-        }
420
+		if ( $group == $table ) {
421
+			$table = $wpdb->prefix . $table;
422
+		}
423 423
 
424 424
 		// switch to singular group name
425 425
 		$group = rtrim( $group, 's' );
426
-    }
426
+	}
427 427
 
428
-    private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
-        if ( ! is_array($args) ) {
428
+	private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
+		if ( ! is_array($args) ) {
430 430
 			$args = array( 'order_by' => $args );
431
-        }
431
+		}
432 432
 
433
-        if ( ! empty( $order_by ) ) {
434
-            $args['order_by'] = $order_by;
435
-        }
433
+		if ( ! empty( $order_by ) ) {
434
+			$args['order_by'] = $order_by;
435
+		}
436 436
 
437
-        if ( ! empty( $limit ) ) {
438
-            $args['limit'] = $limit;
439
-        }
437
+		if ( ! empty( $limit ) ) {
438
+			$args['limit'] = $limit;
439
+		}
440 440
 
441
-        $temp_args = $args;
442
-        foreach ( $temp_args as $k => $v ) {
443
-            if ( $v == '' ) {
441
+		$temp_args = $args;
442
+		foreach ( $temp_args as $k => $v ) {
443
+			if ( $v == '' ) {
444 444
 				unset( $args[ $k ] );
445
-                continue;
446
-            }
445
+				continue;
446
+			}
447 447
 
448
-            if ( $k == 'limit' ) {
448
+			if ( $k == 'limit' ) {
449 449
 				$args[ $k ] = FrmAppHelper::esc_limit( $v );
450
-            }
451
-            $db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
-            if ( strpos( $v, $db_name ) === false ) {
450
+			}
451
+			$db_name = strtoupper( str_replace( '_', ' ', $k ) );
452
+			if ( strpos( $v, $db_name ) === false ) {
453 453
 				$args[ $k ] = $db_name . ' ' . $v;
454
-            }
455
-        }
456
-    }
454
+			}
455
+		}
456
+	}
457 457
 
458
-    public function uninstall() {
458
+	public function uninstall() {
459 459
 		if ( ! current_user_can( 'administrator' ) ) {
460
-            $frm_settings = FrmAppHelper::get_settings();
461
-            wp_die($frm_settings->admin_permission);
462
-        }
463
-
464
-        global $wpdb, $wp_roles;
465
-
466
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
467
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
468
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
469
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
470
-
471
-        delete_option('frm_options');
472
-        delete_option('frm_db_version');
473
-
474
-        //delete roles
475
-        $frm_roles = FrmAppHelper::frm_capabilities();
476
-        $roles = get_editable_roles();
477
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
478
-            foreach ( $roles as $role => $details ) {
479
-                $wp_roles->remove_cap( $role, $frm_role );
480
-                unset($role, $details);
481
-    		}
482
-    		unset($frm_role, $frm_role_description);
460
+			$frm_settings = FrmAppHelper::get_settings();
461
+			wp_die($frm_settings->admin_permission);
462
+		}
463
+
464
+		global $wpdb, $wp_roles;
465
+
466
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
467
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
468
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
469
+		$wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
470
+
471
+		delete_option('frm_options');
472
+		delete_option('frm_db_version');
473
+
474
+		//delete roles
475
+		$frm_roles = FrmAppHelper::frm_capabilities();
476
+		$roles = get_editable_roles();
477
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
478
+			foreach ( $roles as $role => $details ) {
479
+				$wp_roles->remove_cap( $role, $frm_role );
480
+				unset($role, $details);
481
+			}
482
+			unset($frm_role, $frm_role_description);
483 483
 		}
484 484
 		unset($roles, $frm_roles);
485 485
 
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 
504 504
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
505 505
 
506
-        do_action('frm_after_uninstall');
507
-        return true;
508
-    }
506
+		do_action('frm_after_uninstall');
507
+		return true;
508
+	}
509 509
 
510 510
 	/**
511 511
 	 * Migrate old styling settings. If sites are using the old
@@ -544,150 +544,150 @@  discard block
 block discarded – undo
544 544
 		}
545 545
 	}
546 546
 
547
-    /**
548
-     * Change field size from character to pixel -- Multiply by 9
549
-     */
550
-    private function migrate_to_17() {
551
-        global $wpdb;
547
+	/**
548
+	 * Change field size from character to pixel -- Multiply by 9
549
+	 */
550
+	private function migrate_to_17() {
551
+		global $wpdb;
552 552
 		$pixel_conversion = 9;
553 553
 
554
-        // Get query arguments
554
+		// Get query arguments
555 555
 		$field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' );
556 556
 		$query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' );
557 557
 
558
-        // Get results
558
+		// Get results
559 559
 		$fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' );
560 560
 
561
-        $updated = 0;
562
-        foreach ( $fields as $f ) {
563
-            $f->field_options = maybe_unserialize($f->field_options);
564
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
565
-                continue;
566
-            }
561
+		$updated = 0;
562
+		foreach ( $fields as $f ) {
563
+			$f->field_options = maybe_unserialize($f->field_options);
564
+			if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
565
+				continue;
566
+			}
567 567
 
568 568
 			$f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] );
569
-            $f->field_options['size'] .= 'px';
570
-            $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
571
-            if ( $u ) {
572
-                $updated++;
573
-            }
574
-            unset($f);
575
-        }
576
-
577
-        // Change the characters in widgets to pixels
578
-        $widgets = get_option('widget_frm_show_form');
579
-        if ( empty($widgets) ) {
580
-            return;
581
-        }
582
-
583
-        $widgets = maybe_unserialize($widgets);
584
-        foreach ( $widgets as $k => $widget ) {
585
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
586
-                continue;
587
-            }
569
+			$f->field_options['size'] .= 'px';
570
+			$u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
571
+			if ( $u ) {
572
+				$updated++;
573
+			}
574
+			unset($f);
575
+		}
576
+
577
+		// Change the characters in widgets to pixels
578
+		$widgets = get_option('widget_frm_show_form');
579
+		if ( empty($widgets) ) {
580
+			return;
581
+		}
582
+
583
+		$widgets = maybe_unserialize($widgets);
584
+		foreach ( $widgets as $k => $widget ) {
585
+			if ( ! is_array($widget) || ! isset($widget['size']) ) {
586
+				continue;
587
+			}
588 588
 			$size = round( $pixel_conversion * (int) $widget['size'] );
589
-            $size .= 'px';
589
+			$size .= 'px';
590 590
 			$widgets[ $k ]['size'] = $size;
591
-        }
592
-        update_option('widget_frm_show_form', $widgets);
593
-    }
594
-
595
-    /**
596
-     * Migrate post and email notification settings into actions
597
-     */
598
-    private function migrate_to_16() {
599
-        global $wpdb;
600
-
601
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
602
-
603
-        /**
604
-        * Old email settings format:
605
-        * email_to: Email or field id
606
-        * also_email_to: array of fields ids
607
-        * reply_to: Email, field id, 'custom'
608
-        * cust_reply_to: string
609
-        * reply_to_name: field id, 'custom'
610
-        * cust_reply_to_name: string
611
-        * plain_text: 0|1
612
-        * email_message: string or ''
613
-        * email_subject: string or ''
614
-        * inc_user_info: 0|1
615
-        * update_email: 0, 1, 2
616
-        *
617
-        * Old autoresponder settings format:
618
-        * auto_responder: 0|1
619
-        * ar_email_message: string or ''
620
-        * ar_email_to: field id
621
-        * ar_plain_text: 0|1
622
-        * ar_reply_to_name: string
623
-        * ar_reply_to: string
624
-        * ar_email_subject: string
625
-        * ar_update_email: 0, 1, 2
626
-        *
627
-        * New email settings:
628
-        * post_content: json settings
629
-        * post_title: form id
630
-        * post_excerpt: message
631
-        *
632
-        */
633
-
634
-        foreach ( $forms as $form ) {
591
+		}
592
+		update_option('widget_frm_show_form', $widgets);
593
+	}
594
+
595
+	/**
596
+	 * Migrate post and email notification settings into actions
597
+	 */
598
+	private function migrate_to_16() {
599
+		global $wpdb;
600
+
601
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
602
+
603
+		/**
604
+		 * Old email settings format:
605
+		 * email_to: Email or field id
606
+		 * also_email_to: array of fields ids
607
+		 * reply_to: Email, field id, 'custom'
608
+		 * cust_reply_to: string
609
+		 * reply_to_name: field id, 'custom'
610
+		 * cust_reply_to_name: string
611
+		 * plain_text: 0|1
612
+		 * email_message: string or ''
613
+		 * email_subject: string or ''
614
+		 * inc_user_info: 0|1
615
+		 * update_email: 0, 1, 2
616
+		 *
617
+		 * Old autoresponder settings format:
618
+		 * auto_responder: 0|1
619
+		 * ar_email_message: string or ''
620
+		 * ar_email_to: field id
621
+		 * ar_plain_text: 0|1
622
+		 * ar_reply_to_name: string
623
+		 * ar_reply_to: string
624
+		 * ar_email_subject: string
625
+		 * ar_update_email: 0, 1, 2
626
+		 *
627
+		 * New email settings:
628
+		 * post_content: json settings
629
+		 * post_title: form id
630
+		 * post_excerpt: message
631
+		 *
632
+		 */
633
+
634
+		foreach ( $forms as $form ) {
635 635
 			if ( $form->is_template && $form->default_template ) {
636 636
 				// don't migrate the default templates since the email will be added anyway
637 637
 				continue;
638 638
 			}
639 639
 
640
-            // Format form options
641
-            $form_options = maybe_unserialize($form->options);
640
+			// Format form options
641
+			$form_options = maybe_unserialize($form->options);
642 642
 
643
-            // Migrate settings to actions
644
-            FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
645
-        }
646
-    }
643
+			// Migrate settings to actions
644
+			FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
645
+		}
646
+	}
647 647
 
648
-    private function migrate_to_11() {
649
-        global $wpdb;
648
+	private function migrate_to_11() {
649
+		global $wpdb;
650 650
 
651
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
651
+		$forms = FrmDb::get_results( $this->forms, array(), 'id, options');
652 652
 
653
-        $sending = __( 'Sending', 'formidable' );
654
-        $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
655
-        $old_default_html = <<<DEFAULT_HTML
653
+		$sending = __( 'Sending', 'formidable' );
654
+		$img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
655
+		$old_default_html = <<<DEFAULT_HTML
656 656
 <div class="frm_submit">
657 657
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
658 658
 <input type="submit" value="[button_label]" [button_action] />
659 659
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
660 660
 </div>
661 661
 DEFAULT_HTML;
662
-        unset($sending, $img);
662
+		unset($sending, $img);
663 663
 
664
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
665
-        $draft_link = FrmFormsHelper::get_draft_link();
664
+		$new_default_html = FrmFormsHelper::get_default_html('submit');
665
+		$draft_link = FrmFormsHelper::get_draft_link();
666 666
 		foreach ( $forms as $form ) {
667
-            $form->options = maybe_unserialize($form->options);
668
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
669
-                continue;
670
-            }
667
+			$form->options = maybe_unserialize($form->options);
668
+			if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
669
+				continue;
670
+			}
671 671
 
672
-            if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
673
-                $form->options['submit_html'] = $new_default_html;
672
+			if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
673
+				$form->options['submit_html'] = $new_default_html;
674 674
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
675 675
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
676
-                $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
676
+				$form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
677 677
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
678
-            }
679
-            unset($form);
680
-        }
681
-        unset($forms);
682
-    }
678
+			}
679
+			unset($form);
680
+		}
681
+		unset($forms);
682
+	}
683 683
 
684
-    private function migrate_to_6() {
685
-        global $wpdb;
684
+	private function migrate_to_6() {
685
+		global $wpdb;
686 686
 
687 687
 		$no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) );
688 688
 		$fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' );
689 689
 
690
-        $default_html = <<<DEFAULT_HTML
690
+		$default_html = <<<DEFAULT_HTML
691 691
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
692 692
     <label class="frm_pos_[label_position]">[field_name]
693 693
         <span class="frm_required">[required_label]</span>
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 </div>
698 698
 DEFAULT_HTML;
699 699
 
700
-        $old_default_html = <<<DEFAULT_HTML
700
+		$old_default_html = <<<DEFAULT_HTML
701 701
 <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
702 702
     <label class="frm_pos_[label_position]">[field_name]
703 703
         <span class="frm_required">[required_label]</span>
@@ -707,23 +707,23 @@  discard block
 block discarded – undo
707 707
 </div>
708 708
 DEFAULT_HTML;
709 709
 
710
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
711
-        foreach ( $fields as $field ) {
712
-            $field->field_options = maybe_unserialize($field->field_options);
710
+		$new_default_html = FrmFieldsHelper::get_default_html('text');
711
+		foreach ( $fields as $field ) {
712
+			$field->field_options = maybe_unserialize($field->field_options);
713 713
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
714
-                $field->field_options['custom_html'] = $new_default_html;
714
+				$field->field_options['custom_html'] = $new_default_html;
715 715
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
716
-            }
717
-            unset($field);
718
-        }
719
-        unset($default_html, $old_default_html, $fields);
720
-    }
721
-
722
-    private function migrate_to_4() {
723
-        global $wpdb;
716
+			}
717
+			unset($field);
718
+		}
719
+		unset($default_html, $old_default_html, $fields);
720
+	}
721
+
722
+	private function migrate_to_4() {
723
+		global $wpdb;
724 724
 		$user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) );
725
-        foreach ( $user_ids as $user_id ) {
725
+		foreach ( $user_ids as $user_id ) {
726 726
 			$wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) );
727
-        }
728
-    }
727
+		}
728
+	}
729 729
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
     var $entry_metas;
8 8
 
9 9
     public function __construct() {
10
-        if ( ! defined('ABSPATH') ) {
11
-            die('You are not allowed to call this page directly.');
10
+        if ( ! defined( 'ABSPATH' ) ) {
11
+            die( 'You are not allowed to call this page directly.' );
12 12
         }
13 13
 
14 14
         global $wpdb;
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
         $frm_db_version = FrmAppHelper::$db_version;
25 25
         $old_db_version = (float) $old_db_version;
26 26
         if ( ! $old_db_version ) {
27
-            $old_db_version = get_option('frm_db_version');
27
+            $old_db_version = get_option( 'frm_db_version' );
28 28
         }
29 29
 
30 30
         if ( $frm_db_version != $old_db_version ) {
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
35 35
 
36 36
             $this->create_tables();
37
-            $this->migrate_data($frm_db_version, $old_db_version);
37
+            $this->migrate_data( $frm_db_version, $old_db_version );
38 38
 
39 39
             /***** SAVE DB VERSION *****/
40
-            update_option('frm_db_version', $frm_db_version);
40
+            update_option( 'frm_db_version', $frm_db_version );
41 41
 
42 42
             /**** ADD/UPDATE DEFAULT TEMPLATES ****/
43 43
             FrmXMLController::add_default_templates();
44 44
         }
45 45
 
46
-        do_action('frm_after_install');
46
+        do_action( 'frm_after_install' );
47 47
 
48 48
         /**** update the styling settings ****/
49 49
 		if ( is_admin() && function_exists( 'get_filesystem_method' ) ) {
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 
61 61
         $charset_collate = '';
62 62
 		if ( ! empty( $wpdb->charset ) ) {
63
-			$charset_collate .= ' DEFAULT CHARACTER SET '. $wpdb->charset;
63
+			$charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset;
64 64
 		}
65 65
 
66
-        if ( ! empty($wpdb->collate) ) {
67
-            $charset_collate .= ' COLLATE '. $wpdb->collate;
66
+        if ( ! empty( $wpdb->collate ) ) {
67
+            $charset_collate .= ' COLLATE ' . $wpdb->collate;
68 68
         }
69 69
 
70 70
         return $charset_collate;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $sql = array();
76 76
 
77 77
         /* Create/Upgrade Fields Table */
78
-        $sql[] = 'CREATE TABLE '. $this->fields .' (
78
+        $sql[] = 'CREATE TABLE ' . $this->fields . ' (
79 79
                 id int(11) NOT NULL auto_increment,
80 80
 				field_key varchar(100) default NULL,
81 81
                 name text default NULL,
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
         )';
95 95
 
96 96
         /* Create/Upgrade Forms Table */
97
-        $sql[] = 'CREATE TABLE '. $this->forms .' (
97
+        $sql[] = 'CREATE TABLE ' . $this->forms . ' (
98 98
                 id int(11) NOT NULL auto_increment,
99 99
 				form_key varchar(100) default NULL,
100 100
                 name varchar(255) default NULL,
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         )';
113 113
 
114 114
         /* Create/Upgrade Items Table */
115
-        $sql[] = 'CREATE TABLE '. $this->entries .' (
115
+        $sql[] = 'CREATE TABLE ' . $this->entries . ' (
116 116
                 id int(11) NOT NULL auto_increment,
117 117
 				item_key varchar(100) default NULL,
118 118
                 name varchar(255) default NULL,
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         )';
136 136
 
137 137
         /* Create/Upgrade Meta Table */
138
-        $sql[] = 'CREATE TABLE '. $this->entry_metas .' (
138
+        $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
139 139
                 id int(11) NOT NULL auto_increment,
140 140
                 meta_value longtext default NULL,
141 141
                 field_id int(11) NOT NULL,
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
 
149 149
         foreach ( $sql as $q ) {
150 150
 			if ( function_exists( 'dbDelta' ) ) {
151
-				dbDelta( $q . $charset_collate .';' );
151
+				dbDelta( $q . $charset_collate . ';' );
152 152
 			} else {
153 153
 				global $wpdb;
154 154
 				$wpdb->query( $q . $charset_collate );
155 155
 			}
156
-            unset($q);
156
+            unset( $q );
157 157
         }
158 158
     }
159 159
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		$migrations = array( 4, 6, 11, 16, 17, 23, 25 );
165 165
         foreach ( $migrations as $migration ) {
166 166
             if ( $frm_db_version >= $migration && $old_db_version < $migration ) {
167
-                $function_name = 'migrate_to_'. $migration;
167
+                $function_name = 'migrate_to_' . $migration;
168 168
                 $this->$function_name();
169 169
             }
170 170
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * Change array into format $wpdb->prepare can use
175 175
      */
176 176
     public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
177
-        if ( empty($args) ) {
177
+        if ( empty( $args ) ) {
178 178
 			// add an arg to prevent prepare from failing
179 179
 			$args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) );
180 180
 			return;
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
     private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
231 231
 		$key = trim( $key );
232 232
 
233
-        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false  ) {
234
-            $k = explode(' ', $key);
233
+        if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
234
+            $k = explode( ' ', $key );
235 235
             $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
236 236
             $values[] = '%Y-%m-%d %H:%i:%s';
237 237
         } else {
238
-            $where .= ' '. $key;
238
+            $where .= ' ' . $key;
239 239
         }
240 240
 
241 241
 		$lowercase_key = explode( ' ', strtolower( $key ) );
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 				}
258 258
 				$where .= ')';
259 259
 			} else if ( ! empty( $value ) ) {
260
-            	$where .= ' in ('. FrmAppHelper::prepare_array_values( $value, '%s' ) .')';
260
+            	$where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')';
261 261
 				$values = array_merge( $values, $value );
262 262
 			}
263 263
         } else if ( strpos( $lowercase_key, 'like' ) !== false ) {
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
 			$query .= $where . ' ' . implode( ' ', $args );
323 323
 		}
324 324
 
325
-        $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode('_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field .'_'. $type, ' WHERE' ) );
326
-        $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_'. $type );
325
+        $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) );
326
+        $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type );
327 327
         return $results;
328 328
     }
329 329
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 
355 355
     public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) {
356 356
         _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' );
357
-        return self::get_results( $table, $args, $fields, compact('order_by', 'limit') );
357
+        return self::get_results( $table, $args, $fields, compact( 'order_by', 'limit' ) );
358 358
     }
359 359
 
360 360
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 		);
388 388
 
389 389
 		$where_is = strtolower( $where_is );
390
-		if ( isset( $switch_to[ $where_is ] ) ) {
391
-			return ' ' . $switch_to[ $where_is ];
390
+		if ( isset( $switch_to[$where_is] ) ) {
391
+			return ' ' . $switch_to[$where_is];
392 392
 		}
393 393
 
394 394
 		// > and < need a little more work since we don't want them switched to >= and <=
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
     private static function get_group_and_table_name( &$table, &$group ) {
411 411
 		global $wpdb, $wpmuBaseTablePrefix;
412 412
 
413
-        $table_parts = explode(' ', $table);
414
-        $group = reset($table_parts);
413
+        $table_parts = explode( ' ', $table );
414
+        $group = reset( $table_parts );
415 415
         $group = str_replace( $wpdb->prefix, '', $group );
416 416
 
417 417
 		$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
     }
427 427
 
428 428
     private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
429
-        if ( ! is_array($args) ) {
429
+        if ( ! is_array( $args ) ) {
430 430
 			$args = array( 'order_by' => $args );
431 431
         }
432 432
 
@@ -441,16 +441,16 @@  discard block
 block discarded – undo
441 441
         $temp_args = $args;
442 442
         foreach ( $temp_args as $k => $v ) {
443 443
             if ( $v == '' ) {
444
-				unset( $args[ $k ] );
444
+				unset( $args[$k] );
445 445
                 continue;
446 446
             }
447 447
 
448 448
             if ( $k == 'limit' ) {
449
-				$args[ $k ] = FrmAppHelper::esc_limit( $v );
449
+				$args[$k] = FrmAppHelper::esc_limit( $v );
450 450
             }
451 451
             $db_name = strtoupper( str_replace( '_', ' ', $k ) );
452 452
             if ( strpos( $v, $db_name ) === false ) {
453
-				$args[ $k ] = $db_name . ' ' . $v;
453
+				$args[$k] = $db_name . ' ' . $v;
454 454
             }
455 455
         }
456 456
     }
@@ -458,18 +458,18 @@  discard block
 block discarded – undo
458 458
     public function uninstall() {
459 459
 		if ( ! current_user_can( 'administrator' ) ) {
460 460
             $frm_settings = FrmAppHelper::get_settings();
461
-            wp_die($frm_settings->admin_permission);
461
+            wp_die( $frm_settings->admin_permission );
462 462
         }
463 463
 
464 464
         global $wpdb, $wp_roles;
465 465
 
466
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->fields );
467
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->forms );
468
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entries );
469
-        $wpdb->query( 'DROP TABLE IF EXISTS '. $this->entry_metas );
466
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields );
467
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms );
468
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries );
469
+        $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas );
470 470
 
471
-        delete_option('frm_options');
472
-        delete_option('frm_db_version');
471
+        delete_option( 'frm_options' );
472
+        delete_option( 'frm_db_version' );
473 473
 
474 474
         //delete roles
475 475
         $frm_roles = FrmAppHelper::frm_capabilities();
@@ -477,11 +477,11 @@  discard block
 block discarded – undo
477 477
         foreach ( $frm_roles as $frm_role => $frm_role_description ) {
478 478
             foreach ( $roles as $role => $details ) {
479 479
                 $wp_roles->remove_cap( $role, $frm_role );
480
-                unset($role, $details);
480
+                unset( $role, $details );
481 481
     		}
482
-    		unset($frm_role, $frm_role_description);
482
+    		unset( $frm_role, $frm_role_description );
483 483
 		}
484
-		unset($roles, $frm_roles);
484
+		unset( $roles, $frm_roles );
485 485
 
486 486
 		// delete actions, views, and styles
487 487
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 		remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
490 490
 		remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
491 491
 
492
-		$post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts .' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
492
+		$post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
493 493
 		foreach ( $post_ids as $post_id ) {
494 494
 			// Delete's each post.
495 495
 			wp_delete_post( $post_id, true );
@@ -501,9 +501,9 @@  discard block
 block discarded – undo
501 501
 		delete_transient( 'frm_options' );
502 502
 		delete_transient( 'frmpro_options' );
503 503
 
504
-		$wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
504
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
505 505
 
506
-        do_action('frm_after_uninstall');
506
+        do_action( 'frm_after_uninstall' );
507 507
         return true;
508 508
     }
509 509
 
@@ -538,9 +538,9 @@  discard block
 block discarded – undo
538 538
 	 */
539 539
 	private function migrate_to_23() {
540 540
 		global $wpdb;
541
-		$exists = $wpdb->get_row( 'SHOW COLUMNS FROM '. $this->forms .' LIKE "parent_form_id"' );
541
+		$exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' );
542 542
 		if ( empty( $exists ) ) {
543
-			$wpdb->query( 'ALTER TABLE '. $this->forms .' ADD parent_form_id int(11) default 0' );
543
+			$wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' );
544 544
 		}
545 545
 	}
546 546
 
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 
561 561
         $updated = 0;
562 562
         foreach ( $fields as $f ) {
563
-            $f->field_options = maybe_unserialize($f->field_options);
564
-            if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) {
563
+            $f->field_options = maybe_unserialize( $f->field_options );
564
+            if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
565 565
                 continue;
566 566
             }
567 567
 
@@ -569,27 +569,27 @@  discard block
 block discarded – undo
569 569
             $f->field_options['size'] .= 'px';
570 570
             $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
571 571
             if ( $u ) {
572
-                $updated++;
572
+                $updated ++;
573 573
             }
574
-            unset($f);
574
+            unset( $f );
575 575
         }
576 576
 
577 577
         // Change the characters in widgets to pixels
578
-        $widgets = get_option('widget_frm_show_form');
579
-        if ( empty($widgets) ) {
578
+        $widgets = get_option( 'widget_frm_show_form' );
579
+        if ( empty( $widgets ) ) {
580 580
             return;
581 581
         }
582 582
 
583
-        $widgets = maybe_unserialize($widgets);
583
+        $widgets = maybe_unserialize( $widgets );
584 584
         foreach ( $widgets as $k => $widget ) {
585
-            if ( ! is_array($widget) || ! isset($widget['size']) ) {
585
+            if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
586 586
                 continue;
587 587
             }
588 588
 			$size = round( $pixel_conversion * (int) $widget['size'] );
589 589
             $size .= 'px';
590
-			$widgets[ $k ]['size'] = $size;
590
+			$widgets[$k]['size'] = $size;
591 591
         }
592
-        update_option('widget_frm_show_form', $widgets);
592
+        update_option( 'widget_frm_show_form', $widgets );
593 593
     }
594 594
 
595 595
     /**
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 			}
639 639
 
640 640
             // Format form options
641
-            $form_options = maybe_unserialize($form->options);
641
+            $form_options = maybe_unserialize( $form->options );
642 642
 
643 643
             // Migrate settings to actions
644 644
             FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
     private function migrate_to_11() {
649 649
         global $wpdb;
650 650
 
651
-        $forms = FrmDb::get_results( $this->forms, array(), 'id, options');
651
+        $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
652 652
 
653 653
         $sending = __( 'Sending', 'formidable' );
654
-        $img = FrmAppHelper::plugin_url() .'/images/ajax_loader.gif';
654
+        $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
655 655
         $old_default_html = <<<DEFAULT_HTML
656 656
 <div class="frm_submit">
657 657
 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
660 660
 </div>
661 661
 DEFAULT_HTML;
662
-        unset($sending, $img);
662
+        unset( $sending, $img );
663 663
 
664
-        $new_default_html = FrmFormsHelper::get_default_html('submit');
664
+        $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
665 665
         $draft_link = FrmFormsHelper::get_draft_link();
666 666
 		foreach ( $forms as $form ) {
667
-            $form->options = maybe_unserialize($form->options);
668
-            if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) {
667
+            $form->options = maybe_unserialize( $form->options );
668
+            if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) {
669 669
                 continue;
670 670
             }
671 671
 
@@ -673,12 +673,12 @@  discard block
 block discarded – undo
673 673
                 $form->options['submit_html'] = $new_default_html;
674 674
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
675 675
 			} else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
676
-                $form->options['submit_html'] = preg_replace('~\<\/div\>(?!.*\<\/div\>)~', $draft_link ."\r\n</div>", $form->options['submit_html']);
676
+                $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
677 677
 				$wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
678 678
             }
679
-            unset($form);
679
+            unset( $form );
680 680
         }
681
-        unset($forms);
681
+        unset( $forms );
682 682
     }
683 683
 
684 684
     private function migrate_to_6() {
@@ -707,16 +707,16 @@  discard block
 block discarded – undo
707 707
 </div>
708 708
 DEFAULT_HTML;
709 709
 
710
-        $new_default_html = FrmFieldsHelper::get_default_html('text');
710
+        $new_default_html = FrmFieldsHelper::get_default_html( 'text' );
711 711
         foreach ( $fields as $field ) {
712
-            $field->field_options = maybe_unserialize($field->field_options);
712
+            $field->field_options = maybe_unserialize( $field->field_options );
713 713
 			if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) {
714 714
                 $field->field_options['custom_html'] = $new_default_html;
715 715
 				$wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) );
716 716
             }
717
-            unset($field);
717
+            unset( $field );
718 718
         }
719
-        unset($default_html, $old_default_html, $fields);
719
+        unset( $default_html, $old_default_html, $fields );
720 720
     }
721 721
 
722 722
     private function migrate_to_4() {
Please login to merge, or discard this patch.
classes/models/FrmEntry.php 2 patches
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@  discard block
 block discarded – undo
6 6
 class FrmEntry {
7 7
 
8 8
 	/**
9
-	* Create a new entry
10
-	*
11
-	* @param array $values
12
-	* @return int | boolean $entry_id
13
-	*/
9
+	 * Create a new entry
10
+	 *
11
+	 * @param array $values
12
+	 * @return int | boolean $entry_id
13
+	 */
14 14
 	public static function create( $values ) {
15 15
 		$entry_id = self::create_entry( $values, 'standard' );
16 16
 
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	/**
21
-	* Create a new entry with some differences depending on type
22
-	*
23
-	* @param array $values
24
-	* @param string $type
25
-	* @return int | boolean $entry_id
26
-	*/
21
+	 * Create a new entry with some differences depending on type
22
+	 *
23
+	 * @param array $values
24
+	 * @param string $type
25
+	 * @return int | boolean $entry_id
26
+	 */
27 27
 	private static function create_entry( $values, $type ) {
28 28
 		$new_values = self::before_insert_entry_in_database( $values, $type );
29 29
 
@@ -37,110 +37,110 @@  discard block
 block discarded – undo
37 37
 		return $entry_id;
38 38
 	}
39 39
 
40
-    /**
41
-     * check for duplicate entries created in the last minute
42
-     * @return boolean
43
-     */
40
+	/**
41
+	 * check for duplicate entries created in the last minute
42
+	 * @return boolean
43
+	 */
44 44
 	public static function is_duplicate( $new_values, $values ) {
45 45
 		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
46
-            return false;
47
-        }
46
+			return false;
47
+		}
48 48
 
49 49
 		$duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
50 50
 		if ( empty( $duplicate_entry_time ) ) {
51 51
 			return false;
52 52
 		}
53 53
 
54
-        $check_val = $new_values;
54
+		$check_val = $new_values;
55 55
 		$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
56 56
 
57 57
 		unset( $check_val['created_at'], $check_val['updated_at'] );
58 58
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
59 59
 
60
-        if ( $new_values['item_key'] == $new_values['name'] ) {
61
-            unset($check_val['name']);
62
-        }
60
+		if ( $new_values['item_key'] == $new_values['name'] ) {
61
+			unset($check_val['name']);
62
+		}
63 63
 
64
-        global $wpdb;
64
+		global $wpdb;
65 65
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
66 66
 
67
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
68
-            return false;
69
-        }
67
+		if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
68
+			return false;
69
+		}
70 70
 
71
-        $is_duplicate = false;
72
-        foreach ( $entry_exists as $entry_exist ) {
73
-            $is_duplicate = true;
71
+		$is_duplicate = false;
72
+		foreach ( $entry_exists as $entry_exist ) {
73
+			$is_duplicate = true;
74 74
 
75
-            //add more checks here to make sure it's a duplicate
76
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
77
-            $field_metas = array();
78
-            foreach ( $metas as $meta ) {
75
+			//add more checks here to make sure it's a duplicate
76
+			$metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
77
+			$field_metas = array();
78
+			foreach ( $metas as $meta ) {
79 79
 				$field_metas[ $meta->field_id ] = $meta->meta_value;
80
-            }
81
-
82
-            // If prev entry is empty and current entry is not, they are not duplicates
83
-            $filtered_vals = array_filter( $values['item_meta'] );
84
-            if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
85
-                return false;
86
-            }
87
-
88
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
89
-            foreach ( $diff as $field_id => $meta_value ) {
90
-                if ( ! empty($meta_value) ) {
91
-                    $is_duplicate = false;
92
-                    continue;
93
-                }
94
-            }
95
-
96
-            if ( $is_duplicate ) {
80
+			}
81
+
82
+			// If prev entry is empty and current entry is not, they are not duplicates
83
+			$filtered_vals = array_filter( $values['item_meta'] );
84
+			if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
85
+				return false;
86
+			}
87
+
88
+			$diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
89
+			foreach ( $diff as $field_id => $meta_value ) {
90
+				if ( ! empty($meta_value) ) {
91
+					$is_duplicate = false;
92
+					continue;
93
+				}
94
+			}
95
+
96
+			if ( $is_duplicate ) {
97 97
 				break;
98
-            }
99
-        }
98
+			}
99
+		}
100 100
 
101
-        return $is_duplicate;
102
-    }
101
+		return $is_duplicate;
102
+	}
103 103
 
104
-    public static function duplicate( $id ) {
105
-        global $wpdb;
104
+	public static function duplicate( $id ) {
105
+		global $wpdb;
106 106
 
107
-        $values = self::getOne( $id );
107
+		$values = self::getOne( $id );
108 108
 
109
-        $new_values = array();
110
-        $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
111
-        $new_values['name'] = $values->name;
112
-        $new_values['is_draft'] = $values->is_draft;
113
-        $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
114
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
115
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
109
+		$new_values = array();
110
+		$new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
111
+		$new_values['name'] = $values->name;
112
+		$new_values['is_draft'] = $values->is_draft;
113
+		$new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
114
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
115
+		$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
116 116
 
117
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
118
-        if ( ! $query_results ) {
119
-            return false;
120
-        }
117
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
118
+		if ( ! $query_results ) {
119
+			return false;
120
+		}
121 121
 
122
-        $entry_id = $wpdb->insert_id;
122
+		$entry_id = $wpdb->insert_id;
123 123
 
124
-        global $frm_vars;
125
-        if ( ! isset($frm_vars['saved_entries']) ) {
126
-            $frm_vars['saved_entries'] = array();
127
-        }
128
-        $frm_vars['saved_entries'][] = (int) $entry_id;
124
+		global $frm_vars;
125
+		if ( ! isset($frm_vars['saved_entries']) ) {
126
+			$frm_vars['saved_entries'] = array();
127
+		}
128
+		$frm_vars['saved_entries'][] = (int) $entry_id;
129 129
 
130
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
130
+		FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
131 131
 		self::clear_cache();
132 132
 
133 133
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
134
-        return $entry_id;
135
-    }
134
+		return $entry_id;
135
+	}
136 136
 
137 137
 	/**
138
-	* Update an entry (not via XML)
139
-	*
140
-	* @param int $id
141
-	* @param array $values
142
-	* @return boolean|int $update_results
143
-	*/
138
+	 * Update an entry (not via XML)
139
+	 *
140
+	 * @param int $id
141
+	 * @param array $values
142
+	 * @return boolean|int $update_results
143
+	 */
144 144
 	public static function update( $id, $values ) {
145 145
 		$update_results = self::update_entry( $id, $values, 'standard' );
146 146
 
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 	}
149 149
 
150 150
 	/**
151
-	* Update an entry with some differences depending on the update type
152
-	*
153
-	* @since 2.0.16
154
-	*
155
-	* @param int $id
156
-	* @param array $values
157
-	* @return boolean|int $query_results
158
-	*/
151
+	 * Update an entry with some differences depending on the update type
152
+	 *
153
+	 * @since 2.0.16
154
+	 *
155
+	 * @param int $id
156
+	 * @param array $values
157
+	 * @return boolean|int $query_results
158
+	 */
159 159
 	private static function update_entry( $id, $values, $update_type ) {
160 160
 		global $wpdb;
161 161
 
@@ -174,34 +174,34 @@  discard block
 block discarded – undo
174 174
 	}
175 175
 
176 176
 	public static function &destroy( $id ) {
177
-        global $wpdb;
178
-        $id = (int) $id;
177
+		global $wpdb;
178
+		$id = (int) $id;
179 179
 
180 180
 		$entry = self::getOne( $id );
181
-        if ( ! $entry ) {
182
-            $result = false;
183
-            return $result;
184
-        }
181
+		if ( ! $entry ) {
182
+			$result = false;
183
+			return $result;
184
+		}
185 185
 
186
-        do_action('frm_before_destroy_entry', $id, $entry);
186
+		do_action('frm_before_destroy_entry', $id, $entry);
187 187
 
188
-        $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
189
-        $result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
188
+		$wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
189
+		$result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
190 190
 
191 191
 		self::clear_cache();
192 192
 
193
-        return $result;
194
-    }
193
+		return $result;
194
+	}
195 195
 
196 196
 	public static function &update_form( $id, $value, $form_id ) {
197
-        global $wpdb;
198
-        $form_id = isset($value) ? $form_id : null;
197
+		global $wpdb;
198
+		$form_id = isset($value) ? $form_id : null;
199 199
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
200 200
 		if ( $result ) {
201 201
 			self::clear_cache();
202 202
 		}
203
-        return $result;
204
-    }
203
+		return $result;
204
+	}
205 205
 
206 206
 	/**
207 207
 	 * Clear entry caching
@@ -237,161 +237,161 @@  discard block
 block discarded – undo
237 237
 	}
238 238
 
239 239
 	public static function getOne( $id, $meta = false ) {
240
-        global $wpdb;
240
+		global $wpdb;
241 241
 
242
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
242
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
243 243
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
244 244
 
245
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
246
-        $query_args = array( $id );
247
-        $query = $wpdb->prepare( $query, $query_args );
245
+		$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
246
+		$query_args = array( $id );
247
+		$query = $wpdb->prepare( $query, $query_args );
248 248
 
249
-        if ( ! $meta ) {
250
-            $entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
251
-            return stripslashes_deep($entry);
252
-        }
249
+		if ( ! $meta ) {
250
+			$entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
251
+			return stripslashes_deep($entry);
252
+		}
253 253
 
254
-        $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
255
-        if ( $entry !== false ) {
256
-            return stripslashes_deep($entry);
257
-        }
254
+		$entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
255
+		if ( $entry !== false ) {
256
+			return stripslashes_deep($entry);
257
+		}
258 258
 
259
-        $entry = $wpdb->get_row( $query );
260
-        $entry = self::get_meta($entry);
259
+		$entry = $wpdb->get_row( $query );
260
+		$entry = self::get_meta($entry);
261 261
 
262
-        return stripslashes_deep($entry);
263
-    }
262
+		return stripslashes_deep($entry);
263
+	}
264 264
 
265 265
 	public static function get_meta( $entry ) {
266
-        if ( ! $entry ) {
267
-            return $entry;
268
-        }
266
+		if ( ! $entry ) {
267
+			return $entry;
268
+		}
269 269
 
270
-        global $wpdb;
270
+		global $wpdb;
271 271
 		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' );
272 272
 
273
-        $entry->metas = array();
273
+		$entry->metas = array();
274 274
 
275 275
 		$include_key = apply_filters( 'frm_include_meta_keys', false );
276
-        foreach ( $metas as $meta_val ) {
277
-            if ( $meta_val->item_id == $entry->id ) {
276
+		foreach ( $metas as $meta_val ) {
277
+			if ( $meta_val->item_id == $entry->id ) {
278 278
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
279 279
 				if ( $include_key ) {
280 280
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
281 281
 				}
282
-                 continue;
283
-            }
282
+				 continue;
283
+			}
284 284
 
285
-            // include sub entries in an array
285
+			// include sub entries in an array
286 286
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
287 287
 				$entry->metas[ $meta_val->field_id ] = array();
288
-            }
288
+			}
289 289
 
290 290
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
291 291
 
292
-            unset($meta_val);
293
-        }
294
-        unset($metas);
292
+			unset($meta_val);
293
+		}
294
+		unset($metas);
295 295
 
296
-        wp_cache_set( $entry->id, $entry, 'frm_entry');
296
+		wp_cache_set( $entry->id, $entry, 'frm_entry');
297 297
 
298
-        return $entry;
299
-    }
298
+		return $entry;
299
+	}
300 300
 
301
-    /**
302
-     * @param string $id
303
-     */
301
+	/**
302
+	 * @param string $id
303
+	 */
304 304
 	public static function &exists( $id ) {
305
-        global $wpdb;
305
+		global $wpdb;
306 306
 
307
-        if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
308
-            $exists = true;
309
-            return $exists;
310
-        }
307
+		if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
308
+			$exists = true;
309
+			return $exists;
310
+		}
311 311
 
312
-        if ( is_numeric($id) ) {
313
-            $where = array( 'id' => $id );
314
-        } else {
315
-            $where = array( 'item_key' => $id );
316
-        }
317
-        $id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
312
+		if ( is_numeric($id) ) {
313
+			$where = array( 'id' => $id );
314
+		} else {
315
+			$where = array( 'item_key' => $id );
316
+		}
317
+		$id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
318 318
 
319
-        $exists = ($id && $id > 0) ? true : false;
320
-        return $exists;
321
-    }
319
+		$exists = ($id && $id > 0) ? true : false;
320
+		return $exists;
321
+	}
322 322
 
323
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
323
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
324 324
 		global $wpdb;
325 325
 
326
-        $limit = FrmAppHelper::esc_limit($limit);
326
+		$limit = FrmAppHelper::esc_limit($limit);
327 327
 
328
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
329
-        $entries = wp_cache_get($cache_key, 'frm_entry');
328
+		$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
329
+		$entries = wp_cache_get($cache_key, 'frm_entry');
330 330
 
331
-        if ( false === $entries ) {
332
-            $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
333
-            $table = $wpdb->prefix .'frm_items it ';
331
+		if ( false === $entries ) {
332
+			$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
333
+			$table = $wpdb->prefix .'frm_items it ';
334 334
 
335
-            if ( $inc_form ) {
336
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
337
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
338
-            }
335
+			if ( $inc_form ) {
336
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
337
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
338
+			}
339 339
 
340
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
341
-    		    // sort by a requested field
342
-                $field_id = (int) $order_matches[1];
340
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
341
+				// sort by a requested field
342
+				$field_id = (int) $order_matches[1];
343 343
 				$fields .= ', (SELECT meta_value FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id = '. $field_id .' AND item_id = it.id) as meta_'. $field_id;
344 344
 				unset( $order_matches, $field_id );
345
-		    }
345
+			}
346 346
 
347 347
 			// prepare the query
348 348
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
349 349
 
350
-            $entries = $wpdb->get_results($query, OBJECT_K);
351
-            unset($query);
350
+			$entries = $wpdb->get_results($query, OBJECT_K);
351
+			unset($query);
352 352
 
353 353
 			if ( ! FrmAppHelper::prevent_caching() ) {
354 354
 				wp_cache_set( $cache_key, $entries, 'frm_entry', 300 );
355 355
 			}
356
-        }
356
+		}
357 357
 
358
-        if ( ! $meta || ! $entries ) {
359
-            return stripslashes_deep($entries);
360
-        }
361
-        unset($meta);
358
+		if ( ! $meta || ! $entries ) {
359
+			return stripslashes_deep($entries);
360
+		}
361
+		unset($meta);
362 362
 
363
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
363
+		if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
364 364
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
365
-        }
365
+		}
366 366
 
367
-        $meta_where = array( 'field_id !' => 0 );
368
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
369
-            $meta_where['fi.form_id'] = $where['it.form_id'];
370
-        } else {
371
-            $meta_where['item_id'] = array_keys( $entries );
372
-        }
367
+		$meta_where = array( 'field_id !' => 0 );
368
+		if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
369
+			$meta_where['fi.form_id'] = $where['it.form_id'];
370
+		} else {
371
+			$meta_where['item_id'] = array_keys( $entries );
372
+		}
373 373
 
374
-        $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
374
+		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
375 375
 
376
-        unset( $meta_where );
376
+		unset( $meta_where );
377 377
 
378
-        if ( ! $metas ) {
379
-            return stripslashes_deep($entries);
380
-        }
378
+		if ( ! $metas ) {
379
+			return stripslashes_deep($entries);
380
+		}
381 381
 
382
-        foreach ( $metas as $m_key => $meta_val ) {
383
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
384
-                continue;
385
-            }
382
+		foreach ( $metas as $m_key => $meta_val ) {
383
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
384
+				continue;
385
+			}
386 386
 
387
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
387
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
388 388
 				$entries[ $meta_val->item_id ]->metas = array();
389
-            }
389
+			}
390 390
 
391 391
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
392 392
 
393
-            unset($m_key, $meta_val);
394
-        }
393
+			unset($m_key, $meta_val);
394
+		}
395 395
 
396 396
 		if ( ! FrmAppHelper::prevent_caching() ) {
397 397
 			foreach ( $entries as $entry ) {
@@ -400,47 +400,47 @@  discard block
 block discarded – undo
400 400
 			}
401 401
 		}
402 402
 
403
-        return stripslashes_deep($entries);
404
-    }
405
-
406
-    // Pagination Methods
407
-    public static function getRecordCount( $where = '' ) {
408
-        global $wpdb;
409
-        $table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
410
-
411
-        if ( is_numeric($where) ) {
412
-            $table_join = 'frm_items';
413
-            $where = array( 'form_id' => $where );
414
-        }
415
-
416
-        if ( is_array( $where ) ) {
417
-            $count = FrmDb::get_count( $table_join, $where );
418
-        } else {
419
-            global $wpdb;
420
-            $cache_key = 'count_'. maybe_serialize($where);
421
-            $query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
422
-            $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
423
-        }
424
-
425
-        return $count;
426
-    }
427
-
428
-    public static function getPageCount( $p_size, $where = '' ) {
429
-        if ( is_numeric($where) ) {
430
-            return ceil( (int) $where / (int) $p_size );
431
-        } else {
432
-            return ceil( (int) self::getRecordCount($where) / (int) $p_size );
433
-        }
434
-    }
435
-
436
-	/**
437
-	* Prepare the data before inserting it into the database
438
-	*
439
-	* @since 2.0.16
440
-	* @param array $values
441
-	* @param string $type
442
-	* @return array $new_values
443
-	*/
403
+		return stripslashes_deep($entries);
404
+	}
405
+
406
+	// Pagination Methods
407
+	public static function getRecordCount( $where = '' ) {
408
+		global $wpdb;
409
+		$table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
410
+
411
+		if ( is_numeric($where) ) {
412
+			$table_join = 'frm_items';
413
+			$where = array( 'form_id' => $where );
414
+		}
415
+
416
+		if ( is_array( $where ) ) {
417
+			$count = FrmDb::get_count( $table_join, $where );
418
+		} else {
419
+			global $wpdb;
420
+			$cache_key = 'count_'. maybe_serialize($where);
421
+			$query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
422
+			$count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
423
+		}
424
+
425
+		return $count;
426
+	}
427
+
428
+	public static function getPageCount( $p_size, $where = '' ) {
429
+		if ( is_numeric($where) ) {
430
+			return ceil( (int) $where / (int) $p_size );
431
+		} else {
432
+			return ceil( (int) self::getRecordCount($where) / (int) $p_size );
433
+		}
434
+	}
435
+
436
+	/**
437
+	 * Prepare the data before inserting it into the database
438
+	 *
439
+	 * @since 2.0.16
440
+	 * @param array $values
441
+	 * @param string $type
442
+	 * @return array $new_values
443
+	 */
444 444
 	private static function before_insert_entry_in_database( &$values, $type ) {
445 445
 
446 446
 		self::sanitize_entry_post( $values );
@@ -455,13 +455,13 @@  discard block
 block discarded – undo
455 455
 	}
456 456
 
457 457
 	/**
458
-	* Create an entry and perform after create actions
459
-	*
460
-	* @since 2.0.16
461
-	* @param array $values
462
-	* @param array $new_values
463
-	* @return boolean|int $entry_id
464
-	*/
458
+	 * Create an entry and perform after create actions
459
+	 *
460
+	 * @since 2.0.16
461
+	 * @param array $values
462
+	 * @param array $new_values
463
+	 * @return boolean|int $entry_id
464
+	 */
465 465
 	private static function continue_to_create_entry( $values, $new_values ) {
466 466
 		$entry_id = self::insert_entry_into_database( $new_values );
467 467
 		if ( ! $entry_id ) {
@@ -473,37 +473,37 @@  discard block
 block discarded – undo
473 473
 		return $entry_id;
474 474
 	}
475 475
 
476
-    /**
477
-     * Sanitize the POST values before we use them
478
-     *
479
-     * @since 2.0
480
-     * @param array $values The POST values by reference
481
-     */
482
-    public static function sanitize_entry_post( &$values ) {
483
-        $sanitize_method = array(
484
-            'form_id'       => 'absint',
485
-            'frm_action'    => 'sanitize_title',
486
-            'form_key'      => 'sanitize_title',
487
-            'item_key'      => 'sanitize_title',
488
-            'item_name'     => 'sanitize_text_field',
489
-            'frm_saving_draft' => 'absint',
490
-            'is_draft'      => 'absint',
491
-            'post_id'       => 'absint',
492
-            'parent_item_id' => 'absint',
493
-            'created_at'    => 'sanitize_text_field',
494
-            'updated_at'    => 'sanitize_text_field',
495
-        );
496
-
497
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
498
-    }
499
-
500
-	/**
501
-	* Prepare the new values for inserting into the database
502
-	*
503
-	* @since 2.0.16
504
-	* @param array $values
505
-	* @return array $new_values
506
-	*/
476
+	/**
477
+	 * Sanitize the POST values before we use them
478
+	 *
479
+	 * @since 2.0
480
+	 * @param array $values The POST values by reference
481
+	 */
482
+	public static function sanitize_entry_post( &$values ) {
483
+		$sanitize_method = array(
484
+			'form_id'       => 'absint',
485
+			'frm_action'    => 'sanitize_title',
486
+			'form_key'      => 'sanitize_title',
487
+			'item_key'      => 'sanitize_title',
488
+			'item_name'     => 'sanitize_text_field',
489
+			'frm_saving_draft' => 'absint',
490
+			'is_draft'      => 'absint',
491
+			'post_id'       => 'absint',
492
+			'parent_item_id' => 'absint',
493
+			'created_at'    => 'sanitize_text_field',
494
+			'updated_at'    => 'sanitize_text_field',
495
+		);
496
+
497
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
498
+	}
499
+
500
+	/**
501
+	 * Prepare the new values for inserting into the database
502
+	 *
503
+	 * @since 2.0.16
504
+	 * @param array $values
505
+	 * @return array $new_values
506
+	 */
507 507
 	private static function package_entry_data( &$values ) {
508 508
 		global $wpdb;
509 509
 
@@ -536,67 +536,67 @@  discard block
 block discarded – undo
536 536
 	}
537 537
 
538 538
 	/**
539
-	* Get the is_draft value for a new entry
540
-	*
541
-	* @since 2.0.16
542
-	* @param array $values
543
-	* @return int
544
-	*/
539
+	 * Get the is_draft value for a new entry
540
+	 *
541
+	 * @since 2.0.16
542
+	 * @param array $values
543
+	 * @return int
544
+	 */
545 545
 	private static function get_is_draft_value( $values ) {
546 546
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
547 547
 	}
548 548
 
549 549
 	/**
550
-	* Get the form_id value for a new entry
551
-	*
552
-	* @since 2.0.16
553
-	* @param array $values
554
-	* @return int|null
555
-	*/
550
+	 * Get the form_id value for a new entry
551
+	 *
552
+	 * @since 2.0.16
553
+	 * @param array $values
554
+	 * @return int|null
555
+	 */
556 556
 	private static function get_form_id( $values ) {
557 557
 		return isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
558 558
 	}
559 559
 
560 560
 	/**
561
-	* Get the post_id value for a new entry
562
-	*
563
-	* @since 2.0.16
564
-	* @param array $values
565
-	* @return int
566
-	*/
561
+	 * Get the post_id value for a new entry
562
+	 *
563
+	 * @since 2.0.16
564
+	 * @param array $values
565
+	 * @return int
566
+	 */
567 567
 	private static function get_post_id( $values ) {
568 568
 		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
569 569
 	}
570 570
 
571 571
 	/**
572
-	* Get the parent_item_id value for a new entry
573
-	*
574
-	* @since 2.0.16
575
-	* @param array $values
576
-	* @return int
577
-	*/
572
+	 * Get the parent_item_id value for a new entry
573
+	 *
574
+	 * @since 2.0.16
575
+	 * @param array $values
576
+	 * @return int
577
+	 */
578 578
 	private static function get_parent_item_id( $values ) {
579 579
 		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
580 580
 	}
581 581
 
582 582
 	/**
583
-	* Get the created_at value for a new entry
584
-	*
585
-	* @since 2.0.16
586
-	* @param array $values
587
-	* @return string
588
-	*/
583
+	 * Get the created_at value for a new entry
584
+	 *
585
+	 * @since 2.0.16
586
+	 * @param array $values
587
+	 * @return string
588
+	 */
589 589
 	private static function get_created_at( $values ) {
590 590
 		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
591 591
 	}
592 592
 
593 593
 	/**
594
-	* Get the updated_at value for a new entry
595
-	*
596
-	* @since 2.0.16
597
-	* @param array $values
598
-	* @return string
599
-	*/
594
+	 * Get the updated_at value for a new entry
595
+	 *
596
+	 * @since 2.0.16
597
+	 * @param array $values
598
+	 * @return string
599
+	 */
600 600
 	private static function get_updated_at( $values ) {
601 601
 		if ( isset( $values['updated_at'] ) ) {
602 602
 			$updated_at = $values['updated_at'];
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
 	}
609 609
 
610 610
 	/**
611
-	* Get the description value for a new entry
612
-	*
613
-	* @since 2.0.16
614
-	* @param array $values
615
-	* @return string
616
-	*/
611
+	 * Get the description value for a new entry
612
+	 *
613
+	 * @since 2.0.16
614
+	 * @param array $values
615
+	 * @return string
616
+	 */
617 617
 	private static function get_entry_description( $values ) {
618 618
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
619 619
 			$description = maybe_serialize( $values['description'] );
@@ -628,12 +628,12 @@  discard block
 block discarded – undo
628 628
 	}
629 629
 
630 630
 	/**
631
-	* Get the user_id value for a new entry
632
-	*
633
-	* @since 2.0.16
634
-	* @param array $values
635
-	* @return int
636
-	*/
631
+	 * Get the user_id value for a new entry
632
+	 *
633
+	 * @since 2.0.16
634
+	 * @param array $values
635
+	 * @return int
636
+	 */
637 637
 	private static function get_entry_user_id( $values ) {
638 638
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
639 639
 			$user_id = $values['frm_user_id'];
@@ -646,12 +646,12 @@  discard block
 block discarded – undo
646 646
 	}
647 647
 
648 648
 	/**
649
-	* Insert new entry into the database
650
-	*
651
-	* @since 2.0.16
652
-	* @param array $new_values
653
-	* @return int | boolean $entry_id
654
-	*/
649
+	 * Insert new entry into the database
650
+	 *
651
+	 * @since 2.0.16
652
+	 * @param array $new_values
653
+	 * @return int | boolean $entry_id
654
+	 */
655 655
 	private static function insert_entry_into_database( $new_values ) {
656 656
 		global $wpdb;
657 657
 
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
 	}
668 668
 
669 669
 	/**
670
-	* Add the new entry to global $frm_vars
671
-	*
672
-	* @since 2.0.16
673
-	* @param int $entry_id
674
-	*/
670
+	 * Add the new entry to global $frm_vars
671
+	 *
672
+	 * @since 2.0.16
673
+	 * @param int $entry_id
674
+	 */
675 675
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
676 676
 		global $frm_vars;
677 677
 
@@ -683,12 +683,12 @@  discard block
 block discarded – undo
683 683
 	}
684 684
 
685 685
 	/**
686
-	* Add entry metas, if there are any
687
-	*
688
-	* @since 2.0.16
689
-	* @param array $values
690
-	* @param int $entry_id
691
-	*/
686
+	 * Add entry metas, if there are any
687
+	 *
688
+	 * @since 2.0.16
689
+	 * @param array $values
690
+	 * @param int $entry_id
691
+	 */
692 692
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
693 693
 		if ( isset($values['item_meta']) ) {
694 694
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -696,12 +696,12 @@  discard block
 block discarded – undo
696 696
 	}
697 697
 
698 698
 	/**
699
-	* Trigger frm_after_create_entry hooks
700
-	*
701
-	* @since 2.0.16
702
-	* @param int $entry_id
703
-	* @param array $new_values
704
-	*/
699
+	 * Trigger frm_after_create_entry hooks
700
+	 *
701
+	 * @since 2.0.16
702
+	 * @param int $entry_id
703
+	 * @param array $new_values
704
+	 */
705 705
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
706 706
 		// this is a child entry
707 707
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -711,13 +711,13 @@  discard block
 block discarded – undo
711 711
 	}
712 712
 
713 713
 	/**
714
-	* Actions to perform immediately after an entry is inserted in the frm_items database
715
-	*
716
-	* @since 2.0.16
717
-	* @param array $values
718
-	* @param array $new_values
719
-	* @param int $entry_id
720
-	*/
714
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
715
+	 *
716
+	 * @since 2.0.16
717
+	 * @param array $values
718
+	 * @param array $new_values
719
+	 * @param int $entry_id
720
+	 */
721 721
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
722 722
 
723 723
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -730,14 +730,14 @@  discard block
 block discarded – undo
730 730
 	}
731 731
 
732 732
 	/**
733
-	* Perform some actions right before updating an entry
734
-	*
735
-	* @since 2.0.16
736
-	* @param int $id
737
-	* @param array $values
738
-	* @param string $update_type
739
-	* @return boolean $update
740
-	*/
733
+	 * Perform some actions right before updating an entry
734
+	 *
735
+	 * @since 2.0.16
736
+	 * @param int $id
737
+	 * @param array $values
738
+	 * @param string $update_type
739
+	 * @return boolean $update
740
+	 */
741 741
 	private static function before_update_entry( $id, &$values, $update_type ) {
742 742
 		$update = true;
743 743
 
@@ -755,13 +755,13 @@  discard block
 block discarded – undo
755 755
 	}
756 756
 
757 757
 	/**
758
-	* Package the entry data for updating
759
-	*
760
-	* @since 2.0.16
761
-	* @param int $id
762
-	* @param array $values
763
-	* @return array $new_values
764
-	*/
758
+	 * Package the entry data for updating
759
+	 *
760
+	 * @since 2.0.16
761
+	 * @param int $id
762
+	 * @param array $values
763
+	 * @return array $new_values
764
+	 */
765 765
 	private static function package_entry_to_update( $id, $values ) {
766 766
 		global $wpdb;
767 767
 
@@ -795,14 +795,14 @@  discard block
 block discarded – undo
795 795
 	}
796 796
 
797 797
 	/**
798
-	* Perform some actions right after updating an entry
799
-	*
800
-	* @since 2.0.16
801
-	* @param boolean|int $query_results
802
-	* @param int $id
803
-	* @param array $values
804
-	* @param array $new_values
805
-	*/
798
+	 * Perform some actions right after updating an entry
799
+	 *
800
+	 * @since 2.0.16
801
+	 * @param boolean|int $query_results
802
+	 * @param int $id
803
+	 * @param array $values
804
+	 * @param array $new_values
805
+	 */
806 806
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
807 807
 		if ( $query_results ) {
808 808
 			self::clear_cache();
@@ -824,13 +824,13 @@  discard block
 block discarded – undo
824 824
 	}
825 825
 
826 826
 	/**
827
-	* Create entry from an XML import
828
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
829
-	*
830
-	* @since 2.0.16
831
-	* @param array $values
832
-	* @return int | boolean $entry_id
833
-	*/
827
+	 * Create entry from an XML import
828
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
829
+	 *
830
+	 * @since 2.0.16
831
+	 * @param array $values
832
+	 * @return int | boolean $entry_id
833
+	 */
834 834
 	public static function create_entry_from_xml( $values ){
835 835
 		$entry_id = self::create_entry( $values, 'xml' );
836 836
 
@@ -838,28 +838,28 @@  discard block
 block discarded – undo
838 838
 	}
839 839
 
840 840
 	/**
841
-	* Update entry from an XML import
842
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
843
-	*
844
-	* @since 2.0.16
845
-	* @param int $id
846
-	* @param array $values
847
-	* @return int | boolean $updated
848
-	*/
841
+	 * Update entry from an XML import
842
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
843
+	 *
844
+	 * @since 2.0.16
845
+	 * @param int $id
846
+	 * @param array $values
847
+	 * @return int | boolean $updated
848
+	 */
849 849
 	public static function update_entry_from_xml( $id, $values ) {
850 850
 		$updated = self::update_entry( $id, $values, 'xml' );
851 851
 
852 852
 		return $updated;
853 853
 	}
854 854
 
855
-    /**
856
-     * @param string $key
857
-     * @return int entry_id
858
-     */
855
+	/**
856
+	 * @param string $key
857
+	 * @return int entry_id
858
+	 */
859 859
 	public static function get_id_by_key( $key ) {
860
-        $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
861
-        return $entry_id;
862
-    }
860
+		$entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
861
+		return $entry_id;
862
+	}
863 863
 
864 864
 	public static function validate( $values, $exclude = false ) {
865 865
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' );
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      * @return boolean
43 43
      */
44 44
 	public static function is_duplicate( $new_values, $values ) {
45
-		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
45
+		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
46 46
             return false;
47 47
         }
48 48
 
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
59 59
 
60 60
         if ( $new_values['item_key'] == $new_values['name'] ) {
61
-            unset($check_val['name']);
61
+            unset( $check_val['name'] );
62 62
         }
63 63
 
64 64
         global $wpdb;
65 65
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
66 66
 
67
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
67
+        if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
68 68
             return false;
69 69
         }
70 70
 
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
             $is_duplicate = true;
74 74
 
75 75
             //add more checks here to make sure it's a duplicate
76
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
76
+            $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
77 77
             $field_metas = array();
78 78
             foreach ( $metas as $meta ) {
79
-				$field_metas[ $meta->field_id ] = $meta->meta_value;
79
+				$field_metas[$meta->field_id] = $meta->meta_value;
80 80
             }
81 81
 
82 82
             // If prev entry is empty and current entry is not, they are not duplicates
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
                 return false;
86 86
             }
87 87
 
88
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
88
+            $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) );
89 89
             foreach ( $diff as $field_id => $meta_value ) {
90
-                if ( ! empty($meta_value) ) {
90
+                if ( ! empty( $meta_value ) ) {
91 91
                     $is_duplicate = false;
92 92
                     continue;
93 93
                 }
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
         $values = self::getOne( $id );
108 108
 
109 109
         $new_values = array();
110
-        $new_values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_items', 'item_key');
110
+        $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
111 111
         $new_values['name'] = $values->name;
112 112
         $new_values['is_draft'] = $values->is_draft;
113 113
         $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
114
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
115
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
114
+        $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null;
115
+        $new_values['created_at'] = $new_values['updated_at'] = current_time( 'mysql', 1 );
116 116
 
117
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
117
+        $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
118 118
         if ( ! $query_results ) {
119 119
             return false;
120 120
         }
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
         $entry_id = $wpdb->insert_id;
123 123
 
124 124
         global $frm_vars;
125
-        if ( ! isset($frm_vars['saved_entries']) ) {
125
+        if ( ! isset( $frm_vars['saved_entries'] ) ) {
126 126
             $frm_vars['saved_entries'] = array();
127 127
         }
128 128
         $frm_vars['saved_entries'][] = (int) $entry_id;
129 129
 
130
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
130
+        FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
131 131
 		self::clear_cache();
132 132
 
133 133
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
 		$new_values = self::package_entry_to_update( $id, $values );
168 168
 
169
-		$query_results = $wpdb->update( $wpdb->prefix .'frm_items', $new_values, compact('id') );
169
+		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
170 170
 
171 171
 		self::after_update_entry( $query_results, $id, $values, $new_values );
172 172
 
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
             return $result;
184 184
         }
185 185
 
186
-        do_action('frm_before_destroy_entry', $id, $entry);
186
+        do_action( 'frm_before_destroy_entry', $id, $entry );
187 187
 
188
-        $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_item_metas WHERE item_id=%d', $id) );
189
-        $result = $wpdb->query( $wpdb->prepare('DELETE FROM ' . $wpdb->prefix .'frm_items WHERE id=%d', $id) );
188
+        $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
189
+        $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
190 190
 
191 191
 		self::clear_cache();
192 192
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
 	public static function &update_form( $id, $value, $form_id ) {
197 197
         global $wpdb;
198
-        $form_id = isset($value) ? $form_id : null;
198
+        $form_id = isset( $value ) ? $form_id : null;
199 199
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
200 200
 		if ( $result ) {
201 201
 			self::clear_cache();
@@ -242,24 +242,24 @@  discard block
 block discarded – undo
242 242
         $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
243 243
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
244 244
 
245
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
245
+        $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
246 246
         $query_args = array( $id );
247 247
         $query = $wpdb->prepare( $query, $query_args );
248 248
 
249 249
         if ( ! $meta ) {
250
-            $entry = FrmAppHelper::check_cache( $id .'_nometa', 'frm_entry', $query, 'get_row' );
251
-            return stripslashes_deep($entry);
250
+            $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
251
+            return stripslashes_deep( $entry );
252 252
         }
253 253
 
254 254
         $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
255 255
         if ( $entry !== false ) {
256
-            return stripslashes_deep($entry);
256
+            return stripslashes_deep( $entry );
257 257
         }
258 258
 
259 259
         $entry = $wpdb->get_row( $query );
260
-        $entry = self::get_meta($entry);
260
+        $entry = self::get_meta( $entry );
261 261
 
262
-        return stripslashes_deep($entry);
262
+        return stripslashes_deep( $entry );
263 263
     }
264 264
 
265 265
 	public static function get_meta( $entry ) {
@@ -275,25 +275,25 @@  discard block
 block discarded – undo
275 275
 		$include_key = apply_filters( 'frm_include_meta_keys', false );
276 276
         foreach ( $metas as $meta_val ) {
277 277
             if ( $meta_val->item_id == $entry->id ) {
278
-				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
278
+				$entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
279 279
 				if ( $include_key ) {
280
-					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
280
+					$entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id];
281 281
 				}
282 282
                  continue;
283 283
             }
284 284
 
285 285
             // include sub entries in an array
286
-			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
287
-				$entry->metas[ $meta_val->field_id ] = array();
286
+			if ( ! isset( $entry_metas[$meta_val->field_id] ) ) {
287
+				$entry->metas[$meta_val->field_id] = array();
288 288
             }
289 289
 
290
-			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
290
+			$entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value );
291 291
 
292
-            unset($meta_val);
292
+            unset( $meta_val );
293 293
         }
294
-        unset($metas);
294
+        unset( $metas );
295 295
 
296
-        wp_cache_set( $entry->id, $entry, 'frm_entry');
296
+        wp_cache_set( $entry->id, $entry, 'frm_entry' );
297 297
 
298 298
         return $entry;
299 299
     }
@@ -309,28 +309,28 @@  discard block
 block discarded – undo
309 309
             return $exists;
310 310
         }
311 311
 
312
-        if ( is_numeric($id) ) {
312
+        if ( is_numeric( $id ) ) {
313 313
             $where = array( 'id' => $id );
314 314
         } else {
315 315
             $where = array( 'item_key' => $id );
316 316
         }
317
-        $id = FrmDb::get_var( $wpdb->prefix .'frm_items', $where );
317
+        $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
318 318
 
319
-        $exists = ($id && $id > 0) ? true : false;
319
+        $exists = ( $id && $id > 0 ) ? true : false;
320 320
         return $exists;
321 321
     }
322 322
 
323 323
     public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
324 324
 		global $wpdb;
325 325
 
326
-        $limit = FrmAppHelper::esc_limit($limit);
326
+        $limit = FrmAppHelper::esc_limit( $limit );
327 327
 
328
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
329
-        $entries = wp_cache_get($cache_key, 'frm_entry');
328
+        $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
329
+        $entries = wp_cache_get( $cache_key, 'frm_entry' );
330 330
 
331 331
         if ( false === $entries ) {
332 332
             $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
333
-            $table = $wpdb->prefix .'frm_items it ';
333
+            $table = $wpdb->prefix . 'frm_items it ';
334 334
 
335 335
             if ( $inc_form ) {
336 336
                 $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
             if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
341 341
     		    // sort by a requested field
342 342
                 $field_id = (int) $order_matches[1];
343
-				$fields .= ', (SELECT meta_value FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id = '. $field_id .' AND item_id = it.id) as meta_'. $field_id;
343
+				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
344 344
 				unset( $order_matches, $field_id );
345 345
 		    }
346 346
 
347 347
 			// prepare the query
348
-			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
348
+			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
349 349
 
350
-            $entries = $wpdb->get_results($query, OBJECT_K);
351
-            unset($query);
350
+            $entries = $wpdb->get_results( $query, OBJECT_K );
351
+            unset( $query );
352 352
 
353 353
 			if ( ! FrmAppHelper::prevent_caching() ) {
354 354
 				wp_cache_set( $cache_key, $entries, 'frm_entry', 300 );
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
         }
357 357
 
358 358
         if ( ! $meta || ! $entries ) {
359
-            return stripslashes_deep($entries);
359
+            return stripslashes_deep( $entries );
360 360
         }
361
-        unset($meta);
361
+        unset( $meta );
362 362
 
363
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
363
+        if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
364 364
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
365 365
         }
366 366
 
367 367
         $meta_where = array( 'field_id !' => 0 );
368
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
368
+        if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
369 369
             $meta_where['fi.form_id'] = $where['it.form_id'];
370 370
         } else {
371 371
             $meta_where['item_id'] = array_keys( $entries );
@@ -376,21 +376,21 @@  discard block
 block discarded – undo
376 376
         unset( $meta_where );
377 377
 
378 378
         if ( ! $metas ) {
379
-            return stripslashes_deep($entries);
379
+            return stripslashes_deep( $entries );
380 380
         }
381 381
 
382 382
         foreach ( $metas as $m_key => $meta_val ) {
383
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
383
+            if ( ! isset( $entries[$meta_val->item_id] ) ) {
384 384
                 continue;
385 385
             }
386 386
 
387
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
388
-				$entries[ $meta_val->item_id ]->metas = array();
387
+            if ( ! isset( $entries[$meta_val->item_id]->metas ) ) {
388
+				$entries[$meta_val->item_id]->metas = array();
389 389
             }
390 390
 
391
-			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
391
+			$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
392 392
 
393
-            unset($m_key, $meta_val);
393
+            unset( $m_key, $meta_val );
394 394
         }
395 395
 
396 396
 		if ( ! FrmAppHelper::prevent_caching() ) {
@@ -400,15 +400,15 @@  discard block
 block discarded – undo
400 400
 			}
401 401
 		}
402 402
 
403
-        return stripslashes_deep($entries);
403
+        return stripslashes_deep( $entries );
404 404
     }
405 405
 
406 406
     // Pagination Methods
407 407
     public static function getRecordCount( $where = '' ) {
408 408
         global $wpdb;
409
-        $table_join = $wpdb->prefix .'frm_items it LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON it.form_id=fr.id';
409
+        $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
410 410
 
411
-        if ( is_numeric($where) ) {
411
+        if ( is_numeric( $where ) ) {
412 412
             $table_join = 'frm_items';
413 413
             $where = array( 'form_id' => $where );
414 414
         }
@@ -417,19 +417,19 @@  discard block
 block discarded – undo
417 417
             $count = FrmDb::get_count( $table_join, $where );
418 418
         } else {
419 419
             global $wpdb;
420
-            $cache_key = 'count_'. maybe_serialize($where);
421
-            $query = 'SELECT COUNT(*) FROM '. $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
422
-            $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
420
+            $cache_key = 'count_' . maybe_serialize( $where );
421
+            $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
422
+            $count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
423 423
         }
424 424
 
425 425
         return $count;
426 426
     }
427 427
 
428 428
     public static function getPageCount( $p_size, $where = '' ) {
429
-        if ( is_numeric($where) ) {
429
+        if ( is_numeric( $where ) ) {
430 430
             return ceil( (int) $where / (int) $p_size );
431 431
         } else {
432
-            return ceil( (int) self::getRecordCount($where) / (int) $p_size );
432
+            return ceil( (int) self::getRecordCount( $where ) / (int) $p_size );
433 433
         }
434 434
     }
435 435
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 		self::sanitize_entry_post( $values );
447 447
 
448 448
 		if ( $type != 'xml' ) {
449
-			$values = apply_filters('frm_pre_create_entry', $values);
449
+			$values = apply_filters( 'frm_pre_create_entry', $values );
450 450
 		}
451 451
 
452 452
 		$new_values = self::package_entry_data( $values );
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 
514 514
 		$item_name = self::get_new_entry_name( $values, $values['item_key'] );
515 515
 		$new_values = array(
516
-			'item_key'  => FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key'),
516
+			'item_key'  => FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key' ),
517 517
 			'name'      => FrmAppHelper::truncate( $item_name, 255, 1, '' ),
518 518
 			'ip'        => FrmAppHelper::get_ip_address(),
519 519
 			'is_draft'  => self::get_is_draft_value( $values ),
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
 			'user_id' => self::get_entry_user_id( $values ),
527 527
 		);
528 528
 
529
-		if ( is_array($new_values['name']) ) {
530
-			$new_values['name'] = reset($new_values['name']);
529
+		if ( is_array( $new_values['name'] ) ) {
530
+			$new_values['name'] = reset( $new_values['name'] );
531 531
 		}
532 532
 
533
-		$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
533
+		$new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
534 534
 
535 535
 		return $new_values;
536 536
 	}
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 	* @return int
544 544
 	*/
545 545
 	private static function get_is_draft_value( $values ) {
546
-		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
546
+		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
547 547
 	}
548 548
 
549 549
 	/**
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	* @return int
566 566
 	*/
567 567
 	private static function get_post_id( $values ) {
568
-		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
568
+		return isset( $values['post_id'] ) ? (int) $values['post_id'] : 0;
569 569
 	}
570 570
 
571 571
 	/**
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 	* @return int
577 577
 	*/
578 578
 	private static function get_parent_item_id( $values ) {
579
-		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
579
+		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id'] : 0;
580 580
 	}
581 581
 
582 582
 	/**
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 	* @return string
588 588
 	*/
589 589
 	private static function get_created_at( $values ) {
590
-		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
590
+		return isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 );
591 591
 	}
592 592
 
593 593
 	/**
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 	private static function insert_entry_into_database( $new_values ) {
656 656
 		global $wpdb;
657 657
 
658
-		$query_results = $wpdb->insert( $wpdb->prefix .'frm_items', $new_values );
658
+		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
659 659
 
660 660
 		if ( ! $query_results ) {
661 661
 			$entry_id = false;
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
676 676
 		global $frm_vars;
677 677
 
678
-		if ( ! isset($frm_vars['saved_entries']) ) {
678
+		if ( ! isset( $frm_vars['saved_entries'] ) ) {
679 679
 			$frm_vars['saved_entries'] = array();
680 680
 		}
681 681
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
 	* @param int $entry_id
691 691
 	*/
692 692
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
693
-		if ( isset($values['item_meta']) ) {
693
+		if ( isset( $values['item_meta'] ) ) {
694 694
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
695 695
 		}
696 696
 	}
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
708 708
 
709 709
 		do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
710
-		do_action( 'frm_after_create_entry_'. $new_values['form_id'], $entry_id , compact( 'is_child' ) );
710
+		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
711 711
 	}
712 712
 
713 713
 	/**
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 		}
749 749
 
750 750
 		if ( $update && $update_type != 'xml' ) {
751
-			$values = apply_filters('frm_pre_update_entry', $values, $id);
751
+			$values = apply_filters( 'frm_pre_update_entry', $values, $id );
752 752
 		}
753 753
 
754 754
 		return $update;
@@ -769,27 +769,27 @@  discard block
 block discarded – undo
769 769
 			'name'      => self::get_new_entry_name( $values ),
770 770
 			'form_id'   => self::get_form_id( $values ),
771 771
 			'is_draft'  => self::get_is_draft_value( $values ),
772
-			'updated_at' => current_time('mysql', 1),
773
-			'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(),
772
+			'updated_at' => current_time( 'mysql', 1 ),
773
+			'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
774 774
 		);
775 775
 
776
-		if ( isset($values['post_id']) ) {
776
+		if ( isset( $values['post_id'] ) ) {
777 777
 			$new_values['post_id'] = (int) $values['post_id'];
778 778
 		}
779 779
 
780
-		if ( isset($values['item_key']) ) {
781
-			$new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix .'frm_items', 'item_key', $id);
780
+		if ( isset( $values['item_key'] ) ) {
781
+			$new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id );
782 782
 		}
783 783
 
784
-		if ( isset($values['parent_item_id']) ) {
784
+		if ( isset( $values['parent_item_id'] ) ) {
785 785
 			$new_values['parent_item_id'] = (int) $values['parent_item_id'];
786 786
 		}
787 787
 
788
-		if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
788
+		if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
789 789
 			$new_values['user_id'] = $values['frm_user_id'];
790 790
 		}
791 791
 
792
-		$new_values = apply_filters('frm_update_entry', $new_values, $id);
792
+		$new_values = apply_filters( 'frm_update_entry', $new_values, $id );
793 793
 
794 794
 		return $new_values;
795 795
 	}
@@ -819,8 +819,8 @@  discard block
 block discarded – undo
819 819
 			FrmEntryMeta::update_entry_metas( $id, $values['item_meta'] );
820 820
 		}
821 821
 
822
-		do_action('frm_after_update_entry', $id, $new_values['form_id'] );
823
-		do_action('frm_after_update_entry_'. $new_values['form_id'], $id );
822
+		do_action( 'frm_after_update_entry', $id, $new_values['form_id'] );
823
+		do_action( 'frm_after_update_entry_' . $new_values['form_id'], $id );
824 824
 	}
825 825
 
826 826
 	/**
Please login to merge, or discard this patch.
classes/models/FrmEntryFormat.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -126,19 +126,19 @@
 block discarded – undo
126 126
 	}
127 127
 
128 128
 	/**
129
-	* Flatten multi-dimensional array for multi-file upload fields
130
-	* @since 2.0.9
131
-	*/
129
+	 * Flatten multi-dimensional array for multi-file upload fields
130
+	 * @since 2.0.9
131
+	 */
132 132
 	public static function flatten_multi_file_upload( $field, &$val ) {
133 133
 		if ( $field->type == 'file' && FrmField::is_option_true( $field, 'multiple' ) ) {
134 134
 			$val = FrmAppHelper::array_flatten( $val );
135 135
 		}
136 136
 	}
137 137
 
138
-    /**
139
-     * Replace returns with HTML line breaks for display
140
-     * @since 2.0.9
141
-     */
138
+	/**
139
+	 * Replace returns with HTML line breaks for display
140
+	 * @since 2.0.9
141
+	 */
142 142
 	public static function textarea_display_value( $type, $plain_text, &$value ) {
143 143
 		if ( $type == 'textarea' && ! $plain_text ) {
144 144
 			$value = str_replace( array( "\r\n", "\r", "\n" ), ' <br/>', $value );
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -37,20 +37,20 @@  discard block
 block discarded – undo
37 37
 			$atts['id'] = $atts['entry']->id;
38 38
 		}
39 39
 
40
-		if ( ! $atts['fields'] || ! is_array($atts['fields']) ) {
40
+		if ( ! $atts['fields'] || ! is_array( $atts['fields'] ) ) {
41 41
 			$atts['fields'] = FrmField::get_all_for_form( $atts['form_id'], '', 'include' );
42 42
 		}
43 43
 
44 44
 		$values = array();
45 45
 		foreach ( $atts['fields'] as $f ) {
46 46
 			self::fill_entry_values( $atts, $f, $values );
47
-			unset($f);
47
+			unset( $f );
48 48
 		}
49 49
 
50 50
 		self::fill_entry_user_info( $atts, $values );
51 51
 
52 52
 		if ( $atts['format'] == 'json' ) {
53
-			return json_encode($values);
53
+			return json_encode( $values );
54 54
 		} else if ( $atts['format'] == 'array' ) {
55 55
 			return $values;
56 56
 		}
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		self::convert_entry_to_content( $values, $atts, $content );
60 60
 
61 61
 		if ( 'text' == $atts['format'] ) {
62
-			$content = implode('', $content);
62
+			$content = implode( '', $content );
63 63
 		}
64 64
 
65 65
 		if ( $atts['clickable'] ) {
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		}
76 76
 
77 77
 		if ( $atts['default_email'] ) {
78
-			$values[ $f->id ] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $f->id . ']' );
78
+			$values[$f->id] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $f->id . ']' );
79 79
 			return;
80 80
 		}
81 81
 
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 			return;
85 85
 		}
86 86
 
87
-		if ( $atts['entry'] && ! isset( $atts['entry']->metas[ $f->id ] ) ) {
87
+		if ( $atts['entry'] && ! isset( $atts['entry']->metas[$f->id] ) ) {
88 88
 			// In case include_blank is set
89
-			$atts['entry']->metas[ $f->id ] = '';
89
+			$atts['entry']->metas[$f->id] = '';
90 90
 
91 91
 			if ( FrmAppHelper::pro_is_installed() ) {
92 92
 				FrmProEntryMeta::add_post_value_to_entry( $f, $atts['entry'] );
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
 		$val = '';
98 98
 		if ( $atts['entry'] ) {
99
-			$prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] );
99
+			$prev_val = maybe_unserialize( $atts['entry']->metas[$f->id] );
100 100
 			$meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type );
101 101
 
102 102
 			//This filter applies to the default-message shortcode and frm-show-entry shortcode only
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 		}
120 120
 
121 121
 		if ( $atts['format'] != 'text' ) {
122
-			$values[ $f->field_key ] = $val;
122
+			$values[$f->field_key] = $val;
123 123
 		} else {
124
-			$values[ $f->id ] = array( 'label' => $f->name, 'val' => $val );
124
+			$values[$f->id] = array( 'label' => $f->name, 'val' => $val );
125 125
 		}
126 126
 	}
127 127
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			return;
151 151
 		}
152 152
 
153
-		$data  = self::get_entry_description_data( $atts );
153
+		$data = self::get_entry_description_data( $atts );
154 154
 
155 155
 		if ( $atts['default_email'] ) {
156 156
 			$atts['entry']->ip = '[ip]';
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
238 238
 
239 239
 		// see how many we have
240
-		$i = count($matches['browser']);
240
+		$i = count( $matches['browser'] );
241 241
 		if ( $i != 1 ) {
242 242
 			//we will have two since we are not using 'other' argument yet
243 243
 			//see if version is before or after the name
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			$version = '?';
256 256
 		}
257 257
 
258
-		return $bname .' '. $version .' / '. $platform;
258
+		return $bname . ' ' . $version . ' / ' . $platform;
259 259
 	}
260 260
 
261 261
 	public static function convert_entry_to_content( $values, $atts, array &$content ) {
@@ -274,34 +274,34 @@  discard block
 block discarded – undo
274 274
 
275 275
 			// merge defaults, global settings, and shortcode options
276 276
 			foreach ( $default_settings as $key => $setting ) {
277
-				if ( $atts[ $key ] != '' ) {
277
+				if ( $atts[$key] != '' ) {
278 278
 					continue;
279 279
 				}
280 280
 
281
-				$atts[ $key ] = $setting;
281
+				$atts[$key] = $setting;
282 282
 				unset( $key, $setting );
283 283
 			}
284 284
 
285
-			unset($default_settings);
285
+			unset( $default_settings );
286 286
 
287
-			$content[] = '<table cellspacing="0" style="font-size:'. $atts['font_size'] .';line-height:135%; border-bottom:'. $atts['border_width'] . ' solid #' . $atts['border_color'] . ';"><tbody>' . "\r\n";
288
-			$atts['bg_color'] = ' style="background-color:#'. $atts['bg_color'] .';"';
289
-			$bg_color_alt = ' style="background-color:#'. $atts['alt_bg_color'] .';"';
290
-			$row_style = 'style="text-align:' . ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) .';color:#'. $atts['text_color'] . ';padding:7px 9px;border-top:' . $atts['border_width'] .' solid #' . $atts['border_color'] . '"';
287
+			$content[] = '<table cellspacing="0" style="font-size:' . $atts['font_size'] . ';line-height:135%; border-bottom:' . $atts['border_width'] . ' solid #' . $atts['border_color'] . ';"><tbody>' . "\r\n";
288
+			$atts['bg_color'] = ' style="background-color:#' . $atts['bg_color'] . ';"';
289
+			$bg_color_alt = ' style="background-color:#' . $atts['alt_bg_color'] . ';"';
290
+			$row_style = 'style="text-align:' . ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) . ';color:#' . $atts['text_color'] . ';padding:7px 9px;border-top:' . $atts['border_width'] . ' solid #' . $atts['border_color'] . '"';
291 291
 		}
292 292
 
293 293
 		$odd = true;
294 294
 		foreach ( $values as $id => $value ) {
295 295
 			if ( $atts['plain_text'] ) {
296 296
 				if ( 'rtl' == $atts['direction'] ) {
297
-					$content[] = $value['val'] . ' :'. $value['label'] ."\r\n";
297
+					$content[] = $value['val'] . ' :' . $value['label'] . "\r\n";
298 298
 				} else {
299
-					$content[] = $value['label'] . ': '. $value['val'] ."\r\n";
299
+					$content[] = $value['label'] . ': ' . $value['val'] . "\r\n";
300 300
 				}
301 301
 				continue;
302 302
 			}
303 303
 
304
-			if ( $atts['default_email'] && is_numeric($id) ) {
304
+			if ( $atts['default_email'] && is_numeric( $id ) ) {
305 305
 				$content[] = '[if ' . $id . ']<tr style="[frm-alt-color]">';
306 306
 			} else {
307 307
 				$content[] = '<tr' . ( $odd ? $atts['bg_color'] : $bg_color_alt ) . '>';
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 			if ( 'rtl' == $atts['direction'] ) {
312 312
 				$content[] = '<td ' . $row_style . '>' . $value['val'] . '</td><th ' . $row_style . '>' . $value['label'] . '</th>';
313 313
 			} else {
314
-				$content[] = '<th ' . $row_style . '>' . $value['label'] . '</th><td '. $row_style . '>' . $value['val'] . '</td>';
314
+				$content[] = '<th ' . $row_style . '>' . $value['label'] . '</th><td ' . $row_style . '>' . $value['val'] . '</td>';
315 315
 			}
316 316
 			$content[] = '</tr>' . "\r\n";
317 317
 
Please login to merge, or discard this patch.
classes/models/FrmField.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 }
5 5
 
6 6
 class FrmField {
7
-    static $use_cache = true;
7
+	static $use_cache = true;
8 8
 	static $transient_size = 200;
9 9
 
10 10
 	public static function field_selection() {
@@ -52,41 +52,41 @@  discard block
 block discarded – undo
52 52
 		));
53 53
 	}
54 54
 
55
-    public static function create( $values, $return = true ) {
56
-        global $wpdb, $frm_duplicate_ids;
55
+	public static function create( $values, $return = true ) {
56
+		global $wpdb, $frm_duplicate_ids;
57 57
 
58
-        $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60
-        $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
58
+		$new_values = array();
59
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60
+		$new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63 63
 			$new_values[ $col ] = $values[ $col ];
64
-        }
64
+		}
65 65
 
66
-        $new_values['options'] = $values['options'];
66
+		$new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
-        $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
68
+		$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
+		$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
+		$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
71
+		$new_values['field_options'] = $values['field_options'];
72
+		$new_values['created_at'] = current_time('mysql', 1);
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75 75
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
77
-        }
76
+			$new_values = apply_filters('frm_duplicated_field', $new_values);
77
+		}
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80
-            if ( is_array( $v ) ) {
80
+			if ( is_array( $v ) ) {
81 81
 				$new_values[ $k ] = serialize( $v );
82 82
 			}
83
-            unset( $k, $v );
84
-        }
83
+			unset( $k, $v );
84
+		}
85 85
 
86
-        //if(isset($values['id']) and is_numeric($values['id']))
87
-        //    $new_values['id'] = $values['id'];
86
+		//if(isset($values['id']) and is_numeric($values['id']))
87
+		//    $new_values['id'] = $values['id'];
88 88
 
89
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
89
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
90 90
 		$new_id = 0;
91 91
 		if ( $query_results ) {
92 92
 			self::delete_form_transient( $new_values['form_id'] );
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
 		} else {
106 106
 			return false;
107 107
 		}
108
-    }
108
+	}
109 109
 
110
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
-        global $frm_duplicate_ids;
110
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
111
+		global $frm_duplicate_ids;
112 112
 
113 113
 		$where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) );
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116
-        foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
120
-            }
116
+		foreach ( (array) $fields as $field ) {
117
+			$new_key = ($copy_keys) ? $field->field_key : '';
118
+			if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
+				$new_key = rtrim($new_key, 2);
120
+			}
121 121
 
122
-            $values = array();
123
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
122
+			$values = array();
123
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
124 124
 
125 125
 			// If this is a repeating section, create new form
126 126
 			if ( self::is_repeating_field( $field ) ) {
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
147
-        }
148
-    }
142
+			$values = apply_filters('frm_duplicated_field', $values);
143
+			$new_id = self::create($values);
144
+			$frm_duplicate_ids[ $field->id ] = $new_id;
145
+			$frm_duplicate_ids[ $field->field_key ] = $new_id;
146
+			unset($field);
147
+		}
148
+	}
149 149
 
150 150
 	public static function update( $id, $values ) {
151
-        global $wpdb;
151
+		global $wpdb;
152 152
 
153 153
 		$id = absint( $id );
154 154
 
155 155
 		if ( isset( $values['field_key'] ) ) {
156
-            $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
156
+			$values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
160
-            $values['required'] = (int) $values['required'];
161
-        }
159
+		if ( isset($values['required']) ) {
160
+			$values['required'] = (int) $values['required'];
161
+		}
162 162
 
163 163
 		self::preserve_phone_format_backslashes( $values );
164 164
 
@@ -169,43 +169,43 @@  discard block
 block discarded – undo
169 169
 			}
170 170
 		}
171 171
 
172
-        $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
172
+		$query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
173 173
 
174
-        $form_id = 0;
174
+		$form_id = 0;
175 175
 		if ( isset( $values['form_id'] ) ) {
176
-            $form_id = absint( $values['form_id'] );
176
+			$form_id = absint( $values['form_id'] );
177 177
 		} else {
178
-            $field = self::getOne($id);
179
-            if ( $field ) {
180
-                $form_id = $field->form_id;
181
-            }
182
-            unset($field);
183
-        }
184
-        unset($values);
178
+			$field = self::getOne($id);
179
+			if ( $field ) {
180
+				$form_id = $field->form_id;
181
+			}
182
+			unset($field);
183
+		}
184
+		unset($values);
185 185
 
186 186
 		if ( $query_results ) {
187
-            wp_cache_delete( $id, 'frm_field' );
188
-            if ( $form_id ) {
189
-                self::delete_form_transient($form_id);
190
-            }
191
-        }
187
+			wp_cache_delete( $id, 'frm_field' );
188
+			if ( $form_id ) {
189
+				self::delete_form_transient($form_id);
190
+			}
191
+		}
192 192
 
193
-        return $query_results;
194
-    }
193
+		return $query_results;
194
+	}
195 195
 
196 196
 	/**
197
-	* Keep backslashes in the phone format option
198
-	*
199
-	* @since 2.0.8
200
-	* @param $values array - pass by reference
201
-	*/
197
+	 * Keep backslashes in the phone format option
198
+	 *
199
+	 * @since 2.0.8
200
+	 * @param $values array - pass by reference
201
+	 */
202 202
 	private static function preserve_phone_format_backslashes( &$values ) {
203 203
 		if ( isset( $values['field_options']['format'] ) ) {
204 204
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
205 205
 		}
206 206
 	}
207 207
 
208
-    public static function destroy( $id ) {
208
+	public static function destroy( $id ) {
209 209
 		global $wpdb;
210 210
 
211 211
 		do_action( 'frm_before_destroy_field', $id );
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 
221 221
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
222 222
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
223
-    }
223
+	}
224 224
 
225 225
 	public static function delete_form_transient( $form_id ) {
226 226
 		$form_id = absint( $form_id );
@@ -233,16 +233,16 @@  discard block
 block discarded – undo
233 233
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id .'ex%', '_transient_frm_form_fields_' . $form_id .'ex%', '_transient_timeout_frm_form_fields_' . $form_id .'in%', '_transient_frm_form_fields_' . $form_id .'in%' ) );
234 234
 
235 235
 		$cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb';
236
-        wp_cache_delete($cache_key, 'frm_field');
236
+		wp_cache_delete($cache_key, 'frm_field');
237 237
 
238 238
 		// this cache key is autogenerated in FrmDb::get_var
239 239
 		wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' );
240 240
 
241
-        $form = FrmForm::getOne($form_id);
242
-        if ( $form && $form->parent_form_id ) {
243
-            self::delete_form_transient( $form->parent_form_id );
244
-        }
245
-    }
241
+		$form = FrmForm::getOne($form_id);
242
+		if ( $form && $form->parent_form_id ) {
243
+			self::delete_form_transient( $form->parent_form_id );
244
+		}
245
+	}
246 246
 
247 247
 	/**
248 248
 	 * If $field is numeric, get the field object
@@ -258,131 +258,131 @@  discard block
 block discarded – undo
258 258
 			return;
259 259
 		}
260 260
 
261
-        global $wpdb;
261
+		global $wpdb;
262 262
 
263
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264
-        $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
263
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264
+		$query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
265 265
 
266
-        $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
266
+		$results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
267 267
 
268
-        if ( empty($results) ) {
269
-            return $results;
270
-        }
268
+		if ( empty($results) ) {
269
+			return $results;
270
+		}
271 271
 
272
-        if ( is_numeric($id) ) {
273
-            wp_cache_set( $results->field_key, $results, 'frm_field' );
274
-        } else if ( $results ) {
275
-            wp_cache_set( $results->id, $results, 'frm_field' );
276
-        }
272
+		if ( is_numeric($id) ) {
273
+			wp_cache_set( $results->field_key, $results, 'frm_field' );
274
+		} else if ( $results ) {
275
+			wp_cache_set( $results->id, $results, 'frm_field' );
276
+		}
277 277
 
278 278
 		self::prepare_options( $results );
279 279
 
280
-        return stripslashes_deep($results);
281
-    }
280
+		return stripslashes_deep($results);
281
+	}
282 282
 
283
-    /**
284
-     * Get the field type by key or id
285
-     * @param int|string The field id or key
283
+	/**
284
+	 * Get the field type by key or id
285
+	 * @param int|string The field id or key
286 286
 	 * @param mixed $col The name of the column in the fields database table
287
-     */
288
-    public static function &get_type( $id, $col = 'type' ) {
289
-        $field = FrmAppHelper::check_cache( $id, 'frm_field' );
290
-        if ( $field ) {
291
-            $type = $field->{$col};
292
-        } else {
293
-            $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
294
-        }
295
-
296
-        return $type;
297
-    }
287
+	 */
288
+	public static function &get_type( $id, $col = 'type' ) {
289
+		$field = FrmAppHelper::check_cache( $id, 'frm_field' );
290
+		if ( $field ) {
291
+			$type = $field->{$col};
292
+		} else {
293
+			$type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
294
+		}
295
+
296
+		return $type;
297
+	}
298 298
 
299 299
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
300
-        if ( ! $form_id ) {
301
-            return array();
302
-        }
300
+		if ( ! $form_id ) {
301
+			return array();
302
+		}
303 303
 
304 304
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) );
305 305
 		if ( ! empty( $results ) ) {
306
-            $fields = array();
307
-            $count = 0;
308
-            foreach ( $results as $result ) {
309
-                if ( $type != $result->type ) {
310
-                    continue;
311
-                }
306
+			$fields = array();
307
+			$count = 0;
308
+			foreach ( $results as $result ) {
309
+				if ( $type != $result->type ) {
310
+					continue;
311
+				}
312 312
 
313 313
 				$fields[ $result->id ] = $result;
314
-                $count++;
315
-                if ( $limit == 1 ) {
316
-                    $fields = $result;
317
-                    break;
318
-                }
314
+				$count++;
315
+				if ( $limit == 1 ) {
316
+					$fields = $result;
317
+					break;
318
+				}
319 319
 
320
-                if ( ! empty($limit) && $count >= $limit ) {
321
-                    break;
322
-                }
320
+				if ( ! empty($limit) && $count >= $limit ) {
321
+					break;
322
+				}
323 323
 
324
-                unset($result);
325
-            }
326
-            return stripslashes_deep($fields);
327
-        }
324
+				unset($result);
325
+			}
326
+			return stripslashes_deep($fields);
327
+		}
328 328
 
329
-        self::$use_cache = false;
329
+		self::$use_cache = false;
330 330
 
331 331
 		$where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type );
332 332
 		self::maybe_include_repeating_fields( $inc_sub, $where );
333 333
 		$results = self::getAll( $where, 'field_order', $limit );
334
-        self::$use_cache = true;
335
-        self::include_sub_fields($results, $inc_sub, $type);
334
+		self::$use_cache = true;
335
+		self::include_sub_fields($results, $inc_sub, $type);
336 336
 
337
-        return $results;
338
-    }
337
+		return $results;
338
+	}
339 339
 
340 340
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
341
-        if ( ! (int) $form_id ) {
342
-            return array();
343
-        }
341
+		if ( ! (int) $form_id ) {
342
+			return array();
343
+		}
344 344
 
345 345
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
346 346
 		if ( ! empty( $results ) ) {
347
-            if ( empty($limit) ) {
347
+			if ( empty($limit) ) {
348 348
 				return $results;
349
-            }
349
+			}
350 350
 
351
-            $fields = array();
352
-            $count = 0;
353
-            foreach ( $results as $result ) {
351
+			$fields = array();
352
+			$count = 0;
353
+			foreach ( $results as $result ) {
354 354
 				$fields[ $result->id ] = $result;
355
-                if ( ! empty($limit) && $count >= $limit ) {
356
-                    break;
357
-                }
358
-            }
355
+				if ( ! empty($limit) && $count >= $limit ) {
356
+					break;
357
+				}
358
+			}
359 359
 
360 360
 			return $fields;
361
-        }
361
+		}
362 362
 
363
-        self::$use_cache = false;
363
+		self::$use_cache = false;
364 364
 
365 365
 		$where = array( 'fi.form_id' => absint( $form_id ) );
366 366
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
367 367
 		$results = self::getAll( $where, 'field_order', $limit );
368 368
 
369
-        self::$use_cache = true;
369
+		self::$use_cache = true;
370 370
 
371 371
 		self::include_sub_fields( $results, $inc_embed, 'all' );
372 372
 
373
-        if ( empty($limit) ) {
373
+		if ( empty($limit) ) {
374 374
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
375
-        }
375
+		}
376 376
 
377 377
 		return $results;
378
-    }
378
+	}
379 379
 
380 380
 	/**
381
-	* If repeating fields should be included, adjust $where accordingly
382
-	*
383
-	* @param string $inc_repeat
384
-	* @param array $where - pass by reference
385
-	*/
381
+	 * If repeating fields should be included, adjust $where accordingly
382
+	 *
383
+	 * @param string $inc_repeat
384
+	 * @param array $where - pass by reference
385
+	 */
386 386
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
387 387
 		if ( $inc_repeat == 'include' ) {
388 388
 			$form_id = $where['fi.form_id'];
@@ -393,77 +393,77 @@  discard block
 block discarded – undo
393 393
 
394 394
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
395 395
 		if ( 'include' != $inc_embed ) {
396
-            return;
397
-        }
396
+			return;
397
+		}
398 398
 
399
-        $form_fields = $results;
399
+		$form_fields = $results;
400 400
 		$index_offset = 1;
401
-        foreach ( $form_fields as $k => $field ) {
402
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
403
-                continue;
404
-            }
405
-
406
-            if ( $type == 'all' ) {
407
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408
-            } else {
409
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
410
-            }
411
-
412
-            if ( ! empty($sub_fields) ) {
401
+		foreach ( $form_fields as $k => $field ) {
402
+			if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
403
+				continue;
404
+			}
405
+
406
+			if ( $type == 'all' ) {
407
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408
+			} else {
409
+				$sub_fields = self::get_all_types_in_form($field->form_id, $type);
410
+			}
411
+
412
+			if ( ! empty($sub_fields) ) {
413 413
 				$index = $k + $index_offset;
414 414
 				$index_offset += count( $sub_fields );
415 415
 				array_splice($results, $index, 0, $sub_fields);
416
-            }
417
-            unset($field, $sub_fields);
418
-        }
419
-    }
416
+			}
417
+			unset($field, $sub_fields);
418
+		}
419
+	}
420 420
 
421 421
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
422
-        $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
423
-        if ( self::$use_cache ) {
424
-            // make sure old cache doesn't get saved as a transient
425
-            $results = wp_cache_get($cache_key, 'frm_field');
426
-            if ( false !== $results ) {
427
-                return stripslashes_deep($results);
428
-            }
429
-        }
430
-
431
-        global $wpdb;
432
-
433
-        if ( $blog_id && is_multisite() ) {
434
-            global $wpmuBaseTablePrefix;
435
-            if ( $wpmuBaseTablePrefix ) {
436
-                $prefix = $wpmuBaseTablePrefix . $blog_id .'_';
437
-            } else {
438
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
439
-            }
440
-
441
-            $table_name = $prefix .'frm_fields';
442
-            $form_table_name = $prefix .'frm_forms';
422
+		$cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
423
+		if ( self::$use_cache ) {
424
+			// make sure old cache doesn't get saved as a transient
425
+			$results = wp_cache_get($cache_key, 'frm_field');
426
+			if ( false !== $results ) {
427
+				return stripslashes_deep($results);
428
+			}
429
+		}
430
+
431
+		global $wpdb;
432
+
433
+		if ( $blog_id && is_multisite() ) {
434
+			global $wpmuBaseTablePrefix;
435
+			if ( $wpmuBaseTablePrefix ) {
436
+				$prefix = $wpmuBaseTablePrefix . $blog_id .'_';
437
+			} else {
438
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
439
+			}
440
+
441
+			$table_name = $prefix .'frm_fields';
442
+			$form_table_name = $prefix .'frm_forms';
443 443
 		} else {
444
-            $table_name = $wpdb->prefix .'frm_fields';
445
-            $form_table_name = $wpdb->prefix .'frm_forms';
446
-        }
444
+			$table_name = $wpdb->prefix .'frm_fields';
445
+			$form_table_name = $wpdb->prefix .'frm_forms';
446
+		}
447 447
 
448 448
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
449
-            $order_by = ' ORDER BY '. $order_by;
449
+			$order_by = ' ORDER BY '. $order_by;
450 450
 		}
451 451
 
452
-        $limit = FrmAppHelper::esc_limit($limit);
452
+		$limit = FrmAppHelper::esc_limit($limit);
453 453
 
454
-        $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
455
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
454
+		$query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
455
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
456 456
 
457
-        if ( is_array($where) ) {
458
-            $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
457
+		if ( is_array($where) ) {
458
+			$results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
459 459
 		} else {
460 460
 			// if the query is not an array, then it has already been prepared
461
-            $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
461
+			$query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
462 462
 
463 463
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
464 464
 			$results = $wpdb->$function_name( $query );
465
-        }
466
-        unset( $where );
465
+		}
466
+		unset( $where );
467 467
 
468 468
 		self::format_field_results( $results );
469 469
 
@@ -562,21 +562,21 @@  discard block
 block discarded – undo
562 562
 
563 563
 	public static function getIds( $where = '', $order_by = '', $limit = '' ) {
564 564
 		_deprecated_function( __FUNCTION__, '2.0' );
565
-        global $wpdb;
566
-        if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
567
-            $order_by = ' ORDER BY '. $order_by;
568
-        }
565
+		global $wpdb;
566
+		if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
567
+			$order_by = ' ORDER BY '. $order_by;
568
+		}
569 569
 
570
-        $query = 'SELECT fi.id  FROM '. $wpdb->prefix .'frm_fields fi ' .
571
-                 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
572
-                 FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
570
+		$query = 'SELECT fi.id  FROM '. $wpdb->prefix .'frm_fields fi ' .
571
+				 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
572
+				 FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
573 573
 
574
-        $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
575
-        $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
576
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
574
+		$method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
575
+		$cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
576
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
577 577
 
578
-        return $results;
579
-    }
578
+		return $results;
579
+	}
580 580
 
581 581
 	public static function is_no_save_field( $type ) {
582 582
 		return in_array( $type, self::no_save_fields() );
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 	}
682 682
 
683 683
 	/**
684
-	* @since 2.0.09
685
-	*/
684
+	 * @since 2.0.09
685
+	 */
686 686
 	public static function is_repeating_field( $field ) {
687 687
 		if ( is_array( $field ) ) {
688 688
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -692,12 +692,12 @@  discard block
 block discarded – undo
692 692
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
693 693
 	}
694 694
 
695
-    /**
696
-     * @param string $key
697
-     * @return int field id
698
-     */
695
+	/**
696
+	 * @param string $key
697
+	 * @return int field id
698
+	 */
699 699
 	public static function get_id_by_key( $key ) {
700
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
701
-        return $id;
702
-    }
700
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
701
+		return $id;
702
+	}
703 703
 }
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	static $transient_size = 200;
9 9
 
10 10
 	public static function field_selection() {
11
-		$fields = apply_filters('frm_available_fields', array(
11
+		$fields = apply_filters( 'frm_available_fields', array(
12 12
 			'text'      => __( 'Single Line Text', 'formidable' ),
13 13
 			'textarea'  => __( 'Paragraph Text', 'formidable' ),
14 14
 			'checkbox'  => __( 'Checkboxes', 'formidable' ),
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 			'email'     => __( 'Email Address', 'formidable' ),
18 18
 			'url'       => __( 'Website/URL', 'formidable' ),
19 19
 			'captcha'   => __( 'reCAPTCHA', 'formidable' ),
20
-		));
20
+		) );
21 21
 
22 22
 		return $fields;
23 23
 	}
24 24
 
25 25
 	public static function pro_field_selection() {
26
-		return apply_filters('frm_pro_available_fields', array(
26
+		return apply_filters( 'frm_pro_available_fields', array(
27 27
 			'end_divider' => array(
28 28
 				'name'  => __( 'End Section', 'formidable' ),
29 29
 				'switch_from' => 'divider',
@@ -49,36 +49,36 @@  discard block
 block discarded – undo
49 49
 			//'city_selector' => 'US State/County/City selector',
50 50
 			//'full_name' => 'First and Last Name',
51 51
 			//'quiz'    => 'Question and Answer' // for captcha alternative
52
-		));
52
+		) );
53 53
 	}
54 54
 
55 55
     public static function create( $values, $return = true ) {
56 56
         global $wpdb, $frm_duplicate_ids;
57 57
 
58 58
         $new_values = array();
59
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
60
-        $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key');
59
+        $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
60
+        $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
61 61
 
62 62
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
63
-			$new_values[ $col ] = $values[ $col ];
63
+			$new_values[$col] = $values[$col];
64 64
         }
65 65
 
66 66
         $new_values['options'] = $values['options'];
67 67
 
68
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
69
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
70
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
68
+        $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
69
+        $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
70
+        $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
71 71
         $new_values['field_options'] = $values['field_options'];
72
-        $new_values['created_at'] = current_time('mysql', 1);
72
+        $new_values['created_at'] = current_time( 'mysql', 1 );
73 73
 
74 74
 		if ( isset( $values['id'] ) ) {
75
-			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
76
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
75
+			$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
76
+            $new_values = apply_filters( 'frm_duplicated_field', $new_values );
77 77
         }
78 78
 
79 79
 		foreach ( $new_values as $k => $v ) {
80 80
             if ( is_array( $v ) ) {
81
-				$new_values[ $k ] = serialize( $v );
81
+				$new_values[$k] = serialize( $v );
82 82
 			}
83 83
             unset( $k, $v );
84 84
         }
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         //if(isset($values['id']) and is_numeric($values['id']))
87 87
         //    $new_values['id'] = $values['id'];
88 88
 
89
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values );
89
+        $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
90 90
 		$new_id = 0;
91 91
 		if ( $query_results ) {
92 92
 			self::delete_form_transient( $new_values['form_id'] );
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 		if ( $query_results ) {
101 101
 			if ( isset( $values['id'] ) ) {
102
-				$frm_duplicate_ids[ $values['id'] ] = $new_id;
102
+				$frm_duplicate_ids[$values['id']] = $new_id;
103 103
 			}
104 104
 			return $new_id;
105 105
 		} else {
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
115 115
 
116 116
         foreach ( (array) $fields as $field ) {
117
-            $new_key = ($copy_keys) ? $field->field_key : '';
118
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
119
-                $new_key = rtrim($new_key, 2);
117
+            $new_key = ( $copy_keys ) ? $field->field_key : '';
118
+            if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
119
+                $new_key = rtrim( $new_key, 2 );
120 120
             }
121 121
 
122 122
             $values = array();
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 				$values['form_id'] = $new_repeat_form_id;
140 140
 			}
141 141
 
142
-            $values = apply_filters('frm_duplicated_field', $values);
143
-            $new_id = self::create($values);
144
-            $frm_duplicate_ids[ $field->id ] = $new_id;
145
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
146
-            unset($field);
142
+            $values = apply_filters( 'frm_duplicated_field', $values );
143
+            $new_id = self::create( $values );
144
+            $frm_duplicate_ids[$field->id] = $new_id;
145
+            $frm_duplicate_ids[$field->field_key] = $new_id;
146
+            unset( $field );
147 147
         }
148 148
     }
149 149
 
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
 		$id = absint( $id );
154 154
 
155 155
 		if ( isset( $values['field_key'] ) ) {
156
-            $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id);
156
+            $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
157 157
 		}
158 158
 
159
-        if ( isset($values['required']) ) {
159
+        if ( isset( $values['required'] ) ) {
160 160
             $values['required'] = (int) $values['required'];
161 161
         }
162 162
 
@@ -164,29 +164,29 @@  discard block
 block discarded – undo
164 164
 
165 165
 		// serialize array values
166 166
 		foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
167
-			if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
168
-				$values[ $opt ] = serialize( $values[ $opt ] );
167
+			if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) {
168
+				$values[$opt] = serialize( $values[$opt] );
169 169
 			}
170 170
 		}
171 171
 
172
-        $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) );
172
+        $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
173 173
 
174 174
         $form_id = 0;
175 175
 		if ( isset( $values['form_id'] ) ) {
176 176
             $form_id = absint( $values['form_id'] );
177 177
 		} else {
178
-            $field = self::getOne($id);
178
+            $field = self::getOne( $id );
179 179
             if ( $field ) {
180 180
                 $form_id = $field->form_id;
181 181
             }
182
-            unset($field);
182
+            unset( $field );
183 183
         }
184
-        unset($values);
184
+        unset( $values );
185 185
 
186 186
 		if ( $query_results ) {
187 187
             wp_cache_delete( $id, 'frm_field' );
188 188
             if ( $form_id ) {
189
-                self::delete_form_transient($form_id);
189
+                self::delete_form_transient( $form_id );
190 190
             }
191 191
         }
192 192
 
@@ -224,21 +224,21 @@  discard block
 block discarded – undo
224 224
 
225 225
 	public static function delete_form_transient( $form_id ) {
226 226
 		$form_id = absint( $form_id );
227
-		delete_transient( 'frm_form_fields_'. $form_id .'excludeinclude' );
228
-		delete_transient( 'frm_form_fields_'. $form_id .'includeinclude' );
229
-		delete_transient( 'frm_form_fields_'. $form_id .'includeexclude' );
230
-		delete_transient( 'frm_form_fields_'. $form_id .'excludeexclude' );
227
+		delete_transient( 'frm_form_fields_' . $form_id . 'excludeinclude' );
228
+		delete_transient( 'frm_form_fields_' . $form_id . 'includeinclude' );
229
+		delete_transient( 'frm_form_fields_' . $form_id . 'includeexclude' );
230
+		delete_transient( 'frm_form_fields_' . $form_id . 'excludeexclude' );
231 231
 
232 232
 		global $wpdb;
233
-		$wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id .'ex%', '_transient_frm_form_fields_' . $form_id .'ex%', '_transient_timeout_frm_form_fields_' . $form_id .'in%', '_transient_frm_form_fields_' . $form_id .'in%' ) );
233
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) );
234 234
 
235 235
 		$cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb';
236
-        wp_cache_delete($cache_key, 'frm_field');
236
+        wp_cache_delete( $cache_key, 'frm_field' );
237 237
 
238 238
 		// this cache key is autogenerated in FrmDb::get_var
239 239
 		wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' );
240 240
 
241
-        $form = FrmForm::getOne($form_id);
241
+        $form = FrmForm::getOne( $form_id );
242 242
         if ( $form && $form->parent_form_id ) {
243 243
             self::delete_form_transient( $form->parent_form_id );
244 244
         }
@@ -260,16 +260,16 @@  discard block
 block discarded – undo
260 260
 
261 261
         global $wpdb;
262 262
 
263
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
264
-        $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id);
263
+        $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
264
+        $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
265 265
 
266 266
         $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
267 267
 
268
-        if ( empty($results) ) {
268
+        if ( empty( $results ) ) {
269 269
             return $results;
270 270
         }
271 271
 
272
-        if ( is_numeric($id) ) {
272
+        if ( is_numeric( $id ) ) {
273 273
             wp_cache_set( $results->field_key, $results, 'frm_field' );
274 274
         } else if ( $results ) {
275 275
             wp_cache_set( $results->id, $results, 'frm_field' );
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
 		self::prepare_options( $results );
279 279
 
280
-        return stripslashes_deep($results);
280
+        return stripslashes_deep( $results );
281 281
     }
282 282
 
283 283
     /**
@@ -310,20 +310,20 @@  discard block
 block discarded – undo
310 310
                     continue;
311 311
                 }
312 312
 
313
-				$fields[ $result->id ] = $result;
314
-                $count++;
313
+				$fields[$result->id] = $result;
314
+                $count ++;
315 315
                 if ( $limit == 1 ) {
316 316
                     $fields = $result;
317 317
                     break;
318 318
                 }
319 319
 
320
-                if ( ! empty($limit) && $count >= $limit ) {
320
+                if ( ! empty( $limit ) && $count >= $limit ) {
321 321
                     break;
322 322
                 }
323 323
 
324
-                unset($result);
324
+                unset( $result );
325 325
             }
326
-            return stripslashes_deep($fields);
326
+            return stripslashes_deep( $fields );
327 327
         }
328 328
 
329 329
         self::$use_cache = false;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		self::maybe_include_repeating_fields( $inc_sub, $where );
333 333
 		$results = self::getAll( $where, 'field_order', $limit );
334 334
         self::$use_cache = true;
335
-        self::include_sub_fields($results, $inc_sub, $type);
335
+        self::include_sub_fields( $results, $inc_sub, $type );
336 336
 
337 337
         return $results;
338 338
     }
@@ -344,15 +344,15 @@  discard block
 block discarded – undo
344 344
 
345 345
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
346 346
 		if ( ! empty( $results ) ) {
347
-            if ( empty($limit) ) {
347
+            if ( empty( $limit ) ) {
348 348
 				return $results;
349 349
             }
350 350
 
351 351
             $fields = array();
352 352
             $count = 0;
353 353
             foreach ( $results as $result ) {
354
-				$fields[ $result->id ] = $result;
355
-                if ( ! empty($limit) && $count >= $limit ) {
354
+				$fields[$result->id] = $result;
355
+                if ( ! empty( $limit ) && $count >= $limit ) {
356 356
                     break;
357 357
                 }
358 358
             }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 
371 371
 		self::include_sub_fields( $results, $inc_embed, 'all' );
372 372
 
373
-        if ( empty($limit) ) {
373
+        if ( empty( $limit ) ) {
374 374
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
375 375
         }
376 376
 
@@ -399,32 +399,32 @@  discard block
 block discarded – undo
399 399
         $form_fields = $results;
400 400
 		$index_offset = 1;
401 401
         foreach ( $form_fields as $k => $field ) {
402
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
402
+            if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
403 403
                 continue;
404 404
             }
405 405
 
406 406
             if ( $type == 'all' ) {
407 407
                 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
408 408
             } else {
409
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
409
+                $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
410 410
             }
411 411
 
412
-            if ( ! empty($sub_fields) ) {
412
+            if ( ! empty( $sub_fields ) ) {
413 413
 				$index = $k + $index_offset;
414 414
 				$index_offset += count( $sub_fields );
415
-				array_splice($results, $index, 0, $sub_fields);
415
+				array_splice( $results, $index, 0, $sub_fields );
416 416
             }
417
-            unset($field, $sub_fields);
417
+            unset( $field, $sub_fields );
418 418
         }
419 419
     }
420 420
 
421 421
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
422
-        $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id;
422
+        $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
423 423
         if ( self::$use_cache ) {
424 424
             // make sure old cache doesn't get saved as a transient
425
-            $results = wp_cache_get($cache_key, 'frm_field');
425
+            $results = wp_cache_get( $cache_key, 'frm_field' );
426 426
             if ( false !== $results ) {
427
-                return stripslashes_deep($results);
427
+                return stripslashes_deep( $results );
428 428
             }
429 429
         }
430 430
 
@@ -433,32 +433,32 @@  discard block
 block discarded – undo
433 433
         if ( $blog_id && is_multisite() ) {
434 434
             global $wpmuBaseTablePrefix;
435 435
             if ( $wpmuBaseTablePrefix ) {
436
-                $prefix = $wpmuBaseTablePrefix . $blog_id .'_';
436
+                $prefix = $wpmuBaseTablePrefix . $blog_id . '_';
437 437
             } else {
438 438
                 $prefix = $wpdb->get_blog_prefix( $blog_id );
439 439
             }
440 440
 
441
-            $table_name = $prefix .'frm_fields';
442
-            $form_table_name = $prefix .'frm_forms';
441
+            $table_name = $prefix . 'frm_fields';
442
+            $form_table_name = $prefix . 'frm_forms';
443 443
 		} else {
444
-            $table_name = $wpdb->prefix .'frm_fields';
445
-            $form_table_name = $wpdb->prefix .'frm_forms';
444
+            $table_name = $wpdb->prefix . 'frm_fields';
445
+            $form_table_name = $wpdb->prefix . 'frm_forms';
446 446
         }
447 447
 
448 448
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
449
-            $order_by = ' ORDER BY '. $order_by;
449
+            $order_by = ' ORDER BY ' . $order_by;
450 450
 		}
451 451
 
452
-        $limit = FrmAppHelper::esc_limit($limit);
452
+        $limit = FrmAppHelper::esc_limit( $limit );
453 453
 
454 454
         $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
455 455
         $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
456 456
 
457
-        if ( is_array($where) ) {
457
+        if ( is_array( $where ) ) {
458 458
             $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
459 459
 		} else {
460 460
 			// if the query is not an array, then it has already been prepared
461
-            $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
461
+            $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
462 462
 
463 463
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
464 464
 			$results = $wpdb->$function_name( $query );
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 				wp_cache_set( $result->id, $result, 'frm_field' );
482 482
 				wp_cache_set( $result->field_key, $result, 'frm_field' );
483 483
 
484
-				$results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
485
-				$results[ $r_key ]->options = maybe_unserialize( $result->options );
486
-				$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
484
+				$results[$r_key]->field_options = maybe_unserialize( $result->field_options );
485
+				$results[$r_key]->options = maybe_unserialize( $result->options );
486
+				$results[$r_key]->default_value = maybe_unserialize( $result->default_value );
487 487
 
488 488
 				unset( $r_key, $result );
489 489
 			}
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 	private static function prepare_options( &$results ) {
503 503
 		$results->field_options = maybe_unserialize( $results->field_options );
504 504
 
505
-		$results->options = maybe_unserialize($results->options);
506
-		$results->default_value = maybe_unserialize($results->default_value);
505
+		$results->options = maybe_unserialize( $results->options );
506
+		$results->default_value = maybe_unserialize( $results->default_value );
507 507
 	}
508 508
 
509 509
 	/**
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 
531 531
 			if ( count( $next_fields ) >= self::$transient_size ) {
532 532
 				// if this transient is full, check for another
533
-				$next++;
533
+				$next ++;
534 534
 				self::get_next_transient( $fields, $base_name, $next );
535 535
 			}
536 536
 		}
@@ -556,24 +556,24 @@  discard block
 block discarded – undo
556 556
 				return;
557 557
 			}
558 558
 
559
-			$next++;
559
+			$next ++;
560 560
 		}
561 561
 	}
562 562
 
563 563
 	public static function getIds( $where = '', $order_by = '', $limit = '' ) {
564 564
 		_deprecated_function( __FUNCTION__, '2.0' );
565 565
         global $wpdb;
566
-        if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
567
-            $order_by = ' ORDER BY '. $order_by;
566
+        if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) {
567
+            $order_by = ' ORDER BY ' . $order_by;
568 568
         }
569 569
 
570
-        $query = 'SELECT fi.id  FROM '. $wpdb->prefix .'frm_fields fi ' .
571
-                 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' .
572
-                 FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
570
+        $query = 'SELECT fi.id  FROM ' . $wpdb->prefix . 'frm_fields fi ' .
571
+                 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' .
572
+                 FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
573 573
 
574 574
         $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
575
-        $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit;
576
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
575
+        $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit;
576
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method );
577 577
 
578 578
         return $results;
579 579
     }
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
 		}
601 601
 
602 602
 		if ( is_array( $field ) ) {
603
-			return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field );
603
+			return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field );
604 604
 		} else {
605
-			return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field);
605
+			return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select( $field );
606 606
 		}
607 607
 	}
608 608
 
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	public static function is_multiple_select( $field ) {
616 616
 		if ( is_array( $field ) ) {
617
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) );
617
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) );
618 618
 		} else {
619
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select') ) );
619
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select' ) ) );
620 620
 		}
621 621
 	}
622 622
 
@@ -661,23 +661,23 @@  discard block
 block discarded – undo
661 661
 	}
662 662
 
663 663
 	public static function is_option_true_in_array( $field, $option ) {
664
-		return isset( $field[ $option ] ) && $field[ $option ];
664
+		return isset( $field[$option] ) && $field[$option];
665 665
 	}
666 666
 
667 667
 	public static function is_option_true_in_object( $field, $option ) {
668
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
668
+		return isset( $field->field_options[$option] ) && $field->field_options[$option];
669 669
 	}
670 670
 
671 671
 	public static function is_option_empty_in_array( $field, $option ) {
672
-		return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
672
+		return ! isset( $field[$option] ) || empty( $field[$option] );
673 673
 	}
674 674
 
675 675
 	public static function is_option_empty_in_object( $field, $option ) {
676
-		return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
676
+		return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] );
677 677
 	}
678 678
 
679 679
 	public static function is_option_value_in_object( $field, $option ) {
680
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
680
+		return isset( $field->field_options[$option] ) && $field->field_options[$option] != '';
681 681
 	}
682 682
 
683 683
 	/**
@@ -693,11 +693,11 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	public static function get_option_in_array( $field, $option ) {
696
-		return $field[ $option ];
696
+		return $field[$option];
697 697
 	}
698 698
 
699 699
 	public static function get_option_in_object( $field, $option ) {
700
-		return $field->field_options[ $option ];
700
+		return $field->field_options[$option];
701 701
 	}
702 702
 
703 703
 	/**
Please login to merge, or discard this patch.
classes/models/FrmForm.php 2 patches
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -1,376 +1,376 @@  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;
13
-
14
-        $new_values = array(
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,
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13
+
14
+		$new_values = array(
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,
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
-        $options = array();
27
+		$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
-        $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
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
-    }
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;
55
-
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
60
-
61
-        $new_key = $copy_keys ? $values->form_key : '';
62
-
63
-        $new_values = array(
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
-        }
87
-
88
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
89
-
90
-        if ( $query_results ) {
47
+		return $id;
48
+	}
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;
55
+
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60
+
61
+		$new_key = $copy_keys ? $values->form_key : '';
62
+
63
+		$new_values = array(
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
+		}
87
+
88
+		$query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
89
+
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']) ) {
131
-            $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
132
-        }
130
+		if ( isset($values['form_key']) ) {
131
+			$values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
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 ) {
139
-            if ( in_array($value_key, $form_fields) ) {
138
+		foreach ( $values as $value_key => $value ) {
139
+			if ( 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 ) ) {
149
-            $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
150
-            if ( $query_results ) {
148
+		if ( ! empty( $new_values ) ) {
149
+			$query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
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
-        do_action('frm_update_form', $id, $values);
161
-        do_action('frm_update_form_'. $id, $values);
160
+		do_action('frm_update_form', $id, $values);
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
-        $options = array();
174
+		$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['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
-            return $values;
196
-        }
194
+		if ( ! isset($values['options']) && ! 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
 			if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
229
-                //updating the settings page
229
+				//updating the settings page
230 230
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
231 231
 					$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 ) );
232
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
232
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
233 233
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
234
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
235
-                    $prev_opts = $field->field_options;
236
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
-                    if ( $prev_opts != $field->field_options ) {
234
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
235
+					$prev_opts = $field->field_options;
236
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
+					if ( $prev_opts != $field->field_options ) {
238 238
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
239
-                    }
240
-                    unset($prev_opts);
241
-                }
242
-            }
239
+					}
240
+					unset($prev_opts);
241
+				}
242
+			}
243 243
 
244 244
 			if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) {
245
-                continue;
246
-            }
245
+				continue;
246
+			}
247 247
 
248
-            //updating the form
248
+			//updating the form
249 249
 			foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size' ) as $opt ) {
250 250
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : '';
251
-            }
251
+			}
252 252
 
253 253
 			$field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*';
254 254
 			$field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0;
255 255
 
256
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
256
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
257 257
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
258 258
 			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
259 259
 			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
260 260
 			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
261 261
 			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
262 262
 
263
-            FrmField::update($field_id, array(
264
-                'field_key' => $field_key, 'type' => $field_type,
265
-                'default_value' => $default_value, 'field_options' => $field->field_options,
266
-                'description' => $field_description, 'required' => $required,
267
-            ) );
263
+			FrmField::update($field_id, array(
264
+				'field_key' => $field_key, 'type' => $field_type,
265
+				'default_value' => $default_value, 'field_options' => $field->field_options,
266
+				'description' => $field_description, 'required' => $required,
267
+			) );
268 268
 
269
-            FrmField::delete_form_transient($field->form_id);
270
-        }
269
+			FrmField::delete_form_transient($field->form_id);
270
+		}
271 271
 
272
-        return $values;
273
-    }
272
+		return $values;
273
+	}
274 274
 
275
-    /**
276
-     * @param string $status
277
-     * @return int|boolean
278
-     */
275
+	/**
276
+	 * @param string $status
277
+	 * @return int|boolean
278
+	 */
279 279
 	public static function set_status( $id, $status ) {
280
-        if ( 'trash' == $status ) {
281
-            return self::trash($id);
282
-        }
280
+		if ( 'trash' == $status ) {
281
+			return self::trash($id);
282
+		}
283 283
 
284 284
 		$statuses  = array( 'published', 'draft', 'trash' );
285
-        if ( ! in_array( $status, $statuses ) ) {
286
-            return false;
287
-        }
285
+		if ( ! in_array( $status, $statuses ) ) {
286
+			return false;
287
+		}
288 288
 
289
-        global $wpdb;
289
+		global $wpdb;
290 290
 
291
-        if ( is_array($id) ) {
291
+		if ( is_array($id) ) {
292 292
 			$where = array( 'id' => $id );
293 293
 			FrmDb::get_where_clause_and_values( $where );
294 294
 			array_unshift( $where['values'], $status );
295 295
 
296 296
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
297
-        } else {
297
+		} else {
298 298
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
299
-        }
299
+		}
300 300
 
301
-        if ( $query_results ) {
301
+		if ( $query_results ) {
302 302
 			self::clear_form_cache();
303
-        }
303
+		}
304 304
 
305
-        return $query_results;
306
-    }
305
+		return $query_results;
306
+	}
307 307
 
308
-    /**
309
-     * @return int|boolean
310
-     */
308
+	/**
309
+	 * @return int|boolean
310
+	 */
311 311
 	public static function trash( $id ) {
312
-        if ( ! EMPTY_TRASH_DAYS ) {
313
-            return self::destroy( $id );
314
-        }
312
+		if ( ! EMPTY_TRASH_DAYS ) {
313
+			return self::destroy( $id );
314
+		}
315 315
 
316
-        $form = self::getOne($id);
317
-        if ( ! $form ) {
318
-            return false;
319
-        }
316
+		$form = self::getOne($id);
317
+		if ( ! $form ) {
318
+			return false;
319
+		}
320 320
 
321
-        $options = $form->options;
322
-        $options['trash_time'] = time();
321
+		$options = $form->options;
322
+		$options['trash_time'] = time();
323 323
 
324
-        global $wpdb;
325
-        $query_results = $wpdb->update(
326
-            $wpdb->prefix .'frm_forms',
324
+		global $wpdb;
325
+		$query_results = $wpdb->update(
326
+			$wpdb->prefix .'frm_forms',
327 327
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
328 328
 			array( 'id' => $id )
329
-        );
329
+		);
330 330
 
331
-        if ( $query_results ) {
331
+		if ( $query_results ) {
332 332
 			self::clear_form_cache();
333
-        }
333
+		}
334 334
 
335
-        return $query_results;
336
-    }
335
+		return $query_results;
336
+	}
337 337
 
338
-    /**
339
-     * @return int|boolean
340
-     */
338
+	/**
339
+	 * @return int|boolean
340
+	 */
341 341
 	public static function destroy( $id ) {
342
-        global $wpdb;
342
+		global $wpdb;
343 343
 
344
-        $form = self::getOne($id);
345
-        if ( ! $form ) {
346
-            return false;
347
-        }
344
+		$form = self::getOne($id);
345
+		if ( ! $form ) {
346
+			return false;
347
+		}
348 348
 
349
-        // Disconnect the entries from this form
349
+		// Disconnect the entries from this form
350 350
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
351
-        foreach ( $entries as $entry_id ) {
352
-            FrmEntry::destroy($entry_id);
353
-            unset($entry_id);
354
-        }
351
+		foreach ( $entries as $entry_id ) {
352
+			FrmEntry::destroy($entry_id);
353
+			unset($entry_id);
354
+		}
355 355
 
356
-        // Disconnect the fields from this form
357
-        $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));
356
+		// Disconnect the fields from this form
357
+		$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));
358 358
 
359
-        $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
360
-        if ( $query_results ) {
361
-            // Delete all form actions linked to this form
362
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
363
-            $action_control->destroy($id, 'all');
359
+		$query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
360
+		if ( $query_results ) {
361
+			// Delete all form actions linked to this form
362
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
363
+			$action_control->destroy($id, 'all');
364 364
 
365 365
 			// Clear form caching
366 366
 			self::clear_form_cache();
367 367
 
368
-            do_action('frm_destroy_form', $id);
369
-            do_action('frm_destroy_form_'. $id);
370
-        }
368
+			do_action('frm_destroy_form', $id);
369
+			do_action('frm_destroy_form_'. $id);
370
+		}
371 371
 
372
-        return $query_results;
373
-    }
372
+		return $query_results;
373
+	}
374 374
 
375 375
 	/**
376 376
 	 * Delete trashed forms based on how long they have been trashed
@@ -402,49 +402,49 @@  discard block
 block discarded – undo
402 402
 		return $count;
403 403
 	}
404 404
 
405
-    /**
406
-     * @return string form name
407
-     */
408
-    public static function &getName( $id ) {
409
-        global $wpdb;
410
-
411
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
412
-        if ( $form ) {
413
-            $r = stripslashes($form->name);
414
-            return $r;
415
-        }
416
-
417
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
418
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
419
-        $r = stripslashes($r);
420
-
421
-        return $r;
422
-    }
423
-
424
-    /**
425
-     * @param string $key
426
-     * @return int form id
427
-     */
405
+	/**
406
+	 * @return string form name
407
+	 */
408
+	public static function &getName( $id ) {
409
+		global $wpdb;
410
+
411
+		$form = FrmAppHelper::check_cache($id, 'frm_form');
412
+		if ( $form ) {
413
+			$r = stripslashes($form->name);
414
+			return $r;
415
+		}
416
+
417
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
418
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
419
+		$r = stripslashes($r);
420
+
421
+		return $r;
422
+	}
423
+
424
+	/**
425
+	 * @param string $key
426
+	 * @return int form id
427
+	 */
428 428
 	public static function &getIdByKey( $key ) {
429
-        $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
430
-        return $id;
431
-    }
432
-
433
-    /**
434
-     * @param int $id
435
-     * @return string form key
436
-     */
429
+		$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
430
+		return $id;
431
+	}
432
+
433
+	/**
434
+	 * @param int $id
435
+	 * @return string form key
436
+	 */
437 437
 	public static function &getKeyById( $id ) {
438
-        $id = (int) $id;
439
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
440
-        if ( $cache ) {
441
-            return $cache->form_key;
442
-        }
438
+		$id = (int) $id;
439
+		$cache = FrmAppHelper::check_cache($id, 'frm_form');
440
+		if ( $cache ) {
441
+			return $cache->form_key;
442
+		}
443 443
 
444
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
444
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
445 445
 
446
-        return $key;
447
-    }
446
+		return $key;
447
+	}
448 448
 
449 449
 	/**
450 450
 	 * If $form is numeric, get the form object
@@ -457,47 +457,47 @@  discard block
 block discarded – undo
457 457
 		}
458 458
 	}
459 459
 
460
-    /**
461
-     * @return object form
462
-     */
463
-    public static function getOne( $id, $blog_id = false ) {
464
-        global $wpdb;
465
-
466
-        if ( $blog_id && is_multisite() ) {
467
-            global $wpmuBaseTablePrefix;
468
-            $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
469
-
470
-            $table_name = $prefix .'frm_forms';
471
-        } else {
472
-            $table_name = $wpdb->prefix .'frm_forms';
473
-            $cache = wp_cache_get($id, 'frm_form');
474
-            if ( $cache ) {
475
-                if ( isset($cache->options) ) {
476
-                    $cache->options = maybe_unserialize($cache->options);
477
-                }
478
-
479
-                return stripslashes_deep($cache);
480
-            }
481
-        }
482
-
483
-        if ( is_numeric($id) ) {
484
-            $where = array( 'id' => $id );
485
-        } else {
486
-            $where = array( 'form_key' => $id );
487
-        }
488
-
489
-        $results = FrmDb::get_row( $table_name, $where );
490
-
491
-        if ( isset($results->options) ) {
492
-            wp_cache_set($results->id, $results, 'frm_form');
493
-            $results->options = maybe_unserialize($results->options);
494
-        }
495
-        return stripslashes_deep($results);
496
-    }
497
-
498
-    /**
499
-     * @return object|array of objects
500
-     */
460
+	/**
461
+	 * @return object form
462
+	 */
463
+	public static function getOne( $id, $blog_id = false ) {
464
+		global $wpdb;
465
+
466
+		if ( $blog_id && is_multisite() ) {
467
+			global $wpmuBaseTablePrefix;
468
+			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
469
+
470
+			$table_name = $prefix .'frm_forms';
471
+		} else {
472
+			$table_name = $wpdb->prefix .'frm_forms';
473
+			$cache = wp_cache_get($id, 'frm_form');
474
+			if ( $cache ) {
475
+				if ( isset($cache->options) ) {
476
+					$cache->options = maybe_unserialize($cache->options);
477
+				}
478
+
479
+				return stripslashes_deep($cache);
480
+			}
481
+		}
482
+
483
+		if ( is_numeric($id) ) {
484
+			$where = array( 'id' => $id );
485
+		} else {
486
+			$where = array( 'form_key' => $id );
487
+		}
488
+
489
+		$results = FrmDb::get_row( $table_name, $where );
490
+
491
+		if ( isset($results->options) ) {
492
+			wp_cache_set($results->id, $results, 'frm_form');
493
+			$results->options = maybe_unserialize($results->options);
494
+		}
495
+		return stripslashes_deep($results);
496
+	}
497
+
498
+	/**
499
+	 * @return object|array of objects
500
+	 */
501 501
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
502 502
 		if ( is_array( $where ) && ! empty( $where ) ) {
503 503
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
 			$results = reset( $results );
522 522
 		}
523 523
 
524
-        return stripslashes_deep($results);
525
-    }
524
+		return stripslashes_deep($results);
525
+	}
526 526
 
527 527
 	/**
528 528
 	 * Get all published forms
@@ -540,47 +540,47 @@  discard block
 block discarded – undo
540 540
 		return $forms;
541 541
 	}
542 542
 
543
-    /**
544
-     * @return int count of forms
545
-     */
546
-    public static function &get_count() {
547
-    	global $wpdb;
543
+	/**
544
+	 * @return int count of forms
545
+	 */
546
+	public static function &get_count() {
547
+		global $wpdb;
548 548
 
549
-    	$cache_key = 'frm_form_counts';
549
+		$cache_key = 'frm_form_counts';
550 550
 
551
-    	$counts = wp_cache_get( $cache_key, 'counts' );
552
-    	if ( false !== $counts ) {
553
-    	    return $counts;
554
-    	}
551
+		$counts = wp_cache_get( $cache_key, 'counts' );
552
+		if ( false !== $counts ) {
553
+			return $counts;
554
+		}
555 555
 
556
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
556
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
557 557
 
558 558
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
559
-    	$counts = array_fill_keys( $statuses, 0 );
559
+		$counts = array_fill_keys( $statuses, 0 );
560 560
 
561
-    	foreach ( $results as $row ) {
562
-            if ( 'trash' != $row->status ) {
563
-    	        if ( $row->is_template ) {
561
+		foreach ( $results as $row ) {
562
+			if ( 'trash' != $row->status ) {
563
+				if ( $row->is_template ) {
564 564
 					$counts['template']++;
565
-    	        } else {
565
+				} else {
566 566
 					$counts['published']++;
567
-    	        }
568
-    	    } else {
567
+				}
568
+			} else {
569 569
 				$counts['trash']++;
570
-        	}
570
+			}
571 571
 
572
-    	    if ( 'draft' == $row->status ) {
572
+			if ( 'draft' == $row->status ) {
573 573
 				$counts['draft']++;
574
-    	    }
574
+			}
575 575
 
576
-    		unset($row);
577
-    	}
576
+			unset($row);
577
+		}
578 578
 
579
-    	$counts = (object) $counts;
580
-    	wp_cache_set( $cache_key, $counts, 'counts' );
579
+		$counts = (object) $counts;
580
+		wp_cache_set( $cache_key, $counts, 'counts' );
581 581
 
582
-    	return $counts;
583
-    }
582
+		return $counts;
583
+	}
584 584
 
585 585
 	/**
586 586
 	 * Clear form caching
@@ -593,14 +593,14 @@  discard block
 block discarded – undo
593 593
 		FrmAppHelper::cache_delete_group( 'frm_form' );
594 594
 	}
595 595
 
596
-    /**
597
-     * @return array of errors
598
-     */
596
+	/**
597
+	 * @return array of errors
598
+	 */
599 599
 	public static function validate( $values ) {
600
-        $errors = array();
600
+		$errors = array();
601 601
 
602
-        return apply_filters('frm_validate_form', $errors, $values);
603
-    }
602
+		return apply_filters('frm_validate_form', $errors, $values);
603
+	}
604 604
 
605 605
 	public static function get_params( $form = null ) {
606 606
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 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 {
@@ -12,32 +12,32 @@  discard block
 block discarded – undo
12 12
         global $wpdb;
13 13
 
14 14
         $new_values = array(
15
-            'form_key'      => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'),
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 = 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'];
39 39
 
40
-        $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
40
+        $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42 42
         $id = $wpdb->insert_id;
43 43
 
@@ -61,38 +61,38 @@  discard block
 block discarded – undo
61 61
         $new_key = $copy_keys ? $values->form_key : '';
62 62
 
63 63
         $new_values = array(
64
-            'form_key'      => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'),
64
+            'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65 65
             'name'          => $values->name,
66 66
             'description'   => $values->description,
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
-        $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values );
88
+        $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90 90
         if ( $query_results ) {
91 91
 			// Clear form caching
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']) ) {
131
-            $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id);
130
+        if ( isset( $values['form_key'] ) ) {
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
-            if ( in_array($value_key, $form_fields) ) {
140
-				$new_values[ $value_key ] = $value;
139
+            if ( in_array( $value_key, $form_fields ) ) {
140
+				$new_values[$value_key] = $value;
141 141
             }
142 142
         }
143 143
 
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
         }
147 147
 
148 148
         if ( ! empty( $new_values ) ) {
149
-            $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) );
149
+            $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
150 150
             if ( $query_results ) {
151 151
 				self::clear_form_cache();
152 152
             }
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
-        do_action('frm_update_form', $id, $values);
161
-        do_action('frm_update_form_'. $id, $values);
160
+        do_action( 'frm_update_form', $id, $values );
161
+        do_action( 'frm_update_form_' . $id, $values );
162 162
 
163 163
         return $query_results;
164 164
     }
@@ -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 = 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,82 +191,82 @@  discard block
 block discarded – undo
191 191
      */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
194
+        if ( ! isset( $values['options'] ) && ! 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
-			if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
228
+			if ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) {
229 229
                 //updating the settings page
230
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
231
-					$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 ) );
232
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
230
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
231
+					$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 ) );
232
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
233 233
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
234 234
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
235 235
                     $prev_opts = $field->field_options;
236
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
236
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
237 237
                     if ( $prev_opts != $field->field_options ) {
238 238
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
239 239
                     }
240
-                    unset($prev_opts);
240
+                    unset( $prev_opts );
241 241
                 }
242 242
             }
243 243
 
244
-			if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) {
244
+			if ( ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) && ! defined( 'WP_IMPORTING' ) ) {
245 245
                 continue;
246 246
             }
247 247
 
248 248
             //updating the form
249 249
 			foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size' ) as $opt ) {
250
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : '';
250
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( $values['field_options'][$opt . '_' . $field_id] ) : '';
251 251
             }
252 252
 
253
-			$field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*';
254
-			$field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0;
253
+			$field->field_options['required_indicator'] = isset( $values['field_options']['required_indicator_' . $field_id] ) ? trim( $values['field_options']['required_indicator_' . $field_id] ) : '*';
254
+			$field->field_options['separate_value'] = isset( $values['field_options']['separate_value_' . $field_id] ) ? trim( $values['field_options']['separate_value_' . $field_id] ) : 0;
255 255
 
256
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
257
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
258
-			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
259
-			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
260
-			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
261
-			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
256
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
257
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
258
+			$field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key;
259
+			$required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false;
260
+			$field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type;
261
+			$field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description;
262 262
 
263
-            FrmField::update($field_id, array(
263
+            FrmField::update( $field_id, array(
264 264
                 'field_key' => $field_key, 'type' => $field_type,
265 265
                 'default_value' => $default_value, 'field_options' => $field->field_options,
266 266
                 'description' => $field_description, 'required' => $required,
267 267
             ) );
268 268
 
269
-            FrmField::delete_form_transient($field->form_id);
269
+            FrmField::delete_form_transient( $field->form_id );
270 270
         }
271 271
 
272 272
         return $values;
@@ -278,17 +278,17 @@  discard block
 block discarded – undo
278 278
      */
279 279
 	public static function set_status( $id, $status ) {
280 280
         if ( 'trash' == $status ) {
281
-            return self::trash($id);
281
+            return self::trash( $id );
282 282
         }
283 283
 
284
-		$statuses  = array( 'published', 'draft', 'trash' );
284
+		$statuses = array( 'published', 'draft', 'trash' );
285 285
         if ( ! in_array( $status, $statuses ) ) {
286 286
             return false;
287 287
         }
288 288
 
289 289
         global $wpdb;
290 290
 
291
-        if ( is_array($id) ) {
291
+        if ( is_array( $id ) ) {
292 292
 			$where = array( 'id' => $id );
293 293
 			FrmDb::get_where_clause_and_values( $where );
294 294
 			array_unshift( $where['values'], $status );
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             return self::destroy( $id );
314 314
         }
315 315
 
316
-        $form = self::getOne($id);
316
+        $form = self::getOne( $id );
317 317
         if ( ! $form ) {
318 318
             return false;
319 319
         }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 
324 324
         global $wpdb;
325 325
         $query_results = $wpdb->update(
326
-            $wpdb->prefix .'frm_forms',
326
+            $wpdb->prefix . 'frm_forms',
327 327
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
328 328
 			array( 'id' => $id )
329 329
         );
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	public static function destroy( $id ) {
342 342
         global $wpdb;
343 343
 
344
-        $form = self::getOne($id);
344
+        $form = self::getOne( $id );
345 345
         if ( ! $form ) {
346 346
             return false;
347 347
         }
@@ -349,24 +349,24 @@  discard block
 block discarded – undo
349 349
         // Disconnect the entries from this form
350 350
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
351 351
         foreach ( $entries as $entry_id ) {
352
-            FrmEntry::destroy($entry_id);
353
-            unset($entry_id);
352
+            FrmEntry::destroy( $entry_id );
353
+            unset( $entry_id );
354 354
         }
355 355
 
356 356
         // Disconnect the fields from this form
357
-        $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));
357
+        $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 ) );
358 358
 
359
-        $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
359
+        $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
360 360
         if ( $query_results ) {
361 361
             // Delete all form actions linked to this form
362 362
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
363
-            $action_control->destroy($id, 'all');
363
+            $action_control->destroy( $id, 'all' );
364 364
 
365 365
 			// Clear form caching
366 366
 			self::clear_form_cache();
367 367
 
368
-            do_action('frm_destroy_form', $id);
369
-            do_action('frm_destroy_form_'. $id);
368
+            do_action( 'frm_destroy_form', $id );
369
+            do_action( 'frm_destroy_form_' . $id );
370 370
         }
371 371
 
372 372
         return $query_results;
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 			$form->options = maybe_unserialize( $form->options );
395 395
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
396 396
 				self::destroy( $form->id );
397
-				$count++;
397
+				$count ++;
398 398
 			}
399 399
 
400 400
 			unset( $form );
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
     public static function &getName( $id ) {
409 409
         global $wpdb;
410 410
 
411
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
411
+        $form = FrmAppHelper::check_cache( $id, 'frm_form' );
412 412
         if ( $form ) {
413
-            $r = stripslashes($form->name);
413
+            $r = stripslashes( $form->name );
414 414
             return $r;
415 415
         }
416 416
 
417 417
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
418 418
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
419
-        $r = stripslashes($r);
419
+        $r = stripslashes( $r );
420 420
 
421 421
         return $r;
422 422
     }
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
      */
437 437
 	public static function &getKeyById( $id ) {
438 438
         $id = (int) $id;
439
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
439
+        $cache = FrmAppHelper::check_cache( $id, 'frm_form' );
440 440
         if ( $cache ) {
441 441
             return $cache->form_key;
442 442
         }
@@ -465,22 +465,22 @@  discard block
 block discarded – undo
465 465
 
466 466
         if ( $blog_id && is_multisite() ) {
467 467
             global $wpmuBaseTablePrefix;
468
-            $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id );
468
+            $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
469 469
 
470
-            $table_name = $prefix .'frm_forms';
470
+            $table_name = $prefix . 'frm_forms';
471 471
         } else {
472
-            $table_name = $wpdb->prefix .'frm_forms';
473
-            $cache = wp_cache_get($id, 'frm_form');
472
+            $table_name = $wpdb->prefix . 'frm_forms';
473
+            $cache = wp_cache_get( $id, 'frm_form' );
474 474
             if ( $cache ) {
475
-                if ( isset($cache->options) ) {
476
-                    $cache->options = maybe_unserialize($cache->options);
475
+                if ( isset( $cache->options ) ) {
476
+                    $cache->options = maybe_unserialize( $cache->options );
477 477
                 }
478 478
 
479
-                return stripslashes_deep($cache);
479
+                return stripslashes_deep( $cache );
480 480
             }
481 481
         }
482 482
 
483
-        if ( is_numeric($id) ) {
483
+        if ( is_numeric( $id ) ) {
484 484
             $where = array( 'id' => $id );
485 485
         } else {
486 486
             $where = array( 'form_key' => $id );
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 
489 489
         $results = FrmDb::get_row( $table_name, $where );
490 490
 
491
-        if ( isset($results->options) ) {
492
-            wp_cache_set($results->id, $results, 'frm_form');
493
-            $results->options = maybe_unserialize($results->options);
491
+        if ( isset( $results->options ) ) {
492
+            wp_cache_set( $results->id, $results, 'frm_form' );
493
+            $results->options = maybe_unserialize( $results->options );
494 494
         }
495
-        return stripslashes_deep($results);
495
+        return stripslashes_deep( $results );
496 496
     }
497 497
 
498 498
     /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 			$results = reset( $results );
522 522
 		}
523 523
 
524
-        return stripslashes_deep($results);
524
+        return stripslashes_deep( $results );
525 525
     }
526 526
 
527 527
 	/**
@@ -561,19 +561,19 @@  discard block
 block discarded – undo
561 561
     	foreach ( $results as $row ) {
562 562
             if ( 'trash' != $row->status ) {
563 563
     	        if ( $row->is_template ) {
564
-					$counts['template']++;
564
+					$counts['template'] ++;
565 565
     	        } else {
566
-					$counts['published']++;
566
+					$counts['published'] ++;
567 567
     	        }
568 568
     	    } else {
569
-				$counts['trash']++;
569
+				$counts['trash'] ++;
570 570
         	}
571 571
 
572 572
     	    if ( 'draft' == $row->status ) {
573
-				$counts['draft']++;
573
+				$counts['draft'] ++;
574 574
     	    }
575 575
 
576
-    		unset($row);
576
+    		unset( $row );
577 577
     	}
578 578
 
579 579
     	$counts = (object) $counts;
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 	public static function validate( $values ) {
600 600
         $errors = array();
601 601
 
602
-        return apply_filters('frm_validate_form', $errors, $values);
602
+        return apply_filters( 'frm_validate_form', $errors, $values );
603 603
     }
604 604
 
605 605
 	public static function get_params( $form = null ) {
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
 			self::maybe_get_form( $form );
612 612
 		}
613 613
 
614
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
615
-			return $frm_vars['form_params'][ $form->id ];
614
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
615
+			return $frm_vars['form_params'][$form->id];
616 616
 		}
617 617
 
618
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
618
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
619 619
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
620 620
 
621 621
 		$default_values = array(
@@ -633,15 +633,15 @@  discard block
 block discarded – undo
633 633
 			//if there are two forms on the same page, make sure not to submit both
634 634
 			foreach ( $default_values as $var => $default ) {
635 635
 				if ( $var == 'action' ) {
636
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
636
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
637 637
 				} else {
638
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default );
638
+					$values[$var] = FrmAppHelper::get_param( $var, $default );
639 639
 				}
640 640
 				unset( $var, $default );
641 641
 			}
642 642
 		} else {
643 643
 			foreach ( $default_values as $var => $default ) {
644
-				$values[ $var ] = $default;
644
+				$values[$var] = $default;
645 645
 				unset( $var, $default );
646 646
 			}
647 647
 		}
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
 	public static function list_page_params() {
657 657
 		$values = array();
658 658
 		foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
659
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
659
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
660 660
 		}
661 661
 
662 662
 		return $values;
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 			'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
677 677
 			'keep_post' => '',
678 678
 		) as $var => $default ) {
679
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
679
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
680 680
 		}
681 681
 
682 682
 		return $values;
@@ -718,16 +718,16 @@  discard block
 block discarded – undo
718 718
 		$small_form = new stdClass();
719 719
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
720 720
 			$small_form->{$var} = $form->{$var};
721
-			unset($var);
721
+			unset( $var );
722 722
 		}
723 723
 
724 724
 		$frm_vars['forms_loaded'][] = $small_form;
725 725
 
726
-		if ( $this_load && empty($global_load) ) {
726
+		if ( $this_load && empty( $global_load ) ) {
727 727
 			$global_load = $frm_vars['load_css'] = true;
728 728
 		}
729 729
 
730
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
730
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
731 731
 	}
732 732
 
733 733
 	public static function show_submit( $form ) {
Please login to merge, or discard this patch.
classes/models/FrmFormAction.php 2 patches
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	public $action_options;     // Option array passed to wp_register_sidebar_widget()
9 9
 	public $control_options;	// Option array passed to wp_register_widget_control()
10 10
 
11
-    public $form_id;        // The ID of the form to evaluate
11
+	public $form_id;        // The ID of the form to evaluate
12 12
 	public $number = false;	// Unique ID number of the current instance.
13 13
 	public $id = '';		// Unique ID string of the current instance (id_base-number)
14 14
 	public $updated = false;	// Set true when we update the data after a POST submit - makes sure we don't do it twice.
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	}
30 30
 
31 31
 	/**
32
-     * Echo the settings update form
32
+	 * Echo the settings update form
33 33
 	 *
34 34
 	 * @param array $instance Current settings
35 35
 	 */
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
 	 * @return array of the default options
43 43
 	 */
44 44
 	public function get_defaults() {
45
-	    return array();
45
+		return array();
46 46
 	}
47 47
 
48 48
 	public function get_switch_fields() {
49
-	    return array();
49
+		return array();
50 50
 	}
51 51
 
52 52
 	public function migrate_values( $action, $form ) {
53
-	    return $action;
53
+		return $action;
54 54
 	}
55 55
 
56 56
 	// Functions you'll need to call.
@@ -69,24 +69,24 @@  discard block
 block discarded – undo
69 69
 	 *	 - height: currently not used but may be needed in the future
70 70
 	 */
71 71
 	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
-	    if ( ! defined('ABSPATH') ) {
73
-            die('You are not allowed to call this page directly.');
74
-        }
72
+		if ( ! defined('ABSPATH') ) {
73
+			die('You are not allowed to call this page directly.');
74
+		}
75 75
 
76 76
 		$this->id_base = strtolower($id_base);
77 77
 		$this->name = $name;
78 78
 		$this->option_name = 'frm_' . $this->id_base .'_action';
79 79
 
80
-        $default_options = array(
81
-            'classes'   => '',
82
-            'active'    => true,
80
+		$default_options = array(
81
+			'classes'   => '',
82
+			'active'    => true,
83 83
 			'event'     => array( 'create' ),
84
-            'limit'     => 1,
85
-            'force_event' => false,
86
-            'priority'  => 20,
87
-            'ajax_load' => true,
88
-            'tooltip'   => $name,
89
-        );
84
+			'limit'     => 1,
85
+			'force_event' => false,
86
+			'priority'  => 20,
87
+			'ajax_load' => true,
88
+			'tooltip'   => $name,
89
+		);
90 90
 
91 91
 		$action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
92 92
 		$this->action_options = wp_parse_args( $action_options, $default_options );
@@ -132,132 +132,132 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 	public function prepare_new( $form_id = false ) {
135
-        if ( $form_id ) {
136
-            $this->form_id = $form_id;
137
-        }
138
-
139
-        $post_content = array();
140
-        $default_values = $this->get_global_defaults();
141
-
142
-        // fill default values
143
-        $post_content = wp_parse_args( $post_content, $default_values);
144
-
145
-        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
-            $post_content['event'] = array( reset($this->action_options['event']) );
147
-        }
148
-
149
-        $form_action = array(
150
-            'post_title'    => $this->name,
151
-            'post_content'  => $post_content,
152
-            'post_excerpt'  => $this->id_base,
153
-            'ID'            => '',
154
-            'post_status'   => 'publish',
155
-            'post_type'     => FrmFormActionsController::$action_post_type,
156
-            'post_name'     => $this->form_id .'_'. $this->id_base .'_'. $this->number,
157
-            'menu_order'    => $this->form_id,
158
-        );
159
-        unset($post_content);
160
-
161
-        return (object) $form_action;
162
-    }
135
+		if ( $form_id ) {
136
+			$this->form_id = $form_id;
137
+		}
138
+
139
+		$post_content = array();
140
+		$default_values = $this->get_global_defaults();
141
+
142
+		// fill default values
143
+		$post_content = wp_parse_args( $post_content, $default_values);
144
+
145
+		if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
+			$post_content['event'] = array( reset($this->action_options['event']) );
147
+		}
148
+
149
+		$form_action = array(
150
+			'post_title'    => $this->name,
151
+			'post_content'  => $post_content,
152
+			'post_excerpt'  => $this->id_base,
153
+			'ID'            => '',
154
+			'post_status'   => 'publish',
155
+			'post_type'     => FrmFormActionsController::$action_post_type,
156
+			'post_name'     => $this->form_id .'_'. $this->id_base .'_'. $this->number,
157
+			'menu_order'    => $this->form_id,
158
+		);
159
+		unset($post_content);
160
+
161
+		return (object) $form_action;
162
+	}
163 163
 
164 164
 	public function create( $form_id ) {
165
-        $this->form_id = $form_id;
165
+		$this->form_id = $form_id;
166 166
 
167
-        $action = $this->prepare_new();
167
+		$action = $this->prepare_new();
168 168
 
169
-        return $this->save_settings($action);
170
-    }
169
+		return $this->save_settings($action);
170
+	}
171 171
 
172 172
 	public function duplicate_form_actions( $form_id, $old_id ) {
173
-        if ( $form_id == $old_id ) {
174
-            // don't duplicate the actions if this is a template getting updated
175
-            return;
176
-        }
177
-
178
-        $this->form_id = $old_id;
179
-        $actions = $this->get_all( $old_id );
180
-
181
-        $this->form_id = $form_id;
182
-        foreach ( $actions as $action ) {
183
-            $this->duplicate_one($action, $form_id);
184
-            unset($action);
185
-        }
186
-    }
187
-
188
-    /* Check if imported action should be created or updated
173
+		if ( $form_id == $old_id ) {
174
+			// don't duplicate the actions if this is a template getting updated
175
+			return;
176
+		}
177
+
178
+		$this->form_id = $old_id;
179
+		$actions = $this->get_all( $old_id );
180
+
181
+		$this->form_id = $form_id;
182
+		foreach ( $actions as $action ) {
183
+			$this->duplicate_one($action, $form_id);
184
+			unset($action);
185
+		}
186
+	}
187
+
188
+	/* Check if imported action should be created or updated
189 189
     *
190 190
     * Since 2.0
191 191
     *
192 192
     * @param array $action
193 193
     * @return integer $post_id
194 194
     */
195
-    public function maybe_create_action( $action, $forms ) {
195
+	public function maybe_create_action( $action, $forms ) {
196 196
 		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
197
-            // Update action only
198
-            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199
-            $post_id = $this->save_settings( $action );
200
-        } else {
201
-            // Create action
202
-            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
-            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
204
-        }
205
-        return $post_id;
206
-    }
197
+			// Update action only
198
+			$action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199
+			$post_id = $this->save_settings( $action );
200
+		} else {
201
+			// Create action
202
+			$action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
+			$post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
204
+		}
205
+		return $post_id;
206
+	}
207 207
 
208 208
 	public function duplicate_one( $action, $form_id ) {
209
-        global $frm_duplicate_ids;
209
+		global $frm_duplicate_ids;
210 210
 
211
-        $action->menu_order = $form_id;
212
-        $switch = $this->get_global_switch_fields();
213
-        foreach ( (array) $action->post_content as $key => $val ) {
211
+		$action->menu_order = $form_id;
212
+		$switch = $this->get_global_switch_fields();
213
+		foreach ( (array) $action->post_content as $key => $val ) {
214 214
 			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
215 215
 				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
216
-            } else if ( ! is_array( $val ) ) {
216
+			} else if ( ! is_array( $val ) ) {
217 217
 				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
218 218
 			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
219
-                // loop through each value if empty
219
+				// loop through each value if empty
220 220
 				if ( empty( $switch[ $key ] ) ) {
221 221
 					$switch[ $key ] = array_keys( $val );
222 222
 				}
223 223
 
224 224
 				foreach ( $switch[ $key ] as $subkey ) {
225 225
 					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
226
-                }
227
-            }
226
+				}
227
+			}
228 228
 
229
-            unset($key, $val);
230
-        }
231
-        unset($action->ID);
229
+			unset($key, $val);
230
+		}
231
+		unset($action->ID);
232 232
 
233
-        return $this->save_settings($action);
234
-    }
233
+		return $this->save_settings($action);
234
+	}
235 235
 
236 236
 	private function duplicate_array_walk( $action, $subkey, $val ) {
237
-        global $frm_duplicate_ids;
237
+		global $frm_duplicate_ids;
238 238
 
239
-        if ( is_array($subkey) ) {
240
-            foreach ( $subkey as $subkey2 ) {
241
-                foreach ( (array) $val as $ck => $cv ) {
242
-                    if ( is_array($cv) ) {
239
+		if ( is_array($subkey) ) {
240
+			foreach ( $subkey as $subkey2 ) {
241
+				foreach ( (array) $val as $ck => $cv ) {
242
+					if ( is_array($cv) ) {
243 243
 						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
244 244
 					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
245 245
 						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
246
-                    }
247
-                }
248
-            }
249
-        } else {
250
-            foreach ( (array) $val as $ck => $cv ) {
251
-                if ( is_array($cv) ) {
246
+					}
247
+				}
248
+			}
249
+		} else {
250
+			foreach ( (array) $val as $ck => $cv ) {
251
+				if ( is_array($cv) ) {
252 252
 					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
253 253
 				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
254 254
 					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
255
-                }
256
-            }
257
-        }
255
+				}
256
+			}
257
+		}
258 258
 
259
-        return $action;
260
-    }
259
+		return $action;
260
+	}
261 261
 
262 262
 	/**
263 263
 	 * Deal with changed settings.
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 */
268 268
  	public function update_callback( $form_id ) {
269
-        $this->form_id = $form_id;
269
+		$this->form_id = $form_id;
270 270
 
271 271
  		$all_instances = $this->get_settings();
272 272
 
@@ -281,25 +281,25 @@  discard block
 block discarded – undo
281 281
  			return;
282 282
  		}
283 283
 
284
-        $action_ids = array();
284
+		$action_ids = array();
285 285
 
286 286
  		foreach ( $settings as $number => $new_instance ) {
287 287
  			$this->_set($number);
288 288
 
289 289
  			if ( ! isset($new_instance['post_title']) ) {
290
- 			    // settings were never opened, so don't update
291
- 			    $action_ids[] = $new_instance['ID'];
292
-         		$this->updated = true;
293
-         		continue;
290
+ 				// settings were never opened, so don't update
291
+ 				$action_ids[] = $new_instance['ID'];
292
+		 		$this->updated = true;
293
+		 		continue;
294 294
  			}
295 295
 
296 296
 			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
297 297
 
298 298
  			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
299
-            $new_instance['post_name']    = $this->form_id .'_'. $this->id_base .'_'. $this->number;
300
-            $new_instance['menu_order']   = $this->form_id;
301
-            $new_instance['post_status']  = 'publish';
302
-            $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
299
+			$new_instance['post_name']    = $this->form_id .'_'. $this->id_base .'_'. $this->number;
300
+			$new_instance['menu_order']   = $this->form_id;
301
+			$new_instance['post_status']  = 'publish';
302
+			$new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
303 303
 
304 304
  			$instance = $this->update( $new_instance, $old_instance );
305 305
 
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
 			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
320 320
 
321 321
 			$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
-            $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
+			$instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
323 323
 
324 324
 			if ( false !== $instance ) {
325 325
 				$all_instances[ $number ] = $instance;
326 326
 			}
327 327
 
328
-            $action_ids[] = $this->save_settings($instance);
328
+			$action_ids[] = $this->save_settings($instance);
329 329
 
330
-     		$this->updated = true;
330
+	 		$this->updated = true;
331 331
  		}
332 332
 
333 333
  		return $action_ids;
@@ -338,100 +338,100 @@  discard block
 block discarded – undo
338 338
 	}
339 339
 
340 340
 	public function get_single_action( $id ) {
341
-	    $action = get_post($id);
341
+		$action = get_post($id);
342 342
 		if ( $action ) {
343 343
 			$action = $this->prepare_action( $action );
344 344
 			$this->_set( $id );
345 345
 		}
346
-	    return $action;
346
+		return $action;
347 347
 	}
348 348
 
349 349
 	public function get_one( $form_id ) {
350
-	    return $this->get_all($form_id, 1);
350
+		return $this->get_all($form_id, 1);
351 351
 	}
352 352
 
353
-    public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
354
-        $action_controls = FrmFormActionsController::get_form_actions( $type );
355
-        if ( empty($action_controls) ) {
356
-            // don't continue if there are no available actions
357
-            return array();
358
-        }
353
+	public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
354
+		$action_controls = FrmFormActionsController::get_form_actions( $type );
355
+		if ( empty($action_controls) ) {
356
+			// don't continue if there are no available actions
357
+			return array();
358
+		}
359 359
 
360
-        if ( 'all' != $type ) {
361
-            return $action_controls->get_all( $form_id, $limit );
362
-        }
360
+		if ( 'all' != $type ) {
361
+			return $action_controls->get_all( $form_id, $limit );
362
+		}
363 363
 
364 364
 		$args = self::action_args( $form_id, $limit );
365 365
 		$actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
366 366
 
367
-        if ( ! $actions ) {
368
-            return array();
369
-        }
367
+		if ( ! $actions ) {
368
+			return array();
369
+		}
370 370
 
371
-        $settings = array();
372
-        foreach ( $actions as $action ) {
371
+		$settings = array();
372
+		foreach ( $actions as $action ) {
373 373
 			// some plugins/themes are formatting the post_excerpt
374 374
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
375 375
 
376 376
 			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
377
-                continue;
378
-            }
377
+				continue;
378
+			}
379 379
 
380
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
380
+			$action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
381 381
 			$settings[ $action->ID ] = $action;
382 382
 
383 383
 			if ( count( $settings ) >= $limit ) {
384 384
 				break;
385 385
 			}
386
-        }
386
+		}
387 387
 
388
-        if ( 1 === $limit ) {
389
-            $settings = reset($settings);
390
-        }
388
+		if ( 1 === $limit ) {
389
+			$settings = reset($settings);
390
+		}
391 391
 
392
-        return $settings;
393
-    }
392
+		return $settings;
393
+	}
394 394
 
395 395
 	public function get_all( $form_id = false, $limit = 99 ) {
396
-	    if ( $form_id ) {
397
-	        $this->form_id = $form_id;
398
-	    }
396
+		if ( $form_id ) {
397
+			$this->form_id = $form_id;
398
+		}
399 399
 
400
-	    $type = $this->id_base;
400
+		$type = $this->id_base;
401 401
 
402
-	    global $frm_vars;
403
-	    $frm_vars['action_type'] = $type;
402
+		global $frm_vars;
403
+		$frm_vars['action_type'] = $type;
404 404
 
405
-	    add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
405
+		add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
406 406
 		$query = self::action_args( $form_id, $limit );
407
-        $query['post_status']      = 'any';
408
-        $query['suppress_filters'] = false;
407
+		$query['post_status']      = 'any';
408
+		$query['suppress_filters'] = false;
409 409
 
410 410
 		$actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
411
-        unset($query);
411
+		unset($query);
412 412
 
413
-        remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
413
+		remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
414 414
 
415
-        if ( empty($actions) ) {
416
-            return array();
417
-        }
415
+		if ( empty($actions) ) {
416
+			return array();
417
+		}
418 418
 
419
-        $settings = array();
420
-        foreach ( $actions as $action ) {
421
-            if ( count($settings) >= $limit ) {
422
-                continue;
423
-            }
419
+		$settings = array();
420
+		foreach ( $actions as $action ) {
421
+			if ( count($settings) >= $limit ) {
422
+				continue;
423
+			}
424 424
 
425
-            $action = $this->prepare_action($action);
425
+			$action = $this->prepare_action($action);
426 426
 
427 427
 			$settings[ $action->ID ] = $action;
428
-        }
428
+		}
429 429
 
430
-        if ( 1 === $limit ) {
431
-            $settings = reset($settings);
432
-        }
430
+		if ( 1 === $limit ) {
431
+			$settings = reset($settings);
432
+		}
433 433
 
434
-        return $settings;
434
+		return $settings;
435 435
 	}
436 436
 
437 437
 	public static function action_args( $form_id = 0, $limit = 99 ) {
@@ -454,45 +454,45 @@  discard block
 block discarded – undo
454 454
 		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
455 455
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
456 456
 
457
-        $default_values = $this->get_global_defaults();
457
+		$default_values = $this->get_global_defaults();
458 458
 
459
-        // fill default values
460
-        $action->post_content += $default_values;
459
+		// fill default values
460
+		$action->post_content += $default_values;
461 461
 
462
-        foreach ( $default_values as $k => $vals ) {
463
-            if ( is_array($vals) && ! empty($vals) ) {
462
+		foreach ( $default_values as $k => $vals ) {
463
+			if ( is_array($vals) && ! empty($vals) ) {
464 464
 				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
465
-                    continue;
466
-                }
465
+					continue;
466
+				}
467 467
 				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
468
-            }
469
-        }
468
+			}
469
+		}
470 470
 
471
-        if ( ! is_array($action->post_content['event']) ) {
472
-            $action->post_content['event'] = explode(',', $action->post_content['event']);
473
-        }
471
+		if ( ! is_array($action->post_content['event']) ) {
472
+			$action->post_content['event'] = explode(',', $action->post_content['event']);
473
+		}
474 474
 
475
-        return $action;
475
+		return $action;
476 476
 	}
477 477
 
478 478
 	public function destroy( $form_id = false, $type = 'default' ) {
479
-	    global $wpdb;
479
+		global $wpdb;
480 480
 
481
-	    $this->form_id = $form_id;
481
+		$this->form_id = $form_id;
482 482
 
483
-	    $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
484
-	    if ( $form_id ) {
485
-	        $query['menu_order'] = $form_id;
486
-	    }
487
-	    if ( 'all' != $type ) {
488
-	        $query['post_excerpt'] = $this->id_base;
489
-	    }
483
+		$query = array( 'post_type' => FrmFormActionsController::$action_post_type );
484
+		if ( $form_id ) {
485
+			$query['menu_order'] = $form_id;
486
+		}
487
+		if ( 'all' != $type ) {
488
+			$query['post_excerpt'] = $this->id_base;
489
+		}
490 490
 
491
-        $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
491
+		$post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
492 492
 
493
-        foreach ( $post_ids as $id ) {
494
-            wp_delete_post($id);
495
-        }
493
+		foreach ( $post_ids as $id ) {
494
+			wp_delete_post($id);
495
+		}
496 496
 		self::clear_cache();
497 497
 	}
498 498
 
@@ -510,69 +510,69 @@  discard block
 block discarded – undo
510 510
 	}
511 511
 
512 512
 	public function get_global_defaults() {
513
-	    $defaults = $this->get_defaults();
513
+		$defaults = $this->get_defaults();
514 514
 
515
-	    if ( ! isset($defaults['event']) ) {
515
+		if ( ! isset($defaults['event']) ) {
516 516
 			$defaults['event'] = array( 'create' );
517
-	    }
517
+		}
518 518
 
519
-	    if ( ! isset($defaults['conditions']) ) {
520
-	        $defaults['conditions'] = array(
521
-                'send_stop' => '',
522
-                'any_all'   => '',
523
-            );
524
-        }
519
+		if ( ! isset($defaults['conditions']) ) {
520
+			$defaults['conditions'] = array(
521
+				'send_stop' => '',
522
+				'any_all'   => '',
523
+			);
524
+		}
525 525
 
526
-        return $defaults;
526
+		return $defaults;
527 527
 	}
528 528
 
529 529
 	public function get_global_switch_fields() {
530
-	    $switch = $this->get_switch_fields();
530
+		$switch = $this->get_switch_fields();
531 531
 		$switch['conditions'] = array( 'hide_field' );
532
-	    return $switch;
532
+		return $switch;
533 533
 	}
534 534
 
535 535
 	/**
536 536
 	 * Migrate settings from form->options into new action.
537 537
 	 */
538 538
 	public function migrate_to_2( $form, $update = 'update' ) {
539
-        $action = $this->prepare_new($form->id);
540
-        $form->options = maybe_unserialize($form->options);
539
+		$action = $this->prepare_new($form->id);
540
+		$form->options = maybe_unserialize($form->options);
541 541
 
542
-        // fill with existing options
543
-        foreach ( $action->post_content as $name => $val ) {
542
+		// fill with existing options
543
+		foreach ( $action->post_content as $name => $val ) {
544 544
 			if ( isset( $form->options[ $name ] ) ) {
545 545
 				$action->post_content[ $name ] = $form->options[ $name ];
546 546
 				unset( $form->options[ $name ] );
547
-            }
548
-        }
547
+			}
548
+		}
549 549
 
550
-        $action = $this->migrate_values($action, $form);
550
+		$action = $this->migrate_values($action, $form);
551 551
 
552
-        // check if action already exists
553
-        $post_id = get_posts( array(
554
-            'name'          => $action->post_name,
555
-            'post_type'     => FrmFormActionsController::$action_post_type,
556
-            'post_status'   => $action->post_status,
557
-            'numberposts'   => 1,
558
-        ) );
552
+		// check if action already exists
553
+		$post_id = get_posts( array(
554
+			'name'          => $action->post_name,
555
+			'post_type'     => FrmFormActionsController::$action_post_type,
556
+			'post_status'   => $action->post_status,
557
+			'numberposts'   => 1,
558
+		) );
559 559
 
560
-        if ( empty($post_id) ) {
561
-            // create action now
562
-            $post_id = $this->save_settings($action);
563
-        }
560
+		if ( empty($post_id) ) {
561
+			// create action now
562
+			$post_id = $this->save_settings($action);
563
+		}
564 564
 
565
-        if ( $post_id && 'update' == $update ) {
566
-            global $wpdb;
567
-            $form->options = maybe_serialize($form->options);
565
+		if ( $post_id && 'update' == $update ) {
566
+			global $wpdb;
567
+			$form->options = maybe_serialize($form->options);
568 568
 
569
-            // update form options
569
+			// update form options
570 570
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
571
-            wp_cache_delete( $form->id, 'frm_form');
572
-        }
571
+			wp_cache_delete( $form->id, 'frm_form');
572
+		}
573 573
 
574
-        return $post_id;
575
-    }
574
+		return $post_id;
575
+	}
576 576
 
577 577
 	public static function action_conditions_met( $action, $entry ) {
578 578
 		$notification = $action->post_content;
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -2,16 +2,16 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmFormAction {
4 4
 
5
-	public $id_base;			// Root id for all actions of this type.
6
-	public $name;				// Name for this action type.
5
+	public $id_base; // Root id for all actions of this type.
6
+	public $name; // Name for this action type.
7 7
 	public $option_name;
8
-	public $action_options;     // Option array passed to wp_register_sidebar_widget()
9
-	public $control_options;	// Option array passed to wp_register_widget_control()
8
+	public $action_options; // Option array passed to wp_register_sidebar_widget()
9
+	public $control_options; // Option array passed to wp_register_widget_control()
10 10
 
11
-    public $form_id;        // The ID of the form to evaluate
12
-	public $number = false;	// Unique ID number of the current instance.
13
-	public $id = '';		// Unique ID string of the current instance (id_base-number)
14
-	public $updated = false;	// Set true when we update the data after a POST submit - makes sure we don't do it twice.
11
+    public $form_id; // The ID of the form to evaluate
12
+	public $number = false; // Unique ID number of the current instance.
13
+	public $id = ''; // Unique ID string of the current instance (id_base-number)
14
+	public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
15 15
 
16 16
 	// Member functions that you must over-ride.
17 17
 
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 	 *	 - height: currently not used but may be needed in the future
70 70
 	 */
71 71
 	public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
72
-	    if ( ! defined('ABSPATH') ) {
73
-            die('You are not allowed to call this page directly.');
72
+	    if ( ! defined( 'ABSPATH' ) ) {
73
+            die( 'You are not allowed to call this page directly.' );
74 74
         }
75 75
 
76
-		$this->id_base = strtolower($id_base);
76
+		$this->id_base = strtolower( $id_base );
77 77
 		$this->name = $name;
78
-		$this->option_name = 'frm_' . $this->id_base .'_action';
78
+		$this->option_name = 'frm_' . $this->id_base . '_action';
79 79
 
80 80
         $default_options = array(
81 81
             'classes'   => '',
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @return string Name attribute for $field_name
110 110
 	 */
111 111
 	public function get_field_name( $field_name, $post_field = 'post_content' ) {
112
-		return $this->option_name . '[' . $this->number . ']'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']';
112
+		return $this->option_name . '[' . $this->number . ']' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']';
113 113
 	}
114 114
 
115 115
 	/**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @return string ID attribute for $field_name
122 122
 	 */
123 123
 	public function get_field_id( $field_name ) {
124
-		return $field_name .'_'. $this->number;
124
+		return $field_name . '_' . $this->number;
125 125
 	}
126 126
 
127 127
 	// Private Function. Don't worry about this.
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
         $default_values = $this->get_global_defaults();
141 141
 
142 142
         // fill default values
143
-        $post_content = wp_parse_args( $post_content, $default_values);
143
+        $post_content = wp_parse_args( $post_content, $default_values );
144 144
 
145
-        if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) {
146
-            $post_content['event'] = array( reset($this->action_options['event']) );
145
+        if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
146
+            $post_content['event'] = array( reset( $this->action_options['event'] ) );
147 147
         }
148 148
 
149 149
         $form_action = array(
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
             'ID'            => '',
154 154
             'post_status'   => 'publish',
155 155
             'post_type'     => FrmFormActionsController::$action_post_type,
156
-            'post_name'     => $this->form_id .'_'. $this->id_base .'_'. $this->number,
156
+            'post_name'     => $this->form_id . '_' . $this->id_base . '_' . $this->number,
157 157
             'menu_order'    => $this->form_id,
158 158
         );
159
-        unset($post_content);
159
+        unset( $post_content );
160 160
 
161 161
         return (object) $form_action;
162 162
     }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         $action = $this->prepare_new();
168 168
 
169
-        return $this->save_settings($action);
169
+        return $this->save_settings( $action );
170 170
     }
171 171
 
172 172
 	public function duplicate_form_actions( $form_id, $old_id ) {
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
 
181 181
         $this->form_id = $form_id;
182 182
         foreach ( $actions as $action ) {
183
-            $this->duplicate_one($action, $form_id);
184
-            unset($action);
183
+            $this->duplicate_one( $action, $form_id );
184
+            unset( $action );
185 185
         }
186 186
     }
187 187
 
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
     * @return integer $post_id
194 194
     */
195 195
     public function maybe_create_action( $action, $forms ) {
196
-		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
196
+		if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) {
197 197
             // Update action only
198 198
             $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
199 199
             $post_id = $this->save_settings( $action );
200 200
         } else {
201 201
             // Create action
202
-            $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']);
203
-            $post_id = $this->duplicate_one( (object) $action, $action['menu_order']);
202
+            $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
203
+            $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
204 204
         }
205 205
         return $post_id;
206 206
     }
@@ -211,47 +211,47 @@  discard block
 block discarded – undo
211 211
         $action->menu_order = $form_id;
212 212
         $switch = $this->get_global_switch_fields();
213 213
         foreach ( (array) $action->post_content as $key => $val ) {
214
-			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
215
-				$action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
214
+			if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) {
215
+				$action->post_content[$key] = $frm_duplicate_ids[$val];
216 216
             } else if ( ! is_array( $val ) ) {
217
-				$action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
218
-			} else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
217
+				$action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val );
218
+			} else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) {
219 219
                 // loop through each value if empty
220
-				if ( empty( $switch[ $key ] ) ) {
221
-					$switch[ $key ] = array_keys( $val );
220
+				if ( empty( $switch[$key] ) ) {
221
+					$switch[$key] = array_keys( $val );
222 222
 				}
223 223
 
224
-				foreach ( $switch[ $key ] as $subkey ) {
225
-					$action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
224
+				foreach ( $switch[$key] as $subkey ) {
225
+					$action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val );
226 226
                 }
227 227
             }
228 228
 
229
-            unset($key, $val);
229
+            unset( $key, $val );
230 230
         }
231
-        unset($action->ID);
231
+        unset( $action->ID );
232 232
 
233
-        return $this->save_settings($action);
233
+        return $this->save_settings( $action );
234 234
     }
235 235
 
236 236
 	private function duplicate_array_walk( $action, $subkey, $val ) {
237 237
         global $frm_duplicate_ids;
238 238
 
239
-        if ( is_array($subkey) ) {
239
+        if ( is_array( $subkey ) ) {
240 240
             foreach ( $subkey as $subkey2 ) {
241 241
                 foreach ( (array) $val as $ck => $cv ) {
242
-                    if ( is_array($cv) ) {
243
-						$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
244
-					} else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
245
-						$action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
242
+                    if ( is_array( $cv ) ) {
243
+						$action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv );
244
+					} else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) {
245
+						$action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]];
246 246
                     }
247 247
                 }
248 248
             }
249 249
         } else {
250 250
             foreach ( (array) $val as $ck => $cv ) {
251
-                if ( is_array($cv) ) {
252
-					$action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
253
-				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
254
-					$action[ $ck ] = $frm_duplicate_ids[ $cv ];
251
+                if ( is_array( $cv ) ) {
252
+					$action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv );
253
+				} else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) {
254
+					$action[$ck] = $frm_duplicate_ids[$cv];
255 255
                 }
256 256
             }
257 257
         }
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
  			return;
276 276
  		}
277 277
 
278
-		if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
279
-			$settings = $_POST[ $this->option_name ];
278
+		if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) {
279
+			$settings = $_POST[$this->option_name];
280 280
  		} else {
281 281
  			return;
282 282
  		}
@@ -284,19 +284,19 @@  discard block
 block discarded – undo
284 284
         $action_ids = array();
285 285
 
286 286
  		foreach ( $settings as $number => $new_instance ) {
287
- 			$this->_set($number);
287
+ 			$this->_set( $number );
288 288
 
289
- 			if ( ! isset($new_instance['post_title']) ) {
289
+ 			if ( ! isset( $new_instance['post_title'] ) ) {
290 290
  			    // settings were never opened, so don't update
291 291
  			    $action_ids[] = $new_instance['ID'];
292 292
          		$this->updated = true;
293 293
          		continue;
294 294
  			}
295 295
 
296
-			$old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
296
+			$old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array();
297 297
 
298
- 			$new_instance['post_type']  = FrmFormActionsController::$action_post_type;
299
-            $new_instance['post_name']    = $this->form_id .'_'. $this->id_base .'_'. $this->number;
298
+ 			$new_instance['post_type'] = FrmFormActionsController::$action_post_type;
299
+            $new_instance['post_name']    = $this->form_id . '_' . $this->id_base . '_' . $this->number;
300 300
             $new_instance['menu_order']   = $this->form_id;
301 301
             $new_instance['post_status']  = 'publish';
302 302
             $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
@@ -318,14 +318,14 @@  discard block
 block discarded – undo
318 318
 			 */
319 319
 			$instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
320 320
 
321
-			$instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this);
322
-            $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this);
321
+			$instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
322
+            $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
323 323
 
324 324
 			if ( false !== $instance ) {
325
-				$all_instances[ $number ] = $instance;
325
+				$all_instances[$number] = $instance;
326 326
 			}
327 327
 
328
-            $action_ids[] = $this->save_settings($instance);
328
+            $action_ids[] = $this->save_settings( $instance );
329 329
 
330 330
      		$this->updated = true;
331 331
  		}
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	}
339 339
 
340 340
 	public function get_single_action( $id ) {
341
-	    $action = get_post($id);
341
+	    $action = get_post( $id );
342 342
 		if ( $action ) {
343 343
 			$action = $this->prepare_action( $action );
344 344
 			$this->_set( $id );
@@ -347,12 +347,12 @@  discard block
 block discarded – undo
347 347
 	}
348 348
 
349 349
 	public function get_one( $form_id ) {
350
-	    return $this->get_all($form_id, 1);
350
+	    return $this->get_all( $form_id, 1 );
351 351
 	}
352 352
 
353 353
     public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) {
354 354
         $action_controls = FrmFormActionsController::get_form_actions( $type );
355
-        if ( empty($action_controls) ) {
355
+        if ( empty( $action_controls ) ) {
356 356
             // don't continue if there are no available actions
357 357
             return array();
358 358
         }
@@ -373,12 +373,12 @@  discard block
 block discarded – undo
373 373
 			// some plugins/themes are formatting the post_excerpt
374 374
 			$action->post_excerpt = sanitize_title( $action->post_excerpt );
375 375
 
376
-			if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
376
+			if ( ! isset( $action_controls[$action->post_excerpt] ) ) {
377 377
                 continue;
378 378
             }
379 379
 
380
-            $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
381
-			$settings[ $action->ID ] = $action;
380
+            $action = $action_controls[$action->post_excerpt]->prepare_action( $action );
381
+			$settings[$action->ID] = $action;
382 382
 
383 383
 			if ( count( $settings ) >= $limit ) {
384 384
 				break;
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
         }
387 387
 
388 388
         if ( 1 === $limit ) {
389
-            $settings = reset($settings);
389
+            $settings = reset( $settings );
390 390
         }
391 391
 
392 392
         return $settings;
@@ -402,33 +402,33 @@  discard block
 block discarded – undo
402 402
 	    global $frm_vars;
403 403
 	    $frm_vars['action_type'] = $type;
404 404
 
405
-	    add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
405
+	    add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
406 406
 		$query = self::action_args( $form_id, $limit );
407 407
         $query['post_status']      = 'any';
408 408
         $query['suppress_filters'] = false;
409 409
 
410 410
 		$actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
411
-        unset($query);
411
+        unset( $query );
412 412
 
413
-        remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' );
413
+        remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
414 414
 
415
-        if ( empty($actions) ) {
415
+        if ( empty( $actions ) ) {
416 416
             return array();
417 417
         }
418 418
 
419 419
         $settings = array();
420 420
         foreach ( $actions as $action ) {
421
-            if ( count($settings) >= $limit ) {
421
+            if ( count( $settings ) >= $limit ) {
422 422
                 continue;
423 423
             }
424 424
 
425
-            $action = $this->prepare_action($action);
425
+            $action = $this->prepare_action( $action );
426 426
 
427
-			$settings[ $action->ID ] = $action;
427
+			$settings[$action->ID] = $action;
428 428
         }
429 429
 
430 430
         if ( 1 === $limit ) {
431
-            $settings = reset($settings);
431
+            $settings = reset( $settings );
432 432
         }
433 433
 
434 434
         return $settings;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	}
452 452
 
453 453
 	public function prepare_action( $action ) {
454
-		$action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content);
454
+		$action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
455 455
 		$action->post_excerpt = sanitize_title( $action->post_excerpt );
456 456
 
457 457
         $default_values = $this->get_global_defaults();
@@ -460,16 +460,16 @@  discard block
 block discarded – undo
460 460
         $action->post_content += $default_values;
461 461
 
462 462
         foreach ( $default_values as $k => $vals ) {
463
-            if ( is_array($vals) && ! empty($vals) ) {
464
-				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
463
+            if ( is_array( $vals ) && ! empty( $vals ) ) {
464
+				if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) {
465 465
                     continue;
466 466
                 }
467
-				$action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
467
+				$action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals );
468 468
             }
469 469
         }
470 470
 
471
-        if ( ! is_array($action->post_content['event']) ) {
472
-            $action->post_content['event'] = explode(',', $action->post_content['event']);
471
+        if ( ! is_array( $action->post_content['event'] ) ) {
472
+            $action->post_content['event'] = explode( ',', $action->post_content['event'] );
473 473
         }
474 474
 
475 475
         return $action;
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
         $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
492 492
 
493 493
         foreach ( $post_ids as $id ) {
494
-            wp_delete_post($id);
494
+            wp_delete_post( $id );
495 495
         }
496 496
 		self::clear_cache();
497 497
 	}
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
 	public function get_global_defaults() {
513 513
 	    $defaults = $this->get_defaults();
514 514
 
515
-	    if ( ! isset($defaults['event']) ) {
515
+	    if ( ! isset( $defaults['event'] ) ) {
516 516
 			$defaults['event'] = array( 'create' );
517 517
 	    }
518 518
 
519
-	    if ( ! isset($defaults['conditions']) ) {
519
+	    if ( ! isset( $defaults['conditions'] ) ) {
520 520
 	        $defaults['conditions'] = array(
521 521
                 'send_stop' => '',
522 522
                 'any_all'   => '',
@@ -536,18 +536,18 @@  discard block
 block discarded – undo
536 536
 	 * Migrate settings from form->options into new action.
537 537
 	 */
538 538
 	public function migrate_to_2( $form, $update = 'update' ) {
539
-        $action = $this->prepare_new($form->id);
540
-        $form->options = maybe_unserialize($form->options);
539
+        $action = $this->prepare_new( $form->id );
540
+        $form->options = maybe_unserialize( $form->options );
541 541
 
542 542
         // fill with existing options
543 543
         foreach ( $action->post_content as $name => $val ) {
544
-			if ( isset( $form->options[ $name ] ) ) {
545
-				$action->post_content[ $name ] = $form->options[ $name ];
546
-				unset( $form->options[ $name ] );
544
+			if ( isset( $form->options[$name] ) ) {
545
+				$action->post_content[$name] = $form->options[$name];
546
+				unset( $form->options[$name] );
547 547
             }
548 548
         }
549 549
 
550
-        $action = $this->migrate_values($action, $form);
550
+        $action = $this->migrate_values( $action, $form );
551 551
 
552 552
         // check if action already exists
553 553
         $post_id = get_posts( array(
@@ -557,18 +557,18 @@  discard block
 block discarded – undo
557 557
             'numberposts'   => 1,
558 558
         ) );
559 559
 
560
-        if ( empty($post_id) ) {
560
+        if ( empty( $post_id ) ) {
561 561
             // create action now
562
-            $post_id = $this->save_settings($action);
562
+            $post_id = $this->save_settings( $action );
563 563
         }
564 564
 
565 565
         if ( $post_id && 'update' == $update ) {
566 566
             global $wpdb;
567
-            $form->options = maybe_serialize($form->options);
567
+            $form->options = maybe_serialize( $form->options );
568 568
 
569 569
             // update form options
570 570
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
571
-            wp_cache_delete( $form->id, 'frm_form');
571
+            wp_cache_delete( $form->id, 'frm_form' );
572 572
         }
573 573
 
574 574
         return $post_id;
@@ -592,27 +592,27 @@  discard block
 block discarded – undo
592 592
 				continue;
593 593
 			}
594 594
 
595
-			if ( is_array($condition['hide_opt']) ) {
596
-				$condition['hide_opt'] = reset($condition['hide_opt']);
595
+			if ( is_array( $condition['hide_opt'] ) ) {
596
+				$condition['hide_opt'] = reset( $condition['hide_opt'] );
597 597
 			}
598 598
 
599
-			$observed_value = isset( $entry->metas[ $condition['hide_field'] ] ) ? $entry->metas[ $condition['hide_field'] ] : '';
599
+			$observed_value = isset( $entry->metas[$condition['hide_field']] ) ? $entry->metas[$condition['hide_field']] : '';
600 600
 			if ( $condition['hide_opt'] == 'current_user' ) {
601 601
 				$condition['hide_opt'] = get_current_user_id();
602 602
 			}
603 603
 
604
-			$stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']);
604
+			$stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
605 605
 
606 606
 			if ( $notification['conditions']['send_stop'] == 'send' ) {
607 607
 				$stop = $stop ? false : true;
608 608
 			}
609 609
 
610
-			$met[ $stop ] = $stop;
610
+			$met[$stop] = $stop;
611 611
 		}
612 612
 
613 613
 		if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
614
-			$stop = ($notification['conditions']['send_stop'] == 'send');
615
-		} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) {
614
+			$stop = ( $notification['conditions']['send_stop'] == 'send' );
615
+		} else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
616 616
 			$stop = false;
617 617
 		}
618 618
 
Please login to merge, or discard this patch.