|
@@ -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( \GV\Utils::_GET( 'duplicate' ), self::get_nonce_key( $_GET['entry_id'] ) ); |
|
|
303
|
+ $valid_nonce_key = wp_verify_nonce( \GV\Utils::_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 ); |
|
@@ -402,15 +402,15 @@ discard block |
|
|
block discarded – undo |
|
402
|
402
|
return new WP_Error( 'gravityview-duplicate-entry-missing', __( 'The entry does not exist.', 'gravityview' ) ); |
|
403
|
403
|
} |
|
404
|
404
|
|
|
405
|
|
- $row['id'] = null; |
|
406
|
|
- $row['date_created'] = date( 'Y-m-d H:i:s', time() ); |
|
407
|
|
- $row['date_updated'] = $row['date_created']; |
|
408
|
|
- $row['is_starred'] = false; |
|
409
|
|
- $row['is_read'] = false; |
|
410
|
|
- $row['ip'] = GFFormsModel::get_ip(); |
|
411
|
|
- $row['source_url'] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) ); |
|
412
|
|
- $row['user_agent'] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' ); |
|
413
|
|
- $row['created_by'] = wp_get_current_user()->ID; |
|
|
405
|
+ $row[ 'id' ] = null; |
|
|
406
|
+ $row[ 'date_created' ] = date( 'Y-m-d H:i:s', time() ); |
|
|
407
|
+ $row[ 'date_updated' ] = $row[ 'date_created' ]; |
|
|
408
|
+ $row[ 'is_starred' ] = false; |
|
|
409
|
+ $row[ 'is_read' ] = false; |
|
|
410
|
+ $row[ 'ip' ] = GFFormsModel::get_ip(); |
|
|
411
|
+ $row[ 'source_url' ] = esc_url_raw( remove_query_arg( array( 'action', 'gvid' ) ) ); |
|
|
412
|
+ $row[ 'user_agent' ] = \GV\Utils::_SERVER( 'HTTP_USER_AGENT' ); |
|
|
413
|
+ $row[ 'created_by' ] = wp_get_current_user()->ID; |
|
414
|
414
|
|
|
415
|
415
|
/** |
|
416
|
416
|
* @filter `gravityview/entry/duplicate/details` Modify the new entry details before it's created. |
|
@@ -438,15 +438,15 @@ discard block |
|
|
block discarded – undo |
|
438
|
438
|
|
|
439
|
439
|
$save_this_meta = array(); |
|
440
|
440
|
foreach ( $duplicate_meta->get_output() as $m ) { |
|
441
|
|
- $save_this_meta[] = array( |
|
442
|
|
- 'meta_key' => $m['meta_key'], |
|
443
|
|
- 'meta_value' => $m['meta_value'], |
|
444
|
|
- 'item_index' => $m['item_index'], |
|
|
441
|
+ $save_this_meta[ ] = array( |
|
|
442
|
+ 'meta_key' => $m[ 'meta_key' ], |
|
|
443
|
+ 'meta_value' => $m[ 'meta_value' ], |
|
|
444
|
+ 'item_index' => $m[ 'item_index' ], |
|
445
|
445
|
); |
|
446
|
446
|
} |
|
447
|
447
|
|
|
448
|
448
|
// Update the row ID for later usage |
|
449
|
|
- $row['id'] = $duplicated_id; |
|
|
449
|
+ $row[ 'id' ] = $duplicated_id; |
|
450
|
450
|
|
|
451
|
451
|
/** |
|
452
|
452
|
* @filter `gravityview/entry/duplicate/meta` Modify the new entry meta details. |
|
@@ -457,8 +457,8 @@ discard block |
|
|
block discarded – undo |
|
457
|
457
|
$save_this_meta = apply_filters( 'gravityview/entry/duplicate/meta', $save_this_meta, $row, $entry ); |
|
458
|
458
|
|
|
459
|
459
|
foreach ( $save_this_meta as $data ) { |
|
460
|
|
- $data['form_id'] = $entry['form_id']; |
|
461
|
|
- $data['entry_id'] = $duplicated_id; |
|
|
460
|
+ $data[ 'form_id' ] = $entry[ 'form_id' ]; |
|
|
461
|
+ $data[ 'entry_id' ] = $duplicated_id; |
|
462
|
462
|
|
|
463
|
463
|
if ( ! $wpdb->insert( $entry_meta_table, $data ) ) { |
|
464
|
464
|
return new WP_Error( 'gravityview-duplicate-entry-db-meta', __( 'There was an error duplicating the entry.', 'gravityview' ) ); |
|
@@ -492,13 +492,13 @@ discard block |
|
|
block discarded – undo |
|
492
|
492
|
public function verify_nonce() { |
|
493
|
493
|
|
|
494
|
494
|
// No duplicate entry request was made |
|
495
|
|
- if ( empty( $_GET['entry_id'] ) || empty( $_GET['duplicate'] ) ) { |
|
|
495
|
+ if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'duplicate' ] ) ) { |
|
496
|
496
|
return false; |
|
497
|
497
|
} |
|
498
|
498
|
|
|
499
|
|
- $nonce_key = self::get_nonce_key( $_GET['entry_id'] ); |
|
|
499
|
+ $nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] ); |
|
500
|
500
|
|
|
501
|
|
- $valid = wp_verify_nonce( $_GET['duplicate'], $nonce_key ); |
|
|
501
|
+ $valid = wp_verify_nonce( $_GET[ 'duplicate' ], $nonce_key ); |
|
502
|
502
|
|
|
503
|
503
|
/** |
|
504
|
504
|
* @filter `gravityview/duplicate-entry/verify_nonce` Override Duplicate Entry nonce validation. Return true to declare nonce valid. |
|
@@ -529,7 +529,7 @@ discard block |
|
|
block discarded – undo |
|
529
|
529
|
*/ |
|
530
|
530
|
$confirm = apply_filters( 'gravityview/duplicate-entry/confirm-text', $confirm ); |
|
531
|
531
|
|
|
532
|
|
- return 'return window.confirm(\''. esc_js( $confirm ) .'\');'; |
|
|
532
|
+ return 'return window.confirm(\'' . esc_js( $confirm ) . '\');'; |
|
533
|
533
|
} |
|
534
|
534
|
|
|
535
|
535
|
/** |
|
@@ -583,7 +583,7 @@ discard block |
|
|
block discarded – undo |
|
583
|
583
|
public static function check_user_cap_duplicate_entry( $entry, $field, $view_id ) { |
|
584
|
584
|
$current_user = wp_get_current_user(); |
|
585
|
585
|
|
|
586
|
|
- $entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL; |
|
|
586
|
+ $entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL; |
|
587
|
587
|
|
|
588
|
588
|
// Or if they can duplicate any entries (as defined in Gravity Forms), we're good. |
|
589
|
589
|
if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gform_full_access', 'gravityview_full_access' ), $entry_id ) ) { |
|
@@ -598,17 +598,17 @@ discard block |
|
|
block discarded – undo |
|
598
|
598
|
if ( ! empty( $field ) ) { |
|
599
|
599
|
|
|
600
|
600
|
// If capability is not defined, something is not right! |
|
601
|
|
- if ( empty( $field['allow_duplicate_cap'] ) ) { |
|
|
601
|
+ if ( empty( $field[ 'allow_duplicate_cap' ] ) ) { |
|
602
|
602
|
|
|
603
|
603
|
gravityview()->log->error( 'Cannot read duplicate entry field caps', array( 'data' => $field ) ); |
|
604
|
604
|
|
|
605
|
605
|
return false; |
|
606
|
606
|
} |
|
607
|
607
|
|
|
608
|
|
- if ( GVCommon::has_cap( $field['allow_duplicate_cap'] ) ) { |
|
|
608
|
+ if ( GVCommon::has_cap( $field[ 'allow_duplicate_cap' ] ) ) { |
|
609
|
609
|
|
|
610
|
610
|
// Do not return true if cap is read, as we need to check if the current user created the entry |
|
611
|
|
- if ( 'read' !== $field['allow_duplicate_cap'] ) { |
|
|
611
|
+ if ( 'read' !== $field[ 'allow_duplicate_cap' ] ) { |
|
612
|
612
|
return true; |
|
613
|
613
|
} |
|
614
|
614
|
|
|
@@ -621,7 +621,7 @@ discard block |
|
|
block discarded – undo |
|
621
|
621
|
|
|
622
|
622
|
} |
|
623
|
623
|
|
|
624
|
|
- if ( ! isset( $entry['created_by'] ) ) { |
|
|
624
|
+ if ( ! isset( $entry[ 'created_by' ] ) ) { |
|
625
|
625
|
|
|
626
|
626
|
gravityview()->log->error( 'Cannot duplicate entry; entry `created_by` doesn\'t exist.' ); |
|
627
|
627
|
|
|
@@ -646,7 +646,7 @@ discard block |
|
|
block discarded – undo |
|
646
|
646
|
} |
|
647
|
647
|
|
|
648
|
648
|
// If the logged-in user is the same as the user who created the entry, we're good. |
|
649
|
|
- if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
|
649
|
+ if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) { |
|
650
|
650
|
|
|
651
|
651
|
gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id' => $current_user->ID ) ); |
|
652
|
652
|
|
|
@@ -671,16 +671,16 @@ discard block |
|
|
block discarded – undo |
|
671
|
671
|
*/ |
|
672
|
672
|
public function display_message( $current_view_id = 0 ) { |
|
673
|
673
|
|
|
674
|
|
- if ( empty( $_GET['status'] ) || ! self::verify_nonce() ) { |
|
|
674
|
+ if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) { |
|
675
|
675
|
return; |
|
676
|
676
|
} |
|
677
|
677
|
|
|
678
|
678
|
// Entry wasn't duplicateded from current View |
|
679
|
|
- if ( isset( $_GET['view_id'] ) && ( intval( $_GET['view_id'] ) !== intval( $current_view_id ) ) ) { |
|
|
679
|
+ if ( isset( $_GET[ 'view_id' ] ) && ( intval( $_GET[ 'view_id' ] ) !== intval( $current_view_id ) ) ) { |
|
680
|
680
|
return; |
|
681
|
681
|
} |
|
682
|
682
|
|
|
683
|
|
- $status = esc_attr( $_GET['status'] ); |
|
|
683
|
+ $status = esc_attr( $_GET[ 'status' ] ); |
|
684
|
684
|
$message_from_url = \GV\Utils::_GET( 'message' ); |
|
685
|
685
|
$message_from_url = rawurldecode( stripslashes_deep( $message_from_url ) ); |
|
686
|
686
|
$class = ''; |
|
@@ -706,7 +706,7 @@ discard block |
|
|
block discarded – undo |
|
706
|
706
|
$message = apply_filters( 'gravityview/duplicate-entry/message', esc_attr( $message ), $status, $message_from_url ); |
|
707
|
707
|
|
|
708
|
708
|
// DISPLAY ERROR/SUCCESS MESSAGE |
|
709
|
|
- echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>'; |
|
|
709
|
+ echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>'; |
|
710
|
710
|
} |
|
711
|
711
|
|
|
712
|
712
|
|