Marius Cramer
2013-11-14 b1a6a5a3991cec5cd08873b01376e45d0b247f18
interface/lib/classes/functions.inc.php
@@ -125,44 +125,44 @@
            if($islist){
               $json = '[' . implode(',', array_map(array($this, "json_encode"), $data) ) . ']';
            } else {
               $items = Array();
               $items = array();
               foreach( $data as $key => $value ) {
                  $items[] = $this->json_encode("$key") . ':' . $this->json_encode($value);
               }
               $json = '{' . implode(',', $items) . '}';
            }
         } elseif(is_string($data)){
            # Escape non-printable or Non-ASCII characters.
            # I also put the \\ character first, as suggested in comments on the 'addclashes' page.
            // Escape non-printable or Non-ASCII characters.
            // I also put the \\ character first, as suggested in comments on the 'addclashes' page.
            $string = '"'.addcslashes($data, "\\\"\n\r\t/".chr(8).chr(12)).'"';
            $json = '';
            $len = strlen($string);
            # Convert UTF-8 to Hexadecimal Codepoints.
            // Convert UTF-8 to Hexadecimal Codepoints.
            for($i = 0; $i < $len; $i++){
               $char = $string[$i];
               $c1 = ord($char);
               # Single byte;
               // Single byte;
               if($c1 <128){
                  $json .= ($c1 > 31) ? $char : sprintf("\\u%04x", $c1);
                  continue;
               }
               # Double byte
               // Double byte
               $c2 = ord($string[++$i]);
               if(($c1 & 32) === 0){
                  $json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128);
                  continue;
               }
               # Triple
               // Triple
               $c3 = ord($string[++$i]);
               if(($c1 & 16) === 0){
                  $json .= sprintf("\\u%04x", (($c1 - 224) <<12) + (($c2 - 128) << 6) + ($c3 - 128));
                  continue;
               }
               # Quadruple
               // Quadruple
               $c4 = ord($string[++$i]);
               if(($c1 & 8) === 0){
                  $u = (($c1 & 15) << 2) + (($c2>>4) & 3) - 1;
@@ -173,7 +173,7 @@
               }
            }
         } else {
            # int, floats, bools, null
            // int, floats, bools, null
            $json = strtolower(var_export($data, true));
         }
         return $json;
@@ -309,6 +309,8 @@
    * @param int precicion - after-comma-numbers (default: 2)
    * @return string - formated bytes
    */
    public function formatBytes($size, $precision = 2) {
        $base=log($size)/log(1024);
        $suffixes=array('','k','M','G','T');
@@ -340,7 +342,7 @@
                 */
                
                if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
                    include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
               include_once ISPC_CLASS_PATH.'/idn/idna_convert.class.php';
                    $this->idn_converter = new idna_convert(array('idn_version' => 2008));
                    $this->idn_converter_name = 'idna_convert.class';
                }
@@ -357,7 +359,7 @@
                 */
                
                if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
                    include_once(ISPC_CLASS_PATH.'/idn/idna_convert.class.php');
               include_once ISPC_CLASS_PATH.'/idn/idna_convert.class.php';
                    $this->idn_converter = new idna_convert(array('idn_version' => 2008));
                    $this->idn_converter_name = 'idna_convert.class';
                }