PATH:
home
/
thebhoeo
/
.trash
/
backwpup
/
inc
<?php /** * Class BackWPup_Destination_Folder. */ class BackWPup_Destination_Folder extends BackWPup_Destinations { /** * Service name * * @var string */ private const SERVICE_NAME = 'Folder'; /** * Option defaults * * @return array */ public function option_defaults(): array { $backups_dir = self::getDefaultBackupsDirectory(); return [ 'maxbackups' => 15, 'backupdir' => $backups_dir, 'backupsyncnodelete' => true, ]; } /** * {@inheritdoc} * * @param int|array $jobid Job ID or array of job IDs. */ public function edit_form_post_save( $jobid ): void { $backup_dir = trim( sanitize_text_field( $_POST['backupdir'] ) ); // phpcs:ignore WordPress.Security try { $backup_dir = trailingslashit( BackWPup_File::normalize_path( BackWPup_Path_Fixer::slashify( $backup_dir ) ) ); } catch ( \InvalidArgumentException $e ) { $backup_dir = self::getDefaultBackupsDirectory(); } $max_backups = isset( $_POST['maxbackups'] ) && is_numeric( $_POST['maxbackups'] ) ? absint( $_POST['maxbackups'] ) : $this->option_defaults()['maxbackups']; // phpcs:ignore WordPress.Security.NonceVerification.Missing $jobids = (array) $jobid; foreach ( $jobids as $jobid ) { BackWPup_Option::update( $jobid, 'backupdir', $backup_dir ); BackWPup_Option::update( $jobid, 'maxbackups', $max_backups ); BackWPup_Option::update( $jobid, 'backupsyncnodelete', ! empty( $_POST['backupsyncnodelete'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing } } /** * {@inheritdoc} * * @param string $jobdest Job destination identifier. * @param string $backupfile Backup file name. */ public function file_delete( string $jobdest, string $backupfile ): void { [$jobid, $dest] = explode( '_', $jobdest, 2 ); if ( empty( $jobid ) ) { return; } $backup_dir = esc_attr( BackWPup_Option::get( (int) $jobid, 'backupdir' ) ); $backup_dir = BackWPup_File::get_absolute_path( $backup_dir ); $backupfile = realpath( trailingslashit( $backup_dir ) . basename( $backupfile ) ); if ( $backupfile && is_writable( $backupfile ) && ! is_dir( $backupfile ) && ! is_link( $backupfile ) ) { //phpcs:ignore wp_delete_file( $backupfile ); } else { // translators: %s: backup file path. \BackWPup_Admin::message( sprintf( __( 'Could not delete backup archive "%s", check permissions!', 'backwpup' ), $backupfile ), true ); } } /** * {@inheritdoc} * * @param string|null $jobdest Job destination identifier. */ public function file_get_list( ?string $jobdest = '' ): array { $jobid = 0; $backup_folder = $this->option_defaults()['backupdir']; if ( '' !== $jobdest ) { [$jobid, $dest] = explode( '_', $jobdest, 2 ); $backup_folder = BackWPup_Option::get( $jobid, 'backupdir' ); } $filecounter = 0; $files = []; $backup_folder = BackWPup_File::get_absolute_path( $backup_folder ); $not_allowed_files = [ 'index.php', '.htaccess', '.donotbackup', 'Web.config', ]; if ( is_dir( $backup_folder ) ) { $dir = $this->get_backwpup_directory( $backup_folder ); foreach ( $dir as $file ) { if ( $file->isDot() || $file->isDir() || $file->isLink() || in_array( $file->getFilename(), $not_allowed_files, true ) || ! $this->is_backup_archive( $file->getFilename() ) ) { continue; } if ( $file->isReadable() ) { // File list for backups. $files[ $filecounter ]['folder'] = $backup_folder; $files[ $filecounter ]['file'] = BackWPup_Path_Fixer::slashify( $file->getPathname() ); $files[ $filecounter ]['filename'] = $file->getFilename(); $files[ $filecounter ]['downloadurl'] = add_query_arg( [ 'page' => 'backwpupbackups', 'action' => 'downloadfolder', 'file' => $file->getFilename(), 'local_file' => $file->getFilename(), 'jobid' => $jobid, ], network_admin_url( 'admin.php' ) ); $files[ $filecounter ]['filesize'] = $file->getSize(); $files[ $filecounter ]['time'] = $file->getMTime(); ++$filecounter; } } } return array_filter( $files ); } /** * {@inheritdoc} * * @param BackWPup_Job $job_object Job object. */ public function job_run_archive( BackWPup_Job $job_object ): bool { $job_object->substeps_todo = 1; if ( ! empty( $job_object->job['jobid'] ) ) { BackWPup_Option::update( $job_object->job['jobid'], 'lastbackupdownloadurl', add_query_arg( [ 'page' => 'backwpupbackups', 'action' => 'downloadfolder', 'file' => basename( $job_object->backup_file ), 'jobid' => $job_object->job['jobid'], ], network_admin_url( 'admin.php' ) ) ); } // Delete old Backupfiles. $backupfilelist = []; $files = []; if ( is_writable( $job_object->backup_folder ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writable -- Make file list. try { $dir = new BackWPup_Directory( $job_object->backup_folder ); foreach ( $dir as $file ) { if ( $file->isDot() || $file->isDir() || $file->isLink() || ! $file->isWritable() ) { continue; } $is_backup_archive = $this->is_backup_archive( $file->getFilename() ); $is_owned_by_job = $this->is_backup_owned_by_job( $file->getFilename(), $job_object->job['jobid'] ); if ( $is_backup_archive && $is_owned_by_job ) { $backupfilelist[ $file->getMTime() ] = clone $file; } } } catch ( UnexpectedValueException $e ) { $job_object->log( sprintf( /* translators: %s: path. */ esc_html__( 'Could not open path: %s', 'backwpup' ), $e->getMessage() ), E_USER_WARNING ); } } if ( $job_object->job['maxbackups'] > 0 ) { if ( count( $backupfilelist ) > $job_object->job['maxbackups'] ) { ksort( $backupfilelist ); $numdeltefiles = 0; $deleted_files = []; while ( ! empty( $backupfilelist ) ) { $file = array_shift( $backupfilelist ); if ( count( $backupfilelist ) < $job_object->job['maxbackups'] ) { break; } wp_delete_file( $file->getPathname() ); $deleted_files[] = $file->getPathname(); foreach ( $files as $key => $filedata ) { if ( $filedata['file'] === $file->getPathname() ) { unset( $files[ $key ] ); } } ++$numdeltefiles; } if ( $numdeltefiles > 0 ) { $job_object->log( sprintf( // translators: %d: number of backup files. _n( '%d backup file deleted', '%d backup files deleted', $numdeltefiles, 'backwpup' ), $numdeltefiles ), E_USER_NOTICE ); } parent::remove_file_history_from_database( $deleted_files, 'FOLDER' ); } } ++$job_object->substeps_done; return true; } /** * {@inheritdoc} * * @param array $job_settings * @param bool $test_connection Job settings. */ public function can_run( array $job_settings, bool $test_connection = true ): bool { return ! ( empty( $job_settings['backupdir'] ) || '/' === $job_settings['backupdir'] ); } /** * Returns new instance of BackWPup_Directory. * * @param string $dir The directory to iterate. */ protected function get_backwpup_directory( string $dir ): BackWPup_Directory { return new BackWPup_Directory( $dir ); } /** * Returns the default backup directory path. * * @return string Backup directory path relative to the content dir. */ private static function getDefaultBackupsDirectory() { $upload_dir = wp_upload_dir( null, false, true ); $backups_dir = trailingslashit( BackWPup_Path_Fixer::slashify( $upload_dir['basedir'] ) ) . 'backwpup/' . BackWPup::get_plugin_data( 'hash' ) . '/backups/'; $content_path = trailingslashit( BackWPup_Path_Fixer::slashify( (string) WP_CONTENT_DIR ) ); return str_replace( $content_path, '', $backups_dir ); } /** * Get service name */ public function get_service_name(): string { return self::SERVICE_NAME; } }
[-] 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]