PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
← All changes | application/controllers/Wdk_settings.php +732 -470 1.1.0 → 1.5.9 View file →
@@ -1,10 +1,25 @@
1 1 <?php
2 2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly;
3 3
4 +/*
5 +
6 +actions inlcuded
7 +do_action('wdk/settings/import/run', $data); // form data
8 +
9 +apply_filters('wdk/settings/import/run/fields', $this->data['fields']); // fields
10 +apply_filters('wdk/settings/import/run/post', $data);
11 +
12 +*/
13 +
4 14 class Wdk_settings extends Winter_MVC_Controller {
5 15 public $import_log = '';
6 -
16 + public $info_log_message = '';
17 + public $import_images_dir = WPDIRECTORYKIT_PATH.'demo-data/images/';
18 + public $import_xml_file = '';
19 + public $import_xml_file_locations = WPDIRECTORYKIT_PATH.'demo-data/locations.xml';
20 + public $import_count_images = 2;
21 +
7 22 public function __construct(){
8 23 parent::__construct();
9 24 }
10 25
@@ -10,18 +25,26 @@
10 25
11 26 // Edit listing method
12 27 public function index()
13 28 {
29 +
14 30 $this->load->model('settings_m');
15 31 $this->data['db_data'] = NULL;
16 32 $this->data['form'] = &$this->form;
17 33 $this->data['fields'] = $this->settings_m->fields_list;
18 -
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 +
19 38 if($this->form->run($this->data['fields']))
20 39 {
40 +
41 + // Check _wpnonce
42 + check_admin_referer( 'wdk-settings-edit', '_wpnonce' );
43 +
21 44 // Save procedure for basic data
22 45
23 - $data = $this->settings_m->prepare_data($this->input->post(), $this->data['fields']);
46 + $data = $this->settings_m->prepare_data(wdk_get_post(), $this->data['fields']);
24 47 $wdk_slug_listing_preview_page = get_option('wdk_slug_listing_preview_page');
25 48
26 49 // Save standard wp post
27 50 foreach($data as $key => $val)
@@ -52,12 +75,219 @@
52 75 {
53 76 $this->data['db_data'][$field->option_name] = $field->option_value;
54 77 }
55 78
79 + $this->mailtemplates();
80 +
56 81 $this->load->view('wdk_settings/index', $this->data);
57 82 }
83 +
84 + // Edit listing method
85 + public function mailtemplate()
86 + {
58 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 +
59 284 function reset_data () {
285 +
286 + wdk_access_check('settings_m', 1);
287 +
288 + // Check _wpnonce
289 + check_admin_referer( 'reset-data', '_wpnonce' );
60 290
61 291 $this->load->model('location_m');
62 292 $this->load->model('category_m');
63 293 $this->load->model('field_m');
@@ -116,10 +346,10 @@
116 346 // Set to False if you want to send them to Trash.
117 347 }
118 348
119 349 $redirect_url = admin_url("admin.php?page=wdk_settings&is_updated");
120 - if(isset($_GET['redirect_url']))
121 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
350 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
351 + $redirect_url = admin_url(sanitize_text_field(wp_unslash($_GET['redirect_url'])));
122 352
123 353 wp_redirect($redirect_url);
124 354 exit;
125 355 }
@@ -126,9 +356,9 @@
126 356
127 357 // Import demo data listing method
128 358 public function import_demo()
129 359 {
130 -
360 + wdk_access_check('settings_m', 1);
131 361 $this->load->model('field_m');
132 362 $this->load->model('listingfield_m');
133 363 $this->load->model('listing_m');
134 364 $this->load->model('category_m');
@@ -156,12 +386,12 @@
156 386 array('field' => 'import_page_results', 'field_label' => __('Results Page', 'wpdirectorykit'), 'hint' => __('Import demo Results Page', 'wpdirectorykit'), 'field_type' => 'CHECKBOX', 'rules' => ''),
157 387 );
158 388
159 389 $multipurpose_values = array('' => __('Not Selected', 'wpdirectorykit'));
160 - if(file_exists(WPDIRECTORYKIT_PATH.'/demo-data/'))
390 + if(file_exists(WPDIRECTORYKIT_PATH.'demo-data/'))
161 391 {
162 392 $files = array();
163 - $dir = WPDIRECTORYKIT_PATH.'/demo-data/';
393 + $dir = WPDIRECTORYKIT_PATH.'demo-data/';
164 394 if (is_dir($dir)) {
165 395 if ($dh = opendir($dir)) {
166 396 while (($file = readdir($dh)) !== false) {
167 397 if($file == 'locations.xml') continue;
@@ -171,12 +401,16 @@
171 401 closedir($dh);
172 402 }
173 403 }
174 404 }
405 +
175 406 ksort($multipurpose_values);
176 407 if(count($multipurpose_values) > 0)
177 408 $this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values);
178 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']);
179 413
180 414 $this->data['form'] = &$this->form;
181 415 ini_set('max_execution_time', 900);
182 416
@@ -201,9 +435,8 @@
201 435 }
202 436
203 437 if($this->searchform_m->get() || $this->resultitem_m->get()){
204 438 $this->data['db_data']['import_visual_data'] = 0;
205 - $this->import_settings();
206 439 }
207 440
208 441 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
209 442 $this->data['db_data']['import_page_listing_preview'] = 0;
@@ -215,11 +448,13 @@
215 448
216 449 $this->data['db_data']['multipurpose'] = 'real-estate.xml';
217 450
218 451 if(isset($_GET['multipurpose']))
219 - $this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']);
452 + $this->data['db_data']['multipurpose'] = sanitize_text_field(wp_unslash($_GET['multipurpose']));
220 453
221 454 $this->data['import_log'] = '';
455 + $this->data['info_log_message'] = '';
456 +
222 457 $rules = array(
223 458 array(
224 459 'field' => 'import_locations',
225 460 'label' => __('Locations', 'wpdirectorykit'),
@@ -261,18 +496,36 @@
261 496 'rules' => 'required'
262 497 ),
263 498 );
264 499
265 - if($this->data['required_plugins'] && isset($_POST['multipurpose'])) {
266 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing required plugins').'</div>';
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;
267 504 }
268 505
269 506 if(!$this->data['required_plugins'])
270 507 if($this->form->run($rules))
271 508 {
509 + update_option('wdk_install_images_sizes_disable', 1);
510 +
511 + // Check _wpnonce
512 + check_admin_referer( 'wdk-settings_import', '_wpnonce' );
513 +
272 514 // Save procedure for basic data
273 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);
274 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 +
275 528 if( !empty($data['import_locations'])) {
276 529 $this->import_locations();
277 530 }
278 531
@@ -283,9 +536,9 @@
283 536 if( !empty($data['import_fields'])) {
284 537 $this->import_fields($data['multipurpose']);
285 538 }
286 539
287 - if( !empty($data['import_listings'])) {
540 + if( !empty($data['import_listings'])) {
288 541 $this->import_listings($data['multipurpose']);
289 542 }
290 543
291 544 if( !empty($data['import_visual_data'])) {
@@ -301,9 +554,16 @@
301 554 }
302 555
303 556 $this->replace_content_data($data['multipurpose']);
304 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);
305 564 }
565 +
306 566 $this->load->view('wdk_install/index', $this->data);
307 567 }
308 568
309 569 // Import demo data listing method
@@ -308,8 +568,14 @@
308 568
309 569 // Import demo data listing method
310 570 public function remove()
311 571 {
572 +
573 + wdk_access_check('settings_m', 1);
574 +
575 + // Check _wpnonce
576 + check_admin_referer( 'remove-data', '_wpnonce' );
577 +
312 578 $this->load->model('field_m');
313 579 $this->load->model('listingfield_m');
314 580 $this->load->model('listing_m');
315 581 $this->load->model('category_m');
@@ -323,19 +589,21 @@
323 589 $this->load->model('listingfield_m');
324 590 $this->load->model('listing_m');
325 591 $this->load->model('resultitem_m');
326 592 $this->load->model('searchform_m');
593 + $this->load->model('dependfields_m');
327 594
328 595 /* remove fields */
329 596 $this->db->delete($this->location_m->_table_name);
330 597
331 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed').'</div>';
598 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations removed', 'wpdirectorykit').'</div>';
332 599 /* end remove fields */
333 600
334 601 /* remove fields */
335 602 $this->db->delete($this->category_m->_table_name);
603 + $this->db->delete($this->dependfields_m->_table_name);
336 604
337 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed').'</div>';
605 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories removed', 'wpdirectorykit').'</div>';
338 606 /* end remove fields */
339 607
340 608 /* remove fields */
341 609 $this->db->delete($this->field_m->_table_name);
@@ -344,9 +612,9 @@
344 612 if(strpos($field_name, 'field_') ===FALSE) continue;
345 613 $this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.'');
346 614 }
347 615
348 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed').'</div>';
616 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields removed', 'wpdirectorykit').'</div>';
349 617 /* end remove fields */
350 618
351 619 /* remove listings */
352 620 $this->db->delete($this->listing_m->_table_name);
@@ -351,9 +619,9 @@
351 619 /* remove listings */
352 620 $this->db->delete($this->listing_m->_table_name);
353 621 $this->db->delete($this->listingfield_m->_table_name);
354 622
355 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed').'</div>';
623 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings removed', 'wpdirectorykit').'</div>';
356 624 /* end remove listings */
357 625
358 626
359 627 /* remove listings */
@@ -358,9 +626,9 @@
358 626
359 627 /* remove listings */
360 628 $this->db->delete($this->resultitem_m->_table_name);
361 629 $this->db->delete($this->searchform_m->_table_name);
362 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed').'</div>';
630 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Result Card And Search form removed', 'wpdirectorykit').'</div>';
363 631 /* end remove listings */
364 632
365 633
366 634 /* reset autoincrement */
@@ -366,14 +634,15 @@
366 634 /* reset autoincrement */
367 635 $this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`');
368 636 $this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`');
369 637 $this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`');
638 + $this->db->query('TRUNCATE TABLE `'.$this->dependfields_m->_table_name.'`');
370 639 $this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`');
371 640 $this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`');
372 641 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
373 642 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
374 643
375 - $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset').'</div>';
644 + $this->data['data_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Tables reset', 'wpdirectorykit').'</div>';
376 645 /* end reset autoincrement */
377 646
378 647 $wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1));
379 648 foreach( $wdk_posts as $post ) {
@@ -381,13 +650,13 @@
381 650 wp_delete_post( $post->ID, true);
382 651 // Set to False if you want to send them to Trash.
383 652 }
384 653
385 - if(isset($_GET['redirect_url'])){
654 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE){
386 655 if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') {
387 - $redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated");
656 + $redirect_url = admin_url("admin.php?page=wdk_settings&function=import_demo&is_updated&multipurpose=".wmvc_show_data('multipurpose', $_GET, ''));
388 657 } else {
389 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
658 + $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
390 659 }
391 660 wp_redirect($redirect_url);
392 661 }
393 662
@@ -394,11 +663,11 @@
394 663 $this->load->view('wdk_install/remove_log', $this->data);
395 664 }
396 665
397 666 /* add demo pages */
398 - public function demo_pages($purpose = '') {
667 + private function demo_pages($purpose = '') {
399 668
400 - // if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true;
669 + if(get_option('wdk_listing_page') || get_option('wdk_results_page')) return true;
401 670
402 671 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
403 672 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
404 673 });
@@ -537,9 +806,9 @@
537 806
538 807 return $user_id;
539 808 }
540 809
541 - function replace_content_data($purpose = '') {
810 + private function replace_content_data($purpose = '') {
542 811 /* Replace Links */
543 812 /* login */
544 813 $from = 'https://www.wpdirectorykit.com/nexproperty/wp-admin/wp-login.php';
545 814 $to = get_admin_url();
@@ -551,16 +820,15 @@
551 820 $this->replace_meta($from, $to);
552 821
553 822 /* homepage */
554 823 $from = '2020';
555 - $to = date('Y');
824 + $to = gmdate('Y');
556 825 $this->replace_meta($from, $to);
557 826
558 827
559 828 /* replace in db */
560 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose;
561 - if(file_exists($xml_list)) {
562 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
829 + if(file_exists($this->import_xml_file)) {
830 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
563 831 if(isset($dom_array['replace']) && !empty($dom_array['replace'])) {
564 832 if(!empty($dom_array['replace']['text'])) {
565 833 foreach($dom_array['replace']['text'] as $string){
566 834 if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue;
@@ -576,12 +844,12 @@
576 844
577 845 }
578 846
579 847 /* add demo listing preview page */
580 - public function demo_page_listing($purpose = '') {
848 + private function demo_page_listing($purpose = '') {
581 849
582 850 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
583 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists').'</div>';
851 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listing Preview Page already exists', 'wpdirectorykit').'</div>';
584 852 return false;
585 853 }
586 854
587 855 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -610,8 +878,9 @@
610 878 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
611 879 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
612 880 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
613 881 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
882 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
614 883 });
615 884
616 885 // Import elementor templates
617 886 $page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas');
@@ -620,18 +889,18 @@
620 889 // Assign page.
621 890 if($page_listing_preview)
622 891 update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE);
623 892
624 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported').'</div>';
893 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listing Preview Page imported', 'wpdirectorykit').'</div>';
625 894
626 895 return true;
627 896 }
628 897
629 898 /* add demo results page */
630 - public function demo_page_results($purpose = '') {
899 + private function demo_page_results($purpose = '') {
631 900
632 901 if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){
633 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists').'</div>';
902 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Results Listings Page already exists', 'wpdirectorykit').'</div>';
634 903 return false;
635 904 }
636 905
637 906 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -660,8 +929,9 @@
660 929 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
661 930 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
662 931 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
663 932 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
933 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
664 934 });
665 935
666 936 $page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas');
667 937 $this->elementor_assign($page_results->ID, 'page-results-listings.json');
@@ -671,9 +941,9 @@
671 941 update_option( 'page_on_front', $page_results->ID );
672 942
673 943 update_option( 'wdk_results_page', $page_results->ID, TRUE);
674 944
675 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported').'</div>';
945 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Results Listings Page imported', 'wpdirectorykit').'</div>';
676 946
677 947
678 948 $menus = get_registered_nav_menus();
679 949 // first menu defined by template
@@ -705,8 +975,11 @@
705 975 wp_update_nav_menu_item((int)$menu_id, 0, $itemData);
706 976
707 977 // assign menu to top menu
708 978 $locations = get_theme_mod( 'nav_menu_locations' );
979 + if ( ! is_array( $locations ) ) {
980 + $locations = array();
981 + }
709 982 $locations[$first_menu] = $menu_id;
710 983 set_theme_mod('nav_menu_locations', $locations);
711 984 }
712 985
@@ -713,11 +986,11 @@
713 986 return true;
714 987 }
715 988
716 989 /* Create Page */
717 - function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
990 + private function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0)
718 991 {
719 - $post = get_page_by_title($post_title, 'OBJECT', 'page' );
992 + $post = wdk_page_by_title($post_title, 'OBJECT', 'page' );
720 993
721 994 $post_id = NULL;
722 995
723 996 // Delete posts and rebuild
@@ -766,9 +1039,9 @@
766 1039 $file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name;
767 1040 }
768 1041 elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name))
769 1042 {
770 - $file = WPDIRECTORYKIT_PATH.'/demo-data/'.$json_template_name;
1043 + $file = WPDIRECTORYKIT_PATH.'demo-data/'.$json_template_name;
771 1044 }
772 1045
773 1046 if(!$file || !class_exists('Elementor\Plugin'))
774 1047 {
@@ -785,359 +1058,9 @@
785 1058 WP_Filesystem();
786 1059 }
787 1060
788 1061 $string = $wp_filesystem->get_contents($file);
789 - if ($file == WPDIRECTORYKIT_PATH. '/demo-data/page-listing-preview.json') {
790 - $str = '';
791 - if (function_exists('run_wdk_bookings')) {
792 - $str = ' {
793 - "id": "67302676",
794 - "settings": {
795 - "title": "Rates / Prices",
796 - "typography_typography": "custom",
797 - "typography_font_family": "Montserrat",
798 - "typography_font_size": {
799 - "unit": "px",
800 - "size": 18,
801 - "sizes": []
802 - },
803 - "typography_font_weight": "700",
804 - "_margin": {
805 - "unit": "px",
806 - "top": "0",
807 - "right": "0",
808 - "bottom": "31",
809 - "left": "0",
810 - "isLinked": false
811 - },
812 - "title_color": "#161616"
813 - },
814 - "elements": [],
815 - "isInner": false,
816 - "widgetType": "heading",
817 - "elType": "widget"
818 - },
819 - {
820 - "id": "283028da",
821 - "settings": {
822 - "_padding": {
823 - "unit": "px",
824 - "top": "0",
825 - "right": "0",
826 - "bottom": "55",
827 - "left": "0",
828 - "isLinked": false
829 - }
830 - },
831 - "elements": [],
832 - "isInner": false,
833 - "widgetType": "wdk-booking-listing-table",
834 - "elType": "widget"
835 - },
836 - {
837 - "id": "1a243dfd",
838 - "settings": {
839 - "title": "Availability Calendar",
840 - "typography_typography": "custom",
841 - "typography_font_family": "Montserrat",
842 - "typography_font_size": {
843 - "unit": "px",
844 - "size": 18,
845 - "sizes": []
846 - },
847 - "typography_font_weight": "700",
848 - "_margin": {
849 - "unit": "px",
850 - "top": "0",
851 - "right": "0",
852 - "bottom": "31",
853 - "left": "0",
854 - "isLinked": false
855 - },
856 - "title_color": "#161616"
857 - },
858 - "elements": [],
859 - "isInner": false,
860 - "widgetType": "heading",
861 - "elType": "widget"
862 - },
863 - {
864 - "id": "4780b1c7",
865 - "settings": {
866 - "_margin": {
867 - "unit": "px",
868 - "top": "0",
869 - "right": "0",
870 - "bottom": "50",
871 - "left": "0",
872 - "isLinked": false
873 - }
874 - },
875 - "elements": [],
876 - "isInner": false,
877 - "widgetType": "wdk-booking-listing-calendar",
878 - "elType": "widget"
879 - },';
880 - }
881 - $string = str_replace('{booking}', $str, $string);
882 1062
883 - $str = '';
884 - if (function_exists('run_wdk_reviews')) {
885 - $str = ' {
886 - "id": "403a73f6",
887 - "settings": {
888 - "title": "Reviews",
889 - "header_size": "span",
890 - "typography_typography": "custom",
891 - "typography_font_family": "Montserrat",
892 - "typography_font_weight": "700",
893 - "_element_width": "auto",
894 - "typography_font_size": {
895 - "unit": "px",
896 - "size": 18,
897 - "sizes": []
898 - },
899 - "_margin": {
900 - "unit": "px",
901 - "top": "0",
902 - "right": "0",
903 - "bottom": "5",
904 - "left": "0",
905 - "isLinked": false
906 - },
907 - "title_color": "#161616"
908 - },
909 - "elements": [],
910 - "isInner": false,
911 - "widgetType": "heading",
912 - "elType": "widget"
913 - },
914 - {
915 - "id": "34dd7429",
916 - "settings": {
917 - "_margin": {
918 - "unit": "px",
919 - "top": "0",
920 - "right": "0",
921 - "bottom": "0",
922 - "left": "5",
923 - "isLinked": false
924 - },
925 - "_element_width": "auto"
926 - },
927 - "elements": [],
928 - "isInner": false,
929 - "widgetType": "wdk-reviews-average-basic",
930 - "elType": "widget"
931 - },
932 - {
933 - "id": "2f7cdac8",
934 - "settings": {
935 - "space": { "unit": "px", "size": 1, "sizes": [] },
936 - "_padding": {
937 - "unit": "px",
938 - "top": "5",
939 - "right": "0",
940 - "bottom": "0",
941 - "left": "0",
942 - "isLinked": false
943 - }
944 - },
945 - "elements": [],
946 - "isInner": false,
947 - "widgetType": "spacer",
948 - "elType": "widget"
949 - },
950 - {
951 - "id": "30da7684",
952 - "settings": {
953 - "average_hide": "none",
954 - "_margin": {
955 - "unit": "px",
956 - "top": "0",
957 - "right": "0",
958 - "bottom": "0",
959 - "left": "0",
960 - "isLinked": false
961 - }
962 - },
963 - "elements": [],
964 - "isInner": false,
965 - "widgetType": "wdk-reviews-average",
966 - "elType": "widget"
967 - },
968 - {
969 - "id": "6b7a32df",
970 - "settings": {
971 - "space": { "unit": "px", "size": 37, "sizes": [] }
972 - },
973 - "elements": [],
974 - "isInner": false,
975 - "widgetType": "spacer",
976 - "elType": "widget"
977 - },
978 - {
979 - "id": "38432829",
980 - "settings": {
981 - "field_message": "Review",
982 - "field_message_placeholder": "Write your Review",
983 - "field_submit": "Send Review",
984 - "_margin": {
985 - "unit": "px",
986 - "top": "0",
987 - "right": "0",
988 - "bottom": "45",
989 - "left": "0",
990 - "isLinked": false
991 - },
992 - "form_title": "Write a Review",
993 - "comment_name_dynamic_paddingnormal": {
994 - "unit": "px",
995 - "top": "1",
996 - "right": "1",
997 - "bottom": "1",
998 - "left": "1",
999 - "isLinked": true
1000 - },
1001 - "form_title_dynamic_paddingnormal": {
1002 - "unit": "px",
1003 - "top": "0",
1004 - "right": "0",
1005 - "bottom": "5",
1006 - "left": "0",
1007 - "isLinked": false
1008 - }
1009 - },
1010 - "elements": [],
1011 - "isInner": false,
1012 - "widgetType": "wdk-reviews-list",
1013 - "elType": "widget"
1014 - },
1015 - ';
1016 - }
1017 - $string = str_replace('{reviews}', $str, $string);
1018 -
1019 - $str = '';
1020 - if (function_exists('run_wdk_mortgage')) {
1021 - $str = ' {
1022 - "id": "7bfe253b",
1023 - "settings": {
1024 - "box_shadow_box_shadow_type": "yes",
1025 - "box_shadow_box_shadow": {
1026 - "horizontal": 0,
1027 - "vertical": 0,
1028 - "blur": 10,
1029 - "spread": 0,
1030 - "color": "rgba(1, 1, 1, 0.11)"
1031 - },
1032 - "margin": {
1033 - "unit": "px",
1034 - "top": "0",
1035 - "right": 0,
1036 - "bottom": "35",
1037 - "left": 0,
1038 - "isLinked": false
1039 - }
1040 - },
1041 - "elements": [
1042 - {
1043 - "id": "5da49154",
1044 - "settings": {
1045 - "_column_size": 100,
1046 - "_inline_size": null,
1047 - "content_position": "top",
1048 - "align": "flex-start",
1049 - "space_between_widgets": 0,
1050 - "padding": {
1051 - "unit": "px",
1052 - "top": "25",
1053 - "right": "25",
1054 - "bottom": "25",
1055 - "left": "25",
1056 - "isLinked": false
1057 - }
1058 - },
1059 - "elements": [
1060 - {
1061 - "id": "3db04015",
1062 - "settings": {
1063 - "title": "Mortgage",
1064 - "typography_typography": "custom",
1065 - "typography_font_family": "Montserrat",
1066 - "typography_font_size": {
1067 - "unit": "px",
1068 - "size": 16,
1069 - "sizes": []
1070 - },
1071 - "typography_font_weight": "700",
1072 - "_margin": {
1073 - "unit": "px",
1074 - "top": "0",
1075 - "right": "0",
1076 - "bottom": "0",
1077 - "left": "0",
1078 - "isLinked": false
1079 - },
1080 - "_padding": {
1081 - "unit": "px",
1082 - "top": "0",
1083 - "right": "0",
1084 - "bottom": "27",
1085 - "left": "0",
1086 - "isLinked": false
1087 - },
1088 - "typography_letter_spacing": {
1089 - "unit": "px",
1090 - "size": -0.4,
1091 - "sizes": []
1092 - },
1093 - "title_color": "#161616"
1094 - },
1095 - "elements": [],
1096 - "isInner": false,
1097 - "widgetType": "heading",
1098 - "elType": "widget"
1099 - },
1100 - {
1101 - "id": "263622d0",
1102 - "settings": {
1103 - "field_currency": "$",
1104 - "field_product_price_label": "Home Price",
1105 - "field_product_price_placeholder": "Home Price",
1106 - "field_down_payment_label": "Down Payment",
1107 - "field_down_payment_placeholder": "Down Payment",
1108 - "field_mortgage_rate_label": "Mortgage Interest Rate",
1109 - "field_mortgage_rate_placeholder": "Mortgage Rate",
1110 - "field_years_label": "Years",
1111 - "field_years_placeholder": "Loan Years",
1112 - "field_submit": "Calculate",
1113 - "_padding": {
1114 - "unit": "px",
1115 - "top": "0",
1116 - "right": "0",
1117 - "bottom": "0",
1118 - "left": "0",
1119 - "isLinked": false
1120 - }
1121 - },
1122 - "elements": [],
1123 - "isInner": false,
1124 - "widgetType": "wdk-mortgage-calculator",
1125 - "elType": "widget"
1126 - }
1127 - ],
1128 - "isInner": true,
1129 - "elType": "column"
1130 - }
1131 - ],
1132 - "isInner": true,
1133 - "elType": "section"
1134 - },
1135 - ';
1136 - }
1137 - $string = str_replace('{mortgage}', $str, $string);
1138 - }
1139 -
1140 1063 $json_template = json_decode($string, true);
1141 1064 $elements = $json_template['content'];
1142 1065
1143 1066 $data = array(
@@ -1168,11 +1091,10 @@
1168 1091 /* reset autoincrement */
1169 1092 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
1170 1093 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
1171 1094
1172 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose;
1173 - if(file_exists($xml_list)) {
1174 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1095 + if(file_exists($this->import_xml_file)) {
1096 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1175 1097
1176 1098 if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) {
1177 1099 } else {
1178 1100 // Save searchform_m
@@ -1197,19 +1119,18 @@
1197 1119 $data['idresultitem'] = 1;
1198 1120 $insert_id = $this->resultitem_m->insert($data, NULL);
1199 1121 }
1200 1122
1201 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported').'</div>';
1123 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Search Form & Result Card imported', 'wpdirectorykit').'</div>';
1202 1124 return true;
1203 1125 }
1204 -
1205 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1126 + /* translators: 1: XML file path. */
1127 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('Missing xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1206 1128 return false;
1207 1129
1208 1130 }
1209 1131
1210 1132 private function import_locations() {
1211 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/locations.xml';
1212 1133 $this->load->model('location_m');
1213 1134
1214 1135 if($this->location_m->get()){
1215 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
@@ -1215,12 +1136,13 @@
1215 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
1216 1137 return false;
1217 1138 }
1218 1139
1219 - if(file_exists($xml_list)) {
1220 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1140 + if(file_exists($this->import_xml_file_locations)) {
1141 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file_locations));
1221 1142 if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) {
1222 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1143 + /* translators: 1: XML file path. */
1144 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file_locations).'</div>';
1223 1145 return false;
1224 1146 }
1225 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
1226 1148 $this->_recursive_add_locations($location_data);
@@ -1225,13 +1147,13 @@
1225 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
1226 1148 $this->_recursive_add_locations($location_data);
1227 1149 }
1228 1150
1229 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported').'</div>';
1151 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Locations imported', 'wpdirectorykit').'</div>';
1230 1152 return true;
1231 1153 }
1232 -
1233 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1154 + /* translators: 1: XML file path. */
1155 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('Missing xml file %1$s', 'wpdirectorykit'), $this->import_xml_file_locations).'</div>';
1234 1156 return false;
1235 1157 }
1236 1158
1237 1159 private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -1251,18 +1173,21 @@
1251 1173 if(empty(wmvc_show_data('location_title', $location_data))) {
1252 1174 return false;
1253 1175 }
1254 1176
1255 - if(!empty($location_data['image_id']) && file_exists(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['image_id'])){
1177 + if(!empty($location_data['image_id']) && file_exists($this->import_images_dir.$location_data['image_id'])){
1256 1178 /* add files */
1257 - $location_data['image_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['image_id']);
1179 + $location_data['image_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['image_id']);
1258 1180 }
1259 1181
1260 - if(!empty($location_data['icon_id']) && file_exists(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['icon_id'])){
1182 + if(!empty($location_data['icon_id']) && file_exists($this->import_images_dir.$location_data['icon_id'])){
1261 1183 /* add files */
1262 - $location_data['icon_id'] = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.$location_data['icon_id']);
1184 + $location_data['icon_id'] = wmvc_add_wp_image($this->import_images_dir.$location_data['icon_id']);
1263 1185 }
1264 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 +
1265 1190 /* add locations */
1266 1191 $insert_id = $this->location_m->insert($location_data, NULL);
1267 1192 if(isset($data['childs']["location"]) && !empty($data['childs']["location"])) {
1268 1193 foreach ($data['childs']["location"] as $sub_location_data) {
@@ -1271,10 +1196,10 @@
1271 1196 }
1272 1197 }
1273 1198
1274 1199 private function import_categories($purpose = '') {
1275 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose;
1276 - $this->load->model('category_m');
1200 + $this->load->model('category_m') ;
1201 + $this->load->model('dependfields_m') ;
1277 1202
1278 1203 if($this->category_m->get()){
1279 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
1280 1205 return false;
@@ -1279,12 +1204,13 @@
1279 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
1280 1205 return false;
1281 1206 }
1282 1207
1283 - if(file_exists($xml_list)) {
1284 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1208 + if(file_exists($this->import_xml_file)) {
1209 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1285 1210 if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) {
1286 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1211 + /* translators: 1: XML file path. */
1212 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1287 1213 return false;
1288 1214 }
1289 1215
1290 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
@@ -1290,13 +1216,24 @@
1290 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
1291 1217 $this->_recursive_add_categories($category_data);
1292 1218 }
1293 1219
1294 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported').'</div>';
1220 + /* indexes by new order and reorder */
1221 + $results = $this->category_m->get_tree_table();
1222 + $values = array();
1223 + $order_index = 1;
1224 + foreach( $results as $item)
1225 + {
1226 + $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
1227 + $order_index++;
1228 + }
1229 + $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
1230 +
1231 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Categories imported', 'wpdirectorykit').'</div>';
1295 1232 return true;
1296 1233 }
1297 -
1298 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1234 + /* translators: 1: XML file path. */
1235 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1299 1236 return false;
1300 1237 }
1301 1238
1302 1239 private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -1328,11 +1265,11 @@
1328 1265 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']))
1329 1266 {
1330 1267 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'];
1331 1268 }
1332 - elseif(file_exists( WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['image_id']))
1269 + elseif(file_exists( $this->import_images_dir.$category_data['image_id']))
1333 1270 {
1334 - $file = WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['image_id'];
1271 + $file = $this->import_images_dir.$category_data['image_id'];
1335 1272 }
1336 1273 /* add files */
1337 1274
1338 1275 if($file)
@@ -1349,11 +1286,11 @@
1349 1286 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']))
1350 1287 {
1351 1288 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'];
1352 1289 }
1353 - elseif(file_exists( WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['icon_id']))
1290 + elseif(file_exists( $this->import_images_dir.$category_data['icon_id']))
1354 1291 {
1355 - $file = WPDIRECTORYKIT_PATH.'/demo-data/images/'.$category_data['icon_id'];
1292 + $file = $this->import_images_dir.$category_data['icon_id'];
1356 1293 }
1357 1294 /* add files */
1358 1295
1359 1296 if($file)
@@ -1358,11 +1295,27 @@
1358 1295
1359 1296 if($file)
1360 1297 $category_data['icon_id'] = wmvc_add_wp_image($file);
1361 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']);
1362 1302
1363 1303 /* add categories */
1364 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 +
1365 1318 if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) {
1366 1319 foreach ($data['childs']["category"] as $sub_category_data) {
1367 1320 $this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1));
1368 1321 }
@@ -1376,14 +1329,12 @@
1376 1329 if($this->field_m->get()){
1377 1330 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>';
1378 1331 return false;
1379 1332 }
1380 -
1381 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose;
1382 1333
1383 1334 $sections_added_array = array();
1384 - if(file_exists($xml_list)) {
1385 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1335 + if(file_exists($this->import_xml_file)) {
1336 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1386 1337
1387 1338 $base = array(
1388 1339 'field_type' => '',
1389 1340 'field_label' => '',
@@ -1388,22 +1339,24 @@
1388 1339 'field_type' => '',
1389 1340 'field_label' => '',
1390 1341 'hint' => '',
1391 1342 'columns_number' => '',
1392 - 'is_visible_frontend' => '',
1393 - 'is_visible_dashboard' => '',
1343 + 'is_visible_frontend' => '1',
1344 + 'is_visible_dashboard' => '1',
1394 1345 'prefix' => '',
1395 1346 'suffix' => '',
1396 1347 'values_list' => '',
1397 1348 'icon_id' => '',
1398 1349 'is_required' => '',
1350 + 'order_index' => '',
1399 1351 );
1400 1352
1401 1353 if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) {
1402 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No fields in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1354 + /* translators: 1: XML file path. */
1355 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'),$this->import_xml_file).'</div>';
1403 1356 return false;
1404 1357 }
1405 -
1358 +
1406 1359 foreach ($dom_array['fields']['field'] as $key => $field) {
1407 1360 $field_data = array_intersect_key(array_merge($base, $field), $base);
1408 1361 array_walk($field_data, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1409 1362
@@ -1409,8 +1362,17 @@
1409 1362
1410 1363 if(empty(wmvc_show_data('field_type', $field_data)) || empty(wmvc_show_data('field_label', $field_data))) {
1411 1364 continue;
1412 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 + }
1413 1375
1414 1376 if(!in_array($field['section'], $sections_added_array)) {
1415 1377 /* add section */
1416 1378 $section_data = array(
@@ -1416,12 +1378,18 @@
1416 1378 $section_data = array(
1417 1379 'field_type' => 'SECTION',
1418 1380 'field_label' => $field['section'],
1419 1381 'columns_number' => '12',
1420 - 'is_visible_frontend' => '',
1421 - 'is_visible_dashboard' => '',
1382 + 'is_visible_frontend' => '1',
1383 + 'is_visible_dashboard' => '1',
1384 + 'order_index' => $field['order_index'],
1422 1385 );
1423 1386 /* add field */
1387 +
1388 + if($section_data['field_label'] == 'SEO') {
1389 + $section_data['is_visible_frontend'] = 0;
1390 + }
1391 +
1424 1392 $this->field_m->insert($section_data, NULL);
1425 1393
1426 1394 $sections_added_array[] = $field['section'];
1427 1395 }
@@ -1426,8 +1394,13 @@
1426 1394 $sections_added_array[] = $field['section'];
1427 1395 }
1428 1396
1429 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 +
1430 1403 $insert_id = $this->field_m->insert($field_data, NULL);
1431 1404 // check if column exists, add if nto exists
1432 1405 if(!empty($insert_id))
1433 1406 $this->listingfield_m->create_table_column($field_data, $insert_id);
@@ -1432,13 +1405,13 @@
1432 1405 if(!empty($insert_id))
1433 1406 $this->listingfield_m->create_table_column($field_data, $insert_id);
1434 1407 }
1435 1408
1436 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported').'</div>';
1409 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Fields imported', 'wpdirectorykit').'</div>';
1437 1410 return true;
1438 1411 }
1439 -
1440 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1412 + /* translators: 1: XML file path. */
1413 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1441 1414 return false;
1442 1415 }
1443 1416
1444 1417 private function import_listings($purpose = '') {
@@ -1447,9 +1420,9 @@
1447 1420 $this->load->model('listing_m');
1448 1421 $this->load->model('category_m');
1449 1422 $this->load->model('location_m');
1450 1423 $this->load->model('listingusers_m');
1451 -
1424 +
1452 1425 if($this->listing_m->get()){
1453 1426 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Listings already imported', 'wpdirectorykit').'</div>';
1454 1427 return false;
1455 1428 }
@@ -1478,13 +1451,12 @@
1478 1451 }
1479 1452 }
1480 1453
1481 1454 // Open a known directory, and proceed to read its contents
1482 - $dir = WPDIRECTORYKIT_PATH.'/demo-data/images';
1483 1455 $purpose_name = str_replace('.xml','',$purpose);
1484 1456 $files = array();
1485 - if (is_dir($dir)) {
1486 - if ($dh = opendir($dir)) {
1457 + if (is_dir($this->import_images_dir)) {
1458 + if ($dh = opendir($this->import_images_dir)) {
1487 1459 while (($file = readdir($dh)) !== false) {
1488 1460 if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false)
1489 1461 $files[] = $file;
1490 1462 }
@@ -1492,13 +1464,13 @@
1492 1464 }
1493 1465 }
1494 1466 sort($files);
1495 1467
1496 - $xml_list = WPDIRECTORYKIT_PATH.'/demo-data/'.$purpose;
1497 - if(file_exists($xml_list)) {
1498 - $dom_array = $this->xmlstr_to_array(file_get_contents($xml_list));
1468 + if(file_exists($this->import_xml_file)) {
1469 + $dom_array = $this->xmlstr_to_array(file_get_contents($this->import_xml_file));
1499 1470 if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) {
1500 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('No listings in xml file '.$xml_list, 'wpdirectorykit').'</div>';
1471 + /* translators: 1: XML file path. */
1472 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No listings in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1501 1473 return false;
1502 1474 }
1503 1475
1504 1476 /* demo agent add/get if exists */
@@ -1511,12 +1483,12 @@
1511 1483 $location_id = '';
1512 1484 $category_id = '';
1513 1485
1514 1486 if(!empty($categories))
1515 - $category_id = $categories[rand(0, count($categories)-1)];
1487 + $category_id = $categories[wp_rand(0, count($categories)-1)];
1516 1488
1517 1489 if(!empty($location))
1518 - $location_id = $locations[rand(0, count($locations)-1)];
1490 + $location_id = $locations[wp_rand(0, count($locations)-1)];
1519 1491
1520 1492 $data_listing = array(
1521 1493 'post_title' => '',
1522 1494 'post_content' => '',
@@ -1524,26 +1496,37 @@
1524 1496 'location_id' => $location_id,
1525 1497 'address' => '',
1526 1498 'lat' => '',
1527 1499 'listing_images' => '',
1528 - 'date_modified' => date('Y-m-d H:i:s'),
1500 + 'listing_images_path' => '',
1501 + 'listing_images_path_medium' => '',
1502 + 'date_modified' => gmdate('Y-m-d H:i:s'),
1529 1503 'lng' => '',
1530 1504 'is_featured' => '',
1531 1505 'is_activated' => '1',
1532 1506 'is_approved' => '1',
1507 + 'counter_views' => wp_rand(20,250),
1508 + 'user_id_editor' => NULL,
1533 1509 );
1534 -
1510 +
1535 1511 $data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing);
1536 1512 array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1537 -
1513 +
1538 1514 if(empty(wmvc_show_data('post_title', $data_listing))) {
1539 1515 continue;
1540 1516 }
1541 1517
1518 + $hidden_fields_list = wdk_depend_get_hidden_fields($data_listing['category_id']);
1519 +
1542 1520 /*fields */
1521 + $data_listings_fields = array();
1543 1522 foreach($fields as $field_data) {
1523 + if(!empty($hidden_fields_list) && strpos(','.$hidden_fields_list.',', ','.$field_data->idfield.',')!==FALSE) {
1524 + continue;
1525 + }
1526 +
1544 1527 if(isset($listing['field_'.$field_data->idfield])) {
1545 - $data_listing['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1528 + $data_listings_fields['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1546 1529 } else {
1547 1530 if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE')
1548 1531 {
1549 1532 if(empty($field_data->values_list)) continue;
@@ -1551,40 +1534,111 @@
1551 1534 if(count($values) > 0)
1552 1535 {
1553 1536 $start=0;
1554 1537 if(empty($values[0]))$start=1;
1555 - $data_listing['field_'.$field_data->idfield] = $values[rand($start, count($values)-1)];
1538 + $data_listings_fields['field_'.$field_data->idfield] = $values[wp_rand($start, count($values)-1)];
1556 1539 }
1557 1540 }
1558 1541 elseif($field_data->field_type == 'NUMBER')
1559 1542 {
1560 - $data_listing['field_'.$field_data->idfield] = rand(2,499);
1543 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(2,499);
1544 +
1561 1545 }
1562 1546 elseif($field_data->field_type == 'CHECKBOX')
1563 1547 {
1564 - $data_listing['field_'.$field_data->idfield] = rand(0,1);
1548 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(0,1);
1565 1549 }
1566 1550 elseif($field_data->field_type == 'TEXTAREA')
1567 1551 {
1568 - //$data_listing['field_'.$field_data->idfield] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
1552 + //$data_listings_fields['field_'.$field_data->idfield] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
1569 1553 }
1570 1554 }
1571 1555 }
1572 1556
1573 1557 /* add files */
1574 - $count_images = 2;
1558 +
1575 1559 if($purpose == 'car-dealer.xml') {
1576 - $count_images = 1;
1560 + $this->import_count_images = 1;
1577 1561 }
1562 + if(isset($listing['images']) && !empty($listing['images'])) {
1578 1563
1579 - for ($i=0,$image_num=$listing_num; $i<$count_images; $i++,$image_num++) {
1580 - if($image_num >= count($files))
1581 - $image_num = 0;
1564 + foreach (explode(',', $listing['images']) as $key => $file_name) {
1565 +
1566 + if(empty($file_name)) continue;
1582 1567
1583 - if(!empty($data_listing['listing_images']))
1584 - $data_listing['listing_images'].= ',';
1568 + if(!empty($data_listing['listing_images']))
1569 + $data_listing['listing_images'].= ',';
1570 + $image_id = wmvc_add_wp_image($this->import_images_dir.esc_html($file_name));
1585 1571
1586 - $data_listing['listing_images'] .= wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'/demo-data/images/'.esc_html($files[$image_num]));
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 + }
1587 1641 }
1588 1642
1589 1643 // Create post object
1590 1644 $listing_post = array(
@@ -1598,27 +1652,29 @@
1598 1652 // Insert the post into the database
1599 1653 $id = wp_insert_post( $listing_post );
1600 1654
1601 1655 $listing_data = array('post_id' => $id);
1602 - $listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images', 'is_featured', 'is_activated','is_approved');
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');
1603 1657 foreach($listing_data_fields as $field_name)
1604 1658 {
1605 1659 if(isset( $data_listing[$field_name]))
1606 1660 $listing_data[$field_name] = $data_listing[$field_name];
1607 1661 }
1608 -
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 +
1609 1666 $this->listing_m->insert($listing_data, NULL);
1610 1667
1611 - $data_listing['post_id'] = $id;
1612 - $this->listingfield_m->insert_custom_fields($fields, $data_listing, NULL);
1668 + $data_listings_fields['post_id'] = $id;
1669 + $this->listingfield_m->insert_custom_fields($fields, $data_listings_fields, NULL);
1670 + }
1613 1671
1614 - $this->listingusers_m->insert(array('post_id' => $id, 'user_id' => $user_ids[array_rand($user_ids)]), NULL);
1615 - }
1616 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>';
1672 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported', 'wpdirectorykit').'</div>';
1617 1673 return true;
1618 1674 }
1619 -
1620 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Missing xml file '.$xml_list, 'wpdirectorykit').'</div>';
1675 + /* translators: 1: XML file path. */
1676 + $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.wdk_sprintf(esc_html__('No fields in xml file %1$s', 'wpdirectorykit'), $this->import_xml_file).'</div>';
1621 1677 return false;
1622 1678 }
1623 1679
1624 1680 protected function xmlstr_to_array($xmlstr) {
@@ -1679,8 +1735,14 @@
1679 1735 }
1680 1736
1681 1737 public function run()
1682 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 +
1683 1745 ini_set('max_execution_time', 900);
1684 1746 $this->data['import_log'] = '';
1685 1747 $multipurpose = 'real-estate.xml';
1686 1748 if(isset($_GET['multipurpose']))
@@ -1686,11 +1748,17 @@
1686 1748 if(isset($_GET['multipurpose']))
1687 1749 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1688 1750
1689 1751 $redirect_url = admin_url("admin.php?page=wdk_fields&is_updated");
1690 - if(isset($_GET['redirect_url']))
1691 - $redirect_url = sanitize_text_field($_GET['redirect_url']);
1752 + if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
1753 + $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
1692 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 +
1693 1761 $this->import_locations();
1694 1762 $this->import_categories($multipurpose);
1695 1763 $this->import_fields($multipurpose);
1696 1764 $this->import_listings($multipurpose);
@@ -1696,10 +1764,14 @@
1696 1764 $this->import_listings($multipurpose);
1697 1765 $this->import_visual_data($multipurpose);
1698 1766 $this->demo_pages($multipurpose);
1699 1767
1700 - $message = str_replace(" ", '+', __('Import completed successfuly', 'wpdirectorykit'));
1768 + $message = urlencode(str_replace(" ", '+', __('Import completed successfully', 'wpdirectorykit')).' <a href="'.esc_url((wdk_get_option('wdk_results_page')) ? get_permalink(wdk_get_option('wdk_results_page')): home_url()).'">'.__('Check your page now', 'wpdirectorykit').'</a>');
1701 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 +
1702 1774 wp_redirect($redirect_url.'&message='.$message);
1703 1775 exit;
1704 1776 }
1705 1777
@@ -1704,8 +1776,19 @@
1704 1776 }
1705 1777
1706 1778 public function api_import()
1707 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 +
1708 1791 ini_set('max_execution_time', 900);
1709 1792 $this->data['import_log'] = '';
1710 1793 $multipurpose = 'real-estate.xml';
1711 1794 if(isset($_GET['multipurpose']))
@@ -1710,8 +1793,14 @@
1710 1793 $multipurpose = 'real-estate.xml';
1711 1794 if(isset($_GET['multipurpose']))
1712 1795 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1713 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 +
1714 1803 $this->import_locations();
1715 1804 $this->import_categories($multipurpose);
1716 1805 $this->import_fields($multipurpose);
1717 1806 $this->import_listings($multipurpose);
@@ -1719,9 +1808,41 @@
1719 1808 $this->import_settings();
1720 1809
1721 1810 /* action */
1722 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 + }
1723 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);
1724 1845 return true;
1725 1846 }
1726 1847
1727 1848 private function replace_meta($from = '', $to = '') {
@@ -1733,15 +1854,156 @@
1733 1854 "WHERE `meta_key` = '_elementor_data' AND `meta_value` LIKE '[%' ;" );
1734 1855 /* end login */
1735 1856 }
1736 1857
1737 - public function import_settings() {
1858 + private function import_settings() {
1859 + wdk_access_check('settings_m', 1);
1860 +
1738 1861 update_option( 'wdk_is_category_enabled', '1' );
1739 1862 update_option( 'wdk_is_location_enabled', '1' );
1740 1863 update_option( 'wdk_is_address_enabled', '1' );
1741 - update_option( 'wdk_is_results_page_require', '1' );
1864 + update_option( 'wdk_is_results_page_require', 0 );
1742 1865 update_option( 'wdk_seo_description', '2' );
1743 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 +
1744 1875 return true;
1745 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 +
1746 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 +
1747 2009 }