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-themes.php
122 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_Themes { |
| 33 | |
| 34 | public static function execute( $params ) { |
| 35 | |
| 36 | $exclude_filters = array(); |
| 37 | |
| 38 | // Get total themes files count |
| 39 | if ( isset( $params['total_themes_files_count'] ) ) { |
| 40 | $total_themes_files_count = (int) $params['total_themes_files_count']; |
| 41 | } else { |
| 42 | $total_themes_files_count = 1; |
| 43 | } |
| 44 | |
| 45 | // Get total themes files size |
| 46 | if ( isset( $params['total_themes_files_size'] ) ) { |
| 47 | $total_themes_files_size = (int) $params['total_themes_files_size']; |
| 48 | } else { |
| 49 | $total_themes_files_size = 1; |
| 50 | } |
| 51 | |
| 52 | // Set progress |
| 53 | Ai1wm_Status::info( __( 'Gathering theme files...', 'all-in-one-wp-migration' ) ); |
| 54 | |
| 55 | // Exclude inactive themes |
| 56 | if ( isset( $params['options']['no_inactive_themes'] ) ) { |
| 57 | foreach ( search_theme_directories() as $theme_name => $theme_info ) { |
| 58 | if ( ! in_array( $theme_name, array( get_template(), get_stylesheet() ) ) ) { |
| 59 | if ( isset( $theme_info['theme_root'] ) ) { |
| 60 | $exclude_filters[] = $theme_info['theme_root'] . DIRECTORY_SEPARATOR . $theme_name; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Exclude selected files |
| 67 | if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) { |
| 68 | if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) { |
| 69 | foreach ( $excluded_files as $excluded_path ) { |
| 70 | $exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path ); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Create themes list file |
| 76 | $themes_list = ai1wm_open( ai1wm_themes_list_path( $params ), 'w' ); |
| 77 | |
| 78 | // Enumerate over themes directory |
| 79 | if ( isset( $params['options']['no_themes'] ) === false ) { |
| 80 | foreach ( ai1wm_get_themes_dirs() as $theme_dir ) { |
| 81 | if ( is_dir( $theme_dir ) ) { |
| 82 | |
| 83 | // Iterate over themes directory |
| 84 | $iterator = new Ai1wm_Recursive_Directory_Iterator( $theme_dir ); |
| 85 | |
| 86 | // Exclude themes files |
| 87 | $iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_themes_from_export', ai1wm_theme_filters( $exclude_filters ) ) ); |
| 88 | |
| 89 | // Recursively iterate over themes directory |
| 90 | $iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD ); |
| 91 | |
| 92 | // Write path line |
| 93 | foreach ( $iterator as $item ) { |
| 94 | if ( $item->isFile() ) { |
| 95 | if ( ai1wm_putcsv( $themes_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) { |
| 96 | $total_themes_files_count++; |
| 97 | |
| 98 | // Add current file size |
| 99 | $total_themes_files_size += $iterator->getSize(); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Set progress |
| 108 | Ai1wm_Status::info( __( 'Theme files gathered.', 'all-in-one-wp-migration' ) ); |
| 109 | |
| 110 | // Set total themes files count |
| 111 | $params['total_themes_files_count'] = $total_themes_files_count; |
| 112 | |
| 113 | // Set total themes files size |
| 114 | $params['total_themes_files_size'] = $total_themes_files_size; |
| 115 | |
| 116 | // Close the themes list file |
| 117 | ai1wm_close( $themes_list ); |
| 118 | |
| 119 | return $params; |
| 120 | } |
| 121 | } |
| 122 |