Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcodepagemapper.php
Go to the documentation of this file.
1 <?php
18 class eZCodePageMapper
19 {
23 public $RequestedInputCharsetCode;
24 public $InputCharsetCode;
28 public $RequestedOutputCharsetCode;
29 public $OutputCharsetCode;
30 public $Valid;
31 public $InputOutputMap;
32 public $OutputInputMap;
33 public $SubstituteOutputChar;
34 public $SubstituteInputChar;
35 public $SubstituteCharValue;
36 const CACHE_CODE_DATE = 1026316422;
37
45 public function __construct( $input_charset_code, $output_charset_code, $use_cache = true )
46 {
47 $this->RequestedInputCharsetCode = $input_charset_code;
48 $this->InputCharsetCode = eZCharsetInfo::realCharsetCode( $input_charset_code );
49 $this->RequestedOutputCharsetCode = $output_charset_code;
50 $this->OutputCharsetCode = eZCharsetInfo::realCharsetCode( $output_charset_code );
51 $this->Valid = false;
52 $this->load( $use_cache );
53 $this->setSubstituteCharacter( 63 ); // ?
54 }
55
56 function isValid()
57 {
58 return $this->Valid;
59 }
60
61 function &mapInputCode( $in_code )
62 {
63 if ( isset( $this->InputOutputMap[$in_code] ) )
64 return $this->InputOutputMap[$in_code];
65 $retValue = null;
66 return $retValue;
67 }
68
69 function &mapOutputCode( $out_code )
70 {
71 if ( isset( $this->OutputInputMap[$out_code] ) )
72 return $this->OutputInputMap[$out_code];
73 $retValue = null;
74 return $retValue;
75 }
76
77 function mapInputChar( $in_char )
78 {
79 $in_code = ord( $in_char );
80 if ( isset( $this->InputOutputMap[$in_code] ) )
81 return chr( $this->InputOutputMap[$in_code] );
82 return $this->SubstituteOutputChar;
83 }
84
85 function mapOutputChar( $out_char )
86 {
87 $out_code = ord( $out_char );
88 if ( isset( $this->OutputInputMap[$out_code] ) )
89 return chr( $this->OutputInputMap[$out_code] );
90 return $this->SubstituteInputChar;
91 }
92
93 function substituteCharacterFor( $char )
94 {
95 }
96
97 function substituteCharacter()
98 {
99 return $this->SubstituteCharValue;
100 }
101
102 function convertString( $str )
103 {
104 $out = "";
105 $len = strlen( $str );
106 for ( $i = 0; $i < $len; ++$i )
107 {
108 $char = $str[$i];
109 $out .= $this->mapInputChar( $char );
110 }
111 return $out;
112 }
113
114 function strlen( $str )
115 {
116 return strlen( $str );
117 }
118
119 function strpos( $haystack, $needle, $offset = 0 )
120 {
121 return strpos( $haystack, $needle, $offset );
122 }
123
124 function strrpos( $haystack, $needle )
125 {
126 return strrpos( $haystack, $needle );
127 }
128
129 function substr( $str, $start, $length )
130 {
131 return substr( $str, $start, $length );
132 }
133
134 function setSubstituteCharacter( $char_code )
135 {
136 $this->SubstituteCharValue = $char_code;
137 $input_codepage = eZCodePage::instance( $this->InputCharsetCode );
138 $output_codepage = eZCodePage::instance( $this->OutputCharsetCode );
139 if ( !$input_codepage->isValid() )
140 {
141 eZDebug::writeError( "Input codepage for " . $this->InputCharsetCode . " is not valid", "eZCodePageMapper" );
142 return false;
143 }
144 if ( !$output_codepage->isValid() )
145 {
146 eZDebug::writeError( "Output codepage for " . $this->OutputCharsetCode . " is not valid", "eZCodePageMapper" );
147 return false;
148 }
149 $this->SubstituteInputChar = chr( $input_codepage->unicodeToCode( $char_code ) );
150 $this->SubstituteOutputChar = chr( $output_codepage->unicodeToCode( $char_code ) );
151 }
152
153 function load( $use_cache = true )
154 {
155 // temporarely hide the cache display problem
156 // http://ez.no/community/bugs/char_transform_cache_file_is_not_valid_php
157 //$use_cache = false;
158 $cache_dir = "var/cache/codepages/";
159 $cache_filename = md5( $this->InputCharsetCode . $this->OutputCharsetCode );
160 $cache = $cache_dir . $cache_filename . ".php";
161
162 if ( !eZCodePage::exists( $this->InputCharsetCode ) )
163 {
164 $input_file = eZCodePage::fileName( $this->InputCharsetCode );
165 eZDebug::writeWarning( "Couldn't load input codepage file $input_file", "eZCodePageMapper" );
166 return false;
167 }
168 if ( !eZCodePage::exists( $this->OutputCharsetCode ) )
169 {
170 $output_file = eZCodePage::fileName( $this->OutputCharsetCode );
171 eZDebug::writeWarning( "Couldn't load output codepage file $output_file", "eZCodePageMapper" );
172 return false;
173 }
174
175 $this->Valid = false;
176 if ( file_exists( $cache ) and $use_cache )
177 {
178 $cache_m = filemtime( $cache );
179 if ( eZCodePage::fileModification( $this->InputCharsetCode ) <= $cache_m and
180 eZCodePage::fileModification( $this->OutputCharsetCode ) <= $cache_m )
181 {
182 unset( $eZCodePageMapperCacheCodeDate );
183 $in_out_map =& $this->InputOutputMap;
184 $out_in_map =& $this->OutputInputMap;
185 eZDebug::writeDebug( 'loading cache from: ' . $cache, __METHOD__ );
186 include( $cache );
187 if ( isset( $eZCodePageMapperCacheCodeDate ) or
188 $eZCodePageMapperCacheCodeDate == self::CACHE_CODE_DATE )
189 {
190 $this->Valid = true;
191 return;
192 }
193 }
194 }
195
196 $this->InputOutputMap = array();
197 $this->OutputInputMap = array();
198
199 $input_codepage = eZCodePage::instance( $this->InputCharsetCode );
200 $output_codepage = eZCodePage::instance( $this->OutputCharsetCode );
201
202 if ( !$input_codepage->isValid() )
203 {
204 eZDebug::writeError( "Input codepage for " . $this->InputCharsetCode . " is not valid", "eZCodePageMapper" );
205 return false;
206 }
207 if ( !$output_codepage->isValid() )
208 {
209 eZDebug::writeError( "Output codepage for " . $this->OutputCharsetCode . " is not valid", "eZCodePageMapper" );
210 return false;
211 }
212
213 $min = max( $input_codepage->minCharValue(),
214 $output_codepage->minCharValue() );
215 $max = min( $input_codepage->maxCharValue(),
216 $output_codepage->maxCharValue() );
217
218 for ( $i = $min; $i <= $max; ++$i )
219 {
220 $code = $i;
221 $unicode = $input_codepage->codeToUnicode( $code );
222 if ( $unicode !== null )
223 {
224 $output_code = $output_codepage->unicodeToCode( $unicode );
225 if ( $output_code !== null )
226 {
227 $this->InputOutputMap[$code] = $output_code;
228 $this->OutputInputMap[$output_code] = $code;
229 }
230 }
231 }
232 }
233
243 static function instance( $input_charset_code, $output_charset_code, $use_cache = true )
244 {
245 $globalsKey = "eZCodePageMapper-$input_charset_code-$output_charset_code";
246
247 if ( !isset( $GLOBALS[$globalsKey] ) ||
248 !( $GLOBALS[$globalsKey] instanceof eZCodePageMapper ) )
249 {
250 $GLOBALS[$globalsKey] = new eZCodePageMapper( $input_charset_code, $output_charset_code, $use_cache );
251 }
252
253 return $GLOBALS[$globalsKey];
254 }
255
256 }
257
258 ?>
$i
$i
Definition: admin/adlist.php:91
eZCharsetInfo\realCharsetCode
static realCharsetCode( $charsetCode)
Definition: ezcharsetinfo.php:187
eZCodePageMapper
The class eZCodePageMapper does.
Definition: ezcodepagemapper.php:19
eZCodePageMapper\strrpos
strrpos( $haystack, $needle)
Definition: ezcodepagemapper.php:124
eZCodePageMapper\$OutputInputMap
$OutputInputMap
Definition: ezcodepagemapper.php:32
eZCodePageMapper\strpos
strpos( $haystack, $needle, $offset=0)
Definition: ezcodepagemapper.php:119
eZCodePageMapper\$SubstituteCharValue
$SubstituteCharValue
Definition: ezcodepagemapper.php:35
eZCodePageMapper\substr
substr( $str, $start, $length)
Definition: ezcodepagemapper.php:129
eZCodePageMapper\__construct
__construct( $input_charset_code, $output_charset_code, $use_cache=true)
Definition: ezcodepagemapper.php:45
eZCodePageMapper\$InputCharsetCode
$InputCharsetCode
Definition: ezcodepagemapper.php:24
eZCodePageMapper\substituteCharacterFor
substituteCharacterFor( $char)
Definition: ezcodepagemapper.php:93
eZCodePageMapper\instance
static instance( $input_charset_code, $output_charset_code, $use_cache=true)
Definition: ezcodepagemapper.php:243
eZCodePageMapper\$RequestedOutputCharsetCode
$RequestedOutputCharsetCode
Definition: ezcodepagemapper.php:28
eZCodePageMapper\$RequestedInputCharsetCode
$RequestedInputCharsetCode
Definition: ezcodepagemapper.php:23
eZCodePageMapper\$SubstituteOutputChar
$SubstituteOutputChar
Definition: ezcodepagemapper.php:33
eZCodePageMapper\isValid
isValid()
Definition: ezcodepagemapper.php:56
eZCodePageMapper\$OutputCharsetCode
$OutputCharsetCode
Definition: ezcodepagemapper.php:29
eZCodePageMapper\substituteCharacter
substituteCharacter()
Definition: ezcodepagemapper.php:97
eZCodePageMapper\$SubstituteInputChar
$SubstituteInputChar
Definition: ezcodepagemapper.php:34
eZCodePageMapper\CACHE_CODE_DATE
const CACHE_CODE_DATE
Definition: ezcodepagemapper.php:36
eZCodePageMapper\convertString
convertString( $str)
Definition: ezcodepagemapper.php:102
eZCodePageMapper\$InputOutputMap
$InputOutputMap
Definition: ezcodepagemapper.php:31
eZCodePageMapper\mapInputCode
& mapInputCode( $in_code)
Definition: ezcodepagemapper.php:61
eZCodePageMapper\mapOutputChar
mapOutputChar( $out_char)
Definition: ezcodepagemapper.php:85
eZCodePageMapper\load
load( $use_cache=true)
Definition: ezcodepagemapper.php:153
eZCodePageMapper\setSubstituteCharacter
setSubstituteCharacter( $char_code)
Definition: ezcodepagemapper.php:134
eZCodePageMapper\mapOutputCode
& mapOutputCode( $out_code)
Definition: ezcodepagemapper.php:69
eZCodePageMapper\mapInputChar
mapInputChar( $in_char)
Definition: ezcodepagemapper.php:77
eZCodePageMapper\$Valid
$Valid
Definition: ezcodepagemapper.php:30
eZCodePageMapper\strlen
strlen( $str)
Definition: ezcodepagemapper.php:114
eZCodePage\fileName
static fileName( $charset_code)
Definition: ezcodepage.php:346
eZCodePage\instance
static instance( $charset_code, $use_cache=true)
Definition: ezcodepage.php:714
eZCodePage\fileModification
fileModification( $charset_code)
Definition: ezcodepage.php:366
eZCodePage\exists
static exists( $charset_code)
Definition: ezcodepage.php:336
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:589
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:503
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$str
$str
Definition: ezarticle/modules/content.php:30
$offset
$offset
Definition: ezstats/admin/cron.php:51
$haystack
$haystack
Definition: subscriptionlist.php:100
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.