PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / includes / Ajax / TemplateExportImport.php
kirki / includes / Ajax Last commit date
Collaboration 3 weeks ago Apps.php 3 weeks ago Collection.php 1 month ago Comments.php 2 months ago DynamicContent.php 1 month ago ExportImport.php 3 weeks ago Form.php 3 weeks ago Media.php 3 weeks ago Page.php 3 weeks ago PageSettings.php 3 weeks ago RBAC.php 3 weeks ago Symbol.php 3 weeks ago Taxonomy.php 2 months ago TemplateExportImport.php 2 months ago UserData.php 3 weeks ago Users.php 2 months ago Walkthrough.php 2 months ago WordpressData.php 2 months ago WpAdmin.php 2 months ago
TemplateExportImport.php
125 lines
1 <?php
2
3 /**
4 * Manage dynamic form data api calls
5 *
6 * @package kirki
7 */
8
9 namespace Kirki\Ajax;
10
11 use Kirki\ExportImport\TemplateExport;
12 use Kirki\ExportImport\TemplateImport;
13 use Kirki\HelperFunctions;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18 class TemplateExportImport {
19
20
21 public static function export() {
22 $is_assets_with = HelperFunctions::sanitize_text( isset( $_POST['is_assets_with'] ) ? $_POST['is_assets_with'] : false );
23 $is_assets_with = $is_assets_with === 'true' ? true : false;
24
25 $only_published_pages = HelperFunctions::sanitize_text( isset( $_POST['only_published_pages'] ) ? $_POST['only_published_pages'] : true );
26 $only_published_pages = $only_published_pages === 'false' ? false : true;
27
28 $te = new TemplateExport();
29 $d = $te->export( $is_assets_with, $only_published_pages );
30 wp_send_json_success( $d );
31 }
32
33 public static function import() {
34 set_time_limit( 300 );
35 $file = $_FILES['file']; // zip file
36 $upload_dir = wp_upload_dir();
37
38 $file_name = $file['name'];
39 $file_tmp = $file['tmp_name'];
40 $file_error = $file['error'];
41
42 $file_ext = explode( '.', $file_name ); // ['file', 'ext']
43 $file_ext = strtolower( end( $file_ext ) ); // 'ext'
44
45 $allowed = array( 'zip' );
46
47 if ( in_array( $file_ext, $allowed ) ) {
48 if ( $file_error === 0 ) {
49
50 $file_name_new = uniqid( '', true ) . '.' . $file_ext; // 'random.ext'
51 $file_destination = $upload_dir['basedir'] . '/' . $file_name_new;
52
53 global $wp_filesystem;
54 if ( empty( $wp_filesystem ) ) {
55 require_once ABSPATH . 'wp-admin/includes/file.php';
56 WP_Filesystem();
57 }
58
59 if ( $wp_filesystem->move( $file_tmp, $file_destination ) ) {
60
61 $ti = new TemplateImport();
62 $status = $ti->import( $file_destination, true );
63 if ( $status && $status['status'] ) {
64 wp_send_json_success( array( 'queue' => $status['queue'] ) );
65 } else {
66 wp_send_json_error( 'Failed to import template' );
67 }
68 } else {
69 wp_send_json_error( 'Something went wrong' );
70 }
71 } else {
72 wp_send_json_error( 'Zip File upload Failed' );
73 }
74 } else {
75 wp_send_json_error( 'File type not allowed, Upload Kirki Exported Zip file' );
76 }
77 }
78
79
80 public static function import_using_url() {
81 set_time_limit( 300 );
82 $file_url = HelperFunctions::sanitize_text( isset( $_POST['file_url'] ) ? $_POST['file_url'] : '' );
83 $selectedMode = HelperFunctions::sanitize_text( isset( $_POST['selectedMode'] ) ? $_POST['selectedMode'] : 'default' );
84 // Validate the URL to ensure it's a properly formatted and secure URL
85 if ( filter_var( $file_url, FILTER_VALIDATE_URL ) === false ) {
86 wp_send_json_error( 'Invalid file URL', 400 );
87 }
88
89 $ti = new TemplateImport();
90 $status = $ti->import( $file_url, true, $selectedMode );
91 if ( $status && $status['status'] ) {
92 wp_send_json_success(
93 array(
94 'queue' => $status['queue'],
95 'is_template_exits' => isset( $status['is_template_exits'] ) ? $status['is_template_exits'] : false,
96 'template_info' => $status['template_info'],
97 )
98 );
99 } else {
100 wp_send_json_error( 'Failed to import template' );
101 }
102 }
103
104 public static function check_existing_template_data() {
105 $data = HelperFunctions::sanitize_text( isset( $_POST['data'] ) ? $_POST['data'] : '' );
106 $data = json_decode( $data, true );
107
108 $ti = new TemplateImport();
109 $status = $ti->check_existing_template_data( $data );
110 wp_send_json_success( $status );
111 }
112
113 public static function processImport() {
114 $t = new TemplateImport();
115 $res = $t->process();
116 wp_send_json_success( $res );
117 }
118
119 public static function processExport() {
120 $t = new TemplateExport();
121 $res = $t->process();
122 wp_send_json_success( $res );
123 }
124 }
125