2 class WP_Filesystem_Base{
9 if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
11 return $this->find_folder(ABSPATH);
13 function wp_content_dir() {
14 if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
15 return FTP_CONTENT_DIR;
16 return $this->find_folder(WP_CONTENT_DIR);
18 function wp_plugins_dir() {
19 if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
20 return FTP_PLUGIN_DIR;
21 return $this->find_folder(WP_PLUGIN_DIR);
23 function wp_themes_dir() {
24 return $this->wp_content_dir() . '/themes';
26 //Back compat: use abspath() or wp_*_dir
27 function find_base_dir($base = '.', $echo = false) {
28 $this->verbose = $echo;
29 return $this->abspath();
31 //Back compat: use ::abspath() or ::wp_*_dir
32 function get_base_dir($base = '.', $echo = false) {
33 $this->verbose = $echo;
34 return $this->abspath();
37 function find_folder($folder) {
38 $folder = str_replace('\\', '/', $folder); //Windows Sanitiation
39 if ( isset($this->cache[ $folder ] ) )
40 return $this->cache[ $folder ];
42 if ( $this->exists($folder) ) { //Folder exists at that absolute path.
43 $this->cache[ $folder ] = $folder;
46 if( $return = $this->search_for_folder($folder) )
47 $this->cache[ $folder ] = $return;
51 // Assumes $folder is windows sanitized;
52 // Assumes that the drive letter is safe to be stripped off, Should not be a problem for windows servers.
53 function search_for_folder($folder, $base = '.', $loop = false ) {
54 if ( empty( $base ) || '.' == $base )
55 $base = trailingslashit($this->cwd());
57 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
59 $folder_parts = explode('/', $folder);
60 $last_path = $folder_parts[ count($folder_parts) - 1 ];
62 $files = $this->dirlist( $base );
64 foreach ( $folder_parts as $key ) {
65 if ( $key == $last_path )
66 continue; //We want this to be caught by the next code block.
68 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
69 // If its found, change into it and follow through looking for it.
70 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
71 // If it reaches the end, and still cant find it, it'll return false for the entire function.
72 if( isset($files[ $key ]) ){
73 //Lets try that folder:
74 $newdir = trailingslashit(path_join($base, $key));
76 printf( __('Changing to %s') . '<br/>', $newdir );
77 if( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
82 //Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
83 if(isset( $files[ $last_path ] ) ) {
85 printf( __('Found %s') . '<br/>', $base . $last_path );
86 return $base . $last_path;
89 return false;//Prevent tihs function looping again.
90 //As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
91 return $this->search_for_folder($folder, '/', true);
95 //Common Helper functions.
96 function gethchmod($file){
97 //From the PHP.net page for ...?
98 $perms = $this->getchmod($file);
99 if (($perms & 0xC000) == 0xC000) // Socket
101 elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
103 elseif (($perms & 0x8000) == 0x8000) // Regular
105 elseif (($perms & 0x6000) == 0x6000) // Block special
107 elseif (($perms & 0x4000) == 0x4000) // Directory
109 elseif (($perms & 0x2000) == 0x2000) // Character special
111 elseif (($perms & 0x1000) == 0x1000)// FIFO pipe
117 $info .= (($perms & 0x0100) ? 'r' : '-');
118 $info .= (($perms & 0x0080) ? 'w' : '-');
119 $info .= (($perms & 0x0040) ?
120 (($perms & 0x0800) ? 's' : 'x' ) :
121 (($perms & 0x0800) ? 'S' : '-'));
124 $info .= (($perms & 0x0020) ? 'r' : '-');
125 $info .= (($perms & 0x0010) ? 'w' : '-');
126 $info .= (($perms & 0x0008) ?
127 (($perms & 0x0400) ? 's' : 'x' ) :
128 (($perms & 0x0400) ? 'S' : '-'));
131 $info .= (($perms & 0x0004) ? 'r' : '-');
132 $info .= (($perms & 0x0002) ? 'w' : '-');
133 $info .= (($perms & 0x0001) ?
134 (($perms & 0x0200) ? 't' : 'x' ) :
135 (($perms & 0x0200) ? 'T' : '-'));
138 function getnumchmodfromh($mode) {
140 $legal = array("", "w", "r", "x", "-");
141 $attarray = preg_split("//", $mode);
143 for($i=0; $i < count($attarray); $i++)
144 if($key = array_search($attarray[$i], $legal))
145 $realmode .= $legal[$key];
147 $mode = str_pad($realmode, 9, '-');
148 $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
149 $mode = strtr($mode,$trans);
152 $newmode .= $mode[0] + $mode[1] + $mode[2];
153 $newmode .= $mode[3] + $mode[4] + $mode[5];
154 $newmode .= $mode[6] + $mode[7] + $mode[8];