Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
4
core/connection/all.php
Normal file
4
core/connection/all.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
foreach (glob(dirname(__FILE__) . "/*.php") as $file)
|
||||
require_once $file;
|
||||
?>
|
||||
10
core/connection/data.txt
Normal file
10
core/connection/data.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Mon, 31 Mar 2008 12:38:37 GMT
|
||||
Server: Apache/2.0.61 (Win32) SVN/1.4.3 mod_python/3.3.1 Python/2.4.3 PHP/5.2.5 DAV/2
|
||||
X-Powered-By: PHP/5.2.5
|
||||
Expires: Thu, 19 Nov 1981 08:52:00 GMT
|
||||
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
||||
Pragma: no-cache
|
||||
Content-Length: 6232
|
||||
Connection: close
|
||||
Content-Type: text/html; charset=windows-1251
|
||||
95
core/connection/httpconnection.php
Normal file
95
core/connection/httpconnection.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
// HttpConncectionRequest
|
||||
class HttpConnection
|
||||
{
|
||||
const POST = "POST";
|
||||
const GET = "GET";
|
||||
|
||||
private $param = array(); // Ïàðàìåòðû çàïðîñà
|
||||
public $data = null; // Ñîäåðæàíèå
|
||||
public $url; // Àäðåññ
|
||||
public $method = self::GET; // Ìåòîä
|
||||
public $port = 80;
|
||||
public $host = "";
|
||||
public $proxy_host = false;
|
||||
public $proxy_port = false;
|
||||
|
||||
/**
|
||||
* Âîçâðàùàåò çàãîëîâîê ñîåäèíåíèÿ
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
$result = $this->method . " " . $this->url . " HTTP/1.1\r\n";
|
||||
$result .= "Host: ". $this->host ."\r\n";
|
||||
foreach ($this->param as $key => $value) {
|
||||
$result .= $key . ": " . $value . "\r\n";
|
||||
}
|
||||
$result .= "Connection: Close\r\n\r\n";
|
||||
$result .= $this->data;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Óñòàíîâêà ïàðàìåòðîâ çàïðîñà
|
||||
* @parma string $name
|
||||
* @parma string $value
|
||||
*/
|
||||
public function setParameter($name, $value)
|
||||
{
|
||||
$this->param[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ìåòîä çàïðîñà GET èëè POST
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->host = parse_url($this->url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ñîäåðæàíèå çàïðîñà
|
||||
*/
|
||||
public function setContent($data)
|
||||
{
|
||||
$this->setParameter ("Content-length", strlen($data));
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ïîñûëàåò çàïðîñ è âîçâðàùàåò ñòðàíèöó
|
||||
*/
|
||||
public function getPage()
|
||||
{
|
||||
$host = ($this->proxy_host) ? $this->proxy_host : $this->host;
|
||||
$port = ($this->proxy_port) ? $this->proxy_port : $this->port;
|
||||
$socket = fsockopen($host, $port, $errno, $errstr, 30);
|
||||
if (! $socket) {
|
||||
return null; // Exception
|
||||
} else {
|
||||
$header = $this->getHeader();
|
||||
fwrite($socket, $header);
|
||||
|
||||
$result = null;
|
||||
while (! feof($socket)) {
|
||||
$result .= fgets($socket, 128);
|
||||
}
|
||||
fclose($socket);
|
||||
return $result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
82
core/connection/httpconnectionresponse.php
Normal file
82
core/connection/httpconnectionresponse.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Îáðàáàòûâàåò HTTP îòâåò
|
||||
*/
|
||||
class HttpConnectionResponse
|
||||
{
|
||||
private $offset;
|
||||
private $param = array ();
|
||||
private $code;
|
||||
|
||||
public function __construct($response)
|
||||
{
|
||||
$this->offset = 0;
|
||||
$this->response = $response;
|
||||
$this->parseMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Îáðàáîòêà HTTP îòâåòà
|
||||
*/
|
||||
private function parseMessage()
|
||||
{
|
||||
$http = explode(" ", $this->getLine());
|
||||
$this->version = $http[0];
|
||||
$this->code = $http[1];
|
||||
|
||||
$line = $this->getLine();
|
||||
while ($offset = strpos($line, ":")) {
|
||||
$this->param[substr($line, 0, $offset)] = trim(substr($line, $offset + 1));
|
||||
$line = $this->getLine();
|
||||
}
|
||||
|
||||
if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') {
|
||||
//$this->data = substr($this->response, $this->offset);
|
||||
$line = hexdec($this->getLine());
|
||||
$chunk = array();
|
||||
while ($line > 0) {
|
||||
$chunk [] = substr($this->response, $this->offset, $line);
|
||||
$this->offset += $line;
|
||||
$line = hexdec($this->getLine());
|
||||
}
|
||||
|
||||
$this->data = implode("", $chunk);
|
||||
} else {
|
||||
$this->data = substr($this->response, $this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Îáðàáîòêà ñòðîêè HTTP îòâåòà
|
||||
*/
|
||||
private function getLine()
|
||||
{
|
||||
$begin = $this->offset;
|
||||
$offset = strpos($this->response, "\r\n", $this->offset);
|
||||
$result = substr($this->response, $begin, $offset - $begin);
|
||||
$this->offset = $offset + 2;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Çíà÷åíèå ïàðàìåòðà HTTP îòâåòà
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
return $this->param[$name];
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ñîñòîÿíèå
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
}
|
||||
2707
core/connection/idna_convert.php
Normal file
2707
core/connection/idna_convert.php
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue