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 +603 -115 1.2.3 → 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
@@ -15,10 +30,11 @@
15 30 $this->load->model('settings_m');
16 31 $this->data['db_data'] = NULL;
17 32 $this->data['form'] = &$this->form;
18 33 $this->data['fields'] = $this->settings_m->fields_list;
34 + $this->data['fields_list_tabs'] = $this->settings_m->fields_list_tabs;
19 35
20 - $this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _ ', 'wpdirectorykit'));
36 + $this->form->add_error_message('wdk_slug_format', __('Custom Listing Preview Page Slug allowed only a-z 0-9 - _', 'wpdirectorykit'));
21 37
22 38 if($this->form->run($this->data['fields']))
23 39 {
24 40
@@ -59,11 +75,213 @@
59 75 {
60 76 $this->data['db_data'][$field->option_name] = $field->option_value;
61 77 }
62 78
79 + $this->mailtemplates();
80 +
63 81 $this->load->view('wdk_settings/index', $this->data);
64 82 }
83 +
84 + // Edit listing method
85 + public function mailtemplate()
86 + {
65 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 +
66 284 function reset_data () {
67 285
68 286 wdk_access_check('settings_m', 1);
69 287
@@ -129,9 +347,9 @@
129 347 }
130 348
131 349 $redirect_url = admin_url("admin.php?page=wdk_settings&is_updated");
132 350 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
133 - $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
351 + $redirect_url = admin_url(sanitize_text_field(wp_unslash($_GET['redirect_url'])));
134 352
135 353 wp_redirect($redirect_url);
136 354 exit;
137 355 }
@@ -139,9 +357,8 @@
139 357 // Import demo data listing method
140 358 public function import_demo()
141 359 {
142 360 wdk_access_check('settings_m', 1);
143 -
144 361 $this->load->model('field_m');
145 362 $this->load->model('listingfield_m');
146 363 $this->load->model('listing_m');
147 364 $this->load->model('category_m');
@@ -184,12 +401,16 @@
184 401 closedir($dh);
185 402 }
186 403 }
187 404 }
405 +
188 406 ksort($multipurpose_values);
189 407 if(count($multipurpose_values) > 0)
190 408 $this->data['fields']['multipurpose'] = array('field'=>'multipurpose', 'field_label'=>__('Portal version', 'wpdirectorykit'), 'field_type'=>'DROPDOWN', 'rules'=>'required', 'values'=>$multipurpose_values);
191 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']);
192 413
193 414 $this->data['form'] = &$this->form;
194 415 ini_set('max_execution_time', 900);
195 416
@@ -227,11 +448,13 @@
227 448
228 449 $this->data['db_data']['multipurpose'] = 'real-estate.xml';
229 450
230 451 if(isset($_GET['multipurpose']))
231 - $this->data['db_data']['multipurpose'] = sanitize_text_field($_GET['multipurpose']);
452 + $this->data['db_data']['multipurpose'] = sanitize_text_field(wp_unslash($_GET['multipurpose']));
232 453
233 454 $this->data['import_log'] = '';
455 + $this->data['info_log_message'] = '';
456 +
234 457 $rules = array(
235 458 array(
236 459 'field' => 'import_locations',
237 460 'label' => __('Locations', 'wpdirectorykit'),
@@ -275,9 +498,9 @@
275 498 );
276 499
277 500 $plugin = 'elementor/elementor.php';
278 501 if (in_array( $plugin, apply_filters( 'active_plugins', get_option( 'active_plugins' ))) && !class_exists('Elementor\Plugin') ) {
279 - $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Your Elementor Plugin is not fully active, usually this happen because of old PHP version on server, in such case eventually you can try older Elementor Version or Update PHP on your server').'</div>';
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>';
280 503 $this->data['required_plugins'] = true;
281 504 }
282 505
283 506 if(!$this->data['required_plugins'])
@@ -282,14 +505,25 @@
282 505
283 506 if(!$this->data['required_plugins'])
284 507 if($this->form->run($rules))
285 508 {
509 + update_option('wdk_install_images_sizes_disable', 1);
510 +
286 511 // Check _wpnonce
287 512 check_admin_referer( 'wdk-settings_import', '_wpnonce' );
288 513
289 514 // Save procedure for basic data
290 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);
291 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 +
292 526 $this->import_settings();
293 527
294 528 if( !empty($data['import_locations'])) {
295 529 $this->import_locations();
@@ -302,9 +536,9 @@
302 536 if( !empty($data['import_fields'])) {
303 537 $this->import_fields($data['multipurpose']);
304 538 }
305 539
306 - if( !empty($data['import_listings'])) {
540 + if( !empty($data['import_listings'])) {
307 541 $this->import_listings($data['multipurpose']);
308 542 }
309 543
310 544 if( !empty($data['import_visual_data'])) {
@@ -320,9 +554,16 @@
320 554 }
321 555
322 556 $this->replace_content_data($data['multipurpose']);
323 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);
324 564 }
565 +
325 566 $this->load->view('wdk_install/index', $this->data);
326 567 }
327 568
328 569 // Import demo data listing method
@@ -348,19 +589,21 @@
348 589 $this->load->model('listingfield_m');
349 590 $this->load->model('listing_m');
350 591 $this->load->model('resultitem_m');
351 592 $this->load->model('searchform_m');
593 + $this->load->model('dependfields_m');
352 594
353 595 /* remove fields */
354 596 $this->db->delete($this->location_m->_table_name);
355 597
356 - $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>';
357 599 /* end remove fields */
358 600
359 601 /* remove fields */
360 602 $this->db->delete($this->category_m->_table_name);
603 + $this->db->delete($this->dependfields_m->_table_name);
361 604
362 - $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>';
363 606 /* end remove fields */
364 607
365 608 /* remove fields */
366 609 $this->db->delete($this->field_m->_table_name);
@@ -369,9 +612,9 @@
369 612 if(strpos($field_name, 'field_') ===FALSE) continue;
370 613 $this->db->query('ALTER TABLE '.$this->listingfield_m->_table_name.' DROP COLUMN '.$field_name.'');
371 614 }
372 615
373 - $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>';
374 617 /* end remove fields */
375 618
376 619 /* remove listings */
377 620 $this->db->delete($this->listing_m->_table_name);
@@ -376,9 +619,9 @@
376 619 /* remove listings */
377 620 $this->db->delete($this->listing_m->_table_name);
378 621 $this->db->delete($this->listingfield_m->_table_name);
379 622
380 - $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>';
381 624 /* end remove listings */
382 625
383 626
384 627 /* remove listings */
@@ -383,9 +626,9 @@
383 626
384 627 /* remove listings */
385 628 $this->db->delete($this->resultitem_m->_table_name);
386 629 $this->db->delete($this->searchform_m->_table_name);
387 - $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>';
388 631 /* end remove listings */
389 632
390 633
391 634 /* reset autoincrement */
@@ -391,14 +634,15 @@
391 634 /* reset autoincrement */
392 635 $this->db->query('TRUNCATE TABLE `'.$this->location_m->_table_name.'`');
393 636 $this->db->query('TRUNCATE TABLE `'.$this->category_m->_table_name.'`');
394 637 $this->db->query('TRUNCATE TABLE `'.$this->field_m->_table_name.'`');
638 + $this->db->query('TRUNCATE TABLE `'.$this->dependfields_m->_table_name.'`');
395 639 $this->db->query('TRUNCATE TABLE `'.$this->listingfield_m->_table_name.'`');
396 640 $this->db->query('TRUNCATE TABLE `'.$this->listing_m->_table_name.'`');
397 641 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
398 642 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
399 643
400 - $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>';
401 645 /* end reset autoincrement */
402 646
403 647 $wdk_posts = get_posts( array( 'post_type' => 'wdk-listing', 'numberposts' => -1));
404 648 foreach( $wdk_posts as $post ) {
@@ -408,9 +652,9 @@
408 652 }
409 653
410 654 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE){
411 655 if(wmvc_xss_clean($_GET['redirect_url']) =='on_install') {
412 - $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, ''));
413 657 } else {
414 658 $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
415 659 }
416 660 wp_redirect($redirect_url);
@@ -421,9 +665,9 @@
421 665
422 666 /* add demo pages */
423 667 private function demo_pages($purpose = '') {
424 668
425 - // 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;
426 670
427 671 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
428 672 $self->add_widget('Wdk\Elementor\Extensions\WdkContactFormExt');
429 673 });
@@ -576,16 +820,15 @@
576 820 $this->replace_meta($from, $to);
577 821
578 822 /* homepage */
579 823 $from = '2020';
580 - $to = date('Y');
824 + $to = gmdate('Y');
581 825 $this->replace_meta($from, $to);
582 826
583 827
584 828 /* replace in db */
585 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
586 - if(file_exists($xml_list)) {
587 - $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));
588 831 if(isset($dom_array['replace']) && !empty($dom_array['replace'])) {
589 832 if(!empty($dom_array['replace']['text'])) {
590 833 foreach($dom_array['replace']['text'] as $string){
591 834 if(!isset($string['@attributes']) || !isset($string['@attributes']['from']) || !isset($string['@attributes']['to'])) continue;
@@ -604,9 +847,9 @@
604 847 /* add demo listing preview page */
605 848 private function demo_page_listing($purpose = '') {
606 849
607 850 if((get_option('wdk_listing_page')) && get_post_status(get_option('wdk_listing_page')) =='publish'){
608 - $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>';
609 852 return false;
610 853 }
611 854
612 855 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -635,8 +878,9 @@
635 878 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
636 879 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
637 880 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
638 881 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
882 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
639 883 });
640 884
641 885 // Import elementor templates
642 886 $page_listing_preview = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas');
@@ -645,9 +889,9 @@
645 889 // Assign page.
646 890 if($page_listing_preview)
647 891 update_option( 'wdk_listing_page', $page_listing_preview->ID, TRUE);
648 892
649 - $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>';
650 894
651 895 return true;
652 896 }
653 897
@@ -654,9 +898,9 @@
654 898 /* add demo results page */
655 899 private function demo_page_results($purpose = '') {
656 900
657 901 if((get_option('wdk_results_page')) && get_post_status(get_option('wdk_results_page')) == 'publish'){
658 - $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>';
659 903 return false;
660 904 }
661 905
662 906 add_action('wpdirectorykit/elementor-elements/register_widget', function($self){
@@ -685,8 +929,9 @@
685 929 $self->add_widget('Wdk\Elementor\Widgets\WdkListingMap');
686 930 $self->add_widget('Wdk\Elementor\Widgets\WdkListinAgent');
687 931 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentField');
688 932 $self->add_widget('Wdk\Elementor\Widgets\WdkListingAgentAvatar');
933 + $self->add_widget('Wdk\Elementor\Widgets\WdkCoolListingCarousel');
689 934 });
690 935
691 936 $page_results = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas');
692 937 $this->elementor_assign($page_results->ID, 'page-results-listings.json');
@@ -696,9 +941,9 @@
696 941 update_option( 'page_on_front', $page_results->ID );
697 942
698 943 update_option( 'wdk_results_page', $page_results->ID, TRUE);
699 944
700 - $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>';
701 946
702 947
703 948 $menus = get_registered_nav_menus();
704 949 // first menu defined by template
@@ -730,8 +975,11 @@
730 975 wp_update_nav_menu_item((int)$menu_id, 0, $itemData);
731 976
732 977 // assign menu to top menu
733 978 $locations = get_theme_mod( 'nav_menu_locations' );
979 + if ( ! is_array( $locations ) ) {
980 + $locations = array();
981 + }
734 982 $locations[$first_menu] = $menu_id;
735 983 set_theme_mod('nav_menu_locations', $locations);
736 984 }
737 985
@@ -843,11 +1091,10 @@
843 1091 /* reset autoincrement */
844 1092 $this->db->query('TRUNCATE TABLE `'.$this->resultitem_m->_table_name.'`');
845 1093 $this->db->query('TRUNCATE TABLE `'.$this->searchform_m->_table_name.'`');
846 1094
847 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
848 - if(file_exists($xml_list)) {
849 - $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));
850 1097
851 1098 if(!isset($dom_array['search_form']) && empty($dom_array['search_form'])) {
852 1099 } else {
853 1100 // Save searchform_m
@@ -872,19 +1119,18 @@
872 1119 $data['idresultitem'] = 1;
873 1120 $insert_id = $this->resultitem_m->insert($data, NULL);
874 1121 }
875 1122
876 - $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>';
877 1124 return true;
878 1125 }
879 -
880 - $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>';
881 1128 return false;
882 1129
883 1130 }
884 1131
885 1132 private function import_locations() {
886 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/locations.xml';
887 1133 $this->load->model('location_m');
888 1134
889 1135 if($this->location_m->get()){
890 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
@@ -890,12 +1136,13 @@
890 1136 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Locations already imported', 'wpdirectorykit').'</div>';
891 1137 return false;
892 1138 }
893 1139
894 - if(file_exists($xml_list)) {
895 - $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));
896 1142 if(!isset($dom_array['locations']['location']) && empty($dom_array['locations']['location'])) {
897 - $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>';
898 1145 return false;
899 1146 }
900 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
901 1148 $this->_recursive_add_locations($location_data);
@@ -900,13 +1147,13 @@
900 1147 foreach ($dom_array['locations']['location'] as $key => $location_data) {
901 1148 $this->_recursive_add_locations($location_data);
902 1149 }
903 1150
904 - $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>';
905 1152 return true;
906 1153 }
907 -
908 - $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>';
909 1156 return false;
910 1157 }
911 1158
912 1159 private function _recursive_add_locations ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -926,16 +1173,16 @@
926 1173 if(empty(wmvc_show_data('location_title', $location_data))) {
927 1174 return false;
928 1175 }
929 1176
930 - 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'])){
931 1178 /* add files */
932 - $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']);
933 1180 }
934 1181
935 - 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'])){
936 1183 /* add files */
937 - $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']);
938 1185 }
939 1186
940 1187 $location_data['icon_path'] = wdk_generate_path_image($location_data['icon_id']);
941 1188 $location_data['image_path'] = wdk_generate_path_image($location_data['image_id']);
@@ -949,10 +1196,10 @@
949 1196 }
950 1197 }
951 1198
952 1199 private function import_categories($purpose = '') {
953 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
954 - $this->load->model('category_m');
1200 + $this->load->model('category_m') ;
1201 + $this->load->model('dependfields_m') ;
955 1202
956 1203 if($this->category_m->get()){
957 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
958 1205 return false;
@@ -957,12 +1204,13 @@
957 1204 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Categories already imported', 'wpdirectorykit').'</div>';
958 1205 return false;
959 1206 }
960 1207
961 - if(file_exists($xml_list)) {
962 - $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));
963 1210 if(!isset($dom_array['categories']['category']) && empty($dom_array['categories']['category'])) {
964 - $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>';
965 1213 return false;
966 1214 }
967 1215
968 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
@@ -968,13 +1216,24 @@
968 1216 foreach ($dom_array['categories']['category'] as $key => $category_data) {
969 1217 $this->_recursive_add_categories($category_data);
970 1218 }
971 1219
972 - $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>';
973 1232 return true;
974 1233 }
975 -
976 - $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>';
977 1236 return false;
978 1237 }
979 1238
980 1239 private function _recursive_add_categories ($data = array(), $parent_id = 0, $level = 0 ) {
@@ -1006,11 +1265,11 @@
1006 1265 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id']))
1007 1266 {
1008 1267 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['image_id'];
1009 1268 }
1010 - elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id']))
1269 + elseif(file_exists( $this->import_images_dir.$category_data['image_id']))
1011 1270 {
1012 - $file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['image_id'];
1271 + $file = $this->import_images_dir.$category_data['image_id'];
1013 1272 }
1014 1273 /* add files */
1015 1274
1016 1275 if($file)
@@ -1027,11 +1286,11 @@
1027 1286 elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id']))
1028 1287 {
1029 1288 $file = get_template_directory().'/demo-data/wpdirectorykit/images/'.$category_data['icon_id'];
1030 1289 }
1031 - elseif(file_exists( WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id']))
1290 + elseif(file_exists( $this->import_images_dir.$category_data['icon_id']))
1032 1291 {
1033 - $file = WPDIRECTORYKIT_PATH.'demo-data/images/'.$category_data['icon_id'];
1292 + $file = $this->import_images_dir.$category_data['icon_id'];
1034 1293 }
1035 1294 /* add files */
1036 1295
1037 1296 if($file)
@@ -1042,8 +1301,21 @@
1042 1301 $category_data['image_path'] = wdk_generate_path_image($category_data['image_id']);
1043 1302
1044 1303 /* add categories */
1045 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 +
1046 1318 if(isset($data['childs']["category"]) && !empty($data['childs']["category"])) {
1047 1319 foreach ($data['childs']["category"] as $sub_category_data) {
1048 1320 $this->_recursive_add_categories($sub_category_data, $insert_id, ($level+1));
1049 1321 }
@@ -1057,14 +1329,12 @@
1057 1329 if($this->field_m->get()){
1058 1330 $this->data['import_log'] .= '<div class="alert alert-danger" role="alert">'.esc_html__('Fields already imported', 'wpdirectorykit').'</div>';
1059 1331 return false;
1060 1332 }
1061 -
1062 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
1063 1333
1064 1334 $sections_added_array = array();
1065 - if(file_exists($xml_list)) {
1066 - $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));
1067 1337
1068 1338 $base = array(
1069 1339 'field_type' => '',
1070 1340 'field_label' => '',
@@ -1080,9 +1350,10 @@
1080 1350 'order_index' => '',
1081 1351 );
1082 1352
1083 1353 if(!isset($dom_array['fields']['field']) && empty($dom_array['fields']['field'])) {
1084 - $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>';
1085 1356 return false;
1086 1357 }
1087 1358
1088 1359 foreach ($dom_array['fields']['field'] as $key => $field) {
@@ -1134,13 +1405,13 @@
1134 1405 if(!empty($insert_id))
1135 1406 $this->listingfield_m->create_table_column($field_data, $insert_id);
1136 1407 }
1137 1408
1138 - $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>';
1139 1410 return true;
1140 1411 }
1141 -
1142 - $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>';
1143 1414 return false;
1144 1415 }
1145 1416
1146 1417 private function import_listings($purpose = '') {
@@ -1180,13 +1451,12 @@
1180 1451 }
1181 1452 }
1182 1453
1183 1454 // Open a known directory, and proceed to read its contents
1184 - $dir = WPDIRECTORYKIT_PATH.'demo-data/images';
1185 1455 $purpose_name = str_replace('.xml','',$purpose);
1186 1456 $files = array();
1187 - if (is_dir($dir)) {
1188 - if ($dh = opendir($dir)) {
1457 + if (is_dir($this->import_images_dir)) {
1458 + if ($dh = opendir($this->import_images_dir)) {
1189 1459 while (($file = readdir($dh)) !== false) {
1190 1460 if(strpos($file, '.jpg') !== false && strpos($file, $purpose_name) !== false && strpos($file, 'category') === false)
1191 1461 $files[] = $file;
1192 1462 }
@@ -1194,13 +1464,13 @@
1194 1464 }
1195 1465 }
1196 1466 sort($files);
1197 1467
1198 - $xml_list = WPDIRECTORYKIT_PATH.'demo-data/'.$purpose;
1199 - if(file_exists($xml_list)) {
1200 - $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));
1201 1470 if(!isset($dom_array['listings']['listing']) && empty($dom_array['listings']['listing'])) {
1202 - $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>';
1203 1473 return false;
1204 1474 }
1205 1475
1206 1476 /* demo agent add/get if exists */
@@ -1213,12 +1483,12 @@
1213 1483 $location_id = '';
1214 1484 $category_id = '';
1215 1485
1216 1486 if(!empty($categories))
1217 - $category_id = $categories[rand(0, count($categories)-1)];
1487 + $category_id = $categories[wp_rand(0, count($categories)-1)];
1218 1488
1219 1489 if(!empty($location))
1220 - $location_id = $locations[rand(0, count($locations)-1)];
1490 + $location_id = $locations[wp_rand(0, count($locations)-1)];
1221 1491
1222 1492 $data_listing = array(
1223 1493 'post_title' => '',
1224 1494 'post_content' => '',
@@ -1228,27 +1498,35 @@
1228 1498 'lat' => '',
1229 1499 'listing_images' => '',
1230 1500 'listing_images_path' => '',
1231 1501 'listing_images_path_medium' => '',
1232 - 'date_modified' => date('Y-m-d H:i:s'),
1502 + 'date_modified' => gmdate('Y-m-d H:i:s'),
1233 1503 'lng' => '',
1234 1504 'is_featured' => '',
1235 1505 'is_activated' => '1',
1236 1506 'is_approved' => '1',
1507 + 'counter_views' => wp_rand(20,250),
1237 1508 'user_id_editor' => NULL,
1238 1509 );
1239 -
1510 +
1240 1511 $data_listing = array_intersect_key(array_merge($data_listing, $listing), $data_listing);
1241 1512 array_walk($data_listing, function(&$item){$item = (is_array($item)) ? '' : trim(wmvc_xss_clean($item));});
1242 -
1513 +
1243 1514 if(empty(wmvc_show_data('post_title', $data_listing))) {
1244 1515 continue;
1245 1516 }
1246 1517
1518 + $hidden_fields_list = wdk_depend_get_hidden_fields($data_listing['category_id']);
1519 +
1247 1520 /*fields */
1521 + $data_listings_fields = array();
1248 1522 foreach($fields as $field_data) {
1523 + if(!empty($hidden_fields_list) && strpos(','.$hidden_fields_list.',', ','.$field_data->idfield.',')!==FALSE) {
1524 + continue;
1525 + }
1526 +
1249 1527 if(isset($listing['field_'.$field_data->idfield])) {
1250 - $data_listing['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1528 + $data_listings_fields['field_'.$field_data->idfield] = $listing['field_'.$field_data->idfield];
1251 1529 } else {
1252 1530 if($field_data->field_type == 'DROPDOWN' || $field_data->field_type == 'DROPDOWN_MULTIPLE')
1253 1531 {
1254 1532 if(empty($field_data->values_list)) continue;
@@ -1256,67 +1534,110 @@
1256 1534 if(count($values) > 0)
1257 1535 {
1258 1536 $start=0;
1259 1537 if(empty($values[0]))$start=1;
1260 - $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)];
1261 1539 }
1262 1540 }
1263 1541 elseif($field_data->field_type == 'NUMBER')
1264 1542 {
1265 - $data_listing['field_'.$field_data->idfield] = rand(2,499);
1543 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(2,499);
1266 1544
1267 1545 }
1268 1546 elseif($field_data->field_type == 'CHECKBOX')
1269 1547 {
1270 - $data_listing['field_'.$field_data->idfield] = rand(0,1);
1548 + $data_listings_fields['field_'.$field_data->idfield] = wp_rand(0,1);
1271 1549 }
1272 1550 elseif($field_data->field_type == 'TEXTAREA')
1273 1551 {
1274 - //$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.';
1275 1553 }
1276 1554 }
1277 1555 }
1278 1556
1279 1557 /* add files */
1280 - $count_images = 2;
1558 +
1281 1559 if($purpose == 'car-dealer.xml') {
1282 - $count_images = 1;
1560 + $this->import_count_images = 1;
1283 1561 }
1562 + if(isset($listing['images']) && !empty($listing['images'])) {
1284 1563
1285 - for ($i=0,$image_num=$listing_num; $i<$count_images; $i++,$image_num++) {
1286 - if($image_num >= count($files))
1287 - $image_num = 0;
1564 + foreach (explode(',', $listing['images']) as $key => $file_name) {
1565 +
1566 + if(empty($file_name)) continue;
1288 1567
1289 - if(!empty($data_listing['listing_images']))
1290 - $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));
1291 1571
1292 - $image_id = wmvc_add_wp_image(WPDIRECTORYKIT_PATH.'demo-data/images/'.esc_html($files[$image_num]));
1293 - $data_listing['listing_images'] .= $image_id;
1572 + $data_listing['listing_images'] .= $image_id;
1294 1573
1295 - $image_path = wp_get_original_image_path( $image_id);
1574 + $image_path = wp_get_original_image_path( $image_id);
1296 1575
1297 - if($image_path) {
1298 - /* path of image */
1299 - $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1576 + if($image_path) {
1577 + /* path of image */
1578 + $next_path = str_replace(WP_CONTENT_DIR . '/uploads/','', $image_path);
1300 1579
1301 - /* check length listing_images_path + next image + comma, should be less 200*/
1302 - if(strlen($data_listing['listing_images_path'].$next_path)<195) {
1303 - if(!empty($data_listing['listing_images_path']))
1304 - $data_listing['listing_images_path'] .= ',';
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'] .= ',';
1305 1584
1306 - $data_listing['listing_images_path'] .= $next_path;
1585 + $data_listing['listing_images_path'] .= $next_path;
1586 + }
1307 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 + }
1308 1599 }
1309 1600
1310 - $image_url = wp_get_attachment_image_url($image_id, 'large');
1311 - if($image_url) {
1312 - $parsed = parse_url($image_url);
1313 - $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
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;
1314 1606
1315 - if(!empty($data_listing['listing_images_path_medium']))
1316 - $data_listing['listing_images_path_medium'] .= ',';
1607 + if(!empty($data_listing['listing_images']))
1608 + $data_listing['listing_images'].= ',';
1317 1609
1318 - $data_listing['listing_images_path_medium'] .= $next_path;
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 + }
1319 1640 }
1320 1641 }
1321 1642
1322 1643 // Create post object
@@ -1338,19 +1659,22 @@
1338 1659 if(isset( $data_listing[$field_name]))
1339 1660 $listing_data[$field_name] = $data_listing[$field_name];
1340 1661 }
1341 1662 $listing_data['user_id_editor'] = $user_ids[array_rand($user_ids)];
1342 -
1663 + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s');
1664 + $listing_data['counter_views'] = wp_rand(20,250);
1665 +
1343 1666 $this->listing_m->insert($listing_data, NULL);
1344 1667
1345 - $data_listing['post_id'] = $id;
1346 - $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);
1347 1670 }
1348 - $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported').'</div>';
1671 +
1672 + $this->data['import_log'] .= '<div class="alert alert-success" role="alert">'.esc_html__('Listings imported', 'wpdirectorykit').'</div>';
1349 1673 return true;
1350 1674 }
1351 -
1352 - $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>';
1353 1677 return false;
1354 1678 }
1355 1679
1356 1680 protected function xmlstr_to_array($xmlstr) {
@@ -1415,10 +1739,10 @@
1415 1739 wdk_access_check('settings_m', 1);
1416 1740
1417 1741 // Check _wpnonce
1418 1742 check_admin_referer( 'wdk-import-data-run', '_wpnonce' );
1743 + update_option('wdk_install_images_sizes_disable', 1);
1419 1744
1420 -
1421 1745 ini_set('max_execution_time', 900);
1422 1746 $this->data['import_log'] = '';
1423 1747 $multipurpose = 'real-estate.xml';
1424 1748 if(isset($_GET['multipurpose']))
@@ -1427,8 +1751,14 @@
1427 1751 $redirect_url = admin_url("admin.php?page=wdk_fields&is_updated");
1428 1752 if(isset($_GET['redirect_url']) && strpos($_GET['redirect_url'], 'http') === FALSE && strpos($_GET['redirect_url'], '//') === FALSE)
1429 1753 $redirect_url = admin_url(sanitize_text_field($_GET['redirect_url']));
1430 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 +
1431 1761 $this->import_locations();
1432 1762 $this->import_categories($multipurpose);
1433 1763 $this->import_fields($multipurpose);
1434 1764 $this->import_listings($multipurpose);
@@ -1434,10 +1764,14 @@
1434 1764 $this->import_listings($multipurpose);
1435 1765 $this->import_visual_data($multipurpose);
1436 1766 $this->demo_pages($multipurpose);
1437 1767
1438 - $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>');
1439 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 +
1440 1774 wp_redirect($redirect_url.'&message='.$message);
1441 1775 exit;
1442 1776 }
1443 1777
@@ -1443,9 +1777,9 @@
1443 1777
1444 1778 public function api_import()
1445 1779 {
1446 1780 wdk_access_check('settings_m', 1);
1447 -
1781 + update_option('wdk_install_images_sizes_disable', 1);
1448 1782 /* block url access */
1449 1783 if(
1450 1784 (isset($_GET['function']) && $_GET['function'] == 'api_import' ) ||
1451 1785 (isset($_POST['function']) && $_POST['function'] == 'api_import' )
@@ -1459,8 +1793,14 @@
1459 1793 $multipurpose = 'real-estate.xml';
1460 1794 if(isset($_GET['multipurpose']))
1461 1795 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1462 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 +
1463 1803 $this->import_locations();
1464 1804 $this->import_categories($multipurpose);
1465 1805 $this->import_fields($multipurpose);
1466 1806 $this->import_listings($multipurpose);
@@ -1468,15 +1808,19 @@
1468 1808 $this->import_settings();
1469 1809
1470 1810 /* action */
1471 1811 do_action('wpdirectorykit/install/api');
1472 -
1812 + do_action('wdk/settings/import/api_run', $multipurpose);
1813 + update_option('wdk_install_images_sizes_disable', 0);
1473 1814 return true;
1474 1815 }
1475 1816
1476 - public function _api_import()
1817 + public function _api_import($import_count_images = 2)
1477 1818 {
1819 + $this->import_count_images = $import_count_images;
1820 +
1478 1821 wdk_access_check('settings_m', 1);
1822 + update_option('wdk_install_images_sizes_disable', 1);
1479 1823 ini_set('max_execution_time', 900);
1480 1824 $this->data['import_log'] = '';
1481 1825 $multipurpose = 'real-estate.xml';
1482 1826 if(isset($_GET['multipurpose']))
@@ -1481,8 +1825,13 @@
1481 1825 $multipurpose = 'real-estate.xml';
1482 1826 if(isset($_GET['multipurpose']))
1483 1827 $multipurpose = sanitize_text_field($_GET['multipurpose']);
1484 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 +
1485 1834 $this->import_locations();
1486 1835 $this->import_categories($multipurpose);
1487 1836 $this->import_fields($multipurpose);
1488 1837 $this->import_listings($multipurpose);
@@ -1490,9 +1839,10 @@
1490 1839 $this->import_settings();
1491 1840
1492 1841 /* action */
1493 1842 do_action('wpdirectorykit/install/api');
1494 -
1843 + do_action('wdk/settings/import/api_run', $multipurpose);
1844 + update_option('wdk_install_images_sizes_disable', 0);
1495 1845 return true;
1496 1846 }
1497 1847
1498 1848 private function replace_meta($from = '', $to = '') {
@@ -1510,12 +1860,150 @@
1510 1860
1511 1861 update_option( 'wdk_is_category_enabled', '1' );
1512 1862 update_option( 'wdk_is_location_enabled', '1' );
1513 1863 update_option( 'wdk_is_address_enabled', '1' );
1514 - update_option( 'wdk_is_results_page_require', '1' );
1864 + update_option( 'wdk_is_results_page_require', 0 );
1515 1865 update_option( 'wdk_seo_description', '2' );
1516 1866 update_option( 'wdk_seo_keywords', '3' );
1517 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 +
1518 1875 return true;
1519 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 +
1520 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 +
1521 2009 }