PluginProbe
Snippet Shortcodes / 4.1.4
Snippet Shortcodes v4.1.4
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / pages / page.import.php

page.import.php in Snippet Shortcodes 4.1.4, at includes/pages/page.import.php

126 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die('Naw ya dinnie!');
4
5 function sh_cd_admin_page_import() {
6
7 sh_cd_permission_check();
8
9 wp_enqueue_media();
10
11 $importing = false;
12 $output = '';
13
14 if ( true === SH_CD_IS_PREMIUM &&
15 false === empty( $_POST[ 'attachment-id' ] ) ){
16
17 $importing = true;
18 $dry_run = ( false === empty( $_POST[ 'dry-run' ] ) );
19 $output = sh_cd_import_csv( $_POST[ 'attachment-id' ], $dry_run );
20 }
21
22 ?>
23 <div class="wrap sh-cd-csv-import ws-ls-admin-page">
24 <div id="poststuff">
25 <div id="post-body" class="metabox-holder">
26 <div id="post-body-content">
27 <div class="meta-box-sortables ui-sortable">
28 <?php
29 if ( false === SH_CD_IS_PREMIUM ) {
30 sh_cd_display_pro_upgrade_notice();
31 }
32 ?>
33 <div class="postbox">
34 <h2 class="hndle"><?php echo __( 'Import CSV', SH_CD_SLUG ); ?></h2>
35 <div class="inside">
36 <?php if ( false === $importing ): ?>
37 <div class="sh-cd-form-row">
38 <p>
39 <?php echo __( 'Please select a CSV file to import one or shortcodes into your collection.', SH_CD_SLUG ); ?>
40 <a href="https://snippet-shortcodes.yeken.uk/csv-import.html" rel="noopener noreferrer" target="_blank"><?php echo __( 'Read more about CSV imports and the required format', SH_CD_SLUG ); ?>.</a>
41 </p>
42 <input id="select_csv" type="button" class="button" value="<?php echo __( 'Select CSV file', SH_CD_SLUG ); ?>" />
43 <br />
44 </div>
45 <div class="sh-cd-hide sh-cd-import-selected" id="selected-form" >
46 <form action="<?php echo admin_url( 'admin.php?page=sh-cd-import&mode=import'); ?>" method="post">
47 <div class="sh-cd-form-row">
48 <label for="attachment-path"><?php echo __( 'Selected file:', SH_CD_SLUG ); ?></label>
49 <input type='text' name='attachment-path' id='attachment-path' value='' class="widefat" disabled="disabled" />
50 <input type='hidden' name='attachment-id' id='attachment-id' value='' />
51 </div>
52 <div class="sh-cd-form-row">
53 <input type='checkbox' name='dry-run' id='dry-run' value='yes' />
54 <label for="dry-run"><?php echo __( 'Dry run mode. This will do basic tests on the file without performing an import.', SH_CD_SLUG ); ?></label>
55 </div>
56 <div class="sh-cd-form-row">
57 <input type="submit" class="button button-primary" value="<?php echo __( 'Import CSV', SH_CD_SLUG ); ?>" <?php if ( false === SH_CD_IS_PREMIUM ) { echo 'disabled="disabled"'; } ?> />
58 </div>
59 </form>
60 </div>
61 <?php else: ?>
62 <p><strong><?php echo __( 'Output:', SH_CD_SLUG ); ?></strong></p>
63 <textarea class="widefat" rows="20" cols="100"><?php echo esc_html( $output ); ?></textarea>
64 <?php endif; ?>
65 </div>
66 </div>
67 </div>
68 </div>
69 </div>
70 <br class="clear">
71 </div>
72 <script>
73 jQuery( document ).ready(function ($) {
74
75 // CSV import for
76 let file_frame;
77
78 $( '#select_csv').on('click', function( event ){
79
80 event.preventDefault();
81
82 <?php if ( false === SH_CD_IS_PREMIUM ) : ?>
83 alert( '<?php echo __( "Please upgrade to bulk import shortcodes via CSV.", SH_CD_SLUG ); ?>' );
84 return;
85 <?php else: ?>
86
87 // If the media frame already exists, reopen it.
88 if ( file_frame ) {
89
90 // Open frame
91 file_frame.open();
92 return;
93 }
94
95 // Create the media frame.
96 file_frame = wp.media.frames.file_frame = wp.media({
97 title: '<?php echo __( "Select a CSV", SH_CD_SLUG ); ?>',
98 button: {
99 text: '<?php echo __( "Use this file", SH_CD_SLUG ); ?>',
100 },
101 library : {
102 type : ['application/csv', 'text/csv'],
103 },
104 multiple: false
105 });
106
107 // When an image is selected, run a callback.
108 file_frame.on( 'select', function() {
109
110 attachment = file_frame.state().get('selection').first().toJSON();
111
112 $( '#attachment-id' ).val( attachment.id );
113 $( '#attachment-path' ).val( attachment.url );
114 $( '#selected-form' ).removeClass( 'sh-cd-hide' );
115
116 });
117
118 file_frame.open();
119
120 <?php endif; ?>
121 });
122 });
123 </script>
124 <?php
125 }
126