PluginProbe ʕ •ᴥ•ʔ
Advanced Import / 1.3.6
Advanced Import v1.3.6
trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 2.0.0
advanced-import / admin / class-elementor-import.php
advanced-import / admin Last commit date
class-advanced-import-admin.php 4 years ago class-advanced-import-tracking.php 4 years ago class-elementor-import.php 4 years ago class-reset.php 4 years ago index.php 4 years ago
class-elementor-import.php
245 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 /**
7 * The elementor import functionality of the plugin.
8 *
9 * @package Advanced_Import
10 * @subpackage Advanced_Import/admin/Advanced_Import_Elementor
11 * @author Addons Press <addonspress.com>
12 */
13 if ( ! class_exists( 'Advanced_Import_Elementor' ) ) {
14 /**
15 * Advanced_Import_Elementor
16 */
17 class Advanced_Import_Elementor {
18 /**
19 * Main Advanced_Import_Elementor Instance
20 * Initialize the class and set its properties.
21 *
22 * @since 1.0.0
23 * @return object $instance Advanced_Import_Elementor Instance
24 */
25 public static function instance() {
26
27 // Store the instance locally to avoid private static replication.
28 static $instance = null;
29
30 // Only run these methods if they haven't been ran previously.
31 if ( null === $instance ) {
32 $instance = new self();
33 }
34
35 // Always return the instance.
36 return $instance;
37 }
38
39 /**
40 * Change post id related to elementor to new id
41 *
42 * @param array $item current array of demo list.
43 * @param string $key
44 * @return void
45 */
46 public function elementor_id_import( &$item, $key ) {
47 if ( $key == 'id' && ! empty( $item ) && is_numeric( $item ) ) {
48 // check if this has been imported before
49 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
50 if ( $new_meta_val ) {
51 $item = $new_meta_val;
52 }
53 }
54 if ( $key == 'page' && ! empty( $item ) ) {
55
56 if ( false !== strpos( $item, 'p.' ) ) {
57 $new_id = str_replace( 'p.', '', $item );
58 // check if this has been imported before
59 $new_meta_val = advanced_import_admin()->imported_post_id( $new_id );
60 if ( $new_meta_val ) {
61 $item = 'p.' . $new_meta_val;
62 }
63 } elseif ( is_numeric( $item ) ) {
64 // check if this has been imported before
65 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
66 if ( $new_meta_val ) {
67 $item = $new_meta_val;
68 }
69 }
70 }
71 if ( $key == 'post_id' && ! empty( $item ) && is_numeric( $item ) ) {
72 // check if this has been imported before
73 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
74 if ( $new_meta_val ) {
75 $item = $new_meta_val;
76 }
77 }
78 if ( $key == 'url' && ! empty( $item ) && strstr( $item, 'ocalhost' ) ) {
79 // check if this has been imported before
80 $new_meta_val = advanced_import_admin()->imported_post_id( $item );
81 if ( $new_meta_val ) {
82 $item = $new_meta_val;
83 }
84 }
85 if ( ( $key == 'shortcode' || $key == 'editor' ) && ! empty( $item ) ) {
86 // we have to fix the [contact-form-7 id=133] shortcode issue.
87 $item = advanced_import_admin()->parse_shortcode_meta_content( $item );
88
89 }
90 }
91
92 public function elementor_post( $post_id = false ) {
93
94 // regenerate the CSS for this Elementor post
95 if ( class_exists( 'Elementor\Core\Files\CSS\Post' ) ) {
96 $post_css = new Elementor\Core\Files\CSS\Post( $post_id );
97 $post_css->update();
98 }
99 }
100
101 /*
102 set and get transient adi_elementor_data_posts
103 return mix*/
104 public function elementor_data_posts( $el_post_id = false, $meta_val = false ) {
105 $el_posts = get_transient( 'adi_elementor_data_posts' );
106 if ( ! is_array( $el_posts ) ) {
107 $el_posts = array();
108 }
109 if ( $el_post_id && $meta_val ) {
110 $el_posts[ $el_post_id ] = $meta_val;
111 set_transient( 'adi_elementor_data_posts', $el_posts, 60 * 60 * 24 );
112 }
113 return $el_posts;
114 }
115
116 /**
117 * Change post and term id related to elementor meta to new id
118 *
119 * @param array $item current array of demo list.
120 * @param string $key
121 * @return string
122 */
123 public function elementor_data( $elementor_data ) {
124
125 /*$upload_dir = wp_upload_dir();
126 $advanced_export_temp = $upload_dir['basedir'] . '/advanced-export-temp-test/';
127
128 WP_Filesystem();
129 global $wp_filesystem;
130
131 if ( ! file_exists( $advanced_export_temp ) ) {
132 $wp_filesystem->mkdir( $advanced_export_temp );
133 }
134 $file = fopen( $advanced_export_temp . 'content.json', 'a' );//a for append -- could use a+ to create the file if it doesn't exist
135 fwrite( $file, "\n" . print_r( $elementor_data, true ) );
136 fclose( $file );*/
137
138 if ( advanced_import_admin()->isJson( $elementor_data ) && is_string( $elementor_data ) && ! is_null( $elementor_data ) ) {
139 $elementor_data = json_decode( stripslashes( $elementor_data ), true );
140 }
141
142 /*Terms IDS*/
143 $replace_post_ids = apply_filters(
144 'advanced_import_replace_post_ids',
145 array(
146 'image_id',
147 'thumbnail_id',
148 'page_id',
149 'post_id',
150 )
151 );
152
153 /*Terms IDS*/
154 $replace_term_ids = apply_filters(
155 'advanced_import_replace_term_ids',
156 array(
157 'acm_authors_list',
158 'categories_selected',
159 )
160 );
161
162 // Recursively update elementor data.
163 foreach ( $elementor_data as $element_id => $element_data ) {
164 if ( ! empty( $element_data['elements'] ) ) {
165 foreach ( $element_data['elements'] as $el_key => $el_data ) {
166 if ( ! empty( $el_data['elements'] ) ) {
167 foreach ( $el_data['elements'] as $el_child_key => $child_el_data ) {
168 if ( 'widget' === $child_el_data['elType'] ) {
169 $settings = $child_el_data['settings'] ?? array();
170
171 if ( ! empty( $settings ) ) {
172 foreach ( $settings as $el_set_key => $el_set_data ) {
173 if ( in_array( $el_set_key, $replace_post_ids ) ) {
174 if ( is_numeric( $el_set_data ) ) {
175 $el_set_data = advanced_import_admin()->imported_post_id( $el_set_data );
176 } elseif ( is_array( $el_set_data ) && ! empty( $el_set_data ) ) {
177 $new_set_data = array();
178 foreach ( $el_set_data as $el_set_single_data ) {
179 if ( is_numeric( $el_set_data ) ) {
180 $new_set_data[] = advanced_import_admin()->imported_post_id( $el_set_single_data );
181 }
182 }
183 $el_set_data = $new_set_data;
184 }
185 }
186 if ( in_array( $el_set_key, $replace_term_ids ) ) {
187 if ( is_numeric( $el_set_data ) ) {
188 $el_set_data = advanced_import_admin()->imported_term_id( $el_set_data );
189 } elseif ( is_array( $el_set_data ) && ! empty( $el_set_data ) ) {
190 $new_set_data = array();
191 foreach ( $el_set_data as $el_set_single_data ) {
192 if ( is_numeric( $el_set_single_data ) ) {
193 $new_set_data[] = advanced_import_admin()->imported_term_id( $el_set_single_data );
194 }
195 }
196 $el_set_data = $new_set_data;
197 }
198 }
199 $elementor_data[ $element_id ]['elements'][ $el_key ]['elements'][ $el_child_key ]['settings'][ $el_set_key ] = $el_set_data;
200
201 }
202 }
203 }
204 }
205 }
206 }
207 }
208 }
209
210 return wp_json_encode( $elementor_data );
211 }
212
213 /**
214 * Change post and term id related to elementor meta to new id
215 *
216 * @param array $item current array of demo list.
217 * @param string $key
218 * @return string
219 */
220 public function process_elementor_posts() {
221 $el_posts = $this->elementor_data_posts();
222 if ( is_array( $el_posts ) && ! empty( $el_posts ) ) {
223 foreach ( $el_posts as $el_post => $el_data ) {
224 $el_data = $this->elementor_data( $el_data );
225 update_post_meta( $el_post, '_elementor_data', $el_data );
226 }
227 }
228 }
229 }
230 }
231
232
233 /**
234 * Begins execution of the plugin.
235 *
236 * Since everything within the plugin is registered via hooks,
237 * then kicking off the plugin from this point in the file does
238 * not affect the page life cycle.
239 *
240 * @since 1.0.0
241 */
242 function advanced_import_elementor() {
243 return Advanced_Import_Elementor::instance();
244 }
245