|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZTextCodec class 00004 // 00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00006 // SOFTWARE NAME: eZ Publish 00007 // SOFTWARE RELEASE: 4.0.x 00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00009 // SOFTWARE LICENSE: GNU General Public License v2.0 00010 // NOTICE: > 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of version 2.0 of the GNU General 00013 // Public License as published by the Free Software Foundation. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of version 2.0 of the GNU General 00021 // Public License along with this program; if not, write to the Free 00022 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00023 // MA 02110-1301, USA. 00024 // 00025 // 00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00027 // 00028 00029 /*! \defgroup eZI18N Internationalization */ 00030 00031 /*! 00032 \class eZTextCodec eztextcodec.php 00033 \ingroup eZI18N 00034 \brief Handles conversion from one charset to another 00035 00036 Supports <a href="http://www.ietf.org/rfc/rfc2279.txt">utf8</a> encoding/decoding 00037 00038 */ 00039 00040 class eZTextCodec 00041 { 00042 /*! 00043 */ 00044 function eZTextCodec( $inputCharsetCode, $outputCharsetCode, 00045 $realInputCharsetCode, $realOutputCharsetCode, 00046 $inputEncoding, $outputEncoding ) 00047 { 00048 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00049 $this->RequestedInputCharsetCode = $inputCharsetCode; 00050 $this->RequestedOutputCharsetCode = $outputCharsetCode; 00051 $this->InputCharsetCode = $realInputCharsetCode; 00052 $this->OutputCharsetCode = $realOutputCharsetCode; 00053 $this->InputCharacterEncodingScheme = $inputEncoding; 00054 $this->OutputCharacterEncodingScheme = $outputEncoding; 00055 00056 $useMBStringExtension = true; 00057 if ( isset( $GLOBALS['eZTextCodecMBStringExtension'] ) ) 00058 $useMBStringExtension = $GLOBALS['eZTextCodecMBStringExtension']; 00059 00060 // NOTE: 00061 // The method eZMBStringMapper::hasMBStringExtension() has been copied and inlined here 00062 // Any modification must be reflected in the method 00063 $hasMBString = ( function_exists( "mb_convert_encoding" ) and 00064 function_exists( "mb_substitute_character" ) and 00065 function_exists( "mb_strcut" ) and 00066 function_exists( "mb_strlen" ) and 00067 function_exists( "mb_strpos" ) and 00068 function_exists( "mb_strrpos" ) and 00069 function_exists( "mb_strwidth" ) and 00070 function_exists( "mb_substr" ) ); 00071 00072 $useMBString = ( $useMBStringExtension and 00073 eZTextCodec::useMBString() and 00074 $hasMBString ); 00075 00076 // Map for conversion functions using encoding functions 00077 $encodingConvertMap = array(); 00078 $encodingConvertInitMap = array(); 00079 $encodingStrlenMap = array(); 00080 00081 $encodingStrlenMap['unicode'] = 'strlenUnicode'; 00082 $encodingStrlenMap['utf-8'] = 'strlenUTF8'; 00083 $encodingStrlenMap['singlebyte'] = 'strlenCodepage'; 00084 $encodingStrlenMap['doublebyte'] = 'strlenCodepage'; 00085 00086 // Unicode -> other 00087 $encodingConvertMap['unicode']['unicode'] = 'convertNone'; 00088 $encodingConvertMap['unicode']['utf-8'] = 'convertUnicodeToUTF8'; 00089 $encodingConvertMap['unicode']['singlebyte'] = 'convertUnicodeToCodepage'; 00090 $encodingConvertMap['unicode']['doublebyte'] = 'convertUnicodeToCodepage'; 00091 00092 $encodingConvertInitMap['unicode']['singlebyte'] = 'initializeOutputCodepage'; 00093 $encodingConvertInitMap['unicode']['doublebyte'] = 'initializeOutputCodepage'; 00094 00095 // UTF8 -> other 00096 $encodingConvertMap['utf-8']['unicode'] = 'convertUTF8ToUnicode'; 00097 $encodingConvertMap['utf-8']['utf-8'] = 'convertNone'; 00098 $encodingConvertMap['utf-8']['singlebyte'] = 'convertCodepageRev'; 00099 $encodingConvertMap['utf-8']['doublebyte'] = 'convertCodepageRev'; 00100 00101 $encodingConvertInitMap['utf-8']['singlebyte'] = 'initializeOutputCodepage'; 00102 $encodingConvertInitMap['utf-8']['doublebyte'] = 'initializeOutputCodepage'; 00103 00104 // singlebyte -> other 00105 $encodingConvertMap['singlebyte']['unicode'] = 'convertCodepageToUnicode'; 00106 $encodingConvertMap['singlebyte']['utf-8'] = 'convertCodepage'; 00107 $encodingConvertMap['singlebyte']['singlebyte'] = 'convertCodepageMapper'; 00108 $encodingConvertMap['singlebyte']['doublebyte'] = 'convertCodepageMapper'; 00109 00110 $encodingConvertInitMap['singlebyte']['unicode'] = 'initializeInputCodepage'; 00111 $encodingConvertInitMap['singlebyte']['utf-8'] = 'initializeInputCodepage'; 00112 $encodingConvertInitMap['singlebyte']['singlebyte'] = 'initializeCodepageMapper'; 00113 $encodingConvertInitMap['singlebyte']['doublebyte'] = 'initializeCodepageMapper'; 00114 00115 // doublebyte -> other 00116 $encodingConvertMap['doublebyte']['unicode'] = 'convertCodepageToUnicode'; 00117 $encodingConvertMap['doublebyte']['utf-8'] = 'convertCodepage'; 00118 $encodingConvertMap['doublebyte']['singlebyte'] = 'convertCodepageMapper'; 00119 $encodingConvertMap['doublebyte']['doublebyte'] = 'convertCodepageMapper'; 00120 00121 $encodingConvertInitMap['doublebyte']['unicode'] = 'initializeInputCodepage'; 00122 $encodingConvertInitMap['doublebyte']['utf-8'] = 'initializeInputCodepage'; 00123 $encodingConvertInitMap['doublebyte']['singlebyte'] = 'initializeCodepageMapper'; 00124 $encodingConvertInitMap['doublebyte']['doublebyte'] = 'convertCodepageMapper'; 00125 00126 00127 $noneConversionFunction = 'convertNone'; 00128 $noneStrlenFunction = 'strlenNone'; 00129 $conversionFunction = null; 00130 $strlenFunction = null; 00131 $encodingConvertInitFunction = null; 00132 00133 // NOTE: 00134 // The method eZMBStringMapper::charsetList() hash been copied and inlined here 00135 // Any modification must be reflected in the method 00136 $mbStringCharsets =& $GLOBALS["eZMBCharsetList"]; 00137 if ( $useMBString and 00138 !is_array( $mbStringCharsets ) ) 00139 { 00140 $charsetList = array( "ucs-4", "ucs-4be", "ucs-4le", "ucs-2", "ucs-2be", "ucs-2le", "utf-32", "utf-32be", "utf-32le", "utf-16", 00141 "utf-16be", "utf-16le", "utf-8", "utf-7", "ascii", "euc-jp", "sjis", "eucjp-win", "sjis-win", "iso-2022-jp", "jis", 00142 "iso-8859-1", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", 00143 "iso-8859-9", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "byte2be", "byte2le", "byte4be", 00144 "byte4le", "base64", "7bit", "8bit", "utf7-imap" ); 00145 $mbStringCharsets = array(); 00146 foreach ( $charsetList as $charset ) 00147 { 00148 $mbStringCharsets[$charset] = $charset; 00149 } 00150 } 00151 00152 // Is to true if the charsets are the same and they have singlebyte encoding 00153 $isSinglebyteSame = false; 00154 $isSame = false; 00155 00156 // First detect conversion type 00157 if ( $this->InputCharsetCode == $this->OutputCharsetCode ) // Direct match, no conversion 00158 { 00159 $conversionFunction = $noneConversionFunction; 00160 $encodingConvertInitFunction = 'initializeInputCodepage'; 00161 $inpenc = $this->InputCharacterEncodingScheme; 00162 if ( $inpenc == 'singlebyte' ) 00163 { 00164 $isSinglebyteSame = true; 00165 } 00166 $isSame = true; 00167 } 00168 else if ( $useMBString and 00169 isset( $mbStringCharsets[$this->InputCharsetCode] ) and 00170 isset( $mbStringCharsets[$this->OutputCharsetCode] ) ) // Use MBString for converting if charsets supported 00171 { 00172 // NOTE: 00173 // The mbstringmapper object is no longer needed since all functionality is inlined 00174 // $this->MBStringMapper = eZMBStringMapper::instance( $this->InputCharsetCode, 00175 // $this->OutputCharsetCode ); 00176 $conversionFunction = "convertMBString"; 00177 $strlenFunction = "strlenMBString"; 00178 $encodingConvertInitFunction = false; 00179 } 00180 else // See if we support encoding scheme and codepage 00181 { 00182 $inpenc = $this->InputCharacterEncodingScheme; 00183 $outenc = $this->OutputCharacterEncodingScheme; 00184 if ( isset( $encodingConvertMap[$inpenc][$outenc] ) ) 00185 { 00186 $conversionFunction = $encodingConvertMap[$inpenc][$outenc]; 00187 } 00188 } 00189 00190 if ( $strlenFunction === null ) 00191 { 00192 $inpenc = $this->InputCharacterEncodingScheme; 00193 if ( $isSinglebyteSame ) 00194 { 00195 $strlenFunction = 'strlenNone'; 00196 } 00197 else if ( $useMBString and isset( $mbStringCharsets[$this->InputCharsetCode] ) ) 00198 { 00199 $strlenFunction = 'strlenMBString'; 00200 } 00201 else if ( isset( $encodingStrlenMap[$inpenc] ) ) 00202 { 00203 $strlenFunction = $encodingStrlenMap[$inpenc]; 00204 if ( $inpenc == 'utf-8') 00205 { 00206 //include_once( "lib/ezi18n/classes/ezutf8codec.php" ); 00207 } 00208 } 00209 } 00210 00211 if ( !$isSame and 00212 $conversionFunction and 00213 $strlenFunction ) 00214 { 00215 $this->initializeConversionFunction( $encodingConvertInitMap, $encodingConvertInitFunction ); 00216 } 00217 if ( !$conversionFunction or 00218 !$strlenFunction ) 00219 { 00220 eZDebug::writeError( "Cannot create textcodec from characterset " . $this->RequestedInputCharsetCode . 00221 " to characterset " . $this->RequestedOutputCharsetCode, 00222 "eZTextCodec" ); 00223 if ( !$conversionFunction ) 00224 $conversionFunction = $noneConversionFunction; 00225 if ( !$strlenFunction ) 00226 $strlenFunction = $noneStrlenFunction; 00227 } 00228 00229 $this->ConversionFunction = $conversionFunction; 00230 $this->StrlenFunction = $strlenFunction; 00231 $this->RequireConversion = $conversionFunction != $noneConversionFunction; 00232 } 00233 00234 function initializeConversionFunction( $encodingConvertInitMap, $encodingConvertInitFunction ) 00235 { 00236 $inpenc = $this->InputCharacterEncodingScheme; 00237 $outenc = $this->OutputCharacterEncodingScheme; 00238 $initFunction = false; 00239 if ( $encodingConvertInitFunction !== null ) 00240 { 00241 if ( $encodingConvertInitFunction ) 00242 { 00243 $initFunction = $encodingConvertInitFunction; 00244 } 00245 } 00246 else if ( isset( $encodingConvertInitMap[$inpenc][$outenc] ) ) 00247 { 00248 $initFunction = $encodingConvertInitMap[$inpenc][$outenc]; 00249 } 00250 if ( $initFunction ) 00251 { 00252 $this->$initFunction(); 00253 } 00254 } 00255 00256 function initializeCodepageMapper() 00257 { 00258 //include_once( 'lib/ezi18n/classes/ezcodepagemapper.php' ); 00259 $this->CodepageMapper = eZCodePageMapper::instance( $this->InputCharsetCode, 00260 $this->OutputCharsetCode ); 00261 } 00262 00263 function initializeInputCodepage() 00264 { 00265 //include_once( 'lib/ezi18n/classes/ezcodepage.php' ); 00266 $this->Codepage = eZCodePage::instance( $this->InputCharsetCode ); 00267 } 00268 00269 function initializeOutputCodepage() 00270 { 00271 //include_once( 'lib/ezi18n/classes/ezcodepage.php' ); 00272 $this->Codepage = eZCodePage::instance( $this->OutputCharsetCode ); 00273 } 00274 00275 /*!/ 00276 \return true if a conversion is required, if false there's no need to call the textcodec functions. 00277 */ 00278 function conversionRequired() 00279 { 00280 return $this->RequireConversion; 00281 } 00282 00283 function setUseMBString( $use ) 00284 { 00285 $GLOBALS["eZTextCodecUseMBString"] = $use; 00286 } 00287 00288 function useMBString() 00289 { 00290 $use =& $GLOBALS["eZTextCodecUseMBString"]; 00291 if ( !isset( $use ) ) 00292 $use = true; 00293 return $use; 00294 } 00295 00296 function requestedInputCharsetCode() 00297 { 00298 return $this->RequestedInputCharsetCode; 00299 } 00300 00301 function requestedOutputCharsetCode() 00302 { 00303 return $this->RequestedOutputCharsetCode; 00304 } 00305 00306 function inputCharsetCode() 00307 { 00308 return $this->InputCharsetCode; 00309 } 00310 00311 function outputCharsetCode() 00312 { 00313 return $this->OutputCharsetCode; 00314 } 00315 00316 function convertString( $str ) 00317 { 00318 eZDebug::accumulatorStart( 'textcodec_conversion', false, 'String conversion' ); 00319 //eZDebug::writeDebug( $this->ConversionFunction, 'conversion function' ); 00320 $conversionFunction = $this->ConversionFunction; 00321 $tmp = $this->$conversionFunction( $str ); 00322 eZDebug::accumulatorStop( 'textcodec_conversion' ); 00323 return $tmp; 00324 } 00325 00326 function strlen( $str ) 00327 { 00328 $strlenFunction = $this->StrlenFunction; 00329 return $this->$strlenFunction( $str ); 00330 } 00331 00332 /*! 00333 \return an empty array since no conversion is possible. 00334 */ 00335 function convertNoneToUnicode( $str ) 00336 { 00337 return array(); 00338 } 00339 00340 function convertCodepageToUnicode( $str ) 00341 { 00342 eZDebug::accumulatorStart( 'textcodec_codepage_unicode', false, 'String conversion w/ codepage to Unicode' ); 00343 $tmp = $this->Codepage->convertStringToUnicode( $str ); 00344 eZDebug::accumulatorStop( 'textcodec_codepage_unicode' ); 00345 return $tmp; 00346 } 00347 00348 function convertUTF8ToUnicode( $str ) 00349 { 00350 include_once ( 'lib/ezi18n/classes/ezutf8codec.php' ); 00351 eZDebug::accumulatorStart( 'textcodec_utf8_unicode', false, 'String conversion w/ UTF-8 to Unicode' ); 00352 $tmp = eZUTF8Codec::convertStringToUnicode( $str ); 00353 eZDebug::accumulatorStop( 'textcodec_utf8_unicode' ); 00354 return $tmp; 00355 } 00356 00357 function convertUnicodeToCodepage( $unicodeValues ) 00358 { 00359 eZDebug::accumulatorStart( 'textcodec_unicode_codepage', false, 'String conversion w/ Unicode to codepage' ); 00360 $tmp = $this->Codepage->convertUnicodeToString( $unicodeValues ); 00361 eZDebug::accumulatorStop( 'textcodec_unicode_codepage' ); 00362 return $tmp; 00363 } 00364 00365 function convertUnicodeToUTF8( $unicodeValues ) 00366 { 00367 include_once ( 'lib/ezi18n/classes/ezutf8codec.php' ); 00368 eZDebug::accumulatorStart( 'textcodec_unicode_utf8', false, 'String conversion w/ Unicode to UTF8' ); 00369 $tmp = eZUTF8Codec::convertUnicodeToString( $unicodeValues ); 00370 eZDebug::accumulatorStop( 'textcodec_unicode_utf8' ); 00371 return $tmp; 00372 } 00373 00374 function convertNone( $str ) 00375 { 00376 return $str; 00377 } 00378 00379 function convertCodepage( $str ) 00380 { 00381 eZDebug::accumulatorStart( 'textcodec_codepage', false, 'String conversion w/ codepage' ); 00382 $tmp = $this->Codepage->convertString( $str ); 00383 eZDebug::accumulatorStop( 'textcodec_codepage', false, 'String conversion w/ codepage' ); 00384 return $tmp; 00385 } 00386 00387 function convertCodepageRev( $str ) 00388 { 00389 eZDebug::accumulatorStart( 'textcodec_codepage_rev', false, 'String conversion w/ codepage reverse' ); 00390 $tmp = $this->Codepage->convertStringFromUTF8( $str ); 00391 eZDebug::accumulatorStop( 'textcodec_codepage_rev', false, 'String conversion w/ codepage reverse' ); 00392 return $tmp; 00393 } 00394 00395 function convertCodepageMapper( $str ) 00396 { 00397 eZDebug::accumulatorStart( 'textcodec_codepage_mapper', false, 'String conversion w/ codepage mapper' ); 00398 $tmp = $this->CodepageMapper->convertString( $str ); 00399 eZDebug::accumulatorStop( 'textcodec_codepage_mapper', false, 'String conversion w/ codepage mapper' ); 00400 return $tmp; 00401 } 00402 00403 function convertMBString( $str ) 00404 { 00405 eZDebug::accumulatorStart( 'textcodec_mbstring', false, 'String conversion w/ mbstring' ); 00406 // $tmp = $this->MBStringMapper->convertString( $str ); 00407 // NOTE: 00408 // Uses the mbstring function directly instead of going trough the class 00409 $tmp = mb_convert_encoding( $str, $this->OutputCharsetCode, $this->InputCharsetCode ); 00410 eZDebug::accumulatorStop( 'textcodec_mbstring', false, 'String conversion w/ mbstring' ); 00411 return $tmp; 00412 } 00413 00414 function strlenNone( $str ) 00415 { 00416 return strlen( $str ); 00417 } 00418 00419 function strlenUnicode( $unicodeValues ) 00420 { 00421 return count( $unicodeValues ); 00422 } 00423 00424 function strlenCodepage( $str ) 00425 { 00426 return $this->Codepage->strlen( $str ); 00427 } 00428 00429 function strlenUTF8( $str ) 00430 { 00431 $utf8_codec = eZUTF8Codec::instance(); 00432 return $utf8_codec->strlen( $str ); 00433 } 00434 00435 function strlenCodepageRev( $str ) 00436 { 00437 return $this->Codepage->strlenFromUTF8( $str ); 00438 } 00439 00440 function strlenCodepageMapper( $str ) 00441 { 00442 return $this->CodepageMapper->strlen( $str ); 00443 } 00444 00445 function strlenMBString( $str ) 00446 { 00447 // return $this->MBStringMapper->strlen( $str ); 00448 // NOTE: 00449 // Uses the mbstring function directly instead of going trough the class 00450 return mb_strlen( $str, $this->InputCharsetCode ); 00451 } 00452 00453 /*! 00454 \static 00455 \return a text codec instance which can be used to convert from input charset \a $inputCharsetCode 00456 and into output charset \a $outputCharsetCode. 00457 \param $inputCharsetCode If \c false the internal charset it used, otherwise it is used directly 00458 \param $outputCharsetCode If \c false the internal charset it used, otherwise it is used directly 00459 \param $alwaysReturn If \c false it will only return a textcodec instance if it is required for the input and output charset. 00460 In which case it returns \c null. 00461 */ 00462 static function instance( $inputCharsetCode, $outputCharsetCode = false, $alwaysReturn = true ) 00463 { 00464 if ( $inputCharsetCode === false or $outputCharsetCode === false ) 00465 { 00466 if ( isset( $GLOBALS['eZTextCodecInternalCharsetReal'] ) ) 00467 { 00468 $internalCharset = $GLOBALS['eZTextCodecInternalCharsetReal']; 00469 } 00470 else 00471 { 00472 $internalCharset = eZTextCodec::internalCharset(); 00473 } 00474 } 00475 00476 if ( $inputCharsetCode === false ) 00477 { 00478 $realInputCharsetCode = $inputCharsetCode = $internalCharset; 00479 } 00480 else 00481 { 00482 $realInputCharsetCode = eZCharsetInfo::realCharsetCode( $inputCharsetCode ); 00483 } 00484 00485 if ( $outputCharsetCode === false ) 00486 { 00487 $realOutputCharsetCode = $outputCharsetCode = $internalCharset; 00488 } 00489 else 00490 { 00491 $realOutputCharsetCode = eZCharsetInfo::realCharsetCode( $outputCharsetCode ); 00492 } 00493 00494 $check =& $GLOBALS["eZTextCodecCharsetCheck"]["$realInputCharsetCode-$realOutputCharsetCode"]; 00495 if ( !$alwaysReturn and isset( $check ) and !$check ) 00496 { 00497 $check = null; 00498 return $check; 00499 } 00500 if ( isset( $check ) and is_object( $check ) ) 00501 { 00502 return $check; 00503 } 00504 00505 if ( !$realInputCharsetCode ) 00506 { 00507 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00508 $realInputCharsetCode = eZCharsetInfo::realCharsetCode( $inputCharsetCode ); 00509 } 00510 if ( !$realOutputCharsetCode ) 00511 { 00512 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00513 $realOutputCharsetCode = eZCharsetInfo::realCharsetCode( $outputCharsetCode ); 00514 } 00515 $inputEncoding = eZCharsetInfo::characterEncodingScheme( $realInputCharsetCode, true ); 00516 $outputEncoding = eZCharsetInfo::characterEncodingScheme( $realOutputCharsetCode, true ); 00517 if ( !$alwaysReturn and 00518 $inputEncoding == 'singlebyte' and 00519 $inputEncoding == $outputEncoding and 00520 $realInputCharsetCode == $realOutputCharsetCode ) 00521 { 00522 $check = null; 00523 return $check; 00524 } 00525 00526 $globalsKey = "eZTextCodec-$realInputCharsetCode-$realOutputCharsetCode"; 00527 if ( !isset( $GLOBALS[$globalsKey] ) || 00528 !( $GLOBALS[$globalsKey] instanceof eZTextCodec ) ) 00529 { 00530 $GLOBALS[$globalsKey] = new eZTextCodec( $inputCharsetCode, $outputCharsetCode, 00531 $realInputCharsetCode, $realOutputCharsetCode, 00532 $inputEncoding, $outputEncoding ); 00533 } 00534 00535 $check = $GLOBALS[$globalsKey]; 00536 return $GLOBALS[$globalsKey]; 00537 } 00538 00539 /*! 00540 \static 00541 Initializes the eZTextCodec settings to the ones in the array \a $settings. 00542 \sa internalCharset, httpCharset. 00543 */ 00544 static function updateSettings( $settings ) 00545 { 00546 unset( $GLOBALS['eZTextCodecInternalCharsetReal'] ); 00547 unset( $GLOBALS['eZTextCodecHTTPCharsetReal'] ); 00548 unset( $GLOBALS['eZTextCodecCharsetCheck'] ); 00549 $GLOBALS['eZTextCodecInternalCharset'] = $settings['internal-charset']; 00550 $GLOBALS['eZTextCodecHTTPCharset'] = $settings['http-charset']; 00551 $GLOBALS['eZTextCodecMBStringExtension'] = $settings['mbstring-extension']; 00552 if ( function_exists( 'mb_internal_encoding' ) ) 00553 { 00554 @mb_internal_encoding( $settings['internal-charset'] ); 00555 } 00556 } 00557 00558 /*! 00559 \static 00560 \return the charset which is used internally, 00561 this is the charset which all external files and resources are converted to. 00562 \note will return iso-8859-1 if eZTextCodec has been updated with proper settings. 00563 */ 00564 static function internalCharset() 00565 { 00566 $realCharset =& $GLOBALS['eZTextCodecInternalCharsetReal']; 00567 if ( !isset( $realCharset ) ) 00568 { 00569 if ( !isset( $GLOBALS['eZTextCodecInternalCharset'] ) ) 00570 { 00571 $i18n = eZINI::instance( 'i18n.ini', '', false ); 00572 $charsetCode = $i18n->variable( 'CharacterSettings', 'Charset' ); 00573 } 00574 else 00575 $charsetCode = $GLOBALS['eZTextCodecInternalCharset']; 00576 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00577 $realCharset = eZCharsetInfo::realCharsetCode( $charsetCode ); 00578 } 00579 return $realCharset; 00580 } 00581 00582 /*! 00583 \static 00584 \return a charset value which can be used in HTTP headers. 00585 \note Will return the internalCharset() if not http charset is set. 00586 */ 00587 static function httpCharset() 00588 { 00589 $realCharset =& $GLOBALS['eZTextCodecHTTPCharsetReal']; 00590 if ( !isset( $realCharset ) ) 00591 { 00592 $charset = ''; 00593 if ( isset( $GLOBALS['eZTextCodecHTTPCharset'] ) ) 00594 $charset = $GLOBALS['eZTextCodecHTTPCharset']; 00595 if ( $charset == '' ) 00596 { 00597 if ( isset( $GLOBALS['eZTextCodecInternalCharsetReal'] ) ) 00598 $realCharset = $GLOBALS['eZTextCodecInternalCharsetReal']; 00599 else 00600 $realCharset = eZTextCodec::internalCharset(); 00601 } 00602 else 00603 { 00604 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00605 $realCharset = eZCharsetInfo::realCharsetCode( $charset ); 00606 } 00607 } 00608 return $realCharset; 00609 } 00610 } 00611 00612 ?>