@@ -72,6 +72,9 @@ discard block |
||
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | + /** |
|
76 | + * @param integer $bytes |
|
77 | + */ |
|
75 | 78 | function read($bytes) { |
76 | 79 | return $this->STREAM->read($bytes); |
77 | 80 | } |
@@ -80,6 +83,7 @@ discard block |
||
80 | 83 | * Reads an array of Integers from the Stream |
81 | 84 | * |
82 | 85 | * @param int count How many elements should be read |
86 | + * @param integer $count |
|
83 | 87 | * @return Array of Integers |
84 | 88 | */ |
85 | 89 | function readintarray($count) { |
@@ -97,6 +101,7 @@ discard block |
||
97 | 101 | * |
98 | 102 | * @param object Reader the StreamReader object |
99 | 103 | * @param boolean enable_cache Enable or disable caching of strings (default on) |
104 | + * @param FileReader|null $Reader |
|
100 | 105 | */ |
101 | 106 | function __construct($Reader, $enable_cache = true) { |
102 | 107 | // If there isn't a StreamReader, turn on short circuit mode. |
@@ -171,6 +176,7 @@ discard block |
||
171 | 176 | * |
172 | 177 | * @access private |
173 | 178 | * @param int num Offset number of original string |
179 | + * @param integer $num |
|
174 | 180 | * @return string Requested string if found, otherwise '' |
175 | 181 | */ |
176 | 182 | function get_original_string($num) { |
@@ -188,6 +194,7 @@ discard block |
||
188 | 194 | * |
189 | 195 | * @access private |
190 | 196 | * @param int num Offset number of original string |
197 | + * @param integer $num |
|
191 | 198 | * @return string Requested string if found, otherwise '' |
192 | 199 | */ |
193 | 200 | function get_translation_string($num) { |
@@ -273,6 +280,7 @@ discard block |
||
273 | 280 | * Sanitize plural form expression for use in PHP eval call. |
274 | 281 | * |
275 | 282 | * @access private |
283 | + * @param string $expr |
|
276 | 284 | * @return string sanitized plural form expression |
277 | 285 | */ |
278 | 286 | function sanitize_plural_expression($expr) { |
@@ -370,7 +378,8 @@ discard block |
||
370 | 378 | * @param string single |
371 | 379 | * @param string plural |
372 | 380 | * @param string number |
373 | - * @return translated plural form |
|
381 | + * @param string $single |
|
382 | + * @return string plural form |
|
374 | 383 | */ |
375 | 384 | function ngettext($single, $plural, $number) { |
376 | 385 | if ($this->short_circuit) { |
@@ -34,75 +34,75 @@ discard block |
||
34 | 34 | * that you don't want to keep in memory) |
35 | 35 | */ |
36 | 36 | class gettext_reader { |
37 | - //public: |
|
38 | - var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | - |
|
40 | - //private: |
|
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | - var $STREAM = NULL; |
|
43 | - var $short_circuit = false; |
|
44 | - var $enable_cache = false; |
|
45 | - var $originals = NULL; // offset of original table |
|
46 | - var $translations = NULL; // offset of translation table |
|
47 | - var $pluralheader = NULL; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = NULL; // table for original strings (offsets) |
|
50 | - var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | - var $cache_translations = NULL; // original -> translation mapping |
|
52 | - |
|
53 | - |
|
54 | - /* Methods */ |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Reads a 32bit Integer from the Stream |
|
59 | - * |
|
60 | - * @access private |
|
61 | - * @return Integer from the Stream |
|
62 | - */ |
|
63 | - function readint() { |
|
64 | - if ($this->BYTEORDER == 0) { |
|
37 | + //public: |
|
38 | + var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | + |
|
40 | + //private: |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | + var $STREAM = NULL; |
|
43 | + var $short_circuit = false; |
|
44 | + var $enable_cache = false; |
|
45 | + var $originals = NULL; // offset of original table |
|
46 | + var $translations = NULL; // offset of translation table |
|
47 | + var $pluralheader = NULL; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = NULL; // table for original strings (offsets) |
|
50 | + var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | + var $cache_translations = NULL; // original -> translation mapping |
|
52 | + |
|
53 | + |
|
54 | + /* Methods */ |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Reads a 32bit Integer from the Stream |
|
59 | + * |
|
60 | + * @access private |
|
61 | + * @return Integer from the Stream |
|
62 | + */ |
|
63 | + function readint() { |
|
64 | + if ($this->BYTEORDER == 0) { |
|
65 | 65 | // low endian |
66 | 66 | $input=unpack('V', $this->STREAM->read(4)); |
67 | 67 | return array_shift($input); |
68 | - } else { |
|
68 | + } else { |
|
69 | 69 | // big endian |
70 | 70 | $input=unpack('N', $this->STREAM->read(4)); |
71 | 71 | return array_shift($input); |
72 | - } |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | - function read($bytes) { |
|
75 | + function read($bytes) { |
|
76 | 76 | return $this->STREAM->read($bytes); |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Reads an array of Integers from the Stream |
|
81 | - * |
|
82 | - * @param int count How many elements should be read |
|
83 | - * @return Array of Integers |
|
84 | - */ |
|
85 | - function readintarray($count) { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Reads an array of Integers from the Stream |
|
81 | + * |
|
82 | + * @param int count How many elements should be read |
|
83 | + * @return Array of Integers |
|
84 | + */ |
|
85 | + function readintarray($count) { |
|
86 | 86 | if ($this->BYTEORDER == 0) { |
87 | 87 | // low endian |
88 | 88 | return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
89 | - } else { |
|
89 | + } else { |
|
90 | 90 | // big endian |
91 | 91 | return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Constructor |
|
97 | - * |
|
98 | - * @param object Reader the StreamReader object |
|
99 | - * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | - */ |
|
101 | - function __construct($Reader, $enable_cache = true) { |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Constructor |
|
97 | + * |
|
98 | + * @param object Reader the StreamReader object |
|
99 | + * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | + */ |
|
101 | + function __construct($Reader, $enable_cache = true) { |
|
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | 103 | if (! $Reader || isset($Reader->error) ) { |
104 | - $this->short_circuit = true; |
|
105 | - return; |
|
104 | + $this->short_circuit = true; |
|
105 | + return; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Caching can be turned off |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | $this->STREAM = $Reader; |
115 | 115 | $magic = $this->read(4); |
116 | 116 | if ($magic == $MAGIC1) { |
117 | - $this->BYTEORDER = 1; |
|
117 | + $this->BYTEORDER = 1; |
|
118 | 118 | } elseif ($magic == $MAGIC2) { |
119 | - $this->BYTEORDER = 0; |
|
119 | + $this->BYTEORDER = 0; |
|
120 | 120 | } else { |
121 | - $this->error = 1; // not MO file |
|
122 | - return false; |
|
121 | + $this->error = 1; // not MO file |
|
122 | + return false; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // FIXME: Do we care about revision? We should. |
@@ -128,154 +128,154 @@ discard block |
||
128 | 128 | $this->total = $this->readint(); |
129 | 129 | $this->originals = $this->readint(); |
130 | 130 | $this->translations = $this->readint(); |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Loads the translation tables from the MO file into the cache |
|
135 | - * If caching is enabled, also loads all strings into a cache |
|
136 | - * to speed up translation lookups |
|
137 | - * |
|
138 | - * @access private |
|
139 | - */ |
|
140 | - function load_tables() { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Loads the translation tables from the MO file into the cache |
|
135 | + * If caching is enabled, also loads all strings into a cache |
|
136 | + * to speed up translation lookups |
|
137 | + * |
|
138 | + * @access private |
|
139 | + */ |
|
140 | + function load_tables() { |
|
141 | 141 | if (is_array($this->cache_translations) && |
142 | 142 | is_array($this->table_originals) && |
143 | 143 | is_array($this->table_translations)) |
144 | - return; |
|
144 | + return; |
|
145 | 145 | |
146 | 146 | /* get original and translations tables */ |
147 | 147 | if (!is_array($this->table_originals)) { |
148 | - $this->STREAM->seekto($this->originals); |
|
149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
148 | + $this->STREAM->seekto($this->originals); |
|
149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
150 | 150 | } |
151 | 151 | if (!is_array($this->table_translations)) { |
152 | - $this->STREAM->seekto($this->translations); |
|
153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
152 | + $this->STREAM->seekto($this->translations); |
|
153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
158 | - /* read all strings in the cache */ |
|
159 | - for ($i = 0; $i < $this->total; $i++) { |
|
157 | + $this->cache_translations = array (); |
|
158 | + /* read all strings in the cache */ |
|
159 | + for ($i = 0; $i < $this->total; $i++) { |
|
160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
161 | 161 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
162 | 162 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
163 | 163 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
164 | 164 | $this->cache_translations[$original] = $translation; |
165 | - } |
|
165 | + } |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns a string from the "originals" table |
|
171 | - * |
|
172 | - * @access private |
|
173 | - * @param int num Offset number of original string |
|
174 | - * @return string Requested string if found, otherwise '' |
|
175 | - */ |
|
176 | - function get_original_string($num) { |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns a string from the "originals" table |
|
171 | + * |
|
172 | + * @access private |
|
173 | + * @param int num Offset number of original string |
|
174 | + * @return string Requested string if found, otherwise '' |
|
175 | + */ |
|
176 | + function get_original_string($num) { |
|
177 | 177 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 178 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | 179 | if (! $length) |
180 | - return ''; |
|
180 | + return ''; |
|
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | 183 | return (string)$data; |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns a string from the "translations" table |
|
188 | - * |
|
189 | - * @access private |
|
190 | - * @param int num Offset number of original string |
|
191 | - * @return string Requested string if found, otherwise '' |
|
192 | - */ |
|
193 | - function get_translation_string($num) { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns a string from the "translations" table |
|
188 | + * |
|
189 | + * @access private |
|
190 | + * @param int num Offset number of original string |
|
191 | + * @return string Requested string if found, otherwise '' |
|
192 | + */ |
|
193 | + function get_translation_string($num) { |
|
194 | 194 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 195 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | 196 | if (! $length) |
197 | - return ''; |
|
197 | + return ''; |
|
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | 200 | return (string)$data; |
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Binary search for string |
|
205 | - * |
|
206 | - * @access private |
|
207 | - * @param string string |
|
208 | - * @param int start (internally used in recursive function) |
|
209 | - * @param int end (internally used in recursive function) |
|
210 | - * @return int string number (offset in originals table) |
|
211 | - */ |
|
212 | - function find_string($string, $start = -1, $end = -1) { |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Binary search for string |
|
205 | + * |
|
206 | + * @access private |
|
207 | + * @param string string |
|
208 | + * @param int start (internally used in recursive function) |
|
209 | + * @param int end (internally used in recursive function) |
|
210 | + * @return int string number (offset in originals table) |
|
211 | + */ |
|
212 | + function find_string($string, $start = -1, $end = -1) { |
|
213 | 213 | if (($start == -1) or ($end == -1)) { |
214 | - // find_string is called with only one parameter, set start end end |
|
215 | - $start = 0; |
|
216 | - $end = $this->total; |
|
214 | + // find_string is called with only one parameter, set start end end |
|
215 | + $start = 0; |
|
216 | + $end = $this->total; |
|
217 | 217 | } |
218 | 218 | if (abs($start - $end) <= 1) { |
219 | - // We're done, now we either found the string, or it doesn't exist |
|
220 | - $txt = $this->get_original_string($start); |
|
221 | - if ($string == $txt) |
|
219 | + // We're done, now we either found the string, or it doesn't exist |
|
220 | + $txt = $this->get_original_string($start); |
|
221 | + if ($string == $txt) |
|
222 | 222 | return $start; |
223 | - else |
|
223 | + else |
|
224 | 224 | return -1; |
225 | 225 | } else if ($start > $end) { |
226 | - // start > end -> turn around and start over |
|
227 | - return $this->find_string($string, $end, $start); |
|
226 | + // start > end -> turn around and start over |
|
227 | + return $this->find_string($string, $end, $start); |
|
228 | 228 | } else { |
229 | - // Divide table in two parts |
|
230 | - $half = (int)(($start + $end) / 2); |
|
231 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | - if ($cmp == 0) |
|
229 | + // Divide table in two parts |
|
230 | + $half = (int)(($start + $end) / 2); |
|
231 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | + if ($cmp == 0) |
|
233 | 233 | // string is exactly in the middle => return it |
234 | 234 | return $half; |
235 | - else if ($cmp < 0) |
|
235 | + else if ($cmp < 0) |
|
236 | 236 | // The string is in the upper half |
237 | 237 | return $this->find_string($string, $start, $half); |
238 | - else |
|
238 | + else |
|
239 | 239 | // The string is in the lower half |
240 | 240 | return $this->find_string($string, $half, $end); |
241 | 241 | } |
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Translates a string |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @param string string to be translated |
|
249 | - * @return string translated string (or original, if not found) |
|
250 | - */ |
|
251 | - function translate($string) { |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Translates a string |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @param string string to be translated |
|
249 | + * @return string translated string (or original, if not found) |
|
250 | + */ |
|
251 | + function translate($string) { |
|
252 | 252 | if ($this->short_circuit) |
253 | - return $string; |
|
253 | + return $string; |
|
254 | 254 | $this->load_tables(); |
255 | 255 | |
256 | 256 | if ($this->enable_cache) { |
257 | - // Caching enabled, get translated string from cache |
|
258 | - if (array_key_exists($string, $this->cache_translations)) |
|
257 | + // Caching enabled, get translated string from cache |
|
258 | + if (array_key_exists($string, $this->cache_translations)) |
|
259 | 259 | return $this->cache_translations[$string]; |
260 | - else |
|
260 | + else |
|
261 | 261 | return $string; |
262 | 262 | } else { |
263 | - // Caching not enabled, try to find string |
|
264 | - $num = $this->find_string($string); |
|
265 | - if ($num == -1) |
|
263 | + // Caching not enabled, try to find string |
|
264 | + $num = $this->find_string($string); |
|
265 | + if ($num == -1) |
|
266 | 266 | return $string; |
267 | - else |
|
267 | + else |
|
268 | 268 | return $this->get_translation_string($num); |
269 | 269 | } |
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Sanitize plural form expression for use in PHP eval call. |
|
274 | - * |
|
275 | - * @access private |
|
276 | - * @return string sanitized plural form expression |
|
277 | - */ |
|
278 | - function sanitize_plural_expression($expr) { |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Sanitize plural form expression for use in PHP eval call. |
|
274 | + * |
|
275 | + * @access private |
|
276 | + * @return string sanitized plural form expression |
|
277 | + */ |
|
278 | + function sanitize_plural_expression($expr) { |
|
279 | 279 | // Get rid of disallowed characters. |
280 | 280 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
281 | 281 | |
@@ -284,72 +284,72 @@ discard block |
||
284 | 284 | $res = ''; |
285 | 285 | $p = 0; |
286 | 286 | for ($i = 0; $i < strlen($expr); $i++) { |
287 | - $ch = $expr[$i]; |
|
288 | - switch ($ch) { |
|
289 | - case '?': |
|
287 | + $ch = $expr[$i]; |
|
288 | + switch ($ch) { |
|
289 | + case '?': |
|
290 | 290 | $res .= ' ? ('; |
291 | 291 | $p++; |
292 | 292 | break; |
293 | - case ':': |
|
293 | + case ':': |
|
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | - case ';': |
|
296 | + case ';': |
|
297 | 297 | $res .= str_repeat( ')', $p) . ';'; |
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | - default: |
|
300 | + default: |
|
301 | 301 | $res .= $ch; |
302 | - } |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | return $res; |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Parse full PO header and extract only plural forms line. |
|
309 | - * |
|
310 | - * @access private |
|
311 | - * @return string verbatim plural form header field |
|
312 | - */ |
|
313 | - function extract_plural_forms_header_from_po_header($header) { |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Parse full PO header and extract only plural forms line. |
|
309 | + * |
|
310 | + * @access private |
|
311 | + * @return string verbatim plural form header field |
|
312 | + */ |
|
313 | + function extract_plural_forms_header_from_po_header($header) { |
|
314 | 314 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
315 | - $expr = $regs[2]; |
|
315 | + $expr = $regs[2]; |
|
316 | 316 | else |
317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
317 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
318 | 318 | return $expr; |
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Get possible plural forms from MO header |
|
323 | - * |
|
324 | - * @access private |
|
325 | - * @return string plural form header |
|
326 | - */ |
|
327 | - function get_plural_forms() { |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get possible plural forms from MO header |
|
323 | + * |
|
324 | + * @access private |
|
325 | + * @return string plural form header |
|
326 | + */ |
|
327 | + function get_plural_forms() { |
|
328 | 328 | // lets assume message number 0 is header |
329 | 329 | // this is true, right? |
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | 333 | if (! is_string($this->pluralheader)) { |
334 | - if ($this->enable_cache) { |
|
334 | + if ($this->enable_cache) { |
|
335 | 335 | $header = $this->cache_translations[""]; |
336 | - } else { |
|
336 | + } else { |
|
337 | 337 | $header = $this->get_translation_string(0); |
338 | - } |
|
339 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
338 | + } |
|
339 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
341 | 341 | } |
342 | 342 | return $this->pluralheader; |
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Detects which plural form to take |
|
347 | - * |
|
348 | - * @access private |
|
349 | - * @param n count |
|
350 | - * @return int array index of the right plural form |
|
351 | - */ |
|
352 | - function select_string($n) { |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Detects which plural form to take |
|
347 | + * |
|
348 | + * @access private |
|
349 | + * @param n count |
|
350 | + * @return int array index of the right plural form |
|
351 | + */ |
|
352 | + function select_string($n) { |
|
353 | 353 | $string = $this->get_plural_forms(); |
354 | 354 | $string = str_replace('nplurals',"\$total",$string); |
355 | 355 | $string = str_replace("n",$n,$string); |
@@ -361,22 +361,22 @@ discard block |
||
361 | 361 | eval("$string"); |
362 | 362 | if ($plural >= $total) $plural = $total - 1; |
363 | 363 | return $plural; |
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Plural version of gettext |
|
368 | - * |
|
369 | - * @access public |
|
370 | - * @param string single |
|
371 | - * @param string plural |
|
372 | - * @param string number |
|
373 | - * @return translated plural form |
|
374 | - */ |
|
375 | - function ngettext($single, $plural, $number) { |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Plural version of gettext |
|
368 | + * |
|
369 | + * @access public |
|
370 | + * @param string single |
|
371 | + * @param string plural |
|
372 | + * @param string number |
|
373 | + * @return translated plural form |
|
374 | + */ |
|
375 | + function ngettext($single, $plural, $number) { |
|
376 | 376 | if ($this->short_circuit) { |
377 | - if ($number != 1) |
|
377 | + if ($number != 1) |
|
378 | 378 | return $plural; |
379 | - else |
|
379 | + else |
|
380 | 380 | return $single; |
381 | 381 | } |
382 | 382 | |
@@ -388,45 +388,45 @@ discard block |
||
388 | 388 | |
389 | 389 | |
390 | 390 | if ($this->enable_cache) { |
391 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
391 | + if (! array_key_exists($key, $this->cache_translations)) { |
|
392 | 392 | return ($number != 1) ? $plural : $single; |
393 | - } else { |
|
393 | + } else { |
|
394 | 394 | $result = $this->cache_translations[$key]; |
395 | 395 | $list = explode(chr(0), $result); |
396 | 396 | return $list[$select]; |
397 | - } |
|
397 | + } |
|
398 | 398 | } else { |
399 | - $num = $this->find_string($key); |
|
400 | - if ($num == -1) { |
|
399 | + $num = $this->find_string($key); |
|
400 | + if ($num == -1) { |
|
401 | 401 | return ($number != 1) ? $plural : $single; |
402 | - } else { |
|
402 | + } else { |
|
403 | 403 | $result = $this->get_translation_string($num); |
404 | 404 | $list = explode(chr(0), $result); |
405 | 405 | return $list[$select]; |
406 | - } |
|
406 | + } |
|
407 | + } |
|
407 | 408 | } |
408 | - } |
|
409 | 409 | |
410 | - function pgettext($context, $msgid) { |
|
410 | + function pgettext($context, $msgid) { |
|
411 | 411 | $key = $context . chr(4) . $msgid; |
412 | 412 | $ret = $this->translate($key); |
413 | 413 | if (strpos($ret, "\004") !== FALSE) { |
414 | - return $msgid; |
|
414 | + return $msgid; |
|
415 | 415 | } else { |
416 | - return $ret; |
|
416 | + return $ret; |
|
417 | + } |
|
417 | 418 | } |
418 | - } |
|
419 | 419 | |
420 | - function npgettext($context, $singular, $plural, $number) { |
|
420 | + function npgettext($context, $singular, $plural, $number) { |
|
421 | 421 | $key = $context . chr(4) . $singular; |
422 | 422 | $ret = $this->ngettext($key, $plural, $number); |
423 | 423 | if (strpos($ret, "\004") !== FALSE) { |
424 | - return $singular; |
|
424 | + return $singular; |
|
425 | 425 | } else { |
426 | - return $ret; |
|
426 | + return $ret; |
|
427 | 427 | } |
428 | 428 | |
429 | - } |
|
429 | + } |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | ?> |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | var $error = 0; // public variable that holds error code (0 if no error) |
39 | 39 | |
40 | 40 | //private: |
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | 42 | var $STREAM = NULL; |
43 | 43 | var $short_circuit = false; |
44 | 44 | var $enable_cache = false; |
45 | - var $originals = NULL; // offset of original table |
|
46 | - var $translations = NULL; // offset of translation table |
|
47 | - var $pluralheader = NULL; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = NULL; // table for original strings (offsets) |
|
50 | - var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | - var $cache_translations = NULL; // original -> translation mapping |
|
45 | + var $originals = NULL; // offset of original table |
|
46 | + var $translations = NULL; // offset of translation table |
|
47 | + var $pluralheader = NULL; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = NULL; // table for original strings (offsets) |
|
50 | + var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | + var $cache_translations = NULL; // original -> translation mapping |
|
52 | 52 | |
53 | 53 | |
54 | 54 | /* Methods */ |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | function readint() { |
64 | 64 | if ($this->BYTEORDER == 0) { |
65 | 65 | // low endian |
66 | - $input=unpack('V', $this->STREAM->read(4)); |
|
66 | + $input = unpack('V', $this->STREAM->read(4)); |
|
67 | 67 | return array_shift($input); |
68 | 68 | } else { |
69 | 69 | // big endian |
70 | - $input=unpack('N', $this->STREAM->read(4)); |
|
70 | + $input = unpack('N', $this->STREAM->read(4)); |
|
71 | 71 | return array_shift($input); |
72 | 72 | } |
73 | 73 | } |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | function readintarray($count) { |
86 | 86 | if ($this->BYTEORDER == 0) { |
87 | 87 | // low endian |
88 | - return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
|
88 | + return unpack('V' . $count, $this->STREAM->read(4 * $count)); |
|
89 | 89 | } else { |
90 | 90 | // big endian |
91 | - return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
|
91 | + return unpack('N' . $count, $this->STREAM->read(4 * $count)); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | function __construct($Reader, $enable_cache = true) { |
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | - if (! $Reader || isset($Reader->error) ) { |
|
103 | + if (!$Reader || isset($Reader->error)) { |
|
104 | 104 | $this->short_circuit = true; |
105 | 105 | return; |
106 | 106 | } |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
157 | + $this->cache_translations = array(); |
|
158 | 158 | /* read all strings in the cache */ |
159 | 159 | for ($i = 0; $i < $this->total; $i++) { |
160 | - $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
|
161 | - $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
|
162 | - $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
|
163 | - $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
|
160 | + $this->STREAM->seekto($this->table_originals[$i * 2+2]); |
|
161 | + $original = $this->STREAM->read($this->table_originals[$i * 2+1]); |
|
162 | + $this->STREAM->seekto($this->table_translations[$i * 2+2]); |
|
163 | + $translation = $this->STREAM->read($this->table_translations[$i * 2+1]); |
|
164 | 164 | $this->cache_translations[$original] = $translation; |
165 | 165 | } |
166 | 166 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @return string Requested string if found, otherwise '' |
175 | 175 | */ |
176 | 176 | function get_original_string($num) { |
177 | - $length = $this->table_originals[$num * 2 + 1]; |
|
178 | - $offset = $this->table_originals[$num * 2 + 2]; |
|
179 | - if (! $length) |
|
177 | + $length = $this->table_originals[$num * 2+1]; |
|
178 | + $offset = $this->table_originals[$num * 2+2]; |
|
179 | + if (!$length) |
|
180 | 180 | return ''; |
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | - return (string)$data; |
|
183 | + return (string) $data; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * @return string Requested string if found, otherwise '' |
192 | 192 | */ |
193 | 193 | function get_translation_string($num) { |
194 | - $length = $this->table_translations[$num * 2 + 1]; |
|
195 | - $offset = $this->table_translations[$num * 2 + 2]; |
|
196 | - if (! $length) |
|
194 | + $length = $this->table_translations[$num * 2+1]; |
|
195 | + $offset = $this->table_translations[$num * 2+2]; |
|
196 | + if (!$length) |
|
197 | 197 | return ''; |
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | - return (string)$data; |
|
200 | + return (string) $data; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $start = 0; |
216 | 216 | $end = $this->total; |
217 | 217 | } |
218 | - if (abs($start - $end) <= 1) { |
|
218 | + if (abs($start-$end) <= 1) { |
|
219 | 219 | // We're done, now we either found the string, or it doesn't exist |
220 | 220 | $txt = $this->get_original_string($start); |
221 | 221 | if ($string == $txt) |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | return $this->find_string($string, $end, $start); |
228 | 228 | } else { |
229 | 229 | // Divide table in two parts |
230 | - $half = (int)(($start + $end) / 2); |
|
230 | + $half = (int) (($start+$end) / 2); |
|
231 | 231 | $cmp = strcmp($string, $this->get_original_string($half)); |
232 | 232 | if ($cmp == 0) |
233 | 233 | // string is exactly in the middle => return it |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | 296 | case ';': |
297 | - $res .= str_repeat( ')', $p) . ';'; |
|
297 | + $res .= str_repeat(')', $p) . ';'; |
|
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | 300 | default: |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | - if (! is_string($this->pluralheader)) { |
|
333 | + if (!is_string($this->pluralheader)) { |
|
334 | 334 | if ($this->enable_cache) { |
335 | 335 | $header = $this->cache_translations[""]; |
336 | 336 | } else { |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | */ |
352 | 352 | function select_string($n) { |
353 | 353 | $string = $this->get_plural_forms(); |
354 | - $string = str_replace('nplurals',"\$total",$string); |
|
355 | - $string = str_replace("n",$n,$string); |
|
356 | - $string = str_replace('plural',"\$plural",$string); |
|
354 | + $string = str_replace('nplurals', "\$total", $string); |
|
355 | + $string = str_replace("n", $n, $string); |
|
356 | + $string = str_replace('plural', "\$plural", $string); |
|
357 | 357 | |
358 | 358 | $total = 0; |
359 | 359 | $plural = 0; |
360 | 360 | |
361 | 361 | eval("$string"); |
362 | - if ($plural >= $total) $plural = $total - 1; |
|
362 | + if ($plural >= $total) $plural = $total-1; |
|
363 | 363 | return $plural; |
364 | 364 | } |
365 | 365 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | |
389 | 389 | |
390 | 390 | if ($this->enable_cache) { |
391 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
391 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
392 | 392 | return ($number != 1) ? $plural : $single; |
393 | 393 | } else { |
394 | 394 | $result = $this->cache_translations[$key]; |
@@ -140,8 +140,9 @@ discard block |
||
140 | 140 | function load_tables() { |
141 | 141 | if (is_array($this->cache_translations) && |
142 | 142 | is_array($this->table_originals) && |
143 | - is_array($this->table_translations)) |
|
144 | - return; |
|
143 | + is_array($this->table_translations)) { |
|
144 | + return; |
|
145 | + } |
|
145 | 146 | |
146 | 147 | /* get original and translations tables */ |
147 | 148 | if (!is_array($this->table_originals)) { |
@@ -176,8 +177,9 @@ discard block |
||
176 | 177 | function get_original_string($num) { |
177 | 178 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 179 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | - if (! $length) |
|
180 | - return ''; |
|
180 | + if (! $length) { |
|
181 | + return ''; |
|
182 | + } |
|
181 | 183 | $this->STREAM->seekto($offset); |
182 | 184 | $data = $this->STREAM->read($length); |
183 | 185 | return (string)$data; |
@@ -193,8 +195,9 @@ discard block |
||
193 | 195 | function get_translation_string($num) { |
194 | 196 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 197 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | - if (! $length) |
|
197 | - return ''; |
|
198 | + if (! $length) { |
|
199 | + return ''; |
|
200 | + } |
|
198 | 201 | $this->STREAM->seekto($offset); |
199 | 202 | $data = $this->STREAM->read($length); |
200 | 203 | return (string)$data; |
@@ -218,10 +221,11 @@ discard block |
||
218 | 221 | if (abs($start - $end) <= 1) { |
219 | 222 | // We're done, now we either found the string, or it doesn't exist |
220 | 223 | $txt = $this->get_original_string($start); |
221 | - if ($string == $txt) |
|
222 | - return $start; |
|
223 | - else |
|
224 | - return -1; |
|
224 | + if ($string == $txt) { |
|
225 | + return $start; |
|
226 | + } else { |
|
227 | + return -1; |
|
228 | + } |
|
225 | 229 | } else if ($start > $end) { |
226 | 230 | // start > end -> turn around and start over |
227 | 231 | return $this->find_string($string, $end, $start); |
@@ -229,15 +233,16 @@ discard block |
||
229 | 233 | // Divide table in two parts |
230 | 234 | $half = (int)(($start + $end) / 2); |
231 | 235 | $cmp = strcmp($string, $this->get_original_string($half)); |
232 | - if ($cmp == 0) |
|
233 | - // string is exactly in the middle => return it |
|
236 | + if ($cmp == 0) { |
|
237 | + // string is exactly in the middle => return it |
|
234 | 238 | return $half; |
235 | - else if ($cmp < 0) |
|
236 | - // The string is in the upper half |
|
239 | + } else if ($cmp < 0) { |
|
240 | + // The string is in the upper half |
|
237 | 241 | return $this->find_string($string, $start, $half); |
238 | - else |
|
239 | - // The string is in the lower half |
|
242 | + } else { |
|
243 | + // The string is in the lower half |
|
240 | 244 | return $this->find_string($string, $half, $end); |
245 | + } |
|
241 | 246 | } |
242 | 247 | } |
243 | 248 | |
@@ -249,23 +254,26 @@ discard block |
||
249 | 254 | * @return string translated string (or original, if not found) |
250 | 255 | */ |
251 | 256 | function translate($string) { |
252 | - if ($this->short_circuit) |
|
253 | - return $string; |
|
257 | + if ($this->short_circuit) { |
|
258 | + return $string; |
|
259 | + } |
|
254 | 260 | $this->load_tables(); |
255 | 261 | |
256 | 262 | if ($this->enable_cache) { |
257 | 263 | // Caching enabled, get translated string from cache |
258 | - if (array_key_exists($string, $this->cache_translations)) |
|
259 | - return $this->cache_translations[$string]; |
|
260 | - else |
|
261 | - return $string; |
|
264 | + if (array_key_exists($string, $this->cache_translations)) { |
|
265 | + return $this->cache_translations[$string]; |
|
266 | + } else { |
|
267 | + return $string; |
|
268 | + } |
|
262 | 269 | } else { |
263 | 270 | // Caching not enabled, try to find string |
264 | 271 | $num = $this->find_string($string); |
265 | - if ($num == -1) |
|
266 | - return $string; |
|
267 | - else |
|
268 | - return $this->get_translation_string($num); |
|
272 | + if ($num == -1) { |
|
273 | + return $string; |
|
274 | + } else { |
|
275 | + return $this->get_translation_string($num); |
|
276 | + } |
|
269 | 277 | } |
270 | 278 | } |
271 | 279 | |
@@ -311,10 +319,11 @@ discard block |
||
311 | 319 | * @return string verbatim plural form header field |
312 | 320 | */ |
313 | 321 | function extract_plural_forms_header_from_po_header($header) { |
314 | - if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
|
315 | - $expr = $regs[2]; |
|
316 | - else |
|
317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
322 | + if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) { |
|
323 | + $expr = $regs[2]; |
|
324 | + } else { |
|
325 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
326 | + } |
|
318 | 327 | return $expr; |
319 | 328 | } |
320 | 329 | |
@@ -359,7 +368,9 @@ discard block |
||
359 | 368 | $plural = 0; |
360 | 369 | |
361 | 370 | eval("$string"); |
362 | - if ($plural >= $total) $plural = $total - 1; |
|
371 | + if ($plural >= $total) { |
|
372 | + $plural = $total - 1; |
|
373 | + } |
|
363 | 374 | return $plural; |
364 | 375 | } |
365 | 376 | |
@@ -374,10 +385,11 @@ discard block |
||
374 | 385 | */ |
375 | 386 | function ngettext($single, $plural, $number) { |
376 | 387 | if ($this->short_circuit) { |
377 | - if ($number != 1) |
|
378 | - return $plural; |
|
379 | - else |
|
380 | - return $single; |
|
388 | + if ($number != 1) { |
|
389 | + return $plural; |
|
390 | + } else { |
|
391 | + return $single; |
|
392 | + } |
|
381 | 393 | } |
382 | 394 | |
383 | 395 | // find out the appropriate form |
@@ -86,6 +86,9 @@ |
||
86 | 86 | var $_fd; |
87 | 87 | var $_length; |
88 | 88 | |
89 | + /** |
|
90 | + * @param string $filename |
|
91 | + */ |
|
89 | 92 | function __construct($filename) { |
90 | 93 | if (file_exists($filename)) { |
91 | 94 |
@@ -21,146 +21,146 @@ |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | - // Simple class to wrap file streams, string streams, etc. |
|
25 | - // seek is essential, and it should be byte stream |
|
24 | + // Simple class to wrap file streams, string streams, etc. |
|
25 | + // seek is essential, and it should be byte stream |
|
26 | 26 | class StreamReader { |
27 | - // should return a string [FIXME: perhaps return array of bytes?] |
|
28 | - function read($bytes) { |
|
27 | + // should return a string [FIXME: perhaps return array of bytes?] |
|
28 | + function read($bytes) { |
|
29 | 29 | return false; |
30 | - } |
|
30 | + } |
|
31 | 31 | |
32 | - // should return new position |
|
33 | - function seekto($position) { |
|
32 | + // should return new position |
|
33 | + function seekto($position) { |
|
34 | 34 | return false; |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - // returns current position |
|
38 | - function currentpos() { |
|
37 | + // returns current position |
|
38 | + function currentpos() { |
|
39 | 39 | return false; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - // returns length of entire stream (limit for seekto()s) |
|
43 | - function length() { |
|
42 | + // returns length of entire stream (limit for seekto()s) |
|
43 | + function length() { |
|
44 | 44 | return false; |
45 | - } |
|
45 | + } |
|
46 | 46 | }; |
47 | 47 | |
48 | 48 | class StringReader { |
49 | - var $_pos; |
|
50 | - var $_str; |
|
49 | + var $_pos; |
|
50 | + var $_str; |
|
51 | 51 | |
52 | - function __construct($str='') { |
|
52 | + function __construct($str='') { |
|
53 | 53 | $this->_str = $str; |
54 | 54 | $this->_pos = 0; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - function read($bytes) { |
|
57 | + function read($bytes) { |
|
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | 60 | if (strlen($this->_str)<$this->_pos) |
61 | - $this->_pos = strlen($this->_str); |
|
61 | + $this->_pos = strlen($this->_str); |
|
62 | 62 | |
63 | 63 | return $data; |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - function seekto($pos) { |
|
66 | + function seekto($pos) { |
|
67 | 67 | $this->_pos = $pos; |
68 | 68 | if (strlen($this->_str)<$this->_pos) |
69 | - $this->_pos = strlen($this->_str); |
|
69 | + $this->_pos = strlen($this->_str); |
|
70 | 70 | return $this->_pos; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - function currentpos() { |
|
73 | + function currentpos() { |
|
74 | 74 | return $this->_pos; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - function length() { |
|
77 | + function length() { |
|
78 | 78 | return strlen($this->_str); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | }; |
82 | 82 | |
83 | 83 | |
84 | 84 | class FileReader { |
85 | - var $_pos; |
|
86 | - var $_fd; |
|
87 | - var $_length; |
|
85 | + var $_pos; |
|
86 | + var $_fd; |
|
87 | + var $_length; |
|
88 | 88 | |
89 | - function __construct($filename) { |
|
89 | + function __construct($filename) { |
|
90 | 90 | if (file_exists($filename)) { |
91 | 91 | |
92 | - $this->_length=filesize($filename); |
|
93 | - $this->_pos = 0; |
|
94 | - $this->_fd = fopen($filename,'rb'); |
|
95 | - if (!$this->_fd) { |
|
92 | + $this->_length=filesize($filename); |
|
93 | + $this->_pos = 0; |
|
94 | + $this->_fd = fopen($filename,'rb'); |
|
95 | + if (!$this->_fd) { |
|
96 | 96 | $this->error = 3; // Cannot read file, probably permissions |
97 | 97 | return false; |
98 | - } |
|
98 | + } |
|
99 | 99 | } else { |
100 | - $this->error = 2; // File doesn't exist |
|
101 | - return false; |
|
100 | + $this->error = 2; // File doesn't exist |
|
101 | + return false; |
|
102 | + } |
|
102 | 103 | } |
103 | - } |
|
104 | 104 | |
105 | - function read($bytes) { |
|
105 | + function read($bytes) { |
|
106 | 106 | if ($bytes) { |
107 | - fseek($this->_fd, $this->_pos); |
|
107 | + fseek($this->_fd, $this->_pos); |
|
108 | 108 | |
109 | - // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
110 | - // the discussions at PHP Bugs suggest it's the intended behaviour |
|
111 | - $data = ''; |
|
112 | - while ($bytes > 0) { |
|
109 | + // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
110 | + // the discussions at PHP Bugs suggest it's the intended behaviour |
|
111 | + $data = ''; |
|
112 | + while ($bytes > 0) { |
|
113 | 113 | $chunk = fread($this->_fd, $bytes); |
114 | 114 | $data .= $chunk; |
115 | 115 | $bytes -= strlen($chunk); |
116 | - } |
|
117 | - $this->_pos = ftell($this->_fd); |
|
116 | + } |
|
117 | + $this->_pos = ftell($this->_fd); |
|
118 | 118 | |
119 | - return $data; |
|
119 | + return $data; |
|
120 | 120 | } else return ''; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - function seekto($pos) { |
|
123 | + function seekto($pos) { |
|
124 | 124 | fseek($this->_fd, $pos); |
125 | 125 | $this->_pos = ftell($this->_fd); |
126 | 126 | return $this->_pos; |
127 | - } |
|
127 | + } |
|
128 | 128 | |
129 | - function currentpos() { |
|
129 | + function currentpos() { |
|
130 | 130 | return $this->_pos; |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - function length() { |
|
133 | + function length() { |
|
134 | 134 | return $this->_length; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - function close() { |
|
137 | + function close() { |
|
138 | 138 | fclose($this->_fd); |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | }; |
142 | 142 | |
143 | 143 | // Preloads entire file in memory first, then creates a StringReader |
144 | 144 | // over it (it assumes knowledge of StringReader internals) |
145 | 145 | class CachedFileReader extends StringReader { |
146 | - function __construct($filename) { |
|
146 | + function __construct($filename) { |
|
147 | 147 | if (file_exists($filename)) { |
148 | 148 | |
149 | - $length=filesize($filename); |
|
150 | - $fd = fopen($filename,'rb'); |
|
149 | + $length=filesize($filename); |
|
150 | + $fd = fopen($filename,'rb'); |
|
151 | 151 | |
152 | - if (!$fd) { |
|
152 | + if (!$fd) { |
|
153 | 153 | $this->error = 3; // Cannot read file, probably permissions |
154 | 154 | return false; |
155 | - } |
|
156 | - $this->_str = fread($fd, $length); |
|
157 | - fclose($fd); |
|
155 | + } |
|
156 | + $this->_str = fread($fd, $length); |
|
157 | + fclose($fd); |
|
158 | 158 | |
159 | 159 | } else { |
160 | - $this->error = 2; // File doesn't exist |
|
161 | - return false; |
|
160 | + $this->error = 2; // File doesn't exist |
|
161 | + return false; |
|
162 | + } |
|
162 | 163 | } |
163 | - } |
|
164 | 164 | }; |
165 | 165 | |
166 | 166 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | var $_pos; |
50 | 50 | var $_str; |
51 | 51 | |
52 | - function __construct($str='') { |
|
52 | + function __construct($str = '') { |
|
53 | 53 | $this->_str = $str; |
54 | 54 | $this->_pos = 0; |
55 | 55 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | function read($bytes) { |
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | - if (strlen($this->_str)<$this->_pos) |
|
60 | + if (strlen($this->_str) < $this->_pos) |
|
61 | 61 | $this->_pos = strlen($this->_str); |
62 | 62 | |
63 | 63 | return $data; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | function seekto($pos) { |
67 | 67 | $this->_pos = $pos; |
68 | - if (strlen($this->_str)<$this->_pos) |
|
68 | + if (strlen($this->_str) < $this->_pos) |
|
69 | 69 | $this->_pos = strlen($this->_str); |
70 | 70 | return $this->_pos; |
71 | 71 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | function __construct($filename) { |
90 | 90 | if (file_exists($filename)) { |
91 | 91 | |
92 | - $this->_length=filesize($filename); |
|
92 | + $this->_length = filesize($filename); |
|
93 | 93 | $this->_pos = 0; |
94 | - $this->_fd = fopen($filename,'rb'); |
|
94 | + $this->_fd = fopen($filename, 'rb'); |
|
95 | 95 | if (!$this->_fd) { |
96 | 96 | $this->error = 3; // Cannot read file, probably permissions |
97 | 97 | return false; |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | function __construct($filename) { |
147 | 147 | if (file_exists($filename)) { |
148 | 148 | |
149 | - $length=filesize($filename); |
|
150 | - $fd = fopen($filename,'rb'); |
|
149 | + $length = filesize($filename); |
|
150 | + $fd = fopen($filename, 'rb'); |
|
151 | 151 | |
152 | 152 | if (!$fd) { |
153 | 153 | $this->error = 3; // Cannot read file, probably permissions |
@@ -57,16 +57,18 @@ discard block |
||
57 | 57 | function read($bytes) { |
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | - if (strlen($this->_str)<$this->_pos) |
|
61 | - $this->_pos = strlen($this->_str); |
|
60 | + if (strlen($this->_str)<$this->_pos) { |
|
61 | + $this->_pos = strlen($this->_str); |
|
62 | + } |
|
62 | 63 | |
63 | 64 | return $data; |
64 | 65 | } |
65 | 66 | |
66 | 67 | function seekto($pos) { |
67 | 68 | $this->_pos = $pos; |
68 | - if (strlen($this->_str)<$this->_pos) |
|
69 | - $this->_pos = strlen($this->_str); |
|
69 | + if (strlen($this->_str)<$this->_pos) { |
|
70 | + $this->_pos = strlen($this->_str); |
|
71 | + } |
|
70 | 72 | return $this->_pos; |
71 | 73 | } |
72 | 74 | |
@@ -117,7 +119,9 @@ discard block |
||
117 | 119 | $this->_pos = ftell($this->_fd); |
118 | 120 | |
119 | 121 | return $data; |
120 | - } else return ''; |
|
122 | + } else { |
|
123 | + return ''; |
|
124 | + } |
|
121 | 125 | } |
122 | 126 | |
123 | 127 | function seekto($pos) { |
@@ -46,6 +46,9 @@ discard block |
||
46 | 46 | return $handle; |
47 | 47 | } |
48 | 48 | |
49 | + /** |
|
50 | + * @param resource $handle |
|
51 | + */ |
|
49 | 52 | protected function readLog($handle) |
50 | 53 | { |
51 | 54 | print("\n[Daemon]: +++ readLog() +++"); |
@@ -116,6 +119,9 @@ discard block |
||
116 | 119 | |
117 | 120 | } |
118 | 121 | |
122 | + /** |
|
123 | + * @param string $buffer |
|
124 | + */ |
|
119 | 125 | protected function parseIP($buffer) |
120 | 126 | { |
121 | 127 | $ip = ""; |
@@ -134,6 +140,9 @@ discard block |
||
134 | 140 | return $ip; |
135 | 141 | } |
136 | 142 | |
143 | + /** |
|
144 | + * @param string $buffer |
|
145 | + */ |
|
137 | 146 | protected function parseHostname($buffer) |
138 | 147 | { |
139 | 148 | $hostname = ""; |
@@ -152,6 +161,9 @@ discard block |
||
152 | 161 | return $hostname; |
153 | 162 | } |
154 | 163 | |
164 | + /** |
|
165 | + * @param string $line |
|
166 | + */ |
|
155 | 167 | protected function parseExit($line) |
156 | 168 | { |
157 | 169 | $exit = 0; |
@@ -196,6 +208,9 @@ discard block |
||
196 | 208 | |
197 | 209 | } |
198 | 210 | |
211 | + /** |
|
212 | + * @param integer $id |
|
213 | + */ |
|
199 | 214 | protected function sendVncWindowToNuc($id, $vncclient) |
200 | 215 | { |
201 | 216 | print("\n[Daemon]: +++sendVncWindowToNuc() +++ "); |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | $hostname = $this->parseHostname($buffer); |
73 | 73 | $exit = $this->parseExit($buffer); |
74 | 74 | |
75 | - if ($ip!="") { |
|
75 | + if ($ip != "") { |
|
76 | 76 | $client["ip"] = $ip; |
77 | 77 | } |
78 | - if ($hostname!="") { |
|
78 | + if ($hostname != "") { |
|
79 | 79 | $client["hostname"] = $hostname; |
80 | 80 | } |
81 | - if ($exit!=0) { |
|
81 | + if ($exit != 0) { |
|
82 | 82 | $client["exit"] = $exit; |
83 | 83 | } |
84 | 84 | |
85 | 85 | if (strstr($buffer, 'create_image') && $client["ip"] != "" && |
86 | - $client["hostname"]!="" ) { |
|
86 | + $client["hostname"] != "") { |
|
87 | 87 | |
88 | 88 | // add client |
89 | 89 | $this->addClient($client["ip"], $client["hostname"]); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - $halt=$this->_CONNECTIONS; |
|
105 | + $halt = $this->_CONNECTIONS; |
|
106 | 106 | |
107 | 107 | if ($halt == -1) { |
108 | 108 | exit(0); |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | $ip = ""; |
122 | 122 | $line = $buffer; |
123 | 123 | if (strpos($line, "Reverse VNC connection from IP")) { |
124 | - $line=trim($line); |
|
125 | - $item=explode(":", $line); |
|
126 | - $ip=trim($item[1]); |
|
127 | - $ip=preg_replace('/\W\W\d{4}\/\d{2}\/\d{2} \d{2}/', '', $ip); |
|
124 | + $line = trim($line); |
|
125 | + $item = explode(":", $line); |
|
126 | + $ip = trim($item[1]); |
|
127 | + $ip = preg_replace('/\W\W\d{4}\/\d{2}\/\d{2} \d{2}/', '', $ip); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ($ip!="") { |
|
130 | + if ($ip != "") { |
|
131 | 131 | print("\nFOUND IP: " . $ip . "\n"); |
132 | 132 | } |
133 | 133 | |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | $hostname = ""; |
140 | 140 | $line = $buffer; |
141 | 141 | if (strpos($line, "Hostname")) { |
142 | - $line=trim($line); |
|
143 | - $item=explode(":", $line); |
|
144 | - $hostname=trim($item[1]); |
|
145 | - $hostname=preg_replace('/\.uni\-mannheim\.de/', '', $hostname); |
|
142 | + $line = trim($line); |
|
143 | + $item = explode(":", $line); |
|
144 | + $hostname = trim($item[1]); |
|
145 | + $hostname = preg_replace('/\.uni\-mannheim\.de/', '', $hostname); |
|
146 | 146 | } |
147 | 147 | |
148 | - if ($hostname!="") { |
|
148 | + if ($hostname != "") { |
|
149 | 149 | print("\nFOUND HOSTNAME: " . $hostname . "\n"); |
150 | 150 | } |
151 | 151 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $exit = 1; |
160 | 160 | } |
161 | 161 | |
162 | - if ($exit!=0) { |
|
162 | + if ($exit != 0) { |
|
163 | 163 | print("\nCLIENT HAS DISCONNECTED " . $exit . "\n"); |
164 | 164 | } |
165 | 165 | |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | "exit" => 0 |
176 | 176 | ); |
177 | 177 | if (count($this->_VNC_CLIENTS) == 0) { |
178 | - $id=1; |
|
178 | + $id = 1; |
|
179 | 179 | } else { |
180 | - $id=count($this->_VNC_CLIENTS) + 1; |
|
180 | + $id = count($this->_VNC_CLIENTS)+1; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | $this->_VNC_CLIENTS[$id] = $vncclient; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | $this->_CONNECTIONS++; |
193 | 193 | |
194 | - print("\n active connections: ".$this->_CONNECTIONS+1); |
|
194 | + print("\n active connections: " . $this->_CONNECTIONS+1); |
|
195 | 195 | print("\n all saved clients: " . serialize($this->_VNC_CLIENTS)); |
196 | 196 | |
197 | 197 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | |
304 | 304 | foreach ($inactive_vnc_window_ids as $inactive_win_id) { |
305 | 305 | // define vnc-id |
306 | - $inactive_vnc_id = $db->querySingle("SELECT file FROM window WHERE win_id='".$inactive_win_id."'"); |
|
306 | + $inactive_vnc_id = $db->querySingle("SELECT file FROM window WHERE win_id='" . $inactive_win_id . "'"); |
|
307 | 307 | |
308 | 308 | // delete from database (send to control.php) |
309 | 309 | $curl = curl_init(); |
@@ -387,7 +387,7 @@ |
||
387 | 387 | // {AFTER | BEFORE} {DELETE | INSERT | UPDATE } ON table |
388 | 388 | //~ $db->exec("CREATE TRIGGER dbchange AFTER UPDATE ON user |
389 | 389 | //~ BEGIN |
390 | - //~ dbModifiedCallback(); |
|
390 | + //~ dbModifiedCallback(); |
|
391 | 391 | //~ END"); |
392 | 392 | //~ $db = new DBConnector('palma.db'); |
393 | 393 | echo "Tables=" . $db->querySingle('SELECT count(*) FROM sqlite_master WHERE type="table"') . "\n"; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | if (count($next_ids) > 0) { |
117 | 117 | $next = $next_ids[0]; |
118 | 118 | } else { |
119 | - $next = $this->querySingle('SELECT MAX(id) FROM window') + 1; |
|
119 | + $next = $this->querySingle('SELECT MAX(id) FROM window')+1; |
|
120 | 120 | } |
121 | 121 | return $next; |
122 | 122 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | // TODO: Support more than one address for a given username. |
141 | 141 | $this->exec("INSERT OR IGNORE INTO user VALUES (NULL, '$username', 1, 0)"); |
142 | 142 | $usercount = $this->querySingle("SELECT COUNT(*) FROM user"); |
143 | - $userid = $this->querySingle("SELECT userid from user where name='".$username."'"); |
|
143 | + $userid = $this->querySingle("SELECT userid from user where name='" . $username . "'"); |
|
144 | 144 | $this->exec("INSERT INTO address VALUES ('$userid', '$address', '$device')"); |
145 | 145 | trace("user $username connected with $device, $usercount user(s) now connected"); |
146 | 146 | if ($usercount == 1) { |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | |
234 | 234 | public function getWindowState($window_id) |
235 | 235 | { |
236 | - $state = @$this->querySingle('SELECT state FROM window WHERE win_id="'.$window_id.'"'); |
|
236 | + $state = @$this->querySingle('SELECT state FROM window WHERE win_id="' . $window_id . '"'); |
|
237 | 237 | return $state; |
238 | 238 | } |
239 | 239 | |
240 | 240 | public function setWindowState($window_id, $state) |
241 | 241 | { |
242 | - $this->exec('UPDATE window SET state="'.$state.'" WHERE win_id="'.$window_id.'"'); |
|
242 | + $this->exec('UPDATE window SET state="' . $state . '" WHERE win_id="' . $window_id . '"'); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | public function insertWindow($window) |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | public function deleteWindow($window_id) |
259 | 259 | { |
260 | - $this->exec('DELETE FROM window WHERE win_id="'.$window_id.'"'); |
|
260 | + $this->exec('DELETE FROM window WHERE win_id="' . $window_id . '"'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /* |
@@ -268,12 +268,12 @@ discard block |
||
268 | 268 | |
269 | 269 | public function deleteDebug($table, $id, $gt) |
270 | 270 | { |
271 | - $this->exec('DELETE FROM '.$table.' WHERE '.$id.' >"'.$gt.'"'); |
|
271 | + $this->exec('DELETE FROM ' . $table . ' WHERE ' . $id . ' >"' . $gt . '"'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | public function updateWindow($window_id, $field, $value) |
275 | 275 | { |
276 | - $this->exec('UPDATE window SET '.$field.'="'.$value.'" WHERE win_id="'.$window_id.'"'); |
|
276 | + $this->exec('UPDATE window SET ' . $field . '="' . $value . '" WHERE win_id="' . $window_id . '"'); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 |
@@ -81,14 +81,14 @@ |
||
81 | 81 | $targetFile = "file:///$targetFile"; |
82 | 82 | } |
83 | 83 | |
84 | - // Get information of application for uploaded file. |
|
85 | - require_once ('FileHandler.class.php'); |
|
86 | - $handler = FileHandler::getFileHandler($targetFile); |
|
84 | + // Get information of application for uploaded file. |
|
85 | + require_once ('FileHandler.class.php'); |
|
86 | + $handler = FileHandler::getFileHandler($targetFile); |
|
87 | 87 | |
88 | - // create window object and send to nuc |
|
88 | + // create window object and send to nuc |
|
89 | 89 | |
90 | - $dt = new DateTime(); |
|
91 | - $date = $dt->format('Y-m-d H:i:s'); |
|
90 | + $dt = new DateTime(); |
|
91 | + $date = $dt->format('Y-m-d H:i:s'); |
|
92 | 92 | |
93 | 93 | $window = array( |
94 | 94 | "id" => "", |
@@ -49,18 +49,18 @@ |
||
49 | 49 | $f = fopen($targetFile, 'w'); |
50 | 50 | if ($f) { |
51 | 51 | switch ($error) { |
52 | - case UPLOAD_ERR_INI_SIZE: |
|
53 | - $message = __("This file is too large."); |
|
54 | - break; |
|
55 | - case UPLOAD_ERR_FORM_SIZE: |
|
56 | - $message = __("Large files are not supported."); |
|
57 | - break; |
|
58 | - case UPLOAD_ERR_PARTIAL: |
|
59 | - $message = __("File was only partially uploaded."); |
|
60 | - break; |
|
61 | - default: |
|
62 | - $message = sprintf(__("Error code %s."), $error); |
|
63 | - break; |
|
52 | + case UPLOAD_ERR_INI_SIZE: |
|
53 | + $message = __("This file is too large."); |
|
54 | + break; |
|
55 | + case UPLOAD_ERR_FORM_SIZE: |
|
56 | + $message = __("Large files are not supported."); |
|
57 | + break; |
|
58 | + case UPLOAD_ERR_PARTIAL: |
|
59 | + $message = __("File was only partially uploaded."); |
|
60 | + break; |
|
61 | + default: |
|
62 | + $message = sprintf(__("Error code %s."), $error); |
|
63 | + break; |
|
64 | 64 | } |
65 | 65 | fprintf($f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\""); |
66 | 66 | fprintf($f, "\"http://www.w3.org/TR/html4/strict.dtd\">"); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
36 | 36 | // while the other constants are already available from session extension. |
37 | 37 | if (!defined('LC_MESSAGES')) { |
38 | - define('LC_MESSAGES', 5); |
|
38 | + define('LC_MESSAGES', 5); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require('streams.php'); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | /* Class to hold a single domain included in $text_domains. */ |
55 | 55 | class domain { |
56 | - var $l10n; |
|
57 | - var $path; |
|
58 | - var $codeset; |
|
56 | + var $l10n; |
|
57 | + var $path; |
|
58 | + var $codeset; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | // Utility functions |
@@ -64,50 +64,50 @@ discard block |
||
64 | 64 | * Return a list of locales to try for any POSIX-style locale specification. |
65 | 65 | */ |
66 | 66 | function get_list_of_locales($locale) { |
67 | - /* Figure out all possible locale names and start with the most |
|
67 | + /* Figure out all possible locale names and start with the most |
|
68 | 68 | * specific ones. I.e. for sr_CS.UTF-8@latin, look through all of |
69 | 69 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
70 | 70 | */ |
71 | - $locale_names = array(); |
|
72 | - $lang = NULL; |
|
73 | - $country = NULL; |
|
74 | - $charset = NULL; |
|
75 | - $modifier = NULL; |
|
76 | - if ($locale) { |
|
71 | + $locale_names = array(); |
|
72 | + $lang = NULL; |
|
73 | + $country = NULL; |
|
74 | + $charset = NULL; |
|
75 | + $modifier = NULL; |
|
76 | + if ($locale) { |
|
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | - ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | - ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | - $locale, $matches)) { |
|
78 | + ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | + ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | + $locale, $matches)) { |
|
82 | 82 | |
83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
83 | + if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | + if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | + if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | + if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
87 | 87 | |
88 | - if ($modifier) { |
|
88 | + if ($modifier) { |
|
89 | 89 | if ($country) { |
90 | - if ($charset) |
|
90 | + if ($charset) |
|
91 | 91 | array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
92 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
92 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
93 | 93 | } elseif ($charset) |
94 | 94 | array_push($locale_names, "${lang}.$charset@$modifier"); |
95 | 95 | array_push($locale_names, "$lang@$modifier"); |
96 | - } |
|
97 | - if ($country) { |
|
96 | + } |
|
97 | + if ($country) { |
|
98 | 98 | if ($charset) |
99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
99 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
100 | 100 | array_push($locale_names, "${lang}_$country"); |
101 | - } elseif ($charset) |
|
102 | - array_push($locale_names, "${lang}.$charset"); |
|
103 | - array_push($locale_names, $lang); |
|
101 | + } elseif ($charset) |
|
102 | + array_push($locale_names, "${lang}.$charset"); |
|
103 | + array_push($locale_names, $lang); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // If the locale name doesn't match POSIX style, just include it as-is. |
107 | 107 | if (!in_array($locale, $locale_names)) |
108 | - array_push($locale_names, $locale); |
|
109 | - } |
|
110 | - return $locale_names; |
|
108 | + array_push($locale_names, $locale); |
|
109 | + } |
|
110 | + return $locale_names; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | $locale_names = get_list_of_locales($locale); |
127 | 127 | $input = null; |
128 | 128 | foreach ($locale_names as $locale) { |
129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | - if (file_exists($full_path)) { |
|
129 | + $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | + if (file_exists($full_path)) { |
|
131 | 131 | $input = new FileReader($full_path); |
132 | 132 | break; |
133 | - } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | if (!array_key_exists($domain, $text_domains)) { |
137 | - // Initialize an empty domain object. |
|
138 | - $text_domains[$domain] = new domain(); |
|
137 | + // Initialize an empty domain object. |
|
138 | + $text_domains[$domain] = new domain(); |
|
139 | 139 | } |
140 | 140 | $text_domains[$domain]->l10n = new gettext_reader($input, |
141 | - $enable_cache); |
|
141 | + $enable_cache); |
|
142 | 142 | } |
143 | 143 | return $text_domains[$domain]->l10n; |
144 | 144 | } |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
192 | 192 | */ |
193 | 193 | function _get_default_locale($locale) { |
194 | - if ($locale == '') // emulate variable support |
|
194 | + if ($locale == '') // emulate variable support |
|
195 | 195 | return getenv('LANG'); |
196 | - else |
|
196 | + else |
|
197 | 197 | return $locale; |
198 | 198 | } |
199 | 199 | |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | return _setlocale($category, $CURRENTLOCALE); |
212 | 212 | } else { |
213 | 213 | if (function_exists('setlocale')) { |
214 | - $ret = setlocale($category, $locale); |
|
215 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
214 | + $ret = setlocale($category, $locale); |
|
215 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
216 | 216 | ($locale != '' and $ret != $locale)) { // failed setting it |
217 | 217 | // Failed setting it according to environment. |
218 | 218 | $CURRENTLOCALE = _get_default_locale($locale); |
219 | 219 | $EMULATEGETTEXT = 1; |
220 | - } else { |
|
220 | + } else { |
|
221 | 221 | $CURRENTLOCALE = $ret; |
222 | 222 | $EMULATEGETTEXT = 0; |
223 | - } |
|
223 | + } |
|
224 | 224 | } else { |
225 | - // No function setlocale(), emulate it all. |
|
226 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
227 | - $EMULATEGETTEXT = 1; |
|
225 | + // No function setlocale(), emulate it all. |
|
226 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
227 | + $EMULATEGETTEXT = 1; |
|
228 | 228 | } |
229 | 229 | // Allow locale to be changed on the go for one translation domain. |
230 | 230 | global $text_domains, $default_domain; |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | global $text_domains; |
243 | 243 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
244 | 244 | if (substr(php_uname(), 0, 7) == "Windows") { |
245 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
245 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
246 | 246 | $path .= '\\'; |
247 | 247 | } else { |
248 | - if ($path[strlen($path)-1] != '/') |
|
248 | + if ($path[strlen($path)-1] != '/') |
|
249 | 249 | $path .= '/'; |
250 | 250 | } |
251 | 251 | if (!array_key_exists($domain, $text_domains)) { |
252 | - // Initialize an empty domain object. |
|
253 | - $text_domains[$domain] = new domain(); |
|
252 | + // Initialize an empty domain object. |
|
253 | + $text_domains[$domain] = new domain(); |
|
254 | 254 | } |
255 | 255 | $text_domains[$domain]->path = $path; |
256 | 256 | } |
@@ -427,29 +427,29 @@ discard block |
||
427 | 427 | } |
428 | 428 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
429 | 429 | if (_check_locale_and_function()) |
430 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
430 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
431 | 431 | else return _dcngettext($domain, $singular, $plural, $number, $category); |
432 | 432 | } |
433 | 433 | |
434 | 434 | function T_pgettext($context, $msgid) { |
435 | - if (_check_locale_and_function('pgettext')) |
|
436 | - return pgettext($context, $msgid); |
|
437 | - else |
|
438 | - return _pgettext($context, $msgid); |
|
435 | + if (_check_locale_and_function('pgettext')) |
|
436 | + return pgettext($context, $msgid); |
|
437 | + else |
|
438 | + return _pgettext($context, $msgid); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | function T_dpgettext($domain, $context, $msgid) { |
442 | - if (_check_locale_and_function('dpgettext')) |
|
443 | - return dpgettext($domain, $context, $msgid); |
|
444 | - else |
|
445 | - return _dpgettext($domain, $context, $msgid); |
|
442 | + if (_check_locale_and_function('dpgettext')) |
|
443 | + return dpgettext($domain, $context, $msgid); |
|
444 | + else |
|
445 | + return _dpgettext($domain, $context, $msgid); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | function T_dcpgettext($domain, $context, $msgid, $category) { |
449 | - if (_check_locale_and_function('dcpgettext')) |
|
450 | - return dcpgettext($domain, $context, $msgid, $category); |
|
451 | - else |
|
452 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
449 | + if (_check_locale_and_function('dcpgettext')) |
|
450 | + return dcpgettext($domain, $context, $msgid, $category); |
|
451 | + else |
|
452 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | function T_npgettext($context, $singular, $plural, $number) { |
@@ -460,17 +460,17 @@ discard block |
||
460 | 460 | } |
461 | 461 | |
462 | 462 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
463 | - if (_check_locale_and_function('dnpgettext')) |
|
464 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
465 | - else |
|
466 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
463 | + if (_check_locale_and_function('dnpgettext')) |
|
464 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
465 | + else |
|
466 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | function T_dcnpgettext($domain, $context, $singular, $plural, |
470 | - $number, $category) { |
|
470 | + $number, $category) { |
|
471 | 471 | if (_check_locale_and_function('dcnpgettext')) |
472 | 472 | return dcnpgettext($domain, $context, $singular, |
473 | - $plural, $number, $category); |
|
473 | + $plural, $number, $category); |
|
474 | 474 | else |
475 | 475 | return _dcnpgettext($domain, $context, $singular, |
476 | 476 | $plural, $number, $category); |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | return _dcpgettext($domain, $context, $msgid, $category); |
528 | 528 | } |
529 | 529 | function dcnpgettext($domain, $context, $singular, $plural, |
530 | - $number, $category) { |
|
531 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
532 | - $number, $category); |
|
530 | + $number, $category) { |
|
531 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
532 | + $number, $category); |
|
533 | 533 | } |
534 | 534 | } |
535 | 535 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
36 | 36 | // while the other constants are already available from session extension. |
37 | 37 | if (!defined('LC_MESSAGES')) { |
38 | - define('LC_MESSAGES', 5); |
|
38 | + define('LC_MESSAGES', 5); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require('streams.php'); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | 78 | ."(?:_(?P<country>[A-Z]{2}))?" // country code |
79 | 79 | ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | 81 | $locale, $matches)) { |
82 | 82 | |
83 | 83 | if (isset($matches["lang"])) $lang = $matches["lang"]; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * Utility function to get a StreamReader for the given text domain. |
115 | 115 | */ |
116 | -function _get_reader($domain=null, $category=5, $enable_cache=true) { |
|
116 | +function _get_reader($domain = null, $category = 5, $enable_cache = true) { |
|
117 | 117 | global $text_domains, $default_domain, $LC_CATEGORIES; |
118 | 118 | if (!isset($domain)) $domain = $default_domain; |
119 | 119 | if (!isset($text_domains[$domain]->l10n)) { |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $locale = _setlocale(LC_MESSAGES, 0); |
122 | 122 | $bound_path = isset($text_domains[$domain]->path) ? |
123 | 123 | $text_domains[$domain]->path : './'; |
124 | - $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
124 | + $subpath = $LC_CATEGORIES[$category] . "/$domain.mo"; |
|
125 | 125 | |
126 | 126 | $locale_names = get_list_of_locales($locale); |
127 | 127 | $input = null; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * Checks if the current locale is supported on this system. |
156 | 156 | */ |
157 | -function _check_locale_and_function($function=false) { |
|
157 | +function _check_locale_and_function($function = false) { |
|
158 | 158 | global $EMULATEGETTEXT; |
159 | 159 | if ($function and !function_exists($function)) |
160 | 160 | return false; |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | /** |
165 | 165 | * Get the codeset for the given domain. |
166 | 166 | */ |
167 | -function _get_codeset($domain=null) { |
|
167 | +function _get_codeset($domain = null) { |
|
168 | 168 | global $text_domains, $default_domain, $LC_CATEGORIES; |
169 | 169 | if (!isset($domain)) $domain = $default_domain; |
170 | - return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
170 | + return (isset($text_domains[$domain]->codeset)) ? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -80,32 +80,45 @@ discard block |
||
80 | 80 | ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
81 | 81 | $locale, $matches)) { |
82 | 82 | |
83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
83 | + if (isset($matches["lang"])) { |
|
84 | + $lang = $matches["lang"]; |
|
85 | + } |
|
86 | + if (isset($matches["country"])) { |
|
87 | + $country = $matches["country"]; |
|
88 | + } |
|
89 | + if (isset($matches["charset"])) { |
|
90 | + $charset = $matches["charset"]; |
|
91 | + } |
|
92 | + if (isset($matches["modifier"])) { |
|
93 | + $modifier = $matches["modifier"]; |
|
94 | + } |
|
87 | 95 | |
88 | 96 | if ($modifier) { |
89 | 97 | if ($country) { |
90 | - if ($charset) |
|
91 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
98 | + if ($charset) { |
|
99 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
100 | + } |
|
92 | 101 | array_push($locale_names, "${lang}_$country@$modifier"); |
93 | - } elseif ($charset) |
|
94 | - array_push($locale_names, "${lang}.$charset@$modifier"); |
|
102 | + } elseif ($charset) { |
|
103 | + array_push($locale_names, "${lang}.$charset@$modifier"); |
|
104 | + } |
|
95 | 105 | array_push($locale_names, "$lang@$modifier"); |
96 | 106 | } |
97 | 107 | if ($country) { |
98 | - if ($charset) |
|
99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
108 | + if ($charset) { |
|
109 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
110 | + } |
|
100 | 111 | array_push($locale_names, "${lang}_$country"); |
101 | - } elseif ($charset) |
|
102 | - array_push($locale_names, "${lang}.$charset"); |
|
112 | + } elseif ($charset) { |
|
113 | + array_push($locale_names, "${lang}.$charset"); |
|
114 | + } |
|
103 | 115 | array_push($locale_names, $lang); |
104 | 116 | } |
105 | 117 | |
106 | 118 | // If the locale name doesn't match POSIX style, just include it as-is. |
107 | - if (!in_array($locale, $locale_names)) |
|
108 | - array_push($locale_names, $locale); |
|
119 | + if (!in_array($locale, $locale_names)) { |
|
120 | + array_push($locale_names, $locale); |
|
121 | + } |
|
109 | 122 | } |
110 | 123 | return $locale_names; |
111 | 124 | } |
@@ -115,7 +128,9 @@ discard block |
||
115 | 128 | */ |
116 | 129 | function _get_reader($domain=null, $category=5, $enable_cache=true) { |
117 | 130 | global $text_domains, $default_domain, $LC_CATEGORIES; |
118 | - if (!isset($domain)) $domain = $default_domain; |
|
131 | + if (!isset($domain)) { |
|
132 | + $domain = $default_domain; |
|
133 | + } |
|
119 | 134 | if (!isset($text_domains[$domain]->l10n)) { |
120 | 135 | // get the current locale |
121 | 136 | $locale = _setlocale(LC_MESSAGES, 0); |
@@ -156,8 +171,9 @@ discard block |
||
156 | 171 | */ |
157 | 172 | function _check_locale_and_function($function=false) { |
158 | 173 | global $EMULATEGETTEXT; |
159 | - if ($function and !function_exists($function)) |
|
160 | - return false; |
|
174 | + if ($function and !function_exists($function)) { |
|
175 | + return false; |
|
176 | + } |
|
161 | 177 | return !$EMULATEGETTEXT; |
162 | 178 | } |
163 | 179 | |
@@ -166,7 +182,9 @@ discard block |
||
166 | 182 | */ |
167 | 183 | function _get_codeset($domain=null) { |
168 | 184 | global $text_domains, $default_domain, $LC_CATEGORIES; |
169 | - if (!isset($domain)) $domain = $default_domain; |
|
185 | + if (!isset($domain)) { |
|
186 | + $domain = $default_domain; |
|
187 | + } |
|
170 | 188 | return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
171 | 189 | } |
172 | 190 | |
@@ -178,8 +196,7 @@ discard block |
||
178 | 196 | $target_encoding = _get_codeset(); |
179 | 197 | if ($source_encoding != $target_encoding) { |
180 | 198 | return mb_convert_encoding($text, $target_encoding, $source_encoding); |
181 | - } |
|
182 | - else { |
|
199 | + } else { |
|
183 | 200 | return $text; |
184 | 201 | } |
185 | 202 | } |
@@ -191,11 +208,13 @@ discard block |
||
191 | 208 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
192 | 209 | */ |
193 | 210 | function _get_default_locale($locale) { |
194 | - if ($locale == '') // emulate variable support |
|
211 | + if ($locale == '') { |
|
212 | + // emulate variable support |
|
195 | 213 | return getenv('LANG'); |
196 | - else |
|
197 | - return $locale; |
|
198 | -} |
|
214 | + } else { |
|
215 | + return $locale; |
|
216 | + } |
|
217 | + } |
|
199 | 218 | |
200 | 219 | /** |
201 | 220 | * Sets a requested locale, if needed emulates it. |
@@ -203,12 +222,13 @@ discard block |
||
203 | 222 | function _setlocale($category, $locale) { |
204 | 223 | global $CURRENTLOCALE, $EMULATEGETTEXT; |
205 | 224 | if ($locale === 0) { // use === to differentiate between string "0" |
206 | - if ($CURRENTLOCALE != '') |
|
207 | - return $CURRENTLOCALE; |
|
208 | - else |
|
209 | - // obey LANG variable, maybe extend to support all of LC_* vars |
|
225 | + if ($CURRENTLOCALE != '') { |
|
226 | + return $CURRENTLOCALE; |
|
227 | + } else { |
|
228 | + // obey LANG variable, maybe extend to support all of LC_* vars |
|
210 | 229 | // even if we tried to read locale without setting it first |
211 | 230 | return _setlocale($category, $CURRENTLOCALE); |
231 | + } |
|
212 | 232 | } else { |
213 | 233 | if (function_exists('setlocale')) { |
214 | 234 | $ret = setlocale($category, $locale); |
@@ -242,11 +262,13 @@ discard block |
||
242 | 262 | global $text_domains; |
243 | 263 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
244 | 264 | if (substr(php_uname(), 0, 7) == "Windows") { |
245 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
246 | - $path .= '\\'; |
|
265 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') { |
|
266 | + $path .= '\\'; |
|
267 | + } |
|
247 | 268 | } else { |
248 | - if ($path[strlen($path)-1] != '/') |
|
249 | - $path .= '/'; |
|
269 | + if ($path[strlen($path)-1] != '/') { |
|
270 | + $path .= '/'; |
|
271 | + } |
|
250 | 272 | } |
251 | 273 | if (!array_key_exists($domain, $text_domains)) { |
252 | 274 | // Initialize an empty domain object. |
@@ -385,96 +407,126 @@ discard block |
||
385 | 407 | } |
386 | 408 | |
387 | 409 | function T_bindtextdomain($domain, $path) { |
388 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
389 | - else return _bindtextdomain($domain, $path); |
|
390 | -} |
|
410 | + if (_check_locale_and_function()) { |
|
411 | + return bindtextdomain($domain, $path); |
|
412 | + } else { |
|
413 | + return _bindtextdomain($domain, $path); |
|
414 | + } |
|
415 | + } |
|
391 | 416 | function T_bind_textdomain_codeset($domain, $codeset) { |
392 | 417 | // bind_textdomain_codeset is available only in PHP 4.2.0+ |
393 | - if (_check_locale_and_function('bind_textdomain_codeset')) |
|
394 | - return bind_textdomain_codeset($domain, $codeset); |
|
395 | - else return _bind_textdomain_codeset($domain, $codeset); |
|
396 | -} |
|
418 | + if (_check_locale_and_function('bind_textdomain_codeset')) { |
|
419 | + return bind_textdomain_codeset($domain, $codeset); |
|
420 | + } else { |
|
421 | + return _bind_textdomain_codeset($domain, $codeset); |
|
422 | + } |
|
423 | + } |
|
397 | 424 | function T_textdomain($domain) { |
398 | - if (_check_locale_and_function()) return textdomain($domain); |
|
399 | - else return _textdomain($domain); |
|
400 | -} |
|
425 | + if (_check_locale_and_function()) { |
|
426 | + return textdomain($domain); |
|
427 | + } else { |
|
428 | + return _textdomain($domain); |
|
429 | + } |
|
430 | + } |
|
401 | 431 | function T_gettext($msgid) { |
402 | - if (_check_locale_and_function()) return gettext($msgid); |
|
403 | - else return _gettext($msgid); |
|
404 | -} |
|
432 | + if (_check_locale_and_function()) { |
|
433 | + return gettext($msgid); |
|
434 | + } else { |
|
435 | + return _gettext($msgid); |
|
436 | + } |
|
437 | + } |
|
405 | 438 | function T_($msgid) { |
406 | - if (_check_locale_and_function()) return _($msgid); |
|
439 | + if (_check_locale_and_function()) { |
|
440 | + return _($msgid); |
|
441 | + } |
|
407 | 442 | return __($msgid); |
408 | 443 | } |
409 | 444 | function T_ngettext($singular, $plural, $number) { |
410 | - if (_check_locale_and_function()) |
|
411 | - return ngettext($singular, $plural, $number); |
|
412 | - else return _ngettext($singular, $plural, $number); |
|
413 | -} |
|
445 | + if (_check_locale_and_function()) { |
|
446 | + return ngettext($singular, $plural, $number); |
|
447 | + } else { |
|
448 | + return _ngettext($singular, $plural, $number); |
|
449 | + } |
|
450 | + } |
|
414 | 451 | function T_dgettext($domain, $msgid) { |
415 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
416 | - else return _dgettext($domain, $msgid); |
|
417 | -} |
|
452 | + if (_check_locale_and_function()) { |
|
453 | + return dgettext($domain, $msgid); |
|
454 | + } else { |
|
455 | + return _dgettext($domain, $msgid); |
|
456 | + } |
|
457 | + } |
|
418 | 458 | function T_dngettext($domain, $singular, $plural, $number) { |
419 | - if (_check_locale_and_function()) |
|
420 | - return dngettext($domain, $singular, $plural, $number); |
|
421 | - else return _dngettext($domain, $singular, $plural, $number); |
|
422 | -} |
|
459 | + if (_check_locale_and_function()) { |
|
460 | + return dngettext($domain, $singular, $plural, $number); |
|
461 | + } else { |
|
462 | + return _dngettext($domain, $singular, $plural, $number); |
|
463 | + } |
|
464 | + } |
|
423 | 465 | function T_dcgettext($domain, $msgid, $category) { |
424 | - if (_check_locale_and_function()) |
|
425 | - return dcgettext($domain, $msgid, $category); |
|
426 | - else return _dcgettext($domain, $msgid, $category); |
|
427 | -} |
|
466 | + if (_check_locale_and_function()) { |
|
467 | + return dcgettext($domain, $msgid, $category); |
|
468 | + } else { |
|
469 | + return _dcgettext($domain, $msgid, $category); |
|
470 | + } |
|
471 | + } |
|
428 | 472 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
429 | - if (_check_locale_and_function()) |
|
430 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
431 | - else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
432 | -} |
|
473 | + if (_check_locale_and_function()) { |
|
474 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
475 | + } else { |
|
476 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
477 | + } |
|
478 | + } |
|
433 | 479 | |
434 | 480 | function T_pgettext($context, $msgid) { |
435 | - if (_check_locale_and_function('pgettext')) |
|
436 | - return pgettext($context, $msgid); |
|
437 | - else |
|
438 | - return _pgettext($context, $msgid); |
|
439 | -} |
|
481 | + if (_check_locale_and_function('pgettext')) { |
|
482 | + return pgettext($context, $msgid); |
|
483 | + } else { |
|
484 | + return _pgettext($context, $msgid); |
|
485 | + } |
|
486 | + } |
|
440 | 487 | |
441 | 488 | function T_dpgettext($domain, $context, $msgid) { |
442 | - if (_check_locale_and_function('dpgettext')) |
|
443 | - return dpgettext($domain, $context, $msgid); |
|
444 | - else |
|
445 | - return _dpgettext($domain, $context, $msgid); |
|
446 | -} |
|
489 | + if (_check_locale_and_function('dpgettext')) { |
|
490 | + return dpgettext($domain, $context, $msgid); |
|
491 | + } else { |
|
492 | + return _dpgettext($domain, $context, $msgid); |
|
493 | + } |
|
494 | + } |
|
447 | 495 | |
448 | 496 | function T_dcpgettext($domain, $context, $msgid, $category) { |
449 | - if (_check_locale_and_function('dcpgettext')) |
|
450 | - return dcpgettext($domain, $context, $msgid, $category); |
|
451 | - else |
|
452 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
453 | -} |
|
497 | + if (_check_locale_and_function('dcpgettext')) { |
|
498 | + return dcpgettext($domain, $context, $msgid, $category); |
|
499 | + } else { |
|
500 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
501 | + } |
|
502 | + } |
|
454 | 503 | |
455 | 504 | function T_npgettext($context, $singular, $plural, $number) { |
456 | - if (_check_locale_and_function('npgettext')) |
|
457 | - return npgettext($context, $singular, $plural, $number); |
|
458 | - else |
|
459 | - return _npgettext($context, $singular, $plural, $number); |
|
460 | -} |
|
505 | + if (_check_locale_and_function('npgettext')) { |
|
506 | + return npgettext($context, $singular, $plural, $number); |
|
507 | + } else { |
|
508 | + return _npgettext($context, $singular, $plural, $number); |
|
509 | + } |
|
510 | + } |
|
461 | 511 | |
462 | 512 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
463 | - if (_check_locale_and_function('dnpgettext')) |
|
464 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
465 | - else |
|
466 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
467 | -} |
|
513 | + if (_check_locale_and_function('dnpgettext')) { |
|
514 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
515 | + } else { |
|
516 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
517 | + } |
|
518 | + } |
|
468 | 519 | |
469 | 520 | function T_dcnpgettext($domain, $context, $singular, $plural, |
470 | 521 | $number, $category) { |
471 | - if (_check_locale_and_function('dcnpgettext')) |
|
472 | - return dcnpgettext($domain, $context, $singular, |
|
522 | + if (_check_locale_and_function('dcnpgettext')) { |
|
523 | + return dcnpgettext($domain, $context, $singular, |
|
473 | 524 | $plural, $number, $category); |
474 | - else |
|
475 | - return _dcnpgettext($domain, $context, $singular, |
|
525 | + } else { |
|
526 | + return _dcnpgettext($domain, $context, $singular, |
|
476 | 527 | $plural, $number, $category); |
477 | -} |
|
528 | + } |
|
529 | + } |
|
478 | 530 | |
479 | 531 | |
480 | 532 |
@@ -22,7 +22,7 @@ |
||
22 | 22 | if (file_exists($filepath)) { |
23 | 23 | // file exists: return file for download |
24 | 24 | header('Content-Type: application/octet-stream'); |
25 | - header('Content-Disposition: attachment; filename="'.addslashes($filename).'"'); |
|
25 | + header('Content-Disposition: attachment; filename="' . addslashes($filename) . '"'); |
|
26 | 26 | readfile($filepath); |
27 | 27 | } else { |
28 | 28 | // file does not exist: 404 Not Found |
@@ -92,7 +92,7 @@ |
||
92 | 92 | if (is_dir($pictures)) { |
93 | 93 | $filelist = scandir($pictures); |
94 | 94 | sort($filelist, SORT_NATURAL); |
95 | - foreach($filelist as $file) { |
|
95 | + foreach ($filelist as $file) { |
|
96 | 96 | $picture = "$pictures/$file"; |
97 | 97 | if (is_file($picture)) { |
98 | 98 | echo("<li style=\"background-image: url('$picture'); background-repeat: no-repeat\"></li>\n"); |
@@ -62,9 +62,9 @@ |
||
62 | 62 | function getControls() |
63 | 63 | { |
64 | 64 | return FileHandler::CURSOR | FileHandler::ZOOM | |
65 | - FileHandler::HOME | FileHandler::END | |
|
66 | - FileHandler::PRIOR | FileHandler::NEXT | |
|
67 | - FileHandler::DOWNLOAD; |
|
65 | + FileHandler::HOME | FileHandler::END | |
|
66 | + FileHandler::PRIOR | FileHandler::NEXT | |
|
67 | + FileHandler::DOWNLOAD; |
|
68 | 68 | } |
69 | 69 | function show($path) |
70 | 70 | { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | // Shortcuts for combinations of controls. |
91 | 91 | const CURSOR = 15; // UP | DOWN | LEFT | RIGHT |
92 | - const ZOOM = 48; // ZOOMIN | ZOOMOUT |
|
92 | + const ZOOM = 48; // ZOOMIN | ZOOMOUT |
|
93 | 93 | const ALL = 2047; |
94 | 94 | |
95 | 95 | // up down left right zoomin zoomout home end prior next download |
@@ -108,27 +108,27 @@ discard block |
||
108 | 108 | // $params; |
109 | 109 | // echo $ftype; |
110 | 110 | if ($ftype === 'pdf') { |
111 | - $fhandler='/usr/bin/zathura'; |
|
111 | + $fhandler = '/usr/bin/zathura'; |
|
112 | 112 | |
113 | 113 | } elseif ($ftype === 'gif' || $ftype === 'jpg' || $ftype === 'png') { |
114 | - $fhandler='/usr/bin/eog'; |
|
114 | + $fhandler = '/usr/bin/eog'; |
|
115 | 115 | |
116 | 116 | } elseif ($ftype === 'doc' || $ftype === 'docx' || $ftype === 'odt' || $ftype === 'txt') { |
117 | - $fhandler='/usr/bin/libreoffice --writer -o -n --nologo --norestore --view'; |
|
117 | + $fhandler = '/usr/bin/libreoffice --writer -o -n --nologo --norestore --view'; |
|
118 | 118 | |
119 | 119 | } elseif ($ftype === 'ppt' || $ftype === 'pptx' || $ftype === 'pps' || $ftype === 'ppsx' || $ftype === 'odp') { |
120 | 120 | // optional --show (presentation mode) |
121 | - $fhandler='/usr/bin/libreoffice --impress -o -n --nologo --norestore --view'; |
|
121 | + $fhandler = '/usr/bin/libreoffice --impress -o -n --nologo --norestore --view'; |
|
122 | 122 | |
123 | 123 | } elseif ($ftype === 'xls' || $ftype === 'xlsx' || $ftype === 'ods') { |
124 | - $fhandler='/usr/bin/libreoffice --calc -o -n --nologo --norestore --view'; |
|
124 | + $fhandler = '/usr/bin/libreoffice --calc -o -n --nologo --norestore --view'; |
|
125 | 125 | |
126 | 126 | } elseif ($ftype === 'html' || $ftype === 'url') { |
127 | - $fhandler='/usr/bin/dwb --override-restore'; |
|
127 | + $fhandler = '/usr/bin/dwb --override-restore'; |
|
128 | 128 | |
129 | 129 | } elseif ($ftype === 'mpg' || $ftype === 'mpeg' || $ftype === 'avi' || |
130 | 130 | $ftype === 'mp3' || $ftype === 'mp4') { |
131 | - $fhandler='/usr/bin/cvlc --no-audio'; |
|
131 | + $fhandler = '/usr/bin/cvlc --no-audio'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /* |