Use JSON_PRETTY_PRINT in devel_mode

This effectively makes PHP 5.4 a real requirement
pull/5490/head
Aleksander Machniak 8 years ago
parent 1a8bdf554a
commit f43f5bf93f

@ -36,6 +36,7 @@ abstract class rcmail_output extends rcube_output
protected $pagetitle = '';
protected $object_handlers = array();
protected $devel_mode = false;
/**
@ -44,6 +45,8 @@ abstract class rcmail_output extends rcube_output
public function __construct($task = null, $framed = false)
{
parent::__construct();
$this->devel_mode = (bool) $this->config->get('devel_mode');
}
/**

@ -690,7 +690,7 @@ EOF;
$parent = $this->framed || preg_match('/^parent\./', $method);
foreach ($args as $i => $arg) {
$args[$i] = self::json_serialize($arg);
$args[$i] = self::json_serialize($arg, $this->devel_mode);
}
if ($parent) {
@ -1923,7 +1923,7 @@ EOF;
return;
}
$this->add_script('var images = ' . self::json_serialize($images) .';
$this->add_script('var images = ' . self::json_serialize($images, $this->devel_mode) .';
for (var i=0; i<images.length; i++) {
img = new Image();
img.src = images[i];

@ -232,7 +232,7 @@ class rcmail_output_json extends rcmail_output
$response = $hook['response'];
unset($hook['response']);
echo self::json_serialize($response);
echo self::json_serialize($response, $this->devel_mode);
}
/**
@ -245,7 +245,7 @@ class rcmail_output_json extends rcmail_output
foreach ($this->commands as $i => $args) {
$method = array_shift($args);
foreach ($args as $i => $arg) {
$args[$i] = self::json_serialize($arg);
$args[$i] = self::json_serialize($arg, $this->devel_mode);
}
$out .= sprintf(

@ -265,16 +265,22 @@ abstract class rcube_output
/**
* Convert a variable into a javascript object notation
*
* @param mixed Input value
* @param mixed $input Input value
* @param boolean $pretty Enable JSON formatting
*
* @return string Serialized JSON string
*/
public static function json_serialize($input)
public static function json_serialize($input, $pretty = false)
{
$input = rcube_charset::clean($input);
$input = rcube_charset::clean($input);
$options = 0;
if ($pretty) {
$options |= JSON_PRETTY_PRINT;
}
// sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences
// that's why we have @ here
return @json_encode($input);
return @json_encode($input, $options);
}
}

Loading…
Cancel
Save