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 / core.class.php

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

438 lines 12.2 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 add_action('init', array(
72 $this,
73 'automatic_login'
74 ));
75
76 if (!get_option('_worker_public_key'))
77 add_action('admin_notices', array(
78 $this,
79 'admin_notice'
80 ));
81
82
83 }
84
85 /**
86 * Add notice to admin dashboard for security reasons
87 *
88 */
89 function admin_notice()
90 {
91 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
92 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>.
93 </p></div>';
94 }
95
96 /**
97 * Add an item into the Right Now Dashboard widget
98 * to inform that the blog can be managed remotely
99 *
100 */
101 function add_right_now_info()
102 {
103 echo '<div class="mmb-slave-info">
104 <p>This site can be managed remotely.</p>
105 </div>';
106 }
107
108 /**
109 * Gets an instance of the Comment class
110 *
111 */
112 function get_comment_instance()
113 {
114 if (!isset($this->comment_instance)) {
115 $this->comment_instance = new MMB_Comment();
116 }
117
118 return $this->comment_instance;
119 }
120
121 /**
122 * Gets an instance of the Plugin class
123 *
124 */
125 function get_plugin_instance()
126 {
127 if (!isset($this->plugin_instance)) {
128 $this->plugin_instance = new MMB_Plugin();
129 }
130
131 return $this->plugin_instance;
132 }
133
134 /**
135 * Gets an instance of the Theme class
136 *
137 */
138 function get_theme_instance()
139 {
140 if (!isset($this->theme_instance)) {
141 $this->theme_instance = new MMB_Theme();
142 }
143
144 return $this->theme_instance;
145 }
146
147
148 /**
149 * Gets an instance of MMB_Post class
150 *
151 */
152 function get_post_instance()
153 {
154 if (!isset($this->post_instance)) {
155 $this->post_instance = new MMB_Post();
156 }
157
158 return $this->post_instance;
159 }
160
161 /**
162 * Gets an instance of Blogroll class
163 *
164 */
165 function get_blogroll_instance()
166 {
167 if (!isset($this->blogroll_instance)) {
168 $this->blogroll_instance = new MMB_Blogroll();
169 }
170
171 return $this->blogroll_instance;
172 }
173
174
175
176 /**
177 * Gets an instance of the WP class
178 *
179 */
180 function get_wp_instance()
181 {
182 if (!isset($this->wp_instance)) {
183 $this->wp_instance = new MMB_WP();
184 }
185
186 return $this->wp_instance;
187 }
188
189 /**
190 * Gets an instance of User
191 *
192 */
193 function get_user_instance()
194 {
195 if (!isset($this->user_instance)) {
196 $this->user_instance = new MMB_User();
197 }
198
199 return $this->user_instance;
200 }
201
202 /**
203 * Gets an instance of stats class
204 *
205 */
206 function get_stats_instance()
207 {
208 if (!isset($this->stats_instance)) {
209 $this->stats_instance = new MMB_Stats();
210 }
211 return $this->stats_instance;
212 }
213 /**
214 * Gets an instance of search class
215 *
216 */
217 function get_search_instance()
218 {
219 if (!isset($this->search_instance)) {
220 $this->search_instance = new MMB_Search();
221 }
222 //return $this->search_instance;
223 return $this->search_instance;
224 }
225 /**
226 * Gets an instance of stats class
227 *
228 */
229 function get_backup_instance()
230 {
231 if (!isset($this->backup_instance)) {
232 $this->backup_instance = new MMB_Backup();
233 }
234
235 return $this->backup_instance;
236 }
237
238 /**
239 * Gets an instance of links class
240 *
241 */
242 function get_link_instance()
243 {
244 if (!isset($this->link_instance)) {
245 $this->link_instance = new MMB_Link();
246 }
247
248 return $this->link_instance;
249 }
250
251 function get_installer_instance()
252 {
253 if (!isset($this->installer_instance)) {
254 $this->installer_instance = new MMB_Installer();
255 }
256 return $this->installer_instance;
257 }
258
259 /**
260 * Plugin install callback function
261 * Check PHP version
262 */
263 function install()
264 {
265 global $wp_object_cache, $wpdb;
266 if(!empty($wp_object_cache))
267 @$wp_object_cache->flush();
268
269 // delete plugin options, just in case
270 if($this->mmb_multisite != false){
271 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
272 if(!empty($blog_ids)){
273 foreach($blog_ids as $blog_id){
274 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_nossl_key";'));
275 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_public_key";'));
276 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_action_message_id";'));
277 }
278 }
279 } else {
280 delete_option('_worker_nossl_key');
281 delete_option('_worker_public_key');
282 delete_option('_action_message_id');
283 }
284
285 //Reset backup tasks
286 delete_option('mwp_backup_tasks');
287 }
288
289 /**
290 * Saves the (modified) options into the database
291 *
292 */
293 function save_options()
294 {
295 if (get_option($this->slug)) {
296 update_option($this->slug, $this->settings);
297 } else {
298 add_option($this->slug, $this->settings);
299 }
300 }
301
302 /**
303 * Deletes options for communication with master
304 *
305 */
306 function uninstall()
307 {
308 global $wp_object_cache, $wpdb;
309 if(!empty($wp_object_cache))
310 @$wp_object_cache->flush();
311
312 if($this->mmb_multisite != false){
313 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
314 if(!empty($blog_ids)){
315 foreach($blog_ids as $blog){
316 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_nossl_key";'));
317 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_public_key";'));
318 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_action_message_id";'));
319 }
320 }
321 } else {
322 delete_option('_worker_nossl_key');
323 delete_option('_worker_public_key');
324 delete_option('_action_message_id');
325 }
326
327 //Delete backup tasks
328 delete_option('mwp_backup_tasks');
329 wp_clear_scheduled_hook('mwp_backup_tasks');
330 }
331
332
333 /**
334 * Constructs a url (for ajax purpose)
335 *
336 * @param mixed $base_page
337 */
338 function construct_url($params = array(), $base_page = 'index.php')
339 {
340 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
341 foreach ($params as $key => $value) {
342 $url .= "&$key=$value";
343 }
344
345 return $url;
346 }
347
348 /**
349 * Worker update
350 *
351 */
352 function update_worker_plugin($params)
353 {
354 extract($params);
355 if ($download_url) {
356 include_once ABSPATH . 'wp-admin/includes/file.php';
357 include_once ABSPATH . 'wp-admin/includes/misc.php';
358 include_once ABSPATH . 'wp-admin/includes/template.php';
359 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
360
361 if (!$this->is_server_writable()) {
362 return array(
363 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
364 );
365 }
366
367 ob_start();
368 @unlink(dirname(__FILE__));
369 $upgrader = new Plugin_Upgrader();
370 $result = $upgrader->run(array(
371 'package' => $download_url,
372 'destination' => WP_PLUGIN_DIR,
373 'clear_destination' => true,
374 'clear_working' => true,
375 'hook_extra' => array(
376 'plugin' => 'worker/init.php'
377 )
378 ));
379 ob_end_clean();
380 if (is_wp_error($result) || !$result) {
381 return array(
382 'error' => 'ManageWP Worker plugin could not be upgraded.'
383 );
384 } else {
385 return array(
386 'success' => 'ManageWP Worker plugin successfully upgraded.'
387 );
388 }
389 }
390 return array(
391 'error' => 'Bad download path for worker installation file.'
392 );
393 }
394
395 /**
396 * Automatically logs in when called from Master
397 *
398 */
399 function automatic_login()
400 {
401 global $current_user;
402
403 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : '';
404 $username = isset($_GET['username']) ? $_GET['username'] : '';
405 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
406
407 if ((!is_user_logged_in() || ($this->mmb_multisite && $username != $current_user->user_login)) && $auto_login) {
408
409 $signature = base64_decode($_GET['signature']);
410 $message_id = trim($_GET['message_id']);
411
412 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
413 if ($auth === true) {
414 if(isset($current_user->user_login))
415 do_action('wp_logout');
416 $user = get_user_by('login', $username);
417 $user_id = $user->ID;
418 wp_set_current_user($user_id, $username);
419 wp_set_auth_cookie($user_id);
420 do_action('wp_login', $username);
421 } else {
422 unset($_SESSION['mwp_frame_options_header']);
423 wp_die($auth['error']);
424 }
425 }
426
427 if ($_GET['auto_login']) {
428 update_option('mwp_iframe_options_header', microtime(true));
429 if(!headers_sent())
430 header('P3P: CP="CAO PSA OUR"'); // IE redirect iframe header
431 wp_redirect(get_option('siteurl') . "/wp-admin/" . $where);
432 exit();
433 }
434 }
435
436
437 }
438 ?>