web/wp-admin/includes/class-wp-filesystem-base.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    11  *
    11  *
    12  * @since 2.5
    12  * @since 2.5
    13  */
    13  */
    14 class WP_Filesystem_Base {
    14 class WP_Filesystem_Base {
    15 	/**
    15 	/**
    16 	 * Whether to display debug data for the connection or not.
    16 	 * Whether to display debug data for the connection.
    17 	 *
    17 	 *
    18 	 * @since 2.5
    18 	 * @since 2.5
    19 	 * @access public
    19 	 * @access public
    20 	 * @var bool
    20 	 * @var bool
    21 	 */
    21 	 */
    22 	var $verbose = false;
    22 	var $verbose = false;
    23 	/**
    23 	/**
    24 	 * Cached list of local filepaths to maped remote filepaths.
    24 	 * Cached list of local filepaths to mapped remote filepaths.
    25 	 *
    25 	 *
    26 	 * @since 2.7
    26 	 * @since 2.7
    27 	 * @access private
    27 	 * @access private
    28 	 * @var array
    28 	 * @var array
    29 	 */
    29 	 */
    80 	 * @access public
    80 	 * @access public
    81 	 *
    81 	 *
    82 	 * @return string The location of the remote path.
    82 	 * @return string The location of the remote path.
    83 	 */
    83 	 */
    84 	function wp_themes_dir() {
    84 	function wp_themes_dir() {
    85 		return $this->wp_content_dir() . '/themes';
    85 		return $this->wp_content_dir() . 'themes/';
       
    86 	}
       
    87 	/**
       
    88 	 * Returns the path on the remote filesystem of WP_LANG_DIR
       
    89 	 *
       
    90 	 * @since 3.2.0
       
    91 	 * @access public
       
    92 	 *
       
    93 	 * @return string The location of the remote path.
       
    94 	 */
       
    95 	function wp_lang_dir() {
       
    96 		return $this->find_folder(WP_LANG_DIR);
    86 	}
    97 	}
    87 
    98 
    88 	/**
    99 	/**
    89 	 * Locates a folder on the remote filesystem.
   100 	 * Locates a folder on the remote filesystem.
    90 	 *
   101 	 *
   135 	 * @return string The location of the remote path.
   146 	 * @return string The location of the remote path.
   136 	 */
   147 	 */
   137 	function find_folder($folder) {
   148 	function find_folder($folder) {
   138 
   149 
   139 		if ( strpos($this->method, 'ftp') !== false ) {
   150 		if ( strpos($this->method, 'ftp') !== false ) {
   140 			$constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR );
   151 			$constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, 'FTP_LANG_DIR' => WP_LANG_DIR );
   141 			foreach ( $constant_overrides as $constant => $dir )
   152 			foreach ( $constant_overrides as $constant => $dir )
   142 				if ( defined($constant) && $folder === $dir )
   153 				if ( defined($constant) && $folder === $dir )
   143 					return trailingslashit(constant($constant));
   154 					return trailingslashit(constant($constant));
   144 		} elseif ( 'direct' == $this->method ) {
   155 		} elseif ( 'direct' == $this->method ) {
       
   156 			$folder = str_replace('\\', '/', $folder); //Windows path sanitisation
   145 			return trailingslashit($folder);
   157 			return trailingslashit($folder);
   146 		}
   158 		}
   147 
   159 
   148 		$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
   160 		$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows drive letter if it's there.
   149 		$folder = str_replace('\\', '/', $folder); //Windows path sanitiation
   161 		$folder = str_replace('\\', '/', $folder); //Windows path sanitisation
   150 
   162 
   151 		if ( isset($this->cache[ $folder ] ) )
   163 		if ( isset($this->cache[ $folder ] ) )
   152 			return $this->cache[ $folder ];
   164 			return $this->cache[ $folder ];
   153 
   165 
   154 		if ( $this->exists($folder) ) { //Folder exists at that absolute path.
   166 		if ( $this->exists($folder) ) { //Folder exists at that absolute path.
   155 			$folder = trailingslashit($folder);
   167 			$folder = trailingslashit($folder);
   156 			$this->cache[ $folder ] = $folder;
   168 			$this->cache[ $folder ] = $folder;
   157 			return $folder;
   169 			return $folder;
   158 		}
   170 		}
   159 		if( $return = $this->search_for_folder($folder) )
   171 		if ( $return = $this->search_for_folder($folder) )
   160 			$this->cache[ $folder ] = $return;
   172 			$this->cache[ $folder ] = $return;
   161 		return $return;
   173 		return $return;
   162 	}
   174 	}
   163 
   175 
   164 	/**
   176 	/**
   201 				if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
   213 				if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
   202 					return $ret;
   214 					return $ret;
   203 			}
   215 			}
   204 		}
   216 		}
   205 
   217 
   206 		//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.
   218 		//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.
   207 		if (isset( $files[ $last_path ] ) ) {
   219 		if (isset( $files[ $last_path ] ) ) {
   208 			if ( $this->verbose )
   220 			if ( $this->verbose )
   209 				printf( __('Found %s') . '<br/>',  $base . $last_path );
   221 				printf( __('Found %s') . '<br/>',  $base . $last_path );
   210 			return trailingslashit($base . $last_path);
   222 			return trailingslashit($base . $last_path);
   211 		}
   223 		}
   212 		if ( $loop )
   224 		if ( $loop )
   213 			return false; //Prevent tihs function looping again.
   225 			return false; //Prevent this function from looping again.
   214 		//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.
   226 		//As an extra last resort, Change back to / if the folder wasn't found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
   215 		return $this->search_for_folder($folder, '/', true);
   227 		return $this->search_for_folder($folder, '/', true);
   216 
   228 
   217 	}
   229 	}
   218 
   230 
   219 	/**
   231 	/**
   286 	function getnumchmodfromh($mode) {
   298 	function getnumchmodfromh($mode) {
   287 		$realmode = '';
   299 		$realmode = '';
   288 		$legal =  array('', 'w', 'r', 'x', '-');
   300 		$legal =  array('', 'w', 'r', 'x', '-');
   289 		$attarray = preg_split('//', $mode);
   301 		$attarray = preg_split('//', $mode);
   290 
   302 
   291 		for($i=0; $i < count($attarray); $i++)
   303 		for ($i=0; $i < count($attarray); $i++)
   292 		   if($key = array_search($attarray[$i], $legal))
   304 		   if ($key = array_search($attarray[$i], $legal))
   293 			   $realmode .= $legal[$key];
   305 			   $realmode .= $legal[$key];
   294 
   306 
   295 		$mode = str_pad($realmode, 9, '-');
   307 		$mode = str_pad($realmode, 9, '-');
   296 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   308 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   297 		$mode = strtr($mode,$trans);
   309 		$mode = strtr($mode,$trans);
   314 	 */
   326 	 */
   315 	function is_binary( $text ) {
   327 	function is_binary( $text ) {
   316 		return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
   328 		return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127)
   317 	}
   329 	}
   318 }
   330 }
   319 
       
   320 ?>