function fromUnicode($str)
 {
     $ustr = "";
     if (!is_string($str) or !$this->isValid()) {
         return $ustr;
     }
     $utf8_codec = eZUTF8Codec::instance();
     $len = strlen($str);
     for ($i = 0; $i < $len;) {
         $char_code = $utf8_codec->fromUtf8($str, $i, $l);
         if ($char_code !== false) {
             $i += $l;
             $ustr .= chr($this->CodePage->unicodeToChar($char_code));
         } else {
             ++$i;
         }
     }
     return $ustr;
 }
Exemplo n.º 2
0
 static function fetchAlphabet()
 {
     $contentINI = eZINI::instance('content.ini');
     $alphabetRangeList = $contentINI->hasVariable('AlphabeticalFilterSettings', 'AlphabetList') ? $contentINI->variable('AlphabeticalFilterSettings', 'AlphabetList') : array();
     $alphabetFromArray = $contentINI->hasVariable('AlphabeticalFilterSettings', 'ContentFilterList') ? $contentINI->variable('AlphabeticalFilterSettings', 'ContentFilterList') : array('default');
     // If alphabet list is empty
     if (count($alphabetFromArray) == 0) {
         return false;
     }
     $alphabetRangeList = array_merge($alphabetRangeList, array('default' => '97-122'));
     $alphabet = array();
     foreach ($alphabetFromArray as $alphabetFrom) {
         // If $alphabetFrom exists in range array $alphabetRangeList
         if (isset($alphabetRangeList[$alphabetFrom])) {
             $lettersArray = explode(',', $alphabetRangeList[$alphabetFrom]);
             foreach ($lettersArray as $letter) {
                 $rangeArray = explode('-', $letter);
                 if (isset($rangeArray[1])) {
                     $alphabet = array_merge($alphabet, range(trim($rangeArray[0]), trim($rangeArray[1])));
                 } else {
                     $alphabet = array_merge($alphabet, array(trim($letter)));
                 }
             }
         }
     }
     // Get alphabet by default (eng-GB)
     if (count($alphabet) == 0) {
         $rangeArray = explode('-', $alphabetRangeList['default']);
         $alphabet = range($rangeArray[0], $rangeArray[1]);
     }
     $resAlphabet = array();
     $i18nINI = eZINI::instance('i18n.ini');
     $charset = $i18nINI->variable('CharacterSettings', 'Charset');
     $codec = eZTextCodec::instance('utf-8', $charset);
     $utf8_codec = eZUTF8Codec::instance();
     // Convert all letters of alphabet from unicode to utf-8 and from utf-8 to current locale
     foreach ($alphabet as $item) {
         $utf8Letter = $utf8_codec->toUtf8($item);
         $resAlphabet[] = $codec ? $codec->convertString($utf8Letter) : $utf8Letter;
     }
     return $resAlphabet;
 }
 static function strlen($str)
 {
     $table = eZUTF8Codec::utf8LengthTable();
     $len = strlen($str);
     $strlen = 0;
     for ($i = 0; $i < $len;) {
         $char = ord($str[$i]);
         $char_len = $table[$char >> 2 & 0x3f];
         $i += $char_len;
         ++$strlen;
     }
     return $strlen;
 }
 function strlenUTF8($str)
 {
     $utf8_codec = eZUTF8Codec::instance();
     return $utf8_codec->strlen($str);
 }
Exemplo n.º 5
0
 function load($use_cache = true)
 {
     // temporarely hide the cache display problem
     // http://ez.no/community/bugs/char_transform_cache_file_is_not_valid_php
     //$use_cache = false;
     $file = "share/codepages/" . $this->CharsetCode;
     //         eZDebug::writeDebug( "ezcodepage::load was called for $file..." );
     $permissionArray = self::permissionSetting();
     if ($permissionArray !== false) {
         $cache_dir = $permissionArray['var_directory'] . "/codepages/";
         $cache_filename = md5($this->CharsetCode);
         $cache = $cache_dir . $cache_filename . ".php";
     } else {
         $cache = false;
     }
     if (!file_exists($file)) {
         eZDebug::writeWarning("Couldn't load codepage file {$file}", "eZCodePage");
         return;
     }
     $file_m = filemtime($file);
     $this->Valid = false;
     if (isset($GLOBALS['eZSiteBasics'])) {
         $siteBasics = $GLOBALS['eZSiteBasics'];
         if (isset($siteBasics['no-cache-adviced']) and $siteBasics['no-cache-adviced']) {
             $use_cache = false;
         }
     }
     if ($cache && file_exists($cache) and $use_cache) {
         $cache_m = filemtime($cache);
         if ($file_m <= $cache_m) {
             unset($eZCodePageCacheCodeDate);
             $umap = $utf8map = $cmap = $utf8cmap = $min_char = $max_char = $read_extra = null;
             include $cache;
             $this->UnicodeMap = $umap;
             $this->UTF8Map = $utf8map;
             $this->CodeMap = $cmap;
             $this->UTF8CodeMap = $utf8cmap;
             $this->MinCharValue = $min_char;
             $this->MaxCharValue = $max_char;
             $this->ReadExtraMap = $read_extra;
             if (isset($eZCodePageCacheCodeDate) and $eZCodePageCacheCodeDate == self::CACHE_CODE_DATE) {
                 $this->Valid = true;
                 return;
             }
         }
     }
     $utf8_codec = eZUTF8Codec::instance();
     $this->UnicodeMap = array();
     $this->UTF8Map = array();
     $this->CodeMap = array();
     $this->UTF8CodeMap = array();
     $this->ReadExtraMap = array();
     for ($i = 0; $i < 32; ++$i) {
         $code = $i;
         $ucode = $i;
         $utf8_code = $utf8_codec->toUtf8($ucode);
         $this->UnicodeMap[$code] = $ucode;
         $this->UTF8Map[$code] = $utf8_code;
         $this->CodeMap[$ucode] = $code;
         $this->UTF8CodeMap[$utf8_code] = $code;
     }
     $this->MinCharValue = 0;
     $this->MaxCharValue = 31;
     $lines = file($file);
     reset($lines);
     while (($key = key($lines)) !== null) {
         if (preg_match("/^#/", $lines[$key])) {
             next($lines);
             continue;
         }
         $line = trim($lines[$key]);
         $items = explode("\t", $line);
         if (count($items) == 3) {
             $code = false;
             $ucode = false;
             $desc = $items[2];
             if (preg_match("/(=|0x)([0-9a-fA-F]{4})/", $items[0], $args)) {
                 $code = hexdec($args[2]);
                 //                    eZDebug::writeNotice( $args, "doublebyte" );
             } else {
                 if (preg_match("/(=|0x)([0-9a-fA-F]{2})/", $items[0], $args)) {
                     $code = hexdec($args[2]);
                     //                    eZDebug::writeNotice( $args, "singlebyte" );
                 }
             }
             if (preg_match("/(U\\+|0x)([0-9a-fA-F]{4})/", $items[1], $args)) {
                 $ucode = hexdec($args[2]);
             }
             if ($code !== false and $ucode !== false) {
                 $utf8_code = $utf8_codec->toUtf8($ucode);
                 $this->UnicodeMap[$code] = $ucode;
                 $this->UTF8Map[$code] = $utf8_code;
                 $this->CodeMap[$ucode] = $code;
                 $this->UTF8CodeMap[$utf8_code] = $code;
                 $this->MinCharValue = min($this->MinCharValue, $code);
                 $this->MaxCharValue = max($this->MaxCharValue, $code);
             } else {
                 if ($code !== false) {
                     $this->ReadExtraMap[$code] = true;
                 }
             }
         }
         next($lines);
     }
     $this->Valid = true;
     $this->MinCharValue = min($this->MinCharValue, $code);
     $this->MaxCharValue = max($this->MaxCharValue, $code);
     if ($use_cache) {
         // If there is no setting; do nothing:
         if ($permissionArray === false) {
             if (!isset($GLOBALS['EZCODEPAGECACHEOBJECTLIST'])) {
                 $GLOBALS['EZCODEPAGECACHEOBJECTLIST'] = array();
             }
             // The array already exists; we simply append to it.
             $GLOBALS['EZCODEPAGECACHEOBJECTLIST'][] = $this;
         } else {
             // Store the cache object with the correct permission setting.
             $this->storeCacheObject($cache, $permissionArray);
             // Check if the global array for codepage cache objects exist:
         }
     }
 }