PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.3
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / admin / class-evf-admin-import-export.php
everest-forms / includes / admin Last commit date
builder 6 years ago plugin-updates 8 years ago settings 6 years ago views 6 years ago class-evf-admin-addons.php 6 years ago class-evf-admin-assets.php 6 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-editor.php 6 years ago class-evf-admin-entries-table-list.php 6 years ago class-evf-admin-entries.php 6 years ago class-evf-admin-forms-table-list.php 6 years ago class-evf-admin-forms.php 6 years ago class-evf-admin-import-export.php 6 years ago class-evf-admin-menus.php 6 years ago class-evf-admin-notices.php 6 years ago class-evf-admin-settings.php 6 years ago class-evf-admin-tools.php 6 years ago class-evf-admin-welcome.php 6 years ago class-evf-admin.php 6 years ago evf-admin-functions.php 6 years ago
class-evf-admin-import-export.php
161 lines
1 <?php
2 /**
3 * EverestForms Import Export Class
4 *
5 * @package EverestForms\Admin
6 * @since 1.6.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Admin_Forms class.
13 */
14 class EVF_Admin_Import_Export {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 add_action( 'admin_init', array( $this, 'export_json' ) );
21 }
22
23 /**
24 * Exports form data along with settings in JSON format.
25 */
26 public function export_json() {
27 // Check for non empty $_POST.
28 if ( ! isset( $_POST['everest-forms-export-form'] ) || ! isset( $_POST['everest-forms-export-nonce'] ) ) {
29 return;
30 }
31
32 // Nonce check.
33 if ( ! wp_verify_nonce( wp_unslash( $_POST['everest-forms-export-nonce'] ), 'everest_forms_export_nonce' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
34 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'everest-forms' ) );
35 }
36
37 $form_id = isset( $_POST['form_id'] ) ? absint( wp_unslash( $_POST['form_id'] ) ) : 0;
38
39 // Return if form id is not set and current user doesnot have export capability.
40 if ( empty( $form_id ) || ! current_user_can( 'export' ) ) {
41 return;
42 }
43
44 $form_post = get_post( $form_id );
45 $export_data = array(
46 'form_post' => array(
47 'post_content' => $form_post->post_content,
48 'post_title' => $form_post->post_title,
49 'post_name' => $form_post->post_name,
50 'post_type' => $form_post->post_type,
51 'post_status' => $form_post->post_status,
52 ),
53 );
54 $form_name = strtolower( str_replace( ' ', '-', get_the_title( $form_id ) ) );
55 $file_name = html_entity_decode( $form_name, ENT_QUOTES, 'UTF-8' ) . '-' . current_time( 'Y-m-d_H:i:s' ) . '.json';
56
57 if ( ob_get_contents() ) {
58 ob_clean();
59 }
60
61 $export_json = wp_json_encode( $export_data );
62 // Force download.
63 header( 'Content-Type: application/force-download' );
64 // Disposition / Encoding on response body.
65 header( "Content-Disposition: attachment;filename={$file_name}; charset=utf-8" );
66 header( 'Content-type: application/json' );
67 echo $export_json; // phpcs:ignore WordPress.Security.EscapeOutput
68 exit();
69 }
70
71 /**
72 * Import Form from backend.
73 */
74 public static function import_form() {
75 // Check for $_FILES set or not.
76 if ( isset( $_FILES['jsonfile']['name'], $_FILES['jsonfile']['tmp_name'] ) ) {
77 $filename = esc_html( sanitize_text_field( wp_unslash( $_FILES['jsonfile']['name'] ) ) );
78 $extension = pathinfo( $filename, PATHINFO_EXTENSION );
79
80 // Check for file format.
81 if ( 'json' === $extension ) {
82 $form_data = json_decode( file_get_contents( $_FILES['jsonfile']['tmp_name'] ) ); // @codingStandardsIgnoreLine
83
84 // Check for non-empty JSON file.
85 if ( ! empty( $form_data ) ) {
86 // Check for non-empty post data array.
87 if ( ! empty( $form_data->form_post ) ) {
88 $args = array( 'post_type' => 'everest_form' );
89 $forms = get_posts( $args );
90
91 foreach ( $forms as $key => $form_obj ) {
92 if ( $form_data->form_post->post_title === $form_obj->post_title ) {
93 $form_data->form_post->post_title = $form_data->form_post->post_title . ' (Imported)';
94 break;
95 }
96 }
97
98 // Get the form data.
99 $new_form_data = evf_decode( $form_data->form_post->post_content );
100 $new_form = array(
101 'post_content' => evf_encode( $new_form_data ),
102 'post_status' => $form_data->form_post->post_status,
103 'post_title' => $form_data->form_post->post_title,
104 'post_type' => $form_data->form_post->post_type,
105 );
106 $post_id = wp_insert_post( $new_form );
107
108 // Set new form ID.
109 $new_form_data['id'] = absint( $post_id );
110 $form = array(
111 'ID' => $post_id,
112 'post_content' => evf_encode( $new_form_data ),
113 );
114
115 wp_update_post( $form );
116
117 // Check for any error while inserting.
118 if ( is_wp_error( $post_id ) ) {
119 return $post_id;
120 }
121
122 if ( $post_id ) {
123 wp_send_json_success(
124 array(
125 'message' => esc_html__( 'Imported Successfully.', 'everest-forms' ),
126 )
127 );
128 }
129 } else {
130 wp_send_json_error(
131 array(
132 'message' => esc_html__( 'Invalid file content. Please export file from Everest Forms plugin.', 'everest-forms' ),
133 )
134 );
135 }
136 } else {
137 wp_send_json_error(
138 array(
139 'message' => esc_html__( 'Invalid file content. Please export file from Everest Forms plugin.', 'everest-forms' ),
140 )
141 );
142 }
143 } else {
144 wp_send_json_error(
145 array(
146 'message' => esc_html__( 'Invalid file format. Only JSON File Allowed.', 'everest-forms' ),
147 )
148 );
149 }
150 } else {
151 wp_send_json_error(
152 array(
153 'message' => esc_html__( 'Please select json file to import form data.', 'everest-forms' ),
154 )
155 );
156 }
157 }
158 }
159
160 new EVF_Admin_Import_Export();
161