PluginProbe
ManageWP Worker / 3.8.4
ManageWP Worker v3.8.4
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.4, at core.class.php

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