PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / vendor / 10web-utils / tenweb-image-optimizer / src / TenWebIO / Backup.php
tenweb-speed-optimizer / vendor / 10web-utils / tenweb-image-optimizer / src / TenWebIO Last commit date
Exceptions 4 years ago Queue 2 years ago Views 2 years ago Api.php 2 years ago Attachments.php 2 years ago Backup.php 2 years ago CLI.php 3 years ago Compress.php 2 years ago CompressDataService.php 3 years ago CompressService.php 3 years ago Config.php 2 years ago Init.php 2 years ago LastCompress.php 3 years ago Logs.php 2 years ago PreInit.php 3 years ago Rest.php 2 years ago Settings.php 3 years ago Utils.php 1 year ago
Backup.php
110 lines
1 <?php
2
3 namespace TenWebIO;
4
5 class Backup
6 {
7 public $upload_dir;
8 public $backup_dir;
9
10 /**
11 * @param $type
12 */
13 public function __construct($type = 'bulk')
14 {
15 $upload_dir = wp_get_upload_dir();
16 $this->upload_dir = $upload_dir['basedir'];
17 $this->backup_dir = $this->upload_dir . "/tenweb_io_backup/" . $type;
18 }
19
20 /**
21 * @param $original_img
22 * @param $wp_folder
23 *
24 * @return void
25 */
26 public function backupBeforeReplace($original_img, $wp_folder)
27 {
28 if (!is_dir($this->backup_dir . $wp_folder) &&
29 !mkdir($this->backup_dir . $wp_folder, 0777, true)) {
30 Logs::setLog("backup:error", 'Error creating folder. Backup dir: ' . $this->backup_dir, 'error');
31 }
32
33 if (file_exists($original_img)) {
34 rename($original_img, $this->backup_dir . "/" . $original_img);
35 Logs::setLog("backup:log", 'Keep original file. Destination: ' . $this->backup_dir . "/" . $original_img);
36 }
37 }
38
39 /**
40 * @param $source
41 * @param $destination
42 * @param $subDir
43 *
44 * @return void
45 */
46 public function restoreOriginalImages($source = '', $destination = '', $subDir = '')
47 {
48 if (empty($source)) {
49 $source = $this->backup_dir;
50 }
51 if (empty($destination)) {
52 $destination = $this->upload_dir;
53 }
54 $directory = opendir($source);
55
56 if (is_dir($destination) === false) {
57 mkdir($destination);
58 }
59
60 if ($subDir !== '') {
61 if (is_dir("$destination/$subDir") === false) {
62 mkdir("$destination/$subDir");
63 }
64
65 while (($file = readdir($directory)) !== false) {
66 if ($file === '.' || $file === '..') {
67 continue;
68 }
69
70 if (is_dir("$source/$file") === true) {
71 $this->restoreOriginalImages("$source/$file", "$destination/$subDir/$file");
72 } else {
73 rename("$source/$file", "$destination/$subDir/$file");
74 }
75 }
76
77 closedir($directory);
78
79 return;
80 }
81
82 while (($file = readdir($directory)) !== false) {
83 if ($file === '.' || $file === '..') {
84 continue;
85 }
86
87 if (is_dir("$source/$file") === true) {
88 $this->restoreOriginalImages("$source/$file", "$destination/$file");
89 } else {
90 rename("$source/$file", "$destination/$file");
91 }
92 }
93
94 closedir($directory);
95 }
96
97 public function deleteBackup()
98 {
99 foreach (glob("{$this->backup_dir}/*") as $file) {
100 if (is_dir($file)) {
101 $this->deleteBackup($file);
102 } else {
103 unlink($file);
104 }
105 }
106 rmdir($this->backup_dir);
107 }
108
109 }
110