Частичная синхронизация с CMS
This commit is contained in:
parent
312f18a20a
commit
b26e521657
62 changed files with 827 additions and 5992 deletions
|
|
@ -8,18 +8,23 @@ class Connection_HttpRequest
|
|||
private $param = array(); // Параметры запроса
|
||||
public $data = null; // Содержание
|
||||
public $url; // Адресс
|
||||
public $method = self::GET; // Метод
|
||||
public $method; // Метод
|
||||
public $port = 80;
|
||||
public $host = "";
|
||||
public $proxy_host = false;
|
||||
public $proxy_port = false;
|
||||
public $proxy_host = null;
|
||||
public $proxy_port = null;
|
||||
public $http_version = 'HTTP/1.1';
|
||||
|
||||
function __construct() {
|
||||
$this->method = self::GET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает заголовок соединения
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
$result = $this->method . " " . $this->url . " HTTP/1.1\r\n";
|
||||
$result = $this->method . " " . $this->url . " " . $this->http_version . "\r\n";
|
||||
$result .= "Host: ". $this->host ."\r\n";
|
||||
foreach ($this->param as $key => $value) {
|
||||
$result .= $key . ": " . $value . "\r\n";
|
||||
|
|
@ -74,10 +79,10 @@ class Connection_HttpRequest
|
|||
{
|
||||
$host = ($this->proxy_host) ? $this->proxy_host : $this->host;
|
||||
$port = ($this->proxy_port) ? $this->proxy_port : $this->port;
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
$socket = fsockopen($host, $port, $errno, $errstr, 30);
|
||||
if (! $socket) {
|
||||
return null; // Exception
|
||||
} else {
|
||||
if (is_resource($socket)) {
|
||||
$header = $this->getHeader();
|
||||
fwrite($socket, $header);
|
||||
|
||||
|
|
@ -90,5 +95,17 @@ class Connection_HttpRequest
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static function getJSON($url, $data) {
|
||||
$c = new Connection_HttpRequest();
|
||||
$c->http_version = "HTTP/1.0";
|
||||
|
||||
$query = http_build_query($data);
|
||||
$c->setUrl($q = $url . '?' . $query);
|
||||
$page = $c->getPage();
|
||||
|
||||
$response = new Connection_HttpResponse($page);
|
||||
return json_decode((string) preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $response->getData()), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ class Connection_HttpResponse
|
|||
private $param = array ();
|
||||
private $code;
|
||||
public $response;
|
||||
public $data;
|
||||
public $version;
|
||||
public $data;
|
||||
|
||||
public function __construct($response)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue