PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
← All changes | application/controllers/Wdk_settings.php +688 -127 1.1.8 → 1.5.9 View file →
@@ -1,10 +1,25 @@
1 1 <?php
2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly;
3 3
4 +/*
5 +
6 +actions inlcuded
7 +do_action('wdk/settings/import/run', $data); // form data
8 +
9 +apply_filters('wdk/settings/import/run/fields', $this->data['fields']); // fields
10 +apply_filters('wdk/settings/import/run/post', $data);
11 +
12 +*/
13 +
4 14 class Wdk_settings extends Winter_MVC_Controller {
5 15 public $import_log = '';
6 -
16 + public $info_log_message = '';
17 + public $import_images_dir = WPDIRECTORYKIT_PATH.'demo-data/images/';
18 + public $import_xml_file = '';
19 + public $import_xml_file_locations = WPDIRECTORYKIT_PATH.'demo-data/locations.xml';
20 + public $import_count_images = 2;
21 +
7 22 public function __construct(){
8 23 parent::__construct();
9 24 }
10 25
@@ -10,20 +25,26 @@
10 25
11 26 // Edit listing method
12 27 public function index()
13 28 {
29 +
14 30 $this->load->model('settings_m');
15 31 $this->data['db_data'] = NULL;
16 32 $this->data['form'] = &$this->form;
17 33 $this->data['fields'] = $this->settings_m->fields_list;
34 + $this->data['fields_list_tabs'] = $this->settings_m->fields_list_tabs;
18 35
19 - $this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _ ', 'wpdirectorykit'));
36 + $this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _', 'wpdirectorykit'));
20 37
21 38 if($this->form->run($this->data['fields']))
22 39 {
40 +
41 + // Check _wpnonce
42 + check_admin_referer( 'wdk-settings-edit', '_wpnonce' );
43 +
23 44 // Save procedure for basic data
24 45
25 - $data = $this->settings_m->prepare_data($this->input->post(), $this->data['fields']);
46 + $data = $this->settings_m->prepare_data(wdk_get_post(), $this->data['fields']);
26 47 $wdk_slug_listing_preview_page = get_option('wdk_slug_listing_preview_page');
27 48
28 49 // Save standard wp post
29 50 foreach($data as $key => $val)
@@ -54,12 +75,219 @@
54 75 {
55 76 $this->data['db_data'][$field->option_name] = $field->option_value;
56 77 }
57 78
79 + $this->mailtemplates();
80 +
58 81 $this->load->view('wdk_settings/index', $this->data);
59 82 }
83 +
84 + // Edit listing method
85 + public function mailtemplate()
86 + {
60 87
88 + $view_file = $this->input->post_get('file');
89 +
90 + $file = false;
91 + $sourceFile = null;
92 +
93 + if(file_exists(WPDIRECTORYKIT_PATH.'application/views/email/'.$view_file.'.php'))
94 + {
95 + $sourceFile = WPDIRECTORYKIT_PATH.'application/views/email/'.$view_file.'.php';
96 + } else {
97 + exit('File Not Exists');
98 + }
99 +
100 + if(is_child_theme() && !file_exists(get_stylesheet_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php'))
101 + {
102 +
103 + // Create the destination directory if it doesn't exist
104 + if (!is_dir(get_stylesheet_directory().'/wpdirectorykit/application/views/email/')) {
105 + global $wp_filesystem;
106 + if (empty($wp_filesystem)) {
107 + require_once(ABSPATH . '/wp-admin/includes/file.php');
108 + WP_Filesystem();
109 + }
110 + $dir_path = get_stylesheet_directory() . '/wpdirectorykit/application/views/email/';
111 + if (!$wp_filesystem->is_dir($dir_path)) {
112 + $wp_filesystem->mkdir($dir_path, FS_CHMOD_DIR | 0777);
113 + }
114 +
115 + }
116 +
117 + $destinationFile = get_stylesheet_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php';
118 + copy($sourceFile, $destinationFile);
119 + }
120 + elseif(!is_child_theme() && !file_exists(get_template_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php'))
121 + {
122 + // Create the destination directory if it doesn't exist
123 + if (!is_dir(get_template_directory().'/wpdirectorykit/application/views/email/')) {
124 + global $wp_filesystem;
125 + if (empty($wp_filesystem)) {
126 + require_once(ABSPATH . '/wp-admin/includes/file.php');
127 + WP_Filesystem();
128 + }
129 + $dir_path = get_template_directory() . '/wpdirectorykit/application/views/email/';
130 + if (!$wp_filesystem->is_dir($dir_path)) {
131 + $wp_filesystem->mkdir($dir_path, FS_CHMOD_DIR | 0777);
132 + }
133 +
134 + }
135 +
136 + $destinationFile = get_template_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php';
137 + copy($sourceFile, $destinationFile);
138 + }
139 +
140 + $current_theme = wp_get_theme();
141 + $file = esc_url(get_admin_url() . "theme-editor.php?file=wpdirectorykit/application/views/email/".$view_file.".php&theme=".$current_theme->get('TextDomain'));
142 +
143 + if(!empty($file))
144 + {
145 + wp_redirect($file);
146 + exit;
147 + } else {
148 + exit('File Not Exists');
149 + }
150 +
151 + }
152 +
153 + public function mailtemplates()
154 + {
155 + $this->data['mailtemplates'] = array(
156 + array(
157 + 'description' => __('Contact email','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
158 + 'template' => 'contact_form',
159 + ),
160 + array(
161 + 'description' => __('Default layout','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
162 + 'template' => 'default',
163 + ),
164 + array(
165 + 'description' => __('Listing in favorites list updated','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $message(string), $data(sting|array)</em>',
166 + 'template' => 'favorites_listing_updated_alert',
167 + ),
168 + array(
169 + 'description' => __('Membership Contact with owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user_profile(object), $data(sting|array)</em>',
170 + 'template' => 'membership_contact_owner',
171 + ),
172 + array(
173 + 'description' => __('Contact Visitot','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user_profile(object), $data(sting|array)</em>',
174 + 'template' => 'membership_contact_visitor',
175 + ),
176 + array(
177 + 'description' => __('Membership Subscription Expired notify message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $subscription_link(sting)</em>',
178 + 'template' => 'membership_expired_listing_cron',
179 + ),
180 + array(
181 + 'description' => __('Membership Listing Expired notify message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $subscription_link(sting)</em>',
182 + 'template' => 'membership_expired_listing',
183 + ),
184 + array(
185 + 'description' => __('Membership Subscription purchased','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user(object), $subscription_user(object)</em>',
186 + 'template' => 'membership_purchased',
187 + ),
188 + array(
189 + 'description' => __('Unread Messages notify','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $chat(array)</em>',
190 + 'template' => 'messages_unread_notify',
191 + ),
192 + array(
193 + 'description' => __('New claim message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
194 + 'template' => 'new_claim',
195 + ),
196 + array(
197 + 'description' => __('New Listing waiting for approvement','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $post_id(sting)</em>',
198 + 'template' => 'new_listing_approve',
199 + ),
200 + array(
201 + 'description' => __('New Listing approved','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $post_id(sting)</em>',
202 + 'template' => 'new_listing_approved',
203 + ),
204 + array(
205 + 'description' => __('New message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
206 + 'template' => 'new_message',
207 + ),
208 + array(
209 + 'description' => __('New report','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
210 + 'template' => 'new_report',
211 + ),
212 + array(
213 + 'description' => __('Review approved','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $link_review(string)</em>',
214 + 'template' => 'new_review_approved',
215 + ),
216 + array(
217 + 'description' => __('Message for new user about auto created account','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $login(string), $password(string)</em>',
218 + 'template' => 'new_user_auto_created',
219 + ),
220 + array(
221 + 'description' => __('Payment Package expired','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $listing(object), $package_link</em>',
222 + 'template' => 'payments_expired_listing',
223 + ),
224 + array(
225 + 'description' => __('Reservation approved, email for owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $user_owner(object), $user(object), $reservation_id(string), $listing(object)</em>',
226 + 'template' => 'reservation_approved_owner',
227 + ),
228 + array(
229 + 'description' => __('Reservation approved, email for client','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $user_owner(object), $user(object), $reservation_id(string), $listing(object)</em>',
230 + 'template' => 'reservation_approved_visitor',
231 + ),
232 + array(
233 + 'description' => __('Reservation changed, email for owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $user_owner(object), $user_visitor(object), $reservation_id(string), $listing(object)</em>',
234 + 'template' => 'reservation_changed_owner',
235 + ),
236 + array(
237 + 'description' => __('Reservation completed, email for owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $user_owner(object), $user_client(object), $reservation_id(string), $listing(object)</em>',
238 + 'template' => 'reservation_completed_owner',
239 + ),
240 + array(
241 + 'description' => __('Reservation completed, email for visitor','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $user_owner(object), $user_client(object), $reservation_id(string), $listing(object)</em>',
242 + 'template' => 'reservation_completed_visitor',
243 + ),
244 + array(
245 + 'description' => __('Reservation expired','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object)</em>',
246 + 'template' => 'reservation_expired',
247 + ),
248 + array(
249 + 'description' => __('Reservation user payment not expired','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object), $user_owner(object)</em>',
250 + 'template' => 'reservation_user_payment_notify_not_expired',
251 + ),
252 + array(
253 + 'description' => __('Reservation user payment notify','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object), $user_owner(object), $hours_for_payment(string)</em>',
254 + 'template' => 'reservation_user_payment_notify',
255 + ),
256 + array(
257 + 'description' => __('Reservation waiting for approve to owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object), $user_client(object), $user_owner(object)</em>',
258 + 'template' => 'reservation_waiting_for_approve_owner',
259 + ),
260 + array(
261 + 'description' => __('Reservation waiting for approve to client','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object), $user_client(object), $user_owner(object)</em>',
262 + 'template' => 'reservation_waiting_for_approve_visitor',
263 + ),
264 + array(
265 + 'description' => __('Notify related new listings based on saved search','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $results(array), $search_link_edit(string)</em>',
266 + 'template' => 'save_search_new_listings',
267 + ),
268 + array(
269 + 'description' => __('User Email Confirmed','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
270 + 'template' => 'wdk_membership_confirm_email_user_confirmed',
271 + ),
272 + array(
273 + 'description' => __('User Email Confirm request','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
274 + 'template' => 'wdk_membership_confirm_email_user_request',
275 + ),
276 + array(
277 + 'description' => __('Agency agent invitation email (sent to agent when agency invites them)','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $agency_name(string), $agent_name(string), $agency_profile_link(string), $confirmation_link(string)</em>',
278 + 'template' => 'agency_agent_submit',
279 + ),
280 +
281 + );
282 + }
283 +
61 284 function reset_data () {
285 +
286 + wdk_access_check('settings_m', 1);
287 +
288 + // Check _wpnonce
289 + check_admin_referer( 'reset-data', '_wpnonce' );
62 290
63 291 $this->load->model('location_m');
64 292 $this->load->model('category_m');
65 293 $this->load->model('field_m');
@@ -118,10 +346,10 @@
118 346 // Set to False if you want to send them to Trash.
119 347 }
120 348
121 349 $redirect_url = admin_url("admin.php?page=wdk_settings&is_updated");
122 - if(isset($_GET['redirect_url']))
123 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
350 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
351 + $redirect_url = admin_url(sanitize_text_field(wp_unslash($_GET['redirect_url'])));
124 352
125 353 wp_redirect($redirect_url);
126 354 exit;
127 355 }
@@ -128,9 +356,9 @@
128 356
129 357 // Import demo data listing method
130 358 public function import_demo()
131 359 {
132 -
360 + wdk_access_check('settings_m', 1);
133 361 $this->load->model('field_m');
134 362 $this->load->model('listingfield_m');
135 363 $this->load->model('listing_m');
136 364 $this->load->model('category_m');
@@ -173,12 +401,16 @@
173 401 closedir($dh);
174 402 }
175 403 }
176 404 }
405 +
177 406 ksort($multipurpose_values);
178 407 if(count($multipurpose_values) > 0)
179 408 $this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values);
180 409
410 +
411 + if(has_filter('wdk/settings/import/run/fields'))
412 + $this->data['fields'] = apply_filters('wdk/settings/import/run/fields', $this->data['fields']);
181 413
182 414 $this->data['form'] = &$this->form;
183 415 ini_set('max_execution_time', 900);
184 416
@@ -203,9 +435,8 @@
203 435 }
204 436
205 437 if($this->searchform_m->get() || $this->resultitem_m->get()){
206 438 $this->data['db_data']['import_visual_data'] = 0;
207 - $this->import_settings();
208 439 }
209 440
210 441 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
211 442 $this->data['db_data']['import_page_listing_preview'] = 0;
@@ -217,11 +448,13 @@
217 448
218 449 $this->data['db_data']['multipurpose'] = 'real-estate.xml';
219 450
220 451 if(isset($_GET['multipurpose']))
221 - $this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']);
452 + $this->data['db_data']['multipurpose'] = sanitize_text_field(wp_unslash($_GET['multipurpose']));
222 453
223 454 $this->data['import_log'] = '';
455 + $this->data['info_log_message'] = '';
456 +
224 457 $rules = array(
225 458 array(
226 459 'field' => 'import_locations',
227 460 'label' => __('Locations', 'wpdirectorykit'),
@@ -265,9 +498,9 @@
265 498 );
266 499
267 500 $plugin = 'elementor/elementor.php';
268 501 if (in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ))) && !class_exists('Elementor\Plugin') ) {
269 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Your Elementor Plugin is not fully active, usually this happen because of old PHP version on server, in such case eventually you can try older Elementor Version or Update PHP on your server').'</div>';
502 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Your Elementor Plugin is not fully active, usually this happen because of old PHP version on server, in such case eventually you can try older Elementor Version or Update PHP on your server', 'wpdirectorykit').'</div>';
270 503 $this->data['required_plugins'] = true;
271 504 }
272 505
273 506 if(!$this->data['required_plugins'])
@@ -272,11 +505,27 @@
272 505
273 506 if(!$this->data['required_plugins'])
274 507 if($this->form->run($rules))
275 508 {
509 + update_option('wdk_install_images_sizes_disable', 1);
510 +
511 + // Check _wpnonce
512 + check_admin_referer( 'wdk-settings_import', '_wpnonce' );
513 +
276 514 // Save procedure for basic data
277 515 $data = $this->input->post();
516 +
517 + $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$data['multipurpose'];
518 +
519 + if(has_filter('wdk/settings/import/run/post'))
520 + $data = apply_filters('wdk/settings/import/run/post', $data);
278 521
522 + $this->import_images_dir = apply_filters('wdk/settings/import/run/import_images_dir', $this->import_images_dir, $data);
523 + $this->import_xml_file = apply_filters('wdk/settings/import/run/import_xml_file', $this->import_xml_file, $data);
524 + $this->import_xml_file_locations = apply_filters('wdk/settings/import/run/import_xml_file_locations', $this->import_xml_file_locations, $data);
525 +
526 + $this->import_settings();
527 +
279 528 if( !empty($data['import_locations'])) {
280 529 $this->import_locations();
281 530 }
282 531
@@ -287,9 +536,9 @@
287 536 if( !empty($data['import_fields'])) {
288 537 $this->import_fields($data['multipurpose']);
289 538 }
290 539
291 - if( !empty($data['import_listings'])) {
540 + if( !empty($data['import_listings'])) {
292 541 $this->import_listings($data['multipurpose']);
293 542 }
294 543
295 544 if( !empty($data['import_visual_data'])) {
@@ -305,9 +554,16 @@
305 554 }
306 555
307 556 $this->replace_content_data($data['multipurpose']);
308 557
558 + $this->data['info_log_message'] .= '<div class="alert alert-info" role="alert">'.esc_html__('Import completed successfully', 'wpdirectorykit').', <a href="'. esc_url((wdk_get_option('wdk_results_page')) ? get_permalink(wdk_get_option('wdk_results_page')): home_url()).'">'.__('Check your page now', 'wpdirectorykit').'</a></div>';
559 +
560 + $this->data['info_log_message'] = apply_filters('wdk/settings/import/run/info_log_message', $this->data['info_log_message'] , $data);
561 +
562 + do_action('wdk/settings/import/run', $data);
563 + update_option('wdk_install_images_sizes_disable', 0);
309 564 }
565 +
310 566 $this->load->view('wdk_install/index', $this->data);
311 567 }
312 568
313 569 // Import demo data listing method
@@ -312,8 +568,14 @@
312 568
313 569 // Import demo data listing method
314 570 public function remove()
315 571 {
572 +
573 + wdk_access_check('settings_m', 1);
574 +
575 + // Check _wpnonce
576 + check_admin_referer( 'remove-data', '_wpnonce' );
577 +
316 578 $this->load->model('field_m');
317 579 $this->load->model('listingfield_m');
318 580 $this->load->model('listing_m');
319 581 $this->load->model('category_m');
@@ -327,19 +589,21 @@
327 589 $this->load->model('listingfield_m');
328 590 $this->load->model('listing_m');
329 591 $this->load->model('resultitem_m');
330 592 $this->load->model('searchform_m');
593 + $this->load->model('dependfields_m');
331 594
332 595 /* remove fields */
333 596 $this->db->delete($this->location_m->_table_name);
334 597
335 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed').'</div>';
598 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed', 'wpdirectorykit').'</div>';
336 599 /* end remove fields */
337 600
338 601 /* remove fields */
339 602 $this->db->delete($this->category_m->_table_name);
603 + $this->db->delete($this->dependfields_m->_table_name);
340 604
341 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed').'</div>';
605 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed', 'wpdirectorykit').'</div>';
342 606 /* end remove fields */
343 607
344 608 /* remove fields */
345 609 $this->db->delete($this->field_m->_table_name);
@@ -348,9 +612,9 @@
348 612 if(strpos($field_name, 'field_') ===FALSE) continue;
349 613 $this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.'');
350 614 }
351 615
352 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed').'</div>';
616 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed', 'wpdirectorykit').'</div>';
353 617 /* end remove fields */
354 618
355 619 /* remove listings */
356 620 $this->db->delete($this->listing_m->_table_name);
@@ -355,9 +619,9 @@
355 619 /* remove listings */
356 620 $this->db->delete($this->listing_m->_table_name);
357 621 $this->db->delete($this->listingfield_m->_table_name);
358 622
359 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed').'</div>';
623 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed', 'wpdirectorykit').'</div>';
360 624 /* end remove listings */
361 625
362 626
363 627 /* remove listings */
@@ -362,9 +626,9 @@
362 626
363 627 /* remove listings */
364 628 $this->db->delete($this->resultitem_m->_table_name);
365 629 $this->db->delete($this->searchform_m->_table_name);
366 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed').'</div>';
630 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed', 'wpdirectorykit').'</div>';
367 631 /* end remove listings */
368 632
369 633
370 634 /* reset autoincrement */
@@ -370,14 +634,15 @@
370 634 /* reset autoincrement */
371 635 $this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`');
372 636 $this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`');
373 637 $this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`');
638 + $this->db->query('TRUNCATE TABLE `'.$this->dependfields_m->_table_name.'`');
374 639 $this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`');
375 640 $this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`');
376 641 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
377 642 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
378 643
379 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset').'</div>';
644 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset', 'wpdirectorykit').'</div>';
380 645 /* end reset autoincrement */
381 646
382 647 $wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1));
383 648 foreach( $wdk_posts as $post ) {
@@ -385,13 +650,13 @@
385 650 wp_delete_post( $post->ID, true);
386 651 // Set to False if you want to send them to Trash.
387 652 }
388 653
389 - if(isset($_GET['redirect_url'])){
654 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE){
390 655 if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') {
391 - $redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated");
656 + $redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated&multipurpose=".wmvc_show_data('multipurpose', $_GET, ''));
392 657 } else {
393 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
658 + $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
394 659 }
395 660 wp_redirect($redirect_url);
396 661 }
397 662
@@ -398,11 +663,11 @@
398 663 $this->load->view('wdk_install/remove_log', $this->data);
399 664 }
400 665
401 666 /* add demo pages */
402 - public function demo_pages($purpose = '') {
667 + private function demo_pages($purpose = '') {
403 668
404 - // if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true;
669 + if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true;
405 670
406 671 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
407 672 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
408 673 });
@@ -541,9 +806,9 @@
541 806
542 807 return $user_id;
543 808 }
544 809
545 - function replace_content_data($purpose = '') {
810 + private function replace_content_data($purpose = '') {
546 811 /* Replace Links */
547 812 /* login */
548 813 $from = 'https://www.wpdirectorykit.com/nexproperty/wp-admin/wp-login.php';
549 814 $to = get_admin_url();
@@ -555,16 +820,15 @@
555 820 $this->replace_meta($from, $to);
556 821
557 822 /* homepage */
558 823 $from = '2020';
559 - $to = date('Y');
824 + $to = gmdate('Y');
560 825 $this->replace_meta($from, $to);
561 826
562 827
563 828 /* replace in db */
564 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
565 - if(file_exists($xml_list)) {
566 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
829 + if(file_exists($this->import_xml_file)) {
830 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
567 831 if(isset($dom_array['replace']) && !empty($dom_array['replace'])) {
568 832 if(!empty($dom_array['replace']['text'])) {
569 833 foreach($dom_array['replace']['text'] as $string){
570 834 if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue;
@@ -580,12 +844,12 @@
580 844
581 845 }
582 846
583 847 /* add demo listing preview page */
584 - public function demo_page_listing($purpose = '') {
848 + private function demo_page_listing($purpose = '') {
585 849
586 850 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
587 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists').'</div>';
851 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists', 'wpdirectorykit').'</div>';
588 852 return false;
589 853 }
590 854
591 855 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -614,8 +878,9 @@
614 878 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
615 879 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
616 880 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
617 881 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
882 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
618 883 });
619 884
620 885 // Import elementor templates
621 886 $page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas');
@@ -624,18 +889,18 @@
624 889 // Assign page.
625 890 if($page_listing_preview)
626 891 update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE);
627 892
628 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported').'</div>';
893 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported', 'wpdirectorykit').'</div>';
629 894
630 895 return true;
631 896 }
632 897
633 898 /* add demo results page */
634 - public function demo_page_results($purpose = '') {
899 + private function demo_page_results($purpose = '') {
635 900
636 901 if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){
637 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists').'</div>';
902 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists', 'wpdirectorykit').'</div>';
638 903 return false;
639 904 }
640 905
641 906 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -664,8 +929,9 @@
664 929 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
665 930 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
666 931 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
667 932 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
933 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
668 934 });
669 935
670 936 $page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas');
671 937 $this->elementor_assign($page_results->ID, 'page-results-listings.json');
@@ -675,9 +941,9 @@
675 941 update_option( 'page_on_front', $page_results->ID );
676 942
677 943 update_option( 'wdk_results_page', $page_results->ID, TRUE);
678 944
679 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported').'</div>';
945 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported', 'wpdirectorykit').'</div>';
680 946
681 947
682 948 $menus = get_registered_nav_menus();
683 949 // first menu defined by template
@@ -709,8 +975,11 @@
709 975 wp_update_nav_menu_item((int)$menu_id, 0, $itemData);
710 976
711 977 // assign menu to top menu
712 978 $locations = get_theme_mod( 'nav_menu_locations' );
979 + if ( ! is_array( $locations ) ) {
980 + $locations = array();
981 + }
713 982 $locations[$first_menu] = $menu_id;
714 983 set_theme_mod('nav_menu_locations', $locations);
715 984 }
716 985
@@ -717,11 +986,11 @@
717 986 return true;
718 987 }
719 988
720 989 /* Create Page */
721 - function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
990 + private function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
722 991 {
723 - $post = get_page_by_title($post_title, 'OBJECT', 'page' );
992 + $post = wdk_page_by_title($post_title, 'OBJECT', 'page' );
724 993
725 994 $post_id = NULL;
726 995
727 996 // Delete posts and rebuild
@@ -822,11 +1091,10 @@
822 1091 /* reset autoincrement */
823 1092 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
824 1093 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
825 1094
826 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
827 - if(file_exists($xml_list)) {
828 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1095 + if(file_exists($this->import_xml_file)) {
1096 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
829 1097
830 1098 if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) {
831 1099 } else {
832 1100 // Save searchform_m
@@ -851,19 +1119,18 @@
851 1119 $data['idresultitem'] = 1;
852 1120 $insert_id = $this->resultitem_m->insert($data, NULL);
853 1121 }
854 1122
855 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported').'</div>';
1123 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported', 'wpdirectorykit').'</div>';
856 1124 return true;
857 1125 }
858 -
859 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1126 + /* translators: 1: XML file path. */
1127 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('Missing xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
860 1128 return false;
861 1129
862 1130 }
863 1131
864 1132 private function import_locations() {
865 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/locations.xml';
866 1133 $this->load->model('location_m');
867 1134
868 1135 if($this->location_m->get()){
869 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
@@ -869,12 +1136,13 @@
869 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
870 1137 return false;
871 1138 }
872 1139
873 - if(file_exists($xml_list)) {
874 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1140 + if(file_exists($this->import_xml_file_locations)) {
1141 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file_locations));
875 1142 if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) {
876 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1143 + /* translators: 1: XML file path. */
1144 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file_locations).'</div>';
877 1145 return false;
878 1146 }
879 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
880 1148 $this->_recursive_add_locations($location_data);
@@ -879,13 +1147,13 @@
879 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
880 1148 $this->_recursive_add_locations($location_data);
881 1149 }
882 1150
883 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported').'</div>';
1151 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported', 'wpdirectorykit').'</div>';
884 1152 return true;
885 1153 }
886 -
887 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1154 + /* translators: 1: XML file path. */
1155 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('Missing xml file %1$s', 'wpdirectorykit'), $this->import_xml_file_locations).'</div>';
888 1156 return false;
889 1157 }
890 1158
891 1159 private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -905,16 +1173,16 @@
905 1173 if(empty(wmvc_show_data('location_title', $location_data))) {
906 1174 return false;
907 1175 }
908 1176
909 - if(!empty($location_data['image_id']) && file_exists(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['image_id'])){
1177 + if(!empty($location_data['image_id']) && file_exists($this->import_images_dir.$location_data['image_id'])){
910 1178 /* add files */
911 - $location_data['image_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['image_id']);
1179 + $location_data['image_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['image_id']);
912 1180 }
913 1181
914 - if(!empty($location_data['icon_id']) && file_exists(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['icon_id'])){
1182 + if(!empty($location_data['icon_id']) && file_exists($this->import_images_dir.$location_data['icon_id'])){
915 1183 /* add files */
916 - $location_data['icon_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.$location_data['icon_id']);
1184 + $location_data['icon_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['icon_id']);
917 1185 }
918 1186
919 1187 $location_data['icon_path'] = wdk_generate_path_image($location_data['icon_id']);
920 1188 $location_data['image_path'] = wdk_generate_path_image($location_data['image_id']);
@@ -928,10 +1196,10 @@
928 1196 }
929 1197 }
930 1198
931 1199 private function import_categories($purpose = '') {
932 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
933 - $this->load->model('category_m');
1200 + $this->load->model('category_m') ;
1201 + $this->load->model('dependfields_m') ;
934 1202
935 1203 if($this->category_m->get()){
936 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
937 1205 return false;
@@ -936,12 +1204,13 @@
936 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
937 1205 return false;
938 1206 }
939 1207
940 - if(file_exists($xml_list)) {
941 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1208 + if(file_exists($this->import_xml_file)) {
1209 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
942 1210 if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) {
943 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1211 + /* translators: 1: XML file path. */
1212 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
944 1213 return false;
945 1214 }
946 1215
947 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
@@ -947,13 +1216,24 @@
947 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
948 1217 $this->_recursive_add_categories($category_data);
949 1218 }
950 1219
951 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported').'</div>';
1220 + /* indexes by new order and reorder */
1221 + $results = $this->category_m->get_tree_table();
1222 + $values = array();
1223 + $order_index = 1;
1224 + foreach( $results as $item)
1225 + {
1226 + $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
1227 + $order_index++;
1228 + }
1229 + $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
1230 +
1231 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported', 'wpdirectorykit').'</div>';
952 1232 return true;
953 1233 }
954 -
955 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1234 + /* translators: 1: XML file path. */
1235 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
956 1236 return false;
957 1237 }
958 1238
959 1239 private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -985,11 +1265,11 @@
985 1265 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']))
986 1266 {
987 1267 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'];
988 1268 }
989 - elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id']))
1269 + elseif(file_exists( $this->import_images_dir.$category_data['image_id']))
990 1270 {
991 - $file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id'];
1271 + $file = $this->import_images_dir.$category_data['image_id'];
992 1272 }
993 1273 /* add files */
994 1274
995 1275 if($file)
@@ -1006,11 +1286,11 @@
1006 1286 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']))
1007 1287 {
1008 1288 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'];
1009 1289 }
1010 - elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id']))
1290 + elseif(file_exists( $this->import_images_dir.$category_data['icon_id']))
1011 1291 {
1012 - $file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id'];
1292 + $file = $this->import_images_dir.$category_data['icon_id'];
1013 1293 }
1014 1294 /* add files */
1015 1295
1016 1296 if($file)
@@ -1021,8 +1301,21 @@
1021 1301 $category_data['image_path'] = wdk_generate_path_image($category_data['image_id']);
1022 1302
1023 1303 /* add categories */
1024 1304 $insert_id = $this->category_m->insert($category_data, NULL);
1305 +
1306 + if(isset($data['hidden_fields_list']) && !empty($data['hidden_fields_list'])) {
1307 + $data_insert = array(
1308 + 'main_field' => 'categories',
1309 + 'field_id' => $insert_id,
1310 + 'hidden_fields_list' => $data['hidden_fields_list'],
1311 + );
1312 +
1313 + $this->dependfields_m->delete_where(array('field_id' => $insert_id, 'main_field' => 'categories'));
1314 + $this->dependfields_m->insert($data_insert);
1315 + }
1316 +
1317 +
1025 1318 if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) {
1026 1319 foreach ($data['childs']["category"] as $sub_category_data) {
1027 1320 $this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1));
1028 1321 }
@@ -1036,14 +1329,12 @@
1036 1329 if($this->field_m->get()){
1037 1330 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>';
1038 1331 return false;
1039 1332 }
1040 -
1041 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
1042 1333
1043 1334 $sections_added_array = array();
1044 - if(file_exists($xml_list)) {
1045 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1335 + if(file_exists($this->import_xml_file)) {
1336 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1046 1337
1047 1338 $base = array(
1048 1339 'field_type' => '',
1049 1340 'field_label' => '',
@@ -1055,15 +1346,17 @@
1055 1346 'suffix' => '',
1056 1347 'values_list' => '',
1057 1348 'icon_id' => '',
1058 1349 'is_required' => '',
1350 + 'order_index' => '',
1059 1351 );
1060 1352
1061 1353 if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) {
1062 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1354 + /* translators: 1: XML file path. */
1355 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'),$this->import_xml_file).'</div>';
1063 1356 return false;
1064 1357 }
1065 - $order_index = 0;
1358 +
1066 1359 foreach ($dom_array['fields']['field'] as $key => $field) {
1067 1360 $field_data = array_intersect_key(array_merge($base, $field), $base);
1068 1361 array_walk($field_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1069 1362
@@ -1087,18 +1380,27 @@
1087 1380 'field_label' => $field['section'],
1088 1381 'columns_number' => '12',
1089 1382 'is_visible_frontend' => '1',
1090 1383 'is_visible_dashboard' => '1',
1091 - 'order_index' => ++$order_index,
1384 + 'order_index' => $field['order_index'],
1092 1385 );
1093 1386 /* add field */
1387 +
1388 + if($section_data['field_label'] == 'SEO') {
1389 + $section_data['is_visible_frontend'] = 0;
1390 + }
1391 +
1094 1392 $this->field_m->insert($section_data, NULL);
1095 1393
1096 1394 $sections_added_array[] = $field['section'];
1097 1395 }
1098 1396
1099 - $field_data['order_index'] = ++$order_index;
1100 1397 /* add field */
1398 +
1399 + if($field_data['field_label'] == 'Keywords' || $field_data['field_label'] == 'Short Description') {
1400 + $field_data['is_visible_frontend'] = 0;
1401 + }
1402 +
1101 1403 $insert_id = $this->field_m->insert($field_data, NULL);
1102 1404 // check if column exists, add if nto exists
1103 1405 if(!empty($insert_id))
1104 1406 $this->listingfield_m->create_table_column($field_data, $insert_id);
@@ -1103,13 +1405,13 @@
1103 1405 if(!empty($insert_id))
1104 1406 $this->listingfield_m->create_table_column($field_data, $insert_id);
1105 1407 }
1106 1408
1107 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported').'</div>';
1409 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported', 'wpdirectorykit').'</div>';
1108 1410 return true;
1109 1411 }
1110 -
1111 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1412 + /* translators: 1: XML file path. */
1413 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1112 1414 return false;
1113 1415 }
1114 1416
1115 1417 private function import_listings($purpose = '') {
@@ -1149,13 +1451,12 @@
1149 1451 }
1150 1452 }
1151 1453
1152 1454 // Open a known directory, and proceed to read its contents
1153 - $dir = WPDIRECTORYKIT_PATH.'demo-data/images';
1154 1455 $purpose_name = str_replace('.xml','',$purpose);
1155 1456 $files = array();
1156 - if (is_dir($dir)) {
1157 - if ($dh = opendir($dir)) {
1457 + if (is_dir($this->import_images_dir)) {
1458 + if ($dh = opendir($this->import_images_dir)) {
1158 1459 while (($file = readdir($dh)) !== false) {
1159 1460 if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false)
1160 1461 $files[] = $file;
1161 1462 }
@@ -1163,13 +1464,13 @@
1163 1464 }
1164 1465 }
1165 1466 sort($files);
1166 1467
1167 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
1168 - if(file_exists($xml_list)) {
1169 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1468 + if(file_exists($this->import_xml_file)) {
1469 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1170 1470 if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) {
1171 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No listings in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1471 + /* translators: 1: XML file path. */
1472 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No listings in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1172 1473 return false;
1173 1474 }
1174 1475
1175 1476 /* demo agent add/get if exists */
@@ -1182,12 +1483,12 @@
1182 1483 $location_id = '';
1183 1484 $category_id = '';
1184 1485
1185 1486 if(!empty($categories))
1186 - $category_id = $categories[rand(0, count($categories)-1)];
1487 + $category_id = $categories[wp_rand(0, count($categories)-1)];
1187 1488
1188 1489 if(!empty($location))
1189 - $location_id = $locations[rand(0, count($locations)-1)];
1490 + $location_id = $locations[wp_rand(0, count($locations)-1)];
1190 1491
1191 1492 $data_listing = array(
1192 1493 'post_title' => '',
1193 1494 'post_content' => '',
@@ -1197,27 +1498,35 @@
1197 1498 'lat' => '',
1198 1499 'listing_images' => '',
1199 1500 'listing_images_path' => '',
1200 1501 'listing_images_path_medium' => '',
1201 - 'date_modified' => date('Y-m-d H:i:s'),
1502 + 'date_modified' => gmdate('Y-m-d H:i:s'),
1202 1503 'lng' => '',
1203 1504 'is_featured' => '',
1204 1505 'is_activated' => '1',
1205 1506 'is_approved' => '1',
1507 + 'counter_views' => wp_rand(20,250),
1206 1508 'user_id_editor' => NULL,
1207 1509 );
1208 -
1510 +
1209 1511 $data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing);
1210 1512 array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1211 -
1513 +
1212 1514 if(empty(wmvc_show_data('post_title', $data_listing))) {
1213 1515 continue;
1214 1516 }
1215 1517
1518 + $hidden_fields_list = wdk_depend_get_hidden_fields($data_listing['category_id']);
1519 +
1216 1520 /*fields */
1521 + $data_listings_fields = array();
1217 1522 foreach($fields as $field_data) {
1523 + if(!empty($hidden_fields_list) && strpos(','.$hidden_fields_list.',', ','.$field_data->idfield.',')!==FALSE) {
1524 + continue;
1525 + }
1526 +
1218 1527 if(isset($listing['field_'.$field_data->idfield])) {
1219 - $data_listing['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1528 + $data_listings_fields['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1220 1529 } else {
1221 1530 if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE')
1222 1531 {
1223 1532 if(empty($field_data->values_list)) continue;
@@ -1225,66 +1534,110 @@
1225 1534 if(count($values) > 0)
1226 1535 {
1227 1536 $start=0;
1228 1537 if(empty($values[0]))$start=1;
1229 - $data_listing['field_'.$field_data->idfield] = $values[rand($start, count($values)-1)];
1538 + $data_listings_fields['field_'.$field_data->idfield] = $values[wp_rand($start, count($values)-1)];
1230 1539 }
1231 1540 }
1232 1541 elseif($field_data->field_type == 'NUMBER')
1233 1542 {
1234 - $data_listing['field_'.$field_data->idfield] = rand(2,499);
1543 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(2,499);
1544 +
1235 1545 }
1236 1546 elseif($field_data->field_type == 'CHECKBOX')
1237 1547 {
1238 - $data_listing['field_'.$field_data->idfield] = rand(0,1);
1548 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(0,1);
1239 1549 }
1240 1550 elseif($field_data->field_type == 'TEXTAREA')
1241 1551 {
1242 - //$data_listing['field_'.$field_data->idfield] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
1552 + //$data_listings_fields['field_'.$field_data->idfield] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
1243 1553 }
1244 1554 }
1245 1555 }
1246 1556
1247 1557 /* add files */
1248 - $count_images = 2;
1558 +
1249 1559 if($purpose == 'car-dealer.xml') {
1250 - $count_images = 1;
1560 + $this->import_count_images = 1;
1251 1561 }
1562 + if(isset($listing['images']) && !empty($listing['images'])) {
1252 1563
1253 - for ($i=0,$image_num=$listing_num; $i<$count_images; $i++,$image_num++) {
1254 - if($image_num >= count($files))
1255 - $image_num = 0;
1564 + foreach (explode(',', $listing['images']) as $key => $file_name) {
1565 +
1566 + if(empty($file_name)) continue;
1256 1567
1257 - if(!empty($data_listing['listing_images']))
1258 - $data_listing['listing_images'].= ',';
1568 + if(!empty($data_listing['listing_images']))
1569 + $data_listing['listing_images'].= ',';
1570 + $image_id = wmvc_add_wp_image($this->import_images_dir.esc_html($file_name));
1259 1571
1260 - $image_id = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.esc_html($files[$image_num]));
1261 - $data_listing['listing_images'] .= $image_id;
1572 + $data_listing['listing_images'] .= $image_id;
1262 1573
1263 - $image_path = wp_get_original_image_path( $image_id);
1574 + $image_path = wp_get_original_image_path( $image_id);
1264 1575
1265 - if($image_path) {
1266 - /* path of image */
1267 - $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1576 + if($image_path) {
1577 + /* path of image */
1578 + $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1268 1579
1269 - /* check length listing_images_path + next image + comma, should be less 200*/
1270 - if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1271 - if(!empty($data_listing['listing_images_path']))
1272 - $data_listing['listing_images_path'] .= ',';
1580 + /* check length listing_images_path + next image + comma, should be less 200*/
1581 + if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1582 + if(!empty($data_listing['listing_images_path']))
1583 + $data_listing['listing_images_path'] .= ',';
1273 1584
1274 - $data_listing['listing_images_path'] .= $next_path;
1585 + $data_listing['listing_images_path'] .= $next_path;
1586 + }
1275 1587 }
1588 +
1589 + $image_url = wp_get_attachment_image_url($image_id, 'large');
1590 + if($image_url) {
1591 + $parsed = wp_parse_url($image_url);
1592 + $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
1593 +
1594 + if(!empty($data_listing['listing_images_path_medium']))
1595 + $data_listing['listing_images_path_medium'] .= ',';
1596 +
1597 + $data_listing['listing_images_path_medium'] .= $next_path;
1598 + }
1276 1599 }
1277 1600
1278 - $image_url = wp_get_attachment_image_url($image_id, 'large');
1279 - if($image_url) {
1280 - $parsed = parse_url($image_url);
1281 - $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
1601 + } else {
1602 + /* auto import images */
1603 + for ($i=0,$image_num=$listing_num; $i<$this->import_count_images; $i++,$image_num++) {
1604 + if($image_num >= count($files))
1605 + $image_num = 0;
1282 1606
1283 - if(!empty($data_listing['listing_images_path_medium']))
1284 - $data_listing['listing_images_path_medium'] .= ',';
1607 + if(!empty($data_listing['listing_images']))
1608 + $data_listing['listing_images'].= ',';
1285 1609
1286 - $data_listing['listing_images_path_medium'] .= $next_path;
1610 + if(!isset($files[$image_num])) continue;
1611 +
1612 + $image_id = wmvc_add_wp_image($this->import_images_dir.esc_html($files[$image_num]));
1613 + $data_listing['listing_images'] .= $image_id;
1614 +
1615 + $image_path = wp_get_original_image_path( $image_id);
1616 +
1617 + if($image_path) {
1618 + /* path of image */
1619 + $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1620 +
1621 + /* check length listing_images_path + next image + comma, should be less 200*/
1622 + if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1623 + if(!empty($data_listing['listing_images_path']))
1624 + $data_listing['listing_images_path'] .= ',';
1625 +
1626 + $data_listing['listing_images_path'] .= $next_path;
1627 + }
1628 + }
1629 +
1630 + $image_url = wp_get_attachment_image_url($image_id, 'large');
1631 + if($image_url) {
1632 + $parsed = wp_parse_url($image_url);
1633 + $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
1634 +
1635 + if(!empty($data_listing['listing_images_path_medium']))
1636 + $data_listing['listing_images_path_medium'] .= ',';
1637 +
1638 + $data_listing['listing_images_path_medium'] .= $next_path;
1639 + }
1287 1640 }
1288 1641 }
1289 1642
1290 1643 // Create post object
@@ -1306,19 +1659,22 @@
1306 1659 if(isset( $data_listing[$field_name]))
1307 1660 $listing_data[$field_name] = $data_listing[$field_name];
1308 1661 }
1309 1662 $listing_data['user_id_editor'] = $user_ids[array_rand($user_ids)];
1310 -
1663 + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s');
1664 + $listing_data['counter_views'] = wp_rand(20,250);
1665 +
1311 1666 $this->listing_m->insert($listing_data, NULL);
1312 1667
1313 - $data_listing['post_id'] = $id;
1314 - $this->listingfield_m->insert_custom_fields($fields, $data_listing, NULL);
1668 + $data_listings_fields['post_id'] = $id;
1669 + $this->listingfield_m->insert_custom_fields($fields, $data_listings_fields, NULL);
1315 1670 }
1316 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>';
1671 +
1672 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported', 'wpdirectorykit').'</div>';
1317 1673 return true;
1318 1674 }
1319 -
1320 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1675 + /* translators: 1: XML file path. */
1676 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1321 1677 return false;
1322 1678 }
1323 1679
1324 1680 protected function xmlstr_to_array($xmlstr) {
@@ -1379,8 +1735,14 @@
1379 1735 }
1380 1736
1381 1737 public function run()
1382 1738 {
1739 + wdk_access_check('settings_m', 1);
1740 +
1741 + // Check _wpnonce
1742 + check_admin_referer( 'wdk-import-data-run', '_wpnonce' );
1743 + update_option('wdk_install_images_sizes_disable', 1);
1744 +
1383 1745 ini_set('max_execution_time', 900);
1384 1746 $this->data['import_log'] = '';
1385 1747 $multipurpose = 'real-estate.xml';
1386 1748 if(isset($_GET['multipurpose']))
@@ -1386,11 +1748,17 @@
1386 1748 if(isset($_GET['multipurpose']))
1387 1749 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1388 1750
1389 1751 $redirect_url = admin_url("admin.php?page=wdk_fields&is_updated");
1390 - if(isset($_GET['redirect_url']))
1391 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
1752 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
1753 + $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
1392 1754
1755 + $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$multipurpose;
1756 + $this->import_images_dir = apply_filters('wdk/settings/import/api_run/import_images_dir', $this->import_images_dir, $multipurpose);
1757 + $this->import_xml_file = apply_filters('wdk/settings/import/api_run/import_xml_file', $this->import_xml_file, $multipurpose);
1758 + $this->import_xml_file_locations = apply_filters('wdk/settings/import/api_run/import_xml_file_locations', $this->import_xml_file_locations, $multipurpose);
1759 +
1760 +
1393 1761 $this->import_locations();
1394 1762 $this->import_categories($multipurpose);
1395 1763 $this->import_fields($multipurpose);
1396 1764 $this->import_listings($multipurpose);
@@ -1396,10 +1764,14 @@
1396 1764 $this->import_listings($multipurpose);
1397 1765 $this->import_visual_data($multipurpose);
1398 1766 $this->demo_pages($multipurpose);
1399 1767
1400 - $message = str_replace(" ", '+', __('Import completed successfuly', 'wpdirectorykit'));
1768 + $message = urlencode(str_replace(" ", '+', __('Import completed successfully', 'wpdirectorykit')).' <a href="'.esc_url((wdk_get_option('wdk_results_page')) ? get_permalink(wdk_get_option('wdk_results_page')): home_url()).'">'.__('Check your page now', 'wpdirectorykit').'</a>');
1401 1769
1770 + do_action('wpdirectorykit/install/api');
1771 + do_action('wdk/settings/import/api_run', $multipurpose);
1772 + update_option('wdk_install_images_sizes_disable', 0);
1773 +
1402 1774 wp_redirect($redirect_url.'&message='.$message);
1403 1775 exit;
1404 1776 }
1405 1777
@@ -1404,8 +1776,19 @@
1404 1776 }
1405 1777
1406 1778 public function api_import()
1407 1779 {
1780 + wdk_access_check('settings_m', 1);
1781 + update_option('wdk_install_images_sizes_disable', 1);
1782 + /* block url access */
1783 + if(
1784 + (isset($_GET['function']) && $_GET['function'] == 'api_import' ) ||
1785 + (isset($_POST['function']) && $_POST['function'] == 'api_import' )
1786 + ) {
1787 + echo esc_html__('Security blocked', 'wpdirectorykit');
1788 + exit();
1789 + }
1790 +
1408 1791 ini_set('max_execution_time', 900);
1409 1792 $this->data['import_log'] = '';
1410 1793 $multipurpose = 'real-estate.xml';
1411 1794 if(isset($_GET['multipurpose']))
@@ -1410,8 +1793,14 @@
1410 1793 $multipurpose = 'real-estate.xml';
1411 1794 if(isset($_GET['multipurpose']))
1412 1795 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1413 1796
1797 +
1798 + $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$multipurpose;
1799 + $this->import_images_dir = apply_filters('wdk/settings/import/api_run/import_images_dir', $this->import_images_dir, $multipurpose);
1800 + $this->import_xml_file = apply_filters('wdk/settings/import/api_run/import_xml_file', $this->import_xml_file, $multipurpose);
1801 + $this->import_xml_file_locations = apply_filters('wdk/settings/import/api_run/import_xml_file_locations', $this->import_xml_file_locations, $multipurpose);
1802 +
1414 1803 $this->import_locations();
1415 1804 $this->import_categories($multipurpose);
1416 1805 $this->import_fields($multipurpose);
1417 1806 $this->import_listings($multipurpose);
@@ -1419,9 +1808,41 @@
1419 1808 $this->import_settings();
1420 1809
1421 1810 /* action */
1422 1811 do_action('wpdirectorykit/install/api');
1812 + do_action('wdk/settings/import/api_run', $multipurpose);
1813 + update_option('wdk_install_images_sizes_disable', 0);
1814 + return true;
1815 + }
1423 1816
1817 + public function _api_import($import_count_images = 2)
1818 + {
1819 + $this->import_count_images = $import_count_images;
1820 +
1821 + wdk_access_check('settings_m', 1);
1822 + update_option('wdk_install_images_sizes_disable', 1);
1823 + ini_set('max_execution_time', 900);
1824 + $this->data['import_log'] = '';
1825 + $multipurpose = 'real-estate.xml';
1826 + if(isset($_GET['multipurpose']))
1827 + $multipurpose = sanitize_text_field($_GET['multipurpose']);
1828 +
1829 + $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$multipurpose;
1830 + $this->import_images_dir = apply_filters('wdk/settings/import/api_run/import_images_dir', $this->import_images_dir, $multipurpose);
1831 + $this->import_xml_file = apply_filters('wdk/settings/import/api_run/import_xml_file', $this->import_xml_file, $multipurpose);
1832 + $this->import_xml_file_locations = apply_filters('wdk/settings/import/api_run/import_xml_file_locations', $this->import_xml_file_locations, $multipurpose);
1833 +
1834 + $this->import_locations();
1835 + $this->import_categories($multipurpose);
1836 + $this->import_fields($multipurpose);
1837 + $this->import_listings($multipurpose);
1838 + $this->import_visual_data($multipurpose);
1839 + $this->import_settings();
1840 +
1841 + /* action */
1842 + do_action('wpdirectorykit/install/api');
1843 + do_action('wdk/settings/import/api_run', $multipurpose);
1844 + update_option('wdk_install_images_sizes_disable', 0);
1424 1845 return true;
1425 1846 }
1426 1847
1427 1848 private function replace_meta($from = '', $to = '') {
@@ -1433,16 +1854,156 @@
1433 1854 "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" );
1434 1855 /* end login */
1435 1856 }
1436 1857
1437 - public function import_settings() {
1858 + private function import_settings() {
1859 + wdk_access_check('settings_m', 1);
1860 +
1438 1861 update_option( 'wdk_is_category_enabled', '1' );
1439 1862 update_option( 'wdk_is_location_enabled', '1' );
1440 1863 update_option( 'wdk_is_address_enabled', '1' );
1441 - update_option( 'wdk_is_results_page_require', '1' );
1864 + update_option( 'wdk_is_results_page_require', 0 );
1442 1865 update_option( 'wdk_seo_description', '2' );
1443 1866 update_option( 'wdk_seo_keywords', '3' );
1444 1867 update_option( 'wdk_card_slider_enable', '1' );
1868 + update_option('elementor_load_fa4_shim', 'yes');
1869 +
1870 + /* disable elmentor experement feature */
1871 + update_option( 'elementor_experiment-e_font_icon_svg', 'inactive');
1872 + update_option( 'elementor_experiment-landing-pages', 'inactive' );
1873 + update_option( 'elementor_experiment-e_dom_optimization', 'inactive');
1874 +
1445 1875 return true;
1446 1876 }
1877 +
1878 + /* add demo listing preview page */
1879 + public function create_custom_page($layout_json, $page_title = "New Page", $option = '', $custom_message_title = '') {
1880 + $page_title_message = $page_title;
1881 + if(!empty($custom_message_title)){
1882 + $page_title_message = $custom_message_title;
1883 + }
1884 +
1885 + if(!empty($option) && (get_option($option)) && get_post_status(get_option($option)) =='publish'){
1886 + // $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.$page_title_message.' '.esc_html__('Page already exists', 'wpdirectorykit').'</div>';
1887 + // return false;
1888 + }
1889 +
1890 + add_action('wdk-membership/elementor-elements/register_widget', function($self){
1891 + $self->add_widget('WdkMembership\Elementor\Extensions\WdkMembershipContactFormExt');
1892 + });
1893 +
1894 + add_action('wdk-membership/elementor-elements/register_widget', function(){
1895 + add_action('eli/includes', function(){
1896 + require_once WDK_MEMBERSHIP_PATH . '/elementor-extensions/class-contact-form.php';
1897 + });
1898 +
1899 + add_action('eli/register_widget', function(){
1900 + $object = new WdkMembership\Elementor\Extensions\WdkMembershipContactFormExt();
1901 + \Elementor\Plugin::instance()->widgets_manager->register( $object );
1902 + });
1903 + });
1904 +
1905 + add_action('wdk-membership/elementor-elements/register_widget', function($self){
1906 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipContent');
1907 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipMenu');
1908 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileListings');
1909 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileContent');
1910 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileContent');
1911 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipLoginForm');
1912 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipRegisterForm');
1913 + $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipBreadcrumb');
1914 + });
1915 +
1916 + // Import elementor templates
1917 + $page = $this->generate_custom_page($page_title, '', 'elementor_canvas');
1918 + $this->elementor_custom_assign($page->ID, $layout_json);
1919 +
1920 + // Assign page.
1921 + if($page && !empty($option))
1922 + update_option( $option, $page->ID, TRUE);
1923 +
1924 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.$page_title_message.' '.esc_html__('Page imported', 'wpdirectorykit').'</div>';
1925 +
1926 + return $page->ID;
1927 + }
1928 +
1447 1929
1930 + /* Create Page */
1931 + private function generate_custom_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
1932 + {
1933 + $post = wdk_page_by_title($post_title, 'OBJECT', 'page' );
1934 +
1935 + $post_id = NULL;
1936 +
1937 + // Delete posts and rebuild
1938 + if(!empty($post))
1939 + {
1940 + wp_delete_post($post->ID, true);
1941 + $post=NULL;
1942 + }
1943 +
1944 + if(!empty($post))
1945 + $post_id = $post->ID;
1946 +
1947 + if(empty($post_id))
1948 + {
1949 + $error_obj = NULL;
1950 + $post_insert = array(
1951 + 'post_title' => wp_strip_all_tags( $post_title ),
1952 + 'post_content' => $post_content,
1953 + 'post_status' => 'publish',
1954 + 'post_type' => 'page',
1955 + 'post_author' => get_current_user_id(),
1956 + 'post_category' => array(1,2),
1957 + 'page_template' => $post_template,
1958 + 'post_parent' => $post_parent
1959 + );
1960 + $post_id = wp_insert_post( $post_insert, $error_obj );
1961 + }
1962 +
1963 + $post_insert = get_post( $post_id );
1964 +
1965 + return $post_insert;
1966 + }
1967 +
1968 + /* Elementor Import Template */
1969 + public function elementor_custom_assign($page_id, $json_template_name = '')
1970 + {
1971 + $file = false;
1972 +
1973 + if(file_exists( $json_template_name ))
1974 + {
1975 + $file = $json_template_name;
1976 + }
1977 +
1978 + if(!$file || !class_exists('Elementor\Plugin'))
1979 + {
1980 + return false;
1981 + }
1982 +
1983 + $page_template = get_page_template_slug( $page_id );
1984 +
1985 + add_post_meta( $page_id, '_elementor_edit_mode', 'builder' );
1986 +
1987 + global $wp_filesystem;
1988 + // Initialize the WP filesystem, no more using 'file-put-contents' function
1989 + if (empty($wp_filesystem)) {
1990 + WP_Filesystem();
1991 + }
1992 +
1993 + $string = $wp_filesystem->get_contents($file);
1994 +
1995 + $json_template = json_decode($string, true);
1996 +
1997 + $elements = $json_template['content'];
1998 +
1999 + $data = array(
2000 + 'elements' => $elements,
2001 + 'settings' => array('post_status'=>'autosave', 'template'=>$page_template),
2002 + );
2003 + // @codingStandardsIgnoreStart
2004 + $document = Elementor\Plugin::$instance->documents->get( $page_id, false );
2005 + // @codingStandardsIgnoreEnd
2006 + return $document->save( $data );
2007 + }
2008 +
1448 2009 }