dedimania continue
This commit is contained in:
committed by
Steffen Schröder
parent
bb6b47376c
commit
159e2079ee
@ -53,10 +53,9 @@ class AsynchronousFileReader {
|
||||
* @param string $url
|
||||
* @param $function
|
||||
* @param string $contentType
|
||||
* @param string $customHeader
|
||||
* @return bool
|
||||
*/
|
||||
public function loadFile($url, $function, $contentType = 'UTF-8', $customHeader = '') {
|
||||
public function loadFile($url, $function, $contentType = 'UTF-8') {
|
||||
if (!is_callable($function)) {
|
||||
$this->maniaControl->log("Function is not callable");
|
||||
return false;
|
||||
@ -70,10 +69,10 @@ class AsynchronousFileReader {
|
||||
$request = new Request($url);
|
||||
|
||||
$request->getOptions()->set(CURLOPT_TIMEOUT, 5) //
|
||||
->set(CURLOPT_HEADER, false) //
|
||||
->set(CURLOPT_CRLF, true) //
|
||||
->set(CURLOPT_ENCODING, "")//
|
||||
->set(CURLOPT_AUTOREFERER, true)//
|
||||
->set(CURLOPT_HEADER, false) //don't display response header
|
||||
->set(CURLOPT_CRLF, true) //linux linefeed
|
||||
->set(CURLOPT_ENCODING, "")//accept encoding
|
||||
->set(CURLOPT_AUTOREFERER, true)//accept link reference
|
||||
->set(CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType)) //
|
||||
->set(CURLOPT_USERAGENT, 'User-Agent: ManiaControl v' . ManiaControl::VERSION) //
|
||||
->set(CURLOPT_RETURNTRANSFER, true);
|
||||
@ -99,13 +98,65 @@ class AsynchronousFileReader {
|
||||
|
||||
/**
|
||||
* Adds a Request to the queue
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function addRequest(Request $request){
|
||||
public function addRequest(Request $request) {
|
||||
array_push($this->requests, $request);
|
||||
}
|
||||
|
||||
public function postData($url, $function, $content, $compressed = false, $contentType = 'UTF-8') {
|
||||
//TODO update dedimania plugin
|
||||
/**
|
||||
* Send Data via POST Method
|
||||
*
|
||||
* @param $url
|
||||
* @param $function
|
||||
* @param $content
|
||||
* @param string $compression
|
||||
* @param string $contentType
|
||||
* @return bool
|
||||
*/
|
||||
public function postData($url, $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8') {
|
||||
if (!is_callable($function)) {
|
||||
$this->maniaControl->log("Function is not callable");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$url) {
|
||||
$this->maniaControl->log("Url is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($compression) {
|
||||
$content = gzencode($content);
|
||||
}
|
||||
$request = new Request($url);
|
||||
$request->getOptions()->set(CURLOPT_HEADER, false) //don't display response header
|
||||
->set(CURLOPT_CRLF, true) //linux linefeed
|
||||
->set(CURLOPT_ENCODING, "")//accept encoding
|
||||
//->set(CURLOPT_AUTOREFERER, true)//accept link reference
|
||||
->set(CURLOPT_POST, true) //post field
|
||||
->set(CURLOPT_POSTFIELDS, $content) //post content field
|
||||
->set(CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType, "Keep-Alive: 300", "Connection: Keep-Alive", "Content-Encoding: gzip")) //
|
||||
//->set(CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType, "Keep-Alive")) //
|
||||
->set(CURLOPT_USERAGENT, 'User-Agent: ManiaControl v' . ManiaControl::VERSION) //
|
||||
->set(CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$request->addListener('complete', function (\cURL\Event $event) use (&$function) {
|
||||
/** @var Response $response */
|
||||
$response = $event->response;
|
||||
$error = "";
|
||||
$content = "";
|
||||
if ($response->hasError()) {
|
||||
$error = $response->getError()->getMessage();
|
||||
} else {
|
||||
$content = $response->getContent();
|
||||
}
|
||||
|
||||
call_user_func($function, $content, $error);
|
||||
});
|
||||
|
||||
$this->addRequest($request);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user