123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- use Drupal\Component\Utility\Unicode;
- function unicode_requirements() {
- @trigger_error('unicode_requirements() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. There is no replacement; system_requirements() now includes the logic instead. See https://www.drupal.org/node/2884698', E_USER_DEPRECATED);
- $libraries = [
- Unicode::STATUS_SINGLEBYTE => t('Standard PHP'),
- Unicode::STATUS_MULTIBYTE => t('PHP Mbstring Extension'),
- Unicode::STATUS_ERROR => t('Error'),
- ];
- $severities = [
- Unicode::STATUS_SINGLEBYTE => REQUIREMENT_WARNING,
- Unicode::STATUS_MULTIBYTE => NULL,
- Unicode::STATUS_ERROR => REQUIREMENT_ERROR,
- ];
- $failed_check = Unicode::check();
- $library = Unicode::getStatus();
- $requirements['unicode'] = [
- 'title' => t('Unicode library'),
- 'value' => $libraries[$library],
- 'severity' => $severities[$library],
- ];
- switch ($failed_check) {
- case 'mb_strlen':
- $requirements['unicode']['description'] = t('Operations on Unicode strings are emulated on a best-effort basis. Install the <a href="http://php.net/mbstring">PHP mbstring extension</a> for improved Unicode support.');
- break;
- case 'mbstring.func_overload':
- $requirements['unicode']['description'] = t('Multibyte string function overloading in PHP is active and must be disabled. Check the php.ini <em>mbstring.func_overload</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
- break;
- case 'mbstring.encoding_translation':
- $requirements['unicode']['description'] = t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.encoding_translation</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
- break;
- case 'mbstring.http_input':
- $requirements['unicode']['description'] = t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_input</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
- break;
- case 'mbstring.http_output':
- $requirements['unicode']['description'] = t('Multibyte string output conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_output</em> setting. Please refer to the <a href="http://php.net/mbstring">PHP mbstring documentation</a> for more information.');
- break;
- }
- return $requirements;
- }
- function drupal_xml_parser_create(&$data) {
-
- $encoding = 'utf-8';
- $bom = FALSE;
-
- if (!strncmp($data, "\xEF\xBB\xBF", 3)) {
- $bom = TRUE;
- $data = substr($data, 3);
- }
-
- if (!$bom && preg_match('/^<\?xml[^>]+encoding="(.+?)"/', $data, $match)) {
- $encoding = $match[1];
- }
-
- $php_supported = ['utf-8', 'iso-8859-1', 'us-ascii'];
- if (!in_array(strtolower($encoding), $php_supported)) {
- $out = Unicode::convertToUtf8($data, $encoding);
- if ($out !== FALSE) {
- $encoding = 'utf-8';
- $data = preg_replace('/^(<\?xml[^>]+encoding)="(.+?)"/', '\\1="utf-8"', $out);
- }
- else {
- \Drupal::logger('php')->warning('Could not convert XML encoding %s to UTF-8.', ['%s' => $encoding]);
- return FALSE;
- }
- }
- $xml_parser = xml_parser_create($encoding);
- xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'utf-8');
- return $xml_parser;
- }
|