PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / application / controllers / Wdk_settings.php

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

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