Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/blogvaul.../callback
File: streams.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('ABSPATH')) exit;
[2] Fix | Delete
if (!class_exists('BVRespStream')) :
[3] Fix | Delete
[4] Fix | Delete
class BVStream extends BVCallbackBase {
[5] Fix | Delete
public $bvb64stream;
[6] Fix | Delete
public $bvb64cksize;
[7] Fix | Delete
public $checksum;
[8] Fix | Delete
[9] Fix | Delete
function __construct($request) {
[10] Fix | Delete
$this->bvb64stream = $request->bvb64stream;
[11] Fix | Delete
$this->bvb64cksize = $request->bvb64cksize;
[12] Fix | Delete
$this->checksum = $request->checksum;
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
public function writeChunk($chunk) {
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
public static function startStream($account, $request) {
[19] Fix | Delete
$result = array();
[20] Fix | Delete
$params = $request->params;
[21] Fix | Delete
$stream = new BVRespStream($request);
[22] Fix | Delete
if ($request->isAPICall()) {
[23] Fix | Delete
$stream = new BVHttpStream($request);
[24] Fix | Delete
if (!$stream->connect()) {
[25] Fix | Delete
$apicallstatus = array(
[26] Fix | Delete
"httperror" => "Cannot Open Connection to Host",
[27] Fix | Delete
"streamerrno" => $stream->errno,
[28] Fix | Delete
"streamerrstr" => $stream->errstr
[29] Fix | Delete
);
[30] Fix | Delete
return array("apicallstatus" => $apicallstatus);
[31] Fix | Delete
}
[32] Fix | Delete
if (array_key_exists('acbmthd', $params)) {
[33] Fix | Delete
$qstr = http_build_query(array('bvapicheck' => $params['bvapicheck']));
[34] Fix | Delete
$url = '/bvapi/'.$params['acbmthd']."?".$qstr;
[35] Fix | Delete
if (array_key_exists('acbqry', $params)) {
[36] Fix | Delete
$url .= "&".$params['acbqry'];
[37] Fix | Delete
}
[38] Fix | Delete
$stream->multipartChunkedPost($url);
[39] Fix | Delete
} else {
[40] Fix | Delete
return array("apicallstatus" => array("httperror" => "ApiCall method not present"));
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
return array('stream' => $stream);
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
public function writeStream($chunk) {
[47] Fix | Delete
if (strlen($chunk) > 0) {
[48] Fix | Delete
$bvb64_prefix = "";
[49] Fix | Delete
if ($this->bvb64stream) {
[50] Fix | Delete
$chunk_size = $this->bvb64cksize;
[51] Fix | Delete
$chunk = $this->base64Encode($chunk, $chunk_size);
[52] Fix | Delete
$bvb64_prefix .= "BVB64" . ":";
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
$hash_prefix = "";
[56] Fix | Delete
if ($this->checksum == 'crc32') {
[57] Fix | Delete
$hash_prefix .= "CRC32" . ":" . crc32($chunk) . ":";
[58] Fix | Delete
} else if ($this->checksum == 'md5') {
[59] Fix | Delete
$hash_prefix .= "MD5" . ":" . md5($chunk) . ":";
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$chunk = $hash_prefix . $bvb64_prefix . strlen($chunk) . ":" . $chunk;
[63] Fix | Delete
[64] Fix | Delete
$this->writeChunk($chunk);
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
class BVRespStream extends BVStream {
[70] Fix | Delete
public $bvboundry;
[71] Fix | Delete
[72] Fix | Delete
function __construct($request) {
[73] Fix | Delete
parent::__construct($request);
[74] Fix | Delete
$this->bvboundry = $request->bvboundry;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
public function writeChunk($chunk) {
[78] Fix | Delete
echo $this->bvboundry . "ckckckckck" . $chunk . $this->bvboundry . "ckckckckck";
[79] Fix | Delete
}
[80] Fix | Delete
public function endStream() {
[81] Fix | Delete
echo $this->bvboundry . "rerererere";
[82] Fix | Delete
[83] Fix | Delete
return array();
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
class BVHttpStream extends BVStream {
[88] Fix | Delete
var $user_agent = 'BVHttpStream';
[89] Fix | Delete
var $host;
[90] Fix | Delete
var $port;
[91] Fix | Delete
var $timeout = 20;
[92] Fix | Delete
var $conn;
[93] Fix | Delete
var $errno;
[94] Fix | Delete
var $errstr;
[95] Fix | Delete
var $boundary;
[96] Fix | Delete
var $apissl;
[97] Fix | Delete
[98] Fix | Delete
function __construct($request) {
[99] Fix | Delete
parent::__construct($request);
[100] Fix | Delete
$this->host = $request->params['apihost'];
[101] Fix | Delete
$this->port = intval($request->params['apiport']);
[102] Fix | Delete
$this->apissl = array_key_exists('apissl', $request->params);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
public function connect() {
[106] Fix | Delete
if ($this->apissl && function_exists('stream_socket_client')) {
[107] Fix | Delete
$this->conn = stream_socket_client("ssl://".$this->host.":".$this->port, $errno, $errstr, $this->timeout);
[108] Fix | Delete
} else {
[109] Fix | Delete
$this->conn = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
[110] Fix | Delete
}
[111] Fix | Delete
if (!$this->conn) {
[112] Fix | Delete
$this->errno = $errno;
[113] Fix | Delete
$this->errstr = $errstr;
[114] Fix | Delete
return false;
[115] Fix | Delete
}
[116] Fix | Delete
socket_set_timeout($this->conn, $this->timeout);
[117] Fix | Delete
return true;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
public function write($data) {
[121] Fix | Delete
fwrite($this->conn, $data);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
public function sendChunk($data) {
[125] Fix | Delete
$this->write(sprintf("%x\r\n", strlen($data)));
[126] Fix | Delete
$this->write($data);
[127] Fix | Delete
$this->write("\r\n");
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
public function sendRequest($method, $url, $headers = array(), $body = null) {
[131] Fix | Delete
$def_hdrs = array("Connection" => "keep-alive",
[132] Fix | Delete
"Host" => $this->host);
[133] Fix | Delete
$headers = array_merge($def_hdrs, $headers);
[134] Fix | Delete
$request = strtoupper($method)." ".$url." HTTP/1.1\r\n";
[135] Fix | Delete
if (null != $body) {
[136] Fix | Delete
$headers["Content-length"] = strlen($body);
[137] Fix | Delete
}
[138] Fix | Delete
foreach($headers as $key=>$val) {
[139] Fix | Delete
$request .= $key.":".$val."\r\n";
[140] Fix | Delete
}
[141] Fix | Delete
$request .= "\r\n";
[142] Fix | Delete
if (null != $body) {
[143] Fix | Delete
$request .= $body;
[144] Fix | Delete
}
[145] Fix | Delete
$this->write($request);
[146] Fix | Delete
return $request;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
public function post($url, $headers = array(), $body = "") {
[150] Fix | Delete
if(is_array($body)) {
[151] Fix | Delete
$b = "";
[152] Fix | Delete
foreach($body as $key=>$val) {
[153] Fix | Delete
$b .= $key."=".urlencode($val)."&";
[154] Fix | Delete
}
[155] Fix | Delete
$body = substr($b, 0, strlen($b) - 1);
[156] Fix | Delete
}
[157] Fix | Delete
$this->sendRequest("POST", $url, $headers, $body);
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
public function streamedPost($url, $headers = array()) {
[161] Fix | Delete
$headers['Transfer-Encoding'] = "chunked";
[162] Fix | Delete
$this->sendRequest("POST", $url, $headers);
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
public function multipartChunkedPost($url) {
[166] Fix | Delete
$mph = array(
[167] Fix | Delete
"Content-Disposition" => "form-data; name=bvinfile; filename=data",
[168] Fix | Delete
"Content-Type" => "application/octet-stream"
[169] Fix | Delete
);
[170] Fix | Delete
$rnd = rand(100000, 999999);
[171] Fix | Delete
$this->boundary = "----".$rnd;
[172] Fix | Delete
$prologue = "--".$this->boundary."\r\n";
[173] Fix | Delete
foreach($mph as $key=>$val) {
[174] Fix | Delete
$prologue .= $key.":".$val."\r\n";
[175] Fix | Delete
}
[176] Fix | Delete
$prologue .= "\r\n";
[177] Fix | Delete
$headers = array('Content-Type' => "multipart/form-data; boundary=".$this->boundary);
[178] Fix | Delete
$this->streamedPost($url, $headers);
[179] Fix | Delete
$this->sendChunk($prologue);
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
public function writeChunk($data) {
[183] Fix | Delete
$this->sendChunk($data);
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
public function closeChunk() {
[187] Fix | Delete
$this->sendChunk("");
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
public function endStream() {
[191] Fix | Delete
$epilogue = "\r\n\r\n--".$this->boundary."--\r\n";
[192] Fix | Delete
$this->sendChunk($epilogue);
[193] Fix | Delete
$this->closeChunk();
[194] Fix | Delete
[195] Fix | Delete
$result = array();
[196] Fix | Delete
$resp = $this->getResponse();
[197] Fix | Delete
if (array_key_exists('httperror', $resp)) {
[198] Fix | Delete
$result["httperror"] = $resp['httperror'];
[199] Fix | Delete
} else {
[200] Fix | Delete
$result["respstatus"] = $resp['status'];
[201] Fix | Delete
$result["respstatus_string"] = $resp['status_string'];
[202] Fix | Delete
}
[203] Fix | Delete
return array("apicallstatus" => $result);
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
public function getResponse() {
[207] Fix | Delete
$response = array();
[208] Fix | Delete
$response['headers'] = array();
[209] Fix | Delete
$state = 1;
[210] Fix | Delete
$conlen = 0;
[211] Fix | Delete
stream_set_timeout($this->conn, 300);
[212] Fix | Delete
while (!feof($this->conn)) {
[213] Fix | Delete
$line = fgets($this->conn, 4096);
[214] Fix | Delete
if (1 == $state) {
[215] Fix | Delete
if (!BVHelper::safePregMatch('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
[216] Fix | Delete
$response['httperror'] = "Status code line invalid: ".htmlentities($line);
[217] Fix | Delete
return $response;
[218] Fix | Delete
}
[219] Fix | Delete
$response['http_version'] = $m[1];
[220] Fix | Delete
$response['status'] = $m[2];
[221] Fix | Delete
$response['status_string'] = $m[3];
[222] Fix | Delete
$state = 2;
[223] Fix | Delete
} else if (2 == $state) {
[224] Fix | Delete
# End of headers
[225] Fix | Delete
if (2 == strlen($line)) {
[226] Fix | Delete
if ($conlen > 0)
[227] Fix | Delete
$response['body'] = fread($this->conn, $conlen);
[228] Fix | Delete
return $response;
[229] Fix | Delete
}
[230] Fix | Delete
if (!BVHelper::safePregMatch('/([^:]+):\\s*(.*)/', $line, $m)) {
[231] Fix | Delete
// Skip to the next header
[232] Fix | Delete
continue;
[233] Fix | Delete
}
[234] Fix | Delete
$key = strtolower(trim($m[1]));
[235] Fix | Delete
$val = trim($m[2]);
[236] Fix | Delete
$response['headers'][$key] = $val;
[237] Fix | Delete
if ($key == "content-length") {
[238] Fix | Delete
$conlen = intval($val);
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
return $response;
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
endif;
[246] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function