PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.6
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.6
4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Service / ZlibCompressor.php
wp-staging / Backup / Service Last commit date
Compression 1 year ago Database 1 year ago AbstractBackupsFinder.php 1 year ago AbstractExtractor.php 1 year ago AbstractServiceProvider.php 2 years ago Archiver.php 1 year ago BackupAssets.php 2 years ago BackupContent.php 1 year ago BackupMetadataEditor.php 1 year ago BackupMetadataReader.php 1 year ago BackupSigner.php 1 year ago BackupsFinder.php 1 year ago Extractor.php 1 year ago FileBackupService.php 1 year ago FileBackupServiceProvider.php 2 years ago ServiceInterface.php 2 years ago ZlibCompressor.php 2 years ago
ZlibCompressor.php
84 lines
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Backup\Service\Compression\CompressionInterface;
6 use WPStaging\Framework\Facades\Hooks;
7
8 class ZlibCompressor
9 {
10 const FILTER_ZLIB_COMPRESSION_ENABLED = 'wpstg.backup.compression.zlib.enabled';
11
12 /** @var CompressionInterface */
13 protected $service;
14
15 public function __construct(CompressionInterface $service)
16 {
17 $this->service = $service;
18 }
19
20 /**
21 * @return bool Whether the server supports compression.
22 */
23 public function supportsCompression(): bool
24 {
25 return function_exists('gzcompress') && function_exists('gzuncompress');
26 }
27
28 /**
29 * @see \WPStaging\Backup\BackupServiceProvider::registerClasses For the filter.
30 * @return bool Whether the user can use compression.
31 */
32 public function canUseCompression(): bool
33 {
34 static $canUseCompression = null;
35
36 if (!is_null($canUseCompression)) {
37 return $canUseCompression;
38 }
39
40 $isPro = defined('WPSTGPRO_VERSION');
41 $license = get_option('wpstg_license_status');
42
43 $hasActiveLicense = is_object($license) && property_exists($license, 'license') && $license->license === 'valid';
44
45 $canUseCompression = $this->supportsCompression() && $isPro && ($hasActiveLicense || wpstg_is_local());
46
47 return $canUseCompression;
48 }
49
50 /**
51 * @return bool True if compression is enabled, false if not.
52 */
53 public function isCompressionEnabled(): bool
54 {
55 static $isEnabled = null;
56
57 // Early bail: if compression feature not enabled.
58 if (!$this->isCompressionFeatureEnabled()) {
59 return false;
60 }
61
62 if (is_null($isEnabled)) {
63 $settings = (object)get_option('wpstg_settings', []);
64 $isEnabled = $settings->enableCompression ?? false;
65 }
66
67 $canUseCompression = $this->canUseCompression();
68
69 return Hooks::applyFilters(self::FILTER_ZLIB_COMPRESSION_ENABLED, $isEnabled && $canUseCompression);
70 }
71
72 public function getService(): CompressionInterface
73 {
74 return $this->service;
75 }
76
77 /** @return bool */
78 protected function isCompressionFeatureEnabled(): bool
79 {
80 $enabled = (bool)Hooks::applyFilters('wpstg.tests.backup.enable_compression', defined('WPSTG_ENABLE_COMPRESSION') && WPSTG_ENABLE_COMPRESSION);
81 return $enabled;
82 }
83 }
84