PluginProbe
ManageWP Worker / 3.9.6
ManageWP Worker v3.9.6
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.6, at installer.class.php

452 lines 14.0 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
13 class MMB_Installer extends MMB_Core
14 {
15 function __construct()
16 {
17 @set_time_limit(300);
18 parent::__construct();
19 include_once(ABSPATH . 'wp-admin/includes/file.php');
20 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
21 include_once(ABSPATH . 'wp-admin/includes/theme.php');
22 include_once(ABSPATH . 'wp-admin/includes/misc.php');
23 include_once(ABSPATH . 'wp-admin/includes/template.php');
24 @include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
25
26 global $wp_filesystem;
27 if (!$wp_filesystem)
28 WP_Filesystem();
29
30 }
31
32 function mmb_maintenance_mode($enable = false, $maintenance_message = '')
33 {
34 global $wp_filesystem;
35
36 $maintenance_message .= '<?php $upgrading = ' . time() . '; ?>';
37
38 $file = $wp_filesystem->abspath() . '.maintenance';
39 if ($enable) {
40 $wp_filesystem->delete($file);
41 $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
42 } else {
43 $wp_filesystem->delete($file);
44 }
45 }
46
47 function install_remote_file($params)
48 {
49 global $wp_filesystem;
50 extract($params);
51
52 if (!isset($package) || empty($package))
53 return array(
54 'error' => '<p>No files received. Internal error.</p>'
55 );
56
57 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
58 return array(
59 'error' => '<p>Site under maintanace.</p>'
60 );
61 ;
62
63 $upgrader = new WP_Upgrader();
64 $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
65
66
67 foreach ($package as $package_url) {
68 $key = basename($package_url);
69 $install_info[$key] = @$upgrader->run(array(
70 'package' => $package_url,
71 'destination' => $destination,
72 'clear_destination' => false, //Do not overwrite files.
73 'clear_working' => true,
74 'hook_extra' => array()
75 ));
76 }
77
78 if ($activate) {
79 if($type == 'plugins'){
80 include_once(ABSPATH.'wp-admin/includes/plugin.php');
81 $all_plugins = get_plugins();
82 foreach ($all_plugins as $plugin_slug => $plugin) {
83 $plugin_dir = preg_split('/\//', $plugin_slug);
84 foreach ($install_info as $key => $install) {
85 if (!$install || is_wp_error($install))
86 continue;
87
88 if ($install['destination_name'] == $plugin_dir[0]) {
89 $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
90 }
91 }
92 }
93 }else if(count($install_info) == 1){
94 include_once(ABSPATH.'wp-includes/theme.php');
95 $all_themes = get_themes();
96 foreach ($all_themes as $theme_name => $theme_data) {
97
98 foreach ($install_info as $key => $install) {
99 if (!$install || is_wp_error($install))
100 continue;
101
102 if ($theme_data['Template'] == $install['destination_name']) {
103 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
104 }
105 }
106 }
107 }
108 }
109 ob_clean();
110 $this->mmb_maintenance_mode(false);
111 return $install_info;
112 }
113
114 function do_upgrade($params = null){
115
116 if($params == null || empty($params))
117 return array('failed' => 'No upgrades passed.');
118
119 if (!$this->is_server_writable()) {
120 return array(
121 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details</a></a>'
122 );
123 }
124 $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
125
126 $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
127 $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
128 $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
129
130
131 $upgrades = array();
132 if(!empty($core_upgrade)){
133 $upgrades['core'] = $this->upgrade_core($core_upgrade);
134 }
135
136 if(!empty($upgrade_plugins)){
137 $plugin_files = array();
138 foreach($upgrade_plugins as $plugin){
139 $plugin_files[$plugin->file] = $plugin->old_version;
140 }
141
142 $upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
143
144 }
145
146 if(!empty($upgrade_themes)){
147 $theme_temps = array();
148 foreach($upgrade_themes as $theme){
149 $theme_temps[] = $theme['theme_tmp'];
150 }
151
152 $upgrades['themes'] = $this->upgrade_themes($theme_temps);
153 $this->mmb_maintenance_mode(false);
154 }
155 ob_clean();
156 $this->mmb_maintenance_mode(false);
157 return $upgrades;
158 }
159
160 /**
161 * Upgrades WordPress locally
162 *
163 */
164 function upgrade_core($current)
165 {
166 ob_start();
167 if(!function_exists('wp_version_check'))
168 include_once(ABSPATH.'/wp-admin/includes/update.php');
169
170 @wp_version_check();
171
172 if(!function_exists('get_core_updates'))
173 include_once(ABSPATH.'/wp-admin/includes/update.php');
174
175 $updates = get_core_updates();
176
177 $current_update = false;
178 ob_end_flush();
179 ob_end_clean();
180
181 if(!empty($updates)){
182 $updated = $updates[0];
183 if ( !isset( $updated->response ) || $updated->response == 'latest' )
184 return array('upgraded' => ' Upgraded successfully.');
185
186 if ($updated->response == "development" && $current->response == "upgrade") {
187 return array('upgraded' => '<font color="#900">Transient mismatch. Please upgrade manualy</font>');
188 }
189 else if ($updated->response == $current->response || ($updated->response == "upgrade" && $current->response == "development")){
190 if($updated->locale != $current->locale){
191 foreach($updates as $update){
192 if($update->locale == $current->locale){
193 $current_update = $update;
194 break;
195 }
196 }
197 if($current_update == false)
198 return array('error' => ' Localization mismatch. Try again.');
199 } else {
200 $current_update = $updated;
201 }
202 }
203 else
204 return array('error' => ' Transient mismatch. Try again.');
205 } else
206 return array('error' => ' Refresh transient failed. Try again.');
207 if($current_update != false){
208 global $mmb_wp_version, $wp_filesystem, $wp_version;
209
210 if (version_compare($wp_version, '3.1.9', '>')) {
211 if(!class_exists('Core_Upgrader'))
212 include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
213
214 $core = new Core_Upgrader();
215 $result = $core->upgrade($current_update);
216 if(is_wp_error($result)){
217 return array(
218 'error' => $this->mmb_get_error($result)
219 );
220 }
221 else
222 return array(
223 'upgraded' => ' Upgraded successfully.'
224 );
225
226 } else {
227 if(!class_exists('WP_Upgrader')){
228 include_once(ABSPATH.'wp-admin/includes/update.php');
229 if(function_exists('wp_update_core')){
230 $result = wp_update_core($current_update);
231 if(is_wp_error($result)){
232 return array(
233 'error' => $this->mmb_get_error($result)
234 );
235 }
236 else
237 return array(
238 'upgraded' => ' Upgraded successfully.'
239 );
240 }
241 }
242
243 if(class_exists('WP_Upgrader')){
244 $upgrader = new WP_Upgrader();
245
246 // Is an update available?
247 if (!isset($current_update->response) || $current_update->response == 'latest')
248 return array(
249 'upgraded' => ' Upgraded successfully.'
250 );
251
252 $res = $upgrader->fs_connect(array(
253 ABSPATH,
254 WP_CONTENT_DIR
255 ));
256 if (is_wp_error($res))
257 return array(
258 'error' => $this->mmb_get_error($res)
259 );
260
261 $wp_dir = trailingslashit($wp_filesystem->abspath());
262
263 $download = $upgrader->download_package($current_update->package);
264 if (is_wp_error($download))
265 return array(
266 'error' => $this->mmb_get_error($download)
267 );
268
269 $working_dir = $upgrader->unpack_package($download);
270 if (is_wp_error($working_dir))
271 return array(
272 'error' => $this->mmb_get_error($working_dir)
273 );
274
275 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
276 $wp_filesystem->delete($working_dir, true);
277 return array(
278 'error' => 'Unable to move update files.'
279 );
280 }
281
282 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
283
284 require(ABSPATH . 'wp-admin/includes/update-core.php');
285
286
287 $update_core = update_core($working_dir, $wp_dir);
288 ob_end_clean();
289
290 if (is_wp_error($update_core))
291 return array(
292 'error' => $this->mmb_get_error($update_core)
293 );
294 ob_end_flush();
295 return array(
296 'upgraded' => 'Upgraded successfully.'
297 );
298 } else {
299 return array(
300 'error' => 'Upgrade failed.'
301 );
302 }
303 }
304 } else {
305 return array(
306 'error' => 'Upgrade failed.'
307 );
308 }
309 }
310
311 function upgrade_plugins($plugins = false){
312 if(!$plugins || empty($plugins))
313 return array(
314 'error' => 'No plugin files for upgrade.'
315 );
316 $return = array();
317 if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
318
319 $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
320 $result = $upgrader->bulk_upgrade(array_keys($plugins));
321
322 if( !function_exists('wp_update_plugins') )
323 include_once(ABSPATH . 'wp-includes/update.php');
324
325 @wp_update_plugins();
326 $current_plugins = $this->mmb_get_transient('update_plugins');
327
328 if (!empty($result)) {
329 foreach ($result as $plugin_slug => $plugin_info) {
330 if (!$plugin_info || is_wp_error($plugin_info)) {
331 $return[$plugin_slug] = $this->mmb_get_error($plugin_info);
332 } else {
333 if(isset($current_plugins->response[$plugin_slug]) && !empty($current_plugins->response[$plugin_slug])){
334 $return[$plugin_slug] = false;
335 } else {
336 $return[$plugin_slug] = 1;
337 }
338 }
339 }
340 ob_end_clean();
341 return array(
342 'upgraded' => $return
343 );
344 }
345 else
346 return array(
347 'error' => 'Upgrade failed.'
348 );
349 } else {
350 ob_end_clean();
351 return array(
352 'error' => 'WordPress update required first.'
353 );
354 }
355 }
356
357 function upgrade_themes($themes = false){
358 if(!$themes || empty($themes))
359 return array(
360 'error' => 'No theme files for upgrade.'
361 );
362 if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
363
364
365 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
366 $result = $upgrader->bulk_upgrade($themes);
367
368 if( !function_exists('wp_update_themes') )
369 include_once(ABSPATH . 'wp-includes/update.php');
370
371 @wp_update_themes();
372 $current_themes = $this->mmb_get_transient('update_themes');
373
374 $return = array();
375 if (!empty($result)) {
376 foreach ($result as $theme_tmp => $theme_info) {
377 if (is_wp_error($theme_info) || !$theme_info) {
378 $return[$theme_tmp] = $this->mmb_get_error($theme_info);
379 } else {
380 if(isset($current_themes->response[$theme_tmp]) && !empty($current_themes->response[$theme_tmp])){
381 $return[$theme_tmp] = false;
382 } else {
383 $return[$theme_tmp] = 1;
384 }
385 }
386 }
387
388 return array(
389 'upgraded' => $return
390 );
391 } else
392 return array(
393 'error' => 'Upgrade failed.'
394 );
395 } else {
396 ob_end_clean();
397 return array(
398 'error' => 'WordPress update required first'
399 );
400 }
401 }
402
403 function get_upgradable_plugins()
404 {
405 $current = $this->mmb_get_transient('update_plugins');
406 $upgradable_plugins = array();
407 if (!empty($current->response)) {
408 if (!function_exists('get_plugin_data'))
409 include_once ABSPATH . 'wp-admin/includes/plugin.php';
410 foreach ($current->response as $plugin_path => $plugin_data) {
411 if($plugin_path == 'worker/init.php')
412 continue;
413
414 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
415 if(strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
416 $current->response[$plugin_path]->name = $data['Name'];
417 $current->response[$plugin_path]->old_version = $data['Version'];
418 $current->response[$plugin_path]->file = $plugin_path;
419 $upgradable_plugins[] = $current->response[$plugin_path];
420 }
421 }
422 return $upgradable_plugins;
423 } else
424 return array();
425
426 }
427
428 function get_upgradable_themes()
429 {
430 $all_themes = get_themes();
431 $upgrade_themes = array();
432
433 $current = $this->mmb_get_transient('update_themes');
434 foreach ((array) $all_themes as $theme_template => $theme_data) {
435 if (!empty($current->response)) {
436 foreach ($current->response as $current_themes => $theme) {
437 if ($theme_data['Template'] == $current_themes) {
438 if(strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
439 $current->response[$current_themes]['name'] = $theme_data['Name'];
440 $current->response[$current_themes]['old_version'] = $theme_data['Version'];
441 $current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
442 $upgrade_themes[] = $current->response[$current_themes];
443 }
444 }
445 }
446 }
447 }
448
449 return $upgrade_themes;
450 }
451 }
452 ?>