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

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