Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Http
File: JsonResponse.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Http_JsonResponse extends MWP_Http_Response
[10] Fix | Delete
{
[11] Fix | Delete
public function __construct($content, $statusCode = 200, array $headers = array())
[12] Fix | Delete
{
[13] Fix | Delete
$headers['content-type'] = 'application/json';
[14] Fix | Delete
parent::__construct($content, $statusCode, $headers);
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
public function getContentAsString()
[18] Fix | Delete
{
[19] Fix | Delete
$content = json_encode($this->content);
[20] Fix | Delete
[21] Fix | Delete
if (!is_string($content)) {
[22] Fix | Delete
$invalidValues = array();
[23] Fix | Delete
$this->fixUtf8($this->content, $invalidValues);
[24] Fix | Delete
[25] Fix | Delete
if (is_array($this->content) && count($invalidValues) > 0) {
[26] Fix | Delete
$this->content['utf8FixedPaths'] = $invalidValues;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
$content = json_encode($this->content);
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
return "\n" . $content;
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
private function fixUtf8(&$structure, array &$found = array(), &$walkedRefs = array(), array $path = array('_'))
[36] Fix | Delete
{
[37] Fix | Delete
switch ($type = gettype($structure)) {
[38] Fix | Delete
case 'string':
[39] Fix | Delete
if (!seems_utf8($structure)) {
[40] Fix | Delete
$found[implode('.', $path)] = urlencode($structure);
[41] Fix | Delete
$structure = utf8_encode($structure);
[42] Fix | Delete
}
[43] Fix | Delete
break;
[44] Fix | Delete
/** @noinspection PhpMissingBreakStatementInspection */
[45] Fix | Delete
case 'object':
[46] Fix | Delete
// Handle recursion.
[47] Fix | Delete
// __PHP_Incomplete_Class will return false on is_object() call. Luckily, we can still get its object hash.
[48] Fix | Delete
$objectHash = spl_object_hash($structure);
[49] Fix | Delete
if (isset($walkedRefs[$objectHash])) {
[50] Fix | Delete
break;
[51] Fix | Delete
}
[52] Fix | Delete
$walkedRefs[$objectHash] = true;
[53] Fix | Delete
// Fall through.
[54] Fix | Delete
case 'array':
[55] Fix | Delete
// Object and array are by default traversable.
[56] Fix | Delete
foreach ($structure as $key => &$value) {
[57] Fix | Delete
$valuePath = $path;
[58] Fix | Delete
$valuePath[] = $key;
[59] Fix | Delete
$this->fixUtf8($value, $found, $walkedRefs, $valuePath);
[60] Fix | Delete
}
[61] Fix | Delete
break;
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function