InfiniteWP Client - Version 1.1.5

Version Description

  • WP 3.5 compatibility
  • Backup system improved
  • Dropbox upload 500 error fixed
Download this release

Release Info

Developer infinitewp
Plugin Icon 128x128 InfiniteWP Client
Version 1.1.5
Comparing to
See all releases

Code changes from version 1.1.4 to 1.1.5

backup.class.php CHANGED
@@ -172,7 +172,7 @@ if (is_array($params['account_info'])) { //only if sends from IWP Admin Panel fi
172
}
173
}
174
175
- if ($time) { //set next result time before backup
176
if (is_array($before[$task_name]['task_results'])) {
177
$before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
178
}
@@ -316,7 +316,7 @@ function delete_task_now($task_name){
316
317
function backup($args, $task_name = false)
318
{
319
- if (!$args || empty($args))
320
return false;
321
322
extract($args); //extract settings
@@ -325,7 +325,11 @@ function delete_task_now($task_name){
325
$this->set_memory();
326
327
//Remove old backup(s)
328
- $this->remove_old_backups($task_name);
329
330
$new_file_path = IWP_BACKUP_DIR;
331
@@ -378,39 +382,38 @@ function delete_task_now($task_name){
378
ob_start();
379
$result = $this->iwp_mmb_exec($command);
380
ob_get_clean();
381
/*zip_backup_db */
382
if(!$result){
383
$zip_archive_db_result = false;
384
if (class_exists("ZipArchive")) {
385
$this->_log("DB zip, fallback to ZipArchive");
386
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
387
}
388
389
if (!$zip_archive_db_result) {
390
// fallback to pclzip
391
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
392
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
393
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
394
$archive = new IWPPclZip($backup_file);
395
- /*if ($disable_comp) {
396
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
397
-
398
- } else {
399
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
400
- }*/
401
if($fail_safe_files && $disable_comp){
402
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
403
}
404
elseif(!$fail_safe_files && $disable_comp){
405
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
406
}
407
elseif($fail_safe_files && !$disable_comp){
408
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
409
}
410
else{
411
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
412
}
413
@unlink($db_result);
414
@rmdir(IWP_DB_DIR);
415
if (!$result) {
416
return array(
@@ -421,12 +424,13 @@ function delete_task_now($task_name){
421
}
422
423
@unlink($db_result);
424
@rmdir(IWP_DB_DIR);
425
- if (!$result) {
426
return array(
427
'error' => 'Failed to zip database.'
428
);
429
- }
430
$this->update_status($task_name, $this->statuses['db_zip'], true);
431
}
432
} elseif (trim($what) == 'full') {
@@ -566,7 +570,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
566
567
function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
568
{
569
- global $zip_errors;
570
$sys = substr(PHP_OS, 0, 3);
571
572
$this->update_status($task_name, $this->statuses['db_dump']);
@@ -597,6 +602,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
597
ob_start();
598
$result = $this->iwp_mmb_exec($command);
599
ob_get_clean();
600
/*zip_backup_db*/
601
602
if(!$result){
@@ -604,27 +610,30 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
604
if (class_exists("ZipArchive")) {
605
$this->_log("DB zip, fallback to ZipArchive");
606
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
607
}
608
609
if (!$zip_archive_db_result) {
610
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
611
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
612
$archive = new IWPPclZip($backup_file);
613
614
if($fail_safe_files && $disable_comp){
615
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
616
}
617
elseif(!$fail_safe_files && $disable_comp){
618
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
619
}
620
elseif($fail_safe_files && !$disable_comp){
621
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
622
}
623
else{
624
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
625
}
626
627
@unlink($db_result);
628
@rmdir(IWP_DB_DIR);
629
630
if (!$result_db) {
@@ -636,6 +645,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
636
}
637
638
@unlink($db_result);
639
@rmdir(IWP_DB_DIR);
640
641
$this->update_status($task_name, $this->statuses['db_zip'], true);
@@ -694,7 +704,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
694
$exclude_data .= " $data/*.*";
695
else
696
$exclude_data .= " '$data/*'";
697
- }*/
698
699
//Include paths by default
700
$add = array(
@@ -746,15 +756,18 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
746
}
747
}
748
ob_get_clean();
749
if ($result_f && $result_f != 18) {
750
$zip_archive_result = false;
751
if (class_exists("ZipArchive")) {
752
$this->_log("Files zip fallback to ZipArchive");
753
$zip_archive_result = $this->zip_archive_backup($task_name, $backup_file, $exclude, $include);
754
}
755
756
757
if (!$zip_archive_result) { //Try pclZip
758
if (!isset($archive)) {
759
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
760
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
@@ -830,7 +843,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
830
}
831
832
/**
833
- * Zipping database dump and index.php in folder mwp_db by ZipArchive class, requires php zip extension.
834
*
835
* @param string $task_name the name of backup task
836
* @param string $db_result relative path to database dump file
@@ -845,8 +858,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
845
$zip = new ZipArchive();
846
$result = $zip->open($backup_file, ZIPARCHIVE::OVERWRITE); // Tries to open $backup_file for acrhiving
847
if ($result === true) {
848
- $result = $result && $zip->addFile(MWP_BACKUP_DIR.'/iwp_db/index.php', "iwp_db/index.php"); // Tries to add mwp_db/index.php to $backup_file
849
- $result = $result && $zip->addFile($db_result, "iwp_db/" . basename($db_result)); // Tries to add db dump form mwp_db dir to $backup_file
850
$result = $result && $zip->close(); // Tries to close $backup_file
851
} else {
852
$result = false;
@@ -933,6 +946,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
933
return array(
934
'error' => 'Error creating database backup folder (' . $db_folder . '). Make sure you have corrrect write permissions.'
935
);
936
}
937
938
$file = $db_folder . DB_NAME . '.sql';
@@ -949,6 +963,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
949
ob_start();
950
$result = $this->iwp_mmb_exec($command);
951
ob_get_clean();
952
953
if (!$result) { // Fallback to php
954
$result = $this->backup_db_php($file);
@@ -968,6 +983,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
968
global $wpdb;
969
970
if(empty($GLOBALS['fail_safe_db'])){
971
$fp = fopen( $file, 'w' );
972
if ( !mysql_ping( $wpdb->dbh ) ) {
973
mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
@@ -1050,13 +1066,16 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1050
unset ($fp);
1051
}
1052
else{
1053
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
1054
foreach ($tables as $table) {
1055
//drop existing table
1056
$dump_data = "DROP TABLE IF EXISTS $table[0];";
1057
//create table
1058
$create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
1059
- $dump_data .= "\n\n" . $create_table[1] . ";\n\n";
1060
1061
$count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
1062
if ($count > 100)
@@ -1071,7 +1090,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1071
if (is_array($rows)) {
1072
foreach ($rows as $row) {
1073
//insert single row
1074
- $dump_data .= "INSERT INTO $table[0] VALUES(";
1075
$num_values = count($row);
1076
$j = 1;
1077
foreach ($row as $value) {
@@ -1082,13 +1101,14 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
1082
unset($value);
1083
}
1084
$dump_data .= ");\n";
1085
}
1086
}
1087
}
1088
- $dump_data .= "\n\n\n";
1089
1090
unset($rows);
1091
- file_put_contents($file, $dump_data, FILE_APPEND);
1092
unset($dump_data);
1093
}
1094
}
@@ -1281,36 +1301,39 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1281
1282
//Replace options
1283
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
1284
- $old = $wpdb->get_var($wpdb->prepare($query));
1285
$old = rtrim($old, "/");
1286
- $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'home'";
1287
- $wpdb->query($wpdb->prepare($query));
1288
- $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'siteurl'";
1289
- $wpdb->query($wpdb->prepare($query));
1290
//Replace content urls
1291
- $query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, '$old','$home') WHERE post_content REGEXP 'src=\"(.*)$old(.*)\"' OR post_content REGEXP 'href=\"(.*)$old(.*)\"'";
1292
- $wpdb->query($wpdb->prepare($query));
1293
1294
if (trim($new_password)) {
1295
$new_password = wp_hash_password($new_password);
1296
}
1297
if (!trim($clone_from_url) && !trim($iwp_clone)) {
1298
if ($new_user && $new_password) {
1299
- $query = "UPDATE " . $new_table_prefix . "users SET user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$old_user'";
1300
- $wpdb->query($wpdb->prepare($query));
1301
}
1302
} else {
1303
1304
// if ($iwp_clone) {
1305
if ($admin_email) {
1306
//Clean Install
1307
- $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$admin_email' WHERE option_name = 'admin_email'";
1308
- $wpdb->query($wpdb->prepare($query));
1309
$query = "SELECT * FROM " . $new_table_prefix . "users LIMIT 1";
1310
$temp_user = $wpdb->get_row($query);
1311
if (!empty($temp_user)) {
1312
- $query = "UPDATE " . $new_table_prefix . "users SET user_email='$admin_email', user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$temp_user->user_login'";
1313
- $wpdb->query($wpdb->prepare($query));
1314
}
1315
1316
}
@@ -1318,8 +1341,8 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1318
1319
//if ($clone_from_url) {
1320
if ($new_user && $new_password) {
1321
- $query = "UPDATE " . $new_table_prefix . "users SET user_pass = '$new_password' WHERE user_login = '$new_user'";
1322
- $wpdb->query($wpdb->prepare($query));
1323
}
1324
// }
1325
@@ -1328,14 +1351,14 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1328
if (is_array($clone_options) && !empty($clone_options)) {
1329
foreach ($clone_options as $key => $option) {
1330
if (!empty($key)) {
1331
- $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = '$key'";
1332
- $res = $wpdb->get_var($query);
1333
if ($res == false) {
1334
- $query = "INSERT INTO " . $new_table_prefix . "options (option_value,option_name) VALUES('$option','$key')";
1335
- $wpdb->query($wpdb->prepare($query));
1336
} else {
1337
- $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$option' WHERE option_name = '$key'";
1338
- $wpdb->query($wpdb->prepare($query));
1339
}
1340
}
1341
}
@@ -1343,7 +1366,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1343
1344
//Remove hit count
1345
$query = "DELETE FROM " . $new_table_prefix . "options WHERE option_name = 'iwp_client_user_hit_count'";
1346
- $wpdb->query($wpdb->prepare($query));
1347
1348
//Check for .htaccess permalinks update
1349
$this->replace_htaccess($home);
@@ -1387,6 +1410,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1387
1388
1389
@unlink($file_name);
1390
return true;
1391
}
1392
@@ -1440,7 +1464,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1440
{
1441
global $wpdb;
1442
$query = 'SHOW TABLE STATUS';
1443
- $tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
1444
foreach ($tables as $table) {
1445
if (in_array($table['Engine'], array(
1446
'MyISAM',
@@ -1648,6 +1672,12 @@ function ftp_backup($args)
1648
if ($ftp_ssl) {
1649
if (function_exists('ftp_ssl_connect')) {
1650
$conn_id = ftp_ssl_connect($ftp_hostname,$port);
1651
} else {
1652
return array(
1653
'error' => 'Your server doesn\'t support SFTP',
@@ -1693,7 +1723,7 @@ function ftp_backup($args)
1693
if ($upload === false) { //Try ascii
1694
$upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_ASCII);
1695
}
1696
- ftp_close($conn_id);
1697
1698
if ($upload === false) {
1699
return array(
@@ -1749,7 +1779,6 @@ function ftp_backup($args)
1749
$login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1750
if ($login === false) {
1751
return false;
1752
- } else {
1753
}
1754
1755
if ($ftp_site_folder)
@@ -1771,32 +1800,32 @@ function ftp_backup($args)
1771
}
1772
1773
1774
- function dropbox_backup($args)
1775
- {
1776
extract($args);
1777
1778
if(isset($consumer_secret) && !empty($consumer_secret)){
1779
- //New way
1780
- require_once('lib/dropbox.oauth.php');
1781
-
1782
- $dropbox = new Dropbox($consumer_key, $consumer_secret);
1783
- $dropbox->setOAuthToken($oauth_token);
1784
- $dropbox->setOAuthTokenSecret($oauth_token_secret);
1785
-
1786
- if ($dropbox_site_folder == true)
1787
- $dropbox_destination .= '/' . $this->site_name;
1788
-
1789
- try{
1790
-
1791
- $dropbox->filesPost($dropbox_destination, $backup_file,true);
1792
-
1793
- } catch(Exception $e){
1794
- return array(
1795
- 'error' => 'Dropbox upload error. '.$e->getMessage()
1796
- );
1797
- }
1798
-
1799
- return true;
1800
1801
} else {
1802
return array(
@@ -1805,78 +1834,70 @@ function ftp_backup($args)
1805
}
1806
1807
}
1808
1809
- function remove_dropbox_backup($args){
1810
- extract($args);
1811
- if(isset($consumer_secret) && !empty($consumer_secret)){
1812
- //New way
1813
- require_once('lib/dropbox.oauth.php');
1814
-
1815
- $dropbox = new Dropbox($consumer_key, $consumer_secret);
1816
- $dropbox->setOAuthToken($oauth_token);
1817
- $dropbox->setOAuthTokenSecret($oauth_token_secret);
1818
-
1819
- if ($dropbox_site_folder == true)
1820
- $dropbox_destination .= '/' . $this->site_name;
1821
-
1822
- try{
1823
- $dropbox->fileopsDelete($dropbox_destination.'/'.$backup_file, true);
1824
- } catch(Exception $e){
1825
-
1826
- }
1827
- }
1828
- }
1829
-
1830
- function get_dropbox_backup($args){
1831
- extract($args);
1832
-
1833
- if(isset($consumer_secret) && !empty($consumer_secret)){
1834
- //New way
1835
- require_once('lib/dropbox.oauth.php');
1836
-
1837
- $dropbox = new Dropbox($consumer_key, $consumer_secret);
1838
- $dropbox->setOAuthToken($oauth_token);
1839
- $dropbox->setOAuthTokenSecret($oauth_token_secret);
1840
-
1841
- if ($dropbox_site_folder == true)
1842
- $dropbox_destination .= '/' . $this->site_name;
1843
-
1844
- $temp = ABSPATH . 'iwp_temp_backup.zip';
1845
-
1846
- try{
1847
- $file = $dropbox->filesGet($dropbox_destination.'/'.$backup_file, true);
1848
-
1849
- if(isset($file['data']) && !empty($file['data']) )
1850
- $stream = base64_decode($file['data']);
1851
- else
1852
- return false;
1853
-
1854
- $handle = @fopen($temp, 'w+');
1855
- $result = fwrite($handle,$stream);
1856
- fclose($handle);
1857
-
1858
- if($result)
1859
- return $temp;
1860
- else
1861
- return false;
1862
-
1863
- } catch(Exception $e){
1864
-
1865
-
1866
- return false;
1867
- }
1868
-
1869
- } else {
1870
- return false;
1871
- }
1872
-
1873
1874
- }
1875
-
1876
function amazons3_backup($args)
1877
{
1878
if ($this->iwp_mmb_function_exists('curl_init')) {
1879
- require_once('lib/amazon_s3/sdk.class.php');
1880
1881
extract($args);
1882
@@ -1922,7 +1943,7 @@ function ftp_backup($args)
1922
function remove_amazons3_backup($args)
1923
{
1924
if ($this->iwp_mmb_function_exists('curl_init')) {
1925
- require_once('lib/amazon_s3/sdk.class.php');
1926
extract($args);
1927
if ($as3_site_folder == true)
1928
$as3_directory .= '/' . $this->site_name;
@@ -1938,7 +1959,7 @@ function ftp_backup($args)
1938
1939
function get_amazons3_backup($args)
1940
{
1941
- require_once('lib/amazon_s3/sdk.class.php');
1942
extract($args);
1943
$temp = '';
1944
try{
@@ -2142,7 +2163,8 @@ function get_next_schedules()
2142
$backups[$task_name]['task_results']=array();
2143
2144
$this->update_tasks($backups);
2145
- //update_option('iwp_client_backup_tasks', $backups);
2146
}
2147
}
2148
@@ -2221,6 +2243,7 @@ function get_next_schedules()
2221
foreach ($db_files as $file) {
2222
@unlink($file);
2223
}
2224
@rmdir(IWP_DB_DIR);
2225
}
2226
@@ -2234,9 +2257,10 @@ function get_next_schedules()
2234
@rmdir(WP_CONTENT_DIR . '/' . md5('iwp_mmb-client'));
2235
}
2236
2237
- // USE $new = array();
2238
- foreach ($new as $b) {
2239
- $files[] = $b;
2240
}
2241
$deleted = array();
2242
@@ -2365,7 +2389,7 @@ function get_next_schedules()
2365
}
2366
2367
2368
- public static function readd_tasks( $params = array() ){
2369
global $iwp_mmb_core;
2370
2371
if( empty($params) || !isset($params['backups']) )
@@ -2414,9 +2438,9 @@ function get_next_schedules()
2414
}
2415
}
2416
2417
- if( function_exists('add_filter') ){
2418
add_filter( 'iwp_website_add', 'IWP_MMB_Backup::readd_tasks' );
2419
- }
2420
2421
if(!function_exists('get_all_files_from_dir')) {
2422
/**
172
}
173
}
174
175
+ if (isset($time) && $time) { //set next result time before backup
176
if (is_array($before[$task_name]['task_results'])) {
177
$before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
178
}
316
317
function backup($args, $task_name = false)
318
{
319
+ if (!$args || empty($args))
320
return false;
321
322
extract($args); //extract settings
325
$this->set_memory();
326
327
//Remove old backup(s)
328
+ $removed = $this->remove_old_backups($task_name);
329
+ if (is_array($removed) && isset($removed['error'])) {
330
+ //$error_message = $removed['error'];
331
+ return $removed;
332
+ }
333
334
$new_file_path = IWP_BACKUP_DIR;
335
382
ob_start();
383
$result = $this->iwp_mmb_exec($command);
384
ob_get_clean();
385
+ echo "\n".'DB ZIP CMD';
386
/*zip_backup_db */
387
if(!$result){
388
$zip_archive_db_result = false;
389
if (class_exists("ZipArchive")) {
390
$this->_log("DB zip, fallback to ZipArchive");
391
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
392
+ echo "\n".'DB ZIP Archive';
393
}
394
395
if (!$zip_archive_db_result) {
396
+ echo "\n".'DB ZIP PCL';
397
// fallback to pclzip
398
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
399
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
400
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
401
$archive = new IWPPclZip($backup_file);
402
+
403
if($fail_safe_files && $disable_comp){
404
+ $result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
405
}
406
elseif(!$fail_safe_files && $disable_comp){
407
+ $result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
408
}
409
elseif($fail_safe_files && !$disable_comp){
410
+ $result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
411
}
412
else{
413
+ $result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
414
}
415
@unlink($db_result);
416
+ @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
417
@rmdir(IWP_DB_DIR);
418
if (!$result) {
419
return array(
424
}
425
426
@unlink($db_result);
427
+ @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
428
@rmdir(IWP_DB_DIR);
429
+ /*if (!$result) {
430
return array(
431
'error' => 'Failed to zip database.'
432
);
433
+ }*///commented because of zipArchive
434
$this->update_status($task_name, $this->statuses['db_zip'], true);
435
}
436
} elseif (trim($what) == 'full') {
570
571
function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
572
{
573
+
574
+ global $zip_errors;
575
$sys = substr(PHP_OS, 0, 3);
576
577
$this->update_status($task_name, $this->statuses['db_dump']);
602
ob_start();
603
$result = $this->iwp_mmb_exec($command);
604
ob_get_clean();
605
+ echo "\n".'DB ZIP CMD';
606
/*zip_backup_db*/
607
608
if(!$result){
610
if (class_exists("ZipArchive")) {
611
$this->_log("DB zip, fallback to ZipArchive");
612
$zip_archive_db_result = $this->zip_archive_backup_db($task_name, $db_result, $backup_file);
613
+ echo "\n".'DB ZIP Archive';
614
}
615
616
if (!$zip_archive_db_result) {
617
+ echo "\n".'DB ZIP PCL';
618
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
619
require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
620
$archive = new IWPPclZip($backup_file);
621
622
if($fail_safe_files && $disable_comp){
623
+ $result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
624
}
625
elseif(!$fail_safe_files && $disable_comp){
626
+ $result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
627
}
628
elseif($fail_safe_files && !$disable_comp){
629
+ $result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
630
}
631
else{
632
+ $result_db = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
633
}
634
635
@unlink($db_result);
636
+ @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
637
@rmdir(IWP_DB_DIR);
638
639
if (!$result_db) {
645
}
646
647
@unlink($db_result);
648
+ @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
649
@rmdir(IWP_DB_DIR);
650
651
$this->update_status($task_name, $this->statuses['db_zip'], true);
704
$exclude_data .= " $data/*.*";
705
else
706
$exclude_data .= " '$data/*'";
707
+ }*///commented for pclzip modifications
708
709
//Include paths by default
710
$add = array(
756
}
757
}
758
ob_get_clean();
759
+ echo "\n".'Files ZIP CMD';
760
if ($result_f && $result_f != 18) {
761
$zip_archive_result = false;
762
if (class_exists("ZipArchive")) {
763
$this->_log("Files zip fallback to ZipArchive");
764
$zip_archive_result = $this->zip_archive_backup($task_name, $backup_file, $exclude, $include);
765
+ echo "\n".'Files ZIP Archive';
766
}
767
768
769
if (!$zip_archive_result) { //Try pclZip
770
+ echo "\n".'Files ZIP PCL';
771
if (!isset($archive)) {
772
define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
773
//require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
843
}
844
845
/**
846
+ * Zipping database dump and index.php in folder iwp_db by ZipArchive class, requires php zip extension.
847
*
848
* @param string $task_name the name of backup task
849
* @param string $db_result relative path to database dump file
858
$zip = new ZipArchive();
859
$result = $zip->open($backup_file, ZIPARCHIVE::OVERWRITE); // Tries to open $backup_file for acrhiving
860
if ($result === true) {
861
+ $result = $result && $zip->addFile(IWP_BACKUP_DIR.'/iwp_db/index.php', "iwp_db/index.php"); // Tries to add iwp_db/index.php to $backup_file
862
+ $result = $result && $zip->addFile($db_result, "iwp_db/" . basename($db_result)); // Tries to add db dump form iwp_db dir to $backup_file
863
$result = $result && $zip->close(); // Tries to close $backup_file
864
} else {
865
$result = false;
946
return array(
947
'error' => 'Error creating database backup folder (' . $db_folder . '). Make sure you have corrrect write permissions.'
948
);
949
+ @file_put_contents(IWP_BACKUP_DIR.'/iwp_db/index.php', '');
950
}
951
952
$file = $db_folder . DB_NAME . '.sql';
963
ob_start();
964
$result = $this->iwp_mmb_exec($command);
965
ob_get_clean();
966
+ echo "\n".'DB DUMP CMD';
967
968
if (!$result) { // Fallback to php
969
$result = $this->backup_db_php($file);
983
global $wpdb;
984
985
if(empty($GLOBALS['fail_safe_db'])){
986
+ echo "\n".'DB DUMP PHP Normal';
987
$fp = fopen( $file, 'w' );
988
if ( !mysql_ping( $wpdb->dbh ) ) {
989
mysql_connect( DB_HOST, DB_USER, DB_PASSWORD );
1066
unset ($fp);
1067
}
1068
else{
1069
+ echo "\n".'DB DUMP PHP Fail-safe';
1070
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
1071
foreach ($tables as $table) {
1072
//drop existing table
1073
$dump_data = "DROP TABLE IF EXISTS $table[0];";
1074
+ file_put_contents($file, $dump_data, FILE_APPEND);
1075
//create table
1076
$create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
1077
+ $dump_data = "\n\n" . $create_table[1] . ";\n\n";
1078
+ file_put_contents($file, $dump_data, FILE_APPEND);
1079
1080
$count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
1081
if ($count > 100)
1090
if (is_array($rows)) {
1091
foreach ($rows as $row) {
1092
//insert single row
1093
+ $dump_data = "INSERT INTO $table[0] VALUES(";
1094
$num_values = count($row);
1095
$j = 1;
1096
foreach ($row as $value) {
1101
unset($value);
1102
}
1103
$dump_data .= ");\n";
1104
+ file_put_contents($file, $dump_data, FILE_APPEND);
1105
}
1106
}
1107
}
1108
+ $dump_data = "\n\n\n";
1109
+ file_put_contents($file, $dump_data, FILE_APPEND);
1110
1111
unset($rows);
1112
unset($dump_data);
1113
}
1114
}
1301
1302
//Replace options
1303
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
1304
+ $old = $wpdb->get_var($query);
1305
$old = rtrim($old, "/");
1306
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = %s WHERE option_name = 'home'";
1307
+ $wpdb->query($wpdb->prepare($query, $home));
1308
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = %s WHERE option_name = 'siteurl'";
1309
+ $wpdb->query($wpdb->prepare($query, $home));
1310
//Replace content urls
1311
+
1312
+ $regexp1 = 'src="(.*)'.$old.'(.*)"';
1313
+ $regexp2 = 'href="(.*)'.$old.'(.*)"';
1314
+ $query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, %s,%s) WHERE post_content REGEXP %s OR post_content REGEXP %s";
1315
+ $wpdb->query($wpdb->prepare($query, $old, $home, $regexp1, $regexp2));
1316
1317
if (trim($new_password)) {
1318
$new_password = wp_hash_password($new_password);
1319
}
1320
if (!trim($clone_from_url) && !trim($iwp_clone)) {
1321
if ($new_user && $new_password) {
1322
+ $query = "UPDATE " . $new_table_prefix . "users SET user_login = %s, user_pass = %s WHERE user_login = %s";
1323
+ $wpdb->query($wpdb->prepare($query, $new_user, $new_password, $old_user));
1324
}
1325
} else {
1326
1327
// if ($iwp_clone) {
1328
if ($admin_email) {
1329
//Clean Install
1330
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = %s WHERE option_name = 'admin_email'";
1331
+ $wpdb->query($wpdb->prepare($query, $admin_email));
1332
$query = "SELECT * FROM " . $new_table_prefix . "users LIMIT 1";
1333
$temp_user = $wpdb->get_row($query);
1334
if (!empty($temp_user)) {
1335
+ $query = "UPDATE " . $new_table_prefix . "users SET user_email=%s, user_login = %s, user_pass = %s WHERE user_login = %s";
1336
+ $wpdb->query($wpdb->prepare($query, $admin_email, $new_user, $new_password, $temp_user->user_login));
1337
}
1338
1339
}
1341
1342
//if ($clone_from_url) {
1343
if ($new_user && $new_password) {
1344
+ $query = "UPDATE " . $new_table_prefix . "users SET user_pass = %s WHERE user_login = %s";
1345
+ $wpdb->query($wpdb->prepare($query, $new_password, $new_user));
1346
}
1347
// }
1348
1351
if (is_array($clone_options) && !empty($clone_options)) {
1352
foreach ($clone_options as $key => $option) {
1353
if (!empty($key)) {
1354
+ $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = %s";
1355
+ $res = $wpdb->get_var($wpdb->prepare($query, $key));
1356
if ($res == false) {
1357
+ $query = "INSERT INTO " . $new_table_prefix . "options (option_value,option_name) VALUES(%s,%s)";
1358
+ $wpdb->query($wpdb->prepare($query, $option, $key));
1359
} else {
1360
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = %s WHERE option_name = %s";
1361
+ $wpdb->query($wpdb->prepare($query, $option, $key));
1362
}
1363
}
1364
}
1366
1367
//Remove hit count
1368
$query = "DELETE FROM " . $new_table_prefix . "options WHERE option_name = 'iwp_client_user_hit_count'";
1369
+ $wpdb->query($query);
1370
1371
//Check for .htaccess permalinks update
1372
$this->replace_htaccess($home);
1410
1411
1412
@unlink($file_name);
1413
+ @unlink(dirname($file_name));//remove its folder
1414
return true;
1415
}
1416
1464
{
1465
global $wpdb;
1466
$query = 'SHOW TABLE STATUS';
1467
+ $tables = $wpdb->get_results($query, ARRAY_A);
1468
foreach ($tables as $table) {
1469
if (in_array($table['Engine'], array(
1470
'MyISAM',
1672
if ($ftp_ssl) {
1673
if (function_exists('ftp_ssl_connect')) {
1674
$conn_id = ftp_ssl_connect($ftp_hostname,$port);
1675
+ if ($conn_id === false) {
1676
+ return array(
1677
+ 'error' => 'Failed to connect to ' . $ftp_hostname,
1678
+ 'partial' => 1
1679
+ );
1680
+ }
1681
} else {
1682
return array(
1683
'error' => 'Your server doesn\'t support SFTP',
1723
if ($upload === false) { //Try ascii
1724
$upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_ASCII);
1725
}
1726
+ @ftp_close($conn_id);
1727
1728
if ($upload === false) {
1729
return array(
1779
$login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1780
if ($login === false) {
1781
return false;
1782
}
1783
1784
if ($ftp_site_folder)
1800
}
1801
1802
1803
+ function dropbox_backup($args){
1804
extract($args);
1805
1806
if(isset($consumer_secret) && !empty($consumer_secret)){
1807
+
1808
+ require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/dropbox.php';
1809
+
1810
+ $dropbox = new Dropbox($consumer_key, $consumer_secret);
1811
+ $dropbox->setOAuthTokens($oauth_token, $oauth_token_secret);
1812
+
1813
+ if ($dropbox_site_folder == true)
1814
+ $dropbox_destination .= '/' . $this->site_name . '/' . basename($backup_file);
1815
+ else
1816
+ $dropbox_destination .= '/' . basename($backup_file);
1817
+
1818
+ try {
1819
+ $dropbox->upload($backup_file, $dropbox_destination, true);
1820
+ } catch (Exception $e) {
1821
+ $this->_log($e->getMessage());
1822
+ return array(
1823
+ 'error' => $e->getMessage(),
1824
+ 'partial' => 1
1825
+ );
1826
+ }
1827
+
1828
+ return true;
1829
1830
} else {
1831
return array(
1834
}
1835
1836
}
1837
+
1838
1839
+ function remove_dropbox_backup($args) {
1840
+ extract($args);
1841
1842
+ require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/dropbox.php';
1843
+
1844
+ $dropbox = new Dropbox($consumer_key, $consumer_secret);
1845
+ $dropbox->setOAuthTokens($oauth_token, $oauth_token_secret);
1846
+
1847
+ if ($dropbox_site_folder == true)
1848
+ $dropbox_destination .= '/' . $this->site_name;
1849
+
1850
+ try {
1851
+ $dropbox->fileopsDelete($dropbox_destination . '/' . $backup_file);
1852
+ } catch (Exception $e) {
1853
+ $this->_log($e->getMessage());
1854
+ /*return array(
1855
+ 'error' => $e->getMessage(),
1856
+ 'partial' => 1
1857
+ );*/
1858
+ }
1859
+
1860
+ //return true;
1861
+ }
1862
+
1863
+
1864
+ function get_dropbox_backup($args) {
1865
+ extract($args);
1866
+
1867
+ require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/dropbox.php';
1868
+
1869
+ $dropbox = new Dropbox($consumer_key, $consumer_secret);
1870
+ $dropbox->setOAuthTokens($oauth_token, $oauth_token_secret);
1871
+
1872
+ if ($dropbox_site_folder == true)
1873
+ $dropbox_destination .= '/' . $this->site_name;
1874
+
1875
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1876
+
1877
+ try {
1878
+ $file = $dropbox->download($dropbox_destination.'/'.$backup_file);
1879
+ $handle = @fopen($temp, 'w');
1880
+ $result = fwrite($handle,$file);
1881
+ fclose($handle);
1882
+
1883
+ if($result)
1884
+ return $temp;
1885
+ else
1886
+ return false;
1887
+ } catch (Exception $e) {
1888
+ $this->_log($e->getMessage());
1889
+ return array(
1890
+ 'error' => $e->getMessage(),
1891
+ 'partial' => 1
1892
+ );
1893
+ }
1894
+ }
1895
+
1896
+
1897
function amazons3_backup($args)
1898
{
1899
if ($this->iwp_mmb_function_exists('curl_init')) {
1900
+ require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/amazon_s3/sdk.class.php');
1901
1902
extract($args);
1903
1943
function remove_amazons3_backup($args)
1944
{
1945
if ($this->iwp_mmb_function_exists('curl_init')) {
1946
+ require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/amazon_s3/sdk.class.php');
1947
extract($args);
1948
if ($as3_site_folder == true)
1949
$as3_directory .= '/' . $this->site_name;
1959
1960
function get_amazons3_backup($args)
1961
{
1962
+ require_once($GLOBALS['iwp_mmb_plugin_dir'].'/lib/amazon_s3/sdk.class.php');
1963
extract($args);
1964
$temp = '';
1965
try{
2163
$backups[$task_name]['task_results']=array();
2164
2165
$this->update_tasks($backups);
2166
+
2167
+ return true;
2168
}
2169
}
2170
2243
foreach ($db_files as $file) {
2244
@unlink($file);
2245
}
2246
+ @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
2247
@rmdir(IWP_DB_DIR);
2248
}
2249
2257
@rmdir(WP_CONTENT_DIR . '/' . md5('iwp_mmb-client'));
2258
}
2259
2260
+ if (!empty($new)) {
2261
+ foreach ($new as $b) {
2262
+ $files[] = $b;
2263
+ }
2264
}
2265
$deleted = array();
2266
2389
}
2390
2391
2392
+ public function readd_tasks( $params = array() ){
2393
global $iwp_mmb_core;
2394
2395
if( empty($params) || !isset($params['backups']) )
2438
}
2439
}
2440
2441
+ /*if( function_exists('add_filter') ){
2442
add_filter( 'iwp_website_add', 'IWP_MMB_Backup::readd_tasks' );
2443
+ }*/
2444
2445
if(!function_exists('get_all_files_from_dir')) {
2446
/**
core.class.php CHANGED
@@ -259,7 +259,7 @@ class IWP_MMB_Core extends IWP_MMB_Helper
259
private function get_parent_blog_option( $option_name = '' )
260
{
261
global $wpdb;
262
- $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = '{$option_name}' LIMIT 1" ) );
263
return $option;
264
}
265
@@ -434,7 +434,7 @@ class IWP_MMB_Core extends IWP_MMB_Helper
434
435
//delete plugin options, just in case
436
if ($this->iwp_mmb_multisite != false) {
437
- $network_blogs = $wpdb->get_results($wpdb->prepare("select `blog_id`, `site_id` from `{$wpdb->blogs}`"));
438
if(!empty($network_blogs)){
439
if( is_network_admin() ){
440
update_option('iwp_client_network_admin_install', 1);
@@ -493,7 +493,7 @@ class IWP_MMB_Core extends IWP_MMB_Helper
493
$_wp_using_ext_object_cache = false;
494
495
if ($this->iwp_mmb_multisite != false) {
496
- $network_blogs = $wpdb->get_col($wpdb->prepare("select `blog_id` from `{$wpdb->blogs}`"));
497
if(!empty($network_blogs)){
498
if( is_network_admin() ){
499
if( $deactivate ) {
259
private function get_parent_blog_option( $option_name = '' )
260
{
261
global $wpdb;
262
+ $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = %s LIMIT 1", $option_name ) );
263
return $option;
264
}
265
434
435
//delete plugin options, just in case
436
if ($this->iwp_mmb_multisite != false) {
437
+ $network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
438
if(!empty($network_blogs)){
439
if( is_network_admin() ){
440
update_option('iwp_client_network_admin_install', 1);
493
$_wp_using_ext_object_cache = false;
494
495
if ($this->iwp_mmb_multisite != false) {
496
+ $network_blogs = $wpdb->get_col("select `blog_id` from `{$wpdb->blogs}`");
497
if(!empty($network_blogs)){
498
if( is_network_admin() ){
499
if( $deactivate ) {
helper.class.php CHANGED
@@ -230,7 +230,7 @@ class IWP_MMB_Helper
230
global $wpdb;
231
$option_name = '_site_transient_'. $option_name;
232
233
- $result = $wpdb->get_var( $wpdb->prepare("SELECT `meta_value` FROM `{$wpdb->sitemeta}` WHERE meta_key = '{$option_name}' AND `site_id` = '{$this->iwp_mmb_multisite}' "));
234
$result = maybe_unserialize($result);
235
return $result;
236
}
230
global $wpdb;
231
$option_name = '_site_transient_'. $option_name;
232
233
+ $result = $wpdb->get_var( $wpdb->prepare("SELECT `meta_value` FROM `{$wpdb->sitemeta}` WHERE meta_key = %s AND `site_id` = %s", $option_name, $this->mmb_multisite));
234
$result = maybe_unserialize($result);
235
return $result;
236
}
init.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: InfiniteWP - Client
4
Plugin URI: http://infinitewp.com/
5
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6
Author: Revmakx
7
- Version: 1.1.4
8
Author URI: http://www.revmakx.com
9
*/
10
/************************************************************
@@ -26,7 +26,7 @@ Author URI: http://www.revmakx.com
26
**************************************************************/
27
28
if(!defined('IWP_MMB_CLIENT_VERSION'))
29
- define('IWP_MMB_CLIENT_VERSION', '1.1.4');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
@@ -218,10 +218,10 @@ if( !function_exists ( 'iwp_mmb_add_site' )) {
218
$iwp_mmb_core->set_admin_panel_public_key($public_key);
219
$iwp_mmb_core->set_client_message_id($id);
220
$iwp_mmb_core->get_stats_instance();
221
- if(is_array($notifications) && !empty($notifications)){
222
$iwp_mmb_core->stats_instance->set_notifications($notifications);
223
}
224
- if(is_array($brand) && !empty($brand)){
225
update_option('iwp_client_brand',$brand);
226
}
227
@@ -473,6 +473,19 @@ if( !function_exists ( 'iwp_mmb_clean_orphan_backups' )) {
473
}
474
}
475
476
if( !function_exists ( 'iwp_mmb_update_client_plugin' )) {
477
function iwp_mmb_update_client_plugin($params)
478
{
4
Plugin URI: http://infinitewp.com/
5
Description: This is the client plugin of InfiniteWP that communicates with the InfiniteWP Admin panel.
6
Author: Revmakx
7
+ Version: 1.1.5
8
Author URI: http://www.revmakx.com
9
*/
10
/************************************************************
26
**************************************************************/
27
28
if(!defined('IWP_MMB_CLIENT_VERSION'))
29
+ define('IWP_MMB_CLIENT_VERSION', '1.1.5');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
218
$iwp_mmb_core->set_admin_panel_public_key($public_key);
219
$iwp_mmb_core->set_client_message_id($id);
220
$iwp_mmb_core->get_stats_instance();
221
+ if(isset($notifications) && is_array($notifications) && !empty($notifications)){
222
$iwp_mmb_core->stats_instance->set_notifications($notifications);
223
}
224
+ if(isset($brand) && is_array($brand) && !empty($brand)){
225
update_option('iwp_client_brand',$brand);
226
}
227
473
}
474
}
475
476
+
477
+
478
+ add_filter( 'iwp_website_add', 'iwp_mmb_readd_backup_task' );
479
+
480
+ if (!function_exists('iwp_mmb_readd_backup_task')) {
481
+ function iwp_mmb_readd_backup_task($params = array()) {
482
+ global $iwp_mmb_core;
483
+ $backup_instance = $iwp_mmb_core->get_backup_instance();
484
+ $settings = $backup_instance->readd_tasks($params);
485
+ return $settings;
486
+ }
487
+ }
488
+
489
if( !function_exists ( 'iwp_mmb_update_client_plugin' )) {
490
function iwp_mmb_update_client_plugin($params)
491
{
lib/dropbox.oauth.php DELETED
@@ -1,1133 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Dropbox class
5
- *
6
- * This source file can be used to communicate with Dropbox (http://dropbox.com)
7
- *
8
- * The class is documented in the file itself. If you find any bugs help me out and report them. Reporting can be done by sending an email to php-dropbox-bugs[at]verkoyen[dot]eu.
9
- * If you report a bug, make sure you give me enough information (include your code).
10
- *
11
- * Changelog since 1.0.4
12
- * - Fixed filesPost so it returns a boolean.
13
- * - Some code styling
14
- *
15
- * Changelog since 1.0.3
16
- * - Corrected the authorize-URL (thx to Jacob Budin).
17
- *
18
- * Changelog since 1.0.2
19
- * - Added methods to enable oauth-usage.
20
- *
21
- * Changelog since 1.0.1
22
- * - Bugfix: when doing multiple calles where GET and POST is mixed, the postfields should be reset (thx to Daniel Hトてスsken)
23
- *
24
- * Changelog since 1.0.0
25
- * - fixed some issues with generation off the basestring
26
- *
27
- * License
28
- * Copyright (c), Tijs Verkoyen. All rights reserved.
29
- *
30
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
31
- *
32
- * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
33
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
34
- * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
35
- *
36
- * This software is provided by the author "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
37
- *
38
- * @author Tijs Verkoyen <php-dropbox@verkoyen.eu>
39
- * @version 1.0.5
40
- *
41
- * @copyright Copyright (c), Tijs Verkoyen. All rights reserved.
42
- * @license BSD License
43
- */
44
- class Dropbox
45
- {
46
- // internal constant to enable/disable debugging
47
- const DEBUG = false;
48
-
49
- // url for the dropbox-api
50
- const API_URL = 'https://api.dropbox.com';
51
- const API_AUTH_URL = 'https://www.dropbox.com';
52
- const API_CONTENT_URL = 'https://api-content.dropbox.com';
53
-
54
- // port for the dropbox-api
55
- const API_PORT = 443;
56
-
57
- // current version
58
- const VERSION = '1.0.5';
59
-
60
-
61
- /**
62
- * A cURL instance
63
- *
64
- * @var resource
65
- */
66
- private $curl;
67
-
68
-
69
- /**
70
- * The application key
71
- *
72
- * @var string
73
- */
74
- private $applicationKey;
75
-
76
-
77
- /**
78
- * The application secret
79
- *
80
- * @var string
81
- */
82
- private $applicationSecret;
83
-
84
-
85
- /**
86
- * The oAuth-token
87
- *
88
- * @var string
89
- */
90
- private $oAuthToken = '';
91
-
92
-
93
- /**
94
- * The oAuth-token-secret
95
- *
96
- * @var string
97
- */
98
- private $oAuthTokenSecret = '';
99
-
100
-
101
- /**
102
- * The timeout
103
- *
104
- * @var int
105
- */
106
- private $timeOut = 1200;
107
-
108
-
109
- /**
110
- * The user agent
111
- *
112
- * @var string
113
- */
114
- private $userAgent;
115
-
116
-
117
- // class methods
118
- /**
119
- * Default constructor
120
- *
121
- * @return void
122
- * @param string $applicationKey The application key to use.
123
- * @param string $applicationSecret The application secret to use.
124
- */
125
- public function __construct($applicationKey, $applicationSecret)
126
- {
127
- $this->setApplicationKey($applicationKey);
128
- $this->setApplicationSecret($applicationSecret);
129
- }
130
-
131
-
132
- /**
133
- * Default destructor
134
- *
135
- * @return void
136
- */
137
- public function __destruct()
138
- {
139
- if($this->curl != null) curl_close($this->curl);
140
- }
141
-
142
-
143
- /**
144
- * Format the parameters as a querystring
145
- *
146
- * @return string
147
- * @param array $parameters The parameters to pass.
148
- */
149
- private function buildQuery(array $parameters)
150
- {
151
- // no parameters?
152
- if(empty($parameters)) return '';
153
-
154
- // encode the keys
155
- $keys = self::urlencode_rfc3986(array_keys($parameters));
156
-
157
- // encode the values
158
- $values = self::urlencode_rfc3986(array_values($parameters));
159
-
160
- // reset the parameters
161
- $parameters = array_combine($keys, $values);
162
-
163
- // sort parameters by key
164
- uksort($parameters, 'strcmp');
165
-
166
- // loop parameters
167
- foreach($parameters as $key => $value)
168
- {
169
- // sort by value
170
- if(is_array($value)) $parameters[$key] = natsort($value);
171
- }
172
-
173
- // process parameters
174
- foreach($parameters as $key => $value) $chunks[] = $key . '=' . str_replace('%25', '%', $value);
175
-
176
- // return
177
- return implode('&', $chunks);
178
- }
179
-
180
-
181
- /**
182
- * All OAuth 1.0 requests use the same basic algorithm for creating a signature base string and a signature.
183
- * The signature base string is composed of the HTTP method being used, followed by an ampersand ("&") and then the URL-encoded base URL being accessed,
184
- * complete with path (but not query parameters), followed by an ampersand ("&").
185
- * Then, you take all query parameters and POST body parameters (when the POST body is of the URL-encoded type, otherwise the POST body is ignored),
186
- * including the OAuth parameters necessary for negotiation with the request at hand, and sort them in lexicographical order by first parameter name and
187
- * then parameter value (for duplicate parameters), all the while ensuring that both the key and the value for each parameter are URL encoded in isolation.
188
- * Instead of using the equals ("=") sign to mark the key/value relationship, you use the URL-encoded form of "%3D". Each parameter is then joined by the
189
- * URL-escaped ampersand sign, "%26".
190
- *
191
- * @return string
192
- * @param string $url The url to use.
193
- * @param string $method The method that will be called.
194
- * @param array $parameters The parameters to pass.
195
- */
196
- private function calculateBaseString($url, $method, array $parameters)
197
- {
198
- // redefine
199
- $url = (string) $url;
200
- $parameters = (array) $parameters;
201
-
202
- // init var
203
- $pairs = array();
204
- $chunks = array();
205
-
206
- // sort parameters by key
207
- uksort($parameters, 'strcmp');
208
-
209
- // loop parameters
210
- foreach($parameters as $key => $value)
211
- {
212
- // sort by value
213
- if(is_array($value)) $parameters[$key] = natsort($value);
214
- }
215
-
216
- // process queries
217
- foreach($parameters as $key => $value)
218
- {
219
- // only add if not already in the url
220
- if(substr_count($url, $key . '=' . $value) == 0) $chunks[] = self::urlencode_rfc3986($key) . '%3D' . self::urlencode_rfc3986($value);
221
- }
222
-
223
- $urlChunks = explode('/', $url);
224
- $i = 0;
225
-
226
- foreach($urlChunks as &$chunk)
227
- {
228
- if($i > 4) $chunk = self::urlencode_rfc3986($chunk);
229
- else $chunk = urlencode($chunk);
230
-
231
- $i++;
232
-
233
- }
234
-
235
- // build base
236
- $base = $method . '&';
237
- $base .= implode('%2F', $urlChunks);
238
- $base .= (substr_count($url, '?')) ? '%26' : '&';
239
- $base .= implode('%26', $chunks);
240
- $base = str_replace(array('%3F', '%20'), array('&', '%2520'), $base);
241
-
242
- // return
243
- return $base;
244
- }
245
-
246
-
247
- /**
248
- * Build the Authorization header
249
- * @later: fix me
250
- *
251
- * @return string
252
- * @param array $parameters The parameters to pass.
253
- * @param string $url The url to use.
254
- */
255
- private function calculateHeader(array $parameters, $url)
256
- {
257
- // redefine
258
- $url = (string) $url;
259
-
260
- // divide into parts
261
- $parts = parse_url($url);
262
-
263
- // init var
264
- $chunks = array();
265
-
266
- // process queries
267
- foreach($parameters as $key => $value) $chunks[] = str_replace('%25', '%', self::urlencode_rfc3986($key) . '="' . self::urlencode_rfc3986($value) . '"');
268
- $parts['path']=str_replace("%2F", "/", rawurlencode($parts['path']));
269
- // build return
270
- $return = 'Authorization: OAuth realm="' . $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '", ';
271
- $return .= implode(',', $chunks);
272
- // prepend name and OAuth part
273
- return $return;
274
- }
275
-
276
-
277
- /**
278
- * Make an call to the oAuth
279
- * @todo refactor me
280
- *
281
- * @return array
282
- * @param string $url The url that has to be called.
283
- * @param array[optional] $parameters The parameters to pass.
284
- * @param string[optional] $method Which HTTP-method should we use? Possible values are POST, GET.
285
- * @param bool[optional] $expectJSON Do we expect JSON?
286
- */
287
- private function doOAuthCall($url, array $parameters = null, $method = 'POST', $expectJSON = true)
288
- {
289
- // redefine
290
- $url = (string) $url;
291
-
292
- // append default parameters
293
- $parameters['oauth_consumer_key'] = $this->getApplicationKey();
294
- $parameters['oauth_nonce'] = md5(microtime() . rand());
295
- $parameters['oauth_timestamp'] = time();
296
- $parameters['oauth_signature_method'] = 'HMAC-SHA1';
297
- $parameters['oauth_version'] = '1.0';
298
-
299
- // calculate the base string
300
- $base = $this->calculateBaseString(self::API_URL . '/' . $url, 'POST', $parameters);
301
-
302
- // add sign into the parameters
303
- $parameters['oauth_signature'] = $this->hmacsha1($this->getApplicationSecret() . '&' . $this->getOAuthTokenSecret(), $base);
304
-
305
- // calculate header
306
- $header = $this->calculateHeader($parameters, self::API_URL . '/' . $url);
307
-
308
- if($method == 'POST')
309
- {
310
- $options[CURLOPT_POST] = true;
311
- $options[CURLOPT_POSTFIELDS] = $this->buildQuery($parameters);
312
- }
313
-
314
- else
315
- {
316
- // reset post
317
- $options[CURLOPT_POST] = 0;
318
- unset($options[CURLOPT_POSTFIELDS]);
319
-
320
- // add the parameters into the querystring
321
- if(!empty($parameters)) $url .= '?' . $this->buildQuery($parameters);
322
- }
323
-
324
- // set options
325
- $options[CURLOPT_URL] = self::API_URL . '/' . $url;
326
- $options[CURLOPT_PORT] = self::API_PORT;
327
- $options[CURLOPT_USERAGENT] = $this->getUserAgent();
328
- if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) $options[CURLOPT_FOLLOWLOCATION] = true;
329
- $options[CURLOPT_RETURNTRANSFER] = true;
330
- $options[CURLOPT_TIMEOUT] = (int) $this->getTimeOut();
331
- $options[CURLOPT_SSL_VERIFYPEER] = false;
332
- $options[CURLOPT_SSL_VERIFYHOST] = false;
333
- $options[CURLOPT_HTTPHEADER] = array('Expect:');
334
-
335
- // init
336
- $this->curl = curl_init();
337
-
338
- // set options
339
- curl_setopt_array($this->curl, $options);
340
-
341
- // execute
342
- $response = curl_exec($this->curl);
343
- $headers = curl_getinfo($this->curl);
344
-
345
- // fetch errors
346
- $errorNumber = curl_errno($this->curl);
347
- $errorMessage = curl_error($this->curl);
348
-
349
- // error?
350
- if($errorNumber != '') throw new DropboxException($errorMessage, $errorNumber);
351
-
352
- // return
353
- if($expectJSON) return json_decode($response, true);
354
-
355
- // fallback
356
- return $response;
357
- }
358
-
359
-
360
- /**
361
- * Make the call
362
- *
363
- * @return string
364
- * @param string $url The url to call.
365
- * @param array[optional] $parameters Optional parameters.
366
- * @param bool[optional] $method The method to use. Possible values are GET, POST.
367
- * @param string[optional] $filePath The path to the file to upload.
368
- * @param bool[optional] $expectJSON Do we expect JSON?
369
- * @param bool[optional] $isContent Is this content?
370
- */
371
- private function doCall($url, array $parameters = null, $method = 'GET', $filePath = null, $expectJSON = true, $isContent = false)
372
- {
373
- // allowed methods
374
- $allowedMethods = array('GET', 'POST');
375
-
376
- // redefine
377
- $url = (string) $url;
378
- $parameters = (array) $parameters;
379
- $method = (string) $method;
380
- $expectJSON = (bool) $expectJSON;
381
-
382
- // validate method
383
- if(!in_array($method, $allowedMethods)) throw new DropboxException('Unknown method (' . $method . '). Allowed methods are: ' . implode(', ', $allowedMethods));
384
-
385
- // append default parameters
386
- $oauth['oauth_consumer_key'] = $this->getApplicationKey();
387
- $oauth['oauth_nonce'] = md5(microtime() . rand());
388
- $oauth['oauth_timestamp'] = time();
389
- $oauth['oauth_token'] = $this->getOAuthToken();
390
- $oauth['oauth_signature_method'] = 'HMAC-SHA1';
391
- $oauth['oauth_version'] = '1.0';
392
-
393
- // set data
394
- $data = $oauth;
395
- if(!empty($parameters))
396
- {
397
- // convert to UTF-8
398
- foreach($parameters as &$value) $value = utf8_encode($value);
399
-
400
- // merge
401
- $data = array_merge($data, $parameters);
402
- }
403
-
404
- if($filePath != null)
405
- {
406
- // process file
407
- $fileInfo = pathinfo($filePath);
408
-
409
- // add to the data
410
- $data['file'] = $fileInfo['basename'];
411
-
412
- }
413
-
414
- // calculate the base string
415
- if($isContent) $base = $this->calculateBaseString(self::API_CONTENT_URL . '/' . $url, $method, $data);
416
- else $base = $this->calculateBaseString(self::API_URL . '/' . $url, $method, $data);
417
-
418
- // based on the method, we should handle the parameters in a different way
419
- if($method == 'POST')
420
- {
421
- // file provided?
422
- if($filePath != null)
423
- {
424
- // build a boundary
425
- $boundary = md5(time());
426
-
427
- // init var
428
- $content = '--' . $boundary . "\r\n";
429
-
430
- // set file
431
- $content .= 'Content-Disposition: form-data; name=file; filename="' . $fileInfo['basename'] . '"' . "\r\n";
432
- $content .= 'Content-Type: application/octet-stream' . "\r\n";
433
- $content .= "\r\n";
434
- $content .= file_get_contents($filePath);
435
- $content .= "\r\n";
436
- $content .= "--" . $boundary . '--';
437
-
438
- // build headers
439
- $headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
440
- $headers[] = 'Content-Length: ' . strlen($content);
441
-
442
- // set content
443
- $options[CURLOPT_POSTFIELDS] = $content;
444
- }
445
-
446
- // no file
447
- else $options[CURLOPT_POSTFIELDS] = $this->buildQuery($parameters);
448
-
449
- // enable post
450
- $options[CURLOPT_POST] = 1;
451
- }
452
-
453
- else
454
- {
455
- // reset post
456
- $options[CURLOPT_POST] = 0;
457
- unset($options[CURLOPT_POSTFIELDS]);
458
- $url=str_replace("%2F", "/", rawurlencode($url));
459
-
460
- // add the parameters into the querystring
461
- if(!empty($parameters)) $url .= '?' . $this->buildQuery($parameters);
462
- }
463
-
464
- // add sign into the parameters
465
- $oauth['oauth_signature'] = $this->hmacsha1($this->getApplicationSecret() . '&' . $this->getOAuthTokenSecret(), $base);
466
-
467
- if($isContent) $headers[] = $this->calculateHeader($oauth, self::API_CONTENT_URL . '/' . $url);
468
- else $headers[] = $this->calculateHeader($oauth, self::API_URL . '/' . $url);
469
- $headers[] = 'Expect:';
470
-
471
- // set options
472
- if($isContent) $options[CURLOPT_URL] = self::API_CONTENT_URL . '/' . $url;
473
- else $options[CURLOPT_URL] = self::API_URL . '/' . $url;
474
- $options[CURLOPT_PORT] = self::API_PORT;
475
- $options[CURLOPT_USERAGENT] = $this->getUserAgent();
476
- if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) $options[CURLOPT_FOLLOWLOCATION] = true;
477
- $options[CURLOPT_RETURNTRANSFER] = true;
478
- $options[CURLOPT_TIMEOUT] = (int) $this->getTimeOut();
479
- $options[CURLOPT_SSL_VERIFYPEER] = false;
480
- $options[CURLOPT_SSL_VERIFYHOST] = false;
481
- $options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
482
- $options[CURLOPT_HTTPHEADER] = $headers;
483
- // init
484
- if($this->curl == null) $this->curl = curl_init();
485
-
486
- // set options
487
- curl_setopt_array($this->curl, $options);
488
-
489
- // execute
490
- $response = curl_exec($this->curl);
491
- $headers = curl_getinfo($this->curl);
492
-
493
- // fetch errors
494
- $errorNumber = curl_errno($this->curl);
495
- $errorMessage = curl_error($this->curl);
496
-
497
- if(!$expectJSON && $isContent)
498
- {
499
- // is it JSON?
500
- $json = @json_decode($response, true);
501
- if($json !== false && isset($json['error'])) throw new DropboxException($json['error']);
502
-
503
- // set return
504
- $return['content_type'] = $headers['content_type'];
505
- $return['data'] = base64_encode($response);
506
-
507
- // return
508
- return $return;
509
- }
510
-
511
- // we don't expect JSON, return the response
512
- if(!$expectJSON) return $response;
513
-
514
- // replace ids with their string values, added because of some PHP-version can't handle these large values
515
- $response = preg_replace('/id":(\d+)/', 'id":"\1"', $response);
516
-
517
- // we expect JSON, so decode it
518
- $json = @json_decode($response, true);
519
-
520
- // validate JSON
521
- if($json === null)
522
- {
523
- // should we provide debug information
524
- if(self::DEBUG)
525
- {
526
- // make it output proper
527
- echo '<pre>';
528
-
529
- // dump the header-information
530
- var_dump($headers);
531
-
532
- // dump the error
533
- var_dump($errorMessage);
534
-
535
- // dump the raw response
536
- var_dump($response);
537
-
538
- // end proper format
539
- echo '</pre>';
540
- }
541
-
542
- // throw exception
543
- throw new DropboxException('Invalid response.');
544
- }
545
-
546
- // any error
547
- if(isset($json['error']))
548
- {
549
- // should we provide debug information
550
- if(self::DEBUG)
551
- {
552
- // make it output proper
553
- echo '<pre>';
554
-
555
- // dump the header-information
556
- var_dump($headers);
557
-
558
- // dump the raw response
559
- var_dump($response);
560
-
561
- // end proper format
562
- echo '</pre>';
563
- }
564
-
565
- if(isset($json['error']) && is_string($json['error'])) $message = $json['error'];
566
- elseif(isset($json['error']['hash']) && $json['error']['hash'] != '') $message = (string) $json['error']['hash'];
567
- else $message = 'Invalid response.';
568
-
569
- // throw exception
570
- throw new DropboxException($message);
571
- }
572
-
573
- // return
574
- return $json;
575
- }
576
-
577
-
578
- /**
579
- * Get the application key
580
- *
581
- * @return string
582
- */
583
- private function getApplicationKey()
584
- {
585
- return $this->applicationKey;
586
- }
587
-
588
-
589
- /**
590
- * Get the application secret
591
- *
592
- * @return string
593
- */
594
- private function getApplicationSecret()
595
- {
596
- return $this->applicationSecret;
597
- }
598
-
599
-
600
- /**
601
- * Get the oAuth-token
602
- *
603
- * @return string
604
- */
605
- private function getOAuthToken()
606
- {
607
- return $this->oAuthToken;
608
- }
609
-
610
-
611
- /**
612
- * Get the oAuth-token-secret
613
- *
614
- * @return string
615
- */
616
- private function getOAuthTokenSecret()
617
- {
618
- return $this->oAuthTokenSecret;
619
- }
620
-
621
-
622
- /**
623
- * Get the timeout
624
- *
625
- * @return int
626
- */
627
- public function getTimeOut()
628
- {
629
- return (int) $this->timeOut;
630
- }
631
-
632
-
633
- /**
634
- * Get the useragent that will be used. Our version will be prepended to yours.
635
- * It will look like: "PHP Dropbox/<version> <your-user-agent>"
636
- *
637
- * @return string
638
- */
639
- public function getUserAgent()
640
- {
641
- return (string) 'PHP Dropbox/' . self::VERSION . ' ' . $this->userAgent;
642
- }
643
-
644
-
645
- /**
646
- * Set the application key
647
- *
648
- * @return void
649
- * @param string $key The application key to use.
650
- */
651
- private function setApplicationKey($key)
652
- {
653
- $this->applicationKey = (string) $key;
654
- }
655
-
656
-
657
- /**
658
- * Set the application secret
659
- *
660
- * @return void
661
- * @param string $secret The application secret to use.
662
- */
663
- private function setApplicationSecret($secret)
664
- {
665
- $this->applicationSecret = (string) $secret;
666
- }
667
-
668
-
669
- /**
670
- * Set the oAuth-token
671
- *
672
- * @return void
673
- * @param string $token The token to use.
674
- */
675
- public function setOAuthToken($token)
676
- {
677
- $this->oAuthToken = (string) $token;
678
- }
679
-
680
-
681
- /**
682
- * Set the oAuth-secret
683
- *
684
- * @return void
685
- * @param string $secret The secret to use.
686
- */
687
- public function setOAuthTokenSecret($secret)
688
- {
689
- $this->oAuthTokenSecret = (string) $secret;
690
- }
691
-
692
-
693
- /**
694
- * Set the timeout
695
- *
696
- * @return void
697
- * @param int $seconds The timeout in seconds.
698
- */
699
- public function setTimeOut($seconds)
700
- {
701
- $this->timeOut = (int) $seconds;
702
- }
703
-
704
-
705
- /**
706
- * Get the useragent that will be used. Our version will be prepended to yours.
707
- * It will look like: "PHP Dropbox/<version> <your-user-agent>"
708
- *
709
- * @return void
710
- * @param string $userAgent Your user-agent, it should look like <app-name>/<app-version>.
711
- */
712
- public function setUserAgent($userAgent)
713
- {
714
- $this->userAgent = (string) $userAgent;
715
- }
716
-
717
-
718
- /**
719
- * Build the signature for the data
720
- *
721
- * @return string
722
- * @param string $key The key to use for signing.
723
- * @param string $data The data that has to be signed.
724
- */
725
- private function hmacsha1($key, $data)
726
- {
727
- return base64_encode(hash_hmac('SHA1', $data, $key, true));
728
- }
729
-
730
-
731
- /**
732
- * URL-encode method for internatl use
733
- *
734
- * @return string
735
- * @param mixed $value The value to encode.
736
- */
737
- private static function urlencode_rfc3986($value)
738
- {
739
- if(is_array($value)) return array_map(array('Dropbox', 'urlencode_rfc3986'), $value);
740
- else
741
- {
742
- $search = array('+', ' ', '%7E', '%');
743
- $replace = array('%20', '%20', '~', '%25');
744
-
745
- return str_replace($search, $replace, rawurlencode($value));
746
- }
747
- }
748
-
749
-
750
- // oauth resources
751
- /**
752
- * Call for obtaining an OAuth request token.
753
- * Returns a request token and the corresponding request token secret. This token and secret cannot be used to sign requests for the /metadata and /file content API calls.
754
- * Their only purpose is for signing a request to oauth/access_token once the user has gone through the application authorization steps provided by oauth/authorize.
755
- *
756
- * @return array
757
- */
758
- public function oAuthRequestToken()
759
- {
760
- // make the call
761
- $response = $this->doOAuthCall('1/oauth/request_token', null, 'POST', false);
762
-
763
- // process response
764
- $response = (array) explode('&', $response);
765
- $return = array();
766
-
767
- // loop chunks
768
- foreach($response as $chunk)
769
- {
770
- // split again
771
- $chunks = explode('=', $chunk, 2);
772
-
773
- // store return
774
- if(count($chunks) == 2) $return[$chunks[0]] = $chunks[1];
775
- }
776
-
777
- // return
778
- return $return;
779
- }
780
-
781
-
782
- /**
783
- * Redirect the user to the oauth/authorize location so that Dropbox can authenticate the user and ask whether or not the user wants to authorize the application to access
784
- * file metadata and content on its behalf. oauth/authorize is not an API call per se, because it does not have a return value, but rather directs the user to a page on
785
- * api.dropbox.com where they are provided means to log in to Dropbox and grant authority to the application requesting it.
786
- * The page served by oauth/authorize should be presented to the user through their web browser.
787
- * Please note, without directing the user to a Dropbox-provided page via oauth/authorize, it is impossible for your application to use the request token it received
788
- * via oauth/request_token to obtain an access token from oauth/access_token.
789
- *
790
- * @return void
791
- * @param string $oauthToken The request token of the application requesting authority from a user.
792
- * @param string[optional] $oauthCallback After the user authorizes an application, the user is redirected to the application-served URL provided by this parameter.
793
- */
794
- public function oAuthAuthorize($oauthToken, $oauthCallback = null)
795
- {
796
- // build parameters
797
- $parameters = array();
798
- $parameters['oauth_token'] = (string) $oauthToken;
799
- if($oauthCallback !== null) $parameters['oauth_callback'] = (string) $oauthCallback;
800
-
801
- // build url
802
- $url = self::API_AUTH_URL . '/1/oauth/authorize?' . http_build_query($parameters);
803
-
804
- // redirect
805
- header('Location: ' . $url);
806
- exit;
807
- }
808
-
809
- public function iwp_oAuthAuthorize($oauthToken, $oauthCallback = null)
810
- {
811
- // build parameters
812
- $parameters = array();
813
- $parameters['oauth_token'] = (string) $oauthToken;
814
- if($oauthCallback !== null) $parameters['oauth_callback'] = (string) $oauthCallback;
815
-
816
- // build url
817
- $url = self::API_AUTH_URL . '/1/oauth/authorize?' . http_build_query($parameters);
818
-
819
- return $url;
820
- }
821
-
822
- /**
823
- * This call returns a access token and the corresponding access token secret.
824
- * Upon return, the authorization process is now complete and the access token and corresponding secret are used to sign requests for the metadata and file content API calls.
825
- *
826
- * @return array
827
- * @param string $oauthToken The token returned after authorizing.
828
- */
829
- public function oAuthAccessToken($oauthToken)
830
- {
831
- // build parameters
832
- $parameters = array();
833
- $parameters['oauth_token'] = (string) $oauthToken;
834
-
835
- // make the call
836
- $response = $this->doOAuthCall('1/oauth/access_token', $parameters, 'POST', false);
837
-
838
- // process response
839
- $response = (array) explode('&', $response);
840
- $return = array();
841
-
842
- // loop chunks
843
- foreach($response as $chunk)
844
- {
845
- // split again
846
- $chunks = explode('=', $chunk, 2);
847
-
848
- // store return
849
- if(count($chunks) == 2) $return[$chunks[0]] = $chunks[1];
850
- }
851
-
852
- // return
853
- return $return;
854
- }
855
-
856
-
857
- // token resources
858
- /**
859
- * The token call provides a consumer/secret key pair you can use to consistently access the user's account.
860
- * This is the preferred method of authentication over storing the username and password.
861
- * Use the key pair as a signature with every subsequent call.
862
- * The request must be signed using the application's developer and secret key token. Request or access tokens are necessary.
863
- *
864
- * Warning: DO NOT STORE THE USER'S PASSWORD! The way this call works is you call it once with the user's email and password and then
865
- * keep the token around for later. You do NOT (I repeat NOT) call this before everything you do or on each program startup.
866
- * We watch for this and will shut down your application with little notice if we catch you.
867
- * In fact, the Objective-C code does this for you so you can't get it wrong.
868
- *
869
- * @return array Upon successful verification of the user's credentials, returns an array representation of the access token and secret.
870
- * @param string $email The email account of the user.
871
- * @param string $password The password of the user.
872
- */
873
- public function token($email, $password)
874
- {
875
- // build parameters
876
- $parameters = array();
877
- $parameters['email'] = (string) $email;
878
- $parameters['password'] = (string) $password;
879
-
880
- // make the call
881
- $response = (array) $this->doOAuthCall('1/token', $parameters);
882
-
883
- // validate and set
884
- if(isset($response['token'])) $this->setOAuthToken($response['token']);
885
- if(isset($response['secret'])) $this->setOAuthTokenSecret($response['secret']);
886
-
887
- // return
888
- return $response;
889
- }
890
-
891
-
892
- // account resources
893
- /**
894
- * Given a set of account information, the account call allows an application to create a new Dropbox user account.
895
- * This is useful for situations where the trusted third party application is possibly the user's first interaction with Dropbox.
896
- *
897
- * @return bool
898
- * @param string $email The email account of the user.
899
- * @param string $password The password for the user.
900
- * @param string $firstName The user's first name.
901
- * @param string $lastName The user's last name.
902
- */
903
- public function account($email, $password, $firstName, $lastName)
904
- {
905
- // build parameters
906
- $parameters['email'] = (string) $email;
907
- $parameters['first_name'] = (string) $firstName;
908
- $parameters['last_name'] = (string) $lastName;
909
- $parameters['password'] = (string) $password;
910
-
911
- return (bool) ($this->doCall('1/account', $parameters, 'POST', null, false) == 'OK');
912
- }
913
-
914
-
915
- /**
916
- * Get the user account information.
917
- *
918
- * @return array
919
- */
920
- public function accountInfo()
921
- {
922
- // make the call
923
- return (array) $this->doCall('1/account/info');
924
- }
925
-
926
-
927
- // files & metadata
928
- /**
929
- * Retrieves file contents relative to the user's Dropbox root or the application's directory within the user's Dropbox.
930
- *
931
- * @return string
932
- * @param string $path Path of the directory wherin the file is located.
933
- * @param bool[optional] $sandbox Sandbox mode?
934
- */
935
- public function filesGet($path, $sandbox = false)
936
- {
937
- // build url
938
- $url = '1/files/';
939
- $url .= ($sandbox) ? 'sandbox/' : 'dropbox/';
940
- $url .= trim((string) $path, '/');
941
-
942
- // make the call
943
- return $this->doCall($url, null, 'GET', null, false, true);
944
- }
945
-
946
-
947
- /**
948
- * Uploads file contents relative to the user's Dropbox root or the application's directory within the user's Dropbox.
949
- *
950
- * @return bool
951
- * @param string $path Path of the directory wherin the file should be uploaded.
952
- * @param string $localFile Path to the local file.
953
- * @param bool[optional] $sandbox Sandbox mode?
954
- */
955
- public function filesPost($path, $localFile, $sandbox = false)
956
- {
957
- // build url
958
- $url = '1/files/';
959
- $url .= ($sandbox) ? 'sandbox/' : 'dropbox/';
960
- $url .= trim((string) $path, '/');
961
-
962
- // make the call
963
- $return = $this->doCall($url, null, 'POST', $localFile, true, true);
964
- // return the result
965
- return (bool) (isset($return['size']) && $return['size'] == 'winner!');
966
- }
967
-
968
-
969
- /**
970
- * Returns metadata for the file or directory at the given <path> location relative to the user's Dropbox or
971
- * the user's application sandbox. If <path> represents a directory and the list parameter is true, the metadata will
972
- * also include a listing of metadata for the directory's contents.
973
- *
974
- * @return array
975
- * @param string[optional] $path The path to the file/director to get the metadata for.
976
- * @param int[optional] $fileLimit When listing a directory, the service will not report listings containing more than $fileLimit files.
977
- * @param bool[optional] $hash Listing return values include a hash representing the state of the directory's contents.
978
- * @param bool[optional] $list If true, this call returns a list of metadata representations for the contents of the directory. If false, this call returns the metadata for the directory itself.
979
- * @param bool[optional] $sandbox Sandbox mode?
980
- */
981
- public function metadata($path = '', $fileLimit = 10000, $hash = false, $list = true, $sandbox = false)
982
- {
983
- // build url
984
- $url = '1/metadata/';
985
- $url .= ($sandbox) ? 'sandbox/' : 'dropbox/';
986
- $url .= trim((string) $path, '/');
987
-
988
- // build parameters
989
- $parameters = null;
990
- $parameters['file_limit'] = (int) $fileLimit;
991
- if((bool) $hash) $parameters['hash'] = '';
992
- $parameters['list'] = ($list) ? 'true': 'false';
993
-
994
- // make the call
995
- return (array) $this->doCall($url, $parameters);
996
- }
997
-
998
-
999
- /**
1000
- * Get a minimized thumbnail for a photo.
1001
- *
1002
- * @return string Will return a base64_encode string with the JPEG-data
1003
- * @param string $path The path to the photo.
1004
- * @param string[optional] $size The size, possible values are: 'small' (32x32), 'medium' (64x64), 'large' (128x128).
1005
- */
1006
- public function thumbnails($path, $size = 'small')
1007
- {
1008
- // build url
1009
- $url = '1/thumbnails/dropbox/';
1010
- $url .= trim((string) $path, '/');
1011
-
1012
- // build parameters
1013
- $parameters['size'] = (string) $size;
1014
-
1015
- // make the call
1016
- return $this->doCall($url, $parameters, 'GET', null, false, true);
1017
- }
1018
-
1019
-
1020
- // file operations
1021
- /**
1022
- * Copy a file or folder to a new location.
1023
- *
1024
- * @return array
1025
- * @param string $fromPath fromPath specifies either a file or folder to be copied to the location specified by toPath. This path is interpreted relative to the location specified by root.
1026
- * @param string $toPath toPath specifies the destination path including the new name for file or folder. This path is interpreted relative to the location specified by root.
1027
- * @param bool[optional] $sandbox Sandbox mode?
1028
- */
1029
- public function fileopsCopy($fromPath, $toPath, $sandbox = false)
1030
- {
1031
- // build url
1032
- $url = '1/fileops/copy';
1033
-
1034
- // build parameters
1035
- $parameters['from_path'] = (string) $fromPath;
1036
- $parameters['to_path'] = (string) $toPath;
1037
- $parameters['root'] = ($sandbox) ? 'sandbox' : 'dropbox';
1038
-
1039
- // make the call
1040
- return $this->doCall($url, $parameters, 'POST');
1041
- }
1042
-
1043
-
1044
- /**
1045
- * Create a folder relative to the user's Dropbox root or the user's application sandbox folder.
1046
- *
1047
- * @return array
1048
- * @param string $path The path to the new folder to create, relative to root.
1049
- * @param bool[optional] $sandbox Sandbox mode?
1050
- */
1051
- public function fileopsCreateFolder($path, $sandbox = false)
1052
- {
1053
- // build url
1054
- $url = '1/fileops/create_folder';
1055
-
1056
- // build parameters
1057
- $parameters['path'] = trim((string) $path, '/');
1058
- $parameters['root'] = ($sandbox) ? 'sandbox' : 'dropbox';
1059
-
1060
- // make the call
1061
- return $this->doCall($url, $parameters, 'POST');
1062
- }
1063
-
1064
-
1065
- /**
1066
- * Deletes a file or folder.
1067
- *
1068
- * @return array
1069
- * @param string $path path specifies either a file or folder to be deleted. This path is interpreted relative to the location specified by root.
1070
- * @param bool[optional] $sandbox Sandbox mode?
1071
- */
1072
- public function fileopsDelete($path, $sandbox = false)
1073
- {
1074
- // build url
1075
- $url = '1/fileops/delete';
1076
-
1077
- // build parameters
1078
- $parameters['path'] = trim((string) $path, '/');
1079
- $parameters['root'] = ($sandbox) ? 'sandbox' : 'dropbox';
1080
- // make the call
1081
- return $this->doCall($url, $parameters, 'POST');
1082
- }
1083
-
1084
-
1085
- /**
1086
- * Move a file or folder to a new location.
1087
- *
1088
- * @return array
1089
- * @param string $fromPath fromPath specifies either a file or folder to be copied to the location specified by toPath. This path is interpreted relative to the location specified by root.
1090
- * @param string $toPath toPath specifies the destination path including the new name for file or folder. This path is interpreted relative to the location specified by root.
1091
- * @param bool[optional] $sandbox Sandbox mode?
1092
- */
1093
- public function fileopsMove($fromPath, $toPath, $sandbox = false)
1094
- {
1095
- // build url
1096
- $url = '1/fileops/move';
1097
-
1098
- // build parameters
1099
- $parameters['from_path'] = (string) $fromPath;
1100
- $parameters['to_path'] = (string) $toPath;
1101
- $parameters['root'] = ($sandbox) ? 'sandbox' : 'dropbox';
1102
-
1103
- // make the call
1104
- return $this->doCall($url, $parameters, 'POST');
1105
- }
1106
-
1107
- function _log($mixed)
1108
- {
1109
- if (is_array($mixed)) {
1110
- $mixed = print_r($mixed, 1);
1111
- } else if (is_object($mixed)) {
1112
- ob_start();
1113
- var_dump($mixed);
1114
- $mixed = ob_get_clean();
1115
- }
1116
-
1117
- //$handle = fopen(dirname(__FILE__) . '/log', 'a');
1118
- //fwrite($handle, $mixed . PHP_EOL);
1119
- //fclose($handle);
1120
- }
1121
- }
1122
-
1123
-
1124
- /**
1125
- * Dropbox Exception class
1126
- *
1127
- * @author Tijs Verkoyen <php-dropbox@verkoyen.eu>
1128
- */
1129
- class DropboxException extends Exception
1130
- {
1131
- }
1132
-
1133
- ?>
lib/dropbox.php ADDED
@@ -0,0 +1,283 @@