PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-filesystem-base.php

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