info['ID'] = 'FILE'; $this->info['name'] = __( 'Files', 'backwpup' ); $this->info['description'] = __( 'File backup', 'backwpup' ); $this->info['URI'] = __( 'https://backwpup.com', 'backwpup' ); $this->info['author'] = 'WP Media'; $this->info['authorURI'] = __( 'https://wp-media.me', 'backwpup' ); $this->info['version'] = BackWPup::get_plugin_data( 'Version' ); } /** * Enqueues the scripts needed for the job type edit tab. * * @return void */ public function admin_print_scripts() { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wp_enqueue_script( 'backwpupjobtypefile', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_jobtype_file.js', [ 'jquery' ], time(), true ); } else { wp_enqueue_script( 'backwpupjobtypefile', BackWPup::get_plugin_data( 'URL' ) . '/assets/js/page_edit_jobtype_file.min.js', [ 'jquery' ], BackWPup::get_plugin_data( 'Version' ), true ); } } /** * Whether the job type creates a file. * * @return bool */ public function creates_file() { return true; } /** * Returns default options for the job type. * * @return array */ public function option_defaults() { $log_folder = get_site_option( 'backwpup_cfg_logfolder' ); $log_folder = BackWPup_File::get_absolute_path( $log_folder ); return [ 'backupexcludethumbs' => false, 'backupspecialfiles' => true, 'backuproot' => true, 'backupcontent' => true, 'backupplugins' => true, 'backupthemes' => true, 'backupuploads' => true, 'backuprootexcludedirs' => wpm_apply_filters_typed( 'array', 'backwpup_root_exclude_dirs', [ 'logs', 'usage', 'restore', 'restore_temp' ] ), 'backupcontentexcludedirs' => wpm_apply_filters_typed( 'array', 'backwpup_content_exclude_dirs', [ 'cache', 'wflogs', 'logs', 'upgrade', 'w3tc', 'updraft', 'ai1wm-backups', 'snapshots', 'wp-clone', 'ithemes-security', 'backwpup-restore', ] ), 'backuppluginsexcludedirs' => wpm_apply_filters_typed( 'array', 'backwpup_plugins_exclude_dirs', [ 'backwpup', 'backwpup-pro' ] ), 'backupthemesexcludedirs' => wpm_apply_filters_typed( 'array', 'backwpup_themes_exclude_dirs', [] ), 'backupuploadsexcludedirs' => wpm_apply_filters_typed( 'array', 'backwpup_upload_exclude_dirs', [ basename( $log_folder ) ] ), 'fileexclude' => '', 'dirinclude' => wpm_apply_filters_typed( 'string', 'backwpup_dir_include', '' ), 'backupabsfolderup' => false, ]; } /** * Renders the job type edit tab. * * @param int|array $main Job ID or list of job IDs. */ public function edit_tab( $main ) { if ( function_exists( 'set_time_limit' ) ) { set_time_limit( 300 ); } $abs_folder_up = BackWPup_Option::get( $main, 'backupabsfolderup' ); $abs_path = realpath( BackWPup_Path_Fixer::fix_path( ABSPATH ) ); if ( $abs_folder_up ) { $abs_path = dirname( $abs_path ); } ?>

show_folder( 'root', $main, $abs_path ); ?>
show_folder( 'content', $main, WP_CONTENT_DIR ); ?>
show_folder( 'plugins', $main, WP_PLUGIN_DIR ); ?>
show_folder( 'themes', $main, get_theme_root() ); ?>
show_folder( 'uploads', $main, BackWPup_File::get_upload_dir() ); ?>

steps_data[ $job_object->step_working ]['SAVE_STEP_TRY'] !== $job_object->steps_data[ $job_object->step_working ]['STEP_TRY'] ) { $job_object->log( sprintf( /* translators: %d: attempt number. */ __( '%d. Trying to make a list of folders to back up …', 'backwpup' ), $job_object->steps_data[ $job_object->step_working ]['STEP_TRY'] ) ); } $job_object->substeps_todo = 8; $folders_count = 0; $abs_path = realpath( BackWPup_Path_Fixer::fix_path( ABSPATH ) ); if ( $job_object->job['backupabsfolderup'] ) { $abs_path = dirname( $abs_path ); } $abs_path = trailingslashit( BackWPup_Path_Fixer::slashify( $abs_path ) ); if ( empty( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ) { $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; } // Folder lists for blog folders. if ( 0 === $job_object->substeps_done ) { if ( $abs_path && ! empty( $job_object->job['backuproot'] ) ) { $abs_path = trailingslashit( BackWPup_Path_Fixer::slashify( $abs_path ) ); $excludes = $this->get_exclude_dirs( $abs_path ); foreach ( $job_object->job['backuprootexcludedirs'] as $folder ) { $excludes[] = trailingslashit( $abs_path . $folder ); } $this->get_folder_list( $job_object, $abs_path, $excludes ); } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 1; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 1 === $job_object->substeps_done ) { $wp_content_dir = realpath( WP_CONTENT_DIR ); if ( $wp_content_dir && ! empty( $job_object->job['backupcontent'] ) ) { $wp_content_dir = trailingslashit( BackWPup_Path_Fixer::slashify( $wp_content_dir ) ); $excludes = $this->get_exclude_dirs( $wp_content_dir ); foreach ( $job_object->job['backupcontentexcludedirs'] as $folder ) { $excludes[] = trailingslashit( $wp_content_dir . $folder ); } $this->get_folder_list( $job_object, $wp_content_dir, $excludes ); } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 2; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 2 === $job_object->substeps_done ) { $wp_plugin_dir = realpath( WP_PLUGIN_DIR ); if ( $wp_plugin_dir && ! empty( $job_object->job['backupplugins'] ) ) { $wp_plugin_dir = trailingslashit( BackWPup_Path_Fixer::slashify( $wp_plugin_dir ) ); $excludes = $this->get_exclude_dirs( $wp_plugin_dir ); foreach ( $job_object->job['backuppluginsexcludedirs'] as $folder ) { $excludes[] = trailingslashit( $wp_plugin_dir . $folder ); } $this->get_folder_list( $job_object, $wp_plugin_dir, $excludes ); } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 3; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 3 === $job_object->substeps_done ) { $theme_root = realpath( get_theme_root() ); if ( $theme_root && ! empty( $job_object->job['backupthemes'] ) ) { $theme_root = trailingslashit( BackWPup_Path_Fixer::slashify( $theme_root ) ); $excludes = $this->get_exclude_dirs( $theme_root ); foreach ( $job_object->job['backupthemesexcludedirs'] as $folder ) { $excludes[] = trailingslashit( $theme_root . $folder ); } $this->get_folder_list( $job_object, $theme_root, $excludes ); } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 4; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 4 === $job_object->substeps_done ) { $upload_dir = realpath( BackWPup_File::get_upload_dir() ); if ( $upload_dir && ! empty( $job_object->job['backupuploads'] ) ) { $upload_dir = trailingslashit( BackWPup_Path_Fixer::slashify( $upload_dir ) ); $excludes = $this->get_exclude_dirs( $upload_dir ); foreach ( $job_object->job['backupuploadsexcludedirs'] as $folder ) { $excludes[] = trailingslashit( $upload_dir . $folder ); } $this->get_folder_list( $job_object, $upload_dir, $excludes ); } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 5; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 5 === $job_object->substeps_done ) { // Include dirs. if ( $job_object->job['dirinclude'] ) { $dirinclude = explode( ',', (string) $job_object->job['dirinclude'] ); $dirinclude = array_unique( $dirinclude ); // Create file list for includes. foreach ( $dirinclude as $dirincludevalue ) { if ( is_dir( $dirincludevalue ) ) { // translators: %s: Directory path. $job_object->log( sprintf( __( 'Added "%s" folder to backup', 'backwpup' ), $dirincludevalue ) ); $this->get_folder_list( $job_object, $dirincludevalue ); } else { // translators: %s: Directory path. $job_object->log( sprintf( __( '"%s" is not a folder and will be ignored', 'backwpup' ), $dirincludevalue ), E_USER_WARNING ); } } } $job_object->add_folders_to_backup( array_keys( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] = []; $job_object->substeps_done = 6; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 6 === $job_object->substeps_done ) { // Clean up folder list. $folders = $job_object->get_folders_to_backup(); $folders_count = count( $folders ); $job_object->add_folders_to_backup( $folders, true ); $job_object->substeps_done = 7; $job_object->update_working_data(); $job_object->do_restart_time(); } if ( 0 === $folders_count ) { $folders = $job_object->get_folders_to_backup(); $folders_count = count( $folders ); } // Add extra files if selected. if ( ! empty( $job_object->job['backupspecialfiles'] ) ) { // Special handling for wp-config.php. if ( is_readable( ABSPATH . 'wp-config.php' ) ) { $job_object->additional_files_to_backup[] = BackWPup_Path_Fixer::slashify( ABSPATH . 'wp-config.php' ); // translators: %s: File name. $job_object->log( sprintf( __( 'Added "%s" to backup file list', 'backwpup' ), 'wp-config.php' ) ); } elseif ( BackWPup_File::is_in_open_basedir( dirname( (string) ABSPATH ) . '/wp-config.php' ) ) { if ( is_readable( dirname( (string) ABSPATH ) . '/wp-config.php' ) && ! is_readable( dirname( (string) ABSPATH ) . '/wp-settings.php' ) ) { $job_object->additional_files_to_backup[] = BackWPup_Path_Fixer::slashify( dirname( (string) ABSPATH ) . '/wp-config.php' ); // translators: %s: File name. $job_object->log( sprintf( __( 'Added "%s" to backup file list', 'backwpup' ), 'wp-config.php' ) ); } } // Files to include. $special_files = [ '.htaccess', 'nginx.conf', '.htpasswd', 'robots.txt', 'favicon.ico', 'Web.config', ]; foreach ( $special_files as $file ) { if ( is_readable( $abs_path . $file ) && empty( $job_object->job['backuproot'] ) ) { $job_object->additional_files_to_backup[] = $abs_path . $file; $job_object->log( sprintf( /* translators: %s: file name. */ __( 'Added "%s" to backup file list', 'backwpup' ), $file ) ); } } } if ( 0 === $folders_count && 0 === count( $job_object->additional_files_to_backup ) ) { $job_object->log( __( 'No files/folder for the backup.', 'backwpup' ), E_USER_WARNING ); } elseif ( $folders_count > 1 ) { $job_object->log( sprintf( /* translators: %d: number of folders. */ __( '%1$d folders to backup.', 'backwpup' ), $folders_count ) ); } $job_object->substeps_done = 8; return true; } /** * Helper function for folder_list(). * * @param BackWPup_Job $job_object Job object. * @param string $folder Folder path to scan. * @param array $exclude_dirs Excluded directories. * * @return void */ private function get_folder_list( BackWPup_Job $job_object, string $folder, array $exclude_dirs = [] ): void { $folder = trailingslashit( BackWPup_Path_Fixer::slashify( $folder ) ); $dir = opendir( $folder ); if ( false === $dir ) { // translators: %s: folder name. $job_object->log( sprintf( __( 'Could not open path: %s', 'backwpup' ), $folder ), E_USER_WARNING ); return; } $auto_cache_folders = BackWPup_Directory::get_auto_exclusion_plugin_cache_folders(); $excludes = array_flip( array_merge( $exclude_dirs, $auto_cache_folders ) ); $entry = true; while ( false !== $entry ) { $entry = readdir( $dir ); if ( ! $entry || '.' === $entry || '..' === $entry || ! is_dir( $folder . $entry ) ) { continue; } $pathname = $folder . $entry; $path_slash = $pathname . '/'; if ( isset( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'][ $path_slash ] ) ) { continue; } if ( ! is_readable( $pathname ) ) { $job_object->log( // translators: %s: folder name. sprintf( __( 'Folder "%s" is not readable!', 'backwpup' ), $pathname ), E_USER_WARNING ); continue; } foreach ( $job_object->exclude_from_backup as $exclusion ) { $exclusion = trim( (string) $exclusion ); if ( false !== stripos( $pathname, $exclusion ) && ! empty( $exclusion ) ) { continue 2; } } if ( isset( $excludes[ $path_slash ] ) ) { continue; } if ( is_file( $path_slash . '.donotbackup' ) ) { continue; } $this->get_folder_list( $job_object, $path_slash, $exclude_dirs ); } closedir( $dir ); $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'][ $folder ] = count( $job_object->steps_data[ $job_object->step_working ]['folders_to_backup'] ) + 1; $job_object->do_restart_time(); } /** * Get folder to exclude from a given folder for file backups. * * @param string $folder Folder to check for excludes. * @param array $excludedir Existing excluded directories. * * @return array List of folders to exclude. */ private function get_exclude_dirs( $folder, $excludedir = [] ) { $folder = trailingslashit( BackWPup_Path_Fixer::slashify( realpath( BackWPup_Path_Fixer::fix_path( $folder ) ) ) ); if ( false !== strpos( trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_CONTENT_DIR ) ) ), $folder ) && trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_CONTENT_DIR ) ) ) !== $folder ) { $excludedir[] = trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_CONTENT_DIR ) ) ); } if ( false !== strpos( trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_PLUGIN_DIR ) ) ), $folder ) && trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_PLUGIN_DIR ) ) ) !== $folder ) { $excludedir[] = trailingslashit( BackWPup_Path_Fixer::slashify( realpath( WP_PLUGIN_DIR ) ) ); } if ( false !== strpos( trailingslashit( BackWPup_Path_Fixer::slashify( realpath( get_theme_root() ) ) ), $folder ) && trailingslashit( BackWPup_Path_Fixer::slashify( realpath( get_theme_root() ) ) ) !== $folder ) { $excludedir[] = trailingslashit( BackWPup_Path_Fixer::slashify( realpath( get_theme_root() ) ) ); } if ( false !== strpos( trailingslashit( BackWPup_Path_Fixer::slashify( realpath( BackWPup_File::get_upload_dir() ) ) ), $folder ) && trailingslashit( BackWPup_Path_Fixer::slashify( realpath( BackWPup_File::get_upload_dir() ) ) ) !== $folder ) { $excludedir[] = trailingslashit( BackWPup_Path_Fixer::slashify( realpath( BackWPup_File::get_upload_dir() ) ) ); } return array_unique( $excludedir ); } /** * Shows a folder with the options of which files to exclude. * * @param string $id Folder ID suffix. * @param int $jobid Job ID. * @param string $path Folder path. */ private function show_folder( $id, $jobid, $path ) { $folder = realpath( BackWPup_Path_Fixer::fix_path( $path ) ); $folder_size = 0; if ( $folder ) { $folder = untrailingslashit( BackWPup_Path_Fixer::slashify( $folder ) ); $folder_size = BackWPup_File::get_folder_size( $folder ); } ?> name="backup" id="idbackup" value="1" />
isDot() && $file->isDir() && ! in_array( trailingslashit( $file->getPathname() ), $this->get_exclude_dirs( $folder, $dir::get_auto_exclusion_plugins_folders() ), true ) ) { $donotbackup = file_exists( $file->getPathname() . '/.donotbackup' ); $folder_size = BackWPup_File::get_folder_size( $file->getPathname() ); $title = ''; if ( $donotbackup ) { $excludes[] = $file->getFilename(); $title = ' title="' . esc_attr__( 'Excluded by .donotbackup file!', 'backwpup' ) . '"'; } echo '
'; } } } catch ( Exception $e ) { // Do nothing, just skip. unset( $e ); } ?>