PluginProbe
WP Directory Kit / 1.3.4
WP Directory Kit v1.3.4
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / controllers / Wdk_settings.php

Wdk_settings.php in WP Directory Kit 1.3.4, at application/controllers/Wdk_settings.php

1,979 lines 89.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly;
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
14 class Wdk_settings extends Winter_MVC_Controller {
15 public $import_log = '';
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
22 public function __construct(){
23 parent::__construct();
24 }
25
26 // Edit listing method
27 public function index()
28 {
29
30 $this->load->model('settings_m');
31 $this->data['db_data'] = NULL;
32 $this->data['form'] = &$this->form;
33 $this->data['fields'] = $this->settings_m->fields_list;
34 $this->data['fields_list_tabs'] = $this->settings_m->fields_list_tabs;
35
36 $this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _', 'wpdirectorykit'));
37
38 if($this->form->run($this->data['fields']))
39 {
40
41 // Check _wpnonce
42 check_admin_referer( 'wdk-settings-edit', '_wpnonce' );
43
44 // Save procedure for basic data
45
46 $data = $this->settings_m->prepare_data(wdk_get_post(), $this->data['fields']);
47 $wdk_slug_listing_preview_page = get_option('wdk_slug_listing_preview_page');
48
49 // Save standard wp post
50 foreach($data as $key => $val)
51 {
52 update_option( $key, $val, TRUE);
53 }
54
55 if(isset($data['wdk_slug_listing_preview_page']) && $wdk_slug_listing_preview_page != $data['wdk_slug_listing_preview_page']) {
56 update_option('wdk_slug_listing_preview_page_changed', 1);
57 }
58
59 // redirect
60 if(empty($listing_post_id) && !empty($id))
61 {
62 //wp_redirect(admin_url("admin.php?page=wdk_settings&is_updated=true"));
63 exit;
64 }
65
66 }
67
68 // fetch data, after update/insert to get updated last data
69 $fields_data = $this->settings_m->get();
70
71 /* slug udpate rules*/
72 //flush_rewrite_rules();
73
74 foreach($fields_data as $field)
75 {
76 $this->data['db_data'][$field->option_name] = $field->option_value;
77 }
78
79 $this->mailtemplates();
80
81 $this->load->view('wdk_settings/index', $this->data);
82 }
83
84 // Edit listing method
85 public function mailtemplate()
86 {
87
88 $view_file = $this->input->post_get('file');
89 dump($view_file);
90
91 $file = false;
92 $sourceFile = null;
93
94 if(file_exists(WPDIRECTORYKIT_PATH.'application/views/email/'.$view_file.'.php'))
95 {
96 $sourceFile = WPDIRECTORYKIT_PATH.'application/views/email/'.$view_file.'.php';
97 } else {
98 exit('File Not Exists');
99 }
100
101 if(is_child_theme() && !file_exists(get_stylesheet_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php'))
102 {
103
104 // Create the destination directory if it doesn't exist
105 if (!is_dir(get_stylesheet_directory().'/wpdirectorykit/application/views/email/')) {
106 mkdir(get_stylesheet_directory().'/wpdirectorykit/application/views/email/', 0777, true);
107 }
108
109 $destinationFile = get_stylesheet_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php';
110 copy($sourceFile, $destinationFile);
111 }
112 elseif(!is_child_theme() && !file_exists(get_template_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php'))
113 {
114 // Create the destination directory if it doesn't exist
115 if (!is_dir(get_template_directory().'/wpdirectorykit/application/views/email/')) {
116 mkdir(get_template_directory().'/wpdirectorykit/application/views/email/', 0777, true);
117 }
118
119 $destinationFile = get_template_directory().'/wpdirectorykit/application/views/email/'.$view_file.'.php';
120 copy($sourceFile, $destinationFile);
121 }
122
123 $current_theme = wp_get_theme();
124 $file = esc_url(get_admin_url() . "theme-editor.php?file=wpdirectorykit/application/views/email/".$view_file.".php&theme=".$current_theme->get('TextDomain'));
125
126 if(!empty($file))
127 {
128 wp_redirect($file);
129 exit;
130 } else {
131 exit('File Not Exists');
132 }
133
134 }
135
136 public function mailtemplates()
137 {
138 $this->data['mailtemplates'] = array(
139 array(
140 'description' => __('Contact email','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
141 'template' => 'contact_form',
142 ),
143 array(
144 'description' => __('Default layout','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
145 'template' => 'default',
146 ),
147 array(
148 'description' => __('Listing in favorites list updated','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $message(string), $data(sting|array)</em>',
149 'template' => 'favorites_listing_updated_alert',
150 ),
151 array(
152 'description' => __('Membership Contact with owner','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user_profile(object), $data(sting|array)</em>',
153 'template' => 'membership_contact_owner',
154 ),
155 array(
156 'description' => __('Contact Visitot','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user_profile(object), $data(sting|array)</em>',
157 'template' => 'membership_contact_visitor',
158 ),
159 array(
160 'description' => __('Membership Subscription Expired notify message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $subscription_link(sting)</em>',
161 'template' => 'membership_expired_listing_cron',
162 ),
163 array(
164 'description' => __('Membership Listing Expired notify message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $listing(object), $subscription_link(sting)</em>',
165 'template' => 'membership_expired_listing',
166 ),
167 array(
168 'description' => __('Membership Subscription purchased','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $user(object), $subscription_user(object)</em>',
169 'template' => 'membership_purchased',
170 ),
171 array(
172 'description' => __('Unread Messages notify','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $chat(array)</em>',
173 'template' => 'messages_unread_notify',
174 ),
175 array(
176 'description' => __('New claim message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
177 'template' => 'new_claim',
178 ),
179 array(
180 'description' => __('New Listing waiting for approvement','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $post_id(sting)</em>',
181 'template' => 'new_listing_approve',
182 ),
183 array(
184 'description' => __('New Listing approved','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $post_id(sting)</em>',
185 'template' => 'new_listing_approved',
186 ),
187 array(
188 'description' => __('New message','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
189 'template' => 'new_message',
190 ),
191 array(
192 'description' => __('New report','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
193 'template' => 'new_report',
194 ),
195 array(
196 'description' => __('Review approved','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $link_review(string)</em>',
197 'template' => 'new_review_approved',
198 ),
199 array(
200 'description' => __('Message for new user about auto created account','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $login(string), $password(string)</em>',
201 'template' => 'new_user_auto_created',
202 ),
203 array(
204 'description' => __('Payment Package expired','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $listing(object), $package_link</em>',
205 'template' => 'payments_expired_listing',
206 ),
207 array(
208 '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>',
209 'template' => 'reservation_approved_owner',
210 ),
211 array(
212 '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>',
213 'template' => 'reservation_approved_visitor',
214 ),
215 array(
216 '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>',
217 'template' => 'reservation_changed_owner',
218 ),
219 array(
220 '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>',
221 'template' => 'reservation_completed_owner',
222 ),
223 array(
224 '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>',
225 'template' => 'reservation_completed_visitor',
226 ),
227 array(
228 'description' => __('Reservation expired','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array), $reservation_id(string), $listing(object)</em>',
229 'template' => 'reservation_expired',
230 ),
231 array(
232 '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>',
233 'template' => 'reservation_user_payment_notify_not_expired',
234 ),
235 array(
236 '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>',
237 'template' => 'reservation_user_payment_notify',
238 ),
239 array(
240 '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>',
241 'template' => 'reservation_waiting_for_approve_owner',
242 ),
243 array(
244 '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>',
245 'template' => 'reservation_waiting_for_approve_visitor',
246 ),
247 array(
248 'description' => __('Notify related new listings based on saved search','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $results(array), $search_link_edit(string)</em>',
249 'template' => 'save_search_new_listings',
250 ),
251 array(
252 'description' => __('User Email Confirmed','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
253 'template' => 'wdk_membership_confirm_email_user_confirmed',
254 ),
255 array(
256 'description' => __('User Email Confirm request','wpdirectorykit').'<br>'.'<em>Data vars $subject(string), $data(sting|array)</em>',
257 'template' => 'wdk_membership_confirm_email_user_request',
258 ),
259 );
260 }
261
262 function reset_data () {
263
264 wdk_access_check('settings_m', 1);
265
266 // Check _wpnonce
267 check_admin_referer( 'reset-data', '_wpnonce' );
268
269 $this->load->model('location_m');
270 $this->load->model('category_m');
271 $this->load->model('field_m');
272 $this->load->model('listingfield_m');
273 $this->load->model('listing_m');
274 $this->load->model('resultitem_m');
275 $this->load->model('searchform_m');
276
277 /* remove fields */
278 $this->db->delete($this->location_m->_table_name);
279 /* end remove fields */
280
281 /* remove fields */
282 $this->db->delete($this->category_m->_table_name);
283 /* end remove fields */
284
285 /* remove fields */
286 $this->db->delete($this->location_m->_table_name);
287 /* end remove fields */
288
289 /* remove fields */
290 $this->db->delete($this->field_m->_table_name);
291 $field_names = $this->listingfield_m->get_available_fields();
292 foreach($field_names as $field_name => $value){
293 if(strpos($field_name, 'field_') ===FALSE) continue;
294 $this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.'');
295 }
296 /* end remove fields */
297
298 /* remove listings */
299 $this->db->delete($this->listing_m->_table_name);
300 $this->db->delete($this->listingfield_m->_table_name);
301 /* end remove listings */
302
303 /* reset autoincrement */
304 $this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`');
305 $this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`');
306 $this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`');
307 $this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`');
308 $this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`');
309 /* end reset autoincrement */
310
311 /* remove listings */
312 $this->db->delete($this->resultitem_m->_table_name);
313 $this->db->delete($this->searchform_m->_table_name);
314 /* end remove listings */
315
316 /* reset autoincrement */
317 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
318 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
319
320 $wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1));
321 foreach( $wdk_posts as $post ) {
322 // Delete's each post.
323 wp_delete_post( $post->ID, true);
324 // Set to False if you want to send them to Trash.
325 }
326
327 $redirect_url = admin_url("admin.php?page=wdk_settings&is_updated");
328 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
329 $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
330
331 wp_redirect($redirect_url);
332 exit;
333 }
334
335 // Import demo data listing method
336 public function import_demo()
337 {
338 wdk_access_check('settings_m', 1);
339 $this->load->model('field_m');
340 $this->load->model('listingfield_m');
341 $this->load->model('listing_m');
342 $this->load->model('category_m');
343 $this->load->model('location_m');
344 $this->load->model('searchform_m');
345 $this->load->model('resultitem_m');
346 $this->load->model('listingusers_m');
347
348 $this->data['installed'] = false;
349 if($this->field_m->get() || $this->listingfield_m->get() || $this->listing_m->get() || $this->category_m->get() || $this->location_m->get())
350 $this->data['installed'] = true;
351
352 $this->data['required_plugins'] = false;
353 if(!function_exists('eli_installer') || !function_exists('run_elementinvader') || !is_plugin_active('elementor/elementor.php'))
354 $this->data['required_plugins'] = true;
355
356 $this->data['db_data'] = NULL;
357 $this->data['fields'] = array(
358 array('field' => 'import_locations', 'field_label' => __('Locations', 'wpdirectorykit'), 'hint' => __('All Locations will be removed and import demo locations', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
359 array('field' => 'import_categories', 'field_label' => __('Categories', 'wpdirectorykit'), 'hint' => __('All categories will be removed and import demo categories', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
360 array('field' => 'import_fields', 'field_label' => __('Fields', 'wpdirectorykit'), 'hint' => __('All fiedls will be removed and import demo fields', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
361 array('field' => 'import_listings', 'field_label' => __('Listings', 'wpdirectorykit'), 'hint' => __('All listings will be removed and import demo listings', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
362 array('field' => 'import_visual_data', 'field_label' => __('Search Form & Result Card', 'wpdirectorykit'), 'hint' => __('Import demo Search Form & Result Card', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
363 array('field' => 'import_page_listing_preview', 'field_label' => __('Listing Preview Page', 'wpdirectorykit'), 'hint' => __('Import demo Listing Preivew Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
364 array('field' => 'import_page_results', 'field_label' => __('Results Page', 'wpdirectorykit'), 'hint' => __('Import demo Results Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
365 );
366
367 $multipurpose_values = array('' => __('Not Selected', 'wpdirectorykit'));
368 if(file_exists(WPDIRECTORYKIT_PATH.'demo-data/'))
369 {
370 $files = array();
371 $dir = WPDIRECTORYKIT_PATH.'demo-data/';
372 if (is_dir($dir)) {
373 if ($dh = opendir($dir)) {
374 while (($file = readdir($dh)) !== false) {
375 if($file == 'locations.xml') continue;
376 if(strpos($file, '.xml') !== false && strpos($file, '~') === false)
377 $multipurpose_values[$file] = ucwords(str_replace(array('_', '-', '.xml'), ' ', $file));
378 }
379 closedir($dh);
380 }
381 }
382 }
383
384 ksort($multipurpose_values);
385 if(count($multipurpose_values) > 0)
386 $this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values);
387
388
389 if(has_filter('wdk/settings/import/run/fields'))
390 $this->data['fields'] = apply_filters('wdk/settings/import/run/fields', $this->data['fields']);
391
392 $this->data['form'] = &$this->form;
393 ini_set('max_execution_time', 900);
394
395 // [/Check requirements]
396
397 foreach($this->data['fields'] as $field)
398 {
399 $this->data['db_data'][$field['field']] = 1;
400 }
401
402 if($this->field_m->get()) {
403 $this->data['db_data']['import_fields'] = 0;
404 }
405 if($this->listing_m->get()) {
406 $this->data['db_data']['import_listings'] = 0;
407 }
408 if($this->category_m->get()) {
409 $this->data['db_data']['import_categories'] = 0;
410 }
411 if($this->location_m->get()) {
412 $this->data['db_data']['import_locations'] = 0;
413 }
414
415 if($this->searchform_m->get() || $this->resultitem_m->get()){
416 $this->data['db_data']['import_visual_data'] = 0;
417 }
418
419 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
420 $this->data['db_data']['import_page_listing_preview'] = 0;
421 }
422
423 if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){
424 $this->data['db_data']['import_page_results'] = 0;
425 }
426
427 $this->data['db_data']['multipurpose'] = 'real-estate.xml';
428
429 if(isset($_GET['multipurpose']))
430 $this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']);
431
432 $this->data['import_log'] = '';
433 $this->data['info_log_message'] = '';
434
435 $rules = array(
436 array(
437 'field' => 'import_locations',
438 'label' => __('Locations', 'wpdirectorykit'),
439 'rules' => ''
440 ),
441 array(
442 'field' => 'import_categories',
443 'label' => __('Categories', 'wpdirectorykit'),
444 'rules' => ''
445 ),
446 array(
447 'field' => 'import_fields',
448 'label' => __('Fields', 'wpdirectorykit'),
449 'rules' => ''
450 ),
451 array(
452 'field' => 'import_listings',
453 'label' => __('Listings', 'wpdirectorykit'),
454 'rules' => ''
455 ),
456 array(
457 'field' => 'import_visual_data',
458 'label' => __('Search Form & Result Card', 'wpdirectorykit'),
459 'rules' => ''
460 ),
461 array(
462 'field' => 'import_page_listing_preview',
463 'label' => __('Listing Preview Page', 'wpdirectorykit'),
464 'rules' => ''
465 ),
466 array(
467 'field' => 'import_page_results',
468 'label' => __('Results Page', 'wpdirectorykit'),
469 'rules' => ''
470 ),
471 array(
472 'field' => 'multipurpose',
473 'label' => __('Purpose', 'wpdirectorykit'),
474 'rules' => 'required'
475 ),
476 );
477
478 $plugin = 'elementor/elementor.php';
479 if (in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ))) && !class_exists('Elementor\Plugin') ) {
480 $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>';
481 $this->data['required_plugins'] = true;
482 }
483
484 if(!$this->data['required_plugins'])
485 if($this->form->run($rules))
486 {
487 update_option('wdk_install_images_sizes_disable', 1);
488
489 // Check _wpnonce
490 check_admin_referer( 'wdk-settings_import', '_wpnonce' );
491
492 // Save procedure for basic data
493 $data = $this->input->post();
494
495 $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$data['multipurpose'];
496
497 if(has_filter('wdk/settings/import/run/post'))
498 $data = apply_filters('wdk/settings/import/run/post', $data);
499
500 $this->import_images_dir = apply_filters('wdk/settings/import/run/import_images_dir', $this->import_images_dir, $data);
501 $this->import_xml_file = apply_filters('wdk/settings/import/run/import_xml_file', $this->import_xml_file, $data);
502 $this->import_xml_file_locations = apply_filters('wdk/settings/import/run/import_xml_file_locations', $this->import_xml_file_locations, $data);
503
504 $this->import_settings();
505
506 if( !empty($data['import_locations'])) {
507 $this->import_locations();
508 }
509
510 if( !empty($data['import_categories'])) {
511 $this->import_categories($data['multipurpose']);
512 }
513
514 if( !empty($data['import_fields'])) {
515 $this->import_fields($data['multipurpose']);
516 }
517
518 if( !empty($data['import_listings'])) {
519 $this->import_listings($data['multipurpose']);
520 }
521
522 if( !empty($data['import_visual_data'])) {
523 $this->import_visual_data($data['multipurpose']);
524 }
525
526 if( !empty($data['import_page_listing_preview'])) {
527 $this->demo_page_listing($data['multipurpose']);
528 }
529
530 if( !empty($data['import_page_results'])) {
531 $this->demo_page_results($data['multipurpose']);
532 }
533
534 $this->replace_content_data($data['multipurpose']);
535
536 $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>';
537
538 $this->data['info_log_message'] = apply_filters('wdk/settings/import/run/info_log_message', $this->data['info_log_message'] , $data);
539
540 do_action('wdk/settings/import/run', $data);
541 update_option('wdk_install_images_sizes_disable', 0);
542 }
543
544 $this->load->view('wdk_install/index', $this->data);
545 }
546
547 // Import demo data listing method
548 public function remove()
549 {
550
551 wdk_access_check('settings_m', 1);
552
553 // Check _wpnonce
554 check_admin_referer( 'remove-data', '_wpnonce' );
555
556 $this->load->model('field_m');
557 $this->load->model('listingfield_m');
558 $this->load->model('listing_m');
559 $this->load->model('category_m');
560 $this->load->model('location_m');
561
562 $this->data['data_log'] = '';
563
564 $this->load->model('location_m');
565 $this->load->model('category_m');
566 $this->load->model('field_m');
567 $this->load->model('listingfield_m');
568 $this->load->model('listing_m');
569 $this->load->model('resultitem_m');
570 $this->load->model('searchform_m');
571 $this->load->model('dependfields_m');
572
573 /* remove fields */
574 $this->db->delete($this->location_m->_table_name);
575
576 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed').'</div>';
577 /* end remove fields */
578
579 /* remove fields */
580 $this->db->delete($this->category_m->_table_name);
581 $this->db->delete($this->dependfields_m->_table_name);
582
583 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed').'</div>';
584 /* end remove fields */
585
586 /* remove fields */
587 $this->db->delete($this->field_m->_table_name);
588 $field_names = $this->listingfield_m->get_available_fields();
589 foreach($field_names as $field_name => $value){
590 if(strpos($field_name, 'field_') ===FALSE) continue;
591 $this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.'');
592 }
593
594 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed').'</div>';
595 /* end remove fields */
596
597 /* remove listings */
598 $this->db->delete($this->listing_m->_table_name);
599 $this->db->delete($this->listingfield_m->_table_name);
600
601 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed').'</div>';
602 /* end remove listings */
603
604
605 /* remove listings */
606 $this->db->delete($this->resultitem_m->_table_name);
607 $this->db->delete($this->searchform_m->_table_name);
608 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed').'</div>';
609 /* end remove listings */
610
611
612 /* reset autoincrement */
613 $this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`');
614 $this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`');
615 $this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`');
616 $this->db->query('TRUNCATE TABLE `'.$this->dependfields_m->_table_name.'`');
617 $this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`');
618 $this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`');
619 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
620 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
621
622 $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset').'</div>';
623 /* end reset autoincrement */
624
625 $wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1));
626 foreach( $wdk_posts as $post ) {
627 // Delete's each post.
628 wp_delete_post( $post->ID, true);
629 // Set to False if you want to send them to Trash.
630 }
631
632 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE){
633 if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') {
634 $redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated&multipurpose=".wmvc_show_data('multipurpose', $_GET, ''));
635 } else {
636 $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
637 }
638 wp_redirect($redirect_url);
639 }
640
641 $this->load->view('wdk_install/remove_log', $this->data);
642 }
643
644 /* add demo pages */
645 private function demo_pages($purpose = '') {
646
647 if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true;
648
649 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
650 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
651 });
652
653 add_action('wpdirectorykit/elementor-elements/register_widget', function(){
654 add_action('eli/includes', function(){
655 require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php';
656 });
657
658 add_action('eli/register_widget', function(){
659 $object = new Wdk\Elementor\Extensions\WdkContactFormExt();
660 \Elementor\Plugin::instance()->widgets_manager->register( $object );
661 });
662 });
663
664 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
665 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel');
666 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue');
667 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages');
668 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon');
669 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings');
670 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider');
671 $self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection');
672 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
673 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
674 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
675 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
676 });
677
678
679 // Import elementor templates
680 $page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas');
681 $this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json');
682
683 $page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas');
684 $this->elementor_assign($page_results->ID, 'page-results-listings.json');
685
686
687 $menus = get_registered_nav_menus();
688 // first menu defined by template
689 $first_menu = key($menus);
690
691 if ( has_nav_menu($first_menu) ) {
692 $menus = wp_get_nav_menus();
693 $menu_id = (int)$menus[0]->term_id;
694 } else {
695 wp_delete_nav_menu('Primary menu');
696 $menu_name = 'Primary menu';
697 $menu_exists = wp_get_nav_menu_object( $menu_name );
698 $menu_term = $menu_exists;
699 $menu_id = wp_create_nav_menu($menu_name);
700 }
701
702 // first menu defined by template
703 if (!empty($menu_id)) {
704 $itemData = array(
705 'menu-item-object-id' => $page_results->ID,
706 'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'),
707 'menu-item-parent-id' => 0,
708 'menu-item-position' => 3,
709 'menu-item-object' => 'page',
710 'menu-item-type' => 'post_type',
711 'menu-item-status' => 'publish'
712 );
713
714 wp_update_nav_menu_item((int)$menu_id, 0, $itemData);
715
716 // assign menu to top menu
717 $locations = get_theme_mod( 'nav_menu_locations' );
718 $locations[$first_menu] = $menu_id;
719 set_theme_mod('nav_menu_locations', $locations);
720 }
721
722 // Assign page.
723 update_option( 'show_on_front', 'page' );
724 update_option( 'page_on_front', $page_results->ID );
725
726 if($page_listing_preview)
727 update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE);
728
729 if($page_results)
730 update_option( 'wdk_results_page', $page_results->ID, TRUE);
731
732 $this->replace_content_data($purpose);
733
734 return true;
735 }
736
737
738 private function add_demo_user($username, $name, $surname, $email_address='', $type='wdk_agent', $password=NULL, $meta_data = array())
739 {
740
741 if ( username_exists( $username )) {
742 return username_exists( $username );
743 }
744
745 if ( email_exists($email_address)) {
746 return email_exists($email_address);
747 }
748
749 if ( empty($email_address)) {
750 return false;
751 }
752
753 // Generate the password and create the user
754 if(empty($password))
755 $password = wp_generate_password( 12, false );
756
757 $user_id = wp_create_user( $username, $password, $email_address );
758
759 // Set the nickname
760 wp_update_user(
761 array(
762 'ID' => $user_id,
763 'nickname' => $name.' '.$surname,
764 'first_name' => $name,
765 'last_name' => $surname,
766 'description' => 'Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet maurs. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odi non mauris vitae erat consequat Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit.',
767 'display_name'=> $name.' '.$surname,
768 'user_url' => '' ,
769 'admin_bar_front' => 0 ,
770 'wdk_phone' => '123456789'
771 )
772 );
773
774 $user = new WP_User( $user_id );
775 $user->set_role($type);
776
777 if(!empty($meta_data))
778 foreach ($meta_data as $meta_key => $meta_value){
779 update_user_meta( $user_id, $meta_key, wmvc_xss_clean($meta_value) );
780 }
781
782 update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
783 update_user_meta( $user_id, 'show_admin_bar_admin', 'false' );
784
785 return $user_id;
786 }
787
788 private function replace_content_data($purpose = '') {
789 /* Replace Links */
790 /* login */
791 $from = 'https://www.wpdirectorykit.com/nexproperty/wp-admin/wp-login.php';
792 $to = get_admin_url();
793 $this->replace_meta($from, $to);
794
795
796 $from = 'https://www.wpdirectorykit.com/nexproperty';
797 $to = get_home_url();
798 $this->replace_meta($from, $to);
799
800 /* homepage */
801 $from = '2020';
802 $to = date('Y');
803 $this->replace_meta($from, $to);
804
805
806 /* replace in db */
807 if(file_exists($this->import_xml_file)) {
808 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
809 if(isset($dom_array['replace']) && !empty($dom_array['replace'])) {
810 if(!empty($dom_array['replace']['text'])) {
811 foreach($dom_array['replace']['text'] as $string){
812 if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue;
813 if(empty($string['@attributes']['from']) || empty( $string['@attributes']['to'])) continue;
814 $this->replace_meta($string['@attributes']['from'], $string['@attributes']['to']);
815 }
816 }
817 } else {
818
819 }
820 }
821 return true;
822
823 }
824
825 /* add demo listing preview page */
826 private function demo_page_listing($purpose = '') {
827
828 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
829 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists').'</div>';
830 return false;
831 }
832
833 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
834 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
835 });
836
837 add_action('wpdirectorykit/elementor-elements/register_widget', function(){
838 add_action('eli/includes', function(){
839 require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php';
840 });
841
842 add_action('eli/register_widget', function(){
843 $object = new Wdk\Elementor\Extensions\WdkContactFormExt();
844 \Elementor\Plugin::instance()->widgets_manager->register( $object );
845 });
846 });
847
848 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
849 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel');
850 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue');
851 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages');
852 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon');
853 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings');
854 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider');
855 $self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection');
856 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
857 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
858 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
859 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
860 });
861
862 // Import elementor templates
863 $page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas');
864 $this->elementor_assign($page_listing_preview->ID, 'page-listing-preview.json');
865
866 // Assign page.
867 if($page_listing_preview)
868 update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE);
869
870 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported').'</div>';
871
872 return true;
873 }
874
875 /* add demo results page */
876 private function demo_page_results($purpose = '') {
877
878 if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){
879 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists').'</div>';
880 return false;
881 }
882
883 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
884 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
885 });
886
887 add_action('wpdirectorykit/elementor-elements/register_widget', function(){
888 add_action('eli/includes', function(){
889 require_once WPDIRECTORYKIT_PATH . '/elementor-extensions/class-contact-form.php';
890 });
891
892 add_action('eli/register_widget', function(){
893 $object = new Wdk\Elementor\Extensions\WdkContactFormExt();
894 \Elementor\Plugin::instance()->widgets_manager->register( $object );
895 });
896 });
897
898 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
899 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldLabel');
900 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldValue');
901 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldImages');
902 $self->add_widget('Wdk\Elementor\Widgets\WdkFieldIcon');
903 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSimilarListings');
904 $self->add_widget('Wdk\Elementor\Widgets\WdkListingSlider');
905 $self->add_widget('Wdk\Elementor\Widgets\WdkListingFieldsSection');
906 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
907 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
908 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
909 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
910 });
911
912 $page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas');
913 $this->elementor_assign($page_results->ID, 'page-results-listings.json');
914
915 // Assign page.
916 update_option( 'show_on_front', 'page' );
917 update_option( 'page_on_front', $page_results->ID );
918
919 update_option( 'wdk_results_page', $page_results->ID, TRUE);
920
921 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported').'</div>';
922
923
924 $menus = get_registered_nav_menus();
925 // first menu defined by template
926 $first_menu = key($menus);
927
928 if ( has_nav_menu($first_menu) ) {
929 $menus = wp_get_nav_menus();
930 $menu_id = (int)$menus[0]->term_id;
931 } else {
932 wp_delete_nav_menu('Primary menu');
933 $menu_name = 'Primary menu';
934 $menu_exists = wp_get_nav_menu_object( $menu_name );
935 $menu_term = $menu_exists;
936 $menu_id = wp_create_nav_menu($menu_name);
937 }
938
939 // first menu defined by template
940 if (!empty($menu_id)) {
941 $itemData = array(
942 'menu-item-object-id' => $page_results->ID,
943 'menu-item-title' => esc_html__('Grid Map', 'wpdirectorykit'),
944 'menu-item-parent-id' => 0,
945 'menu-item-position' => 3,
946 'menu-item-object' => 'page',
947 'menu-item-type' => 'post_type',
948 'menu-item-status' => 'publish'
949 );
950
951 wp_update_nav_menu_item((int)$menu_id, 0, $itemData);
952
953 // assign menu to top menu
954 $locations = get_theme_mod( 'nav_menu_locations' );
955 $locations[$first_menu] = $menu_id;
956 set_theme_mod('nav_menu_locations', $locations);
957 }
958
959 return true;
960 }
961
962 /* Create Page */
963 private function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
964 {
965 $post = wdk_page_by_title($post_title, 'OBJECT', 'page' );
966
967 $post_id = NULL;
968
969 // Delete posts and rebuild
970 if(!empty($post))
971 {
972 wp_delete_post($post->ID, true);
973 $post=NULL;
974 }
975
976 if(!empty($post))
977 $post_id = $post->ID;
978
979 if(empty($post_id))
980 {
981 $error_obj = NULL;
982 $post_insert = array(
983 'post_title' => wp_strip_all_tags( $post_title ),
984 'post_content' => $post_content,
985 'post_status' => 'publish',
986 'post_type' => 'page',
987 'post_author' => get_current_user_id(),
988 'post_category' => array(1,2),
989 'page_template' => $post_template,
990 'post_parent' => $post_parent
991 );
992 $post_id = wp_insert_post( $post_insert, $error_obj );
993 }
994
995 $post_insert = get_post( $post_id );
996
997 return $post_insert;
998 }
999
1000 /* Elementor Import Template */
1001 private function elementor_assign($page_id, $json_template_name = '')
1002 {
1003
1004 $file = false;
1005
1006 if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name))
1007 {
1008 $file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name;
1009 }
1010 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name))
1011 {
1012 $file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name;
1013 }
1014 elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name))
1015 {
1016 $file = WPDIRECTORYKIT_PATH.'demo-data/'.$json_template_name;
1017 }
1018
1019 if(!$file || !class_exists('Elementor\Plugin'))
1020 {
1021 return false;
1022 }
1023
1024 $page_template = get_page_template_slug( $page_id );
1025
1026 add_post_meta( $page_id, '_elementor_edit_mode', 'builder' );
1027
1028 global $wp_filesystem;
1029 // Initialize the WP filesystem, no more using 'file-put-contents' function
1030 if (empty($wp_filesystem)) {
1031 WP_Filesystem();
1032 }
1033
1034 $string = $wp_filesystem->get_contents($file);
1035
1036 $json_template = json_decode($string, true);
1037 $elements = $json_template['content'];
1038
1039 $data = array(
1040 'elements' => $elements,
1041 'settings' => array('post_status'=>'autosave', 'template'=>$page_template),
1042 );
1043 // @codingStandardsIgnoreStart
1044 $document = Elementor\Plugin::$instance->documents->get( $page_id, false );
1045 // @codingStandardsIgnoreEnd
1046 return $document->save( $data );
1047 }
1048
1049 private function import_visual_data($purpose = '') {
1050 $this->load->model('searchform_m');
1051 $this->load->model('resultitem_m');
1052 $this->load->model('field_m');
1053
1054 if($this->searchform_m->get() || $this->resultitem_m->get()){
1055 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Search and result card already imported', 'wpdirectorykit').'</div>';
1056 return false;
1057 }
1058
1059 /* remove listings */
1060 $this->db->delete($this->resultitem_m->_table_name);
1061 $this->db->delete($this->searchform_m->_table_name);
1062 /* end remove listings */
1063
1064 /* reset autoincrement */
1065 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
1066 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
1067
1068 if(file_exists($this->import_xml_file)) {
1069 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1070
1071 if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) {
1072 } else {
1073 // Save searchform_m
1074 $data = array();
1075 $data['searchform_name'] = 'Primary';
1076 $data['searchform_json'] = trim($dom_array['search_form']);
1077
1078 if (function_exists('run_wdk_bookings') && isset($dom_array['search_form_premium']) && !empty($dom_array['search_form_premium'])) {
1079 $data['searchform_json'] = trim($dom_array['search_form_premium']);
1080 }
1081
1082 $data['idsearchform'] = 1;
1083 $insert_id = $this->searchform_m->insert($data, NULL);
1084 }
1085
1086 if(!isset($dom_array['resultitem']) && empty($dom_array['resultitem'])) {
1087 } else {
1088 // Save searchform_m
1089 $data = array();
1090 $data['resultitem_name'] = 'Primary';
1091 $data['resultitem_json'] = trim($dom_array['resultitem']);
1092 $data['idresultitem'] = 1;
1093 $insert_id = $this->resultitem_m->insert($data, NULL);
1094 }
1095
1096 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported').'</div>';
1097 return true;
1098 }
1099
1100 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1101 return false;
1102
1103 }
1104
1105 private function import_locations() {
1106 $this->load->model('location_m');
1107
1108 if($this->location_m->get()){
1109 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
1110 return false;
1111 }
1112
1113 if(file_exists($this->import_xml_file_locations)) {
1114 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file_locations));
1115 if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) {
1116 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$this->import_xml_file_locations, 'wpdirectorykit').'</div>';
1117 return false;
1118 }
1119 foreach ($dom_array['locations']['location'] as $key => $location_data) {
1120 $this->_recursive_add_locations($location_data);
1121 }
1122
1123 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported').'</div>';
1124 return true;
1125 }
1126
1127 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$this->import_xml_file_locations, 'wpdirectorykit').'</div>';
1128 return false;
1129 }
1130
1131 private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) {
1132 $base = array(
1133 'location_title' => '',
1134 'parent_id' => $parent_id,
1135 'order_index' => '',
1136 'level' => $level,
1137 'font_icon_code' => '',
1138 'image_id' => '',
1139 'icon_id' => '',
1140 'code' => '',
1141 );
1142 $location_data = array_intersect_key(array_merge($base, $data), $base);
1143 array_walk($location_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1144
1145 if(empty(wmvc_show_data('location_title', $location_data))) {
1146 return false;
1147 }
1148
1149 if(!empty($location_data['image_id']) && file_exists($this->import_images_dir.$location_data['image_id'])){
1150 /* add files */
1151 $location_data['image_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['image_id']);
1152 }
1153
1154 if(!empty($location_data['icon_id']) && file_exists($this->import_images_dir.$location_data['icon_id'])){
1155 /* add files */
1156 $location_data['icon_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['icon_id']);
1157 }
1158
1159 $location_data['icon_path'] = wdk_generate_path_image($location_data['icon_id']);
1160 $location_data['image_path'] = wdk_generate_path_image($location_data['image_id']);
1161
1162 /* add locations */
1163 $insert_id = $this->location_m->insert($location_data, NULL);
1164 if(isset($data['childs']["location"]) && !empty($data['childs']["location"])) {
1165 foreach ($data['childs']["location"] as $sub_location_data) {
1166 $this->_recursive_add_locations($sub_location_data, $insert_id, ($level+1));
1167 }
1168 }
1169 }
1170
1171 private function import_categories($purpose = '') {
1172 $this->load->model('category_m') ;
1173 $this->load->model('dependfields_m') ;
1174
1175 if($this->category_m->get()){
1176 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
1177 return false;
1178 }
1179
1180 if(file_exists($this->import_xml_file)) {
1181 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1182 if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) {
1183 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1184 return false;
1185 }
1186
1187 foreach ($dom_array['categories']['category'] as $key => $category_data) {
1188 $this->_recursive_add_categories($category_data);
1189 }
1190
1191 /* indexes by new order and reorder */
1192 $results = $this->category_m->get_tree_table();
1193 $values = array();
1194 $order_index = 1;
1195 foreach( $results as $item)
1196 {
1197 $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
1198 $order_index++;
1199 }
1200 $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
1201
1202 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported').'</div>';
1203 return true;
1204 }
1205
1206 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1207 return false;
1208 }
1209
1210 private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) {
1211 $base = array(
1212 'category_title' => '',
1213 'parent_id' => $parent_id,
1214 'order_index' => '',
1215 'level' => $level,
1216 'font_icon_code' => '',
1217 'image_id' => '',
1218 'icon_id' => '',
1219 'code' => '',
1220 );
1221
1222 $category_data = array_intersect_key(array_merge($base, $data), $base);
1223 array_walk($category_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1224
1225 if(empty(wmvc_show_data('category_title', $category_data))) {
1226 return false;
1227 }
1228
1229 if(!empty($category_data['image_id'])){
1230
1231 $file = false;
1232 if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id']))
1233 {
1234 $file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['image_id'];
1235 }
1236 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']))
1237 {
1238 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'];
1239 }
1240 elseif(file_exists( $this->import_images_dir.$category_data['image_id']))
1241 {
1242 $file = $this->import_images_dir.$category_data['image_id'];
1243 }
1244 /* add files */
1245
1246 if($file)
1247 $category_data['image_id'] = wmvc_add_wp_image($file);
1248 }
1249
1250 if(!empty($category_data['icon_id'])){
1251 /* add files */
1252 $file = false;
1253 if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id']))
1254 {
1255 $file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/images/'.$category_data['icon_id'];
1256 }
1257 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']))
1258 {
1259 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'];
1260 }
1261 elseif(file_exists( $this->import_images_dir.$category_data['icon_id']))
1262 {
1263 $file = $this->import_images_dir.$category_data['icon_id'];
1264 }
1265 /* add files */
1266
1267 if($file)
1268 $category_data['icon_id'] = wmvc_add_wp_image($file);
1269 }
1270
1271 $category_data['icon_path'] = wdk_generate_path_image($category_data['icon_id']);
1272 $category_data['image_path'] = wdk_generate_path_image($category_data['image_id']);
1273
1274 /* add categories */
1275 $insert_id = $this->category_m->insert($category_data, NULL);
1276
1277 if(isset($data['hidden_fields_list']) && !empty($data['hidden_fields_list'])) {
1278 $data_insert = array(
1279 'main_field' => 'categories',
1280 'field_id' => $insert_id,
1281 'hidden_fields_list' => $data['hidden_fields_list'],
1282 );
1283
1284 $this->dependfields_m->delete_where(array('field_id' => $insert_id, 'main_field' => 'categories'));
1285 $this->dependfields_m->insert($data_insert);
1286 }
1287
1288
1289 if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) {
1290 foreach ($data['childs']["category"] as $sub_category_data) {
1291 $this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1));
1292 }
1293 }
1294 }
1295
1296 private function import_fields($purpose = '') {
1297 $this->load->model('field_m');
1298 $this->load->model('listingfield_m');
1299
1300 if($this->field_m->get()){
1301 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>';
1302 return false;
1303 }
1304
1305 $sections_added_array = array();
1306 if(file_exists($this->import_xml_file)) {
1307 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1308
1309 $base = array(
1310 'field_type' => '',
1311 'field_label' => '',
1312 'hint' => '',
1313 'columns_number' => '',
1314 'is_visible_frontend' => '1',
1315 'is_visible_dashboard' => '1',
1316 'prefix' => '',
1317 'suffix' => '',
1318 'values_list' => '',
1319 'icon_id' => '',
1320 'is_required' => '',
1321 'order_index' => '',
1322 );
1323
1324 if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) {
1325 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1326 return false;
1327 }
1328
1329 foreach ($dom_array['fields']['field'] as $key => $field) {
1330 $field_data = array_intersect_key(array_merge($base, $field), $base);
1331 array_walk($field_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1332
1333 if(empty(wmvc_show_data('field_type', $field_data)) || empty(wmvc_show_data('field_label', $field_data))) {
1334 continue;
1335 }
1336
1337 $field_data['is_visible_frontend'] = 1;
1338 $field_data['is_visible_dashboard'] = 1;
1339
1340
1341 /* special set number format for price fields */
1342 if($field_data['field_label'] == 'Rent Price' || $field_data['field_label'] == 'Sale Price') {
1343 $field_data['is_price_format'] = 1;
1344 }
1345
1346 if(!in_array($field['section'], $sections_added_array)) {
1347 /* add section */
1348 $section_data = array(
1349 'field_type' => 'SECTION',
1350 'field_label' => $field['section'],
1351 'columns_number' => '12',
1352 'is_visible_frontend' => '1',
1353 'is_visible_dashboard' => '1',
1354 'order_index' => $field['order_index'],
1355 );
1356 /* add field */
1357
1358 if($section_data['field_label'] == 'SEO') {
1359 $section_data['is_visible_frontend'] = 0;
1360 }
1361
1362 $this->field_m->insert($section_data, NULL);
1363
1364 $sections_added_array[] = $field['section'];
1365 }
1366
1367 /* add field */
1368
1369 if($field_data['field_label'] == 'Keywords' || $field_data['field_label'] == 'Short Description') {
1370 $field_data['is_visible_frontend'] = 0;
1371 }
1372
1373 $insert_id = $this->field_m->insert($field_data, NULL);
1374 // check if column exists, add if nto exists
1375 if(!empty($insert_id))
1376 $this->listingfield_m->create_table_column($field_data, $insert_id);
1377 }
1378
1379 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported').'</div>';
1380 return true;
1381 }
1382
1383 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1384 return false;
1385 }
1386
1387 private function import_listings($purpose = '') {
1388 $this->load->model('field_m');
1389 $this->load->model('listingfield_m');
1390 $this->load->model('listing_m');
1391 $this->load->model('category_m');
1392 $this->load->model('location_m');
1393 $this->load->model('listingusers_m');
1394
1395 if($this->listing_m->get()){
1396 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listings already imported', 'wpdirectorykit').'</div>';
1397 return false;
1398 }
1399
1400 /* generate listings */
1401 $categories_list = $this->category_m->get();
1402 $locations_list = $this->location_m->get();
1403 $categories = array();
1404 $locations = array();
1405 if($categories_list)
1406 foreach($categories_list as $category){
1407 $categories[] = $category->idcategory;
1408 }
1409 if($locations_list)
1410 foreach($locations_list as $location){
1411 $locations[] = $location->idlocation;
1412 }
1413
1414 $this->db->where(array('field_type !='=> 'SECTION'));
1415 $fields = $this->field_m->get();
1416
1417 $listingfield_list = $this->listingfield_m->get_available_fields();
1418 foreach($fields as $key => $field_data) {
1419 if(!isset($listingfield_list['field_'.$field_data->idfield.'_'.$field_data->field_type])) {
1420 unset($fields[$key]);
1421 }
1422 }
1423
1424 // Open a known directory, and proceed to read its contents
1425 $purpose_name = str_replace('.xml','',$purpose);
1426 $files = array();
1427 if (is_dir($this->import_images_dir)) {
1428 if ($dh = opendir($this->import_images_dir)) {
1429 while (($file = readdir($dh)) !== false) {
1430 if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false)
1431 $files[] = $file;
1432 }
1433 closedir($dh);
1434 }
1435 }
1436 sort($files);
1437
1438 if(file_exists($this->import_xml_file)) {
1439 $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1440 if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) {
1441 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No listings in xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1442 return false;
1443 }
1444
1445 /* demo agent add/get if exists */
1446 $user_ids = array();
1447 $user_ids[] = $this->add_demo_user('Debra_Moran', 'Debra', 'Moran', 'agent1@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(917) 367-2058','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#'));
1448 $user_ids[] = $this->add_demo_user('Garry_Novan', 'Garry', 'Novan', 'agent2@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(918) 345-2054','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#'));
1449 $user_ids[] = $this->add_demo_user('Kety_Spear', 'Kety', 'Spear', 'agent3@wpdirectorykit.com','wdk_agent', NULL, array('wdk_phone' =>'(919) 854-2056','wdk_facebook'=>'#','wdk_linkedin'=>'#','wdk_instagram'=>'#','wdk_telegram'=>'#','wdk_twitter'=>'#'));
1450
1451 foreach ($dom_array['listings']['listing'] as $listing_num => $listing) {
1452 $location_id = '';
1453 $category_id = '';
1454
1455 if(!empty($categories))
1456 $category_id = $categories[rand(0, count($categories)-1)];
1457
1458 if(!empty($location))
1459 $location_id = $locations[rand(0, count($locations)-1)];
1460
1461 $data_listing = array(
1462 'post_title' => '',
1463 'post_content' => '',
1464 'category_id' => $category_id,
1465 'location_id' => $location_id,
1466 'address' => '',
1467 'lat' => '',
1468 'listing_images' => '',
1469 'listing_images_path' => '',
1470 'listing_images_path_medium' => '',
1471 'date_modified' => date('Y-m-d H:i:s'),
1472 'lng' => '',
1473 'is_featured' => '',
1474 'is_activated' => '1',
1475 'is_approved' => '1',
1476 'counter_views' => rand(20,250),
1477 'user_id_editor' => NULL,
1478 );
1479
1480 $data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing);
1481 array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1482
1483 if(empty(wmvc_show_data('post_title', $data_listing))) {
1484 continue;
1485 }
1486
1487 $hidden_fields_list = wdk_depend_get_hidden_fields($data_listing['category_id']);
1488
1489 /*fields */
1490 $data_listings_fields = array();
1491 foreach($fields as $field_data) {
1492 if(!empty($hidden_fields_list) && strpos(','.$hidden_fields_list.',', ','.$field_data->idfield.',')!==FALSE) {
1493 continue;
1494 }
1495
1496 if(isset($listing['field_'.$field_data->idfield])) {
1497 $data_listings_fields['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1498 } else {
1499 if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE')
1500 {
1501 if(empty($field_data->values_list)) continue;
1502 $values = explode(',', $field_data->values_list);
1503 if(count($values) > 0)
1504 {
1505 $start=0;
1506 if(empty($values[0]))$start=1;
1507 $data_listings_fields['field_'.$field_data->idfield] = $values[rand($start, count($values)-1)];
1508 }
1509 }
1510 elseif($field_data->field_type == 'NUMBER')
1511 {
1512 $data_listings_fields['field_'.$field_data->idfield] = rand(2,499);
1513
1514 }
1515 elseif($field_data->field_type == 'CHECKBOX')
1516 {
1517 $data_listings_fields['field_'.$field_data->idfield] = rand(0,1);
1518 }
1519 elseif($field_data->field_type == 'TEXTAREA')
1520 {
1521 //$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.';
1522 }
1523 }
1524 }
1525
1526 /* add files */
1527
1528 if($purpose == 'car-dealer.xml') {
1529 $this->import_count_images = 1;
1530 }
1531 if(isset($listing['images']) && !empty($listing['images'])) {
1532
1533 foreach (explode(',', $listing['images']) as $key => $file_name) {
1534
1535 if(empty($file_name)) continue;
1536
1537 if(!empty($data_listing['listing_images']))
1538 $data_listing['listing_images'].= ',';
1539 $image_id = wmvc_add_wp_image($this->import_images_dir.esc_html($file_name));
1540
1541 $data_listing['listing_images'] .= $image_id;
1542
1543 $image_path = wp_get_original_image_path( $image_id);
1544
1545 if($image_path) {
1546 /* path of image */
1547 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1548
1549 /* check length listing_images_path + next image + comma, should be less 200*/
1550 if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1551 if(!empty($data_listing['listing_images_path']))
1552 $data_listing['listing_images_path'] .= ',';
1553
1554 $data_listing['listing_images_path'] .= $next_path;
1555 }
1556 }
1557
1558 $image_url = wp_get_attachment_image_url($image_id, 'large');
1559 if($image_url) {
1560 $parsed = parse_url($image_url);
1561 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
1562
1563 if(!empty($data_listing['listing_images_path_medium']))
1564 $data_listing['listing_images_path_medium'] .= ',';
1565
1566 $data_listing['listing_images_path_medium'] .= $next_path;
1567 }
1568 }
1569
1570 } else {
1571 /* auto import images */
1572 for ($i=0,$image_num=$listing_num; $i<$this->import_count_images; $i++,$image_num++) {
1573 if($image_num >= count($files))
1574 $image_num = 0;
1575
1576 if(!empty($data_listing['listing_images']))
1577 $data_listing['listing_images'].= ',';
1578
1579 if(!isset($files[$image_num])) continue;
1580
1581 $image_id = wmvc_add_wp_image($this->import_images_dir.esc_html($files[$image_num]));
1582 $data_listing['listing_images'] .= $image_id;
1583
1584 $image_path = wp_get_original_image_path( $image_id);
1585
1586 if($image_path) {
1587 /* path of image */
1588 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1589
1590 /* check length listing_images_path + next image + comma, should be less 200*/
1591 if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1592 if(!empty($data_listing['listing_images_path']))
1593 $data_listing['listing_images_path'] .= ',';
1594
1595 $data_listing['listing_images_path'] .= $next_path;
1596 }
1597 }
1598
1599 $image_url = wp_get_attachment_image_url($image_id, 'large');
1600 if($image_url) {
1601 $parsed = parse_url($image_url);
1602 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
1603
1604 if(!empty($data_listing['listing_images_path_medium']))
1605 $data_listing['listing_images_path_medium'] .= ',';
1606
1607 $data_listing['listing_images_path_medium'] .= $next_path;
1608 }
1609 }
1610 }
1611
1612 // Create post object
1613 $listing_post = array(
1614 'ID' => NULL,
1615 'post_type' => 'wdk-listing',
1616 'post_title' => wp_strip_all_tags( $data_listing['post_title'] ),
1617 'post_content' => $data_listing['post_content'],
1618 'post_status' => 'publish',
1619 'post_author' => get_current_user_id()
1620 );
1621 // Insert the post into the database
1622 $id = wp_insert_post( $listing_post );
1623
1624 $listing_data = array('post_id' => $id);
1625 $listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images', 'is_featured', 'is_activated','is_approved','listing_images_path', 'listing_images_path_medium');
1626 foreach($listing_data_fields as $field_name)
1627 {
1628 if(isset( $data_listing[$field_name]))
1629 $listing_data[$field_name] = $data_listing[$field_name];
1630 }
1631 $listing_data['user_id_editor'] = $user_ids[array_rand($user_ids)];
1632 $listing_data['date_modified'] = date('Y-m-d H:i:s');
1633 $listing_data['counter_views'] = rand(20,250);
1634
1635 $this->listing_m->insert($listing_data, NULL);
1636
1637 $data_listings_fields['post_id'] = $id;
1638 $this->listingfield_m->insert_custom_fields($fields, $data_listings_fields, NULL);
1639 }
1640
1641 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>';
1642 return true;
1643 }
1644
1645 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$this->import_xml_file, 'wpdirectorykit').'</div>';
1646 return false;
1647 }
1648
1649 protected function xmlstr_to_array($xmlstr) {
1650 $doc = new DOMDocument();
1651
1652 if ( !@$doc->loadXML($xmlstr) ) {
1653 return false;
1654 }
1655
1656 $root = $doc->documentElement;
1657 $output = $this->domnode_to_array($root);
1658 $output['@root'] = $root->tagName;
1659 return $output;
1660 }
1661
1662 protected function domnode_to_array($node) {
1663 $output = array();
1664 switch ($node->nodeType) {
1665 case XML_CDATA_SECTION_NODE:
1666 case XML_TEXT_NODE:
1667 $output = trim($node->textContent);
1668 break;
1669 case XML_ELEMENT_NODE:
1670 for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) {
1671 $child = $node->childNodes->item($i);
1672 $v = $this->domnode_to_array($child);
1673 if(isset($child->tagName)) {
1674 $t = $child->tagName;
1675 if(!isset($output[$t])) {
1676 $output[$t] = array();
1677 }
1678 $output[$t][] = $v;
1679 }
1680 elseif($v || $v === '0') {
1681 $output = (string) $v;
1682 }
1683 }
1684 if($node->attributes->length && !is_array($output)) { //Has attributes but isn't an array
1685 $output = array('@content'=>$output); //Change output into an array.
1686 }
1687 if(is_array($output)) {
1688 if($node->attributes->length) {
1689 $a = array();
1690 foreach($node->attributes as $attrName => $attrNode) {
1691 $a[$attrName] = (string) $attrNode->value;
1692 }
1693 $output['@attributes'] = $a;
1694 }
1695 foreach ($output as $t => $v) {
1696 if(is_array($v) && count($v)==1 && $t!='@attributes') {
1697 $output[$t] = $v[0];
1698 }
1699 }
1700 }
1701 break;
1702 }
1703 return $output;
1704 }
1705
1706 public function run()
1707 {
1708 wdk_access_check('settings_m', 1);
1709
1710 // Check _wpnonce
1711 check_admin_referer( 'wdk-import-data-run', '_wpnonce' );
1712 update_option('wdk_install_images_sizes_disable', 1);
1713
1714 ini_set('max_execution_time', 900);
1715 $this->data['import_log'] = '';
1716 $multipurpose = 'real-estate.xml';
1717 if(isset($_GET['multipurpose']))
1718 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1719
1720 $redirect_url = admin_url("admin.php?page=wdk_fields&is_updated");
1721 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
1722 $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
1723
1724 $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$multipurpose;
1725 $this->import_images_dir = apply_filters('wdk/settings/import/api_run/import_images_dir', $this->import_images_dir, $multipurpose);
1726 $this->import_xml_file = apply_filters('wdk/settings/import/api_run/import_xml_file', $this->import_xml_file, $multipurpose);
1727 $this->import_xml_file_locations = apply_filters('wdk/settings/import/api_run/import_xml_file_locations', $this->import_xml_file_locations, $multipurpose);
1728
1729
1730 $this->import_locations();
1731 $this->import_categories($multipurpose);
1732 $this->import_fields($multipurpose);
1733 $this->import_listings($multipurpose);
1734 $this->import_visual_data($multipurpose);
1735 $this->demo_pages($multipurpose);
1736
1737 $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>');
1738
1739 do_action('wpdirectorykit/install/api');
1740 do_action('wdk/settings/import/api_run', $multipurpose);
1741 update_option('wdk_install_images_sizes_disable', 0);
1742
1743 wp_redirect($redirect_url.'&message='.$message);
1744 exit;
1745 }
1746
1747 public function api_import()
1748 {
1749 wdk_access_check('settings_m', 1);
1750 update_option('wdk_install_images_sizes_disable', 1);
1751 /* block url access */
1752 if(
1753 (isset($_GET['function']) && $_GET['function'] == 'api_import' ) ||
1754 (isset($_POST['function']) && $_POST['function'] == 'api_import' )
1755 ) {
1756 echo esc_html__('Security blocked', 'wpdirectorykit');
1757 exit();
1758 }
1759
1760 ini_set('max_execution_time', 900);
1761 $this->data['import_log'] = '';
1762 $multipurpose = 'real-estate.xml';
1763 if(isset($_GET['multipurpose']))
1764 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1765
1766
1767 $this->import_xml_file = WPDIRECTORYKIT_PATH.'demo-data/'.$multipurpose;
1768 $this->import_images_dir = apply_filters('wdk/settings/import/api_run/import_images_dir', $this->import_images_dir, $multipurpose);
1769 $this->import_xml_file = apply_filters('wdk/settings/import/api_run/import_xml_file', $this->import_xml_file, $multipurpose);
1770 $this->import_xml_file_locations = apply_filters('wdk/settings/import/api_run/import_xml_file_locations', $this->import_xml_file_locations, $multipurpose);
1771
1772 $this->import_locations();
1773 $this->import_categories($multipurpose);
1774 $this->import_fields($multipurpose);
1775 $this->import_listings($multipurpose);
1776 $this->import_visual_data($multipurpose);
1777 $this->import_settings();
1778
1779 /* action */
1780 do_action('wpdirectorykit/install/api');
1781 do_action('wdk/settings/import/api_run', $multipurpose);
1782 update_option('wdk_install_images_sizes_disable', 0);
1783 return true;
1784 }
1785
1786 public function _api_import($import_count_images = 2)
1787 {
1788 $this->import_count_images = $import_count_images;
1789
1790 wdk_access_check('settings_m', 1);
1791 update_option('wdk_install_images_sizes_disable', 1);
1792 ini_set('max_execution_time', 900);
1793 $this->data['import_log'] = '';
1794 $multipurpose = 'real-estate.xml';
1795 if(isset($_GET['multipurpose']))
1796 $multipurpose = sanitize_text_field($_GET['multipurpose']);
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
1803 $this->import_locations();
1804 $this->import_categories($multipurpose);
1805 $this->import_fields($multipurpose);
1806 $this->import_listings($multipurpose);
1807 $this->import_visual_data($multipurpose);
1808 $this->import_settings();
1809
1810 /* action */
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 }
1816
1817 private function replace_meta($from = '', $to = '') {
1818 global $wpdb;
1819 // @codingStandardsIgnoreStart cannot use `$wpdb->prepare` because it remove's the backslashes
1820 $rows_affected = $wpdb->query(
1821 "UPDATE ".esc_sql($wpdb->postmeta)." " .
1822 "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', esc_sql($from) ) . "', '" . str_replace( '/', '\\\/', esc_sql($to) ) . "') " .
1823 "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" );
1824 /* end login */
1825 }
1826
1827 private function import_settings() {
1828 wdk_access_check('settings_m', 1);
1829
1830 update_option( 'wdk_is_category_enabled', '1' );
1831 update_option( 'wdk_is_location_enabled', '1' );
1832 update_option( 'wdk_is_address_enabled', '1' );
1833 update_option( 'wdk_is_results_page_require', '1' );
1834 update_option( 'wdk_seo_description', '2' );
1835 update_option( 'wdk_seo_keywords', '3' );
1836 update_option( 'wdk_card_slider_enable', '1' );
1837 update_option('elementor_load_fa4_shim', 'yes');
1838
1839 /* disable elmentor experement feature */
1840 update_option( 'elementor_experiment-e_font_icon_svg', 'inactive');
1841 update_option( 'elementor_experiment-landing-pages', 'inactive' );
1842 update_option( 'elementor_experiment-e_dom_optimization', 'inactive');
1843
1844 return true;
1845 }
1846
1847 /* add demo listing preview page */
1848 public function create_custom_page($layout_json, $page_title = "New Page", $option = '', $custom_message_title = '') {
1849 $page_title_message = $page_title;
1850 if(!empty($custom_message_title)){
1851 $page_title_message = $custom_message_title;
1852 }
1853
1854 if(!empty($option) && (get_option($option)) && get_post_status(get_option($option)) =='publish'){
1855 // $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.$page_title_message.' '.esc_html__('Page already exists', 'wdk-membership').'</div>';
1856 // return false;
1857 }
1858
1859 add_action('wdk-membership/elementor-elements/register_widget', function($self){
1860 $self->add_widget('WdkMembership\Elementor\Extensions\WdkMembershipContactFormExt');
1861 });
1862
1863 add_action('wdk-membership/elementor-elements/register_widget', function(){
1864 add_action('eli/includes', function(){
1865 require_once WDK_MEMBERSHIP_PATH . '/elementor-extensions/class-contact-form.php';
1866 });
1867
1868 add_action('eli/register_widget', function(){
1869 $object = new WdkMembership\Elementor\Extensions\WdkMembershipContactFormExt();
1870 \Elementor\Plugin::instance()->widgets_manager->register( $object );
1871 });
1872 });
1873
1874 add_action('wdk-membership/elementor-elements/register_widget', function($self){
1875 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipContent');
1876 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipMenu');
1877 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileListings');
1878 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileContent');
1879 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipProfileContent');
1880 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipLoginForm');
1881 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipRegisterForm');
1882 $self->add_widget('WdkMembership\Elementor\Widgets\WdkMembershipBreadcrumb');
1883 });
1884
1885 // Import elementor templates
1886 $page = $this->generate_custom_page($page_title, '', 'elementor_canvas');
1887 $this->elementor_custom_assign($page->ID, $layout_json);
1888
1889 // Assign page.
1890 if($page && !empty($option))
1891 update_option( $option, $page->ID, TRUE);
1892
1893 $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.$page_title_message.' '.esc_html__('Page imported', 'wdk-membership').'</div>';
1894
1895 return $page->ID;
1896 }
1897
1898
1899 /* Create Page */
1900 private function generate_custom_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
1901 {
1902 $post = wdk_page_by_title($post_title, 'OBJECT', 'page' );
1903
1904 $post_id = NULL;
1905
1906 // Delete posts and rebuild
1907 if(!empty($post))
1908 {
1909 wp_delete_post($post->ID, true);
1910 $post=NULL;
1911 }
1912
1913 if(!empty($post))
1914 $post_id = $post->ID;
1915
1916 if(empty($post_id))
1917 {
1918 $error_obj = NULL;
1919 $post_insert = array(
1920 'post_title' => wp_strip_all_tags( $post_title ),
1921 'post_content' => $post_content,
1922 'post_status' => 'publish',
1923 'post_type' => 'page',
1924 'post_author' => get_current_user_id(),
1925 'post_category' => array(1,2),
1926 'page_template' => $post_template,
1927 'post_parent' => $post_parent
1928 );
1929 $post_id = wp_insert_post( $post_insert, $error_obj );
1930 }
1931
1932 $post_insert = get_post( $post_id );
1933
1934 return $post_insert;
1935 }
1936
1937 /* Elementor Import Template */
1938 public function elementor_custom_assign($page_id, $json_template_name = '')
1939 {
1940 $file = false;
1941
1942 if(file_exists( $json_template_name ))
1943 {
1944 $file = $json_template_name;
1945 }
1946
1947 if(!$file || !class_exists('Elementor\Plugin'))
1948 {
1949 return false;
1950 }
1951
1952 $page_template = get_page_template_slug( $page_id );
1953
1954 add_post_meta( $page_id, '_elementor_edit_mode', 'builder' );
1955
1956 global $wp_filesystem;
1957 // Initialize the WP filesystem, no more using 'file-put-contents' function
1958 if (empty($wp_filesystem)) {
1959 WP_Filesystem();
1960 }
1961
1962 $string = $wp_filesystem->get_contents($file);
1963
1964 $json_template = json_decode($string, true);
1965
1966 $elements = $json_template['content'];
1967
1968 $data = array(
1969 'elements' => $elements,
1970 'settings' => array('post_status'=>'autosave', 'template'=>$page_template),
1971 );
1972 // @codingStandardsIgnoreStart
1973 $document = Elementor\Plugin::$instance->documents->get( $page_id, false );
1974 // @codingStandardsIgnoreEnd
1975 return $document->save( $data );
1976 }
1977
1978 }
1979