Completed
Push — master ( 9a1967...f3bb74 )
by Jamie
03:29
created
classes/helpers/FrmFormsHelper.php 1 patch
Spacing   +66 added lines, -66 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,8 +11,8 @@  discard block
 block discarded – undo
11 11
 	}
12 12
 
13 13
 	public static function get_direct_link( $key, $form = false ) {
14
-		$target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form='. $key ) );
15
-        $target_url = apply_filters('frm_direct_link', $target_url, $key, $form);
14
+		$target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) );
15
+        $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form );
16 16
 
17 17
         return $target_url;
18 18
     }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			$query['id !'] = $args['exclude'];
38 38
         }
39 39
 
40
-        $where = apply_filters('frm_forms_dropdown', $query, $field_name);
40
+        $where = apply_filters( 'frm_forms_dropdown', $query, $field_name );
41 41
 		$forms = FrmForm::get_published_forms( $where, 999, $args['inc_children'] );
42 42
 		$add_html = array();
43 43
 		self::add_html_attr( $args['onchange'], 'onchange', $add_html );
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		<?php } ?>
51 51
 		<?php foreach ( $forms as $form ) { ?>
52 52
 			<option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>><?php
53
-				echo ( '' == $form->name ) ? esc_html__( '(no title)', 'formidable' ) : esc_html( FrmAppHelper::truncate( $form->name, 50 ) ) . ( $form->parent_form_id ? esc_html__( ' (child)', 'formidable' ) : '' ) ;
53
+				echo ( '' == $form->name ) ? esc_html__( '(no title)', 'formidable' ) : esc_html( FrmAppHelper::truncate( $form->name, 50 ) ) . ( $form->parent_form_id ? esc_html__( ' (child)', 'formidable' ) : '' );
54 54
 			?></option>
55 55
 		<?php } ?>
56 56
         </select>
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public static function add_html_attr( $class, $param, &$add_html ) {
68 68
 		if ( ! empty( $class ) ) {
69
-			$add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"';
69
+			$add_html[$param] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"';
70 70
 		}
71 71
 	}
72 72
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		$args = array( 'id' => 0, 'form' => 0 );
78 78
 		if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
79 79
 			unset( $args['form'] );
80
-		} else if ( isset( $_GET['form']) && ! isset( $_GET['id'] ) ) {
80
+		} else if ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) {
81 81
 			unset( $args['id'] );
82 82
         }
83 83
 
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
 		if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy_all' ) ) ) {
86 86
             $args['frm_action'] = 'list';
87 87
             $args['form'] = 0;
88
-		} else if ( FrmAppHelper::is_admin_page('formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
88
+		} else if ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
89 89
             $args['frm_action'] = 'edit';
90 90
 		} else if ( isset( $_GET['post'] ) ) {
91 91
             $args['form'] = 0;
92
-            $base = admin_url('edit.php?post_type=frm_display');
92
+            $base = admin_url( 'edit.php?post_type=frm_display' );
93 93
         }
94 94
 
95 95
         ?>
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			        $args['form'] = $form->id;
106 106
 				}
107 107
                 ?>
108
-				<li><a href="<?php echo esc_url( isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)') : FrmAppHelper::truncate( $form->name, 60 ) ); ?></a></li>
108
+				<li><a href="<?php echo esc_url( isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 60 ) ); ?></a></li>
109 109
 			<?php
110 110
 				unset( $form );
111 111
 			} ?>
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
     }
116 116
 
117 117
 	public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
118
-        echo ($sort_col == $col) ? 'sorted' : 'sortable';
119
-        echo ($sort_col == $col && $sort_dir == 'desc') ? ' asc' : ' desc';
118
+        echo ( $sort_col == $col ) ? 'sorted' : 'sortable';
119
+        echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc';
120 120
     }
121 121
 
122 122
 	public static function get_success_message( $atts ) {
@@ -136,37 +136,37 @@  discard block
 block discarded – undo
136 136
             $post_values = $values;
137 137
         } else {
138 138
             $values = array();
139
-            $post_values = isset($_POST) ? $_POST : array();
139
+            $post_values = isset( $_POST ) ? $_POST : array();
140 140
         }
141 141
 
142 142
 		foreach ( array( 'name' => '', 'description' => '' ) as $var => $default ) {
143
-			if ( ! isset( $values[ $var ] ) ) {
144
-				$values[ $var ] = FrmAppHelper::get_param( $var, $default );
143
+			if ( ! isset( $values[$var] ) ) {
144
+				$values[$var] = FrmAppHelper::get_param( $var, $default );
145 145
             }
146 146
         }
147 147
 
148
-        $values['description'] = FrmAppHelper::use_wpautop($values['description']);
148
+        $values['description'] = FrmAppHelper::use_wpautop( $values['description'] );
149 149
 
150 150
 		foreach ( array( 'form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0, 'status' => 'draft', 'parent_form_id' => 0 ) as $var => $default ) {
151
-            if ( ! isset( $values[ $var ] ) ) {
152
-				$values[ $var ] = FrmAppHelper::get_param( $var, $default );
151
+            if ( ! isset( $values[$var] ) ) {
152
+				$values[$var] = FrmAppHelper::get_param( $var, $default );
153 153
             }
154 154
         }
155 155
 
156 156
         if ( ! isset( $values['form_key'] ) ) {
157
-            $values['form_key'] = ($post_values && isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix .'frm_forms', 'form_key');
157
+            $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
158 158
         }
159 159
 
160
-        $values = self::fill_default_opts($values, false, $post_values);
160
+        $values = self::fill_default_opts( $values, false, $post_values );
161 161
 
162
-        if ( $post_values && isset($post_values['options']['custom_style']) ) {
162
+        if ( $post_values && isset( $post_values['options']['custom_style'] ) ) {
163 163
             $values['custom_style'] = $post_values['options']['custom_style'];
164 164
         } else {
165 165
             $frm_settings = FrmAppHelper::get_settings();
166 166
             $values['custom_style'] = ( $frm_settings->load_style != 'none' );
167 167
         }
168 168
 
169
-        return apply_filters('frm_setup_new_form_vars', $values);
169
+        return apply_filters( 'frm_setup_new_form_vars', $values );
170 170
     }
171 171
 
172 172
     /**
@@ -177,42 +177,42 @@  discard block
 block discarded – undo
177 177
 			$post_values = stripslashes_deep( $_POST );
178 178
 		}
179 179
 
180
-        $values['form_key'] = isset($post_values['form_key']) ? $post_values['form_key'] : $record->form_key;
181
-        $values['default_template'] = isset($post_values['default_template']) ? $post_values['default_template'] : $record->default_template;
182
-        $values['is_template'] = isset($post_values['is_template']) ? $post_values['is_template'] : $record->is_template;
180
+        $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
181
+        $values['default_template'] = isset( $post_values['default_template'] ) ? $post_values['default_template'] : $record->default_template;
182
+        $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
183 183
         $values['status'] = $record->status;
184 184
 
185
-        $values = self::fill_default_opts($values, $record, $post_values);
185
+        $values = self::fill_default_opts( $values, $record, $post_values );
186 186
 
187
-        return apply_filters('frm_setup_edit_form_vars', $values);
187
+        return apply_filters( 'frm_setup_edit_form_vars', $values );
188 188
     }
189 189
 
190 190
 	public static function fill_default_opts( $values, $record, $post_values ) {
191 191
 
192 192
         $defaults = self::get_default_opts();
193 193
 		foreach ( $defaults as $var => $default ) {
194
-            if ( is_array($default) ) {
195
-                if ( ! isset( $values[ $var ] ) ) {
196
-					$values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
194
+            if ( is_array( $default ) ) {
195
+                if ( ! isset( $values[$var] ) ) {
196
+					$values[$var] = ( $record && isset( $record->options[$var] ) ) ? $record->options[$var] : array();
197 197
                 }
198 198
 
199 199
                 foreach ( $default as $k => $v ) {
200
-					$values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v);
200
+					$values[$var][$k] = ( $post_values && isset( $post_values[$var][$k] ) ) ? $post_values[$var][$k] : ( ( $record && isset( $record->options[$var] ) && isset( $record->options[$var][$k] ) ) ? $record->options[$var][$k] : $v );
201 201
 
202 202
                     if ( is_array( $v ) ) {
203 203
                         foreach ( $v as $k1 => $v1 ) {
204
-							$values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
204
+							$values[$var][$k][$k1] = ( $post_values && isset( $post_values[$var][$k][$k1] ) ) ? $post_values[$var][$k][$k1] : ( ( $record && isset( $record->options[$var] ) && isset( $record->options[$var][$k] ) && isset( $record->options[$var][$k][$k1] ) ) ? $record->options[$var][$k][$k1] : $v1 );
205 205
                             unset( $k1, $v1 );
206 206
                         }
207 207
                     }
208 208
 
209
-                    unset($k, $v);
209
+                    unset( $k, $v );
210 210
                 }
211 211
             } else {
212
-				$values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
212
+				$values[$var] = ( $post_values && isset( $post_values['options'][$var] ) ) ? $post_values['options'][$var] : ( ( $record && isset( $record->options[$var] ) ) ? $record->options[$var] : $default );
213 213
             }
214 214
 
215
-            unset($var, $default);
215
+            unset( $var, $default );
216 216
         }
217 217
 
218 218
         return $values;
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
             'submit_value' => $frm_settings->submit_value, 'success_action' => 'message',
226 226
             'success_msg' => $frm_settings->success_msg, 'show_form' => 0, 'akismet' => '',
227 227
             'no_save' => 0, 'ajax_load' => 0, 'form_class' => '', 'custom_style' => 1,
228
-            'before_html' => self::get_default_html('before'),
228
+            'before_html' => self::get_default_html( 'before' ),
229 229
             'after_html' => '',
230
-            'submit_html' => self::get_default_html('submit'),
230
+            'submit_html' => self::get_default_html( 'submit' ),
231 231
         );
232 232
     }
233 233
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	public static function fill_form_options( &$options, $values ) {
240 240
 		$defaults = self::get_default_opts();
241 241
 		foreach ( $defaults as $var => $default ) {
242
-			$options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
242
+			$options[$var] = isset( $values['options'][$var] ) ? $values['options'][$var] : $default;
243 243
 			unset( $var, $default );
244 244
 		}
245 245
 	}
@@ -279,21 +279,21 @@  discard block
 block discarded – undo
279 279
     }
280 280
 
281 281
 	public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
282
-        $button = self::replace_shortcodes($html, $form, $submit, $form_action, $values);
283
-        if ( ! strpos($button, '[button_action]') ) {
282
+        $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
283
+        if ( ! strpos( $button, '[button_action]' ) ) {
284 284
             return;
285 285
         }
286 286
 
287
-        $button_parts = explode('[button_action]', $button);
287
+        $button_parts = explode( '[button_action]', $button );
288 288
         echo $button_parts[0];
289 289
         //echo ' id="frm_submit_"';
290 290
 
291
-        $classes = apply_filters('frm_submit_button_class', array(), $form);
292
-        if ( ! empty($classes) ) {
291
+        $classes = apply_filters( 'frm_submit_button_class', array(), $form );
292
+        if ( ! empty( $classes ) ) {
293 293
 			echo ' class="' . esc_attr( implode( ' ', $classes ) ) . '"';
294 294
         }
295 295
 
296
-        do_action('frm_submit_button_action', $form, $form_action);
296
+        do_action( 'frm_submit_button_action', $form, $form_action );
297 297
         echo $button_parts[1];
298 298
     }
299 299
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 		$last_field = false;
315 315
         foreach ( $fields as $field ) {
316 316
 			if ( $prev_order === $field->field_order ) {
317
-				$add_order++;
317
+				$add_order ++;
318 318
 			}
319 319
 
320 320
 			if ( $add_order ) {
@@ -381,21 +381,21 @@  discard block
 block discarded – undo
381 381
             if ( $code == 'form_name' ) {
382 382
                 $replace_with = $form->name;
383 383
             } else if ( $code == 'form_description' ) {
384
-                $replace_with = FrmAppHelper::use_wpautop($form->description);
385
-            } else if ( $code == 'entry_key' && isset($_GET) && isset($_GET['entry']) ) {
384
+                $replace_with = FrmAppHelper::use_wpautop( $form->description );
385
+            } else if ( $code == 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
386 386
                 $replace_with = FrmAppHelper::simple_get( 'entry' );
387 387
             } else {
388 388
                 $replace_with = '';
389 389
             }
390 390
 
391
-            FrmFieldsHelper::remove_inline_conditions( ( FrmAppHelper::is_true($show) && $replace_with != '' ), $code, $replace_with, $html );
391
+            FrmFieldsHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
392 392
         }
393 393
 
394 394
         //replace [form_key]
395
-        $html = str_replace('[form_key]', $form->form_key, $html);
395
+        $html = str_replace( '[form_key]', $form->form_key, $html );
396 396
 
397 397
         //replace [frmurl]
398
-        $html = str_replace('[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html);
398
+        $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
399 399
 
400 400
 		if ( strpos( $html, '[button_label]' ) ) {
401 401
 			add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 			$html = str_replace( '[button_label]', $replace_with, $html );
404 404
         }
405 405
 
406
-        $html = apply_filters('frm_form_replace_shortcodes', $html, $form, $values);
406
+        $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values );
407 407
 
408 408
 		if ( strpos( $html, '[if back_button]' ) ) {
409 409
 			$html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html );
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     }
422 422
 
423 423
 	public static function submit_button_label( $submit ) {
424
-        if ( ! $submit || empty($submit) ) {
424
+        if ( ! $submit || empty( $submit ) ) {
425 425
             $frm_settings = FrmAppHelper::get_settings();
426 426
             $submit = $frm_settings->submit_value;
427 427
         }
@@ -430,11 +430,11 @@  discard block
 block discarded – undo
430 430
     }
431 431
 
432 432
 	public static function get_form_style_class( $form = false ) {
433
-        $style = self::get_form_style($form);
433
+        $style = self::get_form_style( $form );
434 434
         $class = ' with_frm_style';
435 435
 
436
-        if ( empty($style) ) {
437
-            if ( FrmAppHelper::is_admin_page('formidable-entries') ) {
436
+        if ( empty( $style ) ) {
437
+            if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
438 438
                 return $class;
439 439
             } else {
440 440
                 return;
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
         }
443 443
 
444 444
         //If submit button needs to be inline or centered
445
-        if ( is_object($form) ) {
445
+        if ( is_object( $form ) ) {
446 446
 			$form = $form->options;
447 447
 		}
448 448
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 			$class .= ' frm_center_submit';
455 455
 		}
456 456
 
457
-        $class = apply_filters('frm_add_form_style_class', $class, $style);
457
+        $class = apply_filters( 'frm_add_form_style_class', $class, $style );
458 458
 
459 459
         return $class;
460 460
     }
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
     }
543 543
 
544 544
 	public static function edit_form_link( $form_id ) {
545
-        if ( is_object($form_id) ) {
545
+        if ( is_object( $form_id ) ) {
546 546
             $form = $form_id;
547 547
             $name = $form->name;
548 548
             $form_id = $form->id;
549 549
         } else {
550
-            $name = FrmForm::getName($form_id);
550
+            $name = FrmForm::getName( $form_id );
551 551
         }
552 552
 
553 553
         if ( $form_id ) {
@@ -577,14 +577,14 @@  discard block
 block discarded – undo
577 577
         );
578 578
 
579 579
         $current_page = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : '';
580
-        $base_url = '?page=formidable&form_type='. $current_page .'&id='. $id;
580
+        $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
581 581
         if ( 'trash' == $status ) {
582
-			$link = '<a href="'. esc_url( wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . $id ) ) . '" class="submitdelete deletion">' . $labels['restore'][ $length ] . '</a>';
583
-        } else if ( current_user_can('frm_delete_forms') ) {
582
+			$link = '<a href="' . esc_url( wp_nonce_url( $base_url . '&frm_action=untrash', 'untrash_form_' . $id ) ) . '" class="submitdelete deletion">' . $labels['restore'][$length] . '</a>';
583
+        } else if ( current_user_can( 'frm_delete_forms' ) ) {
584 584
             if ( EMPTY_TRASH_DAYS ) {
585
-				$link = '<a href="' . esc_url( wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . $id ) ) . '" class="submitdelete deletion">' . $labels['trash'][ $length ] . '</a>';
585
+				$link = '<a href="' . esc_url( wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . $id ) ) . '" class="submitdelete deletion">' . $labels['trash'][$length] . '</a>';
586 586
             } else {
587
-				$link = '<a href="' . esc_url( wp_nonce_url( $base_url .'&frm_action=destroy', 'destroy_form_' . $id ) ) . '" class="submitdelete deletion" onclick="return confirm(\'' . esc_attr( __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ) ) . '\')">' . $labels['delete'][ $length ] . '</a>';
587
+				$link = '<a href="' . esc_url( wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . $id ) ) . '" class="submitdelete deletion" onclick="return confirm(\'' . esc_attr( __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ) ) . '\')">' . $labels['delete'][$length] . '</a>';
588 588
             }
589 589
         }
590 590
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
             'publish'   => __( 'Published', 'formidable' ),
599 599
         );
600 600
 
601
-        if ( ! in_array($status, array_keys($nice_names)) ) {
601
+        if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
602 602
             $status = 'publish';
603 603
         }
604 604
 
605
-		$name = $nice_names[ $status ];
605
+		$name = $nice_names[$status];
606 606
 
607 607
         return $name;
608 608
     }
Please login to merge, or discard this patch.