Changeset 6126 for trunk/include


Ignore:
Timestamp:
May 8, 2010, 9:22:29 PM (14 years ago)
Author:
plg
Message:

bug 1652 fixed: json_encode function is required for admin.php?fckb_tags=1
(used in the new tags widget)

Location:
trunk/include
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r5920 r6126  
    8282  'hash_hmac', //(hash) - enabled by default as of PHP 5.1.2
    8383  'preg_last_error', // PHP 5 >= 5.2.0
     84  'json_encode', // PHP 5 >= 5.2.0
    8485  ) as $func)
    8586{
  • trunk/include/ws_protocols/json_encoder.php

    r5196 r6126  
    2121// | USA.                                                                  |
    2222// +-----------------------------------------------------------------------+
    23 
    24 
    25 #_____________________  PHP 5.2
    26 if (! function_exists('json_encode')) {
    27   function json_encode($data) {
    28     switch (gettype($data)) {
    29       case 'boolean':
    30         return ($data ? 'true' : 'false');
    31       case 'null':
    32       case 'NULL':
    33         return 'null';
    34       case 'integer':
    35       case 'double':
    36         return $data;
    37       case 'string':
    38         return '"'. str_replace(array("\\",'"',"/","\n","\r","\t"), array("\\\\",'\"',"\\/","\\n","\\r","\\t"), $data) .'"';
    39       case 'object':
    40       case 'array':
    41         if ($data === array()) return '[]'; # empty array
    42         if (range(0, count($data) - 1) !== array_keys($data) ) { # string keys, unordered, non-incremental keys, .. - whatever, make object
    43           $out = "\n".'{';
    44           foreach($data as $key => $value) {
    45             $out .= json_encode((string) $key) . ':' . json_encode($value) . ',';
    46           }
    47           $out = substr($out, 0, -1) . "\n". '}';
    48         }else{
    49           # regular array
    50           $out = "\n".'[' . join("\n".',', array_map('json_encode', $data)) ."\n".']';
    51         }
    52         return $out;
    53     }
    54   }
    55 }
    5623
    5724class PwgJsonEncoder extends PwgResponseEncoder
Note: See TracChangeset for help on using the changeset viewer.