Version Description
- New interface
- SSL security protocl
- many more
Download this release
Release Info
Developer | freediver |
Plugin | ManageWP Worker |
Version | 3.8.0 |
Comparing to | |
See all releases |
Code changes from version 3.6.3 to 3.8.0
- backup.class.php +483 -519
- category.class.php +0 -118
- clone.class.php +0 -17
- comment.class.php +0 -85
- core.class.php +303 -410
- ende.class.php +0 -124
- helper.class.php +387 -206
- init.php +262 -356
- mmb.wp.upgrader.php +0 -1489
- page.class.php +0 -259
- plugin.class.php +106 -464
- post.class.php +299 -605
- readme.txt +6 -0
- stats.class.php +226 -193
- tags.class.php +0 -162
- theme.class.php +99 -347
- user.class.php +6 -6
- version +1 -1
- wp.class.php +90 -123
backup.class.php
CHANGED
@@ -1,654 +1,618 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
$upload_dir = wp_upload_dir();
|
7 |
-
$sec_string = md5('
|
8 |
-
$file
|
9 |
-
$file_path
|
10 |
file_put_contents($file_path . '/index.php', '');
|
11 |
-
|
12 |
-
if(!file_exists($file_path)){
|
13 |
mkdir($file_path, 0755, true);
|
14 |
}
|
15 |
parent::__construct();
|
16 |
}
|
17 |
-
|
18 |
-
function backup($args)
|
19 |
-
|
20 |
$this->_escape($args);
|
21 |
-
|
22 |
-
$password = $args[1];
|
23 |
//type like manual, weekly, daily
|
24 |
-
$type = $args[
|
25 |
//what like full, only db, only wp-content
|
26 |
-
$what = $args[
|
27 |
-
if(trim($type) == '')
|
28 |
-
$type = 'manual';
|
29 |
-
|
30 |
-
if (!$user = $this->login($username, $password))
|
31 |
-
{
|
32 |
-
return $this->error;
|
33 |
-
}
|
34 |
-
|
35 |
-
if(!current_user_can('administrator'))
|
36 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to perform backup action on this site.');
|
37 |
|
38 |
$upload_dir = wp_upload_dir();
|
39 |
-
$sec_string = md5('
|
40 |
-
$file
|
41 |
-
$file_path
|
42 |
-
|
43 |
-
if(!file_exists($file_path)){
|
44 |
mkdir($file_path, 0755, true);
|
45 |
}
|
46 |
-
|
47 |
-
if(trim($what) == 'full' || trim($what) == 'content'
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
54 |
}
|
55 |
-
|
56 |
-
if(trim($what) == 'full' || trim($what) == 'db'
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
@unlink($content_backup['path']);
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
}
|
67 |
-
require_once ABSPATH.'/wp-admin/includes/class-pclzip.php';
|
68 |
-
|
69 |
-
// Get previous backup in tmp
|
70 |
-
$worker_options = get_option('mwp-worker');
|
71 |
-
$tmp_file = $upload_dir['basedir'].'/'.basename($worker_options['backups'][$type]['path']);
|
72 |
-
|
73 |
-
if(rename($worker_options['backups'][$type]['path'], $tmp_file)){
|
74 |
-
@unlink($worker_options['backups'][$type]['path']);
|
75 |
-
}
|
76 |
|
77 |
-
|
78 |
|
79 |
-
|
|
|
|
|
80 |
|
81 |
-
|
|
|
|
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
if (
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
}
|
89 |
-
|
90 |
-
if(
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
ob_get_clean();
|
98 |
-
}
|
99 |
-
else
|
100 |
-
{
|
101 |
-
$result = $archive->add($content_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
102 |
-
$result = $archive->add($db_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
103 |
-
$err = !$result;
|
104 |
-
}
|
105 |
-
|
106 |
-
}elseif(trim($what) == 'db'){
|
107 |
-
|
108 |
-
if ($this->check_zip())
|
109 |
-
{
|
110 |
-
|
111 |
-
$command = "zip $backup_file -j $db_backup[path]";
|
112 |
-
ob_start();
|
113 |
-
passthru($command,$err);
|
114 |
-
ob_get_clean();
|
115 |
-
|
116 |
-
}
|
117 |
-
else
|
118 |
-
{
|
119 |
-
|
120 |
-
$result = $archive->add($db_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
121 |
-
$err = !$result;
|
122 |
-
}
|
123 |
-
|
124 |
-
|
125 |
-
}elseif(trim($what) == 'content'){
|
126 |
-
if ($this->check_zip())
|
127 |
-
{
|
128 |
-
$command = "zip $backup_file -j $content_backup[path]";
|
129 |
-
ob_start();
|
130 |
-
passthru($command,$err);
|
131 |
-
ob_get_clean();
|
132 |
-
}
|
133 |
-
else
|
134 |
-
{
|
135 |
-
$result = $archive->add($content_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
136 |
-
$err = !$result;
|
137 |
-
}
|
138 |
-
|
139 |
-
|
140 |
-
}
|
141 |
-
|
142 |
-
|
143 |
-
if($err){
|
144 |
-
|
145 |
-
if(rename($tmp_file,$worker_options['backups'][$type]['path'])){
|
146 |
-
@unlink($tmp_file);
|
147 |
-
}
|
148 |
-
return false;
|
149 |
}
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
@unlink($content_backup['path']);
|
154 |
@unlink($db_backup['path']);
|
155 |
-
|
156 |
-
$
|
157 |
-
$worker_options = get_option('mwp-worker');
|
158 |
-
|
159 |
//remove old file
|
160 |
-
if($worker_options['backups'][$type]['path'] != $backup_file)
|
161 |
-
|
162 |
-
|
163 |
|
164 |
$worker_options['backups'][$type]['path'] = $backup_file;
|
165 |
-
$worker_options['backups'][$type]['url']
|
166 |
-
update_option('
|
167 |
|
168 |
|
169 |
return $worker_options['backups'][$type]['url'];
|
170 |
}
|
171 |
-
|
172 |
-
function backup_wpcontent($type)
|
173 |
-
|
174 |
$upload_dir = wp_upload_dir();
|
175 |
-
$sec_string = md5('
|
176 |
-
|
177 |
-
$
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
211 |
}
|
212 |
-
|
213 |
-
|
214 |
-
function backup_db($type)
|
|
|
215 |
$mysqldump_exists = $this->check_mysqldump();
|
216 |
-
|
217 |
-
|
218 |
-
if(is_array($mysqldump_exists)){
|
219 |
-
// $this->_log('backup dump');
|
220 |
-
|
221 |
-
$result = $this->backup_db_dump($type, $mysqldump_exists);
|
222 |
-
|
223 |
-
}else{
|
224 |
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
}
|
227 |
return $result;
|
228 |
}
|
229 |
-
|
230 |
-
function backup_db_dump($type, $paths)
|
231 |
-
|
|
|
232 |
$upload_dir = wp_upload_dir();
|
233 |
-
$sec_string = md5('
|
234 |
-
|
235 |
-
|
236 |
-
$file = $upload_dir['path'] . '/'.DB_NAME.'.sql';
|
237 |
-
$file_url = $upload_dir['baseurl']. '/'.DB_NAME.'.sql';
|
238 |
|
239 |
-
|
|
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
global $wpdb;
|
256 |
-
|
257 |
-
$
|
258 |
-
$
|
259 |
-
$sec_string
|
260 |
-
$zip_file = '/'.$sec_string.'/backups/db_'.date('Y-m-d').'.zip';
|
261 |
$zip_file_path = $upload_dir['basedir'] . $zip_file;
|
262 |
|
263 |
-
$file
|
264 |
-
$file_url = $upload_dir['baseurl']. '/'.DB_NAME.'.sql';
|
265 |
|
266 |
-
|
267 |
-
// $this->_log($zip_file_path);
|
268 |
-
// $this->_log($tables);
|
269 |
-
foreach($tables as $table){
|
270 |
-
//$file = $upload_dir['path'] . '/'.$table[0].'.sql';
|
271 |
-
|
272 |
//drop exixting table
|
273 |
-
$dump_data
|
274 |
//create table
|
275 |
$create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
|
276 |
-
$dump_data .= "\n\n"
|
277 |
-
|
278 |
$count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
|
279 |
-
if($count > 100)
|
280 |
-
$count = ceil($count/100)-1;
|
281 |
else
|
282 |
$count = 1;
|
283 |
-
for($i=0
|
284 |
$low_limit = $i * 100;
|
285 |
-
$qry
|
286 |
-
$rows
|
287 |
-
if(is_array($rows)){
|
288 |
foreach ($rows as $row) {
|
289 |
//insert single row
|
290 |
$dump_data .= "INSERT INTO $table[0] VALUES(";
|
291 |
$num_values = count($row);
|
292 |
-
$j
|
293 |
foreach ($row as $value) {
|
294 |
$value = addslashes($value);
|
295 |
$value = ereg_replace("\n", "\\n", $value);
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
// $dump_data .= "'".$value . "'";
|
300 |
-
// else
|
301 |
-
// $dump_data .= "'".$value . "', ";
|
302 |
-
$num_values == $j ? $dump_data .= "'".$value . "'" : $dump_data .= "'".$value . "', ";
|
303 |
-
$j ++;
|
304 |
-
unset ($value);
|
305 |
}
|
306 |
-
// $dump_data = substr($dump_data, 0, -2);
|
307 |
$dump_data .= ");\n";
|
308 |
}
|
309 |
}
|
310 |
}
|
311 |
$dump_data .= "\n\n\n";
|
312 |
-
|
313 |
-
unset ($rows);
|
314 |
-
file_put_contents($file, $dump_data, FILE_APPEND);
|
315 |
-
unset ($dump_data);
|
316 |
|
317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
}
|
319 |
|
|
|
|
|
|
|
|
|
320 |
|
321 |
-
//return false;
|
322 |
-
return array('path' => $file, 'url' => $file_url);
|
323 |
-
|
324 |
}
|
325 |
-
|
326 |
-
function restore($args)
|
|
|
327 |
$this->_escape($args);
|
328 |
-
$
|
329 |
-
$
|
330 |
-
$type = $args[2];
|
331 |
-
|
332 |
-
if(trim($type) == ''){
|
333 |
return false;
|
334 |
}
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
if(!current_user_can('administrator'))
|
342 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to perform restore action on this site.');
|
343 |
-
|
344 |
-
// Set paths
|
345 |
-
|
346 |
-
$upload_dir = wp_upload_dir();
|
347 |
-
$sec_string = md5('mwp-worker');
|
348 |
-
$backup_dir = "/$sec_string/backups";
|
349 |
-
$file = "/$sec_string/restore";
|
350 |
-
$file_path = $upload_dir['basedir'] . $file; //restore path - temporary
|
351 |
$backup_path = $upload_dir['basedir'] . $backup_dir; //backup path
|
352 |
-
|
353 |
|
354 |
// If manual backup - get backup file from master, if not - get backup file from worker
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
if(rename($tmp_file, $backup_file)){
|
365 |
-
@unlink($tmp_file);
|
366 |
-
}else{
|
367 |
-
$backup_file = $tmp_file;
|
368 |
-
}
|
369 |
-
}
|
370 |
-
else
|
371 |
-
{
|
372 |
-
// Getting file from worker
|
373 |
-
$backup_file = $worker_options['backups'][$type]['path'];
|
374 |
-
}
|
375 |
|
|
|
|
|
|
|
|
|
376 |
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
require_once ABSPATH.'/wp-admin/includes/class-pclzip.php';
|
393 |
-
$archive = new PclZip($backup_file);
|
394 |
-
$extracted = $archive->extract(PCLZIP_OPT_PATH, $file_path, PCLZIP_OPT_REMOVE_ALL_PATH);
|
395 |
-
$err = !$extracted;
|
396 |
-
}
|
397 |
|
398 |
|
399 |
-
if($err){
|
400 |
-
|
401 |
-
|
|
|
402 |
}
|
403 |
|
404 |
list(, $name, $what) = explode('_', basename($backup_file, '.zip'));
|
405 |
-
|
406 |
-
$this->_log($what);
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
}
|
415 |
|
416 |
|
417 |
|
418 |
-
if(trim($what) == 'full' || trim($what) == 'content'
|
419 |
-
|
420 |
-
|
421 |
-
|
|
|
|
|
422 |
}
|
423 |
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
$this->_deleteTempDir($file_path);
|
428 |
}
|
429 |
-
//@lk : better error messages
|
430 |
-
return true;
|
431 |
|
|
|
432 |
}
|
433 |
-
|
434 |
-
function restore_wpcontent($type, $file_path)
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
{
|
442 |
-
|
443 |
chdir(WP_CONTENT_DIR);
|
444 |
$con_file = $content_file[0];
|
445 |
-
|
446 |
ob_start();
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
$archive = new PclZip($content_file[0]);
|
454 |
-
$restore_content = $archive->extract(PCLZIP_OPT_PATH, WP_CONTENT_DIR, PCLZIP_OPT_REPLACE_NEWER);
|
455 |
-
$err = !$restore_content;
|
456 |
}
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
else
|
462 |
-
return
|
463 |
}
|
464 |
-
|
465 |
-
function restore_db($type, $file_path)
|
|
|
466 |
global $wpdb;
|
467 |
|
468 |
$mysqldump = $this->check_mysqldump();
|
469 |
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
// Temporary variable, used to store current query
|
494 |
$current_query = '';
|
495 |
// Read in entire file
|
496 |
-
$lines
|
497 |
-
// $this->_log($lines);
|
498 |
// Loop through each line
|
499 |
-
foreach ($lines as $line){
|
500 |
// Skip it if it's a comment
|
501 |
if (substr($line, 0, 2) == '--' || $line == '')
|
502 |
continue;
|
503 |
-
|
504 |
// Add this line to the current query
|
505 |
$current_query .= $line;
|
506 |
// If it has a semicolon at the end, it's the end of the query
|
507 |
-
if (substr(trim($line), -1, 1) == ';'){
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
// Reset temp variable to empty
|
515 |
-
$current_query = '';
|
516 |
}
|
517 |
}
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
}
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
}
|
527 |
-
|
528 |
-
|
|
|
|
|
529 |
$this->_escape($args);
|
530 |
$username = $args[0];
|
531 |
-
$
|
532 |
-
$type
|
533 |
-
if(trim($type) == ''){
|
534 |
return false;
|
535 |
}
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
540 |
}
|
541 |
-
|
542 |
-
if(
|
543 |
-
return
|
544 |
-
|
545 |
-
$worker_options = get_option('mwp-worker');
|
546 |
-
$daily_file = $worker_options['backups']['daily']['path'];
|
547 |
-
|
548 |
-
$upload_dir = wp_upload_dir();
|
549 |
-
$sec_string = md5('mwp-worker');
|
550 |
-
$file = "/$sec_string/backups";
|
551 |
-
$file_path = $upload_dir['basedir'] . $file;
|
552 |
-
$backup_file = $file_path.'/weekly_'.date('Y-m-d').'.zip';
|
553 |
-
|
554 |
-
if(!copy($daily_file, $backup_file)){
|
555 |
-
return false;
|
556 |
}
|
557 |
-
|
558 |
-
$worker_options['backups']['weekly']['path'] = $backup_file;
|
559 |
-
$worker_options['backups']['weekly']['url'] = $backup_url;
|
560 |
-
|
561 |
-
return $backup_url;
|
562 |
-
|
563 |
-
}
|
564 |
-
|
565 |
-
function get_backup_details($args) {
|
566 |
-
$this->_escape($args);
|
567 |
-
$username = $args[0];
|
568 |
-
$password = $args[1];
|
569 |
-
$type = $args[2];
|
570 |
-
if(trim($type) == ''){
|
571 |
return false;
|
572 |
}
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
|
|
577 |
}
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
$backup_file = $worker_options['backups'][$type]['url'];
|
584 |
-
|
585 |
-
if(!$backup_file)
|
586 |
-
return FALSE;
|
587 |
-
else
|
588 |
-
return $backup_file;
|
589 |
-
}
|
590 |
-
|
591 |
-
### Function: Auto Detect MYSQL and MYSQL Dump Paths
|
592 |
-
function check_mysqldump() {
|
593 |
-
global $wpdb;
|
594 |
-
$paths = array('mysq' => '', 'mysqldump' => '');
|
595 |
-
if(substr(PHP_OS,0,3) == 'WIN') {
|
596 |
-
$mysql_install = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
|
597 |
-
if($mysql_install) {
|
598 |
-
$install_path = str_replace('\\', '/', $mysql_install->Value);
|
599 |
-
$paths['mysql'] = $install_path.'bin/mysql.exe';
|
600 |
-
$paths['mysqldump'] = $install_path.'bin/mysqldump.exe';
|
601 |
-
} else {
|
602 |
-
$paths['mysql'] = 'mysql.exe';
|
603 |
-
$paths['mysqldump'] = 'mysqldump.exe';
|
604 |
-
}
|
605 |
-
} else {
|
606 |
-
if(function_exists('exec')) {
|
607 |
-
$paths['mysql'] = @exec('which mysql');
|
608 |
-
$paths['mysqldump'] = @exec('which mysqldump');
|
609 |
-
} else {
|
610 |
-
$paths['mysql'] = 'mysql';
|
611 |
-
$paths['mysqldump'] = 'mysqldump';
|
612 |
-
}
|
613 |
-
}
|
614 |
-
|
615 |
-
if(!@file_exists(stripslashes($paths['mysqldump']))) {
|
616 |
-
return false;
|
617 |
-
}
|
618 |
-
if(!@file_exists(stripslashes($paths['mysql']))) {
|
619 |
-
return false;
|
620 |
-
}
|
621 |
-
|
622 |
-
$stats_function_disabled = 0;
|
623 |
-
|
624 |
-
if(!function_exists('passthru')) {
|
625 |
-
$stats_function_disabled++;
|
626 |
-
}
|
627 |
-
if(!function_exists('system')) {
|
628 |
-
$stats_function_disabled++;
|
629 |
-
}
|
630 |
-
if(!function_exists('exec')) {
|
631 |
-
$stats_function_disabled++;
|
632 |
-
}
|
633 |
-
|
634 |
-
if($stats_function_disabled == 3){
|
635 |
-
return false;
|
636 |
-
}
|
637 |
-
|
638 |
-
return $paths;
|
639 |
}
|
640 |
|
641 |
-
|
642 |
-
|
643 |
-
$zip = @exec('which zip');
|
644 |
-
return $zip ? true : false;
|
645 |
}
|
646 |
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
}
|
652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
653 |
}
|
654 |
?>
|
1 |
<?php
|
2 |
+
/*************************************************************
|
3 |
+
*
|
4 |
+
* backup.class.php
|
5 |
+
*
|
6 |
+
* Manage Backups
|
7 |
+
*
|
8 |
+
*
|
9 |
+
* Copyright (c) 2011 Prelovac Media
|
10 |
+
* www.prelovac.com
|
11 |
+
**************************************************************/
|
12 |
+
|
13 |
+
class MMB_Backup extends MMB_Core
|
14 |
+
{
|
15 |
+
function __construct()
|
16 |
+
{
|
17 |
$upload_dir = wp_upload_dir();
|
18 |
+
$sec_string = md5('mmb-worker');
|
19 |
+
$file = "/$sec_string/backups";
|
20 |
+
$file_path = $upload_dir['basedir'] . $file;
|
21 |
file_put_contents($file_path . '/index.php', '');
|
22 |
+
if (!file_exists($file_path)) {
|
|
|
23 |
mkdir($file_path, 0755, true);
|
24 |
}
|
25 |
parent::__construct();
|
26 |
}
|
27 |
+
|
28 |
+
function backup($args)
|
29 |
+
{
|
30 |
$this->_escape($args);
|
31 |
+
|
|
|
32 |
//type like manual, weekly, daily
|
33 |
+
$type = $args['type'];
|
34 |
//what like full, only db, only wp-content
|
35 |
+
$what = $args['what'];
|
36 |
+
if (trim($type) == '')
|
37 |
+
$type = 'manual'; //default
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
$upload_dir = wp_upload_dir();
|
40 |
+
$sec_string = md5('mmb-worker');
|
41 |
+
$file = "/$sec_string/backups";
|
42 |
+
$file_path = $upload_dir['basedir'] . $file;
|
43 |
+
|
44 |
+
if (!file_exists($file_path)) {
|
45 |
mkdir($file_path, 0755, true);
|
46 |
}
|
47 |
+
|
48 |
+
if (trim($what) == 'full' || trim($what) == 'content') {
|
49 |
+
//take wp-conetnt backup
|
50 |
+
$content_backup = $this->backup_wpcontent($type);
|
51 |
+
if (!$content_backup) {
|
52 |
+
@unlink($content_backup['path']);
|
53 |
+
return array(
|
54 |
+
'error' => 'Failed to backup wp-content.'
|
55 |
+
);
|
56 |
+
}
|
57 |
}
|
58 |
+
|
59 |
+
if (trim($what) == 'full' || trim($what) == 'db') {
|
60 |
+
//take batabase backup
|
61 |
+
$db_backup = $this->backup_db($type);
|
62 |
+
if (!$db_backup) {
|
63 |
+
if (trim($what) == 'full')
|
64 |
@unlink($content_backup['path']);
|
65 |
+
|
66 |
+
@unlink($db_backup['path']);
|
67 |
+
return array(
|
68 |
+
'error' => 'Failed to backup database.'
|
69 |
+
);
|
70 |
+
}
|
71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
74 |
|
75 |
+
// Get previous backup in tmp
|
76 |
+
$worker_options = get_option('mmb-worker');
|
77 |
+
$tmp_file = $upload_dir['basedir'] . '/' . basename($worker_options['backups'][$type]['path']);
|
78 |
|
79 |
+
if (rename($worker_options['backups'][$type]['path'], $tmp_file)) {
|
80 |
+
@unlink($worker_options['backups'][$type]['path']);
|
81 |
+
}
|
82 |
|
83 |
+
$site_name = $this->remove_http(get_bloginfo('url'));
|
84 |
+
$site_name = str_replace(array(
|
85 |
+
"_",
|
86 |
+
"/"
|
87 |
+
), array(
|
88 |
+
"",
|
89 |
+
"-"
|
90 |
+
), $site_name);
|
91 |
+
$backup_file = $file_path . '/' . $site_name . '_' . $type . '_' . $what . '_' . date('Y-m-d') . '.zip';
|
92 |
+
|
93 |
+
if (!$this->check_zip()) {
|
94 |
+
$archive = new PclZip($backup_file);
|
95 |
+
}
|
96 |
|
97 |
+
if (trim($what) == 'full') {
|
98 |
+
$htaccess_path = ABSPATH . ".htaccess";
|
99 |
+
$wp_config_path = ABSPATH . "wp-config.php";
|
100 |
+
if ($this->check_zip()) {
|
101 |
+
$command = "zip $backup_file -j $content_backup[path] -j $db_backup[path] -j $htaccess_path -j $wp_config_path";
|
102 |
+
ob_start();
|
103 |
+
passthru($command, $err);
|
104 |
+
ob_get_clean();
|
105 |
+
} else {
|
106 |
+
$result = $archive->add($content_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
107 |
+
$result = $archive->add($db_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
108 |
+
$result = $archive->add($htaccess_path, PCLZIP_OPT_REMOVE_ALL_PATH);
|
109 |
+
$result = $archive->add($wp_config_path, PCLZIP_OPT_REMOVE_ALL_PATH);
|
110 |
+
$err = !$result;
|
111 |
+
}
|
112 |
+
|
113 |
+
} elseif (trim($what) == 'db') {
|
114 |
+
if ($this->check_zip()) {
|
115 |
+
$command = "zip $backup_file -j $db_backup[path]";
|
116 |
+
ob_start();
|
117 |
+
passthru($command, $err);
|
118 |
+
ob_get_clean();
|
119 |
+
} else {
|
120 |
+
$result = $archive->add($db_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
121 |
+
$err = !$result;
|
122 |
+
}
|
123 |
+
} elseif (trim($what) == 'content') {
|
124 |
+
if ($this->check_zip()) {
|
125 |
+
$command = "zip $backup_file -j $content_backup[path]";
|
126 |
+
ob_start();
|
127 |
+
passthru($command, $err);
|
128 |
+
ob_get_clean();
|
129 |
+
} else {
|
130 |
+
$result = $archive->add($content_backup['path'], PCLZIP_OPT_REMOVE_ALL_PATH);
|
131 |
+
$err = !$result;
|
132 |
+
}
|
133 |
}
|
134 |
+
|
135 |
+
if ($err) {
|
136 |
+
if (rename($tmp_file, $worker_options['backups'][$type]['path'])) {
|
137 |
+
@unlink($tmp_file);
|
138 |
+
}
|
139 |
+
return array(
|
140 |
+
'error' => 'Backup failed.'
|
141 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
}
|
143 |
+
|
144 |
+
@unlink($tmp_file);
|
|
|
145 |
@unlink($content_backup['path']);
|
146 |
@unlink($db_backup['path']);
|
147 |
+
$backup_url = $upload_dir['baseurl'] . $file . '/' . $site_name . '_' . $type . '_' . $what . '_' . date('Y-m-d') . '.zip';
|
148 |
+
$worker_options = get_option('mmb-worker');
|
|
|
|
|
149 |
//remove old file
|
150 |
+
if ($worker_options['backups'][$type]['path'] != $backup_file) {
|
151 |
+
@unlink($worker_options['backups'][$type]['path']);
|
152 |
+
}
|
153 |
|
154 |
$worker_options['backups'][$type]['path'] = $backup_file;
|
155 |
+
$worker_options['backups'][$type]['url'] = $backup_url;
|
156 |
+
update_option('mmb-worker', $worker_options);
|
157 |
|
158 |
|
159 |
return $worker_options['backups'][$type]['url'];
|
160 |
}
|
161 |
+
|
162 |
+
function backup_wpcontent($type)
|
163 |
+
{
|
164 |
$upload_dir = wp_upload_dir();
|
165 |
+
$sec_string = md5('mmb-worker');
|
166 |
+
$file = '/' . $sec_string . '/backups/wp-content_' . date('Y-m-d') . '.zip';
|
167 |
+
$file_path = $upload_dir['basedir'] . $file;
|
168 |
+
if ($this->check_zip()) {
|
169 |
+
chdir(WP_CONTENT_DIR);
|
170 |
+
$command = "zip -r $file_path 'plugins/' 'themes/' 'uploads/' -x 'uploads/" . $sec_string . "/*'";
|
171 |
+
ob_start();
|
172 |
+
passthru($command, $err);
|
173 |
+
ob_get_clean();
|
174 |
+
if (!$err || $err == 18) {
|
175 |
+
$file_url = $upload_dir['baseurl'] . $file;
|
176 |
+
return array(
|
177 |
+
'path' => $file_path,
|
178 |
+
'url' => $file_url
|
179 |
+
);
|
180 |
+
}
|
181 |
+
@unlink($file_path);
|
182 |
+
return false;
|
183 |
+
|
184 |
+
} else {
|
185 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
186 |
+
$archive = new PclZip($file_path);
|
187 |
+
$result = $archive->add(WP_CONTENT_DIR . '/plugins', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
|
188 |
+
$result = $archive->add(WP_CONTENT_DIR . '/themes', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
|
189 |
+
$result = $archive->add(WP_CONTENT_DIR . '/uploads', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
|
190 |
+
// $this->_log($archive);
|
191 |
+
$result = $archive->delete(PCLZIP_OPT_BY_NAME, 'uploads/' . $sec_string . '/');
|
192 |
+
if ($result) {
|
193 |
+
$file_url = $upload_dir['baseurl'] . $file;
|
194 |
+
return array(
|
195 |
+
'path' => $file_path,
|
196 |
+
'url' => $file_url
|
197 |
+
);
|
198 |
+
}
|
199 |
+
@unlink($file_path);
|
200 |
+
return false;
|
201 |
+
}
|
202 |
}
|
203 |
+
|
204 |
+
|
205 |
+
function backup_db($type)
|
206 |
+
{
|
207 |
$mysqldump_exists = $this->check_mysqldump();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
|
210 |
+
if (is_array($mysqldump_exists)) {
|
211 |
+
// $this->_log('backup dump');
|
212 |
+
|
213 |
+
$result = $this->backup_db_dump($type, $mysqldump_exists);
|
214 |
+
|
215 |
+
} else {
|
216 |
+
$result = $this->backup_db_php($type);
|
217 |
+
|
218 |
}
|
219 |
return $result;
|
220 |
}
|
221 |
+
|
222 |
+
function backup_db_dump($type, $paths)
|
223 |
+
{
|
224 |
+
global $wpdb;
|
225 |
$upload_dir = wp_upload_dir();
|
226 |
+
$sec_string = md5('mmb-worker');
|
227 |
+
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
|
|
|
|
|
|
|
228 |
|
229 |
+
$file = $upload_dir['path'] . '/' . DB_NAME . '.sql';
|
230 |
+
$file_url = $upload_dir['baseurl'] . '/' . DB_NAME . '.sql';
|
231 |
|
232 |
+
$command = $brace . $paths['mysqldump'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
|
233 |
+
|
234 |
+
|
235 |
+
passthru($command, $error);
|
236 |
+
|
237 |
+
if ($error) {
|
238 |
+
$result = $this->backup_db_php($type);
|
239 |
+
return $result;
|
240 |
+
}
|
241 |
+
|
242 |
+
if (filesize($file) == 0 || !is_file($file) || $error) {
|
243 |
+
@unlink($file);
|
244 |
+
return false;
|
245 |
+
} else {
|
246 |
+
return array(
|
247 |
+
'path' => $file,
|
248 |
+
'url' => $file_url
|
249 |
+
);
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
function backup_db_php($type)
|
254 |
+
{
|
255 |
global $wpdb;
|
256 |
+
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
|
257 |
+
$upload_dir = wp_upload_dir();
|
258 |
+
$sec_string = md5('mmb-worker');
|
259 |
+
$zip_file = '/' . $sec_string . '/backups/db_' . date('Y-m-d') . '.zip';
|
|
|
260 |
$zip_file_path = $upload_dir['basedir'] . $zip_file;
|
261 |
|
262 |
+
$file = $upload_dir['path'] . '/' . DB_NAME . '.sql';
|
263 |
+
$file_url = $upload_dir['baseurl'] . '/' . DB_NAME . '.sql';
|
264 |
|
265 |
+
foreach ($tables as $table) {
|
|
|
|
|
|
|
|
|
|
|
266 |
//drop exixting table
|
267 |
+
$dump_data = "DROP TABLE IF EXISTS $table[0];";
|
268 |
//create table
|
269 |
$create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
|
270 |
+
$dump_data .= "\n\n" . $create_table[1] . ";\n\n";
|
271 |
+
|
272 |
$count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
|
273 |
+
if ($count > 100)
|
274 |
+
$count = ceil($count / 100) - 1;
|
275 |
else
|
276 |
$count = 1;
|
277 |
+
for ($i = 0; $i < $count; $i++) {
|
278 |
$low_limit = $i * 100;
|
279 |
+
$qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
|
280 |
+
$rows = $wpdb->get_results($qry, ARRAY_A);
|
281 |
+
if (is_array($rows)) {
|
282 |
foreach ($rows as $row) {
|
283 |
//insert single row
|
284 |
$dump_data .= "INSERT INTO $table[0] VALUES(";
|
285 |
$num_values = count($row);
|
286 |
+
$j = 1;
|
287 |
foreach ($row as $value) {
|
288 |
$value = addslashes($value);
|
289 |
$value = ereg_replace("\n", "\\n", $value);
|
290 |
+
$num_values == $j ? $dump_data .= "'" . $value . "'" : $dump_data .= "'" . $value . "', ";
|
291 |
+
$j++;
|
292 |
+
unset($value);
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
}
|
|
|
294 |
$dump_data .= ");\n";
|
295 |
}
|
296 |
}
|
297 |
}
|
298 |
$dump_data .= "\n\n\n";
|
|
|
|
|
|
|
|
|
299 |
|
300 |
+
unset($rows);
|
301 |
+
file_put_contents($file, $dump_data, FILE_APPEND);
|
302 |
+
unset($dump_data);
|
303 |
+
}
|
304 |
+
if (filesize($file) == 0 || !is_file($file)) {
|
305 |
+
@unlink($file);
|
306 |
+
return false;
|
307 |
}
|
308 |
|
309 |
+
return array(
|
310 |
+
'path' => $file,
|
311 |
+
'url' => $file_url
|
312 |
+
);
|
313 |
|
|
|
|
|
|
|
314 |
}
|
315 |
+
|
316 |
+
function restore($args)
|
317 |
+
{
|
318 |
$this->_escape($args);
|
319 |
+
$type = $args['type'];
|
320 |
+
if (trim($type) == '') {
|
|
|
|
|
|
|
321 |
return false;
|
322 |
}
|
323 |
+
// Set paths
|
324 |
+
$upload_dir = wp_upload_dir();
|
325 |
+
$sec_string = md5('mmb-worker');
|
326 |
+
$backup_dir = "/$sec_string/backups";
|
327 |
+
$file = "/$sec_string/restore";
|
328 |
+
$file_path = $upload_dir['basedir'] . $file; //restore path - temporary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
$backup_path = $upload_dir['basedir'] . $backup_dir; //backup path
|
|
|
330 |
|
331 |
// If manual backup - get backup file from master, if not - get backup file from worker
|
332 |
+
if ($type != 'weekly' && $type != 'daily') {
|
333 |
+
// Download backup file from master
|
334 |
+
$tmp_file = $this->mmb_download_url($type, $upload_dir['basedir'] . '/restore' . md5(time()) . '.tmp');
|
335 |
+
$backup_file = $backup_path . "/" . basename($type);
|
336 |
+
if (rename($tmp_file, $backup_file)) {
|
337 |
+
@unlink($tmp_file);
|
338 |
+
} else {
|
339 |
+
$backup_file = $tmp_file;
|
340 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
|
342 |
+
} else {
|
343 |
+
// Getting file from worker
|
344 |
+
$backup_file = $worker_options['backups'][$type]['path'];
|
345 |
+
}
|
346 |
|
347 |
+
|
348 |
+
if ($backup_file) {
|
349 |
+
if ($this->check_unzip()) {
|
350 |
+
mkdir($file_path);
|
351 |
+
chdir($file_path);
|
352 |
+
$command = "unzip -o $backup_file";
|
353 |
+
ob_start();
|
354 |
+
passthru($command, $err);
|
355 |
+
ob_get_clean();
|
356 |
+
} else {
|
357 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
358 |
+
$archive = new PclZip($backup_file);
|
359 |
+
$extracted = $archive->extract(PCLZIP_OPT_PATH, $file_path, PCLZIP_OPT_REMOVE_ALL_PATH);
|
360 |
+
$err = !$extracted;
|
361 |
+
}
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
|
364 |
+
if ($err) {
|
365 |
+
return array(
|
366 |
+
'error' => 'Error extracting backup file.'
|
367 |
+
);
|
368 |
}
|
369 |
|
370 |
list(, $name, $what) = explode('_', basename($backup_file, '.zip'));
|
|
|
|
|
371 |
|
372 |
+
if (trim($what) == 'full' || trim($what) == 'db') {
|
373 |
+
if (!$this->restore_db($type, $file_path)) {
|
374 |
+
return array(
|
375 |
+
'error' => 'Error restoring database.'
|
376 |
+
);
|
377 |
+
}
|
378 |
}
|
379 |
|
380 |
|
381 |
|
382 |
+
if (trim($what) == 'full' || trim($what) == 'content') {
|
383 |
+
if (!$this->restore_wpcontent($type, $file_path)) {
|
384 |
+
return array(
|
385 |
+
'error' => 'Error restoring wp-content.'
|
386 |
+
);
|
387 |
+
}
|
388 |
}
|
389 |
|
|
|
|
|
|
|
390 |
$this->_deleteTempDir($file_path);
|
391 |
}
|
|
|
|
|
392 |
|
393 |
+
return true;
|
394 |
}
|
395 |
+
|
396 |
+
function restore_wpcontent($type, $file_path)
|
397 |
+
{
|
398 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
399 |
+
$content_file = glob($file_path . "/*.zip");
|
400 |
+
$wp_config_file = glob($file_path . "/wp-config.php");
|
401 |
+
$htaccess_file = glob($file_path . "/.htaccess");
|
402 |
+
if ($this->check_unzip()) {
|
|
|
|
|
403 |
chdir(WP_CONTENT_DIR);
|
404 |
$con_file = $content_file[0];
|
405 |
+
$command = "unzip -o $con_file";
|
406 |
ob_start();
|
407 |
+
passthru($command, $err);
|
408 |
+
ob_get_clean();
|
409 |
+
} else {
|
410 |
+
$archive = new PclZip($content_file[0]);
|
411 |
+
$restore_content = $archive->extract(PCLZIP_OPT_PATH, WP_CONTENT_DIR, PCLZIP_OPT_REPLACE_NEWER);
|
412 |
+
$err = !$restore_content;
|
|
|
|
|
|
|
413 |
}
|
414 |
+
|
415 |
+
if (!rename($wp_config_file[0], ABSPATH . "wp-config.php"))
|
416 |
+
$err = 1;
|
417 |
+
if (!rename($htaccess_file[0], ABSPATH . ".htaccess"))
|
418 |
+
$err = 1;
|
419 |
+
|
420 |
+
@unlink($wp_config_file[0]);
|
421 |
+
@unlink($htaccess_file[0]);
|
422 |
+
|
423 |
+
if ($err)
|
424 |
+
return false;
|
425 |
else
|
426 |
+
return true;
|
427 |
}
|
428 |
+
|
429 |
+
function restore_db($type, $file_path)
|
430 |
+
{
|
431 |
global $wpdb;
|
432 |
|
433 |
$mysqldump = $this->check_mysqldump();
|
434 |
|
435 |
+
if (is_array($mysqldump)) {
|
436 |
+
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
|
437 |
+
|
438 |
+
foreach (glob($file_path . '/*.sql') as $filename) {
|
439 |
+
$command = $brace . $mysqldump['mysql'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" ' . DB_NAME . ' < ' . $brace . $filename . $brace;
|
440 |
+
passthru($command, $error);
|
441 |
+
|
442 |
+
break;
|
443 |
+
}
|
444 |
+
|
445 |
+
if ($error) //try php
|
446 |
+
{
|
447 |
+
foreach (glob($file_path . '/*.sql') as $filename) {
|
448 |
+
$current_query = '';
|
449 |
+
// Read in entire file
|
450 |
+
$lines = file($filename);
|
451 |
+
// Loop through each line
|
452 |
+
foreach ($lines as $line) {
|
453 |
+
// Skip it if it's a comment
|
454 |
+
if (substr($line, 0, 2) == '--' || $line == '')
|
455 |
+
continue;
|
456 |
+
|
457 |
+
// Add this line to the current query
|
458 |
+
$current_query .= $line;
|
459 |
+
// If it has a semicolon at the end, it's the end of the query
|
460 |
+
if (substr(trim($line), -1, 1) == ';') {
|
461 |
+
// Perform the query
|
462 |
+
$result = $wpdb->query($current_query);
|
463 |
+
if ($result === false)
|
464 |
+
return FALSE;
|
465 |
+
// Reset temp variable to empty
|
466 |
+
$current_query = '';
|
467 |
+
}
|
468 |
+
}
|
469 |
+
}
|
470 |
+
return true;
|
471 |
+
} else {
|
472 |
+
return true;
|
473 |
+
}
|
474 |
+
|
475 |
+
} else {
|
476 |
+
foreach (glob($file_path . '/*.sql') as $filename) {
|
477 |
// Temporary variable, used to store current query
|
478 |
$current_query = '';
|
479 |
// Read in entire file
|
480 |
+
$lines = file($filename);
|
|
|
481 |
// Loop through each line
|
482 |
+
foreach ($lines as $line) {
|
483 |
// Skip it if it's a comment
|
484 |
if (substr($line, 0, 2) == '--' || $line == '')
|
485 |
continue;
|
486 |
+
|
487 |
// Add this line to the current query
|
488 |
$current_query .= $line;
|
489 |
// If it has a semicolon at the end, it's the end of the query
|
490 |
+
if (substr(trim($line), -1, 1) == ';') {
|
491 |
+
// Perform the query
|
492 |
+
$result = $wpdb->query($current_query);
|
493 |
+
if ($result === false)
|
494 |
+
return FALSE;
|
495 |
+
// Reset temp variable to empty
|
496 |
+
$current_query = '';
|
|
|
|
|
497 |
}
|
498 |
}
|
499 |
+
}
|
500 |
+
return true;
|
501 |
+
}
|
|
|
|
|
|
|
|
|
|
|
502 |
}
|
503 |
+
|
504 |
+
|
505 |
+
function get_backup_details($args)
|
506 |
+
{
|
507 |
$this->_escape($args);
|
508 |
$username = $args[0];
|
509 |
+
$type = $args[2];
|
510 |
+
if (trim($type) == '') {
|
|
|
511 |
return false;
|
512 |
}
|
513 |
+
|
514 |
+
$worker_options = get_option('mmb-worker');
|
515 |
+
$backup_file = $worker_options['backups'][$type]['url'];
|
516 |
+
|
517 |
+
if (!$backup_file)
|
518 |
+
return FALSE;
|
519 |
+
else
|
520 |
+
return $backup_file;
|
521 |
+
}
|
522 |
+
|
523 |
+
### Function: Auto Detect MYSQL and MYSQL Dump Paths
|
524 |
+
function check_mysqldump()
|
525 |
+
{
|
526 |
+
global $wpdb;
|
527 |
+
$paths = array(
|
528 |
+
'mysq' => '',
|
529 |
+
'mysqldump' => ''
|
530 |
+
);
|
531 |
+
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
532 |
+
$mysql_install = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
|
533 |
+
if ($mysql_install) {
|
534 |
+
$install_path = str_replace('\\', '/', $mysql_install->Value);
|
535 |
+
$paths['mysql'] = $install_path . 'bin/mysql.exe';
|
536 |
+
$paths['mysqldump'] = $install_path . 'bin/mysqldump.exe';
|
537 |
+
} else {
|
538 |
+
$paths['mysql'] = 'mysql.exe';
|
539 |
+
$paths['mysqldump'] = 'mysqldump.exe';
|
540 |
+
}
|
541 |
+
} else {
|
542 |
+
if (function_exists('exec')) {
|
543 |
+
$paths['mysql'] = @exec('which mysql');
|
544 |
+
$paths['mysqldump'] = @exec('which mysqldump');
|
545 |
+
} else {
|
546 |
+
$paths['mysql'] = 'mysql';
|
547 |
+
$paths['mysqldump'] = 'mysqldump';
|
548 |
+
}
|
549 |
}
|
550 |
+
|
551 |
+
if (!@file_exists(stripslashes($paths['mysqldump']))) {
|
552 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
}
|
554 |
+
if (!@file_exists(stripslashes($paths['mysql']))) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
return false;
|
556 |
}
|
557 |
+
|
558 |
+
$stats_function_disabled = 0;
|
559 |
+
|
560 |
+
if (!function_exists('passthru')) {
|
561 |
+
$stats_function_disabled++;
|
562 |
}
|
563 |
+
if (!function_exists('system')) {
|
564 |
+
$stats_function_disabled++;
|
565 |
+
}
|
566 |
+
if (!function_exists('exec')) {
|
567 |
+
$stats_function_disabled++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
568 |
}
|
569 |
|
570 |
+
if ($stats_function_disabled == 3) {
|
571 |
+
return false;
|
|
|
|
|
572 |
}
|
573 |
|
574 |
+
return $paths;
|
575 |
+
}
|
576 |
+
|
577 |
+
function check_zip()
|
578 |
+
{
|
579 |
+
$zip = @exec('which zip');
|
580 |
+
return $zip ? true : false;
|
581 |
+
}
|
582 |
+
|
583 |
+
function check_unzip()
|
584 |
+
{
|
585 |
+
$zip = @exec('which unzip');
|
586 |
+
return $zip ? true : false;
|
587 |
+
}
|
588 |
+
|
589 |
+
|
590 |
+
function mmb_download_url($url, $file_name)
|
591 |
+
{
|
592 |
+
$destination = fopen($file_name, 'wb');
|
593 |
+
$source = @fopen($url, "r");
|
594 |
+
|
595 |
+
while ($a = fread($source, 1024)) {
|
596 |
+
$ret = fwrite($destination, $a);
|
597 |
}
|
598 |
+
|
599 |
+
fclose($source);
|
600 |
+
fclose($destination);
|
601 |
+
return $file_name;
|
602 |
+
}
|
603 |
+
|
604 |
+
function optimize_tables()
|
605 |
+
{
|
606 |
+
global $wpdb;
|
607 |
+
$tables = $wpdb->get_col("SHOW TABLES");
|
608 |
+
|
609 |
+
foreach ($tables as $table_name) {
|
610 |
+
$table_string .= $table_name . ",";
|
611 |
+
}
|
612 |
+
$table_string = rtrim($table_string);
|
613 |
+
$optimize = $wpdb->query("OPTIMIZE TABLE $table_string");
|
614 |
+
return true;
|
615 |
+
}
|
616 |
+
|
617 |
}
|
618 |
?>
|
category.class.php
DELETED
@@ -1,118 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mmb_Category extends Mmb_Core
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
/*************************************************************
|
11 |
-
* FACADE functions
|
12 |
-
* (functions to be called after a remote XMLRPC from Master)
|
13 |
-
**************************************************************/
|
14 |
-
/**
|
15 |
-
* Gets a list of local (slave) category
|
16 |
-
*
|
17 |
-
* @param mixed $args
|
18 |
-
* @return mixed
|
19 |
-
*/
|
20 |
-
function get_list($args)
|
21 |
-
{
|
22 |
-
$this->_escape($args);
|
23 |
-
$username = $args[0];
|
24 |
-
$password = $args[1];
|
25 |
-
$offset = $args[2];
|
26 |
-
$per_page = $args[3];
|
27 |
-
|
28 |
-
if (!$user = $this->login($username, $password))
|
29 |
-
{
|
30 |
-
return $this->error;
|
31 |
-
}
|
32 |
-
|
33 |
-
$count = count(get_categories(array('hide_empty' => FALSE)));
|
34 |
-
$categories= get_categories(array(
|
35 |
-
'offset' => $offset,
|
36 |
-
'number' => $per_page,
|
37 |
-
'hide_empty' => FALSE
|
38 |
-
));
|
39 |
-
|
40 |
-
$cat_dropdown = wp_dropdown_categories(array('echo' => false, 'hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'category_parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None')));
|
41 |
-
|
42 |
-
if(!current_user_can('manage_categories'))
|
43 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
44 |
-
|
45 |
-
return array('categories' => $categories, 'count' => $count,'dropdown' => $cat_dropdown);
|
46 |
-
|
47 |
-
//return get_categories(array('hide_empty' => FALSE));
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Updates a category locally
|
52 |
-
*
|
53 |
-
* @param mixed $args
|
54 |
-
*/
|
55 |
-
function update($args)
|
56 |
-
{
|
57 |
-
$this->_escape($args);
|
58 |
-
$username = $args[0];
|
59 |
-
$password = $args[1];
|
60 |
-
$id = $args[2];
|
61 |
-
$name = $args[3];
|
62 |
-
$slug = $args[4];
|
63 |
-
$description = $args[5];
|
64 |
-
$parent = $args[6];
|
65 |
-
|
66 |
-
if (!$user = $this->login($username, $password))
|
67 |
-
{
|
68 |
-
return $this->error;
|
69 |
-
}
|
70 |
-
|
71 |
-
if(!current_user_can('manage_categories'))
|
72 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
73 |
-
|
74 |
-
$is_success = wp_update_category(array(
|
75 |
-
'cat_ID' => $id,
|
76 |
-
'category_description' => $description,
|
77 |
-
'cat_name' => $name,
|
78 |
-
'category_nicename' => $slug,
|
79 |
-
'category_parent' => $parent,
|
80 |
-
));
|
81 |
-
|
82 |
-
if(!$is_success)
|
83 |
-
return new IXR_Error(401, 'Error Updating Category. Try Again !!!');
|
84 |
-
else
|
85 |
-
return TRUE;
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* Adds a new category locally
|
90 |
-
*
|
91 |
-
* @param mixed $args
|
92 |
-
*/
|
93 |
-
function add($args)
|
94 |
-
{
|
95 |
-
$this->_escape($args);
|
96 |
-
$username = $args[0];
|
97 |
-
$password = $args[1];
|
98 |
-
$params = $args[2];
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
if (!$user = $this->login($username, $password))
|
103 |
-
{
|
104 |
-
return $this->error;
|
105 |
-
}
|
106 |
-
|
107 |
-
if(!current_user_can('manage_categories'))
|
108 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
109 |
-
|
110 |
-
// wordpress' category adding function
|
111 |
-
if ($cat_id = wp_insert_category($params))
|
112 |
-
{
|
113 |
-
return get_category($cat_id, ARRAY_A);
|
114 |
-
}
|
115 |
-
|
116 |
-
return FALSE;
|
117 |
-
}
|
118 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clone.class.php
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mmb_Clone extends Mmb_Core {
|
4 |
-
public function __construct() {
|
5 |
-
parent::__construct();
|
6 |
-
}
|
7 |
-
|
8 |
-
function manage() {
|
9 |
-
|
10 |
-
}
|
11 |
-
|
12 |
-
function clone_blog($param) {
|
13 |
-
|
14 |
-
}
|
15 |
-
}
|
16 |
-
|
17 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
comment.class.php
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mmb_Comment extends Mmb_Core
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
function bulk_edit_comments($args) {
|
11 |
-
|
12 |
-
$this->_escape($args);
|
13 |
-
$username = $args[0];
|
14 |
-
$password = $args[1];
|
15 |
-
$comment_ids = $args[2];
|
16 |
-
$status = $args[3];
|
17 |
-
|
18 |
-
if ( !$user = $this->login($username, $password) )
|
19 |
-
return $this->error;
|
20 |
-
|
21 |
-
if ( !current_user_can( 'moderate_comments' ) )
|
22 |
-
return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blogs.' ) );
|
23 |
-
|
24 |
-
$flag = false;
|
25 |
-
foreach($comment_ids as $comment_id){
|
26 |
-
$commentarr = array( 'comment_ID' => $comment_id,
|
27 |
-
'comment_approved' => $status
|
28 |
-
);
|
29 |
-
$success = wp_update_comment($commentarr);
|
30 |
-
if(!$success)
|
31 |
-
$flag = true;
|
32 |
-
}
|
33 |
-
|
34 |
-
if($flag)
|
35 |
-
return 2;
|
36 |
-
else
|
37 |
-
return 1;
|
38 |
-
}
|
39 |
-
|
40 |
-
function get_comment_count($args) {
|
41 |
-
$this->_escape($args);
|
42 |
-
$username = $args[0];
|
43 |
-
$password = $args[1];
|
44 |
-
|
45 |
-
if ( !$user = $this->login($username, $password) )
|
46 |
-
return $this->error;
|
47 |
-
|
48 |
-
if ( !current_user_can( 'edit_posts' ) )
|
49 |
-
return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
|
50 |
-
|
51 |
-
$count = wp_count_comments();
|
52 |
-
return array(
|
53 |
-
"approved" => $count->approved,
|
54 |
-
"awaiting_moderation" => $count->moderated,
|
55 |
-
"spam" => $count->spam,
|
56 |
-
"trash" => $count->trash,
|
57 |
-
// "total_comments" => $count->total_comments + $count->trash
|
58 |
-
"total_comments" => $count->total_comments
|
59 |
-
);
|
60 |
-
}
|
61 |
-
|
62 |
-
function restore_comment($args) {
|
63 |
-
$this->_escape($args);
|
64 |
-
$username = $args[0];
|
65 |
-
$password = $args[1];
|
66 |
-
$comment_id = $args[2];
|
67 |
-
|
68 |
-
if ( !$user = $this->login($username, $password) )
|
69 |
-
return $this->error;
|
70 |
-
|
71 |
-
if ( !current_user_can( 'moderate_comments' ) )
|
72 |
-
return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blogs.' ) );
|
73 |
-
|
74 |
-
$status = (string) get_comment_meta($comment_id, '_wp_trash_meta_status', true);
|
75 |
-
// $this->_log($status);
|
76 |
-
$success = wp_untrash_comment($comment_id);
|
77 |
-
// $this->_log($success);
|
78 |
-
|
79 |
-
if(!$success)
|
80 |
-
return false;
|
81 |
-
else
|
82 |
-
return $status;
|
83 |
-
|
84 |
-
}
|
85 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
core.class.php
CHANGED
@@ -1,411 +1,304 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class
|
4 |
-
{
|
5 |
-
var $name;
|
6 |
-
var $slug;
|
7 |
-
var $settings;
|
8 |
-
var $remote_client;
|
9 |
-
var $comment_instance;
|
10 |
-
var $plugin_instance;
|
11 |
-
var $theme_instance;
|
12 |
-
var $
|
13 |
-
var $
|
14 |
-
var $
|
15 |
-
var $
|
16 |
-
var $
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
}
|
64 |
-
|
65 |
-
/**
|
66 |
-
*
|
67 |
-
*
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
$
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
$
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
$
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
$
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
$
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
return $
|
150 |
-
}
|
151 |
-
|
152 |
-
/**
|
153 |
-
* Gets an instance of
|
154 |
-
*
|
155 |
-
*/
|
156 |
-
function
|
157 |
-
{
|
158 |
-
if (!isset($this->
|
159 |
-
{
|
160 |
-
$this->
|
161 |
-
}
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
*
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
*
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
}
|
207 |
-
|
208 |
-
/**
|
209 |
-
*
|
210 |
-
*
|
211 |
-
*/
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
}
|
305 |
-
|
306 |
-
function install()
|
307 |
-
{
|
308 |
-
//no need to check just update the table will run only when plugin installs
|
309 |
-
update_option('enable_xmlrpc', 1);
|
310 |
-
}
|
311 |
-
|
312 |
-
/**
|
313 |
-
* Saves the (modified) options into the database
|
314 |
-
*
|
315 |
-
*/
|
316 |
-
function _save_options()
|
317 |
-
{
|
318 |
-
if (get_option($this->slug))
|
319 |
-
{
|
320 |
-
update_option($this->slug, $this->settings);
|
321 |
-
}
|
322 |
-
else
|
323 |
-
{
|
324 |
-
add_option($this->slug, $this->settings);
|
325 |
-
}
|
326 |
-
}
|
327 |
-
|
328 |
-
/**
|
329 |
-
* Constructs a url (for ajax purpose)
|
330 |
-
*
|
331 |
-
* @param mixed $base_page
|
332 |
-
*/
|
333 |
-
function _construct_url($params = array(), $base_page = 'index.php')
|
334 |
-
{
|
335 |
-
$url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
|
336 |
-
foreach ($params as $key => $value)
|
337 |
-
{
|
338 |
-
$url .= "&$key=$value";
|
339 |
-
}
|
340 |
-
|
341 |
-
return $url;
|
342 |
-
}
|
343 |
-
|
344 |
-
function update_this_plugin($args) {
|
345 |
-
$this->_escape($args);
|
346 |
-
|
347 |
-
$username = $args[0];
|
348 |
-
$password = $args[1];
|
349 |
-
$url = $args[2];
|
350 |
-
// return array('test' => 'hello there');
|
351 |
-
|
352 |
-
if (!$user = $this->login($username, $password))
|
353 |
-
{
|
354 |
-
return $this->error;
|
355 |
-
}
|
356 |
-
if (!current_user_can('administrator'))
|
357 |
-
{
|
358 |
-
return new IXR_Error(401, 'Sorry, Only administrators can upgrade this plugin on the remote blog.');
|
359 |
-
}
|
360 |
-
|
361 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
362 |
-
|
363 |
-
ob_start();
|
364 |
-
@unlink(WP_PLUGIN_DIR.'/worker');
|
365 |
-
$upgrader = new Plugin_Upgrader();
|
366 |
-
//$deactivate = $upgrader->deactivate_plugin_before_upgrade(false, 'worker/init.php');
|
367 |
-
$result = $upgrader->run(array(
|
368 |
-
'package' => $url,
|
369 |
-
'destination' => WP_PLUGIN_DIR,
|
370 |
-
'clear_destination' => true,
|
371 |
-
'clear_working' => true,
|
372 |
-
'hook_extra' => array(
|
373 |
-
'plugin' => 'worker/init.php'
|
374 |
-
)));
|
375 |
-
ob_end_clean();
|
376 |
-
if(is_wp_error($result) || !$result){
|
377 |
-
$error = is_wp_error($result) ? $result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
378 |
-
$this->_last_worker_message(array('error' => print_r($error, true)));
|
379 |
-
}else {
|
380 |
-
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $upgrader->plugin_info());
|
381 |
-
$this->_last_worker_message(array('success' => $upgrader->plugin_info(), 'name' => $data['Name'], 'activate' => print_r($activate, true)));
|
382 |
-
}
|
383 |
-
|
384 |
-
}
|
385 |
-
|
386 |
-
/**
|
387 |
-
* Logs a user int
|
388 |
-
*
|
389 |
-
* @param mixed $username
|
390 |
-
* @param mixed $password
|
391 |
-
* @return WP_Error|WP_User
|
392 |
-
*/
|
393 |
-
function login($username, $password)
|
394 |
-
{
|
395 |
-
if (!get_option( 'enable_xmlrpc'))
|
396 |
-
{
|
397 |
-
update_option('enable_xmlrpc', 1);
|
398 |
-
// return new IXR_Error(405, 'XML-RPC services are disabled on this blog.');
|
399 |
-
}
|
400 |
-
|
401 |
-
$user = wp_authenticate($username, $password);
|
402 |
-
|
403 |
-
if (is_wp_error($user)) {
|
404 |
-
$this->error = new IXR_Error(403, __('Bad login/pass combination.'));
|
405 |
-
return false;
|
406 |
-
}
|
407 |
-
|
408 |
-
set_current_user( $user->ID );
|
409 |
-
return $user;
|
410 |
-
}
|
411 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class MMB_Core extends MMB_Helper
|
4 |
+
{
|
5 |
+
var $name;
|
6 |
+
var $slug;
|
7 |
+
var $settings;
|
8 |
+
var $remote_client;
|
9 |
+
var $comment_instance;
|
10 |
+
var $plugin_instance;
|
11 |
+
var $theme_instance;
|
12 |
+
var $wp_instance;
|
13 |
+
var $post_instance;
|
14 |
+
var $stats_instance;
|
15 |
+
var $user_instance;
|
16 |
+
var $backup_instance;
|
17 |
+
|
18 |
+
|
19 |
+
function __construct(){
|
20 |
+
global $mmb_plugin_dir;
|
21 |
+
|
22 |
+
$this->name = 'Manage Multiple Blogs';
|
23 |
+
$this->slug = 'manage-multiple-blogs';
|
24 |
+
$this->settings = get_option($this->slug);
|
25 |
+
if (!$this->settings)
|
26 |
+
{
|
27 |
+
$this->settings = array(
|
28 |
+
'blogs' => array(),
|
29 |
+
'current_blog' => array('type' => null)
|
30 |
+
);
|
31 |
+
}
|
32 |
+
add_action('rightnow_end', array($this, 'add_right_now_info'));
|
33 |
+
add_action('wp_footer', array('MMB_Stats', 'set_hit_count'));
|
34 |
+
register_activation_hook($mmb_plugin_dir.'/init.php', array($this, 'install'));
|
35 |
+
add_action('init', array($this, 'automatic_login'));
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Add an item into the Right Now Dashboard widget
|
41 |
+
* to inform that the blog can be managed remotely
|
42 |
+
*
|
43 |
+
*/
|
44 |
+
function add_right_now_info()
|
45 |
+
{
|
46 |
+
echo '<div class="mmb-slave-info">
|
47 |
+
<p>This site can be managed remotely.</p>
|
48 |
+
</div>';
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Gets an instance of the Comment class
|
53 |
+
*
|
54 |
+
*/
|
55 |
+
function get_comment_instance()
|
56 |
+
{
|
57 |
+
if (!isset($this->comment_instance))
|
58 |
+
{
|
59 |
+
$this->comment_instance = new MMB_Comment();
|
60 |
+
}
|
61 |
+
|
62 |
+
return $this->comment_instance;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Gets an instance of the Plugin class
|
67 |
+
*
|
68 |
+
*/
|
69 |
+
function get_plugin_instance()
|
70 |
+
{
|
71 |
+
if (!isset($this->plugin_instance))
|
72 |
+
{
|
73 |
+
$this->plugin_instance = new MMB_Plugin();
|
74 |
+
}
|
75 |
+
|
76 |
+
return $this->plugin_instance;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Gets an instance of the Theme class
|
81 |
+
*
|
82 |
+
*/
|
83 |
+
function get_theme_instance()
|
84 |
+
{
|
85 |
+
if (!isset($this->theme_instance))
|
86 |
+
{
|
87 |
+
$this->theme_instance = new MMB_Theme();
|
88 |
+
}
|
89 |
+
|
90 |
+
return $this->theme_instance;
|
91 |
+
}
|
92 |
+
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Gets an instance of MMB_Post class
|
96 |
+
*
|
97 |
+
*/
|
98 |
+
function get_post_instance()
|
99 |
+
{
|
100 |
+
if (!isset($this->post_instance))
|
101 |
+
{
|
102 |
+
$this->post_instance = new MMB_Post();
|
103 |
+
}
|
104 |
+
|
105 |
+
return $this->post_instance;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Gets an instance of Blogroll class
|
110 |
+
*
|
111 |
+
*/
|
112 |
+
function get_blogroll_instance()
|
113 |
+
{
|
114 |
+
if (!isset($this->blogroll_instance))
|
115 |
+
{
|
116 |
+
$this->blogroll_instance = new MMB_Blogroll();
|
117 |
+
}
|
118 |
+
|
119 |
+
return $this->blogroll_instance;
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Gets an instance of the WP class
|
126 |
+
*
|
127 |
+
*/
|
128 |
+
function get_wp_instance()
|
129 |
+
{
|
130 |
+
if (!isset($this->wp_instance))
|
131 |
+
{
|
132 |
+
$this->wp_instance = new MMB_WP();
|
133 |
+
}
|
134 |
+
|
135 |
+
return $this->wp_instance;
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Gets an instance of User
|
140 |
+
*
|
141 |
+
*/
|
142 |
+
function get_user_instance()
|
143 |
+
{
|
144 |
+
if (!isset($this->user_instance))
|
145 |
+
{
|
146 |
+
$this->user_instance = new MMB_User();
|
147 |
+
}
|
148 |
+
|
149 |
+
return $this->user_instance;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Gets an instance of stats class
|
154 |
+
*
|
155 |
+
*/
|
156 |
+
function get_stats_instance()
|
157 |
+
{
|
158 |
+
if (!isset($this->stats_instance))
|
159 |
+
{
|
160 |
+
$this->stats_instance = new MMB_Stats();
|
161 |
+
}
|
162 |
+
return $this->stats_instance;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* Gets an instance of stats class
|
167 |
+
*
|
168 |
+
*/
|
169 |
+
function get_backup_instance()
|
170 |
+
{
|
171 |
+
if (!isset($this->backup_instance))
|
172 |
+
{
|
173 |
+
$this->backup_instance = new MMB_Backup();
|
174 |
+
}
|
175 |
+
|
176 |
+
return $this->backup_instance;
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Plugin install callback function
|
181 |
+
* Check PHP version
|
182 |
+
*/
|
183 |
+
function install()
|
184 |
+
{
|
185 |
+
delete_option('_worker_nossl_key');
|
186 |
+
delete_option('_worker_public_key');
|
187 |
+
delete_option('_action_message_id');
|
188 |
+
if(PHP_VERSION < 5)
|
189 |
+
exit("<p>Plugin could not be activated. Your PHP version must be 5.0 or higher.</p>");
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Saves the (modified) options into the database
|
194 |
+
*
|
195 |
+
*/
|
196 |
+
function _save_options()
|
197 |
+
{
|
198 |
+
if (get_option($this->slug))
|
199 |
+
{
|
200 |
+
update_option($this->slug, $this->settings);
|
201 |
+
}
|
202 |
+
else
|
203 |
+
{
|
204 |
+
add_option($this->slug, $this->settings);
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Deletes options for communication with master
|
210 |
+
*
|
211 |
+
*/
|
212 |
+
function uninstall(){
|
213 |
+
delete_option('_worker_nossl_key');
|
214 |
+
delete_option('_worker_public_key');
|
215 |
+
delete_option('_action_message_id');
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Constructs a url (for ajax purpose)
|
220 |
+
*
|
221 |
+
* @param mixed $base_page
|
222 |
+
*/
|
223 |
+
function _construct_url($params = array(), $base_page = 'index.php')
|
224 |
+
{
|
225 |
+
$url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
|
226 |
+
foreach ($params as $key => $value)
|
227 |
+
{
|
228 |
+
$url .= "&$key=$value";
|
229 |
+
}
|
230 |
+
|
231 |
+
return $url;
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Worker update
|
236 |
+
*
|
237 |
+
*/
|
238 |
+
function update_worker_plugin($params) {
|
239 |
+
|
240 |
+
extract($params);
|
241 |
+
if($download_url){
|
242 |
+
|
243 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
244 |
+
include_once ABSPATH . 'wp-admin/includes/misc.php';
|
245 |
+
include_once ABSPATH . 'wp-admin/includes/template.php';
|
246 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
247 |
+
|
248 |
+
ob_start();
|
249 |
+
@unlink(dirname(__FILE__));
|
250 |
+
$upgrader = new Plugin_Upgrader();
|
251 |
+
$result = $upgrader->run(array(
|
252 |
+
'package' => $download_url,
|
253 |
+
'destination' => WP_PLUGIN_DIR,
|
254 |
+
'clear_destination' => true,
|
255 |
+
'clear_working' => true,
|
256 |
+
'hook_extra' => array(
|
257 |
+
'plugin' => 'worker/init.php'
|
258 |
+
)));
|
259 |
+
ob_end_clean();
|
260 |
+
if(is_wp_error($result) || !$result){
|
261 |
+
return array('error' => 'Manage WP Worker could not been upgraded.');
|
262 |
+
}
|
263 |
+
else{
|
264 |
+
return array('success' => 'Manage WP Worker plugin successfully upgraded.');
|
265 |
+
}
|
266 |
+
}
|
267 |
+
return array('error' => 'Bad download path for worker installation file.');
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Automatically logs in when called from Master
|
272 |
+
*
|
273 |
+
*/
|
274 |
+
function automatic_login(){
|
275 |
+
|
276 |
+
|
277 |
+
$where = ($_GET['mwp_goto']);
|
278 |
+
if (!is_user_logged_in() && $_GET['auto_login']) {
|
279 |
+
$signature = base64_decode($_GET['signature']);
|
280 |
+
$message_id = trim($_GET['message_id']);
|
281 |
+
$username = $_GET['username'];
|
282 |
+
|
283 |
+
$auth = $this->_authenticate_message($where.$message_id, $signature, $message_id);
|
284 |
+
if($auth === true){
|
285 |
+
$user = get_user_by('login', $username);
|
286 |
+
$user_id = $user->ID;
|
287 |
+
wp_set_current_user($user_id, $username);
|
288 |
+
wp_set_auth_cookie( $user_id );
|
289 |
+
do_action('wp_login', $username);
|
290 |
+
}
|
291 |
+
else
|
292 |
+
{
|
293 |
+
wp_die($auth['error']);
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
if($_GET['auto_login']){
|
298 |
+
wp_redirect(get_bloginfo('url')."/wp-admin/".$where);
|
299 |
+
exit();
|
300 |
+
}
|
301 |
+
}
|
302 |
+
|
303 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
}
|
ende.class.php
DELETED
@@ -1,124 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Ende - Simple text encryption and decryption
|
4 |
-
by Johan De Klerk
|
5 |
-
johan@wisi.co.za
|
6 |
-
*/
|
7 |
-
|
8 |
-
class Mmb_EnDe {
|
9 |
-
|
10 |
-
var $key;
|
11 |
-
var $data;
|
12 |
-
|
13 |
-
var $td;
|
14 |
-
var $iv;
|
15 |
-
var $init = false;
|
16 |
-
var $mcrypt_available = true;
|
17 |
-
function __construct($key='',$data='') {
|
18 |
-
if ($key != '') {
|
19 |
-
$this->init($key);
|
20 |
-
}
|
21 |
-
$this->data = $data;
|
22 |
-
}
|
23 |
-
|
24 |
-
function init(&$key) {
|
25 |
-
$this->key = substr (md5($key), 0, 16);
|
26 |
-
if(function_exists('mcrypt_module_open')){
|
27 |
-
//rijndael 128 and AES are similar except for key lengths
|
28 |
-
$this->td = mcrypt_module_open (MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
|
29 |
-
// $this->key = substr (md5($key), 0, mcrypt_enc_get_key_size ($this->td));
|
30 |
-
//we will use 16 as key length to simulate AES and mysql aes_encrypt, aes_decrypt
|
31 |
-
$iv_size = mcrypt_enc_get_iv_size ($this->td);
|
32 |
-
$this->iv = mcrypt_create_iv ($iv_size, MCRYPT_RAND);
|
33 |
-
}else{
|
34 |
-
$this->mcrypt_available = false;
|
35 |
-
}
|
36 |
-
$this->init = true;
|
37 |
-
}
|
38 |
-
|
39 |
-
function setKey($key) {
|
40 |
-
$this->init($key);
|
41 |
-
}
|
42 |
-
|
43 |
-
function setData($data) {
|
44 |
-
$this->data = $data;
|
45 |
-
}
|
46 |
-
|
47 |
-
function & getKey() {
|
48 |
-
return $this->key;
|
49 |
-
}
|
50 |
-
|
51 |
-
function & getData() {
|
52 |
-
return $this->data;
|
53 |
-
}
|
54 |
-
|
55 |
-
function & encrypt($data='') {
|
56 |
-
if($this->mcrypt_available)
|
57 |
-
return $this->_crypt('encrypt',$data);
|
58 |
-
else
|
59 |
-
return $this->_mysql_crypt('encrypt', $data);
|
60 |
-
}
|
61 |
-
|
62 |
-
function & decrypt($data='') {
|
63 |
-
if($this->mcrypt_available)
|
64 |
-
return $this->_crypt('decrypt',$data);
|
65 |
-
else
|
66 |
-
return $this->_mysql_crypt('decrypt', $data);
|
67 |
-
}
|
68 |
-
|
69 |
-
function close() {
|
70 |
-
mcrypt_module_close($this->td);
|
71 |
-
}
|
72 |
-
|
73 |
-
function & _crypt($mode,&$data) {
|
74 |
-
if ($data != '') {
|
75 |
-
$this->data = $data;
|
76 |
-
}
|
77 |
-
|
78 |
-
if ($this->init) {
|
79 |
-
$ret = mcrypt_generic_init($this->td,$this->key,$this->iv);
|
80 |
-
if ( ($ret >= 0) || ($ret !== false) ) {
|
81 |
-
if ($mode == 'encrypt') {
|
82 |
-
$this->data = mcrypt_generic($this->td, $this->data);
|
83 |
-
}
|
84 |
-
elseif ($mode == 'decrypt') {
|
85 |
-
$this->data = mdecrypt_generic($this->td, $this->data);
|
86 |
-
}
|
87 |
-
|
88 |
-
mcrypt_generic_deinit($this->td);
|
89 |
-
|
90 |
-
return $this->data;
|
91 |
-
}
|
92 |
-
else {
|
93 |
-
trigger_error('Error initialising '.$mode.'ion handle',E_USER_ERROR);
|
94 |
-
}
|
95 |
-
}
|
96 |
-
else {
|
97 |
-
trigger_error('Key not set. Use setKey() method',E_USER_ERROR);
|
98 |
-
}
|
99 |
-
}
|
100 |
-
|
101 |
-
function _mysql_crypt($mode, $data) {
|
102 |
-
global $wpdb;
|
103 |
-
|
104 |
-
if ($data != '') {
|
105 |
-
$this->data = $data;
|
106 |
-
}
|
107 |
-
|
108 |
-
if($this->init){
|
109 |
-
switch ($mode) {
|
110 |
-
case 'encrypt':
|
111 |
-
return $wpdb->get_var("SELECT AES_ENCRYPT('{$data}', '{$this->key}')");
|
112 |
-
break;
|
113 |
-
|
114 |
-
case 'encrypt':
|
115 |
-
return $wpdb->get_var("SELECT AES_DECRYPT('{$data}', '{$this->key}')");
|
116 |
-
break;
|
117 |
-
|
118 |
-
default:
|
119 |
-
break;
|
120 |
-
}
|
121 |
-
}
|
122 |
-
}
|
123 |
-
}
|
124 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
helper.class.php
CHANGED
@@ -1,206 +1,387 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
$
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
}
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*************************************************************
|
3 |
+
*
|
4 |
+
* helper.class.php
|
5 |
+
*
|
6 |
+
* Various utility functions
|
7 |
+
*
|
8 |
+
*
|
9 |
+
* Copyright (c) 2011 Prelovac Media
|
10 |
+
* www.prelovac.com
|
11 |
+
**************************************************************/
|
12 |
+
|
13 |
+
class MMB_Helper
|
14 |
+
{
|
15 |
+
/**
|
16 |
+
* A helper function to log data
|
17 |
+
*
|
18 |
+
* @param mixed $mixed
|
19 |
+
*/
|
20 |
+
function _log($mixed)
|
21 |
+
{
|
22 |
+
if (is_array($mixed)) {
|
23 |
+
$mixed = print_r($mixed, 1);
|
24 |
+
} else if (is_object($mixed)) {
|
25 |
+
ob_start();
|
26 |
+
var_dump($mixed);
|
27 |
+
$mixed = ob_get_clean();
|
28 |
+
}
|
29 |
+
|
30 |
+
$handle = fopen(dirname(__FILE__) . '/log', 'a');
|
31 |
+
fwrite($handle, $mixed . PHP_EOL);
|
32 |
+
fclose($handle);
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Strips WP disallowed HTML and PHP tags from a string
|
37 |
+
*
|
38 |
+
* @param mixed $str
|
39 |
+
* @return string
|
40 |
+
*/
|
41 |
+
function _strip_tags($str)
|
42 |
+
{
|
43 |
+
return strip_tags($str, '<address><a><abbr><acronym><area><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><map><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Filters a WordPress content (being comments, pages, posts etc)
|
48 |
+
*
|
49 |
+
* @param mixed $str
|
50 |
+
* @return string
|
51 |
+
*/
|
52 |
+
function _filter_content($str)
|
53 |
+
{
|
54 |
+
return nl2br($this->_strip_tags($str));
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
function _escape(&$array)
|
60 |
+
{
|
61 |
+
global $wpdb;
|
62 |
+
|
63 |
+
if (!is_array($array)) {
|
64 |
+
return ($wpdb->escape($array));
|
65 |
+
} else {
|
66 |
+
foreach ((array) $array as $k => $v) {
|
67 |
+
if (is_array($v)) {
|
68 |
+
$this->_escape($array[$k]);
|
69 |
+
} else if (is_object($v)) {
|
70 |
+
//skip
|
71 |
+
} else {
|
72 |
+
$array[$k] = $wpdb->escape($v);
|
73 |
+
}
|
74 |
+
}
|
75 |
+
}
|
76 |
+
}
|
77 |
+
|
78 |
+
function _base64_encode($str)
|
79 |
+
{
|
80 |
+
// a plus sign can break the encoded string
|
81 |
+
// if sent via URL
|
82 |
+
return str_replace('+', '|', base64_encode($str));
|
83 |
+
}
|
84 |
+
|
85 |
+
function _base64_decode($str)
|
86 |
+
{
|
87 |
+
return base64_decode(str_replace('|', '+', $str));
|
88 |
+
}
|
89 |
+
|
90 |
+
function _print_r($arr)
|
91 |
+
{
|
92 |
+
if (is_string($arr))
|
93 |
+
$arr = array(
|
94 |
+
$arr
|
95 |
+
);
|
96 |
+
echo '<pre>';
|
97 |
+
print_r($arr);
|
98 |
+
echo '</pre>';
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Initializes the file system
|
103 |
+
*
|
104 |
+
*/
|
105 |
+
function _init_filesystem()
|
106 |
+
{
|
107 |
+
global $wp_filesystem;
|
108 |
+
|
109 |
+
if (!$wp_filesystem || !is_object($wp_filesystem)) {
|
110 |
+
WP_Filesystem();
|
111 |
+
}
|
112 |
+
|
113 |
+
if (!is_object($wp_filesystem))
|
114 |
+
return FALSE;
|
115 |
+
|
116 |
+
return TRUE;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Gets transient based on WP version
|
121 |
+
*
|
122 |
+
* @global string $wp_version
|
123 |
+
* @param string $option_name
|
124 |
+
* @return mixed
|
125 |
+
*/
|
126 |
+
function mmb_get_transient($option_name)
|
127 |
+
{
|
128 |
+
if (trim($option_name) == '') {
|
129 |
+
return FALSE;
|
130 |
+
}
|
131 |
+
|
132 |
+
global $wp_version, $_wp_using_ext_object_cache;
|
133 |
+
|
134 |
+
if (version_compare($wp_version, '2.8.0', '<')){
|
135 |
+
return get_option($option_name);
|
136 |
+
}
|
137 |
+
else if (version_compare($wp_version, '3.0.0', '<')){
|
138 |
+
if(get_transient($option_name))
|
139 |
+
return get_transient($option_name);
|
140 |
+
else
|
141 |
+
return get_option('_transient_'.$option_name);
|
142 |
+
}
|
143 |
+
else {
|
144 |
+
if(get_site_transient($option_name))
|
145 |
+
return get_site_transient($option_name);
|
146 |
+
else
|
147 |
+
return get_option('_site_transient_'.$option_name);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
function mmb_delete_transient($option_name)
|
152 |
+
{
|
153 |
+
if (trim($option_name) == '') {
|
154 |
+
return FALSE;
|
155 |
+
}
|
156 |
+
|
157 |
+
global $wp_version;
|
158 |
+
|
159 |
+
if (version_compare($wp_version, '2.8.0', '<')){
|
160 |
+
delete_option($option_name);
|
161 |
+
}
|
162 |
+
else if (version_compare($wp_version, '3.0.0', '<')){
|
163 |
+
if(delete_transient($option_name))
|
164 |
+
delete_transient($option_name);
|
165 |
+
else
|
166 |
+
delete_option('_transient_'.$option_name);
|
167 |
+
}
|
168 |
+
else {
|
169 |
+
if(delete_site_transient($option_name))
|
170 |
+
delete_site_transient($option_name);
|
171 |
+
else
|
172 |
+
delete_option('_site_transient_'.$option_name);
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
function mmb_null_op_buffer($buffer)
|
177 |
+
{
|
178 |
+
//do nothing
|
179 |
+
if (!ob_get_level())
|
180 |
+
ob_start(array(
|
181 |
+
$this,
|
182 |
+
'mmb_null_op_buffer'
|
183 |
+
));
|
184 |
+
return '';
|
185 |
+
}
|
186 |
+
|
187 |
+
function _deleteTempDir($directory)
|
188 |
+
{
|
189 |
+
if (substr($directory, -1) == "/") {
|
190 |
+
$directory = substr($directory, 0, -1);
|
191 |
+
}
|
192 |
+
// $this->_log($directory);
|
193 |
+
if (!file_exists($directory) || !is_dir($directory)) {
|
194 |
+
return false;
|
195 |
+
} elseif (!is_readable($directory)) {
|
196 |
+
return false;
|
197 |
+
} else {
|
198 |
+
$directoryHandle = opendir($directory);
|
199 |
+
|
200 |
+
while ($contents = readdir($directoryHandle)) {
|
201 |
+
if ($contents != '.' && $contents != '..') {
|
202 |
+
$path = $directory . "/" . $contents;
|
203 |
+
|
204 |
+
if (is_dir($path)) {
|
205 |
+
$this->_deleteTempDir($path);
|
206 |
+
} else {
|
207 |
+
unlink($path);
|
208 |
+
}
|
209 |
+
}
|
210 |
+
}
|
211 |
+
closedir($directoryHandle);
|
212 |
+
rmdir($directory);
|
213 |
+
return true;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
function _is_ftp_writable_mmb()
|
218 |
+
{
|
219 |
+
if (defined('FTP_PASS')) {
|
220 |
+
return true;
|
221 |
+
} else
|
222 |
+
return false;
|
223 |
+
}
|
224 |
+
|
225 |
+
function _set_worker_message_id($message_id = false)
|
226 |
+
{
|
227 |
+
if ($message_id) {
|
228 |
+
add_option('_action_message_id', $message_id) or update_option('_action_message_id', $message_id);
|
229 |
+
return $message_id;
|
230 |
+
}
|
231 |
+
return false;
|
232 |
+
}
|
233 |
+
|
234 |
+
function _get_worker_message_id()
|
235 |
+
{
|
236 |
+
return (int) get_option('_action_message_id');
|
237 |
+
}
|
238 |
+
|
239 |
+
function _set_master_public_key($public_key = false)
|
240 |
+
{
|
241 |
+
if ($public_key && !get_option('_worker_public_key')) {
|
242 |
+
add_option('_worker_public_key', base64_encode($public_key));
|
243 |
+
return true;
|
244 |
+
}
|
245 |
+
return false;
|
246 |
+
}
|
247 |
+
|
248 |
+
function _get_master_public_key()
|
249 |
+
{
|
250 |
+
if (!get_option('_worker_public_key'))
|
251 |
+
return false;
|
252 |
+
return base64_decode(get_option('_worker_public_key'));
|
253 |
+
}
|
254 |
+
|
255 |
+
function _get_master_referer(){
|
256 |
+
if (!get_option('_master_referer'))
|
257 |
+
return false;
|
258 |
+
return base64_decode(get_option('_master_referer'));
|
259 |
+
}
|
260 |
+
|
261 |
+
function _get_random_signature(){
|
262 |
+
if (!get_option('_worker_nossl_key'))
|
263 |
+
return false;
|
264 |
+
return base64_decode(get_option('_worker_nossl_key'));
|
265 |
+
}
|
266 |
+
|
267 |
+
function _set_random_signature($random_key = false){
|
268 |
+
|
269 |
+
if ($random_key && !get_option('_worker_nossl_key')){
|
270 |
+
add_option('_worker_nossl_key', base64_encode($random_key));
|
271 |
+
return true;
|
272 |
+
}
|
273 |
+
return false;
|
274 |
+
}
|
275 |
+
|
276 |
+
|
277 |
+
function _authenticate_message($data = false, $signature = false, $message_id = false)
|
278 |
+
{
|
279 |
+
if (!$data && !$signature) {
|
280 |
+
return array(
|
281 |
+
'error' => 'Authentication failed.'
|
282 |
+
);
|
283 |
+
}
|
284 |
+
|
285 |
+
$current_message = $this->_get_worker_message_id();
|
286 |
+
|
287 |
+
if ((int) $current_message > (int) $message_id)
|
288 |
+
return array(
|
289 |
+
'error' => 'Invalid message recieved. Please try again.'
|
290 |
+
);
|
291 |
+
|
292 |
+
$pl_key = $this->_get_master_public_key();
|
293 |
+
if (!$pl_key) {
|
294 |
+
return array(
|
295 |
+
'error' => 'Authentication failed (public key).'
|
296 |
+
);
|
297 |
+
}
|
298 |
+
|
299 |
+
if( function_exists( 'openssl_verify' ) && !$this->_get_random_signature()){
|
300 |
+
$verify = openssl_verify($data, $signature, $pl_key);
|
301 |
+
if ($verify == 1) {
|
302 |
+
$message_id = $this->_set_worker_message_id($message_id);
|
303 |
+
return true;
|
304 |
+
} else if ($verify == 0) {
|
305 |
+
return array(
|
306 |
+
'error' => 'Invalid message signature (site is probably managed by another account?)'
|
307 |
+
);
|
308 |
+
} else {
|
309 |
+
return array(
|
310 |
+
'error' => 'Command not successful! Please try again.'
|
311 |
+
);
|
312 |
+
}
|
313 |
+
} else if ($this->_get_random_signature()) {
|
314 |
+
if(md5($data.$this->_get_random_signature()) == $signature ){
|
315 |
+
$message_id = $this->_set_worker_message_id($message_id);
|
316 |
+
return true;
|
317 |
+
}
|
318 |
+
return array(
|
319 |
+
'error' => 'Invalid message signature. Please try again or re-add the site to your account.'
|
320 |
+
);
|
321 |
+
}
|
322 |
+
// no rand key - deleted in get_stat maybe
|
323 |
+
else return array(
|
324 |
+
'error' => 'Invalid message signature, try re-adding the site to your account.)'
|
325 |
+
);
|
326 |
+
}
|
327 |
+
|
328 |
+
function _check_if_user_exists($username = false)
|
329 |
+
{
|
330 |
+
if ($username) {
|
331 |
+
require_once(ABSPATH . WPINC . '/registration.php');
|
332 |
+
|
333 |
+
if (username_exists($username) == null) {
|
334 |
+
return false;
|
335 |
+
}
|
336 |
+
$user = get_userdatabylogin($username);
|
337 |
+
if ($user->wp_user_level == 10) {
|
338 |
+
define('MMB_USER_CAPABILITIES', $user->wp_user_level);
|
339 |
+
return true;
|
340 |
+
}
|
341 |
+
return false;
|
342 |
+
}
|
343 |
+
return false;
|
344 |
+
}
|
345 |
+
|
346 |
+
function refresh_updates()
|
347 |
+
{
|
348 |
+
if (rand(1, 3) == '2') {
|
349 |
+
require_once(ABSPATH . WPINC . '/update.php');
|
350 |
+
wp_update_plugins();
|
351 |
+
wp_update_themes();
|
352 |
+
wp_version_check();
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
function remove_http($url = '')
|
357 |
+
{
|
358 |
+
if ($url == 'http://' OR $url == 'https://') {
|
359 |
+
return $url;
|
360 |
+
}
|
361 |
+
$matches = substr($url, 0, 7);
|
362 |
+
if ($matches == 'http://') {
|
363 |
+
$url = substr($url, 7);
|
364 |
+
} else {
|
365 |
+
$matches = substr($url, 0, 8);
|
366 |
+
if ($matches == 'https://')
|
367 |
+
$url = substr($url, 8);
|
368 |
+
}
|
369 |
+
return $url;
|
370 |
+
}
|
371 |
+
|
372 |
+
function mmb_get_error($error_object){
|
373 |
+
if(!is_wp_error($error_object)){
|
374 |
+
return $error_object != '' ? $error_object : ' error occured.';
|
375 |
+
}
|
376 |
+
else {
|
377 |
+
$errors = array();
|
378 |
+
foreach($error_object->error_data as $error_key => $error_string){
|
379 |
+
$errors[] = str_replace('_', ' ', ucfirst($error_key)).' - '.$error_string;
|
380 |
+
}
|
381 |
+
return implode('<br />', $errors);
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
|
386 |
+
}
|
387 |
+
?>
|
init.php
CHANGED
@@ -1,356 +1,262 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: ManageWP - Worker
|
4 |
-
Plugin URI: http://managewp.com/
|
5 |
-
Description: Manage all your blogs from one dashboard
|
6 |
-
Author: Prelovac Media
|
7 |
-
Version: 3.
|
8 |
-
Author URI: http://prelovac.com
|
9 |
-
*/
|
10 |
-
|
11 |
-
// PHP warnings can break our XML stuffs
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
require_once(
|
28 |
-
require_once("$mmb_plugin_dir/
|
29 |
-
require_once("$mmb_plugin_dir/
|
30 |
-
require_once("$mmb_plugin_dir/
|
31 |
-
require_once("$mmb_plugin_dir/
|
32 |
-
require_once("$mmb_plugin_dir/
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
{
|
59 |
-
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
{
|
87 |
-
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
function
|
98 |
-
{
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
{
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
}
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
}
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
}
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
return
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
{
|
264 |
-
global $mmb_core;
|
265 |
-
return $mmb_core->get_page_instance()->create($args);
|
266 |
-
}
|
267 |
-
|
268 |
-
function mmb_post_get_list($args)
|
269 |
-
{
|
270 |
-
global $mmb_core;
|
271 |
-
return $mmb_core->get_post_instance()->get_list($args);
|
272 |
-
}
|
273 |
-
|
274 |
-
function mmb_post_get_edit_data($args)
|
275 |
-
{
|
276 |
-
global $mmb_core;
|
277 |
-
return $mmb_core->get_post_instance()->get_edit_data($args);
|
278 |
-
}
|
279 |
-
|
280 |
-
function mmb_post_update($args)
|
281 |
-
{
|
282 |
-
global $mmb_core;
|
283 |
-
return $mmb_core->get_post_instance()->update($args);
|
284 |
-
}
|
285 |
-
|
286 |
-
function mmb_post_get_new_data($args)
|
287 |
-
{
|
288 |
-
global $mmb_core;
|
289 |
-
return $mmb_core->get_post_instance()->get_new_data($args);
|
290 |
-
}
|
291 |
-
|
292 |
-
function mmb_post_create($args)
|
293 |
-
{
|
294 |
-
global $mmb_core;
|
295 |
-
return $mmb_core->get_post_instance()->create($args);
|
296 |
-
}
|
297 |
-
|
298 |
-
function mmb_post_publish($args)
|
299 |
-
{
|
300 |
-
global $mmb_core;
|
301 |
-
return $mmb_core->get_post_instance()->publish($args);
|
302 |
-
}
|
303 |
-
|
304 |
-
function mmb_post_checksum($args)
|
305 |
-
{
|
306 |
-
global $mmb_core;
|
307 |
-
return $mmb_core->get_post_instance()->checksum($args);
|
308 |
-
}
|
309 |
-
|
310 |
-
function mmb_user_change_password($args)
|
311 |
-
{
|
312 |
-
global $mmb_core;
|
313 |
-
return $mmb_core->get_user_instance()->change_password($args);
|
314 |
-
}
|
315 |
-
|
316 |
-
|
317 |
-
function mmb_bulk_edit_comment($args) {
|
318 |
-
global $mmb_core;
|
319 |
-
return $mmb_core->get_comment_instance()->bulk_edit_comments($args);
|
320 |
-
}
|
321 |
-
|
322 |
-
function mmb_get_comment_count($args) {
|
323 |
-
global $mmb_core;
|
324 |
-
return $mmb_core->get_comment_instance()->get_comment_count($args);
|
325 |
-
}
|
326 |
-
|
327 |
-
function mmb_restore_comment($args) {
|
328 |
-
global $mmb_core;
|
329 |
-
return $mmb_core->get_comment_instance()->restore_comment($args);
|
330 |
-
}
|
331 |
-
|
332 |
-
function mmb_backup_now($args) {
|
333 |
-
global $mmb_core;
|
334 |
-
return $mmb_core->get_backup_instance()->backup($args);
|
335 |
-
}
|
336 |
-
|
337 |
-
function mmb_restore_now($args) {
|
338 |
-
global $mmb_core;
|
339 |
-
return $mmb_core->get_backup_instance()->restore($args);
|
340 |
-
}
|
341 |
-
|
342 |
-
function mmb_get_backup_url($args) {
|
343 |
-
global $mmb_core;
|
344 |
-
return $mmb_core->get_backup_instance()->get_backup_details($args);
|
345 |
-
}
|
346 |
-
|
347 |
-
function mmb_weekly_backup($args) {
|
348 |
-
global $mmb_core;
|
349 |
-
return $mmb_core->get_backup_instance()->get_weekly_backup($args);
|
350 |
-
}
|
351 |
-
|
352 |
-
function mmb_geet_last_worker_message($args) {
|
353 |
-
global $mmb_core;
|
354 |
-
return $mmb_core->_get_last_worker_message();
|
355 |
-
}
|
356 |
-
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: ManageWP - Worker
|
4 |
+
Plugin URI: http://managewp.com/
|
5 |
+
Description: Manage all your blogs from one dashboard
|
6 |
+
Author: Prelovac Media
|
7 |
+
Version: 3.8.0
|
8 |
+
Author URI: http://www.prelovac.com
|
9 |
+
*/
|
10 |
+
|
11 |
+
// PHP warnings can break our XML stuffs
|
12 |
+
if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
|
13 |
+
error_reporting(E_ERROR);
|
14 |
+
}
|
15 |
+
|
16 |
+
define('MMB_WORKER_VERSION', '3.8.0');
|
17 |
+
|
18 |
+
global $wpdb, $mmb_plugin_dir, $mmb_plugin_url;
|
19 |
+
|
20 |
+
$mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
|
21 |
+
$mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
|
22 |
+
|
23 |
+
require_once(ABSPATH . 'wp-includes/class-IXR.php');
|
24 |
+
require_once("$mmb_plugin_dir/helper.class.php");
|
25 |
+
require_once("$mmb_plugin_dir/core.class.php");
|
26 |
+
require_once("$mmb_plugin_dir/plugin.class.php");
|
27 |
+
require_once("$mmb_plugin_dir/theme.class.php");
|
28 |
+
require_once("$mmb_plugin_dir/wp.class.php");
|
29 |
+
require_once("$mmb_plugin_dir/post.class.php");
|
30 |
+
require_once("$mmb_plugin_dir/stats.class.php");
|
31 |
+
require_once("$mmb_plugin_dir/user.class.php");
|
32 |
+
require_once("$mmb_plugin_dir/backup.class.php");
|
33 |
+
|
34 |
+
$mmb_core = new MMB_Core();
|
35 |
+
add_action('init', '_mmb_parse_request');
|
36 |
+
|
37 |
+
if (function_exists('register_activation_hook'))
|
38 |
+
register_activation_hook(__FILE__, array($mmb_core, 'install'));
|
39 |
+
|
40 |
+
if (function_exists('register_deactivation_hook'))
|
41 |
+
register_deactivation_hook(__FILE__, array($mmb_core, 'uninstall'));
|
42 |
+
|
43 |
+
function _mmb_parse_request()
|
44 |
+
{
|
45 |
+
if (!isset($HTTP_RAW_POST_DATA)) {
|
46 |
+
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
|
47 |
+
}
|
48 |
+
ob_start();
|
49 |
+
|
50 |
+
global $mmb_core;
|
51 |
+
$data = base64_decode($HTTP_RAW_POST_DATA);
|
52 |
+
$num = extract(unserialize($data));
|
53 |
+
|
54 |
+
if ($action) {
|
55 |
+
if (!$mmb_core->_check_if_user_exists($params['username']))
|
56 |
+
mmb_response('Username <b>'.$params['username'].'</b> does not have administrator capabilities. Enter the correct username in the site options.', false);
|
57 |
+
|
58 |
+
if ($action == 'add_site') {
|
59 |
+
mmb_add_site($params);
|
60 |
+
mmb_response('You should never see this.', false);
|
61 |
+
}
|
62 |
+
|
63 |
+
$auth = $mmb_core->_authenticate_message($action . $id, $signature, $id);
|
64 |
+
if ($auth === true) {
|
65 |
+
$mmb_actions = array(
|
66 |
+
'remove_site' => 'mmb_remove_site',
|
67 |
+
'get_stats' => 'mmb_stats_get',
|
68 |
+
'backup' => 'mmb_backup_now',
|
69 |
+
'restore' => 'mmb_restore_now',
|
70 |
+
'optimize_tables' => 'mmb_optimize_tables',
|
71 |
+
'check_wp_version' => 'mmb_wp_checkversion',
|
72 |
+
'create_post' => 'mmb_post_create',
|
73 |
+
'upgrade_plugins' => 'mmb_upgrade_plugins',
|
74 |
+
'wp_upgrade' => 'mmb_upgrade_wp',
|
75 |
+
'upgrade_themes' => 'mmb_themes_upgrade',
|
76 |
+
'upload_plugin_by_url' => 'mmb_plugin_upload_by_url',
|
77 |
+
'upload_theme_by_url' => 'mmb_theme_upload_by_url',
|
78 |
+
'update_worker' => 'mmb_update_worker_plugin'
|
79 |
+
);
|
80 |
+
if (array_key_exists($action, $mmb_actions) && function_exists($mmb_actions[$action]))
|
81 |
+
call_user_func($mmb_actions[$action], $params);
|
82 |
+
else
|
83 |
+
mmb_response('Action "' . $action . '" does not exist.', false);
|
84 |
+
} else if(array_key_exists('openssl_activated', $auth)){
|
85 |
+
mmb_response($auth, true);
|
86 |
+
} else {
|
87 |
+
mmb_response($auth['error'], false);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
|
92 |
+
ob_end_clean();
|
93 |
+
}
|
94 |
+
|
95 |
+
/* Main response function */
|
96 |
+
|
97 |
+
function mmb_response($response = false, $success = true)
|
98 |
+
{
|
99 |
+
$return = array();
|
100 |
+
|
101 |
+
if (empty($response))
|
102 |
+
$return['error'] = 'Empty response';
|
103 |
+
else if ($success)
|
104 |
+
$return['success'] = $response;
|
105 |
+
else
|
106 |
+
$return['error'] = $response;
|
107 |
+
|
108 |
+
header('Content-Type: text/plain');
|
109 |
+
exit(PHP_EOL.base64_encode(serialize($return)));
|
110 |
+
}
|
111 |
+
|
112 |
+
function mmb_add_site($params)
|
113 |
+
{
|
114 |
+
global $mmb_core;
|
115 |
+
|
116 |
+
$num = extract($params);
|
117 |
+
|
118 |
+
if ($num) {
|
119 |
+
if ( !get_option('_action_message_id') && !get_option('_worker_public_key')) {
|
120 |
+
$public_key = base64_decode($public_key) ;
|
121 |
+
|
122 |
+
if ( function_exists('openssl_verify') ) {
|
123 |
+
$verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
|
124 |
+
if ($verify == 1) {
|
125 |
+
$mmb_core->_set_master_public_key($public_key);
|
126 |
+
$mmb_core->_set_worker_message_id($id);
|
127 |
+
|
128 |
+
mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
|
129 |
+
} else if ($verify == 0) {
|
130 |
+
mmb_response('Invalid message signature (site is probably managed by another account?)', false);
|
131 |
+
} else {
|
132 |
+
mmb_response('Command not successful. Please try again.', false);
|
133 |
+
}
|
134 |
+
} else{
|
135 |
+
if ( !get_option('_worker_nossl_key')) {
|
136 |
+
$random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
|
137 |
+
|
138 |
+
$mmb_core->_set_random_signature($random_key);
|
139 |
+
$mmb_core->_set_worker_message_id($id);
|
140 |
+
$mmb_core->_set_master_public_key($public_key);
|
141 |
+
|
142 |
+
mmb_response($mmb_core->get_stats_instance()->get_initial_stats(), true);
|
143 |
+
}
|
144 |
+
else mmb_response('Site seems to be already managed by another ManageWP account. Either remove the site from that account, or deactivate & activate the ManageWP Worker plugin to reset.', false);
|
145 |
+
}
|
146 |
+
} else {
|
147 |
+
mmb_response('Site seems to be already managed by another ManageWP account. Either remove the site from that account, or deactivate & activate the ManageWP Worker plugin to reset.', false);
|
148 |
+
}
|
149 |
+
} else {
|
150 |
+
mmb_response('Invalid parameters received. Please try again.', false);
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
function mmb_remove_site()
|
155 |
+
{
|
156 |
+
global $mmb_core;
|
157 |
+
$mmb_core->uninstall();
|
158 |
+
mmb_response('ManageWP Worker data successfully removed.', true);
|
159 |
+
}
|
160 |
+
|
161 |
+
|
162 |
+
function mmb_stats_get($params)
|
163 |
+
{
|
164 |
+
global $mmb_core;
|
165 |
+
mmb_response($mmb_core->get_stats_instance()->get($params), true);
|
166 |
+
}
|
167 |
+
|
168 |
+
|
169 |
+
//Plugins
|
170 |
+
|
171 |
+
function mmb_upgrade_plugins($params)
|
172 |
+
{
|
173 |
+
global $mmb_core;
|
174 |
+
mmb_response($mmb_core->get_plugin_instance()->upgrade_all($params), true);
|
175 |
+
}
|
176 |
+
|
177 |
+
function mmb_plugin_upload_by_url($params)
|
178 |
+
{
|
179 |
+
global $mmb_core;
|
180 |
+
$return = $mmb_core->get_plugin_instance()->upload_by_url($params);
|
181 |
+
|
182 |
+
|
183 |
+
mmb_response($return['message'],$return['bool'] );
|
184 |
+
|
185 |
+
}
|
186 |
+
|
187 |
+
//Themes
|
188 |
+
function mmb_theme_upload_by_url($params)
|
189 |
+
{
|
190 |
+
global $mmb_core;
|
191 |
+
$return = $mmb_core->get_theme_instance()->upload_theme_by_url($params);
|
192 |
+
mmb_response($return['message'],$return['bool'] );
|
193 |
+
}
|
194 |
+
|
195 |
+
function mmb_themes_upgrade($params)
|
196 |
+
{
|
197 |
+
global $mmb_core;
|
198 |
+
mmb_response($mmb_core->get_theme_instance()->upgrade_all($params), true);
|
199 |
+
}
|
200 |
+
|
201 |
+
|
202 |
+
//wp
|
203 |
+
|
204 |
+
function mmb_upgrade_wp($params)
|
205 |
+
{
|
206 |
+
global $mmb_core;
|
207 |
+
mmb_response($mmb_core->get_wp_instance()->upgrade());
|
208 |
+
}
|
209 |
+
|
210 |
+
//post
|
211 |
+
function mmb_post_create($params)
|
212 |
+
{
|
213 |
+
global $mmb_core;
|
214 |
+
$return = $mmb_core->get_post_instance()->create($params);
|
215 |
+
if (is_int($return))
|
216 |
+
mmb_response($return, true);
|
217 |
+
else
|
218 |
+
mmb_response($return, false);
|
219 |
+
}
|
220 |
+
|
221 |
+
//backup
|
222 |
+
function mmb_backup_now($params)
|
223 |
+
{
|
224 |
+
global $mmb_core;
|
225 |
+
$return = $mmb_core->get_backup_instance()->backup($params);
|
226 |
+
|
227 |
+
if (is_array($return) && array_key_exists('error', $return))
|
228 |
+
mmb_response($return['error'], false);
|
229 |
+
else {
|
230 |
+
$mmb_core->_log($return);
|
231 |
+
mmb_response($return, true);
|
232 |
+
}
|
233 |
+
|
234 |
+
}
|
235 |
+
|
236 |
+
function mmb_optimize_tables($params)
|
237 |
+
{
|
238 |
+
global $mmb_core;
|
239 |
+
$return = $mmb_core->get_backup_instance()->optimize_tables();
|
240 |
+
if ($return)
|
241 |
+
mmb_response($return, true);
|
242 |
+
else
|
243 |
+
mmb_response(false, false);
|
244 |
+
}
|
245 |
+
|
246 |
+
function mmb_restore_now($params)
|
247 |
+
{
|
248 |
+
global $mmb_core;
|
249 |
+
$return = $mmb_core->get_backup_instance()->restore($params);
|
250 |
+
if (is_array($return) && array_key_exists('error', $return))
|
251 |
+
mmb_response($return['error'], false);
|
252 |
+
else
|
253 |
+
mmb_response($return, true);
|
254 |
+
|
255 |
+
}
|
256 |
+
|
257 |
+
function mmb_update_worker_plugin($params)
|
258 |
+
{
|
259 |
+
global $mmb_core;
|
260 |
+
mmb_response($mmb_core->update_worker_plugin($params), true);
|
261 |
+
}
|
262 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mmb.wp.upgrader.php
DELETED
@@ -1,1489 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* A File upgrader class for WordPress.
|
4 |
-
*
|
5 |
-
* This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes.
|
6 |
-
*
|
7 |
-
* @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions
|
8 |
-
*
|
9 |
-
* @package WordPress
|
10 |
-
* @subpackage Upgrader
|
11 |
-
* @since 2.8.0
|
12 |
-
*/
|
13 |
-
|
14 |
-
/**
|
15 |
-
* WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file.
|
16 |
-
*
|
17 |
-
* @TODO More Detailed docs, for methods as well.
|
18 |
-
*
|
19 |
-
* @package WordPress
|
20 |
-
* @subpackage Upgrader
|
21 |
-
* @since 2.8.0
|
22 |
-
*/
|
23 |
-
class Mmb_upgrader {
|
24 |
-
var $strings = array();
|
25 |
-
var $skin = null;
|
26 |
-
var $result = array();
|
27 |
-
|
28 |
-
function Mmb_upgrader($skin = null) {
|
29 |
-
return $this->__construct($skin);
|
30 |
-
}
|
31 |
-
function __construct($skin = null) {
|
32 |
-
if ( null == $skin )
|
33 |
-
$this->skin = new Mmb_upgrader_Skin();
|
34 |
-
else
|
35 |
-
$this->skin = $skin;
|
36 |
-
}
|
37 |
-
|
38 |
-
function init() {
|
39 |
-
$this->skin->set_upgrader($this);
|
40 |
-
$this->generic_strings();
|
41 |
-
}
|
42 |
-
|
43 |
-
function generic_strings() {
|
44 |
-
$this->strings['bad_request'] = __('Invalid Data provided.');
|
45 |
-
$this->strings['fs_unavailable'] = __('Could not access filesystem.');
|
46 |
-
$this->strings['fs_error'] = __('Filesystem error.');
|
47 |
-
$this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.');
|
48 |
-
$this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).');
|
49 |
-
$this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.');
|
50 |
-
$this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.');
|
51 |
-
/* translators: %s: directory name */
|
52 |
-
$this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
|
53 |
-
|
54 |
-
$this->strings['download_failed'] = __('Download failed.');
|
55 |
-
$this->strings['installing_package'] = __('Installing the latest version…');
|
56 |
-
$this->strings['folder_exists'] = __('Destination folder already exists.');
|
57 |
-
$this->strings['mkdir_failed'] = __('Could not create directory.');
|
58 |
-
$this->strings['bad_package'] = __('Incompatible Archive.');
|
59 |
-
|
60 |
-
$this->strings['maintenance_start'] = __('Enabling Maintenance mode…');
|
61 |
-
$this->strings['maintenance_end'] = __('Disabling Maintenance mode…');
|
62 |
-
}
|
63 |
-
|
64 |
-
function fs_connect( $directories = array() ) {
|
65 |
-
global $wp_filesystem;
|
66 |
-
|
67 |
-
if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
|
68 |
-
return false;
|
69 |
-
|
70 |
-
if ( ! WP_Filesystem($credentials) ) {
|
71 |
-
$error = true;
|
72 |
-
if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
|
73 |
-
$error = $wp_filesystem->errors;
|
74 |
-
$this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
|
75 |
-
return false;
|
76 |
-
}
|
77 |
-
|
78 |
-
if ( ! is_object($wp_filesystem) )
|
79 |
-
return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
|
80 |
-
|
81 |
-
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
|
82 |
-
return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
|
83 |
-
|
84 |
-
foreach ( (array)$directories as $dir ) {
|
85 |
-
switch ( $dir ) {
|
86 |
-
case ABSPATH:
|
87 |
-
if ( ! $wp_filesystem->abspath() )
|
88 |
-
return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
|
89 |
-
break;
|
90 |
-
case WP_CONTENT_DIR:
|
91 |
-
if ( ! $wp_filesystem->wp_content_dir() )
|
92 |
-
return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
|
93 |
-
break;
|
94 |
-
case WP_PLUGIN_DIR:
|
95 |
-
if ( ! $wp_filesystem->wp_plugins_dir() )
|
96 |
-
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
|
97 |
-
break;
|
98 |
-
case WP_CONTENT_DIR . '/themes':
|
99 |
-
if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
|
100 |
-
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
|
101 |
-
break;
|
102 |
-
default:
|
103 |
-
if ( ! $wp_filesystem->find_folder($dir) )
|
104 |
-
return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
|
105 |
-
break;
|
106 |
-
}
|
107 |
-
}
|
108 |
-
return true;
|
109 |
-
} //end fs_connect();
|
110 |
-
|
111 |
-
function download_package($package) {
|
112 |
-
|
113 |
-
if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
|
114 |
-
return $package; //must be a local file..
|
115 |
-
|
116 |
-
if ( empty($package) )
|
117 |
-
return new WP_Error('no_package', $this->strings['no_package']);
|
118 |
-
|
119 |
-
// $this->skin->feedback('downloading_package', $package);
|
120 |
-
|
121 |
-
$download_file = download_url($package);
|
122 |
-
|
123 |
-
if ( is_wp_error($download_file) )
|
124 |
-
return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
|
125 |
-
|
126 |
-
return $download_file;
|
127 |
-
}
|
128 |
-
|
129 |
-
function unpack_package($package, $delete_package = true) {
|
130 |
-
global $wp_filesystem;
|
131 |
-
|
132 |
-
// $this->skin->feedback('unpack_package');
|
133 |
-
|
134 |
-
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
|
135 |
-
|
136 |
-
//Clean up contents of upgrade directory beforehand.
|
137 |
-
$upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
|
138 |
-
if ( !empty($upgrade_files) ) {
|
139 |
-
foreach ( $upgrade_files as $file )
|
140 |
-
$wp_filesystem->delete($upgrade_folder . $file['name'], true);
|
141 |
-
}
|
142 |
-
|
143 |
-
//We need a working directory
|
144 |
-
$working_dir = $upgrade_folder . basename($package, '.zip');
|
145 |
-
|
146 |
-
// Clean up working directory
|
147 |
-
if ( $wp_filesystem->is_dir($working_dir) )
|
148 |
-
$wp_filesystem->delete($working_dir, true);
|
149 |
-
|
150 |
-
// Unzip package to working directory
|
151 |
-
$result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice?
|
152 |
-
|
153 |
-
// Once extracted, delete the package if required.
|
154 |
-
if ( $delete_package )
|
155 |
-
unlink($package);
|
156 |
-
|
157 |
-
if ( is_wp_error($result) ) {
|
158 |
-
$wp_filesystem->delete($working_dir, true);
|
159 |
-
return $result;
|
160 |
-
}
|
161 |
-
|
162 |
-
return $working_dir;
|
163 |
-
}
|
164 |
-
|
165 |
-
function install_package($args = array()) {
|
166 |
-
global $wp_filesystem;
|
167 |
-
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these
|
168 |
-
'clear_destination' => false, 'clear_working' => false,
|
169 |
-
'hook_extra' => array());
|
170 |
-
|
171 |
-
$args = wp_parse_args($args, $defaults);
|
172 |
-
extract($args);
|
173 |
-
|
174 |
-
@set_time_limit( 300 );
|
175 |
-
|
176 |
-
if ( empty($source) || empty($destination) )
|
177 |
-
return new WP_Error('bad_request', $this->strings['bad_request']);
|
178 |
-
|
179 |
-
// $this->skin->feedback('installing_package');
|
180 |
-
|
181 |
-
$res = apply_filters('upgrader_pre_install', true, $hook_extra);
|
182 |
-
if ( is_wp_error($res) )
|
183 |
-
return $res;
|
184 |
-
|
185 |
-
//Retain the Original source and destinations
|
186 |
-
$remote_source = $source;
|
187 |
-
$local_destination = $destination;
|
188 |
-
|
189 |
-
$source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
|
190 |
-
$remote_destination = $wp_filesystem->find_folder($local_destination);
|
191 |
-
|
192 |
-
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
|
193 |
-
if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
|
194 |
-
$source = trailingslashit($source) . trailingslashit($source_files[0]);
|
195 |
-
elseif ( count($source_files) == 0 )
|
196 |
-
return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
|
197 |
-
//else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
|
198 |
-
|
199 |
-
//Hook ability to change the source file location..
|
200 |
-
$source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
|
201 |
-
if ( is_wp_error($source) )
|
202 |
-
return $source;
|
203 |
-
|
204 |
-
//Has the source location changed? If so, we need a new source_files list.
|
205 |
-
if ( $source !== $remote_source )
|
206 |
-
$source_files = array_keys( $wp_filesystem->dirlist($source) );
|
207 |
-
|
208 |
-
//Protection against deleting files in any important base directories.
|
209 |
-
if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
|
210 |
-
$remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
|
211 |
-
$destination = trailingslashit($destination) . trailingslashit(basename($source));
|
212 |
-
}
|
213 |
-
|
214 |
-
if ( $wp_filesystem->exists($remote_destination) ) {
|
215 |
-
if ( $clear_destination ) {
|
216 |
-
//We're going to clear the destination if theres something there
|
217 |
-
// $this->skin->feedback('remove_old');
|
218 |
-
$removed = $wp_filesystem->delete($remote_destination, true);
|
219 |
-
$removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
|
220 |
-
|
221 |
-
if ( is_wp_error($removed) )
|
222 |
-
return $removed;
|
223 |
-
else if ( ! $removed )
|
224 |
-
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
|
225 |
-
} else {
|
226 |
-
//If we're not clearing the destination folder and something exists there allready, Bail.
|
227 |
-
//But first check to see if there are actually any files in the folder.
|
228 |
-
$_files = $wp_filesystem->dirlist($remote_destination);
|
229 |
-
if ( ! empty($_files) ) {
|
230 |
-
$wp_filesystem->delete($remote_source, true); //Clear out the source files.
|
231 |
-
return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
|
232 |
-
}
|
233 |
-
}
|
234 |
-
}
|
235 |
-
|
236 |
-
//Create destination if needed
|
237 |
-
if ( !$wp_filesystem->exists($remote_destination) )
|
238 |
-
if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
|
239 |
-
return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
|
240 |
-
|
241 |
-
// Copy new version of item into place.
|
242 |
-
$result = copy_dir($source, $remote_destination);
|
243 |
-
if ( is_wp_error($result) ) {
|
244 |
-
if ( $clear_working )
|
245 |
-
$wp_filesystem->delete($remote_source, true);
|
246 |
-
return $result;
|
247 |
-
}
|
248 |
-
|
249 |
-
//Clear the Working folder?
|
250 |
-
if ( $clear_working )
|
251 |
-
$wp_filesystem->delete($remote_source, true);
|
252 |
-
|
253 |
-
$destination_name = basename( str_replace($local_destination, '', $destination) );
|
254 |
-
if ( '.' == $destination_name )
|
255 |
-
$destination_name = '';
|
256 |
-
|
257 |
-
$this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
|
258 |
-
|
259 |
-
$res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
|
260 |
-
if ( is_wp_error($res) ) {
|
261 |
-
$this->result = $res;
|
262 |
-
return $res;
|
263 |
-
}
|
264 |
-
|
265 |
-
//Bombard the calling function will all the info which we've just used.
|
266 |
-
return $this->result;
|
267 |
-
}
|
268 |
-
|
269 |
-
function run($options) {
|
270 |
-
|
271 |
-
$defaults = array( 'package' => '', //Please always pass this.
|
272 |
-
'destination' => '', //And this
|
273 |
-
'clear_destination' => false,
|
274 |
-
'clear_working' => true,
|
275 |
-
'is_multi' => false,
|
276 |
-
'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
|
277 |
-
);
|
278 |
-
|
279 |
-
$options = wp_parse_args($options, $defaults);
|
280 |
-
extract($options);
|
281 |
-
|
282 |
-
//Connect to the Filesystem first.
|
283 |
-
$res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
|
284 |
-
if ( ! $res ) //Mainly for non-connected filesystem.
|
285 |
-
return false;
|
286 |
-
|
287 |
-
if ( is_wp_error($res) ) {
|
288 |
-
$this->skin->error($res);
|
289 |
-
return $res;
|
290 |
-
}
|
291 |
-
|
292 |
-
if ( !$is_multi ) // call $this->header separately if running multiple times
|
293 |
-
$this->skin->header();
|
294 |
-
|
295 |
-
$this->skin->before();
|
296 |
-
|
297 |
-
//Download the package (Note, This just returns the filename of the file if the package is a local file)
|
298 |
-
$download = $this->download_package( $package );
|
299 |
-
if ( is_wp_error($download) ) {
|
300 |
-
$this->skin->error($download);
|
301 |
-
$this->skin->after();
|
302 |
-
return $download;
|
303 |
-
}
|
304 |
-
|
305 |
-
//Unzip's the file into a temporary directory
|
306 |
-
$working_dir = $this->unpack_package( $download );
|
307 |
-
if ( is_wp_error($working_dir) ) {
|
308 |
-
$this->skin->error($working_dir);
|
309 |
-
$this->skin->after();
|
310 |
-
return $working_dir;
|
311 |
-
}
|
312 |
-
|
313 |
-
//With the given options, this installs it to the destination directory.
|
314 |
-
$result = $this->install_package( array(
|
315 |
-
'source' => $working_dir,
|
316 |
-
'destination' => $destination,
|
317 |
-
'clear_destination' => $clear_destination,
|
318 |
-
'clear_working' => $clear_working,
|
319 |
-
'hook_extra' => $hook_extra
|
320 |
-
) );
|
321 |
-
$this->skin->set_result($result);
|
322 |
-
if ( is_wp_error($result) ) {
|
323 |
-
$this->skin->error($result);
|
324 |
-
// $this->skin->feedback('process_failed');
|
325 |
-
} else {
|
326 |
-
//Install Suceeded
|
327 |
-
// $this->skin->feedback('process_success');
|
328 |
-
}
|
329 |
-
$this->skin->after();
|
330 |
-
|
331 |
-
if ( !$is_multi )
|
332 |
-
$this->skin->footer();
|
333 |
-
|
334 |
-
return $result;
|
335 |
-
}
|
336 |
-
|
337 |
-
function maintenance_mode($enable = false) {
|
338 |
-
global $wp_filesystem;
|
339 |
-
$file = $wp_filesystem->abspath() . '.maintenance';
|
340 |
-
if ( $enable ) {
|
341 |
-
// $this->skin->feedback('maintenance_start');
|
342 |
-
// Create maintenance file to signal that we are upgrading
|
343 |
-
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
|
344 |
-
$wp_filesystem->delete($file);
|
345 |
-
$wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
|
346 |
-
} else if ( !$enable && $wp_filesystem->exists($file) ) {
|
347 |
-
// $this->skin->feedback('maintenance_end');
|
348 |
-
$wp_filesystem->delete($file);
|
349 |
-
}
|
350 |
-
}
|
351 |
-
|
352 |
-
function mmb_get_transient($option_name) {
|
353 |
-
|
354 |
-
if(trim($option_name) == ''){
|
355 |
-
return FALSE;
|
356 |
-
}
|
357 |
-
|
358 |
-
global $wp_version;
|
359 |
-
|
360 |
-
if (version_compare($wp_version, '2.8', '<'))
|
361 |
-
return get_option($option_name);
|
362 |
-
|
363 |
-
else if (version_compare($wp_version, '3.0', '<'))
|
364 |
-
return get_transient($option_name);
|
365 |
-
|
366 |
-
else
|
367 |
-
return get_site_transient($option_name);
|
368 |
-
}
|
369 |
-
|
370 |
-
function mmb_delete_transient($option_name) {
|
371 |
-
if(trim($option_name) == ''){
|
372 |
-
return FALSE;
|
373 |
-
}
|
374 |
-
|
375 |
-
global $wp_version;
|
376 |
-
|
377 |
-
if (version_compare($wp_version, '2.8', '<'))
|
378 |
-
return delete_option($option_name);
|
379 |
-
|
380 |
-
else if (version_compare($wp_version, '3.0', '<'))
|
381 |
-
return get_transient ($option_name);
|
382 |
-
|
383 |
-
else
|
384 |
-
return delete_site_transient($option_name);
|
385 |
-
}
|
386 |
-
|
387 |
-
}
|
388 |
-
|
389 |
-
/**
|
390 |
-
* Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
|
391 |
-
*
|
392 |
-
*
|
393 |
-
* @package WordPress
|
394 |
-
* @subpackage Upgrader
|
395 |
-
* @since 2.8.0
|
396 |
-
*/
|
397 |
-
class Mmb_Plugin_Upgrader extends Mmb_upgrader {
|
398 |
-
|
399 |
-
var $result;
|
400 |
-
var $bulk = false;
|
401 |
-
var $show_before = '';
|
402 |
-
|
403 |
-
function upgrade_strings() {
|
404 |
-
$this->strings['up_to_date'] = __('The plugin is at the latest version.');
|
405 |
-
$this->strings['no_package'] = __('Upgrade package not available.');
|
406 |
-
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
|
407 |
-
$this->strings['unpack_package'] = __('Unpacking the update…');
|
408 |
-
$this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
|
409 |
-
$this->strings['remove_old'] = __('Removing the old version of the plugin…');
|
410 |
-
$this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
|
411 |
-
$this->strings['process_failed'] = __('Plugin upgrade failed.');
|
412 |
-
$this->strings['process_success'] = __('Plugin upgraded successfully.');
|
413 |
-
}
|
414 |
-
|
415 |
-
function install_strings() {
|
416 |
-
$this->strings['no_package'] = __('Install package not available.');
|
417 |
-
$this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
|
418 |
-
$this->strings['unpack_package'] = __('Unpacking the package…');
|
419 |
-
$this->strings['installing_package'] = __('Installing the plugin…');
|
420 |
-
$this->strings['process_failed'] = __('Plugin install failed.');
|
421 |
-
$this->strings['process_success'] = __('Plugin installed successfully.');
|
422 |
-
}
|
423 |
-
|
424 |
-
function install($package) {
|
425 |
-
|
426 |
-
$this->init();
|
427 |
-
$this->install_strings();
|
428 |
-
|
429 |
-
$this->run(array(
|
430 |
-
'package' => $package,
|
431 |
-
'destination' => WP_PLUGIN_DIR,
|
432 |
-
'clear_destination' => false, //Do not overwrite files.
|
433 |
-
'clear_working' => true,
|
434 |
-
'hook_extra' => array()
|
435 |
-
));
|
436 |
-
|
437 |
-
// Force refresh of plugin update information
|
438 |
-
//$this->mmb_delete_transient('update_plugins');
|
439 |
-
|
440 |
-
}
|
441 |
-
|
442 |
-
function upgrade($plugin) {
|
443 |
-
|
444 |
-
$this->init();
|
445 |
-
$this->upgrade_strings();
|
446 |
-
|
447 |
-
$current = $this->mmb_get_transient( 'update_plugins' );
|
448 |
-
if ( !isset( $current->response[ $plugin ] ) ) {
|
449 |
-
$this->skin->before();
|
450 |
-
$this->skin->set_result(false);
|
451 |
-
$this->skin->error('up_to_date');
|
452 |
-
$this->skin->after();
|
453 |
-
return false;
|
454 |
-
}
|
455 |
-
|
456 |
-
// Get the URL to the zip file
|
457 |
-
$r = $current->response[ $plugin ];
|
458 |
-
|
459 |
-
add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
|
460 |
-
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
|
461 |
-
//'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
|
462 |
-
|
463 |
-
$this->run(array(
|
464 |
-
'package' => $r->package,
|
465 |
-
'destination' => WP_PLUGIN_DIR,
|
466 |
-
'clear_destination' => true,
|
467 |
-
'clear_working' => true,
|
468 |
-
'hook_extra' => array(
|
469 |
-
'plugin' => $plugin
|
470 |
-
)
|
471 |
-
));
|
472 |
-
|
473 |
-
// Cleanup our hooks, incase something else does a upgrade on this connection.
|
474 |
-
remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
|
475 |
-
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
|
476 |
-
|
477 |
-
if ( ! $this->result || is_wp_error($this->result) )
|
478 |
-
return $this->result;
|
479 |
-
|
480 |
-
// Force refresh of plugin update information
|
481 |
-
$this->mmb_delete_transient('update_plugins');
|
482 |
-
}
|
483 |
-
|
484 |
-
function bulk_upgrade($plugins) {
|
485 |
-
|
486 |
-
$this->init();
|
487 |
-
$this->bulk = true;
|
488 |
-
$this->upgrade_strings();
|
489 |
-
|
490 |
-
$current = $this->mmb_get_transient( 'update_plugins' );
|
491 |
-
|
492 |
-
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
|
493 |
-
|
494 |
-
$this->skin->header();
|
495 |
-
|
496 |
-
// Connect to the Filesystem first.
|
497 |
-
$res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
|
498 |
-
if ( ! $res ) {
|
499 |
-
$this->skin->footer();
|
500 |
-
return false;
|
501 |
-
}
|
502 |
-
|
503 |
-
$this->skin->bulk_header();
|
504 |
-
|
505 |
-
$this->maintenance_mode(true);
|
506 |
-
|
507 |
-
$results = array();
|
508 |
-
|
509 |
-
$this->update_count = count($plugins);
|
510 |
-
$this->update_current = 0;
|
511 |
-
foreach ( $plugins as $plugin ) {
|
512 |
-
$this->update_current++;
|
513 |
-
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
|
514 |
-
|
515 |
-
if ( !isset( $current->response[ $plugin ] ) ) {
|
516 |
-
$this->skin->set_result(false);
|
517 |
-
$this->skin->before();
|
518 |
-
$this->skin->error('up_to_date');
|
519 |
-
$this->skin->after();
|
520 |
-
$results[$plugin] = false;
|
521 |
-
continue;
|
522 |
-
}
|
523 |
-
|
524 |
-
// Get the URL to the zip file
|
525 |
-
$r = $current->response[ $plugin ];
|
526 |
-
|
527 |
-
$this->skin->plugin_active = is_plugin_active($plugin);
|
528 |
-
|
529 |
-
$result = $this->run(array(
|
530 |
-
'package' => $r->package,
|
531 |
-
'destination' => WP_PLUGIN_DIR,
|
532 |
-
'clear_destination' => true,
|
533 |
-
'clear_working' => true,
|
534 |
-
'is_multi' => true,
|
535 |
-
'hook_extra' => array(
|
536 |
-
'plugin' => $plugin
|
537 |
-
)
|
538 |
-
));
|
539 |
-
|
540 |
-
$results[$plugin] = $this->result;
|
541 |
-
|
542 |
-
// Prevent credentials auth screen from displaying multiple times
|
543 |
-
if ( false === $result )
|
544 |
-
break;
|
545 |
-
} //end foreach $plugins
|
546 |
-
|
547 |
-
$this->maintenance_mode(false);
|
548 |
-
|
549 |
-
$this->skin->bulk_footer();
|
550 |
-
|
551 |
-
$this->skin->footer();
|
552 |
-
|
553 |
-
// Cleanup our hooks, incase something else does a upgrade on this connection.
|
554 |
-
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
|
555 |
-
|
556 |
-
// Force refresh of plugin update information
|
557 |
-
$this->mmb_delete_transient('update_plugins');
|
558 |
-
|
559 |
-
return $results;
|
560 |
-
}
|
561 |
-
|
562 |
-
//return plugin info.
|
563 |
-
function plugin_info() {
|
564 |
-
if ( ! is_array($this->result) )
|
565 |
-
return false;
|
566 |
-
if ( empty($this->result['destination_name']) )
|
567 |
-
return false;
|
568 |
-
|
569 |
-
$plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
|
570 |
-
if ( empty($plugin) )
|
571 |
-
return false;
|
572 |
-
|
573 |
-
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
|
574 |
-
|
575 |
-
return $this->result['destination_name'] . '/' . $pluginfiles[0];
|
576 |
-
}
|
577 |
-
|
578 |
-
//Hooked to pre_install
|
579 |
-
function deactivate_plugin_before_upgrade($return, $plugin) {
|
580 |
-
|
581 |
-
if ( is_wp_error($return) ) //Bypass.
|
582 |
-
return $return;
|
583 |
-
|
584 |
-
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
|
585 |
-
if ( empty($plugin) )
|
586 |
-
return new WP_Error('bad_request', $this->strings['bad_request']);
|
587 |
-
|
588 |
-
if ( is_plugin_active($plugin) ) {
|
589 |
-
// $this->skin->feedback('deactivate_plugin');
|
590 |
-
//Deactivate the plugin silently, Prevent deactivation hooks from running.
|
591 |
-
deactivate_plugins($plugin, true);
|
592 |
-
}
|
593 |
-
}
|
594 |
-
|
595 |
-
//Hooked to upgrade_clear_destination
|
596 |
-
function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
|
597 |
-
global $wp_filesystem;
|
598 |
-
|
599 |
-
if ( is_wp_error($removed) )
|
600 |
-
return $removed; //Pass errors through.
|
601 |
-
|
602 |
-
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
|
603 |
-
if ( empty($plugin) )
|
604 |
-
return new WP_Error('bad_request', $this->strings['bad_request']);
|
605 |
-
|
606 |
-
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
607 |
-
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
|
608 |
-
|
609 |
-
if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
|
610 |
-
return $removed;
|
611 |
-
|
612 |
-
// If plugin is in its own directory, recursively delete the directory.
|
613 |
-
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
|
614 |
-
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
|
615 |
-
else
|
616 |
-
$deleted = $wp_filesystem->delete($plugins_dir . $plugin);
|
617 |
-
|
618 |
-
if ( ! $deleted )
|
619 |
-
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
|
620 |
-
|
621 |
-
return $removed;
|
622 |
-
}
|
623 |
-
}
|
624 |
-
|
625 |
-
/**
|
626 |
-
* Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
|
627 |
-
*
|
628 |
-
* @TODO More Detailed docs, for methods as well.
|
629 |
-
*
|
630 |
-
* @package WordPress
|
631 |
-
* @subpackage Upgrader
|
632 |
-
* @since 2.8.0
|
633 |
-
*/
|
634 |
-
class Mmb_Theme_Upgrader extends Mmb_upgrader {
|
635 |
-
|
636 |
-
var $result;
|
637 |
-
|
638 |
-
function upgrade_strings() {
|
639 |
-
$this->strings['up_to_date'] = __('The theme is at the latest version.');
|
640 |
-
$this->strings['no_package'] = __('Upgrade package not available.');
|
641 |
-
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
|
642 |
-
$this->strings['unpack_package'] = __('Unpacking the update…');
|
643 |
-
$this->strings['remove_old'] = __('Removing the old version of the theme…');
|
644 |
-
$this->strings['remove_old_failed'] = __('Could not remove the old theme.');
|
645 |
-
$this->strings['process_failed'] = __('Theme upgrade failed.');
|
646 |
-
$this->strings['process_success'] = __('Theme upgraded successfully.');
|
647 |
-
}
|
648 |
-
|
649 |
-
function install_strings() {
|
650 |
-
$this->strings['no_package'] = __('Install package not available.');
|
651 |
-
$this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
|
652 |
-
$this->strings['unpack_package'] = __('Unpacking the package…');
|
653 |
-
$this->strings['installing_package'] = __('Installing the theme…');
|
654 |
-
$this->strings['process_failed'] = __('Theme install failed.');
|
655 |
-
$this->strings['process_success'] = __('Theme installed successfully.');
|
656 |
-
}
|
657 |
-
|
658 |
-
function install($package) {
|
659 |
-
|
660 |
-
$this->init();
|
661 |
-
$this->install_strings();
|
662 |
-
|
663 |
-
$options = array(
|
664 |
-
'package' => $package,
|
665 |
-
'destination' => WP_CONTENT_DIR . '/themes',
|
666 |
-
'clear_destination' => false, //Do not overwrite files.
|
667 |
-
'clear_working' => true
|
668 |
-
);
|
669 |
-
|
670 |
-
$this->run($options);
|
671 |
-
|
672 |
-
if ( ! $this->result || is_wp_error($this->result) )
|
673 |
-
return $this->result;
|
674 |
-
|
675 |
-
// Force refresh of theme update information
|
676 |
-
$this->mmb_delete_transient('update_themes');
|
677 |
-
|
678 |
-
if ( empty($result['destination_name']) )
|
679 |
-
return false;
|
680 |
-
else
|
681 |
-
return $result['destination_name'];
|
682 |
-
}
|
683 |
-
|
684 |
-
function upgrade($theme) {
|
685 |
-
|
686 |
-
$this->init();
|
687 |
-
$this->upgrade_strings();
|
688 |
-
|
689 |
-
// Is an update available?
|
690 |
-
$current = $this->mmb_get_transient( 'update_themes' );
|
691 |
-
if ( !isset( $current->response[ $theme ] ) ) {
|
692 |
-
$this->skin->before();
|
693 |
-
$this->skin->set_result(false);
|
694 |
-
$this->skin->error('up_to_date');
|
695 |
-
$this->skin->after();
|
696 |
-
return false;
|
697 |
-
}
|
698 |
-
|
699 |
-
$r = $current->response[ $theme ];
|
700 |
-
|
701 |
-
add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
|
702 |
-
add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
|
703 |
-
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
|
704 |
-
|
705 |
-
$options = array(
|
706 |
-
'package' => $r['package'],
|
707 |
-
'destination' => WP_CONTENT_DIR . '/themes',
|
708 |
-
'clear_destination' => true,
|
709 |
-
'clear_working' => true,
|
710 |
-
'hook_extra' => array(
|
711 |
-
'theme' => $theme
|
712 |
-
)
|
713 |
-
);
|
714 |
-
|
715 |
-
$this->run($options);
|
716 |
-
|
717 |
-
if ( ! $this->result || is_wp_error($this->result) )
|
718 |
-
return $this->result;
|
719 |
-
|
720 |
-
// Force refresh of theme update information
|
721 |
-
$this->mmb_delete_transient('update_themes');
|
722 |
-
|
723 |
-
return true;
|
724 |
-
}
|
725 |
-
|
726 |
-
function bulk_upgrade($themes) {
|
727 |
-
|
728 |
-
$this->init();
|
729 |
-
$this->bulk = true;
|
730 |
-
$this->upgrade_strings();
|
731 |
-
|
732 |
-
$current = $this->mmb_get_transient( 'update_themes' );
|
733 |
-
|
734 |
-
add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
|
735 |
-
add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
|
736 |
-
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
|
737 |
-
|
738 |
-
$this->skin->header();
|
739 |
-
|
740 |
-
// Connect to the Filesystem first.
|
741 |
-
$res = $this->fs_connect( array(WP_CONTENT_DIR) );
|
742 |
-
if ( ! $res ) {
|
743 |
-
$this->skin->footer();
|
744 |
-
return false;
|
745 |
-
}
|
746 |
-
|
747 |
-
$this->skin->bulk_header();
|
748 |
-
|
749 |
-
$this->maintenance_mode(true);
|
750 |
-
|
751 |
-
$results = array();
|
752 |
-
|
753 |
-
$this->update_count = count($themes);
|
754 |
-
$this->update_current = 0;
|
755 |
-
foreach ( $themes as $theme ) {
|
756 |
-
$this->update_current++;
|
757 |
-
|
758 |
-
if ( !isset( $current->response[ $theme ] ) ) {
|
759 |
-
$this->skin->set_result(false);
|
760 |
-
$this->skin->before();
|
761 |
-
$this->skin->error('up_to_date');
|
762 |
-
$this->skin->after();
|
763 |
-
$results[$theme] = false;
|
764 |
-
continue;
|
765 |
-
}
|
766 |
-
|
767 |
-
$this->skin->theme_info = $this->theme_info($theme);
|
768 |
-
|
769 |
-
// Get the URL to the zip file
|
770 |
-
$r = $current->response[ $theme ];
|
771 |
-
|
772 |
-
$options = array(
|
773 |
-
'package' => $r['package'],
|
774 |
-
'destination' => WP_CONTENT_DIR . '/themes',
|
775 |
-
'clear_destination' => true,
|
776 |
-
'clear_working' => true,
|
777 |
-
'hook_extra' => array(
|
778 |
-
'theme' => $theme
|
779 |
-
)
|
780 |
-
);
|
781 |
-
|
782 |
-
$result = $this->run($options);
|
783 |
-
|
784 |
-
$results[$theme] = $this->result;
|
785 |
-
|
786 |
-
// Prevent credentials auth screen from displaying multiple times
|
787 |
-
if ( false === $result )
|
788 |
-
break;
|
789 |
-
} //end foreach $plugins
|
790 |
-
|
791 |
-
$this->maintenance_mode(false);
|
792 |
-
|
793 |
-
$this->skin->bulk_footer();
|
794 |
-
|
795 |
-
$this->skin->footer();
|
796 |
-
|
797 |
-
// Cleanup our hooks, incase something else does a upgrade on this connection.
|
798 |
-
remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
|
799 |
-
remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
|
800 |
-
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
|
801 |
-
|
802 |
-
// Force refresh of theme update information
|
803 |
-
$this->mmb_delete_transient('update_themes');
|
804 |
-
|
805 |
-
return $results;
|
806 |
-
}
|
807 |
-
|
808 |
-
function current_before($return, $theme) {
|
809 |
-
|
810 |
-
if ( is_wp_error($return) )
|
811 |
-
return $return;
|
812 |
-
|
813 |
-
$theme = isset($theme['theme']) ? $theme['theme'] : '';
|
814 |
-
|
815 |
-
if ( $theme != get_stylesheet() ) //If not current
|
816 |
-
return $return;
|
817 |
-
//Change to maintainence mode now.
|
818 |
-
if ( ! $this->bulk )
|
819 |
-
$this->maintenance_mode(true);
|
820 |
-
|
821 |
-
return $return;
|
822 |
-
}
|
823 |
-
function current_after($return, $theme) {
|
824 |
-
if ( is_wp_error($return) )
|
825 |
-
return $return;
|
826 |
-
|
827 |
-
$theme = isset($theme['theme']) ? $theme['theme'] : '';
|
828 |
-
|
829 |
-
if ( $theme != get_stylesheet() ) //If not current
|
830 |
-
return $return;
|
831 |
-
|
832 |
-
//Ensure stylesheet name hasnt changed after the upgrade:
|
833 |
-
if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
|
834 |
-
$theme_info = $this->theme_info();
|
835 |
-
$stylesheet = $this->result['destination_name'];
|
836 |
-
$template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
|
837 |
-
switch_theme($template, $stylesheet, true);
|
838 |
-
}
|
839 |
-
|
840 |
-
//Time to remove maintainence mode
|
841 |
-
if ( ! $this->bulk )
|
842 |
-
$this->maintenance_mode(false);
|
843 |
-
return $return;
|
844 |
-
}
|
845 |
-
|
846 |
-
function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
|
847 |
-
global $wp_filesystem;
|
848 |
-
|
849 |
-
$theme = isset($theme['theme']) ? $theme['theme'] : '';
|
850 |
-
|
851 |
-
if ( is_wp_error($removed) || empty($theme) )
|
852 |
-
return $removed; //Pass errors through.
|
853 |
-
|
854 |
-
$themes_dir = $wp_filesystem->wp_themes_dir();
|
855 |
-
if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
|
856 |
-
if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
|
857 |
-
return false;
|
858 |
-
return true;
|
859 |
-
}
|
860 |
-
|
861 |
-
function theme_info($theme = null) {
|
862 |
-
|
863 |
-
if ( empty($theme) ) {
|
864 |
-
if ( !empty($this->result['destination_name']) )
|
865 |
-
$theme = $this->result['destination_name'];
|
866 |
-
else
|
867 |
-
return false;
|
868 |
-
}
|
869 |
-
return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
|
870 |
-
}
|
871 |
-
|
872 |
-
}
|
873 |
-
|
874 |
-
/**
|
875 |
-
* Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
|
876 |
-
*
|
877 |
-
* @TODO More Detailed docs, for methods as well.
|
878 |
-
*
|
879 |
-
* @package WordPress
|
880 |
-
* @subpackage Upgrader
|
881 |
-
* @since 2.8.0
|
882 |
-
*/
|
883 |
-
class Mmb_Core_Upgrader extends Mmb_upgrader {
|
884 |
-
|
885 |
-
function upgrade_strings() {
|
886 |
-
$this->strings['up_to_date'] = __('WordPress is at the latest version.');
|
887 |
-
$this->strings['no_package'] = __('Upgrade package not available.');
|
888 |
-
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
|
889 |
-
$this->strings['unpack_package'] = __('Unpacking the update…');
|
890 |
-
$this->strings['copy_failed'] = __('Could not copy files.');
|
891 |
-
}
|
892 |
-
|
893 |
-
function upgrade($current) {
|
894 |
-
global $wp_filesystem;
|
895 |
-
|
896 |
-
$this->init();
|
897 |
-
$this->upgrade_strings();
|
898 |
-
|
899 |
-
if ( !empty($feedback) )
|
900 |
-
add_filter('update_feedback', $feedback);
|
901 |
-
|
902 |
-
// Is an update available?
|
903 |
-
if ( !isset( $current->response ) || $current->response == 'latest' )
|
904 |
-
return new WP_Error('up_to_date', $this->strings['up_to_date']);
|
905 |
-
|
906 |
-
$res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
|
907 |
-
if ( is_wp_error($res) )
|
908 |
-
return $res;
|
909 |
-
|
910 |
-
$wp_dir = trailingslashit($wp_filesystem->abspath());
|
911 |
-
|
912 |
-
$download = $this->download_package( $current->package );
|
913 |
-
if ( is_wp_error($download) )
|
914 |
-
return $download;
|
915 |
-
|
916 |
-
$working_dir = $this->unpack_package( $download );
|
917 |
-
if ( is_wp_error($working_dir) )
|
918 |
-
return $working_dir;
|
919 |
-
|
920 |
-
// Copy update-core.php from the new version into place.
|
921 |
-
if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
|
922 |
-
$wp_filesystem->delete($working_dir, true);
|
923 |
-
return new WP_Error('copy_failed', $this->strings['copy_failed']);
|
924 |
-
}
|
925 |
-
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
|
926 |
-
|
927 |
-
require(ABSPATH . 'wp-admin/includes/update-core.php');
|
928 |
-
|
929 |
-
return update_core($working_dir, $wp_dir);
|
930 |
-
}
|
931 |
-
|
932 |
-
}
|
933 |
-
|
934 |
-
/**
|
935 |
-
* Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
|
936 |
-
*
|
937 |
-
* @TODO More Detailed docs, for methods as well.
|
938 |
-
*
|
939 |
-
* @package WordPress
|
940 |
-
* @subpackage Upgrader
|
941 |
-
* @since 2.8.0
|
942 |
-
*/
|
943 |
-
class Mmb_upgrader_Skin {
|
944 |
-
|
945 |
-
var $upgrader;
|
946 |
-
var $done_header = false;
|
947 |
-
var $result = false;
|
948 |
-
|
949 |
-
function Mmb_upgrader_Skin($args = array()) {
|
950 |
-
return $this->__construct($args);
|
951 |
-
}
|
952 |
-
function __construct($args = array()) {
|
953 |
-
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
|
954 |
-
$this->options = wp_parse_args($args, $defaults);
|
955 |
-
}
|
956 |
-
|
957 |
-
function set_upgrader(&$upgrader) {
|
958 |
-
if ( is_object($upgrader) )
|
959 |
-
$this->upgrader =& $upgrader;
|
960 |
-
$this->add_strings();
|
961 |
-
}
|
962 |
-
|
963 |
-
function add_strings() {
|
964 |
-
}
|
965 |
-
|
966 |
-
function set_result($result) {
|
967 |
-
$this->result = $result;
|
968 |
-
}
|
969 |
-
|
970 |
-
function request_filesystem_credentials($error = false) {
|
971 |
-
$url = $this->options['url'];
|
972 |
-
$context = $this->options['context'];
|
973 |
-
if ( !empty($this->options['nonce']) )
|
974 |
-
$url = wp_nonce_url($url, $this->options['nonce']);
|
975 |
-
return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
|
976 |
-
}
|
977 |
-
|
978 |
-
function header() {
|
979 |
-
if ( $this->done_header )
|
980 |
-
return;
|
981 |
-
$this->done_header = true;
|
982 |
-
echo '<div class="wrap">';
|
983 |
-
echo screen_icon();
|
984 |
-
echo '<h2>' . $this->options['title'] . '</h2>';
|
985 |
-
}
|
986 |
-
function footer() {
|
987 |
-
echo '</div>';
|
988 |
-
}
|
989 |
-
|
990 |
-
function error($errors) {
|
991 |
-
if ( ! $this->done_header )
|
992 |
-
$this->header();
|
993 |
-
if ( is_string($errors) ) {
|
994 |
-
// $this->feedback($errors);
|
995 |
-
} elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
|
996 |
-
// foreach ( $errors->get_error_messages() as $message ) {
|
997 |
-
// if ( $errors->get_error_data() )
|
998 |
-
// $this->feedback($message . ' ' . $errors->get_error_data() );
|
999 |
-
// else
|
1000 |
-
// $this->feedback($message);
|
1001 |
-
// }
|
1002 |
-
}
|
1003 |
-
}
|
1004 |
-
|
1005 |
-
function feedback($string) {
|
1006 |
-
if ( isset( $this->upgrader->strings[$string] ) )
|
1007 |
-
$string = $this->upgrader->strings[$string];
|
1008 |
-
|
1009 |
-
if ( strpos($string, '%') !== false ) {
|
1010 |
-
$args = func_get_args();
|
1011 |
-
$args = array_splice($args, 1);
|
1012 |
-
if ( !empty($args) )
|
1013 |
-
$string = vsprintf($string, $args);
|
1014 |
-
}
|
1015 |
-
if ( empty($string) )
|
1016 |
-
return;
|
1017 |
-
show_message($string);
|
1018 |
-
}
|
1019 |
-
function before() {}
|
1020 |
-
function after() {}
|
1021 |
-
|
1022 |
-
}
|
1023 |
-
|
1024 |
-
/**
|
1025 |
-
* Plugin Upgrader Skin for WordPress Plugin Upgrades.
|
1026 |
-
*
|
1027 |
-
* @TODO More Detailed docs, for methods as well.
|
1028 |
-
*
|
1029 |
-
* @package WordPress
|
1030 |
-
* @subpackage Upgrader
|
1031 |
-
* @since 2.8.0
|
1032 |
-
*/
|
1033 |
-
class Mmb_Plugin_Upgrader_Skin extends Mmb_upgrader_Skin {
|
1034 |
-
var $plugin = '';
|
1035 |
-
var $plugin_active = false;
|
1036 |
-
var $plugin_network_active = false;
|
1037 |
-
|
1038 |
-
function Mmb_Plugin_Upgrader_Skin($args = array()) {
|
1039 |
-
return $this->__construct($args);
|
1040 |
-
}
|
1041 |
-
|
1042 |
-
function __construct($args = array()) {
|
1043 |
-
$defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Upgrade Plugin') );
|
1044 |
-
$args = wp_parse_args($args, $defaults);
|
1045 |
-
|
1046 |
-
$this->plugin = $args['plugin'];
|
1047 |
-
|
1048 |
-
$this->plugin_active = is_plugin_active( $this->plugin );
|
1049 |
-
$this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
|
1050 |
-
|
1051 |
-
parent::__construct($args);
|
1052 |
-
}
|
1053 |
-
|
1054 |
-
function after() {
|
1055 |
-
$this->plugin = $this->upgrader->plugin_info();
|
1056 |
-
if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
|
1057 |
-
show_message(__('Reactivating the plugin…'));
|
1058 |
-
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
|
1059 |
-
}
|
1060 |
-
|
1061 |
-
$update_actions = array(
|
1062 |
-
'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
|
1063 |
-
'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
|
1064 |
-
);
|
1065 |
-
if ( $this->plugin_active )
|
1066 |
-
unset( $update_actions['activate_plugin'] );
|
1067 |
-
if ( ! $this->result || is_wp_error($this->result) )
|
1068 |
-
unset( $update_actions['activate_plugin'] );
|
1069 |
-
|
1070 |
-
$update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
|
1071 |
-
// if ( ! empty($update_actions) )
|
1072 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
|
1073 |
-
}
|
1074 |
-
|
1075 |
-
function before() {
|
1076 |
-
if ( $this->upgrader->show_before ) {
|
1077 |
-
echo $this->upgrader->show_before;
|
1078 |
-
$this->upgrader->show_before = '';
|
1079 |
-
}
|
1080 |
-
}
|
1081 |
-
}
|
1082 |
-
|
1083 |
-
/**
|
1084 |
-
* Plugin Upgrader Skin for WordPress Plugin Upgrades.
|
1085 |
-
*
|
1086 |
-
* @package WordPress
|
1087 |
-
* @subpackage Upgrader
|
1088 |
-
* @since 3.0.0
|
1089 |
-
*/
|
1090 |
-
class Mmb_Bulk_Upgrader_Skin extends Mmb_upgrader_Skin {
|
1091 |
-
var $in_loop = false;
|
1092 |
-
var $error = false;
|
1093 |
-
|
1094 |
-
function Bulk_Upgrader_Skin($args = array()) {
|
1095 |
-
return $this->__construct($args);
|
1096 |
-
}
|
1097 |
-
|
1098 |
-
function __construct($args = array()) {
|
1099 |
-
$defaults = array( 'url' => '', 'nonce' => '' );
|
1100 |
-
$args = wp_parse_args($args, $defaults);
|
1101 |
-
|
1102 |
-
parent::__construct($args);
|
1103 |
-
}
|
1104 |
-
|
1105 |
-
function add_strings() {
|
1106 |
-
$this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take awhile on some hosts, so please be patient.');
|
1107 |
-
$this->upgrader->strings['skin_update_failed_error'] = __('An error occured while updating %1$s: <strong>%2$s</strong>.');
|
1108 |
-
$this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
|
1109 |
-
$this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>';
|
1110 |
-
$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
|
1111 |
-
}
|
1112 |
-
|
1113 |
-
function feedback($string) {
|
1114 |
-
if ( isset( $this->upgrader->strings[$string] ) )
|
1115 |
-
$string = $this->upgrader->strings[$string];
|
1116 |
-
|
1117 |
-
if ( strpos($string, '%') !== false ) {
|
1118 |
-
$args = func_get_args();
|
1119 |
-
$args = array_splice($args, 1);
|
1120 |
-
if ( !empty($args) )
|
1121 |
-
$string = vsprintf($string, $args);
|
1122 |
-
}
|
1123 |
-
if ( empty($string) )
|
1124 |
-
return;
|
1125 |
-
if ( $this->in_loop )
|
1126 |
-
echo "$string<br />\n";
|
1127 |
-
else
|
1128 |
-
echo "<p>$string</p>\n";
|
1129 |
-
}
|
1130 |
-
|
1131 |
-
function header() {
|
1132 |
-
// Nothing, This will be displayed within a iframe.
|
1133 |
-
}
|
1134 |
-
|
1135 |
-
function footer() {
|
1136 |
-
// Nothing, This will be displayed within a iframe.
|
1137 |
-
}
|
1138 |
-
function error($error) {
|
1139 |
-
if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
|
1140 |
-
$this->error = $this->upgrader->strings[$error];
|
1141 |
-
|
1142 |
-
if ( is_wp_error($error) ) {
|
1143 |
-
foreach ( $error->get_error_messages() as $emessage ) {
|
1144 |
-
if ( $error->get_error_data() )
|
1145 |
-
$messages[] = $emessage . ' ' . $error->get_error_data();
|
1146 |
-
else
|
1147 |
-
$messages[] = $emessage;
|
1148 |
-
}
|
1149 |
-
$this->error = implode(', ', $messages);
|
1150 |
-
}
|
1151 |
-
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
|
1152 |
-
}
|
1153 |
-
|
1154 |
-
function bulk_header() {
|
1155 |
-
// $this->feedback('skin_upgrade_start');
|
1156 |
-
}
|
1157 |
-
|
1158 |
-
function bulk_footer() {
|
1159 |
-
// $this->feedback('skin_upgrade_end');
|
1160 |
-
}
|
1161 |
-
|
1162 |
-
function before($title = '') {
|
1163 |
-
$this->in_loop = true;
|
1164 |
-
printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <img alt="" src="' . admin_url( 'images/wpspin_light.gif' ) . '" class="hidden waiting-' . $this->upgrader->update_current . '" style="vertical-align:middle;"></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
|
1165 |
-
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
|
1166 |
-
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
|
1167 |
-
$this->flush_output();
|
1168 |
-
}
|
1169 |
-
|
1170 |
-
function after($title = '') {
|
1171 |
-
echo '</p></div>';
|
1172 |
-
if ( $this->error || ! $this->result ) {
|
1173 |
-
if ( $this->error )
|
1174 |
-
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
|
1175 |
-
else
|
1176 |
-
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
|
1177 |
-
|
1178 |
-
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
|
1179 |
-
}
|
1180 |
-
if ( !empty($this->result) && !is_wp_error($this->result) ) {
|
1181 |
-
echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
|
1182 |
-
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
|
1183 |
-
}
|
1184 |
-
|
1185 |
-
$this->reset();
|
1186 |
-
$this->flush_output();
|
1187 |
-
}
|
1188 |
-
|
1189 |
-
function reset() {
|
1190 |
-
$this->in_loop = false;
|
1191 |
-
$this->error = false;
|
1192 |
-
}
|
1193 |
-
|
1194 |
-
function flush_output() {
|
1195 |
-
wp_ob_end_flush_all();
|
1196 |
-
flush();
|
1197 |
-
}
|
1198 |
-
}
|
1199 |
-
|
1200 |
-
class Mmb_Bulk_Plugin_Upgrader_Skin extends Mmb_Bulk_Upgrader_Skin {
|
1201 |
-
var $plugin_info = array(); // Mmb_Plugin_Upgrader::bulk() will fill this in.
|
1202 |
-
function Mmb_Plugin_Upgrader_Skin($args = array()) {
|
1203 |
-
parent::__construct($args);
|
1204 |
-
}
|
1205 |
-
|
1206 |
-
function add_strings() {
|
1207 |
-
parent::add_strings();
|
1208 |
-
$this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
|
1209 |
-
}
|
1210 |
-
|
1211 |
-
function before() {
|
1212 |
-
parent::before($this->plugin_info['Title']);
|
1213 |
-
}
|
1214 |
-
|
1215 |
-
function after() {
|
1216 |
-
parent::after($this->plugin_info['Title']);
|
1217 |
-
}
|
1218 |
-
function bulk_footer() {
|
1219 |
-
parent::bulk_footer();
|
1220 |
-
$update_actions = array(
|
1221 |
-
'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
|
1222 |
-
'updates_page' => '<a href="' . admin_url('update-core.php') . '" title="' . esc_attr__('Goto WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
|
1223 |
-
);
|
1224 |
-
|
1225 |
-
$update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
|
1226 |
-
// if ( ! empty($update_actions) )
|
1227 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
|
1228 |
-
}
|
1229 |
-
}
|
1230 |
-
|
1231 |
-
class Mmb_Bulk_Theme_Upgrader_Skin extends Mmb_Bulk_Upgrader_Skin {
|
1232 |
-
var $theme_info = array(); // Mmb_Theme_Upgrader::bulk() will fill this in.
|
1233 |
-
function Mmb_Theme_Upgrader_Skin($args = array()) {
|
1234 |
-
parent::__construct($args);
|
1235 |
-
}
|
1236 |
-
|
1237 |
-
function add_strings() {
|
1238 |
-
parent::add_strings();
|
1239 |
-
$this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
|
1240 |
-
}
|
1241 |
-
|
1242 |
-
function before() {
|
1243 |
-
parent::before($this->theme_info['Name']);
|
1244 |
-
}
|
1245 |
-
|
1246 |
-
function after() {
|
1247 |
-
parent::after($this->theme_info['Name']);
|
1248 |
-
}
|
1249 |
-
function bulk_footer() {
|
1250 |
-
parent::bulk_footer();
|
1251 |
-
$update_actions = array(
|
1252 |
-
'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Goto themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
|
1253 |
-
'updates_page' => '<a href="' . admin_url('update-core.php') . '" title="' . esc_attr__('Goto WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
|
1254 |
-
);
|
1255 |
-
|
1256 |
-
$update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
|
1257 |
-
// if ( ! empty($update_actions) )
|
1258 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
|
1259 |
-
}
|
1260 |
-
}
|
1261 |
-
|
1262 |
-
/**
|
1263 |
-
* Plugin Installer Skin for WordPress Plugin Installer.
|
1264 |
-
*
|
1265 |
-
* @TODO More Detailed docs, for methods as well.
|
1266 |
-
*
|
1267 |
-
* @package WordPress
|
1268 |
-
* @subpackage Upgrader
|
1269 |
-
* @since 2.8.0
|
1270 |
-
*/
|
1271 |
-
class Mmb_Plugin_Installer_Skin extends Mmb_upgrader_Skin {
|
1272 |
-
var $api;
|
1273 |
-
var $type;
|
1274 |
-
|
1275 |
-
function Plugin_Installer_Skin($args = array()) {
|
1276 |
-
return $this->__construct($args);
|
1277 |
-
}
|
1278 |
-
|
1279 |
-
function __construct($args = array()) {
|
1280 |
-
$defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
|
1281 |
-
$args = wp_parse_args($args, $defaults);
|
1282 |
-
|
1283 |
-
$this->type = $args['type'];
|
1284 |
-
$this->api = isset($args['api']) ? $args['api'] : array();
|
1285 |
-
|
1286 |
-
parent::__construct($args);
|
1287 |
-
}
|
1288 |
-
|
1289 |
-
function before() {
|
1290 |
-
if ( !empty($this->api) )
|
1291 |
-
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
|
1292 |
-
}
|
1293 |
-
|
1294 |
-
function after() {
|
1295 |
-
|
1296 |
-
$plugin_file = $this->upgrader->plugin_info();
|
1297 |
-
|
1298 |
-
$install_actions = array();
|
1299 |
-
|
1300 |
-
$from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
|
1301 |
-
|
1302 |
-
if ( 'import' == $from )
|
1303 |
-
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>';
|
1304 |
-
else
|
1305 |
-
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
|
1306 |
-
|
1307 |
-
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
|
1308 |
-
$install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
|
1309 |
-
|
1310 |
-
if ( 'import' == $from )
|
1311 |
-
$install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
|
1312 |
-
else if ( $this->type == 'web' )
|
1313 |
-
$install_actions['plugins_page'] = '<a href="' . admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
|
1314 |
-
else
|
1315 |
-
$install_actions['plugins_page'] = '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
|
1316 |
-
|
1317 |
-
|
1318 |
-
if ( ! $this->result || is_wp_error($this->result) ) {
|
1319 |
-
unset( $install_actions['activate_plugin'] );
|
1320 |
-
unset( $install_actions['network_activate'] );
|
1321 |
-
}
|
1322 |
-
$install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
|
1323 |
-
// if ( ! empty($install_actions) )
|
1324 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
|
1325 |
-
}
|
1326 |
-
}
|
1327 |
-
|
1328 |
-
/**
|
1329 |
-
* Theme Installer Skin for the WordPress Theme Installer.
|
1330 |
-
*
|
1331 |
-
* @TODO More Detailed docs, for methods as well.
|
1332 |
-
*
|
1333 |
-
* @package WordPress
|
1334 |
-
* @subpackage Upgrader
|
1335 |
-
* @since 2.8.0
|
1336 |
-
*/
|
1337 |
-
class Mmb_Theme_Installer_Skin extends Mmb_upgrader_Skin {
|
1338 |
-
var $api;
|
1339 |
-
var $type;
|
1340 |
-
|
1341 |
-
function Theme_Installer_Skin($args = array()) {
|
1342 |
-
return $this->__construct($args);
|
1343 |
-
}
|
1344 |
-
|
1345 |
-
function __construct($args = array()) {
|
1346 |
-
$defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
|
1347 |
-
$args = wp_parse_args($args, $defaults);
|
1348 |
-
|
1349 |
-
$this->type = $args['type'];
|
1350 |
-
$this->api = isset($args['api']) ? $args['api'] : array();
|
1351 |
-
|
1352 |
-
parent::__construct($args);
|
1353 |
-
}
|
1354 |
-
|
1355 |
-
function before() {
|
1356 |
-
if ( !empty($this->api) ) {
|
1357 |
-
/* translators: 1: theme name, 2: version */
|
1358 |
-
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
|
1359 |
-
}
|
1360 |
-
}
|
1361 |
-
|
1362 |
-
function after() {
|
1363 |
-
if ( empty($this->upgrader->result['destination_name']) )
|
1364 |
-
return;
|
1365 |
-
|
1366 |
-
$theme_info = $this->upgrader->theme_info();
|
1367 |
-
if ( empty($theme_info) )
|
1368 |
-
return;
|
1369 |
-
$name = $theme_info['Name'];
|
1370 |
-
$stylesheet = $this->upgrader->result['destination_name'];
|
1371 |
-
$template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
|
1372 |
-
|
1373 |
-
$preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
|
1374 |
-
$activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
|
1375 |
-
|
1376 |
-
$install_actions = array(
|
1377 |
-
'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>',
|
1378 |
-
'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
|
1379 |
-
);
|
1380 |
-
|
1381 |
-
if ( $this->type == 'web' )
|
1382 |
-
$install_actions['themes_page'] = '<a href="' . admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>';
|
1383 |
-
else
|
1384 |
-
$install_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
|
1385 |
-
|
1386 |
-
if ( ! $this->result || is_wp_error($this->result) )
|
1387 |
-
unset( $install_actions['activate'], $install_actions['preview'] );
|
1388 |
-
|
1389 |
-
$install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
|
1390 |
-
// if ( ! empty($install_actions) )
|
1391 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
|
1392 |
-
}
|
1393 |
-
}
|
1394 |
-
|
1395 |
-
/**
|
1396 |
-
* Theme Upgrader Skin for WordPress Theme Upgrades.
|
1397 |
-
*
|
1398 |
-
* @TODO More Detailed docs, for methods as well.
|
1399 |
-
*
|
1400 |
-
* @package WordPress
|
1401 |
-
* @subpackage Upgrader
|
1402 |
-
* @since 2.8.0
|
1403 |
-
*/
|
1404 |
-
class Mmb_Theme_Upgrader_Skin extends Mmb_upgrader_Skin {
|
1405 |
-
var $theme = '';
|
1406 |
-
|
1407 |
-
function Mmb_Theme_Upgrader_Skin($args = array()) {
|
1408 |
-
return $this->__construct($args);
|
1409 |
-
}
|
1410 |
-
|
1411 |
-
function __construct($args = array()) {
|
1412 |
-
$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Upgrade Theme') );
|
1413 |
-
$args = wp_parse_args($args, $defaults);
|
1414 |
-
|
1415 |
-
$this->theme = $args['theme'];
|
1416 |
-
|
1417 |
-
parent::__construct($args);
|
1418 |
-
}
|
1419 |
-
|
1420 |
-
function after() {
|
1421 |
-
|
1422 |
-
$update_actions = array();
|
1423 |
-
if ( !empty($this->upgrader->result['destination_name']) &&
|
1424 |
-
($theme_info = $this->upgrader->theme_info()) &&
|
1425 |
-
!empty($theme_info) ) {
|
1426 |
-
|
1427 |
-
$name = $theme_info['Name'];
|
1428 |
-
$stylesheet = $this->upgrader->result['destination_name'];
|
1429 |
-
$template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
|
1430 |
-
|
1431 |
-
$preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
|
1432 |
-
$activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
|
1433 |
-
|
1434 |
-
$update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>';
|
1435 |
-
$update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
|
1436 |
-
|
1437 |
-
if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
|
1438 |
-
unset($update_actions['preview'], $update_actions['activate']);
|
1439 |
-
}
|
1440 |
-
|
1441 |
-
$update_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
|
1442 |
-
|
1443 |
-
$update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
|
1444 |
-
// if ( ! empty($update_actions) )
|
1445 |
-
// $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
|
1446 |
-
}
|
1447 |
-
}
|
1448 |
-
|
1449 |
-
/**
|
1450 |
-
* Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions.
|
1451 |
-
*
|
1452 |
-
* @TODO More Detailed docs, for methods as well.
|
1453 |
-
*
|
1454 |
-
* @package WordPress
|
1455 |
-
* @subpackage Upgrader
|
1456 |
-
* @since 2.8.0
|
1457 |
-
*/
|
1458 |
-
class Mmb_File_Upload_Upgrader {
|
1459 |
-
var $package;
|
1460 |
-
var $filename;
|
1461 |
-
|
1462 |
-
function File_Upload_Upgrader($form, $urlholder) {
|
1463 |
-
return $this->__construct($form, $urlholder);
|
1464 |
-
}
|
1465 |
-
function __construct($form, $urlholder) {
|
1466 |
-
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
|
1467 |
-
wp_die($uploads['error']);
|
1468 |
-
|
1469 |
-
if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
|
1470 |
-
wp_die(__('Please select a file'));
|
1471 |
-
|
1472 |
-
if ( !empty($_FILES) )
|
1473 |
-
$this->filename = $_FILES[$form]['name'];
|
1474 |
-
else if ( isset($_GET[$urlholder]) )
|
1475 |
-
$this->filename = $_GET[$urlholder];
|
1476 |
-
|
1477 |
-
//Handle a newly uploaded file, Else assume its already been uploaded
|
1478 |
-
if ( !empty($_FILES) ) {
|
1479 |
-
$this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
|
1480 |
-
$this->package = $uploads['basedir'] . '/' . $this->filename;
|
1481 |
-
|
1482 |
-
// Move the file to the uploads dir
|
1483 |
-
if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
|
1484 |
-
wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
|
1485 |
-
} else {
|
1486 |
-
$this->package = $uploads['basedir'] . '/' . $this->filename;
|
1487 |
-
}
|
1488 |
-
}
|
1489 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page.class.php
DELETED
@@ -1,259 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mmb_Page extends Mmb_Core
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
/*************************************************************
|
11 |
-
* FACADE functions
|
12 |
-
* (functions to be called after a remote XMLRPC from Master)
|
13 |
-
**************************************************************/
|
14 |
-
function get_edit_data($args)
|
15 |
-
{
|
16 |
-
$this->_escape($args);
|
17 |
-
$username = $args[0];
|
18 |
-
$password = $args[1];
|
19 |
-
$page_id = $args[2];
|
20 |
-
|
21 |
-
if (!$user = $this->login($username, $password))
|
22 |
-
{
|
23 |
-
return $this->error;
|
24 |
-
}
|
25 |
-
|
26 |
-
if (!current_user_can('edit_page', $page_id))
|
27 |
-
return new IXR_Error(401, 'You are not allowed to edit this page.');
|
28 |
-
|
29 |
-
$tmp_pages = get_pages("exclude=$page_id");
|
30 |
-
|
31 |
-
|
32 |
-
// trim off redundant data
|
33 |
-
$parents = array();
|
34 |
-
foreach ($tmp_pages as $tmp_page)
|
35 |
-
{
|
36 |
-
$parents[] = array(
|
37 |
-
'ID' => $tmp_page->ID,
|
38 |
-
'title' => $tmp_page->post_title,
|
39 |
-
);
|
40 |
-
}
|
41 |
-
|
42 |
-
$page = get_page($page_id, OBJECT, 'edit');
|
43 |
-
// $this->_log($page);
|
44 |
-
|
45 |
-
$tmp_custom = get_post_custom($page_id);
|
46 |
-
$custom = array();
|
47 |
-
if(is_array($tmp_custom))
|
48 |
-
foreach ($tmp_custom as $key => $value_array){
|
49 |
-
if ('_wp_page_template' == $key)
|
50 |
-
{
|
51 |
-
// the page template! important!!!
|
52 |
-
$page->template = $value_array[0];
|
53 |
-
}
|
54 |
-
|
55 |
-
if ('_' == $key[0]) continue;
|
56 |
-
foreach ($value_array as $value)
|
57 |
-
{
|
58 |
-
$custom[$key][] = base64_encode($value); // keep the new lines
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
|
63 |
-
// encode the page content and excerpt to keep the new lines
|
64 |
-
// as they would be trimmed off during XMLRPC
|
65 |
-
$page->post_content = base64_encode($page->post_content);
|
66 |
-
$page->post_excerpt = base64_encode($page->post_excerpt);
|
67 |
-
|
68 |
-
// visibility
|
69 |
-
if ('private' == $page->post_status)
|
70 |
-
{
|
71 |
-
$page->post_password = '';
|
72 |
-
$page->visibility = 'private';
|
73 |
-
}
|
74 |
-
elseif (!empty($page->post_password))
|
75 |
-
{
|
76 |
-
$page->visibility = 'password';
|
77 |
-
}
|
78 |
-
else
|
79 |
-
{
|
80 |
-
$page->visibility = 'public';
|
81 |
-
}
|
82 |
-
|
83 |
-
$templates = get_page_templates();
|
84 |
-
if (empty($templates)) $templates = array();
|
85 |
-
|
86 |
-
return array(
|
87 |
-
'page' => $page,
|
88 |
-
'parents' => $parents,
|
89 |
-
'custom_fields' => $custom,
|
90 |
-
'templates' => $templates,
|
91 |
-
);
|
92 |
-
}
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Gets necessary local data for page creation
|
96 |
-
*
|
97 |
-
* @param mixed $args
|
98 |
-
* @return IXR_Error
|
99 |
-
*/
|
100 |
-
function get_new_data($args)
|
101 |
-
{
|
102 |
-
$this->_escape($args);
|
103 |
-
$username = $args[0];
|
104 |
-
$password = $args[1];
|
105 |
-
|
106 |
-
if (!$user = $this->login($username, $password))
|
107 |
-
{
|
108 |
-
return $this->error;
|
109 |
-
}
|
110 |
-
|
111 |
-
if (!current_user_can('edit_pages'))
|
112 |
-
return new IXR_Error(401, 'You are not allowed to create a new page.');
|
113 |
-
|
114 |
-
$parents = array();
|
115 |
-
foreach ((array)get_pages() as $tmp_page)
|
116 |
-
{
|
117 |
-
$parents[] = array(
|
118 |
-
'ID' => $tmp_page->ID,
|
119 |
-
'title' => $tmp_page->post_title,
|
120 |
-
);
|
121 |
-
}
|
122 |
-
|
123 |
-
$templates = get_page_templates();
|
124 |
-
if (empty($templates)) $templates = array();
|
125 |
-
|
126 |
-
$page = get_default_page_to_edit();
|
127 |
-
|
128 |
-
// some modifications to the default WordPress data
|
129 |
-
$page->post_date = date('Y-m-d H:i:s');
|
130 |
-
$page->post_status = 'publish';
|
131 |
-
|
132 |
-
return array(
|
133 |
-
'page' => $page,
|
134 |
-
'parents' => $parents,
|
135 |
-
'custom_fields' => array(), // default is an empty array
|
136 |
-
'templates' => $templates,
|
137 |
-
);
|
138 |
-
}
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Locally updates a page
|
142 |
-
*
|
143 |
-
* @param mixed $args
|
144 |
-
*/
|
145 |
-
function update($args)
|
146 |
-
{
|
147 |
-
$this->_escape($args);
|
148 |
-
$username = $args[0];
|
149 |
-
$password = $args[1];
|
150 |
-
$page_data = unserialize(base64_decode($args[2]));
|
151 |
-
|
152 |
-
if (!$user = $this->login($username, $password))
|
153 |
-
{
|
154 |
-
return $this->error;
|
155 |
-
}
|
156 |
-
|
157 |
-
if (!current_user_can('edit_page', $page_data['post_ID']))
|
158 |
-
return new IXR_Error(401, 'You are not allowed to edit this page.');
|
159 |
-
|
160 |
-
// wp_update_post needs ID key
|
161 |
-
$page_data['ID'] = $page_data['post_ID'];
|
162 |
-
|
163 |
-
// wrap the function inside an output buffer to prevent errors from printed
|
164 |
-
ob_start();
|
165 |
-
$custom_fields = get_post_custom($page_data['ID']);
|
166 |
-
foreach ($custom_fields as $key => $value)
|
167 |
-
{
|
168 |
-
delete_post_meta($page_data['ID'], $key);
|
169 |
-
}
|
170 |
-
|
171 |
-
$result = edit_post($page_data);
|
172 |
-
foreach ($page_data['meta'] as $id => $meta)
|
173 |
-
{
|
174 |
-
add_post_meta($page_data['ID'], $meta['key'], $meta['value']);
|
175 |
-
}
|
176 |
-
ob_end_clean();
|
177 |
-
|
178 |
-
if ($result)
|
179 |
-
{
|
180 |
-
return 'Success';
|
181 |
-
}
|
182 |
-
|
183 |
-
return new IXR_Error(401, 'Failed to update the page.');
|
184 |
-
}
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Locally creates a page
|
188 |
-
*
|
189 |
-
* @param mixed $args
|
190 |
-
*/
|
191 |
-
function create($args)
|
192 |
-
{
|
193 |
-
$this->_escape($args);
|
194 |
-
$username = $args[0];
|
195 |
-
$password = $args[1];
|
196 |
-
|
197 |
-
if (!$user = $this->login($username, $password))
|
198 |
-
{
|
199 |
-
return $this->error;
|
200 |
-
}
|
201 |
-
|
202 |
-
if (!current_user_can('edit_pages'))
|
203 |
-
return new IXR_Error(401, 'You are not allowed to create a new page.');
|
204 |
-
|
205 |
-
$page_struct = unserialize(base64_decode($args[2]));
|
206 |
-
$page_data = $page_struct['post_data'];
|
207 |
-
$page_meta = $page_struct['post_extras']['post_meta'];
|
208 |
-
|
209 |
-
//create post
|
210 |
-
$page_id = wp_insert_post($page_data);
|
211 |
-
if($page_id){
|
212 |
-
//get current custom fields
|
213 |
-
$cur_custom = get_post_custom($page_id);
|
214 |
-
//check which values doesnot exists in new custom fields
|
215 |
-
$diff_values = array_diff_key($cur_custom, $page_meta);
|
216 |
-
if(is_array($diff_values))
|
217 |
-
foreach ($diff_values as $meta_key => $value) {
|
218 |
-
delete_post_meta($page_id, $meta_key);
|
219 |
-
}
|
220 |
-
|
221 |
-
//insert new post meta
|
222 |
-
foreach($page_meta as $key => $value){
|
223 |
-
if(strpos($key, '_mmb') === 0 || strpos($key, '_edit') === 0)
|
224 |
-
continue;
|
225 |
-
update_post_meta($page_id, $key, $value[0]);
|
226 |
-
}
|
227 |
-
}
|
228 |
-
return $page_id;
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
// wrap the function inside an output buffer to prevent errors from printed
|
233 |
-
// ob_start();
|
234 |
-
// $_POST = $page_data;
|
235 |
-
// $post_ID = wp_write_post(); // this function gets data from $_POST
|
236 |
-
// if (is_wp_error($post_ID))
|
237 |
-
// {
|
238 |
-
// return new IXR_Error(401, 'Failed to create the page. ' . $result->get_error_message());
|
239 |
-
// }
|
240 |
-
//
|
241 |
-
// if (empty($post_ID))
|
242 |
-
// {
|
243 |
-
// return new IXR_Error(401, 'Failed to create the page: Unknown error.');
|
244 |
-
// }
|
245 |
-
//
|
246 |
-
// foreach ($page_data['meta'] as $id => $meta)
|
247 |
-
// {
|
248 |
-
// add_post_meta($post_ID, $meta['key'], $meta['value']);
|
249 |
-
// }
|
250 |
-
// ob_end_clean();
|
251 |
-
//
|
252 |
-
// if ($post_ID)
|
253 |
-
// {
|
254 |
-
// return 'Success';
|
255 |
-
// }
|
256 |
-
//
|
257 |
-
// return new IXR_Error(401, 'Failed to create the page.');
|
258 |
-
}
|
259 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugin.class.php
CHANGED
@@ -1,489 +1,131 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
-
{
|
5 |
-
|
6 |
function __construct()
|
7 |
{
|
8 |
parent::__construct();
|
9 |
}
|
10 |
|
11 |
-
/*************************************************************
|
12 |
-
* FACADE functions
|
13 |
-
* (functions to be called after a remote XMLRPC from Master)
|
14 |
-
**************************************************************/
|
15 |
-
|
16 |
-
function get_list($args)
|
17 |
-
{
|
18 |
-
$this->_escape($args);
|
19 |
-
$username = $args[0];
|
20 |
-
$password = $args[1];
|
21 |
-
|
22 |
-
if (!$user = $this->login($username, $password))
|
23 |
-
{
|
24 |
-
return $this->error;
|
25 |
-
}
|
26 |
-
|
27 |
-
if(!current_user_can('activate_plugins'))
|
28 |
-
return new IXR_Error(401, 'Sorry, you cannot manage plugins on the remote blog.');
|
29 |
-
|
30 |
-
$this->refresh_transient();
|
31 |
-
|
32 |
-
$all_plugins = get_plugins();
|
33 |
-
|
34 |
-
// we don't allow managing our own plugin this way
|
35 |
-
// better force the user to directly manage it!
|
36 |
-
global $mmb_plugin_dir;
|
37 |
-
$worker_plug = basename($mmb_plugin_dir).'/init.php';
|
38 |
-
unset($all_plugins[$worker_plug]);
|
39 |
-
|
40 |
-
// $current = get_transient('update_plugins');
|
41 |
-
$current = $this->mmb_get_transient('update_plugins');
|
42 |
-
|
43 |
-
foreach ((array)$all_plugins as $plugin_file => $plugin_data)
|
44 |
-
{
|
45 |
-
//Translate, Apply Markup, Sanitize HTML
|
46 |
-
$plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
|
47 |
-
$all_plugins[$plugin_file] = $plugin_data;
|
48 |
-
|
49 |
-
//Filter into individual sections
|
50 |
-
if (is_plugin_active($plugin_file))
|
51 |
-
{
|
52 |
-
$all_plugins[$plugin_file]['status'] = 'active';
|
53 |
-
$active_plugins[$plugin_file] = $plugin_data;
|
54 |
-
}
|
55 |
-
else
|
56 |
-
{
|
57 |
-
$all_plugins[$plugin_file]['status'] = 'inactive';
|
58 |
-
$inactive_plugins[$plugin_file] = $plugin_data;
|
59 |
-
}
|
60 |
-
|
61 |
-
if (isset($current->response[$plugin_file]))
|
62 |
-
{
|
63 |
-
$all_plugins[$plugin_file]['new_version'] = $current->response[$plugin_file];
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
return $all_plugins;
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Deactivates a plugin locally
|
72 |
-
*
|
73 |
-
* @param mixed $args
|
74 |
-
*/
|
75 |
-
function deactivate($args)
|
76 |
-
{
|
77 |
-
$this->_escape($args);
|
78 |
-
$username = $args[0];
|
79 |
-
$password = $args[1];
|
80 |
-
$plugin_files = $args[2];
|
81 |
-
|
82 |
-
if (!$user = $this->login($username, $password))
|
83 |
-
{
|
84 |
-
return $this->error;
|
85 |
-
}
|
86 |
-
|
87 |
-
if(!current_user_can('activate_plugins'))
|
88 |
-
{
|
89 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to deactivate plugins on the remote blog.');
|
90 |
-
}
|
91 |
-
|
92 |
-
$this->refresh_transient();
|
93 |
-
|
94 |
-
$success = deactivate_plugins($plugin_files);
|
95 |
-
if(is_wp_error($success))
|
96 |
-
return false;
|
97 |
-
chdir(WP_PLUGIN_DIR);
|
98 |
-
|
99 |
-
if(is_array($plugin_files)) return true;
|
100 |
-
// get the plugin again
|
101 |
-
return $this->_get_plugin_data($plugin_files);
|
102 |
-
}
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Activates a plugin locally
|
106 |
-
*
|
107 |
-
* @param mixed $args
|
108 |
-
*/
|
109 |
-
function activate($args)
|
110 |
-
{
|
111 |
-
$this->_escape($args);
|
112 |
-
$username = $args[0];
|
113 |
-
$password = $args[1];
|
114 |
-
$plugin_files = $args[2];
|
115 |
-
if (!$user = $this->login($username, $password))
|
116 |
-
{
|
117 |
-
return $this->error;
|
118 |
-
}
|
119 |
-
|
120 |
-
if(!current_user_can('activate_plugins'))
|
121 |
-
{
|
122 |
-
return new IXR_Error( 401, 'Sorry, you are not allowed to manage plugins on the remote blog.');
|
123 |
-
}
|
124 |
-
|
125 |
-
$this->refresh_transient();
|
126 |
-
//@lk test
|
127 |
-
// $this->_log($plugin_file);
|
128 |
-
// ob_start();
|
129 |
-
// var_dump($plugin_file);
|
130 |
-
// $lk_data = ob_get_clean();
|
131 |
-
// file_put_contents('testlog.txt', $lk_data);
|
132 |
-
$success = activate_plugins($plugin_files, '', FALSE);
|
133 |
-
if(is_wp_error($success))
|
134 |
-
return false;
|
135 |
-
chdir(WP_PLUGIN_DIR);
|
136 |
-
|
137 |
-
if(is_array($plugin_files)) return true;
|
138 |
-
// get the plugin again
|
139 |
-
return $this->_get_plugin_data($plugin_files);
|
140 |
-
}
|
141 |
|
142 |
/**
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
function
|
148 |
-
{
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
{
|
156 |
-
return $this->error;
|
157 |
-
}
|
158 |
-
|
159 |
-
if(!current_user_can('activate_plugins'))
|
160 |
-
{
|
161 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to upgrade plugins on the remote blog.');
|
162 |
-
}
|
163 |
-
|
164 |
-
// $current = get_transient('update_plugins');
|
165 |
-
$current = $this->mmb_get_transient('update_plugins');
|
166 |
-
// $this->_log($current);
|
167 |
-
// keep track of plugin active status
|
168 |
-
$needs_reactivaton = is_plugin_active($plugin_file);
|
169 |
-
|
170 |
-
// the Plugin upgrader will echo some HTML on its own
|
171 |
-
// so we wrap it into some output buffering to avoid
|
172 |
-
// breaking the XML response
|
173 |
-
ob_start();
|
174 |
-
// include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
175 |
-
|
176 |
-
$upgrader = new Mmb_Plugin_Upgrader();
|
177 |
-
$result = $upgrader->upgrade($plugin_file);
|
178 |
-
// $this->_log($result);
|
179 |
-
|
180 |
-
// $this->_log($output);
|
181 |
-
|
182 |
-
if (is_wp_error($result))
|
183 |
-
{
|
184 |
-
return new IXR_Error(401, 'Sorry, this plugin could not be upgraded. ' . $result->get_error_message());
|
185 |
-
}
|
186 |
-
|
187 |
-
// remember to reactivate the plugin if needed
|
188 |
-
if($needs_reactivaton)
|
189 |
-
{
|
190 |
-
activate_plugin($plugin_file);
|
191 |
-
}
|
192 |
-
|
193 |
-
unset($current->response[$plugin_file]);
|
194 |
-
set_transient('update_plugins', $current);
|
195 |
-
|
196 |
-
$output = ob_get_clean();
|
197 |
-
|
198 |
-
if ($reget_plugin_data)
|
199 |
-
{
|
200 |
-
chdir(WP_PLUGIN_DIR);
|
201 |
-
|
202 |
-
// get the plugin again.
|
203 |
-
return $this->_get_plugin_data($plugin_file);
|
204 |
-
}
|
205 |
-
}
|
206 |
-
|
207 |
-
function upgrade_multiple($args)
|
208 |
-
{
|
209 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
210 |
-
$this->_escape($args);
|
211 |
-
$username = $args[0];
|
212 |
-
$password = $args[1];
|
213 |
-
$plugin_files = $args[2];
|
214 |
-
|
215 |
-
if ($this->worker_maitanance_mode){
|
216 |
-
$this->_last_worker_message(array('error' => 'Blog is currently under maintenance. Please try again after few minutes.'));
|
217 |
-
die();
|
218 |
-
}
|
219 |
-
if (!$user = $this->login($username, $password))
|
220 |
-
{
|
221 |
-
return $this->error;
|
222 |
-
}
|
223 |
-
|
224 |
-
if(!current_user_can('activate_plugins'))
|
225 |
-
{
|
226 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to upgrade plugins on the remote blog.');
|
227 |
-
}
|
228 |
-
$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
229 |
-
$this->worker_maitanance_mode = true;
|
230 |
-
$result = $upgrader->bulk_upgrade( $plugin_files );
|
231 |
-
if(is_wp_error($upgrader->skin->result) || !$upgrader->plugin_info()){
|
232 |
-
$this->worker_maitanance_mode = false;
|
233 |
-
$error = is_wp_error($upgrader->skin->result) ? $upgrader->skin->result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
234 |
-
$this->_last_worker_message(array('error' => print_r($error, true)));
|
235 |
-
}else {
|
236 |
-
$this->worker_maitanance_mode = false;
|
237 |
-
$return_pl = array();
|
238 |
-
foreach($result as $plugin_file => $data){
|
239 |
-
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_file);
|
240 |
-
$return_pl[] = $data['Name'];
|
241 |
}
|
242 |
-
$this->_last_worker_message(array('success' => $return_pl));
|
243 |
}
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
}
|
265 |
-
|
266 |
-
$plugin_files = array();
|
267 |
-
$current = $this->mmb_get_transient('update_plugins');
|
268 |
-
foreach ((array)$current->response as $file => $data){
|
269 |
-
$plugin_files[] = $file;
|
270 |
-
}
|
271 |
-
$upgrader = new Plugin_Upgrader( new Bulk_Plugin_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
|
272 |
-
$this->worker_maitanance_mode = true;
|
273 |
-
$result = $upgrader->bulk_upgrade( $plugin_files );
|
274 |
-
if(is_wp_error($upgrader->skin->result) || !$upgrader->plugin_info()){
|
275 |
-
$this->worker_maitanance_mode = false;
|
276 |
-
$error = is_wp_error($upgrader->skin->result) ? $upgrader->skin->result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
277 |
-
$this->_last_worker_message(array('error' => print_r($error, true)));
|
278 |
-
}else {
|
279 |
-
$this->worker_maitanance_mode = false;
|
280 |
-
$this->_last_worker_message(array('success' => $result));
|
281 |
-
}
|
282 |
-
}
|
283 |
-
|
284 |
-
/**
|
285 |
-
* Deletes a plugin locally
|
286 |
-
*
|
287 |
-
* @param mixed $args
|
288 |
-
*/
|
289 |
-
function delete($args)
|
290 |
-
{
|
291 |
-
$this->_escape($args);
|
292 |
-
$username = $args[0];
|
293 |
-
$password = $args[1];
|
294 |
-
$plugin_files = $args[2];
|
295 |
-
|
296 |
-
if (!$user = $this->login($username, $password))
|
297 |
-
{
|
298 |
-
return $this->error;
|
299 |
-
}
|
300 |
-
|
301 |
-
if(!current_user_can('delete_plugins'))
|
302 |
-
{
|
303 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to delete plugins from the remote blog.');
|
304 |
-
}
|
305 |
-
|
306 |
-
$this->refresh_transient();
|
307 |
-
|
308 |
-
ob_start();
|
309 |
-
|
310 |
-
// WP is rather stupid here
|
311 |
-
// the agrument MUST be an array????
|
312 |
-
if(!is_array($plugin_files))
|
313 |
-
$plugin_files = array($plugin_files);
|
314 |
-
|
315 |
-
$result = delete_plugins($plugin_files);
|
316 |
-
ob_end_clean();
|
317 |
-
if (is_wp_error($result))
|
318 |
-
{
|
319 |
-
return new IXR_Error(401, 'Sorry, this plugin could not be deleted. ' . $result->get_error_message());
|
320 |
-
}
|
321 |
-
|
322 |
-
return TRUE;
|
323 |
-
}
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Our own functions to get plugin data that fits our needs
|
327 |
-
* (that is, with status and new version info)
|
328 |
-
*
|
329 |
-
* @param mixed $plugin_file
|
330 |
-
*/
|
331 |
-
function _get_plugin_data($plugin_file)
|
332 |
-
{
|
333 |
-
$plugin = get_plugin_data($plugin_file);
|
334 |
-
$plugin['status'] = is_plugin_active($plugin_file) ? 'active' : 'inactive';
|
335 |
-
|
336 |
-
|
337 |
-
// check for new version
|
338 |
-
// $current = get_transient('update_plugins');
|
339 |
-
$current = $this->mmb_get_transient('update_plugins');
|
340 |
-
|
341 |
-
if (isset($current->response[$plugin_file]))
|
342 |
-
{
|
343 |
-
$plugin['new_version'] = $current->response[$plugin_file];
|
344 |
-
}
|
345 |
-
|
346 |
-
return $plugin;
|
347 |
-
}
|
348 |
-
|
349 |
-
/**
|
350 |
-
* Gets a list of plugins with upgrade available
|
351 |
-
*
|
352 |
-
*/
|
353 |
-
function get_upgradable_plugins()
|
354 |
-
{
|
355 |
-
$all_plugins = get_plugins();
|
356 |
-
$upgrade_plugins = array();
|
357 |
-
|
358 |
-
$this->refresh_transient();
|
359 |
-
|
360 |
-
// $current = get_transient('update_plugins');
|
361 |
-
$current = $this->mmb_get_transient('update_plugins');
|
362 |
-
// $test = $this->mmb_get_transient('update_plugins');
|
363 |
-
// $this->_log($test);
|
364 |
-
foreach ((array)$all_plugins as $plugin_file => $plugin_data)
|
365 |
-
{
|
366 |
-
//Translate, Apply Markup, Sanitize HTML
|
367 |
-
$plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
|
368 |
-
if (isset($current->response[$plugin_file]))
|
369 |
-
{
|
370 |
-
$current->response[$plugin_file]->name = $plugin_data['Name'];
|
371 |
-
$current->response[$plugin_file]->old_version = $plugin_data['Version'];
|
372 |
-
$current->response[$plugin_file]->file = $plugin_file;
|
373 |
-
$upgrade_plugins[] = $current->response[$plugin_file];
|
374 |
}
|
|
|
|
|
|
|
|
|
375 |
}
|
376 |
-
|
377 |
-
return $upgrade_plugins;
|
378 |
}
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
function
|
386 |
{
|
|
|
387 |
$this->_escape($args);
|
388 |
-
$
|
389 |
-
$
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
return new IXR_Error(401, 'You do not have sufficient permissions to install plugins for this blog.');
|
399 |
-
|
400 |
-
$this->refresh_transient();
|
401 |
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
|
422 |
-
// return $this->get_list(array($username, $password));
|
423 |
-
// list refresh should be requested by the client to have WP update the plugin list itself
|
424 |
-
return TRUE;
|
425 |
}
|
426 |
|
427 |
-
function
|
428 |
{
|
429 |
-
|
430 |
-
|
431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
-
return $current;
|
434 |
}
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
*
|
439 |
-
* @param mixed $args
|
440 |
-
*/
|
441 |
-
function upload_by_url($args)
|
442 |
-
{
|
443 |
-
$this->_escape($args);
|
444 |
-
$username = $args[0];
|
445 |
-
$password = $args[1];
|
446 |
-
$url = $args[2];
|
447 |
-
$activate = $args[3];
|
448 |
-
|
449 |
-
if (!$user = $this->login($username, $password))
|
450 |
-
{
|
451 |
-
return $this->error;
|
452 |
-
}
|
453 |
-
if($activate && !current_user_can('activate_plugins')){
|
454 |
-
return new IXR_Error( 401, 'Sorry, you are not allowed to manage plugins on the remote blog.');
|
455 |
-
}
|
456 |
-
if (!current_user_can('install_plugins')){
|
457 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to install plugins on the remote blog.');
|
458 |
-
}
|
459 |
-
|
460 |
-
if (!$this->_init_filesystem())
|
461 |
-
return new IXR_Error(401, 'Plugin could not be installed: Failed to initialize file system.');
|
462 |
-
/*if($this->_is_ftp_writable){
|
463 |
-
$this->_last_worker_message(array('error' => 'Blog needs a ftp permissions to complete task.'));
|
464 |
-
die();
|
465 |
-
}*/
|
466 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
467 |
-
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'nonce', 'url' ) ) );
|
468 |
-
ob_start();
|
469 |
-
$result = $upgrader->install($url);
|
470 |
-
ob_end_clean();
|
471 |
-
|
472 |
-
if(is_wp_error($upgrader->skin->result) || !$upgrader->plugin_info()){
|
473 |
-
$error = is_wp_error($upgrader->skin->result) ? $upgrader->skin->result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
474 |
-
$this->_last_worker_message(array('error' => print_r($error, true)));
|
475 |
-
}else {
|
476 |
-
if($activate){
|
477 |
-
$success = activate_plugin($upgrader->plugin_info(), '', FALSE);
|
478 |
-
if(is_wp_error($success)){
|
479 |
-
$this->_last_worker_message($success);
|
480 |
-
return false;
|
481 |
-
}
|
482 |
-
}
|
483 |
-
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $upgrader->plugin_info());
|
484 |
-
$this->_last_worker_message(array('success' => $upgrader->plugin_info(), 'name' => $data['Name'], 'activate' => print_r($activate, true)));
|
485 |
-
}
|
486 |
-
}
|
487 |
-
|
488 |
-
|
489 |
-
}
|
1 |
<?php
|
2 |
|
3 |
+
class MMB_Plugin extends MMB_Core
|
4 |
+
{
|
5 |
+
var $worker_maitanance_mode = false;
|
6 |
function __construct()
|
7 |
{
|
8 |
parent::__construct();
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
/**
|
13 |
+
* Upgrades all upgradable plugins on this blog
|
14 |
+
*
|
15 |
+
* @param mixed $args
|
16 |
+
*/
|
17 |
+
function upgrade_all($params)
|
18 |
+
{
|
19 |
+
$upgradable_plugins = $this->_get_upgradable_plugins();
|
20 |
+
|
21 |
+
$ready_for_upgrade =array();
|
22 |
+
if(!empty($upgradable_plugins)){
|
23 |
+
foreach($upgradable_plugins as $upgrade ){
|
24 |
+
$ready_for_upgrade[] = $upgrade->file;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
|
|
26 |
}
|
27 |
+
$return = '';
|
28 |
+
if (!empty($ready_for_upgrade)) {
|
29 |
+
ob_start();
|
30 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
31 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
32 |
+
require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
33 |
+
if (class_exists('Plugin_Upgrader')) {
|
34 |
+
$upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
|
35 |
+
$result = $upgrader->bulk_upgrade($ready_for_upgrade);
|
36 |
+
ob_end_clean();
|
37 |
+
foreach ($result as $plugin_slug => $plugin_info) {
|
38 |
+
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_slug);
|
39 |
+
if(!$plugin_info || is_wp_error($plugin_info)){
|
40 |
+
$return .= '<code title="Please upgarde manualy">' . $data['Name'] . '</code> was not upgraded.';
|
41 |
+
}else{
|
42 |
+
$return .= '<code>' . $data['Name'] . '</code> successfully upgraded.';
|
43 |
+
}
|
44 |
+
}
|
45 |
+
ob_end_clean();
|
46 |
+
return array('upgraded' => $return);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
+
else {
|
49 |
+
ob_end_clean();
|
50 |
+
return array('error' => 'Could not initialize upgrader.');
|
51 |
+
}
|
52 |
}
|
53 |
+
return array('error' => 'No plugins to upgrade at the moment');
|
|
|
54 |
}
|
55 |
|
56 |
+
/**
|
57 |
+
* Uploads a plugin, given its package url
|
58 |
+
*
|
59 |
+
* @param mixed $args
|
60 |
+
*/
|
61 |
+
function upload_by_url($args)
|
62 |
{
|
63 |
+
//print_r($args);
|
64 |
$this->_escape($args);
|
65 |
+
$plugin_url = $args['url'];
|
66 |
+
$activate_plugin = $args['activate'];
|
67 |
+
|
68 |
+
if ($plugin_url) {
|
69 |
+
ob_start();
|
70 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
71 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
72 |
+
include_once(ABSPATH . 'wp-admin/includes/misc.php');
|
73 |
+
include_once(ABSPATH . 'wp-admin/includes/template.php');
|
74 |
+
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
|
|
|
|
|
|
75 |
|
76 |
+
$upgrader = new Plugin_Upgrader();
|
77 |
+
|
78 |
+
$result = $upgrader->run(array(
|
79 |
+
'package' => $plugin_url,
|
80 |
+
'destination' => WP_PLUGIN_DIR,
|
81 |
+
'clear_destination' => false, //Do not overwrite files.
|
82 |
+
'clear_working' => true,
|
83 |
+
'hook_extra' => array()
|
84 |
+
));
|
85 |
+
|
86 |
+
ob_end_clean();
|
87 |
+
|
88 |
+
|
89 |
+
if (is_wp_error($upgrader->skin->result) || !$upgrader->plugin_info()) {
|
90 |
+
return array('bool' => false, 'message' => 'Plugin was not installed.');
|
91 |
+
}
|
92 |
+
|
93 |
+
if ($activate_plugin) {
|
94 |
+
$success = activate_plugin($upgrader->plugin_info(), '', false);
|
95 |
+
|
96 |
+
if (!is_wp_error($success)) {
|
97 |
+
return array('bool' => true, 'message' => 'Plugin '.$upgrader->result[destination_name].' successfully installed and activated ');
|
98 |
+
}
|
99 |
+
return array('bool' => true, 'message' => 'Plugin '.$upgrader->result[destination_name].' successfully installed ');
|
100 |
+
} else {
|
101 |
+
return (!$result or is_wp_error($result)) ? array('bool' => false, 'message' => 'Upload failed.') : array('bool' => true, 'message' => 'Plugin '.$upgrader->result[destination_name].' successfully installed ');
|
102 |
+
}
|
103 |
+
|
104 |
+
} else
|
105 |
+
return array('bool' => false, 'message' => 'Missing plugin.');
|
106 |
|
|
|
|
|
|
|
107 |
}
|
108 |
|
109 |
+
function _get_upgradable_plugins()
|
110 |
{
|
111 |
+
$current = $this->mmb_get_transient('update_plugins');
|
112 |
+
$upgradable_plugins = array();
|
113 |
+
if(!empty($current->response)){
|
114 |
+
foreach ($current->response as $plugin_path => $plugin_data) {
|
115 |
+
if (!function_exists('get_plugin_data'))
|
116 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
117 |
+
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
|
118 |
+
|
119 |
+
$current->response[$plugin_path]->name = $data['Name'];
|
120 |
+
$current->response[$plugin_path]->old_version = $data['Version'];
|
121 |
+
$current->response[$plugin_path]->file = $plugin_path;
|
122 |
+
$upgradable_plugins[] = $current->response[$plugin_path];
|
123 |
+
}
|
124 |
+
return $upgradable_plugins;
|
125 |
+
}
|
126 |
+
else return array();
|
127 |
|
|
|
128 |
}
|
129 |
|
130 |
+
}
|
131 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post.class.php
CHANGED
@@ -1,656 +1,350 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
class
|
4 |
{
|
5 |
function __construct()
|
6 |
{
|
7 |
parent::__construct();
|
8 |
}
|
9 |
|
10 |
-
/*************************************************************
|
11 |
-
* FACADE functions
|
12 |
-
* (functions to be called after a remote XMLRPC from Master)
|
13 |
-
**************************************************************/
|
14 |
-
|
15 |
-
function get_list($args)
|
16 |
-
{
|
17 |
-
$this->_escape($args);
|
18 |
-
$username = $args[0];
|
19 |
-
$password = $args[1];
|
20 |
-
$offset = $args[2];
|
21 |
-
$number = $args[3];
|
22 |
-
$status = $args[4];
|
23 |
-
$category = $args[5];
|
24 |
-
$tag = $args[6];
|
25 |
-
$author = $args[7];
|
26 |
-
|
27 |
-
if (!$user = $this->login($username, $password))
|
28 |
-
{
|
29 |
-
return $this->error;
|
30 |
-
}
|
31 |
-
|
32 |
-
if (!current_user_can('edit_posts'))
|
33 |
-
return new IXR_Error(401, 'You are not allowed to manage posts.');
|
34 |
-
|
35 |
-
if($category)
|
36 |
-
$category_query = "&category=$category";
|
37 |
-
if($tag)
|
38 |
-
$tag_query = "&tag=$tag";
|
39 |
-
if($author)
|
40 |
-
$author_query = "&author=$author";
|
41 |
-
|
42 |
-
$posts = get_posts("offset=$offset&post_status=$status&numberposts=$number".$category_query.$tag_query.$author_query);
|
43 |
-
|
44 |
-
|
45 |
-
foreach ($posts as &$post)
|
46 |
-
{
|
47 |
-
|
48 |
-
// trim off unnecessary data to save bandwidth and speed
|
49 |
-
$post->post_content = null;
|
50 |
-
$post->post_excerpt = null;
|
51 |
-
|
52 |
-
// get categories and tags data
|
53 |
-
$cats = array();
|
54 |
-
foreach (get_the_category($post->ID) as $k => $cat)
|
55 |
-
{
|
56 |
-
$cats[$k]['name'] = $cat->cat_name;
|
57 |
-
$cats[$k]['ID'] = $cat->cat_ID;
|
58 |
-
//$post->categories .= $cat->cat_name . ', ';
|
59 |
-
}
|
60 |
-
|
61 |
-
//$post->categories = rtrim($post->categories, ', ');
|
62 |
-
$post->categories = $cats;
|
63 |
-
|
64 |
-
$tags = array();
|
65 |
-
|
66 |
-
foreach ( (array)get_the_tags($post->ID) as $k => $tag)
|
67 |
-
{
|
68 |
-
$tags[$k]['name'] = $tag->name;
|
69 |
-
$tags[$k]['slug'] = $tag->slug;
|
70 |
-
//$post->tags .= $tag->name . ', ';
|
71 |
-
}
|
72 |
-
|
73 |
-
$post->tags = $tags;
|
74 |
-
//$post->tags = rtrim($post->tags, ', ');
|
75 |
-
|
76 |
-
// how about author?
|
77 |
-
$author = get_userdata($post->post_author);
|
78 |
-
$post->author = array('author_name' => $author->nickname, 'author_id' => $author->ID);
|
79 |
-
}
|
80 |
-
|
81 |
-
|
82 |
-
//Get number of queried post without offset
|
83 |
-
$queried_posts = get_posts("offset=-1&post_status=-1&numberposts=-1".$category_query.$tag_query.$author_query);
|
84 |
-
|
85 |
-
// category
|
86 |
-
$categories = get_categories(array(
|
87 |
-
'number' => 0,
|
88 |
-
'hide_empty' => 1
|
89 |
-
));
|
90 |
-
|
91 |
-
$data = array(
|
92 |
-
'posts' => $posts,
|
93 |
-
'post_counts' => wp_count_posts('post', 'readable'),
|
94 |
-
'query_post_counts' => count($queried_posts),
|
95 |
-
'categories' => $categories
|
96 |
-
);
|
97 |
-
|
98 |
-
return $data;
|
99 |
-
}
|
100 |
-
|
101 |
-
/**
|
102 |
-
* Gets data to edit a post
|
103 |
-
*
|
104 |
-
* @param mixed $args
|
105 |
-
*/
|
106 |
-
function get_edit_data($args)
|
107 |
-
{
|
108 |
-
$this->_escape($args);
|
109 |
-
$username = $args[0];
|
110 |
-
$password = $args[1];
|
111 |
-
$post_ID = $args[2];
|
112 |
-
|
113 |
-
if (!$user = $this->login($username, $password))
|
114 |
-
{
|
115 |
-
return $this->error;
|
116 |
-
}
|
117 |
-
|
118 |
-
if (!current_user_can('edit_post', $post_ID))
|
119 |
-
return new IXR_Error(401, 'You are not allowed to edit this post.');
|
120 |
-
|
121 |
-
$post = get_post($post_ID);
|
122 |
-
|
123 |
-
if (empty($post->ID))
|
124 |
-
return new IXR_Error(401, 'You attempted to edit a post that doesn’t exist. Perhaps it was deleted?');
|
125 |
-
|
126 |
-
if ('trash' == $post->post_status)
|
127 |
-
return new IXR_Error(401, 'You can’t edit this post because it is in the Trash. Please restore it and try again.');
|
128 |
-
|
129 |
-
$post = get_post_to_edit($post_ID);
|
130 |
-
$post->post_content = base64_encode($post->post_content);
|
131 |
-
$post->post_excerpt = base64_encode($post->post_excerpt);
|
132 |
-
|
133 |
-
// wordpress don't provide information about a post's categories
|
134 |
-
// do it our own
|
135 |
-
foreach ((array)get_the_category($post_ID) as $cat)
|
136 |
-
{
|
137 |
-
// $post->categories[] = $cat->cat_ID;
|
138 |
-
$post->categories[] = $cat->name;
|
139 |
-
}
|
140 |
-
|
141 |
-
// same goes with the tags. What was Matt doing????
|
142 |
-
foreach ((array)get_the_tags($post_ID) as $tag)
|
143 |
-
{
|
144 |
-
$post->tags .= $tag->name . ', ';
|
145 |
-
}
|
146 |
-
|
147 |
-
$post->tags = rtrim($post->tags, ', ');
|
148 |
-
|
149 |
-
// get the categories
|
150 |
-
foreach ((array)get_categories() as $cat)
|
151 |
-
{
|
152 |
-
$categories[] = array(
|
153 |
-
'ID' => $cat->cat_ID,
|
154 |
-
'name' => $cat->cat_name,
|
155 |
-
);
|
156 |
-
}
|
157 |
-
|
158 |
-
// and the custom fields (meta)
|
159 |
-
// this is different from how we handle Page
|
160 |
-
// (because I was stupid at the moment)
|
161 |
-
$custom = array();
|
162 |
-
|
163 |
-
foreach ((array)get_post_custom($post_ID) as $key => $value_array)
|
164 |
-
{
|
165 |
-
if ('_' == $key[0]) continue;
|
166 |
-
foreach ($value_array as $value)
|
167 |
-
{
|
168 |
-
$post->meta[$key][] = base64_encode($value); // keep the new lines
|
169 |
-
}
|
170 |
-
}
|
171 |
-
|
172 |
-
// visibility
|
173 |
-
if ('private' == $post->post_status)
|
174 |
-
{
|
175 |
-
$post->post_password = '';
|
176 |
-
$post->visibility = 'private';
|
177 |
-
$post->sticky = FALSE;
|
178 |
-
}
|
179 |
-
elseif (!empty( $post->post_password))
|
180 |
-
{
|
181 |
-
$post->visibility = 'password';
|
182 |
-
$post->sticky = FALSE;
|
183 |
-
}
|
184 |
-
elseif (is_sticky( $post->ID ))
|
185 |
-
{
|
186 |
-
$post->visibility = 'public';
|
187 |
-
$post->sticky = TRUE;
|
188 |
-
}
|
189 |
-
else
|
190 |
-
{
|
191 |
-
$post->visibility = 'public';
|
192 |
-
$post->sticky = FALSE;
|
193 |
-
}
|
194 |
-
|
195 |
-
$data = array(
|
196 |
-
'post' => $post,
|
197 |
-
'categories' => $categories,
|
198 |
-
);
|
199 |
-
|
200 |
-
return $data;
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Updates a post locally
|
205 |
-
*
|
206 |
-
* @param mixed $args
|
207 |
-
*/
|
208 |
-
function update($args)
|
209 |
-
{
|
210 |
-
$this->_escape($args);
|
211 |
-
$username = $args[0];
|
212 |
-
$password = $args[1];
|
213 |
-
$post_data = unserialize(base64_decode($args[2]));
|
214 |
-
|
215 |
-
if (!$user = $this->login($username, $password))
|
216 |
-
{
|
217 |
-
return $this->error;
|
218 |
-
}
|
219 |
-
|
220 |
-
if (!current_user_can('edit_post', $post_data['post_ID']))
|
221 |
-
return new IXR_Error(401, 'You are not allowed to edit this post.');
|
222 |
-
|
223 |
-
// wp_update_post needs ID key
|
224 |
-
$post_data['ID'] = $post_data['post_ID'];
|
225 |
-
|
226 |
-
// wrap the function inside an output buffer to prevent errors from printed
|
227 |
-
ob_start();
|
228 |
-
$custom_fields = get_post_custom($post_data['ID']);
|
229 |
-
foreach ((array)$custom_fields as $key => $value)
|
230 |
-
{
|
231 |
-
delete_post_meta($post_data['ID'], $key);
|
232 |
-
}
|
233 |
-
|
234 |
-
$result = edit_post($post_data);
|
235 |
-
foreach ((array)$post_data['meta'] as $id => $meta)
|
236 |
-
{
|
237 |
-
add_post_meta($post_data['ID'], $meta['key'], $meta['value']);
|
238 |
-
}
|
239 |
-
|
240 |
-
ob_end_clean();
|
241 |
-
|
242 |
-
if ($result)
|
243 |
-
{
|
244 |
-
return 'Success';
|
245 |
-
}
|
246 |
-
|
247 |
-
return new IXR_Error(401, 'Failed to update the post.');
|
248 |
-
}
|
249 |
-
|
250 |
-
/**
|
251 |
-
* Gets data to create a post
|
252 |
-
*
|
253 |
-
* @param mixed $args
|
254 |
-
*/
|
255 |
-
function get_new_data($args)
|
256 |
-
{
|
257 |
-
$this->_escape($args);
|
258 |
-
$username = $args[0];
|
259 |
-
$password = $args[1];
|
260 |
-
|
261 |
-
if (!$user = $this->login($username, $password))
|
262 |
-
{
|
263 |
-
return $this->error;
|
264 |
-
}
|
265 |
-
|
266 |
-
$post = get_default_post_to_edit();
|
267 |
-
|
268 |
-
// some default data
|
269 |
-
$post->categories= array();
|
270 |
-
$post->tags = '';
|
271 |
-
$post->meta = array();
|
272 |
-
$post->visibility = 'public';
|
273 |
-
$post->sticky = FALSE;
|
274 |
-
$post->post_date = date('Y-m-d H:i:s');
|
275 |
-
$post->post_status = 'publish';
|
276 |
-
|
277 |
-
// get the categories
|
278 |
-
foreach ((array)get_categories() as $cat)
|
279 |
-
{
|
280 |
-
$categories[] = array(
|
281 |
-
'ID' => $cat->cat_ID,
|
282 |
-
'name' => $cat->cat_name,
|
283 |
-
);
|
284 |
-
}
|
285 |
-
|
286 |
-
$data = array(
|
287 |
-
'post' => $post,
|
288 |
-
'categories' => $categories,
|
289 |
-
);
|
290 |
-
|
291 |
-
return $data;
|
292 |
-
}
|
293 |
-
|
294 |
-
/**
|
295 |
-
* Locally creates a post
|
296 |
-
*
|
297 |
-
* @param mixed $args
|
298 |
-
*/
|
299 |
function create($args)
|
300 |
{
|
301 |
-
$this->_escape($args);
|
302 |
-
$username = $args[0];
|
303 |
-
$password = $args[1];
|
304 |
-
if (!$user = $this->login($username, $password))
|
305 |
-
{
|
306 |
-
return $this->error;
|
307 |
-
}
|
308 |
/**
|
309 |
* algorithm
|
310 |
* 1. create post using wp_insert_post (insert tags also here itself)
|
311 |
* 2. use wp_create_categories() to create(not exists) and insert in the post
|
312 |
* 3. insert meta values
|
313 |
*/
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
$
|
319 |
-
|
320 |
-
$
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
//to find all the images
|
357 |
-
|
358 |
-
if($match_count > 0){
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
}
|
385 |
-
continue;
|
386 |
-
}
|
387 |
-
|
388 |
-
$no_thumb ='';
|
389 |
-
if(preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $get_url[4])){
|
390 |
-
$no_thumb = preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', '.'.$get_url[5], $get_url[4]);
|
391 |
-
}else{
|
392 |
-
$no_thumb = $get_url[4];
|
393 |
-
}
|
394 |
-
$file_name = basename($no_thumb);
|
395 |
-
$tmp_file = download_url($no_thumb);
|
396 |
-
$attach_upload['url'] = $upload['url'].'/'.$file_name;
|
397 |
-
$attach_upload['path'] = $upload['path'].'/'.$file_name;
|
398 |
-
$renamed = rename($tmp_file, $attach_upload['path']);
|
399 |
-
if($renamed === true){
|
400 |
-
$match_pattern = '/'.str_replace($rep, $with, $get_url[4]).'/';
|
401 |
-
$replace_pattern = $attach_upload['url'];
|
402 |
-
$post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
|
403 |
-
if(preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $get_url[4])){
|
404 |
-
$match_pattern = '/'.str_replace( $rep, $with, preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', '.'.$get_url[5], $get_url[4]) ).'/';
|
405 |
-
$post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
|
406 |
-
}
|
407 |
-
|
408 |
-
$attachment = array(
|
409 |
-
'post_title' => $file_name,
|
410 |
-
'post_content' => '',
|
411 |
-
'post_type' => 'attachment',
|
412 |
-
//'post_parent' => $post_id,
|
413 |
-
'post_mime_type' => 'image/'.$get_url[5],
|
414 |
-
'guid' => $attach_upload['url']
|
415 |
-
);
|
416 |
-
|
417 |
-
// Save the data
|
418 |
-
$attach_id = wp_insert_attachment( $attachment, $attach_upload['path'] );
|
419 |
-
$attachments[$attach_id] = 0;
|
420 |
-
|
421 |
-
// featured image
|
422 |
-
if($post_featured_img != ''){
|
423 |
-
$feat_img_url = '';
|
424 |
-
if( preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $post_featured_img) ){
|
425 |
-
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
|
426 |
-
}else{
|
427 |
-
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
|
428 |
-
}
|
429 |
-
$m_feat_url = '/'.str_replace($rep, $with, $feat_img_url ).'/';
|
430 |
-
if( preg_match($m_feat_url, $get_url[4]) ){
|
431 |
-
$post_featured_img = '';
|
432 |
-
$attachments[$attach_id] = $attach_id;
|
433 |
-
}
|
434 |
-
}
|
435 |
-
|
436 |
-
// set $get_urls value[6] - parent atta_id
|
437 |
-
foreach($get_urls as $url_k => $url_v){
|
438 |
-
if($get_url_k != $url_k){
|
439 |
-
$s_get_url = '';
|
440 |
-
if(preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $url_v[4])){
|
441 |
-
$s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.') - 8);
|
442 |
-
}else{
|
443 |
-
$s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.'));
|
444 |
-
}
|
445 |
-
$m_patt_url = '/'.str_replace($rep, $with, $s_get_url ).'/';
|
446 |
-
if( preg_match($m_patt_url, $get_url[4]) ){
|
447 |
-
array_push($get_urls[$url_k], $attach_id);
|
448 |
-
}
|
449 |
-
}
|
450 |
-
}
|
451 |
-
wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $attach_upload['path'] ) );
|
452 |
-
// changing href of a tag
|
453 |
-
if($get_url[1] != ''){
|
454 |
-
$mwp_mp = '/'.str_replace($rep, $with, $get_url[2]).'/';
|
455 |
-
if( preg_match('/attachment_id/i', $get_url[2]) ){
|
456 |
-
$mwp_rp = get_bloginfo('wpurl').'/?attachment_id='.$attach_id;
|
457 |
-
$post_content = preg_replace($mwp_mp, $mwp_rp, $post_content);
|
458 |
-
}
|
459 |
-
}
|
460 |
}
|
461 |
-
|
|
|
462 |
}
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
}
|
510 |
-
|
511 |
}
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
$attachment = array(
|
536 |
'post_title' => $file_name,
|
537 |
'post_content' => '',
|
538 |
'post_type' => 'attachment',
|
539 |
-
'post_parent' => $post_id,
|
540 |
-
'post_mime_type' => 'image/'
|
541 |
'guid' => $attach_upload['url']
|
542 |
);
|
543 |
-
|
544 |
// Save the data
|
545 |
-
$attach_id = wp_insert_attachment(
|
546 |
-
wp_update_attachment_metadata(
|
547 |
-
|
548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
549 |
@unlink($tmp_file);
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
$option_post_checksum = maybe_unserialize( get_option('worker_post_checksum') );
|
554 |
-
if($option_post_checksum == ''){
|
555 |
-
$add_post_checksum = array($post_checksum => $post_id);
|
556 |
-
add_option('worker_post_checksum', $add_post_checksum );
|
557 |
-
}else{
|
558 |
-
update_option('worker_post_checksum', array_merge((array)$option_post_checksum, array($post_checksum => $post_id)) );
|
559 |
-
}
|
560 |
-
|
561 |
-
if($post_id && is_array($post_categories)){
|
562 |
//insert categories
|
|
|
563 |
$cat_ids = wp_create_categories($post_categories, $post_id);
|
564 |
}
|
|
|
|
|
565 |
//get current custom fields
|
566 |
-
$cur_custom
|
567 |
//check which values doesnot exists in new custom fields
|
568 |
$diff_values = array_diff_key($cur_custom, $new_custom);
|
569 |
-
|
570 |
-
if(is_array($diff_values))
|
571 |
foreach ($diff_values as $meta_key => $value) {
|
572 |
delete_post_meta($post_id, $meta_key);
|
573 |
}
|
574 |
//insert new post meta
|
575 |
-
foreach($new_custom as $meta_key => $value){
|
576 |
-
if(strpos($meta_key, '_mmb') === 0 || strpos($meta_key, '_edit') === 0){
|
577 |
continue;
|
578 |
-
}else{
|
579 |
update_post_meta($post_id, $meta_key, $value[0]);
|
580 |
}
|
581 |
}
|
582 |
|
|
|
583 |
return $post_id;
|
584 |
-
|
585 |
-
|
586 |
}
|
587 |
|
588 |
/**
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
*/
|
593 |
-
function publish($args)
|
594 |
{
|
595 |
-
$
|
596 |
-
$
|
597 |
-
$
|
598 |
-
|
599 |
-
|
600 |
-
if (!$user = $this->login($username, $password))
|
601 |
-
{
|
602 |
-
return $this->error;
|
603 |
}
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
wp_publish_post($post_id);
|
609 |
-
|
610 |
-
return TRUE;
|
611 |
-
}
|
612 |
-
|
613 |
-
function checksum($args)
|
614 |
-
{
|
615 |
-
$this->_escape($args);
|
616 |
-
$username = $args[0];
|
617 |
-
$password = $args[1];
|
618 |
-
$checksum = $args[2];
|
619 |
-
$post_type = $args[3];
|
620 |
-
|
621 |
-
if (!$user = $this->login($username, $password))
|
622 |
-
return $this->error;
|
623 |
-
|
624 |
-
for($i=0;$i<=30;$i++){
|
625 |
-
global $wpdb;
|
626 |
-
$option = 'worker_post_checksum';
|
627 |
-
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
|
628 |
-
wp_cache_delete('worker_post_checksum','options');
|
629 |
-
$row_option = $row->option_value;
|
630 |
-
$local_checksums = maybe_unserialize($row_option);
|
631 |
-
if(isset($local_checksums[$checksum])){
|
632 |
-
$local_post_id = $local_checksums[$checksum];
|
633 |
-
unset($local_checksums[$checksum]);
|
634 |
-
if(count($local_checksums)){
|
635 |
-
update_option('worker_post_checksum', '');
|
636 |
-
update_option('worker_post_checksum', $local_checksums);
|
637 |
-
}else{
|
638 |
-
delete_option('worker_post_checksum');
|
639 |
-
}
|
640 |
-
return $local_post_id.'#'.$post_type;
|
641 |
-
|
642 |
-
}elseif($i==30){
|
643 |
-
return false;
|
644 |
-
}
|
645 |
-
$this->my_sleep(1);
|
646 |
-
}
|
647 |
-
|
648 |
-
}
|
649 |
-
function my_sleep($seconds)
|
650 |
-
{
|
651 |
-
$start = microtime(true);
|
652 |
-
for ($i = 1; $i <= $seconds; $i ++) {
|
653 |
-
@time_sleep_until($start + $i);
|
654 |
}
|
655 |
-
|
656 |
-
|
1 |
<?php
|
2 |
+
/*************************************************************
|
3 |
+
*
|
4 |
+
* post.class.php
|
5 |
+
*
|
6 |
+
* Create remote post
|
7 |
+
*
|
8 |
+
*
|
9 |
+
* Copyright (c) 2011 Prelovac Media
|
10 |
+
* www.prelovac.com
|
11 |
+
**************************************************************/
|
12 |
|
13 |
+
class MMB_Post extends MMB_Core
|
14 |
{
|
15 |
function __construct()
|
16 |
{
|
17 |
parent::__construct();
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
function create($args)
|
21 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
* algorithm
|
24 |
* 1. create post using wp_insert_post (insert tags also here itself)
|
25 |
* 2. use wp_create_categories() to create(not exists) and insert in the post
|
26 |
* 3. insert meta values
|
27 |
*/
|
28 |
+
|
29 |
+
include_once ABSPATH . 'wp-admin/includes/taxonomy.php';
|
30 |
+
include_once ABSPATH . 'wp-admin/includes/image.php';
|
31 |
+
|
32 |
+
$post_struct = $args['post_data'];
|
33 |
+
|
34 |
+
$post_data = $post_struct['post_data'];
|
35 |
+
$new_custom = $post_struct['post_extras']['post_meta'];
|
36 |
+
$post_categories = explode(',', $post_struct['post_extras']['post_categories']);
|
37 |
+
$post_atta_img = $post_struct['post_extras']['post_atta_images'];
|
38 |
+
$post_upload_dir = $post_struct['post_extras']['post_upload_dir'];
|
39 |
+
$post_checksum = $post_struct['post_extras']['post_checksum'];
|
40 |
+
$post_featured_img = $post_struct['post_extras']['featured_img'];
|
41 |
+
|
42 |
+
$upload = wp_upload_dir();
|
43 |
+
|
44 |
+
// create dynamic url RegExp
|
45 |
+
$mwp_base_url = parse_url($post_upload_dir['url']);
|
46 |
+
$mwp_regexp_url = $mwp_base_url['host'] . $mwp_base_url['path'];
|
47 |
+
$rep = array(
|
48 |
+
'/',
|
49 |
+
'+',
|
50 |
+
'.',
|
51 |
+
':',
|
52 |
+
'?'
|
53 |
+
);
|
54 |
+
$with = array(
|
55 |
+
'\/',
|
56 |
+
'\+',
|
57 |
+
'\.',
|
58 |
+
'\:',
|
59 |
+
'\?'
|
60 |
+
);
|
61 |
+
$mwp_regexp_url = str_replace($rep, $with, $mwp_regexp_url);
|
62 |
+
|
63 |
+
// rename all src ../wp-content/ with hostname/wp-content/
|
64 |
+
$mmb_dot_url = '..' . $mmb_base_url['path'];
|
65 |
+
$mmb_dot_url = str_replace($rep, $with, $mmb_dot_url);
|
66 |
+
$dot_match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]*' . $mmb_dot_url . '[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $dot_get_urls, PREG_SET_ORDER);
|
67 |
+
if ($dot_match_count > 0) {
|
68 |
+
foreach ($dot_get_urls as $dot_url) {
|
69 |
+
$match_dot = '/' . str_replace($rep, $with, $dot_url[4]) . '/';
|
70 |
+
$replace_dot = 'http://' . $mmb_base_url['host'] . substr($dot_url[4], 2, strlen($dot_url[4]));
|
71 |
+
$post_data['post_content'] = preg_replace($match_dot, $replace_dot, $post_data['post_content']);
|
72 |
+
|
73 |
+
if ($dot_url[1] != '') {
|
74 |
+
$match_dot_a = '/' . str_replace($rep, $with, $dot_url[2]) . '/';
|
75 |
+
$replace_dot_a = 'http://' . $mmb_base_url['host'] . substr($dot_url[2], 2, strlen($dot_url[2]));
|
76 |
+
$post_data['post_content'] = preg_replace($match_dot_a, $replace_dot_a, $post_data['post_content']);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
//to find all the images
|
84 |
+
$match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]+' . $mmb_regexp_url . '[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $get_urls, PREG_SET_ORDER);
|
85 |
+
if ($match_count > 0) {
|
86 |
+
$attachments = array();
|
87 |
+
$post_content = $post_data['post_content'];
|
88 |
+
|
89 |
+
foreach ($get_urls as $get_url_k => $get_url) {
|
90 |
+
// unset url in attachment array
|
91 |
+
foreach ($post_atta_img as $atta_url_k => $atta_url_v) {
|
92 |
+
$match_patt_url = '/' . str_replace($rep, $with, substr($atta_url_v['src'], 0, strrpos($atta_url_v['src'], '.'))) . '/';
|
93 |
+
if (preg_match($match_patt_url, $get_url[4])) {
|
94 |
+
unset($post_atta_img[$atta_url_k]);
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
if (isset($get_urls[$get_url_k][6])) { // url have parent, don't download this url
|
99 |
+
if ($get_url[1] != '') {
|
100 |
+
// change src url
|
101 |
+
$s_mmb_mp = '/' . str_replace($rep, $with, $get_url[4]) . '/';
|
102 |
+
|
103 |
+
$s_img_atta = wp_get_attachment_image_src($get_urls[$get_url_k][6]);
|
104 |
+
$s_mmb_rp = $s_img_atta[0];
|
105 |
+
$post_content = preg_replace($s_mmb_mp, $s_mmb_rp, $post_content);
|
106 |
+
// change attachment url
|
107 |
+
if (preg_match('/attachment_id/i', $get_url[2])) {
|
108 |
+
$mmb_mp = '/' . str_replace($rep, $with, $get_url[2]) . '/';
|
109 |
+
$mmb_rp = get_bloginfo('wpurl') . '/?attachment_id=' . $get_urls[$get_url_k][6];
|
110 |
+
$post_content = preg_replace($mmb_mp, $mmb_rp, $post_content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
}
|
112 |
+
}
|
113 |
+
continue;
|
114 |
}
|
115 |
+
|
116 |
+
$no_thumb = '';
|
117 |
+
if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $get_url[4])) {
|
118 |
+
$no_thumb = preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', '.' . $get_url[5], $get_url[4]);
|
119 |
+
} else {
|
120 |
+
$no_thumb = $get_url[4];
|
121 |
+
}
|
122 |
+
$file_name = basename($no_thumb);
|
123 |
+
|
124 |
+
//$tmp_file = $upload['path'].'/tempfile.tmp';
|
125 |
+
$tmp_file = $this->mmb_download_url($no_thumb, $upload['path'] . '/tempfile'.md5(time()).'.tmp');
|
126 |
+
//$tmp_file = download_url($no_thumb);
|
127 |
+
|
128 |
+
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
|
129 |
+
$attach_upload['path'] = $upload['path'] . '/' . $file_name;
|
130 |
+
$renamed = @rename($tmp_file, $attach_upload['path']);
|
131 |
+
if ($renamed === true) {
|
132 |
+
$match_pattern = '/' . str_replace($rep, $with, $get_url[4]) . '/';
|
133 |
+
$replace_pattern = $attach_upload['url'];
|
134 |
+
$post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
|
135 |
+
if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $get_url[4])) {
|
136 |
+
$match_pattern = '/' . str_replace($rep, $with, preg_replace('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', '.' . $get_url[5], $get_url[4])) . '/';
|
137 |
+
$post_content = preg_replace($match_pattern, $replace_pattern, $post_content);
|
138 |
+
}
|
139 |
+
|
140 |
+
$attachment = array(
|
141 |
+
'post_title' => $file_name,
|
142 |
+
'post_content' => '',
|
143 |
+
'post_type' => 'attachment',
|
144 |
+
//'post_parent' => $post_id,
|
145 |
+
'post_mime_type' => 'image/' . $get_url[5],
|
146 |
+
'guid' => $attach_upload['url']
|
147 |
+
);
|
148 |
+
|
149 |
+
// Save the data
|
150 |
+
|
151 |
+
$attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
|
152 |
+
|
153 |
+
$attachments[$attach_id] = 0;
|
154 |
+
|
155 |
+
// featured image
|
156 |
+
if ($post_featured_img != '') {
|
157 |
+
$feat_img_url = '';
|
158 |
+
if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $post_featured_img)) {
|
159 |
+
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
|
160 |
+
} else {
|
161 |
+
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
|
162 |
+
}
|
163 |
+
$m_feat_url = '/' . str_replace($rep, $with, $feat_img_url) . '/';
|
164 |
+
if (preg_match($m_feat_url, $get_url[4])) {
|
165 |
+
$post_featured_img = '';
|
166 |
+
$attachments[$attach_id] = $attach_id;
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// set $get_urls value[6] - parent atta_id
|
171 |
+
foreach ($get_urls as $url_k => $url_v) {
|
172 |
+
if ($get_url_k != $url_k) {
|
173 |
+
$s_get_url = '';
|
174 |
+
if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $url_v[4])) {
|
175 |
+
$s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.') - 8);
|
176 |
+
} else {
|
177 |
+
$s_get_url = substr($url_v[4], 0, strrpos($url_v[4], '.'));
|
178 |
+
}
|
179 |
+
$m_patt_url = '/' . str_replace($rep, $with, $s_get_url) . '/';
|
180 |
+
if (preg_match($m_patt_url, $get_url[4])) {
|
181 |
+
array_push($get_urls[$url_k], $attach_id);
|
182 |
+
}
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
|
187 |
+
$some_data = wp_generate_attachment_metadata($attach_id, $attach_upload['path']);
|
188 |
+
wp_update_attachment_metadata($attach_id, $some_data);
|
189 |
+
|
190 |
+
|
191 |
+
// changing href of a tag
|
192 |
+
if ($get_url[1] != '') {
|
193 |
+
$mmb_mp = '/' . str_replace($rep, $with, $get_url[2]) . '/';
|
194 |
+
if (preg_match('/attachment_id/i', $get_url[2])) {
|
195 |
+
$mmb_rp = get_bloginfo('wpurl') . '/?attachment_id=' . $attach_id;
|
196 |
+
$post_content = preg_replace($mmb_mp, $mmb_rp, $post_content);
|
197 |
}
|
198 |
+
}
|
199 |
}
|
200 |
+
@unlink($tmp_file);
|
201 |
+
}
|
202 |
+
|
203 |
+
|
204 |
+
$post_data['post_content'] = $post_content;
|
205 |
+
|
206 |
+
}
|
207 |
+
if (count($post_atta_img)) {
|
208 |
+
foreach ($post_atta_img as $img) {
|
209 |
+
$file_name = basename($img['src']);
|
210 |
+
|
211 |
+
|
212 |
+
$tmp_file = $this->mmb_download_url($img['src'], $upload['path'] . '/tempfile.tmp');
|
213 |
+
|
214 |
+
//$tmp_file = download_url($img['src']);
|
215 |
+
|
216 |
+
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
|
217 |
+
$attach_upload['path'] = $upload['path'] . '/' . $file_name;
|
218 |
+
$renamed = @rename($tmp_file, $attach_upload['path']);
|
219 |
+
if ($renamed === true) {
|
220 |
+
$atta_ext = end(explode('.', $file_name));
|
221 |
+
|
|
|
222 |
$attachment = array(
|
223 |
'post_title' => $file_name,
|
224 |
'post_content' => '',
|
225 |
'post_type' => 'attachment',
|
226 |
+
//'post_parent' => $post_id,
|
227 |
+
'post_mime_type' => 'image/' . $atta_ext,
|
228 |
'guid' => $attach_upload['url']
|
229 |
);
|
230 |
+
|
231 |
// Save the data
|
232 |
+
$attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
|
233 |
+
wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attach_upload['path']));
|
234 |
+
$attachments[$attach_id] = 0;
|
235 |
+
|
236 |
+
// featured image
|
237 |
+
if ($post_featured_img != '') {
|
238 |
+
$feat_img_url = '';
|
239 |
+
if (preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $post_featured_img)) {
|
240 |
+
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
|
241 |
+
} else {
|
242 |
+
$feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
|
243 |
+
}
|
244 |
+
$m_feat_url = '/' . str_replace($rep, $with, $feat_img_url) . '/';
|
245 |
+
if (preg_match($m_feat_url, $img['src'])) {
|
246 |
+
$post_featured_img = '';
|
247 |
+
$attachments[$attach_id] = $attach_id;
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
}
|
252 |
+
@unlink($tmp_file);
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
|
257 |
+
// create post
|
258 |
+
$post_id = wp_insert_post($post_data);
|
259 |
+
|
260 |
+
if (count($attachments)) {
|
261 |
+
foreach ($attachments as $atta_id => $featured_id) {
|
262 |
+
$result = wp_update_post(array(
|
263 |
+
'ID' => $atta_id,
|
264 |
+
'post_parent' => $post_id
|
265 |
+
));
|
266 |
+
if ($featured_id > 0) {
|
267 |
+
$new_custom['_thumbnail_id'] = array(
|
268 |
+
$featured_id
|
269 |
+
);
|
270 |
+
}
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
// featured image
|
275 |
+
if ($post_featured_img != '') {
|
276 |
+
$file_name = basename($post_featured_img);
|
277 |
+
//$tmp_file = download_url($post_featured_img);
|
278 |
+
$tmp_file = $this->mmb_download_url($no_thumb, $upload['path'] . '/tempfile_feat.tmp');
|
279 |
+
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
|
280 |
+
$attach_upload['path'] = $upload['path'] . '/' . $file_name;
|
281 |
+
$renamed = @rename($tmp_file, $attach_upload['path']);
|
282 |
+
if ($renamed === true) {
|
283 |
+
$atta_ext = end(explode('.', $file_name));
|
284 |
+
|
285 |
+
$attachment = array(
|
286 |
+
'post_title' => $file_name,
|
287 |
+
'post_content' => '',
|
288 |
+
'post_type' => 'attachment',
|
289 |
+
'post_parent' => $post_id,
|
290 |
+
'post_mime_type' => 'image/' . $atta_ext,
|
291 |
+
'guid' => $attach_upload['url']
|
292 |
+
);
|
293 |
+
|
294 |
+
// Save the data
|
295 |
+
$attach_id = wp_insert_attachment($attachment, $attach_upload['path']);
|
296 |
+
wp_update_attachment_metadata($attach_id, wp_generate_attachment_metadata($attach_id, $attach_upload['path']));
|
297 |
+
$new_custom['_thumbnail_id'] = array(
|
298 |
+
$attach_id
|
299 |
+
);
|
300 |
+
}
|
301 |
@unlink($tmp_file);
|
302 |
+
}
|
303 |
+
|
304 |
+
if ($post_id && is_array($post_categories)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
//insert categories
|
306 |
+
|
307 |
$cat_ids = wp_create_categories($post_categories, $post_id);
|
308 |
}
|
309 |
+
|
310 |
+
|
311 |
//get current custom fields
|
312 |
+
$cur_custom = get_post_custom($post_id);
|
313 |
//check which values doesnot exists in new custom fields
|
314 |
$diff_values = array_diff_key($cur_custom, $new_custom);
|
315 |
+
|
316 |
+
if (is_array($diff_values))
|
317 |
foreach ($diff_values as $meta_key => $value) {
|
318 |
delete_post_meta($post_id, $meta_key);
|
319 |
}
|
320 |
//insert new post meta
|
321 |
+
foreach ($new_custom as $meta_key => $value) {
|
322 |
+
if (strpos($meta_key, '_mmb') === 0 || strpos($meta_key, '_edit') === 0) {
|
323 |
continue;
|
324 |
+
} else {
|
325 |
update_post_meta($post_id, $meta_key, $value[0]);
|
326 |
}
|
327 |
}
|
328 |
|
329 |
+
|
330 |
return $post_id;
|
331 |
+
|
332 |
+
|
333 |
}
|
334 |
|
335 |
/**
|
336 |
+
* Aleternate function for WordPress download_url()
|
337 |
+
*/
|
338 |
+
function mmb_download_url($url, $file_name)
|
|
|
|
|
339 |
{
|
340 |
+
$destination = fopen($file_name, 'wb');
|
341 |
+
$source = @fopen($url, "r");
|
342 |
+
while ($a = fread($source, 1024)) {
|
343 |
+
$ret = fwrite($destination, $a);
|
|
|
|
|
|
|
|
|
344 |
}
|
345 |
+
fclose($source);
|
346 |
+
fclose($destination);
|
347 |
+
return $file_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
}
|
349 |
+
}
|
350 |
+
?>
|
readme.txt
CHANGED
@@ -25,6 +25,12 @@ Check out [ManageWP.com](http://managewp.com/ "Manage Multiple Blogs")
|
|
25 |
|
26 |
== Changelog ==
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
= 3.6.3 =
|
29 |
* Initial public release
|
30 |
|
25 |
|
26 |
== Changelog ==
|
27 |
|
28 |
+
= 3.8.0 =
|
29 |
+
* New interface
|
30 |
+
* SSL security protocl
|
31 |
+
* many more
|
32 |
+
|
33 |
+
|
34 |
= 3.6.3 =
|
35 |
* Initial public release
|
36 |
|
stats.class.php
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
<?php
|
2 |
-
class
|
3 |
{
|
4 |
function __construct()
|
5 |
{
|
@@ -7,241 +7,274 @@ class Mmb_Stats extends Mmb_Core
|
|
7 |
}
|
8 |
|
9 |
/*************************************************************
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
function get($
|
15 |
{
|
16 |
-
$
|
|
|
17 |
|
18 |
-
|
19 |
-
$
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
// drafts
|
31 |
-
// available plugin upgrades
|
32 |
-
// available wordpress upgrade
|
33 |
-
// version of worker plugin
|
34 |
-
// and???
|
35 |
|
36 |
-
$
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
$
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
$
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
{
|
50 |
-
|
51 |
-
$
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
|
|
61 |
|
62 |
-
|
63 |
-
$drafts
|
64 |
-
// trim off unnecessary data
|
65 |
-
foreach ($drafts as $draft)
|
66 |
-
{
|
67 |
-
if (!current_user_can('edit_post', $draft->ID)) continue;
|
68 |
-
|
69 |
$props = get_object_vars($draft);
|
70 |
-
foreach ($props as $name => $value)
|
71 |
-
|
72 |
-
if ($name != 'post_title' && $name != 'ID' && $name != 'post_modified')
|
73 |
-
{
|
74 |
unset($draft->$name);
|
|
|
|
|
|
|
75 |
}
|
76 |
}
|
77 |
}
|
|
|
|
|
78 |
|
79 |
-
if (!empty($drafts))
|
80 |
-
{
|
81 |
-
$stats['drafts'] = $drafts;
|
82 |
-
}
|
83 |
|
84 |
-
if (
|
85 |
-
|
86 |
-
// available plugin upgrades
|
87 |
-
$stats['upgradable_plugins'] = $this->get_plugin_instance()->get_upgradable_plugins();
|
88 |
-
}
|
89 |
-
|
90 |
-
if (current_user_can('update_plugins'))
|
91 |
-
{
|
92 |
-
// core upgrade
|
93 |
-
$new_version = $this->get_wp_instance()->check_version(NULL, FALSE);
|
94 |
-
if (!is_a($new_version, 'IXR_Error'))
|
95 |
-
{
|
96 |
-
$stats['new_version'] = $new_version;
|
97 |
-
}
|
98 |
-
|
99 |
-
//@lk worker version
|
100 |
-
//we can either store the version string in a file or a string or both
|
101 |
-
global $mmb_plugin_dir;
|
102 |
-
// $worker_version = file_get_contents($mmb_plugin_dir.'/version');
|
103 |
-
$stats['worker_version'] = MMB_WORKER_VERSION;
|
104 |
-
}
|
105 |
-
if (current_user_can('install_themes')){
|
106 |
-
$stats['upgradable_themes'] = $this->get_theme_instance()->get_upgradable_themes();
|
107 |
-
}
|
108 |
-
$stats['server_ftp'] = 0;
|
109 |
-
if((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)){
|
110 |
-
$stats['server_ftp'] = 1;
|
111 |
}
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
return $stats;
|
114 |
}
|
115 |
-
|
116 |
-
function
|
117 |
-
|
118 |
-
|
119 |
-
$username = $args[0];
|
120 |
-
$password = $args[1];
|
121 |
-
// $this->_log($username);
|
122 |
-
// $this->_log($password);
|
123 |
-
|
124 |
-
if (!$user = $this->login($username, $password)){
|
125 |
-
return $this->error;
|
126 |
-
}
|
127 |
|
128 |
$stats = array();
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
$stats['writable'] = FALSE;
|
142 |
-
}
|
143 |
-
global $mmb_plugin_dir;
|
144 |
-
$stats['worker_path'] = $mmb_plugin_dir;
|
145 |
-
$stats['content_path'] = WP_CONTENT_DIR;
|
146 |
}
|
147 |
-
|
148 |
|
|
|
149 |
}
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
// In activation hook
|
155 |
-
// if(!get_option('user_hit_count')){
|
156 |
-
// $user_hit_count = array();
|
157 |
-
// update_option('user_hit_count', $user_hit_count);
|
158 |
-
// }
|
159 |
-
//
|
160 |
-
// Save a transient to the database
|
161 |
-
// $transient = $_SERVER['REMOTE_ADDR'];
|
162 |
-
// $expiration = somethig; // equal to 8 hrs
|
163 |
-
//
|
164 |
-
// if(!(get_transient($transient)))
|
165 |
-
// set_transient($transient, $transient, $expiration);
|
166 |
-
//
|
167 |
-
// Fetch a saved transient
|
168 |
-
// $current_user_ip = get_transient($transient);
|
169 |
-
// if(!(get_transient($transient))) then increment the hit count
|
170 |
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
173 |
$user_hit_count = get_option('user_hit_count');
|
174 |
-
if(!$user_hit_count){
|
175 |
$user_hit_count[$date] = 1;
|
176 |
update_option('user_hit_count', $user_hit_count);
|
177 |
-
|
178 |
-
$dated_keys
|
179 |
-
$last_visit_date = $dated_keys[count($dated_keys)-1];
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
// $diff = intval($diff / 60);
|
186 |
-
// $hours = $diff % 24;
|
187 |
-
// $days = intval($diff / 24);
|
188 |
-
|
189 |
-
$days = intval ( ( strtotime($date) - strtotime($last_visit_date) ) / 60 / 60 / 24 );
|
190 |
-
|
191 |
-
if($days>1){
|
192 |
-
// $date_elems = getdate(strtotime($last_visit_date));
|
193 |
-
// $yr = $date_elems['year'];
|
194 |
-
// $mn = $date_elems['mon'];
|
195 |
-
// $dt = $date_elems['mday'];
|
196 |
-
|
197 |
$date_to_add = date('Y-m-d', strtotime($last_visit_date));
|
198 |
-
|
199 |
-
for($i = 1; $i
|
200 |
-
if(count($user_hit_count) >
|
201 |
-
|
202 |
-
$shifted = @array_shift($user_hit_count);
|
203 |
}
|
204 |
-
|
205 |
-
//$next_key = $yr.'-'.$mn.'-'.$next_day;
|
206 |
$next_key = strtotime('+1 day', strtotime($date_to_add));
|
207 |
-
if($next_key == $date){
|
208 |
break;
|
209 |
-
}else{
|
210 |
-
|
211 |
}
|
212 |
}
|
213 |
-
|
214 |
-
// if($next_key == $date)
|
215 |
-
// $user_hit_count[$next_key] = 0;
|
216 |
}
|
217 |
-
|
218 |
-
if(!isset($user_hit_count[$date])){
|
219 |
-
|
220 |
}
|
221 |
-
if(!$fix_count)
|
222 |
-
|
223 |
-
|
224 |
-
if(count($user_hit_count) > 7)
|
225 |
-
|
226 |
-
$shifted = @array_shift($user_hit_count);
|
227 |
}
|
228 |
-
|
229 |
-
update_option('user_hit_count', $user_hit_count);
|
230 |
-
|
231 |
-
|
232 |
}
|
233 |
}
|
234 |
|
235 |
-
function get_hit_count()
|
|
|
236 |
// Check if there are no hits on last key date
|
237 |
$mmb_user_hits = get_option('user_hit_count');
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
|
|
|
|
243 |
|
244 |
return get_option('user_hit_count');
|
245 |
}
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
class MMB_Stats extends MMB_Core
|
3 |
{
|
4 |
function __construct()
|
5 |
{
|
7 |
}
|
8 |
|
9 |
/*************************************************************
|
10 |
+
* FACADE functions
|
11 |
+
* (functions to be called after a remote call from Master)
|
12 |
+
**************************************************************/
|
13 |
+
|
14 |
+
function get($params)
|
15 |
{
|
16 |
+
global $wp_version, $mmb_plugin_dir;
|
17 |
+
$stats = array();
|
18 |
|
19 |
+
//define constants
|
20 |
+
$num_pending_comments = 3;
|
21 |
+
$num_approved_comments = 3;
|
22 |
+
$num_spam_comments = 0;
|
23 |
+
$num_draft_comments = 0;
|
24 |
+
$num_trash_comments = 0;
|
25 |
|
26 |
+
require_once(ABSPATH . '/wp-admin/includes/update.php');
|
27 |
+
|
28 |
+
|
29 |
+
$updates = $this->mmb_get_transient('update_core');
|
30 |
+
|
31 |
+
if($updates->updates[0]->response == 'development' || version_compare($wp_version, $updates->updates[0]->current, '<')){
|
32 |
+
$updates->updates[0]->current_version = $wp_version;
|
33 |
+
$stats['core_udates'] = $updates->updates[0];
|
34 |
+
}else
|
35 |
+
$stats['core_udates'] = false;
|
36 |
+
|
37 |
+
$mmb_user_hits = get_option('user_hit_count');
|
38 |
+
if (is_array($mmb_user_hits)) {
|
39 |
+
end($mmb_user_hits);
|
40 |
+
$last_key_date = key($mmb_user_hits);
|
41 |
+
$current_date = date('Y-m-d');
|
42 |
+
if ($last_key_date != $curent_date)
|
43 |
+
$this->set_hit_count(true);
|
44 |
}
|
45 |
+
$stats['hit_counter'] = get_option('user_hit_count');
|
46 |
|
47 |
+
$stats['upgradable_themes'] = $this->get_theme_instance()->_get_upgradable_themes();
|
48 |
+
$stats['upgradable_plugins'] = $this->get_plugin_instance()->_get_upgradable_plugins();
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
$pending_comments = get_comments('status=hold&number='.$num_pending_comments);
|
51 |
+
foreach ($pending_comments as &$comment) {
|
52 |
+
$commented_post = get_post($comment->comment_post_ID);
|
53 |
+
$comment->post_title = $commented_post->post_title;
|
54 |
+
}
|
55 |
+
$approved_comments = get_comments('status=approve&number='.$num_approved_comments);
|
56 |
+
foreach ($approved_comments as &$comment) {
|
57 |
+
$commented_post = get_post($comment->comment_post_ID);
|
58 |
+
$comment->post_title = $commented_post->post_title;
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
$stats['comments']['pending'] = $pending_comments;
|
63 |
+
$stats['comments']['approved'] = $approved_comments;
|
64 |
+
|
65 |
|
66 |
+
$all_posts = get_posts('post_status=publish&numberposts=3&orderby=modified&order=desc');
|
67 |
+
$stats['publish_count'] = count($all_posts);
|
68 |
+
$recent_posts = array();
|
69 |
+
|
70 |
+
foreach ($all_posts as $id => $recent) {
|
71 |
+
|
72 |
+
$recent->post_permalink = get_permalink($recent->ID);
|
73 |
+
unset($recent->post_content);
|
74 |
+
unset($recent->post_author);
|
75 |
+
unset($recent->post_category);
|
76 |
+
unset($recent->post_date_gmt);
|
77 |
+
unset($recent->post_excerpt);
|
78 |
+
unset($recent->post_status);
|
79 |
+
unset($recent->comment_status);
|
80 |
+
unset($recent->ping_status);
|
81 |
+
unset($recent->post_password);
|
82 |
+
unset($recent->post_name);
|
83 |
+
unset($recent->to_ping);
|
84 |
+
unset($recent->pinged);
|
85 |
+
unset($recent->post_modified_gmt);
|
86 |
+
unset($recent->post_content_filtered);
|
87 |
+
unset($recent->post_parent);
|
88 |
+
unset($recent->guid);
|
89 |
+
unset($recent->menu_order);
|
90 |
+
unset($recent->post_type);
|
91 |
+
unset($recent->post_mime_type);
|
92 |
+
unset($recent->filter);
|
93 |
+
unset($recent->featured);
|
94 |
+
$recent_posts[] = $recent;
|
95 |
}
|
96 |
+
$stats['posts'] = $recent_posts;
|
97 |
|
98 |
+
$drafts = get_posts('post_status=draft&numberposts=3');
|
99 |
+
foreach ($drafts as $draft) {
|
|
|
|
|
|
|
|
|
|
|
100 |
$props = get_object_vars($draft);
|
101 |
+
foreach ($props as $name => $value) {
|
102 |
+
if ($name != 'post_title' && $name != 'ID' && $name != 'post_modified') {
|
|
|
|
|
103 |
unset($draft->$name);
|
104 |
+
} else {
|
105 |
+
$draft->post_title = get_the_title($draft->ID);
|
106 |
+
$draft->post_permalink = get_permalink($draft->ID);
|
107 |
}
|
108 |
}
|
109 |
}
|
110 |
+
$stats['draft_count'] = count($drafts);
|
111 |
+
$stats['drafts'] = $drafts;
|
112 |
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
if( function_exists( 'openssl_verify' ) ){
|
115 |
+
$stats['no_openssl'] = $this->_get_random_signature();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
117 |
+
else {
|
118 |
+
delete_option('_worker_nossl_key');
|
119 |
+
$stats['no_openssl'] = false;
|
120 |
+
}
|
121 |
+
|
122 |
+
if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
|
123 |
+
$stats['writable'] = false;
|
124 |
+
}
|
125 |
+
else $stats['writable'] = true;
|
126 |
return $stats;
|
127 |
}
|
128 |
+
|
129 |
+
function get_initial_stats()
|
130 |
+
{
|
131 |
+
global $mmb_plugin_dir;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
$stats = array();
|
134 |
+
|
135 |
+
$stats['email'] = get_option('admin_email');
|
136 |
+
$stats['no_openssl'] = $this->_get_random_signature();
|
137 |
+
$stats['content_path'] = WP_CONTENT_DIR;
|
138 |
+
$stats['worker_path'] = $mmb_plugin_dir;
|
139 |
+
$stats['worker_version'] = MMB_WORKER_VERSION;
|
140 |
+
$stats['site_title'] = get_bloginfo('name');
|
141 |
+
$stats['site_tagline'] = get_bloginfo('description');
|
142 |
+
|
143 |
+
|
144 |
+
if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
|
145 |
+
$stats['writable'] = false;
|
|
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
+
else $stats['writable'] = true;
|
148 |
|
149 |
+
return $stats;
|
150 |
}
|
151 |
|
152 |
+
|
153 |
+
|
154 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
+
function set_hit_count($fix_count = false)
|
157 |
+
{
|
158 |
+
|
159 |
+
if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots() )) {
|
160 |
+
$date = date('Y-m-d');
|
161 |
$user_hit_count = get_option('user_hit_count');
|
162 |
+
if (!$user_hit_count) {
|
163 |
$user_hit_count[$date] = 1;
|
164 |
update_option('user_hit_count', $user_hit_count);
|
165 |
+
} else {
|
166 |
+
$dated_keys = array_keys($user_hit_count);
|
167 |
+
$last_visit_date = $dated_keys[count($dated_keys) - 1];
|
168 |
+
|
169 |
+
$days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
|
170 |
+
|
171 |
+
if ($days > 1) {
|
172 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
$date_to_add = date('Y-m-d', strtotime($last_visit_date));
|
174 |
+
|
175 |
+
for ($i = 1; $i < $days; $i++) {
|
176 |
+
if (count($user_hit_count) > 14) {
|
177 |
+
$shifted = @array_shift($user_hit_count);
|
|
|
178 |
}
|
179 |
+
|
|
|
180 |
$next_key = strtotime('+1 day', strtotime($date_to_add));
|
181 |
+
if ($next_key == $date) {
|
182 |
break;
|
183 |
+
} else {
|
184 |
+
$user_hit_count[$next_key] = 0;
|
185 |
}
|
186 |
}
|
187 |
+
|
|
|
|
|
188 |
}
|
189 |
+
|
190 |
+
if (!isset($user_hit_count[$date])) {
|
191 |
+
$user_hit_count[$date] = 0;
|
192 |
}
|
193 |
+
if (!$fix_count)
|
194 |
+
$user_hit_count[$date] += 1;
|
195 |
+
|
196 |
+
if (count($user_hit_count) > 7) {
|
197 |
+
$shifted = @array_shift($user_hit_count);
|
|
|
198 |
}
|
199 |
+
|
200 |
+
update_option('user_hit_count', $user_hit_count);
|
201 |
+
|
202 |
+
}
|
203 |
}
|
204 |
}
|
205 |
|
206 |
+
function get_hit_count()
|
207 |
+
{
|
208 |
// Check if there are no hits on last key date
|
209 |
$mmb_user_hits = get_option('user_hit_count');
|
210 |
+
if (is_array($mmb_user_hits)) {
|
211 |
+
end($mmb_user_hits);
|
212 |
+
$last_key_date = key($mmb_user_hits);
|
213 |
+
$current_date = date('Y-m-d');
|
214 |
+
if ($last_key_date != $curent_date)
|
215 |
+
$this->set_hit_count(true);
|
216 |
+
}
|
217 |
|
218 |
return get_option('user_hit_count');
|
219 |
}
|
220 |
+
|
221 |
+
function detect_bots()
|
222 |
+
{
|
223 |
+
$agent = $_SERVER['HTTP_USER_AGENT'];
|
224 |
+
|
225 |
+
if ($agent == '')
|
226 |
+
return false;
|
227 |
+
|
228 |
+
$bot_list = array(
|
229 |
+
"Teoma",
|
230 |
+
"alexa",
|
231 |
+
"froogle",
|
232 |
+
"Gigabot",
|
233 |
+
"inktomi",
|
234 |
+
"looksmart",
|
235 |
+
"URL_Spider_SQL",
|
236 |
+
"Firefly",
|
237 |
+
"NationalDirectory",
|
238 |
+
"Ask Jeeves",
|
239 |
+
"TECNOSEEK",
|
240 |
+
"InfoSeek",
|
241 |
+
"WebFindBot",
|
242 |
+
"girafabot",
|
243 |
+
"crawler",
|
244 |
+
"www.galaxy.com",
|
245 |
+
"Googlebot",
|
246 |
+
"Scooter",
|
247 |
+
"Slurp",
|
248 |
+
"msnbot",
|
249 |
+
"appie",
|
250 |
+
"FAST",
|
251 |
+
"WebBug",
|
252 |
+
"Spade",
|
253 |
+
"ZyBorg",
|
254 |
+
"rabaz",
|
255 |
+
"Baiduspider",
|
256 |
+
"Feedfetcher-Google",
|
257 |
+
"TechnoratiSnoop",
|
258 |
+
"Rankivabot",
|
259 |
+
"Mediapartners-Google",
|
260 |
+
"Sogou web spider",
|
261 |
+
"WebAlta Crawler",
|
262 |
+
"aolserver"
|
263 |
+
);
|
264 |
+
|
265 |
+
$thebot = '';
|
266 |
+
foreach ($bot_list as $bot) {
|
267 |
+
if (ereg($bot, $agent)) {
|
268 |
+
$thebot = $bot;
|
269 |
+
break;
|
270 |
+
}
|
271 |
+
}
|
272 |
+
|
273 |
+
if ($thebot != '') {
|
274 |
+
return $thebot;
|
275 |
+
} else
|
276 |
+
return false;
|
277 |
+
}
|
278 |
+
|
279 |
+
}
|
280 |
+
?>
|
tags.class.php
DELETED
@@ -1,162 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Mmb_Tags extends Mmb_Core
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
/*************************************************************
|
11 |
-
* FACADE functions
|
12 |
-
* (functions to be called after a remote XMLRPC from Master)
|
13 |
-
**************************************************************/
|
14 |
-
/**
|
15 |
-
* Gets a list of local (slave) category
|
16 |
-
*
|
17 |
-
* @param mixed $args
|
18 |
-
* @return mixed
|
19 |
-
*/
|
20 |
-
function get_list($args)
|
21 |
-
{
|
22 |
-
$this->_escape($args);
|
23 |
-
$username = $args[0];
|
24 |
-
$password = $args[1];
|
25 |
-
$offset = $args[2];
|
26 |
-
$per_page = $args[3];
|
27 |
-
|
28 |
-
if (!$user = $this->login($username, $password))
|
29 |
-
{
|
30 |
-
return $this->error;
|
31 |
-
}
|
32 |
-
|
33 |
-
if(!current_user_can('manage_categories'))
|
34 |
-
return new IXR_Error(401, 'Sorry, you cannot manage Tags on the remote blog.');
|
35 |
-
global $wpdb;
|
36 |
-
|
37 |
-
$count = count(get_tags(array('hide_empty' => FALSE)));
|
38 |
-
$tags = get_tags(array(
|
39 |
-
'offset' => $offset,
|
40 |
-
'number' => $per_page,
|
41 |
-
'hide_empty' => FALSE
|
42 |
-
));
|
43 |
-
return array('tags' => $tags, 'count' => $count);
|
44 |
-
}
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Updates a category locally
|
48 |
-
*
|
49 |
-
* @param mixed $args
|
50 |
-
*/
|
51 |
-
function update($args)
|
52 |
-
{
|
53 |
-
$this->_escape($args);
|
54 |
-
$username = $args[0];
|
55 |
-
$password = $args[1];
|
56 |
-
$id = $args[2];
|
57 |
-
$name = $args[3];
|
58 |
-
$slug = $args[4];
|
59 |
-
$description = $args[5];
|
60 |
-
$taxonomy = $args[6];
|
61 |
-
|
62 |
-
if (!$user = $this->login($username, $password))
|
63 |
-
{
|
64 |
-
return $this->error;
|
65 |
-
}
|
66 |
-
|
67 |
-
if(!current_user_can('manage_categories'))
|
68 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
69 |
-
|
70 |
-
if(empty($slug))
|
71 |
-
return new IXR_Error(401, 'Sorry, Slug cannot be Empty.');
|
72 |
-
|
73 |
-
|
74 |
-
$taxonomy = !empty($taxonomy) ? $taxonomy : 'post_tag';
|
75 |
-
$tag = get_term( $id, $taxonomy );
|
76 |
-
$args = array('name' => $name,'slug'=> $slug,'description' => $description);
|
77 |
-
$is_success = wp_update_term($id, $taxonomy, $args);
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
if($is_success && !is_wp_error($is_success))
|
83 |
-
return TRUE;
|
84 |
-
else
|
85 |
-
return new IXR_Error(401, 'Error Updating Tags. Try Again !!!');
|
86 |
-
|
87 |
-
}
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Adds a new category locally
|
91 |
-
*
|
92 |
-
* @param mixed $args
|
93 |
-
*/
|
94 |
-
function add($args)
|
95 |
-
{
|
96 |
-
$this->_escape($args);
|
97 |
-
$username = $args[0];
|
98 |
-
$password = $args[1];
|
99 |
-
$tag_name = $args[2];
|
100 |
-
$tag_slug = $args[3];
|
101 |
-
$tag_desc = $args[4];
|
102 |
-
|
103 |
-
if (!$user = $this->login($username, $password))
|
104 |
-
{
|
105 |
-
return $this->error;
|
106 |
-
}
|
107 |
-
|
108 |
-
if(!current_user_can('manage_categories'))
|
109 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
110 |
-
|
111 |
-
// wordpress' category adding function
|
112 |
-
|
113 |
-
$params = array('tag-name' => $tag_name,
|
114 |
-
'slug' => $tag_slug,
|
115 |
-
'description' => $tag_desc
|
116 |
-
);
|
117 |
-
|
118 |
-
|
119 |
-
//$result = wp_create_tag($params);
|
120 |
-
|
121 |
-
$result = wp_insert_term($tag_name, 'post_tag', $params);
|
122 |
-
|
123 |
-
$term = get_terms('post_tag', array('include' => $result['term_id'], 'hide_empty'=>FALSE));
|
124 |
-
if($result && !is_wp_error($is_success))
|
125 |
-
return $term;
|
126 |
-
else
|
127 |
-
return new IXR_Error(401, 'Error Creating Tags. Try Again !!!');
|
128 |
-
// if ($tag_id = wp_create_term($params))
|
129 |
-
// {
|
130 |
-
// return get_terms();
|
131 |
-
// }
|
132 |
-
//
|
133 |
-
// return FALSE;
|
134 |
-
}
|
135 |
-
|
136 |
-
function delete($args){
|
137 |
-
$this->_escape($args);
|
138 |
-
$username = $args[0];
|
139 |
-
$password = $args[1];
|
140 |
-
$term = $args[2];
|
141 |
-
$taxonomy = $args[3];
|
142 |
-
|
143 |
-
if (!$user = $this->login($username, $password))
|
144 |
-
{
|
145 |
-
return $this->error;
|
146 |
-
}
|
147 |
-
if(!current_user_can('manage_categories'))
|
148 |
-
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.');
|
149 |
-
|
150 |
-
$taxonomy = !empty($taxonomy) ? $taxonomy : 'post_tag';
|
151 |
-
|
152 |
-
$is_success = wp_delete_term($term, $taxonomy);
|
153 |
-
|
154 |
-
if($is_success && !is_wp_error($is_success))
|
155 |
-
return TRUE;
|
156 |
-
else
|
157 |
-
return new IXR_Error(401, 'Error Deleting Tags. Try Again !!!');
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
}
|
162 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
theme.class.php
CHANGED
@@ -1,347 +1,99 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
$result = delete_theme($template);
|
101 |
-
ob_end_clean();
|
102 |
-
if (is_wp_error($result))
|
103 |
-
{
|
104 |
-
return new IXR_Error(401, 'Theme could not be deleted. ' . $result->get_error_message());
|
105 |
-
}
|
106 |
-
|
107 |
-
return TRUE;
|
108 |
-
}
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Installs a theme locally
|
112 |
-
*
|
113 |
-
* @param mixed $args
|
114 |
-
*/
|
115 |
-
function install($args)
|
116 |
-
{
|
117 |
-
$this->_escape($args);
|
118 |
-
$username = $args[0];
|
119 |
-
$password = $args[1];
|
120 |
-
$theme = $args[2];
|
121 |
-
$activate = (bool)$args[3];
|
122 |
-
|
123 |
-
if (!$user = $this->login($username, $password))
|
124 |
-
{
|
125 |
-
return $this->error;
|
126 |
-
}
|
127 |
-
|
128 |
-
if (!current_user_can('install_themes'))
|
129 |
-
{
|
130 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to install themes on the remote blog.');
|
131 |
-
}
|
132 |
-
|
133 |
-
ob_start();
|
134 |
-
|
135 |
-
// include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
136 |
-
include_once(ABSPATH . 'wp-admin/includes/theme-install.php');
|
137 |
-
|
138 |
-
$api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false)));
|
139 |
-
|
140 |
-
if (is_wp_error($api))
|
141 |
-
{
|
142 |
-
return new IXR_Error(401, 'Could not install theme. ' . $api->get_error_message());
|
143 |
-
}
|
144 |
-
|
145 |
-
$upgrader = new Mmb_Theme_Upgrader();
|
146 |
-
$result = $upgrader->install($api->download_link);
|
147 |
-
|
148 |
-
if (is_wp_error($result))
|
149 |
-
{
|
150 |
-
return new IXR_Error(401, 'Theme could not be installed. ' . $result->get_error_message());
|
151 |
-
}
|
152 |
-
|
153 |
-
// activate!
|
154 |
-
if ($activate && $theme_info = $upgrader->theme_info())
|
155 |
-
{
|
156 |
-
$stylesheet = $upgrader->result['destination_name'];
|
157 |
-
$template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
|
158 |
-
|
159 |
-
$this->activate(array($username, $password, $template, $stylesheet));
|
160 |
-
}
|
161 |
-
|
162 |
-
ob_end_clean();
|
163 |
-
|
164 |
-
// get the updated theme list
|
165 |
-
return $this->get_list($args);
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Uploads a theme given its URL
|
170 |
-
*
|
171 |
-
* @param mixed $args
|
172 |
-
*/
|
173 |
-
function upload_by_url($args)
|
174 |
-
{
|
175 |
-
$this->_escape($args);
|
176 |
-
$username = $args[0];
|
177 |
-
$password = $args[1];
|
178 |
-
$url = $args[2];
|
179 |
-
|
180 |
-
if (!$user = $this->login($username, $password))
|
181 |
-
{
|
182 |
-
return $this->error;
|
183 |
-
}
|
184 |
-
|
185 |
-
if (!current_user_can('install_themes'))
|
186 |
-
{
|
187 |
-
return new IXR_Error(401, 'Sorry, you are not allowed to install themes on the remote blog.');
|
188 |
-
}
|
189 |
-
|
190 |
-
if (!$this->_init_filesystem())
|
191 |
-
return new IXR_Error(401, 'Theme could not be installed: Failed to initialize file system.');
|
192 |
-
|
193 |
-
|
194 |
-
ob_start();
|
195 |
-
$tmp_file = download_url($url);
|
196 |
-
|
197 |
-
if(is_wp_error($tmp_file))
|
198 |
-
return new IXR_Error(401, 'Theme could not be installed. ' . $response->get_error_message());
|
199 |
-
|
200 |
-
$result = unzip_file($tmp_file, WP_CONTENT_DIR . '/themes');
|
201 |
-
unlink($tmp_file);
|
202 |
-
|
203 |
-
if(is_wp_error($result))
|
204 |
-
{
|
205 |
-
return new IXR_Error(401, 'Theme could not be extracted. ' . $result->get_error_message());
|
206 |
-
}
|
207 |
-
|
208 |
-
unset($args[2]);
|
209 |
-
|
210 |
-
return $this->get_list($args);
|
211 |
-
}
|
212 |
-
function upload_theme_by_url($args){
|
213 |
-
|
214 |
-
$this->_escape($args);
|
215 |
-
$username = $args[0];
|
216 |
-
$password = $args[1];
|
217 |
-
$url = $args[2];
|
218 |
-
|
219 |
-
if (!$user = $this->login($username, $password))
|
220 |
-
{
|
221 |
-
return $this->error;
|
222 |
-
}
|
223 |
-
if(!current_user_can('install_themes')){
|
224 |
-
return new IXR_Error( 401, 'Sorry, you are not allowed to manage theme install on the remote blog.');
|
225 |
-
}
|
226 |
-
if (!$this->_init_filesystem())
|
227 |
-
return new IXR_Error(401, 'Theme could not be installed: Failed to initialize file system.');
|
228 |
-
|
229 |
-
ob_start();
|
230 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
231 |
-
$upgrader = new Theme_Upgrader();
|
232 |
-
$result = $upgrader->install($url);
|
233 |
-
ob_end_clean();
|
234 |
-
if(is_wp_error($upgrader->skin->result) || !$upgrader->skin->result){
|
235 |
-
$error = is_wp_error($upgrader->skin->result) ? $upgrader->skin->result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
236 |
-
$this->_last_worker_message(array('error' => print_r($error,true)));
|
237 |
-
}else {
|
238 |
-
$theme = $upgrader->theme_info();
|
239 |
-
$this->_last_worker_message(array('success' => 'true', 'name' => $theme['Name']));
|
240 |
-
}
|
241 |
-
|
242 |
-
}
|
243 |
-
function upgrade($args){
|
244 |
-
$this->_escape($args);
|
245 |
-
$username = $args[0];
|
246 |
-
$password = $args[1];
|
247 |
-
$template = $args[2];
|
248 |
-
$stylesheet = $args[3];
|
249 |
-
$directory = $args[3];
|
250 |
-
$chmod = false;
|
251 |
-
|
252 |
-
if (!$user = $this->login($username, $password))
|
253 |
-
{
|
254 |
-
return $this->error;
|
255 |
-
}
|
256 |
-
if(!current_user_can('install_themes')){
|
257 |
-
return new IXR_Error( 401, 'Sorry, you are not allowed to manage theme install on the remote blog.');
|
258 |
-
}
|
259 |
-
$chmod = fileperms($directory);
|
260 |
-
if($chmod != 0755 ){
|
261 |
-
chmod($directory, 0755);
|
262 |
-
}
|
263 |
-
ob_start();
|
264 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
265 |
-
$upgrader = new Theme_Upgrader( new Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ) );
|
266 |
-
$result = $upgrader->upgrade($stylesheet);
|
267 |
-
ob_end_clean();
|
268 |
-
|
269 |
-
if(is_wp_error($upgrader->skin->result) || !$upgrader->theme_info()){
|
270 |
-
$error = is_wp_error($upgrader->skin->result) ? $upgrader->skin->result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
271 |
-
$this->_last_worker_message(array('error' => print_r($error)));
|
272 |
-
}else {
|
273 |
-
$theme = $upgrader->theme_info();
|
274 |
-
$this->_last_worker_message(array('success' => 'true', 'name' => $theme['Name']));
|
275 |
-
}
|
276 |
-
chmod($directory, $chmod);
|
277 |
-
}
|
278 |
-
function upgrade_all($args){
|
279 |
-
$this->_escape($args);
|
280 |
-
$username = $args[0];
|
281 |
-
$password = $args[1];
|
282 |
-
$themes = $args[2];
|
283 |
-
$chmod = false;
|
284 |
-
|
285 |
-
if (!$user = $this->login($username, $password))
|
286 |
-
{
|
287 |
-
return $this->error;
|
288 |
-
}
|
289 |
-
if(!current_user_can('install_themes')){
|
290 |
-
return new IXR_Error( 401, 'Sorry, you are not allowed to manage theme install on the remote blog.');
|
291 |
-
}
|
292 |
-
|
293 |
-
if(!empty($themes)){
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
ob_start();
|
298 |
-
|
299 |
-
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
300 |
-
$upgrader = new Theme_Upgrader(new Mmb_Bulk_Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ));
|
301 |
-
$result = $upgrader->bulk_upgrade($themes);
|
302 |
-
|
303 |
-
ob_end_clean();
|
304 |
-
if(is_wp_error($result) || !$result){
|
305 |
-
$error = is_wp_error($result) ? $result->get_error_message() : 'Check your FTP details. <a href="http://managewp.com/user-guide#ftp" title="More Info" target="_blank">More Info</a>' ;
|
306 |
-
$this->_last_worker_message(array('error' => print_r($error, true)));
|
307 |
-
}
|
308 |
-
else {
|
309 |
-
$message = '';
|
310 |
-
foreach($result as $theme_tmp => $info){
|
311 |
-
$message .= '<code>'.$theme_tmp.'</code><br />';
|
312 |
-
}
|
313 |
-
$this->_last_worker_message(array('success' => 'true', 'message' => $message));
|
314 |
-
}
|
315 |
-
|
316 |
-
}else {
|
317 |
-
$this->_last_worker_message(array('error' => 'No themes to upgrade.'));
|
318 |
-
}
|
319 |
-
}
|
320 |
-
|
321 |
-
function get_upgradable_themes(){
|
322 |
-
|
323 |
-
$all_themes = get_themes();
|
324 |
-
$upgrade_themes = array();
|
325 |
-
|
326 |
-
//$this->refresh_transient();
|
327 |
-
|
328 |
-
// $current = get_transient('update_plugins');
|
329 |
-
$current = $this->mmb_get_transient('update_themes');
|
330 |
-
// $test = $this->mmb_get_transient('update_plugins');
|
331 |
-
// $this->_log($test);
|
332 |
-
foreach ((array)$all_themes as $theme_template => $theme_data){
|
333 |
-
foreach ($current->response as $current_themes => $theme){
|
334 |
-
if ($theme_data['Template'] == $current_themes)
|
335 |
-
{
|
336 |
-
$current->response[$current_themes]['name'] = $theme_data['Name'];
|
337 |
-
$current->response[$current_themes]['old_version'] = $theme_data['Version'];
|
338 |
-
$current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
|
339 |
-
$upgrade_themes[] = $current->response[$current_themes];
|
340 |
-
continue;
|
341 |
-
}
|
342 |
-
}
|
343 |
-
}
|
344 |
-
|
345 |
-
return $upgrade_themes;
|
346 |
-
}
|
347 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class MMB_Theme extends MMB_Core
|
4 |
+
{
|
5 |
+
function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
}
|
9 |
+
|
10 |
+
|
11 |
+
function upload_theme_by_url($args){
|
12 |
+
|
13 |
+
$this->_escape($args);
|
14 |
+
$url = $args['url'];
|
15 |
+
|
16 |
+
//return (print_r($args, true));
|
17 |
+
ob_start();
|
18 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
19 |
+
include_once(ABSPATH . 'wp-admin/includes/theme.php');
|
20 |
+
include_once(ABSPATH . 'wp-admin/includes/misc.php');
|
21 |
+
include_once(ABSPATH . 'wp-admin/includes/template.php');
|
22 |
+
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
23 |
+
$upgrader = new Theme_Upgrader();
|
24 |
+
$result = $upgrader->install($url);
|
25 |
+
|
26 |
+
ob_end_clean();
|
27 |
+
|
28 |
+
if(is_wp_error($upgrader->skin->result) || !$upgrader->skin->result){
|
29 |
+
$error = 'Failed to upload theme. Check your URL.' ;
|
30 |
+
return array('bool' => false, 'message' => $error) ;
|
31 |
+
|
32 |
+
}else {
|
33 |
+
$theme = $upgrader->theme_info();
|
34 |
+
return array('bool' => true, 'message' => 'Theme '.$upgrader->result[destination_name].' successfully installed ');
|
35 |
+
|
36 |
+
}
|
37 |
+
|
38 |
+
}
|
39 |
+
|
40 |
+
function upgrade_all($params){
|
41 |
+
|
42 |
+
$upgradable_themes = $this->_get_upgradable_themes();
|
43 |
+
|
44 |
+
$ready_for_upgrade = array();
|
45 |
+
if(!empty($upgradable_themes)){
|
46 |
+
foreach($upgradable_themes as $upgrade ){
|
47 |
+
$ready_for_upgrade[] = $upgrade['theme_tmp'];
|
48 |
+
}
|
49 |
+
}
|
50 |
+
if(!empty($ready_for_upgrade)){
|
51 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
52 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
53 |
+
$upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin( compact('title', 'nonce', 'url', 'theme') ));
|
54 |
+
|
55 |
+
$result = $upgrader->bulk_upgrade($ready_for_upgrade);
|
56 |
+
|
57 |
+
$results = array();
|
58 |
+
if(!empty($result)){
|
59 |
+
foreach($result as $theme_tmp => $info){
|
60 |
+
if(is_wp_error($info) || !$info){
|
61 |
+
$results[$theme_tmp] = '<code title="Please upgarde manualy">'.$theme_tmp.'</code> was not upgraded.';
|
62 |
+
}
|
63 |
+
else {
|
64 |
+
$results[$theme_tmp] = '<code>'.$theme_tmp.'</code> succesfully upgraded.';
|
65 |
+
}
|
66 |
+
}
|
67 |
+
return array('upgraded' => implode('', $results));
|
68 |
+
}
|
69 |
+
else return array('error' => 'Could not initialize upgrader.');
|
70 |
+
|
71 |
+
}else {
|
72 |
+
return array('error' => 'No themes available for upgrade.');
|
73 |
+
}
|
74 |
+
}
|
75 |
+
|
76 |
+
function _get_upgradable_themes(){
|
77 |
+
|
78 |
+
$all_themes = get_themes();
|
79 |
+
$upgrade_themes = array();
|
80 |
+
|
81 |
+
$current = $this->mmb_get_transient('update_themes');
|
82 |
+
foreach ((array)$all_themes as $theme_template => $theme_data){
|
83 |
+
if(!empty($current->response)){
|
84 |
+
foreach ($current->response as $current_themes => $theme){
|
85 |
+
if ($theme_data['Template'] == $current_themes)
|
86 |
+
{
|
87 |
+
$current->response[$current_themes]['name'] = $theme_data['Name'];
|
88 |
+
$current->response[$current_themes]['old_version'] = $theme_data['Version'];
|
89 |
+
$current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
|
90 |
+
$upgrade_themes[] = $current->response[$current_themes];
|
91 |
+
continue;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
return $upgrade_themes;
|
98 |
+
}
|
99 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user.class.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class
|
4 |
{
|
5 |
function __construct()
|
6 |
{
|
@@ -11,12 +11,12 @@ class Mmb_User extends Mmb_Core
|
|
11 |
* FACADE functions
|
12 |
* (functions to be called after a remote XMLRPC from Master)
|
13 |
**************************************************************/
|
14 |
-
|
15 |
{
|
16 |
-
$this->_escape($
|
17 |
-
$username = $
|
18 |
-
$password = trim($
|
19 |
-
$new_password = trim(base64_decode($
|
20 |
|
21 |
if ((!$user = $this->login($username, $password)) || ($new_password ==''))
|
22 |
{
|
1 |
<?php
|
2 |
|
3 |
+
class MMB_User extends MMB_Core
|
4 |
{
|
5 |
function __construct()
|
6 |
{
|
11 |
* FACADE functions
|
12 |
* (functions to be called after a remote XMLRPC from Master)
|
13 |
**************************************************************/
|
14 |
+
function change_password($params)
|
15 |
{
|
16 |
+
$this->_escape($params);
|
17 |
+
$username = $params[0];
|
18 |
+
$password = trim($params[1]);
|
19 |
+
$new_password = trim(base64_decode($params[2]));
|
20 |
|
21 |
if ((!$user = $this->login($username, $password)) || ($new_password ==''))
|
22 |
{
|
version
CHANGED
@@ -1 +1 @@
|
|
1 |
-
3.
|
1 |
+
3.8.0
|
wp.class.php
CHANGED
@@ -1,124 +1,91 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class
|
4 |
-
{
|
5 |
-
function __construct()
|
6 |
-
{
|
7 |
-
parent::__construct();
|
8 |
-
}
|
9 |
-
|
10 |
-
/*************************************************************
|
11 |
-
* FACADE functions
|
12 |
-
* (functions to be called after a remote XMLRPC from Master)
|
13 |
-
**************************************************************/
|
14 |
-
function check_version(
|
15 |
-
{
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
ob_end_clean();
|
92 |
-
if(!$result){
|
93 |
-
$this->_last_worker_message(array('success' => 'true', 'version' => $upgrade_info['latest_version']));
|
94 |
-
|
95 |
-
}else {
|
96 |
-
$this->_last_worker_message(array('error' => $result));
|
97 |
-
}
|
98 |
-
}
|
99 |
-
|
100 |
-
/**
|
101 |
-
* Gets updates to core and plugins (just like Tool->Upgrade)
|
102 |
-
*
|
103 |
-
* @param mixed $args
|
104 |
-
*/
|
105 |
-
function get_updates($args)
|
106 |
-
{
|
107 |
-
$this->_escape($args);
|
108 |
-
|
109 |
-
$username = $args[0];
|
110 |
-
$password = $args[1];
|
111 |
-
|
112 |
-
if (!$user = $this->login($username, $password))
|
113 |
-
{
|
114 |
-
return $this->error;
|
115 |
-
}
|
116 |
-
|
117 |
-
$args[] = 1; // get default data
|
118 |
-
|
119 |
-
return array(
|
120 |
-
'core' => $this->check_version($args, FALSE),
|
121 |
-
'plugins' => $this->get_plugin_instance()->get_upgradable_plugins(),
|
122 |
-
);
|
123 |
-
}
|
124 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class MMB_WP extends MMB_Core
|
4 |
+
{
|
5 |
+
function __construct()
|
6 |
+
{
|
7 |
+
parent::__construct();
|
8 |
+
}
|
9 |
+
|
10 |
+
/*************************************************************
|
11 |
+
* FACADE functions
|
12 |
+
* (functions to be called after a remote XMLRPC from Master)
|
13 |
+
**************************************************************/
|
14 |
+
function check_version()
|
15 |
+
{
|
16 |
+
require_once(ABSPATH . 'wp-includes/version.php');
|
17 |
+
require_once(ABSPATH . '/wp-admin/includes/update.php');
|
18 |
+
|
19 |
+
$updates = get_core_updates();
|
20 |
+
$update = $updates[0];
|
21 |
+
global $wp_version;
|
22 |
+
|
23 |
+
if (!isset($update->response) || 'latest' == $update->response) {
|
24 |
+
return array(
|
25 |
+
'current_version' => $wp_version,
|
26 |
+
'latest_version' => false
|
27 |
+
);
|
28 |
+
} else {
|
29 |
+
return array(
|
30 |
+
'current_version' => $wp_version,
|
31 |
+
'latest_version' => $update
|
32 |
+
);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Upgrades WordPress locally
|
38 |
+
*
|
39 |
+
*/
|
40 |
+
function upgrade($params){
|
41 |
+
|
42 |
+
ob_start();
|
43 |
+
require_once(ABSPATH . 'wp-admin/includes/file.php');
|
44 |
+
require_once(ABSPATH . 'wp-admin/includes/misc.php');
|
45 |
+
require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
46 |
+
|
47 |
+
WP_Filesystem();
|
48 |
+
global $wp_version, $wp_filesystem;
|
49 |
+
$upgrader = new WP_Upgrader();
|
50 |
+
$updates = $this->mmb_get_transient('update_core');
|
51 |
+
$current = $updates->updates[0];
|
52 |
+
|
53 |
+
|
54 |
+
// Is an update available?
|
55 |
+
if ( !isset( $current->response ) || $current->response == 'latest' )
|
56 |
+
return array('upgraded' => ' has latest '.$wp_version.' WordPress version.');
|
57 |
+
|
58 |
+
$res = $upgrader->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
|
59 |
+
if ( is_wp_error($res) )
|
60 |
+
return array('error' => $this->mmb_get_error($res));
|
61 |
+
|
62 |
+
$wp_dir = trailingslashit($wp_filesystem->abspath());
|
63 |
+
|
64 |
+
$download = $upgrader->download_package( $current->package );
|
65 |
+
if ( is_wp_error($download) )
|
66 |
+
return array('error' => $this->mmb_get_error($download));
|
67 |
+
|
68 |
+
$working_dir = $upgrader->unpack_package( $download );
|
69 |
+
if ( is_wp_error($working_dir) )
|
70 |
+
return array('error' => $this->mmb_get_error($working_dir));
|
71 |
+
|
72 |
+
if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
|
73 |
+
$wp_filesystem->delete($working_dir, true);
|
74 |
+
return array('error' => 'Unable to move update files.');
|
75 |
+
}
|
76 |
+
|
77 |
+
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
|
78 |
+
|
79 |
+
require(ABSPATH . 'wp-admin/includes/update-core.php');
|
80 |
+
ob_end_clean();
|
81 |
+
|
82 |
+
$update_core = update_core($working_dir, $wp_dir);
|
83 |
+
|
84 |
+
if(is_wp_error($update_core))
|
85 |
+
return array('error' => $this->mmb_get_error($update_core));
|
86 |
+
|
87 |
+
$this->mmb_delete_transient('update_core');
|
88 |
+
return array('upgraded' => ' upgraded sucessfully.');
|
89 |
+
}
|
90 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|