Completed
Push — develop ( 87b48c...882b48 )
by Gennady
23:47 queued 03:49
created
includes/extensions/duplicate-entry/class-duplicate-entry.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	public static function get_duplicate_link( $entry, $view_id, $post_id = null ) {
261 261
 		self::getInstance()->set_entry( $entry );
262 262
 
263
-        $base = GravityView_API::directory_link( $post_id ? : $view_id, true );
263
+		$base = GravityView_API::directory_link( $post_id ? : $view_id, true );
264 264
 
265 265
 		if ( empty( $base ) ) {
266 266
 			gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) );
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			'action'	=> 'duplicate',
272 272
 			'entry_id'	=> $entry['id'],
273 273
 			'gvid' => $view_id,
274
-            'view_id' => $view_id,
274
+			'view_id' => $view_id,
275 275
 		), $base );
276 276
 
277 277
 		return add_query_arg( 'duplicate', wp_create_nonce( self::get_nonce_key( $entry['id'] ) ), $actionurl );
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		 * @since 2.5
471 471
 		 * @param  array $duplicated_entry The duplicated entry
472 472
 		 * @param  array $entry The original entry
473
-		*/
473
+		 */
474 474
 		do_action( 'gravityview/duplicate-entry/duplicated', $duplicated_entry, $entry );
475 475
 
476 476
 		gravityview()->log->debug( 'Duplicate response: {duplicate_response}', array( 'duplicate_response' => $duplicate_response ) );
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 	public function duplicate_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
115 115
 
116 116
 		// Always a link, never a filter
117
-		unset( $field_options['show_as_link'], $field_options['search_filter'] );
117
+		unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] );
118 118
 
119 119
 
120 120
 		// Duplicate Entry link should only appear to visitors capable of editing entries
121
-		unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] );
121
+		unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] );
122 122
 
123
-		$add_option['duplicate_link'] = array(
123
+		$add_option[ 'duplicate_link' ] = array(
124 124
 			'type' => 'text',
125 125
 			'label' => __( 'Duplicate Link Text', 'gravityview' ),
126 126
 			'desc' => NULL,
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			'merge_tags' => true,
129 129
 		);
130 130
 
131
-		$field_options['allow_duplicate_cap'] = array(
131
+		$field_options[ 'allow_duplicate_cap' ] = array(
132 132
 			'type' => 'select',
133 133
 			'label' => __( 'Allow the following users to duplicate the entry:', 'gravityview' ),
134 134
 			'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ),
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	public function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) {
156 156
 
157 157
 		if ( 'edit' !== $zone ) {
158
-			$entry_default_fields['duplicate_link'] = array(
158
+			$entry_default_fields[ 'duplicate_link' ] = array(
159 159
 				'label' => __( 'Duplicate Entry', 'gravityview' ),
160 160
 				'type'  => 'duplicate_link',
161 161
 				'desc'  => __( 'A link to duplicate the entry. Respects the Duplicate Entry permissions.', 'gravityview' ),
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function add_available_field( $available_fields = array() ) {
178 178
 
179
-		$available_fields['duplicate_link'] = array(
179
+		$available_fields[ 'duplicate_link' ] = array(
180 180
 			'label_text' => __( 'Duplicate Entry', 'gravityview' ),
181 181
 			'field_id' => 'duplicate_link',
182 182
 			'label_type' => 'field',
@@ -209,9 +209,9 @@  discard block
 block discarded – undo
209 209
 		if ( 'duplicate_link' === $field_id ) {
210 210
 
211 211
 			// Remove other built-in caps.
212
-			unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['duplicate_others_posts'] );
212
+			unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'duplicate_others_posts' ] );
213 213
 
214
-			$caps['read'] = _x( 'Entry Creator', 'User capability', 'gravityview' );
214
+			$caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' );
215 215
 		}
216 216
 
217 217
 		return $caps;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	public static function get_duplicate_link( $entry, $view_id, $post_id = null ) {
261 261
 		self::getInstance()->set_entry( $entry );
262 262
 
263
-        $base = GravityView_API::directory_link( $post_id ? : $view_id, true );
263
+        $base = GravityView_API::directory_link( $post_id ?: $view_id, true );
264 264
 
265 265
 		if ( empty( $base ) ) {
266 266
 			gravityview()->log->error( 'Post ID does not exist: {post_id}', array( 'post_id' => $post_id ) );
@@ -269,12 +269,12 @@  discard block
 block discarded – undo
269 269
 
270 270
 		$actionurl = add_query_arg( array(
271 271
 			'action'	=> 'duplicate',
272
-			'entry_id'	=> $entry['id'],
272
+			'entry_id'	=> $entry[ 'id' ],
273 273
 			'gvid' => $view_id,
274 274
             'view_id' => $view_id,
275 275
 		), $base );
276 276
 
277
-		return add_query_arg( 'duplicate', wp_create_nonce( self::get_nonce_key( $entry['id'] ) ), $actionurl );
277
+		return add_query_arg( 'duplicate', wp_create_nonce( self::get_nonce_key( $entry[ 'id' ] ) ), $actionurl );
278 278
 	}
279 279
 
280 280
 	/**
@@ -295,12 +295,12 @@  discard block
 block discarded – undo
295 295
 	public function process_duplicate() {
296 296
 
297 297
 		// If the form is submitted
298
-		if ( ! isset( $_GET['action'] ) || 'duplicate' !== $_GET['action'] || ! isset( $_GET['entry_id'] ) ) {
298
+		if ( ! isset( $_GET[ 'action' ] ) || 'duplicate' !== $_GET[ 'action' ] || ! isset( $_GET[ 'entry_id' ] ) ) {
299 299
 			return;
300 300
 		}
301 301
 
302 302
 		// Make sure it's a GravityView request
303
-		$valid_nonce_key = wp_verify_nonce( $_GET['duplicate'], self::get_nonce_key( $_GET['entry_id'] ) );
303
+		$valid_nonce_key = wp_verify_nonce( $_GET[ 'duplicate' ], self::get_nonce_key( $_GET[ 'entry_id' ] ) );
304 304
 
305 305
 		if ( ! $valid_nonce_key ) {
306 306
 			gravityview()->log->debug( 'Duplicate entry not processed: nonce validation failed.' );
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 		}
309 309
 
310 310
 		// Get the entry slug
311
-		$entry_slug = esc_attr( $_GET['entry_id'] );
311
+		$entry_slug = esc_attr( $_GET[ 'entry_id' ] );
312 312
 
313 313
 		// See if there's an entry there
314 314
 		$entry = gravityview_get_entry( $entry_slug, true, false );
@@ -398,15 +398,15 @@  discard block
 block discarded – undo
398 398
 			return new WP_Error( 'gravityview-duplicate-entry-missing', __( 'The entry does not exist.', 'gravityview' ) );
399 399
 		}
400 400
 
401
-		$row['id'] = null;
402
-		$row['date_created'] = date( 'Y-m-d H:i:s', time() );
403
-		$row['date_updated'] = $row['date_created'];
404
-		$row['is_starred'] = false;
405
-		$row['is_read'] = false;
406
-		$row['ip'] = GFFormsModel::get_ip();
407
-		$row['source_url'] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) );
408
-		$row['user_agent'] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' );
409
-		$row['created_by'] = wp_get_current_user()->ID;
401
+		$row[ 'id' ] = null;
402
+		$row[ 'date_created' ] = date( 'Y-m-d H:i:s', time() );
403
+		$row[ 'date_updated' ] = $row[ 'date_created' ];
404
+		$row[ 'is_starred' ] = false;
405
+		$row[ 'is_read' ] = false;
406
+		$row[ 'ip' ] = GFFormsModel::get_ip();
407
+		$row[ 'source_url' ] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) );
408
+		$row[ 'user_agent' ] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' );
409
+		$row[ 'created_by' ] = wp_get_current_user()->ID;
410 410
 
411 411
 		/**
412 412
 		 * @filter `gravityview/entry/duplicate/details` Modify the new entry details before it's created.
@@ -434,15 +434,15 @@  discard block
 block discarded – undo
434 434
 
435 435
 		$save_this_meta = array();
436 436
 		foreach ( $duplicate_meta->get_output() as $m ) {
437
-			$save_this_meta[] = array(
438
-				'meta_key' => $m['meta_key'],
439
-				'meta_value' => $m['meta_value'],
440
-				'item_index' => $m['item_index'],
437
+			$save_this_meta[ ] = array(
438
+				'meta_key' => $m[ 'meta_key' ],
439
+				'meta_value' => $m[ 'meta_value' ],
440
+				'item_index' => $m[ 'item_index' ],
441 441
 			);
442 442
 		}
443 443
 
444 444
 		// Update the row ID for later usage
445
-		$row['id'] = $duplicated_id;
445
+		$row[ 'id' ] = $duplicated_id;
446 446
 
447 447
 		/**
448 448
 		 * @filter `gravityview/entry/duplicate/meta` Modify the new entry meta details.
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 		$save_this_meta = apply_filters( 'gravityview/entry/duplicate/meta', $save_this_meta, $row, $entry );
454 454
 
455 455
 		foreach ( $save_this_meta as $data ) {
456
-			$data['form_id'] = $entry['form_id'];
457
-			$data['entry_id'] = $duplicated_id;
456
+			$data[ 'form_id' ] = $entry[ 'form_id' ];
457
+			$data[ 'entry_id' ] = $duplicated_id;
458 458
 
459 459
 			if ( ! $wpdb->insert( $entry_meta_table, $data ) ) {
460 460
 				return new WP_Error( 'gravityview-duplicate-entry-db-meta', __( 'There was an error duplicating the entry.', 'gravityview' ) );
@@ -488,13 +488,13 @@  discard block
 block discarded – undo
488 488
 	public function verify_nonce() {
489 489
 
490 490
 		// No duplicate entry request was made
491
-		if ( empty( $_GET['entry_id'] ) || empty( $_GET['duplicate'] ) ) {
491
+		if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'duplicate' ] ) ) {
492 492
 			return false;
493 493
 		}
494 494
 
495
-		$nonce_key = self::get_nonce_key( $_GET['entry_id'] );
495
+		$nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] );
496 496
 
497
-		$valid = wp_verify_nonce( $_GET['duplicate'], $nonce_key );
497
+		$valid = wp_verify_nonce( $_GET[ 'duplicate' ], $nonce_key );
498 498
 
499 499
 		/**
500 500
 		 * @filter `gravityview/duplicate-entry/verify_nonce` Override Duplicate Entry nonce validation. Return true to declare nonce valid.
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 		 */
526 526
 		$confirm = apply_filters( 'gravityview/duplicate-entry/confirm-text', $confirm );
527 527
 
528
-		return 'return window.confirm(\''. esc_js( $confirm ) .'\');';
528
+		return 'return window.confirm(\'' . esc_js( $confirm ) . '\');';
529 529
 	}
530 530
 
531 531
 	/**
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 	public static function check_user_cap_duplicate_entry( $entry, $field, $view_id ) {
580 580
 		$current_user = wp_get_current_user();
581 581
 
582
-		$entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL;
582
+		$entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL;
583 583
 
584 584
 		// Or if they can duplicate any entries (as defined in Gravity Forms), we're good.
585 585
 		if ( GVCommon::has_cap( array( 'gravityforms_edit_entries' ), $entry_id ) ) {
@@ -594,17 +594,17 @@  discard block
 block discarded – undo
594 594
 		if ( ! empty( $field ) ) {
595 595
 
596 596
 			// If capability is not defined, something is not right!
597
-			if ( empty( $field['allow_duplicate_cap'] ) ) {
597
+			if ( empty( $field[ 'allow_duplicate_cap' ] ) ) {
598 598
 
599 599
 				gravityview()->log->error( 'Cannot read duplicate entry field caps', array( 'data' => $field ) );
600 600
 
601 601
 				return false;
602 602
 			}
603 603
 
604
-			if ( GVCommon::has_cap( $field['allow_duplicate_cap'] ) ) {
604
+			if ( GVCommon::has_cap( $field[ 'allow_duplicate_cap' ] ) ) {
605 605
 
606 606
 				// Do not return true if cap is read, as we need to check if the current user created the entry
607
-				if ( 'read' !== $field['allow_duplicate_cap'] ) {
607
+				if ( 'read' !== $field[ 'allow_duplicate_cap' ] ) {
608 608
 					return true;
609 609
 				}
610 610
 
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 
618 618
 		}
619 619
 
620
-		if ( ! isset( $entry['created_by'] ) ) {
620
+		if ( ! isset( $entry[ 'created_by' ] ) ) {
621 621
 
622 622
 			gravityview()->log->error( 'Cannot duplicate entry; entry `created_by` doesn\'t exist.' );
623 623
 
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 
630 630
 			$current_view = gravityview_get_current_view_data( $view_id );
631 631
 
632
-			$user_duplicate = isset( $current_view['atts']['user_duplicate'] ) ? $current_view['atts']['user_duplicate'] : false;
632
+			$user_duplicate = isset( $current_view[ 'atts' ][ 'user_duplicate' ] ) ? $current_view[ 'atts' ][ 'user_duplicate' ] : false;
633 633
 
634 634
 			if ( empty( $user_duplicate ) ) {
635 635
 
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 		}
641 641
 
642 642
 		// If the logged-in user is the same as the user who created the entry, we're good.
643
-		if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) {
643
+		if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) {
644 644
 
645 645
 			gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id' => $current_user->ID ) );
646 646
 
@@ -665,16 +665,16 @@  discard block
 block discarded – undo
665 665
 	 */
666 666
 	public function display_message( $current_view_id = 0 ) {
667 667
 
668
-		if ( empty( $_GET['status'] ) || ! self::verify_nonce() ) {
668
+		if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) {
669 669
 			return;
670 670
 		}
671 671
 
672 672
 		// Entry wasn't duplicateded from current View
673
-		if ( isset( $_GET['view_id'] ) && ( intval( $_GET['view_id'] ) !== intval( $current_view_id ) ) ) {
673
+		if ( isset( $_GET[ 'view_id' ] ) && ( intval( $_GET[ 'view_id' ] ) !== intval( $current_view_id ) ) ) {
674 674
 			return;
675 675
 		}
676 676
 
677
-		$status = esc_attr( $_GET['status'] );
677
+		$status = esc_attr( $_GET[ 'status' ] );
678 678
 		$message_from_url = \GV\Utils::_GET( 'message' );
679 679
 		$message_from_url = rawurldecode( stripslashes_deep( $message_from_url ) );
680 680
 		$class = '';
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 		$message = apply_filters( 'gravityview/duplicate-entry/message', esc_attr( $message ), $status, $message_from_url );
701 701
 
702 702
 		// DISPLAY ERROR/SUCCESS MESSAGE
703
-		echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>';
703
+		echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>';
704 704
 	}
705 705
 
706 706
 
Please login to merge, or discard this patch.