Migration, Backup, Staging – WPvivid - Version 0.9.28

Version Description

  • New feature Added: Export and import posts or pages with images in bulk.
  • Fixed: URL replacement failures after website migration in some cases.
  • Fixed: Too many resumption attempts error that occurred when uploading backups in some cases.
  • Fixed some bugs in the plugin code.
Download this release

Release Info

Developer wpvivid
Plugin Icon 128x128 Migration, Backup, Staging – WPvivid
Version 0.9.28
Comparing to
See all releases

Code changes from version 0.9.27 to 0.9.28

admin/class-wpvivid-admin.php CHANGED
@@ -60,6 +60,7 @@ class WPvivid_Admin {
60
  add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),10);
61
  add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),10);
62
  add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),10);
 
63
 
64
  add_action('wpvivid_before_setup_page',array($this,'migrate_notice'));
65
  add_action('wpvivid_before_setup_page',array($this,'show_add_my_review'));
@@ -127,6 +128,61 @@ class WPvivid_Admin {
127
  return $submenus;
128
  }
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  /**
131
  * Register the stylesheets for the admin area.
132
  *
60
  add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),10);
61
  add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),10);
62
  add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),10);
63
+ add_filter('wpvivid_add_side_bar', array($this, 'wpvivid_add_side_bar'), 10, 2);
64
 
65
  add_action('wpvivid_before_setup_page',array($this,'migrate_notice'));
66
  add_action('wpvivid_before_setup_page',array($this,'show_add_my_review'));
128
  return $submenus;
129
  }
130
 
131
+ public function wpvivid_add_side_bar($html, $show_schedule = false){
132
+ $wpvivid_version = WPVIVID_PLUGIN_VERSION;
133
+ $wpvivid_version = apply_filters('wpvivid_display_pro_version', $wpvivid_version);
134
+ $join_pro_testing = '<div class="postbox">
135
+ <h2><a href="https://wpvivid.com/pro-version-beta-testing?utm_source=client_beta_testing&utm_medium=inner_link&utm_campaign=access" style="text-decoration: none;">WPvivid Backup Pro Beta Testing</a></h2>
136
+ </div>';
137
+ $join_pro_testing = apply_filters('wpvivid_join_pro_testing', $join_pro_testing);
138
+
139
+ $schedule_html = '';
140
+ if($show_schedule){
141
+ $schedule_html = apply_filters('wpvivid_schedule_module', $schedule_html);
142
+ }
143
+
144
+ $html = '<div class="postbox">
145
+ <h2>
146
+ <div style="float: left; margin-right: 10px;"><span style="margin: 0; padding: 0">Current Version: '.$wpvivid_version.'</span></div>
147
+ <div style="float: left; margin-left: 0;">
148
+ <span style="margin: 0; padding: 0"><a href="https://wordpress.org/plugins/wpvivid-backuprestore/#developers" target="_blank" style="text-decoration: none;">changelog</a></span>
149
+ </div>
150
+ <div style="clear: both;"></div>
151
+ </h2>
152
+ </div>
153
+ <div id="wpvivid_backup_schedule_part"></div>
154
+ '.$join_pro_testing.$schedule_html.'
155
+ <div class="postbox">
156
+ <h2><span>Troubleshooting</span></h2>
157
+ <div class="inside">
158
+ <table class="widefat" cellpadding="0">
159
+ <tbody>
160
+ <tr class="alternate">
161
+ <td class="row-title">Read <a href="https://wpvivid.com/troubleshooting-issues-wpvivid-backup-plugin" target="_blank">Troubleshooting page</a> for faster solutions.</td>
162
+ </tr>
163
+ <tr>
164
+ <td class="row-title">Adjust <a href="https://wpvivid.com/wpvivid-backup-plugin-advanced-settings.html" target="_blank">Advanced Settings</a> for higher task success rate.</td>
165
+ </tr>
166
+ </tbody>
167
+ </table>
168
+ </div>
169
+ </div>
170
+ <div class="postbox">
171
+ <h2><span>How-to</span></h2>
172
+ <div class="inside">
173
+ <table class="widefat" cellpadding="0">
174
+ <tbody>
175
+ <tr class="alternate"><td class="row-title"><a href="https://wpvivid.com/get-started-settings.html" target="_blank">WPvivid Backup Settings</a></td></tr>
176
+ <tr><td class="row-title"><a href="https://wpvivid.com/get-started-create-a-manual-backup.html" target="_blank">Create a Manual Backup</a></td></tr>
177
+ <tr class="alternate"><td class="row-title"><a href="https://wpvivid.com/get-started-restore-site.html" target="_blank">Restore Your Site from a Backup</a></td></tr>
178
+ <tr><td class="row-title"><a href="https://wpvivid.com/get-started-transfer-site.html" target="_blank">Migrate WordPress</a></td></tr>
179
+ </tbody>
180
+ </table>
181
+ </div>
182
+ </div>';
183
+ return $html;
184
+ }
185
+
186
  /**
187
  * Register the stylesheets for the admin area.
188
  *
admin/css/wpvivid-admin.css CHANGED
@@ -68,6 +68,10 @@
68
  float:none;
69
  width:100%;
70
  }
 
 
 
 
71
  }
72
  @media only screen and (max-width: 1350px){
73
  #poststuff #post-body.columns-2 {
@@ -213,4 +217,20 @@
213
  background-color:#f5f5f5;
214
  margin-top:10px;
215
  padding:4px 5px;
216
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  float:none;
69
  width:100%;
70
  }
71
+ .export-import-block{
72
+ float:none;
73
+ width:100%;
74
+ }
75
  }
76
  @media only screen and (max-width: 1350px){
77
  #poststuff #post-body.columns-2 {
217
  background-color:#f5f5f5;
218
  margin-top:10px;
219
  padding:4px 5px;
220
+ }
221
+
222
+ .wpvivid-text-space-bottom{margin-bottom: 5px;}
223
+ .wpvivid-text-space-right{margin-right: 5px;}
224
+ .wpvivid-element-space-bottom{margin-bottom: 10px;}
225
+ .wpvivid-element-space-right{margin-right: 10px;}
226
+ .wpvivid-export-type-provider{float: left; cursor: pointer; padding: 10px; height: 30px; line-height: 30px; border-right: 1px solid #e5e5e5;}
227
+ .wpvivid-export-type-provider:hover{background-color:#f1f1f1 !important; color:#fff !important;}
228
+ .wpvivid-export-type-provider-active{background-color:#0085ba !important; color:#fff !important;}
229
+ .wpvivid-import-log{padding:10px; width:100%; height:500px; overflow:auto; box-sizing:border-box;}
230
+ .import > tbody > :nth-child(odd) {background-color: #ffffff;}
231
+ .import > tbody tr:hover {background-color: #f9f9f9;}
232
+ .import .column-delete {width: 10%;}
233
+ .wpvivid-export-import-block span{margin: 0;}
234
+ .export-import-block{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
235
+ .export-import-block label{display:inline-block;}
236
+ .export-import-block a{text-decoration: none;}
admin/partials/images/export-import.png ADDED
Binary file
admin/partials/wpvivid-admin-display.php CHANGED
@@ -40,55 +40,6 @@ foreach ($page_array as $page_name){
40
  add_action('wpvivid_backuprestore_add_page', $page_name['page_func'], $page_name['index']);
41
  }
42
 
43
- function wpvivid_add_side_bar($html){
44
- $wpvivid_version = WPVIVID_PLUGIN_VERSION;
45
- $wpvivid_version = apply_filters('wpvivid_display_pro_version', $wpvivid_version);
46
- $join_pro_testing = '<div class="postbox">
47
- <h2><a href="https://wpvivid.com/pro-version-beta-testing?utm_source=client_beta_testing&utm_medium=inner_link&utm_campaign=access" style="text-decoration: none;">WPvivid Backup Pro Beta Testing</a></h2>
48
- </div>';
49
- $join_pro_testing = apply_filters('wpvivid_join_pro_testing', $join_pro_testing);
50
-
51
- $schedule_html = '';
52
- $schedule_html = apply_filters('wpvivid_schedule_module', $schedule_html);
53
-
54
- $html = '<div class="postbox">
55
- <h2><span>Current Version: '.$wpvivid_version.'</span></h2>
56
- </div>
57
- <div id="wpvivid_backup_schedule_part"></div>
58
- '.$join_pro_testing.$schedule_html.'
59
- <div class="postbox">
60
- <h2><span>Troubleshooting</span></h2>
61
- <div class="inside">
62
- <table class="widefat" cellpadding="0">
63
- <tbody>
64
- <tr class="alternate">
65
- <td class="row-title">Read <a href="https://wpvivid.com/troubleshooting-issues-wpvivid-backup-plugin" target="_blank">Troubleshooting page</a> for faster solutions.</td>
66
- </tr>
67
- <tr>
68
- <td class="row-title">Adjust <a href="https://wpvivid.com/wpvivid-backup-plugin-advanced-settings.html" target="_blank">Advanced Settings</a> for higher task success rate.</td>
69
- </tr>
70
- </tbody>
71
- </table>
72
- </div>
73
- </div>
74
- <div class="postbox">
75
- <h2><span>How-to</span></h2>
76
- <div class="inside">
77
- <table class="widefat" cellpadding="0">
78
- <tbody>
79
- <tr class="alternate"><td class="row-title"><a href="https://wpvivid.com/get-started-settings.html" target="_blank">WPvivid Backup Settings</a></td></tr>
80
- <tr><td class="row-title"><a href="https://wpvivid.com/get-started-create-a-manual-backup.html" target="_blank">Create a Manual Backup</a></td></tr>
81
- <tr class="alternate"><td class="row-title"><a href="https://wpvivid.com/get-started-restore-site.html" target="_blank">Restore Your Site from a Backup</a></td></tr>
82
- <tr><td class="row-title"><a href="https://wpvivid.com/get-started-transfer-site.html" target="_blank">Migrate WordPress</a></td></tr>
83
- </tbody>
84
- </table>
85
- </div>
86
- </div>';
87
- return $html;
88
- }
89
-
90
- add_filter('wpvivid_add_side_bar', 'wpvivid_add_side_bar', 10);
91
-
92
  ?>
93
 
94
  <div class="wrap">
@@ -138,7 +89,7 @@ add_filter('wpvivid_add_side_bar', 'wpvivid_add_side_bar', 10);
138
  <div class="meta-box-sortables">
139
  <?php
140
  $html = '';
141
- echo apply_filters('wpvivid_add_side_bar' ,$html);
142
  ?>
143
  </div>
144
  </div>
40
  add_action('wpvivid_backuprestore_add_page', $page_name['page_func'], $page_name['index']);
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ?>
44
 
45
  <div class="wrap">
89
  <div class="meta-box-sortables">
90
  <?php
91
  $html = '';
92
+ echo apply_filters('wpvivid_add_side_bar' ,$html, true);
93
  ?>
94
  </div>
95
  </div>
admin/partials/wpvivid-backup-restore-page-display.php CHANGED
@@ -1365,6 +1365,7 @@ function wpvivid_backuppage_add_page_restore(){
1365
  jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'none', 'opacity': '1'});
1366
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '1'});
1367
  jQuery('#wpvivid_tab_backup').css({'pointer-events': 'none', 'opacity': '1'});
 
1368
  jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'none', 'opacity': '1'});
1369
  jQuery('#wpvivid_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1370
  jQuery('#page-backups').css({'pointer-events': 'none', 'opacity': '1'});
@@ -1392,6 +1393,7 @@ function wpvivid_backuppage_add_page_restore(){
1392
  jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'auto', 'opacity': '1'});
1393
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1394
  jQuery('#wpvivid_tab_backup').css({'pointer-events': 'auto', 'opacity': '1'});
 
1395
  jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'auto', 'opacity': '1'});
1396
  jQuery('#wpvivid_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1397
  jQuery('#page-backups').css({'pointer-events': 'auto', 'opacity': '1'});
@@ -1487,7 +1489,12 @@ function wpvivid_backuppage_add_backup_module(){
1487
  function wpvivid_backup_module_add_descript(){
1488
  $backupdir=WPvivid_Setting::get_backupdir();
1489
  ?>
1490
- <h2><span><?php _e( 'Back Up Manually','wpvivid'); ?></span></h2>
 
 
 
 
 
1491
  <div class="quickstart-storage-setting">
1492
  <span class="list-top-chip backup" name="ismerge" value="1"><?php _e('Local Storage Directory: '); ?></span>
1493
  <span class="list-top-chip" id="wpvivid_local_storage_path"><?php _e(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir); ?></span>
1365
  jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'none', 'opacity': '1'});
1366
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '1'});
1367
  jQuery('#wpvivid_tab_backup').css({'pointer-events': 'none', 'opacity': '1'});
1368
+ jQuery('#wpvivid_tab_upload').css({'pointer-events': 'none', 'opacity': '1'});
1369
  jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'none', 'opacity': '1'});
1370
  jQuery('#wpvivid_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1371
  jQuery('#page-backups').css({'pointer-events': 'none', 'opacity': '1'});
1393
  jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'auto', 'opacity': '1'});
1394
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1395
  jQuery('#wpvivid_tab_backup').css({'pointer-events': 'auto', 'opacity': '1'});
1396
+ jQuery('#wpvivid_tab_upload').css({'pointer-events': 'auto', 'opacity': '1'});
1397
  jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'auto', 'opacity': '1'});
1398
  jQuery('#wpvivid_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1399
  jQuery('#page-backups').css({'pointer-events': 'auto', 'opacity': '1'});
1489
  function wpvivid_backup_module_add_descript(){
1490
  $backupdir=WPvivid_Setting::get_backupdir();
1491
  ?>
1492
+ <div style="font-size: 14px; padding: 8px 12px; margin: 0; line-height: 1.4; font-weight: 600;">
1493
+ <span style="margin-right: 5px;"><?php _e( 'Back Up Manually','wpvivid'); ?></span>
1494
+ <span style="margin-right: 5px;">|</span>
1495
+ <span style="margin-right: 0;"><a href="<?php echo esc_url(admin_url().'admin.php?page=wpvivid-export-import'); ?>" style="text-decoration: none;">Export Content</a></span>
1496
+ <span style="font-size: 10px; color: #FFA500; line-height: 10px;">(new feature)</span>
1497
+ </div>
1498
  <div class="quickstart-storage-setting">
1499
  <span class="list-top-chip backup" name="ismerge" value="1"><?php _e('Local Storage Directory: '); ?></span>
1500
  <span class="list-top-chip" id="wpvivid_local_storage_path"><?php _e(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir); ?></span>
includes/class-wpvivid-backup.php CHANGED
@@ -1469,7 +1469,7 @@ class WPvivid_Backup_Item
1469
  foreach ($this->config['backup']['files'] as $file)
1470
  {
1471
  if($has_dir)
1472
- $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1473
  else
1474
  $files[]=$file['file_name'];
1475
  }
@@ -1480,7 +1480,7 @@ class WPvivid_Backup_Item
1480
  foreach ($this->config['backup']['data']['meta']['files'] as $file)
1481
  {
1482
  if($has_dir)
1483
- $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1484
  else
1485
  $files[]=$file['file_name'];
1486
  }
@@ -1503,8 +1503,6 @@ class WPvivid_Backup_Item
1503
  public function check_backup_files()
1504
  {
1505
  global $wpvivid_plugin;
1506
- $ret['result']=WPVIVID_FAILED;
1507
- $ret['error']='Unknown error.';
1508
 
1509
  $b_has_data=false;
1510
  $tmp_data=array();
@@ -1525,7 +1523,7 @@ class WPvivid_Backup_Item
1525
  foreach ($tmp_data as $file)
1526
  {
1527
  $need_download=false;
1528
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1529
  if(file_exists($path))
1530
  {
1531
  if(filesize($path) == $file['size']){
@@ -1547,7 +1545,6 @@ class WPvivid_Backup_Item
1547
  else
1548
  {
1549
  $b_test=true;
1550
- $test_str=$path;
1551
  $need_download=true;
1552
  }
1553
 
@@ -1558,7 +1555,7 @@ class WPvivid_Backup_Item
1558
  $b_not_found=true;
1559
  $ret['files'][$file['file_name']]['status']='file_not_found';
1560
  $ret['files'][$file['file_name']]['size']=$file['size'];
1561
- $ret['files'][$file['file_name']]['md5']=$file['md5'];
1562
  }
1563
  else
1564
  {
@@ -1566,7 +1563,7 @@ class WPvivid_Backup_Item
1566
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1567
  $ret['files'][$file['file_name']]['status']='need_download';
1568
  $ret['files'][$file['file_name']]['size']=$file['size'];
1569
- $ret['files'][$file['file_name']]['md5']=$file['md5'];
1570
  }
1571
  }
1572
  }
@@ -1575,7 +1572,7 @@ class WPvivid_Backup_Item
1575
  {
1576
  $ret['result']=WPVIVID_FAILED;
1577
  if($b_test)
1578
- $ret['error']='Backup files doesn\'t exist. Restore failed.'.$test_str;
1579
  else
1580
  $ret['error']='Backup doesn\'t exist in both web server and remote storage. Restore failed.';
1581
  }
@@ -1588,6 +1585,11 @@ class WPvivid_Backup_Item
1588
  $ret['result']=WPVIVID_SUCCESS;
1589
  }
1590
  }
 
 
 
 
 
1591
 
1592
  return $ret;
1593
  }
@@ -1601,7 +1603,7 @@ class WPvivid_Backup_Item
1601
 
1602
  foreach ($tmp_data as $file)
1603
  {
1604
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1605
  if(file_exists($path))
1606
  {
1607
  $ret=$zip->get_json_data($path);
@@ -1639,7 +1641,7 @@ class WPvivid_Backup_Item
1639
 
1640
  foreach ($tmp_data as $file)
1641
  {
1642
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1643
  if(file_exists($path))
1644
  {
1645
  $ret=$zip->get_json_data($path);
@@ -1673,7 +1675,16 @@ class WPvivid_Backup_Item
1673
 
1674
  public function get_local_path()
1675
  {
1676
- return $this->config['local']['path'];
 
 
 
 
 
 
 
 
 
1677
  }
1678
 
1679
  public function get_remote()
@@ -1875,7 +1886,7 @@ class WPvivid_Backup_Item
1875
  {
1876
  $zip=new WPvivid_ZipClass();
1877
 
1878
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1879
 
1880
  $files = array();
1881
 
@@ -1895,7 +1906,7 @@ class WPvivid_Backup_Item
1895
  {
1896
  $zip=new WPvivid_ZipClass();
1897
 
1898
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1899
 
1900
  $ret=$zip->get_json_data($path);
1901
  if($ret['result'] === WPVIVID_SUCCESS) {
@@ -1933,7 +1944,7 @@ class WPvivid_Backup_Item
1933
  public function get_sql_file($file_name)
1934
  {
1935
  $zip=new WPvivid_ZipClass();
1936
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1937
  $files=$zip->list_file($path);
1938
  return $files[0]['file_name'];
1939
  }
@@ -1987,7 +1998,7 @@ class WPvivid_Backup_Item
1987
  foreach ($files as $file)
1988
  {
1989
  $need_download=false;
1990
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1991
  $download_url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1992
  if(file_exists($path)) {
1993
  if(filesize($path) == $file['size']){
1469
  foreach ($this->config['backup']['files'] as $file)
1470
  {
1471
  if($has_dir)
1472
+ $files[]=$this->get_local_path().$file['file_name'];
1473
  else
1474
  $files[]=$file['file_name'];
1475
  }
1480
  foreach ($this->config['backup']['data']['meta']['files'] as $file)
1481
  {
1482
  if($has_dir)
1483
+ $files[]=$this->get_local_path().$file['file_name'];
1484
  else
1485
  $files[]=$file['file_name'];
1486
  }
1503
  public function check_backup_files()
1504
  {
1505
  global $wpvivid_plugin;
 
 
1506
 
1507
  $b_has_data=false;
1508
  $tmp_data=array();
1523
  foreach ($tmp_data as $file)
1524
  {
1525
  $need_download=false;
1526
+ $path=$this->get_local_path().$file['file_name'];
1527
  if(file_exists($path))
1528
  {
1529
  if(filesize($path) == $file['size']){
1545
  else
1546
  {
1547
  $b_test=true;
 
1548
  $need_download=true;
1549
  }
1550
 
1555
  $b_not_found=true;
1556
  $ret['files'][$file['file_name']]['status']='file_not_found';
1557
  $ret['files'][$file['file_name']]['size']=$file['size'];
1558
+ //$ret['files'][$file['file_name']]['md5']=$file['md5'];
1559
  }
1560
  else
1561
  {
1563
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1564
  $ret['files'][$file['file_name']]['status']='need_download';
1565
  $ret['files'][$file['file_name']]['size']=$file['size'];
1566
+ //$ret['files'][$file['file_name']]['md5']=$file['md5'];
1567
  }
1568
  }
1569
  }
1572
  {
1573
  $ret['result']=WPVIVID_FAILED;
1574
  if($b_test)
1575
+ $ret['error']='Backup files doesn\'t exist. Restore failed.';
1576
  else
1577
  $ret['error']='Backup doesn\'t exist in both web server and remote storage. Restore failed.';
1578
  }
1585
  $ret['result']=WPVIVID_SUCCESS;
1586
  }
1587
  }
1588
+ else
1589
+ {
1590
+ $ret['result']=WPVIVID_FAILED;
1591
+ $ret['error']='Unknown error.';
1592
+ }
1593
 
1594
  return $ret;
1595
  }
1603
 
1604
  foreach ($tmp_data as $file)
1605
  {
1606
+ $path=$this->get_local_path().$file['file_name'];
1607
  if(file_exists($path))
1608
  {
1609
  $ret=$zip->get_json_data($path);
1641
 
1642
  foreach ($tmp_data as $file)
1643
  {
1644
+ $path=$this->get_local_path().$file['file_name'];
1645
  if(file_exists($path))
1646
  {
1647
  $ret=$zip->get_json_data($path);
1675
 
1676
  public function get_local_path()
1677
  {
1678
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR;
1679
+ $path=apply_filters('wpvivid_get_site_wpvivid_path',$path,$this->config['local']['path']);
1680
+ return $path;
1681
+ }
1682
+
1683
+ public function get_local_url()
1684
+ {
1685
+ $url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR;
1686
+ $url=apply_filters('wpvivid_get_site_wpvivid_url',$url,$this->config['local']['path']);
1687
+ return $url;
1688
  }
1689
 
1690
  public function get_remote()
1886
  {
1887
  $zip=new WPvivid_ZipClass();
1888
 
1889
+ $path=$this->get_local_path().$file_name;
1890
 
1891
  $files = array();
1892
 
1906
  {
1907
  $zip=new WPvivid_ZipClass();
1908
 
1909
+ $path=$this->get_local_path().$file_name;
1910
 
1911
  $ret=$zip->get_json_data($path);
1912
  if($ret['result'] === WPVIVID_SUCCESS) {
1944
  public function get_sql_file($file_name)
1945
  {
1946
  $zip=new WPvivid_ZipClass();
1947
+ $path=$this->get_local_path().$file_name;
1948
  $files=$zip->list_file($path);
1949
  return $files[0]['file_name'];
1950
  }
1998
  foreach ($files as $file)
1999
  {
2000
  $need_download=false;
2001
+ $path=$this->get_local_path().$file['file_name'];
2002
  $download_url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
2003
  if(file_exists($path)) {
2004
  if(filesize($path) == $file['size']){
includes/class-wpvivid-export-import.php ADDED
@@ -0,0 +1,2610 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ define('WPVIVID_IMPORT_EXPORT_DIR', 'ImportandExport');
4
+
5
+ class WPvivid_Export_Import
6
+ {
7
+ public $main_tab;
8
+ public $sub_tab;
9
+
10
+ public $end_shutdown_function;
11
+
12
+ public function __construct()
13
+ {
14
+ add_action('wp_ajax_wpvivid_export_post_step2', array($this, 'export_post_step2'));
15
+ add_action('wp_ajax_wpvivid_export_post_step3', array($this, 'export_post_step3'));
16
+
17
+ add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),21);
18
+ add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),21);
19
+
20
+ add_action('wp_ajax_wpvivid_export_now', array($this, 'export_now'));
21
+ add_action('wp_ajax_wpvivid_prepare_export_post', array($this, 'prepare_export_post'));
22
+ add_action('wp_ajax_wpvivid_export_list_tasks', array($this, 'list_tasks'));
23
+
24
+ add_action('wp_ajax_wpvivid_get_post_list', array($this, 'get_list'));
25
+ add_action('wp_ajax_wpvivid_get_post_list_page', array($this, 'get_list_page'));
26
+ add_action('wp_ajax_wpvivid_get_import_list_page', array($this, 'get_import_list_page'));
27
+
28
+ add_action('wp_ajax_wpvivid_get_export_list',array($this, 'get_export_list'));
29
+
30
+ add_action('admin_head', array($this, 'my_admin_custom_styles'));
31
+
32
+ add_action('wpvivid_handle_export_success',array($this,'handle_export_success'),10);
33
+ add_action('wpvivid_handle_export_failed',array($this,'handle_export_failed'),10, 2);
34
+
35
+ add_action('wp_ajax_wpvivid_delete_export_list',array($this,'delete_export_list'),10);
36
+
37
+ add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),12);
38
+
39
+ add_action('wp_ajax_wpvivid_start_import', array($this, 'start_import'));
40
+
41
+ add_action('wp_ajax_wpvivid_download_export_backup', array($this, 'wpvivid_download_export_backup'));
42
+ add_action('wp_ajax_wpvivid_check_import_file', array($this, 'check_import_file'));
43
+ add_action('wp_ajax_wpvivid_upload_import_files',array($this,'upload_import_files'));
44
+ add_action('wp_ajax_wpvivid_upload_import_file_complete', array($this, 'upload_import_file_complete'));
45
+ add_action('wp_ajax_wpvivid_get_import_progress', array($this, 'get_import_progress'));
46
+ add_action('wp_ajax_wpvivid_scan_import_folder', array($this, 'wpvivid_scan_import_folder'));
47
+ add_action('wp_ajax_wpvivid_calc_import_folder_size', array($this, 'calc_import_folder_size'));
48
+ add_action('wp_ajax_wpvivid_clean_import_folder', array($this, 'clean_import_folder'));
49
+ //
50
+ $this->end_shutdown_function = false;
51
+ }
52
+
53
+ public function get_screen_ids($screen_ids)
54
+ {
55
+ $screen_ids[]='wpvivid-backup_page_wpvivid-export-import';
56
+ return $screen_ids;
57
+ }
58
+
59
+ public function get_toolbar_menus($toolbar_menus)
60
+ {
61
+ $admin_url = apply_filters('wpvivid_get_admin_url', '');
62
+
63
+ $menu['id']='wpvivid_admin_menu_export_import';
64
+ $menu['parent']='wpvivid_admin_menu';
65
+ $menu['title']='Export & Import';
66
+ $menu['tab']= 'admin.php?page=wpvivid-export-import';
67
+ $menu['href']=$admin_url . 'admin.php?page=wpvivid-export-import';
68
+ $menu['index']=3;
69
+ $toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
70
+ return $toolbar_menus;
71
+ }
72
+
73
+ public function get_admin_menus($submenus)
74
+ {
75
+ $submenu['parent_slug']=WPVIVID_PLUGIN_SLUG;
76
+ $submenu['page_title']= __('WPvivid Backup');
77
+ $submenu['menu_title']=__('Export & Import', 'wpvivid');
78
+ $submenu['capability']='administrator';
79
+ $submenu['menu_slug']='wpvivid-export-import';
80
+ $submenu['index']=3;
81
+ $submenu['function']=array($this, 'init_page');
82
+ $submenus[$submenu['menu_slug']]=$submenu;
83
+ return $submenus;
84
+ }
85
+
86
+ public function init_page()
87
+ {
88
+ ?>
89
+ <div class="wrap">
90
+ <h1><?php
91
+ $plugin_display_name = 'WPvivid Backup Plugin';
92
+ $plugin_display_name = apply_filters('wpvivid_display_pro_name', $plugin_display_name);
93
+ _e($plugin_display_name);
94
+ ?></h1>
95
+ <div id="wpvivid_export_notice"></div>
96
+ </div>
97
+
98
+ <?php
99
+ $args['is_parent_tab']=1;
100
+ $this->main_tab=new WPvivid_Tab_Page_Container();
101
+ $this->main_tab->add_tab('Export','export',array($this, 'output_export'), $args);
102
+ $this->main_tab->add_tab('Import','import',array($this, 'output_import'), $args);
103
+ $this->main_tab->display();
104
+ }
105
+
106
+ //export
107
+ public function output_export()
108
+ {
109
+ $export_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
110
+ ?>
111
+ <div class="postbox export-import-block">
112
+ <div>
113
+ <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
114
+ <img src="<?php echo esc_url(WPVIVID_PLUGIN_IMAGES_URL.'export-import.png'); ?>" style="width:50px;height:50px;">
115
+ </div>
116
+ <div style="float: left; box-sizing: border-box;">
117
+ <div class="wpvivid-text-space-bottom">Export posts or pages with images in bulk.
118
+ <span class="wpvivid-feature-pro">
119
+ <a href="https://wpvivid.com/export-content" target="_blank" style="text-decoration: none;">Learn more</a>
120
+ </span>
121
+ </div>
122
+ <div class="wpvivid-text-space-bottom">This will contain all of your posts, pages, comments, terms and images (original images, featured images and thumbnails).</div>
123
+ <div class="wpvivid-text-space-bottom"><strong>Note:</strong> Try to select fewer items when you are facing a shortage of server resources (typically presented as a timeout error).</div>
124
+ <div style="clear: both;"></div>
125
+ </div>
126
+ <div style="clear: both;"></div>
127
+ </div>
128
+ <div style="clear: both;"></div>
129
+
130
+ <div style="background: #fff; border: 1px solid #e5e5e5; border-radius: 6px; margin-bottom: 10px; padding: 10px;">
131
+ <div><?php _e('Exported files will be temporarily stored in '.$export_dir.' directory'); ?></div>
132
+ </div>
133
+
134
+ <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
135
+ <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2><?php _e('Choose post type', 'wpvivid'); ?></h2></div>
136
+ </div>
137
+ <div style="clear: both;"></div>
138
+
139
+ <div class="postbox wpvivid-element-space-bottom">
140
+ <div class="wpvivid-export-type-provider wpvivid-export-type-post wpvivid-export-type-provider-active" onclick="wpvivid_select_export_type('post');">
141
+ <?php _e('Post', 'wpvivid'); ?>
142
+ </div>
143
+ <div class="wpvivid-export-type-provider wpvivid-export-type-page" onclick="wpvivid_select_export_type('page');">
144
+ <?php _e('Page', 'wpvivid'); ?>
145
+ </div>
146
+ <div class="wpvivid-export-type-provider">
147
+ <?php _e('More post types coming soon...', 'wpvivid'); ?>
148
+ </div>
149
+ </div>
150
+
151
+ <div id="wpvivid_export_page">
152
+ <input class="button-primary wpvivid-button-export-archieve" type="submit" name="<?php _e('post'); ?>" value="Next Step" />
153
+ </div>
154
+ <div class="postbox" id="wpvivid_export_task_progress" style="display: none; margin-top: 10px; margin-bottom: 0;">
155
+ <div class="action-progress-bar" id="wpvivid_export_bar_percent">
156
+ <div class="action-progress-bar-percent" style="width:0; height:24px;"></div>
157
+ </div>
158
+ <div style="clear: both;"></div>
159
+ <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_export_current_doing"></p></div>
160
+ <div style="clear: both;"></div>
161
+ </div>
162
+ <div class="postbox" id="wpvivid_export_summary" style="display: none; margin-top: 10px; margin-bottom: 0; padding: 10px;"></div>
163
+ </div>
164
+
165
+ <script>
166
+ var export_task_id='';
167
+ var retry_count=0;
168
+
169
+ var current_export_type = 'post';
170
+ function wpvivid_select_export_type(export_type){
171
+ jQuery('.wpvivid-export-type-provider').removeClass('wpvivid-export-type-provider-active');
172
+ jQuery('.wpvivid-export-type-'+export_type).addClass('wpvivid-export-type-provider-active');
173
+ if(current_export_type !== export_type){
174
+ current_export_type = export_type;
175
+ var button_html = '<input class="button-primary wpvivid-button-export-archieve" type="submit" name="'+export_type+'" value="Next Step" />';
176
+ jQuery('#wpvivid_export_page').html(button_html);
177
+ jQuery('#wpvivid_export_summary').hide();
178
+ }
179
+ }
180
+
181
+ function wpvivid_archieve_export_info(post_type, is_running){
182
+ var ajax_data = {
183
+ 'action':'wpvivid_export_post_step2',
184
+ 'post_type': post_type
185
+ };
186
+ wpvivid_post_request(ajax_data, function(data) {
187
+ var jsonarray = jQuery.parseJSON(data);
188
+ if (jsonarray.result === 'success') {
189
+ jQuery('#wpvivid_export_page').html(jsonarray.html);
190
+ if(is_running){
191
+ jQuery('#wpvivid_export_custom').hide();
192
+ }
193
+ }
194
+ else if (jsonarray.result === 'failed') {
195
+ alert(jsonarray.error);
196
+ }
197
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
198
+ var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
199
+ alert(error_message);
200
+ });
201
+ }
202
+
203
+ function wpvivid_import_lock_unlock(action){
204
+ var css_pointer_event = '';
205
+ var css_opacity = '';
206
+ if(action === 'lock'){
207
+ css_pointer_event = 'none';
208
+ css_opacity = '0.4';
209
+ }
210
+ else{
211
+ css_pointer_event = 'auto';
212
+ css_opacity = '1';
213
+ }
214
+ jQuery('.wpvivid-export-type-provider').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
215
+ jQuery('#wpvivid_export_page .wpvivid-button-export-archieve').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
216
+ jQuery('#wpvivid_export_page #wpvivid-post-query-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
217
+ jQuery('#wpvivid_export_page #wpvivid-post-research-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
218
+ jQuery('input:radio[name=contain]').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
219
+ jQuery('#wpvivid_export_page #wpvivid_start_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
220
+ jQuery('#wpvivid_tab_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
221
+ jQuery('#wpvivid_tab_import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
222
+ jQuery('#wpvivid_empty_import_folder').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
223
+ jQuery('#wpvivid_select_import_file_button').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
224
+ jQuery('#wpvivid_upload_file_list').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
225
+ jQuery('.export-list-import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
226
+ jQuery('#wpvivid_start_import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
227
+ jQuery('#wpvivid_rechoose_import_file').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
228
+ }
229
+
230
+ function wpvivid_export_lock_unlock(action){
231
+ var css_pointer_event = '';
232
+ var css_opacity = '';
233
+ if(action === 'lock'){
234
+ css_pointer_event = 'none';
235
+ css_opacity = '0.4';
236
+ }
237
+ else{
238
+ css_pointer_event = 'auto';
239
+ css_opacity = '1';
240
+ }
241
+ jQuery('.wpvivid-export-type-provider').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
242
+ jQuery('#wpvivid_export_page .wpvivid-button-export-archieve').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
243
+ jQuery('#wpvivid_export_page #wpvivid-post-query-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
244
+ jQuery('#wpvivid_export_page #wpvivid-post-research-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
245
+ jQuery('input:radio[name=contain]').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
246
+ jQuery('#wpvivid_export_page #wpvivid_start_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
247
+ }
248
+
249
+ jQuery('#wpvivid_export_page').on("click", ".wpvivid-button-export-archieve", function(){
250
+ var post_type = jQuery(this).attr('name');
251
+ wpvivid_archieve_export_info(post_type, false);
252
+ });
253
+
254
+ jQuery('#wpvivid_export_page').on("click", "#wpvivid-post-research-submit",function()
255
+ {
256
+ jQuery('#wpvivid_post_selector').show();
257
+ jQuery('#wpvivid_post_list').hide();
258
+ });
259
+ jQuery('#wpvivid_export_page').on("click", "#wpvivid-post-query-submit",function()
260
+ {
261
+ var post_type = jQuery('#wpvivid-post-query-submit').attr('name');
262
+ var cat=jQuery('select[name=cat]').val();
263
+ var authors=jQuery('select[name=post_author]').val();
264
+ var post_start_date=jQuery('select[name=post_start_date]').val();
265
+ var post_end_date=jQuery('select[name=post_end_date]').val();
266
+ var post_ids=jQuery('input[name=post-id]').val();
267
+ var post_title=jQuery('input[name=post-title]').val();
268
+ var ajax_data = {
269
+ 'action':'wpvivid_get_post_list',
270
+ 'post_type': post_type,
271
+ 'cat':cat,
272
+ 'authors':authors,
273
+ 'post_start_date':post_start_date,
274
+ 'post_end_date':post_end_date,
275
+ 'post_ids':post_ids,
276
+ 'post_title':post_title
277
+ };
278
+ wpvivid_post_request(ajax_data, function(data) {
279
+ var jsonarray = jQuery.parseJSON(data);
280
+ if (jsonarray.result === 'success') {
281
+ jQuery('#wpvivid_post_selector').hide();
282
+ jQuery('#wpvivid_bottom_step2').show();
283
+ jQuery('#wpvivid_post_list').show();
284
+ jQuery('#wpvivid_post_list').html(jsonarray.rows);
285
+ }
286
+ else if (jsonarray.result === 'failed') {
287
+ alert(jsonarray.error);
288
+ }
289
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
290
+ var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
291
+ alert(error_message);
292
+ });
293
+ });
294
+
295
+ jQuery('#wpvivid_export_page').on("click", 'input:radio[name=contain]',function() {
296
+ if(jQuery(this).val()==='list') {
297
+ jQuery('#wpvivid_export_custom').show();
298
+ }
299
+ else {
300
+ jQuery('#wpvivid_export_custom').hide();
301
+ }
302
+ });
303
+
304
+ jQuery('#wpvivid_export_page').on("keyup", '#wpvivid_set_post_comment', function(){
305
+ var post_comment = jQuery('#wpvivid_set_post_comment').val();
306
+ if(post_comment === ''){
307
+ post_comment = '*';
308
+ jQuery('#wpvivid_post_comment').html(post_comment);
309
+ }
310
+ else{
311
+ var reg = RegExp(/wpvivid/, 'i');
312
+ if (post_comment.match(reg)) {
313
+ jQuery('#wpvivid_set_post_comment').val('');
314
+ jQuery('#wpvivid_post_comment').html('*');
315
+ alert('You can not use word \'wpvivid\' to comment the post.');
316
+ }
317
+ else{
318
+ jQuery('#wpvivid_post_comment').html(post_comment);
319
+ }
320
+ }
321
+ });
322
+
323
+ function wpvivid_check_export_status(){
324
+ var check_status = false;
325
+ jQuery('input[name="post[]"]').each(function (i) {
326
+ var id=jQuery(this).val();
327
+ if(jQuery(this).prop('checked')) {
328
+ check_status = true;
329
+ return;
330
+ }
331
+ });
332
+ return check_status;
333
+ }
334
+
335
+ jQuery('#wpvivid_export_page').on("click", '#cb-select-all-1', function() {
336
+ if(jQuery(this).prop('checked')) {
337
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
338
+ }
339
+ else{
340
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
341
+ }
342
+ });
343
+
344
+ jQuery('#wpvivid_export_page').on("click", '#cb-select-all-2', function() {
345
+ if(jQuery(this).prop('checked')) {
346
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
347
+ }
348
+ else{
349
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
350
+ }
351
+ });
352
+
353
+ jQuery('#wpvivid_export_page').on("click", 'input[name="post[]"]', function() {
354
+ var check_status = wpvivid_check_export_status();
355
+ if(check_status){
356
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
357
+ }
358
+ else{
359
+ jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
360
+ }
361
+ });
362
+
363
+ jQuery('#wpvivid_export_page').on("click", '#wpvivid_start_export', function(){
364
+ wpvivid_clear_notice('wpvivid_export_notice');
365
+ jQuery('#wpvivid_export_summary').hide();
366
+ var post_type = jQuery('#wpvivid_start_export').attr('name');
367
+
368
+ var select_type='all';
369
+ jQuery('input:radio[name=contain]').each(function() {
370
+ if(jQuery(this).prop('checked')) {
371
+ select_type=jQuery(this).val();
372
+ }
373
+ });
374
+
375
+ var has_item = false;
376
+ var post_ids = {};
377
+ jQuery('input[name="post[]"]').each(function (i) {
378
+ var id=jQuery(this).val();
379
+ if(jQuery(this).prop('checked')) {
380
+ post_ids[id]=1;
381
+ has_item = true;
382
+ }
383
+ else {
384
+ post_ids[id]=0;
385
+ }
386
+ });
387
+
388
+ if(select_type === 'list' && !has_item){
389
+ alert('Please select at least one item.');
390
+ }
391
+ else{
392
+ var post_ids_json = {
393
+ 'post_ids': post_ids
394
+ };
395
+
396
+ jQuery('#wpvivid_export_custom').hide();
397
+
398
+ var export_data = wpvivid_ajax_data_transfer('export');
399
+ export_data = JSON.parse(export_data);
400
+ jQuery.extend(export_data, post_ids_json);
401
+ export_data = JSON.stringify(export_data);
402
+
403
+ var ajax_data = {
404
+ 'action': 'wpvivid_prepare_export_post',
405
+ 'post_type': post_type,
406
+ 'export_data': export_data
407
+ };
408
+ wpvivid_export_lock_unlock('lock');
409
+ wpvivid_post_request(ajax_data, function(data)
410
+ {
411
+ var jsonarray = jQuery.parseJSON(data);
412
+ if (jsonarray.result === 'success')
413
+ {
414
+ export_task_id=jsonarray.task_id;
415
+
416
+ var ajax_data = {
417
+ 'action':'wpvivid_export_now',
418
+ 'task_id':export_task_id
419
+ };
420
+
421
+ wpvivid_export_progpress();
422
+
423
+ wpvivid_post_request(ajax_data, function(data) {
424
+ },function(XMLHttpRequest, textStatus, errorThrown) {
425
+ });
426
+ }
427
+ else if (jsonarray.result === 'failed') {
428
+ wpvivid_export_lock_unlock('unlock');
429
+ alert(jsonarray.error);
430
+ }
431
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
432
+ wpvivid_export_lock_unlock('unlock');
433
+ var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
434
+ alert(error_message);
435
+ });
436
+ }
437
+ });
438
+
439
+ jQuery('#wpvivid_export_page').on("click",'.first-page',function() {
440
+ wpvivid_change_page('first');
441
+ });
442
+
443
+ jQuery('#wpvivid_export_page').on("click",'.prev-page',function() {
444
+ var page=parseInt(jQuery(this).attr('value'));
445
+ wpvivid_change_page(page-1);
446
+ });
447
+
448
+ jQuery('#wpvivid_export_page').on("click",'.next-page',function() {
449
+ var page=parseInt(jQuery(this).attr('value'));
450
+ wpvivid_change_page(page+1);
451
+ });
452
+
453
+ jQuery('#wpvivid_export_page').on("click",'.last-page',function() {
454
+ wpvivid_change_page('last');
455
+ });
456
+
457
+ jQuery('#wpvivid_export_page').on("keypress", '.current-page', function(){
458
+ if(event.keyCode === 13){
459
+ var page = jQuery(this).val();
460
+ wpvivid_change_page(page);
461
+ }
462
+ });
463
+
464
+ function wpvivid_change_page(page) {
465
+ var post_type='post';
466
+ jQuery('input:radio[name=post_type]').each(function() {
467
+ if(jQuery(this).prop('checked'))
468
+ {
469
+ post_type=jQuery(this).val();
470
+ }
471
+ });
472
+
473
+ var post_ids = {};
474
+
475
+ jQuery('input[name="post[]"]').each(function (i) {
476
+ var id=jQuery(this).val();
477
+ if(jQuery(this).prop('checked'))
478
+ {
479
+ post_ids[id]=1;
480
+ }
481
+ else
482
+ {
483
+ post_ids[id]=0;
484
+ }
485
+ });
486
+
487
+ var ajax_data = {
488
+ 'action':'wpvivid_get_post_list_page',
489
+ 'post_type': post_type,
490
+ 'page': page,
491
+ 'post_ids':post_ids
492
+ };
493
+
494
+ wpvivid_post_request(ajax_data, function(data) {
495
+ var jsonarray = jQuery.parseJSON(data);
496
+ if (jsonarray.result === 'success') {
497
+ jQuery('#wpvivid_post_list').html(jsonarray.rows);
498
+ }
499
+ else if (jsonarray.result === 'failed') {
500
+ alert(jsonarray.error);
501
+ }
502
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
503
+ var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
504
+ alert(error_message);
505
+ });
506
+ }
507
+
508
+ function wpvivid_export_progpress() {
509
+ var ajax_data = {
510
+ 'action': 'wpvivid_export_list_tasks',
511
+ 'task_id': export_task_id
512
+ };
513
+
514
+ jQuery('#wpvivid_export_task_progress').show();
515
+
516
+ wpvivid_post_request(ajax_data, function(data)
517
+ {
518
+ var jsonarray = jQuery.parseJSON(data);
519
+ if (jsonarray.result === 'success')
520
+ {
521
+ retry_count=0;
522
+ export_task_id=jsonarray.task_id;
523
+ if(jsonarray.show)
524
+ {
525
+ jQuery('#wpvivid_export_task_progress').show();
526
+ jQuery('#wpvivid_export_summary').hide();
527
+ jQuery('#wpvivid_export_bar_percent').html(jsonarray.percent);
528
+ jQuery('#wpvivid_export_current_doing').html(jsonarray.doing);
529
+ }
530
+ else
531
+ {
532
+ jQuery('#wpvivid_export_task_progress').hide();
533
+ }
534
+
535
+ if(jsonarray.completed)
536
+ {
537
+ wpvivid_export_lock_unlock('unlock');
538
+ //jQuery('#wpvivid_export_notice').show();
539
+ //jQuery('#wpvivid_export_notice').append(jsonarray.doing);
540
+ jQuery('#wpvivid_export_summary').show();
541
+ jQuery('#wpvivid_export_summary').html(jsonarray.doing);
542
+ jQuery('html, body').animate({scrollTop: jQuery("#wpvivid_export_notice").offset().top}, 'slow');
543
+ wpvivid_download_export(jsonarray.file_name, jsonarray.file_size);
544
+ }
545
+
546
+ if(jsonarray.continue)
547
+ {
548
+ wpvivid_export_lock_unlock('lock');
549
+ setTimeout(function ()
550
+ {
551
+ wpvivid_export_progpress();
552
+ }, 3000);
553
+ }
554
+
555
+ if(jsonarray.error){
556
+ wpvivid_export_lock_unlock('unlock');
557
+ jQuery('#wpvivid_export_notice').show();
558
+ jQuery('#wpvivid_export_notice').append(jsonarray.doing);
559
+ jQuery('html, body').animate({scrollTop: jQuery("#wpvivid_export_notice").offset().top}, 'slow');
560
+ }
561
+ }
562
+ else
563
+ {
564
+ alert(jsonarray.error);
565
+ }
566
+ }, function(XMLHttpRequest, textStatus, errorThrown)
567
+ {
568
+ retry_count++;
569
+ if(retry_count<3)
570
+ {
571
+ setTimeout(function () {
572
+ wpvivid_export_progpress();
573
+ }, 3000);
574
+ }
575
+ });
576
+ }
577
+
578
+ function wpvivid_download_export(file_name, file_size){
579
+ location.href =ajaxurl+'?action=wpvivid_download_export_backup&file_name='+file_name+'&file_size='+file_size;
580
+ }
581
+
582
+ jQuery(document).ready(function (){
583
+ <?php
584
+ $task_id = false;
585
+ $post_type = false;
586
+ $tasks=WPvivid_Exporter_taskmanager::get_tasks();
587
+ foreach ($tasks as $task){
588
+ $task_id = $task['id'];
589
+ $post_type = $task['options']['backup_options']['post_type'];
590
+ break;
591
+ }
592
+ ?>
593
+ var task_id = '<?php echo $task_id; ?>';
594
+ if(task_id != false){
595
+ export_task_id = task_id;
596
+ wpvivid_export_lock_unlock('lock');
597
+ wpvivid_export_progpress();
598
+ }
599
+ });
600
+ </script>
601
+ <?php
602
+ }
603
+
604
+ public function export_post_step2()
605
+ {
606
+ if(isset($_POST['post_type']))
607
+ {
608
+ global $wpdb;
609
+ $post_type = sanitize_text_field($_POST['post_type']);
610
+ $descript_type = $post_type === 'post' ? 'posts' : 'pages';
611
+
612
+ ob_start();
613
+ ?>
614
+ <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
615
+ <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2>Choose what to export</h2></div>
616
+ </div>
617
+ <div style="clear: both;"></div>
618
+ <div style="width:100%; border:1px solid #f1f1f1; float:left; padding:10px 10px 0 10px;margin-bottom:10px; box-sizing: border-box;">
619
+ <fieldset>
620
+ <legend class="screen-reader-text"><span>input type="radio"</span></legend>
621
+ <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
622
+ <label>
623
+ <input type="radio" option="export" name="contain" value="list" checked/><?php _e('Filter Posts/Pages'); ?>
624
+ </label>
625
+ </div>
626
+ <div style="clear: both;"></div>
627
+ </fieldset>
628
+
629
+ <div id="wpvivid_export_custom" style="margin-bottom: 10px;">
630
+ <table id="wpvivid_post_selector" class="wp-list-table widefat plugins" style="width:100%; border:1px solid #f1f1f1;">
631
+ <tbody>
632
+ <?php
633
+ if($post_type !== 'page') {
634
+ ?>
635
+ <tr>
636
+ <td class="plugin-title column-primary">
637
+ <div class="wpvivid-storage-form regular-text">
638
+ <?php
639
+ wp_dropdown_categories(
640
+ array(
641
+ 'class' => 'regular-text',
642
+ 'show_option_all' => __('All Categories')
643
+ )
644
+ );
645
+ ?>
646
+ </div>
647
+ </td>
648
+ <td class="column-description desc">
649
+ <div class="wpvivid-storage-form-desc">
650
+ <i>Export <?php _e($descript_type); ?> of all categories or a specific category.</i>
651
+ </div>
652
+ </td>
653
+ </tr>
654
+ <?php
655
+ }
656
+ ?>
657
+ <tr>
658
+ <td class="plugin-title column-primary">
659
+ <div class="wpvivid-storage-form regular-text">
660
+ <?php
661
+ $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = '$post_type'" );
662
+ wp_dropdown_users(
663
+ array(
664
+ 'class' => 'regular-text',
665
+ 'include' => $authors,
666
+ 'name' => 'post_author',
667
+ 'multi' => true,
668
+ 'show_option_all' => __( 'All Authors' ),
669
+ 'show' => 'display_name_with_login',
670
+ )
671
+ );
672
+ ?>
673
+ </div>
674
+ </td>
675
+ <td class="column-description desc">
676
+ <div class="wpvivid-storage-form-desc">
677
+ <i>Export <?php _e($descript_type); ?> of all authors or a specific author.</i>
678
+ </div>
679
+ </td>
680
+ </tr>
681
+
682
+ <tr>
683
+ <td class="plugin-title column-primary">
684
+ <div class="wpvivid-storage-form regular-text">
685
+ <label for="post-start-date" class="label-responsive" style="display: block;"></label>
686
+ <select class="regular-text" name="post_start_date" id="post-start-date">
687
+ <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
688
+ <?php $this->export_date_options($post_type); ?>
689
+ </select>
690
+ </div>
691
+ </td>
692
+ <td class="column-description desc">
693
+ <div class="wpvivid-storage-form-desc">
694
+ <i>Export <?php _e($descript_type); ?> published or last modified after this date.</i>
695
+ </div>
696
+ </td>
697
+ </tr>
698
+
699
+ <tr>
700
+ <td class="plugin-title column-primary">
701
+ <div class="wpvivid-storage-form regular-text">
702
+ <label for="post-end-date" class="label-responsive" style="display: block;"></label>
703
+ <select class="regular-text" name="post_end_date" id="post-end-date">
704
+ <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
705
+ <?php $this->export_date_options($post_type); ?>
706
+ </select>
707
+ </div>
708
+ </td>
709
+ <td class="column-description desc">
710
+ <div class="wpvivid-storage-form-desc">
711
+ <i>Export <?php _e($descript_type); ?> published or last modified before this date.</i>
712
+ </div>
713
+ </td>
714
+ </tr>
715
+
716
+ <tr style="display: none;">
717
+ <td class="plugin-title column-primary">
718
+ <div class="wpvivid-storage-form">
719
+ <input type="text" class="regular-text" id="post-search-id-input" name="post-id" autocomplete="off" value=""/>
720
+ </div>
721
+ </td>
722
+ <td class="column-description desc">
723
+ <div class="wpvivid-storage-form-desc">
724
+ <i>Enter a <?php _e($post_type); ?> ID.(optional)</i>
725
+ </div>
726
+ </td>
727
+ </tr>
728
+
729
+ <tr style="display: none;">
730
+ <td class="plugin-title column-primary">
731
+ <div class="wpvivid-storage-form">
732
+ <input type="text" class="regular-text" id="post-search-title-input" name="post-title" autocomplete="off" value=""/>
733
+ </div>
734
+ </td>
735
+ <td class="column-description desc">
736
+ <div class="wpvivid-storage-form-desc">
737
+ <i>Enter a <?php _e($post_type); ?> title.(optional)</i>
738
+ </div>
739
+ </td>
740
+ </tr>
741
+
742
+ <tr>
743
+ <td class="plugin-title column-primary">
744
+ <div class="wpvivid-storage-form">
745
+ <input class="button-primary" id="wpvivid-post-query-submit" type="submit" name="<?php _e($post_type); ?>" value="Search" />
746
+ </div>
747
+ </td>
748
+ <td class="column-description desc">
749
+ <div class="wpvivid-storage-form-desc">
750
+ <i>Search for <?php _e($post_type); ?>s according to the above rules.</i>
751
+ </div>
752
+ </td>
753
+ </tr>
754
+ </tbody>
755
+ </table>
756
+ <div id="wpvivid_post_list"></div>
757
+ </div>
758
+ </div>
759
+
760
+ <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
761
+ <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2>Comment the export (optional)</h2></div>
762
+ </div>
763
+ <div style="clear: both;"></div>
764
+ <div style="width:100%; border:1px solid #f1f1f1; float:left; padding:10px 10px 0 10px;margin-bottom:10px; box-sizing: border-box;">
765
+ <div>
766
+ <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left; padding-top: 6px;">Comment the export: </div>
767
+ <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;">
768
+ <input type="text" option="export" name="post_comment" id="wpvivid_set_post_comment" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" />
769
+ </div>
770
+ <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left; padding-top: 6px;">Only letters (except for wpvivid) and numbers are allowed.</div>
771
+ <div style="clear: both;"></div>
772
+ </div>
773
+ <div>
774
+ <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;">Sample:</div>
775
+ <div class="wpvivid-element-space-bottom" style="float: left;">
776
+ <div class="wpvivid-element-space-bottom" style="display: inline;" id="wpvivid_post_comment">*</div><div class="wpvivid-element-space-bottom" style="display: inline;">_wpvivid-5dbf8d6a5f133_2019-11-08-03-15_export_<?php _e($post_type); ?>.zip</div>
777
+ </div>
778
+ <div style="clear: both;"></div>
779
+ </div>
780
+ </div>
781
+
782
+ <div>
783
+ <input class="button-primary" id="wpvivid_start_export" type="submit" name="<?php _e($post_type); ?>" value="Export and Download" style="pointer-events: none; opacity: 0.4;">
784
+ </div>
785
+ <?php
786
+
787
+ $html = ob_get_clean();
788
+ $ret['result']='success';
789
+ $ret['html']=$html;
790
+ }
791
+ else
792
+ {
793
+ $ret['result']='failed';
794
+ $ret['error']='not set post type';
795
+ }
796
+ echo json_encode($ret);
797
+ die();
798
+ }
799
+
800
+ public function export_post_step3()
801
+ {
802
+ if(isset($_POST['post_type'])&&isset($_POST['all']))
803
+ {
804
+ $post_type=$_POST['post_type'];
805
+
806
+ $old_post_ids=array();
807
+ if(isset($_POST['post_ids']))
808
+ {
809
+ $old_post_ids=$_POST['post_ids'];
810
+ }
811
+
812
+ $list_cache=get_option('wpvivid_list_cache',array());
813
+
814
+ foreach ($old_post_ids as $id=>$checked)
815
+ {
816
+ if(isset($list_cache[$id]))
817
+ {
818
+ $list_cache[$id]['checked']=$checked;
819
+ }
820
+ }
821
+ update_option('wpvivid_list_cache',$list_cache);
822
+
823
+ $post_count=0;
824
+
825
+ if($_POST['all']=='all')
826
+ {
827
+ global $wpdb;
828
+
829
+ $where = $wpdb->prepare( "post_type ='%s'", $post_type);
830
+ $posts_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE $where" );
831
+ $post_count=sizeof($posts_ids);
832
+ }
833
+ else
834
+ {
835
+ foreach ($list_cache as $id=>$item)
836
+ {
837
+ if($item['checked'])
838
+ $post_count++;
839
+ }
840
+ }
841
+
842
+ ob_start();
843
+ ?>
844
+ <h2>Export post type:<strong><?php echo $post_type?></strong></h2>
845
+ <p>
846
+ Selected post(s):<?php echo $post_count?>
847
+ </p>
848
+ <p class="submit">
849
+ <input type="button" class="button button-primary wpvivid-export-step3-prev" value="Prev step">
850
+ <input type="button" class="button button-primary" id="wpvivid_start_export" value="Start Export">
851
+ </p>
852
+ <?php
853
+
854
+ $html = ob_get_clean();
855
+ $ret['result']='success';
856
+ $ret['html']=$html;
857
+ }
858
+ else
859
+ {
860
+ $ret['result']='failed';
861
+ $ret['error']='not set post type';
862
+ }
863
+ echo json_encode($ret);
864
+ die();
865
+ }
866
+
867
+ public function my_admin_custom_styles()
868
+ {
869
+ $output_css = '<style type="text/css">
870
+ .column-file_name { width:25% }
871
+ .column-export_type { width:8% }
872
+ .column-posts_count { width:8% }
873
+ .column-media_size { width:8% }
874
+ .column-import { width:8% }
875
+ </style>';
876
+ echo $output_css;
877
+ }
878
+
879
+ public function get_list()
880
+ {
881
+ if(!isset($_POST['post_type'])&&!isset($_POST['cat'])&&!isset($_POST['authors'])&&!isset($_POST['post_start_date'])&&!isset($_POST['post_end_date']))
882
+ {
883
+ die();
884
+ }
885
+
886
+ if(isset($_POST['post_ids'])&&!empty($_POST['post_ids']))
887
+ {
888
+ $select_post_id=(int)$_POST['post_ids'];
889
+ }
890
+ else
891
+ {
892
+ $select_post_id=0;
893
+ }
894
+
895
+ if(isset($_POST['post_title'])&&!empty($_POST['post_title']))
896
+ {
897
+ $post_title=$_POST['post_title'];
898
+ }
899
+ else
900
+ {
901
+ $post_title='';
902
+ }
903
+ //
904
+
905
+ $post_type=$_POST['post_type'];
906
+ if(isset($_POST['cat'])) {
907
+ $cat = (int)$_POST['cat'];
908
+ }
909
+ $author=(int)$_POST['authors'];
910
+ $post_start_date=$_POST['post_start_date'];
911
+ $post_end_date=$_POST['post_end_date'];
912
+
913
+
914
+ global $wpdb;
915
+
916
+ $where = $wpdb->prepare( "post_type ='%s'", $post_type);
917
+ $join = '';
918
+ if(isset($_POST['cat'])) {
919
+ if ($term = term_exists($cat, 'category')) {
920
+ $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
921
+ $where .= $wpdb->prepare(" AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id']);
922
+ }
923
+ }
924
+ if ( $author )
925
+ {
926
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $author );
927
+ }
928
+ if ( $post_start_date )
929
+ {
930
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime( $post_start_date ) ) );
931
+ }
932
+ if ( $post_end_date )
933
+ {
934
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $post_end_date ) ) ) );
935
+ }
936
+ if($select_post_id)
937
+ {
938
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.ID = %d", $select_post_id );
939
+ }
940
+ if($post_title)
941
+ {
942
+ $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . $wpdb->esc_like($post_title) . '%' );
943
+ }
944
+
945
+ $posts_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
946
+
947
+ asort($posts_ids);
948
+
949
+ $list_cache=array();
950
+ foreach ($posts_ids as $id)
951
+ {
952
+ $post_id['id']=$id;
953
+ $post_id['checked']=0;
954
+ $list_cache[$id]=$post_id;
955
+ }
956
+ update_option('wpvivid_list_cache',$list_cache);
957
+ $page=1;
958
+
959
+ $arg['screen']=$post_type;
960
+ $myListTable = new WPvivid_Post_List($arg);
961
+ $myListTable->set_post_ids($list_cache,$page);
962
+ $myListTable->prepare_items();
963
+ ob_start();
964
+ $myListTable->display();
965
+ $rows = ob_get_clean();
966
+ $ret['result']='success';
967
+ $ret['rows']=$rows;
968
+ echo json_encode($ret);
969
+
970
+ die();
971
+ }
972
+
973
+ public function get_export_list()
974
+ {
975
+ $list = get_option('wpvivid_export_list',array());
976
+ $display_list=new WPvivid_Export_List();
977
+ $display_list->set_parent('wpvivid_import_list');
978
+ $display_list->set_list($list);
979
+ $display_list->prepare_items();
980
+ ob_start();
981
+ $display_list->display();
982
+ $html = ob_get_clean();
983
+ $ret['result']='success';
984
+ $ret['html']=$html;
985
+ echo json_encode($ret);
986
+
987
+ die();
988
+ }
989
+
990
+ public function get_list_page()
991
+ {
992
+ if(!isset($_POST['post_type'])&&!isset($_POST['page']))
993
+ {
994
+ die();
995
+ }
996
+
997
+ $list_cache=get_option('wpvivid_list_cache',array());
998
+
999
+ update_option('wpvivid_list_cache',$list_cache);
1000
+
1001
+ $page=$_POST['page'];
1002
+
1003
+ $post_type=$_POST['post_type'];
1004
+ $arg['screen']=$post_type;
1005
+
1006
+ $myListTable = new WPvivid_Post_List($arg);
1007
+ $myListTable->set_post_ids($list_cache,$page);
1008
+ $myListTable->prepare_items();
1009
+ ob_start();
1010
+ $myListTable->display();
1011
+ $rows = ob_get_clean();
1012
+
1013
+ $ret['result']='success';
1014
+ $ret['rows']=$rows;
1015
+ echo json_encode($ret);
1016
+ die();
1017
+ }
1018
+
1019
+ public function export_date_options($post_type = 'post')
1020
+ {
1021
+ global $wpdb, $wp_locale;
1022
+
1023
+ $months = $wpdb->get_results(
1024
+ $wpdb->prepare(
1025
+ "
1026
+ SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
1027
+ FROM $wpdb->posts
1028
+ WHERE post_type = %s AND post_status != 'auto-draft'
1029
+ ORDER BY post_date DESC
1030
+ ",
1031
+ $post_type
1032
+ )
1033
+ );
1034
+
1035
+ $month_count = count( $months );
1036
+ if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
1037
+ return;
1038
+ }
1039
+
1040
+ foreach ( $months as $date ) {
1041
+ if ( 0 == $date->year ) {
1042
+ continue;
1043
+ }
1044
+
1045
+ $month = zeroise( $date->month, 2 );
1046
+ echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
1047
+ }
1048
+ }
1049
+
1050
+ public function prepare_export_post()
1051
+ {
1052
+ if(isset($_POST['post_type'])&&isset($_POST['export_data']))
1053
+ {
1054
+ $post_type = sanitize_text_field($_POST['post_type']);
1055
+ $json_export = sanitize_text_field($_POST['export_data']);
1056
+ $json_export = stripslashes($json_export);
1057
+ $export_data = json_decode($json_export, true);
1058
+
1059
+ $post_ids=array();
1060
+ $posts_ids=array();
1061
+ if(isset($export_data['post_ids']) && !empty($export_data['post_ids']))
1062
+ {
1063
+ $post_ids=$export_data['post_ids'];
1064
+ }
1065
+ foreach ($post_ids as $id=>$checked)
1066
+ {
1067
+ if($checked)
1068
+ {
1069
+ $posts_ids[]=$id;
1070
+ }
1071
+ }
1072
+
1073
+ if(empty($posts_ids))
1074
+ {
1075
+ $ret['result']='failed';
1076
+ $ret['error']=__('Empty post id', 'wpvivid');
1077
+ echo json_encode($ret);
1078
+ die();
1079
+ }
1080
+ if(WPvivid_Exporter_taskmanager::is_tasks_running())
1081
+ {
1082
+ $ret['result']='failed';
1083
+ $ret['error']=__('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid');
1084
+ echo json_encode($ret);
1085
+ die();
1086
+ }
1087
+
1088
+ $export_task=new WPvivid_Exporter_task();
1089
+
1090
+ $options['post_ids']=$posts_ids;
1091
+ $options['post_type']=$post_type;
1092
+ $options['post_comment']=$export_data['post_comment'];
1093
+
1094
+ $ret=$export_task->new_backup_task($options);
1095
+ echo json_encode($ret);
1096
+ }
1097
+ die();
1098
+ }
1099
+
1100
+ public function export_now()
1101
+ {
1102
+ global $wpvivid_plugin;
1103
+ $wpvivid_plugin->ajax_check_security();
1104
+ try
1105
+ {
1106
+ if (!isset($_POST['task_id']) || empty($_POST['task_id']) || !is_string($_POST['task_id']))
1107
+ {
1108
+ $ret['result'] = 'failed';
1109
+ $ret['error'] = __('Error occurred while parsing the request data. Please try to run export task again.', 'wpvivid');
1110
+ echo json_encode($ret);
1111
+ die();
1112
+ }
1113
+
1114
+ $task_id = sanitize_key($_POST['task_id']);
1115
+
1116
+ if(WPvivid_Exporter_taskmanager::is_tasks_running())
1117
+ {
1118
+ $ret['result'] = 'failed';
1119
+ $ret['error'] = __('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid');
1120
+ echo json_encode($ret);
1121
+ die();
1122
+ }
1123
+
1124
+ $this->export_post($task_id);
1125
+ }
1126
+ catch (Exception $error)
1127
+ {
1128
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
1129
+ error_log($message);
1130
+ echo json_encode(array('result'=>'failed','error'=>$message));
1131
+ die();
1132
+ }
1133
+ die();
1134
+ }
1135
+
1136
+ public function export_post($task_id)
1137
+ {
1138
+ $this->end_shutdown_function = false;
1139
+ register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
1140
+ @ignore_user_abort(true);
1141
+
1142
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,true,'running');
1143
+
1144
+ global $wpvivid_plugin;
1145
+
1146
+ $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id,'log_file_name'));
1147
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start export posts.','notice');
1148
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
1149
+ $this->flush($task_id);
1150
+
1151
+ $export=new WPvivid_Exporter();
1152
+
1153
+ set_time_limit(900);
1154
+ try
1155
+ {
1156
+ $ret = $export->export($task_id);
1157
+ if($ret['result']=='success')
1158
+ {
1159
+ do_action('wpvivid_handle_export_success', $task_id, true);
1160
+ }
1161
+ else
1162
+ {
1163
+ $wpvivid_plugin->wpvivid_log->WriteLog($ret['error'],'error');
1164
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id, false, 'error', false, false, $ret['error']);
1165
+ do_action('wpvivid_handle_export_failed', $task_id, true);
1166
+ }
1167
+
1168
+ }
1169
+ catch (Exception $error)
1170
+ {
1171
+ $message = 'An error has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
1172
+ error_log($message);
1173
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,false,$message);
1174
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
1175
+ $this->end_shutdown_function=true;
1176
+ die();
1177
+ }
1178
+
1179
+ echo json_encode($ret);
1180
+ $this->end_shutdown_function=true;
1181
+ die();
1182
+ }
1183
+
1184
+ public function deal_shutdown_error($task_id)
1185
+ {
1186
+ if($this->end_shutdown_function===false)
1187
+ {
1188
+ global $wpvivid_plugin;
1189
+
1190
+ $last_error = error_get_last();
1191
+ if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING,E_DEPRECATED), true))
1192
+ {
1193
+ $error = $last_error;
1194
+ } else {
1195
+ $error = false;
1196
+ }
1197
+ if (WPvivid_Exporter_taskmanager::get_task($task_id) !== false)
1198
+ {
1199
+ if ($wpvivid_plugin->wpvivid_log->log_file_handle == false)
1200
+ {
1201
+ $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id, 'log_file_name'));
1202
+ }
1203
+
1204
+ $status = WPvivid_Exporter_taskmanager::get_backup_task_status($task_id);
1205
+
1206
+ $message='in shutdown';
1207
+
1208
+ if ($error !== false)
1209
+ {
1210
+ $message= 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1211
+ }
1212
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1213
+ if ($wpvivid_plugin->wpvivid_log)
1214
+ $wpvivid_plugin->wpvivid_log->WriteLog($message, 'error');
1215
+ }
1216
+ die();
1217
+ }
1218
+ }
1219
+
1220
+ public function handle_export_success($task_id)
1221
+ {
1222
+ global $wpvivid_plugin;
1223
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'completed');
1224
+
1225
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished to export post','notice');
1226
+ }
1227
+
1228
+ public function handle_export_failed($task_id)
1229
+ {
1230
+ }
1231
+
1232
+ public function list_tasks()
1233
+ {
1234
+ $ret['result']='success';
1235
+ $ret['show']=false;
1236
+ $tasks=WPvivid_Exporter_taskmanager::get_tasks();
1237
+ foreach ($tasks as $task)
1238
+ {
1239
+ $this->task_monitor($task['id']);
1240
+ $task=WPvivid_Exporter_taskmanager::get_task($task['id']);
1241
+ $status=WPvivid_Exporter_taskmanager::get_backup_task_status($task['id']);
1242
+
1243
+ $ret['show']=true;
1244
+ $ret['completed']=false;
1245
+ $ret['error']=false;
1246
+ if($status['str']=='running'||$status['str']=='no_responds'||$status['str']=='ready')
1247
+ {
1248
+ $ret['continue']=1;
1249
+ }
1250
+ else
1251
+ {
1252
+ $ret['continue']=0;
1253
+ $ret['show']=false;
1254
+ }
1255
+
1256
+ $progress=WPvivid_Exporter_taskmanager::get_backup_tasks_progress($task['id']);
1257
+ $ret['percent']='<div class="action-progress-bar-percent" style="height:24px;width:'.(int)$progress['progress'].'%;"></div>';
1258
+ $ret['doing']=$task['data']['doing']='export';
1259
+ if($status['str']=='ready')
1260
+ {
1261
+ $ret['doing']=__('Ready to export. Progress: 0%, running time: 0second.','wpvivid');
1262
+ }
1263
+ else if($status['str']=='running')
1264
+ {
1265
+ $ret['doing']= __(' Progress: ', 'wpvivid') . $progress['descript'] . __(', running time: ', 'wpvivid') . $progress['running_time'];
1266
+ }
1267
+ else if($status['str']=='wait_resume')
1268
+ {
1269
+ $ret['doing']='Task '.$task['id'].' timed out, the export task will retry in '.$task['data']['next_resume_time'].' seconds, retry times: '.$task['status']['resume_count'].'.';
1270
+ }
1271
+ else if($status['str']=='no_responds')
1272
+ {
1273
+ $ret['doing']=__('The export task is not responding.','wpvivid');
1274
+ }
1275
+ else if($status['str']=='completed')
1276
+ {
1277
+ $file_name = $task['data']['export']['export_info']['file_name'];
1278
+ $file_size = $task['data']['export']['export_info']['size'];
1279
+ if($task['options']['backup_options']['post_type'] === 'post'){
1280
+ $post_type = 'posts';
1281
+ }
1282
+ else{
1283
+ $post_type = 'pages';
1284
+ }
1285
+ $msg = '<div style="margin-bottom: 10px;">The export task is completed and the automatic download starts. If the automatic download didn\'t run, please click <a style="cursor:pointer;" onclick="wpvivid_download_export(\''.$file_name.'\', \''.$file_size.'\');">here</a> to download.</div>';
1286
+ $msg .= '<div style="margin-bottom: 10px;">The count of exported '.$post_type.': '.$task['data']['export']['export_info']['post_count'].'.</div>';
1287
+ $msg .= '<div style="margin-bottom: 10px;">File name: '.$file_name.'.</div>';
1288
+ $msg .= '<div>File size: '.size_format($file_size, 2).'.</div>';
1289
+ /*$ret['doing']=__('<div class="notice notice-success is-dismissible inline"><p>Export task have been completed, task id: '.$task['id'].'</p>
1290
+ <button type="button" class="notice-dismiss" onclick="click_dismiss_notice(this);">
1291
+ <span class="screen-reader-text">Dismiss this notice.</span>
1292
+ </button>
1293
+ </div>');*/
1294
+ $ret['completed']=true;
1295
+ $ret['file_name'] = $file_name;
1296
+ $ret['file_size'] = $file_size;
1297
+ $ret['doing']=$msg;
1298
+ }
1299
+ else if($status['str']=='error')
1300
+ {
1301
+ $ret['doing']='Export error: '.$task['status']['error'];
1302
+ $ret['doing']=__('<div class="notice notice-error is-dismissible inline"><p>Export error: '.$task['status']['error'].'</p></div>');
1303
+ $ret['error']=true;
1304
+ }
1305
+
1306
+ if($ret['completed']||$ret['error'])
1307
+ {
1308
+ WPvivid_Exporter_taskmanager::delete_task($task['id']);
1309
+ }
1310
+ }
1311
+ echo json_encode($ret);
1312
+ die();
1313
+ }
1314
+
1315
+ public function task_monitor($task_id)
1316
+ {
1317
+ global $wpvivid_plugin;
1318
+
1319
+ if(WPvivid_Exporter_taskmanager::get_task($task_id)!==false)
1320
+ {
1321
+ if($wpvivid_plugin->wpvivid_log->log_file_handle==false)
1322
+ {
1323
+ $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id,'log_file_name'));
1324
+ }
1325
+
1326
+ $status=WPvivid_Exporter_taskmanager::get_backup_task_status($task_id);
1327
+
1328
+ if($status['str']=='running'||$status['str']=='error'||$status['str']=='no_responds')
1329
+ {
1330
+ $limit=900;
1331
+ $time_spend=time()-$status['timeout'];
1332
+
1333
+ if($time_spend>=$limit)
1334
+ {
1335
+ //time out
1336
+ $message=__('Task time out.', 'wpvivid');
1337
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,$status['resume_count'],$message);
1338
+ WPvivid_error_log::create_error_log($wpvivid_plugin->wpvivid_log->log_file);
1339
+
1340
+ if($wpvivid_plugin->wpvivid_log)
1341
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
1342
+ }
1343
+ else {
1344
+ $time_spend=time()-$status['run_time'];
1345
+ if($time_spend>180)
1346
+ {
1347
+ $wpvivid_plugin->wpvivid_log->WriteLog('Not responding for a long time.','notice');
1348
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'no_responds',false,$status['resume_count']);
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+
1355
+ public function delete_export_list()
1356
+ {
1357
+ if(isset($_POST['export_id']))
1358
+ {
1359
+ $id=sanitize_key($_POST['export_id']);
1360
+ $list = get_option('wpvivid_import_list_cache',array());
1361
+ if(empty($list))
1362
+ {
1363
+ $ret['result']='success';
1364
+ }
1365
+ else
1366
+ {
1367
+ if(isset($list[$id]))
1368
+ {
1369
+ $item=$list[$id];
1370
+ if(isset($item['export']))
1371
+ {
1372
+ foreach ($item['export'] as $file)
1373
+ {
1374
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file['file_name'];
1375
+ @unlink($path);
1376
+ }
1377
+ }
1378
+ unset($list[$id]);
1379
+ update_option('wpvivid_import_list_cache',$list);
1380
+ $ret['result']='success';
1381
+ }
1382
+ else
1383
+ {
1384
+ $ret['result']='success';
1385
+ }
1386
+ }
1387
+ echo json_encode($ret);
1388
+ }
1389
+ die();
1390
+ }
1391
+
1392
+ public function wpvivid_download_export_backup()
1393
+ {
1394
+ global $wpvivid_plugin;
1395
+ $wpvivid_plugin->ajax_check_security();
1396
+ try{
1397
+ if(isset($_REQUEST['file_name']) && !empty($_REQUEST['file_name']) && is_string($_REQUEST['file_name']) &&
1398
+ isset($_REQUEST['file_size']) && !empty($_REQUEST['file_size']) && is_string($_REQUEST['file_size'])){
1399
+ $file_name = $_REQUEST['file_name'];
1400
+ $file_size = intval($_REQUEST['file_size']);
1401
+
1402
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file_name;
1403
+ if (file_exists($path)) {
1404
+ if (session_id()) {
1405
+ session_write_close();
1406
+ }
1407
+ $size = filesize($path);
1408
+ if($size === $file_size) {
1409
+ if (!headers_sent()) {
1410
+ header('Content-Description: File Transfer');
1411
+ header('Content-Type: application/zip');
1412
+ header('Content-Disposition: attachment; filename="' . basename($path) . '"');
1413
+ header('Cache-Control: must-revalidate');
1414
+ header('Content-Length: ' . $size);
1415
+ header('Content-Transfer-Encoding: binary');
1416
+ }
1417
+ if ($size < 1024 * 1024 * 60) {
1418
+ ob_end_clean();
1419
+ readfile($path);
1420
+ exit;
1421
+ } else {
1422
+ ob_end_clean();
1423
+ $download_rate = 1024 * 10;
1424
+ $file = fopen($path, "r");
1425
+ while (!feof($file)) {
1426
+ set_time_limit(20);
1427
+ // send the current file part to the browser
1428
+ print fread($file, round($download_rate * 1024));
1429
+ // flush the content to the browser
1430
+ flush();
1431
+ // sleep one second
1432
+ sleep(1);
1433
+ }
1434
+ fclose($file);
1435
+ exit;
1436
+ }
1437
+ }
1438
+ else{
1439
+ $admin_url = admin_url();
1440
+ echo __('File size not match. please <a href="'.$admin_url.'admin.php?page=wpvivid-export-import">retry</a> again.');
1441
+ die();
1442
+ }
1443
+ }
1444
+
1445
+ $admin_url = admin_url();
1446
+ echo __('File not found. please <a href="'.$admin_url.'admin.php?page=wpvivid-export-import">retry</a> again.');
1447
+ die();
1448
+ }
1449
+ }
1450
+ catch (Exception $error) {
1451
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
1452
+ error_log($message);
1453
+ echo json_encode(array('result'=>'failed','error'=>$message));
1454
+ die();
1455
+ }
1456
+ }
1457
+
1458
+ //import
1459
+ public function output_import()
1460
+ {
1461
+ $import_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
1462
+ update_option('wpvivid_import_list_cache',array());
1463
+ update_option('wpvivid_importer_task_list', array());
1464
+ ?>
1465
+ <div class="postbox export-import-block">
1466
+ <div>
1467
+ <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
1468
+ <img src="<?php echo esc_url(WPVIVID_PLUGIN_IMAGES_URL.'export-import.png'); ?>" style="width:50px;height:50px;">
1469
+ </div>
1470
+ <div style="box-sizing: border-box;">
1471
+ <div class="wpvivid-element-space-bottom wpvivid-element-space-right">Import posts or pages with images in bulk.
1472
+ <span class="wpvivid-feature-pro">
1473
+ <a href="https://wpvivid.com/import-content" target="_blank" style="text-decoration: none;">Learn more</a>
1474
+ </span>
1475
+ </div>
1476
+ <div class="wpvivid-element-space-bottom wpvivid-element-space-right"><strong>Note:</strong> To properly display the imported content,
1477
+ please make sure that the importing and exporting sites have the same environment, for example, same theme or pages built with the same page builder.
1478
+ </div>
1479
+ <div style="clear: both;"></div>
1480
+ </div>
1481
+ <div style="clear: both;"></div>
1482
+ </div>
1483
+ <div style="clear: both;"></div>
1484
+
1485
+ <div style="background: #fff; border: 1px solid #e5e5e5; border-radius: 6px; margin-bottom: 10px; padding: 10px;">
1486
+ <div style="margin-right: 10px; float: left; height: 28px; line-height: 28px;"><?php _e('Imported files will be temporarily stored in directory '.$import_dir); ?></div>
1487
+ <div style="float: left;"><input class="button" type="submit" id="wpvivid_empty_import_folder" value="Delete Exported Files In Folder" onclick="wpvivid_clean_import_folder();" /></div>
1488
+ <div style="clear: both;"></div>
1489
+ </div>
1490
+
1491
+ <div id="wpvivid_import_step1">
1492
+ <p>Choose an export from your computer to import: </p>
1493
+ <input class="button button-primary" type="button" id="wpvivid_select_import_file_button" value="Upload and Import" />
1494
+ <div id="wpvivid_upload_file_list" class="hide-if-no-js" style="margin-top: 10px; display: none;"></div>
1495
+ <br>
1496
+ <p>Or you can use ftp to upload the export to the directory <?php _e($import_dir); ?>. Then click the button below to scan the file to import.</p>
1497
+ <input class="button button-primary" type="button" value="Scan Uploaded Exports" onclick="wpvivid_refresh_import_list();" />
1498
+ <div class="wpvivid-export-import-block" id="wpvivid_import_list" style="margin-top: 10px; display: none;"></div>
1499
+ </div>
1500
+ <div id="wpvivid_import_step2" style="display: none;">
1501
+ <h3>The importing file info</h3>
1502
+ <div id="wpvivid_import_file_data">
1503
+ </div>
1504
+ <h3>Assign author</h3>
1505
+ <div style="margin-bottom: 10px;">
1506
+ Select an existing author:
1507
+ <?php wp_dropdown_users( array( 'name' => "user_map", 'multi' => true, 'show_option_all' => __( '- Select -', 'wpvivid' ) ) );?>
1508
+ </div>
1509
+ <input class="button button-primary" type="button" id="wpvivid_start_import" value="Start to Import" />
1510
+ <input class="button button-primary" type="button" id="wpvivid_rechoose_import_file" value="Back to Import Page" />
1511
+ </div>
1512
+ <div id="wpvivid_import_step3" style="display: none;">
1513
+ <div class="postbox wpvivid-import-log" id="wpvivid_import_log" style="margin-top: 10px; margin-bottom: 0;"></div>
1514
+ </div>
1515
+ </div>
1516
+ <?php
1517
+ $chunk_size = min(wp_max_upload_size()-1024, 1048576*2);
1518
+ $plupload_init = array(
1519
+ 'runtimes' => 'html5,silverlight,flash,html4',
1520
+ 'browse_button' => 'wpvivid_select_import_file_button',
1521
+ 'file_data_name' => 'async-upload',
1522
+ 'max_retries' => 3,
1523
+ 'multiple_queues' => true,
1524
+ 'max_file_size' => '10Gb',
1525
+ 'chunk_size' => $chunk_size.'b',
1526
+ 'url' => admin_url('admin-ajax.php'),
1527
+ 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
1528
+ 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
1529
+ 'multipart' => true,
1530
+ 'urlstream_upload' => true,
1531
+ 'multi_selection' => false,
1532
+ // additional post data to send to our ajax hook
1533
+ 'multipart_params' => array(
1534
+ 'action' => 'wpvivid_upload_import_files', // the ajax action name
1535
+ ),
1536
+ );
1537
+ if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.swf')) {
1538
+ $plupload_init['flash_swf_url'] = includes_url('js/plupload/Moxie.swf');
1539
+ } else {
1540
+ $plupload_init['flash_swf_url'] = includes_url('js/plupload/plupload.flash.swf');
1541
+ }
1542
+
1543
+ if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.xap')) {
1544
+ $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/Moxie.xap');
1545
+ } else {
1546
+ $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/plupload.silverlight.swf');
1547
+ }
1548
+
1549
+ // we should probably not apply this filter, plugins may expect wp's media uploader...
1550
+ $plupload_init = apply_filters('plupload_init', $plupload_init);
1551
+ $upload_file_image = includes_url( '/images/media/archive.png' );
1552
+ ?>
1553
+ <script type="text/javascript">
1554
+ var uploader;
1555
+ var import_file_name='';
1556
+ jQuery(document).ready(function($)
1557
+ {
1558
+ // create the uploader and pass the config from above
1559
+ jQuery('#wpvivid_upload_submit_btn').hide();
1560
+ uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
1561
+
1562
+ // checks if browser supports drag and drop upload, makes some css adjustments if necessary
1563
+ uploader.bind('Init', function(up)
1564
+ {
1565
+ var uploaddiv = $('#wpvivid_plupload-upload-ui');
1566
+
1567
+ if(up.features.dragdrop){
1568
+ uploaddiv.addClass('drag-drop');
1569
+ $('#drag-drop-area')
1570
+ .bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
1571
+ .bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
1572
+
1573
+ }else{
1574
+ uploaddiv.removeClass('drag-drop');
1575
+ $('#drag-drop-area').unbind('.wp-uploader');
1576
+ }
1577
+ });
1578
+ uploader.init();
1579
+
1580
+ function wpvivid_check_plupload_added_files(up, files)
1581
+ {
1582
+ jQuery('#wpvivid_import_list').hide();
1583
+ var file=files[0];
1584
+
1585
+ var ajax_data = {
1586
+ 'action': 'wpvivid_check_import_file',
1587
+ 'file_name':file.name
1588
+ };
1589
+ wpvivid_post_request(ajax_data, function (data)
1590
+ {
1591
+ var jsonarray = jQuery.parseJSON(data);
1592
+ if (jsonarray.result === "success")
1593
+ {
1594
+ jQuery('#wpvivid_select_import_file_button').css({'pointer-events': 'none', 'opacity': '0.4'});
1595
+ var repeat_files = '';
1596
+ plupload.each(files, function(file)
1597
+ {
1598
+ var brepeat=false;
1599
+ var file_list = jQuery('#wpvivid_upload_file_list span');
1600
+ file_list.each(function (index, value) {
1601
+ if (value.innerHTML === file.name) {
1602
+ brepeat=true;
1603
+ }
1604
+ });
1605
+ if(!brepeat) {
1606
+ jQuery('#wpvivid_upload_file_list').append(
1607
+ '<div id="' + file.id + '" style="width: 100%; height: 36px; background: #f1f1f1; margin-bottom: 1px;">' +
1608
+ '<img src=" <?php echo $upload_file_image; ?> " alt="" style="float: left; margin: 2px 10px 0 3px; max-width: 40px; max-height: 32px;">' +
1609
+ '<div style="line-height: 36px; float: left; margin-left: 5px;"><span>' + file.name + '</span></div>' +
1610
+ '<div class="fileprogress" style="line-height: 36px; float: right; margin-right: 5px;"></div>' +
1611
+ '</div>' +
1612
+ '<div style="clear: both;"></div>'
1613
+ );
1614
+ jQuery('#wpvivid_upload_file_list').show();
1615
+
1616
+ uploader.refresh();
1617
+ uploader.start();
1618
+ }
1619
+ else{
1620
+ if(repeat_files === ''){
1621
+ repeat_files += file.name;
1622
+ }
1623
+ else{
1624
+ repeat_files += ', ' + file.name;
1625
+ }
1626
+ }
1627
+ });
1628
+ if(repeat_files !== ''){
1629
+ alert(repeat_files + " already exists in upload list.");
1630
+ repeat_files = '';
1631
+ }
1632
+ }
1633
+ else if(jsonarray.result === "failed")
1634
+ {
1635
+ uploader.removeFile(file);
1636
+ alert(jsonarray.error);
1637
+ }
1638
+ }, function (XMLHttpRequest, textStatus, errorThrown)
1639
+ {
1640
+ var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
1641
+ uploader.removeFile(file);
1642
+ alert(error_message);
1643
+ });
1644
+ }
1645
+
1646
+ uploader.bind('FilesAdded', wpvivid_check_plupload_added_files);
1647
+
1648
+ uploader.bind('Error', function(up, error)
1649
+ {
1650
+ alert('Upload ' + error.file.name +' error, error code: ' + error.code + ', ' + error.message);
1651
+ console.log(error);
1652
+ });
1653
+
1654
+ uploader.bind('FileUploaded', function(up, file, response)
1655
+ {
1656
+ var jsonarray = jQuery.parseJSON(response.response);
1657
+ if(jsonarray.result == 'failed'){
1658
+ alert('upload ' + file.name + ' failed, ' + jsonarray.error);
1659
+ }
1660
+ });
1661
+
1662
+ uploader.bind('UploadProgress', function(up, file)
1663
+ {
1664
+ jQuery('#' + file.id + " .fileprogress").html(file.percent + "%");
1665
+ });
1666
+
1667
+ uploader.bind('UploadComplete',function(up, files)
1668
+ {
1669
+ jQuery('#wpvivid_select_import_file_button').css({'pointer-events': 'auto', 'opacity': '1'});
1670
+ var ajax_data = {
1671
+ 'action': 'wpvivid_upload_import_file_complete',
1672
+ 'files':JSON.stringify(files)
1673
+ };
1674
+ wpvivid_post_request(ajax_data, function (data)
1675
+ {
1676
+ try
1677
+ {
1678
+ var jsonarray = jQuery.parseJSON(data);
1679
+ if(jsonarray.result === 'success')
1680
+ {
1681
+ jQuery('#wpvivid_upload_file_list').html("");
1682
+ jQuery('#wpvivid_upload_file_list').hide();
1683
+ wpvivid_import_step2(jsonarray.data);
1684
+ }
1685
+ else if(jsonarray.result === 'failed')
1686
+ {
1687
+ jQuery('#wpvivid_upload_file_list').html("");
1688
+ jQuery('#wpvivid_upload_file_list').hide();
1689
+ alert(jsonarray.error);
1690
+ }
1691
+ }
1692
+ catch(err)
1693
+ {
1694
+ alert(err);
1695
+ }
1696
+ }, function (XMLHttpRequest, textStatus, errorThrown)
1697
+ {
1698
+ var error_message = wpvivid_output_ajaxerror('refreshing backup list', textStatus, errorThrown);
1699
+ alert(error_message);
1700
+ });
1701
+ plupload.each(files, function(file)
1702
+ {
1703
+ if(typeof file === 'undefined')
1704
+ {
1705
+
1706
+ }
1707
+ else
1708
+ {
1709
+ uploader.removeFile(file.id);
1710
+ }
1711
+ });
1712
+ })
1713
+ });
1714
+
1715
+ function wpvivid_clean_import_folder()
1716
+ {
1717
+ var descript = 'Are you sure you want to delete all the exported files in the /ImportandExport folder? All the export files in the folder will be permanently deleted.';
1718
+ var ret = confirm(descript);
1719
+ if(ret === true){
1720
+ var ajax_data = {
1721
+ 'action': 'wpvivid_clean_import_folder'
1722
+ };
1723
+ wpvivid_post_request(ajax_data, function (data)
1724
+ {
1725
+ try {
1726
+ var jsonarray = jQuery.parseJSON(data);
1727
+ if(jsonarray.html !== false) {
1728
+ jQuery('#wpvivid_import_list').html(jsonarray.html);
1729
+ jQuery('#wpvivid_empty_import_folder').val('Delete Exported Files In Folder ('+jsonarray.size+')');
1730
+ }
1731
+ }
1732
+ catch(err) {
1733
+ alert(err);
1734
+ }
1735
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
1736
+ var error_message = wpvivid_output_ajaxerror('scanning import folder', textStatus, errorThrown);
1737
+ alert(error_message);
1738
+ });
1739
+ }
1740
+ }
1741
+
1742
+ function wpvivid_import_step2(data)
1743
+ {
1744
+ jQuery('#wpvivid_import_file_data').html('');
1745
+ jQuery.each(data, function (index, value)
1746
+ {
1747
+ import_file_name=value['file_name'];
1748
+ var list = "";
1749
+ var myDate = new Date(value['time']*1000);
1750
+ list += "<li>File name: " + value['file_name'] + "</li>";
1751
+ list += "<li>Post type: " + value['export_type'] + "</li>";
1752
+ list += "<li>Posts: " + value['posts_count'] + "</li>";
1753
+ list += "<li>Media files size: " + value['media_size'] + "</li>";
1754
+ list += "<li>Export time: " + myDate.toLocaleString('en-us') + "</li>";
1755
+ jQuery("#wpvivid_import_file_data").append("<ul>"+ list +"</ul>");
1756
+ });
1757
+
1758
+ jQuery('#wpvivid_import_step1').hide();
1759
+ jQuery('#wpvivid_import_step2').show();
1760
+ jQuery('#wpvivid_import_step3').hide();
1761
+ }
1762
+
1763
+ function wpvivid_import_step3()
1764
+ {
1765
+ jQuery('#wpvivid_import_step1').hide();
1766
+ jQuery('#wpvivid_import_step2').hide();
1767
+ jQuery('#wpvivid_import_step3').show();
1768
+ }
1769
+
1770
+ function wpvivid_return_import_page(){
1771
+ jQuery('#wpvivid_import_step1').show();
1772
+ jQuery('#wpvivid_import_step2').hide();
1773
+ jQuery('#wpvivid_import_step3').hide();
1774
+ }
1775
+
1776
+ function wpvivid_monitor_import_task()
1777
+ {
1778
+ var ajax_data = {
1779
+ 'action': 'wpvivid_get_import_progress',
1780
+ };
1781
+ wpvivid_post_request(ajax_data, function(data)
1782
+ {
1783
+ try
1784
+ {
1785
+ var jsonarray = jQuery.parseJSON(data);
1786
+ if (typeof jsonarray === 'object')
1787
+ {
1788
+ if (jsonarray.result === 'success')
1789
+ {
1790
+ jQuery('#wpvivid_import_log').html("");
1791
+ while (jsonarray.log.indexOf('\n') >= 0)
1792
+ {
1793
+ var iLength = jsonarray.log.indexOf('\n');
1794
+ var log = jsonarray.log.substring(0, iLength);
1795
+ jsonarray.log = jsonarray.log.substring(iLength + 1);
1796
+ var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
1797
+ jQuery('#wpvivid_import_log').append(insert_log);
1798
+ var div = jQuery('#wpvivid_import_log');
1799
+ div[0].scrollTop = div[0].scrollHeight;
1800
+ }
1801
+ if (jsonarray.status === 'wait')
1802
+ {
1803
+ setTimeout(function () {
1804
+ wpvivid_monitor_import_task();
1805
+ }, 1000);
1806
+ }
1807
+ else if (jsonarray.status === 'completed')
1808
+ {
1809
+ var insert_log = "<div style=\"clear:both;\"><a style='cursor: pointer;' onclick='wpvivid_return_import_page();'>Return import page</a></div>";
1810
+ jQuery('#wpvivid_import_log').append(insert_log);
1811
+ var div = jQuery('#wpvivid_import_log');
1812
+ div[0].scrollTop = div[0].scrollHeight;
1813
+ setTimeout(function () {
1814
+ alert("Import completed successfully.");
1815
+ }, 1000);
1816
+ wpvivid_import_lock_unlock('unlock');
1817
+ }
1818
+ else if (jsonarray.status === 'error')
1819
+ {
1820
+ alert("Import failed.");
1821
+ wpvivid_import_lock_unlock('unlock');
1822
+ }
1823
+ else
1824
+ {
1825
+ setTimeout(function ()
1826
+ {
1827
+ wpvivid_monitor_import_task();
1828
+ }, 1000);
1829
+ }
1830
+ }
1831
+ else {
1832
+ setTimeout(function () {
1833
+ wpvivid_monitor_import_task();
1834
+ }, 1000);
1835
+ }
1836
+ }
1837
+ else{
1838
+ setTimeout(function () {
1839
+ wpvivid_monitor_import_task();
1840
+ }, 1000);
1841
+ }
1842
+ }
1843
+ catch (err) {
1844
+ setTimeout(function () {
1845
+ wpvivid_monitor_import_task();
1846
+ }, 1000);
1847
+ }
1848
+ },function(XMLHttpRequest, textStatus, errorThrown) {
1849
+ setTimeout(function () {
1850
+ wpvivid_monitor_import_task();
1851
+ }, 1000);
1852
+ });
1853
+ }
1854
+
1855
+ jQuery('#wpvivid_start_import').click(function()
1856
+ {
1857
+ if(import_file_name!=='')
1858
+ {
1859
+ var descript = '';
1860
+ var user=jQuery('select[name="user_map"]').val();
1861
+ if(user !== '0'){
1862
+ wpvivid_start_import(import_file_name, user);
1863
+ }
1864
+ else{
1865
+ alert('Please select an existing author to start importing.');
1866
+ }
1867
+ }
1868
+ });
1869
+
1870
+ jQuery('#wpvivid_rechoose_import_file').click(function(){
1871
+ jQuery('#wpvivid_import_step1').show();
1872
+ jQuery('#wpvivid_import_step2').hide();
1873
+ jQuery('#wpvivid_import_step3').hide();
1874
+ });
1875
+
1876
+ function wpvivid_start_import (file_name, user)
1877
+ {
1878
+ wpvivid_import_lock_unlock('lock');
1879
+ wpvivid_monitor_import_task();
1880
+ wpvivid_import_step3();
1881
+ var ajax_data = {
1882
+ 'action':'wpvivid_start_import',
1883
+ 'file_name':file_name,
1884
+ 'user':user
1885
+ };
1886
+
1887
+ wpvivid_post_request(ajax_data, function(data)
1888
+ {
1889
+ }, function(XMLHttpRequest, textStatus, errorThrown)
1890
+ {
1891
+ });
1892
+ }
1893
+
1894
+ var wpvivid_scan_data={};
1895
+
1896
+ function wpvivid_refresh_import_list()
1897
+ {
1898
+ var ajax_data = {
1899
+ 'action': 'wpvivid_scan_import_folder'
1900
+ };
1901
+ wpvivid_post_request(ajax_data, function (data)
1902
+ {
1903
+ try {
1904
+ var jsonarray = jQuery.parseJSON(data);
1905
+ if(jsonarray.html !== false)
1906
+ {
1907
+ wpvivid_scan_data=jsonarray.data;
1908
+ jQuery('#wpvivid_import_list').show();
1909
+ jQuery('#wpvivid_import_list').html(jsonarray.html);
1910
+ }
1911
+ }
1912
+ catch(err) {
1913
+ alert(err);
1914
+ }
1915
+ }, function (XMLHttpRequest, textStatus, errorThrown)
1916
+ {
1917
+ var error_message = wpvivid_output_ajaxerror('scanning import folder', textStatus, errorThrown);
1918
+ alert(error_message);
1919
+ });
1920
+ }
1921
+
1922
+ jQuery('#wpvivid_import_list').on("click",'.first-page',function()
1923
+ {
1924
+ wpvivid_change_import_page('first');
1925
+ });
1926
+
1927
+ jQuery('#wpvivid_import_list').on("click",'.prev-page',function()
1928
+ {
1929
+ var page=parseInt(jQuery(this).attr('value'));
1930
+ wpvivid_change_import_page(page-1);
1931
+ });
1932
+
1933
+ jQuery('#wpvivid_import_list').on("click",'.next-page',function()
1934
+ {
1935
+ var page=parseInt(jQuery(this).attr('value'));
1936
+ wpvivid_change_import_page(page+1);
1937
+ });
1938
+
1939
+ jQuery('#wpvivid_import_list').on("click",'.last-page',function()
1940
+ {
1941
+ wpvivid_change_import_page('last');
1942
+ });
1943
+
1944
+ jQuery('#wpvivid_import_list').on("keypress", '.current-page', function(){
1945
+ if(event.keyCode === 13){
1946
+ var page = jQuery(this).val();
1947
+ wpvivid_change_import_page(page);
1948
+ }
1949
+ });
1950
+
1951
+ function wpvivid_change_import_page(page)
1952
+ {
1953
+ var post_ids = {};
1954
+
1955
+ jQuery('input[name="export[]"]').each(function (i)
1956
+ {
1957
+ var id=jQuery(this).val();
1958
+ if(jQuery(this).prop('checked'))
1959
+ {
1960
+ post_ids[id]=1;
1961
+ }
1962
+ else
1963
+ {
1964
+ post_ids[id]=0;
1965
+ }
1966
+ });
1967
+
1968
+ var ajax_data = {
1969
+ 'action':'wpvivid_get_import_list_page',
1970
+ 'page': page,
1971
+ 'post_ids':post_ids
1972
+ };
1973
+
1974
+ wpvivid_post_request(ajax_data, function(data)
1975
+ {
1976
+ var jsonarray = jQuery.parseJSON(data);
1977
+ if (jsonarray.result === 'success')
1978
+ {
1979
+ jQuery('#wpvivid_import_list').html(jsonarray.rows);
1980
+ }
1981
+ else if (jsonarray.result === 'failed')
1982
+ {
1983
+ alert(jsonarray.error);
1984
+ }
1985
+ }, function(XMLHttpRequest, textStatus, errorThrown)
1986
+ {
1987
+ var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
1988
+ alert(error_message);
1989
+ });
1990
+ }
1991
+
1992
+ jQuery('#wpvivid_import_list').on("click",".wpvivid-export-list-item td",function()
1993
+ {
1994
+ var id = jQuery(this).parent().attr('id');
1995
+
1996
+ if(jQuery(this).find('div.export-list-import').length !== 0)
1997
+ {
1998
+ var data={};
1999
+ data[id]=wpvivid_scan_data[id];
2000
+ console.log(data[id]);
2001
+ wpvivid_import_step2(data);
2002
+ jQuery('#wpvivid_import_list').hide();
2003
+ }
2004
+ });
2005
+
2006
+ function wpvivid_calc_import_folder_size(){
2007
+ var ajax_data = {
2008
+ 'action': 'wpvivid_calc_import_folder_size'
2009
+ };
2010
+ wpvivid_post_request(ajax_data, function(data)
2011
+ {
2012
+ var jsonarray = jQuery.parseJSON(data);
2013
+ if (jsonarray.result === 'success')
2014
+ {
2015
+ jQuery('#wpvivid_empty_import_folder').val('Delete Exported Files In Folder ('+jsonarray.size+')');
2016
+ }
2017
+ }, function(XMLHttpRequest, textStatus, errorThrown)
2018
+ {
2019
+ var error_message = wpvivid_output_ajaxerror('calc import folder size', textStatus, errorThrown);
2020
+ alert(error_message);
2021
+ });
2022
+ }
2023
+
2024
+ jQuery(document).ready(function (){
2025
+ wpvivid_calc_import_folder_size();
2026
+ });
2027
+ </script>
2028
+ <?php
2029
+ }
2030
+
2031
+ public function wpvivid_check_import_file_name($file_name){
2032
+ if(preg_match('/wpvivid-.*_.*_export_.*\.zip$/', $file_name))
2033
+ {
2034
+ if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
2035
+ {
2036
+ $id= $matches[0];
2037
+ $id=substr($id,0,strlen($id)-1);
2038
+ $ret['result']=WPVIVID_SUCCESS;
2039
+ $ret['id']=$id;
2040
+ }
2041
+ else
2042
+ {
2043
+ $ret['result']=WPVIVID_FAILED;
2044
+ $ret['error']=$file_name.' is not the file exported by WPvivid backup plugin.';
2045
+ }
2046
+ }
2047
+ else
2048
+ {
2049
+ $ret['result']=WPVIVID_FAILED;
2050
+ $ret['error']=$file_name.' is not the file exported by WPvivid backup plugin.';
2051
+ }
2052
+ return $ret;
2053
+ }
2054
+
2055
+ public function check_import_file()
2056
+ {
2057
+ if(isset($_POST['file_name']))
2058
+ {
2059
+ $ret = $this->wpvivid_check_import_file_name($_POST['file_name']);
2060
+ }
2061
+ else
2062
+ {
2063
+ $ret['result']=WPVIVID_FAILED;
2064
+ $ret['error']='Failed to post file name.';
2065
+ }
2066
+
2067
+ echo json_encode($ret);
2068
+ die();
2069
+ }
2070
+
2071
+ public function upload_import_dir($uploads)
2072
+ {
2073
+ $uploads['path'] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
2074
+ return $uploads;
2075
+ }
2076
+
2077
+ public function upload_import_files()
2078
+ {
2079
+ $options['test_form'] =true;
2080
+ $options['action'] ='wpvivid_upload_import_files';
2081
+ $options['test_type'] = false;
2082
+ $options['ext'] = 'zip';
2083
+ $options['type'] = 'application/zip';
2084
+
2085
+ add_filter('upload_dir', array($this, 'upload_import_dir'));
2086
+
2087
+ $status = wp_handle_upload($_FILES['async-upload'],$options);
2088
+
2089
+ remove_filter('upload_dir', array($this, 'upload_import_dir'));
2090
+
2091
+ if (isset($status['error']))
2092
+ {
2093
+ echo json_encode(array('result'=>WPVIVID_FAILED, 'error' => $status['error']));
2094
+ exit;
2095
+ }
2096
+
2097
+ $file_name=basename($_POST['name']);
2098
+
2099
+ if (isset($_POST['chunks']) && isset($_POST['chunk']))
2100
+ {
2101
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2102
+ rename($status['file'],$path.$file_name.'_'.$_POST['chunk'].'.tmp');
2103
+ $status['file'] = $path.$file_name.'_'.$_POST['chunk'].'.tmp';
2104
+ if($_POST['chunk'] == $_POST['chunks']-1)
2105
+ {
2106
+ $file_handle = fopen($path.$file_name, 'wb');
2107
+ if ($file_handle)
2108
+ {
2109
+ for ($i=0; $i<$_POST['chunks']; $i++)
2110
+ {
2111
+ $chunks_handle=fopen($path.$file_name.'_'.$i.'.tmp','rb');
2112
+ if($chunks_handle)
2113
+ {
2114
+ while ($line = fread($chunks_handle, 1048576*2))
2115
+ {
2116
+ fwrite($file_handle, $line);
2117
+ }
2118
+ fclose($chunks_handle);
2119
+ @unlink($path.$file_name.'_'.$i.'.tmp');
2120
+ }
2121
+ }
2122
+ fclose($file_handle);
2123
+ }
2124
+ }
2125
+ }
2126
+ echo json_encode(array('result'=>WPVIVID_SUCCESS));
2127
+ die();
2128
+ }
2129
+
2130
+ public function get_import_progress()
2131
+ {
2132
+ try
2133
+ {
2134
+ $tasks=WPvivid_Impoter_taskmanager::get_tasks();
2135
+ foreach ($tasks as $task)
2136
+ {
2137
+ WPvivid_Impoter_taskmanager::get_task($task['id']);
2138
+ $import_log = new WPvivid_import_data();
2139
+ $ret['result'] = 'success';
2140
+ $ret['status'] = WPvivid_Impoter_taskmanager::get_import_task_status($task['id']);
2141
+ if ($ret['status'] === 'error')
2142
+ {
2143
+ WPvivid_Impoter_taskmanager::delete_task($task['id']);
2144
+ }
2145
+ if($ret['status'] === 'completed')
2146
+ {
2147
+ WPvivid_Impoter_taskmanager::delete_task($task['id']);
2148
+ }
2149
+ $ret['log'] = $import_log->get_log_content();
2150
+ echo json_encode($ret);
2151
+ die();
2152
+ }
2153
+ $ret['result'] = 'success';
2154
+ $ret['status'] ='wait';
2155
+ $ret['log']='';
2156
+ echo json_encode($ret);
2157
+ die();
2158
+ }
2159
+ catch (Exception $error) {
2160
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2161
+ error_log($message);
2162
+ echo json_encode(array('result'=>'failed','error'=>$message));
2163
+ die();
2164
+ }
2165
+ }
2166
+
2167
+ public function upload_import_file_complete()
2168
+ {
2169
+ $ret['html']=false;
2170
+ if(isset($_POST['files']))
2171
+ {
2172
+ $files =stripslashes($_POST['files']);
2173
+ $files =json_decode($files,true);
2174
+ if(is_null($files))
2175
+ {
2176
+ $ret['result']=WPVIVID_FAILED;
2177
+ $ret['error']= 'Failed to decode files.';
2178
+ echo json_encode($ret);
2179
+ die();
2180
+ }
2181
+
2182
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2183
+
2184
+ //if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/',$files[0]['name']))
2185
+ //{
2186
+ $data=array();
2187
+ $check_result=true;
2188
+ foreach ($files as $file)
2189
+ {
2190
+ $res=$this->check_is_import_file($path.$file['name']);
2191
+ if($res['result'] =='success')
2192
+ {
2193
+ $add_file['file_name']=$file['name'];
2194
+ $add_file['size']=filesize($path.$file['name']);
2195
+ $add_file['export_type']=$res['export_type'];
2196
+ $add_file['export_comment']=$res['export_comment'];
2197
+ $add_file['posts_count']=$res['posts_count'];
2198
+ $add_file['media_size']=size_format($res['media_size'],2);
2199
+ $add_file['time']=$res['time'];
2200
+ $data[]=$add_file;
2201
+ }
2202
+ else
2203
+ {
2204
+ $check_result=false;
2205
+ }
2206
+ }
2207
+
2208
+ if($check_result === true)
2209
+ {
2210
+ $ret['result']=WPVIVID_SUCCESS;
2211
+ $ret['data']=$data;
2212
+ }
2213
+ else
2214
+ {
2215
+ $ret['result']=WPVIVID_FAILED;
2216
+ $ret['error']='Upload file failed.';
2217
+ foreach ($files as $file)
2218
+ {
2219
+ $this->clean_tmp_files($path, $file['name']);
2220
+ @unlink($path . $file['name']);
2221
+ }
2222
+ }
2223
+ /*}
2224
+ else
2225
+ {
2226
+ $ret['result']=WPVIVID_FAILED;
2227
+ $ret['error']='The file is not created by WPvivid backup plugin.';
2228
+ }*/
2229
+ }
2230
+ else {
2231
+ $ret['result']=WPVIVID_FAILED;
2232
+ $ret['error']='Failed to post file name.';
2233
+ }
2234
+ echo json_encode($ret);
2235
+ die();
2236
+ }
2237
+
2238
+ public function check_is_import_file($file_name)
2239
+ {
2240
+ $ret=$this->get_backup_file_info($file_name);
2241
+ if($ret['result'] === WPVIVID_SUCCESS)
2242
+ {
2243
+ $export_type_support_array = array('post', 'page');
2244
+ if(isset($ret['json_data']['post_type']) && in_array($ret['json_data']['post_type'], $export_type_support_array))
2245
+ {
2246
+ $ret['export_type']=$ret['json_data']['post_type'];
2247
+ $ret['export_comment']=isset($ret['json_data']['post_comment']) ? $ret['json_data']['post_comment'] : 'N/A';
2248
+ $ret['export_time']=isset($ret['json_data']['create_time']) ? $ret['json_data']['create_time'] : '';
2249
+ $ret['posts_count']=isset($ret['json_data']['posts_count']) ? $ret['json_data']['posts_count'] : 0;
2250
+ $ret['media_size']=isset($ret['json_data']['media_size']) ? $ret['json_data']['media_size'] : 0;
2251
+ $ret['time']=isset($ret['json_data']['create_time']) ? $ret['json_data']['create_time'] : time();
2252
+ return $ret;
2253
+ }
2254
+ else{
2255
+ $ret['result'] = WPVIVID_FAILED;
2256
+ $ret['error'] = 'The backup is not an import file.';
2257
+ return $ret;
2258
+ }
2259
+ }
2260
+ else
2261
+ {
2262
+ return $ret;
2263
+ }
2264
+ }
2265
+
2266
+ public function get_backup_file_info($file_name)
2267
+ {
2268
+ $zip=new WPvivid_ZipClass();
2269
+ $ret=$zip->get_json_data($file_name, 'export');
2270
+ if($ret['result'] === WPVIVID_SUCCESS)
2271
+ {
2272
+ $json=$ret['json_data'];
2273
+ $json = json_decode($json, 1);
2274
+ if (is_null($json))
2275
+ {
2276
+ return array('result'=>WPVIVID_FAILED,'error'=>'Failed to decode json');
2277
+ } else {
2278
+ return array('result'=>WPVIVID_SUCCESS,'json_data'=>$json);
2279
+ }
2280
+ }
2281
+ else {
2282
+ return $ret;
2283
+ }
2284
+ }
2285
+
2286
+ function clean_tmp_files($path, $filename){
2287
+ $handler=opendir($path);
2288
+ while(($file=readdir($handler))!==false) {
2289
+ if (!is_dir($path.$file) && preg_match('/wpvivid-.*_.*_.*\.tmp$/', $file)) {
2290
+ $iPos = strrpos($file, '_');
2291
+ $file_temp = substr($file, 0, $iPos);
2292
+ if($file_temp === $filename) {
2293
+ @unlink($path.$file);
2294
+ }
2295
+ }
2296
+ }
2297
+ @closedir($handler);
2298
+ }
2299
+
2300
+ function wpvivid_write_upload_log($message, $id = ''){
2301
+ if($id === ''){
2302
+ $id=uniqid('wpvivid-');
2303
+ }
2304
+ global $wpvivid_plugin;
2305
+ $wpvivid_plugin->upload_log=new WPvivid_Log();
2306
+ $wpvivid_plugin->upload_log->CreateLogFile($id.'_upload','no_folder','upload');
2307
+ $wpvivid_plugin->upload_log->WriteLogHander();
2308
+ $wpvivid_plugin->upload_log->WriteLog($message,'notice');
2309
+ }
2310
+
2311
+ public function wpvivid_check_is_import_file_ex($file_name, &$backup_id){
2312
+ if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/', $file_name))
2313
+ {
2314
+ if(preg_match('/wpvivid-(.*?)_/', $file_name, $matches))
2315
+ {
2316
+ $id= $matches[0];
2317
+ $id=substr($id,0,strlen($id)-1);
2318
+ $backup_id=$id;
2319
+ return true;
2320
+ }
2321
+ else
2322
+ {
2323
+ return false;
2324
+ }
2325
+ }
2326
+ else
2327
+ {
2328
+ return false;
2329
+ }
2330
+ }
2331
+
2332
+ public function calc_import_folder_size()
2333
+ {
2334
+ global $wpvivid_plugin;
2335
+ $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2336
+ $bytes_total = 0;
2337
+ $path = realpath($path);
2338
+ if($path!==false && $path!='' && file_exists($path))
2339
+ {
2340
+ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){
2341
+ $bytes_total += $object->getSize();
2342
+ }
2343
+ }
2344
+ $ret['result'] = WPVIVID_SUCCESS;
2345
+ $ret['size'] = $wpvivid_plugin->formatBytes($bytes_total);
2346
+ echo json_encode($ret);
2347
+ die();
2348
+ }
2349
+
2350
+ public function clean_import_folder(){
2351
+ $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2352
+ if(is_dir($path))
2353
+ {
2354
+ $handler = opendir($path);
2355
+ while (($filename = readdir($handler)) !== false){
2356
+ if ($filename != "." && $filename != ".."){
2357
+ if (is_dir($path . $filename)) {
2358
+ continue;
2359
+ }
2360
+ else{
2361
+ $res=$this->check_is_import_file($path.$filename);
2362
+ if($res['result'] =='success'){
2363
+ @unlink($path.$filename);
2364
+ }
2365
+ }
2366
+ }
2367
+ }
2368
+ }
2369
+
2370
+ $data = array();
2371
+ update_option('wpvivid_import_list_cache', $data);
2372
+ $page=1;
2373
+ $display_list=new WPvivid_Export_List();
2374
+ $display_list->set_parent('wpvivid_import_list');
2375
+ $display_list->set_list($data, $page);
2376
+ $display_list->prepare_items();
2377
+ ob_start();
2378
+ $display_list->display();
2379
+ $html = ob_get_clean();
2380
+ $ret['html']=$html;
2381
+ $ret['data']=$data;
2382
+ $ret['result']=WPVIVID_SUCCESS;
2383
+
2384
+ global $wpvivid_plugin;
2385
+ $bytes_total = 0;
2386
+ $path = realpath($path);
2387
+ if($path!==false && $path!='' && file_exists($path))
2388
+ {
2389
+ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object)
2390
+ {
2391
+ $bytes_total += $object->getSize();
2392
+ }
2393
+ }
2394
+ $ret['size'] = $wpvivid_plugin->formatBytes($bytes_total);
2395
+
2396
+ echo json_encode($ret);
2397
+ die();
2398
+ }
2399
+
2400
+ public function wpvivid_scan_import_folder()
2401
+ {
2402
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2403
+
2404
+ $data=array();
2405
+ $count = 0;
2406
+ if(is_dir($path))
2407
+ {
2408
+ $handler = opendir($path);
2409
+ while (($filename = readdir($handler)) !== false)
2410
+ {
2411
+ if ($filename != "." && $filename != "..")
2412
+ {
2413
+ $count++;
2414
+
2415
+ if (is_dir($path . $filename))
2416
+ {
2417
+ continue;
2418
+ }
2419
+ else {
2420
+
2421
+ $res=$this->check_is_import_file($path.$filename);
2422
+ if($res['result'] =='success')
2423
+ {
2424
+ $add_file['file_name']=$filename;
2425
+ $add_file['size']=filesize($path.$filename);
2426
+ $add_file['export_type']=$res['export_type'];
2427
+ $add_file['export_comment']=$res['export_comment'];
2428
+ $add_file['posts_count']=$res['posts_count'];
2429
+ $add_file['media_size']=size_format($res['media_size'],2);
2430
+ $add_file['time']=$res['time'];
2431
+ $data[$this->get_file_id($filename)]=$add_file;
2432
+ }
2433
+ }
2434
+ }
2435
+ }
2436
+ if($handler)
2437
+ @closedir($handler);
2438
+ }
2439
+ else{
2440
+ global $wpvivid_plugin;
2441
+ $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
2442
+ $id=uniqid('wpvivid-');
2443
+ $wpvivid_plugin->wpvivid_log->CreateLogFile($id.'_scan','no_folder','scan');
2444
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
2445
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to get local storage directory.','notice');
2446
+ $ret['result']=WPVIVID_FAILED;
2447
+ $ret['error']='Failed to get local storage directory.';
2448
+ }
2449
+ update_option('wpvivid_import_list_cache', $data);
2450
+ $page=1;
2451
+ $display_list=new WPvivid_Export_List();
2452
+ $display_list->set_parent('wpvivid_import_list');
2453
+ $display_list->set_list($data, $page);
2454
+ $display_list->prepare_items();
2455
+ ob_start();
2456
+ $display_list->display();
2457
+ $html = ob_get_clean();
2458
+ $ret['html']=$html;
2459
+ $ret['data']=$data;
2460
+ $ret['result']=WPVIVID_SUCCESS;
2461
+ echo json_encode($ret);
2462
+ die();
2463
+ }
2464
+
2465
+ public function get_import_list_page(){
2466
+ if(!isset($_POST['page']))
2467
+ {
2468
+ die();
2469
+ }
2470
+ $page=$_POST['page'];
2471
+
2472
+ $backups = get_option('wpvivid_import_list_cache');
2473
+
2474
+ $display_list=new WPvivid_Export_List();
2475
+ $display_list->set_parent('wpvivid_import_list');
2476
+ $display_list->set_list($backups, $page);
2477
+ $display_list->prepare_items();
2478
+ ob_start();
2479
+ $display_list->display();
2480
+ $html = ob_get_clean();
2481
+
2482
+ $ret['result']='success';
2483
+ $ret['rows']=$html;
2484
+ echo json_encode($ret);
2485
+ die();
2486
+ }
2487
+
2488
+ public function deal_import_shutdown_error()
2489
+ {
2490
+ if($this->end_shutdown_function===false){
2491
+ $last_error = error_get_last();
2492
+ if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING,E_DEPRECATED), true)) {
2493
+ $error = $last_error;
2494
+ } else {
2495
+ $error = false;
2496
+ }
2497
+ $ret['result'] = 'failed';
2498
+ if ($error === false) {
2499
+ $ret['error'] = 'unknown Error';
2500
+ } else {
2501
+ $ret['error'] = 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
2502
+ error_log($ret['error']);
2503
+ }
2504
+ $id = uniqid('wpvivid-');
2505
+ $log_file_name = $id . '_import';
2506
+ $log = new WPvivid_Log();
2507
+ $log->CreateLogFile($log_file_name, 'no_folder', 'import');
2508
+ $log->WriteLog($ret['error'], 'notice');
2509
+ WPvivid_error_log::create_error_log($log->log_file);
2510
+ $log->CloseFile();
2511
+ echo json_encode($ret);
2512
+ die();
2513
+ }
2514
+ }
2515
+
2516
+ private function flush($task_id)
2517
+ {
2518
+ $ret['result']='success';
2519
+ $ret['task_id']=$task_id;
2520
+ $json=json_encode($ret);
2521
+ if(!headers_sent())
2522
+ {
2523
+ header('Content-Length: '.strlen($json));
2524
+ header('Connection: close');
2525
+ header('Content-Encoding: none');
2526
+ }
2527
+
2528
+
2529
+ if (session_id())
2530
+ session_write_close();
2531
+ echo $json;
2532
+
2533
+ if(function_exists('fastcgi_finish_request'))
2534
+ {
2535
+ fastcgi_finish_request();
2536
+ }
2537
+ else
2538
+ {
2539
+ ob_flush();
2540
+ flush();
2541
+ }
2542
+ }
2543
+
2544
+ public function start_import()
2545
+ {
2546
+ global $wpvivid_plugin;
2547
+ $wpvivid_plugin->ajax_check_security();
2548
+ $this->end_shutdown_function = false;
2549
+ register_shutdown_function(array($this,'deal_import_shutdown_error'));
2550
+ try
2551
+ {
2552
+ if (isset($_POST['file_name']) && !empty($_POST['file_name']) && is_string($_POST['file_name']))
2553
+ {
2554
+ $files=array();
2555
+ $options=array();
2556
+ $files[]=$_POST['file_name'];
2557
+ $options['user']=0;
2558
+ if(isset($_POST['user']))
2559
+ {
2560
+ $options['user']=$_POST['user'];
2561
+ }
2562
+
2563
+ $task_id=$this->get_file_id($_POST['file_name']);
2564
+ WPvivid_Impoter_taskmanager::new_task($task_id, $files,$options);
2565
+ $import_log = new WPvivid_import_data();
2566
+ $import_log->wpvivid_create_import_log();
2567
+ $import_log->wpvivid_write_import_log('Start importing', 'notice');
2568
+ $this->flush($task_id);
2569
+ WPvivid_Impoter_taskmanager::update_import_task_status($task_id, 'running', true);
2570
+ $importer = new WPvivid_media_importer();
2571
+ $ret = $importer->import($task_id);
2572
+ echo json_encode($ret);
2573
+ }
2574
+ }
2575
+ catch (Exception $error)
2576
+ {
2577
+ $message = 'An error has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
2578
+ error_log($message);
2579
+ WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,false,$message);
2580
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
2581
+ $this->end_shutdown_function=true;
2582
+ die();
2583
+ }
2584
+ $this->end_shutdown_function=true;
2585
+ die();
2586
+ }
2587
+
2588
+ public function get_file_id($file_name)
2589
+ {
2590
+ if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/',$file_name))
2591
+ {
2592
+ if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
2593
+ {
2594
+ $id= $matches[0];
2595
+ $id=substr($id,0,strlen($id)-1);
2596
+ return $id;
2597
+ }
2598
+ else
2599
+ {
2600
+ $id=uniqid('wpvivid-');
2601
+ return $id;
2602
+ }
2603
+ }
2604
+ else
2605
+ {
2606
+ $id=uniqid('wpvivid-');
2607
+ return $id;
2608
+ }
2609
+ }
2610
+ }
includes/class-wpvivid-exporter.php ADDED
@@ -0,0 +1,2070 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WPvivid addon: yes
4
+ * Addon Name: wpvivid-backup-pro-all-in-one
5
+ * Description: Pro
6
+ * Version: 1.9.1
7
+ */
8
+
9
+ if ( ! class_exists( 'WP_List_Table' ) )
10
+ {
11
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
12
+ }
13
+
14
+ class WPvivid_Post_List extends WP_List_Table
15
+ {
16
+ public $post_ids;
17
+ public $page_num;
18
+
19
+ public function __construct( $args = array() ) {
20
+ global $post_type_object, $wpdb;
21
+
22
+ parent::__construct(
23
+ array(
24
+ 'plural' => 'posts',
25
+ 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
26
+ )
27
+ );
28
+
29
+ $post_type = $this->screen->post_type;
30
+ $post_type_object = get_post_type_object( $post_type );
31
+
32
+ $exclude_states = get_post_stati(
33
+ array(
34
+ 'show_in_admin_all_list' => false,
35
+ )
36
+ );
37
+ $this->user_posts_count = intval(
38
+ $wpdb->get_var(
39
+ $wpdb->prepare(
40
+ "
41
+ SELECT COUNT( 1 )
42
+ FROM $wpdb->posts
43
+ WHERE post_type = %s
44
+ AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
45
+ AND post_author = %d
46
+ ",
47
+ $post_type,
48
+ get_current_user_id()
49
+ )
50
+ )
51
+ );
52
+
53
+ if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
54
+ $_GET['author'] = get_current_user_id();
55
+ }
56
+
57
+ if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
58
+ $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
59
+ $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
60
+ }
61
+ }
62
+
63
+ public function print_column_headers( $with_id = true ) {
64
+ list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
65
+
66
+ if ( ! empty( $columns['cb'] ) )
67
+ {
68
+ $checked='';
69
+
70
+ static $cb_counter = 1;
71
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
72
+ . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" '.$checked.'/>';
73
+ $cb_counter++;
74
+ }
75
+
76
+ foreach ( $columns as $column_key => $column_display_name ) {
77
+ $class = array( 'manage-column', "column-$column_key" );
78
+
79
+ if ( in_array( $column_key, $hidden ) ) {
80
+ $class[] = 'hidden';
81
+ }
82
+
83
+ if ( 'cb' === $column_key ) {
84
+ $class[] = 'check-column';
85
+ } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
86
+ $class[] = 'num';
87
+ }
88
+
89
+ if ( $column_key === $primary ) {
90
+ $class[] = 'column-primary';
91
+ }
92
+
93
+ $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
94
+ $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
95
+ $id = $with_id ? "id='$column_key'" : '';
96
+
97
+ if ( ! empty( $class ) ) {
98
+ $class = "class='" . join( ' ', $class ) . "'";
99
+ }
100
+
101
+ echo "<$tag $scope $id $class>$column_display_name</$tag>";
102
+ }
103
+ }
104
+
105
+ public function get_columns()
106
+ {
107
+ $post_type = $this->screen->post_type;
108
+
109
+ $posts_columns = array();
110
+
111
+ $posts_columns['cb'] = '<input type="checkbox"/>';
112
+ /* translators: manage posts column name */
113
+ $posts_columns['wpvivid_id'] = 'ID';
114
+
115
+ $posts_columns['title'] = _x( 'Title', 'column name' );
116
+
117
+ if ( post_type_supports( $post_type, 'author' ) ) {
118
+ $posts_columns['author'] = __( 'Author' );
119
+ }
120
+
121
+ $taxonomies = get_object_taxonomies( $post_type, 'objects' );
122
+ $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
123
+
124
+ /**
125
+ * Filters the taxonomy columns in the Posts list table.
126
+ *
127
+ * The dynamic portion of the hook name, `$post_type`, refers to the post
128
+ * type slug.
129
+ *
130
+ * @since 3.5.0
131
+ *
132
+ * @param string[] $taxonomies Array of taxonomy names to show columns for.
133
+ * @param string $post_type The post type.
134
+ */
135
+ $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
136
+ $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
137
+
138
+ foreach ( $taxonomies as $taxonomy ) {
139
+ if ( 'category' === $taxonomy ) {
140
+ $column_key = 'categories';
141
+ } elseif ( 'post_tag' === $taxonomy ) {
142
+ $column_key = 'tags';
143
+ } else {
144
+ $column_key = 'taxonomy-' . $taxonomy;
145
+ }
146
+
147
+ $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
148
+ }
149
+
150
+ $posts_columns['comments'] =__( 'Comments' );
151
+
152
+ $posts_columns['date'] = __( 'Date' );
153
+
154
+ return $posts_columns;
155
+ }
156
+
157
+ function set_post_ids($post_ids,$page_num=1)
158
+ {
159
+ $this->post_ids=$post_ids;
160
+ $this->page_num=$page_num;
161
+ }
162
+
163
+ public function get_pagenum()
164
+ {
165
+ if($this->page_num=='first')
166
+ {
167
+ $this->page_num=1;
168
+ }
169
+ else if($this->page_num=='last')
170
+ {
171
+ $this->page_num=$this->_pagination_args['total_pages'];
172
+ }
173
+ $pagenum = $this->page_num ? $this->page_num : 0;
174
+
175
+ if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
176
+ {
177
+ $pagenum = $this->_pagination_args['total_pages'];
178
+ }
179
+
180
+ return max( 1, $pagenum );
181
+ }
182
+
183
+ function prepare_items()
184
+ {
185
+ $columns = $this->get_columns();
186
+ $hidden = array();
187
+ $sortable = array();
188
+ $this->_column_headers = array($columns, $hidden, $sortable);
189
+
190
+ $total_items =sizeof($this->post_ids);
191
+
192
+ $this->set_pagination_args(
193
+ array(
194
+ 'total_items' => $total_items,
195
+ 'per_page' => 30,
196
+ )
197
+ );
198
+ }
199
+
200
+ public function has_items()
201
+ {
202
+ return !empty($this->post_ids);
203
+ }
204
+
205
+ public function column_cb( $post )
206
+ {
207
+ $checked='';
208
+ if($post->checked)
209
+ {
210
+ $checked='checked';
211
+ }
212
+ ?>
213
+ <input id="cb-select-<?php echo $post->ID; ?>" type="checkbox" name="post[]" value="<?php echo $post->ID; ?>" <?php echo $checked ?>/>
214
+ <?php
215
+ }
216
+
217
+ /**
218
+ * @since 4.3.0
219
+ *
220
+ * @param WP_Post $post
221
+ * @param string $classes
222
+ * @param string $data
223
+ * @param string $primary
224
+ */
225
+ protected function _column_title( $post, $classes, $data, $primary ) {
226
+ echo '<td class="' . $classes . ' page-title" ', $data, '>';
227
+ echo $this->column_title( $post );
228
+ echo '</td>';
229
+ }
230
+
231
+ public function column_wpvivid_id( $post )
232
+ {
233
+ echo '<span>'.$post->ID.'</span>';
234
+ }
235
+ /**
236
+ * Handles the title column output.
237
+ *
238
+ * @since 4.3.0
239
+ *
240
+ * @global string $mode List table view mode.
241
+ *
242
+ * @param WP_Post $post The current WP_Post object.
243
+ */
244
+ public function column_title( $post ) {
245
+ echo '<strong>';
246
+ $title = $post->post_title;
247
+ echo $title;
248
+ echo "</strong>\n";
249
+ }
250
+
251
+ /**
252
+ * Handles the post date column output.
253
+ *
254
+ * @since 4.3.0
255
+ *
256
+ * @global string $mode List table view mode.
257
+ *
258
+ * @param WP_Post $post The current WP_Post object.
259
+ */
260
+ public function column_date( $post )
261
+ {
262
+ global $mode;
263
+
264
+ if ( '0000-00-00 00:00:00' === $post->post_date ) {
265
+ $t_time = $h_time = __( 'Unpublished' );
266
+ $time_diff = 0;
267
+ } else {
268
+ $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
269
+ $m_time = $post->post_date;
270
+ $time = get_post_time( 'G', true, $post );
271
+
272
+ $time_diff = time() - $time;
273
+
274
+ if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
275
+ $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
276
+ } else {
277
+ $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
278
+ }
279
+ }
280
+
281
+ if ( 'publish' === $post->post_status ) {
282
+ $status = __( 'Published' );
283
+ } elseif ( 'future' === $post->post_status ) {
284
+ if ( $time_diff > 0 ) {
285
+ $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
286
+ } else {
287
+ $status = __( 'Scheduled' );
288
+ }
289
+ } else {
290
+ $status = __( 'Last Modified' );
291
+ }
292
+
293
+ /**
294
+ * Filters the status text of the post.
295
+ *
296
+ * @since 4.8.0
297
+ *
298
+ * @param string $status The status text.
299
+ * @param WP_Post $post Post object.
300
+ * @param string $column_name The column name.
301
+ * @param string $mode The list display mode ('excerpt' or 'list').
302
+ */
303
+ $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
304
+
305
+ if ( $status ) {
306
+ echo $status . '<br />';
307
+ }
308
+
309
+ if ( 'excerpt' === $mode ) {
310
+ /**
311
+ * Filters the published time of the post.
312
+ *
313
+ * If `$mode` equals 'excerpt', the published time and date are both displayed.
314
+ * If `$mode` equals 'list' (default), the publish date is displayed, with the
315
+ * time and date together available as an abbreviation definition.
316
+ *
317
+ * @since 2.5.1
318
+ *
319
+ * @param string $t_time The published time.
320
+ * @param WP_Post $post Post object.
321
+ * @param string $column_name The column name.
322
+ * @param string $mode The list display mode ('excerpt' or 'list').
323
+ */
324
+ echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
325
+ } else {
326
+
327
+ /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
328
+ echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Handles the comments column output.
334
+ *
335
+ * @since 4.3.0
336
+ *
337
+ * @param WP_Post $post The current WP_Post object.
338
+ */
339
+ public function column_comments( $post ) {
340
+ ?>
341
+ <div class="post-com-count-wrapper">
342
+ <?php
343
+ echo '<span style="text-align:center">'.get_comments_number($post->ID).'</span>'
344
+ ?>
345
+ </div>
346
+ <?php
347
+ }
348
+
349
+ /**
350
+ * Handles the post author column output.
351
+ *
352
+ * @since 4.3.0
353
+ *
354
+ * @param WP_Post $post The current WP_Post object.
355
+ */
356
+ public function column_author( $post ) {
357
+ $user_data = get_userdata($post->post_author );
358
+
359
+ echo '<span>'.$user_data->display_name.'</span>';
360
+ }
361
+
362
+ /**
363
+ * Handles the default column output.
364
+ *
365
+ * @since 4.3.0
366
+ *
367
+ * @param WP_Post $post The current WP_Post object.
368
+ * @param string $column_name The current column name.
369
+ */
370
+ public function column_default( $post, $column_name ) {
371
+ if ( 'categories' === $column_name )
372
+ {
373
+ $taxonomy = 'category';
374
+ } elseif ( 'tags' === $column_name )
375
+ {
376
+ $taxonomy = 'post_tag';
377
+ } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
378
+ {
379
+ $taxonomy = substr( $column_name, 9 );
380
+ } else {
381
+ $taxonomy = false;
382
+ }
383
+ if ( $taxonomy ) {
384
+ $taxonomy_object = get_taxonomy( $taxonomy );
385
+ $terms = get_the_terms( $post->ID, $taxonomy );
386
+ if ( is_array( $terms ) ) {
387
+ $out = array();
388
+ foreach ( $terms as $t ) {
389
+ $posts_in_term_qv = array();
390
+ if ( 'post' != $post->post_type ) {
391
+ $posts_in_term_qv['post_type'] = $post->post_type;
392
+ }
393
+ if ( $taxonomy_object->query_var ) {
394
+ $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
395
+ } else {
396
+ $posts_in_term_qv['taxonomy'] = $taxonomy;
397
+ $posts_in_term_qv['term'] = $t->slug;
398
+ }
399
+
400
+ $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
401
+
402
+ $out[] = $label;
403
+ }
404
+ /* translators: used between list items, there is a space after the comma */
405
+ echo join( __( ', ' ), $out );
406
+ } else {
407
+ echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
408
+ }
409
+ return;
410
+ }
411
+
412
+ if ( is_post_type_hierarchical( $post->post_type ) ) {
413
+
414
+ /**
415
+ * Fires in each custom column on the Posts list table.
416
+ *
417
+ * This hook only fires if the current post type is hierarchical,
418
+ * such as pages.
419
+ *
420
+ * @since 2.5.0
421
+ *
422
+ * @param string $column_name The name of the column to display.
423
+ * @param int $post_id The current post ID.
424
+ */
425
+ do_action( 'manage_pages_custom_column', $column_name, $post->ID );
426
+ } else {
427
+
428
+ /**
429
+ * Fires in each custom column in the Posts list table.
430
+ *
431
+ * This hook only fires if the current post type is non-hierarchical,
432
+ * such as posts.
433
+ *
434
+ * @since 1.5.0
435
+ *
436
+ * @param string $column_name The name of the column to display.
437
+ * @param int $post_id The current post ID.
438
+ */
439
+ do_action( 'manage_posts_custom_column', $column_name, $post->ID );
440
+ }
441
+
442
+ /**
443
+ * Fires for each custom column of a specific post type in the Posts list table.
444
+ *
445
+ * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
446
+ *
447
+ * @since 3.1.0
448
+ *
449
+ * @param string $column_name The name of the column to display.
450
+ * @param int $post_id The current post ID.
451
+ */
452
+ do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
453
+ }
454
+
455
+ public function display_rows()
456
+ {
457
+ $this->_display_rows( $this->post_ids );
458
+ }
459
+
460
+ private function _display_rows($post_ids)
461
+ {
462
+ $page_post_ids=$post_ids;
463
+ $page=$this->get_pagenum();
464
+ $count=0;
465
+ while ( $count<$page )
466
+ {
467
+ $page_post_ids = array_splice( $post_ids, 0, 30);
468
+ $count++;
469
+ }
470
+ foreach ( $page_post_ids as $post_id)
471
+ {
472
+ $this->single_row($post_id);
473
+ }
474
+ }
475
+
476
+ public function single_row($post_id)
477
+ {
478
+ $post = get_post($post_id['id']);
479
+ $post->checked=$post_id['checked'];
480
+ $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
481
+
482
+ ?>
483
+ <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
484
+ <?php $this->single_row_columns( $post ); ?>
485
+ </tr>
486
+ <?php
487
+ }
488
+
489
+ /**
490
+ * Display the pagination.
491
+ *
492
+ * @since 3.1.0
493
+ *
494
+ * @param string $which
495
+ */
496
+ protected function pagination( $which ) {
497
+ if ( empty( $this->_pagination_args ) ) {
498
+ return;
499
+ }
500
+
501
+ $total_items = $this->_pagination_args['total_items'];
502
+ $total_pages = $this->_pagination_args['total_pages'];
503
+ $infinite_scroll = false;
504
+ if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
505
+ $infinite_scroll = $this->_pagination_args['infinite_scroll'];
506
+ }
507
+
508
+ if ( 'top' === $which && $total_pages > 1 ) {
509
+ $this->screen->render_screen_reader_content( 'heading_pagination' );
510
+ }
511
+
512
+ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
513
+
514
+ $current = $this->get_pagenum();
515
+ $removable_query_args = wp_removable_query_args();
516
+
517
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
518
+
519
+ $current_url = remove_query_arg( $removable_query_args, $current_url );
520
+
521
+ $page_links = array();
522
+
523
+ $total_pages_before = '<span class="paging-input">';
524
+ $total_pages_after = '</span></span>';
525
+
526
+ $disable_first = $disable_last = $disable_prev = $disable_next = false;
527
+
528
+ if ( $current == 1 ) {
529
+ $disable_first = true;
530
+ $disable_prev = true;
531
+ }
532
+ if ( $current == 2 ) {
533
+ $disable_first = true;
534
+ }
535
+ if ( $current == $total_pages ) {
536
+ $disable_last = true;
537
+ $disable_next = true;
538
+ }
539
+ if ( $current == $total_pages - 1 ) {
540
+ $disable_last = true;
541
+ }
542
+
543
+ if ( $disable_first ) {
544
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
545
+ } else {
546
+ $page_links[] = sprintf(
547
+ "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
548
+ __( 'First page' ),
549
+ '&laquo;'
550
+ );
551
+ }
552
+
553
+ if ( $disable_prev ) {
554
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
555
+ } else {
556
+ $page_links[] = sprintf(
557
+ "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
558
+ $current,
559
+ __( 'Previous page' ),
560
+ '&lsaquo;'
561
+ );
562
+ }
563
+
564
+ if ( 'bottom' === $which ) {
565
+ $html_current_page = $current;
566
+ $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
567
+ } else {
568
+ $html_current_page = sprintf(
569
+ "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
570
+ '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
571
+ $current,
572
+ strlen( $total_pages )
573
+ );
574
+ }
575
+ $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
576
+ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
577
+
578
+ if ( $disable_next ) {
579
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
580
+ } else {
581
+ $page_links[] = sprintf(
582
+ "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
583
+ $current,
584
+ __( 'Next page' ),
585
+ '&rsaquo;'
586
+ );
587
+ }
588
+
589
+ if ( $disable_last ) {
590
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
591
+ } else {
592
+ $page_links[] = sprintf(
593
+ "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
594
+ __( 'Last page' ),
595
+ '&raquo;'
596
+ );
597
+ }
598
+
599
+ $pagination_links_class = 'pagination-links';
600
+ if ( ! empty( $infinite_scroll ) ) {
601
+ $pagination_links_class .= ' hide-if-js';
602
+ }
603
+ $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
604
+
605
+ if ( $total_pages ) {
606
+ $page_class = $total_pages < 2 ? ' one-page' : '';
607
+ } else {
608
+ $page_class = ' no-pages';
609
+ }
610
+ $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
611
+
612
+ echo $this->_pagination;
613
+ }
614
+
615
+ /**
616
+ * Generate the table navigation above or below the table
617
+ *
618
+ * @since 3.1.0
619
+ * @param string $which
620
+ */
621
+ protected function display_tablenav( $which ) {
622
+ $css_type = '';
623
+ if ( 'top' === $which ) {
624
+ wp_nonce_field( 'bulk-' . $this->_args['plural'] );
625
+ $css_type = 'margin: 0 0 10px 0';
626
+ }
627
+ else if( 'bottom' === $which ) {
628
+ $css_type = 'margin: 10px 0 0 0';
629
+ }
630
+ ?>
631
+ <div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
632
+ <div class="alignleft actions bulkactions">
633
+ <?php echo '<input class="button-primary" id="wpvivid-post-research-submit" type="submit" name="post" value="Reset Filters">'; ?>
634
+ </div>
635
+ <?php
636
+ $this->extra_tablenav( $which );
637
+ $this->pagination( $which );
638
+ ?>
639
+
640
+ <br class="clear" />
641
+ </div>
642
+ <?php
643
+ }
644
+ }
645
+
646
+ class WPvivid_Exporter_taskmanager
647
+ {
648
+ public static function get_task($task_id)
649
+ {
650
+ $default = array();
651
+ $tasks = get_option('wpvivid_exporter_task_list', $default);
652
+
653
+ if(array_key_exists ($task_id,$tasks))
654
+ {
655
+ return $tasks[$task_id];
656
+ }
657
+ else
658
+ {
659
+ return false;
660
+ }
661
+ }
662
+
663
+ public static function update_task($task_id,$task)
664
+ {
665
+ $default = array();
666
+ $options = get_option('wpvivid_exporter_task_list', $default);
667
+ $options[$task_id]=$task;
668
+ update_option('wpvivid_exporter_task_list',$options);
669
+ }
670
+
671
+ public static function get_tasks()
672
+ {
673
+ $default = array();
674
+ return $options = get_option('wpvivid_exporter_task_list', $default);
675
+ }
676
+
677
+ public static function get_backup_task_status($task_id)
678
+ {
679
+ $tasks=self::get_tasks();
680
+ if(array_key_exists ($task_id,$tasks))
681
+ {
682
+ $task = $tasks[$task_id];
683
+ return $task['status'];
684
+ }
685
+ else
686
+ {
687
+ return false;
688
+ }
689
+ }
690
+
691
+ public static function delete_task($task_id)
692
+ {
693
+ $options = get_option('wpvivid_exporter_task_list', array());
694
+ unset($options[$task_id]);
695
+ update_option('wpvivid_exporter_task_list',$options);
696
+ }
697
+
698
+ public static function update_backup_task_status($task_id,$reset_start_time=false,$status='',$reset_timeout=false,$resume_count=false,$error='')
699
+ {
700
+ $tasks=self::get_tasks();
701
+ if(array_key_exists ($task_id,$tasks))
702
+ {
703
+ $task = $tasks[$task_id];
704
+ $task['status']['run_time']=time();
705
+ if($reset_start_time)
706
+ $task['status']['start_time']=time();
707
+ if(!empty($status))
708
+ {
709
+ $task['status']['str']=$status;
710
+ }
711
+ if($reset_timeout)
712
+ $task['status']['timeout']=time();
713
+ if($resume_count!==false)
714
+ {
715
+ $task['status']['resume_count']=$resume_count;
716
+ }
717
+
718
+ if(!empty($error))
719
+ {
720
+ $task['status']['error']=$error;
721
+ }
722
+ self::update_task($task_id,$task);
723
+ return $task;
724
+ }
725
+ else
726
+ {
727
+ return false;
728
+ }
729
+ }
730
+
731
+ public static function get_task_options($task_id,$option_names)
732
+ {
733
+ $tasks=self::get_tasks();
734
+ if(array_key_exists ($task_id,$tasks))
735
+ {
736
+ $task=$tasks[$task_id];
737
+
738
+ if(is_array($option_names))
739
+ {
740
+ $options=array();
741
+ foreach ($option_names as $name)
742
+ {
743
+ $options[$name]=$task['options'][$name];
744
+ }
745
+ return $options;
746
+ }
747
+ else
748
+ {
749
+ return $task['options'][$option_names];
750
+ }
751
+ }
752
+ else
753
+ {
754
+ return false;
755
+ }
756
+ }
757
+
758
+ public static function is_tasks_running()
759
+ {
760
+ $tasks=self::get_tasks();
761
+ foreach ($tasks as $task)
762
+ {
763
+ if ($task['status']['str']=='running'||$task['status']['str']=='no_responds')
764
+ {
765
+ return true;
766
+ }
767
+ }
768
+ return false;
769
+ }
770
+
771
+ public static function update_main_task_progress($task_id,$job_name,$progress,$finished,$job_data=array())
772
+ {
773
+ $task=self::get_task($task_id);
774
+ if($task!==false)
775
+ {
776
+ $task['status']['run_time']=time();
777
+ $task['status']['str']='running';
778
+ $task['data']['doing']=$job_name;
779
+ $task['data'][$job_name]['finished']=$finished;
780
+ $task['data'][$job_name]['progress']=$progress;
781
+ $task['data'][$job_name]['job_data']=$job_data;
782
+ self::update_task($task_id,$task);
783
+ }
784
+ }
785
+
786
+ public static function get_backup_tasks_progress($task_id)
787
+ {
788
+ $tasks=self::get_tasks();
789
+ if(array_key_exists ($task_id,$tasks))
790
+ {
791
+ $task = $tasks[$task_id];
792
+ $current_time=date("Y-m-d H:i:s");
793
+ $create_time=date("Y-m-d H:i:s",$task['status']['start_time']);
794
+ $time_diff=strtotime($current_time)-strtotime($create_time);
795
+ $running_time='';
796
+ if(date("G",$time_diff) > 0){
797
+ $running_time .= date("G",$time_diff).'hour';
798
+ }
799
+ if(intval(date("i",$time_diff)) > 0){
800
+ $running_time .= intval(date("i",$time_diff)).'min';
801
+ }
802
+ if(intval(date("s",$time_diff)) > 0){
803
+ $running_time .= intval(date("s",$time_diff)).'second';
804
+ }
805
+
806
+ $ret['type']=$task['data']['doing'];
807
+ $ret['progress']=$task['data'][$ret['type']]['progress'];
808
+ $ret['doing']=$task['data'][$ret['type']]['doing'];
809
+ if(isset($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress']))
810
+ $ret['descript']=__($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress'], 'wpvivid');
811
+ else
812
+ $ret['descript']='';
813
+ if(isset($task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data']))
814
+ $ret['upload_data']=$task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data'];
815
+ $task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data']=false;
816
+ $ret['running_time']=$running_time;
817
+ $ret['running_stamp']=$time_diff;
818
+
819
+ return $ret;
820
+ }
821
+ else
822
+ {
823
+ return false;
824
+ }
825
+ }
826
+ }
827
+
828
+ class WPvivid_Exporter_task
829
+ {
830
+ private $task;
831
+
832
+ public function __construct($task_id=false,$task=false)
833
+ {
834
+ if($task_id!==false)
835
+ {
836
+ $this->task=WPvivid_Exporter_taskmanager::get_task($task_id);
837
+ }
838
+
839
+ if($task!==false)
840
+ {
841
+ $this->task=$task;
842
+ }
843
+ }
844
+
845
+ public function get_id()
846
+ {
847
+ return $this->task['id'];
848
+ }
849
+
850
+ public function new_backup_task($options)
851
+ {
852
+ $id=uniqid('wpvivid-');
853
+ $this->task=false;
854
+ $this->task['id']=$id;
855
+
856
+ $this->task['status']['start_time']=time();
857
+ $this->task['status']['run_time']=time();
858
+ $this->task['status']['timeout']=time();
859
+ $this->task['status']['str']='ready';
860
+ $this->task['status']['resume_count']=0;
861
+
862
+ if(isset($options['remote'])) {
863
+ if($options['remote']=='1') {
864
+ $this->task['options']['remote_options'] = isset($options['remote_options']) ? $options['remote_options'] : WPvivid_Setting::get_remote_options();
865
+ }
866
+ else {
867
+ $this->task['options']['remote_options']=false;
868
+ }
869
+ }
870
+ else {
871
+ $this->task['options']['remote_options']=false;
872
+ }
873
+
874
+ $this->task['options']['remote_options'] = apply_filters('wpvivid_set_remote_options', $this->task['options']['remote_options'],$options);
875
+
876
+ if(isset($options['local'])) {
877
+ $this->task['options']['save_local'] = $options['local']=='1' ? 1 : 0;
878
+ }
879
+ else {
880
+ $this->task['options']['save_local']=1;
881
+ }
882
+
883
+ $this->task['options']['post_comment'] = $options['post_comment'];
884
+
885
+ if(empty($backup_prefix))
886
+ $this->task['options']['file_prefix'] = $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']);
887
+ else
888
+ $this->task['options']['file_prefix'] = $backup_prefix . '_' . $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']);
889
+
890
+ $this->task['options']['log_file_name']=$id.'_export';
891
+ $log=new WPvivid_Log();
892
+ $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','export');
893
+ $this->task['options']['backup_options']['prefix']=$this->task['options']['file_prefix'];
894
+ $this->task['options']['backup_options']['compress']=WPvivid_Setting::get_option('wpvivid_compress_setting');
895
+ $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
896
+ $this->task['options']['backup_options']['post_ids']=$options['post_ids'];
897
+ $this->task['options']['backup_options']['post_type']=$options['post_type'];
898
+ $export_data['json_info']['post_type']=$options['post_type'];
899
+ //$export_data['json_info']['post_ids']=$options['post_ids'];
900
+ $export_data['json_info']['post_comment']=$options['post_comment'];
901
+ $this->task['options']['backup_options']['backup'][$options['post_type']]=$export_data;
902
+ $this->task['data']['doing']='export';
903
+ $this->task['data']['export']['doing']='';
904
+ $this->task['data']['export']['finished']=0;
905
+ $this->task['data']['export']['progress']=0;
906
+ if(sizeof($options['post_ids'])>50) {
907
+ $this->task['data']['export']['pre_progress']=(50/sizeof($options['post_ids']))*100;
908
+ }
909
+ else {
910
+ $this->task['data']['export']['pre_progress']=100;
911
+ }
912
+ $this->task['data']['export']['job_data']=array();
913
+ $this->task['data']['export']['sub_job']=array();
914
+ $this->task['data']['export']['export_info']['post_count']=sizeof($options['post_ids']);
915
+ $this->task['data']['upload']['doing']='';
916
+ $this->task['data']['upload']['finished']=0;
917
+ $this->task['data']['upload']['progress']=0;
918
+ $this->task['data']['upload']['job_data']=array();
919
+ $this->task['data']['upload']['sub_job']=array();
920
+ WPvivid_Exporter_taskmanager::update_task($id,$this->task);
921
+ $ret['result']='success';
922
+ $ret['task_id']=$this->task['id'];
923
+ $log->CloseFile();
924
+ return $ret;
925
+ }
926
+
927
+ private function parse_url_all($url)
928
+ {
929
+ $parse = parse_url($url);
930
+ $path=str_replace('/','_',$parse['path']);
931
+ return $parse['host'].$path;
932
+ }
933
+
934
+ public function update_sub_task_progress($key,$finished,$progress)
935
+ {
936
+ $this->task=WPvivid_Exporter_taskmanager::get_task($this->get_id());
937
+ $this->task['status']['run_time']=time();
938
+ $this->task['status']['str']='running';
939
+ $this->task['data']['doing']='export';
940
+ $sub_job_name=$key;
941
+ $this->task['data']['export']['doing']=$key;
942
+ $this->task['data']['export']['sub_job'][$sub_job_name]['finished']=$finished;
943
+ $this->task['data']['export']['sub_job'][$sub_job_name]['progress']=$progress;
944
+ if(!isset( $this->task['data']['export']['sub_job'][$sub_job_name]['job_data']))
945
+ {
946
+ $this->task['data']['export']['sub_job'][$sub_job_name]['job_data']=array();
947
+ }
948
+ WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
949
+ }
950
+
951
+ public function get_next_posts()
952
+ {
953
+ asort($this->task['options']['backup_options']['post_ids']);
954
+ WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
955
+ $post_ids=$this->task['options']['backup_options']['post_ids'];
956
+ if(empty($post_ids))
957
+ {
958
+ return false;
959
+ }
960
+ /*if(sizeof($post_ids)>50)
961
+ {
962
+ $next_post_ids = array_splice( $post_ids, 0, 50 );
963
+ }
964
+ else
965
+ {
966
+ $next_post_ids=$post_ids;
967
+ }*/
968
+ $next_post_ids=$post_ids;
969
+ $ret=$this->get_post_contain_attachment_ids($next_post_ids);
970
+
971
+ $next_post_ids = array_splice( $this->task['options']['backup_options']['post_ids'], 0, $ret['post_count'] );
972
+ $ret['next_post_ids']=$next_post_ids;
973
+
974
+ $post_type = $this->task['options']['backup_options']['post_type'];
975
+ $ret['json_info'] = $this->task['options']['backup_options']['backup'][$post_type]['json_info'];
976
+
977
+ $first=reset($next_post_ids);
978
+ $last=end($next_post_ids);
979
+
980
+ $post_comment = !empty($this->task['options']['post_comment']) ? $this->task['options']['post_comment'].'_' : '';
981
+ $ret['file_name']=$post_comment.self::get_id().'_'.date('Y-m-d-H-i', $this->task['status']['start_time']);
982
+ $ret['export_type']=$this->task['options']['backup_options']['post_type'];
983
+ return $ret;
984
+ }
985
+
986
+ public function update_finished_posts($finished_posts)
987
+ {
988
+ $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
989
+ array_splice( $this->task['options']['backup_options']['post_ids'], 0, $finished_posts['post_count'] );
990
+ $this->task['data']['export']['progress']=$this->task['data']['export']['progress']+$this->task['data']['export']['pre_progress'];
991
+ if($this->task['data']['export']['progress']>100)
992
+ {
993
+ $this->task['data']['export']['progress']=100;
994
+ }
995
+ WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
996
+ }
997
+
998
+ public function update_export_files($file_data)
999
+ {
1000
+ $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
1001
+
1002
+ $this->task['data']['file_data'][]=$file_data;
1003
+
1004
+ $this->task['data']['export']['export_info']['file_name']=$file_data['file_name'];
1005
+ $this->task['data']['export']['export_info']['size']=$file_data['size'];
1006
+
1007
+ WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
1008
+ }
1009
+
1010
+ public function get_export_files()
1011
+ {
1012
+ $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
1013
+
1014
+ if(isset($this->task['data']['file_data']))
1015
+ {
1016
+ $file_data=$this->task['data']['file_data'];
1017
+ return $file_data;
1018
+ }
1019
+ else
1020
+ {
1021
+ return array();
1022
+ }
1023
+ }
1024
+
1025
+ public function get_post_contain_attachment_ids($post_ids)
1026
+ {
1027
+ $max_size=1024*1024*100;
1028
+ $current_size=0;
1029
+ $count=0;
1030
+ $sum_attachment_ids=array();
1031
+ $attachment_added_ids=array();
1032
+ $files=array();
1033
+ foreach ($post_ids as $id)
1034
+ {
1035
+ $count++;
1036
+
1037
+ $attachment_ids=array();
1038
+ $post = get_post( $id );
1039
+ if (preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) )
1040
+ {
1041
+ foreach( $matches[0] as $image )
1042
+ {
1043
+ if ( preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && ( $attachment_id = absint( $class_id[1] ) ) )
1044
+ {
1045
+ if(!in_array($attachment_id,$attachment_added_ids))
1046
+ {
1047
+ if(!is_null(get_post($attachment_id)))
1048
+ {
1049
+ $attachment_ids[] = $attachment_id;
1050
+ $attachment_added_ids[]=$attachment_id;
1051
+ }
1052
+ else
1053
+ {
1054
+ $ret_attachment=$this->get_image_from_post_content($image);
1055
+ $current_size+=$ret_attachment['size'];
1056
+ $files=array_merge($files,$ret_attachment['files']);
1057
+ }
1058
+ }
1059
+ }
1060
+ else
1061
+ {
1062
+ $ret_attachment=$this->get_image_from_post_content($image);
1063
+ $current_size+=$ret_attachment['size'];
1064
+ $files=array_merge($files,$ret_attachment['files']);
1065
+ }
1066
+ }
1067
+ }
1068
+
1069
+ $_elementor_meta=get_post_meta($id,'_elementor_data',true);
1070
+ if($_elementor_meta!=false)
1071
+ {
1072
+ if ( is_string( $_elementor_meta ) && ! empty( $_elementor_meta ) )
1073
+ {
1074
+ $_elementor_meta = json_decode( $_elementor_meta, true );
1075
+ }
1076
+ if ( empty( $_elementor_meta ) )
1077
+ {
1078
+ $_elementor_meta = array();
1079
+ }
1080
+ $elements_data=$_elementor_meta;
1081
+ foreach ( $elements_data as $element_data )
1082
+ {
1083
+ $element_image=$this->get_element_image($element_data,$attachment_added_ids);
1084
+ $attachment_ids=array_merge($attachment_ids,$element_image);
1085
+ }
1086
+ }
1087
+
1088
+ $sum_attachment_ids=array_merge($sum_attachment_ids,$attachment_ids);
1089
+
1090
+ foreach ($attachment_ids as $attachment_id)
1091
+ {
1092
+ $ret_attachment=$this->get_attachment_size($attachment_id);
1093
+ $current_size+=$ret_attachment['size'];
1094
+ $files=array_merge($files,$ret_attachment['files']);
1095
+ }
1096
+
1097
+ if($current_size>$max_size)
1098
+ {
1099
+ break;
1100
+ }
1101
+ }
1102
+
1103
+ $ret['attachment_ids']=$sum_attachment_ids;
1104
+ $ret['post_count']=$count;
1105
+ $ret['files']=$files;
1106
+ return $ret;
1107
+ }
1108
+
1109
+ public function get_image_from_post_content($image)
1110
+ {
1111
+ $ret['size']=0;
1112
+ $ret['files']=array();
1113
+
1114
+ if(class_exists('DOMDocument'))
1115
+ {
1116
+ $doc = new DOMDocument();
1117
+ $doc->loadHTML($image);
1118
+ $xpath = new DOMXPath($doc);
1119
+ $src = $xpath->evaluate("string(//img/@src)");
1120
+ }
1121
+ else
1122
+ {
1123
+ preg_match('/src="([^"]+)/i',$image, $src);
1124
+ $src= str_ireplace( 'src="', '', $src[0]);
1125
+ }
1126
+
1127
+ $src=str_replace('https://','',$src);
1128
+ $src=str_replace('http://','',$src);
1129
+
1130
+ $upload=wp_upload_dir();
1131
+
1132
+ $upload['baseurl']=str_replace('https://','',$upload['baseurl']);
1133
+ $upload['baseurl']=str_replace('http://','',$upload['baseurl']);
1134
+
1135
+
1136
+ $path=str_replace($upload['baseurl'],$upload['basedir'],$src);
1137
+ if(file_exists($path))
1138
+ {
1139
+ $ret['size']+=filesize($path);
1140
+ $ret['files'][]=$path;
1141
+ }
1142
+
1143
+ return $ret;
1144
+ }
1145
+
1146
+ public function get_attachment_size($attachment_id)
1147
+ {
1148
+ $files=array();
1149
+ global $wpdb;
1150
+
1151
+ $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $attachment_id ) );
1152
+
1153
+ foreach ( $postmeta as $meta )
1154
+ {
1155
+ $upload_dir = wp_upload_dir();
1156
+
1157
+ if ( $upload_dir['error'] !== false )
1158
+ {
1159
+ continue;
1160
+ }
1161
+
1162
+ $dir=$upload_dir['basedir'];
1163
+ if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
1164
+ continue;
1165
+ }
1166
+ if($meta->meta_key=='_wp_attached_file')
1167
+ {
1168
+ $bfound=false;
1169
+ $name=$dir.DIRECTORY_SEPARATOR.$meta->meta_value;
1170
+ if(!in_array($name,$files)&&file_exists($name))
1171
+ {
1172
+ $files[]=$name;
1173
+ $bfound=true;
1174
+ }
1175
+ if($bfound)
1176
+ {
1177
+ $attach_meta = wp_get_attachment_metadata( $attachment_id );
1178
+ if($attach_meta!=false)
1179
+ {
1180
+ if(isset($attach_meta['sizes']))
1181
+ {
1182
+ foreach ($attach_meta['sizes'] as $key=>$value)
1183
+ {
1184
+ $data=image_get_intermediate_size($attachment_id,$key);
1185
+ $data['path']=ltrim($data['path'], './');
1186
+ $name=$dir.DIRECTORY_SEPARATOR.$data['path'];
1187
+ if(!in_array($name,$files)&&file_exists($name))
1188
+ {
1189
+ $files[]=$dir.DIRECTORY_SEPARATOR.$data['path'];
1190
+ }
1191
+ }
1192
+ }
1193
+ else
1194
+ {
1195
+ global $wpvivid_plugin;
1196
+ $wpvivid_plugin->wpvivid_log->WriteLog('attach_meta size not found id:'.$attachment_id,'notice');
1197
+ }
1198
+ }
1199
+ }
1200
+ }
1201
+
1202
+ }
1203
+
1204
+ $size=0;
1205
+
1206
+ if(!empty($files))
1207
+ {
1208
+ foreach ($files as $file)
1209
+ {
1210
+ $size+=filesize($file);
1211
+ }
1212
+ }
1213
+
1214
+ $ret['size']=$size;
1215
+ $ret['files']=$files;
1216
+
1217
+ return $ret;
1218
+ }
1219
+
1220
+ public function get_element_image($element_data,&$attachment_added_ids)
1221
+ {
1222
+ $element_image=array();
1223
+
1224
+ if(!empty($element_data['settings']))
1225
+ {
1226
+ $settings=$element_data['settings'];
1227
+ if(isset($settings['image']))
1228
+ {
1229
+ if(!in_array($settings['image']['id'],$attachment_added_ids))
1230
+ {
1231
+ $element_image[]=$settings['image']['id'];
1232
+ $attachment_added_ids[]=$settings['image']['id'];
1233
+ }
1234
+
1235
+ }
1236
+ }
1237
+
1238
+ if(!empty($element_data['elements']))
1239
+ {
1240
+ foreach ($element_data['elements'] as $element)
1241
+ {
1242
+ $temp=$this->get_element_image($element,$attachment_added_ids);
1243
+ $element_image=array_merge($element_image,$temp);
1244
+ }
1245
+ }
1246
+
1247
+ return $element_image;
1248
+ }
1249
+
1250
+ public function add_new_export()
1251
+ {
1252
+ $files=$this->get_export_files();
1253
+
1254
+ $backup_data=array();
1255
+ $status=WPvivid_Exporter_taskmanager::get_backup_task_status($this->task['id']);
1256
+ $backup_data['create_time']=$status['start_time'];
1257
+
1258
+ global $wpvivid_plugin;
1259
+ $backup_data['log']=$wpvivid_plugin->wpvivid_log->log_file;
1260
+ $backup_data['export']=$files;
1261
+ $backup_data['id']=$this->task['id'];
1262
+ $list = get_option('wpvivid_export_list',array());
1263
+ $list[$this->task['id']]=$backup_data;
1264
+ update_option('wpvivid_export_list',$list);
1265
+ }
1266
+ }
1267
+
1268
+ class WPvivid_Exporter_Item{
1269
+ private $config;
1270
+
1271
+ public function __construct($options){
1272
+ $this->config=$options;
1273
+ }
1274
+
1275
+ public function get_download_export_files(){
1276
+ $files = isset($this->config['export']) ? $this->config['export'] : array();
1277
+ if(empty($files)){
1278
+ $ret['result'] = WPVIVID_FAILED;
1279
+ $ret['error']='Failed to get export files.';
1280
+ }
1281
+ else{
1282
+ $ret['result'] = WPVIVID_SUCCESS;
1283
+ $ret['files']=$files;
1284
+ }
1285
+ return $ret;
1286
+ }
1287
+
1288
+ public function get_download_progress($backup_id, $files){
1289
+ $this->config['local']['path'] = 'wpvividbackups';
1290
+ foreach ($files as $file){
1291
+ $need_download = false;
1292
+ $file_path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file;
1293
+ $download_url = content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file;
1294
+ if(file_exists($file_path)){
1295
+ //need calc file size, then compare is need download
1296
+
1297
+ }
1298
+ else{
1299
+ $need_download = true;
1300
+ }
1301
+
1302
+ if($need_download){
1303
+
1304
+ }
1305
+ else{
1306
+ $ret['result'] = WPVIVID_SUCCESS;
1307
+ $ret['files'][$file]['status'] = 'completed';
1308
+ $ret['files'][$file]['download_path'] = $file_path;
1309
+ $ret['files'][$file]['download_url'] = $download_url;
1310
+ ob_start();
1311
+ ?>
1312
+ <div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
1313
+ <span>Part01</span><br>
1314
+ <span><a class="wpvivid-download-export" id="trtr" name="<?php _e($file); ?>" style="cursor: pointer;">Download</a></span><br>
1315
+ <div style="width:100%;height:5px; background-color:#dcdcdc;">
1316
+ <div style="background-color:#0085ba; float:left;width:100%;height:5px;"></div>
1317
+ </div>
1318
+ <span>size: </span><span>1K</span>
1319
+ </div>
1320
+ <?php
1321
+ $html = ob_get_clean();
1322
+ $ret['html']=$html;
1323
+ }
1324
+ }
1325
+ return $ret;
1326
+ }
1327
+ }
1328
+
1329
+ class WPvivid_Exporter
1330
+ {
1331
+ public $task;
1332
+ //public $config;
1333
+
1334
+ public function __construct($task_id=false,$task=false)
1335
+ {
1336
+ if($task_id!==false)
1337
+ {
1338
+ $this->task=new WPvivid_Exporter_task($task_id);
1339
+ }
1340
+ else if($task!==false)
1341
+ {
1342
+ $this->task=new WPvivid_Exporter_task(false,$task);
1343
+ }
1344
+ else
1345
+ {
1346
+ $this->task=new WPvivid_Exporter_task();
1347
+ }
1348
+ }
1349
+
1350
+ public function init_options($task_id)
1351
+ {
1352
+ $this->task=new WPvivid_Exporter_task($task_id);
1353
+ }
1354
+
1355
+ public function export($task_id)
1356
+ {
1357
+ $this->init_options($task_id);
1358
+
1359
+ global $wpvivid_plugin;
1360
+
1361
+ $next=$this->task->get_next_posts();
1362
+
1363
+ $ret['result']='success';
1364
+ WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 5, 0);
1365
+ while($next!==false)
1366
+ {
1367
+ set_time_limit(900);
1368
+ $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to export post '.$next['file_name'],'notice');
1369
+
1370
+ $this->task->update_sub_task_progress($next['file_name'],0,'Start export file '.$next['file_name']);
1371
+ $ret=$this->export_post_to_xml($next['next_post_ids'], $next['attachment_ids'],$next['file_name'],$next['export_type']);
1372
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished to export post '.$next['file_name'],'notice');
1373
+ if($ret['result']=='success')
1374
+ {
1375
+ $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip file '.$next['file_name'],'notice');
1376
+ $next['json_info']['posts_count']=sizeof($next['next_post_ids']);
1377
+ $ret=$this->zip_media_files($ret['xml_file_name'],$next['files'],$next['file_name'],$next['export_type'],$next['json_info']);
1378
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished to zip file '.$next['file_name'],'notice');
1379
+ if($ret['result']!='success')
1380
+ {
1381
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to zip post '.$next['file_name'].' '.json_encode($ret),'notice');
1382
+ return $ret;
1383
+ }
1384
+ $this->task->update_sub_task_progress($next['file_name'],1,'Backing up '.$next['file_name'].' finished');
1385
+ $this->task->update_finished_posts($next);
1386
+ $this->task->update_export_files($ret['file_data']);
1387
+ }
1388
+ else
1389
+ {
1390
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to export post '.$next['file_name'].' '.json_encode($ret),'notice');
1391
+ return $ret;
1392
+ }
1393
+ $next=$this->task->get_next_posts();
1394
+ }
1395
+ WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 100, 1);
1396
+
1397
+ return $ret;
1398
+ }
1399
+
1400
+ public function export_post_to_xml($posts_ids,$attachment_ids,$file_name,$export_type)
1401
+ {
1402
+ $all_ids=array_merge($posts_ids,$attachment_ids);
1403
+ //$xml_file_name=$file_name.'.xml';
1404
+ $xml_file_name=$file_name.'_'.$export_type.'.xml';
1405
+ //$files=array();
1406
+ $export_folder = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
1407
+ if(!file_exists($export_folder)) {
1408
+ @mkdir($export_folder);
1409
+ }
1410
+ $path=$export_folder.DIRECTORY_SEPARATOR.$xml_file_name;
1411
+ $ret['xml_file_name']=$path;
1412
+ if(file_exists($path))
1413
+ {
1414
+ @unlink($path);
1415
+ }
1416
+
1417
+ $this->write_header_to_file($path);
1418
+
1419
+ $this->write_authors_list_to_file($path,$all_ids);
1420
+
1421
+ $this->write_cat_to_file($path,$posts_ids);
1422
+
1423
+ global $wp_query,$wpdb;
1424
+
1425
+ // Fake being in the loop.
1426
+ $wp_query->in_the_loop = true;
1427
+
1428
+ $task_id = $this->task->get_id();
1429
+ while ( $next_posts = array_splice( $posts_ids, 0, 20 ) )
1430
+ {
1431
+ $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
1432
+ $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
1433
+ // Begin Loop.
1434
+ foreach ( $posts as $post )
1435
+ {
1436
+ $this->write_post_to_file($path,$post);
1437
+ }
1438
+ }
1439
+ WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 25, 0);
1440
+ while ( $next_posts = array_splice( $attachment_ids, 0, 20 ) )
1441
+ {
1442
+ $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
1443
+ $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
1444
+ // Begin Loop.
1445
+ foreach ( $posts as $post )
1446
+ {
1447
+ $this->write_media_post_to_file($path,$post);
1448
+ //$post_files=$this->write_media_post_to_file($path,$post);
1449
+ //$files=array_merge($post_files,$files);
1450
+ }
1451
+ }
1452
+ WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 50, 0);
1453
+ $this->write_footer_to_file($path);
1454
+
1455
+ //$ret['files']=$files;
1456
+ $ret['result']='success';
1457
+ return $ret;
1458
+ }
1459
+
1460
+ private function zip_media_files($xml_file,$files,$file_name,$export_type,$json_info=false)
1461
+ {
1462
+ if (!class_exists('PclZip'))
1463
+ include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
1464
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file_name.'_export_'.$export_type.'.zip';
1465
+ $options['compress']['no_compress']=1;
1466
+ $options['compress']['use_temp_file']=1;
1467
+ $options['compress']['use_temp_size']=16;
1468
+ $options['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1469
+
1470
+ if(file_exists($path))
1471
+ @unlink($path);
1472
+ $archive = new PclZip($path);
1473
+
1474
+ if($json_info!==false) {
1475
+ $temp_path = dirname($path).DIRECTORY_SEPARATOR.'wpvivid_export_package_info.json';
1476
+ if(file_exists($temp_path)) {
1477
+ @unlink($temp_path);
1478
+ }
1479
+ $json_info['create_time']=time();
1480
+ $json_info['xml_file']=basename($xml_file);
1481
+ $json_info['media_size']=0;
1482
+ foreach ($files as $file)
1483
+ {
1484
+ $json_info['media_size']+=@filesize($file);
1485
+ }
1486
+ file_put_contents($temp_path,print_r(json_encode($json_info),true));
1487
+ $archive -> add($temp_path,PCLZIP_OPT_REMOVE_PATH,dirname($temp_path));
1488
+ @unlink($temp_path);
1489
+ }
1490
+
1491
+ $ret =$archive -> add($xml_file,PCLZIP_OPT_REMOVE_PATH,dirname($xml_file));
1492
+ @unlink($xml_file);
1493
+ if(!$ret)
1494
+ {
1495
+ return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
1496
+ }
1497
+
1498
+ if(!empty($files)) {
1499
+ $ret = $archive->add($files, PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 16);
1500
+ }
1501
+
1502
+ if(!$ret)
1503
+ {
1504
+ return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
1505
+ }
1506
+
1507
+ $file_data = array();
1508
+ $file_data['file_name'] = basename($path);
1509
+ $file_data['size'] = filesize($path);
1510
+
1511
+ return array('result'=>WPVIVID_SUCCESS,'file_data'=>$file_data);
1512
+ }
1513
+
1514
+ public function write_header_to_file($file)
1515
+ {
1516
+ $wxr_version=1.2;
1517
+
1518
+ $line='<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n";
1519
+ $line.='<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
1520
+ <!-- It contains information about your site\'s posts, pages, comments, categories, and other content. -->
1521
+ <!-- You may use this file to transfer that content from one site to another. -->
1522
+ <!-- This file is not intended to serve as a complete backup of your site. -->
1523
+
1524
+ <!-- To import this information into a WordPress site follow these steps: -->
1525
+ <!-- 1. Log in to that site as an administrator. -->
1526
+ <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
1527
+ <!-- 3. Install the "WordPress" importer from the list. -->
1528
+ <!-- 4. Activate & Run Importer. -->
1529
+ <!-- 5. Upload this file using the form provided on that page. -->
1530
+ <!-- 6. You will first be asked to map the authors in this export file to users -->
1531
+ <!-- on the site. For each author, you may choose to map to an -->
1532
+ <!-- existing user on the site or to create a new user. -->
1533
+ <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
1534
+ <!-- contained in this file into your site. -->';
1535
+ $line.=apply_filters( 'the_generator', get_the_generator( 'export' ), 'export' ) . "\n";
1536
+ $line.='
1537
+ <rss version="2.0"
1538
+ xmlns:excerpt="http://wordpress.org/export/'.$wxr_version.'/excerpt/"
1539
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
1540
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
1541
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
1542
+ xmlns:wp="http://wordpress.org/export/'.$wxr_version.'/"
1543
+ > ';
1544
+ $line.='
1545
+ <channel>
1546
+ <title>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'name' ), 'name' ).'</title>
1547
+ <link>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'url' ), 'url' ).'</link>
1548
+ <description>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'description' ), 'description' ).'</description>
1549
+ <pubDate>'.date( 'D, d M Y H:i:s +0000' ).'</pubDate>
1550
+ <language>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'language' ), 'language' ).'</language>
1551
+ <wp:wxr_version>'.$wxr_version.'</wp:wxr_version>
1552
+ <wp:base_site_url>'.$this->wxr_site_url().'</wp:base_site_url>
1553
+ <wp:base_blog_url>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'url' ), 'url' ).'</wp:base_blog_url>
1554
+ ';
1555
+ file_put_contents($file,$line);
1556
+ }
1557
+
1558
+ public function write_authors_list_to_file($file,$post_ids)
1559
+ {
1560
+ $line=$this->wxr_authors_list( $post_ids );
1561
+ file_put_contents($file,$line,FILE_APPEND);
1562
+ }
1563
+
1564
+ public function write_footer_to_file($file)
1565
+ {
1566
+ $line='
1567
+ </channel>
1568
+ </rss> ';
1569
+ file_put_contents($file,$line,FILE_APPEND);
1570
+ }
1571
+
1572
+ public function write_post_header_to_file($file,$post)
1573
+ {
1574
+ $is_sticky = is_sticky( $post->ID ) ? 1 : 0;
1575
+ $post = get_post( $post );
1576
+
1577
+ $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
1578
+ $id = isset( $post->ID ) ? $post->ID : 0;
1579
+
1580
+ $guid= apply_filters( 'the_guid', $guid, $id );
1581
+ $item_header_line='
1582
+ <item>
1583
+ <title>
1584
+ '.apply_filters( 'the_title_rss', $post->post_title ).'
1585
+ </title>
1586
+ <link>'.esc_url( apply_filters( 'the_permalink_rss', get_permalink($post->ID) ) ).'</link>
1587
+ <pubDate>'.mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true,$post ), false ).'</pubDate>
1588
+ <dc:creator>'.$this->wxr_cdata( get_the_author_meta( 'login' ) ).'</dc:creator>
1589
+ <guid isPermaLink="false">'.$guid.'</guid>
1590
+ <description></description>
1591
+ <content:encoded>'.$this->wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ).' </content:encoded>
1592
+ <excerpt:encoded>'.$this->wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ).'</excerpt:encoded>
1593
+ <wp:post_id>'.intval( $post->ID ).'</wp:post_id>
1594
+ <wp:post_date>'.$this->wxr_cdata( $post->post_date ).'</wp:post_date>
1595
+ <wp:post_date_gmt>'.$this->wxr_cdata( $post->post_date_gmt ).'</wp:post_date_gmt>
1596
+ <wp:comment_status>'.$this->wxr_cdata( $post->comment_status ).'</wp:comment_status>
1597
+ <wp:ping_status>'.$this->wxr_cdata( $post->ping_status ).'</wp:ping_status>
1598
+ <wp:post_name>'.$this->wxr_cdata( $post->post_name ).'</wp:post_name>
1599
+ <wp:status>'.$this->wxr_cdata( $post->post_status ).'</wp:status>
1600
+ <wp:post_parent>'.intval( $post->post_parent ).'</wp:post_parent>
1601
+ <wp:menu_order>'.intval( $post->menu_order ).'</wp:menu_order>
1602
+ <wp:post_type>'.$this->wxr_cdata( $post->post_type ).'</wp:post_type>
1603
+ <wp:post_password>'.$this->wxr_cdata( $post->post_password ).'</wp:post_password>
1604
+ <wp:is_sticky>'.intval( $is_sticky ).'</wp:is_sticky>
1605
+ ';
1606
+ if ( $post->post_type == 'attachment' )
1607
+ $item_header_line.='<wp:attachment_url>'.$this->wxr_cdata( wp_get_attachment_url( $post->ID ) ).'</wp:attachment_url>';
1608
+ file_put_contents($file,$item_header_line,FILE_APPEND);
1609
+
1610
+ $line=$this->wxr_post_taxonomy($post);
1611
+ file_put_contents($file,$line,FILE_APPEND);
1612
+ }
1613
+
1614
+ public function write_media_post_to_file($file,$post)
1615
+ {
1616
+ global $wpdb;
1617
+
1618
+ //$files=array();
1619
+ //$upload_dir = wp_upload_dir();
1620
+ //$dir=$upload_dir['basedir'];
1621
+ //setup_postdata( $post );
1622
+
1623
+ $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
1624
+ $post_meta_line='';
1625
+ //$test_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
1626
+ $added_meta_key=array();
1627
+ foreach ( $postmeta as $meta )
1628
+ {
1629
+ /*
1630
+ $upload_dir = wp_upload_dir( $post->post_date );
1631
+
1632
+ if ( $upload_dir['error'] !== false )
1633
+ {
1634
+ continue;
1635
+ }
1636
+ $dir=$upload_dir['basedir'];
1637
+ $subdir=$upload_dir['subdir'];
1638
+ if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
1639
+ continue;
1640
+ }
1641
+ if($meta->meta_key=='_wp_attached_file')
1642
+ {
1643
+ $bfound=false;
1644
+ $name=$dir.DIRECTORY_SEPARATOR.$meta->meta_value;
1645
+ if(file_exists($name))
1646
+ {
1647
+ $files[]=$name;
1648
+ $bfound=true;
1649
+ }
1650
+
1651
+ if($bfound)
1652
+ {
1653
+ $attach_meta = wp_get_attachment_metadata( $post->ID );
1654
+ if($attach_meta!=false)
1655
+ {
1656
+ foreach ($attach_meta['sizes'] as $key=>$value)
1657
+ {
1658
+ $data=image_get_intermediate_size($post->ID,$key);
1659
+ $data['path']=ltrim($data['path'], './');
1660
+ if(file_exists($dir.DIRECTORY_SEPARATOR.$data['path']))
1661
+ {
1662
+ $files[]=$dir.DIRECTORY_SEPARATOR.$data['path'];
1663
+ }
1664
+ }
1665
+ }
1666
+ }
1667
+ }*/
1668
+ /*
1669
+ else if($meta->meta_key=='_wp_attachment_metadata')
1670
+ {
1671
+ $meta_data=$meta->meta_value;
1672
+ $meta_data = @unserialize($meta_data);
1673
+ if($meta_data!==false)
1674
+ {
1675
+ if(is_array($meta_data))
1676
+ {
1677
+ if(isset($meta_data['sizes']))
1678
+ {
1679
+ foreach ($meta_data['sizes'] as $key=>$value)
1680
+ {
1681
+ $name=$dir.DIRECTORY_SEPARATOR.$value['file'];
1682
+ if(file_exists($name))
1683
+ {
1684
+ $files[]=$name;
1685
+ file_put_contents($test_path.'file_found.txt',$name.PHP_EOL,FILE_APPEND);
1686
+ }
1687
+ else
1688
+ {
1689
+ $name=$dir.$subdir.DIRECTORY_SEPARATOR.$value['file'];
1690
+ if(file_exists($name))
1691
+ {
1692
+ $files[]=$name;
1693
+ file_put_contents($test_path.'file_found.txt',$name.PHP_EOL,FILE_APPEND);
1694
+ }
1695
+ else
1696
+ {
1697
+ $data=image_get_intermediate_size($post->ID,$key);
1698
+ $data['path']=ltrim($data['path'], './');
1699
+ if(file_exists($dir.DIRECTORY_SEPARATOR.$data['path']))
1700
+ {
1701
+ $files[]=$dir.DIRECTORY_SEPARATOR.$data['path'];
1702
+ file_put_contents($test_path.'file_found_data.txt',json_encode($data).PHP_EOL,FILE_APPEND);
1703
+ file_put_contents($test_path.'file_found.txt',$dir.DIRECTORY_SEPARATOR.$data['path'].PHP_EOL,FILE_APPEND);
1704
+ }
1705
+ else
1706
+ {
1707
+ file_put_contents($test_path.'file_not_found_data.txt',json_encode($data).PHP_EOL,FILE_APPEND);
1708
+ file_put_contents($test_path.'file_not_found.txt',$dir.DIRECTORY_SEPARATOR.$data['path'].PHP_EOL,FILE_APPEND);
1709
+ }
1710
+ }
1711
+ }
1712
+ }
1713
+ }
1714
+ }
1715
+ }
1716
+ }
1717
+ */
1718
+ if(in_array($meta->meta_key,$added_meta_key))
1719
+ continue;
1720
+ $added_meta_key[]=$meta->meta_key;
1721
+
1722
+ $post_meta_line.='
1723
+ <wp:postmeta>
1724
+ <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1725
+ <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1726
+ </wp:postmeta>';
1727
+ }
1728
+
1729
+ //if(empty($files))
1730
+ // return $files;
1731
+ //unset($files);
1732
+
1733
+ $this->write_post_header_to_file($file,$post);
1734
+
1735
+ file_put_contents($file,$post_meta_line,FILE_APPEND);
1736
+
1737
+ $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
1738
+ $comments = array_map( 'get_comment', $_comments );
1739
+ $line='';
1740
+ foreach ( $comments as $c )
1741
+ {
1742
+ $line.='
1743
+ <wp:comment>
1744
+ <wp:comment_id>'.intval( $c->comment_ID ).'</wp:comment_id>
1745
+ <wp:comment_author>'.$this->wxr_cdata( $c->comment_author ).'</wp:comment_author>
1746
+ <wp:comment_author_email>'.$this->wxr_cdata( $c->comment_author_email ).'</wp:comment_author_email>
1747
+ <wp:comment_author_url>'.esc_url_raw( $c->comment_author_url ).'</wp:comment_author_url>
1748
+ <wp:comment_author_IP>'.$this->wxr_cdata( $c->comment_author_IP ).'</wp:comment_author_IP>
1749
+ <wp:comment_date>'.$this->wxr_cdata( $c->comment_date ).'</wp:comment_date>
1750
+ <wp:comment_date_gmt>'.$this->wxr_cdata( $c->comment_date_gmt ).'</wp:comment_date_gmt>
1751
+ <wp:comment_content>'.$this->wxr_cdata( $c->comment_content ).'</wp:comment_content>
1752
+ <wp:comment_approved>'.$this->wxr_cdata( $c->comment_approved ).'</wp:comment_approved>
1753
+ <wp:comment_type>'.$this->wxr_cdata( $c->comment_type ).'</wp:comment_type>
1754
+ <wp:comment_parent>'.intval( $c->comment_parent ).'</wp:comment_parent>
1755
+ <wp:comment_user_id>'.intval( $c->user_id ).'</wp:comment_user_id>';
1756
+ $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
1757
+ foreach ( $c_meta as $meta )
1758
+ {
1759
+ if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) )
1760
+ {
1761
+ continue;
1762
+ }
1763
+ $line.='
1764
+ <wp:commentmeta>
1765
+ <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1766
+ <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1767
+ </wp:commentmeta>';
1768
+ }
1769
+ $line.='
1770
+ </wp:comment>';
1771
+ }
1772
+ file_put_contents($file,$line,FILE_APPEND);
1773
+ $line='
1774
+ </item>';
1775
+ file_put_contents($file,$line,FILE_APPEND);
1776
+ }
1777
+
1778
+ public function write_post_to_file($file,$post)
1779
+ {
1780
+ global $wpdb;
1781
+
1782
+ setup_postdata( $post );
1783
+
1784
+ $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
1785
+ $post_meta_line='';
1786
+
1787
+ $added_meta_key=array();
1788
+ foreach ( $postmeta as $meta )
1789
+ {
1790
+ //if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
1791
+ // continue;
1792
+ //}
1793
+ if(in_array($meta->meta_key,$added_meta_key))
1794
+ continue;
1795
+ $added_meta_key[]=$meta->meta_key;
1796
+ $post_meta_line.='
1797
+ <wp:postmeta>
1798
+ <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1799
+ <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1800
+ </wp:postmeta>';
1801
+ }
1802
+
1803
+ $this->write_post_header_to_file($file,$post);
1804
+
1805
+ file_put_contents($file,$post_meta_line,FILE_APPEND);
1806
+
1807
+ $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
1808
+ $comments = array_map( 'get_comment', $_comments );
1809
+ $line='';
1810
+ foreach ( $comments as $c )
1811
+ {
1812
+ $line.='
1813
+ <wp:comment>
1814
+ <wp:comment_id>'.intval( $c->comment_ID ).'</wp:comment_id>
1815
+ <wp:comment_author>'.$this->wxr_cdata( $c->comment_author ).'</wp:comment_author>
1816
+ <wp:comment_author_email>'.$this->wxr_cdata( $c->comment_author_email ).'</wp:comment_author_email>
1817
+ <wp:comment_author_url>'.esc_url_raw( $c->comment_author_url ).'</wp:comment_author_url>
1818
+ <wp:comment_author_IP>'.$this->wxr_cdata( $c->comment_author_IP ).'</wp:comment_author_IP>
1819
+ <wp:comment_date>'.$this->wxr_cdata( $c->comment_date ).'</wp:comment_date>
1820
+ <wp:comment_date_gmt>'.$this->wxr_cdata( $c->comment_date_gmt ).'</wp:comment_date_gmt>
1821
+ <wp:comment_content>'.$this->wxr_cdata( $c->comment_content ).'</wp:comment_content>
1822
+ <wp:comment_approved>'.$this->wxr_cdata( $c->comment_approved ).'</wp:comment_approved>
1823
+ <wp:comment_type>'.$this->wxr_cdata( $c->comment_type ).'</wp:comment_type>
1824
+ <wp:comment_parent>'.intval( $c->comment_parent ).'</wp:comment_parent>
1825
+ <wp:comment_user_id>'.intval( $c->user_id ).'</wp:comment_user_id>';
1826
+ $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
1827
+ foreach ( $c_meta as $meta )
1828
+ {
1829
+ if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) )
1830
+ {
1831
+ continue;
1832
+ }
1833
+ $line.='
1834
+ <wp:commentmeta>
1835
+ <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1836
+ <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1837
+ </wp:commentmeta>';
1838
+ }
1839
+ $line.='
1840
+ </wp:comment>';
1841
+ }
1842
+ file_put_contents($file,$line,FILE_APPEND);
1843
+ $line='
1844
+ </item>';
1845
+ file_put_contents($file,$line,FILE_APPEND);
1846
+ return true;
1847
+ }
1848
+
1849
+ public function write_cat_to_file($file,$post_ids)
1850
+ {
1851
+ $cats = $tags = $terms = array();
1852
+
1853
+ $categories = (array) get_categories( array( 'object_ids' => $post_ids ) );
1854
+ $tags = (array) get_tags( array( 'object_ids' => $post_ids ) );
1855
+
1856
+ $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
1857
+ $custom_terms = (array) get_terms( $custom_taxonomies,array( 'object_ids' => $post_ids ) );
1858
+
1859
+ // Put categories in order with no child going before its parent.
1860
+ while ( $cat = array_shift( $categories ) ) {
1861
+ if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {
1862
+ $cats[ $cat->term_id ] = $cat;
1863
+ } else {
1864
+ $categories[] = $cat;
1865
+ }
1866
+ }
1867
+
1868
+ // Put terms in order with no child going before its parent.
1869
+ while ( $t = array_shift( $custom_terms ) ) {
1870
+ if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {
1871
+ $terms[ $t->term_id ] = $t;
1872
+ } else {
1873
+ $custom_terms[] = $t;
1874
+ }
1875
+ }
1876
+
1877
+ unset( $categories, $custom_taxonomies, $custom_terms );
1878
+
1879
+ $line='';
1880
+ foreach ($cats as $c)
1881
+ {
1882
+ $line.='<wp:category>
1883
+ <wp:term_id>'.intval( $c->term_id ).'</wp:term_id>
1884
+ <wp:category_nicename>'.$this->wxr_cdata( $c->slug ).'</wp:category_nicename>
1885
+ <wp:category_parent>'.$this->wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ).'</wp:category_parent>
1886
+ '.$this->wxr_cat_name( $c ).'
1887
+ '.$this->wxr_category_description( $c ).'
1888
+ '.$this->wxr_term_meta( $c ).'
1889
+ </wp:category>';
1890
+ }
1891
+ file_put_contents($file,$line,FILE_APPEND);
1892
+ $line='';
1893
+ foreach ( $tags as $t )
1894
+ {
1895
+ $line.='<wp:tag>
1896
+ <wp:term_id>'.intval( $t->term_id ).'</wp:term_id>
1897
+ <wp:tag_slug>'.$this->wxr_cdata( $t->slug ).'</wp:tag_slug>
1898
+ '.$this->wxr_tag_name( $t ).'
1899
+ '.$this->wxr_tag_description( $t ).'
1900
+ '.$this->wxr_term_meta( $t ).'
1901
+ </wp:tag>';
1902
+ }
1903
+ file_put_contents($file,$line,FILE_APPEND);
1904
+
1905
+ $line='';
1906
+
1907
+ foreach ( $terms as $t)
1908
+ {
1909
+ $line.='<wp:term>
1910
+ <wp:term_id>'.$this->wxr_cdata( $t->term_id ).'</wp:term_id>
1911
+ <wp:term_taxonomy>'.$this->wxr_cdata( $t->taxonomy ).'</wp:term_taxonomy>
1912
+ <wp:term_slug>'.$this->wxr_cdata( $t->slug ).'</wp:term_slug>
1913
+ <wp:term_parent>'.$this->wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ).'</wp:term_parent>
1914
+ '.$this->wxr_term_name( $t ).'
1915
+ '.$this->wxr_term_description( $t ).'
1916
+ '.$this->wxr_term_meta( $t ).'
1917
+ </wp:term>';
1918
+ }
1919
+ }
1920
+
1921
+ private function wxr_cat_name( $category )
1922
+ {
1923
+ if ( empty( $category->name ) )
1924
+ {
1925
+ return '';
1926
+ }
1927
+
1928
+ return '<wp:cat_name>' . $this->wxr_cdata( $category->name ) . "</wp:cat_name>";
1929
+ }
1930
+
1931
+ private function wxr_category_description( $category ) {
1932
+ if ( empty( $category->description ) ) {
1933
+ return '<wp:category_description></wp:category_description>\n';
1934
+ }
1935
+
1936
+ return '<wp:category_description>' . $this->wxr_cdata( $category->description ) . "</wp:category_description>";
1937
+ }
1938
+
1939
+ private function wxr_tag_name( $tag ) {
1940
+ if ( empty( $tag->name ) ) {
1941
+ return '';
1942
+ }
1943
+
1944
+ return '<wp:tag_name>' . $this->wxr_cdata( $tag->name ) . "</wp:tag_name>";
1945
+ }
1946
+
1947
+ private function wxr_tag_description( $tag ) {
1948
+ if ( empty( $tag->description ) ) {
1949
+ return '';
1950
+ }
1951
+
1952
+ return '<wp:tag_description>' . $this->wxr_cdata( $tag->description ) . "</wp:tag_description>";
1953
+ }
1954
+
1955
+ private function wxr_term_name( $term ) {
1956
+ if ( empty( $term->name ) ) {
1957
+ return '';
1958
+ }
1959
+
1960
+ return '<wp:term_name>' . $this->wxr_cdata( $term->name ) . "</wp:term_name>";
1961
+ }
1962
+
1963
+ private function wxr_term_description( $term ) {
1964
+ if ( empty( $term->description ) ) {
1965
+ return '';
1966
+ }
1967
+
1968
+ return "\t\t<wp:term_description>" . $this->wxr_cdata( $term->description ) . "</wp:term_description>";
1969
+ }
1970
+
1971
+ private function wxr_term_meta( $term ) {
1972
+ global $wpdb;
1973
+
1974
+ $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
1975
+
1976
+ $line='';
1977
+ foreach ( $termmeta as $meta )
1978
+ {
1979
+ /**
1980
+ * Filters whether to selectively skip term meta used for WXR exports.
1981
+ *
1982
+ * Returning a truthy value to the filter will skip the current meta
1983
+ * object from being exported.
1984
+ *
1985
+ * @since 4.6.0
1986
+ *
1987
+ * @param bool $skip Whether to skip the current piece of term meta. Default false.
1988
+ * @param string $meta_key Current meta key.
1989
+ * @param object $meta Current meta object.
1990
+ */
1991
+ if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) )
1992
+ {
1993
+ $line.="\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>".$this->wxr_cdata( $meta->meta_key )."</wp:meta_key>\n\t\t\t<wp:meta_value>".$this->wxr_cdata( $meta->meta_value )."</wp:meta_value>\n\t\t</wp:termmeta>\n";
1994
+ }
1995
+ }
1996
+ return $line;
1997
+ }
1998
+
1999
+ private function wxr_cdata( $str )
2000
+ {
2001
+ if ( ! seems_utf8( $str ) ) {
2002
+ $str = utf8_encode( $str );
2003
+ }
2004
+ // $str = ent2ncr(esc_html($str));
2005
+ $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
2006
+
2007
+ return $str;
2008
+ }
2009
+
2010
+ private function wxr_site_url() {
2011
+ if ( is_multisite() ) {
2012
+ // Multisite: the base URL.
2013
+ return network_home_url();
2014
+ } else {
2015
+ // WordPress (single site): the blog URL.
2016
+ return get_bloginfo_rss( 'url' );
2017
+ }
2018
+ }
2019
+
2020
+ private function wxr_authors_list( array $post_ids = null )
2021
+ {
2022
+ global $wpdb;
2023
+
2024
+ if ( ! empty( $post_ids ) ) {
2025
+ $post_ids = array_map( 'absint', $post_ids );
2026
+ $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
2027
+ } else {
2028
+ $and = '';
2029
+ }
2030
+
2031
+ $authors = array();
2032
+ $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
2033
+ foreach ( (array) $results as $result )
2034
+ {
2035
+ $authors[] = get_userdata( $result->post_author );
2036
+ }
2037
+
2038
+ $authors = array_filter( $authors );
2039
+
2040
+ $line='';
2041
+ foreach ( $authors as $author )
2042
+ {
2043
+ $line.= "\t<wp:author>";
2044
+ $line.= '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
2045
+ $line.= '<wp:author_login>' . $this->wxr_cdata( $author->user_login ) . '</wp:author_login>';
2046
+ $line.= '<wp:author_email>' . $this->wxr_cdata( $author->user_email ) . '</wp:author_email>';
2047
+ $line.= '<wp:author_display_name>' . $this->wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
2048
+ $line.= '<wp:author_first_name>' . $this->wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
2049
+ $line.= '<wp:author_last_name>' . $this->wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
2050
+ $line.= "</wp:author>\n";
2051
+ }
2052
+ return $line;
2053
+ }
2054
+
2055
+ private function wxr_post_taxonomy($post)
2056
+ {
2057
+ $taxonomies = get_object_taxonomies( $post->post_type );
2058
+ if ( empty( $taxonomies ) ) {
2059
+ return;
2060
+ }
2061
+ $terms = wp_get_object_terms( $post->ID, $taxonomies );
2062
+ $line='';
2063
+ foreach ( (array) $terms as $term )
2064
+ {
2065
+ $line.= "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . $this->wxr_cdata( $term->name ) . "</category>\n";
2066
+ }
2067
+ return $line;
2068
+ }
2069
+ }
2070
+
includes/class-wpvivid-importer.php ADDED
@@ -0,0 +1,2454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WPvivid addon: yes
4
+ * Addon Name: wpvivid-backup-pro-all-in-one
5
+ * Description: Pro
6
+ * Version: 1.9.1
7
+ * Need_init: yes
8
+ * Interface Name: WPvivid_media_importer
9
+ */
10
+
11
+ if ( ! class_exists( 'WP_List_Table' ) )
12
+ {
13
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
14
+ }
15
+
16
+ class WPvivid_Export_List extends WP_List_Table
17
+ {
18
+ public $list;
19
+ public $page_num;
20
+ public $parent;
21
+
22
+ public function __construct( $args = array() )
23
+ {
24
+ global $wpdb;
25
+ parent::__construct(
26
+ array(
27
+ 'plural' => 'import',
28
+ 'screen' => 'import',
29
+ )
30
+ );
31
+ }
32
+
33
+ public function set_parent($parent)
34
+ {
35
+ $this->parent=$parent;
36
+ }
37
+
38
+ public function set_list($list, $page_num=1)
39
+ {
40
+ $this->list=$list;
41
+ $this->page_num=$page_num;
42
+ }
43
+
44
+ public function print_column_headers( $with_id = true )
45
+ {
46
+ list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
47
+
48
+ if (!empty($columns['cb'])) {
49
+ static $cb_counter = 1;
50
+ $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
51
+ . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
52
+ $cb_counter++;
53
+ }
54
+
55
+ foreach ($columns as $column_key => $column_display_name) {
56
+ $class = array('manage-column', "column-$column_key");
57
+
58
+ if (in_array($column_key, $hidden)) {
59
+ $class[] = 'hidden';
60
+ }
61
+
62
+ if ('cb' === $column_key) {
63
+ $class[] = 'check-column';
64
+ }
65
+
66
+ if ($column_key === $primary) {
67
+ $class[] = 'column-primary';
68
+ }
69
+
70
+ $tag = ('cb' === $column_key) ? 'td' : 'th';
71
+ $scope = ('th' === $tag) ? 'scope="col"' : '';
72
+ $id = $with_id ? "id='$column_key'" : '';
73
+
74
+ if (!empty($class)) {
75
+ $class = "class='" . join(' ', $class) . "'";
76
+ }
77
+
78
+ echo "<$tag $scope $id $class>$column_display_name</$tag>";
79
+ }
80
+ }
81
+
82
+ public function get_columns()
83
+ {
84
+ $posts_columns = array();
85
+
86
+ $posts_columns['file_name'] = __( 'File Name', 'column name' );
87
+ $posts_columns['export_type'] = __( 'Post Types' );
88
+ $posts_columns['posts_count'] = __( 'Count' );
89
+ $posts_columns['media_size'] = __( 'Media Files Size' );
90
+ $posts_columns['import'] = __( 'Action' );
91
+
92
+ return $posts_columns;
93
+ }
94
+
95
+ protected function display_tablenav( $which ) {
96
+ $total_items =sizeof($this->list);
97
+ if($total_items > 10) {
98
+ if ('top' === $which) {
99
+ wp_nonce_field('bulk-' . $this->_args['plural']);
100
+ }
101
+ ?>
102
+ <div class="tablenav <?php echo esc_attr($which); ?>">
103
+
104
+ <?php if ($this->has_items()) : ?>
105
+ <div class="alignleft actions bulkactions">
106
+ <?php $this->bulk_actions($which); ?>
107
+ </div>
108
+ <?php
109
+ endif;
110
+ $this->extra_tablenav($which);
111
+ $this->pagination($which);
112
+ ?>
113
+
114
+ <br class="clear"/>
115
+ </div>
116
+ <?php
117
+ }
118
+ }
119
+
120
+ function prepare_items()
121
+ {
122
+ $columns = $this->get_columns();
123
+ $hidden = array();
124
+ $sortable = array();
125
+ $this->_column_headers = array($columns, $hidden, $sortable);
126
+
127
+ $total_items =sizeof($this->list);
128
+ if($total_items > 10) {
129
+ $this->set_pagination_args(
130
+ array(
131
+ 'total_items' => $total_items,
132
+ 'per_page' => 10,
133
+ )
134
+ );
135
+ }
136
+ }
137
+
138
+ public function has_items()
139
+ {
140
+ return !empty($this->list);
141
+ }
142
+
143
+ public function column_cb( $item )
144
+ {
145
+ ?>
146
+ <input id="cb-select-<?php echo $item['id']; ?>" type="checkbox" name="export[]" value="<?php echo $item['id']; ?>"/>
147
+ <?php
148
+ }
149
+
150
+ public function _column_file_name( $item, $classes, $data, $primary )
151
+ {
152
+ echo '<td>
153
+ <div>
154
+ '.$item['file_name'].'
155
+ </div>
156
+ <div style="padding-bottom: 5px;">
157
+ <div class="backuptime">Data Modified: ' . __(date('M d, Y H:i', $item['time']), 'wpvivid') . '</div>
158
+ </div>
159
+ </td>';
160
+ }
161
+
162
+ public function _column_export_type( $item, $classes, $data, $primary )
163
+ {
164
+ $export = $item['export_type'] === 'page' ? 'Page' : 'Post';
165
+ echo '<td style="color: #000;">
166
+ <div>
167
+ <div style="float:left;padding:10px 10px 10px 0;">'.__('Type: ').$export.'</div>
168
+ </div>
169
+ </td>';
170
+ }
171
+
172
+ public function _column_posts_count( $item, $classes, $data, $primary )
173
+ {
174
+ echo '<td style="min-width:100px;">
175
+ <div style="float:left;padding:10px 10px 10px 0;">
176
+ '.$item['posts_count'].'
177
+ </div>
178
+ </td>';
179
+ }
180
+
181
+ public function _column_media_size( $item, $classes, $data, $primary )
182
+ {
183
+ echo '<td style="min-width:100px;">
184
+ <div style="float:left;padding:10px 10px 10px 0;">
185
+ '.$item['media_size'].'
186
+ </div>
187
+ </td>';
188
+ }
189
+
190
+ public function _column_import( $item )
191
+ {
192
+ echo '<td style="min-width:100px;">
193
+ <div class="export-list-import" style="cursor:pointer;padding:10px 0 10px 0;">
194
+ <img src="' . esc_url(WPVIVID_PLUGIN_URL . '/admin/partials/images/Restore.png') . '" style="vertical-align:middle;" /><span>' . __('Import', 'wpvivid') . '</span>
195
+ </div>
196
+ </td>';
197
+ }
198
+
199
+ public function display_rows()
200
+ {
201
+ $this->_display_rows( $this->list );
202
+ }
203
+
204
+ private function _display_rows($lists)
205
+ {
206
+ $page_lists=$lists;
207
+ $page=$this->get_pagenum();
208
+ $count=0;
209
+ while ( $count<$page )
210
+ {
211
+ $page_lists = array_splice( $lists, 0, 10);
212
+ $count++;
213
+ }
214
+ foreach ( $page_lists as $key=>$item )
215
+ {
216
+ $item['id']=$key;
217
+ $this->single_row($item);
218
+ }
219
+ ?>
220
+ <?php
221
+ }
222
+
223
+ public function get_pagenum()
224
+ {
225
+ if($this->page_num=='first')
226
+ {
227
+ $this->page_num=1;
228
+ }
229
+ else if($this->page_num=='last')
230
+ {
231
+ $this->page_num=$this->_pagination_args['total_pages'];
232
+ }
233
+ $pagenum = $this->page_num ? $this->page_num : 0;
234
+
235
+ if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
236
+ {
237
+ $pagenum = $this->_pagination_args['total_pages'];
238
+ }
239
+
240
+ return max( 1, $pagenum );
241
+ }
242
+
243
+ public function single_row($item)
244
+ {
245
+ ?>
246
+ <tr id="<?php echo $item['id'] ?>" class="wpvivid-export-list-item">
247
+ <?php $this->single_row_columns( $item ); ?>
248
+ </tr>
249
+ <?php
250
+ }
251
+
252
+ protected function pagination( $which ) {
253
+ if ( empty( $this->_pagination_args ) ) {
254
+ return;
255
+ }
256
+
257
+ $total_items = $this->_pagination_args['total_items'];
258
+ $total_pages = $this->_pagination_args['total_pages'];
259
+ $infinite_scroll = false;
260
+ if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
261
+ $infinite_scroll = $this->_pagination_args['infinite_scroll'];
262
+ }
263
+
264
+ if ( 'top' === $which && $total_pages > 1 ) {
265
+ $this->screen->render_screen_reader_content( 'heading_pagination' );
266
+ }
267
+
268
+ $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
269
+
270
+ $current = $this->get_pagenum();
271
+ $removable_query_args = wp_removable_query_args();
272
+
273
+ $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
274
+
275
+ $current_url = remove_query_arg( $removable_query_args, $current_url );
276
+
277
+ $page_links = array();
278
+
279
+ $total_pages_before = '<span class="paging-input">';
280
+ $total_pages_after = '</span></span>';
281
+
282
+ $disable_first = $disable_last = $disable_prev = $disable_next = false;
283
+
284
+ if ( $current == 1 ) {
285
+ $disable_first = true;
286
+ $disable_prev = true;
287
+ }
288
+ if ( $current == 2 ) {
289
+ $disable_first = true;
290
+ }
291
+ if ( $current == $total_pages ) {
292
+ $disable_last = true;
293
+ $disable_next = true;
294
+ }
295
+ if ( $current == $total_pages - 1 ) {
296
+ $disable_last = true;
297
+ }
298
+
299
+ if ( $disable_first ) {
300
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
301
+ } else {
302
+ $page_links[] = sprintf(
303
+ "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
304
+ __( 'First page' ),
305
+ '&laquo;'
306
+ );
307
+ }
308
+
309
+ if ( $disable_prev ) {
310
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
311
+ } else {
312
+ $page_links[] = sprintf(
313
+ "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
314
+ $current,
315
+ __( 'Previous page' ),
316
+ '&lsaquo;'
317
+ );
318
+ }
319
+
320
+ if ( 'bottom' === $which ) {
321
+ $html_current_page = $current;
322
+ $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
323
+ } else {
324
+ $html_current_page = sprintf(
325
+ "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
326
+ '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
327
+ $current,
328
+ strlen( $total_pages )
329
+ );
330
+ }
331
+ $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
332
+ $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
333
+
334
+ if ( $disable_next ) {
335
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
336
+ } else {
337
+ $page_links[] = sprintf(
338
+ "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
339
+ $current,
340
+ __( 'Next page' ),
341
+ '&rsaquo;'
342
+ );
343
+ }
344
+
345
+ if ( $disable_last ) {
346
+ $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
347
+ } else {
348
+ $page_links[] = sprintf(
349
+ "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
350
+ __( 'Last page' ),
351
+ '&raquo;'
352
+ );
353
+ }
354
+
355
+ $pagination_links_class = 'pagination-links';
356
+ if ( ! empty( $infinite_scroll ) ) {
357
+ $pagination_links_class .= ' hide-if-js';
358
+ }
359
+ $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
360
+
361
+ if ( $total_pages ) {
362
+ $page_class = $total_pages < 2 ? ' one-page' : '';
363
+ } else {
364
+ $page_class = ' no-pages';
365
+ }
366
+ $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
367
+
368
+ echo $this->_pagination;
369
+ }
370
+ }
371
+
372
+ class WPvivid_Impoter_taskmanager
373
+ {
374
+ public static function new_task($task_id,$files,$options)
375
+ {
376
+ $task['id']=$task_id;
377
+ $task['status']['start_time']=time();
378
+ $task['status']['run_time']=time();
379
+ $task['status']['timeout']=time();
380
+ $task['status']['str']='ready';
381
+ $task['status']['resume_count']=0;
382
+ $task['options']=$options;
383
+ $task['data']['files']=$files;
384
+ self::update_task($task_id,$task);
385
+ }
386
+
387
+ public static function get_files($task_id)
388
+ {
389
+ $task=self::get_task($task_id);
390
+ return $task['data']['files'];
391
+ }
392
+
393
+ public static function get_options($task_id)
394
+ {
395
+ $task=self::get_task($task_id);
396
+ return $task['options'];
397
+ }
398
+
399
+ public static function get_tasks(){
400
+ $default = array();
401
+ return $options = get_option('wpvivid_importer_task_list', $default);
402
+ }
403
+
404
+ public static function get_task($task_id)
405
+ {
406
+ $default = array();
407
+ $tasks = get_option('wpvivid_importer_task_list', $default);
408
+ if(array_key_exists ($task_id, $tasks)) {
409
+ return $tasks[$task_id];
410
+ }
411
+ else {
412
+ return false;
413
+ }
414
+ }
415
+
416
+ public static function update_task($task_id, $task)
417
+ {
418
+ $default = array();
419
+ $options = get_option('wpvivid_importer_task_list', $default);
420
+ $options[$task_id]=$task;
421
+ update_option('wpvivid_importer_task_list', $options);
422
+ }
423
+
424
+ public static function delete_task($task_id){
425
+ $options = get_option('wpvivid_importer_task_list', array());
426
+ unset($options[$task_id]);
427
+ update_option('wpvivid_importer_task_list', $options);
428
+ }
429
+
430
+ public static function get_import_task_status($task_id){
431
+ $tasks=self::get_tasks();
432
+ if(array_key_exists ($task_id, $tasks)) {
433
+ $task = $tasks[$task_id];
434
+ return $task['status']['str'];
435
+ }
436
+ else {
437
+ return false;
438
+ }
439
+ }
440
+
441
+ public static function update_import_task_status($task_id, $status, $reset_start_time=false, $reset_timeout=false, $resume_count=false, $error=''){
442
+ $tasks=self::get_tasks();
443
+ if(array_key_exists ($task_id, $tasks))
444
+ {
445
+ $task = $tasks[$task_id];
446
+ $task['status']['run_time']=time();
447
+ if($reset_start_time)
448
+ $task['status']['start_time']=time();
449
+ if(!empty($status)) {
450
+ $task['status']['str']=$status;
451
+ }
452
+ if($reset_timeout)
453
+ $task['status']['timeout']=time();
454
+ if($resume_count!==false) {
455
+ $task['status']['resume_count']=$resume_count;
456
+ }
457
+
458
+ if(!empty($error)) {
459
+ $task['status']['error']=$error;
460
+ }
461
+ self::update_task($task_id, $task);
462
+ return $task;
463
+ }
464
+ else {
465
+ return false;
466
+ }
467
+ }
468
+ }
469
+
470
+ class WPvivid_import_data
471
+ {
472
+ public $import_log = false;
473
+ public $import_log_file;
474
+
475
+ public function __construct()
476
+ {
477
+ $this->import_log_file = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.'wpvivid_import_log.txt';
478
+ }
479
+
480
+ public function wpvivid_create_import_log()
481
+ {
482
+ $this->import_log=new WPvivid_Log();
483
+ $this->import_log->CreateLogFile($this->import_log_file, 'has_folder', 'import');
484
+ }
485
+
486
+ public function wpvivid_write_import_log($message, $type)
487
+ {
488
+ if($this->import_log===false)
489
+ {
490
+ $this->import_log=new WPvivid_Log();
491
+ $this->import_log->OpenLogFile($this->import_log_file,'has_folder');
492
+ }
493
+
494
+ clearstatcache();
495
+ if(filesize($this->import_log_file)>4*1024*1024)
496
+ {
497
+ $this->import_log->CloseFile();
498
+ unlink($this->import_log_file);
499
+ $this->import_log=null;
500
+ $this->import_log=new WPvivid_Log();
501
+ $this->import_log->OpenLogFile($this->import_log_file,'has_folder');
502
+ }
503
+ $this->import_log->WriteLog($message, $type);
504
+ }
505
+
506
+ public function get_log_content()
507
+ {
508
+ $buffer = '';
509
+ if(file_exists($this->import_log_file)){
510
+ $file = fopen($this->import_log_file, 'r');
511
+
512
+ if (!$file) {
513
+ return '';
514
+ }
515
+
516
+ while (!feof($file)) {
517
+ $buffer .= fread($file, 1024);
518
+ }
519
+ fclose($file);
520
+ }
521
+ return $buffer;
522
+ }
523
+ }
524
+
525
+
526
+ global $xml_file_name;
527
+ class WPvivid_media_importer
528
+ {
529
+ var $max_wxr_version = 1.2; // max. supported WXR version
530
+
531
+ var $id; // WXR attachment ID
532
+ var $default_user;
533
+ // information to import from WXR file
534
+ var $version;
535
+ var $authors = array();
536
+ var $posts = array();
537
+ var $terms = array();
538
+ var $categories = array();
539
+ var $tags = array();
540
+ var $base_url = '';
541
+ var $new_site_url='';
542
+
543
+ // mappings from old information to new
544
+ var $processed_authors = array();
545
+ var $author_mapping = array();
546
+ var $processed_terms = array();
547
+ var $processed_posts = array();
548
+ var $post_orphans = array();
549
+ var $processed_menu_items = array();
550
+ var $menu_item_orphans = array();
551
+ var $missing_menu_items = array();
552
+
553
+ var $fetch_attachments = false;
554
+ var $url_remap = array();
555
+ var $featured_images = array();
556
+
557
+ public $import_log;
558
+
559
+ public function __construct()
560
+ {
561
+ }
562
+
563
+ public function import($id)
564
+ {
565
+ if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
566
+
567
+ $this->import_log = new WPvivid_import_data();
568
+
569
+ set_time_limit(900);
570
+
571
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
572
+
573
+ $files=WPvivid_Impoter_taskmanager::get_files($id);
574
+
575
+ define(PCLZIP_TEMPORARY_DIR,dirname($path));
576
+
577
+ global $xml_file_name;
578
+ foreach ($files as $file)
579
+ {
580
+ $file_path=$path.DIRECTORY_SEPARATOR.$file;
581
+ $this->import_log->wpvivid_write_import_log('Prepare to retrieve file info, file name: '.$file_path, 'notice');
582
+ $archive = new PclZip($file_path);
583
+ $ret=$this->get_file_info($file_path);
584
+ if($ret['result']=='failed')
585
+ {
586
+ $this->import_log->wpvivid_write_import_log('Failed to retrieve file info, error: '.$ret['error'], 'notice');
587
+ WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $ret['error']);
588
+ return $ret;
589
+ }
590
+ $this->import_log->wpvivid_write_import_log('Retrieving file info is completed.', 'notice');
591
+ $xml_file=$ret['json_data']['xml_file'];
592
+ $xml_file_name = $ret['json_data']['xml_file'];
593
+ $this->import_log->wpvivid_write_import_log('Prepare to extract, file name: '.$xml_file, 'notice');
594
+ $zip_ret = $archive->extract(PCLZIP_OPT_BY_NAME,basename($xml_file),PCLZIP_OPT_PATH,$path,PCLZIP_OPT_REPLACE_NEWER,PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
595
+ if(!$zip_ret)
596
+ {
597
+ $this->import_log->wpvivid_write_import_log('Failed to extract, error: '.$archive->errorInfo(true), 'notice');
598
+ WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $archive->errorInfo(true));
599
+ $ret['result']='failed';
600
+ $ret['error'] = $archive->errorInfo(true);
601
+ return $ret;
602
+ }
603
+ $this->import_log->wpvivid_write_import_log('The file extracton is completed, file name: '.$xml_file, 'notice');
604
+ $this->import_log->wpvivid_write_import_log('Prepare to extract, file name: '.$file_path, 'notice');
605
+ $zip_ret = $archive->extract(PCLZIP_OPT_PATH, WP_CONTENT_DIR, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_CB_PRE_EXTRACT, 'wpvivid_function_pre_extract_import_callback', PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
606
+ if(!$zip_ret)
607
+ {
608
+ $this->import_log->wpvivid_write_import_log('Failed to extract, error: '.$archive->errorInfo(true), 'notice');
609
+ WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $archive->errorInfo(true));
610
+ $ret['result']='failed';
611
+ $ret['error'] = $archive->errorInfo(true);
612
+ return $ret;
613
+ }
614
+ $this->import_log->wpvivid_write_import_log('The file extracton is completed, file name: '.$file_path, 'notice');
615
+
616
+ set_time_limit(900);
617
+ $file_path=$path.DIRECTORY_SEPARATOR.$xml_file;
618
+ $this->import_log->wpvivid_write_import_log('Prepare import, file name: '.$file_path, 'notice');
619
+ $ret=$this->_import($file_path, WPvivid_Impoter_taskmanager::get_options($id));
620
+ if($ret['result']=='failed')
621
+ {
622
+ $this->import_log->wpvivid_write_import_log('Failed to import, error: '.$ret['error'], 'notice');
623
+ WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $ret['error']);
624
+ return $ret;
625
+ }
626
+ $this->import_log->wpvivid_write_import_log('Import task is completed, file name: '.$file_path, 'notice');
627
+ @unlink($file_path);
628
+ }
629
+
630
+ $this->replace_domain();
631
+
632
+ $ret['result']='success';
633
+ $ret['files']=$files;
634
+ $this->import_log->wpvivid_write_import_log('Import task succeeded.', 'notice');
635
+ WPvivid_Impoter_taskmanager::update_import_task_status($id, 'completed', false);
636
+ return $ret;
637
+ }
638
+
639
+ public function get_file_info($file_name)
640
+ {
641
+ $zip=new WPvivid_ZipClass();
642
+ $ret=$zip->get_json_data($file_name, 'export');
643
+ if($ret['result'] === WPVIVID_SUCCESS)
644
+ {
645
+ $json=$ret['json_data'];
646
+ $json = json_decode($json, 1);
647
+ if (is_null($json))
648
+ {
649
+ return array('result'=>WPVIVID_FAILED,'error'=>'Failed to decode json');
650
+ } else {
651
+ return array('result'=>WPVIVID_SUCCESS,'json_data'=>$json);
652
+ }
653
+ }
654
+ else {
655
+ return $ret;
656
+ }
657
+ }
658
+
659
+ public function _import($file,$options)
660
+ {
661
+ if(isset($options['user']))
662
+ {
663
+ $this->default_user=$options['user'];
664
+ }
665
+ else
666
+ {
667
+ $this->default_user=get_current_user_id();
668
+ }
669
+
670
+ $ret=$this->import_start( $file );
671
+
672
+ if($ret['result']=='failed')
673
+ {
674
+ return $ret;
675
+ }
676
+
677
+ $ret=$this->get_author_mapping();
678
+
679
+ if($ret['result']=='failed')
680
+ {
681
+ return $ret;
682
+ }
683
+
684
+ wp_suspend_cache_invalidation( true );
685
+ $ret=$this->process_categories();
686
+ if($ret['result']=='failed')
687
+ {
688
+ return $ret;
689
+ }
690
+ $ret=$this->process_tags();
691
+ if($ret['result']=='failed')
692
+ {
693
+ return $ret;
694
+ }
695
+ $ret=$this->process_terms();
696
+ if($ret['result']=='failed')
697
+ {
698
+ return $ret;
699
+ }
700
+ $ret=$this->process_posts_ex();
701
+ if($ret['result']=='failed')
702
+ {
703
+ return $ret;
704
+ }
705
+ wp_suspend_cache_invalidation( false );
706
+ $ret=$this->import_end();
707
+
708
+ return $ret;
709
+ }
710
+
711
+ private function import_start( $file )
712
+ {
713
+ $this->import_log->wpvivid_write_import_log('Analyze the imported file, file name: '.$file, 'notice');
714
+ $import_data = $this->parse( $file );
715
+ if( is_wp_error( $import_data ) )
716
+ {
717
+ $this->import_log->wpvivid_write_import_log('Failed to analyze a file, file name: '.$file, 'notice');
718
+ $ret['result']='failed';
719
+ $ret['error']=$import_data->get_error_message();
720
+ return $ret;
721
+ }
722
+
723
+ $this->version = $import_data['version'];
724
+ $this->get_authors_from_import( $import_data );
725
+ $this->posts = $import_data['posts'];
726
+ $this->terms = $import_data['terms'];
727
+ $this->categories = $import_data['categories'];
728
+ $this->tags = $import_data['tags'];
729
+ $this->base_url = esc_url( $import_data['base_url'] );
730
+ $this->import_log->wpvivid_write_import_log('The file analysis is completed, file name: '.$file, 'notice');
731
+ $ret['result']='success';
732
+ return $ret;
733
+ }
734
+
735
+ private function get_author_mapping()
736
+ {
737
+ $ret['result']='success';
738
+
739
+ return $ret;
740
+
741
+ /*
742
+ $create_users = false;
743
+
744
+ foreach ( (array) $_POST['imported_authors'] as $i => $old_login )
745
+ {
746
+ // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
747
+ $santized_old_login = sanitize_user( $old_login, true );
748
+ $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
749
+
750
+ if ( ! empty( $_POST['user_map'][$i] ) )
751
+ {
752
+ $user = get_userdata( intval($_POST['user_map'][$i]) );
753
+ if ( isset( $user->ID ) ) {
754
+ if ( $old_id )
755
+ $this->processed_authors[$old_id] = $user->ID;
756
+ $this->author_mapping[$santized_old_login] = $user->ID;
757
+ }
758
+ } else if ( $create_users )
759
+ {
760
+ if ( ! empty($_POST['user_new'][$i]) )
761
+ {
762
+ $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
763
+ } else if ( $this->version != '1.0' )
764
+ {
765
+ $user_data = array(
766
+ 'user_login' => $old_login,
767
+ 'user_pass' => wp_generate_password(),
768
+ 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
769
+ 'display_name' => $this->authors[$old_login]['author_display_name'],
770
+ 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
771
+ 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
772
+ );
773
+ $user_id = wp_insert_user( $user_data );
774
+ }
775
+
776
+ if ( ! is_wp_error( $user_id ) )
777
+ {
778
+ if ( $old_id )
779
+ $this->processed_authors[$old_id] = $user_id;
780
+ $this->author_mapping[$santized_old_login] = $user_id;
781
+ } else {
782
+ printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
783
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
784
+ echo ' ' . $user_id->get_error_message();
785
+ echo '<br />';
786
+ }
787
+ }
788
+
789
+ // failsafe: if the user_id was invalid, default to the current user
790
+ if ( ! isset( $this->author_mapping[$santized_old_login] ) )
791
+ {
792
+ if ( $old_id )
793
+ $this->processed_authors[$old_id] = (int) get_current_user_id();
794
+ $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
795
+ }
796
+ }
797
+ */
798
+ }
799
+
800
+ private function process_categories()
801
+ {
802
+ $ret['result']='success';
803
+ $this->categories = apply_filters( 'wp_import_categories', $this->categories );
804
+ $this->import_log->wpvivid_write_import_log('Start importing categories.', 'notice');
805
+ if ( empty( $this->categories ) ) {
806
+ $this->import_log->wpvivid_write_import_log('Categories import is completed.', 'notice');
807
+ return $ret;
808
+ }
809
+
810
+ foreach ( $this->categories as $cat )
811
+ {
812
+ // if the category already exists leave it alone
813
+ $term_id = term_exists( $cat['category_nicename'], 'category' );
814
+ if ( $term_id )
815
+ {
816
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
817
+ if ( isset($cat['term_id']) )
818
+ $this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
819
+ continue;
820
+ }
821
+
822
+ $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
823
+ $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
824
+ $catarr = array(
825
+ 'category_nicename' => $cat['category_nicename'],
826
+ 'category_parent' => $category_parent,
827
+ 'cat_name' => $cat['cat_name'],
828
+ 'category_description' => $category_description
829
+ );
830
+ $catarr = wp_slash( $catarr );
831
+
832
+ $id = wp_insert_category( $catarr );
833
+ if ( ! is_wp_error( $id ) )
834
+ {
835
+ if ( isset($cat['term_id']) )
836
+ $this->processed_terms[intval($cat['term_id'])] = $id;
837
+ } else {
838
+
839
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
840
+ {
841
+ $this->import_log->wpvivid_write_import_log('Failed to import categories, error: '.$id->get_error_message(), 'notice');
842
+ $ret['result']='failed';
843
+ $ret['error']='Failed to import category '.$cat['category_nicename'].' '.$id->get_error_message();
844
+ return $ret;
845
+ }
846
+ continue;
847
+ }
848
+
849
+ $this->process_termmeta( $cat, $id['term_id'] );
850
+ }
851
+
852
+ unset( $this->categories );
853
+ $this->import_log->wpvivid_write_import_log('Categories import is completed.', 'notice');
854
+ return $ret;
855
+ }
856
+
857
+ private function process_termmeta( $term, $term_id )
858
+ {
859
+ if ( ! isset( $term['termmeta'] ) )
860
+ {
861
+ $term['termmeta'] = array();
862
+ }
863
+
864
+ $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
865
+
866
+ if ( empty( $term['termmeta'] ) ) {
867
+ return;
868
+ }
869
+
870
+ foreach ( $term['termmeta'] as $meta )
871
+ {
872
+ $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
873
+ if ( ! $key ) {
874
+ continue;
875
+ }
876
+
877
+ // Export gets meta straight from the DB so could have a serialized string
878
+ $value = maybe_unserialize( $meta['value'] );
879
+
880
+ add_term_meta( $term_id, $key, $value );
881
+
882
+ do_action( 'import_term_meta', $term_id, $key, $value );
883
+ }
884
+ }
885
+
886
+ private function process_tags()
887
+ {
888
+ $ret['result']='success';
889
+ $this->tags = apply_filters( 'wp_import_tags', $this->tags );
890
+ $this->import_log->wpvivid_write_import_log('Start importing tags.', 'notice');
891
+ if ( empty( $this->tags ) ){
892
+ $this->import_log->wpvivid_write_import_log('Tags import is completed.', 'notice');
893
+ return $ret;
894
+ }
895
+
896
+ foreach ( $this->tags as $tag )
897
+ {
898
+ $term_id = term_exists( $tag['tag_slug'], 'post_tag' );
899
+ if ( $term_id )
900
+ {
901
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
902
+ if ( isset($tag['term_id']) )
903
+ $this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
904
+ continue;
905
+ }
906
+
907
+ $tag = wp_slash( $tag );
908
+ $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
909
+ $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
910
+
911
+ $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
912
+ if ( ! is_wp_error( $id ) )
913
+ {
914
+ if ( isset($tag['term_id']) )
915
+ $this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
916
+ } else {
917
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
918
+ {
919
+ $this->import_log->wpvivid_write_import_log('Failed to import tags, error: '.$id->get_error_message(), 'notice');
920
+ $ret['result']='failed';
921
+ $ret['error']='Failed to import post tag '.$tag['tag_name'].' '.$id->get_error_message();
922
+ return $ret;
923
+ }
924
+ continue;
925
+ }
926
+
927
+ $this->process_termmeta( $tag, $id['term_id'] );
928
+ }
929
+
930
+ unset( $this->tags );
931
+ $this->import_log->wpvivid_write_import_log('Tags import is completed.', 'notice');
932
+ return $ret;
933
+ }
934
+
935
+ private function process_terms()
936
+ {
937
+ $ret['result']='success';
938
+ $this->terms = apply_filters( 'wp_import_terms', $this->terms );
939
+ $this->import_log->wpvivid_write_import_log('Start importing terms.', 'notice');
940
+ if ( empty( $this->terms ) ) {
941
+ $this->import_log->wpvivid_write_import_log('Terms import is completed.', 'notice');
942
+ return $ret;
943
+ }
944
+
945
+ foreach ( $this->terms as $term )
946
+ {
947
+ // if the term already exists in the correct taxonomy leave it alone
948
+ $term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
949
+ if ( $term_id ) {
950
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
951
+ if ( isset($term['term_id']) )
952
+ $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
953
+ continue;
954
+ }
955
+
956
+ if ( empty( $term['term_parent'] ) ) {
957
+ $parent = 0;
958
+ } else {
959
+ $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
960
+ if ( is_array( $parent ) ) $parent = $parent['term_id'];
961
+ }
962
+ $term = wp_slash( $term );
963
+ $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
964
+ $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
965
+
966
+ $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
967
+ if ( ! is_wp_error( $id ) ) {
968
+ if ( isset($term['term_id']) )
969
+ $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
970
+ } else {
971
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
972
+ {
973
+ $this->import_log->wpvivid_write_import_log('Failed to import terms, error: '.$id->get_error_message(), 'notice');
974
+ $ret['result']='failed';
975
+ $ret['error']='Failed to import '.$term['term_taxonomy'].' '.$term['term_name'].' '.$id->get_error_message();
976
+ return $ret;
977
+ }
978
+
979
+ continue;
980
+ }
981
+
982
+ $this->process_termmeta( $term, $id['term_id'] );
983
+ }
984
+
985
+ unset( $this->terms );
986
+ $this->import_log->wpvivid_write_import_log('Terms import is completed.', 'notice');
987
+ return $ret;
988
+ }
989
+
990
+ private function process_posts_ex()
991
+ {
992
+ $this->import_log->wpvivid_write_import_log('Start importing posts.', 'notice');
993
+ $ret['result']='success';
994
+ $this->posts = apply_filters( 'wp_import_posts', $this->posts );
995
+
996
+ foreach ( $this->posts as $post )
997
+ {
998
+ $this->import_log->wpvivid_write_import_log('Post id: '.$post['post_id'], 'notice');
999
+ $post = apply_filters( 'wp_import_post_data_raw', $post );
1000
+ $post_type_object = get_post_type_object( $post['post_type'] );
1001
+ $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
1002
+ $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
1003
+ if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] )
1004
+ {
1005
+ $this->import_log->wpvivid_write_import_log('The post already exists.', 'notice');
1006
+ $comment_post_ID=$post_id = $post_exists;
1007
+ $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
1008
+ } else {
1009
+ $post_parent = (int) $post['post_parent'];
1010
+ if ( $post_parent )
1011
+ {
1012
+ // if we already know the parent, map it to the new local ID
1013
+ if ( isset( $this->processed_posts[$post_parent] ) )
1014
+ {
1015
+ $post_parent = $this->processed_posts[$post_parent];
1016
+ // otherwise record the parent for later
1017
+ } else {
1018
+ $this->post_orphans[intval($post['post_id'])] = $post_parent;
1019
+ $post_parent = 0;
1020
+ }
1021
+ }
1022
+ // map the post author
1023
+ $author = sanitize_user( $post['post_author'], true );
1024
+ if ( isset( $this->author_mapping[$author] ) ) {
1025
+ $author = $this->author_mapping[$author];
1026
+ }
1027
+ else {
1028
+ $author = (int)$this->default_user;
1029
+ }
1030
+ $postdata = array(
1031
+ 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
1032
+ 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
1033
+ 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
1034
+ 'post_status' => $post['status'], 'post_name' => $post['post_name'],
1035
+ 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
1036
+ 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
1037
+ 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
1038
+ );
1039
+ $original_post_ID = $post['post_id'];
1040
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
1041
+ $postdata = wp_slash( $postdata );
1042
+ if ( 'attachment' == $postdata['post_type'] )
1043
+ {
1044
+ $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
1045
+ // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
1046
+ // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
1047
+ $postdata['upload_date'] = $post['post_date'];
1048
+ if ( isset( $post['postmeta'] ) )
1049
+ {
1050
+ foreach( $post['postmeta'] as $meta )
1051
+ {
1052
+ if ( $meta['key'] == '_wp_attached_file' ) {
1053
+ if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
1054
+ $postdata['upload_date'] = $matches[0];
1055
+ break;
1056
+ }
1057
+ }
1058
+ $postmeta=$post['postmeta'];
1059
+ }
1060
+ else
1061
+ {
1062
+ $postmeta=false;
1063
+ }
1064
+
1065
+ $comment_post_ID = $post_id = $this->process_attachment_ex( $postdata, $remote_url ,$postmeta);
1066
+ } else {
1067
+ $comment_post_ID =$post_id = wp_insert_post( $postdata, true );
1068
+ do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
1069
+ }
1070
+ if ( is_wp_error( $post_id ) )
1071
+ {
1072
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1073
+ {
1074
+ $ret['result']='failed';
1075
+ $ret['error']='Failed to import '.$post_type_object->labels->singular_name.' '.$post['post_title'].' '.$post_id->get_error_message();
1076
+ return $ret;
1077
+ }
1078
+ continue;
1079
+ }
1080
+ if ( $post['is_sticky'] == 1 )
1081
+ stick_post( $post_id );
1082
+ // map pre-import ID to local ID
1083
+ $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
1084
+ }
1085
+
1086
+ if($post_exists)
1087
+ continue;
1088
+
1089
+ if ( ! isset( $post['terms'] ) )
1090
+ $post['terms'] = array();
1091
+
1092
+ $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
1093
+
1094
+ // add categories, tags and other terms
1095
+ if ( ! empty( $post['terms'] ) )
1096
+ {
1097
+ $terms_to_set = array();
1098
+ foreach ( $post['terms'] as $term )
1099
+ {
1100
+ // back compat with WXR 1.0 map 'tag' to 'post_tag'
1101
+ $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain'];
1102
+ $term_exists = term_exists( $term['slug'], $taxonomy );
1103
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
1104
+ if ( ! $term_id )
1105
+ {
1106
+ $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
1107
+ if ( ! is_wp_error( $t ) )
1108
+ {
1109
+ $term_id = $t['term_id'];
1110
+ do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
1111
+ } else {
1112
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1113
+ {
1114
+ $this->import_log->wpvivid_write_import_log('Failed to import post, error: '.$post_id->get_error_message(), 'notice');
1115
+ $ret['result']='failed';
1116
+ $ret['error']='Failed to import '.esc_html($taxonomy).' '.esc_html($term['name']).' '.$post_id->get_error_message();
1117
+ return $ret;
1118
+ }
1119
+ continue;
1120
+ }
1121
+ }
1122
+ $terms_to_set[$taxonomy][] = intval( $term_id );
1123
+ }
1124
+
1125
+ foreach ( $terms_to_set as $tax => $ids )
1126
+ {
1127
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
1128
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
1129
+ }
1130
+ unset( $post['terms'], $terms_to_set );
1131
+ }
1132
+
1133
+ if ( ! isset( $post['comments'] ) )
1134
+ $post['comments'] = array();
1135
+
1136
+ $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
1137
+
1138
+ // add/update comments
1139
+ if ( ! empty( $post['comments'] ) )
1140
+ {
1141
+ $num_comments = 0;
1142
+ $inserted_comments = array();
1143
+ foreach ( $post['comments'] as $comment )
1144
+ {
1145
+ $comment_id = $comment['comment_id'];
1146
+ $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
1147
+ $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
1148
+ $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
1149
+ $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
1150
+ $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
1151
+ $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
1152
+ $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
1153
+ $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
1154
+ $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
1155
+ $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
1156
+ $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
1157
+ $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
1158
+ if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
1159
+ $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
1160
+ }
1161
+ ksort( $newcomments );
1162
+
1163
+ foreach ( $newcomments as $key => $comment )
1164
+ {
1165
+ // if this is a new post we can skip the comment_exists() check
1166
+ if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) )
1167
+ {
1168
+ if ( isset( $inserted_comments[$comment['comment_parent']] ) )
1169
+ $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
1170
+ $comment = wp_slash( $comment );
1171
+ $comment = wp_filter_comment( $comment );
1172
+ $inserted_comments[$key] = wp_insert_comment( $comment );
1173
+ do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
1174
+
1175
+ foreach( $comment['commentmeta'] as $meta ) {
1176
+ $value = maybe_unserialize( $meta['value'] );
1177
+ add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
1178
+ }
1179
+
1180
+ $num_comments++;
1181
+ }
1182
+ }
1183
+ unset( $newcomments, $inserted_comments, $post['comments'] );
1184
+ }
1185
+
1186
+ if ( ! isset( $post['postmeta'] ) )
1187
+ $post['postmeta'] = array();
1188
+
1189
+ $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
1190
+
1191
+ // add/update post meta
1192
+ if ( ! empty( $post['postmeta'] ) )
1193
+ {
1194
+ foreach ( $post['postmeta'] as $meta )
1195
+ {
1196
+ $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
1197
+ $value = false;
1198
+
1199
+ if ( '_edit_last' == $key )
1200
+ {
1201
+ if ( isset( $this->processed_authors[intval($meta['value'])] ) )
1202
+ $value = $this->processed_authors[intval($meta['value'])];
1203
+ else
1204
+ $key = false;
1205
+ }
1206
+
1207
+ if ( $key )
1208
+ {
1209
+ // export gets meta straight from the DB so could have a serialized string
1210
+ if ( ! $value )
1211
+ $value = maybe_unserialize( $meta['value'] );
1212
+
1213
+ add_post_meta( $post_id, $key, $value );
1214
+ do_action( 'import_post_meta', $post_id, $key, $value );
1215
+
1216
+ // if the post has a featured image, take note of this in case of remap
1217
+ if ( '_thumbnail_id' == $key )
1218
+ $this->featured_images[$post_id] = (int) $value;
1219
+ }
1220
+ }
1221
+ }
1222
+ }
1223
+
1224
+ unset( $this->posts );
1225
+ $this->import_log->wpvivid_write_import_log('Posts import is completed.', 'notice');
1226
+ return $ret;
1227
+ }
1228
+
1229
+ public function replace_domain()
1230
+ {
1231
+ $this->new_site_url= untrailingslashit(site_url());
1232
+ $this->import_log->wpvivid_write_import_log('The original domain name: '.$this->base_url, 'notice');
1233
+ $this->import_log->wpvivid_write_import_log('The current domain name: '.$this->new_site_url, 'notice');
1234
+ if(empty($this->base_url))
1235
+ {
1236
+ $this->import_log->wpvivid_write_import_log('Failed to retrieve the original domain name: '.$this->base_url, 'notice');
1237
+ return ;
1238
+ }
1239
+
1240
+ if(empty($this->processed_posts))
1241
+ {
1242
+ $this->import_log->wpvivid_write_import_log('The unimported posts', 'notice');
1243
+ return ;
1244
+ }
1245
+
1246
+ if($this->base_url===$this->new_site_url)
1247
+ {
1248
+ $this->import_log->wpvivid_write_import_log('Replacing domain name is not required.', 'notice');
1249
+ return ;
1250
+ }
1251
+
1252
+
1253
+ global $wp_query,$wpdb;
1254
+ $this->import_log->wpvivid_write_import_log('Start replacing domain name.', 'notice');
1255
+ $wp_query->in_the_loop = true;
1256
+ while ( $next_posts = array_splice( $this->processed_posts, 0, 20 ) )
1257
+ {
1258
+ $where = 'WHERE ID IN (' . join(',', $next_posts) . ')';
1259
+ $posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} $where");
1260
+
1261
+ foreach ( $posts as $post )
1262
+ {
1263
+ $old_data=$post->post_content;
1264
+ $new_data=$this->replace_row_data($old_data);
1265
+ if($new_data==$old_data)
1266
+ {
1267
+ $this->import_log->wpvivid_write_import_log('Post ID '.$post->ID.' is not changed.', 'notice');
1268
+ continue;
1269
+ }
1270
+ else
1271
+ {
1272
+ $this->import_log->wpvivid_write_import_log('Post ID '.$post->ID.' is changed.', 'notice');
1273
+ }
1274
+ $post->post_content=$new_data;
1275
+ wp_update_post($post);
1276
+ }
1277
+ }
1278
+ }
1279
+
1280
+ private function replace_row_data($old_data)
1281
+ {
1282
+ $unserialize_data = @unserialize($old_data);
1283
+ if($unserialize_data===false)
1284
+ {
1285
+ $old_data=$this->replace_string($old_data);
1286
+ }
1287
+ else
1288
+ {
1289
+ $old_data=$this->replace_serialize_data($unserialize_data);
1290
+ $old_data=serialize($old_data);
1291
+ /*if(is_array($unserialize_data))
1292
+ {
1293
+ $temp_data = array();
1294
+ foreach ($unserialize_data as $key => $value)
1295
+ {
1296
+ $temp_data[$key]=$this->replace_string($value);
1297
+ }
1298
+
1299
+ $old_data = $temp_data;
1300
+ unset($temp_data);
1301
+ $old_data=$this->replace_serialize_data($unserialize_data);
1302
+ $old_data=serialize($old_data);
1303
+ }
1304
+ else if(is_object($unserialize_data))
1305
+ {
1306
+ $temp_data = $unserialize_data;
1307
+ $props = get_object_vars($unserialize_data);
1308
+ foreach ($props as $key => $value)
1309
+ {
1310
+ $temp_data->$key =$this->replace_string($value);
1311
+ }
1312
+ $old_data = $temp_data;
1313
+ unset($temp_data);
1314
+ $old_data=serialize($old_data);
1315
+ }*/
1316
+ }
1317
+
1318
+ return $old_data;
1319
+ }
1320
+
1321
+ private function replace_serialize_data($data)
1322
+ {
1323
+ if(is_string($data))
1324
+ {
1325
+ $serialize_data =@unserialize($data);
1326
+ if($serialize_data===false)
1327
+ {
1328
+ $data=$this->replace_string($data);
1329
+ }
1330
+ else
1331
+ {
1332
+ $data=serialize($this->replace_serialize_data($serialize_data));
1333
+ }
1334
+ }
1335
+ else if(is_array($data))
1336
+ {
1337
+ foreach ($data as $key => $value)
1338
+ {
1339
+ if(is_string($value))
1340
+ {
1341
+ $data[$key]=$this->replace_string($value);
1342
+ }
1343
+ else if(is_array($value))
1344
+ {
1345
+ $data[$key]=$this->replace_serialize_data($value);
1346
+ }
1347
+ else if(is_object($value))
1348
+ {
1349
+ if (is_a($value, '__PHP_Incomplete_Class'))
1350
+ {
1351
+ //
1352
+ }
1353
+ else
1354
+ {
1355
+ $data[$key]=$this->replace_serialize_data($value);
1356
+ }
1357
+ }
1358
+ }
1359
+ }
1360
+ else if(is_object($data))
1361
+ {
1362
+ $temp = $data; // new $data_class();
1363
+ if (is_a($data, '__PHP_Incomplete_Class'))
1364
+ {
1365
+
1366
+ }
1367
+ else
1368
+ {
1369
+ $props = get_object_vars($data);
1370
+ foreach ($props as $key => $value)
1371
+ {
1372
+ if(is_string($value))
1373
+ {
1374
+ $temp->$key =$this->replace_string($value);
1375
+ }
1376
+ else if(is_array($value))
1377
+ {
1378
+ $temp->$key=$this->replace_serialize_data($value);
1379
+ }
1380
+ else if(is_object($value))
1381
+ {
1382
+ $temp->$key=$this->replace_serialize_data($value);
1383
+ }
1384
+ }
1385
+ }
1386
+ $data = $temp;
1387
+ unset($temp);
1388
+ }
1389
+
1390
+ return $data;
1391
+ }
1392
+
1393
+ private function replace_string($old_string)
1394
+ {
1395
+ if(!is_string($old_string))
1396
+ {
1397
+ return $old_string;
1398
+ }
1399
+
1400
+ if($this->base_url!=$this->new_site_url)
1401
+ {
1402
+ $remove_http_link=$this->get_remove_http_link($this->base_url);
1403
+ $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1404
+ if(strpos($new_remove_http_link,$remove_http_link)!==false)
1405
+ {
1406
+ return $this->replace_string_ex($old_string);
1407
+ }
1408
+ }
1409
+
1410
+ if($this->base_url!=$this->new_site_url)
1411
+ {
1412
+ $old_string=str_replace($this->base_url,$this->new_site_url,$old_string);
1413
+ $old_mix_link=$this->get_mix_link($this->base_url);
1414
+ if($old_mix_link!==false)
1415
+ {
1416
+ $old_string=str_replace($old_mix_link,$this->new_site_url,$old_string);
1417
+ }
1418
+ $remove_http_link=$this->get_remove_http_link($this->base_url);
1419
+ if($remove_http_link!==false)
1420
+ {
1421
+ $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1422
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1423
+ }
1424
+
1425
+ $remove_http_link=$this->get_remove_http_link_ex($this->base_url);
1426
+ if($remove_http_link!==false)
1427
+ {
1428
+ $new_remove_http_link=$this->get_remove_http_link_ex($this->new_site_url);
1429
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1430
+ }
1431
+ }
1432
+
1433
+ return $old_string;
1434
+ }
1435
+
1436
+ private function replace_string_ex($old_string)
1437
+ {
1438
+ if(!is_string($old_string))
1439
+ {
1440
+ return $old_string;
1441
+ }
1442
+
1443
+ if($this->base_url!=$this->new_site_url)
1444
+ {
1445
+ $remove_http_link=$this->get_remove_http_link($this->base_url);
1446
+ if($remove_http_link!==false)
1447
+ {
1448
+ $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1449
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1450
+ }
1451
+
1452
+ $new_mix_link=$this->get_mix_link($this->new_site_url);
1453
+ if($new_mix_link!==false)
1454
+ {
1455
+ $old_string=str_replace($new_mix_link,$this->new_site_url,$old_string);
1456
+ }
1457
+
1458
+ $remove_http_link=$this->get_remove_http_link_ex($this->base_url);
1459
+ if($remove_http_link!==false)
1460
+ {
1461
+ $new_remove_http_link=$this->get_remove_http_link_ex($this->new_site_url);
1462
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1463
+ }
1464
+ }
1465
+
1466
+ return $old_string;
1467
+ }
1468
+
1469
+ private function get_remove_http_link($url)
1470
+ {
1471
+ if (0 === stripos($url, 'https://'))
1472
+ {
1473
+ $mix_link = '//'.substr($url, 8);
1474
+ } elseif (0 === stripos($url, 'http://')) {
1475
+ $mix_link = '//'.substr($url, 7);
1476
+ }
1477
+ else
1478
+ {
1479
+ $mix_link=false;
1480
+ }
1481
+ return $mix_link;
1482
+ }
1483
+
1484
+ private function get_remove_http_link_ex($url)
1485
+ {
1486
+ if (0 === stripos($url, 'https://'))
1487
+ {
1488
+ $mix_link = '\/\/'.substr($url, 8);
1489
+ } elseif (0 === stripos($url, 'http://')) {
1490
+ $mix_link = '\/\/'.substr($url, 7);
1491
+ }
1492
+ else
1493
+ {
1494
+ $mix_link=false;
1495
+ }
1496
+ return $mix_link;
1497
+ }
1498
+
1499
+ private function get_mix_link($url)
1500
+ {
1501
+ if (0 === stripos($url, 'https://'))
1502
+ {
1503
+ $mix_link = 'http://'.substr($url, 8);
1504
+ } elseif (0 === stripos($url, 'http://')) {
1505
+ $mix_link = 'https://'.substr($url, 7);
1506
+ }
1507
+ else
1508
+ {
1509
+ $mix_link=false;
1510
+ }
1511
+ return $mix_link;
1512
+ }
1513
+
1514
+ function process_attachment_ex( $post, $url,$postmeta )
1515
+ {
1516
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1517
+ if ( preg_match( '|^/[\w\W]+$|', $url ) )
1518
+ $url = rtrim( $this->base_url, '/' ) . $url;
1519
+
1520
+ $upload = $this->fetch_local_file_ex( $url, $post ,$postmeta);
1521
+ if ( is_wp_error( $upload ) )
1522
+ return $upload;
1523
+ $post['post_mime_type']=$upload['type'];
1524
+
1525
+ $post['guid'] = $upload['url'];
1526
+
1527
+ // as per wp-admin/includes/upload.php
1528
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
1529
+
1530
+ if ( is_wp_error( $post_id ) )
1531
+ {
1532
+ return $post_id;
1533
+ }
1534
+
1535
+ if ( preg_match( '!^image/!',$upload['type'] ) )
1536
+ {
1537
+ $parts = pathinfo( $url );
1538
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1539
+
1540
+ $parts_new = pathinfo( $upload['url'] );
1541
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1542
+
1543
+ $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1544
+ }
1545
+
1546
+ return $post_id;
1547
+ }
1548
+
1549
+ function fetch_local_file_ex($url,$post,$postmeta)
1550
+ {
1551
+ $file_name = basename( $url );
1552
+
1553
+ $upload = wp_upload_dir( $post['upload_date'] );
1554
+
1555
+ $new_file='';
1556
+ if($postmeta!==false)
1557
+ {
1558
+ foreach( $postmeta as $meta )
1559
+ {
1560
+ if ( $meta['key'] == '_wp_attached_file' )
1561
+ {
1562
+ $new_file=$upload['basedir'].'/'.$meta['meta_value'];
1563
+ $url = $upload['baseurl'].'/'.$meta['meta_value'];
1564
+ }
1565
+ }
1566
+ }
1567
+
1568
+ if(empty($new_file))
1569
+ {
1570
+ $new_file = $upload['path'] . "/$file_name";
1571
+ $url = $upload['url'] . "/$file_name";
1572
+ }
1573
+
1574
+ if(!file_exists($new_file))
1575
+ {
1576
+ return new WP_Error( 'import_file_error', __('File not exist ex file:'.$new_file, 'wordpress-importer') );
1577
+ }
1578
+
1579
+ $wp_filetype = wp_check_filetype( $file_name );
1580
+
1581
+ if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) )
1582
+ {
1583
+ return new WP_Error( 'import_file_error', __( 'Sorry, this file type is not permitted for security reasons.' ) );
1584
+ }
1585
+
1586
+ return apply_filters(
1587
+ 'wp_handle_upload',
1588
+ array(
1589
+ 'file' => $new_file,
1590
+ 'url' => $url,
1591
+ 'type' => $wp_filetype['type'],
1592
+ 'error' => false,
1593
+ ),
1594
+ 'sideload'
1595
+ );
1596
+ }
1597
+
1598
+ function parse( $file ) {
1599
+ $parser = new WPvivid_WXR_Parser();
1600
+ return $parser->parse( $file );
1601
+ }
1602
+
1603
+ function get_authors_from_import( $import_data )
1604
+ {
1605
+ if ( ! empty( $import_data['authors'] ) )
1606
+ {
1607
+ $this->authors = $import_data['authors'];
1608
+ // no author information, grab it from the posts
1609
+ } else {
1610
+ foreach ( $import_data['posts'] as $post )
1611
+ {
1612
+ $login = sanitize_user( $post['post_author'], true );
1613
+ if ( empty( $login ) )
1614
+ {
1615
+ continue;
1616
+ }
1617
+
1618
+ if ( ! isset($this->authors[$login]) )
1619
+ $this->authors[$login] = array(
1620
+ 'author_login' => $login,
1621
+ 'author_display_name' => $post['post_author']
1622
+ );
1623
+ }
1624
+ }
1625
+ }
1626
+
1627
+ function process_attachment( $post, $url )
1628
+ {
1629
+ if ( ! $this->fetch_attachments )
1630
+ return new WP_Error( 'attachment_processing_error',
1631
+ __( 'Fetching attachments is not enabled', 'wordpress-importer' ) );
1632
+
1633
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1634
+ if ( preg_match( '|^/[\w\W]+$|', $url ) )
1635
+ $url = rtrim( $this->base_url, '/' ) . $url;
1636
+
1637
+ $upload = $this->fetch_local_file( $url, $post );
1638
+ if ( is_wp_error( $upload ) )
1639
+ return $upload;
1640
+
1641
+ if ( $info = wp_check_filetype( $upload['file'] ) )
1642
+ $post['post_mime_type'] = $info['type'];
1643
+ else
1644
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1645
+
1646
+ $post['guid'] = $upload['url'];
1647
+
1648
+ // as per wp-admin/includes/upload.php
1649
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
1650
+
1651
+ if ( is_wp_error( $post_id ) )
1652
+ {
1653
+ echo 'error file:'.$upload['file'];
1654
+ }
1655
+
1656
+ //$metadata=wp_generate_attachment_metadata( $post_id, $upload['file'] );
1657
+ //wp_update_attachment_metadata( $post_id,$metadata );
1658
+
1659
+ // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1660
+ if ( preg_match( '!^image/!', $info['type'] ) ) {
1661
+ $parts = pathinfo( $url );
1662
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1663
+
1664
+ $parts_new = pathinfo( $upload['url'] );
1665
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1666
+
1667
+ $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1668
+ }
1669
+
1670
+ return $post_id;
1671
+ }
1672
+
1673
+ function fetch_local_file($url,$post)
1674
+ {
1675
+ $file_name = basename( $url );
1676
+
1677
+ $upload = wp_upload_dir( $post['upload_date'] );
1678
+ $new_file = $upload['path'] . "/$file_name";
1679
+ $url = $upload['url'] . "/$file_name";
1680
+
1681
+ $wp_filetype = wp_check_filetype( $file_name );
1682
+
1683
+ if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
1684
+ return array( 'error' => __( 'Sorry, this file type is not permitted for security reasons.' ) );
1685
+ }
1686
+
1687
+ if(!file_exists($new_file))
1688
+ {
1689
+ return new WP_Error( 'import_file_error', __('File not exist file:'.$new_file, 'wordpress-importer') );
1690
+ }
1691
+
1692
+ return apply_filters(
1693
+ 'wp_handle_upload',
1694
+ array(
1695
+ 'file' => $new_file,
1696
+ 'url' => $url,
1697
+ 'type' => $wp_filetype['type'],
1698
+ 'error' => false,
1699
+ ),
1700
+ 'sideload'
1701
+ );
1702
+ }
1703
+
1704
+ /**
1705
+ * Performs post-import cleanup of files and the cache
1706
+ */
1707
+ function import_end()
1708
+ {
1709
+ wp_import_cleanup( $this->id );
1710
+
1711
+ wp_cache_flush();
1712
+ foreach ( get_taxonomies() as $tax ) {
1713
+ delete_option( "{$tax}_children" );
1714
+ _get_term_hierarchy( $tax );
1715
+ }
1716
+
1717
+ wp_defer_term_counting( false );
1718
+ wp_defer_comment_counting( false );
1719
+
1720
+ $ret['result']='success';
1721
+
1722
+ do_action( 'import_end' );
1723
+ return $ret;
1724
+ }
1725
+ }
1726
+
1727
+ function wpvivid_function_pre_extract_import_callback($p_event, &$p_header)
1728
+ {
1729
+ global $xml_file_name;
1730
+
1731
+ if(strpos($p_header['filename'],$xml_file_name)!==false)
1732
+ {
1733
+ return 0;
1734
+ }
1735
+
1736
+ if(strpos($p_header['filename'],'wpvivid_export_package_info.json')!==false)
1737
+ {
1738
+ return 0;
1739
+ }
1740
+
1741
+ return 1;
1742
+ }
1743
+
1744
+ /**
1745
+ * WordPress Importer class for managing parsing of WXR files.
1746
+ */
1747
+ class WPvivid_WXR_Parser
1748
+ {
1749
+ function parse( $file )
1750
+ {
1751
+ // Attempt to use proper XML parsers first
1752
+ if ( extension_loaded( 'simplexml' ) )
1753
+ {
1754
+ $parser = new WPvivid_WXR_Parser_SimpleXML;
1755
+ $result = $parser->parse( $file );
1756
+
1757
+ // If SimpleXML succeeds or this is an invalid WXR file then return the results
1758
+ if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
1759
+ return $result;
1760
+ }
1761
+ else if ( extension_loaded( 'xml' ) )
1762
+ {
1763
+ $parser = new WPvivid_WXR_Parser_XML;
1764
+ $result = $parser->parse( $file );
1765
+
1766
+ // If XMLParser succeeds or this is an invalid WXR file then return the results
1767
+ if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
1768
+ return $result;
1769
+ }
1770
+
1771
+ // We have a malformed XML file, so display the error and fallthrough to regex
1772
+ if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1773
+ {
1774
+ $msg='';
1775
+ if ( 'SimpleXML_parse_error' == $result->get_error_code() )
1776
+ {
1777
+ foreach ( $result->get_error_data() as $error )
1778
+ $msg.= $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
1779
+ } else if ( 'XML_parse_error' == $result->get_error_code() )
1780
+ {
1781
+ $error = $result->get_error_data();
1782
+ $msg.= $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
1783
+ }
1784
+ $msg.=__( 'There was an error when reading this WXR file', 'wordpress-importer' ) ;
1785
+ $msg.=__( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' );
1786
+
1787
+ return new WP_Error( 'WXR_Parser_error', $msg,'' );
1788
+ }
1789
+
1790
+ // use regular expressions if nothing else available or this is bad XML
1791
+ $parser = new WPvivid_WXR_Parser_Regex;
1792
+ return $parser->parse( $file );
1793
+ }
1794
+ }
1795
+
1796
+ /**
1797
+ * WXR Parser that makes use of the SimpleXML PHP extension.
1798
+ */
1799
+ class WPvivid_WXR_Parser_SimpleXML
1800
+ {
1801
+ function parse( $file )
1802
+ {
1803
+ $authors = $posts = $categories = $tags = $terms = array();
1804
+
1805
+ $internal_errors = libxml_use_internal_errors(true);
1806
+
1807
+ $dom = new DOMDocument;
1808
+ $old_value = null;
1809
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
1810
+ $old_value = libxml_disable_entity_loader( true );
1811
+ }
1812
+ $success = $dom->loadXML( file_get_contents( $file ) );
1813
+ if ( ! is_null( $old_value ) )
1814
+ {
1815
+ libxml_disable_entity_loader( $old_value );
1816
+ }
1817
+
1818
+ if ( ! $success || isset( $dom->doctype ) )
1819
+ {
1820
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
1821
+ }
1822
+
1823
+ $xml = simplexml_import_dom( $dom );
1824
+ unset( $dom );
1825
+
1826
+ // halt if loading produces an error
1827
+ if ( ! $xml )
1828
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
1829
+
1830
+ $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
1831
+ if ( ! $wxr_version )
1832
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
1833
+
1834
+ $wxr_version = (string) trim( $wxr_version[0] );
1835
+ // confirm that we are dealing with the correct file format
1836
+ if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
1837
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
1838
+
1839
+ $base_url = $xml->xpath('/rss/channel/wp:base_site_url');
1840
+ $base_url = (string) trim( $base_url[0] );
1841
+
1842
+ $namespaces = $xml->getDocNamespaces();
1843
+ if ( ! isset( $namespaces['wp'] ) )
1844
+ $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
1845
+ if ( ! isset( $namespaces['excerpt'] ) )
1846
+ $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
1847
+
1848
+ // grab authors
1849
+ foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr )
1850
+ {
1851
+ $a = $author_arr->children( $namespaces['wp'] );
1852
+ $login = (string) $a->author_login;
1853
+ $authors[$login] = array(
1854
+ 'author_id' => (int) $a->author_id,
1855
+ 'author_login' => $login,
1856
+ 'author_email' => (string) $a->author_email,
1857
+ 'author_display_name' => (string) $a->author_display_name,
1858
+ 'author_first_name' => (string) $a->author_first_name,
1859
+ 'author_last_name' => (string) $a->author_last_name
1860
+ );
1861
+ }
1862
+
1863
+ // grab cats, tags and terms
1864
+ foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr )
1865
+ {
1866
+ $t = $term_arr->children( $namespaces['wp'] );
1867
+ $category = array(
1868
+ 'term_id' => (int) $t->term_id,
1869
+ 'category_nicename' => (string) $t->category_nicename,
1870
+ 'category_parent' => (string) $t->category_parent,
1871
+ 'cat_name' => (string) $t->cat_name,
1872
+ 'category_description' => (string) $t->category_description
1873
+ );
1874
+
1875
+ foreach ( $t->termmeta as $meta ) {
1876
+ $category['termmeta'][] = array(
1877
+ 'key' => (string) $meta->meta_key,
1878
+ 'value' => (string) $meta->meta_value
1879
+ );
1880
+ }
1881
+
1882
+ $categories[] = $category;
1883
+ }
1884
+
1885
+ foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr )
1886
+ {
1887
+ $t = $term_arr->children( $namespaces['wp'] );
1888
+ $tag = array(
1889
+ 'term_id' => (int) $t->term_id,
1890
+ 'tag_slug' => (string) $t->tag_slug,
1891
+ 'tag_name' => (string) $t->tag_name,
1892
+ 'tag_description' => (string) $t->tag_description
1893
+ );
1894
+
1895
+ foreach ( $t->termmeta as $meta ) {
1896
+ $tag['termmeta'][] = array(
1897
+ 'key' => (string) $meta->meta_key,
1898
+ 'value' => (string) $meta->meta_value
1899
+ );
1900
+ }
1901
+
1902
+ $tags[] = $tag;
1903
+ }
1904
+
1905
+ foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr )
1906
+ {
1907
+ $t = $term_arr->children( $namespaces['wp'] );
1908
+ $term = array(
1909
+ 'term_id' => (int) $t->term_id,
1910
+ 'term_taxonomy' => (string) $t->term_taxonomy,
1911
+ 'slug' => (string) $t->term_slug,
1912
+ 'term_parent' => (string) $t->term_parent,
1913
+ 'term_name' => (string) $t->term_name,
1914
+ 'term_description' => (string) $t->term_description
1915
+ );
1916
+
1917
+ foreach ( $t->termmeta as $meta ) {
1918
+ $term['termmeta'][] = array(
1919
+ 'key' => (string) $meta->meta_key,
1920
+ 'value' => (string) $meta->meta_value
1921
+ );
1922
+ }
1923
+
1924
+ $terms[] = $term;
1925
+ }
1926
+
1927
+ // grab posts
1928
+ foreach ( $xml->channel->item as $item )
1929
+ {
1930
+ $post = array(
1931
+ 'post_title' => (string) $item->title,
1932
+ 'guid' => (string) $item->guid,
1933
+ );
1934
+
1935
+ $dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
1936
+ $post['post_author'] = (string) $dc->creator;
1937
+
1938
+ $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
1939
+ $excerpt = $item->children( $namespaces['excerpt'] );
1940
+ $post['post_content'] = (string) $content->encoded;
1941
+ $post['post_excerpt'] = (string) $excerpt->encoded;
1942
+
1943
+ $wp = $item->children( $namespaces['wp'] );
1944
+ $post['post_id'] = (int) $wp->post_id;
1945
+ $post['post_date'] = (string) $wp->post_date;
1946
+ $post['post_date_gmt'] = (string) $wp->post_date_gmt;
1947
+ $post['comment_status'] = (string) $wp->comment_status;
1948
+ $post['ping_status'] = (string) $wp->ping_status;
1949
+ $post['post_name'] = (string) $wp->post_name;
1950
+ $post['status'] = (string) $wp->status;
1951
+ $post['post_parent'] = (int) $wp->post_parent;
1952
+ $post['menu_order'] = (int) $wp->menu_order;
1953
+ $post['post_type'] = (string) $wp->post_type;
1954
+ $post['post_password'] = (string) $wp->post_password;
1955
+ $post['is_sticky'] = (int) $wp->is_sticky;
1956
+
1957
+ if ( isset($wp->attachment_url) )
1958
+ $post['attachment_url'] = (string) $wp->attachment_url;
1959
+
1960
+ foreach ( $item->category as $c )
1961
+ {
1962
+ $att = $c->attributes();
1963
+ if ( isset( $att['nicename'] ) )
1964
+ $post['terms'][] = array(
1965
+ 'name' => (string) $c,
1966
+ 'slug' => (string) $att['nicename'],
1967
+ 'domain' => (string) $att['domain']
1968
+ );
1969
+ }
1970
+
1971
+ foreach ( $wp->postmeta as $meta )
1972
+ {
1973
+ $post['postmeta'][] = array(
1974
+ 'key' => (string) $meta->meta_key,
1975
+ 'value' => (string) $meta->meta_value
1976
+ );
1977
+ }
1978
+
1979
+ foreach ( $wp->comment as $comment )
1980
+ {
1981
+ $meta = array();
1982
+ if ( isset( $comment->commentmeta ) ) {
1983
+ foreach ( $comment->commentmeta as $m ) {
1984
+ $meta[] = array(
1985
+ 'key' => (string) $m->meta_key,
1986
+ 'value' => (string) $m->meta_value
1987
+ );
1988
+ }
1989
+ }
1990
+
1991
+ $post['comments'][] = array(
1992
+ 'comment_id' => (int) $comment->comment_id,
1993
+ 'comment_author' => (string) $comment->comment_author,
1994
+ 'comment_author_email' => (string) $comment->comment_author_email,
1995
+ 'comment_author_IP' => (string) $comment->comment_author_IP,
1996
+ 'comment_author_url' => (string) $comment->comment_author_url,
1997
+ 'comment_date' => (string) $comment->comment_date,
1998
+ 'comment_date_gmt' => (string) $comment->comment_date_gmt,
1999
+ 'comment_content' => (string) $comment->comment_content,
2000
+ 'comment_approved' => (string) $comment->comment_approved,
2001
+ 'comment_type' => (string) $comment->comment_type,
2002
+ 'comment_parent' => (string) $comment->comment_parent,
2003
+ 'comment_user_id' => (int) $comment->comment_user_id,
2004
+ 'commentmeta' => $meta,
2005
+ );
2006
+ }
2007
+
2008
+ $posts[] = $post;
2009
+ }
2010
+
2011
+ return array(
2012
+ 'authors' => $authors,
2013
+ 'posts' => $posts,
2014
+ 'categories' => $categories,
2015
+ 'tags' => $tags,
2016
+ 'terms' => $terms,
2017
+ 'base_url' => $base_url,
2018
+ 'version' => $wxr_version
2019
+ );
2020
+ }
2021
+ }
2022
+
2023
+ /**
2024
+ * WXR Parser that makes use of the XML Parser PHP extension.
2025
+ */
2026
+ class WPvivid_WXR_Parser_XML {
2027
+ var $wp_tags = array(
2028
+ 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
2029
+ 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
2030
+ 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
2031
+ 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
2032
+ 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
2033
+ 'wp:author_first_name', 'wp:author_last_name',
2034
+ );
2035
+ var $wp_sub_tags = array(
2036
+ 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
2037
+ 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
2038
+ 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
2039
+ );
2040
+
2041
+ function parse( $file ) {
2042
+ $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
2043
+ $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
2044
+
2045
+ $xml = xml_parser_create( 'UTF-8' );
2046
+ xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
2047
+ xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
2048
+ xml_set_object( $xml, $this );
2049
+ xml_set_character_data_handler( $xml, 'cdata' );
2050
+ xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
2051
+
2052
+ if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) {
2053
+ $current_line = xml_get_current_line_number( $xml );
2054
+ $current_column = xml_get_current_column_number( $xml );
2055
+ $error_code = xml_get_error_code( $xml );
2056
+ $error_string = xml_error_string( $error_code );
2057
+ return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
2058
+ }
2059
+ xml_parser_free( $xml );
2060
+
2061
+ if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
2062
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
2063
+
2064
+ return array(
2065
+ 'authors' => $this->authors,
2066
+ 'posts' => $this->posts,
2067
+ 'categories' => $this->category,
2068
+ 'tags' => $this->tag,
2069
+ 'terms' => $this->term,
2070
+ 'base_url' => $this->base_url,
2071
+ 'version' => $this->wxr_version
2072
+ );
2073
+ }
2074
+
2075
+ function tag_open( $parse, $tag, $attr ) {
2076
+ if ( in_array( $tag, $this->wp_tags ) ) {
2077
+ $this->in_tag = substr( $tag, 3 );
2078
+ return;
2079
+ }
2080
+
2081
+ if ( in_array( $tag, $this->wp_sub_tags ) ) {
2082
+ $this->in_sub_tag = substr( $tag, 3 );
2083
+ return;
2084
+ }
2085
+
2086
+ switch ( $tag ) {
2087
+ case 'category':
2088
+ if ( isset($attr['domain'], $attr['nicename']) ) {
2089
+ $this->sub_data['domain'] = $attr['domain'];
2090
+ $this->sub_data['slug'] = $attr['nicename'];
2091
+ }
2092
+ break;
2093
+ case 'item': $this->in_post = true;
2094
+ case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
2095
+ case 'guid': $this->in_tag = 'guid'; break;
2096
+ case 'dc:creator': $this->in_tag = 'post_author'; break;
2097
+ case 'content:encoded': $this->in_tag = 'post_content'; break;
2098
+ case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
2099
+
2100
+ case 'wp:term_slug': $this->in_tag = 'slug'; break;
2101
+ case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
2102
+ case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
2103
+ }
2104
+ }
2105
+
2106
+ function cdata( $parser, $cdata ) {
2107
+ if ( ! trim( $cdata ) )
2108
+ return;
2109
+
2110
+ if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
2111
+ $this->cdata .= $cdata;
2112
+ } else {
2113
+ $this->cdata .= trim( $cdata );
2114
+ }
2115
+ }
2116
+
2117
+ function tag_close( $parser, $tag ) {
2118
+ switch ( $tag ) {
2119
+ case 'wp:comment':
2120
+ unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
2121
+ if ( ! empty( $this->sub_data ) )
2122
+ $this->data['comments'][] = $this->sub_data;
2123
+ $this->sub_data = false;
2124
+ break;
2125
+ case 'wp:commentmeta':
2126
+ $this->sub_data['commentmeta'][] = array(
2127
+ 'key' => $this->sub_data['key'],
2128
+ 'value' => $this->sub_data['value']
2129
+ );
2130
+ break;
2131
+ case 'category':
2132
+ if ( ! empty( $this->sub_data ) ) {
2133
+ $this->sub_data['name'] = $this->cdata;
2134
+ $this->data['terms'][] = $this->sub_data;
2135
+ }
2136
+ $this->sub_data = false;
2137
+ break;
2138
+ case 'wp:postmeta':
2139
+ if ( ! empty( $this->sub_data ) )
2140
+ $this->data['postmeta'][] = $this->sub_data;
2141
+ $this->sub_data = false;
2142
+ break;
2143
+ case 'item':
2144
+ $this->posts[] = $this->data;
2145
+ $this->data = false;
2146
+ break;
2147
+ case 'wp:category':
2148
+ case 'wp:tag':
2149
+ case 'wp:term':
2150
+ $n = substr( $tag, 3 );
2151
+ array_push( $this->$n, $this->data );
2152
+ $this->data = false;
2153
+ break;
2154
+ case 'wp:author':
2155
+ if ( ! empty($this->data['author_login']) )
2156
+ $this->authors[$this->data['author_login']] = $this->data;
2157
+ $this->data = false;
2158
+ break;
2159
+ case 'wp:base_site_url':
2160
+ $this->base_url = $this->cdata;
2161
+ break;
2162
+ case 'wp:wxr_version':
2163
+ $this->wxr_version = $this->cdata;
2164
+ break;
2165
+
2166
+ default:
2167
+ if ( $this->in_sub_tag ) {
2168
+ $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
2169
+ $this->in_sub_tag = false;
2170
+ } else if ( $this->in_tag ) {
2171
+ $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
2172
+ $this->in_tag = false;
2173
+ }
2174
+ }
2175
+
2176
+ $this->cdata = false;
2177
+ }
2178
+ }
2179
+
2180
+ /**
2181
+ * WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
2182
+ */
2183
+ class WPvivid_WXR_Parser_Regex {
2184
+ var $authors = array();
2185
+ var $posts = array();
2186
+ var $categories = array();
2187
+ var $tags = array();
2188
+ var $terms = array();
2189
+ var $base_url = '';
2190
+
2191
+ function __construct() {
2192
+ $this->has_gzip = is_callable( 'gzopen' );
2193
+ }
2194
+
2195
+ function parse( $file ) {
2196
+ $wxr_version = $in_multiline = false;
2197
+
2198
+ $multiline_content = '';
2199
+
2200
+ $multiline_tags = array(
2201
+ 'item' => array( 'posts', array( $this, 'process_post' ) ),
2202
+ 'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
2203
+ 'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
2204
+ 'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
2205
+ );
2206
+
2207
+ $fp = $this->fopen( $file, 'r' );
2208
+ if ( $fp ) {
2209
+ while ( ! $this->feof( $fp ) ) {
2210
+ $importline = rtrim( $this->fgets( $fp ) );
2211
+
2212
+ if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
2213
+ $wxr_version = $version[1];
2214
+
2215
+ if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
2216
+ preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
2217
+ $this->base_url = $url[1];
2218
+ continue;
2219
+ }
2220
+
2221
+ if ( false !== strpos( $importline, '<wp:author>' ) ) {
2222
+ preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
2223
+ $a = $this->process_author( $author[1] );
2224
+ $this->authors[$a['author_login']] = $a;
2225
+ continue;
2226
+ }
2227
+
2228
+ foreach ( $multiline_tags as $tag => $handler ) {
2229
+ // Handle multi-line tags on a singular line
2230
+ if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
2231
+ $this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );
2232
+
2233
+ } elseif ( false !== ( $pos = strpos( $importline, "<$tag>" ) ) ) {
2234
+ // Take note of any content after the opening tag
2235
+ $multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) );
2236
+
2237
+ // We don't want to have this line added to `$is_multiline` below.
2238
+ $importline = '';
2239
+ $in_multiline = $tag;
2240
+
2241
+ } elseif ( false !== ( $pos = strpos( $importline, "</$tag>" ) ) ) {
2242
+ $in_multiline = false;
2243
+ $multiline_content .= trim( substr( $importline, 0, $pos ) );
2244
+
2245
+ $this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content );
2246
+ }
2247
+ }
2248
+
2249
+ if ( $in_multiline && $importline ) {
2250
+ $multiline_content .= $importline . "\n";
2251
+ }
2252
+ }
2253
+
2254
+ $this->fclose($fp);
2255
+ }
2256
+
2257
+ if ( ! $wxr_version )
2258
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
2259
+
2260
+ return array(
2261
+ 'authors' => $this->authors,
2262
+ 'posts' => $this->posts,
2263
+ 'categories' => $this->categories,
2264
+ 'tags' => $this->tags,
2265
+ 'terms' => $this->terms,
2266
+ 'base_url' => $this->base_url,
2267
+ 'version' => $wxr_version
2268
+ );
2269
+ }
2270
+
2271
+ function get_tag( $string, $tag ) {
2272
+ preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
2273
+ if ( isset( $return[1] ) ) {
2274
+ if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
2275
+ if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
2276
+ preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
2277
+ $return = '';
2278
+ foreach( $matches[1] as $match )
2279
+ $return .= $match;
2280
+ } else {
2281
+ $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
2282
+ }
2283
+ } else {
2284
+ $return = $return[1];
2285
+ }
2286
+ } else {
2287
+ $return = '';
2288
+ }
2289
+ return $return;
2290
+ }
2291
+
2292
+ function process_category( $c ) {
2293
+ return array(
2294
+ 'term_id' => $this->get_tag( $c, 'wp:term_id' ),
2295
+ 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
2296
+ 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
2297
+ 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
2298
+ 'category_description' => $this->get_tag( $c, 'wp:category_description' ),
2299
+ );
2300
+ }
2301
+
2302
+ function process_tag( $t ) {
2303
+ return array(
2304
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
2305
+ 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
2306
+ 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
2307
+ 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
2308
+ );
2309
+ }
2310
+
2311
+ function process_term( $t ) {
2312
+ return array(
2313
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
2314
+ 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
2315
+ 'slug' => $this->get_tag( $t, 'wp:term_slug' ),
2316
+ 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
2317
+ 'term_name' => $this->get_tag( $t, 'wp:term_name' ),
2318
+ 'term_description' => $this->get_tag( $t, 'wp:term_description' ),
2319
+ );
2320
+ }
2321
+
2322
+ function process_author( $a ) {
2323
+ return array(
2324
+ 'author_id' => $this->get_tag( $a, 'wp:author_id' ),
2325
+ 'author_login' => $this->get_tag( $a, 'wp:author_login' ),
2326
+ 'author_email' => $this->get_tag( $a, 'wp:author_email' ),
2327
+ 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
2328
+ 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
2329
+ 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
2330
+ );
2331
+ }
2332
+
2333
+ function process_post( $post ) {
2334
+ $post_id = $this->get_tag( $post, 'wp:post_id' );
2335
+ $post_title = $this->get_tag( $post, 'title' );
2336
+ $post_date = $this->get_tag( $post, 'wp:post_date' );
2337
+ $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
2338
+ $comment_status = $this->get_tag( $post, 'wp:comment_status' );
2339
+ $ping_status = $this->get_tag( $post, 'wp:ping_status' );
2340
+ $status = $this->get_tag( $post, 'wp:status' );
2341
+ $post_name = $this->get_tag( $post, 'wp:post_name' );
2342
+ $post_parent = $this->get_tag( $post, 'wp:post_parent' );
2343
+ $menu_order = $this->get_tag( $post, 'wp:menu_order' );
2344
+ $post_type = $this->get_tag( $post, 'wp:post_type' );
2345
+ $post_password = $this->get_tag( $post, 'wp:post_password' );
2346
+ $is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
2347
+ $guid = $this->get_tag( $post, 'guid' );
2348
+ $post_author = $this->get_tag( $post, 'dc:creator' );
2349
+
2350
+ $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
2351
+ $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
2352
+ $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
2353
+ $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
2354
+
2355
+ $post_content = $this->get_tag( $post, 'content:encoded' );
2356
+ $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
2357
+ $post_content = str_replace( '<br>', '<br />', $post_content );
2358
+ $post_content = str_replace( '<hr>', '<hr />', $post_content );
2359
+
2360
+ $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt',
2361
+ 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent',
2362
+ 'menu_order', 'post_type', 'post_password', 'is_sticky'
2363
+ );
2364
+
2365
+ $attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
2366
+ if ( $attachment_url )
2367
+ $postdata['attachment_url'] = $attachment_url;
2368
+
2369
+ preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
2370
+ foreach ( $terms as $t ) {
2371
+ $post_terms[] = array(
2372
+ 'slug' => $t[2],
2373
+ 'domain' => $t[1],
2374
+ 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
2375
+ );
2376
+ }
2377
+ if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
2378
+
2379
+ preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
2380
+ $comments = $comments[1];
2381
+ if ( $comments ) {
2382
+ foreach ( $comments as $comment ) {
2383
+ preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
2384
+ $commentmeta = $commentmeta[1];
2385
+ $c_meta = array();
2386
+ foreach ( $commentmeta as $m ) {
2387
+ $c_meta[] = array(
2388
+ 'key' => $this->get_tag( $m, 'wp:meta_key' ),
2389
+ 'value' => $this->get_tag( $m, 'wp:meta_value' ),
2390
+ );
2391
+ }
2392
+
2393
+ $post_comments[] = array(
2394
+ 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
2395
+ 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
2396
+ 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
2397
+ 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
2398
+ 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
2399
+ 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
2400
+ 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
2401
+ 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
2402
+ 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
2403
+ 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
2404
+ 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
2405
+ 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
2406
+ 'commentmeta' => $c_meta,
2407
+ );
2408
+ }
2409
+ }
2410
+ if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
2411
+
2412
+ preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
2413
+ $postmeta = $postmeta[1];
2414
+ if ( $postmeta ) {
2415
+ foreach ( $postmeta as $p ) {
2416
+ $post_postmeta[] = array(
2417
+ 'key' => $this->get_tag( $p, 'wp:meta_key' ),
2418
+ 'value' => $this->get_tag( $p, 'wp:meta_value' ),
2419
+ );
2420
+ }
2421
+ }
2422
+ if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
2423
+
2424
+ return $postdata;
2425
+ }
2426
+
2427
+ function _normalize_tag( $matches ) {
2428
+ return '<' . strtolower( $matches[1] );
2429
+ }
2430
+
2431
+ function fopen( $filename, $mode = 'r' ) {
2432
+ if ( $this->has_gzip )
2433
+ return gzopen( $filename, $mode );
2434
+ return fopen( $filename, $mode );
2435
+ }
2436
+
2437
+ function feof( $fp ) {
2438
+ if ( $this->has_gzip )
2439
+ return gzeof( $fp );
2440
+ return feof( $fp );
2441
+ }
2442
+
2443
+ function fgets( $fp, $len = 8192 ) {
2444
+ if ( $this->has_gzip )
2445
+ return gzgets( $fp, $len );
2446
+ return fgets( $fp, $len );
2447
+ }
2448
+
2449
+ function fclose( $fp ) {
2450
+ if ( $this->has_gzip )
2451
+ return gzclose( $fp );
2452
+ return fclose( $fp );
2453
+ }
2454
+ }
includes/class-wpvivid-restore-data.php CHANGED
@@ -69,7 +69,7 @@ class WPvivid_restore_data
69
 
70
  public function delete_temp_files()
71
  {
72
- $backup=WPvivid_Backuplist::get_backup_by_id($this->restore_cache['task_id']);
73
  $backup_item=new WPvivid_Backup_Item($backup);
74
 
75
  foreach($this->restore_cache['restore_tasks'] as $index => $task)
@@ -98,7 +98,7 @@ class WPvivid_restore_data
98
  $temp_files=$backup_item->get_child_files($file);
99
  foreach ($temp_files as $delete_file)
100
  {
101
- $path= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$delete_file['file_name'];
102
  $this->write_log('clean file:'.$path,'notice');
103
  @unlink($path);
104
  }
69
 
70
  public function delete_temp_files()
71
  {
72
+ $backup=$this->get_backup_data();
73
  $backup_item=new WPvivid_Backup_Item($backup);
74
 
75
  foreach($this->restore_cache['restore_tasks'] as $index => $task)
98
  $temp_files=$backup_item->get_child_files($file);
99
  foreach ($temp_files as $delete_file)
100
  {
101
+ $path= $backup_item->get_local_path().$delete_file['file_name'];
102
  $this->write_log('clean file:'.$path,'notice');
103
  @unlink($path);
104
  }
includes/class-wpvivid-restore-database.php CHANGED
@@ -31,7 +31,6 @@ class WPvivid_RestoreDB
31
  private $new_upload_url;
32
 
33
  private $current_setting;
34
-
35
  //private $db;
36
  //private $skip_query;
37
 
@@ -316,12 +315,11 @@ class WPvivid_RestoreDB
316
  }
317
  }
318
  }
319
- else
320
- {
321
- WPvivid_Setting::import_json_to_setting($this->current_setting);
322
- do_action('wpvivid_reset_schedule');
323
- //WPvivid_Schedule::reset_schedule();
324
- }
325
 
326
  fclose($sql_handle);
327
  $ret['result']=WPVIVID_SUCCESS;
@@ -731,9 +729,9 @@ class WPvivid_RestoreDB
731
 
732
  if(substr($table_name, strlen($this->new_prefix))=='options')
733
  {
734
- WPvivid_Setting::import_json_to_setting($this->current_setting);
735
  //WPvivid_Schedule::reset_schedule();
736
- do_action('wpvivid_reset_schedule');
737
  if($this->old_prefix!=$this->new_prefix)
738
  {
739
  $update_query ='UPDATE '.$table_name.' SET option_name="'.$this->new_prefix.'user_roles" WHERE option_name="'.$this->old_prefix.'user_roles";';
@@ -1075,6 +1073,11 @@ class WPvivid_RestoreDB
1075
  return $mix_link;
1076
  }
1077
 
 
 
 
 
 
1078
  private function replace_string($old_string)
1079
  {
1080
  if(!is_string($old_string))
@@ -1086,7 +1089,7 @@ class WPvivid_RestoreDB
1086
  {
1087
  $remove_http_link=$this->get_remove_http_link($this->old_site_url);
1088
  $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1089
- if(strpos($new_remove_http_link,$remove_http_link)!==false)
1090
  {
1091
  return $this->replace_string_ex($old_string);
1092
  }
@@ -1116,6 +1119,9 @@ class WPvivid_RestoreDB
1116
  $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1117
  }
1118
  }
 
 
 
1119
  }
1120
 
1121
  if($this->old_home_url!=$this->new_home_url)
@@ -1170,6 +1176,9 @@ class WPvivid_RestoreDB
1170
  $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1171
  }
1172
  }
 
 
 
1173
  }
1174
 
1175
  if($this->old_home_url!=$this->new_home_url&&$this->old_home_url!=$this->old_site_url)
31
  private $new_upload_url;
32
 
33
  private $current_setting;
 
34
  //private $db;
35
  //private $skip_query;
36
 
315
  }
316
  }
317
  }
318
+
319
+ WPvivid_Setting::import_json_to_setting($this->current_setting);
320
+ do_action('wpvivid_reset_schedule');
321
+ do_action('wpvivid_do_after_restore_db');
322
+
 
323
 
324
  fclose($sql_handle);
325
  $ret['result']=WPVIVID_SUCCESS;
729
 
730
  if(substr($table_name, strlen($this->new_prefix))=='options')
731
  {
732
+ //WPvivid_Setting::import_json_to_setting($this->current_setting);
733
  //WPvivid_Schedule::reset_schedule();
734
+ //do_action('wpvivid_reset_schedule');
735
  if($this->old_prefix!=$this->new_prefix)
736
  {
737
  $update_query ='UPDATE '.$table_name.' SET option_name="'.$this->new_prefix.'user_roles" WHERE option_name="'.$this->old_prefix.'user_roles";';
1073
  return $mix_link;
1074
  }
1075
 
1076
+ private function get_http_link_at_quota($url)
1077
+ {
1078
+ return str_replace('/','\/',$url);
1079
+ }
1080
+
1081
  private function replace_string($old_string)
1082
  {
1083
  if(!is_string($old_string))
1089
  {
1090
  $remove_http_link=$this->get_remove_http_link($this->old_site_url);
1091
  $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1092
+ if($remove_http_link!==false&&$new_remove_http_link!==false&&strpos($new_remove_http_link,$remove_http_link)!==false)
1093
  {
1094
  return $this->replace_string_ex($old_string);
1095
  }
1119
  $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1120
  }
1121
  }
1122
+ $quota_old_site_url=$this->get_http_link_at_quota($this->old_site_url);
1123
+ $quota_new_site_url=$this->get_http_link_at_quota($this->new_site_url);
1124
+ $old_string=str_replace($quota_old_site_url,$quota_new_site_url,$old_string);
1125
  }
1126
 
1127
  if($this->old_home_url!=$this->new_home_url)
1176
  $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1177
  }
1178
  }
1179
+ $quota_old_site_url=$this->get_http_link_at_quota($this->old_site_url);
1180
+ $quota_new_site_url=$this->get_http_link_at_quota($this->new_site_url);
1181
+ $old_string=str_replace($quota_old_site_url,$quota_new_site_url,$old_string);
1182
  }
1183
 
1184
  if($this->old_home_url!=$this->new_home_url&&$this->old_home_url!=$this->old_site_url)
includes/class-wpvivid-restore-site.php CHANGED
@@ -14,7 +14,9 @@ class WPvivid_RestoreSite
14
  global $wpvivid_plugin;
15
  if(isset($option['has_child']))
16
  {
17
- $root_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
 
 
18
 
19
  if(!file_exists($root_path))
20
  {
@@ -25,24 +27,29 @@ class WPvivid_RestoreSite
25
  $all_files = array();
26
  foreach ($files as $file)
27
  {
28
- $all_files[] =WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
29
  }
30
 
31
  if(isset($option['extract_child_files']))
32
  {
33
- return $zip -> extract_ex($all_files,$root_path,$option['extract_child_files']);
34
  }
35
  else
36
  {
37
- return $zip -> extract($all_files,$root_path);
38
  }
39
  }
40
  else
41
  {
 
 
 
 
42
  $is_type_db = false;
43
  $is_type_db = apply_filters('wpvivid_check_type_database', $is_type_db, $option);
44
- if($is_type_db){
45
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database';
 
46
  if(file_exists($path))
47
  {
48
  @mkdir($path);
@@ -52,7 +59,7 @@ class WPvivid_RestoreSite
52
  $all_files = array();
53
  foreach ($files as $file)
54
  {
55
- $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
56
  }
57
 
58
  $ret= $zip -> extract($all_files,$path);
@@ -87,7 +94,7 @@ class WPvivid_RestoreSite
87
  $zip = new WPvivid_ZipClass();
88
  $all_files = array();
89
  foreach ($files as $file) {
90
- $all_files[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . WPvivid_Setting::get_backupdir() . DIRECTORY_SEPARATOR . $file;
91
  }
92
 
93
  $wpvivid_plugin->restore_data->write_log('restore from files:' . json_encode($all_files), 'notice');
@@ -161,129 +168,10 @@ class WPvivid_RestoreSite
161
  return rmdir($dir);
162
  }
163
 
164
- public function pre_restore($path,$save_old_path,$include_path,$exclude_path)
165
- {
166
- if(!file_exists($save_old_path))
167
- @mkdir($save_old_path);
168
- return $this->copy_old_files($path,$save_old_path,$path,$include_path,$exclude_path);
169
- }
170
-
171
- private function copy_old_files($path,$save_old_path,$root_path,$include_path,$exclude_path)
172
- {
173
- $result = array('result'=>WPVIVID_SUCCESS);
174
-
175
- $handler=opendir($path);
176
- while(($filename=readdir($handler))!==false)
177
- {
178
- if($filename != "." && $filename != "..")
179
- {
180
- $new_dir=$save_old_path.str_replace($root_path,'',$path.DIRECTORY_SEPARATOR.$filename);
181
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename))
182
- {
183
- if(!empty($include_path))
184
- {
185
- if( $this->has_include_dir($path.DIRECTORY_SEPARATOR.$filename,$include_path,$root_path))
186
- {
187
- if(!file_exists($new_dir))
188
- @mkdir($new_dir);
189
- $this->copy_old_files($path.DIRECTORY_SEPARATOR.$filename,$save_old_path,$root_path,$include_path,$exclude_path);
190
- }
191
- else
192
- {
193
- continue;
194
- }
195
- }
196
-
197
- if(!empty($exclude_path))
198
- {
199
- $check_path=$this->transfer_path($path.DIRECTORY_SEPARATOR.$filename);
200
- if(in_array($check_path,$exclude_path))
201
- {
202
- continue;
203
- }
204
- }
205
-
206
- if(!file_exists($new_dir))
207
- @mkdir($new_dir);
208
- $this->copy_old_files($path.DIRECTORY_SEPARATOR.$filename,$save_old_path,$root_path,$include_path,$exclude_path);
209
- }else {
210
- if(!file_exists($new_dir))
211
- {
212
- @copy($path.DIRECTORY_SEPARATOR.$filename,$new_dir);
213
- }
214
- }
215
- }
216
- }
217
- if($handler)
218
- @closedir($handler);
219
- return $result;
220
- }
221
-
222
  private function transfer_path($path)
223
  {
224
  $path = str_replace('\\','/',$path);
225
  $values = explode('/',$path);
226
  return implode(DIRECTORY_SEPARATOR,$values);
227
  }
228
-
229
- private function has_include_dir($path,$include_path,$root)
230
- {
231
- $path=$this->transfer_path($path);
232
- foreach ($include_path as $needed_path)
233
- {
234
- $needed_path=$this->transfer_path($root.DIRECTORY_SEPARATOR.$needed_path);
235
- if(strpos($path,$needed_path)!==false)
236
- {
237
- return true;
238
- }
239
- }
240
- return false;
241
- }
242
-
243
- private function _restore($restorePath,$path , $files){
244
- $zip = new WPvivid_ZipClass();
245
- $allfiles = array();
246
- foreach ($files as $file){
247
- $allfiles[] = $path.DIRECTORY_SEPARATOR.$file['file_name'];
248
- }
249
- return $zip -> zipextract($restorePath , $allfiles);
250
- }
251
-
252
- public function restore_copy($data){
253
- $src_path = $data['data']['src'];
254
- $dst_path = $data['data']['dst'];
255
- $replace_path = $data['data']['replace'];
256
- return $this -> _restore_copy_loop($src_path,$dst_path,$replace_path);
257
- }
258
- private function _restore_copy_loop($path,$temp_path,$replace_path){
259
- $result = array('result'=>WPVIVID_SUCCESS);
260
- if(empty($path)) {
261
- return array('result'=>'failed','error'=>'The old folder not found. It may be deleted, renamed, or moved. Please verify the folder exists.');
262
- }
263
- $handler=opendir($path);
264
- while(($filename=readdir($handler))!==false)
265
- {
266
- if($filename != "." && $filename != "..")
267
- {
268
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename))
269
- {
270
- @mkdir(str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename));
271
- $result = $this->_restore_copy_loop($path.DIRECTORY_SEPARATOR.$filename,$temp_path,$replace_path);
272
- if($result['result'] != WPVIVID_SUCCESS)
273
- break;
274
- }else{
275
- if(file_exists($path.DIRECTORY_SEPARATOR.$filename))
276
- {
277
- if(!copy($path.DIRECTORY_SEPARATOR.$filename,str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename))){
278
- $result = array('result'=>'failed','error'=>'Copying '.$path.DIRECTORY_SEPARATOR.$filename.' into '.$temp_path.DIRECTORY_SEPARATOR.$filename.' failed. The file may be occupied, or the folder may not be granted a permission to write. Please try again.');
279
- break;
280
- }
281
- }
282
- }
283
- }
284
- }
285
- if($handler)
286
- @closedir($handler);
287
- return $result;
288
- }
289
  }
14
  global $wpvivid_plugin;
15
  if(isset($option['has_child']))
16
  {
17
+ $backup=$wpvivid_plugin->restore_data->get_backup_data();
18
+ $backup_item=new WPvivid_Backup_Item($backup);
19
+ $root_path=$backup_item->get_local_path();
20
 
21
  if(!file_exists($root_path))
22
  {
27
  $all_files = array();
28
  foreach ($files as $file)
29
  {
30
+ $all_files[] =$root_path.$file;
31
  }
32
 
33
  if(isset($option['extract_child_files']))
34
  {
35
+ return $zip -> extract_ex($all_files,untrailingslashit($root_path),$option['extract_child_files']);
36
  }
37
  else
38
  {
39
+ return $zip -> extract($all_files,untrailingslashit($root_path));
40
  }
41
  }
42
  else
43
  {
44
+ $backup=$wpvivid_plugin->restore_data->get_backup_data();
45
+ $backup_item=new WPvivid_Backup_Item($backup);
46
+ $local_path=$backup_item->get_local_path();
47
+
48
  $is_type_db = false;
49
  $is_type_db = apply_filters('wpvivid_check_type_database', $is_type_db, $option);
50
+ if($is_type_db)
51
+ {
52
+ $path = $local_path.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database';
53
  if(file_exists($path))
54
  {
55
  @mkdir($path);
59
  $all_files = array();
60
  foreach ($files as $file)
61
  {
62
+ $all_files[] = $local_path.$file;
63
  }
64
 
65
  $ret= $zip -> extract($all_files,$path);
94
  $zip = new WPvivid_ZipClass();
95
  $all_files = array();
96
  foreach ($files as $file) {
97
+ $all_files[] = $local_path. $file;
98
  }
99
 
100
  $wpvivid_plugin->restore_data->write_log('restore from files:' . json_encode($all_files), 'notice');
168
  return rmdir($dir);
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  private function transfer_path($path)
172
  {
173
  $path = str_replace('\\','/',$path);
174
  $values = explode('/',$path);
175
  return implode(DIRECTORY_SEPARATOR,$values);
176
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  }
includes/class-wpvivid-restore.php CHANGED
@@ -27,7 +27,6 @@ class WPvivid_Restore
27
  }
28
  else if($next_task===WPVIVID_RESTORE_RUNNING)
29
  {
30
- //$wpvivid_plugin->restore_data->update_error('A restore task is already running.');
31
  $wpvivid_plugin->restore_data->write_log('A restore task is already running.','error');
32
  return array('result'=>WPVIVID_FAILED,'error'=> 'A restore task is already running.');
33
  }
@@ -64,18 +63,21 @@ class WPvivid_Restore
64
  $option=array_merge($option,$restore_task['option']);
65
  $is_type_db = false;
66
  $is_type_db = apply_filters('wpvivid_check_type_database', $is_type_db, $option);
67
- if($is_type_db){
 
68
  $restore_site = new WPvivid_RestoreSite();
69
  $wpvivid_plugin->restore_data->write_log('Start restoring '.$restore_task['files'][0],'notice');
70
  $ret= $restore_site -> restore($option,$restore_task['files']);
71
- if($ret['result']==WPVIVID_SUCCESS){
72
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR;
 
73
  $sql_file = $backup_item->get_sql_file($restore_task['files'][0]);
74
  $wpvivid_plugin->restore_data->write_log('sql file: '.$sql_file,'notice');
75
  $restore_db=new WPvivid_RestoreDB();
76
  $check_is_remove = false;
77
  $check_is_remove = apply_filters('wpvivid_check_remove_restore_database', $check_is_remove, $option);
78
- if(!$check_is_remove) {
 
79
  $ret = $restore_db->restore($path, $sql_file, $option);
80
  $wpvivid_plugin->restore_data->write_log('Finished restoring '.$restore_task['files'][0],'notice');
81
  $wpvivid_plugin->restore_data->update_need_unzip_file($restore_task['index'],$restore_task['files']);
@@ -103,11 +105,4 @@ class WPvivid_Restore
103
  return $ret;
104
  }
105
  }
106
-
107
- private function transfer_path($path)
108
- {
109
- $path = str_replace('\\','/',$path);
110
- $values = explode('/',$path);
111
- return implode(DIRECTORY_SEPARATOR,$values);
112
- }
113
  }
27
  }
28
  else if($next_task===WPVIVID_RESTORE_RUNNING)
29
  {
 
30
  $wpvivid_plugin->restore_data->write_log('A restore task is already running.','error');
31
  return array('result'=>WPVIVID_FAILED,'error'=> 'A restore task is already running.');
32
  }
63
  $option=array_merge($option,$restore_task['option']);
64
  $is_type_db = false;
65
  $is_type_db = apply_filters('wpvivid_check_type_database', $is_type_db, $option);
66
+ if($is_type_db)
67
+ {
68
  $restore_site = new WPvivid_RestoreSite();
69
  $wpvivid_plugin->restore_data->write_log('Start restoring '.$restore_task['files'][0],'notice');
70
  $ret= $restore_site -> restore($option,$restore_task['files']);
71
+ if($ret['result']==WPVIVID_SUCCESS)
72
+ {
73
+ $path = $backup_item->get_local_path().WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR;
74
  $sql_file = $backup_item->get_sql_file($restore_task['files'][0]);
75
  $wpvivid_plugin->restore_data->write_log('sql file: '.$sql_file,'notice');
76
  $restore_db=new WPvivid_RestoreDB();
77
  $check_is_remove = false;
78
  $check_is_remove = apply_filters('wpvivid_check_remove_restore_database', $check_is_remove, $option);
79
+ if(!$check_is_remove)
80
+ {
81
  $ret = $restore_db->restore($path, $sql_file, $option);
82
  $wpvivid_plugin->restore_data->write_log('Finished restoring '.$restore_task['files'][0],'notice');
83
  $wpvivid_plugin->restore_data->update_need_unzip_file($restore_task['index'],$restore_task['files']);
105
  return $ret;
106
  }
107
  }
 
 
 
 
 
 
 
108
  }
includes/class-wpvivid-setting.php CHANGED
@@ -524,7 +524,7 @@ class WPvivid_Setting
524
  {
525
  foreach ($json['data'] as $option_name=>$option)
526
  {
527
- self::update_option($option_name,$option);
528
  }
529
  }
530
 
524
  {
525
  foreach ($json['data'] as $option_name=>$option)
526
  {
527
+ update_option($option_name,$option);
528
  }
529
  }
530
 
includes/class-wpvivid-tab-page-container.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WPvivid_Tab_Page_Container
4
+ {
5
+ public $tabs;
6
+ public $container_id;
7
+ public $is_parent_tab=1;
8
+
9
+ public function __construct( $args = array() )
10
+ {
11
+ $this->tabs=array();
12
+ $this->container_id=uniqid('tab-');
13
+ }
14
+
15
+ public function add_tab($title,$slug,$callback,$args=array())
16
+ {
17
+ $new_tab['title']=$title;
18
+ $new_tab['slug']=$slug;
19
+ $new_tab['page']=$callback;
20
+ foreach ($args as $key=>$arg)
21
+ {
22
+ $new_tab[$key]=$arg;
23
+ if($key === 'is_parent_tab') {
24
+ $this->is_parent_tab = $arg;
25
+ }
26
+ }
27
+
28
+ $this->tabs[]=$new_tab;
29
+ }
30
+
31
+ public function set_tab($tabs)
32
+ {
33
+ foreach ($tabs as $tab)
34
+ {
35
+ $new_tab['title']=$tab['title'];
36
+ $new_tab['slug']=$tab['slug'];
37
+ $new_tab['page']=$tab['page'];
38
+ $this->tabs[]=$new_tab;
39
+ }
40
+ }
41
+
42
+ public function display()
43
+ {
44
+ ?>
45
+ <div id="<?php echo $this->container_id?>">
46
+ <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
47
+ <?php
48
+ $this->display_tabs();
49
+ ?>
50
+ </h2>
51
+ <?php
52
+ if($this->is_parent_tab){
53
+ ?>
54
+ <div class="wrap" style="max-width:1720px;">
55
+ <div id="poststuff" style="padding-top: 0;">
56
+ <div id="post-body" class="metabox-holder columns-2">
57
+ <div id="post-body-content">
58
+ <div class="inside" style="margin-top:0;">
59
+ <div>
60
+ <?php
61
+ $this->display_page();
62
+ ?>
63
+ </div>
64
+ </div>
65
+ </div>
66
+
67
+ <div id="postbox-container-1" class="postbox-container">
68
+ <div class="meta-box-sortables">
69
+ <?php
70
+ if(has_filter('wpvivid_add_side_bar')){
71
+ $side_bar = '1';
72
+ }
73
+ else{
74
+ $side_bar = '0';
75
+ }
76
+ //$side_bar = '';
77
+ $side_bar = apply_filters('wpvivid_add_side_bar', $side_bar, false);
78
+ echo $side_bar;
79
+ ?>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ <br class="clear">
84
+ </div>
85
+ </div>
86
+ <?php
87
+ }
88
+ else{
89
+ ?>
90
+ <div>
91
+ <?php
92
+ $this->display_page();
93
+ ?>
94
+ </div>
95
+ <?php
96
+ }
97
+ ?>
98
+ </div>
99
+ <script>
100
+ jQuery('#<?php echo $this->container_id?>').on("click",".<?php echo $this->container_id?>-tab",function()
101
+ {
102
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-tab' ).each(function()
103
+ {
104
+ jQuery(this).removeClass( "nav-tab-active" );
105
+ });
106
+
107
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-content' ).each(function()
108
+ {
109
+ jQuery(this).hide();
110
+ });
111
+
112
+ var id=jQuery(this).attr('id');
113
+ id= id.substr(12);
114
+
115
+ jQuery("#wpvivid_page_"+id).show();
116
+ jQuery(this).addClass( "nav-tab-active" );
117
+ });
118
+
119
+ jQuery('#<?php echo $this->container_id?>').on("click",".nav-tab-delete-img",function(event)
120
+ {
121
+ event.stopPropagation();
122
+ var redirect=jQuery(this).attr('redirect');
123
+ jQuery(this).parent().hide();
124
+
125
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-tab' ).each(function()
126
+ {
127
+ jQuery(this).removeClass( "nav-tab-active" );
128
+ });
129
+
130
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-content' ).each(function()
131
+ {
132
+ jQuery(this).hide();
133
+ });
134
+
135
+ jQuery("#wpvivid_page_"+redirect).show();
136
+ jQuery(this).addClass( "nav-tab-active" );
137
+ });
138
+
139
+ jQuery(document).ready(function($)
140
+ {
141
+ jQuery(document).on('<?php echo $this->container_id?>-show', function(event,id)
142
+ {
143
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-tab' ).each(function()
144
+ {
145
+ jQuery(this).removeClass( "nav-tab-active" );
146
+ });
147
+
148
+ jQuery('#<?php echo $this->container_id?>').find( '.<?php echo $this->container_id?>-content' ).each(function()
149
+ {
150
+ jQuery(this).hide();
151
+ });
152
+
153
+ jQuery("#wpvivid_page_"+id).show();
154
+ jQuery("#wpvivid_tab_"+id).show();
155
+ jQuery("#wpvivid_tab_"+id).addClass( "nav-tab-active" );
156
+ });
157
+ });
158
+ </script>
159
+ <?php
160
+ }
161
+
162
+ public function display_tabs()
163
+ {
164
+ $first=true;
165
+
166
+ foreach ($this->tabs as $tab)
167
+ {
168
+ $class='nav-tab '.$this->container_id.'-tab';
169
+ if($first)
170
+ {
171
+ $class.=' nav-tab-active';
172
+ $first=false;
173
+ }
174
+
175
+ $style='';
176
+
177
+ if(isset($tab['hide']))
178
+ {
179
+ $style.=' display: none';
180
+ }
181
+
182
+ if(isset($tab['can_delete']))
183
+ {
184
+ $class.=' delete';
185
+ }
186
+
187
+ echo '<a href="#" id="wpvivid_tab_'.$tab['slug'].'" class="'.$class.'" style="'.$style.'">';
188
+
189
+ if(isset($tab['can_delete']))
190
+ {
191
+ echo '<div style="margin-right: 15px;">'.__($tab['title'], 'wpvivid').'</div>';
192
+ if(isset($tab['redirect']))
193
+ {
194
+ echo '<div class="nav-tab-delete-img" redirect="'.$tab['redirect'].'">
195
+ <img src="'.esc_url( WPVIVID_PLUGIN_URL.'/admin/partials/images/delete-tab.png' ).'" style="vertical-align:middle; cursor:pointer;">
196
+ </div>';
197
+ }
198
+ else
199
+ {
200
+ echo '<div class="nav-tab-delete-img">
201
+ <img src="'.esc_url( WPVIVID_PLUGIN_URL.'/admin/partials/images/delete-tab.png' ).'" style="vertical-align:middle; cursor:pointer;">
202
+ </div>';
203
+ }
204
+ }
205
+ else
206
+ {
207
+ echo __($tab['title'], 'wpvivid');
208
+ }
209
+ echo '</a>';
210
+ }
211
+ }
212
+
213
+ public function display_page()
214
+ {
215
+ $first=true;
216
+ foreach ($this->tabs as $tab)
217
+ {
218
+ //delete
219
+ $style='display: none;';
220
+ if($first)
221
+ {
222
+ if(isset($tab['hide']))
223
+ {
224
+
225
+ }
226
+ else
227
+ {
228
+ $style='';
229
+ $first=false;
230
+ }
231
+ }
232
+
233
+ $class=$this->container_id.'-content';
234
+
235
+ echo '<div id="wpvivid_page_'.$tab['slug'].'" class="'.$class.'" style="'.$style.'">';
236
+ call_user_func($tab['page']);
237
+ echo '</div>';
238
+ }
239
+ }
240
+ }
includes/class-wpvivid-zipclass.php CHANGED
@@ -623,8 +623,9 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
623
  return implode(DIRECTORY_SEPARATOR,$values);
624
  }
625
 
626
- public function get_json_data($path)
627
  {
 
628
  $archive = new PclZip($path);
629
  $list = $archive->listContent();
630
  if($list == false){
@@ -633,9 +634,9 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
633
  else {
634
  $b_exist = false;
635
  foreach ($list as $item) {
636
- if (basename($item['filename']) === 'wpvivid_package_info.json') {
637
  $b_exist = true;
638
- $result = $archive->extract(PCLZIP_OPT_BY_NAME, 'wpvivid_package_info.json', PCLZIP_OPT_EXTRACT_AS_STRING);
639
  if ($result != 0) {
640
  return array('result'=>WPVIVID_SUCCESS,'json_data'=>$result[0]['content']);
641
  } else {
623
  return implode(DIRECTORY_SEPARATOR,$values);
624
  }
625
 
626
+ public function get_json_data($path, $json_type = 'backup')
627
  {
628
+ $json_file_name = $json_type === 'backup' ? 'wpvivid_package_info.json' : 'wpvivid_export_package_info.json';
629
  $archive = new PclZip($path);
630
  $list = $archive->listContent();
631
  if($list == false){
634
  else {
635
  $b_exist = false;
636
  foreach ($list as $item) {
637
+ if (basename($item['filename']) === $json_file_name) {
638
  $b_exist = true;
639
+ $result = $archive->extract(PCLZIP_OPT_BY_NAME, $json_file_name, PCLZIP_OPT_EXTRACT_AS_STRING);
640
  if ($result != 0) {
641
  return array('result'=>WPVIVID_SUCCESS,'json_data'=>$result[0]['content']);
642
  } else {
includes/class-wpvivid.php CHANGED
@@ -178,10 +178,17 @@ class WPvivid {
178
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-additional-db-method.php';
179
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-extra.php';
180
 
 
 
 
 
 
 
181
  $this->function_realize=new WPvivid_Function_Realize();
182
  $this->migrate=new WPvivid_Migrate();
183
  $this->backup_uploader=new Wpvivid_BackupUploader();
184
  $send_to_site=new WPvivid_Send_to_site();
 
185
  }
186
 
187
  public function init_pclzip_tmp_folder()
@@ -1204,7 +1211,7 @@ class WPvivid {
1204
  $this->end_shutdown_function=false;
1205
  register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
1206
  @ignore_user_abort(true);
1207
- WPvivid_taskmanager::update_backup_task_status($task_id,$restart,'running');
1208
  $this->current_task=WPvivid_taskmanager::get_task($task_id);
1209
  //start a watch task event
1210
  $this->add_monitor_event($task_id);
@@ -3006,7 +3013,7 @@ class WPvivid {
3006
  @ini_set('memory_limit', $memory_limit);
3007
 
3008
  $memory_limit = ini_get('memory_limit');
3009
- $unit = substr($memory_limit, -1);
3010
  if ($unit == 'K')
3011
  {
3012
  $memory_limit_tmp = intval($memory_limit) * 1024;
@@ -3019,6 +3026,9 @@ class WPvivid {
3019
  {
3020
  $memory_limit_tmp = intval($memory_limit) * 1024 * 1024 * 1024;
3021
  }
 
 
 
3022
  if ($memory_limit_tmp < 256 * 1024 * 1024)
3023
  {
3024
  $ret['memory_limit_warning'] = 'memory_limit = ' . $memory_limit . ' is too small. The recommended value is 256M or higher. Too small value could result in a failure of website restore.';
@@ -3196,7 +3206,6 @@ class WPvivid {
3196
 
3197
  $backup_item = new WPvivid_Backup_Item($backup);
3198
 
3199
- $local_path = $backup_item->get_local_path();
3200
  $remote_option = $backup_item->get_remote();
3201
 
3202
  if ($remote_option === false) {
178
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-additional-db-method.php';
179
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-restore-db-extra.php';
180
 
181
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-export-import.php';
182
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-exporter.php';
183
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-importer.php';
184
+
185
+ include_once WPVIVID_PLUGIN_DIR.'/includes/class-wpvivid-tab-page-container.php' ;
186
+
187
  $this->function_realize=new WPvivid_Function_Realize();
188
  $this->migrate=new WPvivid_Migrate();
189
  $this->backup_uploader=new Wpvivid_BackupUploader();
190
  $send_to_site=new WPvivid_Send_to_site();
191
+ $export_import = new WPvivid_Export_Import();
192
  }
193
 
194
  public function init_pclzip_tmp_folder()
1211
  $this->end_shutdown_function=false;
1212
  register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
1213
  @ignore_user_abort(true);
1214
+ WPvivid_taskmanager::update_backup_task_status($task_id,$restart,'running',false,0);
1215
  $this->current_task=WPvivid_taskmanager::get_task($task_id);
1216
  //start a watch task event
1217
  $this->add_monitor_event($task_id);
3013
  @ini_set('memory_limit', $memory_limit);
3014
 
3015
  $memory_limit = ini_get('memory_limit');
3016
+ $unit = strtoupper(substr($memory_limit, -1));
3017
  if ($unit == 'K')
3018
  {
3019
  $memory_limit_tmp = intval($memory_limit) * 1024;
3026
  {
3027
  $memory_limit_tmp = intval($memory_limit) * 1024 * 1024 * 1024;
3028
  }
3029
+ else{
3030
+ $memory_limit_tmp = intval($memory_limit);
3031
+ }
3032
  if ($memory_limit_tmp < 256 * 1024 * 1024)
3033
  {
3034
  $ret['memory_limit_warning'] = 'memory_limit = ' . $memory_limit . ' is too small. The recommended value is 256M or higher. Too small value could result in a failure of website restore.';
3206
 
3207
  $backup_item = new WPvivid_Backup_Item($backup);
3208
 
 
3209
  $remote_option = $backup_item->get_remote();
3210
 
3211
  if ($remote_option === false) {
includes/customclass/class-wpvivid-dropbox.php CHANGED
@@ -476,7 +476,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
476
  <tr>
477
  <td class="plugin-title column-primary">
478
  <div class="wpvivid-storage-form">
479
- <input type="text" class="regular-text" autocomplete="off" value="" readonly="readonly" />
480
  </div>
481
  </td>
482
  <td class="column-description desc">
476
  <tr>
477
  <td class="plugin-title column-primary">
478
  <div class="wpvivid-storage-form">
479
+ <input type="text" class="regular-text" autocomplete="off" value="mywebsite01" readonly="readonly" />
480
  </div>
481
  </td>
482
  <td class="column-description desc">
includes/customclass/class-wpvivid-ftpclass.php CHANGED
@@ -72,7 +72,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
72
  <tr>
73
  <td class="plugin-title column-primary">
74
  <div class="wpvivid-storage-form">
75
- <input type="text" autocomplete="off" class="regular-text" value="" readonly="readonly" />
76
  </div>
77
  </td>
78
  <td class="column-description desc">
72
  <tr>
73
  <td class="plugin-title column-primary">
74
  <div class="wpvivid-storage-form">
75
+ <input type="text" autocomplete="off" class="regular-text" value="21" readonly="readonly" />
76
  </div>
77
  </td>
78
  <td class="column-description desc">
includes/customclass/class-wpvivid-google-drive.php CHANGED
@@ -335,7 +335,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
335
  <tr>
336
  <td class="plugin-title column-primary">
337
  <div class="wpvivid-storage-form">
338
- <input type="text" class="regular-text" autocomplete="off" value="" readonly="readonly" />
339
  </div>
340
  </td>
341
  <td class="column-description desc">
335
  <tr>
336
  <td class="plugin-title column-primary">
337
  <div class="wpvivid-storage-form">
338
+ <input type="text" class="regular-text" autocomplete="off" value="mywebsite01" readonly="readonly" />
339
  </div>
340
  </td>
341
  <td class="column-description desc">
includes/customclass/class-wpvivid-one-drive.php CHANGED
@@ -319,7 +319,7 @@ class WPvivid_one_drive extends WPvivid_Remote
319
  <tr>
320
  <td class="plugin-title column-primary">
321
  <div class="wpvivid-storage-form">
322
- <input type="text" class="regular-text" autocomplete="off" value="" readonly="readonly" />
323
  </div>
324
  </td>
325
  <td class="column-description desc">
319
  <tr>
320
  <td class="plugin-title column-primary">
321
  <div class="wpvivid-storage-form">
322
+ <input type="text" class="regular-text" autocomplete="off" value="mywebsite01" readonly="readonly" />
323
  </div>
324
  </td>
325
  <td class="column-description desc">
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: move, clone, migrate, copy, backup, restore, auto backup, cloud backup
4
  Requires at least: 4.5
5
  Tested up to: 5.2
6
  Requires PHP: 5.3
7
- Stable tag: 0.9.27
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
@@ -166,6 +166,11 @@ Thank you for translating WPvivid Backup Plugin to your languages!
166
  * [Andrew Galas](https://profiles.wordpress.org/andrewgalas) (Polish)
167
 
168
  == Changelog ==
 
 
 
 
 
169
  = 0.9.27 =
170
  - Fixed a fatal error that could be triggered by some firewall or security plugins.
171
  - Refined and simplified the plugin menu in admin menu and top admin bar.
4
  Requires at least: 4.5
5
  Tested up to: 5.2
6
  Requires PHP: 5.3
7
+ Stable tag: 0.9.28
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
166
  * [Andrew Galas](https://profiles.wordpress.org/andrewgalas) (Polish)
167
 
168
  == Changelog ==
169
+ = 0.9.28 =
170
+ - New feature Added: Export and import posts or pages with images in bulk.
171
+ - Fixed: URL replacement failures after website migration in some cases.
172
+ - Fixed: Too many resumption attempts error that occurred when uploading backups in some cases.
173
+ - Fixed some bugs in the plugin code.
174
  = 0.9.27 =
175
  - Fixed a fatal error that could be triggered by some firewall or security plugins.
176
  - Refined and simplified the plugin menu in admin menu and top admin bar.
wpvivid-backuprestore.php CHANGED
@@ -7,7 +7,7 @@
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
10
- * Version: 0.9.27
11
  * Author: WPvivid Team
12
  * Author URI: https://wpvivid.com
13
  * License: GPL-3.0+
@@ -21,7 +21,7 @@ if ( ! defined( 'WPINC' ) ) {
21
  die;
22
  }
23
 
24
- define( 'WPVIVID_PLUGIN_VERSION', '0.9.27' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
@@ -127,7 +127,7 @@ function wpvivid_init_plugin_redirect()
127
 
128
  if($b_redirect_pro)
129
  {
130
- wp_redirect(admin_url().'admin.php?page=WPvivid&tab-pro');
131
  }
132
  else
133
  {
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
10
+ * Version: 0.9.28
11
  * Author: WPvivid Team
12
  * Author URI: https://wpvivid.com
13
  * License: GPL-3.0+
21
  die;
22
  }
23
 
24
+ define( 'WPVIVID_PLUGIN_VERSION', '0.9.28' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
127
 
128
  if($b_redirect_pro)
129
  {
130
+ wp_redirect(admin_url().'admin.php?page=wpvivid-pro');
131
  }
132
  else
133
  {