-
+ 0A6E0E0180BD0BC43EB8949BC05729B34291A52AEED1F168E9AF5970CEC13405C224A020BE59A0930CBF439C08B5F1F6F32E9EEB1BA8C54DEC5AF1119290D736mp-wp/wp-admin/includes/class-wp-filesystem-base.php(0 . 0)(1 . 316)
30168 <?php
30169 /**
30170 * Base WordPress Filesystem.
30171 *
30172 * @package WordPress
30173 * @subpackage Filesystem
30174 */
30175
30176 /**
30177 * Base WordPress Filesystem class for which Filesystem implementations extend
30178 *
30179 * @since 2.5
30180 */
30181 class WP_Filesystem_Base {
30182 /**
30183 * Whether to display debug data for the connection or not.
30184 *
30185 * @since 2.5
30186 * @access public
30187 * @var bool
30188 */
30189 var $verbose = false;
30190 /**
30191 * Cached list of local filepaths to maped remote filepaths.
30192 *
30193 * @since 2.7
30194 * @access private
30195 * @var array
30196 */
30197 var $cache = array();
30198
30199 /**
30200 * The Access method of the current connection, Set automatically.
30201 *
30202 * @since 2.5
30203 * @access public
30204 * @var string
30205 */
30206 var $method = '';
30207
30208 /**
30209 * Returns the path on the remote filesystem of ABSPATH
30210 *
30211 * @since 2.7
30212 * @access public
30213 * @return string The location of the remote path.
30214 */
30215 function abspath() {
30216 if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
30217 return FTP_BASE;
30218 $folder = $this->find_folder(ABSPATH);
30219 //Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
30220 if ( ! $folder && $this->is_dir('/wp-includes') )
30221 $folder = '/';
30222 return $folder;
30223 }
30224 /**
30225 * Returns the path on the remote filesystem of WP_CONTENT_DIR
30226 *
30227 * @since 2.7
30228 * @access public
30229 * @return string The location of the remote path.
30230 */
30231 function wp_content_dir() {
30232 if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
30233 return FTP_CONTENT_DIR;
30234 return $this->find_folder(WP_CONTENT_DIR);
30235 }
30236 /**
30237 * Returns the path on the remote filesystem of WP_PLUGIN_DIR
30238 *
30239 * @since 2.7
30240 * @access public
30241 *
30242 * @return string The location of the remote path.
30243 */
30244 function wp_plugins_dir() {
30245 if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
30246 return FTP_PLUGIN_DIR;
30247 return $this->find_folder(WP_PLUGIN_DIR);
30248 }
30249 /**
30250 * Returns the path on the remote filesystem of the Themes Directory
30251 *
30252 * @since 2.7
30253 * @access public
30254 *
30255 * @return string The location of the remote path.
30256 */
30257 function wp_themes_dir() {
30258 return $this->wp_content_dir() . '/themes';
30259 }
30260
30261 /**
30262 * Locates a folder on the remote filesystem.
30263 *
30264 * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
30265 *
30266 * @since 2.5
30267 * @deprecated 2.7
30268 * @access public
30269 *
30270 * @param string $base The folder to start searching from
30271 * @param bool $echo True to display debug information
30272 * @return string The location of the remote path.
30273 */
30274 function find_base_dir($base = '.', $echo = false) {
30275 _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
30276 $this->verbose = $echo;
30277 return $this->abspath();
30278 }
30279 /**
30280 * Locates a folder on the remote filesystem.
30281 *
30282 * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
30283 *
30284 * @since 2.5
30285 * @deprecated 2.7
30286 * @access public
30287 *
30288 * @param string $base The folder to start searching from
30289 * @param bool $echo True to display debug information
30290 * @return string The location of the remote path.
30291 */
30292 function get_base_dir($base = '.', $echo = false) {
30293 _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
30294 $this->verbose = $echo;
30295 return $this->abspath();
30296 }
30297
30298 /**
30299 * Locates a folder on the remote filesystem.
30300 *
30301 * Assumes that on Windows systems, Stripping off the Drive letter is OK
30302 * Sanitizes \\ to / in windows filepaths.
30303 *
30304 * @since 2.7
30305 * @access public
30306 *
30307 * @param string $folder the folder to locate
30308 * @return string The location of the remote path.
30309 */
30310 function find_folder($folder) {
30311
30312 $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
30313 $folder = str_replace('\\', '/', $folder); //Windows path sanitiation
30314
30315 if ( isset($this->cache[ $folder ] ) )
30316 return $this->cache[ $folder ];
30317
30318 if ( $this->exists($folder) ) { //Folder exists at that absolute path.
30319 $this->cache[ $folder ] = $folder;
30320 return $folder;
30321 }
30322 if( $return = $this->search_for_folder($folder) )
30323 $this->cache[ $folder ] = $return;
30324 return $return;
30325 }
30326
30327 /**
30328 * Locates a folder on the remote filesystem.
30329 *
30330 * Expects Windows sanitized path
30331 *
30332 * @since 2.7
30333 * @access private
30334 *
30335 * @param string $folder the folder to locate
30336 * @param string $base the folder to start searching from
30337 * @param bool $loop if the function has recursed, Internal use only
30338 * @return string The location of the remote path.
30339 */
30340 function search_for_folder($folder, $base = '.', $loop = false ) {
30341 if ( empty( $base ) || '.' == $base )
30342 $base = trailingslashit($this->cwd());
30343
30344 $folder = untrailingslashit($folder);
30345
30346 $folder_parts = explode('/', $folder);
30347 $last_path = $folder_parts[ count($folder_parts) - 1 ];
30348
30349 $files = $this->dirlist( $base );
30350
30351 foreach ( $folder_parts as $key ) {
30352 if ( $key == $last_path )
30353 continue; //We want this to be caught by the next code block.
30354
30355 //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
30356 // If its found, change into it and follow through looking for it.
30357 // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
30358 // If it reaches the end, and still cant find it, it'll return false for the entire function.
30359 if( isset($files[ $key ]) ){
30360 //Lets try that folder:
30361 $newdir = trailingslashit(path_join($base, $key));
30362 if( $this->verbose )
30363 printf( __('Changing to %s') . '<br/>', $newdir );
30364 if( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
30365 return $ret;
30366 }
30367 }
30368
30369 //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.
30370 if(isset( $files[ $last_path ] ) ) {
30371 if( $this->verbose )
30372 printf( __('Found %s') . '<br/>', $base . $last_path );
30373 return $base . $last_path;
30374 }
30375 if( $loop )
30376 return false;//Prevent tihs function looping again.
30377 //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.
30378 return $this->search_for_folder($folder, '/', true);
30379
30380 }
30381
30382 /**
30383 * Returns the *nix style file permissions for a file
30384 *
30385 * From the PHP documentation page for fileperms()
30386 *
30387 * @link http://docs.php.net/fileperms
30388 * @since 2.5
30389 * @access public
30390 *
30391 * @param string $file string filename
30392 * @return int octal representation of permissions
30393 */
30394 function gethchmod($file){
30395 $perms = $this->getchmod($file);
30396 if (($perms & 0xC000) == 0xC000) // Socket
30397 $info = 's';
30398 elseif (($perms & 0xA000) == 0xA000) // Symbolic Link
30399 $info = 'l';
30400 elseif (($perms & 0x8000) == 0x8000) // Regular
30401 $info = '-';
30402 elseif (($perms & 0x6000) == 0x6000) // Block special
30403 $info = 'b';
30404 elseif (($perms & 0x4000) == 0x4000) // Directory
30405 $info = 'd';
30406 elseif (($perms & 0x2000) == 0x2000) // Character special
30407 $info = 'c';
30408 elseif (($perms & 0x1000) == 0x1000)// FIFO pipe
30409 $info = 'p';
30410 else // Unknown
30411 $info = 'u';
30412
30413 // Owner
30414 $info .= (($perms & 0x0100) ? 'r' : '-');
30415 $info .= (($perms & 0x0080) ? 'w' : '-');
30416 $info .= (($perms & 0x0040) ?
30417 (($perms & 0x0800) ? 's' : 'x' ) :
30418 (($perms & 0x0800) ? 'S' : '-'));
30419
30420 // Group
30421 $info .= (($perms & 0x0020) ? 'r' : '-');
30422 $info .= (($perms & 0x0010) ? 'w' : '-');
30423 $info .= (($perms & 0x0008) ?
30424 (($perms & 0x0400) ? 's' : 'x' ) :
30425 (($perms & 0x0400) ? 'S' : '-'));
30426
30427 // World
30428 $info .= (($perms & 0x0004) ? 'r' : '-');
30429 $info .= (($perms & 0x0002) ? 'w' : '-');
30430 $info .= (($perms & 0x0001) ?
30431 (($perms & 0x0200) ? 't' : 'x' ) :
30432 (($perms & 0x0200) ? 'T' : '-'));
30433 return $info;
30434 }
30435
30436 /**
30437 * Converts *nix style file permissions to a octal number.
30438 *
30439 * Converts '-rw-r--r--' to 0644
30440 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
30441 *
30442 * @link http://docs.php.net/manual/en/function.chmod.php#49614
30443 * @since 2.5
30444 * @access public
30445 *
30446 * @param string $mode string *nix style file permission
30447 * @return int octal representation
30448 */
30449 function getnumchmodfromh($mode) {
30450 $realmode = '';
30451 $legal = array('', 'w', 'r', 'x', '-');
30452 $attarray = preg_split('//', $mode);
30453
30454 for($i=0; $i < count($attarray); $i++)
30455 if($key = array_search($attarray[$i], $legal))
30456 $realmode .= $legal[$key];
30457
30458 $mode = str_pad($realmode, 9, '-');
30459 $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
30460 $mode = strtr($mode,$trans);
30461
30462 $newmode = '';
30463 $newmode .= $mode[0] + $mode[1] + $mode[2];
30464 $newmode .= $mode[3] + $mode[4] + $mode[5];
30465 $newmode .= $mode[6] + $mode[7] + $mode[8];
30466 return $newmode;
30467 }
30468
30469 /**
30470 * Determines if the string provided contains binary characters.
30471 *
30472 * @since 2.7
30473 * @access private
30474 *
30475 * @param string $text String to test against
30476 * @return bool true if string is binary, false otherwise
30477 */
30478 function is_binary( $text ) {
30479 return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
30480 }
30481 }
30482
30483 ?>