PluginProbe
ManageWP Worker / 3.8.6
ManageWP Worker v3.8.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.8.6, at core.class.php

366 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 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
76 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>
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 function get_installer_instance()
223 {
224 if (!isset($this->installer_instance)) {
225 $this->installer_instance = new MMB_Installer();
226 }
227 return $this->installer_instance;
228 }
229
230 /**
231 * Plugin install callback function
232 * Check PHP version
233 */
234 function install()
235 {
236 if (PHP_VERSION < 5) // min version 5 supported
237 exit("<p>Plugin could not be activated. Your PHP version must be 5.0 or higher.</p>");
238
239 // delete plugin options, just in case
240 delete_option('_worker_nossl_key');
241 delete_option('_worker_public_key');
242 delete_option('_action_message_id');
243
244 }
245
246 /**
247 * Saves the (modified) options into the database
248 *
249 */
250 function save_options()
251 {
252 if (get_option($this->slug)) {
253 update_option($this->slug, $this->settings);
254 } else {
255 add_option($this->slug, $this->settings);
256 }
257 }
258
259 /**
260 * Deletes options for communication with master
261 *
262 */
263 function uninstall()
264 {
265 delete_option('_worker_nossl_key');
266 delete_option('_worker_public_key');
267 delete_option('_action_message_id');
268 }
269
270 /**
271 * Constructs a url (for ajax purpose)
272 *
273 * @param mixed $base_page
274 */
275 function construct_url($params = array(), $base_page = 'index.php')
276 {
277 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
278 foreach ($params as $key => $value) {
279 $url .= "&$key=$value";
280 }
281
282 return $url;
283 }
284
285 /**
286 * Worker update
287 *
288 */
289 function update_worker_plugin($params)
290 {
291 extract($params);
292 if ($download_url) {
293 include_once ABSPATH . 'wp-admin/includes/file.php';
294 include_once ABSPATH . 'wp-admin/includes/misc.php';
295 include_once ABSPATH . 'wp-admin/includes/template.php';
296 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
297
298 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && (get_filesystem_method(array(), false) != 'direct'))
299 {
300 return array(
301 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
302 );
303 }
304
305 ob_start();
306 @unlink(dirname(__FILE__));
307 $upgrader = new Plugin_Upgrader();
308 $result = $upgrader->run(array(
309 'package' => $download_url,
310 'destination' => WP_PLUGIN_DIR,
311 'clear_destination' => true,
312 'clear_working' => true,
313 'hook_extra' => array(
314 'plugin' => 'worker/init.php'
315 )
316 ));
317 ob_end_clean();
318 if (is_wp_error($result) || !$result) {
319 return array(
320 'error' => 'ManageWP Worker could not been upgraded.'
321 );
322 } else {
323 return array(
324 'success' => 'ManageWP Worker plugin successfully upgraded.'
325 );
326 }
327 }
328 return array(
329 'error' => 'Bad download path for worker installation file.'
330 );
331 }
332
333 /**
334 * Automatically logs in when called from Master
335 *
336 */
337 function automatic_login()
338 {
339 $where = ($_GET['mwp_goto']);
340
341 if (!is_user_logged_in() && $_GET['auto_login']) {
342 $signature = base64_decode($_GET['signature']);
343 $message_id = trim($_GET['message_id']);
344 $username = $_GET['username'];
345
346 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
347 if ($auth === true) {
348 $user = get_user_by('login', $username);
349 $user_id = $user->ID;
350 wp_set_current_user($user_id, $username);
351 wp_set_auth_cookie($user_id);
352 do_action('wp_login', $username);
353 } else {
354 wp_die($auth['error']);
355 }
356 }
357
358 if ($_GET['auto_login']) {
359 wp_redirect(get_bloginfo('url') . "/wp-admin/" . $where);
360 exit();
361 }
362 }
363
364
365 }
366 ?>