PluginProbe
ManageWP Worker / 3.9.0
ManageWP Worker v3.9.0
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.0, at core.class.php

385 lines 9.8 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 $user_instance;
26 var $backup_instance;
27 var $installer_instance;
28
29
30 function __construct()
31 {
32 global $mmb_plugin_dir;
33
34 $this->name = 'Manage Multiple Blogs';
35 $this->slug = 'manage-multiple-blogs';
36 $this->settings = get_option($this->slug);
37 if (!$this->settings) {
38 $this->settings = array(
39 'blogs' => array(),
40 'current_blog' => array(
41 'type' => null
42 )
43 );
44 $this->save_options();
45 }
46 add_action('rightnow_end', array(
47 $this,
48 'add_right_now_info'
49 ));
50 add_action('wp_footer', array(
51 'MMB_Stats',
52 'set_hit_count'
53 ));
54 register_activation_hook($mmb_plugin_dir . '/init.php', array(
55 $this,
56 'install'
57 ));
58 add_action('init', array(
59 $this,
60 'automatic_login'
61 ));
62
63 if (!get_option('_worker_public_key'))
64 add_action('admin_notices', array(
65 $this,
66 'admin_notice'
67 ));
68 }
69 /**
70 * Add notice to admin dashboard for security reasons
71 *
72 */
73 function admin_notice()
74 {
75 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
76 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>.
77 </p></div>';
78 }
79
80 /**
81 * Add an item into the Right Now Dashboard widget
82 * to inform that the blog can be managed remotely
83 *
84 */
85 function add_right_now_info()
86 {
87 echo '<div class="mmb-slave-info">
88 <p>This site can be managed remotely.</p>
89 </div>';
90 }
91
92 /**
93 * Gets an instance of the Comment class
94 *
95 */
96 function get_comment_instance()
97 {
98 if (!isset($this->comment_instance)) {
99 $this->comment_instance = new MMB_Comment();
100 }
101
102 return $this->comment_instance;
103 }
104
105 /**
106 * Gets an instance of the Plugin class
107 *
108 */
109 function get_plugin_instance()
110 {
111 if (!isset($this->plugin_instance)) {
112 $this->plugin_instance = new MMB_Plugin();
113 }
114
115 return $this->plugin_instance;
116 }
117
118 /**
119 * Gets an instance of the Theme class
120 *
121 */
122 function get_theme_instance()
123 {
124 if (!isset($this->theme_instance)) {
125 $this->theme_instance = new MMB_Theme();
126 }
127
128 return $this->theme_instance;
129 }
130
131
132 /**
133 * Gets an instance of MMB_Post class
134 *
135 */
136 function get_post_instance()
137 {
138 if (!isset($this->post_instance)) {
139 $this->post_instance = new MMB_Post();
140 }
141
142 return $this->post_instance;
143 }
144
145 /**
146 * Gets an instance of Blogroll class
147 *
148 */
149 function get_blogroll_instance()
150 {
151 if (!isset($this->blogroll_instance)) {
152 $this->blogroll_instance = new MMB_Blogroll();
153 }
154
155 return $this->blogroll_instance;
156 }
157
158
159
160 /**
161 * Gets an instance of the WP class
162 *
163 */
164 function get_wp_instance()
165 {
166 if (!isset($this->wp_instance)) {
167 $this->wp_instance = new MMB_WP();
168 }
169
170 return $this->wp_instance;
171 }
172
173 /**
174 * Gets an instance of User
175 *
176 */
177 function get_user_instance()
178 {
179 if (!isset($this->user_instance)) {
180 $this->user_instance = new MMB_User();
181 }
182
183 return $this->user_instance;
184 }
185
186 /**
187 * Gets an instance of stats class
188 *
189 */
190 function get_stats_instance()
191 {
192 if (!isset($this->stats_instance)) {
193 $this->stats_instance = new MMB_Stats();
194 }
195 return $this->stats_instance;
196 }
197 /**
198 * Gets an instance of search class
199 *
200 */
201 function get_search_instance()
202 {
203 if (!isset($this->search_instance)) {
204 $this->search_instance = new MMB_Search();
205 }
206 //return $this->search_instance;
207 return $this->search_instance;
208 }
209 /**
210 * Gets an instance of stats class
211 *
212 */
213 function get_backup_instance()
214 {
215 if (!isset($this->backup_instance)) {
216 $this->backup_instance = new MMB_Backup();
217 }
218
219 return $this->backup_instance;
220 }
221
222 /**
223 * Gets an instance of links class
224 *
225 */
226 function get_link_instance()
227 {
228 if (!isset($this->link_instance)) {
229 $this->link_instance = new MMB_Link();
230 }
231
232 return $this->link_instance;
233 }
234
235 function get_installer_instance()
236 {
237 if (!isset($this->installer_instance)) {
238 $this->installer_instance = new MMB_Installer();
239 }
240 return $this->installer_instance;
241 }
242
243 /**
244 * Plugin install callback function
245 * Check PHP version
246 */
247 function install()
248 {
249 global $wp_object_cache;
250 if(!empty($wp_object_cache))
251 @$wp_object_cache->flush();
252
253 // delete plugin options, just in case
254 delete_option('_worker_nossl_key');
255 delete_option('_worker_public_key');
256 delete_option('_action_message_id');
257
258 }
259
260 /**
261 * Saves the (modified) options into the database
262 *
263 */
264 function save_options()
265 {
266 if (get_option($this->slug)) {
267 update_option($this->slug, $this->settings);
268 } else {
269 add_option($this->slug, $this->settings);
270 }
271 }
272
273 /**
274 * Deletes options for communication with master
275 *
276 */
277 function uninstall()
278 {
279 global $wp_object_cache;
280 if(!empty($wp_object_cache))
281 @$wp_object_cache->flush();
282
283 delete_option('_worker_nossl_key');
284 delete_option('_worker_public_key');
285 delete_option('_action_message_id');
286 }
287
288 /**
289 * Constructs a url (for ajax purpose)
290 *
291 * @param mixed $base_page
292 */
293 function construct_url($params = array(), $base_page = 'index.php')
294 {
295 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
296 foreach ($params as $key => $value) {
297 $url .= "&$key=$value";
298 }
299
300 return $url;
301 }
302
303 /**
304 * Worker update
305 *
306 */
307 function update_worker_plugin($params)
308 {
309 extract($params);
310 if ($download_url) {
311 include_once ABSPATH . 'wp-admin/includes/file.php';
312 include_once ABSPATH . 'wp-admin/includes/misc.php';
313 include_once ABSPATH . 'wp-admin/includes/template.php';
314 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
315
316 if (!$this->is_server_writable()) {
317 return array(
318 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
319 );
320 }
321
322 ob_start();
323 @unlink(dirname(__FILE__));
324 $upgrader = new Plugin_Upgrader();
325 $result = $upgrader->run(array(
326 'package' => $download_url,
327 'destination' => WP_PLUGIN_DIR,
328 'clear_destination' => true,
329 'clear_working' => true,
330 'hook_extra' => array(
331 'plugin' => 'worker/init.php'
332 )
333 ));
334 ob_end_clean();
335 if (is_wp_error($result) || !$result) {
336 return array(
337 'error' => 'ManageWP Worker could not been upgraded.'
338 );
339 } else {
340 return array(
341 'success' => 'ManageWP Worker plugin successfully upgraded.'
342 );
343 }
344 }
345 return array(
346 'error' => 'Bad download path for worker installation file.'
347 );
348 }
349
350 /**
351 * Automatically logs in when called from Master
352 *
353 */
354 function automatic_login()
355 {
356 $where = ($_GET['mwp_goto']);
357
358 if (!is_user_logged_in() && $_GET['auto_login']) {
359 $signature = base64_decode($_GET['signature']);
360 $message_id = trim($_GET['message_id']);
361 $username = $_GET['username'];
362
363 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
364 if ($auth === true) {
365 $user = get_user_by('login', $username);
366 $user_id = $user->ID;
367 wp_set_current_user($user_id, $username);
368 wp_set_auth_cookie($user_id);
369 do_action('wp_login', $username);
370 } else {
371 unset($_SESSION['mwp_frame_options_header']);
372 wp_die($auth['error']);
373 }
374 }
375
376 if ($_GET['auto_login']) {
377 update_option('mwp_iframe_options_header', microtime(true));
378 wp_redirect(get_option('siteurl') . "/wp-admin/" . $where);
379 exit();
380 }
381 }
382
383
384 }
385 ?>