deprecated FileUtil loadFile() method
This commit is contained in:
		| @@ -3,7 +3,6 @@ | |||||||
| namespace ManiaControl\Files; | namespace ManiaControl\Files; | ||||||
|  |  | ||||||
| use ManiaControl\Logger; | use ManiaControl\Logger; | ||||||
| use ManiaControl\ManiaControl; |  | ||||||
| use ManiaControl\Utils\Formatter; | use ManiaControl\Utils\Formatter; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -16,57 +15,12 @@ use ManiaControl\Utils\Formatter; | |||||||
| abstract class FileUtil { | abstract class FileUtil { | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Load a remote file | 	 * @deprecated | ||||||
| 	 * | 	 * @see \ManiaControl\Files\WebReader | ||||||
| 	 * @param string $url |  | ||||||
| 	 * @param string $contentType |  | ||||||
| 	 * @return string |  | ||||||
| 	 */ | 	 */ | ||||||
| 	public static function loadFile($url, $contentType = 'UTF-8') { | 	public static function loadFile($url) { | ||||||
| 		if (!$url) { | 		$response = WebReader::loadUrl($url); | ||||||
| 			return null; | 		return $response->getContent(); | ||||||
| 		} |  | ||||||
| 		$urlData  = parse_url($url); |  | ||||||
| 		$host     = $urlData['host']; |  | ||||||
| 		$port     = (isset($urlData['port']) ? $urlData['port'] : 80); |  | ||||||
| 		$urlQuery = (isset($urlData['query']) ? '?' . $urlData['query'] : ''); |  | ||||||
|  |  | ||||||
| 		$fsock = fsockopen($host, $port); |  | ||||||
| 		if (!is_resource($fsock)) { |  | ||||||
| 			trigger_error("Couldn't open socket connection to '{$host}' on port '{$port}'!"); |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
| 		stream_set_timeout($fsock, 3); |  | ||||||
|  |  | ||||||
| 		$query = 'GET ' . $urlData['path'] . $urlQuery . ' HTTP/1.0' . PHP_EOL; |  | ||||||
| 		$query .= 'Host: ' . $host . PHP_EOL; |  | ||||||
| 		$query .= 'Content-Type: ' . $contentType . PHP_EOL; |  | ||||||
| 		$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL; |  | ||||||
| 		$query .= PHP_EOL; |  | ||||||
|  |  | ||||||
| 		fwrite($fsock, $query); |  | ||||||
|  |  | ||||||
| 		$buffer = ''; |  | ||||||
| 		$info   = array('timed_out' => false); |  | ||||||
| 		while (!feof($fsock) && !$info['timed_out']) { |  | ||||||
| 			$buffer .= fread($fsock, 1024); |  | ||||||
| 			$info = stream_get_meta_data($fsock); |  | ||||||
| 		} |  | ||||||
| 		fclose($fsock); |  | ||||||
|  |  | ||||||
| 		if ($info['timed_out'] || !$buffer) { |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
| 		if (substr($buffer, 9, 3) !== '200') { |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		$result = explode("\r\n\r\n", $buffer, 2); |  | ||||||
| 		if (count($result) < 2) { |  | ||||||
| 			return null; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		return $result[1]; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user