PATH:
home
/
thebhoeo
/
.trash
/
backwpup
/
inc
<?php /** * Dropbox Files Downloader. */ /** * Class BackWPup_Destination_Dropbox_Downloader. * * @since 3.5.0 */ final class BackWPup_Destination_Dropbox_Downloader implements BackWPup_Destination_Downloader_Interface { public const OPTION_ROOT = 'dropboxroot'; public const OPTION_TOKEN = 'dropboxtoken'; /** * Downloader data object. * * @var \BackWpUp_Destination_Downloader_Data */ private $data; /** * Local file handler. * * @var resource */ private $local_file_handler; /** * Dropbox API client. * * @var BackWPup_Destination_Dropbox_API */ private $dropbox_api; /** * BackWPup_Destination_Dropbox_Downloader constructor. * * @param \BackWpUp_Destination_Downloader_Data $data Download data. * * @throws \BackWPup_Destination_Dropbox_API_Exception When the API cannot be initialized. */ public function __construct( BackWpUp_Destination_Downloader_Data $data ) { $this->data = $data; $this->dropbox_api(); } /** * Clean up things. */ public function __destruct() { fclose( $this->local_file_handler ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose } /** * Download a chunk from Dropbox. * * @param int $start_byte Start byte offset. * @param int $end_byte End byte offset. * * @return void * @throws \RuntimeException When the local file cannot be opened. */ public function download_chunk( $start_byte, $end_byte ) { $this->local_file_handler( $start_byte ); try { $data = $this->dropbox_api->download( [ 'path' => $this->data->source_file_path() ], $start_byte, $end_byte ); $bytes = (int) fwrite( $this->local_file_handler, (string) $data ); //phpcs:ignore if ( 0 === $bytes ) { throw new \RuntimeException( esc_html__( 'Could not write data to file.', 'backwpup' ) ); } } catch ( \Exception $e ) { BackWPup_Admin::message( 'Dropbox: ' . $e->getMessage() ); } } /** * Calculate the total file size. * * @return int */ public function calculate_size() { $metadata = $this->dropbox_api->files_get_metadata( [ 'path' => $this->data->source_file_path() ] ); return $metadata['size']; } /** * Set local file hanlder. * * @param int $start_byte Start byte offset. * * @return void * @throws \RuntimeException When the local file cannot be opened. */ private function local_file_handler( $start_byte ) { if ( is_resource( $this->local_file_handler ) ) { return; } // Open file; write mode if $start_byte is 0, else append. $this->local_file_handler = fopen( $this->data->local_file_path(), 0 === $start_byte ? 'wb' : 'ab' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( ! is_resource( $this->local_file_handler ) ) { throw new \RuntimeException( esc_html__( 'File could not be opened for writing.', 'backwpup' ) ); } } /** * Set the dropbox api instance. * * @throws \BackWPup_Destination_Dropbox_API_Exception When the Dropbox API cannot be initialized. */ private function dropbox_api(): void { $this->dropbox_api = new \BackWPup_Destination_Dropbox_API( \BackWPup_Option::get( $this->data->job_id(), self::OPTION_ROOT ) ); $this->dropbox_api->set_o_auth_tokens( \BackWPup_Option::get( $this->data->job_id(), self::OPTION_TOKEN ) ); } }
[-] class-system-tests-runner.php
[edit]
[-] class-jobtype-dbdump.php
[edit]
[-] class-destination-rsc.php
[edit]
[-] class-encryption.php
[edit]
[-] class-destination-downloader-factory.php
[edit]
[-] class-destination-downloader-interface.php
[edit]
[-] class-destination-ftp-type-ftp.php
[edit]
[-] class-path-fixer.php
[edit]
[-] class-message-box.php
[edit]
[-] class-destination-dropbox-api.php
[edit]
[-] class-option.php
[edit]
[-] class-destination-dropbox-api-request-exception.php
[edit]
[-] class-page-about.php
[edit]
[-] class-migrate.php
[edit]
[-] class-system-requirements.php
[edit]
[-] class-adminbar.php
[edit]
[-] class-msazure-destination-configuration.php
[edit]
[-] class-job.php
[edit]
[-] class-destination-ftp-type-exception.php
[edit]
[-] class-destination-sugarsync-api.php
[edit]
[-] class-download-file-interface.php
[edit]
[-] class-encryption-fallback.php
[edit]
[-] BackWPup.php
[edit]
[-] class-page-backwpup.php
[edit]
[-] class-destination-downloader-data.php
[edit]
[-] class-mysqldump-exception.php
[edit]
[-] class-s3-destination.php
[edit]
[-] class-destination-ftp.php
[edit]
[-] class-cron.php
[edit]
[+]
Notice
[-] class-destination-downloader.php
[edit]
[-] class-destinations.php
[edit]
[-] class-destination-ftp-downloader.php
[edit]
[-] class-destination-dropbox-downloader.php
[edit]
[-] class-download-handler.php
[edit]
[-] class-destination-dropbox.php
[edit]
[-] class-system-tests.php
[edit]
[-] class-destination-folder-downloader.php
[edit]
[-] class-destination-ftp-type.php
[edit]
[-] class-thirdparties.php
[edit]
[-] class-jobtype-wpplugin.php
[edit]
[-] class-directory.php
[edit]
[-] class-recursive-directory.php
[edit]
[-] class-destination-msazure-downloader.php
[edit]
[-] class-destination-connect-interface.php
[edit]
[-] class-install.php
[edit]
[-] class-admin.php
[edit]
[-] class-jobtype-file.php
[edit]
[-] functions.php
[edit]
[+]
Utils
[+]
ThirdParty
[-] class-destination-s3-downloader.php
[edit]
[-] class-destination-rsc-downloader.php
[edit]
[-] class-destination-sugarsync-downloader.php
[edit]
[-] class-destination-email.php
[edit]
[+]
..
[-] class-mysqldump.php
[edit]
[-] class-page-firstbackup.php
[edit]
[-] class-jobtype-wpexp.php
[edit]
[-] class-jobtype-dbcheck.php
[edit]
[-] class-file.php
[edit]
[-] class-sanitize-path.php
[edit]
[+]
Settings
[-] class-destination-s3.php
[edit]
[-] class-page-logs.php
[edit]
[-] class-factory-exception.php
[edit]
[-] class-page-restore.php
[edit]
[+]
dependencies
[-] class-create-archive-exception.php
[edit]
[-] class-page-editjob.php
[edit]
[-] class-page-backups.php
[edit]
[-] class-destination-dropbox-api-exception.php
[edit]
[-] class-create-archive.php
[edit]
[-] class-encryption-openssl.php
[edit]
[-] class-destination-onedrive-config-trait.php
[edit]
[-] class-destination-download-exception.php
[edit]
[-] class-download-file.php
[edit]
[-] class-page-settings.php
[edit]
[-] class-destination-msazure.php
[edit]
[-] class-page-onboarding.php
[edit]
[-] class-destination-folder.php
[edit]
[-] class-jobtypes.php
[edit]
[-] class-destination-connect-exception.php
[edit]
[-] class-destination-sugarsync.php
[edit]
[-] class-page-jobs.php
[edit]
[-] class-destination-sugarsync-api-exception.php
[edit]
[-] class-encryption-mcrypt.php
[edit]