| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | $output = json_decode($response); |
| 53 | 53 | $count = 0; |
| 54 | 54 | foreach ($output as $key => $value) { |
| 55 | 55 | $data['rss'][] = array( |
| 56 | - 'date' => wdk_get_date(wmvc_show_data('date', $value, date('Y-m-d H:i:s'), TRUE, TRUE), false), | |
| 56 | + 'date' => wdk_get_date(wmvc_show_data('date', $value, gmdate('Y-m-d H:i:s'), TRUE, TRUE), false), | |
| 57 | 57 | 'title' => wmvc_show_data('title', $value, '', TRUE, TRUE), |
| 58 | 58 | 'link' => wmvc_show_data('link', $value, '', TRUE, TRUE), |
| 59 | 59 | ); |
| 60 | 60 | $count++; |
| @@ -267,9 +267,9 @@ | ||
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | $image_url = wp_get_attachment_image_url($image_id, 'large'); |
| 270 | 270 | if ($image_url) { |
| 271 | - $parsed = parse_url($image_url); | |
| 271 | + $parsed = wp_parse_url($image_url); | |
| 272 | 272 | $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/') + 8); |
| 273 | 273 | |
| 274 | 274 | if (!empty($listing_data['listing_images_path_medium'])) |
| 275 | 275 | $listing_data['listing_images_path_medium'] .= ','; |
| @@ -595,8 +595,57 @@ | ||
| 595 | 595 | $data['popup_text_success'] = __('Strings generated', 'wpdirectorykit'); |
| 596 | 596 | $this->output($data); |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | + public function optimization_db_fields() | |
| 600 | + { | |
| 601 | + $data = array(); | |
| 602 | + $data['message'] = ''; | |
| 603 | + $data['popup_text_success'] = ''; | |
| 604 | + $data['popup_text_error'] = ''; | |
| 605 | + $data['parameters'] = $_POST; | |
| 606 | + $data['success'] = false; | |
| 607 | + | |
| 608 | + /* protect */ | |
| 609 | + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) { | |
| 610 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 611 | + $this->output($data); | |
| 612 | + } | |
| 613 | + | |
| 614 | + // Check _wpnonce | |
| 615 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 616 | + | |
| 617 | + $this->load->load_helper('listing'); | |
| 618 | + $this->load->model('field_m'); | |
| 619 | + $this->load->model('listingfield_m'); | |
| 620 | + | |
| 621 | + global $wpdb; | |
| 622 | + | |
| 623 | + $existing_listing_fields = $this->listingfield_m->get_available_fields(); | |
| 624 | + unset($existing_listing_fields['idlistings_fields'],$existing_listing_fields['post_id'],$existing_listing_fields['lang_code']); | |
| 625 | + | |
| 626 | + $fields = $this->field_m->get(); | |
| 627 | + foreach ($fields as $key => $field) { | |
| 628 | + // add exits fields | |
| 629 | + $field_col = 'field_'.$field->idfield.'_'.$field->field_type; | |
| 630 | + if(isset($existing_listing_fields[$field_col])) { | |
| 631 | + unset($existing_listing_fields[$field_col]); | |
| 632 | + } | |
| 633 | + } | |
| 634 | + $table_listing_fields = $wpdb->prefix . 'wdk_listings_fields'; | |
| 635 | + if(!empty($existing_listing_fields)) foreach ($existing_listing_fields as $field_listing_col => $field_listing) { | |
| 636 | + if(substr($field_listing_col, 0, 6) == 'field_') { | |
| 637 | + $wpdb->query( $wpdb->prepare( "ALTER TABLE `{$table_listing_fields}` DROP `$field_listing_col`;" ) ); | |
| 638 | + } | |
| 639 | + } | |
| 640 | + | |
| 641 | + | |
| 642 | + /* fields */ | |
| 643 | + $data['success'] = true; | |
| 644 | + $data['popup_text_success'] = __('Fields optimization', 'wpdirectorykit'); | |
| 645 | + $this->output($data); | |
| 646 | + } | |
| 647 | + | |
| 599 | 648 | public function loading_sublistings() |
| 600 | 649 | { |
| 601 | 650 | $data = array(); |
| 602 | 651 | $data['message'] = ''; |
| @@ -627,9 +676,8 @@ | ||
| 627 | 676 | $this->load->model('listing_m'); |
| 628 | 677 | |
| 629 | 678 | |
| 630 | 679 | $this->db->where($this->db->prefix . 'wdk_listings.post_id IN(' . wdk_field_value('listing_related_ids', $listing_id) . ')', null, false); |
| 631 | - $this->db->where(array('is_activated' => 1, 'is_approved' => 1)); | |
| 632 | 680 | $this->db->order_by('FIELD(' . $this->db->prefix . 'wdk_listings.post_id, ' . wdk_field_value('listing_related_ids', $listing_id) . ')'); |
| 633 | 681 | |
| 634 | 682 | $results = $this->listing_m->get(); |
| 635 | 683 | |
| @@ -640,12 +688,14 @@ | ||
| 640 | 688 | $_listing['post_content_short'] = wmvc_character_limiter(wdk_field_value('post_content', $sublisting), 30); |
| 641 | 689 | $_listing['date'] = wdk_get_date(wdk_field_value('date', $sublisting), false); |
| 642 | 690 | $_listing['location'] = wdk_field_value('location_title', $sublisting); |
| 643 | 691 | $_listing['category'] = wdk_field_value('category_title', $sublisting); |
| 692 | + $_listing['counter_views'] = wdk_field_value('counter_views', $sublisting); | |
| 693 | + $_listing['counter_results_views'] = wdk_field_value('counter_results_views', $sublisting); | |
| 644 | 694 | $_listing['image_src'] = wdk_image_src($sublisting); |
| 645 | - $_listing['listing_remove_url'] = get_admin_url() . "admin.php?page=wdk&function=delete&id=" . wdk_field_value('post_id', $sublisting); | |
| 695 | + $_listing['listing_remove_url'] = esc_url(get_admin_url() . "admin.php?page=wdk&function=delete&id=" . wdk_field_value('post_id', $sublisting)); | |
| 646 | 696 | $_listing['listing_view_url'] = get_permalink($sublisting); |
| 647 | - $_listing['listing_edit_url'] = get_admin_url() . "admin.php?page=wdk_listing&id=" . wdk_field_value('post_id', $sublisting); | |
| 697 | + $_listing['listing_edit_url'] = esc_url(get_admin_url() . "admin.php?page=wdk_listing&id=" . wdk_field_value('post_id', $sublisting)); | |
| 648 | 698 | $_listing['listing_dash_remove_url'] = ''; |
| 649 | 699 | $_listing['listing_dash_edit_url'] = ''; |
| 650 | 700 | if(function_exists(' wdk_dash_url')) { |
| 651 | 701 | $_listing['listing_dash_remove_url'] = wdk_dash_url("dash_page=listings&table_action=table&action=delete&ids=" . wdk_field_value('post_id', $sublisting)); |
| @@ -706,8 +756,237 @@ | ||
| 706 | 756 | |
| 707 | 757 | |
| 708 | 758 | $this->output($data); |
| 709 | 759 | } |
| 760 | + | |
| 761 | + public function reinstall_page() | |
| 762 | + { | |
| 763 | + $data = array(); | |
| 764 | + $data['message'] = ''; | |
| 765 | + $data['popup_text_success'] = ''; | |
| 766 | + $data['popup_text_error'] = ''; | |
| 767 | + $data['parameters'] = $_POST; | |
| 768 | + $data['success'] = false; | |
| 769 | + $data['page_id'] = false; | |
| 770 | + $data['page_title'] = false; | |
| 771 | + $data['results'] = array(); | |
| 772 | + /* protect */ | |
| 773 | + if(!wmvc_user_in_role('administrator')) { | |
| 774 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 775 | + $this->output($data); | |
| 776 | + } | |
| 777 | + | |
| 778 | + // Check _wpnonce | |
| 779 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 780 | + | |
| 781 | + $page = sanitize_text_field(wmvc_show_data('arg', $data['parameters'])); | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + // Import elementor templates | |
| 786 | + switch($page) { | |
| 787 | + case 'wdk_listing_page': | |
| 788 | + $new_page = $this->create_page(esc_html__('Listing Preview', 'wpdirectorykit'), '', 'elementor_canvas'); | |
| 789 | + $this->elementor_assign($new_page->ID, 'page-listing-preview.json'); | |
| 790 | + update_option('wdk_listing_page', $new_page->ID); | |
| 791 | + $data['page_title'] = esc_html__('Listing Preview', 'wpdirectorykit'); | |
| 792 | + break; | |
| 793 | + case 'wdk_results_page': | |
| 794 | + $new_page = $this->create_page(esc_html__('Results Listings', 'wpdirectorykit'), '', 'elementor_canvas'); | |
| 795 | + $this->elementor_assign($new_page->ID, 'page-results-listings.json'); | |
| 796 | + update_option('wdk_results_page', $new_page->ID); | |
| 797 | + $data['page_title'] = esc_html__('Results Listings', 'wpdirectorykit'); | |
| 798 | + break; | |
| 799 | + } | |
| 800 | + | |
| 801 | + if (empty($new_page)) { | |
| 802 | + $data['popup_text_error'] = __('Page not Created', 'wpdirectorykit'); | |
| 803 | + } else { | |
| 804 | + $data['page_id'] = $new_page->ID; | |
| 805 | + } | |
| 806 | + | |
| 807 | + if (empty($data['popup_text_error'])) { | |
| 808 | + $data['success'] = true; | |
| 809 | + } | |
| 810 | + | |
| 811 | + $this->output($data); | |
| 812 | + } | |
| 813 | + | |
| 814 | + public function wdk_save_ai_search_fields() | |
| 815 | + { | |
| 816 | + $data = array(); | |
| 817 | + $data['message'] = ''; | |
| 818 | + $data['popup_text_success'] = ''; | |
| 819 | + $data['popup_text_error'] = ''; | |
| 820 | + $data['parameters'] = $_POST; | |
| 821 | + $data['success'] = false; | |
| 822 | + $data['page_id'] = false; | |
| 823 | + $data['page_title'] = false; | |
| 824 | + $data['results'] = array(); | |
| 825 | + | |
| 826 | + /* protect */ | |
| 827 | + if(!wmvc_user_in_role('administrator')) { | |
| 828 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 829 | + $this->output($data); | |
| 830 | + } | |
| 831 | + | |
| 832 | + // Check _wpnonce | |
| 833 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 834 | + | |
| 835 | + $fields = isset($_POST['fields']) | |
| 836 | + ? array_filter( | |
| 837 | + array_map('intval', (array) wp_unslash($_POST['fields'])), | |
| 838 | + function($val) { return is_int($val) && $val > 0; } | |
| 839 | + ) | |
| 840 | + : []; | |
| 841 | + | |
| 842 | + | |
| 843 | + update_option( | |
| 844 | + 'wdk_ai_search_fields', | |
| 845 | + $fields | |
| 846 | + ); | |
| 847 | + | |
| 848 | + $data['popup_text_success'] = __('AI Search fields updated successfully.', 'wpdirectorykit'); | |
| 849 | + | |
| 850 | + if (empty($data['popup_text_error'])) { | |
| 851 | + $data['success'] = true; | |
| 852 | + } | |
| 853 | + | |
| 854 | + $this->output($data); | |
| 855 | + } | |
| 856 | + | |
| 857 | + public function upload_image() | |
| 858 | + { | |
| 859 | + $data = array(); | |
| 860 | + $data['message'] = ''; | |
| 861 | + $data['popup_text_success'] = ''; | |
| 862 | + $data['popup_text_error'] = ''; | |
| 863 | + $data['parameters'] = $_POST; | |
| 864 | + $data['success'] = false; | |
| 865 | + $data['page_id'] = false; | |
| 866 | + $data['page_title'] = false; | |
| 867 | + $data['results'] = array(); | |
| 868 | + /* protect */ | |
| 869 | + if(!wmvc_user_in_role('administrator')) { | |
| 870 | + $data['message'] = __('Disabled for current user', 'wpdirectorykit'); | |
| 871 | + $this->output($data); | |
| 872 | + } | |
| 873 | + | |
| 874 | + // Check _wpnonce | |
| 875 | + check_admin_referer( 'wdk-backendajax', '_wpnonce' ); | |
| 876 | + | |
| 877 | + if(!empty($data['parameters']['image'])) | |
| 878 | + foreach (explode(',', sanitize_text_field($_POST['image'])) as $key => $image_or_src) { | |
| 879 | + if(empty($image_or_src)) continue; | |
| 880 | + $image_id = wmvc_add_wp_image($image_or_src); | |
| 881 | + $image_url = wp_get_attachment_image_url($image_id, 'large'); | |
| 882 | + | |
| 883 | + $data['results'][] = [ | |
| 884 | + 'image_id'=> $image_id, | |
| 885 | + 'image_url'=> $image_url, | |
| 886 | + ]; | |
| 887 | + } | |
| 888 | + | |
| 889 | + | |
| 890 | + if (empty($data['popup_text_error'])) { | |
| 891 | + $data['success'] = true; | |
| 892 | + } | |
| 893 | + | |
| 894 | + $this->output($data); | |
| 895 | + } | |
| 896 | + | |
| 897 | + | |
| 898 | + /* Create Page */ | |
| 899 | + private function create_page($post_title, $post_content = '', $post_template = NULL, $post_parent=0, $rebuild = FALSE) | |
| 900 | + { | |
| 901 | + | |
| 902 | + $post_id = NULL; | |
| 903 | + | |
| 904 | + // Delete posts and rebuild | |
| 905 | + if($rebuild) { | |
| 906 | + | |
| 907 | + $post = wdk_page_by_title($post_title, 'OBJECT', 'page' ); | |
| 908 | + if(!empty($post)) | |
| 909 | + { | |
| 910 | + wp_delete_post($post->ID, true); | |
| 911 | + $post=NULL; | |
| 912 | + } | |
| 913 | + if(!empty($post)) | |
| 914 | + $post_id = $post->ID; | |
| 915 | + } | |
| 916 | + | |
| 917 | + | |
| 918 | + if(empty($post_id)) | |
| 919 | + { | |
| 920 | + $error_obj = NULL; | |
| 921 | + $post_insert = array( | |
| 922 | + 'post_title' => wp_strip_all_tags( $post_title ), | |
| 923 | + 'post_content' => $post_content, | |
| 924 | + 'post_status' => 'publish', | |
| 925 | + 'post_type' => 'page', | |
| 926 | + 'post_author' => get_current_user_id(), | |
| 927 | + 'post_category' => array(1,2), | |
| 928 | + 'page_template' => $post_template, | |
| 929 | + 'post_parent' => $post_parent | |
| 930 | + ); | |
| 931 | + $post_id = wp_insert_post( $post_insert, $error_obj ); | |
| 932 | + } | |
| 933 | + | |
| 934 | + $post_insert = get_post( $post_id ); | |
| 935 | + | |
| 936 | + return $post_insert; | |
| 937 | + } | |
| 938 | + | |
| 939 | + /* Elementor Import Template */ | |
| 940 | + private function elementor_assign($page_id, $json_template_name = '') | |
| 941 | + { | |
| 942 | + | |
| 943 | + $file = false; | |
| 944 | + | |
| 945 | + if(is_child_theme() && file_exists(get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name)) | |
| 946 | + { | |
| 947 | + $file = get_stylesheet_directory().'/elementor-data/wpdirectorykit/'.$json_template_name; | |
| 948 | + } | |
| 949 | + elseif(file_exists(get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name)) | |
| 950 | + { | |
| 951 | + $file = get_template_directory().'/demo-data/wpdirectorykit/'.$json_template_name; | |
| 952 | + } | |
| 953 | + elseif(file_exists( WPDIRECTORYKIT_PATH. '/demo-data/'.$json_template_name)) | |
| 954 | + { | |
| 955 | + $file = WPDIRECTORYKIT_PATH.'demo-data/'.$json_template_name; | |
| 956 | + } | |
| 957 | + | |
| 958 | + if(!$file || !class_exists('Elementor\Plugin')) | |
| 959 | + { | |
| 960 | + return false; | |
| 961 | + } | |
| 962 | + | |
| 963 | + $page_template = get_page_template_slug( $page_id ); | |
| 964 | + | |
| 965 | + add_post_meta( $page_id, '_elementor_edit_mode', 'builder' ); | |
| 966 | + | |
| 967 | + global $wp_filesystem; | |
| 968 | + // Initialize the WP filesystem, no more using 'file-put-contents' function | |
| 969 | + if (empty($wp_filesystem)) { | |
| 970 | + WP_Filesystem(); | |
| 971 | + } | |
| 972 | + | |
| 973 | + $string = $wp_filesystem->get_contents($file); | |
| 974 | + | |
| 975 | + $json_template = json_decode($string, true); | |
| 976 | + $elements = $json_template['content']; | |
| 977 | + | |
| 978 | + $data = array( | |
| 979 | + 'elements' => $elements, | |
| 980 | + 'settings' => array('post_status'=>'autosave', 'template'=>$page_template), | |
| 981 | + ); | |
| 982 | + // @codingStandardsIgnoreStart | |
| 983 | + $document = Elementor\Plugin::$instance->documents->get( $page_id, false ); | |
| 984 | + // @codingStandardsIgnoreEnd | |
| 985 | + return $document->save( $data ); | |
| 986 | + } | |
| 987 | + | |
| 988 | + | |
| 710 | 989 | |
| 711 | 990 | private function output($data, $print = TRUE) |
| 712 | 991 | { |
| 713 | 992 | if ($print) { |