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