PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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.3, at application/controllers/Wdk_backendajax.php

728 lines 26.7 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 generated_strings()
422 {
423 $data = array();
424 $data['message'] = '';
425 $data['popup_text_success'] = '';
426 $data['popup_text_error'] = '';
427 $data['parameters'] = $_POST;
428 $data['success'] = false;
429
430 /* protect */
431 if(!wmvc_user_in_role('administrator')) {
432 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
433 $this->output($data);
434 }
435
436 // Check _wpnonce
437 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
438
439 global $wp_filesystem;
440 // Initialize the WP filesystem, no more using 'file-put-contents' function
441 if (empty($wp_filesystem)) {
442 require_once(ABSPATH . '/wp-admin/includes/file.php');
443 WP_Filesystem();
444 }
445 // @codingStandardsIgnoreEnd
446
447 $this->load->load_helper('listing');
448 $this->load->model('location_m');
449 $this->load->model('category_m');
450
451
452 /* locations strings */
453 $this->db->select('location_title');
454 $this->db->from($this->location_m->_table_name);
455 $query = $this->db->get();
456 $count_file = 1;
457 $limit_size = '80000';
458 $file_strings_content = '<?php ';
459 if ($this->db->num_rows() > 0) {
460 foreach ($this->db->results() as $location) {
461 $file_strings_content .= '__(\'' . addslashes($location->location_title) . '\',\'wpdirectorykit\');' . "\n";
462
463 if (strlen($file_strings_content) > $limit_size) {
464 $file_strings_content .= "\n" . '?>';
465 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content);
466
467 /* create new file */
468 $file_strings_content = '<?php ';
469 $count_file++;
470 }
471 }
472 $file_strings_content .= "\n" . '?>';
473
474 if (!empty($file_strings_content))
475 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/locations_' . $count_file . '.php', $file_strings_content);
476 }
477
478
479 /* categories strings */
480 $this->db->select('category_title');
481 $this->db->from($this->category_m->_table_name);
482 $query = $this->db->get();
483 $count_file = 1;
484 $limit_size = '80000';
485 $file_strings_content = '<?php ';
486 if ($this->db->num_rows() > 0) {
487 foreach ($this->db->results() as $category) {
488 $file_strings_content .= '__(\'' . addslashes($category->category_title) . '\',\'wpdirectorykit\');' . "\n";
489
490 if (strlen($file_strings_content) > $limit_size) {
491 $file_strings_content .= "\n" . '?>';
492 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content);
493
494 /* create new file */
495 $file_strings_content = '<?php ';
496 $count_file++;
497 }
498 }
499 $file_strings_content .= "\n" . '?>';
500
501 if (!empty($file_strings_content))
502 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/categories_' . $count_file . '.php', $file_strings_content);
503 }
504
505 /* fields */
506
507 $this->load->model('field_m');
508 $this->db->select('field_label,prefix,suffix,values_list,hint,placeholder');
509 $this->db->from($this->field_m->_table_name);
510 $query = $this->db->get();
511 $count_file = 1;
512 $limit_size = '70000';
513 $file_strings_content = '<?php ';
514 if ($this->db->num_rows() > 0) {
515 foreach ($this->db->results() as $field) {
516
517 if (!empty($field->field_label))
518 $file_strings_content .= '__(\'' . addslashes($field->field_label) . '\',\'wpdirectorykit\');' . "\n";
519
520 if (!empty($field->prefix))
521 $file_strings_content .= '__(\'' . addslashes($field->prefix) . '\',\'wpdirectorykit\');' . "\n";
522
523 if (!empty($field->suffix))
524 $file_strings_content .= '__(\'' . addslashes($field->suffix) . '\',\'wpdirectorykit\');' . "\n";
525
526 if (!empty($field->values_list))
527 $file_strings_content .= '__(\'' . addslashes($field->values_list) . '\',\'wpdirectorykit\');' . "\n";
528
529 if (!empty($field->placeholder))
530 $file_strings_content .= '__(\'' . addslashes($field->placeholder) . '\',\'wpdirectorykit\');' . "\n";
531
532 if (strlen($file_strings_content) > $limit_size) {
533 $file_strings_content .= "\n" . '?>';
534 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content);
535
536 /* create new file */
537 $file_strings_content = '<?php ';
538 $count_file++;
539 }
540 }
541 $file_strings_content .= "\n" . '?>';
542
543 if (!empty($file_strings_content))
544 $wp_filesystem->put_contents(WPDIRECTORYKIT_PATH . 'translation_strings/fields_' . $count_file . '.php', $file_strings_content);
545 }
546
547
548 $data['success'] = true;
549 $data['popup_text_success'] = __('Strings generated', 'wpdirectorykit');
550 $this->output($data);
551 }
552
553 public function loading_sublistings()
554 {
555 $data = array();
556 $data['message'] = '';
557 $data['popup_text_success'] = '';
558 $data['popup_text_error'] = '';
559 $data['parameters'] = $_POST;
560 $data['success'] = false;
561 $data['results'] = array();
562
563 /* protect */
564 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) {
565 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
566 $this->output($data);
567 }
568
569 // Check _wpnonce
570 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
571
572 $listing_id = intval(wmvc_show_data('listing_id', $data['parameters']));
573
574 if (empty($listing_id)) {
575 $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit');
576 }
577
578 if (empty($data['popup_text_error'])) {
579
580 $this->load->load_helper('listing');
581 $this->load->model('listing_m');
582
583
584 $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 $this->db->order_by('FIELD(' . $this->db->prefix . 'wdk_listings.post_id, ' . wdk_field_value('listing_related_ids', $listing_id) . ')');
587
588 $results = $this->listing_m->get();
589
590 foreach ($results as $sublisting) {
591 $_listing = array();
592 $_listing['post_id'] = wdk_field_value('post_id', $sublisting);
593 $_listing['post_title'] = wdk_field_value('post_title', $sublisting);
594 $_listing['post_content_short'] = wmvc_character_limiter(wdk_field_value('post_content', $sublisting), 30);
595 $_listing['date'] = wdk_get_date(wdk_field_value('date', $sublisting), false);
596 $_listing['location'] = wdk_field_value('location_title', $sublisting);
597 $_listing['category'] = wdk_field_value('category_title', $sublisting);
598 $_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);
600 $_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));
604
605 $data['results'][] = $_listing;
606
607 }
608 }
609
610 $data['success'] = true;
611 $this->output($data);
612 }
613
614 public function remove_listing()
615 {
616 $data = array();
617 $data['message'] = '';
618 $data['popup_text_success'] = '';
619 $data['popup_text_error'] = '';
620 $data['parameters'] = $_POST;
621 $data['success'] = false;
622 $data['results'] = array();
623
624 /* protect */
625 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) {
626 $data['message'] = __('Disabled for current user', 'wpdirectorykit');
627 $this->output($data);
628 }
629
630 // Check _wpnonce
631 check_admin_referer( 'wdk-backendajax', '_wpnonce' );
632
633 $listing_id = intval(wmvc_show_data('listing_id', $data['parameters']));
634
635 if (empty($listing_id)) {
636 $data['popup_text_error'] = __('Missing Listing', 'wpdirectorykit');
637 }
638
639 if (empty($data['popup_text_error'])) {
640
641 $this->load->load_helper('listing');
642 $this->load->model('listing_m');
643
644 $listing = $this->listing_m->get($listing_id, TRUE);
645 $parent_listing = $this->listing_m->get($listing->listing_parent_post_id, TRUE);
646
647 $this->listing_m->delete($listing_id);
648
649 if(isset($parent_listing->listing_related_ids) && !empty($parent_listing->listing_related_ids)) {
650 $related_ids = trim(str_replace(','.$listing_id.'','', ','.$parent_listing->listing_related_ids.','),',');
651 $this->listing_m->insert(array('listing_related_ids' => $related_ids), $listing->listing_parent_post_id);
652 }
653
654 $data['success'] = true;
655 }
656
657
658 $this->output($data);
659 }
660
661 private function output($data, $print = TRUE)
662 {
663 if ($print) {
664 header('Pragma: no-cache');
665 header('Cache-Control: no-store, no-cache');
666 header('Content-Type: application/json; charset=utf8');
667 //header('Content-Length: '.$length); // special characters causing troubles
668 echo (wp_json_encode($data));
669 exit();
670 } else {
671 return $data;
672 }
673 }
674 }
675
676 if (!class_exists('\Plugin_Upgrader', false)) {
677 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
678 }
679
680 /**
681 * WordPress class extended for on-the-fly plugin installations.
682 */
683 class PluginInstallerSkinSilentWdk extends \WP_Upgrader_Skin
684 {
685
686 /**
687 * Empty out the header of its HTML content.
688 */
689 public function header()
690 {
691 }
692
693 /**
694 * Empty out the footer of its HTML content.
695 */
696 public function footer()
697 {
698 }
699
700 /**
701 * Empty out the footer of its HTML content.
702 *
703 * @param string $string
704 * @param mixed ...$args Optional text replacements.
705 */
706 public function feedback($string, ...$args)
707 {
708 }
709
710 /**
711 * Empty out JavaScript output that calls function to decrement the update counts.
712 *
713 * @param string $type Type of update count to decrement.
714 */
715 public function decrement_update_count($type)
716 {
717 }
718
719 /**
720 * Empty out the error HTML content.
721 *
722 * @param string|WP_Error $errors A string or WP_Error object of the install error/s.
723 */
724 public function error($errors)
725 {
726 }
727 }
728