/** * Locates a folder on the remote filesystem. * * Expects Windows sanitized path * * @since 2.7 * @access private * * @param string $folder the folder to locate * @param string $base the folder to start searching from * @param bool $loop if the function has recursed, Internal use only * @return string The location of the remote path. */ function search_for_folder($folder, $base = '.', $loop = false) { if (empty($base) || '.' == $base) { $base = File::trailingslashit($this->cwd()); } $folder = File::untrailingslashit($folder); $folder_parts = explode('/', $folder); $last_path = $folder_parts[count($folder_parts) - 1]; $files = $this->dirlist($base); foreach ($folder_parts as $key) { if ($key == $last_path) { continue; } //We want this to be caught by the next code block. //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, // If its found, change into it and follow through looking for it. // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. // If it reaches the end, and still cant find it, it'll return false for the entire function. if (isset($files[$key])) { //Lets try that folder: $newdir = File::trailingslashit(File::path_join($base, $key)); if ($this->verbose) { printf(__('Changing to %s') . '<br/>', $newdir); } if ($ret = $this->search_for_folder($folder, $newdir, $loop)) { return $ret; } } } //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. if (isset($files[$last_path])) { if ($this->verbose) { printf(__('Found %s') . '<br/>', $base . $last_path); } return File::trailingslashit($base . $last_path); } if ($loop) { return false; } //Prevent this function from looping again. //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. return $this->search_for_folder($folder, '/', true); }