filereader update
This commit is contained in:
		
				
					committed by
					
						
						Steffen Schröder
					
				
			
			
				
	
			
			
			
						parent
						
							244428a2fe
						
					
				
				
					commit
					bb6b47376c
				
			@@ -63,19 +63,21 @@ class AsynchronousFileReader {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!$url) {
 | 
			
		||||
			return null;
 | 
			
		||||
			$this->maniaControl->log("Url is empty");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$request = new \cURL\Request($url);
 | 
			
		||||
		$request = new Request($url);
 | 
			
		||||
 | 
			
		||||
		$request->getOptions()->set(CURLOPT_TIMEOUT, 5) //
 | 
			
		||||
			->set(CURLOPT_HEADER, false) //
 | 
			
		||||
			->set(CURLOPT_CRLF, true) //
 | 
			
		||||
			//->set(CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType))
 | 
			
		||||
			->set(CURLOPT_ENCODING, "")//
 | 
			
		||||
			->set(CURLOPT_AUTOREFERER, true)//
 | 
			
		||||
			->set(CURLOPT_HTTPHEADER, array("Content-Type: " . $contentType)) //
 | 
			
		||||
			->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;
 | 
			
		||||
@@ -91,61 +93,19 @@ class AsynchronousFileReader {
 | 
			
		||||
			call_user_func($function, $content, $error);
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		array_push($this->requests, $request);
 | 
			
		||||
 | 
			
		||||
		$this->addRequest($request);
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Send Data via POST Method
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param        $url
 | 
			
		||||
	 * @param        $function
 | 
			
		||||
	 * @param        $content
 | 
			
		||||
	 * @param string $contentType
 | 
			
		||||
	 * @return bool|null
 | 
			
		||||
	 * Adds a Request to the queue
 | 
			
		||||
	 * @param Request $request
 | 
			
		||||
	 */
 | 
			
		||||
	public function addRequest(Request $request){
 | 
			
		||||
		array_push($this->requests, $request);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function postData($url, $function, $content, $compressed = false, $contentType = 'UTF-8') {
 | 
			
		||||
		/*if (!is_callable($function)) {
 | 
			
		||||
			$this->maniaControl->log("Function is not callable");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!$url) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		$urlData = parse_url($url);
 | 
			
		||||
		$port    = (isset($urlData['port']) ? $urlData['port'] : 80);
 | 
			
		||||
 | 
			
		||||
		$socket = @fsockopen($urlData['host'], $port, $errno, $errstr, 4);
 | 
			
		||||
		if (!$socket) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$query = 'POST ' . $urlData['path'] . ' HTTP/1.1' . PHP_EOL;
 | 
			
		||||
		$query .= 'Host: ' . $urlData['host'] . PHP_EOL;
 | 
			
		||||
		$query .= 'Accept-Charset: utf-8' . PHP_EOL;
 | 
			
		||||
		$query .= 'Accept-Encoding: gzip, deflate' . PHP_EOL;
 | 
			
		||||
		//$query .= 'Content-Encoding: gzip' . PHP_EOL;
 | 
			
		||||
		$query .= 'Content-Type: text/xml; charset=utf-8;' . PHP_EOL;
 | 
			
		||||
		$query .= 'Keep-Alive: 300' . PHP_EOL;
 | 
			
		||||
		$query .= 'Connection: Keep-Alive' . PHP_EOL;
 | 
			
		||||
		$query .= 'User-Agent: ManiaControl v' . ManiaControl::VERSION . PHP_EOL;
 | 
			
		||||
		$query .= 'Content-Length: ' . strlen($content) . PHP_EOL . PHP_EOL;
 | 
			
		||||
 | 
			
		||||
		$query .= $content . PHP_EOL;
 | 
			
		||||
 | 
			
		||||
		fwrite($socket, $query);
 | 
			
		||||
 | 
			
		||||
		$success = stream_set_blocking($socket, 0);
 | 
			
		||||
		if (!$success) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$socketStructure = new SocketStructure($url, $socket, $function);
 | 
			
		||||
		array_push($this->sockets, $socketStructure);
 | 
			
		||||
 | 
			
		||||
		return true;*/
 | 
			
		||||
		//TODO update dedimania plugin
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user