Completed
Push — develop ( d4082e...23f066 )
by Gennady
24:27 queued 17:56
created
includes/extensions/edit-entry/class-edit-entry-render.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 
95 95
 	/**
96 96
 	 * ID of the current post. May also be ID of the current View.
97
-     *
98
-     * @since 2.0.13
99
-     * 
100
-     * @var int
97
+	 *
98
+	 * @since 2.0.13
99
+	 * 
100
+	 * @var int
101 101
 	 */
102 102
 	public $post_id;
103 103
 
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
 	public function prevent_maybe_process_form() {
170 170
 
171 171
 		if( ! empty( $_POST ) ) {
172
-	        gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
172
+			gravityview()->log->debug( 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', array( 'data' => esc_html( print_r( $_POST, true ) ) ) );
173 173
 		}
174 174
 
175 175
 		if( $this->is_edit_entry_submission() ) {
176 176
 			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
-	        remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
177
+			remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
178 178
 		}
179 179
 	}
180 180
 
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 	 * When Edit entry view is requested setup the vars
203 203
 	 */
204 204
 	private function setup_vars() {
205
-        global $post;
205
+		global $post;
206 206
 
207 207
 		$gravityview_view = GravityView_View::getInstance();
208 208
 
209 209
 
210 210
 		$entries = $gravityview_view->getEntries();
211
-	    self::$original_entry = $entries[0];
212
-	    $this->entry = $entries[0];
211
+		self::$original_entry = $entries[0];
212
+		$this->entry = $entries[0];
213 213
 
214 214
 		self::$original_form = $gravityview_view->getForm();
215 215
 		$this->form = $gravityview_view->getForm();
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 
334 334
 			GFFormsModel::save_lead( $form, $this->entry );
335 335
 
336
-	        // Delete the values for hidden inputs
337
-	        $this->unset_hidden_field_values();
336
+			// Delete the values for hidden inputs
337
+			$this->unset_hidden_field_values();
338 338
 			
339 339
 			$this->entry['date_created'] = $date_created;
340 340
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 			// Perform actions normally performed after updating a lead
345 345
 			$this->after_update();
346 346
 
347
-	        /**
347
+			/**
348 348
 			 * Must be AFTER after_update()!
349 349
 			 * @see https://github.com/gravityview/GravityView/issues/764
350 350
 			 */
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 
353 353
 			/**
354 354
 			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
355
-             * @since 2.1 Added $gv_data parameter
355
+			 * @since 2.1 Added $gv_data parameter
356 356
 			 * @param array $form Gravity Forms form array
357 357
 			 * @param string $entry_id Numeric ID of the entry that was updated
358 358
 			 * @param GravityView_Edit_Entry_Render $this This object
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 	 * @return void
377 377
 	 */
378 378
 	private function unset_hidden_field_values() {
379
-	    global $wpdb;
379
+		global $wpdb;
380 380
 
381 381
 		/**
382 382
 		 * @filter `gravityview/edit_entry/unset_hidden_field_values` Whether to delete values of fields hidden by conditional logic
@@ -398,27 +398,27 @@  discard block
 block discarded – undo
398 398
 			$current_fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) );
399 399
 		}
400 400
 
401
-	    foreach ( $this->entry as $input_id => $field_value ) {
401
+		foreach ( $this->entry as $input_id => $field_value ) {
402 402
 
403
-		    $field = RGFormsModel::get_field( $this->form, $input_id );
403
+			$field = RGFormsModel::get_field( $this->form, $input_id );
404 404
 
405
-		    // Reset fields that are hidden
406
-		    // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
407
-		    if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
405
+			// Reset fields that are hidden
406
+			// Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
407
+			if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
408 408
 
409
-		        // List fields are stored as empty arrays when empty
410
-			    $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
409
+				// List fields are stored as empty arrays when empty
410
+				$empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
411 411
 
412
-			    $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
412
+				$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
413 413
 
414
-			    GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
414
+				GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
415 415
 
416
-			    // Prevent the $_POST values of hidden fields from being used as default values when rendering the form
416
+				// Prevent the $_POST values of hidden fields from being used as default values when rendering the form
417 417
 				// after submission
418
-			    $post_input_id = 'input_' . str_replace( '.', '_', $input_id );
419
-			    $_POST[ $post_input_id ] = '';
420
-		    }
421
-	    }
418
+				$post_input_id = 'input_' . str_replace( '.', '_', $input_id );
419
+				$_POST[ $post_input_id ] = '';
420
+			}
421
+		}
422 422
 	}
423 423
 
424 424
 	/**
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 
513 513
 		$form = $this->form;
514 514
 
515
-	    /** @var GF_Field $field */
515
+		/** @var GF_Field $field */
516 516
 		foreach( $form['fields'] as $k => &$field ) {
517 517
 
518 518
 			/**
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 
529 529
 			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
530 530
 				foreach( $field->inputs as $key => $input ) {
531
-				    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
531
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
532 532
 				}
533 533
 			}
534 534
 		}
@@ -549,13 +549,13 @@  discard block
 block discarded – undo
549 549
 			foreach ( $this->fields_with_calculation as $calc_field ) {
550 550
 				$inputs = $calc_field->get_entry_inputs();
551 551
 				if ( is_array( $inputs ) ) {
552
-				    foreach ( $inputs as $input ) {
553
-				        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
554
-				        $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
555
-				    }
552
+					foreach ( $inputs as $input ) {
553
+						$input_name = 'input_' . str_replace( '.', '_', $input['id'] );
554
+						$entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
555
+					}
556 556
 				} else {
557
-				    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
558
-				    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
557
+					$input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
558
+					$entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
559 559
 				}
560 560
 			}
561 561
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 			$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
604 604
 
605 605
 			$ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
606
-	        $ary = stripslashes_deep( $ary );
606
+			$ary = stripslashes_deep( $ary );
607 607
 			$img_url = \GV\Utils::get( $ary, 0 );
608 608
 
609 609
 			$img_title       = count( $ary ) > 1 ? $ary[1] : '';
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	private function maybe_update_post_fields( $form ) {
677 677
 
678 678
 		if( empty( $this->entry['post_id'] ) ) {
679
-	        gravityview()->log->debug( 'This entry has no post fields. Continuing...' );
679
+			gravityview()->log->debug( 'This entry has no post fields. Continuing...' );
680 680
 			return;
681 681
 		}
682 682
 
@@ -711,51 +711,51 @@  discard block
 block discarded – undo
711 711
 
712 712
 				switch( $field->type ) {
713 713
 
714
-				    case 'post_title':
715
-				        $post_title = $value;
716
-				        if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) {
717
-				            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
718
-				        }
719
-				        $updated_post->post_title = $post_title;
720
-				        $updated_post->post_name  = $post_title;
721
-				        unset( $post_title );
722
-				        break;
723
-
724
-				    case 'post_content':
725
-				        $post_content = $value;
726
-				        if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) {
727
-				            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
728
-				        }
729
-				        $updated_post->post_content = $post_content;
730
-				        unset( $post_content );
731
-				        break;
732
-				    case 'post_excerpt':
733
-				        $updated_post->post_excerpt = $value;
734
-				        break;
735
-				    case 'post_tags':
736
-				        wp_set_post_tags( $post_id, $value, false );
737
-				        break;
738
-				    case 'post_category':
739
-				        break;
740
-				    case 'post_custom_field':
714
+					case 'post_title':
715
+						$post_title = $value;
716
+						if ( \GV\Utils::get( $form, 'postTitleTemplateEnabled' ) ) {
717
+							$post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
718
+						}
719
+						$updated_post->post_title = $post_title;
720
+						$updated_post->post_name  = $post_title;
721
+						unset( $post_title );
722
+						break;
723
+
724
+					case 'post_content':
725
+						$post_content = $value;
726
+						if ( \GV\Utils::get( $form, 'postContentTemplateEnabled' ) ) {
727
+							$post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
728
+						}
729
+						$updated_post->post_content = $post_content;
730
+						unset( $post_content );
731
+						break;
732
+					case 'post_excerpt':
733
+						$updated_post->post_excerpt = $value;
734
+						break;
735
+					case 'post_tags':
736
+						wp_set_post_tags( $post_id, $value, false );
737
+						break;
738
+					case 'post_category':
739
+						break;
740
+					case 'post_custom_field':
741 741
 						if ( is_array( $value ) && ( floatval( $field_id ) !== floatval( $field->id ) ) ) {
742 742
 							$value = $value[ $field_id ];
743 743
 						}
744 744
 
745
-				        if( ! empty( $field->customFieldTemplateEnabled ) ) {
746
-				            $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
747
-				        }
745
+						if( ! empty( $field->customFieldTemplateEnabled ) ) {
746
+							$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
747
+						}
748 748
 
749
-	                    if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
750
-		                    $value = wp_json_encode( $value );
751
-	                    }
749
+						if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
750
+							$value = wp_json_encode( $value );
751
+						}
752 752
 
753
-				        update_post_meta( $post_id, $field->postCustomFieldName, $value );
754
-				        break;
753
+						update_post_meta( $post_id, $field->postCustomFieldName, $value );
754
+						break;
755 755
 
756
-				    case 'post_image':
757
-				        $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
758
-				        break;
756
+					case 'post_image':
757
+						$value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
758
+						break;
759 759
 
760 760
 				}
761 761
 
@@ -800,20 +800,20 @@  discard block
 block discarded – undo
800 800
 	 */
801 801
 	private function is_field_json_encoded( $field ) {
802 802
 
803
-	    $json_encoded = false;
803
+		$json_encoded = false;
804 804
 
805 805
 		$input_type = RGFormsModel::get_input_type( $field );
806 806
 
807
-	    // Only certain custom field types are supported
808
-	    switch( $input_type ) {
809
-		    case 'fileupload':
810
-		    case 'list':
811
-		    case 'multiselect':
812
-			    $json_encoded = true;
813
-			    break;
814
-	    }
807
+		// Only certain custom field types are supported
808
+		switch( $input_type ) {
809
+			case 'fileupload':
810
+			case 'list':
811
+			case 'multiselect':
812
+				$json_encoded = true;
813
+				break;
814
+		}
815 815
 
816
-	    return $json_encoded;
816
+		return $json_encoded;
817 817
 	}
818 818
 
819 819
 	/**
@@ -903,14 +903,14 @@  discard block
 block discarded – undo
903 903
 			?><h2 class="gv-edit-entry-title">
904 904
 				<span><?php
905 905
 
906
-				    /**
907
-				     * @filter `gravityview_edit_entry_title` Modify the edit entry title
908
-				     * @param string $edit_entry_title Modify the "Edit Entry" title
909
-				     * @param GravityView_Edit_Entry_Render $this This object
910
-				     */
911
-				    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
906
+					/**
907
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
908
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
909
+					 * @param GravityView_Edit_Entry_Render $this This object
910
+					 */
911
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
912 912
 
913
-				    echo esc_attr( $edit_entry_title );
913
+					echo esc_attr( $edit_entry_title );
914 914
 			?></span>
915 915
 			</h2>
916 916
 
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 
1020 1020
 		ob_get_clean();
1021 1021
 
1022
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
1022
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
1023 1023
 		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
1024 1024
 		remove_filter( 'gform_disable_view_counter', '__return_true' );
1025 1025
 		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
 
1074 1074
 		// for now we don't support Save and Continue feature.
1075 1075
 		if( ! self::$supports_save_and_continue ) {
1076
-	        unset( $form['save'] );
1076
+			unset( $form['save'] );
1077 1077
 		}
1078 1078
 
1079 1079
 		$form = $this->unselect_default_values( $form );
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 			|| ! empty( $field_content )
1151 1151
 			|| in_array( $field->type, array( 'honeypot' ) )
1152 1152
 		) {
1153
-	        return $field_content;
1153
+			return $field_content;
1154 1154
 		}
1155 1155
 
1156 1156
 		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
@@ -1158,24 +1158,24 @@  discard block
 block discarded – undo
1158 1158
 
1159 1159
 		$field_value = $this->get_field_value( $field );
1160 1160
 
1161
-	    // Prevent any PHP warnings, like undefined index
1162
-	    ob_start();
1161
+		// Prevent any PHP warnings, like undefined index
1162
+		ob_start();
1163 1163
 
1164
-	    $return = null;
1164
+		$return = null;
1165 1165
 
1166 1166
 		/** @var GravityView_Field $gv_field */
1167 1167
 		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1168 1168
 			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1169 1169
 		} else {
1170
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1171
-	    }
1170
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
1171
+		}
1172 1172
 
1173
-	    // If there was output, it's an error
1174
-	    $warnings = ob_get_clean();
1173
+		// If there was output, it's an error
1174
+		$warnings = ob_get_clean();
1175 1175
 
1176
-	    if( !empty( $warnings ) ) {
1177
-		    gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) );
1178
-	    }
1176
+		if( !empty( $warnings ) ) {
1177
+			gravityview()->log->error( '{warning}', array( 'warning' => $warnings, 'data' => $field_value ) );
1178
+		}
1179 1179
 
1180 1180
 		return $return;
1181 1181
 	}
@@ -1210,8 +1210,8 @@  discard block
 block discarded – undo
1210 1210
 				$input_id = strval( $input['id'] );
1211 1211
 				
1212 1212
 				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1213
-				    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1214
-				    $allow_pre_populated = false;
1213
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1214
+					$allow_pre_populated = false;
1215 1215
 				}
1216 1216
 
1217 1217
 			}
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
 			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1236 1236
 				$categories = array();
1237 1237
 				foreach ( explode( ',', $field_value ) as $cat_string ) {
1238
-				    $categories[] = GFCommon::format_post_category( $cat_string, true );
1238
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
1239 1239
 				}
1240 1240
 				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1241 1241
 			}
@@ -1245,25 +1245,25 @@  discard block
 block discarded – undo
1245 1245
 		// if value is empty get the default value if defined
1246 1246
 		$field_value = $field->get_value_default_if_empty( $field_value );
1247 1247
 
1248
-	    /**
1249
-	     * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1250
-	     * @since 1.11
1251
-	     * @since 1.20 Added third param
1252
-	     * @param mixed $field_value field value used to populate the input
1253
-	     * @param object $field Gravity Forms field object ( Class GF_Field )
1254
-	     * @param GravityView_Edit_Entry_Render $this Current object
1255
-	     */
1256
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1257
-
1258
-	    /**
1259
-	     * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1260
-	     * @since 1.17
1261
-	     * @since 1.20 Added third param
1262
-	     * @param mixed $field_value field value used to populate the input
1263
-	     * @param GF_Field $field Gravity Forms field object
1264
-	     * @param GravityView_Edit_Entry_Render $this Current object
1265
-	     */
1266
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1248
+		/**
1249
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1250
+		 * @since 1.11
1251
+		 * @since 1.20 Added third param
1252
+		 * @param mixed $field_value field value used to populate the input
1253
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
1254
+		 * @param GravityView_Edit_Entry_Render $this Current object
1255
+		 */
1256
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1257
+
1258
+		/**
1259
+		 * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1260
+		 * @since 1.17
1261
+		 * @since 1.20 Added third param
1262
+		 * @param mixed $field_value field value used to populate the input
1263
+		 * @param GF_Field $field Gravity Forms field object
1264
+		 * @param GravityView_Edit_Entry_Render $this Current object
1265
+		 */
1266
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1267 1267
 
1268 1268
 		return $field_value;
1269 1269
 	}
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
 			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
1291 1291
 			// expects certain field array items to be set.
1292 1292
 			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1293
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1293
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1294 1294
 			}
1295 1295
 
1296 1296
 			switch( RGFormsModel::get_input_type( $field ) ) {
@@ -1304,61 +1304,61 @@  discard block
 block discarded – undo
1304 1304
 				 */
1305 1305
 				case 'fileupload':
1306 1306
 
1307
-				    // Set the previous value
1308
-				    $entry = $this->get_entry();
1307
+					// Set the previous value
1308
+					$entry = $this->get_entry();
1309 1309
 
1310
-				    $input_name = 'input_'.$field->id;
1311
-				    $form_id = $form['id'];
1310
+					$input_name = 'input_'.$field->id;
1311
+					$form_id = $form['id'];
1312 1312
 
1313
-				    $value = NULL;
1313
+					$value = NULL;
1314 1314
 
1315
-				    // Use the previous entry value as the default.
1316
-				    if( isset( $entry[ $field->id ] ) ) {
1317
-				        $value = $entry[ $field->id ];
1318
-				    }
1315
+					// Use the previous entry value as the default.
1316
+					if( isset( $entry[ $field->id ] ) ) {
1317
+						$value = $entry[ $field->id ];
1318
+					}
1319 1319
 
1320
-				    // If this is a single upload file
1321
-				    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1322
-				        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1323
-				        $value = $file_path['url'];
1320
+					// If this is a single upload file
1321
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1322
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1323
+						$value = $file_path['url'];
1324 1324
 
1325
-				    } else {
1325
+					} else {
1326 1326
 
1327
-				        // Fix PHP warning on line 1498 of form_display.php for post_image fields
1328
-				        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1329
-				        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1327
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
1328
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1329
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1330 1330
 
1331
-				    }
1331
+					}
1332 1332
 
1333
-				    if ( \GV\Utils::get( $field, "multipleFiles" ) ) {
1333
+					if ( \GV\Utils::get( $field, "multipleFiles" ) ) {
1334 1334
 
1335
-				        // If there are fresh uploads, process and merge them.
1336
-				        // Otherwise, use the passed values, which should be json-encoded array of URLs
1337
-				        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1338
-				            $value = empty( $value ) ? '[]' : $value;
1339
-				            $value = stripslashes_deep( $value );
1340
-				            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1341
-				        }
1335
+						// If there are fresh uploads, process and merge them.
1336
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
1337
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1338
+							$value = empty( $value ) ? '[]' : $value;
1339
+							$value = stripslashes_deep( $value );
1340
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1341
+						}
1342 1342
 
1343
-				    } else {
1343
+					} else {
1344 1344
 
1345
-				        // A file already exists when editing an entry
1346
-				        // We set this to solve issue when file upload fields are required.
1347
-				        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1345
+						// A file already exists when editing an entry
1346
+						// We set this to solve issue when file upload fields are required.
1347
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1348 1348
 
1349
-				    }
1349
+					}
1350 1350
 
1351
-				    $this->entry[ $input_name ] = $value;
1352
-				    $_POST[ $input_name ] = $value;
1351
+					$this->entry[ $input_name ] = $value;
1352
+					$_POST[ $input_name ] = $value;
1353 1353
 
1354
-				    break;
1354
+					break;
1355 1355
 
1356 1356
 				case 'number':
1357
-				    // Fix "undefined index" issue at line 1286 in form_display.php
1358
-				    if( !isset( $_POST['input_'.$field->id ] ) ) {
1359
-				        $_POST['input_'.$field->id ] = NULL;
1360
-				    }
1361
-				    break;
1357
+					// Fix "undefined index" issue at line 1286 in form_display.php
1358
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
1359
+						$_POST['input_'.$field->id ] = NULL;
1360
+					}
1361
+					break;
1362 1362
 			}
1363 1363
 
1364 1364
 		}
@@ -1443,42 +1443,42 @@  discard block
 block discarded – undo
1443 1443
 				case 'fileupload' :
1444 1444
 				case 'post_image':
1445 1445
 
1446
-				    // in case nothing is uploaded but there are already files saved
1447
-				    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1448
-				        $field->failed_validation = false;
1449
-				        unset( $field->validation_message );
1450
-				    }
1446
+					// in case nothing is uploaded but there are already files saved
1447
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1448
+						$field->failed_validation = false;
1449
+						unset( $field->validation_message );
1450
+					}
1451 1451
 
1452
-				    // validate if multi file upload reached max number of files [maxFiles] => 2
1453
-				    if( \GV\Utils::get( $field, 'maxFiles') && \GV\Utils::get( $field, 'multipleFiles') ) {
1452
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1453
+					if( \GV\Utils::get( $field, 'maxFiles') && \GV\Utils::get( $field, 'multipleFiles') ) {
1454 1454
 
1455
-				        $input_name = 'input_' . $field->id;
1456
-				        //uploaded
1457
-				        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1455
+						$input_name = 'input_' . $field->id;
1456
+						//uploaded
1457
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1458 1458
 
1459
-				        //existent
1460
-				        $entry = $this->get_entry();
1461
-				        $value = NULL;
1462
-				        if( isset( $entry[ $field->id ] ) ) {
1463
-				            $value = json_decode( $entry[ $field->id ], true );
1464
-				        }
1459
+						//existent
1460
+						$entry = $this->get_entry();
1461
+						$value = NULL;
1462
+						if( isset( $entry[ $field->id ] ) ) {
1463
+							$value = json_decode( $entry[ $field->id ], true );
1464
+						}
1465 1465
 
1466
-				        // count uploaded files and existent entry files
1467
-				        $count_files = count( $file_names ) + count( $value );
1466
+						// count uploaded files and existent entry files
1467
+						$count_files = count( $file_names ) + count( $value );
1468 1468
 
1469
-				        if( $count_files > $field->maxFiles ) {
1470
-				            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1471
-				            $field->failed_validation = 1;
1472
-				            $gv_valid = false;
1469
+						if( $count_files > $field->maxFiles ) {
1470
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1471
+							$field->failed_validation = 1;
1472
+							$gv_valid = false;
1473 1473
 
1474
-				            // in case of error make sure the newest upload files are removed from the upload input
1475
-				            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1476
-				        }
1474
+							// in case of error make sure the newest upload files are removed from the upload input
1475
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1476
+						}
1477 1477
 
1478
-				    }
1478
+					}
1479 1479
 
1480 1480
 
1481
-				    break;
1481
+					break;
1482 1482
 
1483 1483
 			}
1484 1484
 
@@ -1489,47 +1489,47 @@  discard block
 block discarded – undo
1489 1489
 
1490 1490
 				switch ( $field_type ) {
1491 1491
 
1492
-				    // Captchas don't need to be re-entered.
1493
-				    case 'captcha':
1492
+					// Captchas don't need to be re-entered.
1493
+					case 'captcha':
1494 1494
 
1495
-				        // Post Image fields aren't editable, so we un-fail them.
1496
-				    case 'post_image':
1497
-				        $field->failed_validation = false;
1498
-				        unset( $field->validation_message );
1499
-				        break;
1495
+						// Post Image fields aren't editable, so we un-fail them.
1496
+					case 'post_image':
1497
+						$field->failed_validation = false;
1498
+						unset( $field->validation_message );
1499
+						break;
1500 1500
 
1501 1501
 				}
1502 1502
 
1503 1503
 				// You can't continue inside a switch, so we do it after.
1504 1504
 				if( empty( $field->failed_validation ) ) {
1505
-				    continue;
1505
+					continue;
1506 1506
 				}
1507 1507
 
1508 1508
 				// checks if the No Duplicates option is not validating entry against itself, since
1509 1509
 				// we're editing a stored entry, it would also assume it's a duplicate.
1510 1510
 				if( !empty( $field->noDuplicates ) ) {
1511 1511
 
1512
-				    $entry = $this->get_entry();
1512
+					$entry = $this->get_entry();
1513 1513
 
1514
-				    // If the value of the entry is the same as the stored value
1515
-				    // Then we can assume it's not a duplicate, it's the same.
1516
-				    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1517
-				        //if value submitted was not changed, then don't validate
1518
-				        $field->failed_validation = false;
1514
+					// If the value of the entry is the same as the stored value
1515
+					// Then we can assume it's not a duplicate, it's the same.
1516
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1517
+						//if value submitted was not changed, then don't validate
1518
+						$field->failed_validation = false;
1519 1519
 
1520
-				        unset( $field->validation_message );
1520
+						unset( $field->validation_message );
1521 1521
 
1522
-				        gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) );
1522
+						gravityview()->log->debug( 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', array( 'data' => $entry ) );
1523 1523
 
1524
-				        continue;
1525
-				    }
1524
+						continue;
1525
+					}
1526 1526
 				}
1527 1527
 
1528 1528
 				// if here then probably we are facing the validation 'At least one field must be filled out'
1529 1529
 				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1530
-				    unset( $field->validation_message );
1531
-	                $field->validation_message = false;
1532
-				    continue;
1530
+					unset( $field->validation_message );
1531
+					$field->validation_message = false;
1532
+					continue;
1533 1533
 				}
1534 1534
 
1535 1535
 				$gv_valid = false;
@@ -1593,8 +1593,8 @@  discard block
 block discarded – undo
1593 1593
 		// Hide fields depending on admin settings
1594 1594
 		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1595 1595
 
1596
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1597
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1596
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1597
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1598 1598
 
1599 1599
 		/**
1600 1600
 		 * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
@@ -1654,11 +1654,11 @@  discard block
 block discarded – undo
1654 1654
 		// The edit tab has been configured, so we loop through to configured settings
1655 1655
 		foreach ( $configured_fields as $configured_field ) {
1656 1656
 
1657
-	        /** @var GF_Field $field */
1658
-	        foreach ( $fields as $field ) {
1657
+			/** @var GF_Field $field */
1658
+			foreach ( $fields as $field ) {
1659 1659
 				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1660
-				    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1661
-				    break;
1660
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1661
+					break;
1662 1662
 				}
1663 1663
 
1664 1664
 			}
@@ -1714,28 +1714,28 @@  discard block
 block discarded – undo
1714 1714
 	 */
1715 1715
 	private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1716 1716
 
1717
-	    /**
1717
+		/**
1718 1718
 		 * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true
1719
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1720
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1721
-	     * @since 1.9.1
1722
-	     * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions.
1723
-	     * @param array $form GF Form array
1724
-	     * @param int $view_id View ID
1725
-	     */
1726
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1727
-
1728
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1719
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1720
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1721
+		 * @since 1.9.1
1722
+		 * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions.
1723
+		 * @param array $form GF Form array
1724
+		 * @param int $view_id View ID
1725
+		 */
1726
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1727
+
1728
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1729 1729
 			foreach( $fields as $k => $field ) {
1730 1730
 				if( $field->adminOnly ) {
1731
-				    unset( $fields[ $k ] );
1731
+					unset( $fields[ $k ] );
1732 1732
 				}
1733 1733
 			}
1734 1734
 			return $fields;
1735 1735
 		}
1736 1736
 
1737
-	    foreach( $fields as &$field ) {
1738
-		    $field->adminOnly = false;
1737
+		foreach( $fields as &$field ) {
1738
+			$field->adminOnly = false;
1739 1739
 		}
1740 1740
 
1741 1741
 		return $fields;
@@ -1791,36 +1791,36 @@  discard block
 block discarded – undo
1791 1791
 
1792 1792
 			if( 'checkbox' === $field->type ) {
1793 1793
 				foreach ( $field->get_entry_inputs() as $key => $input ) {
1794
-				    $input_id = $input['id'];
1795
-				    $choice = $field->choices[ $key ];
1796
-				    $value = \GV\Utils::get( $this->entry, $input_id );
1797
-				    $match = RGFormsModel::choice_value_match( $field, $choice, $value );
1798
-				    if( $match ) {
1799
-				        $field->choices[ $key ]['isSelected'] = true;
1800
-				    }
1794
+					$input_id = $input['id'];
1795
+					$choice = $field->choices[ $key ];
1796
+					$value = \GV\Utils::get( $this->entry, $input_id );
1797
+					$match = RGFormsModel::choice_value_match( $field, $choice, $value );
1798
+					if( $match ) {
1799
+						$field->choices[ $key ]['isSelected'] = true;
1800
+					}
1801 1801
 				}
1802 1802
 			} else {
1803 1803
 
1804 1804
 				// We need to run through each field to set the default values
1805 1805
 				foreach ( $this->entry as $field_id => $field_value ) {
1806 1806
 
1807
-				    if( floatval( $field_id ) === floatval( $field->id ) ) {
1807
+					if( floatval( $field_id ) === floatval( $field->id ) ) {
1808 1808
 
1809
-				        if( 'list' === $field->type ) {
1810
-				            $list_rows = maybe_unserialize( $field_value );
1809
+						if( 'list' === $field->type ) {
1810
+							$list_rows = maybe_unserialize( $field_value );
1811 1811
 
1812
-				            $list_field_value = array();
1813
-				            foreach ( (array) $list_rows as $row ) {
1814
-				                foreach ( (array) $row as $column ) {
1815
-				                    $list_field_value[] = $column;
1816
-				                }
1817
-				            }
1812
+							$list_field_value = array();
1813
+							foreach ( (array) $list_rows as $row ) {
1814
+								foreach ( (array) $row as $column ) {
1815
+									$list_field_value[] = $column;
1816
+								}
1817
+							}
1818 1818
 
1819
-				            $field->defaultValue = serialize( $list_field_value );
1820
-				        } else {
1821
-				            $field->defaultValue = $field_value;
1822
-				        }
1823
-				    }
1819
+							$field->defaultValue = serialize( $list_field_value );
1820
+						} else {
1821
+							$field->defaultValue = $field_value;
1822
+						}
1823
+					}
1824 1824
 				}
1825 1825
 			}
1826 1826
 		}
@@ -1877,7 +1877,7 @@  discard block
 block discarded – undo
1877 1877
 			return $has_conditional_logic;
1878 1878
 		}
1879 1879
 
1880
-	    /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1880
+		/** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1881 1881
 		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1882 1882
 	}
1883 1883
 
@@ -1944,14 +1944,14 @@  discard block
 block discarded – undo
1944 1944
 
1945 1945
 		if( $echo && $error !== true ) {
1946 1946
 
1947
-	        $error = esc_html( $error );
1947
+			$error = esc_html( $error );
1948 1948
 
1949
-	        /**
1950
-	         * @since 1.9
1951
-	         */
1952
-	        if ( ! empty( $this->entry ) ) {
1953
-		        $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) );
1954
-	        }
1949
+			/**
1950
+			 * @since 1.9
1951
+			 */
1952
+			if ( ! empty( $this->entry ) ) {
1953
+				$error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) );
1954
+			}
1955 1955
 
1956 1956
 			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1957 1957
 		}
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
 
959 959
 			$back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
960 960
 
961
-			if( ! $this->is_valid ){
961
+			if( ! $this->is_valid ) {
962 962
 
963 963
 				// Keeping this compatible with Gravity Forms.
964 964
 				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
@@ -1755,9 +1755,11 @@  discard block
 block discarded – undo
1755 1755
 	 */
1756 1756
 	function unselect_default_values( $form ) {
1757 1757
 		foreach ( $form['fields'] as &$field ) {
1758
-			if ( $field->choices ) foreach ( $field->choices as &$choice ) {
1758
+			if ( $field->choices ) {
1759
+				foreach ( $field->choices as &$choice ) {
1759 1760
 				if ( \GV\Utils::get( $choice, 'isSelected' ) ) {
1760 1761
 					$choice['isSelected'] = false;
1762
+			}
1761 1763
 				}
1762 1764
 			}
1763 1765
 		}
@@ -2032,9 +2034,7 @@  discard block
 block discarded – undo
2032 2034
 		// Verify
2033 2035
 		else if( ! $this->is_edit_entry() ) {
2034 2036
 			$valid = false;
2035
-		}
2036
-
2037
-		else {
2037
+		} else {
2038 2038
 			$valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
2039 2039
 		}
2040 2040
 
Please login to merge, or discard this patch.