home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / includes / class-wp-filesystem-base.php < prev    next >
Encoding:
PHP Script  |  2017-07-26  |  21.7 KB  |  802 lines

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