PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
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.4.8, at application/controllers/Wdk_settings.php

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