PluginProbe
ManageWP Worker / 3.8.8
ManageWP Worker v3.8.8
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.8.8, at core.class.php

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