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