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_listing.php +107 -25 1.3.1 → 1.5.9 View file →
@@ -5,8 +5,87 @@
5 5
6 6 public function __construct(){
7 7 parent::__construct();
8 8 }
9 +
10 + public function copy()
11 + {
12 + $this->load->model('field_m');
13 + $this->load->model('listing_m');
14 + $this->load->model('listingfield_m');
15 + $this->load->model('listingusers_m');
16 + $this->load->model('category_m');
17 + $this->load->model('location_m');
18 + $this->load->model('user_m');
19 + $this->load->model('categorieslistings_m');
20 + $this->load->model('locationslistings_m');
21 +
22 + $from_id = intval($_GET['from_id']);
23 + $to_lang = sanitize_text_field(wp_unslash($_GET['to_lang']));
24 +
25 + // fetch data
26 + $listing_post = get_post( $from_id );
27 +
28 + $listing_db_data = $this->listing_m->get($from_id, TRUE);
29 +
30 + $listingfield_db_data = $this->listingfield_m->get($from_id, TRUE);
31 + $listingusers_db_data = $this->listingusers_m->get($from_id);
32 +
33 + $lang_from_code = pll_get_post_language($from_id);
34 +
35 + $post_data = array(
36 + 'post_title' => wp_strip_all_tags($listing_post->post_title).' '.$to_lang,
37 + 'post_content' => $listing_post->post_content,
38 + 'post_status' => 'publish',
39 + 'post_type' => 'wdk-listing',
40 + 'post_author' => get_current_user_id()
41 + // Other fields as needed
42 + );
43 +
44 + // Insert the custom post into the database
45 + $post_id = wp_insert_post($post_data);
46 +
47 + pll_set_post_language($post_id, $to_lang);
48 +
49 + // Link the translations together
50 + pll_save_post_translations(array(
51 + $lang_from_code => $from_id,
52 + $to_lang => $post_id,
53 + ));
54 +
55 + $listing_data = array('post_id' => $post_id);
56 +
57 +
58 + $listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images','listing_plans_documents', 'is_featured', 'is_activated','is_approved', 'package_id','rank','subscription_id',
59 + 'user_id_editor', 'listing_parent_post_id','listing_related_ids');
60 + foreach($listing_data_fields as $field_name)
61 + {
62 + if(isset($listing_db_data->$field_name))
63 + $listing_data[$field_name] = $listing_db_data->$field_name;
64 + }
65 +
66 + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s');
67 +
68 + // copy listing data
69 + $this->listing_m->insert($listing_data, NULL);
70 +
71 + if($this->db->last_error() != '')
72 + exit('DB Error: '.esc_html($this->db->last_error()));
73 +
74 + $this->data['listing_fields'] = $this->field_m->get();
75 +
76 + foreach($this->data['listing_fields'] as $field_data)
77 + {
78 + if(isset($listing_db_data->{'field_'.$field_data->idfield.'_'.$field_data->field_type}))
79 + $listing_data['field_'.$field_data->idfield] = $listing_db_data->{'field_'.$field_data->idfield.'_'.$field_data->field_type};
80 + }
81 +
82 + $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $listing_data, NULL);
83 +
84 + //exit($this->db->last_query());
85 +
86 + wp_redirect(get_admin_url() . "admin.php?page=wdk_listing&id=".$post_id);
87 + }
9 88
10 89 // Edit listing method
11 90 public function index()
12 91 {
@@ -112,26 +191,17 @@
112 191 $Winter_MVC_wdk_membership->model('subscription_user_m');
113 192 $Winter_MVC_wdk_membership->model('subscription_m');
114 193
115 194 $this->db->select('*');
116 - $this->db->join($Winter_MVC_wdk_membership->subscription_m->_table_name.' ON '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.idsubscription = '.$Winter_MVC_wdk_membership->subscription_user_m->_table_name.'.subscription_id');
117 195 $this->db->join($this->db->prefix.'wdk_categories ON '.$this->db->prefix.'wdk_categories.idcategory = '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.category_id', TRUE, 'LEFT');
118 196 $this->db->join($this->db->prefix.'wdk_locations ON '.$this->db->prefix.'wdk_locations.idlocation = '.$Winter_MVC_wdk_membership->subscription_m->_table_name.'.location_id', TRUE, 'LEFT');
119 - $this->db->where(array(
120 - '(date_expire > \''.current_time( 'mysql' ).'\')'=>NULL,
121 - '(user_id = \''.wmvc_show_data('user_id_editor', $this->data['db_data'], false).'\')'=>NULL,
122 - '(status = \'ACTIVE\')'=>NULL,
123 - )
124 - );
125 -
126 - $subscriptions = $Winter_MVC_wdk_membership->subscription_user_m->get();
197 + $subscriptions = $Winter_MVC_wdk_membership->subscription_m->get();
127 198 if (count($subscriptions) > 0) {
128 199 foreach($subscriptions as $subscription) {
129 - $this->data['subscriptions'][wdk_show_data('subscription_id',$subscription,'', TRUE, TRUE)] = wdk_show_data('subscription_id', $subscription,'', TRUE, TRUE)
200 + $this->data['subscriptions'][wdk_show_data('idsubscription', $subscription,'', TRUE, TRUE)] = wdk_show_data('idsubscription', $subscription,'', TRUE, TRUE)
130 201 .', '.wdk_show_data('subscription_name', $subscription,'', TRUE, TRUE)
131 202 .', '.wdk_show_data('location_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Location', 'wpdirectorykit')
132 - .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit')
133 - .'('.wdk_get_date(wdk_show_data('date_expire', $subscription,'', TRUE, TRUE)).')';
203 + .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit');
134 204 }
135 205 }
136 206 }
137 207
@@ -236,13 +306,9 @@
236 306 'field' => 'listing_parent_post_id',
237 307 'label' => __('Listing parent id', 'wpdirectorykit'),
238 308 'rules' => ''
239 309 ),
240 - array(
241 - 'field' => 'listing_related_ids',
242 - 'label' => __('Listing childs', 'wpdirectorykit'),
243 - 'rules' => ''
244 - ),
310 +
245 311 );
246 312
247 313 $rules[] = array(
248 314 'field' => 'rank',
@@ -250,8 +316,16 @@
250 316 'rules' => 'numeric'
251 317 );
252 318
253 319
320 + if(wdk_get_option('wdk_sub_listings_enable')) {
321 + $rules[] = array(
322 + 'field' => 'listing_related_ids',
323 + 'label' => __('Listing childs', 'wpdirectorykit'),
324 + 'rules' => 'wdk_related_validation'
325 + );
326 + }
327 +
254 328 foreach($this->data['fields'] as $key => $field)
255 329 {
256 330 if($field->field_type == 'SECTION'){
257 331 $this->data['fields'][$key]->is_required = '';
@@ -312,8 +386,9 @@
312 386 $this->data['db_data']['field_'.$field->idfield.'_'.$field->field_type];
313 387 }
314 388
315 389 $this->form->add_error_message('wdk_gps_single', __('Gps field is not valid, should be like xx.xxxxxx (between -180 and 180)', 'wpdirectorykit'));
390 + $this->form->add_error_message('wdk_related_validation', __('Related listings must not contain child listings and cannot be child listings themselves.', 'wpdirectorykit'));
316 391 if($this->form->run($rules))
317 392 {
318 393 // Check _wpnonce
319 394 check_admin_referer( 'wdk-listing-edit_'.$listing_post_id, '_wpnonce' );
@@ -343,13 +418,17 @@
343 418 $listing_data = array('post_id' => $id);
344 419
345 420 $listing_data_fields = array('category_id', 'location_id', 'address', 'lat', 'lng', 'listing_images','listing_plans_documents', 'is_featured', 'is_activated','is_approved', 'package_id','rank','subscription_id',
346 421 'user_id_editor', 'listing_parent_post_id','listing_related_ids');
422 +
347 423 foreach($listing_data_fields as $field_name)
348 424 {
349 - $listing_data[$field_name] = $data[$field_name];
425 + $listing_data[$field_name] = $data[$field_name] ?? '';
350 426 }
351 427
428 + if(empty($listing_data['user_id_editor']))
429 + $listing_data['user_id_editor'] = $this->data['db_data']['user_id_editor'] = get_current_user_id();
430 +
352 431 $image_ids = array();
353 432 if(!empty($data['listing_images']))
354 433 $image_ids = explode(',', $data['listing_images']);
355 434
@@ -372,9 +451,9 @@
372 451 }
373 452
374 453 $image_url = wp_get_attachment_image_url($image_id, 'large');
375 454 if($image_url) {
376 - $parsed = parse_url($image_url);
455 + $parsed = wp_parse_url($image_url);
377 456 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8);
378 457
379 458 if(!empty($listing_data['listing_images_path_medium']))
380 459 $listing_data['listing_images_path_medium'] .= ',';
@@ -382,8 +461,11 @@
382 461 $listing_data['listing_images_path_medium'] .= $next_path;
383 462 }
384 463 }
385 464 }
465 +
466 + /* add featured images */
467 + set_post_thumbnail($id, reset($image_ids));
386 468 }
387 469
388 470 if((wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) && $this->input->post('slug')) {
389 471 // update the post slug
@@ -413,9 +495,9 @@
413 495 $package = $Winter_MVC_wdk_payments->package_m->get(wmvc_show_data('package_id', $listing_data_field, false), TRUE);
414 496 if ($packages) {
415 497 if(!isset($listing_data['rank']) || empty($listing_data['rank']))
416 498 $listing_data['rank'] = wdk_show_data('featured_rank',$package, 0, TRUE, TRUE);
417 - $listing_data['date_package_expire'] = date('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days'));
499 + $listing_data['date_package_expire'] = gmdate('Y-m-d H:i:s', strtotime('+'.wdk_show_data('days_limit',$package, 0, TRUE, TRUE).'days'));
418 500 }
419 501 }
420 502
421 503 /* dates set */
@@ -421,9 +503,9 @@
421 503 /* dates set */
422 504 if(isset($this->data['db_data']['date']))
423 505 $listing_data['date'] = $this->data['db_data']['date'];
424 506
425 - $listing_data['date_modified'] = date('Y-m-d H:i:s');
507 + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s');
426 508
427 509 if(empty($listing_db_data))
428 510 {
429 511 $id_ret = $this->listing_m->insert($listing_data, NULL);
@@ -433,9 +515,9 @@
433 515 $id_ret = $this->listing_m->insert($listing_data, $id);
434 516 }
435 517
436 518 if($this->db->last_error() != '')
437 - exit('DB Error: '.$this->db->last_error());
519 + exit('DB Error: '.esc_html($this->db->last_error()));
438 520
439 521 //var_dump($id_ret);
440 522
441 523 // insert users/agents
@@ -497,9 +579,9 @@
497 579
498 580 global $wpdb;
499 581 foreach($this->data['fields'] as $key => $field)
500 582 {
501 - if($field->field_type == 'TEXTAREA'){
583 + if($field->field_type == 'TEXTAREA' && !empty($data['field_'.$field->idfield])){
502 584 $data[ 'field_'.$field->idfield ] = wp_encode_emoji( $data['field_'.$field->idfield] );
503 585 }
504 586 }
505 587
@@ -512,15 +594,15 @@
512 594 $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, $id);
513 595 }
514 596
515 597 if($this->db->last_error() != '')
516 - exit('DB Error: '.$this->db->last_error());
598 + exit('DB Error: '.esc_html($this->db->last_error()));
517 599
518 600 $this->load->model('editlog_m');
519 601 $this->editlog_m->insert(array(
520 602 'user_id' => get_current_user_id(),
521 603 'post_id' => $id,
522 - 'date' => date('Y-m-d H:i:s'),
604 + 'date' => gmdate('Y-m-d H:i:s'),
523 605 'ip' => $_SERVER['REMOTE_ADDR']
524 606 ));
525 607
526 608