PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/backupbuddy/destinations/live/_viewfiles_tables.php

https://gitlab.com/mattswann/launch-housing
PHP | 176 lines | 118 code | 40 blank | 18 comment | 25 complexity | e43b9dd206ef0add10ab6bc7d59cfa5c MD5 | raw file
  1. <?php
  2. /* BackupBuddy Stash Live Remote Tables Viewer
  3. *
  4. * @author Dustin Bolton
  5. * @since 7.0
  6. *
  7. */
  8. pb_backupbuddy::verify_nonce();
  9. // @author Dustin Bolton 2015.
  10. // Incoming variables: $destination, $destination_id
  11. if ( isset( $destination['disabled'] ) && ( '1' == $destination['disabled'] ) ) {
  12. die( __( 'This destination is currently disabled based on its settings. Re-enable it under its Advanced Settings.', 'it-l10n-backupbuddy' ) );
  13. }
  14. // Load required files.
  15. require_once( pb_backupbuddy::plugin_path() . '/destinations/live/init.php' );
  16. // Settings.
  17. $destinationID = $destination_id;
  18. if ( isset( pb_backupbuddy::$options['remote_destinations'][$destination_id] ) ) {
  19. if ( ! isset( pb_backupbuddy::$options['remote_destinations'][ $destinationID ] ) ) {
  20. die( 'Error #23793442: Destination not found.' );
  21. }
  22. $settings = &pb_backupbuddy::$options['remote_destinations'][ $destinationID ];
  23. $settings = pb_backupbuddy_destination_live::_formatSettings( $settings );
  24. }
  25. $remotePath = 'wp-content/uploads/backupbuddy_temp/SERIAL/';
  26. // Handle deletion.
  27. if ( pb_backupbuddy::_POST( 'bulk_action' ) == 'delete_backup' ) {
  28. pb_backupbuddy::verify_nonce();
  29. $deleteFiles = array();
  30. foreach( (array)pb_backupbuddy::_POST( 'items' ) as $file ) {
  31. $file = base64_decode( $file );
  32. if ( FALSE !== strstr( $file, '?' ) ) {
  33. $file = substr( $file, 0, strpos( $file, '?' ) );
  34. }
  35. $deleteFiles[] = $file;
  36. }
  37. $deleteSettings = $settings;
  38. $deleteSettings['directory'] = $remotePath;
  39. $response = pb_backupbuddy_destination_live::deleteFiles( $deleteSettings, $deleteFiles );
  40. if ( true === $response ) {
  41. pb_backupbuddy::alert( 'Deleted ' . implode( ', ', $deleteFiles ) . '.' );
  42. } else {
  43. pb_backupbuddy::alert( 'Failed to delete one or more files. Details: `' . $response . '`.' );
  44. }
  45. echo '<br>';
  46. } // end deletion.
  47. // Handle download link
  48. if ( pb_backupbuddy::_GET( 'downloadlink_file' ) != '' ) {
  49. $downloadSettings = $settings;
  50. $downloadSettings['directory'] = $remotePath;
  51. $link = pb_backupbuddy_destination_live::getFileURL( $downloadSettings, base64_decode( pb_backupbuddy::_GET( 'downloadlink_file' ) ) );
  52. pb_backupbuddy::alert( 'You may download this backup (' . base64_decode( pb_backupbuddy::_GET( 'downloadlink_file' ) ) . ') with <a href="' . $link . '">this link</a>. The link is valid for one hour.' );
  53. echo '<br>';
  54. } // end download link.
  55. $marker = null;
  56. if ( '' != pb_backupbuddy::_GET( 'marker' ) ) { // Jump to specific spot.
  57. $marker = base64_decode( urldecode( pb_backupbuddy::_GET( 'marker' ) ) );
  58. }
  59. $files = pb_backupbuddy_destination_live::listFiles( $settings, $remotePath, $marker );
  60. if ( ! is_array( $files ) ) {
  61. pb_backupbuddy::alert( 'Error #892329b: ' . $files );
  62. die();
  63. }
  64. /*
  65. echo '<pre>';
  66. print_r( $files );
  67. echo '</pre>';
  68. */
  69. $backup_list_temp = array();
  70. foreach( (array)$files as $file ) {
  71. $last_modified = strtotime( $file['LastModified'] );
  72. while ( isset( $backup_list_temp[ $last_modified ] ) ) {
  73. $last_modified += 0.1; // Add .1 repeatedly until timestamp is free.
  74. }
  75. $backup_list_temp[ $last_modified ] = $file;
  76. }
  77. krsort( $backup_list_temp );
  78. $backup_list = array();
  79. foreach( $backup_list_temp as $file ) {
  80. $last_modified = strtotime( $file['LastModified'] );
  81. $size = (double) $file['Size'];
  82. $key = base64_encode( $file['Key'] );
  83. $backup_list[ $key ] = array(
  84. array( $key, '<span title="' . $file['Key'] . '">' . $file['Key'] . '</span>' ),
  85. pb_backupbuddy::$format->date( pb_backupbuddy::$format->localize_time( $last_modified ) ) . '<br><span class="description">(' . pb_backupbuddy::$format->time_ago( $last_modified ) . ' ago)</span>',
  86. pb_backupbuddy::$format->file_size( $size ),
  87. );
  88. }
  89. $marker = end( $backup_list );
  90. reset( $backup_list );
  91. $marker = $marker[0][0];
  92. $urlPrefix = pb_backupbuddy::nonce_url( pb_backupbuddy::page_url() . '&live_action=view_files_tables' );
  93. ?>
  94. <center>
  95. <b><?php $backup_count = count( $backup_list ); echo $backup_count; ?> files displayed.</b><br><br>
  96. <?php if ( $backup_count >= $settings['max_filelist_keys'] ) { ?>
  97. <?php if ( '' != pb_backupbuddy::_GET( 'marker' ) ) { ?>
  98. <a href="<?php echo pb_backupbuddy::nonce_url( pb_backupbuddy::page_url() . '&live_action=view_files_tables&marker=' . urlencode( pb_backupbuddy::_GET( 'back' ) ) ); ?>" class="button button-secondary button-tertiary">Previous Page</a>
  99. <?php } ?>
  100. &nbsp;
  101. <a href="<?php echo pb_backupbuddy::nonce_url( pb_backupbuddy::page_url() . '&live_action=view_files_tables&marker=' . urlencode( $marker ) . '&back=' . urlencode( pb_backupbuddy::_GET( 'marker' ) ) ); ?>" class="button button-secondary button-tertiary">Next Page</a>
  102. <?php } ?>
  103. </center>
  104. <?php
  105. // Render table listing files.
  106. if ( count( $backup_list ) == 0 ) {
  107. echo '<center><br><b>';
  108. _e( 'You have not completed sending anything to this destination for this site yet.', 'it-l10n-backupbuddy' );
  109. echo '</b></center>';
  110. } else {
  111. pb_backupbuddy::$ui->list_table(
  112. $backup_list,
  113. array(
  114. 'action' => $urlPrefix,
  115. 'columns' => array( 'Backup File <img src="' . pb_backupbuddy::plugin_url() . '/images/sort_down.png" style="vertical-align: 0px;" title="Sorted alphabetically">', 'Uploaded', 'File Size' ),
  116. 'hover_actions' => array( $urlPrefix . '&downloadlink_file=' => 'Get download link' ),
  117. 'hover_action_column_key' => '0',
  118. 'bulk_actions' => array( 'delete_backup' => 'Delete' ),
  119. 'css' => 'width: 100%;',
  120. )
  121. );
  122. }
  123. ?>
  124. <center>
  125. <b><?php echo count( $backup_list ); ?> files displayed.</b><br><br>
  126. <?php if ( $backup_count >= $settings['max_filelist_keys'] ) { ?>
  127. <?php if ( '' != pb_backupbuddy::_GET( 'marker' ) ) { ?>
  128. <a href="<?php echo pb_backupbuddy::page_url(); ?>&live_action=view_files&marker=<?php echo urlencode( pb_backupbuddy::_GET( 'back' ) ); ?>" class="button button-secondary button-tertiary">Previous Page</a>
  129. <?php } ?>
  130. &nbsp;
  131. <a href="<?php echo pb_backupbuddy::nonce_url( pb_backupbuddy::page_url() . '&live_action=view_files_tables&marker=' . urlencode( $marker ) . '&back=' . urlencode( pb_backupbuddy::_GET( 'marker' ) ) ); ?>" class="button button-secondary button-tertiary">Next Page</a>
  132. <?php } ?>
  133. </center>
  134. <?php
  135. echo '<br style="clear: both;">';
  136. return;