Esempio n. 1
0
 function eZCodePage($charset_code, $use_cache = true)
 {
     $this->RequestedCharsetCode = $charset_code;
     $this->CharsetCode = eZCharsetInfo::realCharsetCode($charset_code);
     $this->CharsetEncodingScheme = eZCharsetInfo::characterEncodingScheme($charset_code);
     $this->Valid = false;
     $this->SubstituteChar = 63;
     // the ? character
     $this->MinCharValue = 0;
     $this->MaxCharValue = 0;
     $this->load($use_cache);
 }
 /**
  * Returns a shared instance of the eZTextCodec pr the
  * $inputCharsetCode and $outputCharsetCode params.
  *
  * @param string|false $inputCharsetCode Uses {@link eZTextCodec::internalCharset()} if false
  * @param string|false $outputCharsetCode Uses {@link eZTextCodec::internalCharset()} if false
  * @param bool $alwaysReturn
  * @return eZTextCodec|null Returns null if $alwaysReturn is false and text codec is not needed for
  *         current $inputCharsetCode and $outputCharsetCode.
  */
 static function instance($inputCharsetCode, $outputCharsetCode = false, $alwaysReturn = true)
 {
     if ($inputCharsetCode === false or $outputCharsetCode === false) {
         if (isset($GLOBALS['eZTextCodecInternalCharsetReal'])) {
             $internalCharset = $GLOBALS['eZTextCodecInternalCharsetReal'];
         } else {
             $internalCharset = eZTextCodec::internalCharset();
         }
     }
     if ($inputCharsetCode === false) {
         $realInputCharsetCode = $inputCharsetCode = $internalCharset;
     } else {
         $realInputCharsetCode = eZCharsetInfo::realCharsetCode($inputCharsetCode);
     }
     if ($outputCharsetCode === false) {
         $realOutputCharsetCode = $outputCharsetCode = $internalCharset;
     } else {
         $realOutputCharsetCode = eZCharsetInfo::realCharsetCode($outputCharsetCode);
     }
     $check =& $GLOBALS["eZTextCodecCharsetCheck"]["{$realInputCharsetCode}-{$realOutputCharsetCode}"];
     if (!$alwaysReturn and isset($check) and !$check) {
         $check = null;
         return $check;
     }
     if (isset($check) and is_object($check)) {
         return $check;
     }
     if (!$realInputCharsetCode) {
         $realInputCharsetCode = eZCharsetInfo::realCharsetCode($inputCharsetCode);
     }
     if (!$realOutputCharsetCode) {
         $realOutputCharsetCode = eZCharsetInfo::realCharsetCode($outputCharsetCode);
     }
     $inputEncoding = eZCharsetInfo::characterEncodingScheme($realInputCharsetCode, true);
     $outputEncoding = eZCharsetInfo::characterEncodingScheme($realOutputCharsetCode, true);
     if (!$alwaysReturn and $inputEncoding == 'singlebyte' and $inputEncoding == $outputEncoding and $realInputCharsetCode == $realOutputCharsetCode) {
         $check = null;
         return $check;
     }
     $globalsKey = "eZTextCodec-{$realInputCharsetCode}-{$realOutputCharsetCode}";
     if (!isset($GLOBALS[$globalsKey]) || !$GLOBALS[$globalsKey] instanceof eZTextCodec) {
         $GLOBALS[$globalsKey] = new eZTextCodec($inputCharsetCode, $outputCharsetCode, $realInputCharsetCode, $realOutputCharsetCode, $inputEncoding, $outputEncoding);
     }
     $check = $GLOBALS[$globalsKey];
     return $GLOBALS[$globalsKey];
 }