Index: trunk/extensions/wikihiero/wikihiero.body.php |
— | — | @@ -27,9 +27,6 @@ |
28 | 28 | die( 'Not an entry point' ); |
29 | 29 | } |
30 | 30 | |
31 | | -global $wh_phonemes, $wh_prefabs, $wh_files, $wh_phonemes, $wh_text_conv; |
32 | | -include( dirname( __FILE__ ) . '/wh_list.php' ); |
33 | | - |
34 | 31 | // D E F I N E S |
35 | 32 | define( "WH_TABLE_S", '<table class="mw-hiero-table">' ); |
36 | 33 | define( "WH_TABLE_E", '</table>' ); |
— | — | @@ -65,10 +62,27 @@ |
66 | 63 | |
67 | 64 | private $scale = 100; |
68 | 65 | |
| 66 | + private static $phonemes, $prefabs, $files, $textConv; |
| 67 | + |
69 | 68 | public function __construct( $scale = WH_SCALE_DEFAULT ) { |
| 69 | + self::loadData(); |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
| 73 | + * Loads |
| 74 | + */ |
| 75 | + private static function loadData() { |
| 76 | + if ( self::$phonemes ) { |
| 77 | + return; |
| 78 | + } |
| 79 | + require_once( dirname( __FILE__ ) . '/wh_list.php' ); |
| 80 | + self::$phonemes = $wh_phonemes; |
| 81 | + self::$prefabs = $wh_prefabs; |
| 82 | + self::$files = $wh_files; |
| 83 | + self::$textConv = $wh_text_conv; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
73 | 87 | * Render hieroglyph text |
74 | 88 | * |
75 | 89 | * @param $text string: text to convert |
— | — | @@ -117,9 +131,6 @@ |
118 | 132 | * @return string: a string to add to the stream |
119 | 133 | */ |
120 | 134 | private function renderGlyph( $glyph, $option = '' ) { |
121 | | - global $wh_phonemes; |
122 | | - global $wh_files; |
123 | | - |
124 | 135 | if ( $glyph == ".." ) { // Render void block |
125 | 136 | $width = WH_HEIGHT; |
126 | 137 | return "<table class=\"mw-hiero-table\" style=\"width: {$width}px;\"><tr><td> </td></tr></table>"; |
— | — | @@ -132,25 +143,25 @@ |
133 | 144 | elseif ( $glyph == '<' ) // Render open cartouche |
134 | 145 | { |
135 | 146 | $height = intval( WH_HEIGHT * $this->scale / 100 ); |
136 | | - $code = $wh_phonemes[$glyph]; |
| 147 | + $code = self::$phonemes[$glyph]; |
137 | 148 | return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
138 | 149 | } |
139 | 150 | elseif ( $glyph == '>' ) // Render close cartouche |
140 | 151 | { |
141 | 152 | $height = intval( WH_HEIGHT * $this->scale / 100 ); |
142 | | - $code = $wh_phonemes[$glyph]; |
| 153 | + $code = self::$phonemes[$glyph]; |
143 | 154 | return "<img src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' height='{$height}' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
144 | 155 | } |
145 | 156 | |
146 | | - if ( array_key_exists( $glyph, $wh_phonemes ) ) |
| 157 | + if ( array_key_exists( $glyph, self::$phonemes ) ) |
147 | 158 | { |
148 | | - $code = $wh_phonemes[$glyph]; |
149 | | - if ( array_key_exists( $code, $wh_files ) ) |
| 159 | + $code = self::$phonemes[$glyph]; |
| 160 | + if ( array_key_exists( $code, self::$files ) ) |
150 | 161 | return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$code}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( "{$code} [{$glyph}]" ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
151 | 162 | else |
152 | 163 | return "<font title='" . htmlspecialchars( $code ) . "'>" . htmlspecialchars( $glyph ) . "</font>"; |
153 | 164 | } |
154 | | - elseif ( array_key_exists( $glyph, $wh_files ) ) |
| 165 | + elseif ( array_key_exists( $glyph, self::$files ) ) |
155 | 166 | return "<img style='margin:" . WH_IMG_MARGIN . "px;' $option src='" . htmlspecialchars( WH_IMG_DIR . WH_IMG_PRE . "{$glyph}." . self::IMG_EXT ) . "' title='" . htmlspecialchars( $glyph ) . "' alt='" . htmlspecialchars( $glyph ) . "' />"; |
156 | 167 | else |
157 | 168 | return htmlspecialchars( $glyph ); |
— | — | @@ -165,11 +176,8 @@ |
166 | 177 | * @return size |
167 | 178 | */ |
168 | 179 | private function resizeGlyph( $item, $is_cartouche = false, $total = 0 ) { |
169 | | - global $wh_phonemes; |
170 | | - global $wh_files; |
171 | | - |
172 | | - if ( array_key_exists( $item, $wh_phonemes ) ) { |
173 | | - $glyph = $wh_phonemes[$item]; |
| 180 | + if ( array_key_exists( $item, self::$phonemes ) ) { |
| 181 | + $glyph = self::$phonemes[$item]; |
174 | 182 | } else { |
175 | 183 | $glyph = $item; |
176 | 184 | } |
— | — | @@ -179,8 +187,8 @@ |
180 | 188 | $margin += 2 * intval( WH_CARTOUCHE_WIDTH * $this->scale / 100 ); |
181 | 189 | } |
182 | 190 | |
183 | | - if ( array_key_exists( $glyph, $wh_files ) ) { |
184 | | - $height = $margin + $wh_files[$glyph][1]; |
| 191 | + if ( array_key_exists( $glyph, self::$files ) ) { |
| 192 | + $height = $margin + self::$files[$glyph][1]; |
185 | 193 | if ( $total ) { |
186 | 194 | if ( $total > WH_HEIGHT ) { |
187 | 195 | return ( intval( $height * WH_HEIGHT / $total ) - $margin ) * $this->scale / 100; |
— | — | @@ -207,8 +215,6 @@ |
208 | 216 | * @return string: converted code |
209 | 217 | */ |
210 | 218 | public function renderText( $hiero, $line = false ) { |
211 | | - global $wh_text_conv; |
212 | | - |
213 | 219 | $html = ""; |
214 | 220 | |
215 | 221 | if ( $line ) |
— | — | @@ -216,9 +222,9 @@ |
217 | 223 | |
218 | 224 | for ( $char = 0; $char < strlen( $hiero ); $char++ ) |
219 | 225 | { |
220 | | - if ( array_key_exists( $hiero[$char], $wh_text_conv ) ) |
| 226 | + if ( array_key_exists( $hiero[$char], self::$textConv ) ) |
221 | 227 | { |
222 | | - $html .= $wh_text_conv[$hiero[$char]]; |
| 228 | + $html .= self::$textConv[$hiero[$char]]; |
223 | 229 | if ( $hiero[$char] == '!' ) |
224 | 230 | if ( $line ) |
225 | 231 | $html .= "<hr />\n"; |
— | — | @@ -239,10 +245,6 @@ |
240 | 246 | * @return string: converted code |
241 | 247 | */ |
242 | 248 | public function renderHtml( $hiero, $scale = WH_SCALE_DEFAULT, $line = false ) { |
243 | | - global $wh_prefabs; |
244 | | - global $wh_files; |
245 | | - global $wh_phonemes; |
246 | | - |
247 | 249 | if ( $scale != WH_SCALE_DEFAULT ) |
248 | 250 | $this->setScale( $scale ); |
249 | 251 | |
— | — | @@ -380,7 +382,7 @@ |
381 | 383 | } |
382 | 384 | |
383 | 385 | // test is block is into tje prefabs list |
384 | | - if ( in_array( $temp, $wh_prefabs ) ) { |
| 386 | + if ( in_array( $temp, self::$prefabs ) ) { |
385 | 387 | $option = "height='" . $this->resizeGlyph( $temp, $is_cartouche ) . "'"; |
386 | 388 | |
387 | 389 | $contentHtml .= WH_TD_S . self::renderGlyph( $temp, $option ) . WH_TD_E; |
— | — | @@ -405,13 +407,13 @@ |
406 | 408 | $line_max = $height; |
407 | 409 | } |
408 | 410 | } else { |
409 | | - if ( array_key_exists( $t, $wh_phonemes ) ) { |
410 | | - $glyph = $wh_phonemes[$t]; |
| 411 | + if ( array_key_exists( $t, self::$phonemes ) ) { |
| 412 | + $glyph = self::$phonemes[$t]; |
411 | 413 | } else { |
412 | 414 | $glyph = $t; |
413 | 415 | } |
414 | | - if ( array_key_exists( $glyph, $wh_files ) ) { |
415 | | - $height = 2 + $wh_files[$glyph][1]; |
| 416 | + if ( array_key_exists( $glyph, self::$files ) ) { |
| 417 | + $height = 2 + self::$files[$glyph][1]; |
416 | 418 | } |
417 | 419 | } |
418 | 420 | } // end foreach |
— | — | @@ -464,6 +466,7 @@ |
465 | 467 | * @return string: converted code |
466 | 468 | */ |
467 | 469 | public static function getCode( $file ) { |
468 | | - return substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( self::IMG_EXT ) ) ); |
| 470 | + $s = substr( $file, strlen( WH_IMG_PRE ), -( 1 + strlen( self::IMG_EXT ) ) ); |
| 471 | + return str_replace( '&', ':', $s ); |
469 | 472 | } |
470 | 473 | } |