-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathCdnEngine_Ftp.php
788 lines (623 loc) · 21.1 KB
/
CdnEngine_Ftp.php
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
<?php
/**
* File: CdnEngine_CloudFront.php
*
* @package W3TC
*/
namespace W3TC;
define( 'W3TC_CDN_FTP_CONNECT_TIMEOUT', 30 );
/**
* Class CdnEngine_Ftp
*
* W3 CDN FTP Class
*
* phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
* phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
* phpcs:disable WordPress.WP.AlternativeFunctions
*/
class CdnEngine_Ftp extends CdnEngine_Base {
/**
* FTP resource
*
* @var resource
*/
private $_ftp = null;
/**
* Class constructor for initializing FTP/SFTP connection settings.
*
* @param array $config Optional configuration array to override default values.
* Keys include 'host', 'type', 'user', 'pass', 'default_keys',
* 'pubkey', 'privkey', 'path', 'pasv', 'domain', and 'docroot'.
*/
public function __construct( $config = array() ) {
$config = array_merge(
array(
'host' => '',
'type' => '',
'user' => '',
'pass' => '',
'default_keys' => false,
'pubkey' => '',
'privkey' => '',
'path' => '',
'pasv' => false,
'domain' => array(),
'docroot' => '',
),
$config
);
list( $ip, $port ) = Util_Content::endpoint_to_host_port( $config['host'], 21 );
$config['host'] = $ip;
$config['port'] = $port;
if ( 'sftp' === $config['type'] && $config['default_keys'] ) {
$home = isset( $_SERVER['HOME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HOME'] ) ) : '';
$config['pubkey'] = $home . '/.ssh/id_rsa.pub';
$config['privkey'] = $home . '/.ssh/id_rsa';
}
parent::__construct( $config );
}
/**
* Establishes a connection to the FTP/SFTP server.
*
* Attempts to connect to the server using the configuration provided in the class.
* Handles both FTP and SFTP types with error handling and connection setup.
*
* @param string $error Reference to a variable to capture error messages.
*
* @return bool Returns true on successful connection, false on failure.
*/
public function _connect( &$error ) {
if ( empty( $this->_config['host'] ) ) {
$error = 'Empty host.';
return false;
}
$this->_set_error_handler();
if ( 'sftp' === $this->_config['type'] ) {
if ( ! function_exists( 'ssh2_connect' ) ) {
$error = sprintf( 'Missing required php-ssh2 extension.' );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_ftp = @ssh2_connect( $this->_config['host'], (int) $this->_config['port'] );
return $this->_connect_sftp( $error );
}
if ( 'ftps' === $this->_config['type'] ) {
$this->_ftp = @ftp_ssl_connect( $this->_config['host'], (int) $this->_config['port'], W3TC_CDN_FTP_CONNECT_TIMEOUT );
} else {
$this->_ftp = @ftp_connect( $this->_config['host'], (int) $this->_config['port'], W3TC_CDN_FTP_CONNECT_TIMEOUT );
}
if ( ! $this->_ftp ) {
$error = sprintf(
'Unable to connect to %s:%d (%s).',
$this->_config['host'],
$this->_config['port'],
$this->_get_last_error()
);
$this->_restore_error_handler();
return false;
}
if ( ! @ftp_login( $this->_ftp, $this->_config['user'], $this->_config['pass'] ) ) {
$error = sprintf( 'Incorrect login or password (%s).', $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! @ftp_pasv( $this->_ftp, $this->_config['pasv'] ) ) {
$error = sprintf( 'Unable to change mode to passive (%s).', $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! empty( $this->_config['path'] ) && ! @ftp_chdir( $this->_ftp, $this->_config['path'] ) ) {
$error = sprintf( 'Unable to change directory to: %s (%s).', $this->_config['path'], $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_restore_error_handler();
return true;
}
/**
* Establishes an SFTP connection and authenticates using the provided credentials.
*
* This method is used specifically for handling SFTP connections, including both
* public key and password-based authentication.
*
* @param string $error Reference to a variable to capture error messages.
*
* @return bool Returns true on successful connection, false on failure.
*/
public function _connect_sftp( &$error ) {
if ( is_file( $this->_config['pass'] ) ) {
if ( ! @ssh2_auth_pubkey_file( $this->_ftp, $this->_config['user'], $this->_config['pubkey'], $this->_config['privkey'], $this->_config['pass'] ) ) {
$error = sprintf( 'Public key authentication failed (%s).', $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
} elseif ( ! @ssh2_auth_password( $this->_ftp, $this->_config['user'], $this->_config['pass'] ) ) {
$error = sprintf( 'Incorrect login or password (%s).', $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! empty( $this->_config['path'] ) && ! @ssh2_exec( $this->_ftp, 'cd ' . $this->_config['path'] ) ) {
$error = sprintf( 'Unable to change directory to: %s (%s).', $this->_config['path'], $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_restore_error_handler();
return true;
}
/**
* Closes the current FTP/SFTP connection.
*
* This method properly terminates the connection to the server based on the connection type.
*
* @return void
*/
public function _disconnect() {
if ( 'sftp' === $this->_config['type'] ) {
if ( function_exists( 'ssh2_connect' ) ) {
@ssh2_exec( $this->_ftp, 'echo "EXITING" && exit;' );
$this->_ftp = null;
}
} else {
@ftp_close( $this->_ftp );
}
}
/**
* Sends an MDTM (Modification Time) command to the FTP server to update the modification time of a file.
*
* This method is used for updating the timestamp of a remote file.
*
* @param string $remote_file The remote file path to modify.
* @param int $mtime The modification time to set for the file.
*
* @return array Returns the raw response from the FTP server.
*/
public function _mdtm( $remote_file, $mtime ) {
$command = sprintf( 'MDTM %s %s', gmdate( 'YmdHis', $mtime ), $remote_file );
return @ftp_raw( $this->_ftp, $command );
}
/**
* Uploads files to the FTP/SFTP server.
*
* Handles the upload of files, including checking for existing files and handling
* overwrites, directory creation, and error logging.
*
* @param array $files Array of files to upload, with 'local_path' and 'remote_path' for each file.
* @param array $results Array to capture the results of the upload attempt.
* @param bool $force_rewrite Whether to force overwriting files even if they are up-to-date.
* @param int|null $timeout_time Optional timeout time to stop the process if exceeded.
*
* @return bool Returns true if the upload is successful, false if there were errors.
*/
public function upload( $files, &$results, $force_rewrite = false, $timeout_time = null ) {
$error = null;
if ( ! $this->_connect( $error ) ) {
$results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT, $error );
return false;
}
$this->_set_error_handler();
if ( 'sftp' === $this->_config['type'] ) {
return $this->_upload_sftp( $files, $results, $force_rewrite, $timeout_time );
}
$home = @ftp_pwd( $this->_ftp );
if ( false === $home ) {
$results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT, sprintf( 'Unable to get current directory (%s).', $this->_get_last_error() ) );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
foreach ( $files as $file ) {
$local_path = $file['local_path'];
$remote_path = $file['remote_path'];
// process at least one item before timeout so that progress goes on.
if ( ! empty( $results ) ) {
if ( ! is_null( $timeout_time ) && time() > $timeout_time ) {
return 'timeout';
}
}
if ( ! file_exists( $local_path ) ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
'Source file not found.',
$file
);
continue;
}
@ftp_chdir( $this->_ftp, $home );
$remote_dir = dirname( $remote_path );
$remote_dirs = preg_split( '~\\/+~', $remote_dir );
foreach ( $remote_dirs as $dir ) {
if ( ! @ftp_chdir( $this->_ftp, $dir ) ) {
if ( ! @ftp_mkdir( $this->_ftp, $dir ) ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to create directory (%s).', $this->_get_last_error() ),
$file
);
continue 2;
}
if ( ! @ftp_chdir( $this->_ftp, $dir ) ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to change directory (%s).', $this->_get_last_error() ),
$file
);
continue 2;
}
}
}
// basename cannot be used, kills chinese chars and similar characters.
$remote_file = substr( $remote_path, strrpos( $remote_path, '/' ) + 1 );
$mtime = @filemtime( $local_path );
if ( ! $force_rewrite ) {
$size = @filesize( $local_path );
$ftp_size = @ftp_size( $this->_ftp, $remote_file );
$ftp_mtime = @ftp_mdtm( $this->_ftp, $remote_file );
if ( $size === $ftp_size && $mtime === $ftp_mtime ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_OK,
'File up-to-date.',
$file
);
continue;
}
}
$result = @ftp_put( $this->_ftp, $remote_file, $local_path, FTP_BINARY );
if ( $result ) {
$this->_mdtm( $remote_file, $mtime );
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_OK,
'OK',
$file
);
} else {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to upload file (%s).', $this->_get_last_error() ),
$file
);
}
}
$this->_restore_error_handler();
$this->_disconnect();
return ! $this->_is_error( $results );
}
/**
* Handles the SFTP-specific file upload process.
*
* This method is called when the connection type is SFTP, and is responsible for
* uploading files using the SFTP protocol, including directory creation and file transfer.
*
* @param array $files Array of files to upload, with 'local_path' and 'remote_path' for each file.
* @param array $results Array to capture the results of the upload attempt.
* @param bool $force_rewrite Whether to force overwriting files even if they are up-to-date.
* @param int|null $timeout_time Optional timeout time to stop the process if exceeded.
*
* @return string Returns 'timeout' if the process times out, otherwise no return value on success.
*/
public function _upload_sftp( $files, $results, $force_rewrite, $timeout_time ) {
$sftp = ssh2_sftp( $this->_ftp );
foreach ( $files as $file ) {
$local_path = $file['local_path'];
$remote_path = $file['remote_path'];
// process at least one item before timeout so that progress goes on.
if ( ! empty( $results ) ) {
if ( ! is_null( $timeout_time ) && time() > $timeout_time ) {
return 'timeout';
}
}
if ( ! file_exists( $local_path ) ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
'Source file not found.',
$file
);
continue;
}
$remote_dir = dirname( $remote_path );
if ( ! @file_exists( 'ssh2.sftp://' . intval( $sftp ) . $remote_dir ) ) {
if ( ! @ssh2_sftp_mkdir( $sftp, $remote_dir, null, true ) ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to create directory (%s).', $this->_get_last_error() ),
$file
);
continue;
}
}
$mtime = @filemtime( $local_path );
if ( ! $force_rewrite ) {
$size = @filesize( $local_path );
$statinfo = @ssh2_sftp_stat( $sftp, $remote_path );
if ( $size === $statinfo['size'] && $mtime === $statinfo['mtime'] ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_OK,
'File up-to-date.',
$file
);
continue;
}
}
$result = @ssh2_scp_send( $this->_ftp, $local_path, $remote_path );
if ( $result ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_OK,
'OK',
$file
);
} else {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to upload file (%s).', $this->_get_last_error() ),
$file
);
}
}
$this->_restore_error_handler();
$this->_disconnect();
return ! $this->_is_error( $results );
}
/**
* Deletes the specified files from the remote FTP/SFTP server.
*
* This method connects to the remote server, attempts to delete each file, and then tries to remove
* the directories associated with those files. It collects the results of the delete operations
* and stores them in the results array.
*
* @param array $files An array of file data, where each entry contains the local and remote paths of the files.
* @param array $results An array that will be populated with the results of each delete operation.
*
* @return bool Returns true if all files and directories were deleted successfully, otherwise false.
*/
public function delete( $files, &$results ) {
$error = null;
if ( ! $this->_connect( $error ) ) {
$results = $this->_get_results( $files, W3TC_CDN_RESULT_HALT, $error );
return false;
}
$this->_set_error_handler();
foreach ( $files as $file ) {
$local_path = $file['local_path'];
$remote_path = $file['remote_path'];
if ( 'sftp' === $this->_config['type'] ) {
$sftp = @ssh2_sftp( $this->_ftp );
$result = @ssh2_sftp_unlink( $sftp, $remote_path );
} else {
$result = @ftp_delete( $this->_ftp, $remote_path );
}
if ( $result ) {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_OK,
'OK',
$file
);
} else {
$results[] = $this->_get_result(
$local_path,
$remote_path,
W3TC_CDN_RESULT_ERROR,
sprintf( 'Unable to delete file (%s).', $this->_get_last_error() ),
$file
);
}
while ( true ) {
$remote_path = dirname( $remote_path );
if ( '.' === $remote_path ) {
break;
}
if ( 'sftp' === $this->_config['type'] && ! @ssh2_sftp_rmdir( $sftp, $remote_path ) ) {
break;
} elseif ( ! @ftp_rmdir( $this->_ftp, $remote_path ) ) {
break;
}
}
}
$this->_restore_error_handler();
$this->_disconnect();
return ! $this->_is_error( $results );
}
/**
* Tests the FTP/SFTP connection and upload/download functionality.
*
* This method tests the FTP/SFTP connection by performing a series of file operations including
* creating a temporary directory, uploading a test file, deleting it, and cleaning up. If any step
* fails, an error message is returned via the $error parameter.
*
* @param string $error A reference to a variable that will be populated with an error message, if any.
*
* @return bool Returns true if the test was successful, otherwise false.
*/
public function test( &$error ) {
if ( ! parent::test( $error ) ) {
return false;
}
if ( 'sftp' === $this->_config['type'] ) {
return $this->_test_sftp( $error );
}
$rand = md5( time() );
$tmp_dir = 'test_dir_' . $rand;
$tmp_file = 'test_file_' . $rand;
$tmp_path = W3TC_CACHE_TMP_DIR . '/' . $tmp_file;
if ( ! @file_put_contents( $tmp_path, $rand ) ) {
$error = sprintf( 'Unable to create file: %s.', $tmp_path );
return false;
}
if ( ! $this->_connect( $error ) ) {
return false;
}
$this->_set_error_handler();
if ( ! @ftp_mkdir( $this->_ftp, $tmp_dir ) ) {
$error = sprintf( 'Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error() );
@unlink( $tmp_path );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( file_exists( $this->_config['docroot'] . '/' . $tmp_dir ) ) {
$error = sprintf( 'Test directory was made in your site root, not on separate FTP host or path. Change path or FTP information: %s.', $tmp_dir );
@unlink( $tmp_path );
@ftp_rmdir( $this->_ftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! @ftp_chdir( $this->_ftp, $tmp_dir ) ) {
$error = sprintf( 'Unable to change directory to: %s (%s).', $tmp_dir, $this->_get_last_error() );
@unlink( $tmp_path );
@ftp_rmdir( $this->_ftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! @ftp_put( $this->_ftp, $tmp_file, $tmp_path, FTP_BINARY ) ) {
$error = sprintf( 'Unable to upload file: %s (%s).', $tmp_path, $this->_get_last_error() );
@unlink( $tmp_path );
@ftp_cdup( $this->_ftp );
@ftp_rmdir( $this->_ftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
@unlink( $tmp_path );
if ( ! @ftp_delete( $this->_ftp, $tmp_file ) ) {
$error = sprintf( 'Unable to delete file: %s (%s).', $tmp_path, $this->_get_last_error() );
@ftp_cdup( $this->_ftp );
@ftp_rmdir( $this->_ftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
@ftp_cdup( $this->_ftp );
if ( ! @ftp_rmdir( $this->_ftp, $tmp_dir ) ) {
$error = sprintf( 'Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_restore_error_handler();
$this->_disconnect();
return true;
}
/**
* Tests SFTP-specific functionality, including directory creation and file upload/delete.
*
* This method is specifically designed to test SFTP connections by creating directories, uploading
* a test file, and performing file deletions using SFTP commands. If any operation fails, an error message
* is returned via the $error parameter.
*
* @param string $error A reference to a variable that will be populated with an error message, if any.
*
* @return bool Returns true if the SFTP test was successful, otherwise false.
*/
public function _test_sftp( &$error ) {
$rand = md5( time() );
$tmp_dir = 'test_dir_' . $rand;
$tmp_file = 'test_file_' . $rand;
$local_path = W3TC_CACHE_TMP_DIR . '/' . $tmp_file;
$remote_path = $tmp_dir . '/' . $tmp_file;
if ( ! @file_put_contents( $local_path, $rand ) ) {
$error = sprintf( 'Unable to create file: %s.', $local_path );
return false;
}
if ( ! $this->_connect( $error ) ) {
return false;
}
$sftp = @ssh2_sftp( $this->_ftp );
$this->_set_error_handler();
if ( ! @ssh2_sftp_mkdir( $sftp, $tmp_dir ) ) {
$error = sprintf( 'Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error() );
@unlink( $local_path );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( file_exists( $this->_config['docroot'] . '/' . $tmp_dir ) ) {
$error = sprintf( 'Test directory was made in your site root, not on separate FTP host or path. Change path or FTP information: %s.', $tmp_dir );
@unlink( $local_path );
@ssh2_sftp_rmdir( $sftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! @ssh2_scp_send( $this->_ftp, $local_path, $remote_path ) ) {
$error = sprintf( 'Unable to upload file: %s (%s).', $local_path, $this->_get_last_error() );
@unlink( $local_path );
@ssh2_sftp_rmdir( $sftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
@unlink( $local_path );
if ( ! @ssh2_sftp_unlink( $sftp, $remote_path ) ) {
$error = sprintf( 'Unable to delete file: %s (%s).', $local_path, $this->_get_last_error() );
@ssh2_sftp_rmdir( $sftp, $tmp_dir );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if ( ! @ssh2_sftp_rmdir( $sftp, $tmp_dir ) ) {
$error = sprintf( 'Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error() );
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_restore_error_handler();
$this->_disconnect();
return true;
}
/**
* Retrieves the domains configured for the CDN.
*
* This method returns the domains associated with the CDN configuration, or an empty array if no
* domains are configured.
*
* @return array An array of domain names.
*/
public function get_domains() {
if ( ! empty( $this->_config['domain'] ) ) {
return (array) $this->_config['domain'];
}
return array();
}
/**
* Returns the headers support level for the CDN.
*
* This method returns the type of header mirroring support available for the CDN configuration.
*
* @return string The header mirroring type supported by the CDN.
*/
public function headers_support() {
return W3TC_CDN_HEADER_MIRRORING;
}
}