|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Adslight; |
|
4
|
|
|
|
|
5
|
|
|
// ------------------------------------------------------------------------- // |
|
6
|
|
|
// XOOPS - Module MP Manager // |
|
7
|
|
|
// <http://www.xoops.org/> // |
|
8
|
|
|
// ------------------------------------------------------------------------- // |
|
9
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
10
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
11
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
12
|
|
|
// (at your option) any later version. // |
|
13
|
|
|
// // |
|
14
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
15
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
16
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
17
|
|
|
// GNU General Public License for more details. // |
|
18
|
|
|
// // |
|
19
|
|
|
// You should have received a copy of the GNU General Public License // |
|
20
|
|
|
// along with this program; if not, write to the Free Software // |
|
21
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
22
|
|
|
// ------------------------------------------------------------------------- // |
|
23
|
|
|
// Votre nouveau systeme de messagerie priver // |
|
24
|
|
|
// // |
|
25
|
|
|
// "MP" // |
|
26
|
|
|
// // |
|
27
|
|
|
// http://lexode.info/mods // |
|
28
|
|
|
// // |
|
29
|
|
|
// // |
|
30
|
|
|
//---------------------------------------------------------------------------// |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class FS_Storage |
|
34
|
|
|
* @package XoopsModules\Adslight |
|
35
|
|
|
*/ |
|
36
|
|
|
class FS_Storage |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var String |
|
41
|
|
|
*/ |
|
42
|
|
|
public $rootDir; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* FS_Storage constructor. |
|
46
|
|
|
* @param $rootDir |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct($rootDir) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->rootDir = $rootDir; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $location |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function deldir($location) |
|
57
|
|
|
{ |
|
58
|
|
|
if (is_dir($location)) { |
|
59
|
|
|
$all = opendir($location); |
|
60
|
|
|
while ($file = readdir($all)) { |
|
|
|
|
|
|
61
|
|
|
if ('..' !== $file && '.' !== $file && is_dir("$location/$file")) { |
|
62
|
|
|
self::deldir("$location/$file"); |
|
63
|
|
|
if (file_exists("$location/$file")) { |
|
64
|
|
|
rmdir("$location/$file"); |
|
65
|
|
|
} |
|
66
|
|
|
unset($file); |
|
67
|
|
|
} elseif (!is_dir("$location/$file")) { |
|
68
|
|
|
if (file_exists("$location/$file")) { |
|
69
|
|
|
unlink("$location/$file"); |
|
70
|
|
|
} |
|
71
|
|
|
unset($file); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
closedir($all); |
|
|
|
|
|
|
75
|
|
|
rmdir($location); |
|
76
|
|
|
} else { |
|
77
|
|
|
if (file_exists((string)$location)) { |
|
78
|
|
|
unlink((string)$location); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param $fichier |
|
85
|
|
|
* @return false|string |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function date_modif($fichier) |
|
88
|
|
|
{ |
|
89
|
|
|
$tmp = filemtime($fichier); |
|
90
|
|
|
return date('d/m/Y H:i', $tmp); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
// A function to copy files from one directory to another one, including subdirectories and |
|
95
|
|
|
// nonexisting or newer files. Function returns number of files copied. |
|
96
|
|
|
// This function is PHP implementation of Windows xcopy A:\dir1\* B:\dir2 /D /E /F /H /R /Y |
|
97
|
|
|
// Syntaxis: [$number =] dircopy($sourcedirectory, $destinationdirectory [, $verbose]); |
|
98
|
|
|
// Example: $num = dircopy('A:\dir1', 'B:\dir2', 1); |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param $srcdir |
|
102
|
|
|
* @param $dstdir |
|
103
|
|
|
* @param $errors |
|
104
|
|
|
* @param $success |
|
105
|
|
|
* @param bool $verbose |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
|
|
public static function dircopy($srcdir, $dstdir, &$errors, &$success, $verbose = false) |
|
109
|
|
|
{ |
|
110
|
|
|
$num = 0; |
|
111
|
|
|
if (!is_dir($dstdir)) { |
|
112
|
|
|
if (!mkdir($dstdir) && !is_dir($dstdir)) { |
|
113
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dstdir)); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
if ($curdir = opendir($srcdir)) { |
|
117
|
|
|
while ($file = readdir($curdir)) { |
|
118
|
|
|
if ('.' !== $file && '..' !== $file) { |
|
119
|
|
|
$srcfile = $srcdir . DIRECTORY_SEPARATOR . $file; |
|
120
|
|
|
$dstfile = $dstdir . DIRECTORY_SEPARATOR . $file; |
|
121
|
|
|
if (is_file($srcfile)) { |
|
122
|
|
|
if (is_file($dstfile)) { |
|
123
|
|
|
$ow = filemtime($srcfile) - filemtime($dstfile); |
|
124
|
|
|
} else { |
|
125
|
|
|
$ow = 1; |
|
126
|
|
|
} |
|
127
|
|
|
if ($ow > 0) { |
|
128
|
|
|
if ($verbose) { |
|
129
|
|
|
echo "Copying '$srcfile' to '$dstfile'..."; |
|
130
|
|
|
} |
|
131
|
|
|
if (copy($srcfile, $dstfile)) { |
|
132
|
|
|
touch($dstfile, filemtime($srcfile)); |
|
133
|
|
|
$num++; |
|
134
|
|
|
if ($verbose) { |
|
135
|
|
|
echo "OK\n"; |
|
136
|
|
|
} |
|
137
|
|
|
$success[] = $srcfile; |
|
138
|
|
|
} else { |
|
139
|
|
|
$errors[] = $srcfile; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} else if (is_dir($srcfile)) { |
|
143
|
|
|
$num += self::dircopy($srcfile, $dstfile, $errors, $success, $verbose); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
closedir($curdir); |
|
148
|
|
|
} |
|
149
|
|
|
return $num; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param $destDir |
|
154
|
|
|
* @param $srcFile |
|
155
|
|
|
* @param $error |
|
156
|
|
|
* @param $success |
|
157
|
|
|
* @param bool $move |
|
158
|
|
|
*/ |
|
159
|
|
|
public static function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move = false) |
|
160
|
|
|
{ |
|
161
|
|
|
$mess = ConfService::getMessages(); |
|
|
|
|
|
|
162
|
|
|
$destFile = ConfService::getRootDir() . $destDir . '/' . basename($srcFile); |
|
163
|
|
|
$realSrcFile = ConfService::getRootDir() . "/$srcFile"; |
|
164
|
|
|
if (!file_exists($realSrcFile)) { |
|
165
|
|
|
$error[] = $mess[100] . $srcFile; |
|
166
|
|
|
return; |
|
167
|
|
|
} |
|
168
|
|
|
if ($realSrcFile == $destFile) { |
|
169
|
|
|
$error[] = $mess[101]; |
|
170
|
|
|
return; |
|
171
|
|
|
} |
|
172
|
|
|
if (is_dir($realSrcFile)) { |
|
173
|
|
|
$errors = []; |
|
174
|
|
|
$succFiles = []; |
|
175
|
|
|
$dirRes = self::dircopy($realSrcFile, $destFile, $errors, $succFiles); |
|
176
|
|
|
if (count($errors)) { |
|
177
|
|
|
$error[] = $mess[114]; |
|
178
|
|
|
return; |
|
179
|
|
|
} |
|
180
|
|
|
} else { |
|
181
|
|
|
$res = copy($realSrcFile, $destFile); |
|
182
|
|
|
if (1 != $res) { |
|
183
|
|
|
$error[] = $mess[114]; |
|
184
|
|
|
return; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
if ($move) { |
|
189
|
|
|
// Now delete original |
|
190
|
|
|
self::deldir($realSrcFile); // both file and dir |
|
191
|
|
|
$messagePart = $mess[74] . " $destDir"; |
|
192
|
|
|
if ($destDir == '/' . ConfService::getRecycleBinDir()) { |
|
193
|
|
|
$messagePart = $mess[123] . ' ' . $mess[122]; |
|
194
|
|
|
} |
|
195
|
|
|
if (isset($dirRes)) { |
|
196
|
|
|
$success[] = $mess[117] . ' ' . basename($srcFile) . ' ' . $messagePart . " ($dirRes " . $mess[116] . ') '; |
|
197
|
|
|
} else { |
|
198
|
|
|
$success[] = $mess[34] . ' ' . basename($srcFile) . ' ' . $messagePart; |
|
199
|
|
|
} |
|
200
|
|
|
} else { |
|
201
|
|
|
if (isSet($dirRes)) { |
|
202
|
|
|
$success[] = $mess[117] . ' ' . basename($srcFile) . ' ' . $mess[73] . " $destDir (" . $dirRes . ' ' . $mess[116] . ')'; |
|
203
|
|
|
} else { |
|
204
|
|
|
$success[] = $mess[34] . ' ' . basename($srcFile) . ' ' . $mess[73] . " $destDir"; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|