-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenginescript-site-exporter.php
More file actions
201 lines (169 loc) · 6.58 KB
/
Copy pathenginescript-site-exporter.php
File metadata and controls
201 lines (169 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* Plugin Name: EngineScript Site Exporter
* Description: Exports the site files and the database as an EngineScript-compatible site archive.
* Version: 2.1.0
* Author: EngineScript
* Requires at least: 6.8
* Tested up to: 7.1
* Requires PHP: 8.2
* Network: true
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: enginescript-site-exporter
* Domain Path: /languages
*
* @package EngineScript_Site_Exporter
*/
// Prevent direct access. Note: Using return here instead of exit.
if ( ! defined( 'ABSPATH' ) ) {
return; // Prevent direct access.
}
// Define plugin version.
if ( ! defined( 'ES_SITE_EXPORTER_VERSION' ) ) {
define( 'ES_SITE_EXPORTER_VERSION', '2.1.0' );
}
// Define allowed file extensions for export operations.
if ( ! defined( 'SSE_ALLOWED_EXTENSIONS' ) ) {
define( 'SSE_ALLOWED_EXTENSIONS', [ 'zip' ] );
}
// Define export directory name used across the plugin.
if ( ! defined( 'SSE_EXPORT_DIR_NAME' ) ) {
define( 'SSE_EXPORT_DIR_NAME', 'enginescript-site-exporter-exports' );
}
// Define private export directory naming and filesystem modes.
if ( ! defined( 'SSE_EXPORT_PRIVATE_DIR_PREFIX' ) ) {
define( 'SSE_EXPORT_PRIVATE_DIR_PREFIX', 'export-' );
}
if ( ! defined( 'SSE_PRIVATE_DIR_MODE' ) ) {
define( 'SSE_PRIVATE_DIR_MODE', 0700 );
}
if ( ! defined( 'SSE_PRIVATE_FILE_MODE' ) ) {
define( 'SSE_PRIVATE_FILE_MODE', 0600 );
}
// Define the filter name for maximum file size override.
if ( ! defined( 'SSE_FILTER_MAX_FILE_SIZE' ) ) {
define( 'SSE_FILTER_MAX_FILE_SIZE', 'sse_max_file_size_for_export' );
}
// Define the EngineScript archive filename marker used for generated export ZIP files.
if ( ! defined( 'SSE_EXPORT_ARCHIVE_MARKER' ) ) {
define( 'SSE_EXPORT_ARCHIVE_MARKER', 'enginescript_site_export' );
}
// Define conservative aggregate export resource limits.
if ( ! defined( 'SSE_DEFAULT_MAX_EXPORT_ENTRIES' ) ) {
define( 'SSE_DEFAULT_MAX_EXPORT_ENTRIES', 250000 );
}
if ( ! defined( 'SSE_DEFAULT_MAX_EXPORT_SOURCE_BYTES' ) ) {
define( 'SSE_DEFAULT_MAX_EXPORT_SOURCE_BYTES', 53687091200 );
}
if ( ! defined( 'SSE_DEFAULT_MAX_EXPORT_GENERATED_BYTES' ) ) {
define( 'SSE_DEFAULT_MAX_EXPORT_GENERATED_BYTES', 107374182400 );
}
if ( ! defined( 'SSE_DEFAULT_MIN_FREE_DISK_BYTES' ) ) {
define( 'SSE_DEFAULT_MIN_FREE_DISK_BYTES', 1073741824 );
}
if ( ! defined( 'SSE_DEFAULT_MAX_EXPORT_SECONDS' ) ) {
define( 'SSE_DEFAULT_MAX_EXPORT_SECONDS', 1800 );
}
if ( ! defined( 'SSE_DEFAULT_EXPORT_RECOVERY_GRACE_SECONDS' ) ) {
define( 'SSE_DEFAULT_EXPORT_RECOVERY_GRACE_SECONDS', 300 );
}
if ( ! defined( 'SSE_DEFAULT_PROCESS_TERMINATION_GRACE_MILLISECONDS' ) ) {
define( 'SSE_DEFAULT_PROCESS_TERMINATION_GRACE_MILLISECONDS', 2000 );
}
if ( ! defined( 'SSE_DEFAULT_PROCESS_FORCE_GRACE_MILLISECONDS' ) ) {
define( 'SSE_DEFAULT_PROCESS_FORCE_GRACE_MILLISECONDS', 2000 );
}
// Define plugin file constant for use in included files.
if ( ! defined( 'SSE_PLUGIN_FILE' ) ) {
define( 'SSE_PLUGIN_FILE', __FILE__ );
}
/**
* WordPress and PHP runtime dependencies.
*
* WordPress supplies WP_Error; PHP supplies the other classes below when the
* required extensions are enabled. Archive requirements are checked before
* export work begins. These global classes do not need namespace imports.
*
* Runtime classes used:
*
* @see WP_Error - WordPress error handling class
* @see ZipArchive - PHP ZipArchive class
* @see RecursiveIteratorIterator - PHP SPL iterator
* @see RecursiveDirectoryIterator - PHP SPL directory iterator
* @see RecursiveCallbackFilterIterator - PHP SPL filter iterator
* @see SplFileInfo - PHP SPL file information class
* @see RuntimeException - PHP runtime exception class
* @see Exception - PHP base exception class
*/
// Load plugin components.
require_once __DIR__ . '/includes/helpers.php';
require_once __DIR__ . '/includes/security.php';
require_once __DIR__ . '/includes/admin-page.php';
require_once __DIR__ . '/includes/export.php';
require_once __DIR__ . '/includes/tar.php';
require_once __DIR__ . '/includes/archive.php';
require_once __DIR__ . '/includes/cleanup.php';
require_once __DIR__ . '/includes/download.php';
/**
* Initialize the EngineScript Site Exporter plugin.
*
* This function is hooked to 'plugins_loaded' to ensure that all other plugins
* and WordPress core functions are available before initializing this plugin.
* This prevents load order issues and conflicts with other plugins.
*
* @since 1.8.5
* @return void
*/
function sse_init_plugin(): void {
// Hook single-site and multisite Network Admin menu creation.
add_action( 'admin_menu', 'sse_admin_menu' );
add_action( 'network_admin_menu', 'sse_network_admin_menu' );
// Hook admin assets.
add_action( 'admin_enqueue_scripts', 'sse_enqueue_admin_assets' );
// Hook export handler.
add_action( 'admin_post_sse_export_site', 'sse_handle_export' );
// Hook scheduled deletion handler.
add_action( 'sse_delete_export_file', 'sse_delete_export_file_handler' );
// Hook bulk cleanup handler.
add_action( 'sse_bulk_cleanup_exports', 'sse_bulk_cleanup_exports_handler' );
// Hook independent stale-export recovery and recurring housekeeping.
add_action( 'sse_recover_expired_export', 'sse_recover_expired_export_handler' );
add_action( 'sse_export_housekeeping', 'sse_export_housekeeping_handler' );
sse_schedule_export_housekeeping();
// Hook secure download handler.
add_action( 'admin_post_sse_secure_download', 'sse_handle_secure_download' );
// Hook export deletion handler.
add_action( 'admin_post_sse_delete_export', 'sse_handle_export_deletion' );
}
/**
* Removes exports, scheduled events, and the lease when the plugin is deactivated.
*
* An inactive plugin cannot delete an archive, so nothing may be left for it
* to delete.
*
* @since 2.1.1
* @param bool $_network_wide Whether the plugin is being deactivated network-wide.
* @return void
*/
function sse_deactivate_plugin( bool $_network_wide = false ): void {
if ( $_network_wide ) {
sse_log( 'The exporter is being deactivated in the current network context.', 'info' );
}
sse_remove_plugin_runtime_state();
}
/**
* Registers the uninstall callback when the plugin is activated.
*
* @since 2.1.1
* @param bool $_network_wide Whether the plugin is being activated network-wide.
* @return void
*/
function sse_activate_plugin( bool $_network_wide = false ): void {
unset( $_network_wide );
sse_register_uninstall_callback();
}
// Initialize the plugin when all plugins are loaded.
add_action( 'plugins_loaded', 'sse_init_plugin' );
register_activation_hook( SSE_PLUGIN_FILE, 'sse_activate_plugin' );
register_deactivation_hook( SSE_PLUGIN_FILE, 'sse_deactivate_plugin' );