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