class-ai1wm-export-archive.php
1 year ago
class-ai1wm-export-clean.php
1 year ago
class-ai1wm-export-compatibility.php
1 year ago
class-ai1wm-export-config-file.php
1 year ago
class-ai1wm-export-config.php
1 year ago
class-ai1wm-export-content.php
1 year ago
class-ai1wm-export-database-file.php
1 year ago
class-ai1wm-export-database.php
1 year ago
class-ai1wm-export-download.php
1 year ago
class-ai1wm-export-enumerate-content.php
1 year ago
class-ai1wm-export-enumerate-media.php
1 year ago
class-ai1wm-export-enumerate-plugins.php
1 year ago
class-ai1wm-export-enumerate-tables.php
1 year ago
class-ai1wm-export-enumerate-themes.php
1 year ago
class-ai1wm-export-init.php
1 year ago
class-ai1wm-export-media.php
1 year ago
class-ai1wm-export-plugins.php
1 year ago
class-ai1wm-export-themes.php
1 year ago
class-ai1wm-export-enumerate-media.php
109 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright (C) 2014-2025 ServMask Inc. |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * Attribution: This code is part of the All-in-One WP Migration plugin, developed by |
| 19 | * |
| 20 | * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ |
| 21 | * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ |
| 22 | * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ |
| 23 | * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ |
| 24 | * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ |
| 25 | * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ |
| 26 | */ |
| 27 | |
| 28 | if ( ! defined( 'ABSPATH' ) ) { |
| 29 | die( 'Kangaroos cannot jump here' ); |
| 30 | } |
| 31 | |
| 32 | class Ai1wm_Export_Enumerate_Media { |
| 33 | |
| 34 | public static function execute( $params ) { |
| 35 | |
| 36 | $exclude_filters = array(); |
| 37 | |
| 38 | // Get total media files count |
| 39 | if ( isset( $params['total_media_files_count'] ) ) { |
| 40 | $total_media_files_count = (int) $params['total_media_files_count']; |
| 41 | } else { |
| 42 | $total_media_files_count = 1; |
| 43 | } |
| 44 | |
| 45 | // Get total media files size |
| 46 | if ( isset( $params['total_media_files_size'] ) ) { |
| 47 | $total_media_files_size = (int) $params['total_media_files_size']; |
| 48 | } else { |
| 49 | $total_media_files_size = 1; |
| 50 | } |
| 51 | |
| 52 | // Set progress |
| 53 | Ai1wm_Status::info( __( 'Gathering media files...', 'all-in-one-wp-migration' ) ); |
| 54 | |
| 55 | // Exclude selected files |
| 56 | if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) { |
| 57 | if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) { |
| 58 | foreach ( $excluded_files as $excluded_path ) { |
| 59 | $exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Create media list file |
| 65 | $media_list = ai1wm_open( ai1wm_media_list_path( $params ), 'w' ); |
| 66 | |
| 67 | // Enumerate over media directory |
| 68 | if ( isset( $params['options']['no_media'] ) === false ) { |
| 69 | if ( is_dir( ai1wm_get_uploads_dir() ) ) { |
| 70 | |
| 71 | // Iterate over media directory |
| 72 | $iterator = new Ai1wm_Recursive_Directory_Iterator( ai1wm_get_uploads_dir() ); |
| 73 | |
| 74 | // Exclude media files |
| 75 | $iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_media_from_export', ai1wm_media_filters( $exclude_filters ) ) ); |
| 76 | |
| 77 | // Recursively iterate over content directory |
| 78 | $iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD ); |
| 79 | |
| 80 | // Write path line |
| 81 | foreach ( $iterator as $item ) { |
| 82 | if ( $item->isFile() ) { |
| 83 | if ( ai1wm_putcsv( $media_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) { |
| 84 | $total_media_files_count++; |
| 85 | |
| 86 | // Add current file size |
| 87 | $total_media_files_size += $iterator->getSize(); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Set progress |
| 95 | Ai1wm_Status::info( __( 'Media files gathered.', 'all-in-one-wp-migration' ) ); |
| 96 | |
| 97 | // Set total media files count |
| 98 | $params['total_media_files_count'] = $total_media_files_count; |
| 99 | |
| 100 | // Set total media files size |
| 101 | $params['total_media_files_size'] = $total_media_files_size; |
| 102 | |
| 103 | // Close the media list file |
| 104 | ai1wm_close( $media_list ); |
| 105 | |
| 106 | return $params; |
| 107 | } |
| 108 | } |
| 109 |