PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 2.1.3
Backup Migration v2.1.3
2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / cli-handler.php
backup-backup / includes Last commit date
banner 3 months ago bodies 3 months ago check 3 months ago cli 3 months ago cron 3 months ago dashboard 3 months ago database 3 months ago external 3 months ago extracter 3 months ago htaccess 3 months ago notices 3 months ago progress 3 months ago scanner 3 months ago staging 3 months ago traits 3 months ago uploader 3 months ago vendor 3 months ago zipper 3 months ago .htaccess 3 months ago activation.php 3 months ago ajax.php 3 months ago ajax_offline.php 3 months ago analyst.php 3 months ago backup-process.php 3 months ago class-backup-method-mananger.php 3 months ago cli-handler.php 3 months ago compatibility.php 3 months ago config.php 3 months ago constants.php 3 months ago file-explorer.php 3 months ago initializer.php 3 months ago logger.php 3 months ago offline.php 3 months ago
cli-handler.php
260 lines
1 <?php
2
3
4 // Namespace
5 namespace BMI\Plugin;
6
7 // Use classes
8 use BMI\Plugin\BMI_Logger as Logger;
9 use BMI\Plugin\Backup_Migration_Plugin as BMP;
10 use BMI\Plugin\Extracter\BMI_Extracter as Extracter;
11 use BMI\Plugin\Progress\BMI_MigrationProgress as MigrationProgress;
12 use BMI\Plugin AS BMI;
13
14 // Allow only PHP CLI to use this script
15 if (php_sapi_name() !== 'cli') {
16 echo 'This script it dedicated for PHP CLI';
17 exit;
18 }
19
20 function isFunctionEnabled($func) {
21 $disabled = explode(',', ini_get('disable_functions'));
22 $isDisabled = in_array($func, $disabled);
23 if (!$isDisabled && function_exists($func)) return true;
24 else return false;
25 }
26
27 // Find WordPress Path
28 function bmi_find_wordpress_base_path() {
29
30 $dir = dirname(__FILE__);
31 $previous = null;
32
33 do {
34
35 if (file_exists($dir . '/wp-load.php') && file_exists($dir . '/wp-config.php')) return $dir;
36 if ($previous == $dir) break;
37 $previous = $dir;
38
39 } while ($dir = dirname($dir));
40
41 return null;
42
43 }
44
45 // Tell WP to not use Themes and set Base Path
46 define('BASE_PATH', bmi_find_wordpress_base_path() . '/');
47 define('BMI_USING_CLI_FUNCTIONALITY', true);
48 if (isset($argv[1])) define('BMI_CLI_FUNCTION', $argv[1]);
49 else {
50
51 echo "\n\n========= BACKUP MIGRATION PLUGIN =========\n\n";
52 echo "Please specify CLI function: bmi_restore [<backup_name>.zip], bmi_backup or bmi_quick_migration <backup URL>\n\n";
53 echo "Examples: \n";
54 echo " – php -f cli-handler.php bmi_backup\n";
55 echo " – php -f cli-handler.php bmi_backup BMI_12-12-12_nameOfMySite_nameOfBackup.zip\n";
56 echo " – php -f cli-handler.php bmi_restore BMI_12-12-12_nameOfMySite_nameOfBackup.zip\n";
57 echo " – php -f cli-handler.php bmi_quick_migration \"http://localhost/site/linkToMyBackup.zip\"\n";
58 echo "\n========= BACKUP MIGRATION PLUGIN =========\n\n";
59 exit();
60
61 }
62
63 if (isset($argv[2])) define('BMI_CLI_ARGUMENT', $argv[2]);
64 if (isset($argv[3])) define('BMI_CLI_ARGUMENT_2', $argv[3]);
65
66 // Pseudo Server variables
67 $_SERVER['REQUEST_METHOD'] = 'CLI';
68
69 // Increase max execution time
70 if (isFunctionEnabled('headers_sent')) {
71 if (!headers_sent()) {
72 if (isFunctionEnabled('set_time_limit')) @set_time_limit(259200);
73 if (isFunctionEnabled('ini_set')) {
74 @ini_set('max_input_time', '259200');
75 @ini_set('max_execution_time', '259200');
76 }
77 }
78 }
79
80 // Response
81 ob_start();
82 echo '100101011101' . "\n";
83
84 @header('Connection: close');
85 @header('Content-Length: ' . ob_get_length());
86
87 ob_end_clean();
88 flush();
89
90 if (isFunctionEnabled('fastcgi_finish_request') && isFunctionEnabled('is_callable') && is_callable('fastcgi_finish_request')) {
91 fastcgi_finish_request();
92 }
93
94 // Let the server know it's server-side script
95 if (isFunctionEnabled('ignore_user_abort')) {
96 @ignore_user_abort(true);
97 }
98
99 if (isFunctionEnabled('session_write_close')) {
100 @session_write_close();
101 }
102
103 function fixSlashes($str, $slash = false) {
104 // Old version
105 // $str = str_replace('\\\\', DIRECTORY_SEPARATOR, $str);
106 // $str = str_replace('\\', DIRECTORY_SEPARATOR, $str);
107 // $str = str_replace('\/', DIRECTORY_SEPARATOR, $str);
108 // $str = str_replace('/', DIRECTORY_SEPARATOR, $str);
109
110 // if ($str[strlen($str) - 1] == DIRECTORY_SEPARATOR) {
111 // $str = substr($str, 0, -1);
112 // }
113
114 // Since 1.3.2
115 $protocol = '';
116 if ($slash == false) $slash = DIRECTORY_SEPARATOR;
117 if (substr($str, 0, 7) == 'http://') $protocol = 'http://';
118 else if (substr($str, 0, 8) == 'https://') $protocol = 'https://';
119
120 $str = substr($str, strlen($protocol));
121 $str = preg_replace('/[\\\\\/]+/', $slash, $str);
122 $str = rtrim($str, '/\\' );
123
124 return $protocol . $str;
125 }
126
127 function bmiLoadWordPressAndBackupPlugin() {
128
129 // Define how WP should load
130 define('WP_USE_THEMES', false);
131 define('SHORTINIT', true);
132
133 // Set path to our plugin's main file
134 $bmiPluginPathToLoad = fixSlashes(dirname(__DIR__) . '/backup-backup.php');
135 $bmiPluginPathToLoadPro = fixSlashes(dirname(dirname(__DIR__)) . '/backup-backup-pro/backup-backup-pro.php');
136
137 // Use WP Globals and load WordPress
138 global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
139 require_once bmi_find_wordpress_base_path() . DIRECTORY_SEPARATOR . 'wp-load.php';
140 global $wp_version;
141
142 // Load directory WordPress constants
143 require_once ABSPATH . WPINC . '/formatting.php';
144 require_once ABSPATH . WPINC . '/meta.php';
145 wp_plugin_directory_constants();
146
147 // Allow to register activation hook and realpath
148 $GLOBALS['wp_plugin_paths'] = array();
149 $GLOBALS['shortcode_tags'] = array();
150
151 // Load all dependencies of WordPress for Backup plugin
152 $dependencies = [
153 ABSPATH . WPINC . '/l10n.php',
154 ABSPATH . WPINC . '/plugin.php',
155 ABSPATH . WPINC . '/link-template.php',
156 ABSPATH . WPINC . '/class-wp-textdomain-registry.php',
157 ABSPATH . WPINC . '/class-wp-locale.php',
158 ABSPATH . WPINC . '/class-wp-locale-switcher.php',
159 ABSPATH . WPINC . '/session.php',
160 ABSPATH . WPINC . '/pluggable.php',
161 ABSPATH . WPINC . '/class-wp-ajax-response.php',
162 ABSPATH . WPINC . '/capabilities.php',
163 ABSPATH . WPINC . '/class-wp-roles.php',
164 ABSPATH . WPINC . '/class-wp-role.php',
165 ABSPATH . WPINC . '/class-wp-user.php',
166 ABSPATH . WPINC . '/class-wp-query.php',
167 ABSPATH . WPINC . '/query.php',
168 ABSPATH . WPINC . '/general-template.php',
169 ABSPATH . WPINC . '/http.php',
170 ABSPATH . WPINC . '/class-http.php',
171 ABSPATH . WPINC . '/class-wp-http.php',
172 ABSPATH . WPINC . '/class-wp-http-streams.php',
173 ABSPATH . WPINC . '/class-wp-http-curl.php',
174 ABSPATH . WPINC . '/class-wp-http-proxy.php',
175 ABSPATH . WPINC . '/class-wp-http-cookie.php',
176 ABSPATH . WPINC . '/class-wp-http-encoding.php',
177 ABSPATH . WPINC . '/class-wp-http-response.php',
178 ABSPATH . WPINC . '/class-wp-http-requests-response.php',
179 ABSPATH . WPINC . '/class-wp-http-requests-hooks.php',
180 ABSPATH . WPINC . '/widgets.php',
181 ABSPATH . WPINC . '/class-wp-widget.php',
182 ABSPATH . WPINC . '/class-wp-widget-factory.php',
183 ABSPATH . WPINC . '/class-wp-user-request.php',
184 ABSPATH . WPINC . '/user.php',
185 ABSPATH . WPINC . '/class-wp-user-query.php',
186 ABSPATH . WPINC . '/class-wp-session-tokens.php',
187 ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php',
188 ABSPATH . WPINC . '/rest-api.php',
189 ABSPATH . WPINC . '/kses.php',
190 ABSPATH . WPINC . '/theme.php',
191 ABSPATH . WPINC . '/rewrite.php',
192 ABSPATH . WPINC . '/class-wp-block-editor-context.php',
193 ABSPATH . WPINC . '/class-wp-block-type.php',
194 ABSPATH . WPINC . '/class-wp-block-pattern-categories-registry.php',
195 ABSPATH . WPINC . '/class-wp-block-patterns-registry.php',
196 ABSPATH . WPINC . '/class-wp-block-styles-registry.php',
197 ABSPATH . WPINC . '/class-wp-block-type-registry.php',
198 ABSPATH . WPINC . '/class-wp-block.php',
199 ABSPATH . WPINC . '/class-wp-block-list.php',
200 ABSPATH . WPINC . '/class-wp-block-parser-block.php',
201 ABSPATH . WPINC . '/class-wp-block-parser-frame.php',
202 ABSPATH . WPINC . '/class-wp-block-parser.php',
203 ABSPATH . WPINC . '/blocks.php',
204 ABSPATH . WPINC . '/blocks/index.php',
205 ];
206
207 for ($i = 0; $i < sizeof($dependencies); ++$i) {
208 $dependency = $dependencies[$i];
209 if (strpos($dependency, 'class-http.php') && version_compare($wp_version, '5.9.0', '>=')) {
210 continue;
211 }
212 if (strpos($dependency, 'session.php') && version_compare($wp_version, '4.7.0', '>=')) {
213 continue;
214 }
215 if (file_exists($dependency)) require_once $dependency;
216 }
217
218 // Load Cookie Constants
219 wp_cookie_constants();
220
221 // Load SSL Constants for DB export
222 wp_ssl_constants();
223
224 // Register Translation
225 if (class_exists('WP_Textdomain_Registry')) {
226 $GLOBALS['wp_textdomain_registry'] = new \WP_Textdomain_Registry();
227 }
228
229 if (file_exists($bmiPluginPathToLoadPro) && is_readable($bmiPluginPathToLoadPro)) {
230 wp_register_plugin_realpath($bmiPluginPathToLoadPro);
231 include_once $bmiPluginPathToLoadPro;
232
233 require_once BMI_PRO_ROOT_DIR . '/classes/core' . ((BMI_PRO_DEBUG) ? '.to-enc' : '') . '.php';
234 $bmi_pro_instance = new BMI_Pro_Core();
235 $bmi_pro_instance->initialize();
236 }
237
238 // Register our backup plugin and load its contents
239 wp_register_plugin_realpath($bmiPluginPathToLoad);
240 include_once $bmiPluginPathToLoad;
241
242 // Enable our plugin WITHOUT calling plugins_loaded hook – it's important
243 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'constants.php';
244
245 // Initialize backup-migration
246 if (!class_exists('Backup_Migration_Plugin')) {
247
248 // Require initializator
249 require_once BMI_ROOT_DIR . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'initializer.php';
250
251 // Initialize entire plugin
252 $bmi_instance = new BMI\Backup_Migration_Plugin();
253 $bmi_instance->initialize();
254
255 }
256
257 }
258
259 bmiLoadWordPressAndBackupPlugin();
260