PluginProbe
Borderless – Addons and Templates for Elementor / trunk
Borderless – Addons and Templates for Elementor vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / includes / library / inc / Importer.php

Importer.php in Borderless – Addons and Templates for Elementor trunk, at includes/library/inc/Importer.php

114 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LIBRARY;
4
5 class Importer {
6 private $importer;
7 private $microtime;
8 public $logger;
9 private $library;
10 public function __construct( $importer_options = array(), $logger = null ) {
11 $this->include_required_files();
12 $this->importer = new WXRImporter( $importer_options );
13
14 $this->logger = $logger;
15 if ( ! empty( $this->logger ) ) {
16 $this->set_logger( $this->logger );
17 }
18
19 $this->library = BorderlessLibraryImporter::get_instance();
20 }
21
22
23 private function include_required_files() {
24 if ( ! class_exists( '\WP_Importer' ) ) {
25 require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
26 }
27 }
28
29
30 public function import( $data_file ) {
31 $this->importer->import( $data_file );
32 }
33
34
35 public function set_logger( $logger ) {
36 $this->importer->set_logger( $logger );
37 }
38
39
40 public function get_importer_data() {
41 return $this->importer->get_importer_data();
42 }
43
44
45 public function set_importer_data( $data ) {
46 $this->importer->set_importer_data( $data );
47 }
48
49
50 public function import_content( $import_file_path ) {
51 $this->microtime = microtime( true );
52
53 if ( strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) === false ) {
54 set_time_limit( Helpers::apply_filters( 'library/set_time_limit_for_demo_data_import', 300 ) );
55 }
56
57 add_filter( 'wxr_importer.pre_process.user', '__return_false' );
58
59 add_filter( 'wxr_importer.pre_process.post', array( $this, 'new_ajax_request_maybe' ) );
60
61 if ( ! Helpers::apply_filters( 'library/regenerate_thumbnails_in_content_import', true ) ) {
62 add_filter( 'intermediate_image_sizes_advanced', '__return_null' );
63 }
64
65 if ( ! empty( $import_file_path ) ) {
66 ob_start();
67 $this->import( $import_file_path );
68 $message = ob_get_clean();
69 }
70
71 return $this->logger->error_output;
72 }
73
74
75 public function new_ajax_request_maybe( $data ) {
76 $time = microtime( true ) - $this->microtime;
77
78 if ( $time > Helpers::apply_filters( 'library/time_for_one_ajax_call', 25 ) ) {
79 $response = array(
80 'status' => 'newAJAX',
81 'message' => 'Time for new AJAX request!: ' . $time,
82 );
83
84 $message = ob_get_clean();
85
86 if ( ! empty( $message ) ) {
87 $this->library->append_to_frontend_error_messages( $message );
88 }
89
90 $log_added = Helpers::append_to_file(
91 __( 'New AJAX call!' , 'borderless' ) . PHP_EOL . $message,
92 $this->library->get_log_file_path(),
93 ''
94 );
95
96 $this->set_current_importer_data();
97
98 wp_send_json( $response );
99 }
100
101 $current_user_obj = wp_get_current_user();
102 $data['post_author'] = $current_user_obj->user_login;
103
104 return $data;
105 }
106
107
108 private function set_current_importer_data() {
109 $data = array_merge( $this->library->get_current_importer_data(), $this->get_importer_data() );
110
111 Helpers::set_library_import_data_transient( $data );
112 }
113 }
114