|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZCodePage 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 /*! 00030 \class eZCodePage ezcodepage.php 00031 \ingroup eZI18N 00032 \brief Handles codepage files for charset mapping 00033 00034 */ 00035 00036 require_once( "lib/ezutils/classes/ezdebug.php" ); 00037 //include_once( "lib/ezi18n/classes/ezutf8codec.php" ); 00038 //include_once( "lib/ezi18n/classes/ezcharsetinfo.php" ); 00039 00040 class eZCodePage 00041 { 00042 const CACHE_CODE_DATE = 1028204478; 00043 00044 /*! 00045 Initializes the codepage with the charset code $charset_code, and then loads it. 00046 */ 00047 function eZCodePage( $charset_code, $use_cache = true ) 00048 { 00049 $this->RequestedCharsetCode = $charset_code; 00050 $this->CharsetCode = eZCharsetInfo::realCharsetCode( $charset_code ); 00051 $this->CharsetEncodingScheme = eZCharsetInfo::characterEncodingScheme( $charset_code ); 00052 $this->Valid = false; 00053 $this->SubstituteChar = 63; // the ? character 00054 $this->MinCharValue = 0; 00055 $this->MaxCharValue = 0; 00056 00057 $this->load( $use_cache ); 00058 } 00059 00060 function convertString( $str ) 00061 { 00062 $len = strlen( $str ); 00063 $chars = ''; 00064 $utf8_codec = eZUTF8Codec::instance(); 00065 for ( $i = 0; $i < $len; ) 00066 { 00067 $charLen = 1; 00068 $char = $this->charToUTF8( $str, $i, $charLen ); 00069 if ( $char !== null ) 00070 $chars .= $char; 00071 else 00072 $chars .= $utf8_codec->toUtf8( $this->SubstituteChar ); 00073 $i += $charLen; 00074 } 00075 return $chars; 00076 } 00077 00078 function convertStringToUnicode( $str ) 00079 { 00080 $len = strlen( $str ); 00081 $unicodeValues = array(); 00082 for ( $i = 0; $i < $len; ) 00083 { 00084 $charLen = 1; 00085 $unicodeValue = $this->charToUnicode( $str, $i, $charLen ); 00086 if ( $unicodeValue !== null ) 00087 $unicodeValues[] = $unicodeValue; 00088 $i += $charLen; 00089 } 00090 return $unicodeValues; 00091 } 00092 00093 function convertUnicodeToString( $unicodeValues ) 00094 { 00095 if ( !is_array( $unicodeValues ) ) 00096 return false; 00097 $text = ''; 00098 foreach ( $unicodeValues as $unicodeValue ) 00099 { 00100 $char = $this->unicodeToChar( $unicodeValue ); 00101 $text .= $char; 00102 } 00103 return $text; 00104 } 00105 00106 function convertStringFromUTF8( $multi_char ) 00107 { 00108 $strlen = strlen( $multi_char ); 00109 $text = ''; 00110 $codeMap = $this->CodeMap; 00111 $subChar = $this->SubstituteChar; 00112 for ( $offs = 0; $offs < $strlen; ) 00113 { 00114 // The following code has been copied from lib/ezi18n/classes/ezutf8codec.php 00115 // It has been optimized a bit from the original code due to inlining 00116 00117 $char_code = false; 00118 if ( ( ord( $multi_char[$offs + 0] ) & 0x80 ) == 0x00 ) // 7 bit, 1 char 00119 { 00120 $char_code = ord( $multi_char[$offs + 0] ); 00121 $offs += 1; 00122 } 00123 else if ( ( ord( $multi_char[$offs + 0] ) & 0xe0 ) == 0xc0 ) // 11 bit, 2 chars 00124 { 00125 if ( ( ord( $multi_char[$offs + 1] ) & 0xc0 ) != 0x80 ) 00126 { 00127 $offs += 2; 00128 continue; 00129 } 00130 $char_code = ( (( ord( $multi_char[$offs + 0] ) & 0x1f ) << 6) + 00131 (( ord( $multi_char[$offs + 1] ) & 0x3f )) ); 00132 $offs += 2; 00133 if ( $char_code < 128 ) // Illegal multibyte, should use less than 2 chars 00134 continue; 00135 } 00136 else if ( ( ord( $multi_char[$offs + 0] ) & 0xf0 ) == 0xe0 ) // 16 bit, 3 chars 00137 { 00138 if ( ( ord( $multi_char[$offs + 1] ) & 0xc0 ) != 0x80 or 00139 ( ord( $multi_char[$offs + 2] ) & 0xc0 ) != 0x80 ) 00140 { 00141 $offs += 3; 00142 continue; 00143 } 00144 $char_code = ( (( ord( $multi_char[$offs + 0] ) & 0x0f ) << 12) + 00145 (( ord( $multi_char[$offs + 1] ) & 0x3f ) << 6) + 00146 (( ord( $multi_char[$offs + 2] ) & 0x3f )) ); 00147 $offs += 3; 00148 if ( $char_code < 2048 ) // Illegal multibyte, should use less than 3 chars 00149 continue; 00150 } 00151 else if ( ( ord( $multi_char[$offs + 0] ) & 0xf8 ) == 0xf0 ) // 21 bit, 4 chars 00152 { 00153 if ( ( ord( $multi_char[$offs + 1] ) & 0xc0 ) != 0x80 or 00154 ( ord( $multi_char[$offs + 2] ) & 0xc0 ) != 0x80 or 00155 ( ord( $multi_char[$offs + 3] ) & 0xc0 ) != 0x80 ) 00156 { 00157 $offs += 4; 00158 continue; 00159 } 00160 $char_code = ( (( ord( $multi_char[$offs + 0] ) & 0x07 ) << 18) + 00161 (( ord( $multi_char[$offs + 1] ) & 0x3f ) << 12) + 00162 (( ord( $multi_char[$offs + 2] ) & 0x3f ) << 6) + 00163 (( ord( $multi_char[$offs + 3] ) & 0x3f )) ); 00164 $offs += 4; 00165 if ( $char_code < 65536 ) // Illegal multibyte, should use less than 4 chars 00166 continue; 00167 } 00168 else if ( ( ord( $multi_char[$offs + 0] ) & 0xfc ) == 0xf8 ) // 26 bit, 5 chars 00169 { 00170 if ( ( ord( $multi_char[$offs + 1] ) & 0xc0 ) != 0x80 or 00171 ( ord( $multi_char[$offs + 2] ) & 0xc0 ) != 0x80 or 00172 ( ord( $multi_char[$offs + 3] ) & 0xc0 ) != 0x80 or 00173 ( ord( $multi_char[$offs + 4] ) & 0xc0 ) != 0x80 ) 00174 { 00175 $offs += 5; 00176 continue; 00177 } 00178 $char_code = ( (( ord( $multi_char[$offs + 0] ) & 0x03 ) << 24) + 00179 (( ord( $multi_char[$offs + 1] ) & 0x3f ) << 18) + 00180 (( ord( $multi_char[$offs + 2] ) & 0x3f ) << 12) + 00181 (( ord( $multi_char[$offs + 3] ) & 0x3f ) << 6) + 00182 (( ord( $multi_char[$offs + 4] ) & 0x3f )) ); 00183 $offs += 5; 00184 if ( $char_code < 2097152 ) // Illegal multibyte, should use less than 5 chars 00185 continue; 00186 } 00187 else if ( ( ord( $multi_char[$offs + 0] ) & 0xfe ) == 0xfc ) // 31 bit, 6 chars 00188 { 00189 if ( ( ord( $multi_char[$offs + 1] ) & 0xc0 ) != 0x80 or 00190 ( ord( $multi_char[$offs + 2] ) & 0xc0 ) != 0x80 or 00191 ( ord( $multi_char[$offs + 3] ) & 0xc0 ) != 0x80 or 00192 ( ord( $multi_char[$offs + 4] ) & 0xc0 ) != 0x80 or 00193 ( ord( $multi_char[$offs + 5] ) & 0xc0 ) != 0x80 ) 00194 { 00195 $offs += 6; 00196 continue; 00197 } 00198 $char_code = ( (( ord( $multi_char[$offs + 0] ) & 0x01 ) << 30) + 00199 (( ord( $multi_char[$offs + 1] ) & 0x3f ) << 24) + 00200 (( ord( $multi_char[$offs + 2] ) & 0x3f ) << 18) + 00201 (( ord( $multi_char[$offs + 3] ) & 0x3f ) << 12) + 00202 (( ord( $multi_char[$offs + 4] ) & 0x3f ) << 6) + 00203 (( ord( $multi_char[$offs + 5] ) & 0x3f )) ); 00204 $offs += 6; 00205 if ( $char_code < 67108864 ) // Illegal multibyte, should use less than 6 chars 00206 continue; 00207 } 00208 else // Unknown state, just increase one to make sure we don't get stuck 00209 { 00210 $offs += 1; 00211 continue; 00212 } 00213 00214 // The following code has been copied from the member function unicodeToChar 00215 if ( isset( $codeMap[$char_code] ) ) 00216 { 00217 $code = $codeMap[$char_code]; 00218 if ( $code <= 0xff ) 00219 $text .= chr( $code ); 00220 else 00221 $text .= chr( ( $code >> 8 ) & 0xff ) . chr( $code & 0xff ); 00222 } 00223 else 00224 $text .= chr( $subChar ); 00225 } 00226 return $text; 00227 } 00228 00229 function strlen( $str ) 00230 { 00231 if ( $this->CharsetEncodingScheme == "doublebyte" ) 00232 { 00233 $len = strlen( $str ); 00234 $strlen = 0; 00235 for ( $i = 0; $i < $len; ) 00236 { 00237 $charLen = 1; 00238 $code = ord( $str[$i] ); 00239 if ( isset( $this->ReadExtraMap[$code] ) ) 00240 $charLen = 2; 00241 ++$strlen; 00242 $i += $charLen; 00243 } 00244 return $strlen; 00245 } 00246 else 00247 return strlen( $str ); 00248 } 00249 00250 function strlenFromUTF8( $str ) 00251 { 00252 return eZUTF8Codec::instance()->strlen( $str ); 00253 } 00254 00255 function charToUtf8( $str, $pos, &$charLen ) 00256 { 00257 $code = ord( $str[$pos] ); 00258 $charLen = 1; 00259 if ( isset( $this->ReadExtraMap[$code] ) ) 00260 { 00261 $code = ( $code << 8 ) | ord( $str[$pos+1] ); 00262 $charLen = 2; 00263 } 00264 if ( isset( $this->UTF8Map[$code] ) ) 00265 return $this->UTF8Map[$code]; 00266 return null; 00267 } 00268 00269 function charToUnicode( $str, $pos, &$charLen ) 00270 { 00271 $code = ord( $str[$pos] ); 00272 $charLen = 1; 00273 if ( isset( $this->ReadExtraMap[$code] ) ) 00274 { 00275 $code = ( $code << 8 ) | ord( $str[$pos+1] ); 00276 $charLen = 2; 00277 } 00278 if ( isset( $this->UnicodeMap[$code] ) ) 00279 return $this->UnicodeMap[$code]; 00280 return null; 00281 } 00282 00283 function codeToUtf8( $code ) 00284 { 00285 return $this->UTF8Map[$code]; 00286 } 00287 00288 function codeToUnicode( $code ) 00289 { 00290 if ( isset( $this->UnicodeMap[$code] ) ) 00291 { 00292 return $this->UnicodeMap[$code]; 00293 } 00294 return null; 00295 } 00296 00297 function utf8ToChar( $ucode ) 00298 { 00299 if ( isset( $this->UTF8CodeMap[$ucode] ) ) 00300 { 00301 $code = $this->UTF8CodeMap[$ucode]; 00302 if ( $code <= 0xff ) 00303 return chr( $code ); 00304 else 00305 return chr( ( $code >> 8 ) & 0xff ) . chr( $code & 0xff ); 00306 } 00307 else 00308 return chr( $this->SubstituteChar ); 00309 } 00310 00311 function unicodeToChar( $ucode ) 00312 { 00313 if ( isset( $this->CodeMap[$ucode] ) ) 00314 { 00315 $code = $this->CodeMap[$ucode]; 00316 if ( $code <= 0xff ) 00317 return chr( $code ); 00318 else 00319 return chr( ( $code >> 8 ) & 0xff ) . chr( $code & 0xff ); 00320 } 00321 else 00322 return chr( $this->SubstituteChar ); 00323 } 00324 00325 function utf8ToCode( $ucode ) 00326 { 00327 if ( isset( $this->UTF8CodeMap[$ucode] ) ) 00328 return $this->UTF8CodeMap[$ucode]; 00329 return null; 00330 } 00331 00332 function unicodeToCode( $ucode ) 00333 { 00334 if ( isset( $this->CodeMap[$ucode] ) ) 00335 return $this->CodeMap[$ucode]; 00336 return null; 00337 } 00338 00339 function substituteChar() 00340 { 00341 return $this->SubstituteChar; 00342 } 00343 00344 function setSubstituteChar( $char ) 00345 { 00346 $this->SubstituteChar = $char; 00347 } 00348 00349 /*! 00350 \static 00351 Returns true if the codepage $charset_code exists. 00352 */ 00353 static function exists( $charset_code ) 00354 { 00355 $file = eZCodePage::fileName( $charset_code ); 00356 return file_exists( $file ); 00357 } 00358 00359 /*! 00360 \static 00361 Returns the filename of the charset code \a $charset_code. 00362 */ 00363 static function fileName( $charset_code ) 00364 { 00365 $charset_code = eZCharsetInfo::realCharsetCode( $charset_code ); 00366 $file = "share/codepages/" . $charset_code; 00367 return $file; 00368 } 00369 00370 function cacheFileName( $charset_code ) 00371 { 00372 $permissionArray = eZCodePage::permissionSetting(); 00373 00374 if ( $permissionArray === false ) 00375 return false; 00376 $charset_code = eZCharsetInfo::realCharsetCode( $charset_code ); 00377 $cache_dir = $permissionArray['var_directory'] . "/codepages/"; 00378 $cache_filename = md5( $charset_code ); 00379 $cache = $cache_dir . $cache_filename . ".php"; 00380 return $cache; 00381 } 00382 00383 function fileModification( $charset_code ) 00384 { 00385 $file = eZCodePage::fileName( $charset_code ); 00386 if ( !file_exists( $file ) ) 00387 return false; 00388 return filemtime( $file ); 00389 } 00390 00391 function codepageList() 00392 { 00393 $list = array(); 00394 $dir = "share/codepages/"; 00395 $dh = opendir( $dir ); 00396 while ( ( $file = readdir( $dh ) ) !== false ) 00397 { 00398 if ( $file == "." or 00399 $file == ".." or 00400 preg_match( "/^\./", $file ) or 00401 preg_match( "/~$/", $file ) ) 00402 continue; 00403 $list[] = $file; 00404 } 00405 closedir( $dh ); 00406 sort( $list ); 00407 return $list; 00408 } 00409 00410 00411 /*! 00412 Stores the cache object. 00413 */ 00414 function storeCacheObject( $filename, $permissionArray ) 00415 { 00416 $dir = dirname( $filename ); 00417 $file = basename( $filename ); 00418 $php = new eZPHPCreator( $dir, $file ); 00419 00420 $php->addVariable( "umap", array() ); 00421 $php->addVariable( "utf8map", array() ); 00422 $php->addVariable( "cmap", array() ); 00423 $php->addVariable( "utf8cmap", array() ); 00424 00425 reset( $this->UnicodeMap ); 00426 while ( ( $key = key( $this->UnicodeMap ) ) !== null ) 00427 { 00428 $item = $this->UnicodeMap[$key]; 00429 $php->addVariable( "umap[$key]", $item ); 00430 next( $this->UnicodeMap ); 00431 } 00432 00433 reset( $this->UTF8Map ); 00434 while ( ( $key = key( $this->UTF8Map ) ) !== null ) 00435 { 00436 $item = $this->UTF8Map[$key]; 00437 if ( $item == 0 ) 00438 { 00439 $php->addCodePiece( "\$utf8map[0] = chr(0);\n" ); 00440 } 00441 else 00442 { 00443 $val = str_replace( array( "\\", "'" ), 00444 array( "\\\\", "\\'" ), 00445 $item ); 00446 $php->addVariable( "utf8map[$key]", $val ); 00447 } 00448 next( $this->UTF8Map ); 00449 } 00450 00451 reset( $this->CodeMap ); 00452 while ( ( $key = key( $this->CodeMap ) ) !== null ) 00453 { 00454 $item = $this->CodeMap[$key]; 00455 $php->addVariable( "cmap[$key]", $item ); 00456 next( $this->CodeMap ); 00457 } 00458 00459 reset( $this->UTF8CodeMap ); 00460 while ( ( $key = key( $this->UTF8CodeMap ) ) !== null ) 00461 { 00462 $item = $this->UTF8CodeMap[$key]; 00463 if ( $item == 0 ) 00464 { 00465 $php->addVariable( "utf8cmap[chr(0)]", 0 ); 00466 } 00467 else 00468 { 00469 $val = str_replace( array( "\\", "'" ), 00470 array( "\\\\", "\\'" ), 00471 $key ); 00472 $php->addVariable( "utf8cmap['$val']", $item ); 00473 } 00474 next( $this->UTF8CodeMap ); 00475 } 00476 00477 reset( $this->ReadExtraMap ); 00478 while ( ( $key = key( $this->ReadExtraMap ) ) !== null ) 00479 { 00480 $item = $this->ReadExtraMap[$key]; 00481 $php->addVariable( "read_extra[$key]", $item ); 00482 next( $this->ReadExtraMap ); 00483 } 00484 00485 $php->addVariable( "eZCodePageCacheCodeDate", self::CACHE_CODE_DATE ); 00486 $php->addVariable( "min_char", $this->MinCharValue ); 00487 $php->addVariable( "max_char", $this->MaxCharValue ); 00488 $php->store( true ); 00489 00490 if ( file_exists( $filename ) ) 00491 { 00492 // Store the old umask and set a new one. 00493 $oldPermissionSetting = umask( 0 ); 00494 00495 // Change the permission setting. 00496 @chmod( $filename, $permissionArray['file_permission'] ); 00497 00498 // Restore the old umask. 00499 umask( $oldPermissionSetting ); 00500 } 00501 } 00502 00503 00504 /*! 00505 */ 00506 function cacheFilepath() 00507 { 00508 $permissionArray = eZCodePage::permissionSetting(); 00509 00510 if ( $permissionArray === false ) 00511 return false; 00512 $cache_dir = $permissionArray['var_directory'] . "/codepages/"; 00513 $cache_filename = md5( $this->CharsetCode ); 00514 $cache = $cache_dir . $cache_filename . ".php"; 00515 00516 return $cache; 00517 } 00518 00519 00520 00521 /*! 00522 Loads the codepage from disk. 00523 If $use_cache is true and a cached version is found it is used instead. 00524 If $use_cache is true and no cache was found a new cache is created. 00525 */ 00526 function load( $use_cache = true ) 00527 { 00528 // temporarely hide the cache display problem 00529 // http://ez.no/community/bugs/char_transform_cache_file_is_not_valid_php 00530 //$use_cache = false; 00531 $file = "share/codepages/" . $this->CharsetCode; 00532 // eZDebug::writeDebug( "ezcodepage::load was called for $file..." ); 00533 00534 $permissionArray = self::permissionSetting(); 00535 if ( $permissionArray !== false ) 00536 { 00537 $cache_dir = $permissionArray['var_directory'] . "/codepages/"; 00538 $cache_filename = md5( $this->CharsetCode ); 00539 $cache = $cache_dir . $cache_filename . ".php"; 00540 } 00541 else 00542 { 00543 $cache = false; 00544 } 00545 00546 if ( !file_exists( $file ) ) 00547 { 00548 eZDebug::writeWarning( "Couldn't load codepage file $file", "eZCodePage" ); 00549 return; 00550 } 00551 $file_m = filemtime( $file ); 00552 $this->Valid = false; 00553 if ( isset( $GLOBALS['eZSiteBasics'] ) ) 00554 { 00555 $siteBasics = $GLOBALS['eZSiteBasics']; 00556 if ( isset( $siteBasics['no-cache-adviced'] ) and 00557 $siteBasics['no-cache-adviced'] ) 00558 $use_cache = false; 00559 } 00560 if ( $cache && file_exists( $cache ) and $use_cache ) 00561 { 00562 $cache_m = filemtime( $cache ); 00563 if ( $file_m <= $cache_m ) 00564 { 00565 unset( $eZCodePageCacheCodeDate ); 00566 $umap = $utf8map = $cmap = $utf8cmap = $min_char = $max_char = $read_extra = null; 00567 include( $cache ); 00568 $this->UnicodeMap = $umap; 00569 $this->UTF8Map = $utf8map; 00570 $this->CodeMap = $cmap; 00571 $this->UTF8CodeMap = $utf8cmap; 00572 $this->MinCharValue = $min_char; 00573 $this->MaxCharValue = $max_char; 00574 $this->ReadExtraMap = $read_extra; 00575 00576 if ( isset( $eZCodePageCacheCodeDate ) and 00577 $eZCodePageCacheCodeDate == self::CACHE_CODE_DATE ) 00578 { 00579 $this->Valid = true; 00580 return; 00581 } 00582 } 00583 } 00584 00585 $utf8_codec = eZUTF8Codec::instance(); 00586 00587 $this->UnicodeMap = array(); 00588 $this->UTF8Map = array(); 00589 $this->CodeMap = array(); 00590 $this->UTF8CodeMap = array(); 00591 $this->ReadExtraMap = array(); 00592 for ( $i = 0; $i < 32; ++$i ) 00593 { 00594 $code = $i; 00595 $ucode = $i; 00596 $utf8_code = $utf8_codec->toUtf8( $ucode ); 00597 $this->UnicodeMap[$code] = $ucode; 00598 $this->UTF8Map[$code] = $utf8_code; 00599 $this->CodeMap[$ucode] = $code; 00600 $this->UTF8CodeMap[$utf8_code] = $code; 00601 } 00602 $this->MinCharValue = 0; 00603 $this->MaxCharValue = 31; 00604 00605 $lines = file( $file ); 00606 reset( $lines ); 00607 while ( ( $key = key( $lines ) ) !== null ) 00608 { 00609 if ( preg_match( "/^#/", $lines[$key] ) ) 00610 { 00611 next( $lines ); 00612 continue; 00613 } 00614 $line = trim( $lines[$key] ); 00615 $items = explode( "\t", $line ); 00616 if ( count( $items ) == 3 ) 00617 { 00618 $code = false; 00619 $ucode = false; 00620 $desc = $items[2]; 00621 if ( preg_match( "/(=|0x)([0-9a-fA-F]{4})/", $items[0], $args ) ) 00622 { 00623 $code = hexdec( $args[2] ); 00624 // eZDebug::writeNotice( $args, "doublebyte" ); 00625 } 00626 else if ( preg_match( "/(=|0x)([0-9a-fA-F]{2})/", $items[0], $args ) ) 00627 { 00628 $code = hexdec( $args[2] ); 00629 // eZDebug::writeNotice( $args, "singlebyte" ); 00630 } 00631 if ( preg_match( "/(U\+|0x)([0-9a-fA-F]{4})/", $items[1], $args ) ) 00632 { 00633 $ucode = hexdec( $args[2] ); 00634 } 00635 00636 if ( $code !== false and 00637 $ucode !== false ) 00638 { 00639 $utf8_code = $utf8_codec->toUtf8( $ucode ); 00640 $this->UnicodeMap[$code] = $ucode; 00641 $this->UTF8Map[$code] = $utf8_code; 00642 $this->CodeMap[$ucode] = $code; 00643 $this->UTF8CodeMap[$utf8_code] = $code; 00644 $this->MinCharValue = min( $this->MinCharValue, $code ); 00645 $this->MaxCharValue = max( $this->MaxCharValue, $code ); 00646 } 00647 else if ( $code !== false ) 00648 { 00649 $this->ReadExtraMap[$code] = true; 00650 } 00651 } 00652 next( $lines ); 00653 } 00654 00655 $this->Valid = true; 00656 $this->MinCharValue = min( $this->MinCharValue, $code ); 00657 $this->MaxCharValue = max( $this->MaxCharValue, $code ); 00658 00659 if ( $use_cache ) 00660 { 00661 // If there is no setting; do nothing: 00662 if ( $permissionArray === false ) 00663 { 00664 if ( !isset ( $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] ) ) 00665 { 00666 $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] = array(); 00667 } 00668 00669 // The array already exists; we simply append to it. 00670 $GLOBALS['EZCODEPAGECACHEOBJECTLIST'][] = $this; 00671 } 00672 // Else: a permission setting exists: 00673 else 00674 { 00675 // Store the cache object with the correct permission setting. 00676 $this->storeCacheObject( $cache, $permissionArray ); 00677 00678 // Check if the global array for codepage cache objects exist: 00679 } 00680 } 00681 } 00682 00683 /*! 00684 \return the charset code which is in use. This may not be the charset that was 00685 requested due to aliases. 00686 \sa requestedCharsetCode 00687 */ 00688 function charsetCode() 00689 { 00690 return $this->CharsetCode; 00691 } 00692 00693 /*! 00694 \return the charset code which was requested, may differ from charsetCode() 00695 */ 00696 function requestedCharsetCode() 00697 { 00698 return $this->RequestedCharsetCode; 00699 } 00700 00701 /*! 00702 \return the lowest character value used in the mapping table. 00703 */ 00704 function minCharValue() 00705 { 00706 return $this->MinCharValue; 00707 } 00708 00709 /*! 00710 \return the largest character value used in the mapping table. 00711 */ 00712 function maxCharValue() 00713 { 00714 return $this->MaxCharValue; 00715 } 00716 00717 /*! 00718 Returns true if the codepage is valid for use. 00719 */ 00720 function isValid() 00721 { 00722 return $this->Valid; 00723 } 00724 00725 /*! 00726 Returns the only instance of the codepage for $charset_code. 00727 */ 00728 static function instance( $charset_code, $use_cache = true ) 00729 { 00730 if ( empty( $GLOBALS["eZCodePage-$charset_code"] ) ) 00731 { 00732 $GLOBALS["eZCodePage-$charset_code"] = new eZCodePage( $charset_code, $use_cache ); 00733 } 00734 return $GLOBALS["eZCodePage-$charset_code"]; 00735 } 00736 00737 /*! 00738 \private 00739 00740 Gets the permission setting for codepage files & returns it. 00741 If the permission setting doesnt exists: returns false. 00742 */ 00743 static function permissionSetting() 00744 { 00745 // eZDebug::writeDebug( "permissionSetting was called..." ); 00746 00747 if ( isset( $GLOBALS['EZCODEPAGEPERMISSIONS'] ) ) 00748 { 00749 return $GLOBALS['EZCODEPAGEPERMISSIONS']; 00750 } 00751 else 00752 { 00753 return false; 00754 } 00755 } 00756 00757 /*! 00758 \private 00759 00760 Sets the permission setting for codepagefiles. 00761 */ 00762 static function setPermissionSetting( $permissionArray ) 00763 { 00764 // eZDebug::writeDebug( "setPermissionSetting was called..." ); 00765 00766 $GLOBALS['EZCODEPAGEPERMISSIONS'] = $permissionArray; 00767 00768 if ( $permissionArray !== false ) 00769 { 00770 eZCodePage::flushCacheObject(); 00771 } 00772 } 00773 00774 /*! 00775 \private 00776 */ 00777 static function flushCacheObject() 00778 { 00779 // eZDebug::writeDebug("flushCacheObject is called... ",""); 00780 if ( !isset( $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] ) ) 00781 { 00782 return false; 00783 } 00784 00785 // Grab the permission setting for codepage cache files. 00786 $permissionArray = self::permissionSetting(); 00787 00788 // If we were unable to extract the permission setting: 00789 if ( $permissionArray === false ) 00790 { 00791 // eZDebug::writeDebug( "permissionSetting: unable to grab permission setting from global array..." ); 00792 00793 // Bail with false. 00794 return false; 00795 } 00796 // Else: permission setting is available: 00797 else 00798 { 00799 // eZDebug::writeDebug( "permissionSetting: grabbed permission setting from global array..." ); 00800 00801 // For all the cache objects: 00802 foreach( array_keys( $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] ) as $codePageKey ) 00803 { 00804 $codePage = $GLOBALS['EZCODEPAGECACHEOBJECTLIST'][$codePageKey]; 00805 00806 $filename = $codePage->cacheFilepath(); 00807 00808 // Store __FIX_ME__ 00809 $codePage->storeCacheObject( $filename, $permissionArray ); 00810 } 00811 00812 // 00813 unset( $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] ); 00814 } 00815 } 00816 00817 /// \privatesection 00818 /// The charset code which was requested, may differ from $CharsetCode 00819 public $RequestedCharsetCode; 00820 /// The read charset code, may differ from $RequestedCharsetCode 00821 public $CharsetCode; 00822 /// Encoding scheme for current charset, for instance utf-8, singlebyte, multibyte 00823 public $CharsetEncodingScheme; 00824 /// Maps normal codes to unicode 00825 public $UnicodeMap; 00826 /// Maps normal codes to utf8 00827 public $UTF8Map; 00828 /// Maps unicode to normal codes 00829 public $CodeMap; 00830 /// Maps utf8 to normal codes 00831 public $UTF8CodeMap; 00832 /// The minimum key value for the mapping tables 00833 public $MinCharValue; 00834 /// The maximum key value for the mapping tables 00835 public $MaxCharValue; 00836 /// Whether the codepage is valid or not 00837 public $Valid; 00838 /// The character to use when an alternative doesn't exist 00839 public $SubstituteChar; 00840 } 00841 00842 // Checks if index.php or any other script has set any codepage permissions 00843 if ( isset( $GLOBALS['EZCODEPAGEPERMISSIONS'] ) and 00844 $GLOBALS['EZCODEPAGEPERMISSIONS'] !== false ) 00845 { 00846 eZCodePage::flushCacheObject(); 00847 } 00848 00849 ?>