30 public $cache = array(); |
29 public $cache = array(); |
31 |
30 |
32 /** |
31 /** |
33 * The Access method of the current connection, Set automatically. |
32 * The Access method of the current connection, Set automatically. |
34 * |
33 * |
35 * @access public |
|
36 * @since 2.5.0 |
34 * @since 2.5.0 |
37 * @var string |
35 * @var string |
38 */ |
36 */ |
39 public $method = ''; |
37 public $method = ''; |
40 |
38 |
|
39 /** |
|
40 * @var WP_Error |
|
41 */ |
41 public $errors = null; |
42 public $errors = null; |
42 |
43 |
|
44 /** |
|
45 */ |
43 public $options = array(); |
46 public $options = array(); |
44 |
47 |
45 /** |
48 /** |
46 * Return the path on the remote filesystem of ABSPATH. |
49 * Return the path on the remote filesystem of ABSPATH. |
47 * |
50 * |
48 * @access public |
|
49 * @since 2.7.0 |
51 * @since 2.7.0 |
50 * |
52 * |
51 * @return string The location of the remote path. |
53 * @return string The location of the remote path. |
52 */ |
54 */ |
53 public function abspath() { |
55 public function abspath() { |
114 } |
112 } |
115 |
113 |
116 /** |
114 /** |
117 * Locate a folder on the remote filesystem. |
115 * Locate a folder on the remote filesystem. |
118 * |
116 * |
119 * @access public |
|
120 * @since 2.5.0 |
117 * @since 2.5.0 |
121 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead. |
118 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead. |
122 * @see WP_Filesystem::abspath() |
119 * @see WP_Filesystem::abspath() |
123 * @see WP_Filesystem::wp_content_dir() |
120 * @see WP_Filesystem::wp_content_dir() |
124 * @see WP_Filesystem::wp_plugins_dir() |
121 * @see WP_Filesystem::wp_plugins_dir() |
129 * @param bool $echo True to display debug information. |
126 * @param bool $echo True to display debug information. |
130 * Default false. |
127 * Default false. |
131 * @return string The location of the remote path. |
128 * @return string The location of the remote path. |
132 */ |
129 */ |
133 public function find_base_dir( $base = '.', $echo = false ) { |
130 public function find_base_dir( $base = '.', $echo = false ) { |
134 _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); |
131 _deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); |
135 $this->verbose = $echo; |
132 $this->verbose = $echo; |
136 return $this->abspath(); |
133 return $this->abspath(); |
137 } |
134 } |
138 |
135 |
139 /** |
136 /** |
140 * Locate a folder on the remote filesystem. |
137 * Locate a folder on the remote filesystem. |
141 * |
138 * |
142 * @access public |
|
143 * @since 2.5.0 |
139 * @since 2.5.0 |
144 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead. |
140 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead. |
145 * @see WP_Filesystem::abspath() |
141 * @see WP_Filesystem::abspath() |
146 * @see WP_Filesystem::wp_content_dir() |
142 * @see WP_Filesystem::wp_content_dir() |
147 * @see WP_Filesystem::wp_plugins_dir() |
143 * @see WP_Filesystem::wp_plugins_dir() |
151 * @param string $base The folder to start searching from. |
147 * @param string $base The folder to start searching from. |
152 * @param bool $echo True to display debug information. |
148 * @param bool $echo True to display debug information. |
153 * @return string The location of the remote path. |
149 * @return string The location of the remote path. |
154 */ |
150 */ |
155 public function get_base_dir( $base = '.', $echo = false ) { |
151 public function get_base_dir( $base = '.', $echo = false ) { |
156 _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); |
152 _deprecated_function(__FUNCTION__, '2.7.0', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); |
157 $this->verbose = $echo; |
153 $this->verbose = $echo; |
158 return $this->abspath(); |
154 return $this->abspath(); |
159 } |
155 } |
160 |
156 |
161 /** |
157 /** |
162 * Locate a folder on the remote filesystem. |
158 * Locate a folder on the remote filesystem. |
163 * |
159 * |
164 * Assumes that on Windows systems, Stripping off the Drive |
160 * Assumes that on Windows systems, Stripping off the Drive |
165 * letter is OK Sanitizes \\ to / in windows filepaths. |
161 * letter is OK Sanitizes \\ to / in windows filepaths. |
166 * |
162 * |
167 * @access public |
|
168 * @since 2.7.0 |
163 * @since 2.7.0 |
169 * |
164 * |
170 * @param string $folder the folder to locate. |
165 * @param string $folder the folder to locate. |
171 * @return string|false The location of the remote path, false on failure. |
166 * @return string|false The location of the remote path, false on failure. |
172 */ |
167 */ |
173 public function find_folder( $folder ) { |
168 public function find_folder( $folder ) { |
174 |
|
175 if ( isset( $this->cache[ $folder ] ) ) |
169 if ( isset( $this->cache[ $folder ] ) ) |
176 return $this->cache[ $folder ]; |
170 return $this->cache[ $folder ]; |
177 |
171 |
178 if ( stripos($this->method, 'ftp') !== false ) { |
172 if ( stripos($this->method, 'ftp') !== false ) { |
179 $constant_overrides = array( |
173 $constant_overrides = array( |
242 if ( empty( $base ) || '.' == $base ) |
236 if ( empty( $base ) || '.' == $base ) |
243 $base = trailingslashit($this->cwd()); |
237 $base = trailingslashit($this->cwd()); |
244 |
238 |
245 $folder = untrailingslashit($folder); |
239 $folder = untrailingslashit($folder); |
246 |
240 |
247 if ( $this->verbose ) |
241 if ( $this->verbose ) { |
248 printf( "\n" . __('Looking for %1$s in %2$s') . "<br/>\n", $folder, $base ); |
242 /* translators: 1: folder to locate, 2: folder to start searching from */ |
|
243 printf( "\n" . __( 'Looking for %1$s in %2$s' ) . "<br/>\n", $folder, $base ); |
|
244 } |
249 |
245 |
250 $folder_parts = explode('/', $folder); |
246 $folder_parts = explode('/', $folder); |
251 $folder_part_keys = array_keys( $folder_parts ); |
247 $folder_part_keys = array_keys( $folder_parts ); |
252 $last_index = array_pop( $folder_part_keys ); |
248 $last_index = array_pop( $folder_part_keys ); |
253 $last_path = $folder_parts[ $last_index ]; |
249 $last_path = $folder_parts[ $last_index ]; |
267 */ |
263 */ |
268 if ( isset($files[ $key ]) ){ |
264 if ( isset($files[ $key ]) ){ |
269 |
265 |
270 // Let's try that folder: |
266 // Let's try that folder: |
271 $newdir = trailingslashit(path_join($base, $key)); |
267 $newdir = trailingslashit(path_join($base, $key)); |
272 if ( $this->verbose ) |
268 if ( $this->verbose ) { |
273 printf( "\n" . __('Changing to %s') . "<br/>\n", $newdir ); |
269 /* translators: %s: directory name */ |
|
270 printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir ); |
|
271 } |
274 |
272 |
275 // Only search for the remaining path tokens in the directory, not the full path again. |
273 // Only search for the remaining path tokens in the directory, not the full path again. |
276 $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); |
274 $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); |
277 if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) ) |
275 if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) ) |
278 return $ret; |
276 return $ret; |
279 } |
277 } |
280 } |
278 } |
281 |
279 |
282 // Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take. |
280 // Only check this as a last resort, to prevent locating the incorrect install. |
|
281 // All above procedures will fail quickly if this is the right branch to take. |
283 if (isset( $files[ $last_path ] ) ) { |
282 if (isset( $files[ $last_path ] ) ) { |
284 if ( $this->verbose ) |
283 if ( $this->verbose ) { |
285 printf( "\n" . __('Found %s') . "<br/>\n", $base . $last_path ); |
284 /* translators: %s: directory name */ |
|
285 printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path ); |
|
286 } |
286 return trailingslashit($base . $last_path); |
287 return trailingslashit($base . $last_path); |
287 } |
288 } |
288 |
289 |
289 // Prevent this function from looping again. |
290 // Prevent this function from looping again. |
290 // No need to proceed if we've just searched in / |
291 // No need to proceed if we've just searched in / |
300 /** |
301 /** |
301 * Return the *nix-style file permissions for a file. |
302 * Return the *nix-style file permissions for a file. |
302 * |
303 * |
303 * From the PHP documentation page for fileperms(). |
304 * From the PHP documentation page for fileperms(). |
304 * |
305 * |
305 * @link http://docs.php.net/fileperms |
306 * @link https://secure.php.net/manual/en/function.fileperms.php |
306 * |
307 * |
307 * @access public |
|
308 * @since 2.5.0 |
308 * @since 2.5.0 |
309 * |
309 * |
310 * @param string $file String filename. |
310 * @param string $file String filename. |
311 * @return string The *nix-style representation of permissions. |
311 * @return string The *nix-style representation of permissions. |
312 */ |
312 */ |
313 public function gethchmod( $file ){ |
313 public function gethchmod( $file ){ |
314 $perms = $this->getchmod($file); |
314 $perms = intval( $this->getchmod( $file ), 8 ); |
315 if (($perms & 0xC000) == 0xC000) // Socket |
315 if (($perms & 0xC000) == 0xC000) // Socket |
316 $info = 's'; |
316 $info = 's'; |
317 elseif (($perms & 0xA000) == 0xA000) // Symbolic Link |
317 elseif (($perms & 0xA000) == 0xA000) // Symbolic Link |
318 $info = 'l'; |
318 $info = 'l'; |
319 elseif (($perms & 0x8000) == 0x8000) // Regular |
319 elseif (($perms & 0x8000) == 0x8000) // Regular |
351 (($perms & 0x0200) ? 'T' : '-')); |
351 (($perms & 0x0200) ? 'T' : '-')); |
352 return $info; |
352 return $info; |
353 } |
353 } |
354 |
354 |
355 /** |
355 /** |
|
356 * Gets the permissions of the specified file or filepath in their octal format |
|
357 * |
|
358 * @since 2.5.0 |
|
359 * @param string $file |
|
360 * @return string the last 3 characters of the octal number |
|
361 */ |
|
362 public function getchmod( $file ) { |
|
363 return '777'; |
|
364 } |
|
365 |
|
366 /** |
356 * Convert *nix-style file permissions to a octal number. |
367 * Convert *nix-style file permissions to a octal number. |
357 * |
368 * |
358 * Converts '-rw-r--r--' to 0644 |
369 * Converts '-rw-r--r--' to 0644 |
359 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() |
370 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() |
360 * |
371 * |
361 * @link http://docs.php.net/manual/en/function.chmod.php#49614 |
372 * @link https://secure.php.net/manual/en/function.chmod.php#49614 |
362 * |
373 * |
363 * @access public |
|
364 * @since 2.5.0 |
374 * @since 2.5.0 |
365 * |
375 * |
366 * @param string $mode string The *nix-style file permission. |
376 * @param string $mode string The *nix-style file permission. |
367 * @return int octal representation |
377 * @return int octal representation |
368 */ |
378 */ |
454 /** |
467 /** |
455 * Write a string to a file. |
468 * Write a string to a file. |
456 * |
469 * |
457 * @since 2.5.0 |
470 * @since 2.5.0 |
458 * @abstract |
471 * @abstract |
|
472 * |
459 * @param string $file Remote path to the file where to write the data. |
473 * @param string $file Remote path to the file where to write the data. |
460 * @param string $contents The data to write. |
474 * @param string $contents The data to write. |
461 * @param int $mode Optional. The file permissions as octal number, usually 0644. |
475 * @param int $mode Optional. The file permissions as octal number, usually 0644. |
462 * @return bool False on failure. |
476 * @return bool False on failure. |
463 */ |
477 */ |
479 /** |
494 /** |
480 * Change current directory. |
495 * Change current directory. |
481 * |
496 * |
482 * @since 2.5.0 |
497 * @since 2.5.0 |
483 * @abstract |
498 * @abstract |
|
499 * |
484 * @param string $dir The new current directory. |
500 * @param string $dir The new current directory. |
485 * @return bool Returns true on success or false on failure. |
501 * @return bool|string |
486 */ |
502 */ |
487 public function chdir( $dir ) { |
503 public function chdir( $dir ) { |
488 return false; |
504 return false; |
489 } |
505 } |
490 |
506 |
491 /** |
507 /** |
492 * Change the file group. |
508 * Change the file group. |
493 * |
509 * |
494 * @since 2.5.0 |
510 * @since 2.5.0 |
495 * @abstract |
511 * @abstract |
|
512 * |
496 * @param string $file Path to the file. |
513 * @param string $file Path to the file. |
497 * @param mixed $group A group name or number. |
514 * @param mixed $group A group name or number. |
498 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
515 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
499 * @return bool Returns true on success or false on failure. |
516 * @return bool|string |
500 */ |
517 */ |
501 public function chgrp( $file, $group, $recursive = false ) { |
518 public function chgrp( $file, $group, $recursive = false ) { |
502 return false; |
519 return false; |
503 } |
520 } |
504 |
521 |
505 /** |
522 /** |
506 * Change filesystem permissions. |
523 * Change filesystem permissions. |
507 * |
524 * |
508 * @since 2.5.0 |
525 * @since 2.5.0 |
509 * @abstract |
526 * @abstract |
|
527 * |
510 * @param string $file Path to the file. |
528 * @param string $file Path to the file. |
511 * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. |
529 * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. |
512 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
530 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
513 * @return bool Returns true on success or false on failure. |
531 * @return bool|string |
514 */ |
532 */ |
515 public function chmod( $file, $mode = false, $recursive = false ) { |
533 public function chmod( $file, $mode = false, $recursive = false ) { |
516 return false; |
534 return false; |
517 } |
535 } |
518 |
536 |
519 /** |
537 /** |
520 * Get the file owner. |
538 * Get the file owner. |
521 * |
539 * |
522 * @since 2.5.0 |
540 * @since 2.5.0 |
523 * @abstract |
541 * @abstract |
|
542 * |
524 * @param string $file Path to the file. |
543 * @param string $file Path to the file. |
525 * @return string|bool Username of the user or false on error. |
544 * @return string|bool Username of the user or false on error. |
526 */ |
545 */ |
527 public function owner( $file ) { |
546 public function owner( $file ) { |
528 return false; |
547 return false; |
543 /** |
563 /** |
544 * Copy a file. |
564 * Copy a file. |
545 * |
565 * |
546 * @since 2.5.0 |
566 * @since 2.5.0 |
547 * @abstract |
567 * @abstract |
|
568 * |
548 * @param string $source Path to the source file. |
569 * @param string $source Path to the source file. |
549 * @param string $destination Path to the destination file. |
570 * @param string $destination Path to the destination file. |
550 * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
571 * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
551 * Default false. |
572 * Default false. |
552 * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. |
573 * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. |
560 /** |
581 /** |
561 * Move a file. |
582 * Move a file. |
562 * |
583 * |
563 * @since 2.5.0 |
584 * @since 2.5.0 |
564 * @abstract |
585 * @abstract |
|
586 * |
565 * @param string $source Path to the source file. |
587 * @param string $source Path to the source file. |
566 * @param string $destination Path to the destination file. |
588 * @param string $destination Path to the destination file. |
567 * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
589 * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. |
568 * Default false. |
590 * Default false. |
569 * @return bool True if file copied successfully, False otherwise. |
591 * @return bool True if file copied successfully, False otherwise. |
575 /** |
597 /** |
576 * Delete a file or directory. |
598 * Delete a file or directory. |
577 * |
599 * |
578 * @since 2.5.0 |
600 * @since 2.5.0 |
579 * @abstract |
601 * @abstract |
|
602 * |
580 * @param string $file Path to the file. |
603 * @param string $file Path to the file. |
581 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
604 * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. |
582 * Default false. |
605 * Default false. |
583 * @param bool $type Type of resource. 'f' for file, 'd' for directory. |
606 * @param bool $type Type of resource. 'f' for file, 'd' for directory. |
584 * Default false. |
607 * Default false. |
704 /** |
737 /** |
705 * Create a directory. |
738 * Create a directory. |
706 * |
739 * |
707 * @since 2.5.0 |
740 * @since 2.5.0 |
708 * @abstract |
741 * @abstract |
|
742 * |
709 * @param string $path Path for new directory. |
743 * @param string $path Path for new directory. |
710 * @param mixed $chmod Optional. The permissions as octal number, (or False to skip chmod) |
744 * @param mixed $chmod Optional. The permissions as octal number, (or False to skip chmod) |
711 * Default false. |
745 * Default false. |
712 * @param mixed $chown Optional. A user name or number (or False to skip chown) |
746 * @param mixed $chown Optional. A user name or number (or False to skip chown) |
713 * Default false. |
747 * Default false. |