PDF rausgenommen
This commit is contained in:
17
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http.php
vendored
Normal file
17
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http.php
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @package s9e\TextFormatter
|
||||
* @copyright Copyright (c) 2010-2017 The s9e Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
namespace s9e\TextFormatter\Utils;
|
||||
use s9e\TextFormatter\Utils\Http\Clients\Curl;
|
||||
use s9e\TextFormatter\Utils\Http\Clients\Native;
|
||||
abstract class Http
|
||||
{
|
||||
public static function getClient()
|
||||
{
|
||||
return (\extension_loaded('curl')) ? new Curl : new Native;
|
||||
}
|
||||
}
|
15
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Client.php
vendored
Normal file
15
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Client.php
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @package s9e\TextFormatter
|
||||
* @copyright Copyright (c) 2010-2017 The s9e Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
namespace s9e\TextFormatter\Utils\Http;
|
||||
abstract class Client
|
||||
{
|
||||
public $sslVerifyPeer = \false;
|
||||
public $timeout = 10;
|
||||
abstract public function get($url, $headers = []);
|
||||
abstract public function post($url, $headers = [], $body = '');
|
||||
}
|
48
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Clients/Curl.php
vendored
Normal file
48
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Clients/Curl.php
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @package s9e\TextFormatter
|
||||
* @copyright Copyright (c) 2010-2017 The s9e Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
namespace s9e\TextFormatter\Utils\Http\Clients;
|
||||
use s9e\TextFormatter\Utils\Http\Client;
|
||||
class Curl extends Client
|
||||
{
|
||||
protected static $handle;
|
||||
public function get($url, $headers = [])
|
||||
{
|
||||
$handle = $this->getHandle();
|
||||
\curl_setopt($handle, \CURLOPT_HTTPGET, \true);
|
||||
\curl_setopt($handle, \CURLOPT_HTTPHEADER, $headers);
|
||||
\curl_setopt($handle, \CURLOPT_URL, $url);
|
||||
return \curl_exec($handle);
|
||||
}
|
||||
public function post($url, $headers = [], $body = '')
|
||||
{
|
||||
$headers[] = 'Content-Length: ' . \strlen($body);
|
||||
$handle = $this->getHandle();
|
||||
\curl_setopt($handle, \CURLOPT_HTTPHEADER, $headers);
|
||||
\curl_setopt($handle, \CURLOPT_POST, \true);
|
||||
\curl_setopt($handle, \CURLOPT_POSTFIELDS, $body);
|
||||
\curl_setopt($handle, \CURLOPT_URL, $url);
|
||||
return \curl_exec($handle);
|
||||
}
|
||||
protected function getHandle()
|
||||
{
|
||||
if (!isset(self::$handle))
|
||||
self::$handle = $this->getNewHandle();
|
||||
\curl_setopt(self::$handle, \CURLOPT_SSL_VERIFYPEER, $this->sslVerifyPeer);
|
||||
\curl_setopt(self::$handle, \CURLOPT_TIMEOUT, $this->timeout);
|
||||
return self::$handle;
|
||||
}
|
||||
protected function getNewHandle()
|
||||
{
|
||||
$handle = \curl_init();
|
||||
\curl_setopt($handle, \CURLOPT_ENCODING, '');
|
||||
\curl_setopt($handle, \CURLOPT_FAILONERROR, \true);
|
||||
\curl_setopt($handle, \CURLOPT_FOLLOWLOCATION, \true);
|
||||
\curl_setopt($handle, \CURLOPT_RETURNTRANSFER, \true);
|
||||
return $handle;
|
||||
}
|
||||
}
|
56
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Clients/Native.php
vendored
Normal file
56
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/Http/Clients/Native.php
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @package s9e\TextFormatter
|
||||
* @copyright Copyright (c) 2010-2017 The s9e Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
namespace s9e\TextFormatter\Utils\Http\Clients;
|
||||
use s9e\TextFormatter\Utils\Http\Client;
|
||||
class Native extends Client
|
||||
{
|
||||
public $gzipEnabled;
|
||||
public function __construct()
|
||||
{
|
||||
$this->gzipEnabled = \extension_loaded('zlib');
|
||||
}
|
||||
public function get($url, $headers = [])
|
||||
{
|
||||
return $this->request('GET', $url, $headers);
|
||||
}
|
||||
public function post($url, $headers = [], $body = '')
|
||||
{
|
||||
return $this->request('POST', $url, $headers, $body);
|
||||
}
|
||||
protected function createContext($method, array $headers, $body)
|
||||
{
|
||||
$contextOptions = [
|
||||
'ssl' => ['verify_peer' => $this->sslVerifyPeer],
|
||||
'http' => [
|
||||
'method' => $method,
|
||||
'timeout' => $this->timeout,
|
||||
'header' => $this->generateHeaders($headers, $body),
|
||||
'content' => $body
|
||||
]
|
||||
];
|
||||
return \stream_context_create($contextOptions);
|
||||
}
|
||||
protected function decompress($content)
|
||||
{
|
||||
if ($this->gzipEnabled && \substr($content, 0, 2) === "\x1f\x8b")
|
||||
return \gzdecode($content);
|
||||
return $content;
|
||||
}
|
||||
protected function generateHeaders(array $headers, $body)
|
||||
{
|
||||
if ($this->gzipEnabled)
|
||||
$headers[] = 'Accept-Encoding: gzip';
|
||||
$headers[] = 'Content-Length: ' . \strlen($body);
|
||||
return $headers;
|
||||
}
|
||||
protected function request($method, $url, $headers, $body = '')
|
||||
{
|
||||
$response = @\file_get_contents($url, \false, $this->createContext($method, $headers, $body));
|
||||
return (\is_string($response)) ? $this->decompress($response) : $response;
|
||||
}
|
||||
}
|
43
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/XPath.php
vendored
Normal file
43
msd2/phpBB3/vendor/s9e/text-formatter/src/Utils/XPath.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @package s9e\TextFormatter
|
||||
* @copyright Copyright (c) 2010-2017 The s9e Authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
namespace s9e\TextFormatter\Utils;
|
||||
use InvalidArgumentException;
|
||||
abstract class XPath
|
||||
{
|
||||
public static function export($value)
|
||||
{
|
||||
if (!\is_scalar($value))
|
||||
throw new InvalidArgumentException(__METHOD__ . '() cannot export non-scalar values');
|
||||
if (\is_int($value))
|
||||
return (string) $value;
|
||||
if (\is_float($value))
|
||||
return \preg_replace('(\\.?0+$)', '', \sprintf('%F', $value));
|
||||
return self::exportString((string) $value);
|
||||
}
|
||||
protected static function exportString($str)
|
||||
{
|
||||
if (\strpos($str, "'") === \false)
|
||||
return "'" . $str . "'";
|
||||
if (\strpos($str, '"') === \false)
|
||||
return '"' . $str . '"';
|
||||
$toks = [];
|
||||
$c = '"';
|
||||
$pos = 0;
|
||||
while ($pos < \strlen($str))
|
||||
{
|
||||
$spn = \strcspn($str, $c, $pos);
|
||||
if ($spn)
|
||||
{
|
||||
$toks[] = $c . \substr($str, $pos, $spn) . $c;
|
||||
$pos += $spn;
|
||||
}
|
||||
$c = ($c === '"') ? "'" : '"';
|
||||
}
|
||||
return 'concat(' . \implode(',', $toks) . ')';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user