web/wp-admin/includes/class-wp-filesystem-base.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
   191 			$base = trailingslashit($this->cwd());
   191 			$base = trailingslashit($this->cwd());
   192 
   192 
   193 		$folder = untrailingslashit($folder);
   193 		$folder = untrailingslashit($folder);
   194 
   194 
   195 		$folder_parts = explode('/', $folder);
   195 		$folder_parts = explode('/', $folder);
   196 		$last_path = $folder_parts[ count($folder_parts) - 1 ];
   196 		$last_index = array_pop( array_keys( $folder_parts ) );
       
   197 		$last_path = $folder_parts[ $last_index ];
   197 
   198 
   198 		$files = $this->dirlist( $base );
   199 		$files = $this->dirlist( $base );
   199 
   200 
   200 		foreach ( $folder_parts as $key ) {
   201 		foreach ( $folder_parts as $index => $key ) {
   201 			if ( $key == $last_path )
   202 			if ( $index == $last_index )
   202 				continue; //We want this to be caught by the next code block.
   203 				continue; //We want this to be caught by the next code block.
   203 
   204 
   204 			//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
   205 			//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
   205 			// If its found, change into it and follow through looking for it.
   206 			// If its found, change into it and follow through looking for it.
   206 			// If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
   207 			// If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
   208 			if ( isset($files[ $key ]) ){
   209 			if ( isset($files[ $key ]) ){
   209 				//Lets try that folder:
   210 				//Lets try that folder:
   210 				$newdir = trailingslashit(path_join($base, $key));
   211 				$newdir = trailingslashit(path_join($base, $key));
   211 				if ( $this->verbose )
   212 				if ( $this->verbose )
   212 					printf( __('Changing to %s') . '<br/>', $newdir );
   213 					printf( __('Changing to %s') . '<br/>', $newdir );
   213 				if ( $ret = $this->search_for_folder( $folder, $newdir, $loop) )
   214 				// only search for the remaining path tokens in the directory, not the full path again
       
   215 				$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
       
   216 				if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) )
   214 					return $ret;
   217 					return $ret;
   215 			}
   218 			}
   216 		}
   219 		}
   217 
   220 
   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.
   221 		//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.
   302 
   305 
   303 		for ($i=0; $i < count($attarray); $i++)
   306 		for ($i=0; $i < count($attarray); $i++)
   304 		   if ($key = array_search($attarray[$i], $legal))
   307 		   if ($key = array_search($attarray[$i], $legal))
   305 			   $realmode .= $legal[$key];
   308 			   $realmode .= $legal[$key];
   306 
   309 
   307 		$mode = str_pad($realmode, 9, '-');
   310 		$mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
   308 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   311 		$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');
   309 		$mode = strtr($mode,$trans);
   312 		$mode = strtr($mode,$trans);
   310 
   313 
   311 		$newmode = '';
   314 		$newmode = $mode[0];
   312 		$newmode .= $mode[0] + $mode[1] + $mode[2];
   315 		$newmode .= $mode[1] + $mode[2] + $mode[3];
   313 		$newmode .= $mode[3] + $mode[4] + $mode[5];
   316 		$newmode .= $mode[4] + $mode[5] + $mode[6];
   314 		$newmode .= $mode[6] + $mode[7] + $mode[8];
   317 		$newmode .= $mode[7] + $mode[8] + $mode[9];
   315 		return $newmode;
   318 		return $newmode;
   316 	}
   319 	}
   317 
   320 
   318 	/**
   321 	/**
   319 	 * Determines if the string provided contains binary characters.
   322 	 * Determines if the string provided contains binary characters.