/** * @param string $encoding optional * @return string */ function GetText($encoding = null) { if ($encoding == null) { $encoding = $this->TextCodePage; } $this->DefaultCodePage = strtolower($this->DefaultCodePage); $encoding = strtolower($encoding); if (array_key_exists($encoding, $this->_text)) { return $this->_text[$encoding]; } if ($this->DefaultCodePage == CPAGE_UTF8 && $encoding == CPAGE_UTF7_Imap) { $this->_text[$encoding] = ConvertUtils::Utf8to7($this->_text[$this->DefaultCodePage]); return $this->_text[$encoding]; } if ($this->DefaultCodePage == CPAGE_UTF7_Imap && $encoding == CPAGE_UTF8) { $this->_text[$encoding] = ConvertUtils::Utf7to8($this->_text[$this->DefaultCodePage]); return $this->_text[$encoding]; } if (extension_loaded('xml')) { // convert here if ($this->DefaultCodePage == CPAGE_ISO8859_1 && $encoding == CPAGE_UTF8) { $this->_text[$encoding] = utf8_encode($this->_text[$this->DefaultCodePage]); return $this->_text[$encoding]; } if ($this->DefaultCodePage == CPAGE_UTF8 && $encoding == CPAGE_ISO8859_1) { $this->_text[$encoding] = utf8_decode($this->_text[$this->DefaultCodePage]); return $this->_text[$encoding]; } } $cyrCodePages = array(CPAGE_KOI8R => 'k', CPAGE_WINDOWS_1251 => 'w', CPAGE_ISO8859_5 => 'i', CPAGE_IBM866 => 'd', CPAGE_MAC_CYRILLIC => 'm'); if (array_key_exists($this->DefaultCodePage, $cyrCodePages) && array_key_exists($encoding, $cyrCodePages)) { $this->_text[$encoding] = convert_cyr_string($this->_text[$this->DefaultCodePage], $cyrCodePages[$this->DefaultCodePage], $cyrCodePages[$encoding]); return $this->_text[$encoding]; } if (function_exists('iconv') && USE_ICONV && $this->DefaultCodePage != CPAGE_UTF7_Imap) { return ConvertUtils::ClassIconv($this->DefaultCodePage, $encoding, $this->_text[$this->DefaultCodePage]); } if (function_exists('mb_convert_encoding') && USE_MBSTRING) { return ConvertUtils::ClassMb_convert_encoding($this->DefaultCodePage, $encoding, $this->_text[$this->DefaultCodePage]); } if ($encoding == CPAGE_UTF8) { return $this->GetTextAsUtf8(); } if (!array_key_exists(CPAGE_UTF8, $this->_text)) { $this->GetTextAsUtf8(); } if (array_key_exists(CPAGE_UTF8, $this->_text)) { $utf8MappingList =& $this->GetUtf8MappingList(); if (in_array($encoding, $utf8MappingList)) { require_once WM_ROOTPATH . 'common/utf8encode/' . $encoding . '.php'; $this->_text[$encoding] = call_user_func('charset_encode_' . str_replace('-', '_', $encoding), $this->_text[CPAGE_UTF8]); return $this->_text[$encoding]; } } // undefined codepage, we'll return original string return $this->_text[$this->DefaultCodePage]; }