PATH:
home
/
thebhoeo
/
.trash
/
backwpup
/
inc
<?php use Inpsyde\BackWPupShared\File\MimeTypeExtractor; /** * Class BackWPup_Download_File. */ final class BackWPup_Download_File implements BackWPup_Download_File_Interface { /** * The file path. * * @var string The path of the file to download */ private $filepath; /** * File Name. * * @var string The file name */ private $filename; /** * Encoding type. * * @var string The encoding type. */ private static $encoding = 'binary'; /** * File content length. * * @var int The length of the file */ private $length; /** * Callback. * * @var callable The callback to call that will perform the download action */ private $callback; /** * Capability. * * @var string The capability needed to download the file */ private $capability; /** * BackWPup_Download_File constructor. * * @todo move the file stuffs into a specific class to manage only files. Blocked by class-file.php * * @param string $filepath The path of the file to download. * @param callable $callback The callback to call that will perform the download action. * @param string $capability The capability needed to download the file. * * @throws \InvalidArgumentException In case the callback is not a valid callback. */ public function __construct( $filepath, $callback, $capability ) { if ( ! is_callable( $callback ) ) { throw new \InvalidArgumentException( sprintf( 'Invalid callback passed to %s. Callback parameter must be callable.', self::class ) ); } $this->filepath = $filepath; $this->filename = basename( $filepath ); $this->callback = $callback; $this->length = file_exists( $filepath ) ? filesize( $filepath ) : 0; $this->capability = $capability; } /** * {@inheritdoc} */ public function download() { if ( ! current_user_can( $this->capability ) ) { wp_die( 'Cheating Uh?' ); } $this->perform_download_callback(); } /** * {@inheritdoc} */ public function clean_ob() { $level = ob_get_level(); if ( $level ) { for ( $i = 0; $i < $level; ++$i ) { ob_end_clean(); } } return $this; } /** * {@inheritdoc} */ public function filepath() { return $this->filepath; } /** * {@inheritdoc} */ public function headers() { $mime = MimeTypeExtractor::fromFilePath( $this->filepath ); $level = ob_get_level(); if ( $level ) { for ( $i = 0; $i < $level; ++$i ) { ob_end_clean(); } } // phpcs:ignore @set_time_limit(300); nocache_headers(); // Set headers. header( 'Content-Description: File Transfer' ); header( "Content-Type: {$mime}" ); header( "Content-Disposition: attachment; filename={$this->filename}" ); header( 'Content-Transfer-Encoding: ' . self::$encoding ); header( "Content-Length: {$this->length}" ); return $this; } /** * Perform the Download. * * Note: The callback must call `die` it self. */ private function perform_download_callback() { call_user_func( $this->callback, $this ); } }
[-] 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]