Backup & Restore Dropbox - Version 1.4.7

Version Description

Please, keep your Dropbox Backup and Restore plugin up-to-date.

Download this release

Release Info

Developer backup-dropbox
Plugin Icon 128x128 Backup & Restore Dropbox
Version 1.4.7
Comparing to
See all releases

Code changes from version 1.4.6.2 to 1.4.7

commands/class-wpadm-command-archive.php CHANGED
@@ -4,41 +4,72 @@
4
  class WPadm_Command_Archive extends WPAdm_Сommand{
5
  public function execute(WPAdm_Command_Context $context)
6
  {
7
- ini_set("memory_limit", "256M");
8
- require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
9
- $af = $this->getArchiveName($context->get('to_file'));
10
- ini_set("memory_limit", "256M");
11
- $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
12
- $archive->setRemovePath($context->get('remove_path'));
13
- $files = $context->get('files');
14
- if ( !file_exists( $af ) ) {
15
- WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
16
- }
17
- if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
18
- $af = $this->getNextArchiveName($context->get('to_file'));
19
- unset($archive);
20
  if ( !file_exists( $af ) ) {
21
  WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
22
  }
23
- $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
24
- $archive->setRemovePath($context->get('remove_path'));
25
- }
26
- $files_str = implode(',', $files);
27
- $files_archive = WPAdm_Running::getCommandResultData('archive');
28
- if (!in_array($files_str, $files_archive)) {
29
- $archive->add($files_str);
30
- $files_archive = WPAdm_Running::getCommandResultData('archive');
31
- $files_archive[] = $files_str;
32
- if (!empty($files_archive)) {
33
- WPAdm_Running::setCommandResultData('archive', $files_archive);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
  }
36
  return true;
 
37
  }
38
 
39
  private function getArchiveName($name)
40
  {
 
41
  $archives = glob("{$name}-*.zip");
 
42
  if (empty($archives)) {
43
  return "{$name}-1.zip";
44
  }
@@ -49,9 +80,11 @@ class WPadm_Command_Archive extends WPAdm_Сommand{
49
 
50
  private function getNextArchiveName($name)
51
  {
 
52
  $archives = glob("{$name}-*.zip");
53
- $n = 1 + count($archives);
54
  $a = "{$name}-{$n}.zip";
 
55
  return $a;
56
  }
57
  }
4
  class WPadm_Command_Archive extends WPAdm_Сommand{
5
  public function execute(WPAdm_Command_Context $context)
6
  {
7
+ if ( WPAdm_Running::is_stop() ) {
8
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
9
+ $af = $this->getArchiveName($context->get('to_file'));
10
+ ini_set("memory_limit", "256M");
11
+ if ( WPAdm_Running::is_stop() ) {
12
+ $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
13
+ $archive->setRemovePath($context->get('remove_path'));
14
+ $files = $context->get('files');
15
+ } else {
16
+ return true;
17
+ }
 
 
18
  if ( !file_exists( $af ) ) {
19
  WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
20
  }
21
+ if (file_exists($af) && filesize($af) > $context->get('max_file_size')) {
22
+ if ( WPAdm_Running::is_stop() ) {
23
+ $af = $this->getNextArchiveName($context->get('to_file'));
24
+ unset($archive);
25
+ if ( !file_exists( $af ) ) {
26
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
27
+ }
28
+ $archive = new WPAdm_Archive($af, $context->get('to_file') . '.md5');
29
+ $archive->setRemovePath($context->get('remove_path'));
30
+ } else {
31
+ return true;
32
+ }
33
+ }
34
+ if ( WPAdm_Running::is_stop() ) {
35
+ $md5 = md5( print_r( $files, 1 ) );
36
+ $files_str = implode(',', $files);
37
+ $files_archive = WPAdm_Running::getCommandResultData('archive');
38
+ if ( WPAdm_Running::is_stop() ) {
39
+ if (!in_array($md5, $files_archive)) {
40
+ if ( WPAdm_Running::is_stop() ) {
41
+ $res = $archive->add($files_str);
42
+ if ($res) {
43
+ $files_archive = WPAdm_Running::getCommandResultData('archive');
44
+ $files_archive[] = $md5;
45
+ if (!empty($files_archive)) {
46
+ WPAdm_Running::setCommandResultData('archive', $files_archive);
47
+ WPAdm_Process::setInc( 'archiving', count($files) );
48
+ }
49
+ } else {
50
+ $context->setError( $archive->error );
51
+ return false;
52
+ }
53
+ } else {
54
+ return true;
55
+ }
56
+ }
57
+ } else {
58
+ return true;
59
+ }
60
+ } else {
61
+ return true;
62
  }
63
  }
64
  return true;
65
+
66
  }
67
 
68
  private function getArchiveName($name)
69
  {
70
+ //WPAdm_Core::log("{$name}-*.zip");
71
  $archives = glob("{$name}-*.zip");
72
+ //WPAdm_Core::log( print_r($archives, 1) );
73
  if (empty($archives)) {
74
  return "{$name}-1.zip";
75
  }
80
 
81
  private function getNextArchiveName($name)
82
  {
83
+ //WPAdm_Core::log("{$name}-*.zip");
84
  $archives = glob("{$name}-*.zip");
85
+ $n = 1 + count($archives);
86
  $a = "{$name}-{$n}.zip";
87
+ //WPAdm_Core::log($a);
88
  return $a;
89
  }
90
  }
commands/class-wpadm-command-mysqldump.php CHANGED
@@ -1,22 +1,24 @@
1
- <?php
2
- if (!class_exists('WPadm_Command_Mysqldump')) {
3
- class WPadm_Command_Mysqldump extends WPAdm_Сommand{
4
- public function execute(WPAdm_Command_Context $context)
5
- {
6
- //WPAdm_Core::log(print_r($context, true));
7
- require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
8
- $mysqldump = new WPAdm_Mysqldump();
9
- $mysqldump->host = $context->get('host');
10
- $mysqldump->user = $context->get('user');
11
- $mysqldump->password = $context->get('password');
12
-
13
- try {
14
- $mysqldump->mysqldump($context->get('db'), $context->get('to_file'));
15
- } catch (Exception $e) {
16
- $context->setError($e->getMessage());
17
- return false;
18
- }
19
- return true;
20
- }
21
- }
 
 
22
  }
1
+ <?php
2
+ if (!class_exists('WPadm_Command_Mysqldump')) {
3
+ class WPadm_Command_Mysqldump extends WPAdm_Сommand{
4
+ public function execute(WPAdm_Command_Context $context)
5
+ {
6
+ if ( WPAdm_Running::is_stop() ) {
7
+ //WPAdm_Core::log(print_r($context, true));
8
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
9
+ $mysqldump = new WPAdm_Mysqldump();
10
+ $mysqldump->host = $context->get('host');
11
+ $mysqldump->user = $context->get('user');
12
+ $mysqldump->password = $context->get('password');
13
+
14
+ try {
15
+ $mysqldump->mysqldump($context->get('db'), $context->get('to_file'));
16
+ } catch (Exception $e) {
17
+ $context->setError($e->getMessage());
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ }
23
+ }
24
  }
commands/class-wpadm-command-send-to-dropbox.php CHANGED
@@ -6,72 +6,88 @@ if (!class_exists('WPadm_Command_Send_To_Dropbox')) {
6
  public function execute(WPAdm_Command_Context $context)
7
  {
8
  @session_start();
9
- require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
 
10
 
11
- WPAdm_Core::log(__('Send to dropbox files' ,'dropbox-backup') );
12
- $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
13
 
14
- if (!$dropbox->isAuth()) {
15
- $context->setError( str_replace(array('%d', '%k', '%s'),
16
- array( SITE_HOME, $context->get('key'), $context->get('secret') ),__('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"' ,'dropbox-backup') ) );
17
- return false;
18
- }
19
- $files = $context->get('files');
20
- $file = explode("/", $files);
21
- $file_name = array_pop($file);
22
- $folder_project_temp = $context->get('folder_project');
23
- $folder_project = "";
24
- if (!empty($folder_project_temp)) {
25
- $folder_project = $folder_project_temp . "/";
26
- $dropbox->createDir($folder_project_temp );
27
- $dropbox->createDir($folder_project . $context->get('folder') );
28
- } else {
29
- $dropbox->createDir($context->get('folder') );
30
- }
31
-
32
- $fromFile = str_replace('//', '/', $files);
33
- $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
34
- $local = $context->get('local');
35
- $file_dropbox = $dropbox->listing($folder_project . $context->get('folder') . '/' . $file_name);
36
- $send = true;
37
- if ( !isset($file_dropbox['error']) ) {
38
- if ($file_dropbox['bytes'] != filesize($fromFile)) {
39
- $delete_file = $dropbox->deleteFile($folder_project . $context->get('folder') . '/' . $file_name);
40
- if (isset($delete_file['error'])) {
41
- $context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
42
- return false;
43
- }
44
- $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
45
- if (isset($data_command[$fromFile])) {
46
- $data_error_command[$fromFile]['count'] += 1;
47
  } else {
48
- $data_error_command[$fromFile] = array();
49
- $data_error_command[$fromFile]['count'] = 1;
50
  }
51
- WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
52
  } else {
53
- $send = false;
54
  }
55
- }
56
- if ( $local ) {
57
- $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
58
- if (empty($data_command) || !in_array($fromFile ,$data_command) ) {
59
- if ($send) {
60
- $res = $dropbox->uploadFile($fromFile, $toFile, true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  } else {
62
- $this->saveDataCommand($fromFile);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
  }
65
- } else {
66
- $res = $dropbox->uploadFile($fromFile, $toFile, true);
67
- }
68
- if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
69
- $context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
70
- return false;
71
- }
72
- if (isset($res['size']) && isset($res['client_mtime'])) {
73
- WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $files ) . __(' size: ' ,'dropbox-backup') . $res['size']);
74
- $this->saveDataCommand($fromFile);
75
  }
76
  return true;
77
  }
6
  public function execute(WPAdm_Command_Context $context)
7
  {
8
  @session_start();
9
+ if ( WPAdm_Running::is_stop() ) {
10
+ require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
11
 
12
+ WPAdm_Core::log(__('Send to dropbox files' ,'dropbox-backup') );
13
+ $dropbox = new dropbox($context->get('key'), $context->get('secret'), $context->get('token'));
14
 
15
+ if (!$dropbox->isAuth()) {
16
+ $context->setError( str_replace(array('%d', '%k', '%s'),
17
+ array( SITE_HOME, $context->get('key'), $context->get('secret') ),__('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"' ,'dropbox-backup') ) );
18
+ return false;
19
+ }
20
+ if ( WPAdm_Running::is_stop() ) {
21
+ $files = $context->get('files');
22
+ $file = explode("/", $files);
23
+ $file_name = array_pop($file);
24
+ $folder_project_temp = $context->get('folder_project');
25
+ $folder_project = "";
26
+ if (!empty($folder_project_temp)) {
27
+ $folder_project = $folder_project_temp . "/";
28
+ $dropbox->createDir($folder_project_temp );
29
+ $dropbox->createDir($folder_project . $context->get('folder') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  } else {
31
+ $dropbox->createDir($context->get('folder') );
 
32
  }
 
33
  } else {
34
+ return true;
35
  }
36
+
37
+ $fromFile = str_replace('//', '/', $files);
38
+ $toFile = str_replace('//', '/', $folder_project . $context->get('folder') . '/' . $file_name);
39
+ $local = $context->get('local');
40
+ $file_dropbox = $dropbox->listing($folder_project . $context->get('folder') . '/' . $file_name);
41
+ $send = true;
42
+ if ( !isset($file_dropbox['error']) ) {
43
+ if ($file_dropbox['bytes'] != filesize($fromFile)) {
44
+ if ( WPAdm_Running::is_stop() ) {
45
+ $delete_file = $dropbox->deleteFile($folder_project . $context->get('folder') . '/' . $file_name);
46
+ if (isset($delete_file['error'])) {
47
+ $context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
48
+ return false;
49
+ }
50
+ $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
51
+ if (isset($data_command[$fromFile])) {
52
+ $data_error_command[$fromFile]['count'] += 1;
53
+ } else {
54
+ $data_error_command[$fromFile] = array();
55
+ $data_error_command[$fromFile]['count'] = 1;
56
+ }
57
+ WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
58
+ }
59
  } else {
60
+ $send = false;
61
+ }
62
+ }
63
+ if ( $local ) {
64
+ if ( WPAdm_Running::is_stop() ) {
65
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
66
+ $md5 = md5($fromFile);
67
+ if (empty($data_command) || !in_array($md5 ,$data_command) ) {
68
+ if ($send) {
69
+ $res = $dropbox->uploadFile($fromFile, $toFile, true);
70
+ } else {
71
+ $this->saveDataCommand($md5);
72
+ WPAdm_Process::setInc('dropbox', 1);
73
+ }
74
+ }
75
+ }
76
+ } else {
77
+ $md5 = md5($fromFile);
78
+ $res = $dropbox->uploadFile($fromFile, $toFile, true);
79
+ }
80
+ if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
81
+ $context->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
82
+ return false;
83
+ }
84
+ if ( WPAdm_Running::is_stop() ) {
85
+ if (isset($res['size']) && isset($res['client_mtime'])) {
86
+ WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $files ) . __(' size: ' ,'dropbox-backup') . $res['size']);
87
+ $this->saveDataCommand($md5);
88
+ WPAdm_Process::setInc('dropbox', 1);
89
  }
90
  }
 
 
 
 
 
 
 
 
 
 
91
  }
92
  return true;
93
  }
dropbox-backup.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
- Version: 1.4.6.2
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
@@ -21,10 +21,12 @@ add_action('admin_print_scripts', array('wpadm_wp_full_backup_dropbox', 'include
21
  add_action('admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
22
  add_action('admin_post_activate_wpadm_full_backup_dropbox', array('wpadm_wp_full_backup_dropbox', 'activatePlugin') );
23
 
24
- if (!function_exists('wpadm_full_backup_dropbox_run')) {
25
  function wpadm_full_backup_dropbox_run()
26
  {
27
  wpadm_run('dropbox-backup', dirname(__FILE__));
28
  }
29
  }
30
 
 
 
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
+ Version: 1.4.7
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
21
  add_action('admin_menu', array('wpadm_wp_full_backup_dropbox', 'draw_menu'));
22
  add_action('admin_post_activate_wpadm_full_backup_dropbox', array('wpadm_wp_full_backup_dropbox', 'activatePlugin') );
23
 
24
+ if ( !function_exists('wpadm_full_backup_dropbox_run') ) {
25
  function wpadm_full_backup_dropbox_run()
26
  {
27
  wpadm_run('dropbox-backup', dirname(__FILE__));
28
  }
29
  }
30
 
31
+
32
+
functions/wpadm.php CHANGED
@@ -44,6 +44,12 @@ if ( ! function_exists('wpadm_pack')) {
44
  }
45
  }
46
 
 
 
 
 
 
 
47
 
48
  if ( ! function_exists('wpadm_deactivation')) {
49
  function wpadm_deactivation() {
44
  }
45
  }
46
 
47
+ if ( ! function_exists('wpadm_admin_notice')) {
48
+ function wpadm_admin_notice() {
49
+
50
+ }
51
+ }
52
+
53
 
54
  if ( ! function_exists('wpadm_deactivation')) {
55
  function wpadm_deactivation() {
libs/wpadm.server.main.class.php CHANGED
@@ -135,7 +135,7 @@
135
  'error' => $error_system)
136
  )
137
  );
138
-
139
  $res = self::sendToServer(array('actApi' => "errorLog",
140
  "site" => str_ireplace(array("http://","https://"), "", home_url()),
141
  "data" => $logs_report )
@@ -563,12 +563,12 @@
563
  $dir_backup = DROPBOX_BACKUP_DIR_BACKUP ;
564
 
565
  $backups = array('data' => array(), 'md5' => '');
566
-
567
  $backups['data'] = self::getBackups($dir_backup, $dirs_read);
568
-
569
  $backups['data'] = array_merge($backups['data'], self::getBackups(ABSPATH . WPADM_DIR_NAME, $dirs_read) );
570
  $backups['data'] = array_merge($backups['data'], self::getBackups(WPADM_DIR_BACKUP, $dirs_read) );
571
-
572
  $backups['md5'] = md5( print_r($backups['data'] , 1) );
573
  return $backups;
574
  }
@@ -579,28 +579,32 @@
579
  if (is_dir($dir_backup)) {
580
  $i = 0;
581
  $dir_open = opendir($dir_backup);
 
 
582
  while($d = readdir($dir_open)) {
583
  if ($d != '.' && $d != '..' && is_dir($dir_backup . "/$d") && strpos($d, self::$type) !== false) {
584
- $backups[$i]['dt'] = self::getDateInName($d);
585
- $backups[$i]['name'] = "$d";
586
- if ($dirs_read === false) {
587
- $size = 0;
588
- $dir_b = opendir($dir_backup . "/$d");
589
- $count_zip = 0;
590
- $backups[$i]['files'] = "[";
591
- while($d_b = readdir($dir_b)) {
592
- if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && ( substr($d_b, -3) == "zip" || substr($d_b, -3) == 'md5' ) ) {
593
- $backups[$i]['files'] .= "$d_b,";
594
- $size += filesize($dir_backup . "/$d/$d_b");
595
- $count_zip = $count_zip + 1;
 
 
596
  }
 
 
 
 
597
  }
598
- $backups[$i]['files'] .= ']';
599
- $backups[$i]['size'] = $size;
600
- $backups[$i]['type'] = 'local';
601
- $backups[$i]['count'] = $count_zip;
602
  }
603
- $i += 1;
604
  }
605
  }
606
  }
@@ -869,18 +873,18 @@
869
  $mysqlVersion = $mysqli->db_version();
870
  }
871
  $upMaxExecutionTime = 0;
872
- $newMaxExecutionTime = intval($maxExecutionTime) + 60;
 
873
  @set_time_limit( $newMaxExecutionTime );
874
  if( ini_get('max_execution_time') == $newMaxExecutionTime ){
875
  $upMaxExecutionTime = 1;
876
- $maxExecutionTime = ini_get('max_execution_time');
877
  }
878
  $upMemoryLimit = 0;
879
  $newMemoryLimit = intval($maxMemoryLimit) + 60;
880
  ini_set('memory_limit', $newMemoryLimit.'M');
881
  if( ini_get('memory_limit') == $newMemoryLimit ){
882
  $upMemoryLimit = 1;
883
- $maxMemoryLimit = ini_get('memory_limit');
884
  }
885
  $extensions_search = array('curl', 'json', 'mysqli', 'sockets', 'zip', 'ftp');
886
  $disabledFunctions_search = array('set_time_limit', 'curl_init', 'fsockopen', 'ftp_connect');
@@ -889,11 +893,11 @@
889
  $func = check_function($disabledFunctions, $disabledFunctions_search, true);
890
 
891
  return array('wp_version' => $wp_version, 'php_verion' => phpversion(),
892
- 'maxExecutionTime' => $maxExecutionTime, 'maxMemoryLimit' => $maxMemoryLimit,
893
  'extensions' => $extensions, 'disabledFunctions' => $disabledFunctions,
894
  'mysqlVersion' => $mysqlVersion, 'upMaxExecutionTime' => $upMaxExecutionTime,
895
  'newMaxExecutionTime' => $newMaxExecutionTime, 'upMemoryLimit' => $upMemoryLimit,
896
- 'newMemoryLimit' => $newMaxExecutionTime, 'maxMemoryLimit' => $maxMemoryLimit,
897
  'ex' => $ex, 'func' => $func, 'wp_lang' => get_option('WPLANG'),
898
  );
899
 
135
  'error' => $error_system)
136
  )
137
  );
138
+
139
  $res = self::sendToServer(array('actApi' => "errorLog",
140
  "site" => str_ireplace(array("http://","https://"), "", home_url()),
141
  "data" => $logs_report )
563
  $dir_backup = DROPBOX_BACKUP_DIR_BACKUP ;
564
 
565
  $backups = array('data' => array(), 'md5' => '');
566
+
567
  $backups['data'] = self::getBackups($dir_backup, $dirs_read);
568
+
569
  $backups['data'] = array_merge($backups['data'], self::getBackups(ABSPATH . WPADM_DIR_NAME, $dirs_read) );
570
  $backups['data'] = array_merge($backups['data'], self::getBackups(WPADM_DIR_BACKUP, $dirs_read) );
571
+
572
  $backups['md5'] = md5( print_r($backups['data'] , 1) );
573
  return $backups;
574
  }
579
  if (is_dir($dir_backup)) {
580
  $i = 0;
581
  $dir_open = opendir($dir_backup);
582
+ $stop_precess = WPAdm_Running::getCommandResultData('stop_process');
583
+ $name_backup = isset($stop_precess['name']) ? $stop_precess['name'] : '' ;
584
  while($d = readdir($dir_open)) {
585
  if ($d != '.' && $d != '..' && is_dir($dir_backup . "/$d") && strpos($d, self::$type) !== false) {
586
+ if ($d != $name_backup) {
587
+ $backups[$i]['dt'] = self::getDateInName($d);
588
+ $backups[$i]['name'] = "$d";
589
+ if ($dirs_read === false) {
590
+ $size = 0;
591
+ $dir_b = opendir($dir_backup . "/$d");
592
+ $count_zip = 0;
593
+ $backups[$i]['files'] = "[";
594
+ while($d_b = readdir($dir_b)) {
595
+ if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && ( substr($d_b, -3) == "zip" || substr($d_b, -3) == 'md5' ) ) {
596
+ $backups[$i]['files'] .= "$d_b,";
597
+ $size += filesize($dir_backup . "/$d/$d_b");
598
+ $count_zip = $count_zip + 1;
599
+ }
600
  }
601
+ $backups[$i]['files'] .= ']';
602
+ $backups[$i]['size'] = $size;
603
+ $backups[$i]['type'] = 'local';
604
+ $backups[$i]['count'] = $count_zip;
605
  }
606
+ $i += 1;
 
 
 
607
  }
 
608
  }
609
  }
610
  }
873
  $mysqlVersion = $mysqli->db_version();
874
  }
875
  $upMaxExecutionTime = 0;
876
+ $newMaxExecutionTime = intval($maxExecutionTime) + 180;
877
+
878
  @set_time_limit( $newMaxExecutionTime );
879
  if( ini_get('max_execution_time') == $newMaxExecutionTime ){
880
  $upMaxExecutionTime = 1;
881
+
882
  }
883
  $upMemoryLimit = 0;
884
  $newMemoryLimit = intval($maxMemoryLimit) + 60;
885
  ini_set('memory_limit', $newMemoryLimit.'M');
886
  if( ini_get('memory_limit') == $newMemoryLimit ){
887
  $upMemoryLimit = 1;
 
888
  }
889
  $extensions_search = array('curl', 'json', 'mysqli', 'sockets', 'zip', 'ftp');
890
  $disabledFunctions_search = array('set_time_limit', 'curl_init', 'fsockopen', 'ftp_connect');
893
  $func = check_function($disabledFunctions, $disabledFunctions_search, true);
894
 
895
  return array('wp_version' => $wp_version, 'php_verion' => phpversion(),
896
+ 'maxExecutionTime' => $maxExecutionTime,
897
  'extensions' => $extensions, 'disabledFunctions' => $disabledFunctions,
898
  'mysqlVersion' => $mysqlVersion, 'upMaxExecutionTime' => $upMaxExecutionTime,
899
  'newMaxExecutionTime' => $newMaxExecutionTime, 'upMemoryLimit' => $upMemoryLimit,
900
+ 'newMemoryLimit' => $newMemoryLimit, 'maxMemoryLimit' => $maxMemoryLimit,
901
  'ex' => $ex, 'func' => $func, 'wp_lang' => get_option('WPLANG'),
902
  );
903
 
main/wpadm-class-wp.php CHANGED
@@ -13,12 +13,13 @@
13
  add_action('wp_ajax_wpadm_local_backup', array('wpadm_wp_full_backup_dropbox', 'local_backup') );
14
  add_action('wp_ajax_wpadm_dropbox_create', array('wpadm_wp_full_backup_dropbox', 'dropbox_backup_create') );
15
  add_action('wp_ajax_set_user_mail', array('wpadm_wp_full_backup_dropbox', 'setUserMail') );
16
- add_action('wp_ajax_stop_backup', array('wpadm_wp_full_backup_dropbox', 'stopBackup') );
17
  add_action('wp_ajax_saveSetting', array('wpadm_wp_full_backup_dropbox', 'saveSetting') );
18
 
19
 
20
  add_action('admin_post_wpadm_delete_backup', array('wpadm_wp_full_backup_dropbox', 'delete_backup') );
21
  add_action('admin_post_dropboxConnect', array('wpadm_wp_full_backup_dropbox', 'dropboxConnect') );
 
22
 
23
  add_action('admin_post_login-process', array('wpadm_wp_full_backup_dropbox', 'auth_user') );
24
 
@@ -38,9 +39,51 @@
38
 
39
  const MIN_PASSWORD = 6;
40
 
41
- static function stopBackup()
 
 
 
 
42
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  WPAdm_Running::init_params_default();
 
 
 
 
 
44
  }
45
 
46
  static function add_link_to_admin_bar($wp_admin_bar)
@@ -50,6 +93,9 @@
50
  if ($dropbox_options) {
51
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
52
  }
 
 
 
53
  if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
54
  if (!is_admin() || !is_super_admin()) {
55
  $show = false;
@@ -134,6 +180,7 @@
134
  wp_enqueue_style('admin-wpadm', plugins_url( "/template/css/admin-style-wpadm.css", dirname( __FILE__ )) );
135
  wp_enqueue_script( 'js-admin-wpadm', plugins_url( "/template/js/admin-wpadm.js", dirname( __FILE__ ) ) );
136
  wp_enqueue_script( 'postbox' );
 
137
  }
138
  wp_enqueue_style('css-admin-wpadm-toolbar', plugins_url( "/template/css/tool-bar.css", dirname( __FILE__ )) );
139
  }
@@ -154,12 +201,16 @@
154
  }
155
  public static function saveSetting()
156
  {
157
- if (isset($_POST['is_admin']) || isset($_POST['is_optimization']) || isset($_POST['is_local_backup_delete']) || isset($_POST['is_repair']) ) {
 
158
 
159
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
160
  if ($dropbox_options) {
161
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
162
  }
 
 
 
163
  if (isset($_POST['is_admin'])) {
164
  $dropbox_options['is_admin'] = (int) $_POST['is_admin'];
165
  }
@@ -172,6 +223,9 @@
172
  if (isset($_POST['is_repair'])) {
173
  $dropbox_options['is_repair'] = (int) $_POST['is_repair'];
174
  }
 
 
 
175
  update_option(PREFIX_BACKUP_ . 'dropbox-setting', base64_encode( serialize( $dropbox_options ) ) );
176
  }
177
  }
@@ -190,6 +244,7 @@
190
  public static function local_backup()
191
  {
192
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
 
193
  @session_write_close();
194
  parent::$type = 'full';
195
  if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
@@ -197,34 +252,49 @@
197
  }
198
  if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
199
  file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
200
- }
 
 
 
201
  WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
202
  WPAdm_Running::init_params_default();
203
- if ( WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) ) {
204
- WPAdm_Running::delCommandResultData("local_backup");
205
- $dropbox_options = self::getSettings();
206
- $optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
207
- $repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
208
- $backup = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
209
- if (WPAdm_Core::$cron === false) {
210
- $res = $backup->getResult()->toArray();
211
- $res['md5_data'] = md5( print_r($res, 1) );
212
- $res['name'] = $backup->name;
213
- $res['time'] = $backup->time;
214
- $res['type'] = 'local';
215
- $res['counts'] = count($res['data']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  } else {
217
- set_transient('running_command', 'local_backup', 0);
218
- $res['result'] = 'work';
219
- $res['error'] = '';
220
  $res['data'] = array();
221
  $res['size'] = 0;
222
  }
223
- } else {
224
- $res['result'] = 'error';
225
- $res['error'] = str_replace(array('%domain', '%dir-backup'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".','dropbox-backup') );
226
- $res['data'] = array();
227
- $res['size'] = 0;
228
  }
229
 
230
  @session_start();
@@ -232,16 +302,54 @@
232
  wp_die();
233
 
234
  }
 
235
  public static function getLog()
236
  {
237
  @session_write_close();
238
  @session_start();
239
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
 
240
  $backup = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
241
  $log = WPAdm_Core::getLog();
242
  $log2 = WPAdm_Core::getTmpDir() . "/logs2";
243
- if (file_exists($log2)) {
 
244
  $text = @file_get_contents($log2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  file_put_contents($log2, $log);
246
  $log = str_replace($text, "", $log);
247
  } else {
@@ -249,12 +357,23 @@
249
  }
250
  $log = explode("\n", $log);
251
  krsort($log);
252
- $log_array = array('log' => $log );
253
  $data_result = WPAdm_Running::getCommandResultData($_POST['type-backup']);
254
  if (!empty($data_result)) {
255
  $log_array['data'] = $data_result;
256
  set_transient('drb_running', 0, 1);
257
  }
 
 
 
 
 
 
 
 
 
 
 
258
  echo json_encode( $log_array );
259
  exit;
260
  }
@@ -422,7 +541,9 @@
422
  }
423
  }
424
  }
425
- header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
 
 
426
  }
427
 
428
  protected static function getPluginName()
@@ -486,6 +607,7 @@
486
  public static function dropbox_backup_create()
487
  {
488
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
 
489
  @session_write_close();
490
 
491
  $log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
@@ -495,6 +617,9 @@
495
  if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
496
  file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
497
  }
 
 
 
498
  if ( WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) ) {
499
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
500
  $send_to_dropbox = true;
@@ -518,6 +643,16 @@
518
  $send_to_dropbox = false;
519
  }
520
 
 
 
 
 
 
 
 
 
 
 
521
  if ($send_to_dropbox) {
522
  parent::$type = 'full';
523
  WPAdm_Running::init_params_default();
@@ -583,45 +718,50 @@
583
  $folder_project = str_ireplace( array("http://", "https://"), '', home_url() );
584
  $folder_project = str_ireplace( array( "-", '/', '.'), '_', $folder_project );
585
  $folder_project = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
586
- array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
587
- $folder_project );
588
  return $folder_project;
589
  }
590
 
591
-
592
  public static function wpadm_show_backup()
593
  {
594
-
595
  require_once DRBBACKUP_BASE_DIR. "/modules/dropbox.class.php";
596
  parent::$type = 'full';
597
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
 
 
598
  if ($dropbox_options) {
599
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
600
  if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) {
601
  $dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
602
  $folder_project = self::getNameProject();
 
 
 
603
  $backups = $dropbox->listing($folder_project);
604
  $n = count($backups['items']);
605
  $data['data'] = array();
606
  $not_all_upload = false;
607
  for($i = 0; $i < $n; $i++) {
608
- $backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']);
609
- $data['data'][$i]['name'] = $backups['items'][$i]['name'];
610
- $data['data'][$i]['size'] = (float)$backup['size'] * 1024 * 1024;
611
- $data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']);
612
- $data['data'][$i]['count'] = count($backup['items']);
613
- $data['data'][$i]['type'] = 'dropbox';
614
- $k = $data['data'][$i]['count'];
615
- $data['data'][$i]['files'] = '[';
616
- for($j = 0; $j < $k; $j++) {
617
- if ( strpos($backup['items'][$j]['name'] , '.md5') !== false || strpos($backup['items'][$j]['name'] , '.zip') !== true ) {
618
- if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
619
- $not_all_upload = true;
 
 
 
620
  }
621
- $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
622
  }
 
623
  }
624
- $data['data'][$i]['not_all_upload'] = $not_all_upload;
625
  }
626
  }
627
  }
@@ -679,31 +819,34 @@
679
  $name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
680
  $name_running_backup .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $running_backup['params']['time']);
681
  }
682
-
683
  if ( !file_exists( DROPBOX_BACKUP_DIR_BACKUP . '/local-key') ) {
684
  WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
685
  $key = md5(time() . 'wpadm-key');
686
  file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack(array('key' => $key, 'time-update' => time() + 3600) ));
687
  } else {
688
  $key_values = wpadm_unpack( file_get_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key') );
689
- if (isset($key_values['time-update']) && $key_values['time-update'] <= time()) {
690
- $key = md5(time() . 'wpadm-key');
691
- file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack(array('key' => $key, 'time-update' => time() + 3600) ));
692
  } else {
693
  $key = $key_values['key'];
694
  }
695
  }
696
-
697
  $show = !get_option('wpadm_pub_key') && is_super_admin();
698
  $error = parent::getError(true);
 
 
 
699
  $msg = parent::getMessage(true);
 
700
  $base_path = DRBBACKUP_BASE_DIR ;
701
  ob_start();
702
  require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
703
  echo ob_get_clean();
704
  }
705
-
706
-
707
  public static function draw_menu()
708
  {
709
  $show = true;
13
  add_action('wp_ajax_wpadm_local_backup', array('wpadm_wp_full_backup_dropbox', 'local_backup') );
14
  add_action('wp_ajax_wpadm_dropbox_create', array('wpadm_wp_full_backup_dropbox', 'dropbox_backup_create') );
15
  add_action('wp_ajax_set_user_mail', array('wpadm_wp_full_backup_dropbox', 'setUserMail') );
16
+
17
  add_action('wp_ajax_saveSetting', array('wpadm_wp_full_backup_dropbox', 'saveSetting') );
18
 
19
 
20
  add_action('admin_post_wpadm_delete_backup', array('wpadm_wp_full_backup_dropbox', 'delete_backup') );
21
  add_action('admin_post_dropboxConnect', array('wpadm_wp_full_backup_dropbox', 'dropboxConnect') );
22
+ add_action('admin_post_stop_backup', array('wpadm_wp_full_backup_dropbox', 'stopBackup') );
23
 
24
  add_action('admin_post_login-process', array('wpadm_wp_full_backup_dropbox', 'auth_user') );
25
 
39
 
40
  const MIN_PASSWORD = 6;
41
 
42
+ private static $circle = 18;
43
+
44
+ private static $local_delete = false;
45
+
46
+ static function stopBackup($local = false)
47
  {
48
+ if (isset($_POST['type_backup'])) {
49
+ self::$local_delete = $local;
50
+ $setting_backup = array();
51
+ if ( $_POST['type_backup'] == 'local_backup' ) {
52
+ $setting_backup = WPAdm_Running::getCommand( 'local_backup' );
53
+ $_POST['backup-type'] = 'local';
54
+ } elseif ($_POST['type_backup'] == 'send-to-dropbox') {
55
+ $setting_backup = WPAdm_Running::getCommand( 'send-to-dropbox' );
56
+ $_POST['backup-type'] = 'dropbox';
57
+ }
58
+ // WPAdm_Running::setCommandResultData('stop_backup', $setting_backup);
59
+ $name = '';
60
+ if (isset($setting_backup['params']['time'])) {
61
+ $name = get_option('siteurl');
62
+
63
+ $name = str_replace("http://", '', $name);
64
+ $name = str_replace("https://", '', $name);
65
+ $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
66
+ array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
67
+ $name );
68
+ $name = preg_replace("|\W|", "_", $name);
69
+ $name .= '-full-' . date("Y_m_d_H_i", $setting_backup['params']['time']);
70
+ $_POST['backup-name'] = $name;
71
+ if ($_POST['type_backup'] == 'send-to-dropbox') {
72
+ $_POST['backup-type'] = 'local';
73
+ //WPAdm_Running::setCommandResultData('stop_backup_post1', $_POST);
74
+ self::delete_backup();
75
+ $_POST['backup-type'] = 'dropbox';
76
+ }
77
+ //WPAdm_Running::setCommandResultData('stop_backup_post2', $_POST);
78
+ self::delete_backup();
79
+ }
80
+ }
81
  WPAdm_Running::init_params_default();
82
+ WPAdm_Running::setCommandResultData('stop_process', array( 'stop' => 1, 'name' => $name, 'type' => $_POST['backup-type'] ) );
83
+ if ($local === false || empty($local)) {
84
+ header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
85
+ exit;
86
+ }
87
  }
88
 
89
  static function add_link_to_admin_bar($wp_admin_bar)
93
  if ($dropbox_options) {
94
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
95
  }
96
+ if ( ( isset($dropbox_options['is_show_admin_bar']) && $dropbox_options['is_show_admin_bar'] == 0 ) ) {
97
+ $show = false;
98
+ }
99
  if ( ( isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ) || !isset($dropbox_options['is_admin']) ) {
100
  if (!is_admin() || !is_super_admin()) {
101
  $show = false;
180
  wp_enqueue_style('admin-wpadm', plugins_url( "/template/css/admin-style-wpadm.css", dirname( __FILE__ )) );
181
  wp_enqueue_script( 'js-admin-wpadm', plugins_url( "/template/js/admin-wpadm.js", dirname( __FILE__ ) ) );
182
  wp_enqueue_script( 'postbox' );
183
+ wp_enqueue_script( 'jquery-ui-tooltip' );
184
  }
185
  wp_enqueue_style('css-admin-wpadm-toolbar', plugins_url( "/template/css/tool-bar.css", dirname( __FILE__ )) );
186
  }
201
  }
202
  public static function saveSetting()
203
  {
204
+ if (isset($_POST['is_admin']) || isset($_POST['is_optimization']) || isset($_POST['is_local_backup_delete'])
205
+ || isset($_POST['is_repair']) || isset($_POST['time_error']) || isset($_POST['is_show_admin_bar'] ) ) {
206
 
207
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
208
  if ($dropbox_options) {
209
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
210
  }
211
+ if (isset($_POST['time_error'])) {
212
+ $dropbox_options['time_error'] = (int)$_POST['time_error'];
213
+ }
214
  if (isset($_POST['is_admin'])) {
215
  $dropbox_options['is_admin'] = (int) $_POST['is_admin'];
216
  }
223
  if (isset($_POST['is_repair'])) {
224
  $dropbox_options['is_repair'] = (int) $_POST['is_repair'];
225
  }
226
+ if (isset($_POST['is_show_admin_bar'])) {
227
+ $dropbox_options['is_show_admin_bar'] = (int) $_POST['is_show_admin_bar'];
228
+ }
229
  update_option(PREFIX_BACKUP_ . 'dropbox-setting', base64_encode( serialize( $dropbox_options ) ) );
230
  }
231
  }
244
  public static function local_backup()
245
  {
246
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
247
+ require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
248
  @session_write_close();
249
  parent::$type = 'full';
250
  if (file_exists(WPAdm_Core::getTmpDir() . "/logs2")) {
252
  }
253
  if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
254
  file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
255
+ }
256
+
257
+ WPAdm_Process::clear();
258
+
259
  WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
260
  WPAdm_Running::init_params_default();
261
+ $res['result'] = 'success';
262
+ if (defined('DISABLE_WP_CRON')) {
263
+ if (DISABLE_WP_CRON === true) {
264
+ $res['result'] = 'error';
265
+ $res['error'] = __('please enable cron-tasks on your website.','dropbox-backup'); //. '<br /><a href="" target="_blank">' . __('How to enable cron-tasks on my website?','dropbox-backup') . '</a>';
266
+ $res['data'] = array();
267
+ $res['size'] = 0;
268
+ }
269
+ }
270
+
271
+ if ( (isset($res['result']) && $res['result'] != 'error') ) {
272
+ if ( WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) ) {
273
+ WPAdm_Running::delCommandResultData("local_backup");
274
+ $dropbox_options = self::getSettings();
275
+ $optimization = (isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1) || (!isset($dropbox_options['is_optimization'])) ? 1 : 0;
276
+ $repair = (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 1 : 0;
277
+ $backup = new WPAdm_Core(array('method' => "local_backup", 'params' => array('optimize' => $optimization, 'repair' => $repair, 'limit' => 0, 'time' => @$_POST['time'], 'types' => array('db', 'files') )), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
278
+ if (WPAdm_Core::$cron === false) {
279
+ $res = $backup->getResult()->toArray();
280
+ $res['md5_data'] = md5( print_r($res, 1) );
281
+ $res['name'] = $backup->name;
282
+ $res['time'] = $backup->time;
283
+ $res['type'] = 'local';
284
+ $res['counts'] = count($res['data']);
285
+ } else {
286
+ set_transient('running_command', 'local_backup', 0);
287
+ $res['result'] = 'work';
288
+ $res['error'] = '';
289
+ $res['data'] = array();
290
+ $res['size'] = 0;
291
+ }
292
  } else {
293
+ $res['result'] = 'error';
294
+ $res['error'] = str_replace(array('%domain', '%dir-backup'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during file creation: Failed to create file, please check the permissions on the folder "%dir-backup".','dropbox-backup') );
 
295
  $res['data'] = array();
296
  $res['size'] = 0;
297
  }
 
 
 
 
 
298
  }
299
 
300
  @session_start();
302
  wp_die();
303
 
304
  }
305
+
306
  public static function getLog()
307
  {
308
  @session_write_close();
309
  @session_start();
310
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
311
+ require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
312
  $backup = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
313
  $log = WPAdm_Core::getLog();
314
  $log2 = WPAdm_Core::getTmpDir() . "/logs2";
315
+ $log_array = array();
316
+ if ( file_exists($log2) ) {
317
  $text = @file_get_contents($log2);
318
+ if ($text == $log) {
319
+ $circle = WPAdm_Running::getCommandResultData( 'circle' );
320
+ if ( empty($circle['count']) || $circle['count'] == 0) {
321
+ $circle['count'] = 0;
322
+ }
323
+ $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
324
+ if ($dropbox_options) {
325
+ $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
326
+ if (isset($dropbox_options['time_error'])) {
327
+ self::$circle = ( (int)$dropbox_options['time_error'] * 6 );
328
+ }
329
+ }
330
+ $log_array['circle'] = self::$circle;
331
+ if ( $circle['count'] <= self::$circle ) {
332
+ $circle['count']++;
333
+ $circle['time'] = time();
334
+ WPAdm_Running::setCommandResultData( 'circle', $circle );
335
+ } else {
336
+ $date_systm = get_system_data();
337
+ $error_msg = __('There is not enough script running time to perform backup operations, please increase the PHP variable max_execution_time.', 'dropbox-backup');
338
+ if ( $date_systm['upMemoryLimit'] == 0 ) {
339
+ $error_msg = __('There is not enough memory to perform archiving of big files and continue backup operations, please increase the PHP variable memory_limit.', 'dropbox-backup');
340
+ }
341
+ $log_array['data'] = array(
342
+ 'result' => 'error',
343
+ 'error' => $error_msg,
344
+ 'data' => null,
345
+ 'size' => 0 );
346
+ $_POST['type_backup'] = $_POST['type-backup'];
347
+ self::stopBackup(true);
348
+ }
349
+ $log_array['example'] = $circle;
350
+ } else {
351
+ WPAdm_Running::setCommandResultData( 'circle', array( 'count' => 0, 'time' => time() ) );
352
+ }
353
  file_put_contents($log2, $log);
354
  $log = str_replace($text, "", $log);
355
  } else {
357
  }
358
  $log = explode("\n", $log);
359
  krsort($log);
360
+ $log_array['log'] = $log;
361
  $data_result = WPAdm_Running::getCommandResultData($_POST['type-backup']);
362
  if (!empty($data_result)) {
363
  $log_array['data'] = $data_result;
364
  set_transient('drb_running', 0, 1);
365
  }
366
+ if (isset($_POST['type-backup2'])) {
367
+ $data_result = WPAdm_Running::getCommandResultData($_POST['type-backup2']);
368
+ if (!empty($data_result) && $data_result['result'] != 'success') {
369
+ $log_array['data'] = $data_result;
370
+ set_transient('drb_running', 0, 1);
371
+ }
372
+ }
373
+ $log_array['processes'] = WPAdm_Process::getAll();
374
+ if (defined('WP_CRON_LOCK_TIMEOUT')) {
375
+ $log_array['lock_cron'] = WP_CRON_LOCK_TIMEOUT;
376
+ }
377
  echo json_encode( $log_array );
378
  exit;
379
  }
541
  }
542
  }
543
  }
544
+ if (self::$local_delete === false || empty(self::$local_delete)) {
545
+ header("Location: " . admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"));
546
+ }
547
  }
548
 
549
  protected static function getPluginName()
607
  public static function dropbox_backup_create()
608
  {
609
  require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-core.php";
610
+ require_once DRBBACKUP_BASE_DIR . "/modules/class-wpadm-process.php";
611
  @session_write_close();
612
 
613
  $log = new WPAdm_Core(array('method' => "local"), 'full_backup_dropbox', WPAdm_Core::$pl_dir);
617
  if (file_exists(WPAdm_Core::getTmpDir() . "/log.log")) {
618
  file_put_contents(WPAdm_Core::getTmpDir() . "/log.log", '');
619
  }
620
+
621
+ WPAdm_Process::clear();
622
+
623
  if ( WPAdm_Core::dir_writeble(DROPBOX_BACKUP_DIR_BACKUP) ) {
624
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
625
  $send_to_dropbox = true;
643
  $send_to_dropbox = false;
644
  }
645
 
646
+ if (defined('DISABLE_WP_CRON')) {
647
+ if (DISABLE_WP_CRON === true) {
648
+ $res['result'] = 'error';
649
+ $res['error'] = __('please enable cron-task of your website.','dropbox-backup');
650
+ $res['data'] = array();
651
+ $res['size'] = 0;
652
+ $send_to_dropbox = false;
653
+ }
654
+ }
655
+
656
  if ($send_to_dropbox) {
657
  parent::$type = 'full';
658
  WPAdm_Running::init_params_default();
718
  $folder_project = str_ireplace( array("http://", "https://"), '', home_url() );
719
  $folder_project = str_ireplace( array( "-", '/', '.'), '_', $folder_project );
720
  $folder_project = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
721
+ array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
722
+ $folder_project );
723
  return $folder_project;
724
  }
725
 
 
726
  public static function wpadm_show_backup()
727
  {
 
728
  require_once DRBBACKUP_BASE_DIR. "/modules/dropbox.class.php";
729
  parent::$type = 'full';
730
  $dropbox_options = get_option(PREFIX_BACKUP_ . 'dropbox-setting');
731
+ $stop_precess = WPAdm_Running::getCommandResultData('stop_process');
732
+ $name_backup = isset($stop_precess['name']) ? $stop_precess['name'] : '' ;
733
  if ($dropbox_options) {
734
  $dropbox_options = unserialize( base64_decode( $dropbox_options ) );
735
  if (isset($dropbox_options['app_key']) && isset($dropbox_options['app_secret']) && isset($dropbox_options['auth_token_secret'])) {
736
  $dropbox = new dropbox($dropbox_options['app_key'], $dropbox_options['app_secret'], $dropbox_options['auth_token_secret']);
737
  $folder_project = self::getNameProject();
738
+ //$dropbox->uploadFile(dirname(__FILE__) . "/index.php", $folder_project . '/index.php', true);
739
+ // $res = $dropbox->downloadFile("localhost_wp_dropbox/localhost_wp_dropbox-full-2016_06_07_14_05/localhost_wp_dropbox-full-2016_06_07_14_05.md5", DROPBOX_BACKUP_DIR_BACKUP . "/localhost_wp_dropbox-full-2016_06_07_14_05.md5");
740
+ //var_dump($res);
741
  $backups = $dropbox->listing($folder_project);
742
  $n = count($backups['items']);
743
  $data['data'] = array();
744
  $not_all_upload = false;
745
  for($i = 0; $i < $n; $i++) {
746
+ if ($name_backup != $backups['items'][$i]['name']) {
747
+ $backup = $dropbox->listing($folder_project . "/" . $backups['items'][$i]['name']);
748
+ $data['data'][$i]['name'] = $backups['items'][$i]['name'];
749
+ $data['data'][$i]['size'] = (float)$backup['size'] * 1024 * 1024;
750
+ $data['data'][$i]['dt'] = parent::getDateInName($backups['items'][$i]['name']);
751
+ $data['data'][$i]['count'] = count($backup['items']);
752
+ $data['data'][$i]['type'] = 'dropbox';
753
+ $k = $data['data'][$i]['count'];
754
+ $data['data'][$i]['files'] = '[';
755
+ for($j = 0; $j < $k; $j++) {
756
+ if ( strpos($backup['items'][$j]['name'] , '.md5') !== false || strpos($backup['items'][$j]['name'] , '.zip') !== true ) {
757
+ if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
758
+ $not_all_upload = true;
759
+ }
760
+ $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
761
  }
 
762
  }
763
+ $data['data'][$i]['not_all_upload'] = $not_all_upload;
764
  }
 
765
  }
766
  }
767
  }
819
  $name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
820
  $name_running_backup .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $running_backup['params']['time']);
821
  }
822
+
823
  if ( !file_exists( DROPBOX_BACKUP_DIR_BACKUP . '/local-key') ) {
824
  WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
825
  $key = md5(time() . 'wpadm-key');
826
  file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack(array('key' => $key, 'time-update' => time() + 3600) ));
827
  } else {
828
  $key_values = wpadm_unpack( file_get_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key') );
829
+ if (isset($key_values['time-update']) && $key_values['time-update'] <= time() ) {
830
+ $key = md5( time() . 'wpadm-key' );
831
+ file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack( array( 'key' => $key, 'time-update' => time() + 3600 ) ) );
832
  } else {
833
  $key = $key_values['key'];
834
  }
835
  }
836
+
837
  $show = !get_option('wpadm_pub_key') && is_super_admin();
838
  $error = parent::getError(true);
839
+ if ( !empty( WPAdm_Core::$error ) ) {
840
+ $error .= '<br />' . WPAdm_Core::$error;
841
+ }
842
  $msg = parent::getMessage(true);
843
+ $default = self::$circle / 6; // 18 request for log files, one request every 10 seconds
844
  $base_path = DRBBACKUP_BASE_DIR ;
845
  ob_start();
846
  require_once $base_path . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show_backup.php";
847
  echo ob_get_clean();
848
  }
849
+
 
850
  public static function draw_menu()
851
  {
852
  $show = true;
methods/class-wpadm-method-backup.php CHANGED
@@ -56,8 +56,8 @@ if (!class_exists('WPadm_Method_Backup')) {
56
  $name = str_replace("https://", '', $name);
57
  $name = preg_replace("|\W|", "_", $name);
58
  $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
59
- array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
60
- $name );
61
  $name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
62
  $this->name = $name;
63
 
@@ -93,45 +93,76 @@ if (!class_exists('WPadm_Method_Backup')) {
93
  }
94
  $wp_mysql_params = $this->getWpMysqlParams();
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
97
- WPAdm_Core::log('optimization Database');
98
- $commandContext = new WPAdm_Command_Context();
99
- $commandContext ->addParam('command','mysqloptimize')
100
- ->addParam('host', $wp_mysql_params['host'])
101
- ->addParam('db', $wp_mysql_params['db'])
102
- ->addParam('user', $wp_mysql_params['user'])
103
- ->addParam('password', $wp_mysql_params['password']);
104
- $this->queue->clear()
105
- ->add($commandContext);
106
- unset($commandContext);
 
 
 
 
 
 
107
  }
108
 
109
- $commandContext = new WPAdm_Command_Context();
110
- $commandContext ->addParam('command','mysqldump')
111
- ->addParam('host', $wp_mysql_params['host'])
112
- ->addParam('db', $wp_mysql_params['db'])
113
- ->addParam('user', $wp_mysql_params['user'])
114
- ->addParam('password', $wp_mysql_params['password'])
115
- ->addParam('tables', '')
116
- ->addParam('to_file', $mysql_dump_file);
117
- $res = $this->queue->add($commandContext)
118
- ->save()
119
- ->execute();
120
-
121
- if (!$res) {
122
- $log = str_replace( array('%domain', '%s'), array(SITE_HOME, $this->queue->getError(), __('Website "%domain" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.','dropbox-backup') ) );
123
- WPAdm_Core::log($log);
124
- $errors[] = $log;
125
- } elseif (0 == (int)filesize($mysql_dump_file)) {
126
- $log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP__('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') ));
 
127
  $errors[] = $log;
128
  WPAdm_Core::log($log);
 
 
 
129
  } else {
130
  $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
131
- $log = str_replace("%s", $size_dump , __('Database Dump was successfully created ( %s Mb) : ','dropbox-backup') ) ;
132
- WPAdm_Core::log($log . ' '. str_replace(ABSPATH, '', $mysql_dump_file) );
133
  }
134
- unset($commandContext);
135
 
136
 
137
  WPAdm_Core::log('Start Created List Files');
@@ -167,23 +198,38 @@ if (!class_exists('WPadm_Method_Backup')) {
167
  }
168
 
169
  WPAdm_Core::log('Сreated List Files is successfully');
170
- $this->queue->clear();
171
-
 
 
 
172
  foreach($files2 as $files) {
173
- $commandContext = new WPAdm_Command_Context();
174
- $commandContext ->addParam('command','archive')
175
- ->addParam('files', $files)
176
- ->addParam('to_file', $this->dir . '/'.$this->name)
177
- ->addParam('max_file_size', 900000)
178
- ->addParam('remove_path', ABSPATH);
179
-
180
- $this->queue->add($commandContext);
181
- unset($commandContext);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
- WPAdm_Core::log('Start archived files');
184
- // сохраним и выполним
185
- $this->queue->save()
186
- ->execute();
187
  WPAdm_Core::log('End archived files');
188
 
189
  $files = glob($this->dir . '/'.$this->name . '*');
@@ -229,6 +275,29 @@ if (!class_exists('WPadm_Method_Backup')) {
229
 
230
  }
231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
 
233
 
234
  public function createListFilesForArchive() {
@@ -238,15 +307,15 @@ if (!class_exists('WPadm_Method_Backup')) {
238
  $files = array_merge(
239
  $files,
240
  array(
241
- ABSPATH .'/.htaccess',
242
  ABSPATH .'/index.php',
243
- ABSPATH .'/license.txt',
244
- ABSPATH .'/readme.html',
245
  ABSPATH .'/wp-activate.php',
246
  ABSPATH .'/wp-blog-header.php',
247
  ABSPATH .'/wp-comments-post.php',
248
  ABSPATH .'/wp-config.php',
249
- ABSPATH .'/wp-config-sample.php',
250
  ABSPATH .'/wp-cron.php',
251
  ABSPATH .'/wp-links-opml.php',
252
  ABSPATH .'/wp-load.php',
@@ -259,12 +328,25 @@ if (!class_exists('WPadm_Method_Backup')) {
259
  )
260
  );
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  if (!empty($this->params['minus-path'])) {
263
  foreach($files as $k=>$v) {
264
  $v = str_replace(ABSPATH .'/' , '', $v);
265
  if (in_array($v, $this->params['minus-path'])) {
266
  unset($files[$k]);
267
- WPAdm_Core::log('Пропускаем файл ' . $v);
268
  }
269
  }
270
  }
@@ -277,17 +359,18 @@ if (!class_exists('WPadm_Method_Backup')) {
277
  ABSPATH .'/wp-includes',
278
  )
279
  );
280
-
281
- foreach($this->params['plus-path'] as $p) {
282
- if (empty($p)) {
283
- continue;
284
- }
285
- $p = ABSPATH .'/' . $p;
286
- if (file_exists($p)) {
287
- if (is_dir($p)) {
288
- $folders[] = $p;
289
- } else{
290
- $files[] = $p;
 
291
  }
292
  }
293
  }
@@ -314,7 +397,7 @@ if (!class_exists('WPadm_Method_Backup')) {
314
  if (
315
  in_array($d, $this->params['minus-path'])
316
  ) {
317
- WPAdm_Core::log('Пропускаем папку ' . $directory);
318
  return array();
319
  }
320
 
@@ -329,7 +412,7 @@ if (!class_exists('WPadm_Method_Backup')) {
329
  if (strpos($d2, 'cache') !== false
330
  && !in_array($tmp[0], array('plugins', 'themes'))
331
  ) {
332
- WPAdm_Core::log('Пропускаем папку(cache) ' . $directory);
333
  return array();
334
  }
335
  if(strpos($directory, 'wpadm_backups') !== false) {
@@ -348,11 +431,11 @@ if (!class_exists('WPadm_Method_Backup')) {
348
  if (!is_dir($file)) {
349
  $ff = preg_replace("/\/\//si", "/", $file);
350
  $f = str_replace(ABSPATH . '/', '', $ff);
351
- // пропускаем ненужные директории
352
  if (!in_array($f, $this->params['minus-path'])) {
353
  $array_items[] = $ff;
354
  } else {
355
- WPAdm_Core::log('Пропускаем файл ' . $ff);
356
  }
357
  }
358
  } else {
@@ -360,11 +443,11 @@ if (!class_exists('WPadm_Method_Backup')) {
360
  if (!is_dir($file)) {
361
  $ff = preg_replace("/\/\//si", "/", $file);
362
  $f = str_replace(ABSPATH . '/', '', $ff);
363
- // пропускаем ненужные директории
364
  if (!in_array($f, $this->params['minus-path'])) {
365
  $array_items[] = $ff;
366
  } else {
367
- WPAdm_Core::log('Пропускаем файл ' . $ff);
368
  }
369
  }
370
  }
@@ -377,7 +460,7 @@ if (!class_exists('WPadm_Method_Backup')) {
377
 
378
 
379
  /*
380
- * Берем реквизиты доступа к MySQL из параметров WP
381
  * return Array()
382
  */
383
  private function getWpMysqlParams()
@@ -400,10 +483,10 @@ if (!class_exists('WPadm_Method_Backup')) {
400
 
401
 
402
  private function init(array $conf) {
403
- //todo: нормализация
404
  $this->id = $conf['id'];
405
  $this->stime = $conf['stime'];
406
- $this->queue = new WPAdm_Queue($this->id);
407
  $this->type = $conf['type'];
408
  }
409
  }
56
  $name = str_replace("https://", '', $name);
57
  $name = preg_replace("|\W|", "_", $name);
58
  $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
59
+ array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
60
+ $name );
61
  $name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
62
  $this->name = $name;
63
 
93
  }
94
  $wp_mysql_params = $this->getWpMysqlParams();
95
 
96
+ if ( isset($this->params['repair']) && ( $this->params['repair'] == 1 ) ) {
97
+ if ( WPAdm_Running::is_stop() ) {
98
+ if (!class_exists('WPAdm_Mysqldump')) {
99
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
100
+ }
101
+
102
+ $mysql = new WPAdm_Mysqldump();
103
+ $mysql->host = $wp_mysql_params['host'];
104
+ $mysql->user = $wp_mysql_params['user'];
105
+ $mysql->password = $wp_mysql_params['password'];
106
+ try {
107
+ $mysql->repair($wp_mysql_params['db']);
108
+ unset($mysql);
109
+ } catch (Exception $e) {
110
+ $this->result->setError( $e->getMessage() );
111
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
112
+ return $this->result;
113
+ }
114
+ unset($mysql);
115
+ }
116
+ }
117
+
118
  if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
119
+ WPAdm_Core::log(__('Optimize Database Tables','dropbox-backup'));
120
+ if (!class_exists('WPAdm_Mysqldump')) {
121
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
122
+ }
123
+ $mysql = new WPAdm_Mysqldump();
124
+ $mysql->host = $wp_mysql_params['host'];
125
+ $mysql->user = $wp_mysql_params['user'];
126
+ $mysql->password = $wp_mysql_params['password'];
127
+ try {
128
+ $mysql->optimize($wp_mysql_params['db']);
129
+ } catch (Exception $e) {
130
+ $this->result->setError( $e->getMessage() );
131
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
132
+ return $this->result;
133
+ }
134
+ unset($mysql);
135
  }
136
 
137
+ if (!class_exists('WPAdm_Mysqldump')) {
138
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
139
+ }
140
+ $mysql = new WPAdm_Mysqldump();
141
+ $mysql->host = $wp_mysql_params['host'];
142
+ $mysql->user = $wp_mysql_params['user'];
143
+ $mysql->password = $wp_mysql_params['password'];
144
+
145
+ try {
146
+ $mysql->mysqldump($wp_mysql_params['db'], $mysql_dump_file);
147
+ } catch (Exception $e) {
148
+ $this->result->setError( $e->getMessage() );
149
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
150
+ return $this->result;
151
+ }
152
+ unset($mysql);
153
+
154
+ if (0 == (int)filesize($mysql_dump_file)) {
155
+ $log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
156
  $errors[] = $log;
157
  WPAdm_Core::log($log);
158
+ $this->result->setError( $log );
159
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
160
+ return $this->result;
161
  } else {
162
  $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
163
+ $log = str_replace("%size", $size_dump , __('Database Dump was successfully created ( %size Mb) : ','dropbox-backup') ) ;
164
+ WPAdm_Core::log($log . $mysql_dump_file);
165
  }
 
166
 
167
 
168
  WPAdm_Core::log('Start Created List Files');
198
  }
199
 
200
  WPAdm_Core::log('Сreated List Files is successfully');
201
+ //$this->queue->clear();
202
+ WPAdm_Core::log('Start archived files');
203
+ if (!class_exists('WPAdm_Archive')) {
204
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
205
+ }
206
  foreach($files2 as $files) {
207
+ $af = $this->getArchiveName($to_file);
208
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
209
+ $archive->setRemovePath(ABSPATH);
210
+ if ( !file_exists( $af ) ) {
211
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
212
+ }
213
+
214
+ if (file_exists($af) && filesize($af) > 900000) {
215
+ $af = $this->getNextArchiveName($to_file);
216
+ unset($archive);
217
+ if ( !file_exists( $af ) ) {
218
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
219
+ }
220
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
221
+ $archive->setRemovePath( ABSPATH );
222
+ }
223
+ $files_str = implode(',', $files);
224
+ $res = $archive->add($files_str);
225
+ if ($res) {
226
+
227
+ } else {
228
+ $this->result->setError( $archive->error );
229
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
230
+ return $this->result;
231
+ }
232
  }
 
 
 
 
233
  WPAdm_Core::log('End archived files');
234
 
235
  $files = glob($this->dir . '/'.$this->name . '*');
275
 
276
  }
277
 
278
+ private function getArchiveName($name)
279
+ {
280
+ //WPAdm_Core::log("{$name}-*.zip");
281
+ $archives = glob("{$name}-*.zip");
282
+ //WPAdm_Core::log( print_r($archives, 1) );
283
+ if (empty($archives)) {
284
+ return "{$name}-1.zip";
285
+ }
286
+ $n = count($archives);
287
+ $f = "{$name}-{$n}.zip";
288
+ return $f;
289
+ }
290
+
291
+ private function getNextArchiveName($name)
292
+ {
293
+ //WPAdm_Core::log("{$name}-*.zip");
294
+ $archives = glob("{$name}-*.zip");
295
+ $n = 1 + count($archives);
296
+ $a = "{$name}-{$n}.zip";
297
+ //WPAdm_Core::log($a);
298
+ return $a;
299
+ }
300
+
301
 
302
 
303
  public function createListFilesForArchive() {
307
  $files = array_merge(
308
  $files,
309
  array(
310
+ // ABSPATH .'/.htaccess',
311
  ABSPATH .'/index.php',
312
+ //ABSPATH .'/license.txt',
313
+ //ABSPATH .'/readme.html',
314
  ABSPATH .'/wp-activate.php',
315
  ABSPATH .'/wp-blog-header.php',
316
  ABSPATH .'/wp-comments-post.php',
317
  ABSPATH .'/wp-config.php',
318
+ //ABSPATH .'/wp-config-sample.php',
319
  ABSPATH .'/wp-cron.php',
320
  ABSPATH .'/wp-links-opml.php',
321
  ABSPATH .'/wp-load.php',
328
  )
329
  );
330
 
331
+ if ( file_exists(ABSPATH . '.htaccess') ) {
332
+ $files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
333
+ }
334
+ if ( file_exists( ABSPATH . 'license.txt' ) ) {
335
+ $files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
336
+ }
337
+ if ( file_exists( ABSPATH . 'readme.html' ) ) {
338
+ $files = array_merge( $files, array( ABSPATH . 'readme.html') );
339
+ }
340
+ if ( file_exists(ABSPATH . '.htaccess') ) {
341
+ $files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
342
+ }
343
+
344
  if (!empty($this->params['minus-path'])) {
345
  foreach($files as $k=>$v) {
346
  $v = str_replace(ABSPATH .'/' , '', $v);
347
  if (in_array($v, $this->params['minus-path'])) {
348
  unset($files[$k]);
349
+ WPAdm_Core::log('Skip of File ' . $v);
350
  }
351
  }
352
  }
359
  ABSPATH .'/wp-includes',
360
  )
361
  );
362
+ if (!empty($this->params['plus-path'])) {
363
+ foreach($this->params['plus-path'] as $p) {
364
+ if (empty($p)) {
365
+ continue;
366
+ }
367
+ $p = ABSPATH .'/' . $p;
368
+ if (file_exists($p)) {
369
+ if (is_dir($p)) {
370
+ $folders[] = $p;
371
+ } else{
372
+ $files[] = $p;
373
+ }
374
  }
375
  }
376
  }
397
  if (
398
  in_array($d, $this->params['minus-path'])
399
  ) {
400
+ WPAdm_Core::log('Skip of Folder ' . $directory);
401
  return array();
402
  }
403
 
412
  if (strpos($d2, 'cache') !== false
413
  && !in_array($tmp[0], array('plugins', 'themes'))
414
  ) {
415
+ WPAdm_Core::log('Skip of Cache-Folder ' . $directory);
416
  return array();
417
  }
418
  if(strpos($directory, 'wpadm_backups') !== false) {
431
  if (!is_dir($file)) {
432
  $ff = preg_replace("/\/\//si", "/", $file);
433
  $f = str_replace(ABSPATH . '/', '', $ff);
434
+ // Skip files
435
  if (!in_array($f, $this->params['minus-path'])) {
436
  $array_items[] = $ff;
437
  } else {
438
+ WPAdm_Core::log('Skip of File ' . $ff);
439
  }
440
  }
441
  } else {
443
  if (!is_dir($file)) {
444
  $ff = preg_replace("/\/\//si", "/", $file);
445
  $f = str_replace(ABSPATH . '/', '', $ff);
446
+ // skip folders
447
  if (!in_array($f, $this->params['minus-path'])) {
448
  $array_items[] = $ff;
449
  } else {
450
+ WPAdm_Core::log('Skip of Folder ' . $ff);
451
  }
452
  }
453
  }
460
 
461
 
462
  /*
463
+ * get access to mysql from params WP
464
  * return Array()
465
  */
466
  private function getWpMysqlParams()
483
 
484
 
485
  private function init(array $conf) {
486
+ //todo: norm
487
  $this->id = $conf['id'];
488
  $this->stime = $conf['stime'];
489
+ //$this->queue = new WPAdm_Queue($this->id);
490
  $this->type = $conf['type'];
491
  }
492
  }
methods/class-wpadm-method-full-backup-dropbox.php CHANGED
@@ -49,14 +49,16 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
49
  )
50
  );
51
 
52
-
 
 
53
  $name = get_option('siteurl');
54
 
55
  $name = str_replace("http://", '', $name);
56
  $name = str_replace("https://", '', $name);
57
  $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
58
- array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
59
- $name );
60
  $name = preg_replace("|\W|", "_", $name);
61
  $name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
62
  $this->name = $name;
@@ -98,46 +100,77 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
98
  }
99
  $wp_mysql_params = $this->getWpMysqlParams();
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
102
- WPAdm_Core::log( __('Table optimization','dropbox-backup') );
103
- $commandContext = new WPAdm_Command_Context();
104
- $commandContext ->addParam('command','mysqloptimize')
105
- ->addParam('host', $wp_mysql_params['host'])
106
- ->addParam('db', $wp_mysql_params['db'])
107
- ->addParam('user', $wp_mysql_params['user'])
108
- ->addParam('password', $wp_mysql_params['password']);
109
- $this->queue->clear()
110
- ->add($commandContext);
111
- unset($commandContext);
112
- }
113
-
114
- $commandContext = new WPAdm_Command_Context();
115
- $commandContext ->addParam('command','mysqldump')
116
- ->addParam('host', $wp_mysql_params['host'])
117
- ->addParam('db', $wp_mysql_params['db'])
118
- ->addParam('user', $wp_mysql_params['user'])
119
- ->addParam('password', $wp_mysql_params['password'])
120
- ->addParam('tables', '')
121
- ->addParam('to_file', $mysql_dump_file);
122
- $res = $this->queue->add($commandContext)
123
- ->save()
124
- ->execute();
125
- if (!$res) {
126
- $log = str_replace('%s', $this->queue->getError(), __('Error: Dump of Database wasn\'t created (%s)','dropbox-backup') );
127
- WPAdm_Core::log($log);
 
 
 
 
 
 
 
 
 
 
 
128
  $errors[] = $log;
129
- } elseif (0 == (int)@filesize($mysql_dump_file)) {
130
- $errors[] = __('MySQL Error: Database-Dump File is empty','dropbox-backup');
131
- WPAdm_Core::log(__('Dump of Database wasn\'t created (File of Database-Dump is empty!)','dropbox-backup'));
 
132
  } else {
133
  $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
134
- $log = str_replace("%s", $size_dump , __('Database Dump was successfully created ( %s Mb) : ','dropbox-backup') ) ;
135
  WPAdm_Core::log($log . $mysql_dump_file);
136
  }
137
- unset($commandContext);
138
 
139
-
140
- #ЗАРХИВИРУЕМ ФАЙЛЫ
141
  WPAdm_Core::log( __('Create a list of files for Backup','dropbox-backup') );
142
  $files = $this->createListFilesForArchive();
143
  if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
@@ -168,23 +201,39 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
168
  }
169
 
170
  WPAdm_Core::log( __('List of Backup-Files was successfully created','dropbox-backup') );
171
-
172
- $this->queue->clear();
173
-
 
 
 
174
  foreach($files2 as $files) {
175
- $commandContext = new WPAdm_Command_Context();
176
- $commandContext ->addParam('command','archive')
177
- ->addParam('files', $files)
178
- ->addParam('to_file', $this->dir . '/'.$this->name)
179
- ->addParam('max_file_size', 900000)
180
- ->addParam('remove_path', ABSPATH);
181
 
182
- $this->queue->add($commandContext);
183
- unset($commandContext);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  }
185
- WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
186
- $this->queue->save()
187
- ->execute();
188
  WPAdm_Core::log( __('End of File Backup','dropbox-backup') );
189
 
190
  $files = glob($this->dir . '/'.$this->name . '*');
@@ -199,125 +248,38 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
199
 
200
 
201
  $remove_from_server = 0;
202
- if (isset($this->params['storage'])) {
203
- foreach($this->params['storage'] as $storage) {
204
- if ($storage['type'] == 'ftp') {
205
- WPAdm_Core::log( __('Begin copying files to FTP','dropbox-backup') );
206
- $this->queue->clear();
207
- $files = glob($this->dir . '/'.$this->name . '*');
208
- //$this->getResult()->setData($files);
209
- $ad = $storage['access_details'];
210
- $dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
211
- $dir = trim($dir, '/') . '/' . $this->name;
212
- foreach($files as $file) {
213
- $commandContext = new WPAdm_Command_Context();
214
- $commandContext ->addParam('command','send_to_ftp')
215
- ->addParam('file', $file)
216
- ->addParam('host', $ad['host'])
217
- ->addParam('port', (isset($ad['port']))? $ad['port'] : 21)
218
- ->addParam('user', $ad['user'])
219
- ->addParam('password', $ad['password'])
220
- ->addParam('dir', $dir)
221
- ->addParam('http_host', isset($ad['http_host']) ? $ad['http_host'] : '');
222
- $this->queue->add($commandContext);
223
- unset($commandContext);
224
- }
225
- $res = $this->queue->save()
226
- ->execute();
227
- if (!$res) {
228
- $log = __('FTP: ' ,'dropbox-backup');
229
- WPAdm_Core::log($log . $this->queue->getError());
230
- $errors[] = $log . $this->queue->getError();
231
- }
232
- WPAdm_Core::log( __('Finished copying files to FTP' ,'dropbox-backup') );
233
- if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1 ) {
234
- $remove_from_server = $storage['remove_from_server'];
235
- }
236
- } elseif ($storage['type'] == 's3') {
237
- WPAdm_Core::log( __('Begin coping files to S3' ,'dropbox-backup') );
238
- $this->queue->clear();
239
- $files = glob($this->dir . '/'.$this->name . '*');
240
- //$this->getResult()->setData($files);
241
- $ad = $storage['access_details'];
242
- $dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
243
- $dir = trim($dir, '/') . '/' . $this->name;
244
- foreach($files as $file) {
245
- $commandContext = new WPAdm_Command_Context();
246
- $commandContext ->addParam('command','send_to_s3')
247
- ->addParam('file', $file)
248
- ->addParam('bucket', $ad['bucket'])
249
- ->addParam('AccessKeyId', $ad['AccessKeyId'])
250
- ->addParam('SecretAccessKey', $ad['SecretAccessKey'])
251
- ->addParam('SessionToken', $ad['SessionToken']);
252
- $this->queue->add($commandContext);
253
- unset($commandContext);
254
- }
255
- $res = $this->queue->save()
256
- ->execute();
257
- if (!$res) {
258
- WPAdm_Core::log('S3: ' . $this->queue->getError());
259
- $errors[] = 'S3: '.$this->queue->getError();
260
- }
261
- WPAdm_Core::log( __('Finished copying files to S3' ,'dropbox-backup') );
262
- if (isset($storage['remove_from_server']) && $storage['remove_from_server'] == 1 ) {
263
- $remove_from_server = $storage['remove_from_server'];
264
- }
265
- }
266
- }
267
- if ($remove_from_server) {
268
- // удаляем файлы на сервере
269
- WPAdm_Core::log( __('Remove the backup server' ,'dropbox-backup') );
270
- WPAdm_Core::rmdir($this->dir);
271
- }
272
-
273
- }
274
- if (isset($this->params['gd']) && isset($this->params['gd']['key']) && isset($this->params['gd']['secret'])) {
275
- $this->queue->clear();
276
- $files = glob($this->dir . '/' . $this->name . '*');
277
- $files = array_merge_recursive(array($mysql_dump_file), $files);
278
- WPAdm_Core::log( __('files to google: ' ,'dropbox-backup') . print_r($files, true));
279
- $n = count($files);
280
- for($i = 0; $i <$n; $i++) {
281
- $commandContext = new WPAdm_Command_Context();
282
- $commandContext->addParam('command', 'send_to_google_drive')
283
- ->addParam('key', $this->params['gd']['key'])
284
- ->addParam('secret', $this->params['gd']['secret'])
285
- ->addParam('token', $this->params['gd']['token'])
286
- ->addParam('folder_project', $this->params['gd']['folder'])
287
- ->addParam('folder', $this->name )
288
- ->addParam('files', $files[$i]);
289
- $this->queue->add($commandContext);
290
- unset($commandContext);
291
- }
292
- $res = $this->queue->save()
293
- ->execute();
294
- if (!$res) {
295
- WPAdm_Core::log( __('Google drive: ' ,'dropbox-backup') . $this->queue->getError());
296
- }
297
- //WPAdm_Core::log('google drive' . print_r($this->params, true));
298
- }
299
  if (isset($this->params['dropbox']) && isset($this->params['dropbox']['key']) && isset($this->params['dropbox']['secret'])) {
300
- $this->queue->clear();
301
  $files = glob($this->dir . '/' . $this->name . '*');
 
302
  $files = array_merge_recursive(array($mysql_dump_file), $files);
303
  WPAdm_Core::log( __('files to dropbox: ' ,'dropbox-backup') . print_r($files, true));
304
- $n = count($files);
305
- for($i = 0; $i <$n; $i++) {
306
- $commandContext = new WPAdm_Command_Context();
307
- $commandContext->addParam('command', 'send_to_dropbox')
308
- ->addParam('key', $this->params['dropbox']['key'])
309
- ->addParam('secret', $this->params['dropbox']['secret'])
310
- ->addParam('token', $this->params['dropbox']['token'])
311
- ->addParam('folder_project', $this->params['dropbox']['folder'])
312
- ->addParam('folder', $this->name)
313
- ->addParam('files', $files[$i]);
314
- $this->queue->add($commandContext);
315
- unset($commandContext);
316
  }
317
- $this->queue->save()
318
- ->execute();
319
- if (!$res) {
320
- WPAdm_Core::log(__('Dropbox: ' ,'dropbox-backup') . $this->queue->getError());
 
 
 
 
 
 
 
 
 
 
 
 
321
  }
322
  }
323
 
@@ -327,22 +289,25 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
327
  #Removind old backups(if limit the number of stored backups)
328
  WPAdm_Core::log( __('Start removing old backups' ,'dropbox-backup') );
329
  if ($this->params['limit'] != 0) {
330
- $files = glob(DROPBOX_BACKUP_DIR_BACKUP . '/*');
331
- if (count($files) > $this->params['limit']) {
332
- $files2 = array();
333
- foreach($files as $f) {
334
- $fa = explode('-', $f);
335
- if (count($fa) != 3) {
336
- continue;
 
 
 
337
  }
338
- $files2[$fa[2]] = $f;
339
-
340
  }
341
- ksort($files2);
342
- $d = count($files2) - $this->params['limit'];
343
- $del = array_slice($files2, 0, $d);
344
- foreach($del as $d) {
345
- WPAdm_Core::rmdir($d);
 
 
346
  }
347
  }
348
  }
@@ -370,15 +335,15 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
370
  $files = array_merge(
371
  $files,
372
  array(
373
- ABSPATH . '.htaccess',
374
  ABSPATH . 'index.php',
375
- ABSPATH . 'license.txt',
376
- ABSPATH . 'readme.html',
377
  ABSPATH . 'wp-activate.php',
378
  ABSPATH . 'wp-blog-header.php',
379
  ABSPATH . 'wp-comments-post.php',
380
  ABSPATH . 'wp-config.php',
381
- ABSPATH . 'wp-config-sample.php',
382
  ABSPATH . 'wp-cron.php',
383
  ABSPATH . 'wp-links-opml.php',
384
  ABSPATH . 'wp-load.php',
@@ -390,6 +355,21 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
390
  ABSPATH . 'xmlrpc.php',
391
  )
392
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
 
394
  if (!empty($this->params['minus-path'])) {
395
  $minus_path = explode(",", $this->params['minus-path']);
@@ -532,5 +512,28 @@ if (!class_exists('WPadm_Method_Full_Backup_Dropbox')) {
532
  $this->stime = $conf['stime'];
533
  $this->queue = new WPAdm_Queue($this->id);
534
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  }
536
  }
49
  )
50
  );
51
 
52
+ if (!class_exists('WPAdm_Process')) {
53
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
54
+ }
55
  $name = get_option('siteurl');
56
 
57
  $name = str_replace("http://", '', $name);
58
  $name = str_replace("https://", '', $name);
59
  $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
60
+ array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
61
+ $name );
62
  $name = preg_replace("|\W|", "_", $name);
63
  $name .= '-' . $this->type . '-' . date("Y_m_d_H_i");
64
  $this->name = $name;
100
  }
101
  $wp_mysql_params = $this->getWpMysqlParams();
102
 
103
+ if ( isset($this->params['repair']) && ( $this->params['repair'] == 1 ) ) {
104
+ if ( WPAdm_Running::is_stop() ) {
105
+ if (!class_exists('WPAdm_Mysqldump')) {
106
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
107
+ }
108
+
109
+ $mysql = new WPAdm_Mysqldump();
110
+ $mysql->host = $wp_mysql_params['host'];
111
+ $mysql->user = $wp_mysql_params['user'];
112
+ $mysql->password = $wp_mysql_params['password'];
113
+ try {
114
+ $mysql->repair($wp_mysql_params['db']);
115
+ unset($mysql);
116
+ } catch (Exception $e) {
117
+ $this->result->setError( $e->getMessage() );
118
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
119
+ return $this->result;
120
+ }
121
+ unset($mysql);
122
+ }
123
+ }
124
+
125
  if (isset($this->params['optimize']) && ($this->params['optimize']==1)) {
126
+ WPAdm_Core::log(__('Optimize Database Tables','dropbox-backup'));
127
+ if (!class_exists('WPAdm_Mysqldump')) {
128
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
129
+ }
130
+ $mysql = new WPAdm_Mysqldump();
131
+ $mysql->host = $wp_mysql_params['host'];
132
+ $mysql->user = $wp_mysql_params['user'];
133
+ $mysql->password = $wp_mysql_params['password'];
134
+ try {
135
+ $mysql->optimize($wp_mysql_params['db']);
136
+ } catch (Exception $e) {
137
+ $this->result->setError( $e->getMessage() );
138
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
139
+ return $this->result;
140
+ }
141
+ unset($mysql);
142
+ }
143
+
144
+ if (!class_exists('WPAdm_Mysqldump')) {
145
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
146
+ }
147
+ $mysql = new WPAdm_Mysqldump();
148
+ $mysql->host = $wp_mysql_params['host'];
149
+ $mysql->user = $wp_mysql_params['user'];
150
+ $mysql->password = $wp_mysql_params['password'];
151
+
152
+ try {
153
+ $mysql->mysqldump($wp_mysql_params['db'], $mysql_dump_file);
154
+ } catch (Exception $e) {
155
+ $this->result->setError( $e->getMessage() );
156
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
157
+ return $this->result;
158
+ }
159
+ unset($mysql);
160
+
161
+ if (0 == (int)filesize($mysql_dump_file)) {
162
+ $log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
163
  $errors[] = $log;
164
+ WPAdm_Core::log($log);
165
+ $this->result->setError( $log );
166
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
167
+ return $this->result;
168
  } else {
169
  $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
170
+ $log = str_replace("%size", $size_dump , __('Database Dump was successfully created ( %size Mb) : ','dropbox-backup') ) ;
171
  WPAdm_Core::log($log . $mysql_dump_file);
172
  }
 
173
 
 
 
174
  WPAdm_Core::log( __('Create a list of files for Backup','dropbox-backup') );
175
  $files = $this->createListFilesForArchive();
176
  if (file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
201
  }
202
 
203
  WPAdm_Core::log( __('List of Backup-Files was successfully created','dropbox-backup') );
204
+ WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
205
+ //$this->queue->clear();
206
+ if (!class_exists('WPAdm_Archive')) {
207
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
208
+ }
209
+ $to_file = $this->dir . '/' . $this->name;
210
  foreach($files2 as $files) {
211
+ $af = $this->getArchiveName($to_file);
212
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
213
+ $archive->setRemovePath(ABSPATH);
214
+ if ( !file_exists( $af ) ) {
215
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
216
+ }
217
 
218
+ if (file_exists($af) && filesize($af) > 900000) {
219
+ $af = $this->getNextArchiveName($to_file);
220
+ unset($archive);
221
+ if ( !file_exists( $af ) ) {
222
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
223
+ }
224
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
225
+ $archive->setRemovePath( ABSPATH );
226
+ }
227
+ $files_str = implode(',', $files);
228
+ $res = $archive->add($files_str);
229
+ if ($res) {
230
+
231
+ } else {
232
+ $this->result->setError( $archive->error );
233
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
234
+ return $this->result;
235
+ }
236
  }
 
 
 
237
  WPAdm_Core::log( __('End of File Backup','dropbox-backup') );
238
 
239
  $files = glob($this->dir . '/'.$this->name . '*');
248
 
249
 
250
  $remove_from_server = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  if (isset($this->params['dropbox']) && isset($this->params['dropbox']['key']) && isset($this->params['dropbox']['secret'])) {
 
252
  $files = glob($this->dir . '/' . $this->name . '*');
253
+ require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
254
  $files = array_merge_recursive(array($mysql_dump_file), $files);
255
  WPAdm_Core::log( __('files to dropbox: ' ,'dropbox-backup') . print_r($files, true));
256
+ $n = count($files);
257
+ $folder_project_temp = $this->params['dropbox']['folder'];
258
+ $folder_project = "";
259
+ $dir = $this->name;
260
+ if (!empty($folder_project_temp)) {
261
+ $folder_project = $folder_project_temp . "/";
262
+ $dropbox->createDir($folder_project_temp );
263
+ $dropbox->createDir($folder_project . $dir );
264
+ } else {
265
+ $dropbox->createDir( $dir );
 
 
266
  }
267
+ for($i = 0; $i <$n; $i++) {
268
+ $file_ = explode("/", $files[$i]);
269
+ $file_name = array_pop($file_);
270
+ $fromFile = str_replace('//', '/', $files[$i]);
271
+ $toFile = str_replace('//', '/', $folder_project . $dir . '/' . $file_name);
272
+
273
+ $res = $dropbox->uploadFile($fromFile, $toFile, true);
274
+
275
+ if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
276
+ $this->result->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"' );
277
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
278
+ return $this->result;
279
+ }
280
+ if (isset($res['size']) && isset($res['client_mtime'])) {
281
+ WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $file ) . __(' size: ' ,'dropbox-backup') . $res['size']);
282
+ }
283
  }
284
  }
285
 
289
  #Removind old backups(if limit the number of stored backups)
290
  WPAdm_Core::log( __('Start removing old backups' ,'dropbox-backup') );
291
  if ($this->params['limit'] != 0) {
292
+ if (is_dir(DROPBOX_BACKUP_DIR_BACKUP)) {
293
+ $dir_open = opendir(DROPBOX_BACKUP_DIR_BACKUP);
294
+ $files2 = array();
295
+ while ($read_dir = readdir($dir_open)) {
296
+ if ($read_dir != '.' && $read_dir != '..' && is_dir( DROPBOX_BACKUP_DIR_BACKUP . "/$read_dir")) {
297
+ $fa = explode('-', $read_dir);
298
+ if (count($fa) != 3) {
299
+ continue;
300
+ }
301
+ $files2[$fa[2]] = $f;
302
  }
 
 
303
  }
304
+ if ( ( $n = count($files2) ) > $this->params['limit']) {
305
+ ksort($files2);
306
+ $d = count($files2) - $this->params['limit'];
307
+ $del = array_slice($files2, 0, $d);
308
+ foreach($del as $d) {
309
+ WPAdm_Core::rmdir($d);
310
+ }
311
  }
312
  }
313
  }
335
  $files = array_merge(
336
  $files,
337
  array(
338
+ // ABSPATH . '.htaccess',
339
  ABSPATH . 'index.php',
340
+ // ABSPATH . 'license.txt',
341
+ // ABSPATH . 'readme.html',
342
  ABSPATH . 'wp-activate.php',
343
  ABSPATH . 'wp-blog-header.php',
344
  ABSPATH . 'wp-comments-post.php',
345
  ABSPATH . 'wp-config.php',
346
+ // ABSPATH . 'wp-config-sample.php',
347
  ABSPATH . 'wp-cron.php',
348
  ABSPATH . 'wp-links-opml.php',
349
  ABSPATH . 'wp-load.php',
355
  ABSPATH . 'xmlrpc.php',
356
  )
357
  );
358
+ if ( file_exists(ABSPATH . '.htaccess') ) {
359
+ $files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
360
+ }
361
+ if ( file_exists( ABSPATH . 'license.txt' ) ) {
362
+ $files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
363
+ }
364
+ if ( file_exists( ABSPATH . 'readme.html' ) ) {
365
+ $files = array_merge( $files, array( ABSPATH . 'readme.html') );
366
+ }
367
+ if ( file_exists(ABSPATH . '.htaccess') ) {
368
+ $files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
369
+ }
370
+ if ( file_exists(ABSPATH . 'robots.txt') ) {
371
+ $files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
372
+ }
373
 
374
  if (!empty($this->params['minus-path'])) {
375
  $minus_path = explode(",", $this->params['minus-path']);
512
  $this->stime = $conf['stime'];
513
  $this->queue = new WPAdm_Queue($this->id);
514
  }
515
+
516
+ private function getArchiveName($name)
517
+ {
518
+ //WPAdm_Core::log("{$name}-*.zip");
519
+ $archives = glob("{$name}-*.zip");
520
+ //WPAdm_Core::log( print_r($archives, 1) );
521
+ if (empty($archives)) {
522
+ return "{$name}-1.zip";
523
+ }
524
+ $n = count($archives);
525
+ $f = "{$name}-{$n}.zip";
526
+ return $f;
527
+ }
528
+
529
+ private function getNextArchiveName($name)
530
+ {
531
+ //WPAdm_Core::log("{$name}-*.zip");
532
+ $archives = glob("{$name}-*.zip");
533
+ $n = 1 + count($archives);
534
+ $a = "{$name}-{$n}.zip";
535
+ //WPAdm_Core::log($a);
536
+ return $a;
537
+ }
538
  }
539
  }
methods/class-wpadm-method-local-backup.php CHANGED
@@ -7,48 +7,62 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
7
 
8
  public function __construct($params)
9
  {
10
- parent::__construct($params);
11
- $this->init(
12
- array(
13
- 'id' => uniqid('wpadm_method__local_backup__'),
14
- 'stime' => time(),
15
- )
16
- );
17
 
18
- WPAdm_Core::log(__('Create Unique Id ','dropbox-backup') . $this->id);
 
 
 
 
 
 
 
19
 
 
20
 
21
- $name = get_option('siteurl');
22
 
23
- $name = str_replace("http://", '', $name);
24
- $name = str_replace("https://", '', $name);
25
- $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
26
- array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
27
- $name );
28
- $name = preg_replace("|\W|", "_", $name);
29
- if (isset($params['time']) && !empty($params['time'])) { // time 1432751372
30
- $this->time = date("Y-m-d H:i", $params['time']);
31
- $name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $params['time']);
32
- } else {
33
- $this->time = date("Y-m-d H:i"); //23.04.2015 13:45
34
- $name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i");
35
- }
36
- $this->name = $name;
37
 
38
- // folder for backup
39
- $this->dir = DROPBOX_BACKUP_DIR_BACKUP . '/' . $name;
40
- if (($f = $this->checkBackup()) !== false) {
41
- $this->dir = DROPBOX_BACKUP_DIR_BACKUP . '/' . $f;
42
- }
43
- $error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
44
- if (!empty($error)) {
45
- $this->result->setError($error);
46
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
47
- }
48
- $error = WPAdm_Core::mkdir($this->dir);
49
- if (!empty($error)) {
50
- $this->result->setError($error);
51
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
  }
54
  public function checkBackup()
@@ -68,217 +82,311 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
68
  {
69
 
70
  $errors = array();
71
-
72
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
73
- $this->result->setError('');
74
- WPAdm_Core::log(__('Start Backup process...','dropbox-backup'));
75
-
76
- # create db dump
77
- if (in_array('db', $this->params['types']) ) {
78
- $mysql_dump_file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql';
79
- if ( !WPAdm_Running::getCommandResult('db') ) {
80
- WPAdm_Running::setCommandResult('db');
81
- WPAdm_Core::log(__('Creating Database Dump','dropbox-backup'));
82
- $error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
83
- if (!empty($error)) {
84
- $this->result->setError($error);
85
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
86
- return $this->result;
87
- }
88
- if (file_exists($mysql_dump_file) && !file_exists(WPAdm_Core::getTmpDir() . "/db")) {
89
- unlink($mysql_dump_file);
90
- }
91
- $wp_mysql_params = $this->getWpMysqlParams();
92
-
93
- if ( isset($this->params['repair']) && ( $this->params['repair'] == 1 ) ) {
94
- require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
95
- $mysql = new WPAdm_Mysqldump();
96
- $mysql->host = $wp_mysql_params['host'];
97
- $mysql->user = $wp_mysql_params['user'];
98
- $mysql->password = $wp_mysql_params['password'];
99
- try {
100
- $mysql->repair($wp_mysql_params['db']);
101
- } catch (Exception $e) {
102
- $this->result->setError( $e->getMessage() );
103
  $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
104
- return false;
105
- }
106
-
107
- }
 
 
 
 
 
 
 
 
108
 
109
- if (isset($this->params['optimize']) && ($this->params['optimize']==1 ) ) {
110
- $opt_db = WPAdm_Running::getCommandResultData('db', $proc_data);
111
- if (!isset($opt_db['optimize'])) {
112
- WPAdm_Core::log(__('Optimize Database Tables','dropbox-backup'));
113
- $commandContext = new WPAdm_Command_Context();
114
- $commandContext ->addParam('command','mysqloptimize')
115
- ->addParam('host', $wp_mysql_params['host'])
116
- ->addParam('db', $wp_mysql_params['db'])
117
- ->addParam('user', $wp_mysql_params['user'])
118
- ->addParam('password', $wp_mysql_params['password']);
119
- $this->queue->clear()
120
- ->add($commandContext);
121
- unset($commandContext);
 
122
  }
123
- }
124
-
125
-
126
-
127
- $commandContext = new WPAdm_Command_Context();
128
- $commandContext ->addParam('command','mysqldump')
129
- ->addParam('host', $wp_mysql_params['host'])
130
- ->addParam('db', $wp_mysql_params['db'])
131
- ->addParam('user', $wp_mysql_params['user'])
132
- ->addParam('password', $wp_mysql_params['password'])
133
- ->addParam('tables', '')
134
- ->addParam('to_file', $mysql_dump_file);
135
- $res = $this->queue->add($commandContext)
136
- ->save()
137
- ->execute();
138
- if (!$res) {
139
- $log = str_replace(array('%domain', '%s'), array(SITE_HOME, $this->queue->getError() ), __('Website "%domain" returned an error during database dump creation: \'Dump of Database wasn\'t created: "%s"\'. To solve this problem, please check your database system logs or send to us your FTP access data. You can send to us support request using "Help" button on plugin page.','dropbox-backup') );
140
- WPAdm_Core::log($log);
141
- $errors[] = $log;
142
- } elseif (0 == (int)filesize($mysql_dump_file)) {
143
- $log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
144
- $errors[] = $log;
145
- WPAdm_Core::log($log);
146
- } else {
147
- $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
148
- $log = str_replace("%size", $size_dump , __('Database Dump was successfully created ( %size Mb) : ','dropbox-backup') ) ;
149
- WPAdm_Core::log($log . $mysql_dump_file);
150
- }
151
- unset($commandContext);
152
- WPAdm_Running::setCommandResult('db', true);
153
- }
154
- }
155
 
156
- if (count($errors) == 0) {
157
- $command_files_list = WPAdm_Running::getCommandResultData('files');
158
- if (in_array('files', $this->params['types']) && empty($command_files_list) ) {
159
- $files = $this->createListFilesForArchive();
160
- WPAdm_Running::setCommandResultData('files', $files);
161
- } else {
162
- $files = $command_files_list;
163
- }
164
- if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
165
- $files[] = $mysql_dump_file;
166
- }
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
- if (empty($files)) {
169
- $errors[] = str_replace(array('%d'), array(SITE_HOME), __( 'Website "%d" returned an error during creation of the list of files for a backup: list of files for a backup is empty. To solve this problem, please check files and folders permissions for website "%d".' ,'dropbox-backup') );
170
- }
171
 
172
- // split the file list by 170kbayt lists, To break one big task into smaller
173
- $files2 = WPAdm_Running::getCommandResultData('files2');
174
- if (empty($files2)) {
175
- $files2 = array();
176
- $files2[0] = array();
177
- $i = 0;
178
- $size = 0;
179
- foreach($files as $f) {
180
- if ($size > 170000) {//~170kbyte
181
- $i ++;
182
- $size = 0;
183
- $files2[$i] = array();
184
- }
185
- $f_size =(int)@filesize($f);
186
- if ($f_size == 0 || $f_size > 1000000) {
187
- WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
189
- $size += $f_size;
190
- $files2[$i][] = $f;
191
  }
192
- WPAdm_Running::setCommandResultData('files2', $files2);
193
  }
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
- WPAdm_Core::log(__('List of Backup-Files was successfully created','dropbox-backup') );
197
- $this->queue->clear();
198
- if ( !WPAdm_Running::getCommandResult('archive') ) {
199
- WPAdm_Running::setCommandResult('archive');
200
- $files_archive = WPAdm_Running::getCommandResultData('archive');
201
- foreach($files2 as $files) {
202
- $files_str = implode(',', $files);
203
- if (!in_array($files_str, $files_archive)) {
204
- $commandContext = new WPAdm_Command_Context();
205
- $commandContext ->addParam('command', 'archive')
206
- ->addParam('files', $files)
207
- ->addParam('to_file', $this->dir . '/' . $this->name)
208
- ->addParam('max_file_size', 900000)
209
- ->addParam('remove_path', ABSPATH);
210
-
211
- $this->queue->add($commandContext);
212
- unset($commandContext);
 
 
 
 
 
213
  }
 
 
214
  }
215
- WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
216
- $this->queue->save()->execute();
217
- WPAdm_Core::log( __('End of File Backup','dropbox-backup') );
218
- WPAdm_Running::setCommandResult('archive', true);
219
- }
220
- $files = glob($this->dir . '/'.$this->name . '*');
221
- $urls = array();
222
- $totalSize = 0;
223
- foreach($files as $file) {
224
- $urls[] = str_replace(ABSPATH, '', $file);
225
- $totalSize += @intval( filesize($file) );
226
- }
227
- $this->result->setData($urls);
228
- $this->result->setSize($totalSize);
229
- $this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
230
- $this->result->setValue('name', $this->name );
231
- $this->result->setValue('time', $this->time);
232
- $this->result->setValue('type', 'local');
233
- $this->result->setValue('counts', count($urls) );
234
- $size = $totalSize / 1024 / 1024; /// MByte
235
- $size = round($size, 2);
236
- $log = str_replace("%s", $size , __('Backup Size %s Mb','dropbox-backup') ) ;
237
- WPAdm_Core::log($log);
238
-
239
- $remove_from_server = 0;
240
- #Removing TMP-files
241
- WPAdm_Core::rmdir($mysql_dump_file);
242
-
243
- #Removind old backups(if limit the number of stored backups)
244
- if ($this->params['limit'] != 0) {
245
- WPAdm_Core::log( __('Limits of Backups ','dropbox-backup') . $this->params['limit'] );
246
- WPAdm_Core::log( __('Removing of old Backups was started','dropbox-backup') );
247
- $files = glob(DROPBOX_BACKUP_DIR_BACKUP . '/*');
248
- if (count($files) > $this->params['limit']) {
249
- $files2 = array();
250
- foreach($files as $f) {
251
- $fa = explode('-', $f);
252
- if (count($fa) != 3) {
253
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
255
- $files2[$fa[2]] = $f;
 
 
256
 
257
  }
258
- ksort($files2);
259
- $d = count($files2) - $this->params['limit'];
260
- $del = array_slice($files2, 0, $d);
261
- foreach($del as $d) {
262
- WPAdm_Core::rmdir($d);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  }
 
 
264
  }
265
- WPAdm_Core::log( __('Removing of old Backups was Finished','dropbox-backup') );
266
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
268
- wpadm_class::setBackup(1);
269
- if (!empty($errors)) {
270
- $this->result->setError(implode("\n", $errors));
271
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
272
- WPAdm_Core::rmdir($this->dir);
273
- wpadm_class::setStatus(0);
274
- wpadm_class::setErrors( implode(", ", $errors) );
275
- } else {
276
- wpadm_class::setStatus(1);
277
- WPAdm_Core::log( __('Backup creation was complete successfully!','dropbox-backup') );
278
- }
279
- wpadm_class::backupSend();
280
-
281
- return $this->result;
282
 
283
  }
284
  public function createListFilesForArchive()
@@ -289,15 +397,15 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
289
  $files = array_merge(
290
  $files,
291
  array(
292
- ABSPATH . '.htaccess',
293
  ABSPATH . 'index.php',
294
- ABSPATH . 'license.txt',
295
- ABSPATH . 'readme.html',
296
  ABSPATH . 'wp-activate.php',
297
  ABSPATH . 'wp-blog-header.php',
298
  ABSPATH . 'wp-comments-post.php',
299
  ABSPATH . 'wp-config.php',
300
- ABSPATH . 'wp-config-sample.php',
301
  ABSPATH . 'wp-cron.php',
302
  ABSPATH . 'wp-links-opml.php',
303
  ABSPATH . 'wp-load.php',
@@ -309,6 +417,21 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
309
  ABSPATH . 'xmlrpc.php',
310
  )
311
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
  if (!empty($this->params['minus-path'])) {
314
  $minus_path = explode(",", $this->params['minus-path']);
@@ -389,8 +512,8 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
389
 
390
  if ($handle = opendir($directory)) {
391
  while (false !== ($file = readdir($handle))) {
392
- if ($file != "." && $file != "..") {
393
- if (is_dir($directory. "/" . $file)) {
394
  if($recursive) {
395
  $array_items = array_merge($array_items, $this->directoryToArray($directory. "/" . $file, $recursive));
396
  }
@@ -453,7 +576,30 @@ if (!class_exists('WPAdm_Method_Local_Backup')) {
453
  private function init(array $conf) {
454
  $this->id = $conf['id'];
455
  $this->stime = $conf['stime'];
456
- $this->queue = new WPAdm_Queue($this->id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  }
458
  }
459
  }
7
 
8
  public function __construct($params)
9
  {
 
 
 
 
 
 
 
10
 
11
+ if ( WPAdm_Running::is_stop() ) {
12
+ parent::__construct($params);
13
+ $this->init(
14
+ array(
15
+ 'id' => uniqid('wpadm_method__local_backup__'),
16
+ 'stime' => time(),
17
+ )
18
+ );
19
 
20
+ WPAdm_Core::log(__('Create Unique Id ','dropbox-backup') . $this->id);
21
 
 
22
 
23
+ $name = get_option('siteurl');
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ if (!class_exists('WPAdm_Process')) {
26
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
27
+ }
28
+
29
+ $name = str_replace("http://", '', $name);
30
+ $name = str_replace("https://", '', $name);
31
+ $name = str_ireplace( array( 'Ä', 'ä', 'Ö', 'ö', 'ß', 'Ü', 'ü', 'å'),
32
+ array('ae', 'ae', 'oe', 'oe', 's', 'ue', 'ue', 'a'),
33
+ $name );
34
+ $name = preg_replace("|\W|", "_", $name);
35
+ if (isset($params['time']) && !empty($params['time'])) { // time 1432751372
36
+ $this->time = date("Y-m-d H:i", $params['time']);
37
+ $name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $params['time']);
38
+ } else {
39
+ $this->time = date("Y-m-d H:i"); //23.04.2015 13:45
40
+ $name .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i");
41
+ }
42
+ $this->name = $name;
43
+
44
+ // folder for backup
45
+
46
+ $this->dir = DROPBOX_BACKUP_DIR_BACKUP . '/' . $name;
47
+ $opt_folder = WPAdm_Running::getCommandResultData('folder_create');
48
+ if (!isset($opt_folder[$name])) {
49
+ if (($f = $this->checkBackup()) !== false) {
50
+ $this->dir = DROPBOX_BACKUP_DIR_BACKUP . '/' . $f;
51
+ }
52
+ $error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
53
+ if (!empty($error)) {
54
+ $this->result->setError($error);
55
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
56
+ }
57
+ $error = WPAdm_Core::mkdir($this->dir);
58
+ if (!empty($error)) {
59
+ $this->result->setError($error);
60
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
61
+ }
62
+ $opt_folder = WPAdm_Running::getCommandResultData('folder_create');
63
+ $opt_folder[$name] = true;
64
+ WPAdm_Running::setCommandResultData('folder_create', $opt_folder);
65
+ }
66
  }
67
  }
68
  public function checkBackup()
82
  {
83
 
84
  $errors = array();
85
+ if ( WPAdm_Running::is_stop() ) {
86
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
87
+ $this->result->setError('');
88
+ WPAdm_Core::log(__('Start Backup process...', 'dropbox-backup'));
89
+
90
+ # create db dump
91
+ if (in_array('db', $this->params['types']) ) {
92
+ $mysql_dump_file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql';
93
+ if ( !WPAdm_Running::getCommandResult('db') ) {
94
+ WPAdm_Running::setCommandResult('db');
95
+ WPAdm_Core::log(__('Creating Database Dump','dropbox-backup'));
96
+ $error = WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
97
+ if (!empty($error)) {
98
+ $this->result->setError($error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
100
+ return $this->result;
101
+ }
102
+ if (file_exists($mysql_dump_file) && !file_exists(WPAdm_Core::getTmpDir() . "/db")) {
103
+ unlink($mysql_dump_file);
104
+ }
105
+ $wp_mysql_params = $this->getWpMysqlParams();
106
+
107
+ if ( isset($this->params['repair']) && ( $this->params['repair'] == 1 ) ) {
108
+ if ( WPAdm_Running::is_stop() ) {
109
+ if (!class_exists('WPAdm_Mysqldump')) {
110
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
111
+ }
112
 
113
+ $mysql = new WPAdm_Mysqldump();
114
+ $mysql->host = $wp_mysql_params['host'];
115
+ $mysql->user = $wp_mysql_params['user'];
116
+ $mysql->password = $wp_mysql_params['password'];
117
+ try {
118
+ $mysql->repair($wp_mysql_params['db']);
119
+ unset($mysql);
120
+ } catch (Exception $e) {
121
+ $this->result->setError( $e->getMessage() );
122
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
123
+ return $this->result;
124
+ }
125
+ unset($mysql);
126
+ }
127
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
+ if (isset($this->params['optimize']) && ($this->params['optimize'] == 1 ) ) {
130
+ $opt_db = WPAdm_Running::getCommandResultData('db');
131
+ if (!isset($opt_db['optimize'])) {
132
+ if ( WPAdm_Running::is_stop() ) {
133
+ WPAdm_Core::log(__('Optimize Database Tables','dropbox-backup'));
134
+ if (!class_exists('WPAdm_Mysqldump')) {
135
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
136
+ }
137
+ $mysql = new WPAdm_Mysqldump();
138
+ $mysql->host = $wp_mysql_params['host'];
139
+ $mysql->user = $wp_mysql_params['user'];
140
+ $mysql->password = $wp_mysql_params['password'];
141
+ try {
142
+ $mysql->optimize($wp_mysql_params['db']);
143
+ } catch (Exception $e) {
144
+ $this->result->setError( $e->getMessage() );
145
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
146
+ return $this->result;
147
+ }
148
+ unset($mysql);
149
+ }
150
+ }
151
+ }
152
 
 
 
 
153
 
154
+ if ( WPAdm_Running::is_stop() ) {
155
+ if ( WPAdm_Running::getCommandResult('db') === false) {
156
+
157
+ if (!class_exists('WPAdm_Mysqldump')) {
158
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-mysqldump.php';
159
+ }
160
+ $mysql = new WPAdm_Mysqldump();
161
+ $mysql->host = $wp_mysql_params['host'];
162
+ $mysql->user = $wp_mysql_params['user'];
163
+ $mysql->password = $wp_mysql_params['password'];
164
+
165
+ try {
166
+ $mysql->mysqldump($wp_mysql_params['db'], $mysql_dump_file);
167
+ } catch (Exception $e) {
168
+ $this->result->setError( $e->getMessage() );
169
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
170
+ return $this->result;
171
+ }
172
+ unset($mysql);
173
+
174
+ if (0 == (int)filesize($mysql_dump_file)) {
175
+ $log = str_replace(array('%domain', '%dir'), array(SITE_HOME, DROPBOX_BACKUP_DIR_BACKUP), __('Website "%domain" returned an error during database dump creation: Database-Dump file is emplty. To solve this problem, please check permissions to folder: "%dir".','dropbox-backup') );
176
+ $errors[] = $log;
177
+ WPAdm_Core::log($log);
178
+ $this->result->setError( $log );
179
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
180
+ return $this->result;
181
+ } else {
182
+ $size_dump = round( (filesize($mysql_dump_file) / 1024 / 1024) , 2);
183
+ $log = str_replace("%size", $size_dump , __('Database Dump was successfully created ( %size Mb) : ','dropbox-backup') ) ;
184
+ WPAdm_Core::log($log . $mysql_dump_file);
185
+ }
186
+ WPAdm_Running::setCommandResult('db', true);
187
+ }
188
  }
 
 
189
  }
 
190
  }
191
 
192
+ if (count($errors) == 0) {
193
+ if ( WPAdm_Running::is_stop() ) {
194
+ $command_files_list = WPAdm_Running::getCommandResultData('files');
195
+ if (in_array('files', $this->params['types']) && empty($command_files_list) ) {
196
+ $files = $this->createListFilesForArchive();
197
+ WPAdm_Running::setCommandResultData('files', $files);
198
+ } else {
199
+ $files = $command_files_list;
200
+ }
201
+ if (isset($mysql_dump_file) && file_exists($mysql_dump_file) && filesize($mysql_dump_file) > 0) {
202
+ $files[] = $mysql_dump_file;
203
+ }
204
+ WPAdm_Process::init('archiving', count($files) );
205
+ if (empty($files)) {
206
+ $errors[] = str_replace(array('%d'), array(SITE_HOME), __( 'Website "%d" returned an error during creation of the list of files for a backup: list of files for a backup is empty. To solve this problem, please check files and folders permissions for website "%d".' ,'dropbox-backup') );
207
+ }
208
+ } else {
209
+ return true;
210
+ }
211
 
212
+ // split the file list by 170kbayt lists, To break one big task into smaller
213
+ if ( WPAdm_Running::is_stop() ) {
214
+ $files2 = WPAdm_Running::getCommandResultData('files2');
215
+ if (empty($files2)) {
216
+ $files2 = array();
217
+ $files2[0] = array();
218
+ $i = 0;
219
+ $size = 0;
220
+ foreach($files as $f) {
221
+ if ($size > 170000) {//~170kbyte
222
+ $i ++;
223
+ $size = 0;
224
+ $files2[$i] = array();
225
+ }
226
+ $f_size =(int)@filesize($f);
227
+ if ($f_size == 0 || $f_size > 1000000) {
228
+ WPAdm_Core::log('File ' . $f . ' Size ' . $f_size);
229
+ }
230
+ $size += $f_size;
231
+ $files2[$i][] = $f;
232
+ }
233
+ WPAdm_Running::setCommandResultData('files2', $files2);
234
  }
235
+ } else {
236
+ return true;
237
  }
238
+
239
+
240
+ WPAdm_Core::log(__('List of Backup-Files was successfully created','dropbox-backup') );
241
+ //$this->queue->clear();
242
+ if ( !WPAdm_Running::getCommandResult('archive') ) {
243
+ if ( WPAdm_Running::is_stop() ) {
244
+ WPAdm_Running::setCommandResult('archive');
245
+ $files_archive = WPAdm_Running::getCommandResultData('archive');
246
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-archive.php';
247
+ ini_set("memory_limit", "256M"); // files for archive
248
+ $to_file = $this->dir . '/' . $this->name;
249
+ foreach($files2 as $key => $files) {
250
+ $md5 = md5( print_r( $files, 1 ) );
251
+ if ( !isset($files_archive[$md5]) ) {
252
+ if ( WPAdm_Running::is_stop() ) {
253
+ $af = $this->getArchiveName($to_file);
254
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
255
+ $archive->setRemovePath(ABSPATH);
256
+ if ( !file_exists( $af ) ) {
257
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
258
+ }
259
+ }
260
+ if (file_exists($af) && filesize($af) > 900000) {
261
+ if ( WPAdm_Running::is_stop() ) {
262
+ $af = $this->getNextArchiveName($to_file);
263
+ unset($archive);
264
+ if ( !file_exists( $af ) ) {
265
+ WPAdm_Core::log(__('Create part ','dropbox-backup') . basename( $af ) );
266
+ }
267
+ $archive = new WPAdm_Archive($af, $to_file . '.md5');
268
+ $archive->setRemovePath( ABSPATH );
269
+ } else {
270
+ return true;
271
+ }
272
+ }
273
+ if ( WPAdm_Running::is_stop() ) {
274
+ $md5 = md5( print_r( $files, 1 ) );
275
+ $files_str = implode(',', $files);
276
+ $files_archive = WPAdm_Running::getCommandResultData('archive');
277
+ if ( WPAdm_Running::is_stop() ) {
278
+ if ( !isset($files_archive[$md5]) ) {
279
+ if ( WPAdm_Running::is_stop() ) {
280
+ $res = $archive->add($files_str);
281
+ if ($res) {
282
+ $files_archive = WPAdm_Running::getCommandResultData('archive');
283
+ $files_archive[$md5] = 1;
284
+ WPAdm_Running::setCommandResultData('archive', $files_archive);
285
+ WPAdm_Process::setInc( 'archiving', count($files) );
286
+ } else {
287
+ $this->result->setError( $archive->error );
288
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
289
+ return $this->result;
290
+ }
291
+ } else {
292
+ return true;
293
+ }
294
+ }
295
+ } else {
296
+ return true;
297
+ }
298
+ }
299
+ /*$commandContext = new WPAdm_Command_Context();
300
+ $commandContext ->addParam('command', 'archive')
301
+ ->addParam('files', $files)
302
+ ->addParam('to_file', $this->dir . '/' . $this->name)
303
+ ->addParam('max_file_size', 900000)
304
+ ->addParam('remove_path', ABSPATH);
305
+
306
+ $this->queue->add($commandContext);
307
+ unset($commandContext); */
308
+ }
309
  }
310
+ WPAdm_Core::log( __('Backup of Files was started','dropbox-backup') );
311
+ WPAdm_Core::log( __('End of File Backup','dropbox-backup') );
312
+ WPAdm_Running::setCommandResult('archive', true);
313
 
314
  }
315
+ if (empty($errors)) {
316
+ if ( WPAdm_Running::is_stop() ) {
317
+ $files = glob($this->dir . '/'.$this->name . '*');
318
+ $urls = array();
319
+ $totalSize = 0;
320
+ foreach($files as $file) {
321
+ $urls[] = str_replace(ABSPATH, '', $file);
322
+ $totalSize += @intval( filesize($file) );
323
+ }
324
+ $this->result->setData($urls);
325
+ $this->result->setSize($totalSize);
326
+ $this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
327
+ $this->result->setValue('name', $this->name );
328
+ $this->result->setValue('time', $this->time);
329
+ $this->result->setValue('type', 'local');
330
+ $this->result->setValue('counts', count($urls) );
331
+ $size = $totalSize / 1024 / 1024; /// MByte
332
+ $size = round($size, 2);
333
+ $log = str_replace("%s", $size , __('Backup Size %s Mb','dropbox-backup') ) ;
334
+ WPAdm_Core::log($log);
335
+
336
+ $remove_from_server = 0;
337
+ #Removing TMP-files
338
+ WPAdm_Core::rmdir($mysql_dump_file);
339
+
340
+ #Removind old backups(if limit the number of stored backups)
341
+ if ($this->params['limit'] != 0) {
342
+ WPAdm_Core::log( __('Limits of Backups ','dropbox-backup') . $this->params['limit'] );
343
+ WPAdm_Core::log( __('Removing of old Backups was started','dropbox-backup') );
344
+ $files = glob(DROPBOX_BACKUP_DIR_BACKUP . '/*');
345
+ if (count($files) > $this->params['limit']) {
346
+ $files2 = array();
347
+ foreach($files as $f) {
348
+ $fa = explode('-', $f);
349
+ if (count($fa) != 3) {
350
+ continue;
351
+ }
352
+ $files2[$fa[2]] = $f;
353
+
354
+ }
355
+ ksort($files2);
356
+ $d = count($files2) - $this->params['limit'];
357
+ $del = array_slice($files2, 0, $d);
358
+ foreach($del as $d) {
359
+ WPAdm_Core::rmdir($d);
360
+ }
361
+ }
362
+ WPAdm_Core::log( __('Removing of old Backups was Finished','dropbox-backup') );
363
+ }
364
+ } else {
365
+ return true;
366
+ }
367
  }
368
+ } else {
369
+ return true;
370
  }
 
371
  }
372
+ if ( WPAdm_Running::is_stop() ) {
373
+ wpadm_class::setBackup(1);
374
+ if (!empty($errors)) {
375
+ $this->result->setError(implode("\n", $errors));
376
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
377
+ WPAdm_Core::rmdir($this->dir);
378
+ wpadm_class::setStatus(0);
379
+ wpadm_class::setErrors( implode(", ", $errors) );
380
+ } else {
381
+ wpadm_class::setStatus(1);
382
+ WPAdm_Core::log( __('Backup creation was complete successfully!','dropbox-backup') );
383
+ }
384
+ wpadm_class::backupSend();
385
+ } else {
386
+ return true;
387
+ }
388
+ return $this->result;
389
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
 
391
  }
392
  public function createListFilesForArchive()
397
  $files = array_merge(
398
  $files,
399
  array(
400
+ //ABSPATH . '.htaccess',
401
  ABSPATH . 'index.php',
402
+ // ABSPATH . 'license.txt',
403
+ // ABSPATH . 'readme.html',
404
  ABSPATH . 'wp-activate.php',
405
  ABSPATH . 'wp-blog-header.php',
406
  ABSPATH . 'wp-comments-post.php',
407
  ABSPATH . 'wp-config.php',
408
+ // ABSPATH . 'wp-config-sample.php',
409
  ABSPATH . 'wp-cron.php',
410
  ABSPATH . 'wp-links-opml.php',
411
  ABSPATH . 'wp-load.php',
417
  ABSPATH . 'xmlrpc.php',
418
  )
419
  );
420
+ if ( file_exists(ABSPATH . '.htaccess') ) {
421
+ $files = array_merge( $files, array( ABSPATH . '.htaccess' ) );
422
+ }
423
+ if ( file_exists( ABSPATH . 'license.txt' ) ) {
424
+ $files = array_merge( $files, array( ABSPATH . 'license.txt' ) );
425
+ }
426
+ if ( file_exists( ABSPATH . 'readme.html' ) ) {
427
+ $files = array_merge( $files, array( ABSPATH . 'readme.html') );
428
+ }
429
+ if ( file_exists(ABSPATH . 'wp-config-sample.php') ) {
430
+ $files = array_merge( $files, array( ABSPATH . 'wp-config-sample.php' ) );
431
+ }
432
+ if ( file_exists(ABSPATH . 'robots.txt') ) {
433
+ $files = array_merge( $files, array( ABSPATH . 'robots.txt' ) );
434
+ }
435
 
436
  if (!empty($this->params['minus-path'])) {
437
  $minus_path = explode(",", $this->params['minus-path']);
512
 
513
  if ($handle = opendir($directory)) {
514
  while (false !== ($file = readdir($handle))) {
515
+ if ($file != "." && $file != ".." && $file != 'tmp') {
516
+ if (is_dir($directory. "/" . $file) ) {
517
  if($recursive) {
518
  $array_items = array_merge($array_items, $this->directoryToArray($directory. "/" . $file, $recursive));
519
  }
576
  private function init(array $conf) {
577
  $this->id = $conf['id'];
578
  $this->stime = $conf['stime'];
579
+ //$this->queue = new WPAdm_Queue($this->id);
580
+ }
581
+
582
+ private function getArchiveName($name)
583
+ {
584
+ //WPAdm_Core::log("{$name}-*.zip");
585
+ $archives = glob("{$name}-*.zip");
586
+ //WPAdm_Core::log( print_r($archives, 1) );
587
+ if (empty($archives)) {
588
+ return "{$name}-1.zip";
589
+ }
590
+ $n = count($archives);
591
+ $f = "{$name}-{$n}.zip";
592
+ return $f;
593
+ }
594
+
595
+ private function getNextArchiveName($name)
596
+ {
597
+ //WPAdm_Core::log("{$name}-*.zip");
598
+ $archives = glob("{$name}-*.zip");
599
+ $n = 1 + count($archives);
600
+ $a = "{$name}-{$n}.zip";
601
+ //WPAdm_Core::log($a);
602
+ return $a;
603
  }
604
  }
605
  }
methods/class-wpadm-method-queue-controller.php CHANGED
@@ -88,7 +88,7 @@ if (!class_exists('WPAdm_Method_Queue_Controller')) {
88
  }
89
  //если еще есть невыполненые задачи - рестаратуем
90
  if (!empty($this->contexts)) {
91
- $this->restart();
92
  }
93
 
94
  // если все задачи выполнили, то пометим файл
88
  }
89
  //если еще есть невыполненые задачи - рестаратуем
90
  if (!empty($this->contexts)) {
91
+ //$this->restart();
92
  }
93
 
94
  // если все задачи выполнили, то пометим файл
methods/class-wpadm-method-reconnect.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- if (!class_exists('WPAdm_Method_Reconnect')) {
4
- class WPAdm_Method_Reconnect extends WPAdm_Method_Class {
5
- public function getResult()
6
- {
7
- // обновить публичный ключ
8
- update_option('wpadm_pub_key', $this->params['pub_key']);
9
-
10
- $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
11
- $this->result->setData('');
12
- return $this->result;
13
- }
14
- }
15
  }
1
+ <?php
2
+
3
+ if (!class_exists('WPAdm_Method_Reconnect')) {
4
+ class WPAdm_Method_Reconnect extends WPAdm_Method_Class {
5
+ public function getResult()
6
+ {
7
+ // update public key
8
+ update_option('wpadm_pub_key', $this->params['pub_key']);
9
+
10
+ $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
11
+ $this->result->setData('');
12
+ return $this->result;
13
+ }
14
+ }
15
  }
methods/class-wpadm-method-send-to-dropbox.php CHANGED
@@ -12,105 +12,255 @@ if (!class_exists('WPadm_Method_Send_To_Dropbox')) {
12
 
13
  private $id;
14
 
 
15
  //private $name = '';
16
 
17
  public function getResult()
18
  {
19
- $errors = array();
20
- $this->id = uniqid('wpadm_method_send_to_dropbox_');
 
21
 
22
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
23
- $this->result->setError('');
24
- if (isset($this->params['local']) && $this->params['local']) {
25
- $params_data_cron = WPAdm_Running::getCommandResultData('local_backup');
26
- $this->params['files'] = $params_data_cron['data'];
27
- $this->params['access_details']['dir'] = $params_data_cron['name'];
28
- WPAdm_Core::log( '' );
29
- }
 
 
 
 
 
 
 
 
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- $this->queue = new WPAdm_Queue($this->id);
 
 
 
 
 
33
 
34
- $ad = $this->params['access_details'];
35
- $this->queue->clear();
36
- $files = $this->params['files'];
37
- //$this->getResult()->setData($files);
 
 
 
 
 
 
 
 
38
 
39
- $dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
40
- //$dir = trim($dir, '/') . '/' . $this->name;
41
- if (is_array($files)) {
42
- $send = false;
43
-
44
- foreach($files as $file) {
45
- if (isset($this->params['local']) && $this->params['local']) {
46
- $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
47
- $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
48
- if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) {
49
- $msg = str_replace('%file%', $file, __('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.' ,'dropbox-backup'));
50
- WPAdm_Core::log( $msg );
51
- $errors[] = $msg;
52
- break;
53
- }
54
- if ( !empty($data_command) && in_array(ABSPATH . $file, $data_command) ) {
55
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
 
 
57
  }
58
- $commandContext = new WPAdm_Command_Context();
59
- $commandContext->addParam('command', 'send_to_dropbox')
60
- ->addParam('key', $ad['key'])
61
- ->addParam('secret', $ad['secret'])
62
- ->addParam('token', $ad['token'])
63
- ->addParam('folder_project', $ad['folder'])
64
- ->addParam('folder', $dir)
65
- ->addParam('files', ABSPATH . $file);
66
- if (isset($this->params['local']) && $this->params['local']) {
67
- $commandContext->addParam('local', true);
 
 
 
 
 
 
 
68
  }
69
- $this->queue->add($commandContext);
70
- unset($commandContext);
71
- $send = true;
72
  }
73
- }
74
- if ($send) {
75
- WPAdm_Core::log( __('Start copy to Dropbox Cloud' ,'dropbox-backup') );
76
- $res = $this->queue->save()->execute();
77
- WPAdm_Core::log( __('End Copy Files to Dropbox' ,'dropbox-backup') );
78
- }
79
- if (isset($res) && !$res) {
80
- WPAdm_Core::log(__('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError());
81
- $errors[] = __('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError();
82
- }
83
-
84
- if (count($errors) > 0) {
85
- $this->result->setError(implode("\n", $errors));
86
- $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
87
- } else {
88
- if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists( WPAdm_Core::getTmpDir() . "/notice-star") ) {
89
- wpadm_wp_full_backup_dropbox::setFlagToTmp( 'notice-star', time() . "_1d" );
90
  }
91
- if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) {
92
- $this->result->setData($this->params['files']);
93
- $this->result->setSize($params_data_cron['size']);
94
- $this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
95
- $this->result->setValue('name', $params_data_cron['name']);
96
- $this->result->setValue('time', $params_data_cron['time']);
97
- $this->result->setValue('type', 'dropbox');
98
- $this->result->setValue('counts', $params_data_cron['counts'] );
99
- if( (isset($this->params['is_local_backup']) && $this->params['is_local_backup'] == 0 ) || ( !isset($this->params['is_local_backup']) ) ) {
100
- WPAdm_Core::rmdir( DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}");
101
  }
102
  }
 
103
  }
 
 
104
 
105
- return $this->result;
 
 
 
 
106
  }
107
 
108
- private function init(array $conf) {
109
- //todo: нормализация
110
- $this->id = $conf['id'];
111
- $this->stime = $conf['stime'];
112
- $this->queue = new WPAdm_Queue($this->id);
113
- $this->type = $conf['type'];
 
 
 
 
 
 
 
114
  }
115
  }
116
  }
12
 
13
  private $id;
14
 
15
+ private $time_send = 120; // seconds for send to dropbox
16
  //private $name = '';
17
 
18
  public function getResult()
19
  {
20
+ if ( WPAdm_Running::is_stop() ) {
21
+ $errors = array();
22
+ $this->id = uniqid('wpadm_method_send_to_dropbox_');
23
 
24
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_SUCCESS);
25
+ $this->result->setError('');
26
+ if ( WPAdm_Running::is_stop() ) {
27
+ if (isset($this->params['local']) && $this->params['local']) {
28
+ $params_data_cron = WPAdm_Running::getCommandResultData('local_backup');
29
+ if ( isset($res['result']) && $res['result'] == 'error' ) {
30
+ $errors[] = $res['error'];
31
+ } else {
32
+ $this->params['files'] = $params_data_cron['data'];
33
+ $this->params['access_details']['dir'] = $params_data_cron['name'];
34
+ }
35
+ }
36
+ } else {
37
+ return true;
38
+ }
39
+ if ( WPAdm_Running::is_stop() ) {
40
+ if (empty($errors)) {
41
 
42
+ $ad = $this->params['access_details'];
43
+ $files = $this->params['files'];
44
+ //$this->getResult()->setData($files);
45
+ //$dir = trim($dir, '/') . '/' . $this->name;
46
+ if (is_array($files)) {
47
+ $send = false;
48
+ if (!class_exists('WPAdm_Process')) {
49
+ require_once WPAdm_Core::getPluginDir() . '/modules/class-wpadm-process.php';
50
+ }
51
+ WPAdm_Process::init( 'dropbox', count($files) );
52
+ WPAdm_Core::log( __('Start copy to Dropbox Cloud', 'dropbox-backup') );
53
+ foreach($files as $file) {
54
+ try {
55
+ $this->sendFileToDropbox( ABSPATH . $file, $ad );
56
+ } catch (Exception $e) {
57
+ $this->result->setError( $e->getMessage() );
58
+ $this->result->setResult( WPAdm_Result::WPADM_RESULT_ERROR );
59
+ return $this->deleteBackup();
60
+ }
61
+ if (isset($this->params['local']) && $this->params['local']) {
62
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
63
+ $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
64
+ if (isset($data_error_command[ABSPATH . $file]) && $data_error_command[ABSPATH . $file]['count'] > WPADM_COUNT_LIMIT_SEND_TO_DROPBOX) {
65
+ $msg = str_replace('%file%', $file, __('Not perhaps sending file: "%file%". If you wish make upload file, increase execution time code or speed internet provider is small for upload file.' ,'dropbox-backup'));
66
+ WPAdm_Core::log( $msg );
67
+ $errors[] = $msg;
68
+ break;
69
+ }
70
+ $md5 = md5(ABSPATH . $file);
71
+ if ( !empty($data_command) && in_array($md5, $data_command) ) {
72
+ continue;
73
+ }
74
+ }
75
+ /* $commandContext = new WPAdm_Command_Context();
76
+ $commandContext->addParam('command', 'send_to_dropbox')
77
+ ->addParam('key', $ad['key'])
78
+ ->addParam('secret', $ad['secret'])
79
+ ->addParam('token', $ad['token'])
80
+ ->addParam('folder_project', $ad['folder'])
81
+ ->addParam('folder', $dir)
82
+ ->addParam('files', ABSPATH . $file);
83
+ if (isset($this->params['local']) && $this->params['local']) {
84
+ $commandContext->addParam('local', true);
85
+ }
86
+ $this->queue->add($commandContext);
87
+ unset($commandContext);
88
+ $send = true;
89
+ } */
90
+ }
91
+ WPAdm_Core::log( __('End Copy Files to Dropbox' ,'dropbox-backup') );
92
+ /*if (isset($res) && !$res) {
93
+ WPAdm_Core::log(__('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError());
94
+ $errors[] = __('Answer from Dropbox ' ,'dropbox-backup') . $this->queue->getError();
95
+ } */
96
+ }
97
+ }
98
+ } else {
99
+ return true;
100
+ }
101
+ if (count($errors) > 0) {
102
+ $this->result->setError(implode("\n", $errors));
103
+ $this->result->setResult(WPAdm_Result::WPADM_RESULT_ERROR);
104
+ return $this->deleteBackup();
105
+ } else {
106
+ if ( WPAdm_Running::is_stop() ) {
107
+ if (class_exists('wpadm_wp_full_backup_dropbox') && !file_exists( WPAdm_Core::getTmpDir() . "/notice-star") ) {
108
+ wpadm_wp_full_backup_dropbox::setFlagToTmp( 'notice-star', time() . "_1d" );
109
+ }
110
+ if (isset($this->params['local']) && $this->params['local'] && isset($params_data_cron)) {
111
+ if ( WPAdm_Running::is_stop() ) {
112
+ $this->result->setData($this->params['files']);
113
+ $this->result->setSize($params_data_cron['size']);
114
+ $this->result->setValue('md5_data', md5 ( print_r($this->result->toArray(), 1 ) ) );
115
+ $this->result->setValue('name', $params_data_cron['name']);
116
+ $this->result->setValue('time', $params_data_cron['time']);
117
+ $this->result->setValue('type', 'dropbox');
118
+ $this->result->setValue('counts', $params_data_cron['counts'] );
119
+ if( (isset($this->params['is_local_backup']) && $this->params['is_local_backup'] == 0 ) || ( !isset($this->params['is_local_backup']) ) ) {
120
+ WPAdm_Core::rmdir( DROPBOX_BACKUP_DIR_BACKUP . "/{$params_data_cron['name']}");
121
+ }
122
+ return $this->result;
123
+ } else {
124
+ return $this->result;
125
+ }
126
+ }
127
+ } else {
128
+ return $this->result;
129
+ }
130
+ }
131
+ return $this->result;
132
+ }
133
+ return true;
134
+ }
135
 
136
+ private function init(array $conf)
137
+ {
138
+ $this->id = $conf['id'];
139
+ $this->stime = $conf['stime'];
140
+ $this->type = $conf['type'];
141
+ }
142
 
143
+ private function sendFileToDropbox($file, $ad)
144
+ {
145
+ if ( WPAdm_Running::is_stop() ) {
146
+ require_once WPAdm_Core::getPluginDir() . '/modules/dropbox.class.php';
147
+ $command_dropbox = WPAdm_Running::getCommandResultData('command_dropbox');
148
+ $fromFile = str_replace('//', '/', $file);
149
+ $md5 = md5($fromFile);
150
+ if (in_array($md5, $command_dropbox)) {
151
+ return true;
152
+ }
153
+ WPAdm_Core::log(__('Send to dropbox files' ,'dropbox-backup') );
154
+ $dropbox = new dropbox($ad['key'], $ad['secret'], $ad['token'] );
155
 
156
+ if (!$dropbox->isAuth()) {
157
+ $this->setError( str_replace(array('%d', '%k', '%s'),
158
+ array( SITE_HOME, $ad['key'], $ad['secret'] ),__('Website "%d" can\'t authorize on Dropbox with using of "app key: %k" and "app secret: %s"' ,'dropbox-backup') ) );
159
+ return false;
160
+ }
161
+ $dir = (isset($ad['dir'])) ? $ad['dir'] : '/';
162
+ if ( WPAdm_Running::is_stop() ) {
163
+ $file_ = explode("/", $file);
164
+ $file_name = array_pop($file_);
165
+ $folder_project_temp = $ad['folder'];
166
+ $folder_project = "";
167
+ if (!empty($folder_project_temp)) {
168
+ $folder_project = $folder_project_temp . "/";
169
+ $dropbox->createDir($folder_project_temp );
170
+ $dropbox->createDir($folder_project . $dir );
171
+ } else {
172
+ $dropbox->createDir( $dir );
173
+ }
174
+ } else {
175
+ return true;
176
+ }
177
+ //$files = ''; // to comment
178
+ $fromFile = str_replace('//', '/', $file);
179
+ $toFile = str_replace('//', '/', $folder_project . $dir . '/' . $file_name);
180
+ $local = isset( $this->params['local'] ) ? $this->params['local'] : false ;
181
+ $file_dropbox = $dropbox->listing($folder_project . $dir. '/' . $file_name);
182
+ $send = true;
183
+ if ( !isset($file_dropbox['error']) ) {
184
+ if ($file_dropbox['bytes'] != filesize($fromFile)) {
185
+ if ( WPAdm_Running::is_stop() ) {
186
+ $delete_file = $dropbox->deleteFile($folder_project . $dir . '/' . $file_name);
187
+ if (isset($delete_file['error'])) {
188
+ $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $delete_file['text'] . '"');
189
+ return false;
190
+ }
191
+ $data_error_command = WPAdm_Running::getCommandResultData('errors_sending');
192
+ if (isset($data_command[$fromFile])) {
193
+ $data_error_command[$fromFile]['count'] += 1;
194
+ } else {
195
+ $data_error_command[$fromFile] = array();
196
+ $data_error_command[$fromFile]['count'] = 1;
197
+ }
198
+ WPAdm_Running::setCommandResultData('errors_sending', $data_error_command);
199
  }
200
+ } else {
201
+ $send = false;
202
  }
203
+ }
204
+ if ( $local ) {
205
+ if ( WPAdm_Running::is_stop() ) {
206
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
207
+ $md5 = md5($fromFile);
208
+ if (empty($data_command) || !in_array($md5 ,$data_command) ) {
209
+ if ($send) {
210
+ $res = $dropbox->uploadFile($fromFile, $toFile, true);
211
+ } else {
212
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
213
+ if (!in_array($md5, $data_command)) {
214
+ $this->saveDataCommand($md5);
215
+ WPAdm_Process::setInc('dropbox', 1);
216
+ }
217
+
218
+ }
219
+ }
220
  }
221
+ } else {
222
+ $md5 = md5($fromFile);
223
+ $res = $dropbox->uploadFile($fromFile, $toFile, true);
224
  }
225
+ if (isset($res['error']) && isset($res['text']) && $res['error'] == 1) {
226
+ $this->setError( __('Dropbox returned an error during file sending: ' ,'dropbox-backup') . '"' . $res['text'] . '"');
227
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
+ if ( WPAdm_Running::is_stop() ) {
230
+ if (isset($res['size']) && isset($res['client_mtime'])) {
231
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
232
+ if (!in_array($md5, $data_command)) {
233
+ WPAdm_Core::log( __('File upload: ' ,'dropbox-backup') . basename( $file ) . __(' size: ' ,'dropbox-backup') . $res['size']);
234
+ $this->saveDataCommand($md5);
235
+ WPAdm_Process::setInc('dropbox', 1);
236
+ }
 
 
237
  }
238
  }
239
+
240
  }
241
+ return true;
242
+ }
243
 
244
+ private function saveDataCommand($file)
245
+ {
246
+ $data_command = WPAdm_Running::getCommandResultData('command_dropbox');
247
+ $data_command[] = $file;
248
+ WPAdm_Running::setCommandResultData('command_dropbox', $data_command);
249
  }
250
 
251
+ private function setError($txt = '')
252
+ {
253
+ throw new Exception($txt);
254
+ }
255
+
256
+ private function deleteBackup()
257
+ {
258
+ if( (isset($this->params['is_local_backup']) && $this->params['is_local_backup'] == 0 ) || ( !isset($this->params['is_local_backup']) ) ) {
259
+ if (isset($this->params['access_details']['dir'])) {
260
+ WPAdm_Core::rmdir( DROPBOX_BACKUP_DIR_BACKUP . "/{$this->params['access_details']['dir']}");
261
+ }
262
+ }
263
+ return $this->result;
264
  }
265
  }
266
  }
modules/HttpFsockopen.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ justin was here :D
5
+ */
6
+
7
+ class HttpFsockopen {
8
+
9
+ protected $url;
10
+ protected $path;
11
+ protected $host;
12
+ protected $query;
13
+ protected $post;
14
+ protected $port;
15
+ protected $headers;
16
+ protected $ssl;
17
+ protected $method;
18
+ protected $timeout;
19
+ protected $str_headers = '';
20
+ protected $is_post = false;
21
+
22
+ protected static $autoload;
23
+
24
+ public function __construct($url, $use_autoload = true){
25
+ if(is_null(HttpFsockopen::$autoload) && $use_autoload){
26
+ HttpFsockopen::$autoload = true;
27
+ spl_autoload_register(array("HttpFsockopen", "load"));
28
+ }
29
+ $url_array = parse_url($url);
30
+
31
+ if(!empty($url_array["scheme"]) && preg_match("#^https|ssl$#i", $url_array["scheme"])){
32
+ $this -> ssl = true;
33
+ } else {
34
+ $this -> ssl = false;
35
+ }
36
+
37
+ if(empty($url_array["port"])){
38
+ if($this -> ssl){
39
+ $this -> port = 443;
40
+ } else {
41
+ $this -> port = 80;
42
+ }
43
+ }
44
+
45
+ if(array_key_exists("path", $url_array)){
46
+ $this -> path = $url_array["path"];
47
+ } else {
48
+ $this -> path = false;
49
+ }
50
+
51
+ if(array_key_exists("query", $url_array)){
52
+ $this -> query = $url_array["query"];
53
+ } else {
54
+ $this -> query = false;
55
+ }
56
+
57
+ $this -> host = $url_array["host"];
58
+ $this -> method = "GET";
59
+ $this -> timeout = 15;
60
+ $this -> is_post = false;
61
+ }
62
+
63
+ public static function load($class){
64
+ $file = dirname( __FILE__ ) . DIRECTORY_SEPARATOR .
65
+ preg_replace("#[_]+#", DIRECTORY_SEPARATOR , $class) . ".php";
66
+ if(file_exists($file))
67
+ include_once $file ;
68
+ }
69
+
70
+ public function setQueryData($data){
71
+ if(is_array($data)){
72
+ $data = http_build_query($data);
73
+ }
74
+ $this -> query = $data;
75
+ return $this;
76
+ }
77
+
78
+ public function setPostData($data){
79
+ if(is_array($data)){
80
+ $data = http_build_query($data);
81
+ }
82
+ $this -> post = $data;
83
+ $this -> method = "POST";
84
+ $this -> is_post = true;
85
+ $this -> setHeaders("Content-Type", "application/x-www-form-urlencoded");
86
+ return $this;
87
+ }
88
+
89
+ public function setMethod($method){
90
+ $previous_method = $this -> method;
91
+ if(preg_match("#^[a-z]+$#i", $method)){
92
+ $this -> method = strtoupper($method);
93
+ }
94
+ if($this -> method == "POST" && $previous_method != "POST"){
95
+ //$this -> setHeaders("Content-Type", "application/x-www-form-urlencoded");
96
+ }
97
+ if($this -> method != "POST" && $previous_method == "POST"){
98
+ $this -> setHeaders("Content-Type", null);
99
+ }
100
+ return $this;
101
+ }
102
+
103
+ public function setTimeout($timeout){
104
+ $this -> timeout = $timeout;
105
+ return $this;
106
+ }
107
+
108
+ public function setPort($port){
109
+ $this -> port = $port;
110
+ return $this;
111
+ }
112
+
113
+ public function setHeaders($key, $value = null){
114
+ if(is_array($key)){
115
+ foreach($key as $key => $value){
116
+ if(is_null($value)){
117
+ unset($this -> headers[$key]);
118
+ } else {
119
+ $this -> headers[$key] = $value;
120
+ }
121
+ }
122
+ } else {
123
+ if(is_null($value)){
124
+ unset($this -> headers[$key]);
125
+ } else {
126
+ $this -> headers[$key] = $value;
127
+ }
128
+ }
129
+ return $this;
130
+ }
131
+
132
+ public function setStrHeaders($str)
133
+ {
134
+ $this->str_headers = $str;
135
+ }
136
+
137
+ public function setUserAgent($user_agent){
138
+ return $this -> setHeaders("User-Agent", $user_agent);
139
+ }
140
+
141
+ public function exec(){
142
+ $socket = fsockopen(($this -> ssl ? "ssl://" : "") . $this -> host, $this -> port, $errno, $errstr,
143
+ $this -> timeout);
144
+ $contents = "";
145
+
146
+ if($socket){
147
+ $http = $this -> method . " ". (strlen($this -> path) ? $this -> path : "/") .
148
+ (strlen($this -> query)>0 ? "?" . $this -> query : "")
149
+ ." HTTP/1.1\r\n";
150
+ $http .= "Host: ".$this -> host."\r\n";
151
+ foreach($this -> headers as $key => $value){
152
+ $http .= $key. ": ".$value."\r\n";
153
+ }
154
+
155
+ if ( $this -> is_post || $this -> method == 'GET' ) {
156
+ $http .= "Content-length: " . strlen($this -> post) . "\r\n";
157
+ $http .= "Connection: close\r\n\r\n";
158
+ }
159
+
160
+ if (!empty($this->str_headers)) {
161
+ $http .= $this->str_headers;
162
+ }
163
+
164
+ if(!is_null($this -> post)) {
165
+ $http .= $this -> post . "\r\n\r\n";
166
+ }
167
+
168
+ // echo '<pre>' . $http . '</pre>';
169
+ // file_put_contents(dirname(__FILE__) . '/http.log', $http . "\n\r\n\r", FILE_APPEND);
170
+ // file_put_contents(dirname(__FILE__) . '/params.log', serialize($this) . "\n\r\n\r", FILE_APPEND);
171
+ fwrite($socket, $http);
172
+ while (!feof($socket)) {
173
+ $contents .= fgetc($socket);
174
+ }
175
+ fclose($socket);
176
+ }
177
+
178
+ return $contents;
179
+ }
180
+
181
+ }
modules/class-wpadm-archive.php CHANGED
@@ -1,4 +1,7 @@
1
  <?php
 
 
 
2
  if ( !class_exists("PclZip") ) {
3
  require_once dirname(__FILE__) . '/pclzip.lib.php';
4
  }
@@ -11,26 +14,44 @@ if (!class_exists('WPAdm_Archive')) {
11
  */
12
  private $archive;
13
  private $md5_file = '';
 
14
 
15
- public function __construct($file, $md5_file = '') {
16
  $this->archive = new PclZip($file);
17
  $this->files[] = $file;
18
  $this->md5_file = $md5_file;
19
  }
20
 
21
  public function add($file)
22
- {
23
- $this->packed($file);
24
  }
25
  public function packed($file)
26
  {
27
  ini_set("memory_limit", "256M");
28
- if (empty($this->remove_path)) {
29
- $this->archive->add($file);
30
- } else {
31
- $this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
32
- }
33
- $this->saveMd5($file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
 
36
  protected function saveMd5($file) {
1
  <?php
2
+ if (!defined('PCLZIP_TEMPORARY_DIR')) {
3
+ define('PCLZIP_TEMPORARY_DIR', WPAdm_Core::getTmpDir() . '/');
4
+ }
5
  if ( !class_exists("PclZip") ) {
6
  require_once dirname(__FILE__) . '/pclzip.lib.php';
7
  }
14
  */
15
  private $archive;
16
  private $md5_file = '';
17
+ public $error = '';
18
 
19
+ public function __construct($file, $md5_file = '') {
20
  $this->archive = new PclZip($file);
21
  $this->files[] = $file;
22
  $this->md5_file = $md5_file;
23
  }
24
 
25
  public function add($file)
26
+ {
27
+ return $this->packed($file);
28
  }
29
  public function packed($file)
30
  {
31
  ini_set("memory_limit", "256M");
32
+ if ( WPAdm_Running::is_stop() ) {
33
+ if (empty($this->remove_path)) {
34
+ if ( WPAdm_Running::is_stop() ) {
35
+ $res = $this->archive->add($file);
36
+ }
37
+ } else {
38
+ if ( WPAdm_Running::is_stop() ) {
39
+ $res = $this->archive->add($file, PCLZIP_OPT_REMOVE_PATH, $this->remove_path);
40
+ }
41
+ }
42
+ if ( WPAdm_Running::is_stop() ) {
43
+ if ($res == 0) {
44
+ WPAdm_Core::log( $this->archive->errorInfo(true) );
45
+ if (file_exists($this->md5_file)) {
46
+ unset($this->md5_file);
47
+ }
48
+ $this->error = $this->archive->errorInfo(true);
49
+ return false;
50
+ }
51
+ $this->saveMd5($file);
52
+ }
53
+ }
54
+ return true;
55
  }
56
 
57
  protected function saveMd5($file) {
modules/class-wpadm-core.php CHANGED
@@ -8,6 +8,7 @@ require_once DRBBACKUP_BASE_DIR . '/modules/class-wpadm-command-factory.php';
8
 
9
 
10
  if (!class_exists('WPAdm_Core')) {
 
11
  class WPAdm_Core {
12
 
13
  /*
@@ -41,7 +42,7 @@ if (!class_exists('WPAdm_Core')) {
41
 
42
  public static $plugin_name;
43
 
44
- private static $cron_method = array('local_backup', 'send_to_dropbox', 'full_backup_dropbox');
45
 
46
 
47
  public function __construct(array $request, $plugin = '', $plugin_dir = '') {
@@ -72,7 +73,7 @@ if (!class_exists('WPAdm_Core')) {
72
  $this->result = $obj->getResult();
73
  }
74
  } else {
75
- $this->result->setError('Unknown method "' . $request['method'] . '"');
76
  }
77
  }
78
 
@@ -85,11 +86,14 @@ if (!class_exists('WPAdm_Core')) {
85
  $tmp_dir = self::$pl_dir . '/tmp';
86
  self::mkdir($tmp_dir);
87
  if (!file_exists($tmp_dir . '/index.php')) {
88
- file_put_contents($tmp_dir . '/index.php', '');
 
 
 
89
  }
90
  return $tmp_dir;
91
  }
92
-
93
  static public function getPluginDir() {
94
  return self::$pl_dir;
95
  }
@@ -119,7 +123,7 @@ if (!class_exists('WPAdm_Core')) {
119
 
120
  $class_name = "WPAdm_Method_{$method}";
121
  if (!class_exists($class_name)) {
122
- $this->getResult()->setError("Class '$class_name' not found");
123
  $this->getResult()->setResult(WPAdm_result::WPADM_RESULT_ERROR);
124
  return null;
125
  }
@@ -185,16 +189,16 @@ if (!class_exists('WPAdm_Core')) {
185
  if ('connect' == $this->request['method']) {
186
  $this->pub_key = $this->request['params']['pub_key'];
187
  } else {
188
- $this->getResult()->setError('Activate site in WPAdm.com for work to plugins.');
189
  return false;
190
  }
191
  } elseif ('connect' == $this->request['method']) {
192
  if( $this->pub_key != $this->request['params']['pub_key'] ){
193
- $this->getResult()->setError('Ошибка. Воспользуйтесь переподключением плагина.');
194
  return false;
195
  }
196
  } elseif('queue_controller' == $this->request['method']) {
197
- //todo: проверить, что запустили сами себя
198
  return true;
199
 
200
  }
@@ -206,7 +210,7 @@ if (!class_exists('WPAdm_Core')) {
206
 
207
  //$ret = ($sign == $request_sign);
208
  if (!$ret) {
209
- $this->getResult()->setError("Неверная подпись");
210
  }
211
  return $ret;
212
  }
8
 
9
 
10
  if (!class_exists('WPAdm_Core')) {
11
+
12
  class WPAdm_Core {
13
 
14
  /*
42
 
43
  public static $plugin_name;
44
 
45
+ private static $cron_method = array('local_backup', 'send_to_dropbox');
46
 
47
 
48
  public function __construct(array $request, $plugin = '', $plugin_dir = '') {
73
  $this->result = $obj->getResult();
74
  }
75
  } else {
76
+ $this->result->setError(sprintf(__('Unknown method "%s"', 'dropbox-backup'), $request['method'] ) );
77
  }
78
  }
79
 
86
  $tmp_dir = self::$pl_dir . '/tmp';
87
  self::mkdir($tmp_dir);
88
  if (!file_exists($tmp_dir . '/index.php')) {
89
+ @file_put_contents($tmp_dir . '/index.php', '');
90
+ if (!file_exists($tmp_dir . '/index.php')) {
91
+ self::$error = ( sprintf( __('Failed to create a file, please check the permissions on the folders "%s".<br /> Plugin is working incorrectly.', 'dropbxo-backup'), $tmp_dir ) );
92
+ }
93
  }
94
  return $tmp_dir;
95
  }
96
+
97
  static public function getPluginDir() {
98
  return self::$pl_dir;
99
  }
123
 
124
  $class_name = "WPAdm_Method_{$method}";
125
  if (!class_exists($class_name)) {
126
+ $this->getResult()->setError(sprintf( __( "Class '%s' not found", 'dropbox-backup' ), $class_name ) );
127
  $this->getResult()->setResult(WPAdm_result::WPADM_RESULT_ERROR);
128
  return null;
129
  }
189
  if ('connect' == $this->request['method']) {
190
  $this->pub_key = $this->request['params']['pub_key'];
191
  } else {
192
+ $this->getResult()->setError( __( 'Activate site in WPAdm.com for work to plugins.', 'dropbox-backup' ) );
193
  return false;
194
  }
195
  } elseif ('connect' == $this->request['method']) {
196
  if( $this->pub_key != $this->request['params']['pub_key'] ){
197
+ $this->getResult()->setError( __( 'Error. Reconnect Plugin.', 'dropbox-backup' ) );
198
  return false;
199
  }
200
  } elseif('queue_controller' == $this->request['method']) {
201
+ //todo: check run self
202
  return true;
203
 
204
  }
210
 
211
  //$ret = ($sign == $request_sign);
212
  if (!$ret) {
213
+ $this->getResult()->setError(__("Incorrect signature", 'dropbox-backup'));
214
  }
215
  return $ret;
216
  }
modules/class-wpadm-mysqldump.php CHANGED
@@ -13,7 +13,7 @@ if (!class_exists('WPAdm_Mysqldump')) {
13
 
14
  private function connect($db = '') {
15
  //WPAdm_Core::log("----------------------------------------------------");
16
- //WPAdm_Core::log( __('Connecting to MySQL...' ,'dropbox-backup') );
17
  if (! class_exists('wpdb')) {
18
  require_once ABSPATH . '/' . WPINC . '/wp-db.php';
19
  }
@@ -39,41 +39,49 @@ if (!class_exists('WPAdm_Mysqldump')) {
39
  }
40
  }
41
  }
42
- return $this->dbh;
43
  }
44
 
45
  public function optimize($db) {
46
  $proc_data = WPAdm_Running::getCommandResultData('db');
47
- if (!isset($proc_data['optimize'])) {
48
- $link = $this->connect($db);
49
- WPAdm_Core::log( __('Optimize Database Tables was started' ,'dropbox-backup') );
50
- $n = $link->query('SHOW TABLES');
51
- $result = $link->last_result;
52
- if (!empty( $link->last_error ) && $n > 0) {
53
- $this->setError($link->last_error);
54
- } else {
55
- for($i = 0; $i < $n; $i++ ) {
56
- $res = array_values( get_object_vars( $result[$i] ) );
57
- $proc_data = WPAdm_Running::getCommandResultData('db');
58
- if (!isset($proc_data['optimize_table'][$res[0]])) {
59
- $link->query('OPTIMIZE TABLE '. $res[0]);
60
- if (!empty( $link->last_error ) ) {
61
- $tables = isset($proc_data['optimize_table']) ? $proc_data['optimize_table'] : array();
62
- $tables[$res[0]] = 1;
63
- $proc_data['optimize_table'] = $tables;
64
- WPAdm_Running::setCommandResultData('db', $proc_data);
65
- $log = str_replace('%s', $res[0], __('Error to Optimize Table `%s`' ,'dropbox-backup') );
66
- WPAdm_Core::log($log);
67
- } else {
68
- $log = str_replace('%s', $res[0], __('Optimize Table `%s` was successfully' ,'dropbox-backup') );
69
- WPAdm_Core::log($log);
 
 
 
 
 
 
70
  }
71
  }
 
 
 
 
 
 
72
  }
73
- WPAdm_Core::log( __('Optimize Database Tables was Finished' ,'dropbox-backup') );
74
- $proc_data = WPAdm_Running::getCommandResultData('db');
75
- $proc_data['optimize'] = true;
76
- WPAdm_Running::setCommandResultData('db', $proc_data);
77
  }
78
  }
79
  }
@@ -82,36 +90,43 @@ if (!class_exists('WPAdm_Mysqldump')) {
82
  $proc_data = WPAdm_Running::getCommandResultData('repair');
83
  if (!isset($proc_data['work'])) {
84
  $link = $this->connect($db);
85
-
86
- WPAdm_Core::log( __('MySQL of repair was started' ,'dropbox-backup') );
87
- $n = $link->query('SHOW TABLE STATUS;');
88
- $result = $link->last_result;
89
- if (!empty( $link->last_error )) {
90
- $this->setError($link->last_error);
91
- return false;
92
- }
93
- if ($link->last_result === null) {
94
- $this->setError(print_r(implode("\n", $link->error->errors), 1));
95
- return false;
96
- }
97
- $tables = array();
98
- for($i = 0; $i < $n; $i++ ) {
99
- $row = get_object_vars( $result[$i] );
100
- $tables[] = $row;
101
- WPAdm_Core::log('Start repair table `' . $row['Name'] . '`' );
102
- $res = $link->query("REPAIR TABLE {$row['Name']};");
103
- if ($res == 1) {
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  $proc_data = WPAdm_Running::getCommandResultData('repair');
105
- $proc_data['repair'][$table] = 1;
106
  WPAdm_Running::setCommandResultData('repair', $proc_data);
107
- } else {
108
- $this->setError($link->last_error);
109
  }
110
- WPAdm_Core::log('Finish repair table `' . $row['Name'] . '`');
111
  }
112
- $proc_data = WPAdm_Running::getCommandResultData('repair');
113
- $proc_data['work'] = 1;
114
- WPAdm_Running::setCommandResultData('repair', $proc_data);
115
  }
116
  }
117
 
@@ -120,119 +135,152 @@ if (!class_exists('WPAdm_Mysqldump')) {
120
  $proc_data = WPAdm_Running::getCommandResultData('db');
121
  if (!isset($proc_data['mysqldump'])) {
122
  $link = $this->connect($db);
123
- WPAdm_Core::log( __('MySQL of Dump was started' ,'dropbox-backup') );
124
- $tables = array();
125
- $n = $link->query('SHOW TABLES');
126
- $result = $link->last_result;
127
- if (!empty( $link->last_error )) {
128
- $this->setError($link->last_error);
129
- return false;
130
- }
131
- if ($link->last_result === null) {
132
- /* foreach($link->error->errors as $key => $errors) {
133
- if ($key == db_connect_fail)
134
- }*/
135
- $this->setError(print_r(implode("\n", $link->error->errors), 1));
136
- return false;
137
- }
138
- for($i = 0; $i < $n; $i++ ) {
139
- $row = array_values( get_object_vars( $result[$i] ) );
140
- $tables[] = $row[0];
141
- }
142
-
143
- foreach($tables as $table) {
144
- $return = '';
145
- $proc_data = WPAdm_Running::getCommandResultData('db');
146
- if (!isset($proc_data['mysqldump_table'][$table])) {
147
-
148
-
149
- $result = $link->last_result;
150
- if (!empty( $link->last_error ) && $n > 0) {
151
- $this->setError($link->last_error);
152
  }
153
- $return.= 'DROP TABLE IF EXISTS ' . $table . ';';
 
 
 
 
 
154
 
155
- $ress = $link->query('SHOW CREATE TABLE ' . $table);
156
- $result2 = $link->last_result;
157
- if (!empty( $link->last_error ) && $n > 0) {
158
- $this->setError($link->last_error);
159
- }
160
- $row2 = array_values( get_object_vars( $result2[0] ) );
161
- $return.= "\n\n".$row2[1].";\n\n";
162
 
163
- file_put_contents($filename, $return, FILE_APPEND);
164
- $proc_data = WPAdm_Running::getCommandResultData('db');
165
- $proc_data['mysqldump_table'][$table] = 1;
166
- WPAdm_Running::setCommandResultData('db', $proc_data);
167
- $log = str_replace('%s', $table, __('Add a table "%s" in the database dump' ,'dropbox-backup') );
168
- WPAdm_Core::log( $log );
169
- }
170
- $while = true;
171
- while($while) {
172
- $table_db = WPAdm_Running::getCommandResultData('tabledb');
173
- if (isset($table_db[$table])) {
174
- if (isset($table_db[$table]['work']) && $table_db[$table]['work'] == true) {
175
- $from = $table_db[$table]['from']; // value from
176
- $to = $table_db[$table]['to']; // value to
 
 
177
  }
178
- } else {
179
- $from = 0;
180
- $to = $this->rows;
181
- }
182
- if (isset($from) && !empty($to) && $from >= 0 && $to >= 0) {
183
- unset($link);
184
- $link = $this->connect($db);
185
- $num_fields = $link->query( 'SELECT * FROM ' . $table . " LIMIT {$from}, {$to}" );
186
- if ($num_fields > 0) {
187
-
188
- $result2 = $link->last_result;
189
- for ($i = 0; $i < $num_fields; $i++) {
190
- $return = '';
191
- $row = array_values( get_object_vars( $result2[$i] ) );
192
- //WPAdm_Core::log('row' . print_r($row, 1));
193
- $rows_num = count($row);
194
- if ($rows_num > 0) {
195
- $return.= 'INSERT INTO ' . $table . ' VALUES(';
196
- for($j=0; $j < $rows_num; $j++) {
197
- $row[$j] = addslashes($row[$j]);
198
- $row[$j] = str_replace("\n","\\n",$row[$j]);
199
- if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
200
- if ($j<($rows_num-1)) { $return.= ','; }
201
  }
202
- $return .= ");\n";
203
- file_put_contents($filename, $return, FILE_APPEND);
204
- $from += 1;
205
- $table_db[$table]['from'] = $from;
206
- $table_db[$table]['to'] = $to;
207
- $table_db[$table]['work'] = true;
208
- WPAdm_Running::setCommandResultData('tabledb', $table_db);
209
-
210
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
213
- $log = str_replace(array('%s', '%from%', '%to%'), array($table, $from, $to), __('Add a table rows "%s" in the database dump from %from% to %to%' ,'dropbox-backup') );
214
- WPAdm_Core::log( $log );
215
- } else {
216
- $while = false;
217
- $table_db[$table]['work'] = false;
218
- WPAdm_Running::setCommandResultData('tabledb', $table_db);
219
  }
220
- } else {
221
- $while = false;
222
- $table_db[$table]['work'] = false;
223
- WPAdm_Running::setCommandResultData('tabledb', $table_db);
224
  }
225
  }
226
- if (!isset($proc_data['mysqldump_table'][$table])) {
227
- $return ="\n\n\n";
228
- file_put_contents($filename, $return, FILE_APPEND);
 
 
 
229
  }
230
  }
231
- unset($link);
232
- WPAdm_Core::log( __('MySQL of Dump was finished' ,'dropbox-backup') );
233
- $proc_data = WPAdm_Running::getCommandResultData('db');
234
- $proc_data['mysqldump'] = true;
235
- WPAdm_Running::setCommandResultData('db', $proc_data);
236
  return true;
237
  } else {
238
  return false;
13
 
14
  private function connect($db = '') {
15
  //WPAdm_Core::log("----------------------------------------------------");
16
+ //WPAdm_Core::log( __('Connecting to MySQL...' ,'dropbox-backup') );
17
  if (! class_exists('wpdb')) {
18
  require_once ABSPATH . '/' . WPINC . '/wp-db.php';
19
  }
39
  }
40
  }
41
  }
42
+ return $this->dbh;
43
  }
44
 
45
  public function optimize($db) {
46
  $proc_data = WPAdm_Running::getCommandResultData('db');
47
+ if (!isset($proc_data['optimize'])) {
48
+ if ( WPAdm_Running::is_stop() ) {
49
+ $link = $this->connect($db);
50
+ WPAdm_Core::log( __('Optimize Database Tables was started' ,'dropbox-backup') );
51
+ $n = $link->query('SHOW TABLES');
52
+ WPAdm_Process::init('optimization', $n);
53
+ $result = $link->last_result;
54
+ if (!empty( $link->last_error ) && $n > 0) {
55
+ $this->setError($link->last_error);
56
+ } else {
57
+ for($i = 0; $i < $n; $i++ ) {
58
+ $res = array_values( get_object_vars( $result[$i] ) );
59
+ $proc_data = WPAdm_Running::getCommandResultData('db');
60
+ if ( WPAdm_Running::is_stop() ) {
61
+ if (!isset($proc_data['optimize_table'][$res[0]])) {
62
+ $link->query('OPTIMIZE TABLE '. $res[0]);
63
+ if (!empty( $link->last_error ) ) {
64
+ $tables = isset($proc_data['optimize_table']) ? $proc_data['optimize_table'] : array();
65
+ $tables[$res[0]] = 1;
66
+ $proc_data['optimize_table'] = $tables;
67
+ WPAdm_Running::setCommandResultData('db', $proc_data);
68
+ $log = str_replace('%s', $res[0], __('Error to Optimize Table `%s`' ,'dropbox-backup') );
69
+ WPAdm_Core::log($log);
70
+ } else {
71
+ $log = str_replace('%s', $res[0], __('Optimize Table `%s` was successfully' ,'dropbox-backup') );
72
+ WPAdm_Core::log($log);
73
+ WPAdm_Process::set('optimization', ( $i + 1 ) );
74
+ }
75
+ }
76
  }
77
  }
78
+ if ( WPAdm_Running::is_stop() ) {
79
+ WPAdm_Core::log( __('Optimize Database Tables was Finished' ,'dropbox-backup') );
80
+ $proc_data = WPAdm_Running::getCommandResultData('db');
81
+ $proc_data['optimize'] = true;
82
+ WPAdm_Running::setCommandResultData('db', $proc_data);
83
+ }
84
  }
 
 
 
 
85
  }
86
  }
87
  }
90
  $proc_data = WPAdm_Running::getCommandResultData('repair');
91
  if (!isset($proc_data['work'])) {
92
  $link = $this->connect($db);
93
+ if ( WPAdm_Running::is_stop() ) {
94
+ WPAdm_Core::log( __('MySQL of repair was started' ,'dropbox-backup') );
95
+ $n = $link->query('SHOW TABLE STATUS;');
96
+ WPAdm_Process::init('repair', $n);
97
+ $result = $link->last_result;
98
+ if (!empty( $link->last_error )) {
99
+ $this->setError($link->last_error);
100
+ return false;
101
+ }
102
+ if ($link->last_result === null) {
103
+ $this->setError(print_r(implode("\n", $link->error->errors), 1));
104
+ return false;
105
+ }
106
+ $tables = array();
107
+ for($i = 0; $i < $n; $i++ ) {
108
+ if ( WPAdm_Running::is_stop() ) {
109
+ $row = get_object_vars( $result[$i] );
110
+ $tables[] = $row;
111
+ WPAdm_Core::log('Start repair table `' . $row['Name'] . '`' );
112
+ $res = $link->query("REPAIR TABLE {$row['Name']};");
113
+ if ($res == 1) {
114
+ $proc_data = WPAdm_Running::getCommandResultData('repair');
115
+ $proc_data['repair'][$table] = 1;
116
+ WPAdm_Running::setCommandResultData('repair', $proc_data);
117
+ } else {
118
+ $this->setError($link->last_error);
119
+ }
120
+ WPAdm_Process::set('repair', ($i + 1) );
121
+ WPAdm_Core::log('Finish repair table `' . $row['Name'] . '`');
122
+ }
123
+ }
124
+ if ( WPAdm_Running::is_stop() ) {
125
  $proc_data = WPAdm_Running::getCommandResultData('repair');
126
+ $proc_data['work'] = 1;
127
  WPAdm_Running::setCommandResultData('repair', $proc_data);
 
 
128
  }
 
129
  }
 
 
 
130
  }
131
  }
132
 
135
  $proc_data = WPAdm_Running::getCommandResultData('db');
136
  if (!isset($proc_data['mysqldump'])) {
137
  $link = $this->connect($db);
138
+ if ( WPAdm_Running::is_stop() ) {
139
+ WPAdm_Core::log( __('MySQL of Dump was started' ,'dropbox-backup') );
140
+ $tables = array();
141
+ $n = $link->query('SHOW TABLES');
142
+ WPAdm_Process::init('mysqldump', $n);
143
+ $result = $link->last_result;
144
+ if (!empty( $link->last_error )) {
145
+ $this->setError($link->last_error);
146
+ return false;
147
+ }
148
+ if ($link->last_result === null) {
149
+ /* foreach($link->error->errors as $key => $errors) {
150
+ if ($key == db_connect_fail)
151
+ }*/
152
+ $this->setError(print_r(implode("\n", $link->error->errors), 1));
153
+ return false;
154
+ }
155
+ if ( WPAdm_Running::is_stop() ) {
156
+ for($i = 0; $i < $n; $i++ ) {
157
+ $row = array_values( get_object_vars( $result[$i] ) );
158
+ $tables[] = $row[0];
 
 
 
 
 
 
 
 
159
  }
160
+ }
161
+ if ( WPAdm_Running::is_stop() ) {
162
+ foreach($tables as $key_tables => $table) {
163
+ $return = '';
164
+ $proc_data = WPAdm_Running::getCommandResultData('db');
165
+ if ( !isset($proc_data['mysqldump_table'][$table]) ) {
166
 
167
+ $result = $link->last_result;
168
+ if (!empty( $link->last_error ) && $n > 0) {
169
+ $this->setError($link->last_error);
170
+ }
171
+ if ( WPAdm_Running::is_stop() ) {
172
+ $return.= 'DROP TABLE IF EXISTS ' . $table . ';';
 
173
 
174
+ $ress = $link->query('SHOW CREATE TABLE ' . $table);
175
+ $result2 = $link->last_result;
176
+ if (!empty( $link->last_error ) && $n > 0) {
177
+ $this->setError($link->last_error);
178
+ }
179
+ $row2 = array_values( get_object_vars( $result2[0] ) );
180
+ $return.= "\n\n".$row2[1].";\n\n";
181
+ }
182
+ if ( WPAdm_Running::is_stop() ) {
183
+ file_put_contents($filename, $return, FILE_APPEND);
184
+ $proc_data = WPAdm_Running::getCommandResultData('db');
185
+ $proc_data['mysqldump_table'][$table] = 1;
186
+ WPAdm_Running::setCommandResultData('db', $proc_data);
187
+ $log = str_replace('%s', $table, __('Add a table "%s" in the database dump' ,'dropbox-backup') );
188
+ WPAdm_Core::log( $log );
189
+ }
190
  }
191
+ if ( WPAdm_Running::is_stop() ) {
192
+ $while = true;
193
+ while($while) {
194
+ $insert_values = false;
195
+ if ( WPAdm_Running::is_stop() ) {
196
+ $table_db = WPAdm_Running::getCommandResultData('tabledb');
197
+ if (isset($table_db[$table])) {
198
+ if (isset($table_db[$table]['work']) && $table_db[$table]['work'] == 1) {
199
+ $from = $table_db[$table]['from']; // value from
200
+ $to = $table_db[$table]['to']; // value to
201
+ $insert_values = true;
202
+ }
203
+ } else {
204
+ $from = 0;
205
+ $to = $this->rows;
206
+ $insert_values = true;
 
 
 
 
 
 
 
207
  }
 
 
 
 
 
 
 
 
208
  }
209
+
210
+ if (isset($from) && !empty($to) && $from >= 0 && $to >= 0 && $insert_values === true) {
211
+ unset($link);
212
+ $link = $this->connect($db);
213
+ $num_fields = $link->query( 'SELECT * FROM ' . $table . " LIMIT {$from}, {$to}" );
214
+ if ($num_fields > 0) {
215
+ WPAdm_Core::log( $link->last_error ) ;
216
+ $result2 = $link->last_result;
217
+ for ($i = 0; $i < $num_fields; $i++) {
218
+ if ( WPAdm_Running::is_stop() ) {
219
+ $return = '';
220
+ $row = array_values( get_object_vars( $result2[$i] ) );
221
+ //WPAdm_Core::log('row' . print_r($row, 1));
222
+ $rows_num = count($row);
223
+ if ($rows_num > 0) {
224
+ $return.= 'INSERT INTO ' . $table . ' VALUES(';
225
+ for($j=0; $j < $rows_num; $j++) {
226
+ $row[$j] = addslashes($row[$j]);
227
+ $row[$j] = str_replace("\n","\\n",$row[$j]);
228
+ if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
229
+ if ($j<($rows_num-1)) { $return.= ','; }
230
+ }
231
+ $return .= ");\n";
232
+ file_put_contents($filename, $return, FILE_APPEND);
233
+ $from += 1;
234
+ $table_db = WPAdm_Running::getCommandResultData('tabledb');
235
+ $table_db[$table]['from'] = $from;
236
+ $table_db[$table]['to'] = $to;
237
+ $table_db[$table]['work'] = 1;
238
+ WPAdm_Running::setCommandResultData('tabledb', $table_db);
239
 
240
+ }
241
+ }
242
+ }
243
+ if ( WPAdm_Running::is_stop() ) {
244
+ $log = str_replace(array('%s', '%from%', '%to%'), array($table, $from, $to), __('Add a table rows "%s" in the database dump from %from% to %to%' ,'dropbox-backup') );
245
+ WPAdm_Core::log( $log );
246
+ }
247
+ } else {
248
+ $while = false;
249
+ if ( WPAdm_Running::is_stop() ) {
250
+ $table_db = WPAdm_Running::getCommandResultData('tabledb');
251
+ $table_db[$table]['work'] = 0;
252
+ WPAdm_Running::setCommandResultData('tabledb', $table_db);
253
+ WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
254
+ }
255
+ }
256
+ } else {
257
+ $while = false;
258
+ if ( WPAdm_Running::is_stop() ) {
259
+ $table_db = WPAdm_Running::getCommandResultData('tabledb');
260
+ $table_db[$table]['work'] = 0;
261
+ WPAdm_Running::setCommandResultData('tabledb', $table_db);
262
+ WPAdm_Process::set('mysqldump', ( $key_tables + 1 ) );
263
+ }
264
+ }
265
+ }
266
+ }
267
+ if ( WPAdm_Running::is_stop() ) {
268
+ $proc_data = WPAdm_Running::getCommandResultData('db');
269
+ if (!isset($proc_data['mysqldump_table'][$table])) {
270
+ $return ="\n\n\n";
271
+ file_put_contents($filename, $return, FILE_APPEND);
272
  }
 
 
 
 
 
 
273
  }
 
 
 
 
274
  }
275
  }
276
+ if ( WPAdm_Running::is_stop() ) {
277
+ unset($link);
278
+ WPAdm_Core::log( __('MySQL of Dump was finished' ,'dropbox-backup') );
279
+ $proc_data = WPAdm_Running::getCommandResultData('db');
280
+ $proc_data['mysqldump'] = true;
281
+ WPAdm_Running::setCommandResultData('db', $proc_data);
282
  }
283
  }
 
 
 
 
 
284
  return true;
285
  } else {
286
  return false;
modules/class-wpadm-process.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class WPAdm_Сommand
4
+ */
5
+ if (!class_exists('WPAdm_Process')) {
6
+
7
+ class WPAdm_Process {
8
+
9
+ public static $processes = array('repair', 'optimization', 'mysqldump', 'archiving', 'dropbox');
10
+
11
+ private static $file_name = 'processes.data';
12
+
13
+ private static $file = '';
14
+
15
+ private static $data = array();
16
+
17
+ public static function includeCore()
18
+ {
19
+ if (!class_exists('WPAdm_Core')) {
20
+ include_once 'class-wpadm-core.php';
21
+ WPAdm_Core::$pl_dir = DRBBACKUP_BASE_DIR;
22
+ }
23
+ self::$file = WPAdm_Core::getTmpDir() . '/' . self::$file_name;
24
+ }
25
+
26
+ public static function init($process, $all)
27
+ {
28
+ self::includeCore();
29
+
30
+ if (file_exists(self::$file)) {
31
+ self::$data = wpadm_unpack( file_get_contents( self::$file ) );
32
+ }
33
+ self::$data[$process]['all'] = $all;
34
+ file_put_contents(self::$file, wpadm_pack( self::$data ) );
35
+ }
36
+
37
+
38
+
39
+ public static function clear()
40
+ {
41
+ self::includeCore();
42
+ if ( file_exists( self::$file ) ) {
43
+ unlink(self::$file);
44
+ }
45
+ }
46
+
47
+ public static function set($process, $count = 0)
48
+ {
49
+ self::includeCore();
50
+ if (file_exists(self::$file)) {
51
+ self::$data = wpadm_unpack( file_get_contents( self::$file ) );
52
+ }
53
+ self::$data[$process]['count'] = $count;
54
+ file_put_contents(self::$file, wpadm_pack( self::$data ) );
55
+ }
56
+
57
+ public static function setInc($process, $count = 0)
58
+ {
59
+ self::includeCore();
60
+ if (file_exists(self::$file)) {
61
+ self::$data = wpadm_unpack( file_get_contents( self::$file ) );
62
+ }
63
+ if (isset(self::$data[$process]['count'])) {
64
+ self::set($process, self::$data[$process]['count'] + $count);
65
+ } else {
66
+ self::set($process, $count);
67
+ }
68
+ }
69
+
70
+ public static function get($process)
71
+ {
72
+ self::includeCore();
73
+ if (file_exists(self::$file)) {
74
+ self::$data = wpadm_unpack( file_get_contents( self::$file ) );
75
+ }
76
+ $count = $procent = $all = 0;
77
+ if ( isset( self::$data[$process]['all'] ) && self::$data[$process]['all'] > 0 ) {
78
+ $all = self::$data[$process]['all'];
79
+ $count = isset(self::$data[$process]['count']) ? self::$data[$process]['count'] : 0;
80
+ $procent = round( ( ( $count / self::$data[$process]['all'] ) * 100 ) ) ;
81
+ }
82
+ return array('all' => $all, 'count' => $count, 'procent' => $procent);
83
+ }
84
+
85
+ public static function getAll()
86
+ {
87
+ $result = array();
88
+ $n = count(self::$processes);
89
+ for($i = 0; $i < $n; $i++) {
90
+ $result[self::$processes[$i]] = self::get( self::$processes[$i] );
91
+ }
92
+ return $result;
93
+ }
94
+
95
+ }
96
+
97
+ }
modules/class-wpadm-running.php CHANGED
@@ -4,13 +4,13 @@
4
  */
5
  if (!class_exists('WPAdm_Running')) {
6
 
7
- if (function_exists('set_time_limit')) {
8
- @set_time_limit(0);
9
- }
10
- if (function_exists('ini_set')) {
11
- @ini_set('memory_limit', '2048M');
12
- }
13
-
14
 
15
  add_action('drb_run_backup', array('wpadm_running', 'init') );
16
 
@@ -22,9 +22,9 @@ if (!class_exists('WPAdm_Running')) {
22
 
23
  static function init_params_default($method = true)
24
  {
25
- update_option(PREFIX_BACKUP_ . "_commands", array());
26
  update_option(PREFIX_BACKUP_ . "proccess-command", array());
27
- set_transient('drb_running', 0, 60 * 5);
28
  $path = WPAdm_Core::getTmpDir();
29
  if (!empty($path)) {
30
  WPAdm_Core::rmdir($path . "/db");
@@ -43,7 +43,9 @@ if (!class_exists('WPAdm_Running')) {
43
  WPAdm_Core::rmdir($path . "/files-list-retore");
44
  WPAdm_Core::rmdir($path . "/extract-files-restore");
45
  WPAdm_Core::rmdir($path . "/cron-restore.data");
46
-
 
 
47
  if ($method) {
48
  $files = glob($path ."/wpadm_method*.queue");
49
  if (!empty($files)) {
@@ -52,6 +54,13 @@ if (!class_exists('WPAdm_Running')) {
52
  WPAdm_Core::rmdir($files[$i]);
53
  }
54
  }
 
 
 
 
 
 
 
55
  $files = glob($path ."/wpadm_method*.done");
56
  if (!empty($files)) {
57
  $n = count($files);
@@ -61,87 +70,103 @@ if (!class_exists('WPAdm_Running')) {
61
  }
62
  }
63
  }
64
- }
65
 
66
  static function init()
67
  {
68
  $command = self::getCommand();
69
- if ($command) {
 
70
  WPAdm_Core::$cron = false;
71
  wpadm_class::$type = 'full';
72
  //$time_load = ini_get("max_execution_time");
73
- //WPAdm_Core::log('proccess is work ' . $time_load . 'sec');
74
  /*if ($time_load != 0) {
75
- self::run($time_load - 5);
76
  } else {
77
- self::run(90);
78
  } */
79
- self::run(30);
80
-
81
- if ( self::checkLock() ) {
82
-
83
- $core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
84
- if ( $result = $core->getResult()->toArray(true) ) {
85
- if ($result['result'] == 'success') {
86
- self::delCommand($command['method']);
87
  set_transient('drb_running', 0, 60 * 5);
88
- self::stop();
89
- self::setCommandResultData($command['method'], $result);
90
- self::init();
91
- } elseif ($result['result'] == 'error') {
92
- self::setCommandResultData($command['method'], $result);
93
- self::stop();
94
- self::init_params_default();
95
- }
96
- }
97
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
- public static function checkLock()
101
- {
102
- // false - cron is running
103
- // true - cron not running
104
- $running_cron = get_transient('drb_running');
105
- if ($running_cron && $running_cron == 1) {
106
- $time = microtime( true );
107
- $locked = get_transient('doing_cron');
108
-
109
- if ( $locked > $time + 10 * 60 ) { // 10 minutes
110
- $locked = 0;
111
- }
112
- if ((defined('WP_CRON_LOCK_TIMEOUT') && $locked + WP_CRON_LOCK_TIMEOUT > $time) || (!defined('WP_CRON_LOCK_TIMEOUT') && $locked + 60 > $time)) {
113
- return false;
114
- }
115
- if (function_exists('_get_cron_array')) {
116
- $crons = _get_cron_array();
117
- } else {
118
- $crons = get_option('cron');
119
- }
120
- if (!is_array($crons)) {
121
- return false;
122
- }
123
-
124
- $values = array_values( $crons );
125
- if (isset($values['drb_run_backup'])) {
126
- $keys = array_keys( $crons );
127
- if ( isset($keys[0]) && $keys[0] > $time ) {
128
- return false;
129
- }
130
- }
131
- }
132
- set_transient('drb_running', 1, 60 * 5);
133
- return true;
134
- }
135
-
136
- static function is_running()
137
- {
138
- $running = get_transient('drb_running');
139
- if ($running && $running == 1) {
140
- return true;
141
- }
142
- return false;
143
- }
144
-
145
  static function getCommand($command = '')
146
  {
147
  $commands = get_option(PREFIX_BACKUP_ . "_commands");
@@ -168,13 +193,13 @@ if (!class_exists('WPAdm_Running')) {
168
  $commands = get_option(PREFIX_BACKUP_ . "_commands");
169
  if ($commands !== false && is_array($commands)) {
170
  $id = wpadm_in_array($method, 'method', $commands, true);
171
- unset($commands[$id]);
172
  if (!empty($commands)) {
173
  $commands = array_values($commands);
174
  } else {
175
  $commands = array();
176
  }
177
- update_option(PREFIX_BACKUP_ . "_commands", $commands);
178
  }
179
  }
180
 
@@ -197,7 +222,6 @@ if (!class_exists('WPAdm_Running')) {
197
  {
198
  $options = get_option( PREFIX_BACKUP_ . "proccess-command" );
199
  $id = wpadm_in_array($command, 'command', $options, true );
200
- self::$command_result = $command;
201
  if ($options === false || $id === false ) {
202
  $options[] = array('command' => $command, 'work' => 0);
203
  self::$command_result_id = wpadm_in_array($command, 'command', $options, true );
@@ -214,7 +238,6 @@ if (!class_exists('WPAdm_Running')) {
214
  static function setCommandResultData($command, $data = array())
215
  {
216
  $path = WPAdm_Core::getTmpDir();
217
- self::$command_result_data = $data;
218
  file_put_contents($path ."/$command", wpadm_pack( $data ) );
219
  }
220
  static function delCommandResultData($command)
@@ -238,15 +261,12 @@ if (!class_exists('WPAdm_Running')) {
238
  }
239
  static function getCommandResultData($command)
240
  {
241
- if (self::$command_result == $command) {
242
- return self::$command_result_data;
243
- } else {
244
- $path = WPAdm_Core::getTmpDir();
245
- if (file_exists($path . "/$command")) {
246
- self::$command_result_data = wpadm_unpack( file_get_contents( $path . "/$command" ) );
247
- return self::$command_result_data;
248
- }
249
  }
 
250
  return array();
251
  }
252
  }
4
  */
5
  if (!class_exists('WPAdm_Running')) {
6
 
7
+ if (function_exists('set_time_limit')) {
8
+ @set_time_limit(0);
9
+ }
10
+ if (function_exists('ini_set')) {
11
+ @ini_set('memory_limit', '512M');
12
+ }
13
+
14
 
15
  add_action('drb_run_backup', array('wpadm_running', 'init') );
16
 
22
 
23
  static function init_params_default($method = true)
24
  {
25
+ update_option(PREFIX_BACKUP_ . "_commands", array());
26
  update_option(PREFIX_BACKUP_ . "proccess-command", array());
27
+ set_transient('drb_running', 0, 60 * 5);
28
  $path = WPAdm_Core::getTmpDir();
29
  if (!empty($path)) {
30
  WPAdm_Core::rmdir($path . "/db");
43
  WPAdm_Core::rmdir($path . "/files-list-retore");
44
  WPAdm_Core::rmdir($path . "/extract-files-restore");
45
  WPAdm_Core::rmdir($path . "/cron-restore.data");
46
+ WPAdm_Core::rmdir($path . "/stop_process");
47
+ WPAdm_Core::rmdir($path . "/folder_create");
48
+
49
  if ($method) {
50
  $files = glob($path ."/wpadm_method*.queue");
51
  if (!empty($files)) {
54
  WPAdm_Core::rmdir($files[$i]);
55
  }
56
  }
57
+ $files = glob($path ."/pclzip*.tmp");
58
+ if (!empty($files)) {
59
+ $n = count($files);
60
+ for($i = 0; $i < $n; $i++) {
61
+ WPAdm_Core::rmdir($files[$i]);
62
+ }
63
+ }
64
  $files = glob($path ."/wpadm_method*.done");
65
  if (!empty($files)) {
66
  $n = count($files);
70
  }
71
  }
72
  }
73
+ }
74
 
75
  static function init()
76
  {
77
  $command = self::getCommand();
78
+
79
+ if ($command && self::is_stop() ) {
80
  WPAdm_Core::$cron = false;
81
  wpadm_class::$type = 'full';
82
  //$time_load = ini_get("max_execution_time");
83
+ //WPAdm_Core::log('proccess is work ' . $time_load . 'sec');
84
  /*if ($time_load != 0) {
85
+ self::run($time_load - 5);
86
  } else {
87
+ self::run(90);
88
  } */
89
+ self::run(60);
90
+
91
+ if ( self::checkLock() ) {
92
+
93
+ $core = new WPAdm_Core($command, 'full_backup_dropbox', DRBBACKUP_BASE_DIR);
94
+ if (!is_bool( $core->getResult() ) && is_object( $core->getResult() ) && ( $result = $core->getResult()->toArray(true) ) ) {
95
+ if ($result['result'] == 'success') {
96
+ self::delCommand($command['method']);
97
  set_transient('drb_running', 0, 60 * 5);
98
+ self::stop();
99
+ self::setCommandResultData($command['method'], $result);
100
+ self::init();
101
+ } elseif ($result['result'] == 'error') {
102
+ self::setCommandResultData($command['method'], $result);
103
+ self::stop();
104
+ self::init_params_default();
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ public static function checkLock()
111
+ {
112
+ // false - cron is running
113
+ // true - cron not running
114
+ $running_cron = get_transient('drb_running');
115
+ if ($running_cron && $running_cron == 1) {
116
+ $time = microtime( true );
117
+ $locked = get_transient('doing_cron');
118
+
119
+ if ( $locked > $time + 10 * 60 ) { // 10 minutes
120
+ $locked = 0;
121
+ }
122
+ if ((defined('WP_CRON_LOCK_TIMEOUT') && $locked + WP_CRON_LOCK_TIMEOUT > $time) || (!defined('WP_CRON_LOCK_TIMEOUT') && $locked + 60 > $time)) {
123
+ return false;
124
+ }
125
+ if (function_exists('_get_cron_array')) {
126
+ $crons = _get_cron_array();
127
+ } else {
128
+ $crons = get_option('cron');
129
+ }
130
+ if (!is_array($crons)) {
131
+ return false;
132
+ }
133
+
134
+ $values = array_values( $crons );
135
+ if (isset($values['drb_run_backup'])) {
136
+ $keys = array_keys( $crons );
137
+ if ( isset($keys[0]) && $keys[0] > $time ) {
138
+ return false;
139
+ }
140
+ }
141
+ }
142
+ set_transient('drb_running', 1, 60 * 5);
143
+ return true;
144
+ }
145
+
146
+ static function is_running()
147
+ {
148
+ $running = get_transient('drb_running');
149
+ if ($running && $running == 1) {
150
+ return true;
151
  }
152
+ return false;
153
+ }
154
+
155
+ static function is_stop()
156
+ {
157
+ $stop_precess = self::getCommandResultData('stop_process');
158
+ if ( !empty( $stop_precess ) && isset( $stop_precess['name'] ) && isset( $stop_precess['type'] ) ) {
159
+ $_POST['backup-name'] = $stop_precess['name'];
160
+ if ($stop_precess['type'] == 'dropbox') {
161
+ $_POST['backup-type'] = $stop_precess['type'];
162
+ wpadm_wp_full_backup_dropbox::delete_backup();
163
+ $_POST['backup-type'] = 'local';
164
+ }
165
+ wpadm_wp_full_backup_dropbox::delete_backup();
166
+ }
167
+ return empty($stop_precess);
168
  }
169
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  static function getCommand($command = '')
171
  {
172
  $commands = get_option(PREFIX_BACKUP_ . "_commands");
193
  $commands = get_option(PREFIX_BACKUP_ . "_commands");
194
  if ($commands !== false && is_array($commands)) {
195
  $id = wpadm_in_array($method, 'method', $commands, true);
196
+ unset($commands[$id]);
197
  if (!empty($commands)) {
198
  $commands = array_values($commands);
199
  } else {
200
  $commands = array();
201
  }
202
+ update_option(PREFIX_BACKUP_ . "_commands", $commands);
203
  }
204
  }
205
 
222
  {
223
  $options = get_option( PREFIX_BACKUP_ . "proccess-command" );
224
  $id = wpadm_in_array($command, 'command', $options, true );
 
225
  if ($options === false || $id === false ) {
226
  $options[] = array('command' => $command, 'work' => 0);
227
  self::$command_result_id = wpadm_in_array($command, 'command', $options, true );
238
  static function setCommandResultData($command, $data = array())
239
  {
240
  $path = WPAdm_Core::getTmpDir();
 
241
  file_put_contents($path ."/$command", wpadm_pack( $data ) );
242
  }
243
  static function delCommandResultData($command)
261
  }
262
  static function getCommandResultData($command)
263
  {
264
+ $path = WPAdm_Core::getTmpDir();
265
+ if (file_exists($path . "/$command")) {
266
+ $data = wpadm_unpack( file_get_contents( $path . "/$command" ) );
267
+ return $data;
 
 
 
 
268
  }
269
+
270
  return array();
271
  }
272
  }
modules/constant.php CHANGED
@@ -53,6 +53,13 @@ if (!defined("WPADM_COUNT_LIMIT_SEND_TO_DROPBOX")) {
53
  define("WPADM_COUNT_LIMIT_SEND_TO_DROPBOX", 5);
54
  }
55
 
56
- if (!defined("SITE_HOME")) {
57
  define("SITE_HOME", str_ireplace( array( 'http://', 'https://' ), '', home_url() ) );
 
 
 
 
 
 
 
58
  }
53
  define("WPADM_COUNT_LIMIT_SEND_TO_DROPBOX", 5);
54
  }
55
 
56
+ if (!defined("SITE_HOME") && function_exists( 'home_url' ) ) {
57
  define("SITE_HOME", str_ireplace( array( 'http://', 'https://' ), '', home_url() ) );
58
+ } else {
59
+ if (class_exists('dbr_database')) {
60
+ $data = dbr_database::db_get('options', array('option_value'), array('option_name' => 'home'), 1);
61
+ if (isset($data['option_value'])) {
62
+ define("SITE_HOME", str_ireplace( array( 'http://', 'https://' ), '', $data['option_value'] ) );
63
+ }
64
+ }
65
  }
modules/dropbox.class.php CHANGED
@@ -13,15 +13,15 @@ class dropbox
13
  private $chunk_size_mb = 50;
14
  private $request_token;
15
 
16
- private $api_url = "https://api.dropbox.com/1/";
17
  private $api_url_content = "https://api-content.dropbox.com/1/";
18
 
19
 
20
  /**
21
- * @param $app_key
22
- * @param $app_secret
23
- * @param string $token - постоянный токен
24
- */
25
  public function __construct ($app_key, $app_secret, $token = "")
26
  {
27
  $this->app_key = $app_key;
@@ -30,20 +30,20 @@ class dropbox
30
  }
31
 
32
  /**
33
- * Проверка на то, был ли получен постоянный токен
34
- *
35
- * @return bool
36
- */
37
  public function isAuth()
38
  {
39
  return !empty($this->token);
40
  }
41
 
42
  /**
43
- * Получение временного токена, необходимого для авторизации и получения токена постоянного
44
- *
45
- * @return mixed
46
- */
47
  public function getRequestToken()
48
  {
49
  if (!$this->request_token) {
@@ -56,11 +56,11 @@ class dropbox
56
  }
57
 
58
  /**
59
- * Авторизация, шаг1: Генерация ссылки для авторизации приложения
60
- *
61
- * @param $callback - URL для возвращения токена после авторизации
62
- * @return string
63
- */
64
  public function generateAuthUrl($callback)
65
  {
66
  $request_token = $this->getRequestToken();
@@ -70,11 +70,11 @@ class dropbox
70
 
71
 
72
  /**
73
- * Получение токена, необходимого для запросов к API
74
- *
75
- * @param $request_token - временный токен, полученный функцией getRequestToken
76
- * @return string токен
77
- */
78
  public function getAccessToken($request_token)
79
  {
80
  if (!empty($this->token)) {
@@ -89,25 +89,25 @@ class dropbox
89
  }
90
 
91
  /**
92
- * Удаление файла
93
- *
94
- * @param $file
95
- * @return mixed
96
- */
97
  public function deleteFile($file)
98
  {
99
  return $this->doApi("fileops/delete", "POST", array(
100
- "path" => $file,
101
- "root" => "auto"
102
  ));
103
  }
104
 
105
  /**
106
- * Удаление нескольких файлов
107
- *
108
- * @param array $files
109
- * @return array
110
- */
111
  public function deleteFiles($files = array())
112
  {
113
  $result = array();
@@ -115,8 +115,8 @@ class dropbox
115
  foreach ($files as $file) {
116
  $do = $this->deleteFile($file);
117
  $result[] = array (
118
- "name" => $file,
119
- "result" => $do['error'] ? 0 : 1
120
  );
121
  }
122
 
@@ -124,43 +124,42 @@ class dropbox
124
  }
125
 
126
  /**
127
- * Перемещение файлов
128
- *
129
- * @param $from - откуда
130
- * @param $to - куда
131
- * @return mixed
132
- */
133
  public function moveFile ($from, $to)
134
  {
135
  return $this->doApi("fileops/move", "POST", array(
136
- "root" => "auto",
137
- "from_path" => $from,
138
- "to_path" => $to
139
  ));
140
  }
141
 
142
  public function listing($path)
143
  {
144
  $dir = $this->doApi("metadata/auto/".ltrim($path, "/"), "GET", array(
145
- "list" => TRUE
146
  ));
147
 
148
  if ($dir['error']) {
149
  return $dir;
150
  }
151
- //Это не папка
152
  elseif (!$dir['is_dir']) {
153
  return array (
154
- "size" => $dir['size'],
155
- "bytes" => $dir['bytes'],
156
- "date" => $dir['modified'],
157
- "name" => $dir['path']
158
  );
159
  }
160
 
161
  $all_size = 0;
162
  $items = array();
163
-
164
  foreach ($dir['contents'] as $item) {
165
  if (!$item['is_dir']) {
166
  switch (substr($item['size'], -2)) {
@@ -184,18 +183,18 @@ class dropbox
184
  }
185
 
186
  $items[] = array (
187
- "type" => $item['is_dir'] ? "dir" : "file",
188
- "date" => $item['modified'],
189
- "name" => basename($item['path']),
190
- "size" => $item['size']
191
  );
192
  }
193
 
194
  $dir_result = array (
195
- "size" => $this->bite2other($all_size),
196
- "date" => $dir['modified'],
197
- "name" => $dir['path'],
198
- "items" => $items
199
  );
200
 
201
  return $dir_result;
@@ -211,23 +210,23 @@ class dropbox
211
  if ($size < $kb) {
212
  return $size.' B';
213
  } else if ($size < $mb) {
214
- return round($size / $kb, 2).' KB';
215
- } else if ($size < $gb) {
216
- return round($size / $mb, 2).' MB';
217
- } else if ($size < $tb) {
218
- return round($size / $gb, 2).' GB';
219
- } else {
220
- return round($size / $tb, 2).' TB';
221
  }
222
  }
223
 
224
  /**
225
- * Скачивание файла
226
- *
227
- * @param $file
228
- * @param $server_path - путь, куда скачать на сервер. Если задан -- вернет путь к файлу в случае успешной загрузки.
229
- * @return array
230
- */
231
  public function downloadFile($file, $server_path = "")
232
  {
233
  $isset = $this->listing($file);
@@ -245,8 +244,9 @@ class dropbox
245
  header("Content-Transfer-Encoding: binary");
246
 
247
  $this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
248
- CURLOPT_BINARYTRANSFER => 1,
249
- CURLOPT_RETURNTRANSFER => 0,
 
250
  ), TRUE);
251
  exit;
252
  }
@@ -255,15 +255,16 @@ class dropbox
255
  //Файл недоступен для записи
256
  if (!$fd = fopen($server_path, "wb")) {
257
  return array (
258
- "error" => 1,
259
- "text" => "File '".$server_path."' not writable"
260
  );
261
  }
262
 
263
  $this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
264
- CURLOPT_BINARYTRANSFER => 1,
265
- CURLOPT_RETURNTRANSFER => 1,
266
- CURLOPT_FILE => $fd
 
267
  ), TRUE);
268
 
269
  fclose($fd);
@@ -278,12 +279,12 @@ class dropbox
278
  }
279
 
280
  /**
281
- * Поделиться файлом
282
- *
283
- * @param $file
284
- * @param bool $short_url - короткая ссылка
285
- * @return mixed
286
- */
287
  public function shareFile($file, $short_url = TRUE)
288
  {
289
  $result = $this->doApi("shares/auto/".ltrim($file, "/"), "POST", compact("short_url"));
@@ -291,12 +292,12 @@ class dropbox
291
  }
292
 
293
  /**
294
- * Загрузка нескольких файлов
295
- *
296
- * @param $files - массив формата файл_на_сервере => файл_в_дропбоксе
297
- *
298
- * @return array - информация о списке файлов
299
- */
300
  public function uploadFiles($files = array())
301
  {
302
  $result = array();
@@ -304,8 +305,8 @@ class dropbox
304
  foreach ($files as $file => $dbx) {
305
  $do = $this->uploadFile($file, $dbx);
306
  $result[] = array (
307
- "name" => $file,
308
- "result" => $do['error'] ? 0 : 1
309
  );
310
  }
311
 
@@ -313,13 +314,13 @@ class dropbox
313
  }
314
 
315
  /**
316
- * Загрузка файла
317
- *
318
- * @param $file_path - путь к файлу на сервере
319
- * @param $dropbox_path - куда загружать, если не задан, будет загружен в корень дропбокса с таким же именем
320
- * @param bool $overwrite - заменять ли файлы со схожими именами
321
- * @return mixed
322
- */
323
  public function uploadFile($file_path, $dropbox_path = "", $overwrite = FALSE)
324
  {
325
  if (empty($dropbox_path)) {
@@ -328,8 +329,8 @@ class dropbox
328
 
329
  if (!is_file($file_path)) {
330
  return array(
331
- "error" => 1,
332
- "text" => "File '".$file_path."' not found."
333
  );
334
  }
335
 
@@ -339,15 +340,16 @@ class dropbox
339
  if ($fsize/1024/1024 < $this->max_filesize_mb)
340
  {
341
  $result = $this->doApi("files_put/auto/".ltrim($dropbox_path, "/"),
342
- "PUT",
343
- compact ("overwrite"),
344
- array(
345
- CURLOPT_INFILE => $file,
346
- CURLOPT_INFILESIZE => filesize($file_path),
347
- CURLOPT_BINARYTRANSFER => 1,
348
- CURLOPT_PUT => 1
349
- ),
350
- TRUE);
 
351
 
352
  }
353
  //Файл слишком велик
@@ -361,15 +363,17 @@ class dropbox
361
  $offset += $chunk;
362
 
363
  $result = $this->doApi("chunked_upload",
364
- "PUT",
365
- compact("upload_id", "offset"),
366
- array(
367
- CURLOPT_INFILE => $file,
368
- CURLOPT_INFILESIZE => $chunk,
369
- CURLOPT_BINARYTRANSFER => 1,
370
- CURLOPT_PUT => 1
371
- ),
372
- TRUE);
 
 
373
 
374
  fseek($file, $offset);
375
  if($offset >= $fsize) {
@@ -382,10 +386,10 @@ class dropbox
382
  }
383
 
384
  $result = $this->doApi("commit_chunked_upload/auto/".ltrim($dropbox_path, "/"),
385
- "POST",
386
- compact("upload_id", "overwrite"),
387
- array(),
388
- TRUE);
389
  }
390
 
391
  @fclose($file);
@@ -394,73 +398,61 @@ class dropbox
394
  }
395
 
396
  /**
397
- * Создание директории
398
- *
399
- * @param $path
400
- * @return mixed
401
- */
402
  public function createDir($path)
403
  {
404
  return $this->doApi("fileops/create_folder", "POST", array(
405
- "root" => "auto",
406
- "path" => $path
407
  ));
408
  }
409
 
410
  /**
411
- * Информация об аккаунте
412
- *
413
- * @return mixed
414
- */
415
  public function accInfo()
416
  {
417
  return $this->doApi("account/info", "GET");
418
  }
419
 
420
  /** Запрос к API
421
- *
422
- * @param $op - операция (url)
423
- * @param $method - post/get
424
- * @param array $data - доп. данные, url запрос
425
- * @param array $opts - доп. параметры для curl
426
- * @param $api_content - использовать url для загрузки файлов
427
- * @return mixed
428
- */
429
  private function doApi ($op, $method, $data = array(), $opts = array(), $api_content = FALSE)
430
  {
431
  if (($method == "GET" || $method == "PUT") && count($data)) {
432
  $op .= "?".http_build_query($data);
433
  }
 
434
  $result = $this->doCurl((!$api_content ? $this->api_url : $this->api_url_content).$op, $method, $data, $opts);
435
  $return = json_decode($result, TRUE);
436
  return self::checkError($return);
437
  }
438
 
439
  /**
440
- * Обертка для отправки подписанного запроса через curl
441
- *
442
- * @param $url
443
- * @param string $method
444
- * @param array $data - POST данные
445
- * @param $opts - доп. параметры для curl
446
- * @return mixed
447
- */
448
  public function doCurl($url, $method = "POST", $data = array(), $opts = array())
449
  {
450
- $ch = curl_init($url);
451
- $opts += array(
452
- CURLOPT_RETURNTRANSFER => 1,
453
- CURLOPT_HEADER => 0,
454
- CURLOPT_SSL_VERIFYPEER => 0,
455
- CURLOPT_SSL_VERIFYHOST => 0,
456
- );
457
-
458
-
459
- if ($method == "POST") {
460
- $opts[CURLOPT_POST] = TRUE;
461
- $opts[CURLOPT_POSTFIELDS] = http_build_query($data);
462
- }
463
-
464
  $oauth = new OAuthSimple($this->app_key, $this->app_secret);
465
 
466
  if (!$this->request_token && $this->token) {
@@ -484,23 +476,141 @@ class dropbox
484
  }
485
 
486
  $signed = $oauth->sign(array(
487
- 'action' => $method,
488
- 'path' => $path
489
- )
490
  );
491
- $opts[CURLOPT_HTTPHEADER][] = "Authorization: ".$signed['header'];
492
 
493
- if ($method == "PUT")
494
- {
495
- $opts[CURLOPT_CUSTOMREQUEST] = "PUT";
496
- }
497
- curl_setopt_array($ch, $opts);
498
- $result = curl_exec($ch);
 
 
 
 
 
499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  return $result;
502
  }
503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
 
505
  private static function checkError($return)
506
  {
13
  private $chunk_size_mb = 50;
14
  private $request_token;
15
 
16
+ private $api_url = "https://api.dropbox.com/1/"; // api.dropboxapi.com api.dropbox.com
17
  private $api_url_content = "https://api-content.dropbox.com/1/";
18
 
19
 
20
  /**
21
+ * @param $app_key
22
+ * @param $app_secret
23
+ * @param string $token - постоянный токен
24
+ */
25
  public function __construct ($app_key, $app_secret, $token = "")
26
  {
27
  $this->app_key = $app_key;
30
  }
31
 
32
  /**
33
+ * Проверка на то, был ли получен постоянный токен
34
+ *
35
+ * @return bool
36
+ */
37
  public function isAuth()
38
  {
39
  return !empty($this->token);
40
  }
41
 
42
  /**
43
+ * Получение временного токена, необходимого для авторизации и получения токена постоянного
44
+ *
45
+ * @return mixed
46
+ */
47
  public function getRequestToken()
48
  {
49
  if (!$this->request_token) {
56
  }
57
 
58
  /**
59
+ * Авторизация, шаг1: Генерация ссылки для авторизации приложения
60
+ *
61
+ * @param $callback - URL для возвращения токена после авторизации
62
+ * @return string
63
+ */
64
  public function generateAuthUrl($callback)
65
  {
66
  $request_token = $this->getRequestToken();
70
 
71
 
72
  /**
73
+ * Получение токена, необходимого для запросов к API
74
+ *
75
+ * @param $request_token - временный токен, полученный функцией getRequestToken
76
+ * @return string токен
77
+ */
78
  public function getAccessToken($request_token)
79
  {
80
  if (!empty($this->token)) {
89
  }
90
 
91
  /**
92
+ * Удаление файла
93
+ *
94
+ * @param $file
95
+ * @return mixed
96
+ */
97
  public function deleteFile($file)
98
  {
99
  return $this->doApi("fileops/delete", "POST", array(
100
+ "path" => $file,
101
+ "root" => "auto"
102
  ));
103
  }
104
 
105
  /**
106
+ * Удаление нескольких файлов
107
+ *
108
+ * @param array $files
109
+ * @return array
110
+ */
111
  public function deleteFiles($files = array())
112
  {
113
  $result = array();
115
  foreach ($files as $file) {
116
  $do = $this->deleteFile($file);
117
  $result[] = array (
118
+ "name" => $file,
119
+ "result" => $do['error'] ? 0 : 1
120
  );
121
  }
122
 
124
  }
125
 
126
  /**
127
+ * Перемещение файлов
128
+ *
129
+ * @param $from - откуда
130
+ * @param $to - куда
131
+ * @return mixed
132
+ */
133
  public function moveFile ($from, $to)
134
  {
135
  return $this->doApi("fileops/move", "POST", array(
136
+ "root" => "auto",
137
+ "from_path" => $from,
138
+ "to_path" => $to
139
  ));
140
  }
141
 
142
  public function listing($path)
143
  {
144
  $dir = $this->doApi("metadata/auto/".ltrim($path, "/"), "GET", array(
145
+ "list" => TRUE
146
  ));
147
 
148
  if ($dir['error']) {
149
  return $dir;
150
  }
151
+ //this not folder
152
  elseif (!$dir['is_dir']) {
153
  return array (
154
+ "size" => $dir['size'],
155
+ "bytes" => $dir['bytes'],
156
+ "date" => $dir['modified'],
157
+ "name" => $dir['path']
158
  );
159
  }
160
 
161
  $all_size = 0;
162
  $items = array();
 
163
  foreach ($dir['contents'] as $item) {
164
  if (!$item['is_dir']) {
165
  switch (substr($item['size'], -2)) {
183
  }
184
 
185
  $items[] = array (
186
+ "type" => $item['is_dir'] ? "dir" : "file",
187
+ "date" => $item['modified'],
188
+ "name" => basename($item['path']),
189
+ "size" => $item['size']
190
  );
191
  }
192
 
193
  $dir_result = array (
194
+ "size" => $this->bite2other($all_size),
195
+ "date" => $dir['modified'],
196
+ "name" => $dir['path'],
197
+ "items" => $items
198
  );
199
 
200
  return $dir_result;
210
  if ($size < $kb) {
211
  return $size.' B';
212
  } else if ($size < $mb) {
213
+ return round($size / $kb, 2).' KB';
214
+ } else if ($size < $gb) {
215
+ return round($size / $mb, 2).' MB';
216
+ } else if ($size < $tb) {
217
+ return round($size / $gb, 2).' GB';
218
+ } else {
219
+ return round($size / $tb, 2).' TB';
220
  }
221
  }
222
 
223
  /**
224
+ * Скачивание файла
225
+ *
226
+ * @param $file
227
+ * @param $server_path - путь, куда скачать на сервер. Если задан -- вернет путь к файлу в случае успешной загрузки.
228
+ * @return array
229
+ */
230
  public function downloadFile($file, $server_path = "")
231
  {
232
  $isset = $this->listing($file);
244
  header("Content-Transfer-Encoding: binary");
245
 
246
  $this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
247
+ 'socket' => array('file_download' => $server_path),
248
+ CURLOPT_BINARYTRANSFER => 1,
249
+ CURLOPT_RETURNTRANSFER => 0,
250
  ), TRUE);
251
  exit;
252
  }
255
  //Файл недоступен для записи
256
  if (!$fd = fopen($server_path, "wb")) {
257
  return array (
258
+ "error" => 1,
259
+ "text" => "File '".$server_path."' not writable"
260
  );
261
  }
262
 
263
  $this->doApi("files/auto/".ltrim($file, "/"), "GET", array(), array(
264
+ 'socket' => array('file_download' => $server_path),
265
+ CURLOPT_BINARYTRANSFER => 1,
266
+ CURLOPT_RETURNTRANSFER => 1,
267
+ CURLOPT_FILE => $fd
268
  ), TRUE);
269
 
270
  fclose($fd);
279
  }
280
 
281
  /**
282
+ * Поделиться файлом
283
+ *
284
+ * @param $file
285
+ * @param bool $short_url - короткая ссылка
286
+ * @return mixed
287
+ */
288
  public function shareFile($file, $short_url = TRUE)
289
  {
290
  $result = $this->doApi("shares/auto/".ltrim($file, "/"), "POST", compact("short_url"));
292
  }
293
 
294
  /**
295
+ * Загрузка нескольких файлов
296
+ *
297
+ * @param $files - массив формата файл_на_сервере => файл_в_дропбоксе
298
+ *
299
+ * @return array - информация о списке файлов
300
+ */
301
  public function uploadFiles($files = array())
302
  {
303
  $result = array();
305
  foreach ($files as $file => $dbx) {
306
  $do = $this->uploadFile($file, $dbx);
307
  $result[] = array (
308
+ "name" => $file,
309
+ "result" => $do['error'] ? 0 : 1
310
  );
311
  }
312
 
314
  }
315
 
316
  /**
317
+ * Загрузка файла
318
+ *
319
+ * @param $file_path - путь к файлу на сервере
320
+ * @param $dropbox_path - куда загружать, если не задан, будет загружен в корень дропбокса с таким же именем
321
+ * @param bool $overwrite - заменять ли файлы со схожими именами
322
+ * @return mixed
323
+ */
324
  public function uploadFile($file_path, $dropbox_path = "", $overwrite = FALSE)
325
  {
326
  if (empty($dropbox_path)) {
329
 
330
  if (!is_file($file_path)) {
331
  return array(
332
+ "error" => 1,
333
+ "text" => "File '".$file_path."' not found."
334
  );
335
  }
336
 
340
  if ($fsize/1024/1024 < $this->max_filesize_mb)
341
  {
342
  $result = $this->doApi("files_put/auto/".ltrim($dropbox_path, "/"),
343
+ "PUT",
344
+ compact ("overwrite"),
345
+ array(
346
+ 'socket' => array('file' => $file_path),
347
+ CURLOPT_INFILE => $file,
348
+ CURLOPT_INFILESIZE => filesize($file_path),
349
+ CURLOPT_BINARYTRANSFER => 1,
350
+ CURLOPT_PUT => 1
351
+ ),
352
+ TRUE);
353
 
354
  }
355
  //Файл слишком велик
363
  $offset += $chunk;
364
 
365
  $result = $this->doApi("chunked_upload",
366
+ "PUT",
367
+ compact("upload_id", "offset"),
368
+ array(
369
+ 'socket' => array('file' => $file_path, 'dropbox_path' => $dropbox_path),
370
+
371
+ CURLOPT_INFILE => $file,
372
+ CURLOPT_INFILESIZE => $chunk,
373
+ CURLOPT_BINARYTRANSFER => 1,
374
+ CURLOPT_PUT => 1
375
+ ),
376
+ TRUE);
377
 
378
  fseek($file, $offset);
379
  if($offset >= $fsize) {
386
  }
387
 
388
  $result = $this->doApi("commit_chunked_upload/auto/".ltrim($dropbox_path, "/"),
389
+ "POST",
390
+ compact("upload_id", "overwrite"),
391
+ array(),
392
+ TRUE);
393
  }
394
 
395
  @fclose($file);
398
  }
399
 
400
  /**
401
+ * Создание директории
402
+ *
403
+ * @param $path
404
+ * @return mixed
405
+ */
406
  public function createDir($path)
407
  {
408
  return $this->doApi("fileops/create_folder", "POST", array(
409
+ "root" => "auto",
410
+ "path" => $path
411
  ));
412
  }
413
 
414
  /**
415
+ * Информация об аккаунте
416
+ *
417
+ * @return mixed
418
+ */
419
  public function accInfo()
420
  {
421
  return $this->doApi("account/info", "GET");
422
  }
423
 
424
  /** Запрос к API
425
+ *
426
+ * @param $op - операция (url)
427
+ * @param $method - post/get
428
+ * @param array $data - доп. данные, url запрос
429
+ * @param array $opts - доп. параметры для curl
430
+ * @param $api_content - использовать url для загрузки файлов
431
+ * @return mixed
432
+ */
433
  private function doApi ($op, $method, $data = array(), $opts = array(), $api_content = FALSE)
434
  {
435
  if (($method == "GET" || $method == "PUT") && count($data)) {
436
  $op .= "?".http_build_query($data);
437
  }
438
+
439
  $result = $this->doCurl((!$api_content ? $this->api_url : $this->api_url_content).$op, $method, $data, $opts);
440
  $return = json_decode($result, TRUE);
441
  return self::checkError($return);
442
  }
443
 
444
  /**
445
+ * Обертка для отправки подписанного запроса через curl
446
+ *
447
+ * @param $url
448
+ * @param string $method
449
+ * @param array $data - POST данные
450
+ * @param $opts - доп. параметры для curl
451
+ * @return mixed
452
+ */
453
  public function doCurl($url, $method = "POST", $data = array(), $opts = array())
454
  {
455
+ $result = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  $oauth = new OAuthSimple($this->app_key, $this->app_secret);
457
 
458
  if (!$this->request_token && $this->token) {
476
  }
477
 
478
  $signed = $oauth->sign(array(
479
+ 'action' => $method,
480
+ 'path' => $path
481
+ )
482
  );
 
483
 
484
+ if (function_exists('curl_init')) {
485
+ if (isset($opts['socket'])) {
486
+ unset($opts['socket']);
487
+ }
488
+ $ch = curl_init($url);
489
+ $opts += array(
490
+ CURLOPT_RETURNTRANSFER => 1,
491
+ CURLOPT_HEADER => 0,
492
+ CURLOPT_SSL_VERIFYPEER => 0,
493
+ CURLOPT_SSL_VERIFYHOST => 0,
494
+ );
495
 
496
+ if ($method == "POST") {
497
+ $opts[CURLOPT_POST] = TRUE;
498
+ $opts[CURLOPT_POSTFIELDS] = http_build_query($data);
499
+ }
500
+
501
+ //$oauth = new OAuthSimple($this->app_key, $this->app_secret);
502
+
503
+ /*if (!$this->request_token && $this->token) {
504
+ $this->request_token = $this->token;
505
+ }
506
+
507
+ if ($this->request_token) {
508
+ $oauth->setParameters(array('oauth_token' => $this->request_token['oauth_token']));
509
+ $oauth->signatures(array('oauth_secret'=> $this->request_token['oauth_token_secret']));
510
+ }
511
+
512
+ if ($method == "POST" && count($data)) {
513
+ $oauth->setParameters(http_build_query($data));
514
+ }
515
+
516
+ $path = $url;
517
+ $query = strrchr($url,'?');
518
+ if(!empty($query)) {
519
+ $oauth->setParameters(substr($query,1));
520
+ $path = substr($url, 0, -strlen($query));
521
+ }
522
+
523
+ $signed = $oauth->sign(array(
524
+ 'action' => $method,
525
+ 'path' => $path
526
+ )
527
+ ); */
528
+ $opts[CURLOPT_HTTPHEADER][] = "Authorization: ".$signed['header'];
529
 
530
+ if ($method == "PUT") {
531
+ $opts[CURLOPT_CUSTOMREQUEST] = "PUT";
532
+ }
533
+ curl_setopt_array($ch, $opts);
534
+ $result = curl_exec($ch);
535
+
536
+ } elseif (function_exists('fsockopen')) {
537
+ include_once dirname(__FILE__) . '/HttpFsockopen.php';
538
+ $socket = new HttpFsockopen($url, false);
539
+ if ($method == 'POST') {
540
+ $socket->setPostData($data);
541
+ }
542
+ if ($method == 'PUT') {
543
+ if (isset($opts['socket']['file'])) {
544
+ $data = '';
545
+ srand( (double)microtime() * 1000000);
546
+ $file_data = join('', file( $opts['socket']['file'] ) ) ;
547
+ $rand = substr( md5( rand( 0, 32000 ) ), 0, 10);
548
+ $boundary = $rand;
549
+ $data = "";
550
+ $data .= "Content-Disposition: form-data; name=\"" . basename($opts['socket']['file']) ."\"; filename=\"" . basename( $opts['socket']['file'] ) . "\"\r\n";
551
+ $data .= "Content-Type: application/x-www-form-urlencoded;\r\n"; //multipart/form-data;
552
+ $data .= "Content-length: " . strlen($file_data) . "\r\n";
553
+ $data .= "Connection: close\r\n\r\n";
554
+ $data .= $file_data ;
555
+ $socket->setStrHeaders($data);
556
+ $socket->setMethod("PUT");
557
+ }
558
+ }
559
+ $socket->setHeaders('Authorization', $signed['header']);
560
+ $res = $socket->exec();
561
+ if ($method == 'GET') {
562
+ if (isset($opts['socket']['file_download'])) {
563
+ $r = $this->getResult($res);
564
+ if (isset($r[1])) {
565
+ file_put_contents($opts['socket']['file_download'], $r[1]);
566
+ }
567
+ }
568
+ }
569
+ if ( empty($result) ) {
570
+ $res = $this->getResult($res);
571
+ if (isset($res[1])) {
572
+ $res1 = $this->getResult($res[1], "\r", true);
573
+ preg_match("/{.*}/is", trim($res1), $r);
574
+ if(isset($r[0])) {
575
+ $result = $r[0];
576
+ } else {
577
+ $res1 = $this->getResult($res[1], "\n", true);
578
+ preg_match("/{.*}/is", trim($res1), $r);
579
+ if(isset($r[0])) {
580
+ $result = $r[0];
581
+ } else {
582
+ $res1 = $this->getResult($res[1], "\r\n", true);
583
+ preg_match("/{.*}/is", trim($res1), $r);
584
+ if(isset($r[0])) {
585
+ $result = $r[0];
586
+ }
587
+
588
+ }
589
+ }
590
+
591
+ }
592
+ }
593
+ }
594
  return $result;
595
  }
596
 
597
+ private function getResult($str, $patern = "\r\n\r\n", $is_json = false)
598
+ {
599
+ if ($is_json === false) {
600
+ return explode($patern, $str);
601
+ } else {
602
+ $res = explode($patern, $str);
603
+ $n = count($res);
604
+ $result = '';
605
+ for($i = 0; $i < $n; $i++) {
606
+ if ( preg_match_all("/[\{\"\:\,\}\s]+/is", trim($res[$i]), $r ) ) {
607
+ $result .= str_replace(array("\r", "\n"), '', $res[$i]);
608
+ }
609
+ }
610
+ return $result;
611
+ }
612
+ }
613
+
614
 
615
  private static function checkError($return)
616
  {
modules/restore-class.php CHANGED
@@ -262,40 +262,38 @@ if ( !class_exists('dbr_api') ) {
262
  $info = curl_getinfo($curl);
263
  curl_close($curl);
264
  } elseif (function_exists("fsockopen")) {
265
- $postdata = http_build_query($post, '', '&');
266
- $length = strlen($postdata);
267
- $url = trim( substr(WPADM_URL_BASE, 7), '/' );
268
- $req = '/api/';
269
- $out = "POST " . $req . " HTTP/1.1\r\n";
270
- $out.= "HOST: " . $url . "\r\n";
271
- $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
272
- $out.= "Content-Length: ".$length."\r\n";
273
- $out.= "Connection:Close\r\n\r\n";
274
- $out.= $postdata."\r\n\r\n";
275
- try {
276
- $errno='';
277
- $errstr = '';
278
- $socket = @fsockopen($url, 80, $errno, $errstr, 30);
279
- if($socket) {
280
- if(!fwrite($socket, $out)) {
281
- throw new Exception("unable to write fsockopen");
282
- } else {
283
- while ($in = @fgets ($socket, 1024)) {
284
- $result .= $in;
285
- }
286
- }
287
- $result = explode("\r\n\r\n", $result);
288
- $result = $result[1];
289
-
290
  }
291
- } catch(exception $e) {
292
- array('res' => $result, 'info' => $info );
293
  }
 
294
  }
295
- return array('res' => $result, 'info' => $info );
296
  }
297
-
298
  }
 
299
  }
300
 
301
  if ( !class_exists('dbr_helper') ) {
@@ -573,9 +571,11 @@ if ( !class_exists('dbr_methods') ) {
573
  if ($is_sql) {
574
  $ress = dbr_database::query( $sql );
575
  }
576
- if ( $ress === false || !empty( dbr_database::$error )) {
577
- dbr_helper::setError('MySQL Error: ' . dbr_database::$error );
578
- break;
 
 
579
  };
580
  $sql = "";
581
  }
262
  $info = curl_getinfo($curl);
263
  curl_close($curl);
264
  } elseif (function_exists("fsockopen")) {
265
+ include_once 'HttpFsockopen.php';
266
+ $socket = new HttpFsockopen($url, false);
267
+ $socket->setPostData($post);
268
+ if (isset($options['timelimit'])) {
269
+ $socket->setTimeout($options['timelimit']);
270
+ }
271
+ $res = $socket->exec();
272
+ $res = self::getResult($res);
273
+ if (isset($res[1])) {
274
+ $result = $res[1];
275
+ }
276
+ }
277
+ return array('res' => $result, 'info' => $info );
278
+ }
279
+ public static function getResult ($str, $patern = "\r\n\r\n", $is_json = false)
280
+ {
281
+ if ($is_json === false) {
282
+ return explode($patern, $str);
283
+ } else {
284
+ $res = explode($patern, $str);
285
+ $n = count($res);
286
+ $result = '';
287
+ for($i = 0; $i < $n; $i++) {
288
+ if ( preg_match_all("/[\{\"\:\,\}\s]+/is", trim($res[$i]), $r ) ) {
289
+ $result .= str_replace(array("\r", "\n"), '', $res[$i]);
290
  }
 
 
291
  }
292
+ return $result;
293
  }
 
294
  }
 
295
  }
296
+
297
  }
298
 
299
  if ( !class_exists('dbr_helper') ) {
571
  if ($is_sql) {
572
  $ress = dbr_database::query( $sql );
573
  }
574
+ if ( $ress === false || !empty( dbr_database::$error )) {
575
+ if (stripos(dbr_database::$error, 'duplicate entry') === false) {
576
+ dbr_helper::setError('MySQL Error: ' . dbr_database::$error );
577
+ break;
578
+ }
579
  };
580
  $sql = "";
581
  }
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Backup & Restore Dropbox ===
2
  Plugin Name: Backup & Restore Dropbox
3
- Version: 1.4.6.2
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
7
  Requires at least: 3.9
8
- Tested up to: 4.5
9
  Stable tag: trunk
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -391,7 +391,12 @@ Please, keep your Dropbox Backup and Restore plugin up-to-date.
391
 
392
  **Rev.**&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;**Description** <br />
393
 
394
- &nbsp;&nbsp;&nbsp;&nbsp;check permission of backup folder
 
 
 
 
 
395
  @1400462&nbsp;&nbsp;&nbsp;&nbsp;filter for ajax text(html)
396
  @1393861&nbsp;&nbsp;&nbsp;&nbsp;Dropbox backup and restore tested up to WordPress 4.5
397
  @1390219&nbsp;&nbsp;&nbsp;&nbsp;Dropbox backup and restore fixes.<br />
1
  === Backup & Restore Dropbox ===
2
  Plugin Name: Backup & Restore Dropbox
3
+ Version: 1.4.7
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
7
  Requires at least: 3.9
8
+ Tested up to: 4.5.3
9
  Stable tag: trunk
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
391
 
392
  **Rev.**&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;**Description** <br />
393
 
394
+ @1448769&nbsp;&nbsp;&nbsp;&nbsp;"Dropbox backup & restore" - added tmp folder for library pclzip, deleted files tmp for pclzip
395
+ @1442461&nbsp;&nbsp;&nbsp;&nbsp;"Dropbox backup & restore" - Show as Item in "Admin bar"
396
+ @1438063&nbsp;&nbsp;&nbsp;&nbsp;"Dropbox backup & restore" new version(1.4.7) added - stop button, bugs fixed, update styles, process restore to connect mysql, process bar, update processes on creating mysqldump, archive files
397
+ @1427803&nbsp;&nbsp;&nbsp;&nbsp;"Dropbox backup & restore" - update a view notice
398
+ @1420446&nbsp;&nbsp;&nbsp;&nbsp;Changed
399
+ @1407804&nbsp;&nbsp;&nbsp;&nbsp;"Dropbox backup & restore" new version(1.4.4) added - check permission of backup folder
400
  @1400462&nbsp;&nbsp;&nbsp;&nbsp;filter for ajax text(html)
401
  @1393861&nbsp;&nbsp;&nbsp;&nbsp;Dropbox backup and restore tested up to WordPress 4.5
402
  @1390219&nbsp;&nbsp;&nbsp;&nbsp;Dropbox backup and restore fixes.<br />
template/advantage-plugin.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="inline" style="width: 60%">
2
+ <span style="font-size:16px;">
3
+ <?php _e('Use Professional version of "Dropbox backup and restore" plugin and get:','dropbox-backup') ; ?>
4
+ </span>
5
+ <ul class="list-dropbox-backup-pro">
6
+ <li><img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
7
+ <span class="text">
8
+ <?php _e('Automated Dropbox backup (Scheduled backup tasks)','dropbox-backup') ; ?>
9
+ </span>
10
+ </li>
11
+ <li>
12
+ <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
13
+ <span class="text">
14
+ <?php _e('Automated Local backup (Scheduled backup tasks)','dropbox-backup') ; ?>
15
+ </span>
16
+ </li>
17
+ <li>
18
+ <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
19
+ <span class="text">
20
+ <?php _e('Backup Status E-Mail Reporting','dropbox-backup') ; ?>
21
+ </span>
22
+ </li>
23
+ <li>
24
+ <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
25
+ <span class="text">
26
+ <?php _e('Online Service "Backup Website Manager" (Copy, Clone or Migrate of websites)','dropbox-backup') ; ?>
27
+ </span>
28
+ </li>
29
+ <li>
30
+ <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
31
+ <span class="text">
32
+ <?php _e('One Year Free Updates for PRO version','dropbox-backup') ; ?>
33
+ </span>
34
+ </li>
35
+ <li>
36
+ <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
37
+ <span class="text">
38
+ <?php _e('One Year Priority support','dropbox-backup') ; ?>
39
+ </span>
40
+ </li>
41
+ </ul>
42
+ </div>
43
+ <div class="inline-right" style="margin-top: 0;">
44
+ <div class="image-dropbox-pro" onclick="document.dropbox_pro_form.submit();">
45
+ <img src="<?php echo plugins_url('/template/dropbox_pro_logo_box1.png', dirname(__FILE__));?>" title="<?php _e('Get PRO version','dropbox-backup');?>" alt="<?php _e('Get PRO version','dropbox-backup'); ?>">
46
+ </div>
47
+ <div style="margin-top:26%; float: left; margin-left: 20px; margin-right: 15px;">
48
+ <form action="<?php echo WPADM_URL_PRO_VERSION; ?>api/" method="post" id="dropbox_pro_form" name="dropbox_pro_form" >
49
+ <input type="hidden" value="<?php echo home_url();?>" name="site">
50
+ <input type="hidden" value="<?php echo 'proBackupPay'?>" name="actApi">
51
+ <input type="hidden" value="<?php echo get_option('admin_email');?>" name="email">
52
+ <input type="hidden" value="<?php echo 'dropbox-backup';?>" name="plugin">
53
+ <input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=success"); ?>" name="success_url">
54
+ <input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=cancel"); ?>" name="cancel_url">
55
+ <input type="submit" class="backup_button" value="<?php _e('Get PRO','dropbox-backup');?>">
56
+ </form>
57
+ </div>
58
+ </div>
59
+
60
+ <div class="clear"></div>
template/css/admin-style-wpadm.css CHANGED
@@ -1,24 +1,4 @@
1
 
2
- .list-dropbox-backup-pro {
3
- margin-top:10px;
4
- margin-bottom:0;
5
- }
6
- .list-dropbox-backup-pro li {
7
- margin-bottom: 0;
8
- font-size:14px;
9
- margin-left:35px;
10
- }
11
- .list-dropbox-backup-pro .text {
12
- line-height: 25px;
13
- }
14
- .image-dropbox-pro {
15
- width: 183px;
16
- height: 187px;
17
- border:2px solid #ddd;
18
- cursor: pointer;
19
- text-align: center;
20
- float:left;
21
- }
22
  .dropbox-image-toolbar a:before {
23
  content: url('./../../img/wpadm-logo.png');
24
  /*background-image: ;*/
@@ -38,50 +18,6 @@
38
  content:"/";
39
  }
40
 
41
- .backup_button {
42
- -moz-box-shadow:inset 0px 1px 0px 0px #9fb4f2;
43
- -webkit-box-shadow:inset 0px 1px 0px 0px #9fb4f2;
44
- box-shadow:inset 0px 1px 0px 0px #9fb4f2;
45
- background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #7892c2), color-stop(1, #476e9e));
46
- background:-moz-linear-gradient(top, #7892c2 5%, #476e9e 100%);
47
- background:-webkit-linear-gradient(top, #7892c2 5%, #476e9e 100%);
48
- background:-o-linear-gradient(top, #7892c2 5%, #476e9e 100%);
49
- background:-ms-linear-gradient(top, #7892c2 5%, #476e9e 100%);
50
- background:linear-gradient(to bottom, #7892c2 5%, #476e9e 100%);
51
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#7892c2', endColorstr='#476e9e',GradientType=0);
52
- background-color:#7892c2;
53
- -moz-border-radius:3px;
54
- -webkit-border-radius:3px;
55
- border-radius:3px;
56
- border:1px solid #4e6096;
57
- display:inline-block;
58
- cursor:pointer;
59
- color:#ffffff;
60
- font-family:Arial;
61
- font-size:17px;
62
- font-weight:bold;
63
- padding:10px 20px;
64
- text-decoration:none;
65
- text-shadow:0px 1px 0px #283966;
66
- }
67
- .backup_button:hover {
68
- background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #476e9e), color-stop(1, #7892c2));
69
- background:-moz-linear-gradient(top, #476e9e 5%, #7892c2 100%);
70
- background:-webkit-linear-gradient(top, #476e9e 5%, #7892c2 100%);
71
- background:-o-linear-gradient(top, #476e9e 5%, #7892c2 100%);
72
- background:-ms-linear-gradient(top, #476e9e 5%, #7892c2 100%);
73
- background:linear-gradient(to bottom, #476e9e 5%, #7892c2 100%);
74
- filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#476e9e', endColorstr='#7892c2',GradientType=0);
75
- background-color:#476e9e;
76
- color:#fff;
77
- }
78
- .backup_button:active {
79
- position:relative;
80
- top:1px;
81
- }
82
- button.backup_button:disabled, button.backup_button:disabled:hover {
83
- background: #9eb7d8;
84
- }
85
  .form-counter {
86
  background: #0096d6;
87
  border: 1px solid #fff;
@@ -105,17 +41,86 @@ button.backup_button:disabled, button.backup_button:disabled:hover {
105
  border: 1px solid #e8e8e8;
106
  padding: 10px;
107
  }
108
- #logs-form, #reviews-dropbox, #action-buttons {
109
  float:left;
110
  }
111
- #logs-form, #reviews-dropbox {
112
  padding: 10px; background: #ffffc8; border: 1px solid #0096d6; position: relative; height: 100px; text-align: center;
113
  }
114
- #reviews-dropbox {
115
  float: right;
116
  height: 150px;
117
  width: 25%;
118
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  #action-buttons {
120
  margin-right: 10px;
121
  float:left;
@@ -292,16 +297,7 @@ button.backup_button:disabled, button.backup_button:disabled:hover {
292
  padding: 0;
293
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
294
  }
295
- .inline-right {
296
- float:right;
297
- }
298
- .inline {
299
- float:left;
300
- }
301
- .inline-right, .inline {
302
- margin-top:10px;
303
- margin-left:10px;
304
- }
305
  #header_navigation_line #main_menu ul li a {
306
  background: -moz-linear-gradient(center top , #2e9ed2 5%, #21749b 100%) repeat scroll 0 0 #2e9ed2;
307
  border: 1px solid #1b5f7f;
@@ -510,7 +506,38 @@ h3.plugins-title {
510
  }
511
  .setting-checkbox {
512
  padding-left: 5px;margin-top: 5px;
 
513
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  .form-help-send-error input[type="text"], .form-help-send-error input[type="text"] {
515
  padding: 0px;
516
  border: 1px solid #999;
@@ -954,16 +981,16 @@ font-size:12px;
954
  height: 20px;
955
  }
956
  .dbb-info-details-form {
957
- line-height: 16px;
958
- margin:7px;
959
- padding:7px 11px;
960
- font-size:14px;
961
  }
962
  .dbb-info-details-form .button-submit {
963
- padding:5px;
964
- margin-top:11px;
965
- margin-bottom:18px;
966
-
967
  }
968
 
969
  }
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  .dropbox-image-toolbar a:before {
3
  content: url('./../../img/wpadm-logo.png');
4
  /*background-image: ;*/
18
  content:"/";
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  .form-counter {
22
  background: #0096d6;
23
  border: 1px solid #fff;
41
  border: 1px solid #e8e8e8;
42
  padding: 10px;
43
  }
44
+ #logs-form, #reviews-dropbox, #action-buttons, #process-box {
45
  float:left;
46
  }
47
+ #logs-form, #reviews-dropbox, #process-box {
48
  padding: 10px; background: #ffffc8; border: 1px solid #0096d6; position: relative; height: 100px; text-align: center;
49
  }
50
+ #reviews-dropbox, #process-box {
51
  float: right;
52
  height: 150px;
53
  width: 25%;
54
  }
55
+ #process-box {
56
+ height: 150px;
57
+ width: 35%;
58
+ }
59
+
60
+ #process-box .inline {
61
+ float:none;
62
+ margin:0;
63
+ text-align: left;;
64
+ margin-bottom:8px;
65
+ }
66
+
67
+ .progress-box {
68
+ position: relative;
69
+ z-index: 5;
70
+ background:#fff;
71
+ border:1px solid #ccc;
72
+ border-radius: 0px;
73
+ display: inline-block;
74
+
75
+ }
76
+ .progress-text {
77
+ position: absolute;
78
+ font: bold 14px/20px Arial;
79
+ text-align: left;
80
+ margin-left:5px;
81
+ top: 0;
82
+ left: 0;
83
+ z-index:21;
84
+ }
85
+ .procent-progress {
86
+ float:right;
87
+ margin-right:10px;
88
+ }
89
+ .progress, .progress-bar, .progress-text {
90
+ width: 100%;
91
+ height: 15px;
92
+ color: #595959;
93
+ text-shadow: 1px 1px 2px rgba(255, 255, 255, 1);
94
+ font-size:11px;
95
+ line-height: 13px;
96
+ }
97
+
98
+ .progress-bar {
99
+ overflow: hidden;
100
+ position: relative;
101
+ z-index: 10;
102
+ border-radius: 0px;
103
+ width: 0;
104
+ -moz-transition: width .3s linear;
105
+ -webkit-transition: width .3s linear;
106
+ -o-transition: width .3s linear;
107
+ transition: width .3s linear;
108
+ background-color: #00f42e;
109
+ background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.35) 25%, rgba(255, 255, 255, 0) 25%, rgba(255, 255, 255, 0) 50%, rgba(255, 255, 255, 0.35) 50%, rgba(255, 255, 255, 0.35) 75%, rgba(255, 255, 255, 0) 75%, rgba(255, 255, 255, 0));
110
+ background-repeat: repeat-x;
111
+ background-size: 20px 20px;
112
+ -webkit-animation: candystripe 3s linear infinite;
113
+ -moz-animation: candystripe 3s linear infinite;
114
+ animation: candystripe 3s linear infinite;
115
+ }
116
+
117
+
118
+
119
+ #process-box .main-title {
120
+ font-size: 16px;
121
+ margin-bottom: 15px;
122
+ }
123
+
124
  #action-buttons {
125
  margin-right: 10px;
126
  float:left;
297
  padding: 0;
298
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
299
  }
300
+
 
 
 
 
 
 
 
 
 
301
  #header_navigation_line #main_menu ul li a {
302
  background: -moz-linear-gradient(center top , #2e9ed2 5%, #21749b 100%) repeat scroll 0 0 #2e9ed2;
303
  border: 1px solid #1b5f7f;
506
  }
507
  .setting-checkbox {
508
  padding-left: 5px;margin-top: 5px;
509
+ clear:both;
510
  }
511
+ .setting-checkbox input[type="checkbox"] {
512
+ margin: 2px 5px 0px 0px;
513
+ }
514
+ .setting-checkbox input[type="checkbox"], .setting-checkbox label, .setting-checkbox select, .setting-checkbox span {
515
+ float:left;
516
+ }
517
+ .setting-checkbox label {
518
+ margin-bottom:6px;
519
+ }
520
+ .setting-checkbox .dashicons-editor-help {
521
+ margin-left:-3px;
522
+ margin-top: -1px;
523
+ }
524
+ .setting-checkbox select {
525
+ margin-top: -5px;
526
+ }
527
+
528
+ .ui-tooltip {
529
+ padding: 8px;
530
+ position: absolute;
531
+ z-index: 9999;
532
+ max-width: 300px;
533
+ -webkit-box-shadow: 0 0 5px #aaa;
534
+ box-shadow: 0 0 5px #aaa;
535
+ background: #fff;
536
+ }
537
+ body .ui-tooltip {
538
+ border-width: 2px;
539
+ }
540
+
541
  .form-help-send-error input[type="text"], .form-help-send-error input[type="text"] {
542
  padding: 0px;
543
  border: 1px solid #999;
981
  height: 20px;
982
  }
983
  .dbb-info-details-form {
984
+ line-height: 16px;
985
+ margin:7px;
986
+ padding:7px 11px;
987
+ font-size:14px;
988
  }
989
  .dbb-info-details-form .button-submit {
990
+ padding:5px;
991
+ margin-top:11px;
992
+ margin-bottom:18px;
993
+
994
  }
995
 
996
  }
template/css/tool-bar.css CHANGED
@@ -1,4 +1,82 @@
1
  .dropbox-image-toolbar a:before {
2
  content: url('./../../img/wpadm-logo.png');
3
  /*background-image: ;*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
1
  .dropbox-image-toolbar a:before {
2
  content: url('./../../img/wpadm-logo.png');
3
  /*background-image: ;*/
4
+ }
5
+
6
+ .list-dropbox-backup-pro {
7
+ margin-top:10px;
8
+ margin-bottom:0;
9
+ }
10
+ .list-dropbox-backup-pro li {
11
+ margin-bottom: 0;
12
+ font-size:14px;
13
+ margin-left:35px;
14
+ }
15
+ .list-dropbox-backup-pro .text {
16
+ line-height: 25px;
17
+ }
18
+ .image-dropbox-pro {
19
+ width: 183px;
20
+ height: 187px;
21
+ border:2px solid #ddd;
22
+ cursor: pointer;
23
+ text-align: center;
24
+ float:left;
25
+ }
26
+
27
+
28
+ .backup_button {
29
+ -moz-box-shadow:inset 0px 1px 0px 0px #9fb4f2;
30
+ -webkit-box-shadow:inset 0px 1px 0px 0px #9fb4f2;
31
+ box-shadow:inset 0px 1px 0px 0px #9fb4f2;
32
+ background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #7892c2), color-stop(1, #476e9e));
33
+ background:-moz-linear-gradient(top, #7892c2 5%, #476e9e 100%);
34
+ background:-webkit-linear-gradient(top, #7892c2 5%, #476e9e 100%);
35
+ background:-o-linear-gradient(top, #7892c2 5%, #476e9e 100%);
36
+ background:-ms-linear-gradient(top, #7892c2 5%, #476e9e 100%);
37
+ background:linear-gradient(to bottom, #7892c2 5%, #476e9e 100%);
38
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#7892c2', endColorstr='#476e9e',GradientType=0);
39
+ background-color:#7892c2;
40
+ -moz-border-radius:3px;
41
+ -webkit-border-radius:3px;
42
+ border-radius:3px;
43
+ border:1px solid #4e6096;
44
+ display:inline-block;
45
+ cursor:pointer;
46
+ color:#ffffff;
47
+ font-family:Arial;
48
+ font-size:17px;
49
+ font-weight:bold;
50
+ padding:10px 20px;
51
+ text-decoration:none;
52
+ text-shadow:0px 1px 0px #283966;
53
+ }
54
+ .backup_button:hover {
55
+ background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #476e9e), color-stop(1, #7892c2));
56
+ background:-moz-linear-gradient(top, #476e9e 5%, #7892c2 100%);
57
+ background:-webkit-linear-gradient(top, #476e9e 5%, #7892c2 100%);
58
+ background:-o-linear-gradient(top, #476e9e 5%, #7892c2 100%);
59
+ background:-ms-linear-gradient(top, #476e9e 5%, #7892c2 100%);
60
+ background:linear-gradient(to bottom, #476e9e 5%, #7892c2 100%);
61
+ filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#476e9e', endColorstr='#7892c2',GradientType=0);
62
+ background-color:#476e9e;
63
+ color:#fff;
64
+ }
65
+ .backup_button:active {
66
+ position:relative;
67
+ top:1px;
68
+ }
69
+ button.backup_button:disabled, button.backup_button:disabled:hover {
70
+ background: #9eb7d8;
71
+ }
72
+
73
+ .inline-right {
74
+ float:right;
75
+ }
76
+ .inline {
77
+ float:left;
78
+ }
79
+ .inline-right, .inline {
80
+ margin-top:10px;
81
+ margin-left:10px;
82
  }
template/notice.php CHANGED
@@ -1,8 +1,22 @@
1
  <div class="clear"></div>
2
  <div class="update-nag" style="width: 95%;">
3
  <?php _e('Professional version of','dropbox-backup'); ?>
4
- "<a href="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"); ?>" title="<?php _e('Dropbox backup and restore"','dropbox-backup')?>" alt="<?php _e('Dropbox backup and restore','dropbox-backup')?>"><?php _e('Dropbox backup and restore','dropbox-backup')?></a>"
5
  <?php _e(' plugin is now available!','dropbox-backup'); ?>
6
- <a href="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox"); ?>" title="<?php _e('Read more...','dropbox-backup')?>" alt="<?php _e('Read more...','dropbox-backup')?>"><?php _e('Read more...','dropbox-backup')?></a>
7
  <a href="<?php echo admin_url( 'admin-post.php?action=hide_notice&type=preview' ); ?>" style="float: right; font-size: 12px;">[<?php _e('hide this message','dropbox-backup')?>]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </div>
1
  <div class="clear"></div>
2
  <div class="update-nag" style="width: 95%;">
3
  <?php _e('Professional version of','dropbox-backup'); ?>
4
+ "<a href="javascript:showProWPADMDescription();" title="<?php _e('Dropbox backup and restore"','dropbox-backup')?>" alt="<?php _e('Dropbox backup and restore','dropbox-backup')?>"><?php _e('Dropbox backup and restore','dropbox-backup')?></a>"
5
  <?php _e(' plugin is now available!','dropbox-backup'); ?>
6
+ <a href="javascript:showProWPADMDescription();" title="<?php _e('Read more...','dropbox-backup')?>" alt="<?php _e('Read more...','dropbox-backup')?>"><?php _e('Read more...','dropbox-backup')?></a>
7
  <a href="<?php echo admin_url( 'admin-post.php?action=hide_notice&type=preview' ); ?>" style="float: right; font-size: 12px;">[<?php _e('hide this message','dropbox-backup')?>]</a>
8
+ <div id="pro-plugin-description" style="margin-top:15px;display: none;">
9
+ <?php include 'advantage-plugin.php'; ?>
10
+ </div>
11
+ <script>
12
+ function showProWPADMDescription()
13
+ {
14
+ var disp = jQuery('#pro-plugin-description').css('display');
15
+ if (disp == 'none') {
16
+ jQuery('#pro-plugin-description').show(700);
17
+ } else {
18
+ jQuery('#pro-plugin-description').hide(700);
19
+ }
20
+ }
21
+ </script>
22
  </div>
template/wpadm_show_backup.php CHANGED
@@ -8,6 +8,30 @@
8
  </style>
9
  <script>
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  function disable_buttons()
12
  {
13
  jQuery('.disable-button').each(function() {
@@ -87,7 +111,7 @@
87
  jQuery("#logs-form").show("slow");
88
  jQuery("#action-buttons").css('margin-top', '8px');
89
  <?php if(!$stars5) { ?>
90
- jQuery("#support-button").css('margin-top', '132px');
91
  <?php } else { ?>
92
  jQuery("#support-button").css('margin-top', '8px');
93
  <?php } ?>
@@ -95,6 +119,9 @@
95
  jQuery(".title-logs").css('display', 'block');
96
  jQuery(".title-status").css('display', 'none');
97
  type_backup = 'local_backup';
 
 
 
98
  jQuery.ajax({
99
  type: "POST",
100
  url: ajaxurl,
@@ -119,49 +146,41 @@
119
  }
120
  function AjaxAlert(jqXHR, textStatus, errorThrown)
121
  {
122
- <?php $command_running = get_transient('running_command');
123
- if (isset($is_runnig) && $is_runnig && $command_running) {
124
- echo 'var running_command = true;';
125
- } else {
126
- echo 'var running_command = false;';
127
- }
128
- ?>
129
- if (running_command === false ) {
130
- var msg = 'Website "' + home_url + '" returned an error during operation with return:<br /><br /> <span style="font-size:13px; font-style: italic;">code: ' + jqXHR.status + ', text status: ' + textStatus + ', text: ' + errorThrown + "</span>";
131
- jQuery("#ajax-message").html(msg);
132
- jQuery("#msg_ajax").val(msg);
133
- jQuery('#ajax-alert').arcticmodal({
134
- beforeOpen: function(data, el) {
135
- jQuery('#ajax-alert').css('display','block');
136
- },
137
- afterClose: function(data, el) {
138
- jQuery('#ajax-alert').css('display','none');
139
  }
140
- });
141
- enable_buttons();
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
  }
144
 
 
 
145
  function stopBackup()
146
  {
147
-
148
- var data_backup = {
149
- 'action': 'stop_backup',
150
- 'type-backup': type_backup,
151
- };
152
- jQuery.ajax({
153
- type: "POST",
154
- url: ajaxurl,
155
- data: data_backup,
156
- dataType: 'json',
157
- success: function(data){
158
-
159
- },
160
- error: function(jqXHR, textStatus, errorThrown) {
161
- processStop();
162
- AjaxAlert(jqXHR, textStatus, errorThrown);
163
- },
164
- });
165
 
166
  }
167
 
@@ -180,13 +199,17 @@
180
  jQuery("#action-buttons").css('margin-top', '8px');
181
 
182
  <?php if(!$stars5) { ?>
183
- jQuery("#support-button").css('margin-top', '132px');
184
  <?php } else { ?>
185
  jQuery("#support-button").css('margin-top', '8px');
186
  <?php } ?>
187
  jQuery("#log-backup").html('');
188
  jQuery(".title-logs").css('display', 'block');
189
  jQuery(".title-status").css('display', 'none');
 
 
 
 
190
  type_backup = 'send-to-dropbox';
191
  jQuery.ajax({
192
  type: "POST",
@@ -276,7 +299,7 @@
276
  } else {
277
  var error_log = '';
278
  if (data.error && data.error != 'undefined') {
279
- error_log = ': ' + data.error;
280
  }
281
  jQuery('.title-logs').css('display', 'none');
282
  jQuery('.title-status').css({'display':'block', 'color':'red'});
@@ -364,7 +387,10 @@
364
  var data_log = {
365
  'action': 'wpadm_logs',
366
  'type-backup' : method,
367
- };
 
 
 
368
 
369
  var url_ajax = ajaxurl;
370
  if (method == 'restore') {
@@ -386,6 +412,12 @@
386
  jQuery("#log-backup").html(l);
387
  }
388
  }
 
 
 
 
 
 
389
  if (process_flag == 1) {
390
  if (data.data) {
391
  if (method == 'restore') {
@@ -398,17 +430,20 @@
398
  showData(data.data);
399
  }
400
  processStop();
 
401
  } else {
402
- setTimeout('processBar("' + method + '")', 5000);
403
  }
404
  }
405
  } else {
406
- setTimeout('processBar("' + method + '")', 5000);
407
  }
408
  },
409
  error: function(jqXHR, textStatus, errorThrown){
410
- processStop();
411
- AjaxAlert(jqXHR, textStatus, errorThrown);
 
 
412
  },
413
  });
414
  }
@@ -491,7 +526,7 @@
491
  jQuery("#log-backup").html('');
492
  jQuery("#action-buttons").css('margin-top', '8px');
493
  <?php if(!$stars5) { ?>
494
- jQuery("#support-button").css('margin-top', '132px');
495
  <?php } else { ?>
496
  jQuery("#support-button").css('margin-top', '8px');
497
  <?php } ?>
@@ -796,10 +831,14 @@
796
  function saveSetting(id)
797
  {
798
  if (jQuery('#' + id).length > 0) {
799
- is_value = 0;
800
- if(document.getElementById(id).checked) {
801
- is_value = 1;
802
- }
 
 
 
 
803
 
804
  data = {'action' : 'saveSetting'}
805
  data[id] = is_value;
@@ -861,7 +900,7 @@
861
  jQuery("#action-buttons").css('margin-top', '8px');
862
 
863
  <?php if(!$stars5) { ?>
864
- jQuery("#support-button").css('margin-top', '132px');
865
  <?php } else { ?>
866
  jQuery("#support-button").css('margin-top', '8px');
867
  <?php } ?>
@@ -874,10 +913,16 @@
874
  disable_buttons() ;
875
  }, 10)
876
  process_flag = 1;
 
 
 
877
  processBar(type_backup);
878
  showTime(1);
879
  });
880
  <?php }?>
 
 
 
881
  </script>
882
  <?php if (!empty($error)) {
883
  echo '<div class="error" style="text-align: center; color: red; font-weight:bold;">
@@ -1005,68 +1050,8 @@
1005
  <input type="button" value="<?php _e('OK','dropbox-backup'); ?>" onclick="jQuery('#helper-keys').arcticmodal('close');" style="text-align: center; width: 100px;" class="button-wpadm">
1006
  </div>
1007
  </div>
1008
- <!-- <a href="#" onclick="stopBackup();">Stop backup</a> -->
1009
  <div class="block-content" style="margin-top:20px;">
1010
- <div class="inline" style="width: 60%">
1011
- <span style="font-size:16px;">
1012
- <?php _e('Use Professional version of "Dropbox backup and restore" plugin and get:','dropbox-backup') ; ?>
1013
- </span>
1014
- <ul class="list-dropbox-backup-pro">
1015
- <li><img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1016
- <span class="text">
1017
- <?php _e('Automated Dropbox backup (Scheduled backup tasks)','dropbox-backup') ; ?>
1018
- </span>
1019
- </li>
1020
- <li>
1021
- <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1022
- <span class="text">
1023
- <?php _e('Automated Local backup (Scheduled backup tasks)','dropbox-backup') ; ?>
1024
- </span>
1025
- </li>
1026
- <li>
1027
- <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1028
- <span class="text">
1029
- <?php _e('Backup Status E-Mail Reporting','dropbox-backup') ; ?>
1030
- </span>
1031
- </li>
1032
- <li>
1033
- <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1034
- <span class="text">
1035
- <?php _e('Online Service "Backup Website Manager" (Copy, Clone or Migrate of websites)','dropbox-backup') ; ?>
1036
- </span>
1037
- </li>
1038
- <li>
1039
- <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1040
- <span class="text">
1041
- <?php _e('One Year Free Updates for PRO version','dropbox-backup') ; ?>
1042
- </span>
1043
- </li>
1044
- <li>
1045
- <img src="<?php echo plugins_url('/template/ok-icon.png', dirname(__FILE__));?>" title="" alt="" />
1046
- <span class="text">
1047
- <?php _e('One Year Priority support','dropbox-backup') ; ?>
1048
- </span>
1049
- </li>
1050
- </ul>
1051
- </div>
1052
- <div class="inline-right" style="margin-top: 0;">
1053
- <div class="image-dropbox-pro" onclick="document.dropbox_pro_form.submit();">
1054
- <img src="<?php echo plugins_url('/template/dropbox_pro_logo_box1.png', dirname(__FILE__));?>" title="<?php _e('Get PRO version','dropbox-backup');?>" alt="<?php _e('Get PRO version','dropbox-backup'); ?>">
1055
- </div>
1056
- <div style="margin-top:26%; float: left; margin-left: 20px; margin-right: 15px;">
1057
- <form action="<?php echo WPADM_URL_PRO_VERSION; ?>api/" method="post" id="dropbox_pro_form" name="dropbox_pro_form" >
1058
- <input type="hidden" value="<?php echo home_url();?>" name="site">
1059
- <input type="hidden" value="<?php echo 'proBackupPay'?>" name="actApi">
1060
- <input type="hidden" value="<?php echo get_option('admin_email');?>" name="email">
1061
- <input type="hidden" value="<?php echo 'dropbox-backup';?>" name="plugin">
1062
- <input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=success"); ?>" name="success_url">
1063
- <input type="hidden" value="<?php echo admin_url("admin.php?page=wpadm_wp_full_backup_dropbox&pay=cancel"); ?>" name="cancel_url">
1064
- <input type="submit" class="backup_button" value="<?php _e('Get PRO','dropbox-backup');?>">
1065
- </form>
1066
- </div>
1067
- </div>
1068
-
1069
- <div class="clear"></div>
1070
  </div>
1071
  <div class="block-content" style="margin-top:2px;">
1072
  <div style="min-height : 215px; padding: 5px; padding-top: 10px;">
@@ -1213,6 +1198,21 @@
1213
  </tbody>
1214
  </table>
1215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1216
  <?php if ( is_super_admin() ) { ?>
1217
  <div class="setting-checkbox">
1218
  <input type="checkbox" <?php echo isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ? 'checked="checked"' : ''; ?> name="is_admin" value="1" id="is_admin" onclick="saveSetting('is_admin')" />
@@ -1225,12 +1225,16 @@
1225
  </div>
1226
  <div class="setting-checkbox">
1227
  <input type="checkbox" <?php echo (isset($dropbox_options['is_local_backup_delete']) && $dropbox_options['is_local_backup_delete'] == 1) ? 'checked="checked"' : ''; ?> name="is_local_backup_delete" value="1" id="is_local_backup_delete" onclick="saveSetting('is_local_backup_delete')" />
1228
- <label for="is_local_backup_delete" style="font-size: 13px;"><?php _e('Don\'t delete a local backup copy after uploading to dropbox','dropbox-backup'); ?></label>
1229
  </div>
1230
  <div class="setting-checkbox">
1231
  <input type="checkbox" <?php echo (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 'checked="checked"' : ''; ?> name="is_repair" value="1" id="is_repair" onclick="saveSetting('is_repair')" />
1232
  <label for="is_repair" style="font-size: 13px;"><?php _e('Try database repair','dropbox-backup'); ?></label>
1233
  </div>
 
 
 
 
1234
  </div>
1235
  </form>
1236
  </div>
@@ -1247,8 +1251,12 @@
1247
  <div style="clear: both;"></div>
1248
  <div class="block-content">
1249
  <div class="" style="margin-top:10px;">
1250
- <div id="logs-form" style="display: none; float:left; width: 70%;">
1251
- <div class="title-logs"><span style="font-size:16px;"><?php _e('Please wait...','dropbox-backup'); ?> <span id="time_backup">0 <?php _e('sec.','dropbox-backup'); ?></span><img style="float: right;" src="<?php echo plugins_url('/img/wpadmload.gif', dirname(__FILE__))?>" alt=""></span></div>
 
 
 
 
1252
  <div class="title-status" style="font-size:16px; display: none;"></div>
1253
  <div style="border: 1px solid #ddd; text-align: left; background: #fff; padding: 2px;">
1254
  <div id="log-backup" style="overflow: auto; height: 60px; border: 5px solid #fff; "></div>
@@ -1261,6 +1269,57 @@
1261
  <img src="<?php echo plugins_url('/img/stars-5.png', dirname(__FILE__));?>" alt=""></a>
1262
  </div>
1263
  <?php }?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1264
  <div id="support-button" style="float: right; margin-top: 130px; margin-right: 20px;">
1265
  <button onclick="window.open('<?php echo SERVER_URL_INDEX . 'support/?pl=dbp'?>')" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Help','dropbox-backup'); ?></button> <br />
1266
  </div>
@@ -1271,6 +1330,9 @@
1271
  <div style="float: left; margin-top: 2px;">
1272
  <button onclick="start_local_backup()" text-button="<?php _e('Create Local Backup','dropbox-backup');?>" class="backup_button disable-button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Create Local Backup','dropbox-backup'); ?></button> <br />
1273
  </div>
 
 
 
1274
  <!-- <div style="float: left; margin-top: 2px;margin-left: 20px;">
1275
  <button onclick="InludesSetting();" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Folders & files','dropbox-backup'); ?></button> <br />
1276
  </div> -->
@@ -1290,6 +1352,9 @@
1290
  <input type="hidden" name="backup-name" id="backup_name" value="" />
1291
  <input type="hidden" name="backup-type" id="backup_type" value="" />
1292
  </form>
 
 
 
1293
  <!-- <div id="inludes-setting" class="" style="display: none; position: relative; text-align: center; background: #f1ebeb; border: 2px solid #dde4ff; border-radius: 5px;">
1294
  <div>
1295
  <div class="title-description" style="font-size: 20px; text-align: center;padding-top:20px; line-height: 30px;">
8
  </style>
9
  <script>
10
 
11
+ function showProcessesData(data)
12
+ {
13
+ if (type_backup == 'send-to-dropbox') {
14
+ jQuery('#dropbox-process').css('display', 'block');
15
+ }
16
+ for(i in data) {
17
+ if (data[i]['all']) {
18
+ if (data[i]['all'] > 0) {
19
+ jQuery('#' + i + '-process').css('display', 'block');
20
+ jQuery('.stats-' + i ).css('display', 'inline');
21
+ }
22
+ jQuery('#all_' + i).html(data[i]['all']);
23
+ }
24
+ if (data[i]['count']) {
25
+ jQuery('#count_' + i).html(data[i]['count']);
26
+ }
27
+ if (data[i]['procent']) {
28
+ jQuery('#procent_' + i).html(data[i]['procent'] + '%');
29
+ }
30
+ jQuery('.procent-' + i).css('width', data[i]['procent'] + '%');
31
+ }
32
+
33
+ }
34
+
35
  function disable_buttons()
36
  {
37
  jQuery('.disable-button').each(function() {
111
  jQuery("#logs-form").show("slow");
112
  jQuery("#action-buttons").css('margin-top', '8px');
113
  <?php if(!$stars5) { ?>
114
+ jQuery("#support-button").css('margin-top', '9px');
115
  <?php } else { ?>
116
  jQuery("#support-button").css('margin-top', '8px');
117
  <?php } ?>
119
  jQuery(".title-logs").css('display', 'block');
120
  jQuery(".title-status").css('display', 'none');
121
  type_backup = 'local_backup';
122
+ jQuery('#process-box').show('slow');
123
+ jQuery('#reviews-dropbox').hide('slow');
124
+ jQuery('#stop-button').css('display', 'block');
125
  jQuery.ajax({
126
  type: "POST",
127
  url: ajaxurl,
146
  }
147
  function AjaxAlert(jqXHR, textStatus, errorThrown)
148
  {
149
+ if (stop_backup_flag === false) {
150
+ <?php $command_running = get_transient('running_command');
151
+ if (isset($is_runnig) && $is_runnig && $command_running) {
152
+ echo 'var running_command = true;';
153
+ } else {
154
+ echo 'var running_command = false;';
 
 
 
 
 
 
 
 
 
 
 
155
  }
156
+ ?>
157
+ if (running_command === false ) {
158
+ var msg = 'Website "' + home_url + '" returned an error during operation with return:<br /><br /> <span style="font-size:13px; font-style: italic;">code: ' + jqXHR.status + ', text status: ' + textStatus + ', text: ' + errorThrown + "</span>";
159
+ jQuery("#ajax-message").html(msg);
160
+ jQuery("#msg_ajax").val(msg);
161
+ jQuery('#ajax-alert').arcticmodal({
162
+ beforeOpen: function(data, el) {
163
+ jQuery('#ajax-alert').css('display','block');
164
+ },
165
+ afterClose: function(data, el) {
166
+ jQuery('#ajax-alert').css('display','none');
167
+ }
168
+ });
169
+ enable_buttons();
170
+ }
171
  }
172
  }
173
 
174
+ var stop_backup_flag = false;
175
+
176
  function stopBackup()
177
  {
178
+ // type_backup != '' &&
179
+ if ( confirm("<?php _e('Interrupted progress in backup? All data is lost.', 'dropbox-backup')?>")) {
180
+ stop_backup_flag = true;
181
+ document.stop_backups.type_backup.value = type_backup;
182
+ document.stop_backups.submit();
183
+ }
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  }
186
 
199
  jQuery("#action-buttons").css('margin-top', '8px');
200
 
201
  <?php if(!$stars5) { ?>
202
+ jQuery("#support-button").css('margin-top', '9px');
203
  <?php } else { ?>
204
  jQuery("#support-button").css('margin-top', '8px');
205
  <?php } ?>
206
  jQuery("#log-backup").html('');
207
  jQuery(".title-logs").css('display', 'block');
208
  jQuery(".title-status").css('display', 'none');
209
+ jQuery('#process-box').show('slow');
210
+ jQuery('#reviews-dropbox').hide('slow');
211
+ jQuery('#stop-button').css('display', 'block');
212
+ jQuery('#dropbox-process').css('display', 'block');
213
  type_backup = 'send-to-dropbox';
214
  jQuery.ajax({
215
  type: "POST",
299
  } else {
300
  var error_log = '';
301
  if (data.error && data.error != 'undefined') {
302
+ error_log = data.error;
303
  }
304
  jQuery('.title-logs').css('display', 'none');
305
  jQuery('.title-status').css({'display':'block', 'color':'red'});
387
  var data_log = {
388
  'action': 'wpadm_logs',
389
  'type-backup' : method,
390
+ };
391
+ if (method == 'send-to-dropbox') {
392
+ data_log['type-backup2'] = 'local_backup';
393
+ }
394
 
395
  var url_ajax = ajaxurl;
396
  if (method == 'restore') {
412
  jQuery("#log-backup").html(l);
413
  }
414
  }
415
+
416
+ if (data.processes) {
417
+ console.log(data.processes);
418
+ showProcessesData(data.processes);
419
+ }
420
+
421
  if (process_flag == 1) {
422
  if (data.data) {
423
  if (method == 'restore') {
430
  showData(data.data);
431
  }
432
  processStop();
433
+ jQuery('#stop-button').css('display', 'none');
434
  } else {
435
+ setTimeout('processBar("' + method + '")', 10000);
436
  }
437
  }
438
  } else {
439
+ setTimeout('processBar("' + method + '")', 10000);
440
  }
441
  },
442
  error: function(jqXHR, textStatus, errorThrown){
443
+ if (jqXHR.status != 0) {
444
+ processStop();
445
+ AjaxAlert(jqXHR, textStatus, errorThrown);
446
+ }
447
  },
448
  });
449
  }
526
  jQuery("#log-backup").html('');
527
  jQuery("#action-buttons").css('margin-top', '8px');
528
  <?php if(!$stars5) { ?>
529
+ jQuery("#support-button").css('margin-top', '9px');
530
  <?php } else { ?>
531
  jQuery("#support-button").css('margin-top', '8px');
532
  <?php } ?>
831
  function saveSetting(id)
832
  {
833
  if (jQuery('#' + id).length > 0) {
834
+ if ( jQuery('#' + id).is('select') ) {
835
+ is_value = jQuery('#' + id).val();
836
+ } else {
837
+ is_value = 0;
838
+ if(document.getElementById(id).checked) {
839
+ is_value = 1;
840
+ }
841
+ }
842
 
843
  data = {'action' : 'saveSetting'}
844
  data[id] = is_value;
900
  jQuery("#action-buttons").css('margin-top', '8px');
901
 
902
  <?php if(!$stars5) { ?>
903
+ jQuery("#support-button").css('margin-top', '9px');
904
  <?php } else { ?>
905
  jQuery("#support-button").css('margin-top', '8px');
906
  <?php } ?>
913
  disable_buttons() ;
914
  }, 10)
915
  process_flag = 1;
916
+ jQuery('#process-box').show('slow');
917
+ jQuery('#reviews-dropbox').hide('slow');
918
+ jQuery('#stop-button').css('display', 'block');
919
  processBar(type_backup);
920
  showTime(1);
921
  });
922
  <?php }?>
923
+ jQuery(document).ready(function() {
924
+ jQuery('.wpadm-tooltip').tooltip();
925
+ });
926
  </script>
927
  <?php if (!empty($error)) {
928
  echo '<div class="error" style="text-align: center; color: red; font-weight:bold;">
1050
  <input type="button" value="<?php _e('OK','dropbox-backup'); ?>" onclick="jQuery('#helper-keys').arcticmodal('close');" style="text-align: center; width: 100px;" class="button-wpadm">
1051
  </div>
1052
  </div>
 
1053
  <div class="block-content" style="margin-top:20px;">
1054
+ <?php include 'advantage-plugin.php'; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1055
  </div>
1056
  <div class="block-content" style="margin-top:2px;">
1057
  <div style="min-height : 215px; padding: 5px; padding-top: 10px;">
1198
  </tbody>
1199
  </table>
1200
 
1201
+ <div class="setting-checkbox">
1202
+ <span class="dashicons dashicons-editor-help wpadm-tooltip" title="<?php _e('The average waiting time before error message will be displayed. During this time the plugin will try to perform failed operation attempts. If this time was expired and operation still fails, the backup process will be interrupted and the message about problem will be shown on the screen.', 'dropbox-backup')?>"></span>
1203
+ <label for="time_error" style="font-size: 13px;"><?php _e('Waiting time (minutes)', 'dropbox-backup'); ?></label>
1204
+ <select name="time_error" id="time_error" onchange="saveSetting('time_error')">
1205
+ <?php
1206
+ for($i = 1; $i < 11; $i++) {
1207
+ ?>
1208
+ <option value="<?php echo $i?>" <?php echo isset($dropbox_options['time_error']) && $dropbox_options['time_error'] == $i ? 'selected="selected"' : (!isset($dropbox_options['time_error']) && $i == $default ) ? 'selected="selected"' : '' ?> ><?php echo $i?>:00</option>
1209
+ <?php
1210
+ }
1211
+ ?>
1212
+ </select>
1213
+
1214
+ <span></span>
1215
+ </div>
1216
  <?php if ( is_super_admin() ) { ?>
1217
  <div class="setting-checkbox">
1218
  <input type="checkbox" <?php echo isset($dropbox_options['is_admin']) && $dropbox_options['is_admin'] == 1 ? 'checked="checked"' : ''; ?> name="is_admin" value="1" id="is_admin" onclick="saveSetting('is_admin')" />
1225
  </div>
1226
  <div class="setting-checkbox">
1227
  <input type="checkbox" <?php echo (isset($dropbox_options['is_local_backup_delete']) && $dropbox_options['is_local_backup_delete'] == 1) ? 'checked="checked"' : ''; ?> name="is_local_backup_delete" value="1" id="is_local_backup_delete" onclick="saveSetting('is_local_backup_delete')" />
1228
+ <label for="is_local_backup_delete" style="font-size: 13px; width: 90%"><?php _e('Don\'t delete a local backup copy after uploading to dropbox','dropbox-backup'); ?></label>
1229
  </div>
1230
  <div class="setting-checkbox">
1231
  <input type="checkbox" <?php echo (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) ? 'checked="checked"' : ''; ?> name="is_repair" value="1" id="is_repair" onclick="saveSetting('is_repair')" />
1232
  <label for="is_repair" style="font-size: 13px;"><?php _e('Try database repair','dropbox-backup'); ?></label>
1233
  </div>
1234
+ <div class="setting-checkbox">
1235
+ <input type="checkbox" <?php echo (isset($dropbox_options['is_show_admin_bar']) && $dropbox_options['is_show_admin_bar'] == 1) ? 'checked="checked"' : ( !isset($dropbox_options['is_show_admin_bar']) ? 'checked="checked"' : '' ); ?> name="is_show_admin_bar" value="1" id="is_show_admin_bar" onclick="saveSetting('is_show_admin_bar')" />
1236
+ <label for="is_show_admin_bar" style="font-size: 13px;"><?php _e('Show in a admin bar','dropbox-backup'); ?></label>
1237
+ </div>
1238
  </div>
1239
  </form>
1240
  </div>
1251
  <div style="clear: both;"></div>
1252
  <div class="block-content">
1253
  <div class="" style="margin-top:10px;">
1254
+ <div id="logs-form" style="display: none; float:left; width: 60%;">
1255
+ <div class="title-logs progress-box">
1256
+ <span style="font-size:16px;"><?php _e('Please wait...','dropbox-backup'); ?>
1257
+ <span id="time_backup">0 <?php _e('sec.','dropbox-backup'); ?></span>
1258
+ </span>
1259
+ </div>
1260
  <div class="title-status" style="font-size:16px; display: none;"></div>
1261
  <div style="border: 1px solid #ddd; text-align: left; background: #fff; padding: 2px;">
1262
  <div id="log-backup" style="overflow: auto; height: 60px; border: 5px solid #fff; "></div>
1269
  <img src="<?php echo plugins_url('/img/stars-5.png', dirname(__FILE__));?>" alt=""></a>
1270
  </div>
1271
  <?php }?>
1272
+ <div id="process-box" style="display: none;">
1273
+ <div class="main-title"><?php _e('Backup processing status', 'dropbox-backup')?></div>
1274
+ <?php if (isset($dropbox_options['is_repair']) && $dropbox_options['is_repair'] == 1) {?>
1275
+ <div class="inline progress-box" id="repair-process" data-width="0%" style="display: block;">
1276
+ <div class="progress-text">
1277
+ <?php _e('Repairing of database tables', 'dropbox-backup')?>
1278
+ <span class="stats-repair" style="display: none;">(<span id="count_repair">0</span> <?php _e('of', 'dropbox-backup'); ?> <span id="all_repair">0</span>)</span> <span class="procent-progress" id="procent_repair">0%</span>
1279
+ </div>
1280
+ <div class="progress-bar procent-repair" style="width: 0%;">
1281
+ </div>
1282
+ </div>
1283
+ <?php } ?>
1284
+ <?php if ( !isset($dropbox_options['is_optimization']) || ( isset($dropbox_options['is_optimization']) && $dropbox_options['is_optimization'] == 1 ) ) { ?>
1285
+ <div class="inline progress-box" id="optimization-process" style="display: block;">
1286
+ <div class="progress-text">
1287
+ <?php _e('Optimization of database tables', 'dropbox-backup')?>
1288
+ <span class="stats-optimization" style="display: none;">(<span id="count_optimization">0</span> <?php _e('of', 'dropbox-backup'); ?> <span id="all_optimization">0</span>)</span> <span class="procent-progress" id="procent_optimization">0%</span>
1289
+ </div>
1290
+ <div class="progress-bar procent-optimization" style="width: 0%;">
1291
+ </div>
1292
+ </div>
1293
+ <?php } ?>
1294
+
1295
+ <div class="inline progress-box" id="mysqldump-process" style="display: block;">
1296
+ <div class="progress-text">
1297
+ <?php _e('Creation of database dump', 'dropbox-backup')?>
1298
+ <span class="stats-mysqldump" style="display: none;">(<span id="count_mysqldump">0</span> <?php _e('of', 'dropbox-backup'); ?> <span id="all_mysqldump">0</span>)</span> <span class="procent-progress" id="procent_mysqldump">0%</span>
1299
+ </div>
1300
+ <div class="progress-bar procent-mysqldump" style="width: 0%;">
1301
+ </div>
1302
+ </div>
1303
+
1304
+
1305
+ <div class="inline progress-box" id="archiving-process" style="display: block;">
1306
+ <div class="progress-text">
1307
+ <?php _e('Archiving of files', 'dropbox-backup')?>
1308
+ <span class="stats-archiving" style="display: none;">(<span id="count_archiving">0</span> <?php _e('of', 'dropbox-backup'); ?> <span id="all_archiving">0</span>)</span> <span class="procent-progress" id="procent_archiving">0%</span>
1309
+ </div>
1310
+ <div class="progress-bar procent-archiving" style="width: 0%;">
1311
+ </div>
1312
+ </div>
1313
+
1314
+ <div class="inline progress-box" id="dropbox-process" style="display: none;">
1315
+ <div class="progress-text">
1316
+ <?php _e('Sending of backup to Dropbox', 'dropbox-backup')?>
1317
+ <span class="stats-dropbox" style="display: none;">(<span id="count_dropbox">0</span> <?php _e('of', 'dropbox-backup'); ?> <span id="all_dropbox">0</span>)</span> <span class="procent-progress" id="procent_dropbox">0%</span>
1318
+ </div>
1319
+ <div class="progress-bar procent-dropbox" style="width: 0%;">
1320
+ </div>
1321
+ </div>
1322
+ </div>
1323
  <div id="support-button" style="float: right; margin-top: 130px; margin-right: 20px;">
1324
  <button onclick="window.open('<?php echo SERVER_URL_INDEX . 'support/?pl=dbp'?>')" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Help','dropbox-backup'); ?></button> <br />
1325
  </div>
1330
  <div style="float: left; margin-top: 2px;">
1331
  <button onclick="start_local_backup()" text-button="<?php _e('Create Local Backup','dropbox-backup');?>" class="backup_button disable-button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Create Local Backup','dropbox-backup'); ?></button> <br />
1332
  </div>
1333
+ <div id="stop-button" style="float: left; margin-top: 2px; margin-left:20px; display: none;">
1334
+ <button onclick="stopBackup();" text-button="<?php _e('Stop Backup','dropbox-backup');?>" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Stop Backup','dropbox-backup'); ?></button> <br />
1335
+ </div>
1336
  <!-- <div style="float: left; margin-top: 2px;margin-left: 20px;">
1337
  <button onclick="InludesSetting();" class="backup_button" style="padding: 5px 10px; margin-top: 10px; font-size: 15px;bottom: 0px;"><?php _e('Folders & files','dropbox-backup'); ?></button> <br />
1338
  </div> -->
1352
  <input type="hidden" name="backup-name" id="backup_name" value="" />
1353
  <input type="hidden" name="backup-type" id="backup_type" value="" />
1354
  </form>
1355
+ <form action="<?php echo admin_url( 'admin-post.php?action=stop_backup' )?>" method="post" id="stop_backups" name="stop_backups">
1356
+ <input type="hidden" name="type_backup" id="type_backup" value="" />
1357
+ </form>
1358
  <!-- <div id="inludes-setting" class="" style="display: none; position: relative; text-align: center; background: #f1ebeb; border: 2px solid #dde4ff; border-radius: 5px;">
1359
  <div>
1360
  <div class="title-description" style="font-size: 20px; text-align: center;padding-top:20px; line-height: 30px;">