ManageWP Worker - Version 3.6.3

Version Description

  • Initial public release

=

Download this release

Release Info

Developer freediver
Plugin Icon 128x128 ManageWP Worker
Version 3.6.3
Comparing to
See all releases

Version 3.6.3

Screenshot-1.png ADDED
Binary file
Screenshot-2.png ADDED
Binary file
Screenshot-3.png ADDED
Binary file
backup.class.php ADDED
@@ -0,0 +1,654 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mmb_Backup extends Mmb_Core {
4
+
5
+ function __construct() {
6
+ $upload_dir = wp_upload_dir();
7
+ $sec_string = md5('mwp-worker');
8
+ $file = "/$sec_string/backups";
9
+ $file_path = $upload_dir['basedir'] . $file;
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
+ $username = $args[0];
22
+ $password = $args[1];
23
+ //type like manual, weekly, daily
24
+ $type = $args[2];
25
+ //what like full, only db, only wp-content
26
+ $what = $args[3];
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('mwp-worker');
40
+ $file = "/$sec_string/backups";
41
+ $file_path = $upload_dir['basedir'] . $file;
42
+
43
+ if(!file_exists($file_path)){
44
+ mkdir($file_path, 0755, true);
45
+ }
46
+
47
+ if(trim($what) == 'full' || trim($what) == 'content' ){
48
+ //take wp-conetnt backup
49
+ $content_backup = $this->backup_wpcontent($type);
50
+ if(!$content_backup){
51
+ @unlink($content_backup['path']);
52
+ return FALSE;
53
+ }
54
+ }
55
+
56
+ if(trim($what) == 'full' || trim($what) == 'db' ){
57
+ //take batabase backup
58
+ $db_backup = $this->backup_db($type);
59
+ if(!$db_backup){
60
+ if(trim($what) == 'full')
61
+ @unlink($content_backup['path']);
62
+
63
+ @unlink($db_backup['path']);
64
+ return false;
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
+ $site_name = get_bloginfo('name');
78
+
79
+ $site_name = str_replace(array(" ","_"),array("",""),$site_name);
80
+
81
+ $backup_file = $file_path.'/'.$site_name.'_'.$type.'_'.$what.'_'.date('Y-m-d').'.zip';
82
+
83
+
84
+ if (!$this->check_zip())
85
+ {
86
+ $archive = new PclZip($backup_file);
87
+
88
+ }
89
+
90
+ if(trim($what) == 'full'){
91
+
92
+ if ($this->check_zip())
93
+ {
94
+ $command = "zip $backup_file -j $content_backup[path] -j $db_backup[path]";
95
+ ob_start();
96
+ passthru($command,$err);
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
+ @unlink($tmp_file);
152
+
153
+ @unlink($content_backup['path']);
154
+ @unlink($db_backup['path']);
155
+
156
+ $backup_url = $upload_dir['baseurl'].$file.'/'.$site_name.'_'.$type.'_'.$what.'_'.date('Y-m-d').'.zip';
157
+ $worker_options = get_option('mwp-worker');
158
+
159
+ //remove old file
160
+ if($worker_options['backups'][$type]['path'] != $backup_file)
161
+ @unlink($worker_options['backups'][$type]['path']);
162
+
163
+
164
+ $worker_options['backups'][$type]['path'] = $backup_file;
165
+ $worker_options['backups'][$type]['url'] = $backup_url;
166
+ update_option('mwp-worker', $worker_options);
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('mwp-worker');
176
+ // $file = "/$sec_string/backups";
177
+ $file = '/'.$sec_string.'/backups/wp-content_'.date('Y-m-d').'.zip';
178
+ $file_path = $upload_dir['basedir'] . $file;
179
+ if ($this->check_zip())
180
+ {
181
+ chdir(WP_CONTENT_DIR);
182
+ $command = "zip -r $file_path 'plugins/' 'themes/' 'uploads/' -x 'uploads/".$sec_string."/*'";
183
+ ob_start();
184
+ passthru($command,$err);
185
+ ob_get_clean();
186
+
187
+ if(!$err){
188
+ $file_url = $upload_dir['baseurl'] . $file;
189
+ return array('path' => $file_path, 'url' => $file_url);
190
+ }
191
+ @unlink($file_path);
192
+ return false;
193
+
194
+ }
195
+ else
196
+ {
197
+ require_once ABSPATH.'/wp-admin/includes/class-pclzip.php';
198
+ $archive = new PclZip($file_path);
199
+ $result = $archive->add(WP_CONTENT_DIR . '/plugins', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
200
+ $result = $archive->add(WP_CONTENT_DIR . '/themes', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
201
+ $result = $archive->add(WP_CONTENT_DIR . '/uploads', PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR);
202
+ // $this->_log($archive);
203
+ $result = $archive->delete(PCLZIP_OPT_BY_NAME, 'uploads/'.$sec_string.'/');
204
+ if($result){
205
+ $file_url = $upload_dir['baseurl'] . $file;
206
+ return array('path' => $file_path, 'url' => $file_url);
207
+ }
208
+ @unlink($file_path);
209
+ return false;
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
+ $result = $this->backup_db_php($type);
226
+ }
227
+ return $result;
228
+ }
229
+
230
+ function backup_db_dump($type, $paths) {
231
+ global $wpdb;
232
+ $upload_dir = wp_upload_dir();
233
+ $sec_string = md5('mwp-worker');
234
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
235
+
236
+ $file = $upload_dir['path'] . '/'.DB_NAME.'.sql';
237
+ $file_url = $upload_dir['baseurl']. '/'.DB_NAME.'.sql';
238
+
239
+ $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;
240
+
241
+
242
+ passthru($command, $error);
243
+
244
+ if(filesize($file) == 0 || !is_file($file) || $error) {
245
+
246
+ @unlink($file);
247
+ return false;
248
+ }else{
249
+
250
+ return array('path' => $file, 'url' => $file_url);
251
+ }
252
+ }
253
+
254
+ function backup_db_php($type) {
255
+ global $wpdb;
256
+ //require_once ABSPATH.'/wp-admin/includes/class-pclzip.php';
257
+ $tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
258
+ $upload_dir = wp_upload_dir();
259
+ $sec_string = md5('mwp-worker');
260
+ $zip_file = '/'.$sec_string.'/backups/db_'.date('Y-m-d').'.zip';
261
+ $zip_file_path = $upload_dir['basedir'] . $zip_file;
262
+
263
+ $file = $upload_dir['path'] . '/'.DB_NAME.'.sql';
264
+ $file_url = $upload_dir['baseurl']. '/'.DB_NAME.'.sql';
265
+
266
+ // $archive = new PclZip($zip_file_path);
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 = "DROP TABLE IF EXISTS $table[0];";
274
+ //create table
275
+ $create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
276
+ $dump_data .= "\n\n".$create_table[1].";\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;$i<$count;$i++){
284
+ $low_limit = $i * 100;
285
+ $qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
286
+ $rows = $wpdb->get_results($qry, ARRAY_A);
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 = 1;
293
+ foreach ($row as $value) {
294
+ $value = addslashes($value);
295
+ $value = ereg_replace("\n", "\\n", $value);
296
+ // $dump_data .= "'".$value . "', ";
297
+
298
+ // if($num_values == $i)
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
+ $username = $args[0];
329
+ $password = $args[1];
330
+ $type = $args[2];
331
+
332
+ if(trim($type) == ''){
333
+ return false;
334
+ }
335
+
336
+ if (!$user = $this->login($username, $password))
337
+ {
338
+ return $this->error;
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
+ if($type != 'weekly' && $type != 'daily')
357
+ {
358
+ // Download backup file from master
359
+ $tmp_file = download_url($type);
360
+
361
+ $backup_file = $backup_path."/". basename($type);
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
+ // $backup_file = glob($file_path);
378
+ // $backup_file = $backup_file[0];
379
+ if($backup_file){
380
+
381
+ if($this->check_unzip())
382
+ {
383
+ mkdir($file_path);
384
+ chdir($file_path);
385
+ $command = "unzip -o $backup_file";
386
+ ob_start();
387
+ passthru($command,$err);
388
+ ob_get_clean();
389
+ }
390
+ else
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
+ return false;
402
+ }
403
+
404
+ list(, $name, $what) = explode('_', basename($backup_file, '.zip'));
405
+
406
+ $this->_log($what);
407
+
408
+
409
+ if(trim($what) == 'full' || trim($what) == 'db' ){
410
+
411
+ if(!$this->restore_db($type, $file_path)){
412
+ return false;
413
+ }
414
+ }
415
+
416
+
417
+
418
+ if(trim($what) == 'full' || trim($what) == 'content' ){
419
+ if(!$this->restore_wpcontent($type, $file_path)){
420
+ return false;
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
+ require_once ABSPATH.'/wp-admin/includes/class-pclzip.php';
436
+ $content_file = glob($file_path."/wp*");
437
+
438
+
439
+ // $this->_log($content_file);
440
+ if($this->check_unzip())
441
+ {
442
+
443
+ chdir(WP_CONTENT_DIR);
444
+ $con_file = $content_file[0];
445
+ $command = "unzip -o $con_file";
446
+ ob_start();
447
+ passthru($command,$err);
448
+ ob_get_clean();
449
+
450
+ }
451
+ else
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
+ // $this->_log($archive);
458
+ // $this->_log($archive->errorInfo(TRUE));
459
+ if($err)
460
+ return FALSE;
461
+ else
462
+ return TRUE;
463
+ }
464
+
465
+ function restore_db($type, $file_path) {
466
+ global $wpdb;
467
+
468
+ $mysqldump = $this->check_mysqldump();
469
+
470
+ //$mysqldump = ''; //debug
471
+ if(is_array($mysqldump))
472
+ {
473
+
474
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
475
+
476
+ foreach(glob($file_path.'/*.sql') as $filename){
477
+
478
+ $command = $brace.$mysqldump['mysql'].$brace.' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" '.DB_NAME.' < '.$brace.$filename.$brace;
479
+ passthru($command, $error);
480
+
481
+ break;
482
+ }
483
+ return $error ? false : true;
484
+ }
485
+ else
486
+ {
487
+
488
+
489
+ // $this->_log($content_file);
490
+
491
+ foreach(glob($file_path.'/*.sql') as $filename){
492
+ // $this->_log($filename);
493
+ // Temporary variable, used to store current query
494
+ $current_query = '';
495
+ // Read in entire file
496
+ $lines = file($filename);
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
+ // Perform the query
509
+ // $this->_log($current_query);
510
+ $result = $wpdb->query($current_query);
511
+ // $this->_log($result);
512
+ if($result === false)
513
+ return FALSE;
514
+ // Reset temp variable to empty
515
+ $current_query = '';
516
+ }
517
+ }
518
+ }
519
+ return true;
520
+
521
+
522
+ }
523
+
524
+
525
+
526
+ }
527
+
528
+ function get_weekly_backup($args) {
529
+ $this->_escape($args);
530
+ $username = $args[0];
531
+ $password = $args[1];
532
+ $type = $args[2];
533
+ if(trim($type) == ''){
534
+ return false;
535
+ }
536
+
537
+ if (!$user = $this->login($username, $password))
538
+ {
539
+ return $this->error;
540
+ }
541
+
542
+ if(!current_user_can('administrator'))
543
+ return new IXR_Error(401, 'Sorry, you are not allowed to perform this action on the site.');
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
+ $backup_path = $upload_dir['baseurl'].$file.'/weekly_'.date('Y-m-d').'.zip';
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
+ if (!$user = $this->login($username, $password))
575
+ {
576
+ return $this->error;
577
+ }
578
+
579
+ if(!current_user_can('administrator'))
580
+ return new IXR_Error(401, 'Sorry, you are not allowed to perform this action on the site.');
581
+
582
+ $worker_options = get_option('mwp-worker');
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
+ function check_zip()
642
+ {
643
+ $zip = @exec('which zip');
644
+ return $zip ? true : false;
645
+ }
646
+
647
+ function check_unzip()
648
+ {
649
+ $zip = @exec('which unzip');
650
+ return $zip ? true : false;
651
+ }
652
+
653
+ }
654
+ ?>
category.class.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,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 $category_instance;
13
+ var $wp_instance;
14
+ var $page_instance;
15
+ var $post_instance;
16
+ var $stats_instance;
17
+ var $user_instance;
18
+ var $tag_instance;
19
+ var $backup_instance;
20
+ // var $ende_instance;
21
+ // protected $secret_key;
22
+
23
+ function __construct(){
24
+ global $mmb_plugin_dir;
25
+ // get_option();
26
+ // $this->secret_key = trim(get_option('siteurl'), ' /');
27
+ $this->name = 'Manage Multiple Blogs';
28
+ $this->slug = 'manage-multiple-blogs';
29
+ $this->settings = get_option($this->slug);
30
+ // $this->ende_instance = new Mmb_EnDe($this->secret_key);
31
+ if (!$this->settings)
32
+ {
33
+ $this->settings = array(
34
+ 'blogs' => array(),
35
+ 'current_blog' => array(
36
+ 'type' => null,
37
+ ),
38
+ );
39
+ }
40
+
41
+ add_action('rightnow_end', array($this, 'add_right_now_info'));
42
+ add_action('wp_footer', array('Mmb_Stats', 'set_hit_count'));
43
+ // add_action('xmlrpc_call', array($this, 'extend_xmlrpc_methods'), 0, 1);
44
+ add_filter('xmlrpc_methods', array($this, 'add_xmlrpc_methods'));
45
+ register_activation_hook($mmb_plugin_dir.'/init.php', array($this, 'install'));
46
+ add_action('init', array($this, 'mmb_test_fix'));
47
+ }
48
+
49
+ function mmb_test_fix() {
50
+
51
+ }
52
+
53
+ /**
54
+ * Add an item into the Right Now Dashboard widget
55
+ * to inform that the blog can be managed remotely
56
+ *
57
+ */
58
+ function add_right_now_info()
59
+ {
60
+ echo '<div class="mmb-slave-info">
61
+ <p>This site can be managed remotely.</p>
62
+ </div>';
63
+ }
64
+
65
+ /**
66
+ * Add custom XMLRPC methods to fit our needs
67
+ * This function should only be called if the current blog is a Slave
68
+ *
69
+ * @param mixed $methods
70
+ */
71
+ function add_xmlrpc_methods($methods)
72
+ {
73
+
74
+ $methods['mmbUpgradeWorker'] = 'mmb_worker_upgrade';
75
+ // stats
76
+ $methods['mmbGetStats'] = 'mmb_stats_get';
77
+ $methods['mmbGetServerStatus'] = 'mmb_stats_server_get';
78
+ $methods['mmbGetUserHitStats'] = 'mmb_stats_hit_count_get';
79
+
80
+ // plugins
81
+ $methods['mmbGetPluginList'] = 'mmb_plugin_get_list';
82
+ $methods['mmbActivatePlugin'] = 'mmb_plugin_activate';
83
+ $methods['mmbDeactivatePlugin'] = 'mmb_plugin_deactivate';
84
+ $methods['mmbUpgradePlugin'] = 'mmb_plugin_upgrade';
85
+ $methods['mmbUpgradePlugins'] = 'mmb_plugin_upgrade_multiple';
86
+ $methods['mmbUpgradeAllPlugins'] = 'mmb_plugin_upgrade_all';
87
+ $methods['mmbDeletePlugin'] = 'mmb_plugin_delete';
88
+ $methods['mmbInstallPlugin'] = 'mmb_plugin_install';
89
+ $methods['mmbUploadPluginByURL'] = 'mmb_plugin_upload_by_url';
90
+
91
+ //themes
92
+ $methods['mmbGetThemeList'] = 'mmb_theme_get_list';
93
+ $methods['mmbActivateTheme'] = 'mmb_theme_activate';
94
+ $methods['mmbDeleteTheme'] = 'mmb_theme_delete';
95
+ $methods['mmbInstallTheme'] = 'mmb_theme_install';
96
+ $methods['mmbUpgradeTheme'] = 'mmb_theme_upgrade';
97
+ $methods['mmbUpgradeThemes'] = 'mmb_themes_upgrade';
98
+ $methods['mmbUploadThemeByURL'] = 'mmb_theme_upload_by_url';
99
+
100
+ // wordpress update
101
+ $methods['mmbWPCheckVersion'] = 'mmb_wp_checkversion';
102
+ $methods['mmbWPUpgrade'] = 'mmb_wp_upgrade';
103
+ $methods['mmbWPGetUpdates'] = 'mmb_wp_get_updates';
104
+
105
+ // categories
106
+ // native XMLRPC method to get category list is not good enough
107
+ // so we make our own
108
+ $methods['mmbGetCategoryList'] = 'mmb_cat_get_list';
109
+ $methods['mmbUpdateCategory'] = 'mmb_cat_update';
110
+ $methods['mmbAddCategory'] = 'mmb_cat_add';
111
+ // (category deleting can be handled well by native XMLRPC method)
112
+
113
+ //tags by ashish
114
+ $methods['mmbGetTagList'] = 'mmb_tag_get_list';
115
+ $methods['mmbUpdateTag'] = 'mmb_tag_update';
116
+ $methods['mmbAddTag'] = 'mmb_tag_add';
117
+ $methods['mmbDeleteTag'] = 'mmb_tag_delete';
118
+
119
+
120
+ // pages
121
+ $methods['mmbGetPageEditData'] = 'mmb_page_get_edit_data';
122
+ $methods['mmbGetPageNewData'] = 'mmb_page_get_new_data';
123
+ $methods['mmbUpdatePage'] = 'mmb_page_update';
124
+ $methods['mmbCreatePage'] = 'mmb_page_create';
125
+
126
+ // posts
127
+ $methods['mmbGetPostList'] = 'mmb_post_get_list';
128
+ $methods['mmbGetPostNewData'] = 'mmb_post_get_new_data';
129
+ $methods['mmbGetPostEditData'] = 'mmb_post_get_edit_data';
130
+ $methods['mmbUpdatePost'] = 'mmb_post_update';
131
+ $methods['mmbCreatePost'] = 'mmb_post_create';
132
+ $methods['mmbPublishPost'] = 'mmb_post_publish';
133
+ $methods['mmbPostChecksum'] = 'mmb_post_checksum';
134
+
135
+ //comments
136
+ $methods['mmbRestoreComment'] = 'mmb_restore_comment';
137
+ $methods['mmbGetCommentCount'] = 'mmb_get_comment_count';
138
+ $methods['mmbBulkEditComment'] = 'mmb_bulk_edit_comment';
139
+
140
+ //users
141
+ $methods['mmbUserChangePassword'] = 'mmb_user_change_password';
142
+
143
+ //Backup/Restore
144
+ $methods['mmbBackupNow'] = 'mmb_backup_now';
145
+ $methods['mmbRestoreNow'] = 'mmb_restore_now';
146
+ $methods['mmbGetBackupUrl'] = 'mmb_get_backup_url';
147
+ $methods['mmbWeeklyBackup'] = 'mmb_weekly_backup';
148
+ $methods['mmbLastWorkerMessage'] = 'mmb_geet_last_worker_message';
149
+ return $methods;
150
+ }
151
+
152
+ /**
153
+ * Gets an instance of the Comment class
154
+ *
155
+ */
156
+ function get_comment_instance()
157
+ {
158
+ if (!isset($this->comment_instance))
159
+ {
160
+ $this->comment_instance = new Mmb_Comment();
161
+ }
162
+
163
+ return $this->comment_instance;
164
+ }
165
+
166
+ /**
167
+ * Gets an instance of the Plugin class
168
+ *
169
+ */
170
+ function get_plugin_instance()
171
+ {
172
+ if (!isset($this->plugin_instance))
173
+ {
174
+ $this->plugin_instance = new Mmb_Plugin();
175
+ }
176
+
177
+ return $this->plugin_instance;
178
+ }
179
+
180
+ /**
181
+ * Gets an instance of the Theme class
182
+ *
183
+ */
184
+ function get_theme_instance()
185
+ {
186
+ if (!isset($this->theme_instance))
187
+ {
188
+ $this->theme_instance = new Mmb_Theme();
189
+ }
190
+
191
+ return $this->theme_instance;
192
+ }
193
+
194
+ /**
195
+ * Gets an instance of Mmb_Page class
196
+ *
197
+ */
198
+ function get_page_instance()
199
+ {
200
+ if (!isset($this->page_instance))
201
+ {
202
+ $this->page_instance = new Mmb_Page();
203
+ }
204
+
205
+ return $this->page_instance;
206
+ }
207
+
208
+ /**
209
+ * Gets an instance of Mmb_Post class
210
+ *
211
+ */
212
+ function get_post_instance()
213
+ {
214
+ if (!isset($this->post_instance))
215
+ {
216
+ $this->post_instance = new Mmb_Post();
217
+ }
218
+
219
+ return $this->post_instance;
220
+ }
221
+
222
+ /**
223
+ * Gets an instance of Category class
224
+ *
225
+ */
226
+ function get_category_instance()
227
+ {
228
+ if (!isset($this->category_instance))
229
+ {
230
+ $this->category_instance = new Mmb_Category();
231
+ }
232
+
233
+ return $this->category_instance;
234
+ }
235
+
236
+ /**
237
+ * Gets an instance of Tag class
238
+ *
239
+ */
240
+ function get_tag_instance()
241
+ {
242
+ if (!isset($this->tag_instance))
243
+ {
244
+ $this->tag_instance = new Mmb_Tags();
245
+ }
246
+
247
+ return $this->tag_instance;
248
+ }
249
+
250
+ /**
251
+ * Gets an instance of the WP class
252
+ *
253
+ */
254
+ function get_wp_instance()
255
+ {
256
+ if (!isset($this->wp_instance))
257
+ {
258
+ $this->wp_instance = new Mmb_WP();
259
+ }
260
+
261
+ return $this->wp_instance;
262
+ }
263
+
264
+ /**
265
+ * Gets an instance of User
266
+ *
267
+ */
268
+ function get_user_instance()
269
+ {
270
+ if (!isset($this->user_instance))
271
+ {
272
+ $this->user_instance = new Mmb_User();
273
+ }
274
+
275
+ return $this->user_instance;
276
+ }
277
+
278
+ /**
279
+ * Gets an instance of stats class
280
+ *
281
+ */
282
+ function get_stats_instance()
283
+ {
284
+ if (!isset($this->stats_instance))
285
+ {
286
+ $this->stats_instance = new Mmb_Stats();
287
+ }
288
+
289
+ return $this->stats_instance;
290
+ }
291
+
292
+ /**
293
+ * Gets an instance of stats class
294
+ *
295
+ */
296
+ function get_backup_instance()
297
+ {
298
+ if (!isset($this->backup_instance))
299
+ {
300
+ $this->backup_instance = new Mmb_Backup();
301
+ }
302
+
303
+ return $this->backup_instance;
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
+ }
ende.class.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mmb_Helper
4
+ {
5
+ /**
6
+ * Creates an ajax response
7
+ *
8
+ * @param mixed $status
9
+ * @param mixed $msg
10
+ */
11
+ function _create_ajax_response($msg, $success = TRUE, $other_html = '')
12
+ {
13
+ $msg = base64_encode($msg);
14
+ $success = $success ? 'true' : 'false';
15
+ echo <<<EOT
16
+ <script type="text/javascript">
17
+ mmbAjaxSuccess = $success;
18
+ mmbAjaxMessage = "$msg";
19
+ </script>
20
+ $other_html
21
+ EOT;
22
+ die();
23
+ }
24
+
25
+ /**
26
+ * A helper function to log data
27
+ *
28
+ * @param mixed $mixed
29
+ */
30
+ function _log($mixed)
31
+ {
32
+ if (is_array($mixed))
33
+ {
34
+ $mixed = print_r($mixed, 1);
35
+ }
36
+ else if (is_object($mixed))
37
+ {
38
+ ob_start();
39
+ var_dump($mixed);
40
+ $mixed = ob_get_clean();
41
+ }
42
+
43
+ $handle = fopen(dirname(__FILE__) . '/log', 'a');
44
+ fwrite($handle, $mixed . PHP_EOL);
45
+ fclose($handle);
46
+ }
47
+
48
+ /**
49
+ * Strips WP disallowed HTML and PHP tags from a string
50
+ *
51
+ * @param mixed $str
52
+ * @return string
53
+ */
54
+ function _strip_tags($str)
55
+ {
56
+ 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>');
57
+ }
58
+
59
+ /**
60
+ * Filters a WordPress content (being comments, pages, posts etc)
61
+ *
62
+ * @param mixed $str
63
+ * @return string
64
+ */
65
+ function _filter_content($str)
66
+ {
67
+ return nl2br($this->_strip_tags($str));
68
+ }
69
+
70
+
71
+
72
+ function _escape(&$array) {
73
+ global $wpdb;
74
+
75
+ if(!is_array($array)) {
76
+ return($wpdb->escape($array));
77
+ }
78
+ else {
79
+ foreach ( (array) $array as $k => $v ) {
80
+ if (is_array($v)) {
81
+ $this->_escape($array[$k]);
82
+ } else if (is_object($v)) {
83
+ //skip
84
+ } else {
85
+ $array[$k] = $wpdb->escape($v);
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ function _base64_encode($str)
92
+ {
93
+ // a plus sign can break the encoded string
94
+ // if sent via URL
95
+ return str_replace('+', '|', base64_encode($str));
96
+ }
97
+
98
+ function _base64_decode($str)
99
+ {
100
+ return base64_decode(str_replace('|', '+', $str));
101
+ }
102
+
103
+ function _print_r($arr)
104
+ {
105
+ if (is_string($arr)) $arr = array($arr);
106
+ echo '<pre>';
107
+ print_r($arr);
108
+ echo '</pre>';
109
+ }
110
+
111
+ /**
112
+ * Initializes the file system
113
+ *
114
+ */
115
+ function _init_filesystem()
116
+ {
117
+ global $wp_filesystem;
118
+
119
+ if (!$wp_filesystem || !is_object($wp_filesystem))
120
+ {
121
+ WP_Filesystem();
122
+ }
123
+
124
+ if (!is_object($wp_filesystem))
125
+ return FALSE;
126
+
127
+ return TRUE;
128
+ }
129
+
130
+ /**
131
+ * Gets transient based on WP version
132
+ *
133
+ * @global string $wp_version
134
+ * @param string $option_name
135
+ * @return mixed
136
+ */
137
+ function mmb_get_transient($option_name)
138
+ {
139
+
140
+ if(trim($option_name) == ''){
141
+ return FALSE;
142
+ }
143
+
144
+ global $wp_version;
145
+
146
+ if (version_compare($wp_version, '2.8', '<'))
147
+ return get_option($option_name);
148
+
149
+ else if (version_compare($wp_version, '3.0', '<'))
150
+ return get_transient($option_name);
151
+
152
+ else
153
+ return get_site_transient($option_name);
154
+
155
+ }
156
+
157
+ function mmb_null_op_buffer($buffer) {
158
+ //do nothing
159
+ if(!ob_get_level())
160
+ ob_start(array($this, 'mmb_null_op_buffer'));
161
+ return '';
162
+ }
163
+
164
+ function _deleteTempDir($directory) {
165
+ if(substr($directory,-1) == "/") {
166
+ $directory = substr($directory,0,-1);
167
+ }
168
+ // $this->_log($directory);
169
+ if(!file_exists($directory) || !is_dir($directory)) {
170
+ return false;
171
+ } elseif(!is_readable($directory)) {
172
+ return false;
173
+ } else {
174
+ $directoryHandle = opendir($directory);
175
+
176
+ while ($contents = readdir($directoryHandle)) {
177
+ if($contents != '.' && $contents != '..') {
178
+ $path = $directory . "/" . $contents;
179
+
180
+ if(is_dir($path)) {
181
+ $this->_deleteTempDir($path);
182
+ } else {
183
+ unlink($path);
184
+ }
185
+ }
186
+ }
187
+ closedir($directoryHandle);
188
+ rmdir($directory);
189
+ return true;
190
+ }
191
+ }
192
+ function _last_worker_message($message){
193
+ add_option('_worker_last_massage', serialize($message)) or update_option('_worker_last_massage', serialize($message));
194
+ }
195
+ function _get_last_worker_message(){
196
+ $message = get_option('_worker_last_massage', array());
197
+ delete_option('_worker_last_massage');
198
+ return (array)maybe_unserialize($message);
199
+ }
200
+ function _is_ftp_writable_mmb(){
201
+ if(defined('FTP_PASS')){
202
+ return true;
203
+ }
204
+ else return false;
205
+ }
206
+ }
init.php ADDED
@@ -0,0 +1,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.6.3
8
+ Author URI: http://prelovac.com/
9
+ */
10
+
11
+ // PHP warnings can break our XML stuffs
12
+
13
+ if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1')
14
+ {
15
+ error_reporting(E_ERROR);
16
+ }
17
+
18
+ define('MMB_WORKER_VERSION', '3.6.3');
19
+
20
+ global $wpdb, $mmb_plugin_dir, $mmb_plugin_url;
21
+
22
+ $mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
23
+ $mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
24
+ //$mmb_plugin_dir = WP_PLUGIN_DIR . '/manage-multiple-blogs-worker';
25
+ //$mmb_plugin_url = WP_PLUGIN_URL . '/manage-multiple-blogs-worker';
26
+
27
+ require_once(ABSPATH . 'wp-includes/class-IXR.php');
28
+ require_once("$mmb_plugin_dir/helper.class.php");
29
+ require_once("$mmb_plugin_dir/ende.class.php");
30
+ require_once("$mmb_plugin_dir/core.class.php");
31
+ require_once("$mmb_plugin_dir/comment.class.php");
32
+ require_once("$mmb_plugin_dir/plugin.class.php");
33
+ require_once("$mmb_plugin_dir/theme.class.php");
34
+ require_once("$mmb_plugin_dir/category.class.php");
35
+ require_once("$mmb_plugin_dir/wp.class.php");
36
+ require_once("$mmb_plugin_dir/page.class.php");
37
+ require_once("$mmb_plugin_dir/post.class.php");
38
+ require_once("$mmb_plugin_dir/stats.class.php");
39
+ require_once("$mmb_plugin_dir/user.class.php");
40
+ require_once("$mmb_plugin_dir/tags.class.php");
41
+ require_once("$mmb_plugin_dir/backup.class.php");
42
+ require_once("$mmb_plugin_dir/clone.class.php");
43
+ require_once("$mmb_plugin_dir/mmb.wp.upgrader.php");
44
+
45
+ //class Mmb_IXR extends IXR_Server{
46
+ //
47
+ //}
48
+
49
+ $mmb_core = new Mmb_Core();
50
+ register_activation_hook(__FILE__, array($mmb_core, 'install'));
51
+
52
+ function mmb_worker_upgrade($args) {
53
+ global $mmb_core;
54
+ return $mmb_core->update_this_plugin($args);
55
+ }
56
+
57
+ function mmb_stats_get($args)
58
+ {
59
+ global $mmb_core;
60
+ return $mmb_core->get_stats_instance()->get($args);
61
+ }
62
+
63
+ function mmb_stats_server_get($args) {
64
+ global $mmb_core;
65
+ return $mmb_core->get_stats_instance()->get_server_stats($args);
66
+ }
67
+
68
+ function mmb_stats_hit_count_get($args) {
69
+ global $mmb_core;
70
+ return $mmb_core->get_stats_instance()->get_hit_count($args);
71
+ }
72
+
73
+ function mmb_plugin_get_list($args)
74
+ {
75
+ global $mmb_core;
76
+ return $mmb_core->get_plugin_instance()->get_list($args);
77
+ }
78
+
79
+ function mmb_plugin_activate($args)
80
+ {
81
+ global $mmb_core;
82
+ return $mmb_core->get_plugin_instance()->activate($args);
83
+ }
84
+
85
+ function mmb_plugin_deactivate($args)
86
+ {
87
+ global $mmb_core;
88
+ return $mmb_core->get_plugin_instance()->deactivate($args);
89
+ }
90
+
91
+ function mmb_plugin_upgrade($args)
92
+ {
93
+ global $mmb_core;
94
+ return $mmb_core->get_plugin_instance()->upgrade($args);
95
+ }
96
+
97
+ function mmb_plugin_upgrade_multiple($args)
98
+ {
99
+ global $mmb_core;
100
+ return $mmb_core->get_plugin_instance()->upgrade_multiple($args);
101
+ }
102
+
103
+ function mmb_plugin_upgrade_all($args)
104
+ {
105
+ global $mmb_core;
106
+ return $mmb_core->get_plugin_instance()->upgrade_all($args);
107
+ }
108
+
109
+ function mmb_plugin_delete($args)
110
+ {
111
+ global $mmb_core;
112
+ return $mmb_core->get_plugin_instance()->delete($args);
113
+ }
114
+
115
+ function mmb_plugin_install($args)
116
+ {
117
+ global $mmb_core;
118
+ return $mmb_core->get_plugin_instance()->install($args);
119
+ }
120
+
121
+ function mmb_plugin_upload_by_url($args)
122
+ {
123
+ global $mmb_core;
124
+ return $mmb_core->get_plugin_instance()->upload_by_url($args);
125
+ }
126
+
127
+
128
+
129
+ function mmb_theme_get_list($args)
130
+ {
131
+ global $mmb_core;
132
+ return $mmb_core->get_theme_instance()->get_list($args);
133
+ }
134
+
135
+ function mmb_theme_activate($args)
136
+ {
137
+ global $mmb_core;
138
+ return $mmb_core->get_theme_instance()->activate($args);
139
+ }
140
+
141
+ function mmb_theme_delete($args)
142
+ {
143
+ global $mmb_core;
144
+ return $mmb_core->get_theme_instance()->delete($args);
145
+ }
146
+
147
+ function mmb_theme_install($args)
148
+ {
149
+ global $mmb_core;
150
+ return $mmb_core->get_theme_instance()->install($args);
151
+ }
152
+
153
+ function mmb_theme_upgrade($args)
154
+ {
155
+ global $mmb_core;
156
+ return $mmb_core->get_theme_instance()->upgrade($args);
157
+ }
158
+
159
+ function mmb_themes_upgrade($args)
160
+ {
161
+ global $mmb_core;
162
+ return $mmb_core->get_theme_instance()->upgrade_all($args);
163
+ }
164
+
165
+ function mmb_theme_upload_by_url($args)
166
+ {
167
+ global $mmb_core;
168
+ return $mmb_core->get_theme_instance()->upload_theme_by_url($args);
169
+ }
170
+
171
+
172
+
173
+
174
+ function mmb_wp_checkversion($args)
175
+ {
176
+ global $mmb_core;
177
+ return $mmb_core->get_wp_instance()->check_version($args);
178
+ }
179
+
180
+ function mmb_wp_upgrade($args)
181
+ {
182
+ global $mmb_core;
183
+ return $mmb_core->get_wp_instance()->upgrade($args);
184
+ }
185
+
186
+ function mmb_wp_get_updates($args)
187
+ {
188
+ global $mmb_core;
189
+ return $mmb_core->get_wp_instance()->get_updates($args);
190
+ }
191
+
192
+
193
+
194
+
195
+
196
+
197
+ function mmb_cat_get_list($args)
198
+ {
199
+ global $mmb_core;
200
+ return $mmb_core->get_category_instance()->get_list($args);
201
+ }
202
+
203
+ function mmb_cat_update($args)
204
+ {
205
+ global $mmb_core;
206
+ return $mmb_core->get_category_instance()->update($args);
207
+ }
208
+
209
+ function mmb_cat_add($args)
210
+ {
211
+ global $mmb_core;
212
+ return $mmb_core->get_category_instance()->add($args);
213
+ }
214
+
215
+
216
+ //Tag start
217
+
218
+
219
+ function mmb_tag_get_list($args)
220
+ {
221
+ global $mmb_core;
222
+ return $mmb_core->get_tag_instance()->get_list($args);
223
+ }
224
+
225
+ function mmb_tag_update($args)
226
+ {
227
+ global $mmb_core;
228
+ return $mmb_core->get_tag_instance()->update($args);
229
+ }
230
+
231
+ function mmb_tag_add($args)
232
+ {
233
+ global $mmb_core;
234
+ return $mmb_core->get_tag_instance()->add($args);
235
+ }
236
+
237
+ function mmb_tag_delete($args)
238
+ {
239
+ global $mmb_core;
240
+ return $mmb_core->get_tag_instance()->delete($args);
241
+ }
242
+ ////End of tag
243
+
244
+ function mmb_page_get_edit_data($args)
245
+ {
246
+ global $mmb_core;
247
+ return $mmb_core->get_page_instance()->get_edit_data($args);
248
+ }
249
+
250
+ function mmb_page_get_new_data($args)
251
+ {
252
+ global $mmb_core;
253
+ return $mmb_core->get_page_instance()->get_new_data($args);
254
+ }
255
+
256
+ function mmb_page_update($args)
257
+ {
258
+ global $mmb_core;
259
+ return $mmb_core->get_page_instance()->update($args);
260
+ }
261
+
262
+ function mmb_page_create($args)
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
+ ?>
mmb.wp.upgrader.php ADDED
@@ -0,0 +1,1489 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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&#8230;');
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&#8230;');
61
+ $this->strings['maintenance_end'] = __('Disabling Maintenance mode&#8230;');
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>&#8230;');
407
+ $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
408
+ $this->strings['deactivate_plugin'] = __('Deactivating the plugin&#8230;');
409
+ $this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;');
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>&#8230;');
418
+ $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
419
+ $this->strings['installing_package'] = __('Installing the plugin&#8230;');
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>&#8230;');
642
+ $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
643
+ $this->strings['remove_old'] = __('Removing the old version of the theme&#8230;');
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>&#8230;');
652
+ $this->strings['unpack_package'] = __('Unpacking the package&#8230;');
653
+ $this->strings['installing_package'] = __('Installing the theme&#8230;');
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>&#8230;');
889
+ $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
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&#8230;'));
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&amp;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&amp;from=import&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin &amp; Run Importer') . '</a>';
1304
+ else
1305
+ $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;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&amp;networkwide=1&amp;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&amp;template=" . urlencode($template) . "&amp;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 &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>',
1378
+ 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $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&amp;template=" . urlencode($template) . "&amp;stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1433
+
1434
+ $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $name)) . '">' . __('Preview') . '</a>';
1435
+ $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate &#8220;%s&#8221;'), $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 ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,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
+ * 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
+ * Upgrades a plugin locally
144
+ *
145
+ * @param mixed $args
146
+ */
147
+ function upgrade($args, $login_required = TRUE, $reget_plugin_data = TRUE)
148
+ {
149
+ $this->_escape($args);
150
+ $username = $args[0];
151
+ $password = $args[1];
152
+ $plugin_file = $args[2];
153
+
154
+ if ($login_required && !$user = $this->login($username, $password))
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
+ * Upgrades all upgradable plugins on this blog
247
+ *
248
+ * @param mixed $args
249
+ */
250
+ function upgrade_all($args)
251
+ {
252
+ include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
253
+ $this->_escape($args);
254
+ $username = $args[0];
255
+ $password = $args[1];
256
+
257
+ if ($this->worker_maitanance_mode){
258
+ $this->_last_worker_message(array('error' => 'Blog is currently under maintenance. Please try again after few minutes.'));
259
+ die();
260
+ }
261
+ if (!$user = $this->login($username, $password))
262
+ {
263
+ return $this->error;
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
+ * Installs a plugin by its slug
382
+ *
383
+ * @param mixed $args
384
+ */
385
+ function install($args)
386
+ {
387
+ $this->_escape($args);
388
+ $username = $args[0];
389
+ $password = $args[1];
390
+ $slug = $args[2];
391
+ $activate = (bool)$args[3];
392
+
393
+ if (!$user = $this->login($username, $password))
394
+ {
395
+ return $this->error;
396
+ }
397
+ if (!current_user_can('install_plugins'))
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
+ ob_start();
403
+ include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
404
+ // include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
405
+
406
+ $api = plugins_api('plugin_information', array('slug' => $slug, 'fields' => array('sections' => false)));
407
+
408
+ if (is_wp_error($api))
409
+ return new IXR_Error(401, 'Failed to install plugin. ' . $api->get_error_message());
410
+
411
+ // $upgrader = new Plugin_Upgrader();
412
+ $upgrader = new Mmb_Plugin_Upgrader();
413
+ $upgrader->install($api->download_link);
414
+
415
+ $output = ob_get_clean();
416
+
417
+ if ($activate)
418
+ {
419
+ $this->activate(array($username, $password, $upgrader->plugin_info()));
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 refresh_transient()
428
+ {
429
+ delete_transient('update_plugins');
430
+ $current = $this->mmb_get_transient('update_plugins');
431
+ wp_update_plugins();
432
+
433
+ return $current;
434
+ }
435
+
436
+ /**
437
+ * Uploads a plugin, given its package url
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
+ }
post.class.php ADDED
@@ -0,0 +1,656 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mmb_Post 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
+ 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&#8217;t exist. Perhaps it was deleted?');
125
+
126
+ if ('trash' == $post->post_status)
127
+ return new IXR_Error(401, 'You can&#8217;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
+ $post_struct = unserialize(base64_decode($args[2]));
318
+ $post_data = $post_struct['post_data'];
319
+ $new_custom = $post_struct['post_extras']['post_meta'];
320
+ $post_categories = explode(',', $post_struct['post_extras']['post_categories']);
321
+ $post_atta_img = $post_struct['post_extras']['post_atta_images'];
322
+ $post_upload_dir = $post_struct['post_extras']['post_upload_dir'];
323
+ $post_checksum = $post_struct['post_extras']['post_checksum'];
324
+ $post_featured_img = $post_struct['post_extras']['featured_img'];
325
+
326
+ //create post
327
+ //$post_id = wp_insert_post($post_data);
328
+
329
+ $upload = wp_upload_dir();
330
+
331
+ // create dynamic url RegExp
332
+ $mwp_base_url = parse_url($post_upload_dir['url']);
333
+ $mwp_regexp_url = $mwp_base_url['host'].$mwp_base_url['path'];
334
+ $rep = array('/', '+', '.', ':', '?');
335
+ $with = array('\/', '\+', '\.', '\:', '\?');
336
+ $mwp_regexp_url = str_replace($rep, $with, $mwp_regexp_url);
337
+
338
+ // rename all src ../wp-content/ with hostname/wp-content/
339
+ $mwp_dot_url = '..'.$mwp_base_url['path'];
340
+ $mwp_dot_url = str_replace($rep, $with, $mwp_dot_url);
341
+ $dot_match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]*'.$mwp_dot_url.'[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $dot_get_urls, PREG_SET_ORDER);
342
+ if($dot_match_count > 0){
343
+ foreach($dot_get_urls as $dot_url){
344
+ $match_dot = '/'.str_replace($rep, $with, $dot_url[4]).'/';
345
+ $replace_dot = 'http://'.$mwp_base_url['host'].substr( $dot_url[4], 2, strlen($dot_url[4]) );
346
+ $post_data['post_content'] = preg_replace($match_dot, $replace_dot, $post_data['post_content']);
347
+
348
+ if($dot_url[1] != ''){
349
+ $match_dot_a = '/'.str_replace($rep, $with, $dot_url[2]).'/';
350
+ $replace_dot_a = 'http://'.$mwp_base_url['host'].substr( $dot_url[2], 2, strlen($dot_url[2]) );
351
+ $post_data['post_content'] = preg_replace($match_dot_a, $replace_dot_a, $post_data['post_content']);
352
+ }
353
+ }
354
+ }
355
+
356
+ //to find all the images
357
+ $match_count = preg_match_all('/(<a[^>]+href=\"([^"]+)\"[^>]*>)?(<\s*img.[^\/>]*src="([^"]+'.$mwp_regexp_url.'[^\s]+\.(jpg|jpeg|png|gif|bmp))"[^>]*>)/ixu', $post_data['post_content'], $get_urls, PREG_SET_ORDER);
358
+ if($match_count > 0){
359
+ $attachments = array();
360
+ $post_content = $post_data['post_content'];
361
+
362
+ foreach($get_urls as $get_url_k => $get_url){
363
+ // unset url in attachment array
364
+ foreach($post_atta_img as $atta_url_k => $atta_url_v){
365
+ $match_patt_url = '/'.str_replace($rep, $with, substr($atta_url_v['src'], 0, strrpos($atta_url_v['src'], '.')) ).'/';
366
+ if( preg_match($match_patt_url, $get_url[4]) ){
367
+ unset($post_atta_img[$atta_url_k]);
368
+ }
369
+ }
370
+
371
+ if( isset($get_urls[$get_url_k][6])){ // url have parent, don't download this url
372
+ if($get_url[1] != ''){
373
+ // change src url
374
+ $s_mwp_mp = '/'.str_replace($rep, $with, $get_url[4]).'/';
375
+ $s_img_atta = wp_get_attachment_image_src( $get_urls[$get_url_k][6] );
376
+ $s_mwp_rp = $s_img_atta[0];
377
+ $post_content = preg_replace($s_mwp_mp, $s_mwp_rp, $post_content);
378
+ // change attachment url
379
+ if( preg_match('/attachment_id/i', $get_url[2]) ){
380
+ $mwp_mp = '/'.str_replace($rep, $with, $get_url[2]).'/';
381
+ $mwp_rp = get_bloginfo('wpurl').'/?attachment_id='.$get_urls[$get_url_k][6];
382
+ $post_content = preg_replace($mwp_mp, $mwp_rp, $post_content);
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
+ @unlink($tmp_file);
462
+ }
463
+ // $updated_post = array();
464
+ // $updated_post['ID'] = $results[$i]->ID;
465
+ // $updated_post['post_content'] = $post_content;
466
+
467
+ $post_data['post_content'] = $post_content;
468
+
469
+ }
470
+ if(count($post_atta_img)){
471
+ foreach($post_atta_img as $img){
472
+ $file_name = basename($img['src']);
473
+ $tmp_file = download_url($img['src']);
474
+ $attach_upload['url'] = $upload['url'].'/'.$file_name;
475
+ $attach_upload['path'] = $upload['path'].'/'.$file_name;
476
+ $renamed = rename($tmp_file, $attach_upload['path']);
477
+ if($renamed === true){
478
+ $atta_ext = end(explode('.', $file_name));
479
+
480
+ $attachment = array(
481
+ 'post_title' => $file_name,
482
+ 'post_content' => '',
483
+ 'post_type' => 'attachment',
484
+ //'post_parent' => $post_id,
485
+ 'post_mime_type' => 'image/'.$atta_ext,
486
+ 'guid' => $attach_upload['url']
487
+ );
488
+
489
+ // Save the data
490
+ $attach_id = wp_insert_attachment( $attachment, $attach_upload['path'] );
491
+ wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $attach_upload['path'] ) );
492
+ $attachments[$attach_id] = 0;
493
+
494
+ // featured image
495
+ if($post_featured_img != ''){
496
+ $feat_img_url = '';
497
+ if( preg_match('/-\d{3}x\d{3}\.[a-zA-Z0-9]{3,4}$/', $post_featured_img) ){
498
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.') - 8);
499
+ }else{
500
+ $feat_img_url = substr($post_featured_img, 0, strrpos($post_featured_img, '.'));
501
+ }
502
+ $m_feat_url = '/'.str_replace($rep, $with, $feat_img_url ).'/';
503
+ if( preg_match($m_feat_url, $img['src']) ){
504
+ $post_featured_img = '';
505
+ $attachments[$attach_id] = $attach_id;
506
+ }
507
+ }
508
+
509
+ }
510
+ @unlink($tmp_file);
511
+ }
512
+ }
513
+
514
+ // create post
515
+ $post_id = wp_insert_post($post_data);
516
+ if(count($attachments)){
517
+ foreach($attachments as $atta_id => $featured_id){
518
+ $result = wp_update_post(array('ID' => $atta_id, 'post_parent' => $post_id));
519
+ if($featured_id > 0){
520
+ $new_custom['_thumbnail_id'] = array( $featured_id );
521
+ }
522
+ }
523
+ }
524
+
525
+ // featured image
526
+ if($post_featured_img != ''){
527
+ $file_name = basename($post_featured_img);
528
+ $tmp_file = download_url($post_featured_img);
529
+ $attach_upload['url'] = $upload['url'].'/'.$file_name;
530
+ $attach_upload['path'] = $upload['path'].'/'.$file_name;
531
+ $renamed = rename($tmp_file, $attach_upload['path']);
532
+ if($renamed === true){
533
+ $atta_ext = end(explode('.', $file_name));
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/'.$atta_ext,
541
+ 'guid' => $attach_upload['url']
542
+ );
543
+
544
+ // Save the data
545
+ $attach_id = wp_insert_attachment( $attachment, $attach_upload['path'] );
546
+ wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $attach_upload['path'] ) );
547
+ $new_custom['_thumbnail_id'] = array( $attach_id );
548
+ }
549
+ @unlink($tmp_file);
550
+ }
551
+
552
+ //checksum
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 = get_post_custom($post_id);
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
+ //TODO : handle other post attributes like sticky, private, etc
586
+ }
587
+
588
+ /**
589
+ * Locally publishes a post
590
+ *
591
+ * @param mixed $args
592
+ */
593
+ function publish($args)
594
+ {
595
+ $this->_escape($args);
596
+ $username = $args[0];
597
+ $password = $args[1];
598
+ $post_id = $args[2];
599
+
600
+ if (!$user = $this->login($username, $password))
601
+ {
602
+ return $this->error;
603
+ }
604
+
605
+ if (!current_user_can('edit_post', $post_id))
606
+ return new IXR_Error(401, 'You are not allowed to edit this post.');
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
+ }
readme.txt ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === ManageWP Worker ===
2
+ Contributors: freediver
3
+ Donate link: https://www.networkforgood.org/donation/MakeDonation.aspx?ORGID2=520781390
4
+ Tags: managewp, managewp worker, admin, manage blogs, multi blog manager, manage multiple blogs
5
+ Requires at least: 3.0
6
+ Tested up to: 3.1
7
+ Stable tag: trunk
8
+
9
+ ManageWP Worker plugin allows you to remotely manage your blogs from one dashboard.
10
+
11
+ == Description ==
12
+
13
+ ManageWP is a revolutionary plugin that allows you to manage multiple WordPress blogs from one dashboard.
14
+
15
+ Features:
16
+ - One click WordPress, plugin and themes upgrades across all sites
17
+ - Access admin of any site without leaving the dasboard
18
+ - Publish posts to multiple sites at once
19
+ - Add links to blogroll and add new user to multiple sites
20
+ - Automatic backups of your sites
21
+ - Clone one site to another
22
+ - Many, many more...
23
+
24
+ Check out [ManageWP.com](http://managewp.com/ "Manage Multiple Blogs")
25
+
26
+ == Changelog ==
27
+
28
+ = 3.6.3 =
29
+ * Initial public release
30
+
31
+ == Installation ==
32
+
33
+ 1. Upload the whole plugin folder to your /wp-content/plugins/ folder.
34
+ 2. Go to the Plugins page and activate the plugin.
35
+ 3. Visit [ManageWP.com](http://managewp.com/ "Manage Multiple Blogs"), sign up and add your blogs
36
+
37
+
38
+ == Screenshots ==
39
+
40
+ 1. Global dashboard with quick upgrades
41
+ 2. Manage every blog with statistics
42
+ 3. ManageWP.com
43
+
44
+
45
+
46
+ == License ==
47
+
48
+ This file is part of ManageWP Worker.
49
+
50
+ ManageWP Worker is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
51
+
52
+ ManageWP Worker is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
53
+
54
+ You should have received a copy of the GNU General Public License along with ManageWP Worker. If not, see <http://www.gnu.org/licenses/>.
55
+
56
+
57
+ == Frequently Asked Questions ==
58
+
59
+ = I have problems installing new plugins =
60
+
61
+ ManageWP Worker currently relies on file permissions set up correctly on your server, in order to write files to your plugin folder. Some servers require ftp login details to write the files and Plugin Central will support this option in the future.
62
+
stats.class.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mmb_Stats extends Mmb_Core
3
+ {
4
+ function __construct()
5
+ {
6
+ parent::__construct();
7
+ }
8
+
9
+ /*************************************************************
10
+ * FACADE functions
11
+ * (functions to be called after a remote XMLRPC from Master)
12
+ **************************************************************/
13
+
14
+ function get($args)
15
+ {
16
+ $this->_escape($args);
17
+
18
+ $username = $args[0];
19
+ $password = $args[1];
20
+ // $this->_log($username);
21
+ // $this->_log($password);
22
+
23
+ if (!$user = $this->login($username, $password))
24
+ {
25
+ return $this->error;
26
+ }
27
+
28
+ // Things to get:
29
+ // pending comments
30
+ // drafts
31
+ // available plugin upgrades
32
+ // available wordpress upgrade
33
+ // version of worker plugin
34
+ // and???
35
+
36
+ $stats = array();
37
+
38
+ $mmb_user_hits = get_option('user_hit_count');
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
+
48
+ if (current_user_can('moderate_comments'))
49
+ {
50
+ // pending comments
51
+ $pending_comments = get_comments('status=hold&number=5');
52
+ // trim off unnecessary data
53
+ foreach ($pending_comments as &$comment)
54
+ {
55
+ $commented_post = get_post($comment->comment_post_ID);
56
+ $comment->post_title = $commented_post->post_title;
57
+ }
58
+
59
+ $stats['pending_comments'] = $pending_comments;
60
+ }
61
+
62
+ // drafts
63
+ $drafts = get_posts('post_status=draft&numberposts=0');
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 (current_user_can('activate_plugins'))
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 get_server_stats($args) {
117
+ $this->_escape($args);
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
+ if(!current_user_can('administrator')){
131
+ return array('add_error'=>'You are not an administrator on %s. Please use an account with administrator privilege.');
132
+ }
133
+
134
+ if (current_user_can('upload_files')){
135
+ // check if wp-content is writable
136
+ // $this->_log(is_writable(WP_CONTENT_DIR));
137
+ // if(is_writable(WP_CONTENT_DIR) && is_writable(WP_CONTENT_DIR.'/plugins') && is_writable(WP_CONTENT_DIR.'/themes') && is_writable(WP_CONTENT_DIR.'/uploads') && is_writable(WP_CONTENT_DIR.'/upgrade')){
138
+ if(is_writable(WP_CONTENT_DIR) && is_writable(WP_CONTENT_DIR.'/plugins') && is_writable(WP_CONTENT_DIR.'/themes')){
139
+ $stats['writable'] = TRUE;
140
+ }else{
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
+ return $stats;
148
+
149
+ }
150
+
151
+ function set_hit_count($fix_count = false) {
152
+ // TODO : IP based checking for hit count
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
+ if(is_single () || $fix_count){
172
+ $date = date('Y-m-d');
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
+ }else{
178
+ $dated_keys = array_keys($user_hit_count);
179
+ $last_visit_date = $dated_keys[count($dated_keys)-1];
180
+
181
+ // $diff = strtotime($date) - strtotime($last_visit_date);
182
+ // $sec = $diff % 60;
183
+ // $diff = intval($diff / 60);
184
+ // $min = $diff % 60;
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<$days ; $i++){
200
+ if(count($user_hit_count) > 7)
201
+ {
202
+ $shifted = @array_shift($user_hit_count);
203
+ }
204
+ //$next_day = ($dt + $i);
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
+ $user_hit_count[$next_key] = 0;
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
+ $user_hit_count[$date] = 0;
220
+ }
221
+ if(!$fix_count)
222
+ $user_hit_count[$date] += 1;
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
+ // $this->_log($user_hit_count);
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
+ end($mmb_user_hits);
239
+ $last_key_date = key($mmb_user_hits);
240
+ $current_date = date('Y-m-d');
241
+ if($last_key_date != $curent_date)
242
+ $this->set_hit_count(true);
243
+
244
+ return get_option('user_hit_count');
245
+ }
246
+
247
+ }
tags.class.php ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mmb_Theme 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
+ function get_list($args)
16
+ {
17
+ $this->_escape($args);
18
+ $username = $args[0];
19
+ $password = $args[1];
20
+
21
+ if (!$user = $this->login($username, $password))
22
+ {
23
+ return $this->error;
24
+ }
25
+
26
+ if(!current_user_can('switch_themes'))
27
+ return new IXR_Error(401, 'Sorry, you are not allowed to manage themes on the remote blog.');
28
+
29
+ $all_themes = get_themes();
30
+ $theme_updates = $this->mmb_get_transient('update_themes');
31
+ $current_theme = current_theme_info();
32
+
33
+ foreach($all_themes as $theme_name => $theme_data){
34
+ if(isset($theme_updates->response[$theme_data['Template']])){
35
+ $all_themes[$theme_name]['new_version'] = $theme_updates->response[$theme_data['Template']]['new_version'];
36
+ $all_themes[$theme_name]['new_url'] = $theme_updates->response[$theme_data['Template']]['url'];
37
+ }
38
+ }
39
+ $activated_theme = $all_themes[$current_theme->name];
40
+ unset($all_themes[$current_theme->name]);
41
+
42
+ // I don't bother paging
43
+ // who would have 100's of themes anyway?
44
+ return array(
45
+ 'current' => $activated_theme,
46
+ 'inactive' => $all_themes,
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Activates a theme locally
52
+ *
53
+ * @param mixed $args
54
+ */
55
+ function activate($args)
56
+ {
57
+ $this->_escape($args);
58
+ $username = $args[0];
59
+ $password = $args[1];
60
+ $template = $args[2];
61
+ $stylesheet = $args[3];
62
+
63
+ if (!$user = $this->login($username, $password))
64
+ {
65
+ return $this->error;
66
+ }
67
+
68
+ if(!current_user_can('switch_themes'))
69
+ return new IXR_Error(401, 'Sorry, you are not allowed to activate themes on the remote blog.');
70
+
71
+ switch_theme($template, $stylesheet);
72
+
73
+ // get the new updated theme list
74
+ return $this->get_list($args);
75
+ }
76
+
77
+ /**
78
+ * Deletes a theme locally
79
+ *
80
+ * @param mixed $args
81
+ */
82
+ function delete($args)
83
+ {
84
+ $this->_escape($args);
85
+ $username = $args[0];
86
+ $password = $args[1];
87
+ $template = $args[2];
88
+
89
+ if (!$user = $this->login($username, $password))
90
+ {
91
+ return $this->error;
92
+ }
93
+
94
+ if(!current_user_can('update_themes'))
95
+ {
96
+ return new IXR_Error(401, 'Sorry, you are not allowed to delete themes from the remote blog.');
97
+ }
98
+
99
+ ob_start();
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
+ }
user.class.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mmb_User 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 change_password($args)
15
+ {
16
+ $this->_escape($args);
17
+ $username = $args[0];
18
+ $password = trim($args[1]);
19
+ $new_password = trim(base64_decode($args[2]));
20
+
21
+ if ((!$user = $this->login($username, $password)) || ($new_password ==''))
22
+ {
23
+ return FALSE;
24
+ }
25
+
26
+ wp_update_user(array(
27
+ 'ID' => $user->data->ID,
28
+ 'user_pass' => $new_password,
29
+ ));
30
+
31
+ return TRUE;
32
+ }
33
+ }
34
+
version ADDED
@@ -0,0 +1 @@
 
1
+ 3.6.3
wp.class.php ADDED
@@ -0,0 +1,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($args, $login_required = TRUE)
15
+ {
16
+ $this->_escape($args);
17
+
18
+ $username = $args[0];
19
+ if($login_required)
20
+ $password = $args[1];
21
+ // $password = $this->ende_instance->decrypt(base64_decode($args[1]));
22
+ $get_default_data = (bool) $args[2];
23
+
24
+ if ($login_required && !$user = $this->login($username, $password))
25
+ {
26
+ return $this->error;
27
+ }
28
+
29
+ if (!current_user_can('update_plugins'))
30
+ {
31
+ return new IXR_Error(401, 'You do not have sufficient permissions to upgrade WordPress on the remote blog.');
32
+ }
33
+
34
+ require_once(ABSPATH . 'wp-includes/version.php');
35
+
36
+ $updates = get_core_updates();
37
+ $update = $updates[0];
38
+ global $wp_version;
39
+ if (!isset($update->response) || 'latest' == $update->response)
40
+ {
41
+ if (!$get_default_data)
42
+ return new IXR_Error(999, 'The remote blog has the latest version of WordPress. You do not need to upgrade.');
43
+
44
+ // return default (current version) data
45
+ // this is used when initial blog row
46
+ return array(
47
+ 'current_version' => $wp_version,
48
+ 'latest_version' => FALSE,
49
+ );
50
+ }
51
+ else
52
+ {
53
+ return array(
54
+ 'current_version' => $wp_version,
55
+ 'latest_version' => $update,
56
+ );
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Upgrades WordPress locally
62
+ *
63
+ */
64
+ function upgrade($args){
65
+
66
+ $username = $args[0];
67
+ // $password = $this->ende_instance->decrypt(base64_decode($args[1]));
68
+ $password = $args[1];
69
+
70
+ if (!$user = $this->login($username, $password))
71
+ {
72
+ $this->_last_worker_message(array('error' => $this->error));
73
+ }
74
+
75
+ if(!current_user_can('administrator')){
76
+ $this->_last_worker_message(array('error' => "You don't have permissions to upgrade this blog."));
77
+ die();
78
+ }
79
+
80
+ $upgrade_info = $this->check_version($args);
81
+ if(empty($upgrade_info['latest_version'])){
82
+ $this->_last_worker_message(array('error' => print_r($upgrade_info, true)));
83
+ die();
84
+ }
85
+ ob_start();
86
+
87
+ include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
88
+ $upgrader = new Core_Upgrader();
89
+ $result = $upgrader->upgrade($upgrade_info['latest_version']);
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
+ }