PluginProbe
WP Directory Kit / 1.5.6
WP Directory Kit v1.5.6
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
wpdirectorykit / application / controllers / Wdk_settings.php

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

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