| @@ 244-261 (lines=18) @@ | ||
| 241 | return $r; |
|
| 242 | } |
|
| 243 | ||
| 244 | if ($respEncoding != '') { |
|
| 245 | ||
| 246 | // Since parsing will fail if charset is not specified in the xml prologue, |
|
| 247 | // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that... |
|
| 248 | // The following code might be better for mb_string enabled installs, but makes the lib about 200% slower... |
|
| 249 | //if (!is_valid_charset($respEncoding, array('UTF-8'))) |
|
| 250 | if (!in_array($respEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) { |
|
| 251 | if ($respEncoding == 'ISO-8859-1') { |
|
| 252 | $data = utf8_encode($data); |
|
| 253 | } else { |
|
| 254 | if (extension_loaded('mbstring')) { |
|
| 255 | $data = mb_convert_encoding($data, 'UTF-8', $respEncoding); |
|
| 256 | } else { |
|
| 257 | Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received response: ' . $respEncoding); |
|
| 258 | } |
|
| 259 | } |
|
| 260 | } |
|
| 261 | } |
|
| 262 | ||
| 263 | // PHP internally might use ISO-8859-1, so we have to tell the xml parser to give us back data in the expected charset. |
|
| 264 | // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8 |
|
| @@ 237-254 (lines=18) @@ | ||
| 234 | { |
|
| 235 | // 'guestimate' encoding |
|
| 236 | $valEncoding = XMLParser::guessEncoding('', $xmlVal); |
|
| 237 | if ($valEncoding != '') { |
|
| 238 | ||
| 239 | // Since parsing will fail if charset is not specified in the xml prologue, |
|
| 240 | // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that... |
|
| 241 | // The following code might be better for mb_string enabled installs, but makes the lib about 200% slower... |
|
| 242 | //if (!is_valid_charset($valEncoding, array('UTF-8')) |
|
| 243 | if (!in_array($valEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($xmlVal)) { |
|
| 244 | if ($valEncoding == 'ISO-8859-1') { |
|
| 245 | $xmlVal = utf8_encode($xmlVal); |
|
| 246 | } else { |
|
| 247 | if (extension_loaded('mbstring')) { |
|
| 248 | $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding); |
|
| 249 | } else { |
|
| 250 | Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding); |
|
| 251 | } |
|
| 252 | } |
|
| 253 | } |
|
| 254 | } |
|
| 255 | ||
| 256 | // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8! |
|
| 257 | if (!in_array(PhpXmlRpc::$xmlrpc_internalencoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) { |
|
| @@ 476-493 (lines=18) @@ | ||
| 473 | { |
|
| 474 | // decompose incoming XML into request structure |
|
| 475 | ||
| 476 | if ($reqEncoding != '') { |
|
| 477 | // Since parsing will fail if charset is not specified in the xml prologue, |
|
| 478 | // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that... |
|
| 479 | // The following code might be better for mb_string enabled installs, but |
|
| 480 | // makes the lib about 200% slower... |
|
| 481 | //if (!is_valid_charset($reqEncoding, array('UTF-8'))) |
|
| 482 | if (!in_array($reqEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) { |
|
| 483 | if ($reqEncoding == 'ISO-8859-1') { |
|
| 484 | $data = utf8_encode($data); |
|
| 485 | } else { |
|
| 486 | if (extension_loaded('mbstring')) { |
|
| 487 | $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding); |
|
| 488 | } else { |
|
| 489 | Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding); |
|
| 490 | } |
|
| 491 | } |
|
| 492 | } |
|
| 493 | } |
|
| 494 | ||
| 495 | // PHP internally might use ISO-8859-1, so we have to tell the xml parser to give us back data in the expected charset. |
|
| 496 | // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8 |
|