Ticket #6913: 6193_3.patch
File 6193_3.patch, 5.7 KB (added by , 13 years ago) |
---|
-
ckeditor_php4.php
531 531 532 532 /** 533 533 * This little function provides a basic JSON support. 534 * http://php.net/manual/en/function.json-encode.php535 534 * \private 536 535 * 537 536 * @param mixed $val … … 542 541 if (is_null($val)) { 543 542 return 'null'; 544 543 } 545 if ( $val === false) {546 return 'false';544 if (is_bool($val)) { 545 return $val ? 'true' : 'false'; 547 546 } 548 if ( $val === true) {549 return 'true';547 if (is_int($val)) { 548 return $val; 550 549 } 551 if (is_ scalar($val))552 {553 if (is_float($val))554 555 // Always use "." for floats.556 $val = str_replace(",", ".", strval($val));550 if (is_float($val)) { 551 return str_replace(',', '.', $val); 552 } 553 if (is_array($val) || is_object($val)) { 554 if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) { 555 return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']'; 557 556 } 558 559 // Use @@ to not use quotes when outputting string value 560 if (strpos($val, '@@') === 0) { 561 return substr($val, 2); 557 $temp = array(); 558 foreach ($val as $k => $v){ 559 $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v); 562 560 } 563 else { 564 // All scalars are converted to strings to avoid indeterminism. 565 // PHP's "1" and 1 are equal for all PHP operators, but 566 // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend, 567 // we should get the same result in the JS frontend (string). 568 // Character replacements for JSON. 569 static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), 570 array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"')); 571 572 $val = str_replace($jsonReplaces[0], $jsonReplaces[1], $val); 573 if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') { 574 return $val; 575 } 576 577 return '"' . $val . '"'; 578 } 561 return '{' . implode(',', $temp) . '}'; 579 562 } 580 $isList = true; 581 for ($i = 0, reset($val); $i < count($val); $i++, next($val)) 582 { 583 if (key($val) !== $i) 584 { 585 $isList = false; 586 break; 587 } 588 } 589 $result = array(); 590 if ($isList) 591 { 592 foreach ($val as $v) $result[] = $this->jsEncode($v); 593 return '[ ' . join(', ', $result) . ' ]'; 594 } 595 else 596 { 597 foreach ($val as $k => $v) $result[] = $this->jsEncode($k).': '.$this->jsEncode($v); 598 return '{ ' . join(', ', $result) . ' }'; 599 } 563 // String otherwise 564 if (strpos($val, '@@') === 0) 565 return substr($val, 2); 566 if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') 567 return $val; 568 569 return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"'; 600 570 } 601 571 } -
ckeditor_php5.php
522 522 523 523 /** 524 524 * This little function provides a basic JSON support. 525 * http://php.net/manual/en/function.json-encode.php526 525 * 527 526 * @param mixed $val 528 527 * @return string … … 532 531 if (is_null($val)) { 533 532 return 'null'; 534 533 } 535 if ( $val === false) {536 return 'false';534 if (is_bool($val)) { 535 return $val ? 'true' : 'false'; 537 536 } 538 if ( $val === true) {539 return 'true';537 if (is_int($val)) { 538 return $val; 540 539 } 541 if (is_ scalar($val))542 {543 if (is_float($val))544 545 // Always use "." for floats.546 $val = str_replace(",", ".", strval($val));540 if (is_float($val)) { 541 return str_replace(',', '.', $val); 542 } 543 if (is_array($val) || is_object($val)) { 544 if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) { 545 return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']'; 547 546 } 548 549 // Use @@ to not use quotes when outputting string value 550 if (strpos($val, '@@') === 0) { 551 return substr($val, 2); 547 $temp = array(); 548 foreach ($val as $k => $v){ 549 $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v); 552 550 } 553 else { 554 // All scalars are converted to strings to avoid indeterminism. 555 // PHP's "1" and 1 are equal for all PHP operators, but 556 // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend, 557 // we should get the same result in the JS frontend (string). 558 // Character replacements for JSON. 559 static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), 560 array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"')); 561 562 $val = str_replace($jsonReplaces[0], $jsonReplaces[1], $val); 563 if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') { 564 return $val; 565 } 566 567 return '"' . $val . '"'; 568 } 551 return '{' . implode(',', $temp) . '}'; 569 552 } 570 $isList = true; 571 for ($i = 0, reset($val); $i < count($val); $i++, next($val)) 572 { 573 if (key($val) !== $i) 574 { 575 $isList = false; 576 break; 577 } 578 } 579 $result = array(); 580 if ($isList) 581 { 582 foreach ($val as $v) $result[] = $this->jsEncode($v); 583 return '[ ' . join(', ', $result) . ' ]'; 584 } 585 else 586 { 587 foreach ($val as $k => $v) $result[] = $this->jsEncode($k).': '.$this->jsEncode($v); 588 return '{ ' . join(', ', $result) . ' }'; 589 } 553 // String otherwise 554 if (strpos($val, '@@') === 0) 555 return substr($val, 2); 556 if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') 557 return $val; 558 559 return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"'; 590 560 } 591 561 }