PluginProbe
ManageWP Worker / 3.9.26
ManageWP Worker v3.9.26
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / installer.class.php

installer.class.php in ManageWP Worker 3.9.26, at installer.class.php

968 lines 37.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * installer.class.php
5 *
6 * Upgrade WordPress
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12 if(basename($_SERVER['SCRIPT_FILENAME']) == "installer.class.php"):
13 exit;
14 endif;
15 class MMB_Installer extends MMB_Core
16 {
17 function __construct()
18 {
19 @set_time_limit(600);
20 parent::__construct();
21 @include_once(ABSPATH . 'wp-admin/includes/file.php');
22 @include_once(ABSPATH . 'wp-admin/includes/plugin.php');
23 @include_once(ABSPATH . 'wp-admin/includes/theme.php');
24 @include_once(ABSPATH . 'wp-admin/includes/misc.php');
25 @include_once(ABSPATH . 'wp-admin/includes/template.php');
26 @include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
27
28 global $wp_filesystem;
29 if (!$wp_filesystem)
30 WP_Filesystem();
31 }
32
33 function mmb_maintenance_mode($enable = false, $maintenance_message = '')
34 {
35 global $wp_filesystem;
36
37 $maintenance_message .= '<?php $upgrading = ' . time() . '; ?>';
38
39 $file = $wp_filesystem->abspath() . '.maintenance';
40 if ($enable) {
41 $wp_filesystem->delete($file);
42 $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
43 } else {
44 $wp_filesystem->delete($file);
45 }
46 }
47
48 function install_remote_file($params)
49 {
50 global $wp_filesystem;
51 extract($params);
52
53 if (!isset($package) || empty($package))
54 return array(
55 'error' => '<p>No files received. Internal error.</p>'
56 );
57
58 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
59 return array(
60 'error' => '<p>Site under maintanace.</p>'
61 );
62
63 if (!class_exists('WP_Upgrader'))
64 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
65
66 $upgrader_skin = new WP_Upgrader_Skin();
67 $upgrader_skin->done_header = true;
68
69 $upgrader = new WP_Upgrader($upgrader_skin);
70 $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
71 $clear_destination = isset($clear_destination) ? $clear_destination : false;
72
73 foreach ($package as $package_url) {
74 $key = basename($package_url);
75 $install_info[$key] = @$upgrader->run(array(
76 'package' => $package_url,
77 'destination' => $destination,
78 'clear_destination' => $clear_destination, //Do not overwrite files.
79 'clear_working' => true,
80 'hook_extra' => array()
81 ));
82 }
83
84 if ($activate) {
85 if ($type == 'plugins') {
86 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
87 $all_plugins = get_plugins();
88 foreach ($all_plugins as $plugin_slug => $plugin) {
89 $plugin_dir = preg_split('/\//', $plugin_slug);
90 foreach ($install_info as $key => $install) {
91 if (!$install || is_wp_error($install))
92 continue;
93 if ($install['destination_name'] == $plugin_dir[0]) {
94 $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
95 }
96 }
97 }
98 } else if (count($install_info) == 1) {
99 global $wp_themes;
100 include_once(ABSPATH . 'wp-includes/theme.php');
101
102 $wp_themes = null;
103 unset($wp_themes); //prevent theme data caching
104 if(function_exists('wp_get_themes')){
105 $all_themes = wp_get_themes();
106 foreach ($all_themes as $theme_name => $theme_data) {
107 foreach ($install_info as $key => $install) {
108 if (!$install || is_wp_error($install))
109 continue;
110
111 if ($theme_data->Template == $install['destination_name']) {
112 $install_info[$key]['activated'] = switch_theme($theme_data->Template, $theme_data->Stylesheet);
113 }
114 }
115 }
116 }else{
117 $all_themes = get_themes();
118 foreach ($all_themes as $theme_name => $theme_data) {
119 foreach ($install_info as $key => $install) {
120 if (!$install || is_wp_error($install))
121 continue;
122
123 if ($theme_data['Template'] == $install['destination_name']) {
124 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
125 }
126 }
127 }
128 }
129 }
130 }
131 ob_clean();
132 $this->mmb_maintenance_mode(false);
133 return $install_info;
134 }
135
136 function do_upgrade($params = null)
137 {
138 if ($params == null || empty($params))
139 return array(
140 'failed' => 'No upgrades passed.'
141 );
142
143 if (!$this->is_server_writable()) {
144 return array(
145 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details</a>'
146 );
147 }
148
149
150 $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
151
152 $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
153 $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
154 $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
155
156 $upgrades = array();
157 $premium_upgrades = array();
158 if (!empty($core_upgrade)) {
159 $upgrades['core'] = $this->upgrade_core($core_upgrade);
160 }
161
162 if (!empty($upgrade_plugins)) {
163 $plugin_files = array();
164 foreach ($upgrade_plugins as $plugin) {
165 if (isset($plugin->file))
166 $plugin_files[$plugin->file] = $plugin->old_version;
167 else
168 $premium_upgrades[md5($plugin->name)] = $plugin;
169 }
170 if (!empty($plugin_files))
171 $upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
172
173 }
174
175 if (!empty($upgrade_themes)) {
176 $theme_temps = array();
177 foreach ($upgrade_themes as $theme) {
178 if (isset($theme['theme_tmp']))
179 $theme_temps[] = $theme['theme_tmp'];
180 else
181 $premium_upgrades[md5($theme['name'])] = $theme;
182 }
183
184 if (!empty($theme_temps))
185 $upgrades['themes'] = $this->upgrade_themes($theme_temps);
186
187 }
188
189 if (!empty($premium_upgrades)) {
190 $premium_upgrades = $this->upgrade_premium($premium_upgrades);
191 if (!empty($premium_upgrades)) {
192 if (!empty($upgrades)) {
193 foreach ($upgrades as $key => $val) {
194 if (isset($premium_upgrades[$key])) {
195 $upgrades[$key] = array_merge_recursive($upgrades[$key], $premium_upgrades[$key]);
196 }
197 }
198 } else {
199 $upgrades = $premium_upgrades;
200 }
201 }
202 }
203 ob_clean();
204 $this->mmb_maintenance_mode(false);
205 return $upgrades;
206 }
207
208 /**
209 * Upgrades WordPress locally
210 *
211 */
212 function upgrade_core($current)
213 {
214 ob_start();
215 if (!function_exists('wp_version_check'))
216 include_once(ABSPATH . '/wp-admin/includes/update.php');
217
218 @wp_version_check();
219
220 $current_update = false;
221 ob_end_flush();
222 ob_end_clean();
223 $core = $this->mmb_get_transient('update_core');
224
225 if (isset($core->updates) && !empty($core->updates)) {
226 $updates = $core->updates[0];
227 $updated = $core->updates[0];
228 if (!isset($updated->response) || $updated->response == 'latest')
229 return array(
230 'upgraded' => ' updated'
231 );
232
233 if ($updated->response == "development" && $current->response == "upgrade") {
234 return array(
235 'upgraded' => '<font color="#900">Unexpected error. Please upgrade manually.</font>'
236 );
237 } else if ($updated->response == $current->response || ($updated->response == "upgrade" && $current->response == "development")) {
238 if ($updated->locale != $current->locale) {
239 foreach ($updates as $update) {
240 if ($update->locale == $current->locale) {
241 $current_update = $update;
242 break;
243 }
244 }
245 if ($current_update == false)
246 return array(
247 'error' => ' Localization mismatch. Try again.'
248 );
249 } else {
250 $current_update = $updated;
251 }
252 } else
253 return array(
254 'error' => ' Transient mismatch. Try again.'
255 );
256 } else
257 return array(
258 'error' => ' Refresh transient failed. Try again.'
259 );
260 if ($current_update != false) {
261 global $mmb_wp_version, $wp_filesystem, $wp_version;
262
263 if (version_compare($wp_version, '3.1.9', '>')) {
264 if (!class_exists('Core_Upgrader'))
265 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
266
267 $core = new Core_Upgrader();
268 $result = $core->upgrade($current_update);
269 $this->mmb_maintenance_mode(false);
270 if (is_wp_error($result)) {
271 return array(
272 'error' => $this->mmb_get_error($result)
273 );
274 } else
275 return array(
276 'upgraded' => ' updated'
277 );
278
279 } else {
280 if (!class_exists('WP_Upgrader')) {
281 include_once(ABSPATH . 'wp-admin/includes/update.php');
282 if (function_exists('wp_update_core')) {
283 $result = wp_update_core($current_update);
284 if (is_wp_error($result)) {
285 return array(
286 'error' => $this->mmb_get_error($result)
287 );
288 } else
289 return array(
290 'upgraded' => ' updated'
291 );
292 }
293 }
294
295 if (class_exists('WP_Upgrader')) {
296 $upgrader_skin = new WP_Upgrader_Skin();
297 $upgrader_skin->done_header = true;
298
299 $upgrader = new WP_Upgrader($upgrader_skin);
300
301 // Is an update available?
302 if (!isset($current_update->response) || $current_update->response == 'latest')
303 return array(
304 'upgraded' => ' updated'
305 );
306
307 $res = $upgrader->fs_connect(array(
308 ABSPATH,
309 WP_CONTENT_DIR
310 ));
311 if (is_wp_error($res))
312 return array(
313 'error' => $this->mmb_get_error($res)
314 );
315
316 $wp_dir = trailingslashit($wp_filesystem->abspath());
317
318 $core_package = false;
319 if (isset($current_update->package) && !empty($current_update->package))
320 $core_package = $current_update->package;
321 elseif (isset($current_update->packages->full) && !empty($current_update->packages->full))
322 $core_package = $current_update->packages->full;
323
324 $download = $upgrader->download_package($core_package);
325 if (is_wp_error($download))
326 return array(
327 'error' => $this->mmb_get_error($download)
328 );
329
330 $working_dir = $upgrader->unpack_package($download);
331 if (is_wp_error($working_dir))
332 return array(
333 'error' => $this->mmb_get_error($working_dir)
334 );
335
336 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
337 $wp_filesystem->delete($working_dir, true);
338 return array(
339 'error' => 'Unable to move update files.'
340 );
341 }
342
343 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
344
345 require(ABSPATH . 'wp-admin/includes/update-core.php');
346
347
348 $update_core = update_core($working_dir, $wp_dir);
349 ob_end_clean();
350
351 $this->mmb_maintenance_mode(false);
352 if (is_wp_error($update_core))
353 return array(
354 'error' => $this->mmb_get_error($update_core)
355 );
356 ob_end_flush();
357 return array(
358 'upgraded' => 'updated'
359 );
360 } else {
361 return array(
362 'error' => 'failed'
363 );
364 }
365 }
366 } else {
367 return array(
368 'error' => 'failed'
369 );
370 }
371 }
372
373 function upgrade_plugins($plugins = false)
374 {
375 if (!$plugins || empty($plugins))
376 return array(
377 'error' => 'No plugin files for upgrade.'
378 );
379
380 $current = $this->mmb_get_transient('update_plugins');
381 $versions = array();
382 if(!empty($current)){
383 foreach($plugins as $plugin => $data){
384 if(isset($current->checked[$plugin])){
385 $versions[$current->checked[$plugin]] = $plugin;
386 }
387 if ( !isset( $current->response[ $plugin ] ) ) {
388 unset($plugins[$plugin]);
389 }
390 }
391 }
392 $return = array();
393 if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
394 $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
395 $result = $upgrader->bulk_upgrade(array_keys($plugins));
396 if (!function_exists('wp_update_plugins'))
397 include_once(ABSPATH . 'wp-includes/update.php');
398
399 @wp_update_plugins();
400 $current = $this->mmb_get_transient('update_plugins');
401 if (!empty($result)) {
402 foreach ($result as $plugin_slug => $plugin_info) {
403 if (!$plugin_info || is_wp_error($plugin_info)) {
404 $return[$plugin_slug] = $this->mmb_get_error($plugin_info);
405 } else {
406 if(!empty($result[$plugin_slug]) || (isset($current->checked[$plugin_slug]) && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true)){
407 $return[$plugin_slug] = 1;
408 } else {
409 update_option('mmb_forcerefresh', true);
410 $return[$plugin_slug] = 'Could not refresh upgrade transients, please reload website data';
411 }
412 }
413 }
414 ob_end_clean();
415 return array(
416 'upgraded' => $return
417 );
418 } else
419 return array(
420 'error' => 'Upgrade failed.'
421 );
422 } else {
423 ob_end_clean();
424 return array(
425 'error' => 'WordPress update required first.'
426 );
427 }
428 }
429
430 function upgrade_themes($themes = false)
431 {
432 if (!$themes || empty($themes))
433 return array(
434 'error' => 'No theme files for upgrade.'
435 );
436
437 $current = $this->mmb_get_transient('update_themes');
438 $versions = array();
439 if(!empty($current)){
440 foreach($themes as $theme){
441 if(isset($current->checked[$theme])){
442 $versions[$current->checked[$theme]] = $theme;
443 }
444 }
445 }
446 if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
447 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
448 $result = $upgrader->bulk_upgrade($themes);
449
450 if (!function_exists('wp_update_themes'))
451 include_once(ABSPATH . 'wp-includes/update.php');
452
453 @wp_update_themes();
454 $current = $this->mmb_get_transient('update_themes');
455 $return = array();
456 if (!empty($result)) {
457 foreach ($result as $theme_tmp => $theme_info) {
458 if (is_wp_error($theme_info) || empty($theme_info)) {
459 $return[$theme_tmp] = $this->mmb_get_error($theme_info);
460 } else {
461 if(!empty($result[$theme_tmp]) || (isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true)){
462 $return[$theme_tmp] = 1;
463 } else {
464 update_option('mmb_forcerefresh', true);
465 $return[$theme_tmp] = 'Could not refresh upgrade transients, please reload website data';
466 }
467 }
468 }
469 return array(
470 'upgraded' => $return
471 );
472 } else
473 return array(
474 'error' => 'Upgrade failed.'
475 );
476 } else {
477 ob_end_clean();
478 return array(
479 'error' => 'WordPress update required first'
480 );
481 }
482 }
483
484 function upgrade_premium($premium = false)
485 {
486 global $mmb_plugin_url;
487
488 if (!class_exists('WP_Upgrader'))
489 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
490
491 if (!$premium || empty($premium))
492 return array(
493 'error' => 'No premium files for upgrade.'
494 );
495
496 $upgrader = false;
497 $pr_update = array();
498 $themes = array();
499 $plugins = array();
500 $result = array();
501 $premium_update = array();
502 $premium_update = apply_filters('mwp_premium_perform_update', $premium_update);
503 if (!empty($premium_update)) {
504
505 foreach ($premium as $pr) {
506 foreach ($premium_update as $key => $update) {
507 $update = array_change_key_case($update, CASE_LOWER);
508 if ($update['name'] == $pr['name']) {
509
510 // prepare bulk updates for premiums that use WordPress upgrader
511 if(isset($update['type'])){
512 if($update['type'] == 'plugin'){
513 if(isset($update['slug']) && !empty($update['slug']))
514 $plugins[$update['slug']] = $update;
515 }
516
517 if($update['type'] == 'theme'){
518 if(isset($update['template']) && !empty($update['template']))
519 $themes[$update['template']] = $update;
520 }
521 }
522 } else {
523 unset($premium_update[$key]);
524 }
525 }
526 }
527
528 // try default wordpress upgrader
529 if(!empty($plugins)){
530 $updateplugins = $this->upgrade_plugins(array_values($plugins));
531 if(!empty($updateplugins) && isset($updateplugins['upgraded'])){
532 foreach ($premium_update as $key => $update) {
533 $update = array_change_key_case($update, CASE_LOWER);
534 foreach($updateplugins['upgraded'] as $slug => $upgrade){
535 if( isset($update['slug']) && $update['slug'] == $slug){
536 if( $upgrade == 1 )
537 unset($premium_update[$key]);
538
539 $pr_update['plugins']['upgraded'][md5($update['name'])] = $upgrade;
540 }
541 }
542 }
543 }
544 }
545
546 // if(!empty($themes)){
547 // $updatethemes = $this->upgrade_themes(array_keys($themes));
548 // if(!empty($updatethemes) && isset($updatethemes['upgraded'])){
549 // foreach ($premium_update as $key => $update) {
550 // $update = array_change_key_case($update, CASE_LOWER);
551 // foreach($updatethemes['upgraded'] as $template => $upgrade){
552 // if( isset($update['template']) && $update['template'] == $template) {
553 // if( $upgrade == 1 )
554 // unset($premium_update[$key]);
555 //
556 // $pr_update['themes']['upgraded'][md5($update['name'])] = $upgrade;
557 // }
558 // }
559 // }
560 // }
561 // }
562
563 //try direct install with overwrite
564 if(!empty($premium_update)){
565 foreach ($premium_update as $update) {
566 $update = array_change_key_case($update, CASE_LOWER);
567 $update_result = false;
568 if (isset($update['url'])) {
569 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
570 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
571
572 $upgrader_skin = new WP_Upgrader_Skin();
573 $upgrader_skin->done_header = true;
574 $upgrader = new WP_Upgrader();
575 @$update_result = $upgrader->run(array(
576 'package' => $update['url'],
577 'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR,
578 'clear_destination' => true,
579 'clear_working' => true,
580 'is_multi' => true,
581 'hook_extra' => array()
582 ));
583 $update_result = !$update_result || is_wp_error($update_result) ? $this->mmb_get_error($update_result) : 1;
584
585 } else if (isset($update['callback'])) {
586 if (is_array($update['callback'])) {
587 $update_result = call_user_func(array( $update['callback'][0], $update['callback'][1] ));
588 } else if (is_string($update['callback'])) {
589 $update_result = call_user_func($update['callback']);
590 } else {
591 $update_result = 'Upgrade function "' . $update['callback'] . '" does not exists.';
592 }
593
594 $update_result = $update_result !== true ? $this->mmb_get_error($update_result) : 1;
595 } else
596 $update_result = 'Bad update params.';
597
598 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
599 }
600 }
601 return $pr_update;
602 } else {
603 foreach ($premium as $pr) {
604 $result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = 'This premium update is not registered.';
605 }
606 return $result;
607 }
608 }
609
610 function get_upgradable_plugins( $filter = array() )
611 {
612 $current = $this->mmb_get_transient('update_plugins');
613
614 $upgradable_plugins = array();
615 if (!empty($current->response)) {
616 if (!function_exists('get_plugin_data'))
617 include_once ABSPATH . 'wp-admin/includes/plugin.php';
618 foreach ($current->response as $plugin_path => $plugin_data) {
619 if ($plugin_path == 'worker/init.php')
620 continue;
621
622 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
623 if(isset($data['Name']) && in_array($data['Name'], $filter))
624 continue;
625
626 if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
627 $current->response[$plugin_path]->name = $data['Name'];
628 $current->response[$plugin_path]->old_version = $data['Version'];
629 $current->response[$plugin_path]->file = $plugin_path;
630 unset($current->response[$plugin_path]->upgrade_notice);
631 $upgradable_plugins[] = $current->response[$plugin_path];
632 }
633 }
634 return $upgradable_plugins;
635 } else
636 return array();
637 }
638
639 function get_upgradable_themes( $filter = array() )
640 {
641 if(function_exists('wp_get_themes')){
642 $all_themes = wp_get_themes();
643 $upgrade_themes = array();
644
645 $current = $this->mmb_get_transient('update_themes');
646 if (!empty($current->response)) {
647 foreach ((array) $all_themes as $theme_template => $theme_data) {
648 if(isset($theme_data->{'Parent Theme'}) && !empty($theme_data->{'Parent Theme'}))
649 continue;
650
651 if(isset($theme_data->Name) && in_array($theme_data->Name, $filter))
652 continue;
653
654 foreach ($current->response as $current_themes => $theme) {
655 if ($theme_data->Template == $current_themes) {
656 if (strlen($theme_data->Name) > 0 && strlen($theme_data->Version) > 0) {
657 $current->response[$current_themes]['name'] = $theme_data->Name;
658 $current->response[$current_themes]['old_version'] = $theme_data->Version;
659 $current->response[$current_themes]['theme_tmp'] = $theme_data->Template;
660 $upgrade_themes[] = $current->response[$current_themes];
661 }
662 }
663 }
664 }
665 }
666 }else{
667 $all_themes = get_themes();
668
669 $upgrade_themes = array();
670
671 $current = $this->mmb_get_transient('update_themes');
672 if (!empty($current->response)) {
673 foreach ((array) $all_themes as $theme_template => $theme_data) {
674 if(isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme']))
675 continue;
676
677 if(isset($theme_data['Name']) && in_array($theme_data['Name'], $filter))
678 continue;
679
680 foreach ($current->response as $current_themes => $theme) {
681 if ($theme_data['Template'] == $current_themes) {
682 if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
683 $current->response[$current_themes]['name'] = $theme_data['Name'];
684 $current->response[$current_themes]['old_version'] = $theme_data['Version'];
685 $current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
686 $upgrade_themes[] = $current->response[$current_themes];
687 }
688 }
689 }
690 }
691 }
692 }
693
694
695 return $upgrade_themes;
696 }
697
698 function get($args)
699 {
700 if (empty($args))
701 return false;
702
703 //Args: $items('plugins,'themes'), $type (active || inactive), $search(name string)
704
705 $return = array();
706 if (is_array($args['items']) && in_array('plugins', $args['items'])) {
707 $return['plugins'] = $this->get_plugins($args);
708 }
709 if (is_array($args['items']) && in_array('themes', $args['items'])) {
710 $return['themes'] = $this->get_themes($args);
711 }
712
713 return $return;
714 }
715
716 function get_plugins($args)
717 {
718 if (empty($args))
719 return false;
720
721 extract($args);
722
723 if (!function_exists('get_plugins')) {
724 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
725 }
726 $all_plugins = get_plugins();
727 $plugins = array(
728 'active' => array(),
729 'inactive' => array()
730 );
731 if (is_array($all_plugins) && !empty($all_plugins)) {
732 $activated_plugins = get_option('active_plugins');
733 if (!$activated_plugins)
734 $activated_plugins = array();
735
736 $br_a = 0;
737 $br_i = 0;
738 foreach ($all_plugins as $path => $plugin) {
739 if ($plugin['Name'] != 'ManageWP - Worker') {
740 if (in_array($path, $activated_plugins)) {
741 $plugins['active'][$br_a]['path'] = $path;
742 $plugins['active'][$br_a]['name'] = strip_tags($plugin['Name']);
743 $plugins['active'][$br_a]['version'] = $plugin['Version'];
744 $br_a++;
745 }
746
747 if (!in_array($path, $activated_plugins)) {
748 $plugins['inactive'][$br_i]['path'] = $path;
749 $plugins['inactive'][$br_i]['name'] = strip_tags($plugin['Name']);
750 $plugins['inactive'][$br_i]['version'] = $plugin['Version'];
751 $br_i++;
752 }
753
754 }
755
756 if ($search) {
757 foreach ($plugins['active'] as $k => $plugin) {
758 if (!stristr($plugin['name'], $search)) {
759 unset($plugins['active'][$k]);
760 }
761 }
762
763 foreach ($plugins['inactive'] as $k => $plugin) {
764 if (!stristr($plugin['name'], $search)) {
765 unset($plugins['inactive'][$k]);
766 }
767 }
768 }
769 }
770 }
771
772 return $plugins;
773 }
774
775 function get_themes($args)
776 {
777 if (empty($args))
778 return false;
779
780 extract($args);
781
782 if (!function_exists('wp_get_themes')) {
783 include_once(ABSPATH . WPINC . '/theme.php');
784 }
785 if(function_exists('wp_get_themes')){
786 $all_themes = wp_get_themes();
787 $themes = array(
788 'active' => array(),
789 'inactive' => array()
790 );
791
792 if (is_array($all_themes) && !empty($all_themes)) {
793 $current_theme = get_current_theme();
794
795 $br_a = 0;
796 $br_i = 0;
797 foreach ($all_themes as $theme_name => $theme) {
798 if ($current_theme == strip_tags($theme->Name)) {
799 $themes['active'][$br_a]['path'] = $theme->Template;
800 $themes['active'][$br_a]['name'] = strip_tags($theme->Name);
801 $themes['active'][$br_a]['version'] = $theme->Version;
802 $themes['active'][$br_a]['stylesheet'] = $theme->Stylesheet;
803 $br_a++;
804 }
805
806 if ($current_theme != strip_tags($theme->Name)) {
807 $themes['inactive'][$br_i]['path'] = $theme->Template;
808 $themes['inactive'][$br_i]['name'] = strip_tags($theme->Name);
809 $themes['inactive'][$br_i]['version'] = $theme->Version;
810 $themes['inactive'][$br_i]['stylesheet'] = $theme->Stylesheet;
811 $br_i++;
812 }
813
814 }
815
816 if ($search) {
817 foreach ($themes['active'] as $k => $theme) {
818 if (!stristr($theme['name'], $search)) {
819 unset($themes['active'][$k]);
820 }
821 }
822
823 foreach ($themes['inactive'] as $k => $theme) {
824 if (!stristr($theme['name'], $search)) {
825 unset($themes['inactive'][$k]);
826 }
827 }
828 }
829 }
830 }else{
831 $all_themes = get_themes();
832 $themes = array(
833 'active' => array(),
834 'inactive' => array()
835 );
836
837 if (is_array($all_themes) && !empty($all_themes)) {
838 $current_theme = get_current_theme();
839
840 $br_a = 0;
841 $br_i = 0;
842 foreach ($all_themes as $theme_name => $theme) {
843 if ($current_theme == $theme_name) {
844 $themes['active'][$br_a]['path'] = $theme['Template'];
845 $themes['active'][$br_a]['name'] = strip_tags($theme['Name']);
846 $themes['active'][$br_a]['version'] = $theme['Version'];
847 $themes['active'][$br_a]['stylesheet'] = $theme['Stylesheet'];
848 $br_a++;
849 }
850
851 if ($current_theme != $theme_name) {
852 $themes['inactive'][$br_i]['path'] = $theme['Template'];
853 $themes['inactive'][$br_i]['name'] = strip_tags($theme['Name']);
854 $themes['inactive'][$br_i]['version'] = $theme['Version'];
855 $themes['inactive'][$br_i]['stylesheet'] = $theme['Stylesheet'];
856 $br_i++;
857 }
858
859 }
860
861 if ($search) {
862 foreach ($themes['active'] as $k => $theme) {
863 if (!stristr($theme['name'], $search)) {
864 unset($themes['active'][$k]);
865 }
866 }
867
868 foreach ($themes['inactive'] as $k => $theme) {
869 if (!stristr($theme['name'], $search)) {
870 unset($themes['inactive'][$k]);
871 }
872 }
873 }
874 }
875
876 }
877
878 return $themes;
879 }
880
881 function edit($args)
882 {
883 extract($args);
884 $return = array();
885 if ($type == 'plugins') {
886 $return['plugins'] = $this->edit_plugins($args);
887 } elseif ($type == 'themes') {
888 $return['themes'] = $this->edit_themes($args);
889 }
890 return $return;
891 }
892
893 function edit_plugins($args)
894 {
895 extract($args);
896 $return = array();
897 foreach ($items as $item) {
898 switch ($items_edit_action) {
899 case 'activate':
900 $result = activate_plugin($item['path']);
901 break;
902 case 'deactivate':
903 $result = deactivate_plugins(array(
904 $item['path']
905 ));
906 break;
907 case 'delete':
908 $result = delete_plugins(array(
909 $item['path']
910 ));
911 break;
912 default:
913 break;
914 }
915
916 if (is_wp_error($result)) {
917 $result = array(
918 'error' => $result->get_error_message()
919 );
920 } elseif ($result === false) {
921 $result = array(
922 'error' => "Failed to perform action."
923 );
924 } else {
925 $result = "OK";
926 }
927 $return[$item['name']] = $result;
928 }
929
930 return $return;
931 }
932
933 function edit_themes($args)
934 {
935 extract($args);
936 $return = array();
937 foreach ($items as $item) {
938 switch ($items_edit_action) {
939 case 'activate':
940 switch_theme($item['path'], $item['stylesheet']);
941 break;
942 case 'delete':
943 $result = delete_theme($item['path']);
944 break;
945 default:
946 break;
947 }
948
949 if (is_wp_error($result)) {
950 $result = array(
951 'error' => $result->get_error_message()
952 );
953 } elseif ($result === false) {
954 $result = array(
955 'error' => "Failed to perform action."
956 );
957 } else {
958 $result = "OK";
959 }
960 $return[$item['name']] = $result;
961 }
962
963 return $return;
964
965 }
966 }
967 ?>
968