first
This commit is contained in:
151
system/vendor/brunodebarros/fix-php-post-input/FixPhpPostInput.php
vendored
Executable file
151
system/vendor/brunodebarros/fix-php-post-input/FixPhpPostInput.php
vendored
Executable file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace Brunodebarros\FixPhpPostInput;
|
||||
|
||||
/**
|
||||
* If your $_POST/$_FILES are empty and they shouldn't be, this library fixes them.
|
||||
*
|
||||
* @package Brunodebarros\FixPhpPostInput
|
||||
*/
|
||||
class FixPhpPostInput {
|
||||
|
||||
protected $temp_files = [];
|
||||
|
||||
protected function edit_array($array, $name, $value) {
|
||||
$name_parts = explode("[", $name);
|
||||
$array_part = &$array;
|
||||
|
||||
$is_last = false;
|
||||
$i = 1;
|
||||
foreach ($name_parts as $name_part) {
|
||||
if ($i == count($name_parts)) {
|
||||
$is_last = true;
|
||||
}
|
||||
|
||||
$name_part = str_ireplace(']', "", $name_part);
|
||||
|
||||
if (!isset($array_part[$name_part])) {
|
||||
if (empty($name_part)) {
|
||||
$array_part[] = ($is_last ? $value : []);
|
||||
} else {
|
||||
$array_part[$name_part] = ($is_last ? $value : []);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$is_last) {
|
||||
$array_part = &$array_part[$name_part];
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function store_temp($contents) {
|
||||
$tmp_name = tempnam(sys_get_temp_dir(), "file-");
|
||||
$this->temp_files[] = $tmp_name;
|
||||
$result = file_put_contents($tmp_name, $contents);
|
||||
|
||||
if (strlen($contents) !== $result) {
|
||||
throw new \RuntimeException("Could not store temp file in $tmp_name.");
|
||||
}
|
||||
|
||||
return $tmp_name;
|
||||
}
|
||||
|
||||
protected function map_name_to_array($name, $array) {
|
||||
if (substr($name, -2) == "[]") {
|
||||
if (isset($array[substr($name, 0, -2)])) {
|
||||
return $array[substr($name, 0, -2)];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($array[$name])) {
|
||||
return $array[$name];
|
||||
}
|
||||
|
||||
|
||||
$return = null;
|
||||
$code = 'if(isset($array' . implode("", $name) . ')) {$return = $array' . implode("", $name) . ';} else { $return = null; }';
|
||||
eval($code);
|
||||
return $return;
|
||||
}
|
||||
|
||||
function __construct(&$post = null, &$files = null, $server = null, $php_input = null) {
|
||||
|
||||
if ($post === null) {
|
||||
$post = &$_POST;
|
||||
}
|
||||
|
||||
if ($files === null) {
|
||||
$files = &$_FILES;
|
||||
}
|
||||
|
||||
if ($php_input === null) {
|
||||
$php_input = file_get_contents('php://input');
|
||||
}
|
||||
|
||||
if ($server === null) {
|
||||
$server = $_SERVER;
|
||||
}
|
||||
|
||||
if (count($post) == 0) {
|
||||
$is_post = false;
|
||||
foreach ($server as $key => $value) {
|
||||
$search = "REQUEST_METHOD";
|
||||
if (substr($key, -strlen($search)) == $search) {
|
||||
if ($value == "POST") {
|
||||
$is_post = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_post) {
|
||||
if (!empty($php_input)) {
|
||||
$is_multipart = (stristr($server["CONTENT_TYPE"], "multipart/form-data") !== false);
|
||||
$is_json = (stristr($server["CONTENT_TYPE"], "application/json") !== false);
|
||||
|
||||
if ($is_json) {
|
||||
$post = json_decode($php_input, true);
|
||||
} elseif ($is_multipart) {
|
||||
$document = new \Riverline\MultiPartParser\Part("Content-Type: " . $server["CONTENT_TYPE"] . "\n\n" . $php_input);
|
||||
foreach ($document->getParts() as $part) {
|
||||
if ($part->isFile()) {
|
||||
$size = strlen($part->getBody());
|
||||
|
||||
$data = [
|
||||
"name" => $part->getFileName(),
|
||||
"type" => $size ? $part->getMimeType() : "",
|
||||
"tmp_name" => $size ? $this->store_temp($part->getBody()) : "",
|
||||
"error" => $size ? UPLOAD_ERR_OK : UPLOAD_ERR_NO_FILE,
|
||||
"size" => $size,
|
||||
];
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$name = explode("[", $part->getName(), 2);
|
||||
$name = $name[0] . "[$key][" . $name[1];
|
||||
$files = $this->edit_array($files, $name, $value);
|
||||
}
|
||||
} else {
|
||||
$post = $this->edit_array($post, $part->getName(), $part->getBody());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parse_str($php_input, $post);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
foreach ($this->temp_files as $temp_file) {
|
||||
if (file_exists($temp_file)) {
|
||||
unlink($temp_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
21
system/vendor/brunodebarros/fix-php-post-input/LICENSE.md
vendored
Executable file
21
system/vendor/brunodebarros/fix-php-post-input/LICENSE.md
vendored
Executable file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Bruno De Barros
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
5
system/vendor/brunodebarros/fix-php-post-input/bootstrap.php
vendored
Executable file
5
system/vendor/brunodebarros/fix-php-post-input/bootstrap.php
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
# We use a global variable here to make sure the __destruct is only called at the end of the script's execution.
|
||||
# Otherwise, it'd be called right after the execution of this file, which would delete all temp files.
|
||||
$GLOBALS["d094efdc456faca4f987b6fc6e44c6c10a892765"] = new Brunodebarros\FixPhpPostInput\FixPhpPostInput();
|
||||
43
system/vendor/brunodebarros/fix-php-post-input/composer.json
vendored
Executable file
43
system/vendor/brunodebarros/fix-php-post-input/composer.json
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "brunodebarros/fix-php-post-input",
|
||||
"type": "library",
|
||||
"description": "If your $_POST/$_FILES are empty and they shouldn't be, this library fixes them.",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"post",
|
||||
"files",
|
||||
"input"
|
||||
],
|
||||
"homepage": "https://github.com/BrunoDeBarros/fix-php-post-input",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Bruno De Barros",
|
||||
"email": "bruno@terraduo.com"
|
||||
}
|
||||
],
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/brunodebarros/multipart-parser"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4",
|
||||
"riverline/multipart-parser": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Brunodebarros\\FixPhpPostInput\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"optimize-autoloader": true
|
||||
}
|
||||
}
|
||||
72
system/vendor/brunodebarros/fix-php-post-input/composer.lock
generated
vendored
Executable file
72
system/vendor/brunodebarros/fix-php-post-input/composer.lock
generated
vendored
Executable file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9b3b2714adf4aa244ebcc5410e3afee1",
|
||||
"packages": [
|
||||
{
|
||||
"name": "riverline/multipart-parser",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/BrunoDeBarros/multipart-parser.git",
|
||||
"reference": "24fe25355e14eb86774e6c8dba35c52c62a091e6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/BrunoDeBarros/multipart-parser/zipball/24fe25355e14eb86774e6c8dba35c52c62a091e6",
|
||||
"reference": "24fe25355e14eb86774e6c8dba35c52c62a091e6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.7 || ^5.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Riverline\\MultiPartParser": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Romain Cambien",
|
||||
"email": "romain@riverline.fr"
|
||||
},
|
||||
{
|
||||
"name": "Riverline",
|
||||
"homepage": "http://www.riverline.fr"
|
||||
}
|
||||
],
|
||||
"description": "One class library to parse multipart content with encoding and charset support.",
|
||||
"keywords": [
|
||||
"http",
|
||||
"multipart",
|
||||
"parser"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/BrunoDeBarros/multipart-parser/tree/master"
|
||||
},
|
||||
"time": "2018-08-13T07:57:45+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"riverline/multipart-parser": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"platform-dev": []
|
||||
}
|
||||
Reference in New Issue
Block a user