PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / controllers / Wdk_backendajax.php

Wdk_backendajax.php in WP Directory Kit 1.2.7, at application/controllers/Wdk_backendajax.php

774 lines 28.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly;
3
4 class Wdk_backendajax extends Winter_MVC_Controller
5 {
6
7 public function __construct()
8 {
9 if (defined('WP_DEBUG') && WP_DEBUG) {
10 ini_set('display_errors', 1);
11 ini_set('display_startup_errors', 1);
12 error_reporting(-1);
13 }
14 parent::__construct();
15
16 $this->data['is_ajax'] = true;
17 }
18
19 public function index(&$output = NULL, $atts = array())
20 {
21 }
22
23
24 public function plugin_news()
25 {
26 $data = array();
27 $data['message'] = __('No message returned!', 'wpdirectorykit');
28 $data['success'] = false;
29 $data['response'] = NULL;
30 $data['rss'] = array();
31
32 /* protect */
33 if(!current_user_can( 'read' ) && !wmvc_user_in_role('administrator')) {
34 $this->output($data);
35 }
36
37 //https://wpdirectorykit.com/wp/last_news.php?f=news.json
38
39 $request = wp_remote_get('https://wpdirectorykit.com/wp/last_news.php?f=news.json');
40
41 // request failed
42 if (is_wp_error($request)) {
43 $data['response'] = $request;
44 }
45 $code = (int) wp_remote_retrieve_response_code($request);
46
47 // make sure the fetch was successful
48 if (empty($data['response']) && $code == 200) {
49 $response = wp_remote_retrieve_body($request);
50
51 // Decode the json
52 $output = json_decode($response);
53 $count = 0;
54 foreach ($output as $key => $value) {
55 $data['rss'][] = array(
56 'date' => wdk_get_date(wmvc_show_data('date', $value, date('Y-m-d H:i:s'), TRUE, TRUE), false),
57 'title' => wmvc_show_data('title', $value, '', TRUE, TRUE),
58 'link' => wmvc_show_data('link', $value, '', TRUE, TRUE),
59 );
60 $count++;
61
62 if ($count > 10) break;
63 }
64 } else {
65 $data['response'] = get_status_header_desc($code);
66 }
67
68 $this->output($data);
69 }
70
71 public function plugin_upgrader($output = "", $atts = array(), $instance = NULL)
72 {
73 $data = array();
74 $data['message'] = __('No message returned!', 'wpdirectorykit');
75 $data['success'] = false;
76
77 /* protect */
78 if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) {
79 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
80 $this->output($data);
81 }
82
83 // Check _wpnonce
84 check_admin_referer( 'wdk-plugin_upgrader', '_wpnonce' );
85
86 ob_start();
87
88 $parameters = array();
89
90 foreach ($_POST as $key => $value) {
91 $parameters[$key] = sanitize_text_field($value);
92 }
93
94 $source = 'https://downloads.wordpress.org/plugin/' . $parameters['slug'] . '.zip';
95
96 if (!empty($parameters['source']))
97 $source = $parameters['source'];
98
99 if (!class_exists('Plugin_Upgrader', false)) {
100 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
101 }
102
103 $upgrader = new Plugin_Upgrader(new PluginInstallerSkinSilentWdk($skin_args));
104
105 if (!file_exists(WP_PLUGIN_DIR . '/' . $parameters['slug'] . '/' . $parameters['slug'] . '.php')) {
106 //exit(WP_PLUGIN_DIR .'/'.$parameters['slug'].'/'.$parameters['slug'].'.php');
107
108 $upgrader->install($source);
109 }
110
111 ob_clean();
112
113 $activate = activate_plugin($parameters['slug'] . '/' . $parameters['slug'] . '.php');
114
115 if (is_wp_error($activate)) {
116 $data['message'] = wp_kses_post($activate->get_error_message());
117 $data['success'] = false;
118 } else {
119 $data['success'] = true;
120 }
121
122 $data['slug'] = $parameters['slug'];
123
124 $data['parameters'] = $parameters;
125
126 //$data['sql'] = $this->db->last_query();
127 $this->output($data);
128 }
129
130 public function install_content($output = "", $atts = array(), $instance = NULL)
131 {
132 $data = array();
133 $data['message'] = __('No message returned!', 'wpdirectorykit');
134 $data['success'] = false;
135
136
137 /* protect */
138 if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) {
139 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
140 $this->output($data);
141 }
142
143 // Check _wpnonce
144 check_admin_referer( 'wdk-install_content', '_wpnonce' );
145
146 ob_start();
147
148 $parameters = array();
149
150 foreach ($_POST as $key => $value) {
151 $parameters[$key] = sanitize_text_field($value);
152 }
153
154 if (!class_exists('\WP_Importer')) {
155 require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
156 }
157
158 require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger.php';
159 require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger-html.php';
160 require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-logger-serversentevents.php';
161 require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-wxr-importer.php';
162 require_once WPDIRECTORYKIT_PATH . 'vendor/WordPress-Importer/class-wxr-import-info.php';
163
164 $importer_options = array(
165 'fetch_attachments' => true
166 );
167
168 $logger = new WP_Importer_Logger();
169
170 $importer = new WXR_Importer($importer_options);
171
172 $importer->set_logger($logger);
173
174 $current_theme = wp_get_theme();
175
176 $tmp_file = download_url($current_theme->get('AuthorURI') . '/demo_themes/' . $current_theme->get('TextDomain') . '.xml');
177
178 $results_importer = $importer->import($tmp_file);
179
180 ob_clean();
181
182 if (is_wp_error($results_importer)) {
183 $data['message'] = wp_kses_post($results_importer->get_error_message());
184 $data['success'] = false;
185 } else {
186 $data['success'] = true;
187 }
188
189 $data['parameters'] = $parameters;
190
191 //$data['sql'] = $this->db->last_query();
192 $this->output($data);
193 }
194
195 public function install_listings($output = "", $atts = array(), $instance = NULL)
196 {
197 $this->load->load_helper('listing');
198 $this->load->model('listing_m');
199 $this->load->model('listingfield_m');
200
201 $data = array();
202 $data['message'] = __('No message returned!', 'wpdirectorykit');
203 $data['success'] = false;
204
205 /* protect */
206 if(!current_user_can( 'install_plugins' ) && !wmvc_user_in_role('administrator')) {
207 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
208 $this->output($data);
209 }
210
211 // Check _wpnonce
212 check_admin_referer( 'wdk-install_listings', '_wpnonce' );
213
214 ob_start();
215
216 $parameters = array();
217
218 foreach ($_POST as $key => $value) {
219 $parameters[$key] = sanitize_text_field($value);
220 }
221
222 $data['parameters'] = $parameters;
223
224 //$data['sql'] = $this->db->last_query();
225 $this->output($data);
226 }
227
228
229 public function generated_listings_images_path()
230 {
231 $data = array();
232 $data['message'] = '';
233 $data['popup_text_success'] = '';
234 $data['popup_text_error'] = '';
235 $data['parameters'] = $_POST;
236 $data['success'] = false;
237
238 /* protect */
239 if(!wmvc_user_in_role('administrator')) {
240 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
241 $this->output($data);
242 }
243
244 // Check _wpnonce
245 check_admin_referer( 'wdk-generated_listings_images_path', '_wpnonce' );
246
247 $this->load->load_helper('listing');
248 $this->load->model('listing_m');
249 $listings = $this->listing_m->get();
250
251 foreach ($listings as $listing) {
252 $image_ids = explode(',', $listing->listing_images);
253 $listing_data = array('listing_images_path' => '', 'listing_images_path_medium' => '');
254 if (is_array($image_ids)) {
255 foreach ($image_ids as $image_id) {
256 if (is_numeric($image_id)) {
257 $image_path = wp_get_original_image_path($image_id);
258 if (!$image_path) continue;
259
260 /* path of image */
261 $next_path = str_replace(WP_CONTENT_DIR . '/uploads/', '', $image_path);
262
263 if (!empty($listing_data['listing_images_path']))
264 $listing_data['listing_images_path'] .= ',';
265
266 $listing_data['listing_images_path'] .= $next_path;
267 }
268
269 $image_url = wp_get_attachment_image_url($image_id, 'large');
270 if ($image_url) {
271 $parsed = parse_url($image_url);
272 $next_path = substr($parsed['path'], strpos($parsed['path'], 'uploads/') + 8);
273
274 if (!empty($listing_data['listing_images_path_medium']))
275 $listing_data['listing_images_path_medium'] .= ',';
276
277 $listing_data['listing_images_path_medium'] .= $next_path;
278 }
279 }
280 }
281
282 $this->listing_m->insert($listing_data, $listing->post_id);
283 }
284
285 $this->load->model('location_m');
286 $locations = $this->location_m->get();
287 if ($locations) foreach ($locations as $location) {
288 $save_data = array(
289 "parent_id" => $location->parent_id,
290 );
291 $save_data['icon_path'] = wdk_generate_path_image($location->icon_id);
292 $save_data['image_path'] = wdk_generate_path_image($location->image_id);
293
294 $this->location_m->insert($save_data, $location->idlocation);
295 }
296
297 $this->load->model('category_m');
298 $categories = $this->category_m->get();
299 if ($categories) foreach ($categories as $category) {
300 $save_data = array(
301 "parent_id" => $category->parent_id,
302 );
303 $save_data['icon_path'] = wdk_generate_path_image($category->icon_id);
304 $save_data['image_path'] = wdk_generate_path_image($category->image_id);
305 $save_data['marker_image_path'] = wdk_generate_path_image($category->marker_image_id);
306
307 $this->category_m->insert($save_data, $category->idcategory);
308 }
309
310 $data['success'] = true;
311 $data['popup_text_success'] = __('images path of listings,locations,categories generated', 'wpdirectorykit');
312 $this->output($data);
313 }
314
315 public function optimization_listingfields_table()
316 {
317 $data = array();
318 $data['message'] = '';
319 $data['popup_text_success'] = '';
320 $data['popup_text_error'] = '';
321 $data['parameters'] = $_POST;
322 $data['success'] = false;
323
324 /* protect */
325 if(!wmvc_user_in_role('administrator')) {
326 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
327 $this->output($data);
328 }
329
330 // Check _wpnonce
331 check_admin_referer( 'wdk-optimization_listingfields_table', '_wpnonce' );
332
333 $this->load->load_helper('listing');
334 $this->load->model('listingfield_m');
335 $this->load->model('field_m');
336 $listingfields = $this->listingfield_m->get_available_fields();
337
338 global $wpdb;
339
340 /* remove if missing */
341 foreach ($listingfields as $listingfield => $field_data) {
342 if (strpos($listingfield, 'field_') !== FALSE) {
343 list($prefix, $field_id, $field_type) = explode('_', $listingfield);
344
345 if (!wdk_field_option($field_id, 'field_type', false)) {
346 $wpdb->query("ALTER TABLE {$this->listingfield_m->_table_name} DROP COLUMN $listingfield;");
347 }
348 }
349 }
350
351 /* add if missing listingfield and change from varchar to TEXT */
352 $this->db->where(array('field_type !=' => 'SECTION'));
353 $fields = $this->field_m->get();
354
355 $listingfields = $this->listingfield_m->get_available_fields();
356 foreach ($fields as $field) {
357 $column_name = 'field_' . $field->idfield . '_' . $field->field_type;
358 if (!isset($listingfields[$column_name])) {
359 $this->listingfield_m->create_table_column(array('field_type' => $field->field_type), $field->idfield);
360 } else {
361
362 /* change from varchar to TEXT */
363 if (
364 stripos($listingfields[$column_name]->Type, 'VARCHAR') !== FALSE
365 && ($field->field_type == 'INPUTBOX' || $field->field_type == 'DROPDOWN' || $field->field_type == 'DROPDOWNMULTIPLE')
366 ) {
367 $wpdb->query("ALTER TABLE `{$this->listingfield_m->_table_name}` CHANGE `$column_name` `$column_name` TEXT NULL DEFAULT NULL;");
368 }
369 }
370 }
371
372 $data['success'] = true;
373 $data['popup_text_success'] = __('Table listingfields optimized', 'wpdirectorykit');
374 $this->output($data);
375 }
376
377 public function update_depend()
378 {
379 $data = array();
380 $data['message'] = __('No message returned!', 'wpdirectorykit');
381 $data['success'] = false;
382 $data['parameters'] = $_POST;
383
384 /* protect */
385 if(!wmvc_user_in_role('administrator')) {
386 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
387 $this->output($data);
388 }
389
390 // Check _wpnonce
391 check_admin_referer( 'wdk-update_depend', '_wpnonce' );
392
393 $this->load->load_helper('listing');
394 $this->load->model('dependfields_m');
395
396 if (wmvc_show_data('field_id', $data['parameters'], false) && wmvc_show_data('main_field', $data['parameters'], false)) {
397
398 $hidden_fields = array();
399 foreach ($data['parameters'] as $key => $value) {
400 if (strpos($key, 'field_hide_') !== FALSE) {
401 $field_id = str_replace('field_hide_', '', $key);
402 if (is_intval($field_id)) {
403 $hidden_fields[] = $field_id;
404 }
405 }
406 }
407
408 $data_insert = array(
409 'main_field' => wmvc_show_data('main_field', $data['parameters'], false),
410 'field_id' => wmvc_show_data('field_id', $data['parameters'], false),
411 'hidden_fields_list' => join(',', $hidden_fields),
412 );
413
414 $this->dependfields_m->delete_where(array('field_id' => $data_insert['field_id'], 'main_field' => $data_insert['main_field']));
415 $this->dependfields_m->insert($data_insert);
416 }
417
418 $this->output($data);
419 }
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')) {
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
467 public function generated_strings()
468 {
469 $data = array();
470 $data['message'] = '';
471 $data['popup_text_success'] = '';
472 $data['popup_text_error'] = '';
473 $data['parameters'] = $_POST;
474 $data['success'] = false;
475
476 /* protect */
477 if(!wmvc_user_in_role('administrator')) {
478 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
479 $this->output($data);
480 }
481
482 // Check _wpnonce
483 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
484
485 global $wp_filesystem;
486 // Initialize the WP filesystem, no more using 'file-put-contents' function
487 if (empty($wp_filesystem)) {
488 require_once(ABSPATH . '/wp-admin/includes/file.php');
489 WP_Filesystem();
490 }
491 // @codingStandardsIgnoreEnd
492
493 $this->load->load_helper('listing');
494 $this->load->model('location_m');
495 $this->load->model('category_m');
496
497
498 /* locations strings */
499 $this->db->select('location_title');
500 $this->db->from($this->location_m->_table_name);
501 $query = $this->db->get();
502 $count_file = 1;
503 $limit_size = '80000';
504 $file_strings_content = '<?php ';
505 if ($this->db->num_rows() > 0) {
506 foreach ($this->db->results() as $location) {
507 $file_strings_content .= '__(\'' . addslashes($location->location_title) . '\',\'wpdirectorykit\');' . "\n";
508
509 if (strlen($file_strings_content) > $limit_size) {
510 $file_strings_content .= "\n" . '?>';
511 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content);
512
513 /* create new file */
514 $file_strings_content = '<?php ';
515 $count_file++;
516 }
517 }
518 $file_strings_content .= "\n" . '?>';
519
520 if (!empty($file_strings_content))
521 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content);
522 }
523
524
525 /* categories strings */
526 $this->db->select('category_title');
527 $this->db->from($this->category_m->_table_name);
528 $query = $this->db->get();
529 $count_file = 1;
530 $limit_size = '80000';
531 $file_strings_content = '<?php ';
532 if ($this->db->num_rows() > 0) {
533 foreach ($this->db->results() as $category) {
534 $file_strings_content .= '__(\'' . addslashes($category->category_title) . '\',\'wpdirectorykit\');' . "\n";
535
536 if (strlen($file_strings_content) > $limit_size) {
537 $file_strings_content .= "\n" . '?>';
538 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content);
539
540 /* create new file */
541 $file_strings_content = '<?php ';
542 $count_file++;
543 }
544 }
545 $file_strings_content .= "\n" . '?>';
546
547 if (!empty($file_strings_content))
548 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content);
549 }
550
551 /* fields */
552
553 $this->load->model('field_m');
554 $this->db->select('field_label,prefix,suffix,values_list,hint,placeholder');
555 $this->db->from($this->field_m->_table_name);
556 $query = $this->db->get();
557 $count_file = 1;
558 $limit_size = '70000';
559 $file_strings_content = '<?php ';
560 if ($this->db->num_rows() > 0) {
561 foreach ($this->db->results() as $field) {
562
563 if (!empty($field->field_label))
564 $file_strings_content .= '__(\'' . addslashes($field->field_label) . '\',\'wpdirectorykit\');' . "\n";
565
566 if (!empty($field->prefix))
567 $file_strings_content .= '__(\'' . addslashes($field->prefix) . '\',\'wpdirectorykit\');' . "\n";
568
569 if (!empty($field->suffix))
570 $file_strings_content .= '__(\'' . addslashes($field->suffix) . '\',\'wpdirectorykit\');' . "\n";
571
572 if (!empty($field->values_list))
573 $file_strings_content .= '__(\'' . addslashes($field->values_list) . '\',\'wpdirectorykit\');' . "\n";
574
575 if (!empty($field->placeholder))
576 $file_strings_content .= '__(\'' . addslashes($field->placeholder) . '\',\'wpdirectorykit\');' . "\n";
577
578 if (strlen($file_strings_content) > $limit_size) {
579 $file_strings_content .= "\n" . '?>';
580 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content);
581
582 /* create new file */
583 $file_strings_content = '<?php ';
584 $count_file++;
585 }
586 }
587 $file_strings_content .= "\n" . '?>';
588
589 if (!empty($file_strings_content))
590 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content);
591 }
592
593
594 $data['success'] = true;
595 $data['popup_text_success'] = __('Strings generated', 'wpdirectorykit');
596 $this->output($data);
597 }
598
599 public function loading_sublistings()
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 $data['results'] = array();
608
609 /* protect */
610 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) {
611 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
612 $this->output($data);
613 }
614
615 // Check _wpnonce
616 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
617
618 $listing_id = intval(wmvc_show_data('listing_id', $data['parameters']));
619
620 if (empty($listing_id)) {
621 $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit');
622 }
623
624 if (empty($data['popup_text_error'])) {
625
626 $this->load->load_helper('listing');
627 $this->load->model('listing_m');
628
629
630 $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 $this->db->order_by('FIELD(' . $this->db->prefix . 'wdk_listings.post_id, ' . wdk_field_value('listing_related_ids', $listing_id) . ')');
633
634 $results = $this->listing_m->get();
635
636 foreach ($results as $sublisting) {
637 $_listing = array();
638 $_listing['post_id'] = wdk_field_value('post_id', $sublisting);
639 $_listing['post_title'] = wdk_field_value('post_title', $sublisting);
640 $_listing['post_content_short'] = wmvc_character_limiter(wdk_field_value('post_content', $sublisting), 30);
641 $_listing['date'] = wdk_get_date(wdk_field_value('date', $sublisting), false);
642 $_listing['location'] = wdk_field_value('location_title', $sublisting);
643 $_listing['category'] = wdk_field_value('category_title', $sublisting);
644 $_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);
646 $_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);
648 $_listing['listing_dash_remove_url'] = wdk_dash_url("dash_page=listings&table_action=table&action=delete&ids=" . wdk_field_value('post_id', $sublisting));
649 $_listing['listing_dash_edit_url'] = wdk_dash_url("dash_page=listings&function=edit&id=" . wdk_field_value('post_id', $sublisting));
650
651 $data['results'][] = $_listing;
652
653 }
654 }
655
656 $data['success'] = true;
657 $this->output($data);
658 }
659
660 public function remove_listing()
661 {
662 $data = array();
663 $data['message'] = '';
664 $data['popup_text_success'] = '';
665 $data['popup_text_error'] = '';
666 $data['parameters'] = $_POST;
667 $data['success'] = false;
668 $data['results'] = array();
669
670 /* protect */
671 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) {
672 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
673 $this->output($data);
674 }
675
676 // Check _wpnonce
677 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
678
679 $listing_id = intval(wmvc_show_data('listing_id', $data['parameters']));
680
681 if (empty($listing_id)) {
682 $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit');
683 }
684
685 if (empty($data['popup_text_error'])) {
686
687 $this->load->load_helper('listing');
688 $this->load->model('listing_m');
689
690 $listing = $this->listing_m->get($listing_id, TRUE);
691 $parent_listing = $this->listing_m->get($listing->listing_parent_post_id, TRUE);
692
693 $this->listing_m->delete($listing_id);
694
695 if(isset($parent_listing->listing_related_ids) && !empty($parent_listing->listing_related_ids)) {
696 $related_ids = trim(str_replace(','.$listing_id.'','', ','.$parent_listing->listing_related_ids.','),',');
697 $this->listing_m->insert(array('listing_related_ids' => $related_ids), $listing->listing_parent_post_id);
698 }
699
700 $data['success'] = true;
701 }
702
703
704 $this->output($data);
705 }
706
707 private function output($data, $print = TRUE)
708 {
709 if ($print) {
710 header('Pragma: no-cache');
711 header('Cache-Control: no-store, no-cache');
712 header('Content-Type: application/json; charset=utf8');
713 //header('Content-Length: '.$length); // special characters causing troubles
714 echo (wp_json_encode($data));
715 exit();
716 } else {
717 return $data;
718 }
719 }
720 }
721
722 if (!class_exists('\Plugin_Upgrader', false)) {
723 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
724 }
725
726 /**
727 * WordPress class extended for on-the-fly plugin installations.
728 */
729 class PluginInstallerSkinSilentWdk extends \WP_Upgrader_Skin
730 {
731
732 /**
733 * Empty out the header of its HTML content.
734 */
735 public function header()
736 {
737 }
738
739 /**
740 * Empty out the footer of its HTML content.
741 */
742 public function footer()
743 {
744 }
745
746 /**
747 * Empty out the footer of its HTML content.
748 *
749 * @param string $string
750 * @param mixed ...$args Optional text replacements.
751 */
752 public function feedback($string, ...$args)
753 {
754 }
755
756 /**
757 * Empty out JavaScript output that calls function to decrement the update counts.
758 *
759 * @param string $type Type of update count to decrement.
760 */
761 public function decrement_update_count($type)
762 {
763 }
764
765 /**
766 * Empty out the error HTML content.
767 *
768 * @param string|WP_Error $errors A string or WP_Error object of the install error/s.
769 */
770 public function error($errors)
771 {
772 }
773 }
774