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_backendajax.php +340 -11 1.2.3 → 1.5.9 View file →
@@ -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++;
@@ -235,9 +235,9 @@
235 235 $data['parameters'] = $_POST;
236 236 $data['success'] = false;
237 237
238 238 /* protect */
239 - if(!wmvc_user_in_role('administrator')) {
239 + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
240 240 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
241 241 $this->output($data);
242 242 }
243 243
@@ -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'] .= ',';
@@ -321,9 +321,9 @@
321 321 $data['parameters'] = $_POST;
322 322 $data['success'] = false;
323 323
324 324 /* protect */
325 - if(!wmvc_user_in_role('administrator')) {
325 + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
326 326 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
327 327 $this->output($data);
328 328 }
329 329
@@ -381,9 +381,9 @@
381 381 $data['success'] = false;
382 382 $data['parameters'] = $_POST;
383 383
384 384 /* protect */
385 - if(!wmvc_user_in_role('administrator')) {
385 + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
386 386 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
387 387 $this->output($data);
388 388 }
389 389
@@ -417,8 +417,54 @@
417 417
418 418 $this->output($data);
419 419 }
420 420
421 + public function depend_copy_on_subcategories()
422 + {
423 + $data = array();
424 + $data['message'] = __('No message returned!', 'wpdirectorykit');
425 + $data['success'] = false;
426 + $data['parameters'] = $_POST;
427 +
428 + /* protect */
429 + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
430 + $data['message'] = __('Disabled for current user', 'wpdirectorykit');
431 + $this->output($data);
432 + }
433 +
434 + // Check _wpnonce
435 + check_admin_referer( 'wdk_depend_copy_on_subcategories', '_wpnonce' );
436 +
437 + $this->load->load_helper('listing');
438 + $this->load->model('dependfields_m');
439 +
440 + if (wmvc_show_data('category_id', $data['parameters'], false)) {
441 +
442 + $sub_categories_ids = wdk_category_get_all_childs(intval($data['parameters']['category_id']));
443 +
444 + $depends_list = wdk_depend_get_hidden_fields(intval($data['parameters']['category_id']));
445 +
446 +
447 + $data['sub_categories_ids'] = $sub_categories_ids;
448 + $data['depends_list'] = $depends_list;
449 +
450 + if($sub_categories_ids){
451 + $this->dependfields_m->delete_where(array('field_id IN ('.join(',',$sub_categories_ids).')'=>NULL));
452 + foreach ($sub_categories_ids as $key => $id) {
453 + # code...
454 + $data_insert = array(
455 + 'main_field' => 'categories',
456 + 'field_id' => $id,
457 + 'hidden_fields_list' => $depends_list,
458 + );
459 + $this->dependfields_m->insert($data_insert);
460 + }
461 + }
462 + }
463 +
464 + $this->output($data);
465 + }
466 +
421 467 public function generated_strings()
422 468 {
423 469 $data = array();
424 470 $data['message'] = '';
@@ -427,9 +473,9 @@
427 473 $data['parameters'] = $_POST;
428 474 $data['success'] = false;
429 475
430 476 /* protect */
431 - if(!wmvc_user_in_role('administrator')) {
477 + if(!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage')) {
432 478 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
433 479 $this->output($data);
434 480 }
435 481
@@ -549,8 +595,57 @@
549 595 $data['popup_text_success'] = __('Strings generated', 'wpdirectorykit');
550 596 $this->output($data);
551 597 }
552 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 +
553 648 public function loading_sublistings()
554 649 {
555 650 $data = array();
556 651 $data['message'] = '';
@@ -581,9 +676,8 @@
581 676 $this->load->model('listing_m');
582 677
583 678
584 679 $this->db->where($this->db->prefix . 'wdk_listings.post_id IN(' . wdk_field_value('listing_related_ids', $listing_id) . ')', null, false);
585 - $this->db->where(array('is_activated' => 1, 'is_approved' => 1));
586 680 $this->db->order_by('FIELD(' . $this->db->prefix . 'wdk_listings.post_id, ' . wdk_field_value('listing_related_ids', $listing_id) . ')');
587 681
588 682 $results = $this->listing_m->get();
589 683
@@ -594,14 +688,20 @@
594 688 $_listing['post_content_short'] = wmvc_character_limiter(wdk_field_value('post_content', $sublisting), 30);
595 689 $_listing['date'] = wdk_get_date(wdk_field_value('date', $sublisting), false);
596 690 $_listing['location'] = wdk_field_value('location_title', $sublisting);
597 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);
598 694 $_listing['image_src'] = wdk_image_src($sublisting);
599 - $_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));
600 696 $_listing['listing_view_url'] = get_permalink($sublisting);
601 - $_listing['listing_edit_url'] = get_admin_url() . "admin.php?page=wdk_listing&id=" . wdk_field_value('post_id', $sublisting);
602 - $_listing['listing_dash_remove_url'] = wdk_dash_url("dash_page=listings&table_action=table&action=delete&ids=" . wdk_field_value('post_id', $sublisting));
603 - $_listing['listing_dash_edit_url'] = wdk_dash_url("dash_page=listings&function=edit&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));
698 + $_listing['listing_dash_remove_url'] = '';
699 + $_listing['listing_dash_edit_url'] = '';
700 + if(function_exists(' wdk_dash_url')) {
701 + $_listing['listing_dash_remove_url'] = wdk_dash_url("dash_page=listings&table_action=table&action=delete&ids=" . wdk_field_value('post_id', $sublisting));
702 + $_listing['listing_dash_edit_url'] = wdk_dash_url("dash_page=listings&function=edit&id=" . wdk_field_value('post_id', $sublisting));
703 + }
604 704
605 705 $data['results'][] = $_listing;
606 706
607 707 }
@@ -656,8 +756,237 @@
656 756
657 757
658 758 $this->output($data);
659 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 +
660 989
661 990 private function output($data, $print = TRUE)
662 991 {
663 992 if ($print) {