author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Base WordPress Filesystem |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Filesystem |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
9 | 10 |
* Base WordPress Filesystem class which Filesystem implementations extend. |
0 | 11 |
* |
12 |
* @since 2.5.0 |
|
13 |
*/ |
|
14 |
class WP_Filesystem_Base { |
|
9 | 15 |
|
0 | 16 |
/** |
17 |
* Whether to display debug data for the connection. |
|
18 |
* |
|
19 |
* @since 2.5.0 |
|
20 |
* @var bool |
|
21 |
*/ |
|
5 | 22 |
public $verbose = false; |
0 | 23 |
|
24 |
/** |
|
25 |
* Cached list of local filepaths to mapped remote filepaths. |
|
26 |
* |
|
27 |
* @since 2.7.0 |
|
28 |
* @var array |
|
29 |
*/ |
|
5 | 30 |
public $cache = array(); |
0 | 31 |
|
32 |
/** |
|
33 |
* The Access method of the current connection, Set automatically. |
|
34 |
* |
|
35 |
* @since 2.5.0 |
|
36 |
* @var string |
|
37 |
*/ |
|
5 | 38 |
public $method = ''; |
0 | 39 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* @var WP_Error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
*/ |
5 | 43 |
public $errors = null; |
44 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
*/ |
5 | 47 |
public $options = array(); |
0 | 48 |
|
49 |
/** |
|
9 | 50 |
* Returns the path on the remote filesystem of ABSPATH. |
0 | 51 |
* |
52 |
* @since 2.7.0 |
|
53 |
* |
|
54 |
* @return string The location of the remote path. |
|
55 |
*/ |
|
5 | 56 |
public function abspath() { |
9 | 57 |
$folder = $this->find_folder( ABSPATH ); |
16 | 58 |
|
59 |
// Perhaps the FTP folder is rooted at the WordPress install. |
|
60 |
// Check for wp-includes folder in root. Could have some false positives, but rare. |
|
9 | 61 |
if ( ! $folder && $this->is_dir( '/' . WPINC ) ) { |
0 | 62 |
$folder = '/'; |
9 | 63 |
} |
16 | 64 |
|
0 | 65 |
return $folder; |
66 |
} |
|
67 |
||
68 |
/** |
|
9 | 69 |
* Returns the path on the remote filesystem of WP_CONTENT_DIR. |
0 | 70 |
* |
71 |
* @since 2.7.0 |
|
72 |
* |
|
73 |
* @return string The location of the remote path. |
|
74 |
*/ |
|
5 | 75 |
public function wp_content_dir() { |
9 | 76 |
return $this->find_folder( WP_CONTENT_DIR ); |
0 | 77 |
} |
78 |
||
79 |
/** |
|
9 | 80 |
* Returns the path on the remote filesystem of WP_PLUGIN_DIR. |
0 | 81 |
* |
82 |
* @since 2.7.0 |
|
83 |
* |
|
84 |
* @return string The location of the remote path. |
|
85 |
*/ |
|
5 | 86 |
public function wp_plugins_dir() { |
9 | 87 |
return $this->find_folder( WP_PLUGIN_DIR ); |
0 | 88 |
} |
89 |
||
90 |
/** |
|
9 | 91 |
* Returns the path on the remote filesystem of the Themes Directory. |
0 | 92 |
* |
93 |
* @since 2.7.0 |
|
94 |
* |
|
9 | 95 |
* @param string|false $theme Optional. The theme stylesheet or template for the directory. |
96 |
* Default false. |
|
0 | 97 |
* @return string The location of the remote path. |
98 |
*/ |
|
5 | 99 |
public function wp_themes_dir( $theme = false ) { |
0 | 100 |
$theme_root = get_theme_root( $theme ); |
101 |
||
16 | 102 |
// Account for relative theme roots. |
103 |
if ( '/themes' === $theme_root || ! is_dir( $theme_root ) ) { |
|
0 | 104 |
$theme_root = WP_CONTENT_DIR . $theme_root; |
9 | 105 |
} |
0 | 106 |
|
107 |
return $this->find_folder( $theme_root ); |
|
108 |
} |
|
109 |
||
110 |
/** |
|
9 | 111 |
* Returns the path on the remote filesystem of WP_LANG_DIR. |
0 | 112 |
* |
113 |
* @since 3.2.0 |
|
114 |
* |
|
115 |
* @return string The location of the remote path. |
|
116 |
*/ |
|
5 | 117 |
public function wp_lang_dir() { |
9 | 118 |
return $this->find_folder( WP_LANG_DIR ); |
0 | 119 |
} |
120 |
||
121 |
/** |
|
9 | 122 |
* Locates a folder on the remote filesystem. |
0 | 123 |
* |
124 |
* @since 2.5.0 |
|
18 | 125 |
* @deprecated 2.7.0 use WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir() instead. |
126 |
* @see WP_Filesystem_Base::abspath() |
|
127 |
* @see WP_Filesystem_Base::wp_content_dir() |
|
128 |
* @see WP_Filesystem_Base::wp_plugins_dir() |
|
129 |
* @see WP_Filesystem_Base::wp_themes_dir() |
|
130 |
* @see WP_Filesystem_Base::wp_lang_dir() |
|
0 | 131 |
* |
19 | 132 |
* @param string $base Optional. The folder to start searching from. Default '.'. |
133 |
* @param bool $verbose Optional. True to display debug information. Default false. |
|
0 | 134 |
* @return string The location of the remote path. |
135 |
*/ |
|
19 | 136 |
public function find_base_dir( $base = '.', $verbose = false ) { |
18 | 137 |
_deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir()' ); |
19 | 138 |
$this->verbose = $verbose; |
0 | 139 |
return $this->abspath(); |
140 |
} |
|
141 |
||
142 |
/** |
|
9 | 143 |
* Locates a folder on the remote filesystem. |
0 | 144 |
* |
145 |
* @since 2.5.0 |
|
18 | 146 |
* @deprecated 2.7.0 use WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir() methods instead. |
147 |
* @see WP_Filesystem_Base::abspath() |
|
148 |
* @see WP_Filesystem_Base::wp_content_dir() |
|
149 |
* @see WP_Filesystem_Base::wp_plugins_dir() |
|
150 |
* @see WP_Filesystem_Base::wp_themes_dir() |
|
151 |
* @see WP_Filesystem_Base::wp_lang_dir() |
|
0 | 152 |
* |
19 | 153 |
* @param string $base Optional. The folder to start searching from. Default '.'. |
154 |
* @param bool $verbose Optional. True to display debug information. Default false. |
|
0 | 155 |
* @return string The location of the remote path. |
156 |
*/ |
|
19 | 157 |
public function get_base_dir( $base = '.', $verbose = false ) { |
18 | 158 |
_deprecated_function( __FUNCTION__, '2.7.0', 'WP_Filesystem_Base::abspath() or WP_Filesystem_Base::wp_*_dir()' ); |
19 | 159 |
$this->verbose = $verbose; |
0 | 160 |
return $this->abspath(); |
161 |
} |
|
162 |
||
163 |
/** |
|
9 | 164 |
* Locates a folder on the remote filesystem. |
0 | 165 |
* |
166 |
* Assumes that on Windows systems, Stripping off the Drive |
|
9 | 167 |
* letter is OK Sanitizes \\ to / in Windows filepaths. |
0 | 168 |
* |
169 |
* @since 2.7.0 |
|
170 |
* |
|
171 |
* @param string $folder the folder to locate. |
|
5 | 172 |
* @return string|false The location of the remote path, false on failure. |
0 | 173 |
*/ |
5 | 174 |
public function find_folder( $folder ) { |
9 | 175 |
if ( isset( $this->cache[ $folder ] ) ) { |
0 | 176 |
return $this->cache[ $folder ]; |
9 | 177 |
} |
0 | 178 |
|
9 | 179 |
if ( stripos( $this->method, 'ftp' ) !== false ) { |
0 | 180 |
$constant_overrides = array( |
9 | 181 |
'FTP_BASE' => ABSPATH, |
0 | 182 |
'FTP_CONTENT_DIR' => WP_CONTENT_DIR, |
9 | 183 |
'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, |
184 |
'FTP_LANG_DIR' => WP_LANG_DIR, |
|
0 | 185 |
); |
186 |
||
16 | 187 |
// Direct matches ( folder = CONSTANT/ ). |
0 | 188 |
foreach ( $constant_overrides as $constant => $dir ) { |
9 | 189 |
if ( ! defined( $constant ) ) { |
0 | 190 |
continue; |
9 | 191 |
} |
16 | 192 |
|
9 | 193 |
if ( $folder === $dir ) { |
0 | 194 |
return trailingslashit( constant( $constant ) ); |
9 | 195 |
} |
0 | 196 |
} |
197 |
||
16 | 198 |
// Prefix matches ( folder = CONSTANT/subdir ), |
0 | 199 |
foreach ( $constant_overrides as $constant => $dir ) { |
9 | 200 |
if ( ! defined( $constant ) ) { |
0 | 201 |
continue; |
9 | 202 |
} |
16 | 203 |
|
204 |
if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir. |
|
0 | 205 |
$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); |
206 |
$potential_folder = trailingslashit( $potential_folder ); |
|
207 |
||
208 |
if ( $this->is_dir( $potential_folder ) ) { |
|
209 |
$this->cache[ $folder ] = $potential_folder; |
|
16 | 210 |
|
0 | 211 |
return $potential_folder; |
212 |
} |
|
213 |
} |
|
214 |
} |
|
16 | 215 |
} elseif ( 'direct' === $this->method ) { |
216 |
$folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. |
|
217 |
||
9 | 218 |
return trailingslashit( $folder ); |
0 | 219 |
} |
220 |
||
16 | 221 |
$folder = preg_replace( '|^([a-z]{1}):|i', '', $folder ); // Strip out Windows drive letter if it's there. |
222 |
$folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. |
|
0 | 223 |
|
9 | 224 |
if ( isset( $this->cache[ $folder ] ) ) { |
0 | 225 |
return $this->cache[ $folder ]; |
9 | 226 |
} |
0 | 227 |
|
9 | 228 |
if ( $this->exists( $folder ) ) { // Folder exists at that absolute path. |
229 |
$folder = trailingslashit( $folder ); |
|
0 | 230 |
$this->cache[ $folder ] = $folder; |
16 | 231 |
|
0 | 232 |
return $folder; |
233 |
} |
|
16 | 234 |
|
235 |
$return = $this->search_for_folder( $folder ); |
|
236 |
||
237 |
if ( $return ) { |
|
0 | 238 |
$this->cache[ $folder ] = $return; |
9 | 239 |
} |
16 | 240 |
|
0 | 241 |
return $return; |
242 |
} |
|
243 |
||
244 |
/** |
|
9 | 245 |
* Locates a folder on the remote filesystem. |
0 | 246 |
* |
247 |
* Expects Windows sanitized path. |
|
248 |
* |
|
249 |
* @since 2.7.0 |
|
250 |
* |
|
251 |
* @param string $folder The folder to locate. |
|
252 |
* @param string $base The folder to start searching from. |
|
16 | 253 |
* @param bool $loop If the function has recursed. Internal use only. |
5 | 254 |
* @return string|false The location of the remote path, false to cease looping. |
0 | 255 |
*/ |
5 | 256 |
public function search_for_folder( $folder, $base = '.', $loop = false ) { |
16 | 257 |
if ( empty( $base ) || '.' === $base ) { |
9 | 258 |
$base = trailingslashit( $this->cwd() ); |
259 |
} |
|
0 | 260 |
|
9 | 261 |
$folder = untrailingslashit( $folder ); |
0 | 262 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
if ( $this->verbose ) { |
16 | 264 |
/* translators: 1: Folder to locate, 2: Folder to start searching from. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br/>\n", $folder, $base ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
} |
0 | 267 |
|
9 | 268 |
$folder_parts = explode( '/', $folder ); |
0 | 269 |
$folder_part_keys = array_keys( $folder_parts ); |
9 | 270 |
$last_index = array_pop( $folder_part_keys ); |
271 |
$last_path = $folder_parts[ $last_index ]; |
|
0 | 272 |
|
273 |
$files = $this->dirlist( $base ); |
|
274 |
||
275 |
foreach ( $folder_parts as $index => $key ) { |
|
18 | 276 |
if ( $index === $last_index ) { |
0 | 277 |
continue; // We want this to be caught by the next code block. |
9 | 278 |
} |
0 | 279 |
|
5 | 280 |
/* |
281 |
* Working from /home/ to /user/ to /wordpress/ see if that file exists within |
|
282 |
* the current folder, If it's found, change into it and follow through looking |
|
9 | 283 |
* for it. If it can't find WordPress down that route, it'll continue onto the next |
5 | 284 |
* folder level, and see if that matches, and so on. If it reaches the end, and still |
9 | 285 |
* can't find it, it'll return false for the entire function. |
5 | 286 |
*/ |
9 | 287 |
if ( isset( $files[ $key ] ) ) { |
5 | 288 |
|
289 |
// Let's try that folder: |
|
9 | 290 |
$newdir = trailingslashit( path_join( $base, $key ) ); |
16 | 291 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
if ( $this->verbose ) { |
16 | 293 |
/* translators: %s: Directory name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
} |
5 | 296 |
|
297 |
// Only search for the remaining path tokens in the directory, not the full path again. |
|
0 | 298 |
$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); |
16 | 299 |
$ret = $this->search_for_folder( $newfolder, $newdir, $loop ); |
300 |
||
301 |
if ( $ret ) { |
|
0 | 302 |
return $ret; |
9 | 303 |
} |
0 | 304 |
} |
305 |
} |
|
306 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
// Only check this as a last resort, to prevent locating the incorrect install. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
// All above procedures will fail quickly if this is the right branch to take. |
9 | 309 |
if ( isset( $files[ $last_path ] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
if ( $this->verbose ) { |
16 | 311 |
/* translators: %s: Directory name. */ |
9 | 312 |
printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
} |
16 | 314 |
|
9 | 315 |
return trailingslashit( $base . $last_path ); |
0 | 316 |
} |
317 |
||
318 |
// Prevent this function from looping again. |
|
16 | 319 |
// No need to proceed if we've just searched in `/`. |
320 |
if ( $loop || '/' === $base ) { |
|
0 | 321 |
return false; |
9 | 322 |
} |
0 | 323 |
|
324 |
// As an extra last resort, Change back to / if the folder wasn't found. |
|
325 |
// This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... |
|
326 |
return $this->search_for_folder( $folder, '/', true ); |
|
327 |
||
328 |
} |
|
329 |
||
330 |
/** |
|
9 | 331 |
* Returns the *nix-style file permissions for a file. |
0 | 332 |
* |
333 |
* From the PHP documentation page for fileperms(). |
|
334 |
* |
|
16 | 335 |
* @link https://www.php.net/manual/en/function.fileperms.php |
0 | 336 |
* |
337 |
* @since 2.5.0 |
|
338 |
* |
|
339 |
* @param string $file String filename. |
|
340 |
* @return string The *nix-style representation of permissions. |
|
341 |
*/ |
|
9 | 342 |
public function gethchmod( $file ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
$perms = intval( $this->getchmod( $file ), 8 ); |
16 | 344 |
|
18 | 345 |
if ( ( $perms & 0xC000 ) === 0xC000 ) { // Socket. |
0 | 346 |
$info = 's'; |
18 | 347 |
} elseif ( ( $perms & 0xA000 ) === 0xA000 ) { // Symbolic Link. |
0 | 348 |
$info = 'l'; |
18 | 349 |
} elseif ( ( $perms & 0x8000 ) === 0x8000 ) { // Regular. |
0 | 350 |
$info = '-'; |
18 | 351 |
} elseif ( ( $perms & 0x6000 ) === 0x6000 ) { // Block special. |
0 | 352 |
$info = 'b'; |
18 | 353 |
} elseif ( ( $perms & 0x4000 ) === 0x4000 ) { // Directory. |
0 | 354 |
$info = 'd'; |
18 | 355 |
} elseif ( ( $perms & 0x2000 ) === 0x2000 ) { // Character special. |
0 | 356 |
$info = 'c'; |
18 | 357 |
} elseif ( ( $perms & 0x1000 ) === 0x1000 ) { // FIFO pipe. |
0 | 358 |
$info = 'p'; |
16 | 359 |
} else { // Unknown. |
0 | 360 |
$info = 'u'; |
9 | 361 |
} |
0 | 362 |
|
16 | 363 |
// Owner. |
9 | 364 |
$info .= ( ( $perms & 0x0100 ) ? 'r' : '-' ); |
365 |
$info .= ( ( $perms & 0x0080 ) ? 'w' : '-' ); |
|
366 |
$info .= ( ( $perms & 0x0040 ) ? |
|
367 |
( ( $perms & 0x0800 ) ? 's' : 'x' ) : |
|
368 |
( ( $perms & 0x0800 ) ? 'S' : '-' ) ); |
|
0 | 369 |
|
16 | 370 |
// Group. |
9 | 371 |
$info .= ( ( $perms & 0x0020 ) ? 'r' : '-' ); |
372 |
$info .= ( ( $perms & 0x0010 ) ? 'w' : '-' ); |
|
373 |
$info .= ( ( $perms & 0x0008 ) ? |
|
374 |
( ( $perms & 0x0400 ) ? 's' : 'x' ) : |
|
375 |
( ( $perms & 0x0400 ) ? 'S' : '-' ) ); |
|
0 | 376 |
|
16 | 377 |
// World. |
9 | 378 |
$info .= ( ( $perms & 0x0004 ) ? 'r' : '-' ); |
379 |
$info .= ( ( $perms & 0x0002 ) ? 'w' : '-' ); |
|
380 |
$info .= ( ( $perms & 0x0001 ) ? |
|
381 |
( ( $perms & 0x0200 ) ? 't' : 'x' ) : |
|
382 |
( ( $perms & 0x0200 ) ? 'T' : '-' ) ); |
|
16 | 383 |
|
0 | 384 |
return $info; |
385 |
} |
|
386 |
||
387 |
/** |
|
9 | 388 |
* Gets the permissions of the specified file or filepath in their octal format. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* @since 2.5.0 |
9 | 391 |
* |
392 |
* @param string $file Path to the file. |
|
393 |
* @return string Mode of the file (the last 3 digits). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
public function getchmod( $file ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
return '777'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
/** |
9 | 400 |
* Converts *nix-style file permissions to a octal number. |
0 | 401 |
* |
402 |
* Converts '-rw-r--r--' to 0644 |
|
403 |
* From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() |
|
9 | 404 |
* |
16 | 405 |
* @link https://www.php.net/manual/en/function.chmod.php#49614 |
0 | 406 |
* |
407 |
* @since 2.5.0 |
|
408 |
* |
|
19 | 409 |
* @param string $mode string The *nix-style file permissions. |
410 |
* @return string Octal representation of permissions. |
|
0 | 411 |
*/ |
5 | 412 |
public function getnumchmodfromh( $mode ) { |
0 | 413 |
$realmode = ''; |
9 | 414 |
$legal = array( '', 'w', 'r', 'x', '-' ); |
415 |
$attarray = preg_split( '//', $mode ); |
|
0 | 416 |
|
5 | 417 |
for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) { |
16 | 418 |
$key = array_search( $attarray[ $i ], $legal, true ); |
419 |
||
420 |
if ( $key ) { |
|
9 | 421 |
$realmode .= $legal[ $key ]; |
422 |
} |
|
5 | 423 |
} |
0 | 424 |
|
9 | 425 |
$mode = str_pad( $realmode, 10, '-', STR_PAD_LEFT ); |
426 |
$trans = array( |
|
427 |
'-' => '0', |
|
428 |
'r' => '4', |
|
429 |
'w' => '2', |
|
430 |
'x' => '1', |
|
431 |
); |
|
432 |
$mode = strtr( $mode, $trans ); |
|
0 | 433 |
|
9 | 434 |
$newmode = $mode[0]; |
0 | 435 |
$newmode .= $mode[1] + $mode[2] + $mode[3]; |
436 |
$newmode .= $mode[4] + $mode[5] + $mode[6]; |
|
437 |
$newmode .= $mode[7] + $mode[8] + $mode[9]; |
|
16 | 438 |
|
0 | 439 |
return $newmode; |
440 |
} |
|
441 |
||
442 |
/** |
|
9 | 443 |
* Determines if the string provided contains binary characters. |
0 | 444 |
* |
445 |
* @since 2.7.0 |
|
446 |
* |
|
447 |
* @param string $text String to test against. |
|
9 | 448 |
* @return bool True if string is binary, false otherwise. |
0 | 449 |
*/ |
5 | 450 |
public function is_binary( $text ) { |
0 | 451 |
return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127) |
452 |
} |
|
453 |
||
454 |
/** |
|
9 | 455 |
* Changes the owner of a file or directory. |
0 | 456 |
* |
457 |
* Default behavior is to do nothing, override this in your subclass, if desired. |
|
458 |
* |
|
459 |
* @since 2.5.0 |
|
460 |
* |
|
9 | 461 |
* @param string $file Path to the file or directory. |
462 |
* @param string|int $owner A user name or number. |
|
463 |
* @param bool $recursive Optional. If set to true, changes file owner recursively. |
|
464 |
* Default false. |
|
465 |
* @return bool True on success, false on failure. |
|
0 | 466 |
*/ |
5 | 467 |
public function chown( $file, $owner, $recursive = false ) { |
0 | 468 |
return false; |
469 |
} |
|
470 |
||
471 |
/** |
|
9 | 472 |
* Connects filesystem. |
0 | 473 |
* |
474 |
* @since 2.5.0 |
|
5 | 475 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
* |
9 | 477 |
* @return bool True on success, false on failure (always true for WP_Filesystem_Direct). |
0 | 478 |
*/ |
5 | 479 |
public function connect() { |
0 | 480 |
return true; |
481 |
} |
|
482 |
||
483 |
/** |
|
9 | 484 |
* Reads entire file into a string. |
0 | 485 |
* |
486 |
* @since 2.5.0 |
|
5 | 487 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* |
0 | 489 |
* @param string $file Name of the file to read. |
9 | 490 |
* @return string|false Read data on success, false on failure. |
0 | 491 |
*/ |
5 | 492 |
public function get_contents( $file ) { |
0 | 493 |
return false; |
494 |
} |
|
495 |
||
496 |
/** |
|
9 | 497 |
* Reads entire file into an array. |
0 | 498 |
* |
499 |
* @since 2.5.0 |
|
5 | 500 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* |
0 | 502 |
* @param string $file Path to the file. |
9 | 503 |
* @return array|false File contents in an array on success, false on failure. |
0 | 504 |
*/ |
5 | 505 |
public function get_contents_array( $file ) { |
0 | 506 |
return false; |
507 |
} |
|
508 |
||
509 |
/** |
|
9 | 510 |
* Writes a string to a file. |
0 | 511 |
* |
512 |
* @since 2.5.0 |
|
5 | 513 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* |
9 | 515 |
* @param string $file Remote path to the file where to write the data. |
516 |
* @param string $contents The data to write. |
|
517 |
* @param int|false $mode Optional. The file permissions as octal number, usually 0644. |
|
518 |
* Default false. |
|
519 |
* @return bool True on success, false on failure. |
|
0 | 520 |
*/ |
5 | 521 |
public function put_contents( $file, $contents, $mode = false ) { |
0 | 522 |
return false; |
523 |
} |
|
524 |
||
525 |
/** |
|
9 | 526 |
* Gets the current working directory. |
0 | 527 |
* |
528 |
* @since 2.5.0 |
|
5 | 529 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* |
9 | 531 |
* @return string|false The current working directory on success, false on failure. |
0 | 532 |
*/ |
5 | 533 |
public function cwd() { |
0 | 534 |
return false; |
535 |
} |
|
536 |
||
537 |
/** |
|
9 | 538 |
* Changes current directory. |
0 | 539 |
* |
540 |
* @since 2.5.0 |
|
5 | 541 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
* |
0 | 543 |
* @param string $dir The new current directory. |
9 | 544 |
* @return bool True on success, false on failure. |
0 | 545 |
*/ |
5 | 546 |
public function chdir( $dir ) { |
0 | 547 |
return false; |
548 |
} |
|
549 |
||
550 |
/** |
|
9 | 551 |
* Changes the file group. |
0 | 552 |
* |
553 |
* @since 2.5.0 |
|
5 | 554 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
* |
9 | 556 |
* @param string $file Path to the file. |
557 |
* @param string|int $group A group name or number. |
|
558 |
* @param bool $recursive Optional. If set to true, changes file group recursively. |
|
559 |
* Default false. |
|
560 |
* @return bool True on success, false on failure. |
|
0 | 561 |
*/ |
5 | 562 |
public function chgrp( $file, $group, $recursive = false ) { |
0 | 563 |
return false; |
564 |
} |
|
565 |
||
566 |
/** |
|
9 | 567 |
* Changes filesystem permissions. |
0 | 568 |
* |
569 |
* @since 2.5.0 |
|
5 | 570 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
* |
9 | 572 |
* @param string $file Path to the file. |
573 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
574 |
* 0755 for directories. Default false. |
|
16 | 575 |
* @param bool $recursive Optional. If set to true, changes file permissions recursively. |
9 | 576 |
* Default false. |
577 |
* @return bool True on success, false on failure. |
|
0 | 578 |
*/ |
5 | 579 |
public function chmod( $file, $mode = false, $recursive = false ) { |
0 | 580 |
return false; |
581 |
} |
|
582 |
||
583 |
/** |
|
9 | 584 |
* Gets the file owner. |
0 | 585 |
* |
586 |
* @since 2.5.0 |
|
5 | 587 |
* @abstract |
9 | 588 |
* |
0 | 589 |
* @param string $file Path to the file. |
9 | 590 |
* @return string|false Username of the owner on success, false on failure. |
0 | 591 |
*/ |
5 | 592 |
public function owner( $file ) { |
0 | 593 |
return false; |
594 |
} |
|
595 |
||
596 |
/** |
|
9 | 597 |
* Gets the file's group. |
0 | 598 |
* |
599 |
* @since 2.5.0 |
|
5 | 600 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
* |
0 | 602 |
* @param string $file Path to the file. |
9 | 603 |
* @return string|false The group on success, false on failure. |
0 | 604 |
*/ |
5 | 605 |
public function group( $file ) { |
0 | 606 |
return false; |
607 |
} |
|
608 |
||
609 |
/** |
|
9 | 610 |
* Copies a file. |
611 |
* |
|
612 |
* @since 2.5.0 |
|
613 |
* @abstract |
|
614 |
* |
|
615 |
* @param string $source Path to the source file. |
|
616 |
* @param string $destination Path to the destination file. |
|
617 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
618 |
* Default false. |
|
619 |
* @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, |
|
620 |
* 0755 for dirs. Default false. |
|
621 |
* @return bool True on success, false on failure. |
|
622 |
*/ |
|
623 |
public function copy( $source, $destination, $overwrite = false, $mode = false ) { |
|
624 |
return false; |
|
625 |
} |
|
626 |
||
627 |
/** |
|
628 |
* Moves a file. |
|
0 | 629 |
* |
630 |
* @since 2.5.0 |
|
5 | 631 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* |
0 | 633 |
* @param string $source Path to the source file. |
634 |
* @param string $destination Path to the destination file. |
|
635 |
* @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
|
636 |
* Default false. |
|
9 | 637 |
* @return bool True on success, false on failure. |
0 | 638 |
*/ |
5 | 639 |
public function move( $source, $destination, $overwrite = false ) { |
0 | 640 |
return false; |
641 |
} |
|
642 |
||
643 |
/** |
|
9 | 644 |
* Deletes a file or directory. |
0 | 645 |
* |
646 |
* @since 2.5.0 |
|
5 | 647 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
* |
9 | 649 |
* @param string $file Path to the file or directory. |
16 | 650 |
* @param bool $recursive Optional. If set to true, deletes files and folders recursively. |
9 | 651 |
* Default false. |
652 |
* @param string|false $type Type of resource. 'f' for file, 'd' for directory. |
|
653 |
* Default false. |
|
654 |
* @return bool True on success, false on failure. |
|
0 | 655 |
*/ |
5 | 656 |
public function delete( $file, $recursive = false, $type = false ) { |
0 | 657 |
return false; |
658 |
} |
|
659 |
||
660 |
/** |
|
9 | 661 |
* Checks if a file or directory exists. |
0 | 662 |
* |
663 |
* @since 2.5.0 |
|
5 | 664 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
* |
9 | 666 |
* @param string $file Path to file or directory. |
0 | 667 |
* @return bool Whether $file exists or not. |
668 |
*/ |
|
5 | 669 |
public function exists( $file ) { |
0 | 670 |
return false; |
671 |
} |
|
672 |
||
673 |
/** |
|
9 | 674 |
* Checks if resource is a file. |
0 | 675 |
* |
676 |
* @since 2.5.0 |
|
5 | 677 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
* |
0 | 679 |
* @param string $file File path. |
680 |
* @return bool Whether $file is a file. |
|
681 |
*/ |
|
5 | 682 |
public function is_file( $file ) { |
0 | 683 |
return false; |
684 |
} |
|
685 |
||
686 |
/** |
|
9 | 687 |
* Checks if resource is a directory. |
0 | 688 |
* |
689 |
* @since 2.5.0 |
|
5 | 690 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* |
0 | 692 |
* @param string $path Directory path. |
693 |
* @return bool Whether $path is a directory. |
|
694 |
*/ |
|
5 | 695 |
public function is_dir( $path ) { |
0 | 696 |
return false; |
697 |
} |
|
698 |
||
699 |
/** |
|
9 | 700 |
* Checks if a file is readable. |
0 | 701 |
* |
702 |
* @since 2.5.0 |
|
5 | 703 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
* |
0 | 705 |
* @param string $file Path to file. |
706 |
* @return bool Whether $file is readable. |
|
707 |
*/ |
|
5 | 708 |
public function is_readable( $file ) { |
0 | 709 |
return false; |
710 |
} |
|
711 |
||
712 |
/** |
|
9 | 713 |
* Checks if a file or directory is writable. |
0 | 714 |
* |
715 |
* @since 2.5.0 |
|
5 | 716 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* |
9 | 718 |
* @param string $file Path to file or directory. |
0 | 719 |
* @return bool Whether $file is writable. |
720 |
*/ |
|
5 | 721 |
public function is_writable( $file ) { |
0 | 722 |
return false; |
723 |
} |
|
724 |
||
725 |
/** |
|
726 |
* Gets the file's last access time. |
|
727 |
* |
|
728 |
* @since 2.5.0 |
|
5 | 729 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* |
0 | 731 |
* @param string $file Path to file. |
9 | 732 |
* @return int|false Unix timestamp representing last access time, false on failure. |
0 | 733 |
*/ |
5 | 734 |
public function atime( $file ) { |
0 | 735 |
return false; |
736 |
} |
|
737 |
||
738 |
/** |
|
739 |
* Gets the file modification time. |
|
740 |
* |
|
741 |
* @since 2.5.0 |
|
5 | 742 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
* |
0 | 744 |
* @param string $file Path to file. |
9 | 745 |
* @return int|false Unix timestamp representing modification time, false on failure. |
0 | 746 |
*/ |
5 | 747 |
public function mtime( $file ) { |
0 | 748 |
return false; |
749 |
} |
|
750 |
||
751 |
/** |
|
752 |
* Gets the file size (in bytes). |
|
753 |
* |
|
754 |
* @since 2.5.0 |
|
5 | 755 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* |
0 | 757 |
* @param string $file Path to file. |
9 | 758 |
* @return int|false Size of the file in bytes on success, false on failure. |
0 | 759 |
*/ |
5 | 760 |
public function size( $file ) { |
0 | 761 |
return false; |
762 |
} |
|
763 |
||
764 |
/** |
|
9 | 765 |
* Sets the access and modification times of a file. |
0 | 766 |
* |
767 |
* Note: If $file doesn't exist, it will be created. |
|
768 |
* |
|
769 |
* @since 2.5.0 |
|
5 | 770 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
* |
0 | 772 |
* @param string $file Path to file. |
773 |
* @param int $time Optional. Modified time to set for file. |
|
774 |
* Default 0. |
|
775 |
* @param int $atime Optional. Access time to set for file. |
|
776 |
* Default 0. |
|
9 | 777 |
* @return bool True on success, false on failure. |
0 | 778 |
*/ |
5 | 779 |
public function touch( $file, $time = 0, $atime = 0 ) { |
0 | 780 |
return false; |
781 |
} |
|
782 |
||
783 |
/** |
|
9 | 784 |
* Creates a directory. |
0 | 785 |
* |
786 |
* @since 2.5.0 |
|
5 | 787 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
* |
18 | 789 |
* @param string $path Path for new directory. |
790 |
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod). |
|
791 |
* Default false. |
|
792 |
* @param string|int|false $chown Optional. A user name or number (or false to skip chown). |
|
793 |
* Default false. |
|
794 |
* @param string|int|false $chgrp Optional. A group name or number (or false to skip chgrp). |
|
795 |
* Default false. |
|
9 | 796 |
* @return bool True on success, false on failure. |
0 | 797 |
*/ |
5 | 798 |
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { |
0 | 799 |
return false; |
800 |
} |
|
801 |
||
802 |
/** |
|
9 | 803 |
* Deletes a directory. |
0 | 804 |
* |
805 |
* @since 2.5.0 |
|
5 | 806 |
* @abstract |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
* |
0 | 808 |
* @param string $path Path to directory. |
809 |
* @param bool $recursive Optional. Whether to recursively remove files/directories. |
|
810 |
* Default false. |
|
9 | 811 |
* @return bool True on success, false on failure. |
0 | 812 |
*/ |
5 | 813 |
public function rmdir( $path, $recursive = false ) { |
0 | 814 |
return false; |
815 |
} |
|
816 |
||
817 |
/** |
|
9 | 818 |
* Gets details for files in a directory or a specific file. |
0 | 819 |
* |
820 |
* @since 2.5.0 |
|
5 | 821 |
* @abstract |
0 | 822 |
* |
823 |
* @param string $path Path to directory or file. |
|
824 |
* @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. |
|
825 |
* Default true. |
|
826 |
* @param bool $recursive Optional. Whether to recursively include file details in nested directories. |
|
827 |
* Default false. |
|
9 | 828 |
* @return array|false { |
0 | 829 |
* Array of files. False if unable to list directory contents. |
830 |
* |
|
9 | 831 |
* @type string $name Name of the file or directory. |
5 | 832 |
* @type string $perms *nix representation of permissions. |
19 | 833 |
* @type string $permsn Octal representation of permissions. |
5 | 834 |
* @type string $owner Owner name or ID. |
835 |
* @type int $size Size of file in bytes. |
|
836 |
* @type int $lastmodunix Last modified unix timestamp. |
|
837 |
* @type mixed $lastmod Last modified month (3 letter) and day (without leading 0). |
|
838 |
* @type int $time Last modified time. |
|
839 |
* @type string $type Type of resource. 'f' for file, 'd' for directory. |
|
19 | 840 |
* @type mixed $files If a directory and `$recursive` is true, contains another array of files. |
0 | 841 |
* } |
842 |
*/ |
|
5 | 843 |
public function dirlist( $path, $include_hidden = true, $recursive = false ) { |
0 | 844 |
return false; |
845 |
} |
|
846 |
||
16 | 847 |
} |