PluginProbe
ManageWP Worker / 3.9.9
ManageWP Worker v3.9.9
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 / core.class.php

core.class.php in ManageWP Worker 3.9.9, at core.class.php

441 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * core.class.php
5 *
6 * Upgrade Plugins
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12 class MMB_Core extends MMB_Helper
13 {
14 var $name;
15 var $slug;
16 var $settings;
17 var $remote_client;
18 var $comment_instance;
19 var $plugin_instance;
20 var $theme_instance;
21 var $wp_instance;
22 var $post_instance;
23 var $stats_instance;
24 var $search_instance;
25 var $links_instance;
26 var $user_instance;
27 var $backup_instance;
28 var $installer_instance;
29 var $mmb_multisite = false;
30
31
32 function __construct()
33 {
34 global $mmb_plugin_dir, $wpmu_version, $blog_id;
35
36 $this->name = 'Manage Multiple Blogs';
37 $this->slug = 'manage-multiple-blogs';
38 $this->settings = get_option($this->slug);
39 if (!$this->settings) {
40 $this->settings = array(
41 'blogs' => array(),
42 'current_blog' => array(
43 'type' => null
44 )
45 );
46 $this->save_options();
47 }
48
49
50
51 if (function_exists('is_multisite')) {
52 if (is_multisite()) {
53 $this->mmb_multisite = $blog_id;
54 }
55 } else if (!empty($wpmu_version)) {
56 $this->mmb_multisite = $blog_id;
57 }
58
59 add_action('rightnow_end', array(
60 $this,
61 'add_right_now_info'
62 ));
63 add_action('wp_footer', array(
64 'MMB_Stats',
65 'set_hit_count'
66 ));
67 register_activation_hook($mmb_plugin_dir . '/init.php', array(
68 $this,
69 'install'
70 ));
71 if (!get_option('_worker_public_key'))
72 add_action('admin_notices', array(
73 $this,
74 'admin_notice'
75 ));
76
77
78 }
79
80 /**
81 * Add notice to admin dashboard for security reasons
82 *
83 */
84 function admin_notice()
85 {
86 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
87 Please add this site to your <a target="_blank" href="http://managewp.com/user-guide#security">ManageWP.com</a> account now to remove this notice or deactivate the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide#security">security issues</a>.
88 </p></div>';
89 }
90
91 /**
92 * Add an item into the Right Now Dashboard widget
93 * to inform that the blog can be managed remotely
94 *
95 */
96 function add_right_now_info()
97 {
98 echo '<div class="mmb-slave-info">
99 <p>This site can be managed remotely.</p>
100 </div>';
101 }
102
103 /**
104 * Gets an instance of the Comment class
105 *
106 */
107 function get_comment_instance()
108 {
109 if (!isset($this->comment_instance)) {
110 $this->comment_instance = new MMB_Comment();
111 }
112
113 return $this->comment_instance;
114 }
115
116 /**
117 * Gets an instance of the Plugin class
118 *
119 */
120 function get_plugin_instance()
121 {
122 if (!isset($this->plugin_instance)) {
123 $this->plugin_instance = new MMB_Plugin();
124 }
125
126 return $this->plugin_instance;
127 }
128
129 /**
130 * Gets an instance of the Theme class
131 *
132 */
133 function get_theme_instance()
134 {
135 if (!isset($this->theme_instance)) {
136 $this->theme_instance = new MMB_Theme();
137 }
138
139 return $this->theme_instance;
140 }
141
142
143 /**
144 * Gets an instance of MMB_Post class
145 *
146 */
147 function get_post_instance()
148 {
149 if (!isset($this->post_instance)) {
150 $this->post_instance = new MMB_Post();
151 }
152
153 return $this->post_instance;
154 }
155
156 /**
157 * Gets an instance of Blogroll class
158 *
159 */
160 function get_blogroll_instance()
161 {
162 if (!isset($this->blogroll_instance)) {
163 $this->blogroll_instance = new MMB_Blogroll();
164 }
165
166 return $this->blogroll_instance;
167 }
168
169
170
171 /**
172 * Gets an instance of the WP class
173 *
174 */
175 function get_wp_instance()
176 {
177 if (!isset($this->wp_instance)) {
178 $this->wp_instance = new MMB_WP();
179 }
180
181 return $this->wp_instance;
182 }
183
184 /**
185 * Gets an instance of User
186 *
187 */
188 function get_user_instance()
189 {
190 if (!isset($this->user_instance)) {
191 $this->user_instance = new MMB_User();
192 }
193
194 return $this->user_instance;
195 }
196
197 /**
198 * Gets an instance of stats class
199 *
200 */
201 function get_stats_instance()
202 {
203 if (!isset($this->stats_instance)) {
204 $this->stats_instance = new MMB_Stats();
205 }
206 return $this->stats_instance;
207 }
208 /**
209 * Gets an instance of search class
210 *
211 */
212 function get_search_instance()
213 {
214 if (!isset($this->search_instance)) {
215 $this->search_instance = new MMB_Search();
216 }
217 //return $this->search_instance;
218 return $this->search_instance;
219 }
220 /**
221 * Gets an instance of stats class
222 *
223 */
224 function get_backup_instance()
225 {
226 if (!isset($this->backup_instance)) {
227 $this->backup_instance = new MMB_Backup();
228 }
229
230 return $this->backup_instance;
231 }
232
233 /**
234 * Gets an instance of links class
235 *
236 */
237 function get_link_instance()
238 {
239 if (!isset($this->link_instance)) {
240 $this->link_instance = new MMB_Link();
241 }
242
243 return $this->link_instance;
244 }
245
246 function get_installer_instance()
247 {
248 if (!isset($this->installer_instance)) {
249 $this->installer_instance = new MMB_Installer();
250 }
251 return $this->installer_instance;
252 }
253
254 /**
255 * Plugin install callback function
256 * Check PHP version
257 */
258 function install()
259 {
260 global $wp_object_cache, $wpdb;
261 if (!empty($wp_object_cache))
262 @$wp_object_cache->flush();
263
264 //delete plugin options, just in case
265 if ($this->mmb_multisite != false) {
266 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
267 if (!empty($blog_ids)) {
268 foreach ($blog_ids as $blog_id) {
269 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_worker_nossl_key";'));
270 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_worker_public_key";'));
271 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_action_message_id";'));
272 }
273 }
274 } else {
275 delete_option('_worker_nossl_key');
276 delete_option('_worker_public_key');
277 delete_option('_action_message_id');
278 }
279
280 delete_option('mwp_backup_tasks');
281 delete_option('mwp_notifications');
282
283 }
284
285 /**
286 * Saves the (modified) options into the database
287 *
288 */
289 function save_options()
290 {
291 if (get_option($this->slug)) {
292 update_option($this->slug, $this->settings);
293 } else {
294 add_option($this->slug, $this->settings);
295 }
296 }
297
298 /**
299 * Deletes options for communication with master
300 *
301 */
302 function uninstall()
303 {
304 global $wp_object_cache, $wpdb;
305 if (!empty($wp_object_cache))
306 @$wp_object_cache->flush();
307
308 if ($this->mmb_multisite != false) {
309 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
310 if (!empty($blog_ids)) {
311 foreach ($blog_ids as $blog) {
312 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_worker_nossl_key";'));
313 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_worker_public_key";'));
314 $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . $blog->blog_id . '_options WHERE `option_name` = "_action_message_id";'));
315 }
316 }
317 } else {
318 delete_option('_worker_nossl_key');
319 delete_option('_worker_public_key');
320 delete_option('_action_message_id');
321 }
322
323 //Delete backup tasks
324 delete_option('mwp_backup_tasks');
325 wp_clear_scheduled_hook('mwp_backup_tasks');
326
327 //Delete notifications
328 delete_option('mwp_notifications');
329 wp_clear_scheduled_hook('mwp_notifications');
330
331 }
332
333
334 /**
335 * Constructs a url (for ajax purpose)
336 *
337 * @param mixed $base_page
338 */
339 function construct_url($params = array(), $base_page = 'index.php')
340 {
341 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
342 foreach ($params as $key => $value) {
343 $url .= "&$key=$value";
344 }
345
346 return $url;
347 }
348
349 /**
350 * Worker update
351 *
352 */
353 function update_worker_plugin($params)
354 {
355 extract($params);
356 if ($download_url) {
357 @include_once ABSPATH . 'wp-admin/includes/file.php';
358 @include_once ABSPATH . 'wp-admin/includes/misc.php';
359 @include_once ABSPATH . 'wp-admin/includes/template.php';
360 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
361 @include_once ABSPATH . 'wp-admin/includes/screen.php';
362
363 if (!$this->is_server_writable()) {
364 return array(
365 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
366 );
367 }
368
369 ob_start();
370 @unlink(dirname(__FILE__));
371 $upgrader = new Plugin_Upgrader();
372 $result = $upgrader->run(array(
373 'package' => $download_url,
374 'destination' => WP_PLUGIN_DIR,
375 'clear_destination' => true,
376 'clear_working' => true,
377 'hook_extra' => array(
378 'plugin' => 'worker/init.php'
379 )
380 ));
381 ob_end_clean();
382 if (is_wp_error($result) || !$result) {
383 return array(
384 'error' => 'ManageWP Worker plugin could not be updated.'
385 );
386 } else {
387 return array(
388 'success' => 'ManageWP Worker plugin successfully updated.'
389 );
390 }
391 }
392 return array(
393 'error' => 'Bad download path for worker installation file.'
394 );
395 }
396
397 /**
398 * Automatically logs in when called from Master
399 *
400 */
401 function automatic_login()
402 {
403 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : false;
404 $username = isset($_GET['username']) ? $_GET['username'] : '';
405 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
406
407 if( !function_exists('is_user_logged_in') )
408 include_once( ABSPATH.'wp-includes/pluggable.php' );
409
410 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->mmb_multisite) && $this->mmb_multisite )) {
411 $signature = base64_decode($_GET['signature']);
412 $message_id = trim($_GET['message_id']);
413
414 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
415 if ($auth === true) {
416 update_option('mwp_iframe_options_header', microtime(true));
417
418 if (!headers_sent())
419 header('P3P: CP="CAO PSA OUR"');
420
421 $siteurl = get_site_option( 'siteurl' );
422 $user = get_user_by('login', $username);
423 wp_set_current_user($user->ID);
424
425 $expiration = time() + apply_filters('auth_cookie_expiration', 21600, $user->ID, false);
426 $auth_cookie = wp_generate_auth_cookie($user->ID, $expiration, 'auth');
427 $logged_in_cookie = wp_generate_auth_cookie($user->ID, $expiration, 'logged_in');
428
429 $_COOKIE['wordpress_'.md5( $siteurl )] = $auth_cookie;
430 $_COOKIE['wordpress_logged_in_'.md5( $siteurl )] = $logged_in_cookie;
431
432 wp_set_auth_cookie($user->ID);
433
434
435 } else {
436 wp_die($auth['error']);
437 }
438 }
439 }
440 }
441 ?>