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;
     $cache_dir = "var/cache/codepages/";
     $cache_filename = md5($this->InputCharsetCode . $this->OutputCharsetCode);
     $cache = $cache_dir . $cache_filename . ".php";
     if (!eZCodePage::exists($this->InputCharsetCode)) {
         $input_file = eZCodePage::fileName($this->InputCharsetCode);
         eZDebug::writeWarning("Couldn't load input codepage file {$input_file}", "eZCodePageMapper");
         return false;
     }
     if (!eZCodePage::exists($this->OutputCharsetCode)) {
         $output_file = eZCodePage::fileName($this->OutputCharsetCode);
         eZDebug::writeWarning("Couldn't load output codepage file {$output_file}", "eZCodePageMapper");
         return false;
     }
     $this->Valid = false;
     if (file_exists($cache) and $use_cache) {
         $cache_m = filemtime($cache);
         if (eZCodePage::fileModification($this->InputCharsetCode) <= $cache_m and eZCodePage::fileModification($this->OutputCharsetCode) <= $cache_m) {
             unset($eZCodePageMapperCacheCodeDate);
             $in_out_map =& $this->InputOutputMap;
             $out_in_map =& $this->OutputInputMap;
             eZDebug::writeDebug('loading cache from: ' . $cache, __METHOD__);
             include $cache;
             if (isset($eZCodePageMapperCacheCodeDate) or $eZCodePageMapperCacheCodeDate == self::CACHE_CODE_DATE) {
                 $this->Valid = true;
                 return;
             }
         }
     }
     $this->InputOutputMap = array();
     $this->OutputInputMap = array();
     $input_codepage = eZCodePage::instance($this->InputCharsetCode);
     $output_codepage = eZCodePage::instance($this->OutputCharsetCode);
     if (!$input_codepage->isValid()) {
         eZDebug::writeError("Input codepage for " . $this->InputCharsetCode . " is not valid", "eZCodePageMapper");
         return false;
     }
     if (!$output_codepage->isValid()) {
         eZDebug::writeError("Output codepage for " . $this->OutputCharsetCode . " is not valid", "eZCodePageMapper");
         return false;
     }
     $min = max($input_codepage->minCharValue(), $output_codepage->minCharValue());
     $max = min($input_codepage->maxCharValue(), $output_codepage->maxCharValue());
     for ($i = $min; $i <= $max; ++$i) {
         $code = $i;
         $unicode = $input_codepage->codeToUnicode($code);
         if ($unicode !== null) {
             $output_code = $output_codepage->unicodeToCode($unicode);
             if ($output_code !== null) {
                 $this->InputOutputMap[$code] = $output_code;
                 $this->OutputInputMap[$output_code] = $code;
             }
         }
     }
 }
Esempio n. 2
0
 function fileModification($charset_code)
 {
     $file = eZCodePage::fileName($charset_code);
     if (!file_exists($file)) {
         return false;
     }
     return filemtime($file);
 }