deprecated FileUtil loadFile() method
This commit is contained in:
parent
8e44f0f3c5
commit
1aa1432384
@ -3,7 +3,6 @@
|
||||
namespace ManiaControl\Files;
|
||||
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Utils\Formatter;
|
||||
|
||||
/**
|
||||
@ -16,57 +15,12 @@ use ManiaControl\Utils\Formatter;
|
||||
abstract class FileUtil {
|
||||
|
||||
/**
|
||||
* Load a remote file
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $contentType
|
||||
* @return string
|
||||
* @deprecated
|
||||
* @see \ManiaControl\Files\WebReader
|
||||
*/
|
||||
public static function loadFile($url, $contentType = 'UTF-8') {
|
||||
if (!$url) {
|
||||
return null;
|
||||
}
|
||||
$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];
|
||||
public static function loadFile($url) {
|
||||
$response = WebReader::loadUrl($url);
|
||||
return $response->getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user