Changeset 549264
- Timestamp:
- 05/26/2012 11:06:33 AM (13 years ago)
- Location:
- backup/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
backup/trunk/backup.php
r548407 r549264 2 2 /* 3 3 Plugin Name: Backup 4 Version: 1.1. 44 Version: 1.1.5 5 5 Plugin URI: http://hel.io/wordpress/backup/ 6 6 Description: Backup your WordPress website to Google Drive. … … 27 27 } 28 28 29 // check allow_url_fopen29 // check zip extension 30 30 if(!extension_loaded('zip')) { 31 31 throw new Exception(__('Please load the \'zip\' PHP extension. It is needed in order to create the archive to be backed up.', 'backup')); … … 157 157 <div class="misc-pub-section"><?php _e( 'Most recent backup:', 'backup' ); ?><br/><?php 158 158 if ( $options['last_backup'] ) { 159 echo '<strong>' . date( __( "M j, Y \a\\t H:i:s", 'backup' ), $options['last_backup'] ) . '</strong> <br/><br/>';159 echo '<strong>' . date( __( "M j, Y \a\\t H:i:s", 'backup' ), $options['last_backup'] ) . '</strong>'; 160 160 if ( $options['local_number'] > 0 ) { 161 ?>< a class="button-secondary" title="<?php _e( 'Download most recent backup', 'backup'); ?>" href="<?php echo WP_CONTENT_URL . substr( end( $options['local_files'] ), strlen( WP_CONTENT_DIR ) ); ?>">Download backup</a><?php161 ?><br/><br/><a class="button-secondary" title="<?php _e( 'Download most recent backup', 'backup'); ?>" href="<?php echo WP_CONTENT_URL . substr( end( $options['local_files'] ), strlen( WP_CONTENT_DIR ) ); ?>">Download backup</a><?php 162 162 } 163 163 } … … 320 320 $options['last_backup'] = $backup_time; 321 321 $options['local_files'][] = $file_path; 322 if ( $options[' token'] && $options['client_id'] && $options['client_secret'] ) {322 if ( $options['drive_number'] > 0 && $options['token'] && $options['client_id'] && $options['client_secret'] ) { 323 323 if ( $access = access_token( $options['token'], $options['client_id'], $options['client_secret'] ) ) { 324 324 backup_log( 'NOTICE', 'Attempting to upload archive to Google Drive' ); … … 329 329 backup_log( 'NOTICE', 'Archive ' . $file_name . ' uploaded to Google Drive in ' . ( microtime( true ) - $timer_start ) . ' seconds' ); 330 330 $options['drive_files'][] = $id; 331 while ( count( $options['drive_files'] ) > $options['drive_number'] )332 if ( delete_file( $r = array_shift( $options['drive_files'] ), $access ) )333 backup_log( 'NOTICE', 'Deleted Google Drive file ' . $r );334 else335 backup_log( 'WARNING', 'Could not delete Google Drive file ' . $r );336 331 } 337 332 } … … 340 335 } 341 336 } 337 338 // Delete excess Drive files 339 while ( count( $options['drive_files'] ) > $options['drive_number'] ) 340 if ( delete_file( $r = array_shift( $options['drive_files'] ), $access ) ) 341 backup_log( 'NOTICE', 'Deleted Google Drive file ' . $r ); 342 else 343 backup_log( 'WARNING', 'Could not delete Google Drive file ' . $r ); 344 345 // Delete excess local files 342 346 while ( count( $options['local_files'] ) > $options['local_number'] ) 343 347 if ( unlink( $f = array_shift( $options['local_files'] ) ) ) … … 345 349 else 346 350 backup_log( 'WARNING', 'Could not delete file ' . $f ); 351 347 352 update_option( 'backup_options', $options ); 348 353 } … … 386 391 ); 387 392 388 $url = 'https://docs.google.com/feeds/upload/create-session/default/private/full'; 389 if ( $parent ) 390 $url .= '/folder%3A' . $parent . '/contents'; 391 $url .= '?convert=false'; // needed to upload a file 393 $url = get_resumable_create_media_link( $token, $parent ); 394 if ( $url ) 395 $url .= '?convert=false'; // needed to upload a file 396 else { 397 backup_log( 'ERROR', 'Could not retrieve resumable create media link.', __FILE__, __LINE__ ); 398 return false; 399 } 392 400 393 401 $result = @file_get_contents( $url, false, stream_context_create( $context ) ); … … 420 428 } 421 429 else { 422 backup_log( 'ERROR', 'Bad response: ' . $response . ' . Request header: ' . join( "; ", $header ), __FILE__, __LINE__ );430 backup_log( 'ERROR', 'Bad response: ' . $response . ' Response header: ' . var_export( $response_header, true ) . ' Response body: ' . $result . ' Request URL: ' . $url, __FILE__, __LINE__ ); 423 431 return false; 424 432 } … … 512 520 if ( strpos( $headers[0], '200' ) ) 513 521 return true; 522 return false; 523 } 524 /** 525 * Get the resumable-create-media link needed to upload files 526 * 527 * @param string $token The Google Account access token 528 * @param string $parent The Id of the folder where the upload is to be made. Default is empty string. 529 * @return string|boolean Returns a link on success, FALSE on failure. 530 */ 531 function get_resumable_create_media_link( $token, $parent = '' ) { 532 $header = array( 533 'Authorization: Bearer ' . $token, 534 'GData-Version: 3.0' 535 ); 536 $context = array( 537 'http' => array( 538 'method' => 'GET', 539 'header' => join( "\r\n", $header ) 540 ) 541 ); 542 $url = 'https://docs.google.com/feeds/default/private/full'; 543 544 if ( $parent ) 545 $url .= '/' . $parent; 546 547 $result = @file_get_contents( $url, false, stream_context_create( $context ) ); 548 549 if ( $result !== false ) { 550 $xml = new SimpleXMLElement( $result ); 551 error_log( $result ); 552 foreach ( $xml->link as $link ) 553 if ( $link['rel'] == 'http://schemas.google.com/g/2005#resumable-create-media' ) 554 return $link['href']; 555 } 514 556 return false; 515 557 } -
backup/trunk/readme.txt
r547983 r549264 5 5 Requires at least: 3.0 6 6 Tested up to: 3.3.2 7 Stable tag: 1.1. 37 Stable tag: 1.1.5 8 8 9 9 Make backups of your Wordpress site to Google Drive. … … 26 26 27 27 == Changelog == 28 = 1.1.5 = 29 * You can now chose not to upload backups to Google Drive by entering `0` in the appropriate field on the settings page. 30 * Resumable create media link is no longer hard coded. 31 28 32 = 1.1.3 = 29 33 * Fixed some issues created by the `1.1.2` update
Note: See TracChangeset
for help on using the changeset viewer.