| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | $this->load->model('categorieslistings_m'); |
| 20 | 20 | $this->load->model('locationslistings_m'); |
| 21 | 21 | |
| 22 | 22 | $from_id = intval($_GET['from_id']); |
| 23 | - $to_lang = sanitize_text_field($_GET['to_lang']); | |
| 23 | + $to_lang = sanitize_text_field(wp_unslash($_GET['to_lang'])); | |
| 24 | 24 | |
| 25 | 25 | // fetch data |
| 26 | 26 | $listing_post = get_post( $from_id ); |
| 27 | 27 | |
| @@ -62,15 +62,15 @@ | ||
| 62 | 62 | if(isset($listing_db_data->$field_name)) |
| 63 | 63 | $listing_data[$field_name] = $listing_db_data->$field_name; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $listing_data['date_modified'] = date('Y-m-d H:i:s'); | |
| 66 | + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s'); | |
| 67 | 67 | |
| 68 | 68 | // copy listing data |
| 69 | 69 | $this->listing_m->insert($listing_data, NULL); |
| 70 | 70 | |
| 71 | 71 | if($this->db->last_error() != '') |
| 72 | - exit('DB Error: '.$this->db->last_error()); | |
| 72 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 73 | 73 | |
| 74 | 74 | $this->data['listing_fields'] = $this->field_m->get(); |
| 75 | 75 | |
| 76 | 76 | foreach($this->data['listing_fields'] as $field_data) |
| @@ -191,26 +191,17 @@ | ||
| 191 | 191 | $Winter_MVC_wdk_membership->model('subscription_user_m'); |
| 192 | 192 | $Winter_MVC_wdk_membership->model('subscription_m'); |
| 193 | 193 | |
| 194 | 194 | $this->db->select('*'); |
| 195 | - $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'); | |
| 196 | 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'); |
| 197 | 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'); |
| 198 | - $this->db->where(array( | |
| 199 | - '(date_expire > \''.current_time( 'mysql' ).'\')'=>NULL, | |
| 200 | - '(user_id = \''.wmvc_show_data('user_id_editor', $this->data['db_data'], false).'\')'=>NULL, | |
| 201 | - '(status = \'ACTIVE\')'=>NULL, | |
| 202 | - ) | |
| 203 | - ); | |
| 204 | - | |
| 205 | - $subscriptions = $Winter_MVC_wdk_membership->subscription_user_m->get(); | |
| 197 | + $subscriptions = $Winter_MVC_wdk_membership->subscription_m->get(); | |
| 206 | 198 | if (count($subscriptions) > 0) { |
| 207 | 199 | foreach($subscriptions as $subscription) { |
| 208 | - $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) | |
| 209 | 201 | .', '.wdk_show_data('subscription_name', $subscription,'', TRUE, TRUE) |
| 210 | 202 | .', '.wdk_show_data('location_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Location', 'wpdirectorykit') |
| 211 | - .', '.wdk_show_data('category_title',$subscription, esc_html__('Any', 'wpdirectorykit'), TRUE, TRUE).' '. esc_html__('Category', 'wpdirectorykit') | |
| 212 | - .'('.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'); | |
| 213 | 204 | } |
| 214 | 205 | } |
| 215 | 206 | } |
| 216 | 207 | |
| @@ -315,13 +306,9 @@ | ||
| 315 | 306 | 'field' => 'listing_parent_post_id', |
| 316 | 307 | 'label' => __('Listing parent id', 'wpdirectorykit'), |
| 317 | 308 | 'rules' => '' |
| 318 | 309 | ), |
| 319 | - array( | |
| 320 | - 'field' => 'listing_related_ids', | |
| 321 | - 'label' => __('Listing childs', 'wpdirectorykit'), | |
| 322 | - 'rules' => '' | |
| 323 | - ), | |
| 310 | + | |
| 324 | 311 | ); |
| 325 | 312 | |
| 326 | 313 | $rules[] = array( |
| 327 | 314 | 'field' => 'rank', |
| @@ -329,8 +316,16 @@ | ||
| 329 | 316 | 'rules' => 'numeric' |
| 330 | 317 | ); |
| 331 | 318 | |
| 332 | 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 | + | |
| 333 | 328 | foreach($this->data['fields'] as $key => $field) |
| 334 | 329 | { |
| 335 | 330 | if($field->field_type == 'SECTION'){ |
| 336 | 331 | $this->data['fields'][$key]->is_required = ''; |
| @@ -391,8 +386,9 @@ | ||
| 391 | 386 | $this->data['db_data']['field_'.$field->idfield.'_'.$field->field_type]; |
| 392 | 387 | } |
| 393 | 388 | |
| 394 | 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')); | |
| 395 | 391 | if($this->form->run($rules)) |
| 396 | 392 | { |
| 397 | 393 | // Check _wpnonce |
| 398 | 394 | check_admin_referer( 'wdk-listing-edit_'.$listing_post_id, '_wpnonce' ); |
| @@ -422,13 +418,17 @@ | ||
| 422 | 418 | $listing_data = array('post_id' => $id); |
| 423 | 419 | |
| 424 | 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', |
| 425 | 421 | 'user_id_editor', 'listing_parent_post_id','listing_related_ids'); |
| 422 | + | |
| 426 | 423 | foreach($listing_data_fields as $field_name) |
| 427 | 424 | { |
| 428 | - $listing_data[$field_name] = $data[$field_name]; | |
| 425 | + $listing_data[$field_name] = $data[$field_name] ?? ''; | |
| 429 | 426 | } |
| 430 | 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 | + | |
| 431 | 431 | $image_ids = array(); |
| 432 | 432 | if(!empty($data['listing_images'])) |
| 433 | 433 | $image_ids = explode(',', $data['listing_images']); |
| 434 | 434 | |
| @@ -451,9 +451,9 @@ | ||
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | $image_url = wp_get_attachment_image_url($image_id, 'large'); |
| 454 | 454 | if($image_url) { |
| 455 | - $parsed = parse_url($image_url); | |
| 455 | + $parsed = wp_parse_url($image_url); | |
| 456 | 456 | $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/')+8); |
| 457 | 457 | |
| 458 | 458 | if(!empty($listing_data['listing_images_path_medium'])) |
| 459 | 459 | $listing_data['listing_images_path_medium'] .= ','; |
| @@ -461,8 +461,11 @@ | ||
| 461 | 461 | $listing_data['listing_images_path_medium'] .= $next_path; |
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | + | |
| 466 | + /* add featured images */ | |
| 467 | + set_post_thumbnail($id, reset($image_ids)); | |
| 465 | 468 | } |
| 466 | 469 | |
| 467 | 470 | if((wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) && $this->input->post('slug')) { |
| 468 | 471 | // update the post slug |
| @@ -492,9 +495,9 @@ | ||
| 492 | 495 | $package = $Winter_MVC_wdk_payments->package_m->get(wmvc_show_data('package_id', $listing_data_field, false), TRUE); |
| 493 | 496 | if ($packages) { |
| 494 | 497 | if(!isset($listing_data['rank']) || empty($listing_data['rank'])) |
| 495 | 498 | $listing_data['rank'] = wdk_show_data('featured_rank',$package, 0, TRUE, TRUE); |
| 496 | - $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')); | |
| 497 | 500 | } |
| 498 | 501 | } |
| 499 | 502 | |
| 500 | 503 | /* dates set */ |
| @@ -500,9 +503,9 @@ | ||
| 500 | 503 | /* dates set */ |
| 501 | 504 | if(isset($this->data['db_data']['date'])) |
| 502 | 505 | $listing_data['date'] = $this->data['db_data']['date']; |
| 503 | 506 | |
| 504 | - $listing_data['date_modified'] = date('Y-m-d H:i:s'); | |
| 507 | + $listing_data['date_modified'] = gmdate('Y-m-d H:i:s'); | |
| 505 | 508 | |
| 506 | 509 | if(empty($listing_db_data)) |
| 507 | 510 | { |
| 508 | 511 | $id_ret = $this->listing_m->insert($listing_data, NULL); |
| @@ -512,9 +515,9 @@ | ||
| 512 | 515 | $id_ret = $this->listing_m->insert($listing_data, $id); |
| 513 | 516 | } |
| 514 | 517 | |
| 515 | 518 | if($this->db->last_error() != '') |
| 516 | - exit('DB Error: '.$this->db->last_error()); | |
| 519 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 517 | 520 | |
| 518 | 521 | //var_dump($id_ret); |
| 519 | 522 | |
| 520 | 523 | // insert users/agents |
| @@ -576,9 +579,9 @@ | ||
| 576 | 579 | |
| 577 | 580 | global $wpdb; |
| 578 | 581 | foreach($this->data['fields'] as $key => $field) |
| 579 | 582 | { |
| 580 | - if($field->field_type == 'TEXTAREA'){ | |
| 583 | + if($field->field_type == 'TEXTAREA' && !empty($data['field_'.$field->idfield])){ | |
| 581 | 584 | $data[ 'field_'.$field->idfield ] = wp_encode_emoji( $data['field_'.$field->idfield] ); |
| 582 | 585 | } |
| 583 | 586 | } |
| 584 | 587 | |
| @@ -591,15 +594,15 @@ | ||
| 591 | 594 | $this->listingfield_m->insert_custom_fields($this->data['listing_fields'], $data, $id); |
| 592 | 595 | } |
| 593 | 596 | |
| 594 | 597 | if($this->db->last_error() != '') |
| 595 | - exit('DB Error: '.$this->db->last_error()); | |
| 598 | + exit('DB Error: '.esc_html($this->db->last_error())); | |
| 596 | 599 | |
| 597 | 600 | $this->load->model('editlog_m'); |
| 598 | 601 | $this->editlog_m->insert(array( |
| 599 | 602 | 'user_id' => get_current_user_id(), |
| 600 | 603 | 'post_id' => $id, |
| 601 | - 'date' => date('Y-m-d H:i:s'), | |
| 604 | + 'date' => gmdate('Y-m-d H:i:s'), | |
| 602 | 605 | 'ip' => $_SERVER['REMOTE_ADDR'] |
| 603 | 606 | )); |
| 604 | 607 | |
| 605 | 608 | |