InfiniteWP Client - Version 1.1.3

Version Description

  • Backup improved and optimize table while backing up fixed
  • Excluding wp-content/cache & wp-content/w3tc/ by default
  • Amazon S3 backup improved
  • pclZip functions naming problem fixed
  • get_themes incompatibility fixed
Download this release

Release Info

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

Code changes from version 1.1.2 to 1.1.3

addons/backup_repository/backup_repository.class.php CHANGED
@@ -70,14 +70,7 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup
70
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
71
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
72
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
73
- }
74
-
75
- if (isset($account_info['iwp_email']) && !empty($account_info['iwp_email'])) {
76
- $account_info['iwp_email']['file_path'] = $backup_file;
77
- $account_info['iwp_email']['task_name'] = 'Backup Now';
78
- $return = $this->email_backup($account_info['iwp_email']);
79
- }
80
-
81
82
if ($return == true && $del_host_file) {
83
@unlink($backup_file);
@@ -96,7 +89,5 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup
96
return $return;
97
98
}
99
-
100
-
101
}
102
?>
70
if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
71
$account_info['iwp_dropbox']['backup_file'] = $backup_file;
72
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
73
+ }
74
75
if ($return == true && $del_host_file) {
76
@unlink($backup_file);
89
return $return;
90
91
}
92
}
93
?>
backup.class.php CHANGED
@@ -91,7 +91,7 @@ class IWP_MMB_Backup extends IWP_MMB_Core
91
function set_memory()
92
{
93
$changed = array('execution_time' => 0, 'memory_limit' => 0);
94
-
95
$memory_limit = trim(ini_get('memory_limit'));
96
$last = strtolower(substr($memory_limit, -1));
97
@@ -368,47 +368,57 @@ function delete_task_now($task_name){
368
$this->update_status($task_name, $this->statuses['db_dump'], true);
369
$this->update_status($task_name, $this->statuses['db_zip']);
370
371
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
372
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
373
$comp_level = $disable_comp ? '-0' : '-1';
374
-
375
chdir(IWP_BACKUP_DIR);
376
$zip = $this->get_zip();
377
$command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
378
ob_start();
379
$result = $this->iwp_mmb_exec($command);
380
ob_get_clean();
381
- if (!$result) { // fallback to pclzip
382
- define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
383
- //require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
384
- require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
385
- $archive = new IWPPclZip($backup_file);
386
- /*if ($disable_comp) {
387
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
388
-
389
- } else {
390
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
391
- }*/
392
- if($fail_safe_files && $disable_comp){
393
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
394
}
395
- elseif(!$fail_safe_files && $disable_comp){
396
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
397
- }
398
- elseif($fail_safe_files && !$disable_comp){
399
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
400
- }
401
- else{
402
- $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
403
}
404
- @unlink($db_result);
405
- @rmdir(IWP_DB_DIR);
406
- if (!$result) {
407
- return array(
408
- 'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
409
- );
410
- }
411
- }
412
413
@unlink($db_result);
414
@rmdir(IWP_DB_DIR);
@@ -496,7 +506,7 @@ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_ftp']))
496
/*
497
//IWP Remove starts here //IWP Remove ends here
498
*/
499
- if ($task_name != 'Backup Now') {
500
501
if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
502
$this->update_status($task_name, $this->statuses['ftp']);
@@ -542,19 +552,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
542
$this->wpdb_reconnect();
543
$this->update_status($task_name, $this->statuses['dropbox'], true);
544
}
545
-
546
- if (isset($account_info['iwp_email']) && !empty($account_info['iwp_email'])) {
547
- $this->update_status($task_name, $this->statuses['email']);
548
- $account_info['iwp_email']['task_name'] = $task_name;
549
- $account_info['iwp_email']['file_path'] = $backup_file;
550
-
551
- $email_result = $this->email_backup($account_info['iwp_email']);
552
- if (is_array($email_result) && isset($email_result['error'])) {
553
- return $email_result;
554
- }
555
- $this->update_status($task_name, $this->statuses['email'], true);
556
- }
557
-
558
if ($del_host_file) {
559
@unlink($backup_file);
560
}
@@ -564,6 +562,7 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
564
//$this->update_status($task_name,$this->statuses['finished'],true);
565
return $backup_url; //Return url to backup file
566
}
567
568
function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
569
{
@@ -587,10 +586,10 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
587
$this->update_status($task_name, $this->statuses['db_dump'], true);
588
$this->update_status($task_name, $this->statuses['db_zip']);
589
590
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
591
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
592
$comp_level = $disable_comp ? '-0' : '-1';
593
-
594
$zip = $this->get_zip();
595
//Add database file
596
chdir(IWP_BACKUP_DIR);
@@ -598,42 +597,43 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
598
ob_start();
599
$result = $this->iwp_mmb_exec($command);
600
ob_get_clean();
601
-
602
-
603
- if (!$result) {
604
- define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
605
- //require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
606
- require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
607
- $archive = new IWPPclZip($backup_file);
608
-
609
- /*if ($disable_comp) {
610
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
611
- } else {
612
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
613
- }*/
614
-
615
- if($fail_safe_files && $disable_comp){
616
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
617
- }
618
- elseif(!$fail_safe_files && $disable_comp){
619
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
620
- }
621
- elseif($fail_safe_files && !$disable_comp){
622
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
623
}
624
- else{
625
- $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
626
}
627
-
628
- @unlink($db_result);
629
- @rmdir(IWP_DB_DIR);
630
-
631
- if (!$result_db) {
632
- return array(
633
- 'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
634
- );
635
- }
636
- }
637
638
@unlink($db_result);
639
@rmdir(IWP_DB_DIR);
@@ -644,9 +644,13 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
644
//Always remove backup folders
645
$remove = array(
646
trim(basename(WP_CONTENT_DIR)) . "/infinitewp/backups",
647
- trim(basename(WP_CONTENT_DIR)) . "/" . md5('iwp_mmb-client') . "/iwp_backups"
648
);
649
650
//Exclude paths
651
$exclude_data = "-x";
652
@@ -654,6 +658,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
654
655
if (!empty($exclude) && is_array($exclude)) {
656
foreach ($exclude as $data) {
657
if (is_dir(ABSPATH . $data)) {
658
if ($sys == 'WIN')
659
$exclude_data .= " $data/*.*";
@@ -681,12 +687,14 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
681
$exclude_file_data = "-x".$exclude_file_data;
682
}
683
684
- foreach ($remove as $data) {
685
if ($sys == 'WIN')
686
$exclude_data .= " $data/*.*";
687
else
688
$exclude_data .= " '$data/*'";
689
- }
690
691
//Include paths by default
692
$add = array(
@@ -706,6 +714,8 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
706
//Additional includes?
707
if (!empty($include) && is_array($include)) {
708
foreach ($include as $data) {
709
if ($data) {
710
if ($sys == 'WIN')
711
$include_data .= " $data/*.*";
@@ -718,10 +728,10 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
718
$this->update_status($task_name, $this->statuses['files_zip']);
719
chdir(ABSPATH);
720
ob_start();
721
- $command = "$zip -q -j $comp_level $backup_file .* * $exclude_data";
722
$result_f = $this->iwp_mmb_exec($command, false, true);
723
if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
724
- $command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
725
$result_d = $this->iwp_mmb_exec($command, false, true);
726
if ($result_d && $result_d != 18) {
727
@unlink($backup_file);
@@ -736,107 +746,185 @@ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
736
}
737
}
738
ob_get_clean();
739
-
740
- if ($result_f && $result_f != 18) { //Try pclZip
741
-
742
- if (!isset($archive)) {
743
- define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
744
- //require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
745
- require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
746
- $archive = new IWPPclZip($backup_file);
747
- }
748
-
749
- //Include paths
750
- $include_data = array();
751
- if (!empty($include) && is_array($include)) {
752
- foreach ($include as $data) {
753
- if ($data && file_exists(ABSPATH . $data))
754
- $include_data[] = ABSPATH . $data . '/';
755
- }
756
- }
757
-
758
- foreach ($add as $data) {
759
- if (file_exists(ABSPATH . $data))
760
- $include_data[] = ABSPATH . $data . '/';
761
- }
762
-
763
- //Include root files
764
- if ($handle = opendir(ABSPATH)) {
765
- while (false !== ($file = readdir($handle))) {
766
- if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
767
- $include_data[] = ABSPATH . $file;
768
- }
769
- }
770
- closedir($handle);
771
- }
772
-
773
- //exclude paths
774
- $exclude_data = array();
775
- if (!empty($exclude) && is_array($exclude)) {
776
- foreach ($exclude as $data) {
777
- if (is_dir(ABSPATH . $data))
778
- $exclude_data[] = $data . '/';
779
- else
780
- $exclude_data[] = $data;
781
- }
782
- }
783
-
784
- foreach ($remove as $rem) {
785
- $exclude_data[] = $rem . '/';
786
- }
787
-
788
- if($fail_safe_files && $disable_comp){
789
- $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
790
- }
791
- elseif(!$fail_safe_files && $disable_comp){
792
- $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_NO_COMPRESSION);
793
- }
794
- elseif($fail_safe_files && !$disable_comp){
795
- $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
796
- }
797
- else{
798
- $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data);
799
}
800
-
801
- if (!$result) {
802
- @unlink($backup_file);
803
- return array(
804
- 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
805
- );
806
- }
807
-
808
- //Now exclude paths
809
- /*$exclude_data = array();
810
- if (!empty($exclude)) {
811
- foreach ($exclude as $data) {
812
- if (is_dir(ABSPATH . $data))
813
- $exclude_data[] = $data . '/';
814
- else
815
- $exclude_data[] = $data;
816
- }
817
- }
818
-
819
- foreach ($remove as $rem) {
820
- $exclude_data[] = $rem . '/';
821
- }
822
-
823
- $result_excl = $archive->delete(PCLZIP_OPT_BY_NAME, $exclude_data);
824
- if (!$result_excl) {
825
- @unlink($backup_file);
826
- return array(
827
- 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
828
- );
829
- }*/
830
}
831
-
832
//Reconnect
833
$this->wpdb_reconnect();
834
835
$this->update_status($task_name, $this->statuses['files_zip'], true);
836
return true;
837
}
838
-
839
-
840
function backup_db()
841
{
842
$db_folder = IWP_DB_DIR . '/';
@@ -1064,7 +1152,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1064
} elseif (isset($task['task_results'][$result_id]['amazons3'])) {
1065
$amazons3_file = $task['task_results'][$result_id]['amazons3'];
1066
$args = $task['task_args']['account_info']['iwp_amazon_s3'];
1067
- $args['backup_file'] = $ftp_file;
1068
$backup_file = $this->get_amazons3_backup($args);
1069
if ($backup_file == false) {
1070
return array(
@@ -1072,7 +1160,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1072
);
1073
}
1074
} elseif(isset($task['task_results'][$result_id]['dropbox'])){
1075
- $dropbox_file = $task['task_results'][$result_id]['dropbox'];
1076
$args = $task['task_args']['account_info']['iwp_dropbox'];
1077
$args['backup_file'] = $dropbox_file;
1078
$backup_file = $this->get_dropbox_backup($args);
@@ -1167,7 +1255,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1167
1168
} else {
1169
return array(
1170
- 'error' => 'Error restoring. Cannot find backup file.'
1171
);
1172
}
1173
@@ -1351,7 +1439,7 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1351
function optimize_tables()
1352
{
1353
global $wpdb;
1354
- $query = 'SHOW TABLES';
1355
$tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
1356
foreach ($tables as $table) {
1357
if (in_array($table['Engine'], array(
@@ -1367,8 +1455,10 @@ elseif (isset($task['task_results'][$result_id]['ftp'])) {
1367
}
1368
}
1369
1370
- $table_string = rtrim($table_string);
1371
$optimize = $wpdb->query("OPTIMIZE TABLE $table_string");
1372
1373
return $optimize ? true : false;
1374
}
@@ -1683,16 +1773,15 @@ function ftp_backup($args)
1683
1684
function dropbox_backup($args)
1685
{
1686
-
1687
extract($args);
1688
1689
if(isset($consumer_secret) && !empty($consumer_secret)){
1690
//New way
1691
require_once('lib/dropbox.oauth.php');
1692
1693
- $dropbox = new Dropbox($consumer_key, $consumer_secret);
1694
- $dropbox->setOAuthToken($oauth_token);
1695
- $dropbox->setOAuthTokenSecret($oauth_token_secret);
1696
1697
if ($dropbox_site_folder == true)
1698
$dropbox_destination .= '/' . $this->site_name;
@@ -1710,36 +1799,10 @@ function ftp_backup($args)
1710
return true;
1711
1712
} else {
1713
- //old way
1714
- require_once('lib/dropbox.php');
1715
- // extract($args);
1716
-
1717
- //$email, $password, $backup_file, $destination, $dropbox_site_folder
1718
-
1719
- $size = ceil(filesize($backup_file) / 1024);
1720
- if ($size > 300000) {
1721
- return array(
1722
- 'error' => 'Cannot upload file to Dropbox. Dropbox has upload limit of 300Mb per file.',
1723
- 'partial' => 1
1724
- );
1725
- }
1726
-
1727
- if ($dropbox_site_folder == true)
1728
- $dropbox_destination .= '/' . $this->site_name;
1729
-
1730
- try {
1731
- $uploader = new DropboxUploader($dropbox_username, $dropbox_password);
1732
- $uploader->upload($backup_file, $dropbox_destination);
1733
- }
1734
- catch (Exception $e) {
1735
- return array(
1736
- 'error' => $e->getMessage(),
1737
- 'partial' => 1
1738
);
1739
- }
1740
-
1741
- return true;
1742
- }
1743
1744
}
1745
@@ -1813,16 +1876,20 @@ function ftp_backup($args)
1813
function amazons3_backup($args)
1814
{
1815
if ($this->iwp_mmb_function_exists('curl_init')) {
1816
- require_once('lib/s3.php');
1817
extract($args);
1818
1819
if ($as3_site_folder == true)
1820
$as3_directory .= '/' . $this->site_name;
1821
-
1822
- $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1823
try{
1824
- $s3 = new iwpS3(trim($as3_access_key), trim(str_replace(' ', '+', $as3_secure_key)), false, $endpoint);
1825
- if ($s3->putObjectFile($backup_file, $as3_bucket, $as3_directory . '/' . basename($backup_file), iwpS3::ACL_PRIVATE)) {
1826
return true;
1827
} else {
1828
return array(
@@ -1851,17 +1918,18 @@ function ftp_backup($args)
1851
}
1852
}
1853
1854
function remove_amazons3_backup($args)
1855
{
1856
if ($this->iwp_mmb_function_exists('curl_init')) {
1857
- require_once('lib/s3.php');
1858
extract($args);
1859
if ($as3_site_folder == true)
1860
$as3_directory .= '/' . $this->site_name;
1861
- $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1862
try{
1863
- $s3 = new iwpS3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1864
- $s3->deleteObject($as3_bucket, $as3_directory . '/' . $backup_file);
1865
} catch (Exception $e){
1866
1867
}
@@ -1870,17 +1938,17 @@ function ftp_backup($args)
1870
1871
function get_amazons3_backup($args)
1872
{
1873
- require_once('lib/s3.php');
1874
extract($args);
1875
- $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1876
$temp = '';
1877
try{
1878
- $s3 = new iwpS3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1879
- if ($as3_site_folder == true)
1880
- $as3_directory .= '/' . $this->site_name;
1881
-
1882
- $temp = ABSPATH . 'iwp_temp_backup.zip';
1883
- $s3->getObject($as3_bucket, $as3_directory . '/' . $backup_file, $temp);
1884
} catch (Exception $e){
1885
return $temp;
1886
}
@@ -2349,4 +2417,58 @@ function get_next_schedules()
2349
if( function_exists('add_filter') ){
2350
add_filter( 'iwp_website_add', 'IWP_MMB_Backup::readd_tasks' );
2351
}
2352
?>
91
function set_memory()
92
{
93
$changed = array('execution_time' => 0, 'memory_limit' => 0);
94
+ @ignore_user_abort(true);
95
$memory_limit = trim(ini_get('memory_limit'));
96
$last = strtolower(substr($memory_limit, -1));
97
368
$this->update_status($task_name, $this->statuses['db_dump'], true);
369
$this->update_status($task_name, $this->statuses['db_zip']);
370
371
+ /*zip_backup_db*/
372
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
373
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
374
$comp_level = $disable_comp ? '-0' : '-1';
375
chdir(IWP_BACKUP_DIR);
376
$zip = $this->get_zip();
377
$command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
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(
417
+ 'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
418
+ );
419
+ }
420
}
421
+ }
422
423
@unlink($db_result);
424
@rmdir(IWP_DB_DIR);
506
/*
507
//IWP Remove starts here //IWP Remove ends here
508
*/
509
+ if ($task_name != 'Backup Now') {
510
511
if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
512
$this->update_status($task_name, $this->statuses['ftp']);
552
$this->wpdb_reconnect();
553
$this->update_status($task_name, $this->statuses['dropbox'], true);
554
}
555
+
556
if ($del_host_file) {
557
@unlink($backup_file);
558
}
562
//$this->update_status($task_name,$this->statuses['finished'],true);
563
return $backup_url; //Return url to backup file
564
}
565
+
566
567
function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
568
{
586
$this->update_status($task_name, $this->statuses['db_dump'], true);
587
$this->update_status($task_name, $this->statuses['db_zip']);
588
589
+ /*zip_backup_db*/
590
$fail_safe_files = $this->tasks[$task_name]['task_args']['fail_safe_files'];
591
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
592
$comp_level = $disable_comp ? '-0' : '-1';
593
$zip = $this->get_zip();
594
//Add database file
595
chdir(IWP_BACKUP_DIR);
597
ob_start();
598
$result = $this->iwp_mmb_exec($command);
599
ob_get_clean();
600
+ /*zip_backup_db*/
601
+
602
+ if(!$result){
603
+ $zip_archive_db_result = false;
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) {
631
+ return array(
632
+ 'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
633
+ );
634
+ }
635
}
636
+ }
637
638
@unlink($db_result);
639
@rmdir(IWP_DB_DIR);
644
//Always remove backup folders
645
$remove = array(
646
trim(basename(WP_CONTENT_DIR)) . "/infinitewp/backups",
647
+ trim(basename(WP_CONTENT_DIR)) . "/" . md5('iwp_mmb-client') . "/iwp_backups",
648
+ trim(basename(WP_CONTENT_DIR)) . "/cache",
649
+ trim(basename(WP_CONTENT_DIR)) . "/w3tc"
650
);
651
652
+ $exclude = array_merge($exclude, $remove);
653
+
654
//Exclude paths
655
$exclude_data = "-x";
656
658
659
if (!empty($exclude) && is_array($exclude)) {
660
foreach ($exclude as $data) {
661
+ if(empty($data))
662
+ continue;
663
if (is_dir(ABSPATH . $data)) {
664
if ($sys == 'WIN')
665
$exclude_data .= " $data/*.*";
687
$exclude_file_data = "-x".$exclude_file_data;
688
}
689
690
+ /* foreach ($remove as $data) {
691
+ if(empty($data))
692
+ continue;
693
if ($sys == 'WIN')
694
$exclude_data .= " $data/*.*";
695
else
696
$exclude_data .= " '$data/*'";
697
+ }*/
698
699
//Include paths by default
700
$add = array(
714
//Additional includes?
715
if (!empty($include) && is_array($include)) {
716
foreach ($include as $data) {
717
+ if(empty($data))
718
+ continue;
719
if ($data) {
720
if ($sys == 'WIN')
721
$include_data .= " $data/*.*";
728
$this->update_status($task_name, $this->statuses['files_zip']);
729
chdir(ABSPATH);
730
ob_start();
731
+ $command = "$zip -q -j $comp_level $backup_file .* * $exclude_file_data";
732
$result_f = $this->iwp_mmb_exec($command, false, true);
733
if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
734
+ $command = "$zip -q -r $comp_level $backup_file $include_data $exclude_file_data";
735
$result_d = $this->iwp_mmb_exec($command, false, true);
736
if ($result_d && $result_d != 18) {
737
@unlink($backup_file);
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';
761
+ require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
762
+ $archive = new IWPPclZip($backup_file);
763
+ }
764
+
765
+ //Include paths
766
+ $include_data = array();
767
+ if (!empty($include) && is_array($include)) {
768
+ foreach ($include as $data) {
769
+ if ($data && file_exists(ABSPATH . $data))
770
+ $include_data[] = ABSPATH . $data . '/';
771
+ }
772
+ }
773
+
774
+ foreach ($add as $data) {
775
+ if (file_exists(ABSPATH . $data))
776
+ $include_data[] = ABSPATH . $data . '/';
777
+ }
778
+
779
+ //Include root files
780
+ if ($handle = opendir(ABSPATH)) {
781
+ while (false !== ($file = readdir($handle))) {
782
+ if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
783
+ $include_data[] = ABSPATH . $file;
784
+ }
785
+ }
786
+ closedir($handle);
787
+ }
788
+
789
+ //exclude paths
790
+ $exclude_data = array();
791
+ if (!empty($exclude) && is_array($exclude)) {
792
+ foreach ($exclude as $data) {
793
+ if (is_dir(ABSPATH . $data))
794
+ $exclude_data[] = $data . '/';
795
+ else
796
+ $exclude_data[] = $data;
797
+ }
798
+ }
799
+
800
+ foreach ($remove as $rem) {
801
+ $exclude_data[] = $rem . '/';
802
+ }
803
+
804
+ if($fail_safe_files && $disable_comp){
805
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
806
+ }
807
+ elseif(!$fail_safe_files && $disable_comp){
808
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_NO_COMPRESSION);
809
+ }
810
+ elseif($fail_safe_files && !$disable_comp){
811
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 1);
812
+ }
813
+ else{
814
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data);
815
+ }
816
+
817
+ if (!$result) {
818
+ @unlink($backup_file);
819
+ return array(
820
+ 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
821
+ );
822
+ }
823
}
824
}
825
//Reconnect
826
$this->wpdb_reconnect();
827
828
$this->update_status($task_name, $this->statuses['files_zip'], true);
829
return true;
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
837
+ * @param string $backup_file absolute path to zip file
838
+ * @return bool is compress successful or not
839
+ */
840
+ function zip_archive_backup_db($task_name, $db_result, $backup_file) {
841
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
842
+ if (!$disable_comp) {
843
+ $this->_log("Compression is not supported by ZipArchive");
844
+ }
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;
853
+ }
854
+
855
+ return $result; // true if $backup_file iz zipped successfully, false if error is occured in zip process
856
+ }
857
+
858
+ /**
859
+ * Zipping whole site root folder and append to backup file with database dump
860
+ * by ZipArchive class, requires php zip extension.
861
+ *
862
+ * @param string $task_name the name of backup task
863
+ * @param string $backup_file absolute path to zip file
864
+ * @param array $exclude array of files of folders to exclude, relative to site's root
865
+ * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default)
866
+ * @return array|bool true if successful or an array with error message if not
867
+ */
868
+ function zip_archive_backup($task_name, $backup_file, $exclude, $include, $overwrite = false) {
869
+
870
+ $filelist = $this->get_backup_files($exclude, $include);
871
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
872
+ if (!$disable_comp) {
873
+ $this->_log("Compression is not supported by ZipArchive");
874
+ }
875
+ $zip = new ZipArchive();
876
+ if ($overwrite) {
877
+ $result = $zip->open($backup_file, ZipArchive::OVERWRITE); // Tries to open $backup_file for acrhiving
878
+ } else {
879
+ $result = $zip->open($backup_file); // Tries to open $backup_file for acrhiving
880
+ }
881
+ if ($result === true) {
882
+ foreach ($filelist as $file) {
883
+ $result = $result && $zip->addFile($file, sprintf("%s", str_replace(ABSPATH, '', $file))); // Tries to add a new file to $backup_file
884
+ }
885
+ $result = $result && $zip->close(); // Tries to close $backup_file
886
+ } else {
887
+ $result = false;
888
+ }
889
+ return $result; // true if $backup_file iz zipped successfully, false if error is occured in zip process
890
+ }
891
+
892
+
893
+ /**
894
+ * Gets an array of relative paths of all files in site root recursively.
895
+ * By default, there are all files from root folder, all files from folders wp-admin, wp-content, wp-includes recursively.
896
+ * Parameter $include adds other folders from site root, and excludes any file or folder by relative path to site's root.
897
+ *
898
+ * @param array $exclude array of files of folders to exclude, relative to site's root
899
+ * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default)
900
+ * @return array array with all files in site root dir
901
+ */
902
+ function get_backup_files($exclude, $include) {
903
+
904
+ $add = array(
905
+ trim(WPINC),
906
+ trim(basename(WP_CONTENT_DIR)),
907
+ "wp-admin"
908
+ );
909
+
910
+ $include = array_merge($add, $include);
911
+
912
+ $filelist = array();
913
+ if ($handle = opendir(ABSPATH)) {
914
+ while (false !== ($file = readdir($handle))) {
915
+ if (is_dir($file) && file_exists(ABSPATH . $file) && !(in_array($file, $include))) {
916
+ $exclude[] = $file;
917
+ }
918
+ }
919
+ closedir($handle);
920
+ }
921
+
922
+ $filelist = get_all_files_from_dir(ABSPATH, $exclude);
923
+
924
+ return $filelist;
925
+ }
926
+
927
+
928
function backup_db()
929
{
930
$db_folder = IWP_DB_DIR . '/';
1152
} elseif (isset($task['task_results'][$result_id]['amazons3'])) {
1153
$amazons3_file = $task['task_results'][$result_id]['amazons3'];
1154
$args = $task['task_args']['account_info']['iwp_amazon_s3'];
1155
+ $args['backup_file'] = $amazons3_file;
1156
$backup_file = $this->get_amazons3_backup($args);
1157
if ($backup_file == false) {
1158
return array(
1160
);
1161
}
1162
} elseif(isset($task['task_results'][$result_id]['dropbox'])){
1163
+ $dropbox_file = $task['task_results'][$result_id]['dropbox'];
1164
$args = $task['task_args']['account_info']['iwp_dropbox'];
1165
$args['backup_file'] = $dropbox_file;
1166
$backup_file = $this->get_dropbox_backup($args);
1255
1256
} else {
1257
return array(
1258
+ 'error' => 'Error while restoring. The WP root directory is not writable. Set write permission(755 or 777).'
1259
);
1260
}
1261
1439
function optimize_tables()
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(
1455
}
1456
}
1457
1458
+ if(!empty($table_string)){
1459
+ $table_string = rtrim($table_string, ',');
1460
$optimize = $wpdb->query("OPTIMIZE TABLE $table_string");
1461
+ }
1462
1463
return $optimize ? true : false;
1464
}
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;
1799
return true;
1800
1801
} else {
1802
+ return array(
1803
+ 'error' => 'Please connect your InfiniteWP panel with your Dropbox account.'
1804
);
1805
+ }
1806
1807
}
1808
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
1883
if ($as3_site_folder == true)
1884
$as3_directory .= '/' . $this->site_name;
1885
+
1886
try{
1887
+
1888
+ CFCredentials::set(array('development' => array('key' => trim($as3_access_key), 'secret' => trim(str_replace(' ', '+', $as3_secure_key)), 'default_cache_config' => '', 'certificate_authority' => true, 'use_ssl'=>false, 'ssl_verification'=>false), '@default' => 'development'));
1889
+ $s3 = new AmazonS3();
1890
+ $response = $s3->create_object($as3_bucket, $as3_directory . '/' . basename($backup_file), array('fileUpload' => $backup_file));
1891
+ $upload = $response->isOk();
1892
+ if($upload) {
1893
return true;
1894
} else {
1895
return array(
1918
}
1919
}
1920
1921
+
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;
1929
try{
1930
+ CFCredentials::set(array('development' => array('key' => trim($as3_access_key), 'secret' => trim(str_replace(' ', '+', $as3_secure_key)), 'default_cache_config' => '', 'certificate_authority' => true), '@default' => 'development'));
1931
+ $s3 = new AmazonS3();
1932
+ $s3->delete_object($as3_bucket, $as3_directory . '/' . $backup_file);
1933
} catch (Exception $e){
1934
1935
}
1938
1939
function get_amazons3_backup($args)
1940
{
1941
+ require_once('lib/amazon_s3/sdk.class.php');
1942
extract($args);
1943
$temp = '';
1944
try{
1945
+ CFCredentials::set(array('development' => array('key' => trim($as3_access_key), 'secret' => trim(str_replace(' ', '+', $as3_secure_key)), 'default_cache_config' => '', 'certificate_authority' => true), '@default' => 'development'));
1946
+ $s3 = new AmazonS3();
1947
+ if ($as3_site_folder == true)
1948
+ $as3_directory .= '/' . $this->site_name;
1949
+
1950
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1951
+ $s3->get_object($as3_bucket, $as3_directory . '/' . $backup_file, array("fileDownload" => $temp));
1952
} catch (Exception $e){
1953
return $temp;
1954
}
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
+ /**
2423
+ * Get all files in directory
2424
+ *
2425
+ * @param string $path Relative or absolute path to folder
2426
+ * @param array $exclude List of excluded files or folders, relative to $path
2427
+ * @return array List of all files in folder $path, exclude all files in $exclude array
2428
+ */
2429
+ function get_all_files_from_dir($path, $exclude = array()) {
2430
+ if ($path[strlen($path) - 1] === "/") $path = substr($path, 0, -1);
2431
+ global $directory_tree, $ignore_array;
2432
+ $directory_tree = array();
2433
+ foreach ($exclude as $file) {
2434
+ if (!in_array($file, array('.', '..'))) {
2435
+ if ($file[0] === "/") $path = substr($file, 1);
2436
+ $ignore_array[] = "$path/$file";
2437
+ }
2438
+ }
2439
+ get_all_files_from_dir_recursive($path);
2440
+ return $directory_tree;
2441
+ }
2442
+ }
2443
+
2444
+ if (!function_exists('get_all_files_from_dir_recursive')) {
2445
+ /**
2446
+ * Get all files in directory,
2447
+ * wrapped function which writes in global variable
2448
+ * and exclued files or folders are read from global variable
2449
+ *
2450
+ * @param string $path Relative or absolute path to folder
2451
+ * @return void
2452
+ */
2453
+ function get_all_files_from_dir_recursive($path) {
2454
+ if ($path[strlen($path) - 1] === "/") $path = substr($path, 0, -1);
2455
+ global $directory_tree, $ignore_array;
2456
+ $directory_tree_temp = array();
2457
+ $dh = @opendir($path);
2458
+
2459
+ while (false !== ($file = @readdir($dh))) {
2460
+ if (!in_array($file, array('.', '..'))) {
2461
+ if (!in_array("$path/$file", $ignore_array)) {
2462
+ if (!is_dir("$path/$file")) {
2463
+ $directory_tree[] = "$path/$file";
2464
+ } else {
2465
+ get_all_files_from_dir_recursive("$path/$file");
2466
+ }
2467
+ }
2468
+ }
2469
+ }
2470
+ @closedir($dh);
2471
+ }
2472
+ }
2473
+
2474
?>
helper.class.php CHANGED
@@ -36,9 +36,9 @@ class IWP_MMB_Helper
36
$mixed = ob_get_clean();
37
}
38
39
- $handle = fopen(dirname(__FILE__) . '/log', 'a');
40
- fwrite($handle, $mixed . PHP_EOL);
41
- fclose($handle);
42
}
43
44
function _escape(&$array)
36
$mixed = ob_get_clean();
37
}
38
39
+ //$handle = fopen(dirname(__FILE__) . '/log', 'a');
40
+ //fwrite($handle, $mixed . PHP_EOL);
41
+ //fclose($handle);
42
}
43
44
function _escape(&$array)
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.2
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.2');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
@@ -74,6 +74,9 @@ if( !function_exists ( 'iwp_mmb_filter_params' )) {
74
}
75
}
76
77
if( !function_exists ('iwp_mmb_parse_request')) {
78
function iwp_mmb_parse_request()
79
{
@@ -99,6 +102,7 @@ if( !function_exists ('iwp_mmb_parse_request')) {
99
}
100
101
if (isset($iwp_action)) {
102
$action = $iwp_action;
103
$_wp_using_ext_object_cache = false;
104
@set_time_limit(600);
@@ -794,6 +798,7 @@ if(!function_exists('checkOpenSSL')){
794
}
795
796
$iwp_mmb_core = new IWP_MMB_Core();
797
798
if(isset($_GET['auto_login']))
799
$iwp_mmb_core->automatic_login();
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.3
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.3');
30
31
32
if ( !defined('IWP_MMB_XFRAME_COOKIE')){
74
}
75
}
76
77
+
78
+
79
+
80
if( !function_exists ('iwp_mmb_parse_request')) {
81
function iwp_mmb_parse_request()
82
{
102
}
103
104
if (isset($iwp_action)) {
105
+ if(!defined('IWP_AUTHORISED_CALL')) define('IWP_AUTHORISED_CALL', 1);
106
$action = $iwp_action;
107
$_wp_using_ext_object_cache = false;
108
@set_time_limit(600);
798
}
799
800
$iwp_mmb_core = new IWP_MMB_Core();
801
+ $mmb_core = 1;
802
803
if(isset($_GET['auto_login']))
804
$iwp_mmb_core->automatic_login();
installer.class.php CHANGED
@@ -111,7 +111,19 @@ class IWP_MMB_Installer extends IWP_MMB_Core
111
112
$wp_themes = null;
113
unset($wp_themes); //prevent theme data caching
114
115
$all_themes = get_themes();
116
foreach ($all_themes as $theme_name => $theme_data) {
117
foreach ($install_info as $key => $install) {
@@ -125,6 +137,7 @@ class IWP_MMB_Installer extends IWP_MMB_Core
125
}
126
}
127
}
128
ob_clean();
129
$this->iwp_mmb_maintenance_mode(false);
130
return $install_info;
@@ -632,7 +645,34 @@ class IWP_MMB_Installer extends IWP_MMB_Core
632
633
function get_upgradable_themes( $filter = array() )
634
{
635
$all_themes = get_themes();
636
$upgrade_themes = array();
637
638
$current = $this->iwp_mmb_get_transient('update_themes');
@@ -656,6 +696,8 @@ class IWP_MMB_Installer extends IWP_MMB_Core
656
}
657
}
658
}
659
660
return $upgrade_themes;
661
}
@@ -744,9 +786,55 @@ class IWP_MMB_Installer extends IWP_MMB_Core
744
745
extract($args);
746
747
- if (!function_exists('get_themes')) {
748
include_once(ABSPATH . WPINC . '/theme.php');
749
}
750
$all_themes = get_themes();
751
$themes = array(
752
'active' => array(),
@@ -792,6 +880,8 @@ class IWP_MMB_Installer extends IWP_MMB_Core
792
}
793
}
794
795
return $themes;
796
}
797
111
112
$wp_themes = null;
113
unset($wp_themes); //prevent theme data caching
114
+ if(function_exists('wp_get_themes')){
115
+ $all_themes = wp_get_themes();
116
+ foreach ($all_themes as $theme_name => $theme_data) {
117
+ foreach ($install_info as $key => $install) {
118
+ if (!$install || is_wp_error($install))
119
+ continue;
120
121
+ if ($theme_data->Template == $install['destination_name']) {
122
+ $install_info[$key]['activated'] = switch_theme($theme_data->Template, $theme_data->Stylesheet);
123
+ }
124
+ }
125
+ }
126
+ }else{
127
$all_themes = get_themes();
128
foreach ($all_themes as $theme_name => $theme_data) {
129
foreach ($install_info as $key => $install) {
137
}
138
}
139
}
140
+ }
141
ob_clean();
142
$this->iwp_mmb_maintenance_mode(false);
143
return $install_info;
645
646
function get_upgradable_themes( $filter = array() )
647
{
648
+ if(function_exists('wp_get_themes')){
649
+ $all_themes = wp_get_themes();
650
+ $upgrade_themes = array();
651
+
652
+ $current = $this->iwp_mmb_get_transient('update_themes');
653
+ if (!empty($current->response)) {
654
+ foreach ((array) $all_themes as $theme_template => $theme_data) {
655
+ if(isset($theme_data->{'Parent Theme'}) && !empty($theme_data->{'Parent Theme'}))
656
+ continue;
657
+
658
+ if(isset($theme_data->Name) && in_array($theme_data->Name, $filter))
659
+ continue;
660
+
661
+ foreach ($current->response as $current_themes => $theme) {
662
+ if ($theme_data->Template == $current_themes) {
663
+ if (strlen($theme_data->Name) > 0 && strlen($theme_data->Version) > 0) {
664
+ $current->response[$current_themes]['name'] = $theme_data->Name;
665
+ $current->response[$current_themes]['old_version'] = $theme_data->Version;
666
+ $current->response[$current_themes]['theme_tmp'] = $theme_data->Template;
667
+ $upgrade_themes[] = $current->response[$current_themes];
668
+ }
669
+ }
670
+ }
671
+ }
672
+ }
673
+ }else{
674
$all_themes = get_themes();
675
+
676
$upgrade_themes = array();
677
678
$current = $this->iwp_mmb_get_transient('update_themes');
696
}
697
}
698
}
699
+ }
700
+
701
702
return $upgrade_themes;
703
}
786
787
extract($args);
788
789
+ if (!function_exists('wp_get_themes')) {
790
include_once(ABSPATH . WPINC . '/theme.php');
791
}
792
+ if(function_exists('wp_get_themes')){
793
+ $all_themes = wp_get_themes();
794
+ $themes = array(
795
+ 'active' => array(),
796
+ 'inactive' => array()
797
+ );
798
+
799
+ if (is_array($all_themes) && !empty($all_themes)) {
800
+ $current_theme = get_current_theme();
801
+
802
+ $br_a = 0;
803
+ $br_i = 0;
804
+ foreach ($all_themes as $theme_name => $theme) {
805
+ if ($current_theme == strip_tags($theme->Name)) {
806
+ $themes['active'][$br_a]['path'] = $theme->Template;
807
+ $themes['active'][$br_a]['name'] = strip_tags($theme->Name);
808
+ $themes['active'][$br_a]['version'] = $theme->Version;
809
+ $themes['active'][$br_a]['stylesheet'] = $theme->Stylesheet;
810
+ $br_a++;
811
+ }
812
+
813
+ if ($current_theme != strip_tags($theme->Name)) {
814
+ $themes['inactive'][$br_i]['path'] = $theme->Template;
815
+ $themes['inactive'][$br_i]['name'] = strip_tags($theme->Name);
816
+ $themes['inactive'][$br_i]['version'] = $theme->Version;
817
+ $themes['inactive'][$br_i]['stylesheet'] = $theme->Stylesheet;
818
+ $br_i++;
819
+ }
820
+
821
+ }
822
+
823
+ if ($search) {
824
+ foreach ($themes['active'] as $k => $theme) {
825
+ if (!stristr($theme['name'], $search)) {
826
+ unset($themes['active'][$k]);
827
+ }
828
+ }
829
+
830
+ foreach ($themes['inactive'] as $k => $theme) {
831
+ if (!stristr($theme['name'], $search)) {
832
+ unset($themes['inactive'][$k]);
833
+ }
834
+ }
835
+ }
836
+ }
837
+ }else{
838
$all_themes = get_themes();
839
$themes = array(
840
'active' => array(),
880
}
881
}
882
883
+ }
884
+
885
return $themes;
886
}
887
lib/amazon_s3/extensions/dynamodbsessionhandler.class.php ADDED
@@ -0,0 +1,513 @@
1
+ <?php
2
+ /*
3
+ * Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License").
6
+ * You may not use this file except in compliance with the License.
7
+ * A copy of the License is located at
8
+ *
9
+ * http://aws.amazon.com/apache2.0
10
+ *
11
+ * or in the "license" file accompanying this file. This file is distributed
12
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
+ * express or implied. See the License for the specific language governing
14
+ * permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ /**
19
+ * Provides an interface for using Amazon DynamoDB as a session store by hooking into
20
+ * PHP's session handler hooks. This class is not auto-loaded, and must be included
21
+ * manually or via the <code>AmazonDynamoDB::register_session_hander()</code> method.
22
+ *
23
+ * Once registered, You may use the native <code>$_SESSION</code> superglobal and
24
+ * session functions, and the sessions will be stored automatically in DynamoDB.
25
+ */
26
+ class DynamoDBSessionHandler
27
+ {
28
+ /**
29
+ * @var AmazonDynamoDB The DyanamoDB client.
30
+ */
31
+ protected $_dynamodb = null;
32
+
33
+ /**
34
+ * @var string The session save path (see <php:session_save_path()>).
35
+ */
36
+ protected $_save_path = null;
37
+
38
+ /**
39
+ * @var string The session name (see <php:session_name()>).
40
+ */
41
+ protected $_session_name = null;
42
+
43
+ /**
44
+ * @var boolean Keeps track of if the session is open.
45
+ */
46
+ protected $_open_session = null;
47
+
48
+ /**
49
+ * @var boolean Keeps track of whether the session is open.
50
+ */
51
+ protected $_session_written = false;
52
+
53
+ /**
54
+ * @var string The name of the DynamoDB table in which to store sessions.
55
+ */
56
+ protected $_table_name = 'sessions';
57
+
58
+ /**
59
+ * @var string The name of the hash key in the DynamoDB sessions table.
60
+ */
61
+ protected $_hash_key = 'id';
62
+
63
+ /**
64
+ * @var integer The lifetime of an inactive session before it should be garbage collected.
65
+ */
66
+ protected $_session_lifetime = 0;
67
+
68
+ /**
69
+ * @var boolean Whether or not the session handler should do consistent reads from DynamoDB.
70
+ */
71
+ protected $_consistent_reads = true;
72
+
73
+ /**
74
+ * @var boolean Whether or not the session handler should do session locking.
75
+ */
76
+ protected $_session_locking = true;
77
+
78
+ /**
79
+ * @var integer Maximum time, in seconds, that the session handler should take to acquire a lock.
80
+ */
81
+ protected $_max_lock_wait_time = 30;
82
+
83
+ /**
84
+ * @var integer Minimum time, in microseconds, that the session handler should wait to retry acquiring a lock.
85
+ */
86
+ protected $_min_lock_retry_utime = 10000;
87
+
88
+ /**
89
+ * @var integer Maximum time, in microseconds, that the session handler should wait to retry acquiring a lock.
90
+ */
91
+ protected $_max_lock_retry_utime = 100000;
92
+
93
+ /**
94
+ * @var array Type for casting the configuration options.
95
+ */
96
+ protected static $_option_types = array(
97
+ 'table_name' => 'string',
98
+ 'hash_key' => 'string',
99
+ 'session_lifetime' => 'integer',
100
+ 'consistent_reads' => 'boolean',
101
+ 'session_locking' => 'boolean',
102
+ 'max_lock_wait_time' => 'integer',
103
+ 'min_lock_retry_utime' => 'integer',
104
+ 'max_lock_retry_utime' => 'integer',
105
+ );
106
+
107
+ /**
108
+ * Initializes the session handler and prepares the configuration options.
109
+ *
110
+ * @param AmazonDynamoDB $dynamodb (Required) An instance of the DynamoDB client.
111
+ * @param array $options (Optional) Configuration options.
112
+ */
113
+ public function __construct(AmazonDynamoDB $dynamodb, array $options = array())
114
+ {
115
+ // Store the AmazonDynamoDB client for use in the session handler
116
+ $this->_dynamodb = $dynamodb;
117
+
118
+ // Do type conversions on options and store the values
119
+ foreach ($options as $key => $value)
120
+ {
121
+ if (isset(self::$_option_types[$key]))
122
+ {
123
+ settype($value, self::$_option_types[$key]);
124
+ $this->{'_' . $key} = $value;
125
+ }
126
+ }
127
+
128
+ // Make sure the lifetime is positive. Use the gc_maxlifetime otherwise
129
+ if ($this->_session_lifetime <= 0)
130
+ {
131
+ $this->_session_lifetime = (integer) ini_get('session.gc_maxlifetime');
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Destruct the session handler and make sure the session gets written.
137
+ *
138
+ * NOTE: It is usually better practice to call <code>session_write_close()</code>
139
+ * manually in your application as soon as session modifications are complete. This
140
+ * is especially true if session locking is enabled (which it is by default).
141
+ *
142
+ * @see http://php.net/manual/en/function.session-set-save-handler.php#refsect1-function.session-set-save-handler-notes
143
+ */
144
+ public function __destruct()
145
+ {
146
+ session_write_close();
147
+ }
148
+
149
+ /**
150
+ * Register DynamoDB as a session handler.
151
+ *
152
+ * Uses the PHP-provided method to register this class as a session handler.
153
+ *
154
+ * @return DynamoDBSessionHandler Chainable.
155
+ */
156
+ public function register()
157
+ {
158
+ session_set_save_handler(
159
+ array($this, 'open'),
160
+ array($this, 'close'),
161
+ array($this, 'read'),
162
+ array($this, 'write'),
163
+ array($this, 'destroy'),
164
+ array($this, 'garbage_collect')
165
+ );
166
+
167
+ return $this;
168
+ }
169
+
170
+ /**
171
+ * Checks if the session is open and writable.
172
+ *
173
+ * @return boolean Whether or not the session is still open for writing.
174
+ */
175
+ public function is_session_open()
176
+ {
177
+ return (boolean) $this->_open_session;
178
+ }
179
+
180
+ /**
181
+ * Delegates to <code>session_start()</code>
182
+ *
183
+ * @return DynamoDBSessionHandler Chainable.
184
+ */
185
+ public function open_session()
186
+ {
187
+ session_start();
188
+
189
+ return $this;
190
+ }
191
+
192
+ /**
193
+ * Delegates to <code>session_commit()</code>
194
+ *
195
+ * @return DynamoDBSessionHandler Chainable.
196
+ */
197
+ public function close_session()
198
+ {
199
+ session_commit();
200
+
201
+ return $this;
202
+ }
203
+
204
+ /**
205
+ * Delegates to <code>session_destroy()</code>
206
+ *
207
+ * @return DynamoDBSessionHandler Chainable.
208
+ */
209
+ public function destroy_session()
210
+ {
211
+ session_destroy();
212
+
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * Open a session for writing. Triggered by <php:session_start()>.
218
+ *
219
+ * Part of the standard PHP session handler interface.
220
+ *
221
+ * @param string $save_path (Required) The session save path (see <php:session_save_path()>).
222
+ * @param string $session_name (Required) The session name (see <php:session_name()>).
223
+ * @return boolean Whether or not the operation succeeded.
224
+ */
225
+ public function open($save_path, $session_name)
226
+ {
227
+ $this->_save_path = $save_path;
228
+ $this->_session_name = $session_name;
229
+ $this->_open_session = session_id();
230
+
231
+ return true;
232
+ }
233
+
234
+ /**
235
+ * Close a session from writing
236
+ *
237
+ * Part of the standard PHP session handler interface
238
+ *
239
+ * @return boolean Success
240
+ */
241
+ public function close()
242
+ {
243
+ if (!$this->_session_written)
244
+ {
245
+ // Ensure that the session is unlocked even if the write did not happen
246
+ $id = $this->_open_session;
247
+ $response = $this->_dynamodb->update_item(array(
248
+ 'TableName' => $this->_table_name,
249
+ 'Key' => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
250
+ 'AttributeUpdates' => array(
251
+ 'expires' => $this->_dynamodb->attribute(time() + $this->_session_lifetime, 'update'),
252
+ 'lock' => array('Action' => AmazonDynamoDB::ACTION_DELETE)
253
+ ),
254
+ ));
255
+
256
+ $this->_session_written = $response->isOK();
257
+ }
258
+
259
+ $this->_open_session = null;
260
+
261
+ return $this->_session_written;
262
+ }
263
+
264
+ /**
265
+ * Read a session stored in DynamoDB
266
+ *
267
+ * Part of the standard PHP session handler interface
268
+ *
269
+ * @param string $id (Required) The session ID.
270
+ * @return string The session data.
271
+ */
272
+ public function read($id)
273
+ {
274
+ $result = '';
275
+
276
+ // Get the session data from DynamoDB (acquire a lock if locking is enabled)
277
+ if ($this->_session_locking)
278
+ {
279
+ $response = $this->_lock_and_read($id);
280
+ $node_name = 'Attributes';
281
+ }
282
+ else
283
+ {
284
+ $response = $this->_dynamodb->get_item(array(
285
+ 'TableName' => $this->_table_name,
286
+ 'Key' => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
287
+ 'ConsistentRead' => $this->_consistent_reads,
288
+ ));
289
+ $node_name = 'Item';
290
+ }
291
+
292
+ if ($response->isOK())
293
+ {
294
+ $item = array();
295
+
296
+ // Get the data from the DynamoDB response
297
+ if ($response->body->{$node_name})
298
+ {
299
+ foreach ($response->body->{$node_name}->children() as $key => $value)
300
+ {
301
+ $item[$key] = (string) current($value);
302
+ }
303
+ }
304
+
305
+ if (isset($item['expires']) && isset($item['data']))
306
+ {
307
+ // Check the expiration date before using
308
+ if ($item['expires'] > time())
309
+ {
310
+ $result = $item['data'];
311
+ }
312
+ else
313
+ {
314
+ $this->destroy($id);
315
+ }
316
+ }
317
+ }
318
+
319
+ return $result;
320
+ }
321
+
322
+ /**
323
+ * Write a session to DynamoDB.
324
+ *
325
+ * Part of the standard PHP session handler interface.
326
+ *
327
+ * @param string $id (Required) The session ID.
328
+ * @param string $data (Required) The session data.
329
+ * @return boolean Whether or not the operation succeeded.
330
+ */
331
+ public function write($id, $data)
332
+ {
333
+ // Write the session data to DynamoDB
334
+ $response = $this->_dynamodb->put_item(array(
335
+ 'TableName' => $this->_table_name,
336
+ 'Item' => $this->_dynamodb->attributes(array(
337
+ $this->_hash_key => $this->_id($id),
338
+ 'expires' => time() + $this->_session_lifetime,
339
+ 'data' => $data,
340
+ )),
341
+ ));
342
+
343
+ $this->_session_written = $response->isOK();
344
+
345
+ return $this->_session_written;
346
+ }
347
+
348
+ /**
349
+ * Delete a session stored in DynamoDB.
350
+ *
351
+ * Part of the standard PHP session handler interface.
352
+ *
353
+ * @param string $id (Required) The session ID.
354
+ * @param boolean $garbage_collect_mode (Optional) Whether or not the handler is doing garbage collection.
355
+ * @return boolean Whether or not the operation succeeded.
356
+ */
357
+ public function destroy($id, $garbage_collect_mode = false)
358
+ {
359
+ // Make sure we don't prefix the ID a second time
360
+ if (!$garbage_collect_mode)
361
+ {
362
+ $id = $this->_id($id);
363
+ }
364
+
365
+ $delete_options = array(
366
+ 'TableName' => $this->_table_name,
367
+ 'Key' => array('HashKeyElement' => $this->_dynamodb->attribute($id)),
368
+ );
369
+
370
+ // Make sure not to garbage collect locked sessions
371
+ if ($garbage_collect_mode && $this->_session_locking)
372
+ {
373
+ $delete_options['Expected'] = array('lock' => array('Exists' => false));
374
+ }
375
+
376
+ // Send the delete request to DynamoDB
377
+ $response = $this->_dynamodb->delete_item($delete_options);
378
+
379
+ $this->_session_written = $response->isOK();
380
+
381
+ return $this->_session_written;
382
+ }
383
+
384
+ /**
385
+ * Performs garbage collection on the sessions stored in the DynamoDB table.
386
+ *
387
+ * Part of the standard PHP session handler interface.
388
+ *
389
+ * @param integer $maxlifetime (Required) The value of <code>session.gc_maxlifetime</code>. Ignored.
390
+ * @return boolean Whether or not the operation succeeded.
391
+ */
392
+ public function garbage_collect($maxlifetime = null)
393
+ {
394
+ // Send a search request to DynamoDB looking for expired sessions
395
+ $response = $this->_dynamodb->scan(array(
396
+ 'TableName' => $this->_table_name,
397
+ 'ScanFilter' => array('expires' => array(
398
+ 'AttributeValueList' => array($this->_dynamodb->attribute(time())),
399
+ 'ComparisonOperator' => AmazonDynamoDB::CONDITION_LESS_THAN,
400
+ )),
401
+ ));
402
+
403
+ // Delete the expired sessions
404
+ if ($response->isOK())
405
+ {
406
+ $deleted = array();
407
+
408
+ // Get the ID of and delete each session that is expired
409
+ foreach ($response->body->Items as $item)
410
+ {
411
+ $id = (string) $item->{$this->_hash_key}->{AmazonDynamoDB::TYPE_STRING};
412
+ $deleted[$id] = $this->destroy($id, true);
413
+ }
414
+
415
+ // Return true if all of the expired sessions were deleted
416
+ return (array_sum($deleted) === count($deleted));
417
+ }
418
+
419
+ return false;
420
+ }
421
+
422
+ /**
423
+ * Creates a table in DynamoDB for session storage according to provided configuration options.
424
+ *
425
+ * Note: Table creation may also be done via the AWS Console, which might make the most sense for this use case.
426
+ *
427
+ * @param integer $read_capacity_units (Required) Read capacity units for table throughput.
428
+ * @param integer $write_capacity_units (Required) Write capacity units for table throughput.
429
+ * @return boolean Returns <code>true</code> on success.
430
+ */
431
+ public function create_sessions_table($read_capacity_units = 10, $write_capacity_units = 5)
432
+ {
433
+ $response = $this->_dynamodb->create_table(array(
434
+ 'TableName' => $this->_table_name,
435
+ 'KeySchema' => array(
436
+ 'HashKeyElement' => array(
437
+ 'AttributeName' => $this->_hash_key,
438
+ 'AttributeType' => AmazonDynamoDB::TYPE_STRING,
439
+ )
440
+ ),
441
+ 'ProvisionedThroughput' => array(
442
+ 'ReadCapacityUnits' => $read_capacity_units,
443
+ 'WriteCapacityUnits' => $write_capacity_units,
444
+ )
445
+ ));
446
+
447
+ return $response->isOK();
448
+ }
449
+
450
+ /**
451
+ * Deletes the session storage table from DynamoDB.
452
+ *
453
+ * Note: Table deletion may also be done via the AWS Console, which might make the most sense for this use case.
454
+ *
455
+ * @return boolean Returns <code>true</code> on success.
456
+ */
457
+ public function delete_sessions_table()
458
+ {
459
+ $response = $this->_dynamodb->delete_table(array('TableName' => $this->_table_name));
460
+
461
+ return $response->isOK();
462
+ }
463
+
464
+ /**
465
+ * Prefix the session ID with the session name and prepare for DynamoDB usage
466
+ *
467
+ * @param string $id (Required) The session ID.
468
+ * @return array The HashKeyElement value formatted as an array.
469
+ */
470
+ protected function _id($id)
471
+ {
472
+ return trim($this->_session_name . '_' . $id, '_');
473
+ }
474
+
475
+ /**
476
+ * Acquires a lock on a session in DynamoDB using conditional updates.
477
+ *
478
+ * WARNING: There is a <code>while(true);</code> in here.
479
+ *
480
+ * @param string $id (Required) The session ID.
481
+ * @return CFResponse The response from DynamoDB.
482
+ */
483
+ protected function _lock_and_read($id)
484
+ {
485
+ $now = time();
486
+ $timeout = $now + $this->_max_lock_wait_time;
487
+
488
+ do
489
+ {
490
+ // Acquire the lock
491
+ $response = $this->_dynamodb->update_item(array(
492
+ 'TableName' => $this->_table_name,
493
+ 'Key' => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
494
+ 'AttributeUpdates' => array('lock' => $this->_dynamodb->attribute(1, 'update')),
495
+ 'Expected' => array('lock' => array('Exists' => false)),
496
+ 'ReturnValues' => 'ALL_NEW',
497
+ ));
498
+
499
+ // If lock succeeds (or times out), exit the loop, otherwise sleep and try again
500
+ if ($response->isOK() || $now >= $timeout)
501
+ {
502
+ return $response;
503
+ }
504
+ else
505
+ {
506
+ usleep(rand($this->_min_lock_retry_utime, $this->_max_lock_retry_utime));
507
+
508
+ $now = time();
509
+ }
510
+ }
511
+ while(true);
512
+ }
513
+ }
lib/amazon_s3/extensions/s3browserupload.class.php ADDED
@@ -0,0 +1,172 @@
1
+ <?php
2
+ /*
3
+ * Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License").
6
+ * You may not use this file except in compliance with the License.
7
+ * A copy of the License is located at
8
+ *
9
+ * http://aws.amazon.com/apache2.0
10
+ *
11
+ * or in the "license" file accompanying this file. This file is distributed
12
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
+ * express or implied. See the License for the specific language governing
14
+ * permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ class S3BrowserUpload extends AmazonS3
19
+ {
20
+ /**
21
+ * The <code>POST</code> operation adds an object to a specified bucket using HTML forms. POST is an alternate
22
+ * form of <code>PUT</code> that enables browser-based uploads as a way of putting objects in buckets.
23
+ * Parameters that are passed to <code>PUT</code> via HTTP headers are instead passed as form fields to
24
+ * <code>POST</code> in the <code>multipart/form-data</code> encoded message body. You must have
25
+ * <code>WRITE</code> access on a bucket to add an object to it. Amazon S3 never stores partial objects: if
26
+ * you receive a successful response, you can be confident the entire object was stored.
27
+ *
28
+ * @param string $bucket (Required) The name of the bucket to use.
29
+ * @param string|integer $expires (Optional) The point in time when the upload form field should expire. The default value is <code>+1 hour</code>.
30
+ * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
31
+ * <li><code>acl</code> - <code>string</code> - Optional - The access control setting to apply to the uploaded file. Accepts any of the following constants: [Allowed values: <code>AmazonS3::ACL_PRIVATE</code>, <code>AmazonS3::ACL_PUBLIC</code>, <code>AmazonS3::ACL_OPEN</code>, <code>AmazonS3::ACL_AUTH_READ</code>, <code>AmazonS3::ACL_OWNER_READ</code>, <code>AmazonS3::ACL_OWNER_FULL_CONTROL</code>].</li>
32
+ * <li><code>Cache-Control</code> - <code>string</code> - Optional - The Cache-Control HTTP header value to apply to the uploaded file. To use a <code>starts-with</code> comparison instead of an <code>equals</code> comparison, prefix the value with a <code>^</code> (carat) character.</li>
33
+ * <li><code>Content-Disposition</code> - <code>string</code> - Optional - The Content-Disposition HTTP header value to apply to the uploaded file. To use a <code>starts-with</code> comparison instead of an <code>equals</code> comparison, prefix the value with a <code>^</code> (carat) character.</li>
34
+ * <li><code>Content-Encoding</code> - <code>string</code> - Optional - The Content-Encoding HTTP header value to apply to the uploaded file. To use a <code>starts-with</code> comparison instead of an <code>equals</code> comparison, prefix the value with a <code>^</code> (carat) character.</li>
35
+ * <li><code>Content-Type</code> - <code>string</code> - Optional - The Content-Type HTTP header value to apply to the uploaded file. The default value is <code>application/octet-stream</code>. To use a <code>starts-with</code> comparison instead of an <code>equals</code> comparison, prefix the value with a <code>^</code> (carat) character.</li>
36
+ * <li><code>Expires</code> - <code>string</code> - Optional - The Expires HTTP header value to apply to the uploaded file. To use a <code>starts-with</code> comparison instead of an <code>equals</code> comparison, prefix the value with a <code>^</code> (carat) character.</li>
37
+ * <li><code>key</code> - <code>string</code> - Optional - The location where the file should be uploaded to. The default value is <code>${filename}</code>.</li>
38
+ * <li><code>success_action_redirect</code> - <code>string</code> - Optional - The URI for Amazon S3 to redirect to upon successful upload.</li>
39
+ * <li><code>success_action_status</code> - <code>integer</code> - Optional - The status code for Amazon S3 to return upon successful upload.</li>
40
+ * <li><code>x-amz-server-side-encryption</code> - <code>string</code> - Optional - The server-side encryption mechanism to use. [Allowed values: <code>AES256</code>].</li>
41
+ * <li><code>x-amz-storage-class</code> - <code>string</code> - Optional - The storage setting to apply to the object. [Allowed values: <code>AmazonS3::STORAGE_STANDARD</code>, <code>AmazonS3::STORAGE_REDUCED</code>]. The default value is <code>AmazonS3::STORAGE_STANDARD</code>.</li>
42
+ * <li><code>x-amz-meta-*</code> - <code>mixed</code> - Optional - Any custom meta tag that should be set to the object.</li>
43
+ * </ul>
44
+ * @return array An array of fields that can be converted into markup.
45
+ * @link http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPOST.html POST Object
46
+ */
47
+ public function generate_upload_parameters($bucket, $expires = '+1 hour', $opt = null)
48
+ {
49
+ if (!$opt) $opt = array();
50
+
51
+ // Policy document
52
+ $policy = array(
53
+ 'conditions' => array(
54
+ array('bucket' => $bucket),
55
+ )
56
+ );
57
+
58
+ // Basic form
59
+ $form = array();
60
+ $form['form'] = array(
61
+ 'action' => $bucket . '.s3.amazonaws.com',
62
+ 'method' => 'POST',
63
+ 'enctype' => 'multipart/form-data'
64
+ );
65
+
66
+ // Inputs
67
+ $form['inputs'] = array(
68
+ 'AWSAccessKeyId' => $this->key
69
+ );
70
+
71
+ // Expires
72
+ if ($expires)
73
+ {
74
+ if (is_numeric($expires))
75
+ {
76
+ $expires = gmdate('j M Y, g:i a Z', (integer) $expires);
77
+ }
78
+
79
+ $expires = $this->util->convert_date_to_iso8601($expires);
80
+ $policy['expiration'] = (string) $expires;
81
+ }
82
+
83
+ // Default values
84
+ if (!isset($opt['key']))
85
+ {
86
+ $opt['key'] = '${filename}';
87
+ }
88
+
89
+ // Success Action Status
90
+ if (isset($opt['success_action_status']) && !empty($opt['success_action_status']))
91
+ {
92
+ $form['inputs']['success_action_status'] = (string) $opt['success_action_status'];
93
+ $policy['conditions'][] = array(
94
+ 'success_action_status' => (string) $opt['success_action_status']
95
+ );
96
+ unset($opt['success_action_status']);
97
+ }
98
+
99
+ // Other parameters
100
+ foreach ($opt as $param_key => $param_value)
101
+ {
102
+ if ($param_value[0] === '^')
103
+ {
104
+ $form['inputs'][$param_key] = substr((string) $param_value, 1);
105
+ $param_value = preg_replace('/\$\{(\w*)\}/', '', (string) $param_value);
106
+ $policy['conditions'][] = array('starts-with', '#x27; . $param_key, (substr((string) $param_value, 1) ? substr((string) $param_value, 1) : ''));
107
+ }
108
+ else
109
+ {
110
+ $form['inputs'][$param_key] = (string) $param_value;
111
+ $policy['conditions'][] = array(
112
+ $param_key => (string) $param_value
113
+ );
114
+ }
115
+ }
116
+
117
+ // Add policy
118
+ $json_policy = json_encode($policy);
119
+ $json_policy_b64 = base64_encode($json_policy);
120
+ $form['inputs']['policy'] = $json_policy_b64;
121
+ $form['metadata']['json_policy'] = $json_policy;
122
+
123
+ // Add signature
124
+ $form['inputs']['signature'] = base64_encode(hash_hmac('sha1', $json_policy_b64, $this->secret_key, true));
125
+
126
+ return $form;
127
+ }
128
+
129
+
130
+ /*%******************************************************************************************%*/
131
+ // HELPERS
132
+
133
+ /**
134
+ * Returns the protocol of the web page that this script is currently running on. This method only works
135
+ * correctly when run from a publicly-accessible web page.
136
+ */
137
+ public static function protocol()
138
+ {
139
+ return (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') ? 'https://' : 'http://';
140
+ }
141
+
142
+ /**
143
+ * Returns the domain (and port) of the web page that this script is currently running on. This method
144
+ * only works correctly when run from a publicly-accessible web page.
145
+ */
146
+ public static function domain()
147
+ {
148
+ if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT']))
149
+ {
150
+ return $_SERVER['SERVER_NAME'] . ((integer) $_SERVER['SERVER_PORT'] === 80 ? '' : ':' . $_SERVER['SERVER_PORT']);
151
+ }
152
+
153
+ return null;
154
+ }
155
+
156
+ /**
157
+ * Returns the URI of the web page that this script is currently running on. This method only works
158
+ * correctly when run from a publicly-accessible web page.
159
+ */
160
+ public static function current_uri()
161
+ {
162
+ if (isset($_SERVER['REQUEST_URI']))
163
+ {
164
+ $uri = self::protocol();
165
+ $uri .= self::domain();
166
+ $uri .= $_SERVER['REQUEST_URI'];
167
+ return $uri;
168
+ }
169
+
170
+ return null;
171
+ }
172
+ }
lib/amazon_s3/extensions/s3streamwrapper.class.php ADDED
@@ -0,0 +1,606 @@