@@ -6,10 +6,10 @@ |
||
6 | 6 | |
7 | 7 | $ERRORS[0] = ""; |
8 | 8 | |
9 | -$ERRORS[1] = __("This program requires XmlHttpRequest " . |
|
9 | +$ERRORS[1] = __("This program requires XmlHttpRequest ". |
|
10 | 10 | "to function properly. Your browser doesn't seem to support it."); |
11 | 11 | |
12 | -$ERRORS[2] = __("This program requires cookies " . |
|
12 | +$ERRORS[2] = __("This program requires cookies ". |
|
13 | 13 | "to function properly. Your browser doesn't seem to support them."); |
14 | 14 | |
15 | 15 | $ERRORS[3] = __("Backend sanity check failed."); |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | $entry = substr($ico, 6 + 16 * $i, 16); |
68 | 68 | if (!$entry || strlen($entry) < 16) |
69 | 69 | continue; |
70 | - $e = unpack("Cwidth/" . |
|
71 | - "Cheight/" . |
|
72 | - "Ccolors/" . |
|
73 | - "Czero/" . |
|
74 | - "vplanes/" . |
|
75 | - "vbpp/" . |
|
76 | - "Vsize/" . |
|
70 | + $e = unpack("Cwidth/". |
|
71 | + "Cheight/". |
|
72 | + "Ccolors/". |
|
73 | + "Czero/". |
|
74 | + "vplanes/". |
|
75 | + "vbpp/". |
|
76 | + "Vsize/". |
|
77 | 77 | "Voffset/", |
78 | 78 | $entry); |
79 | 79 | if ($e["width"] == 0) |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | // directory entry. |
123 | 123 | $bitmapinfo = unpack("Vsize", $data); |
124 | 124 | if ($bitmapinfo["size"] == 40) { |
125 | - $info = unpack("Vsize/" . |
|
126 | - "Vwidth/" . |
|
127 | - "Vheight/" . |
|
128 | - "vplanes/" . |
|
129 | - "vbpp/" . |
|
130 | - "Vcompress/" . |
|
131 | - "Vsize/" . |
|
132 | - "Vxres/" . |
|
133 | - "Vyres/" . |
|
134 | - "Vpalcolors/" . |
|
125 | + $info = unpack("Vsize/". |
|
126 | + "Vwidth/". |
|
127 | + "Vheight/". |
|
128 | + "vplanes/". |
|
129 | + "vbpp/". |
|
130 | + "Vcompress/". |
|
131 | + "Vsize/". |
|
132 | + "Vxres/". |
|
133 | + "Vyres/". |
|
134 | + "Vpalcolors/". |
|
135 | 135 | "Vimpcolors/", $data); |
136 | 136 | if ($e["bpp"] == 0) { |
137 | 137 | $e["bpp"] = $info["bpp"]; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $pixel1 = $palette[$p >> 4]; |
213 | 213 | $pixel2 = $palette[$p & 0x0f]; |
214 | 214 | $XOR[$y][$x] = $pixel1; |
215 | - $XOR[$y][$x+1] = $pixel2; |
|
215 | + $XOR[$y][$x + 1] = $pixel2; |
|
216 | 216 | $x += 2; |
217 | 217 | $offset++; |
218 | 218 | } elseif ($bpp == 8) { |
@@ -24,13 +24,15 @@ discard block |
||
24 | 24 | $r = ord($str[2]); |
25 | 25 | if (strlen($str) > 3) { |
26 | 26 | $a = 127 - (ord($str[3]) / 2); |
27 | - if ($a != 0 && $a != 127) |
|
28 | - $this->had_alpha = 1; |
|
27 | + if ($a != 0 && $a != 127) { |
|
28 | + $this->had_alpha = 1; |
|
29 | + } |
|
29 | 30 | } else { |
30 | 31 | $a = 0; |
31 | 32 | } |
32 | - if ($a != 127) |
|
33 | - $this->all_transaprent = 0; |
|
33 | + if ($a != 127) { |
|
34 | + $this->all_transaprent = 0; |
|
35 | + } |
|
34 | 36 | return imagecolorallocatealpha($img, $r, $g, $b, $a); |
35 | 37 | } |
36 | 38 | |
@@ -65,8 +67,9 @@ discard block |
||
65 | 67 | $most_pixels = 0; |
66 | 68 | for ($i = 0; $i < $h["num"]; $i++) { |
67 | 69 | $entry = substr($ico, 6 + 16 * $i, 16); |
68 | - if (!$entry || strlen($entry) < 16) |
|
69 | - continue; |
|
70 | + if (!$entry || strlen($entry) < 16) { |
|
71 | + continue; |
|
72 | + } |
|
70 | 73 | $e = unpack("Cwidth/" . |
71 | 74 | "Cheight/" . |
72 | 75 | "Ccolors/" . |
@@ -76,10 +79,12 @@ discard block |
||
76 | 79 | "Vsize/" . |
77 | 80 | "Voffset/", |
78 | 81 | $entry); |
79 | - if ($e["width"] == 0) |
|
80 | - $e["width"] = 256; |
|
81 | - if ($e["height"] == 0) |
|
82 | - $e["height"] = 256; |
|
82 | + if ($e["width"] == 0) { |
|
83 | + $e["width"] = 256; |
|
84 | + } |
|
85 | + if ($e["height"] == 0) { |
|
86 | + $e["height"] = 256; |
|
87 | + } |
|
83 | 88 | if ($e["zero"] != 0) { |
84 | 89 | $this->error = "nonzero reserved field"; |
85 | 90 | return false; |
@@ -226,8 +231,9 @@ discard block |
||
226 | 231 | } |
227 | 232 | } |
228 | 233 | // End of row padding |
229 | - while ($offset & 3) |
|
230 | - $offset++; |
|
234 | + while ($offset & 3) { |
|
235 | + $offset++; |
|
236 | + } |
|
231 | 237 | } |
232 | 238 | |
233 | 239 | // Now the "AND" image, which is 1 bit per pixel. Ignore |
@@ -261,8 +267,9 @@ discard block |
||
261 | 267 | } |
262 | 268 | |
263 | 269 | // End of row padding |
264 | - while ($offset & 3) |
|
265 | - $offset++; |
|
270 | + while ($offset & 3) { |
|
271 | + $offset++; |
|
272 | + } |
|
266 | 273 | } |
267 | 274 | return $img; |
268 | 275 | } |
@@ -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 | } |
@@ -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,7 +154,7 @@ 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 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
@@ -176,11 +176,11 @@ discard block |
||
176 | 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 | - if (! $length) |
|
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 | /** |
@@ -193,11 +193,11 @@ discard block |
||
193 | 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 | - if (! $length) |
|
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 | /** |
@@ -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 { |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | function select_string($n) { |
353 | 353 | if (!is_int($n)) { |
354 | 354 | throw new InvalidArgumentException( |
355 | - "Select_string only accepts integers: " . $n); |
|
355 | + "Select_string only accepts integers: ".$n); |
|
356 | 356 | } |
357 | 357 | $string = $this->get_plural_forms(); |
358 | - $string = str_replace('nplurals',"\$total",$string); |
|
359 | - $string = str_replace("n",$n,$string); |
|
360 | - $string = str_replace('plural',"\$plural",$string); |
|
358 | + $string = str_replace('nplurals', "\$total", $string); |
|
359 | + $string = str_replace("n", $n, $string); |
|
360 | + $string = str_replace('plural', "\$plural", $string); |
|
361 | 361 | |
362 | 362 | $total = 0; |
363 | 363 | $plural = 0; |
@@ -388,11 +388,11 @@ discard block |
||
388 | 388 | $select = $this->select_string($number); |
389 | 389 | |
390 | 390 | // this should contains all strings separated by NULLs |
391 | - $key = $single . chr(0) . $plural; |
|
391 | + $key = $single.chr(0).$plural; |
|
392 | 392 | |
393 | 393 | |
394 | 394 | if ($this->enable_cache) { |
395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
395 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
396 | 396 | return ($number != 1) ? $plural : $single; |
397 | 397 | } else { |
398 | 398 | $result = $this->cache_translations[$key]; |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | function pgettext($context, $msgid) { |
415 | - $key = $context . chr(4) . $msgid; |
|
415 | + $key = $context.chr(4).$msgid; |
|
416 | 416 | $ret = $this->translate($key); |
417 | 417 | if (strpos($ret, "\004") !== FALSE) { |
418 | 418 | return $msgid; |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | function npgettext($context, $singular, $plural, $number) { |
425 | - $key = $context . chr(4) . $singular; |
|
425 | + $key = $context.chr(4).$singular; |
|
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | 427 | if (strpos($ret, "\004") !== FALSE) { |
428 | 428 | return $singular; |
@@ -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 | |
@@ -363,7 +372,9 @@ discard block |
||
363 | 372 | $plural = 0; |
364 | 373 | |
365 | 374 | eval("$string"); |
366 | - if ($plural >= $total) $plural = $total - 1; |
|
375 | + if ($plural >= $total) { |
|
376 | + $plural = $total - 1; |
|
377 | + } |
|
367 | 378 | return $plural; |
368 | 379 | } |
369 | 380 | |
@@ -378,10 +389,11 @@ discard block |
||
378 | 389 | */ |
379 | 390 | function ngettext($single, $plural, $number) { |
380 | 391 | if ($this->short_circuit) { |
381 | - if ($number != 1) |
|
382 | - return $plural; |
|
383 | - else |
|
384 | - return $single; |
|
392 | + if ($number != 1) { |
|
393 | + return $plural; |
|
394 | + } else { |
|
395 | + return $single; |
|
396 | + } |
|
385 | 397 | } |
386 | 398 | |
387 | 399 | // find out the appropriate form |
@@ -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,12 +121,12 @@ 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; |
128 | 128 | foreach ($locale_names as $locale) { |
129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
129 | + $full_path = $bound_path.$locale."/".$subpath; |
|
130 | 130 | if (file_exists($full_path)) { |
131 | 131 | $input = new FileReader($full_path); |
132 | 132 | break; |
@@ -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 | /** |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | global $text_domains; |
242 | 242 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 243 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
244 | + if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
245 | 245 | $path .= '\\'; |
246 | 246 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
247 | + if ($path[strlen($path) - 1] != '/') |
|
248 | 248 | $path .= '/'; |
249 | 249 | } |
250 | 250 | if (!array_key_exists($domain, $text_domains)) { |
@@ -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 | |
@@ -177,8 +195,9 @@ discard block |
||
177 | 195 | $target_encoding = _get_codeset(); |
178 | 196 | if (function_exists("mb_detect_encoding")) { |
179 | 197 | $source_encoding = mb_detect_encoding($text); |
180 | - if ($source_encoding != $target_encoding) |
|
181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
198 | + if ($source_encoding != $target_encoding) { |
|
199 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
200 | + } |
|
182 | 201 | } |
183 | 202 | return $text; |
184 | 203 | } |
@@ -190,11 +209,13 @@ discard block |
||
190 | 209 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
191 | 210 | */ |
192 | 211 | function _get_default_locale($locale) { |
193 | - if ($locale == '') // emulate variable support |
|
212 | + if ($locale == '') { |
|
213 | + // emulate variable support |
|
194 | 214 | return getenv('LANG'); |
195 | - else |
|
196 | - return $locale; |
|
197 | -} |
|
215 | + } else { |
|
216 | + return $locale; |
|
217 | + } |
|
218 | + } |
|
198 | 219 | |
199 | 220 | /** |
200 | 221 | * Sets a requested locale, if needed emulates it. |
@@ -202,12 +223,13 @@ discard block |
||
202 | 223 | function _setlocale($category, $locale) { |
203 | 224 | global $CURRENTLOCALE, $EMULATEGETTEXT; |
204 | 225 | if ($locale === 0) { // use === to differentiate between string "0" |
205 | - if ($CURRENTLOCALE != '') |
|
206 | - return $CURRENTLOCALE; |
|
207 | - else |
|
208 | - // obey LANG variable, maybe extend to support all of LC_* vars |
|
226 | + if ($CURRENTLOCALE != '') { |
|
227 | + return $CURRENTLOCALE; |
|
228 | + } else { |
|
229 | + // obey LANG variable, maybe extend to support all of LC_* vars |
|
209 | 230 | // even if we tried to read locale without setting it first |
210 | 231 | return _setlocale($category, $CURRENTLOCALE); |
232 | + } |
|
211 | 233 | } else { |
212 | 234 | if (function_exists('setlocale')) { |
213 | 235 | $ret = setlocale($category, $locale); |
@@ -241,11 +263,13 @@ discard block |
||
241 | 263 | global $text_domains; |
242 | 264 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 265 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
245 | - $path .= '\\'; |
|
266 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') { |
|
267 | + $path .= '\\'; |
|
268 | + } |
|
246 | 269 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
248 | - $path .= '/'; |
|
270 | + if ($path[strlen($path)-1] != '/') { |
|
271 | + $path .= '/'; |
|
272 | + } |
|
249 | 273 | } |
250 | 274 | if (!array_key_exists($domain, $text_domains)) { |
251 | 275 | // Initialize an empty domain object. |
@@ -384,96 +408,126 @@ discard block |
||
384 | 408 | } |
385 | 409 | |
386 | 410 | function T_bindtextdomain($domain, $path) { |
387 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
388 | - else return _bindtextdomain($domain, $path); |
|
389 | -} |
|
411 | + if (_check_locale_and_function()) { |
|
412 | + return bindtextdomain($domain, $path); |
|
413 | + } else { |
|
414 | + return _bindtextdomain($domain, $path); |
|
415 | + } |
|
416 | + } |
|
390 | 417 | function T_bind_textdomain_codeset($domain, $codeset) { |
391 | 418 | // bind_textdomain_codeset is available only in PHP 4.2.0+ |
392 | - if (_check_locale_and_function('bind_textdomain_codeset')) |
|
393 | - return bind_textdomain_codeset($domain, $codeset); |
|
394 | - else return _bind_textdomain_codeset($domain, $codeset); |
|
395 | -} |
|
419 | + if (_check_locale_and_function('bind_textdomain_codeset')) { |
|
420 | + return bind_textdomain_codeset($domain, $codeset); |
|
421 | + } else { |
|
422 | + return _bind_textdomain_codeset($domain, $codeset); |
|
423 | + } |
|
424 | + } |
|
396 | 425 | function T_textdomain($domain) { |
397 | - if (_check_locale_and_function()) return textdomain($domain); |
|
398 | - else return _textdomain($domain); |
|
399 | -} |
|
426 | + if (_check_locale_and_function()) { |
|
427 | + return textdomain($domain); |
|
428 | + } else { |
|
429 | + return _textdomain($domain); |
|
430 | + } |
|
431 | + } |
|
400 | 432 | function T_gettext($msgid) { |
401 | - if (_check_locale_and_function()) return gettext($msgid); |
|
402 | - else return _gettext($msgid); |
|
403 | -} |
|
433 | + if (_check_locale_and_function()) { |
|
434 | + return gettext($msgid); |
|
435 | + } else { |
|
436 | + return _gettext($msgid); |
|
437 | + } |
|
438 | + } |
|
404 | 439 | function T_($msgid) { |
405 | - if (_check_locale_and_function()) return _($msgid); |
|
440 | + if (_check_locale_and_function()) { |
|
441 | + return _($msgid); |
|
442 | + } |
|
406 | 443 | return __($msgid); |
407 | 444 | } |
408 | 445 | function T_ngettext($singular, $plural, $number) { |
409 | - if (_check_locale_and_function()) |
|
410 | - return ngettext($singular, $plural, $number); |
|
411 | - else return _ngettext($singular, $plural, $number); |
|
412 | -} |
|
446 | + if (_check_locale_and_function()) { |
|
447 | + return ngettext($singular, $plural, $number); |
|
448 | + } else { |
|
449 | + return _ngettext($singular, $plural, $number); |
|
450 | + } |
|
451 | + } |
|
413 | 452 | function T_dgettext($domain, $msgid) { |
414 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
415 | - else return _dgettext($domain, $msgid); |
|
416 | -} |
|
453 | + if (_check_locale_and_function()) { |
|
454 | + return dgettext($domain, $msgid); |
|
455 | + } else { |
|
456 | + return _dgettext($domain, $msgid); |
|
457 | + } |
|
458 | + } |
|
417 | 459 | function T_dngettext($domain, $singular, $plural, $number) { |
418 | - if (_check_locale_and_function()) |
|
419 | - return dngettext($domain, $singular, $plural, $number); |
|
420 | - else return _dngettext($domain, $singular, $plural, $number); |
|
421 | -} |
|
460 | + if (_check_locale_and_function()) { |
|
461 | + return dngettext($domain, $singular, $plural, $number); |
|
462 | + } else { |
|
463 | + return _dngettext($domain, $singular, $plural, $number); |
|
464 | + } |
|
465 | + } |
|
422 | 466 | function T_dcgettext($domain, $msgid, $category) { |
423 | - if (_check_locale_and_function()) |
|
424 | - return dcgettext($domain, $msgid, $category); |
|
425 | - else return _dcgettext($domain, $msgid, $category); |
|
426 | -} |
|
467 | + if (_check_locale_and_function()) { |
|
468 | + return dcgettext($domain, $msgid, $category); |
|
469 | + } else { |
|
470 | + return _dcgettext($domain, $msgid, $category); |
|
471 | + } |
|
472 | + } |
|
427 | 473 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
428 | - if (_check_locale_and_function()) |
|
429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
430 | - else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
431 | -} |
|
474 | + if (_check_locale_and_function()) { |
|
475 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
476 | + } else { |
|
477 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
478 | + } |
|
479 | + } |
|
432 | 480 | |
433 | 481 | function T_pgettext($context, $msgid) { |
434 | - if (_check_locale_and_function('pgettext')) |
|
435 | - return pgettext($context, $msgid); |
|
436 | - else |
|
437 | - return _pgettext($context, $msgid); |
|
438 | -} |
|
482 | + if (_check_locale_and_function('pgettext')) { |
|
483 | + return pgettext($context, $msgid); |
|
484 | + } else { |
|
485 | + return _pgettext($context, $msgid); |
|
486 | + } |
|
487 | + } |
|
439 | 488 | |
440 | 489 | function T_dpgettext($domain, $context, $msgid) { |
441 | - if (_check_locale_and_function('dpgettext')) |
|
442 | - return dpgettext($domain, $context, $msgid); |
|
443 | - else |
|
444 | - return _dpgettext($domain, $context, $msgid); |
|
445 | -} |
|
490 | + if (_check_locale_and_function('dpgettext')) { |
|
491 | + return dpgettext($domain, $context, $msgid); |
|
492 | + } else { |
|
493 | + return _dpgettext($domain, $context, $msgid); |
|
494 | + } |
|
495 | + } |
|
446 | 496 | |
447 | 497 | function T_dcpgettext($domain, $context, $msgid, $category) { |
448 | - if (_check_locale_and_function('dcpgettext')) |
|
449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
450 | - else |
|
451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
452 | -} |
|
498 | + if (_check_locale_and_function('dcpgettext')) { |
|
499 | + return dcpgettext($domain, $context, $msgid, $category); |
|
500 | + } else { |
|
501 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
502 | + } |
|
503 | + } |
|
453 | 504 | |
454 | 505 | function T_npgettext($context, $singular, $plural, $number) { |
455 | - if (_check_locale_and_function('npgettext')) |
|
456 | - return npgettext($context, $singular, $plural, $number); |
|
457 | - else |
|
458 | - return _npgettext($context, $singular, $plural, $number); |
|
459 | -} |
|
506 | + if (_check_locale_and_function('npgettext')) { |
|
507 | + return npgettext($context, $singular, $plural, $number); |
|
508 | + } else { |
|
509 | + return _npgettext($context, $singular, $plural, $number); |
|
510 | + } |
|
511 | + } |
|
460 | 512 | |
461 | 513 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
462 | - if (_check_locale_and_function('dnpgettext')) |
|
463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | - else |
|
465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
466 | -} |
|
514 | + if (_check_locale_and_function('dnpgettext')) { |
|
515 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
516 | + } else { |
|
517 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
518 | + } |
|
519 | + } |
|
467 | 520 | |
468 | 521 | function T_dcnpgettext($domain, $context, $singular, $plural, |
469 | 522 | $number, $category) { |
470 | - if (_check_locale_and_function('dcnpgettext')) |
|
471 | - return dcnpgettext($domain, $context, $singular, |
|
523 | + if (_check_locale_and_function('dcnpgettext')) { |
|
524 | + return dcnpgettext($domain, $context, $singular, |
|
472 | 525 | $plural, $number, $category); |
473 | - else |
|
474 | - return _dcnpgettext($domain, $context, $singular, |
|
526 | + } else { |
|
527 | + return _dcnpgettext($domain, $context, $singular, |
|
475 | 528 | $plural, $number, $category); |
476 | -} |
|
529 | + } |
|
530 | + } |
|
477 | 531 | |
478 | 532 | |
479 | 533 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | var $_pos; |
50 | 50 | var $_str; |
51 | 51 | |
52 | - function StringReader($str='') { |
|
52 | + function StringReader($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 FileReader($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 CachedFileReader($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) { |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | class QRimage { |
28 | 28 | |
29 | 29 | //---------------------------------------------------------------------- |
30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) |
|
31 | 31 | { |
32 | 32 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
33 | 33 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | Header("Content-type: image/png"); |
36 | 36 | ImagePng($image); |
37 | 37 | } else { |
38 | - if($saveandprint===TRUE){ |
|
38 | + if ($saveandprint === TRUE) { |
|
39 | 39 | ImagePng($image, $filename); |
40 | 40 | header("Content-type: image/png"); |
41 | 41 | ImagePng($image); |
42 | - }else{ |
|
42 | + } else { |
|
43 | 43 | ImagePng($image, $filename); |
44 | 44 | } |
45 | 45 | } |
@@ -68,25 +68,25 @@ discard block |
||
68 | 68 | $h = count($frame); |
69 | 69 | $w = strlen($frame[0]); |
70 | 70 | |
71 | - $imgW = $w + 2*$outerFrame; |
|
72 | - $imgH = $h + 2*$outerFrame; |
|
71 | + $imgW = $w + 2 * $outerFrame; |
|
72 | + $imgH = $h + 2 * $outerFrame; |
|
73 | 73 | |
74 | - $base_image =ImageCreate($imgW, $imgH); |
|
74 | + $base_image = ImageCreate($imgW, $imgH); |
|
75 | 75 | |
76 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
77 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
76 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
77 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
78 | 78 | |
79 | 79 | imagefill($base_image, 0, 0, $col[0]); |
80 | 80 | |
81 | - for($y=0; $y<$h; $y++) { |
|
82 | - for($x=0; $x<$w; $x++) { |
|
81 | + for ($y = 0; $y < $h; $y++) { |
|
82 | + for ($x = 0; $x < $w; $x++) { |
|
83 | 83 | if ($frame[$y][$x] == '1') { |
84 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
84 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
89 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
90 | 90 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
91 | 91 | ImageDestroy($base_image); |
92 | 92 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | ImagePng($image, $filename); |
40 | 40 | header("Content-type: image/png"); |
41 | 41 | ImagePng($image); |
42 | - }else{ |
|
42 | + } else{ |
|
43 | 43 | ImagePng($image, $filename); |
44 | 44 | } |
45 | 45 | } |
@@ -255,14 +255,14 @@ |
||
255 | 255 | $mode = $this->identifyMode(0); |
256 | 256 | |
257 | 257 | switch ($mode) { |
258 | - case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
259 | - case QR_MODE_AN: $length = $this->eatAn(); break; |
|
260 | - case QR_MODE_KANJI: |
|
261 | - if ($this->modeHint == QR_MODE_KANJI) |
|
262 | - $length = $this->eatKanji(); |
|
263 | - else $length = $this->eat8(); |
|
264 | - break; |
|
265 | - default: $length = $this->eat8(); break; |
|
258 | + case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
259 | + case QR_MODE_AN: $length = $this->eatAn(); break; |
|
260 | + case QR_MODE_KANJI: |
|
261 | + if ($this->modeHint == QR_MODE_KANJI) |
|
262 | + $length = $this->eatKanji(); |
|
263 | + else $length = $this->eat8(); |
|
264 | + break; |
|
265 | + default: $length = $this->eat8(); break; |
|
266 | 266 | |
267 | 267 | } |
268 | 268 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | if ($pos >= strlen($str)) |
51 | 51 | return false; |
52 | 52 | |
53 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
|
53 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9'))); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | //---------------------------------------------------------------------- |
@@ -70,17 +70,17 @@ discard block |
||
70 | 70 | |
71 | 71 | $c = $this->dataStr[$pos]; |
72 | 72 | |
73 | - if(self::isdigitat($this->dataStr, $pos)) { |
|
73 | + if (self::isdigitat($this->dataStr, $pos)) { |
|
74 | 74 | return QR_MODE_NUM; |
75 | - } else if(self::isalnumat($this->dataStr, $pos)) { |
|
75 | + } else if (self::isalnumat($this->dataStr, $pos)) { |
|
76 | 76 | return QR_MODE_AN; |
77 | - } else if($this->modeHint == QR_MODE_KANJI) { |
|
77 | + } else if ($this->modeHint == QR_MODE_KANJI) { |
|
78 | 78 | |
79 | - if ($pos+1 < strlen($this->dataStr)) |
|
79 | + if ($pos + 1 < strlen($this->dataStr)) |
|
80 | 80 | { |
81 | - $d = $this->dataStr[$pos+1]; |
|
81 | + $d = $this->dataStr[$pos + 1]; |
|
82 | 82 | $word = (ord($c) << 8) | ord($d); |
83 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
83 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
|
84 | 84 | return QR_MODE_KANJI; |
85 | 85 | } |
86 | 86 | } |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
96 | 96 | |
97 | 97 | $p = 0; |
98 | - while(self::isdigitat($this->dataStr, $p)) { |
|
98 | + while (self::isdigitat($this->dataStr, $p)) { |
|
99 | 99 | $p++; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $run = $p; |
103 | 103 | $mode = $this->identifyMode($p); |
104 | 104 | |
105 | - if($mode == QR_MODE_8) { |
|
105 | + if ($mode == QR_MODE_8) { |
|
106 | 106 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
107 | 107 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
108 | 108 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
109 | - if($dif > 0) { |
|
109 | + if ($dif > 0) { |
|
110 | 110 | return $this->eat8(); |
111 | 111 | } |
112 | 112 | } |
113 | - if($mode == QR_MODE_AN) { |
|
113 | + if ($mode == QR_MODE_AN) { |
|
114 | 114 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
115 | 115 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
116 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
117 | - if($dif > 0) { |
|
116 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
117 | + if ($dif > 0) { |
|
118 | 118 | return $this->eatAn(); |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | 122 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
123 | - if($ret < 0) |
|
123 | + if ($ret < 0) |
|
124 | 124 | return -1; |
125 | 125 | |
126 | 126 | return $run; |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | //---------------------------------------------------------------------- |
130 | 130 | public function eatAn() |
131 | 131 | { |
132 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
132 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
133 | 133 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
134 | 134 | |
135 | 135 | $p = 0; |
136 | 136 | |
137 | - while(self::isalnumat($this->dataStr, $p)) { |
|
138 | - if(self::isdigitat($this->dataStr, $p)) { |
|
137 | + while (self::isalnumat($this->dataStr, $p)) { |
|
138 | + if (self::isdigitat($this->dataStr, $p)) { |
|
139 | 139 | $q = $p; |
140 | - while(self::isdigitat($this->dataStr, $q)) { |
|
140 | + while (self::isdigitat($this->dataStr, $q)) { |
|
141 | 141 | $q++; |
142 | 142 | } |
143 | 143 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
146 | 146 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
147 | 147 | |
148 | - if($dif < 0) { |
|
148 | + if ($dif < 0) { |
|
149 | 149 | break; |
150 | 150 | } else { |
151 | 151 | $p = $q; |
@@ -157,17 +157,17 @@ discard block |
||
157 | 157 | |
158 | 158 | $run = $p; |
159 | 159 | |
160 | - if(!self::isalnumat($this->dataStr, $p)) { |
|
160 | + if (!self::isalnumat($this->dataStr, $p)) { |
|
161 | 161 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
162 | 162 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
163 | 163 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
164 | - if($dif > 0) { |
|
164 | + if ($dif > 0) { |
|
165 | 165 | return $this->eat8(); |
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | 169 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
170 | - if($ret < 0) |
|
170 | + if ($ret < 0) |
|
171 | 171 | return -1; |
172 | 172 | |
173 | 173 | return $run; |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | { |
179 | 179 | $p = 0; |
180 | 180 | |
181 | - while($this->identifyMode($p) == QR_MODE_KANJI) { |
|
181 | + while ($this->identifyMode($p) == QR_MODE_KANJI) { |
|
182 | 182 | $p += 2; |
183 | 183 | } |
184 | 184 | |
185 | 185 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
186 | - if($ret < 0) |
|
186 | + if ($ret < 0) |
|
187 | 187 | return -1; |
188 | 188 | |
189 | 189 | return $ret; |
@@ -198,34 +198,34 @@ discard block |
||
198 | 198 | $p = 1; |
199 | 199 | $dataStrLen = strlen($this->dataStr); |
200 | 200 | |
201 | - while($p < $dataStrLen) { |
|
201 | + while ($p < $dataStrLen) { |
|
202 | 202 | |
203 | 203 | $mode = $this->identifyMode($p); |
204 | - if($mode == QR_MODE_KANJI) { |
|
204 | + if ($mode == QR_MODE_KANJI) { |
|
205 | 205 | break; |
206 | 206 | } |
207 | - if($mode == QR_MODE_NUM) { |
|
207 | + if ($mode == QR_MODE_NUM) { |
|
208 | 208 | $q = $p; |
209 | - while(self::isdigitat($this->dataStr, $q)) { |
|
209 | + while (self::isdigitat($this->dataStr, $q)) { |
|
210 | 210 | $q++; |
211 | 211 | } |
212 | 212 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
213 | 213 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
214 | 214 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
215 | - if($dif < 0) { |
|
215 | + if ($dif < 0) { |
|
216 | 216 | break; |
217 | 217 | } else { |
218 | 218 | $p = $q; |
219 | 219 | } |
220 | - } else if($mode == QR_MODE_AN) { |
|
220 | + } else if ($mode == QR_MODE_AN) { |
|
221 | 221 | $q = $p; |
222 | - while(self::isalnumat($this->dataStr, $q)) { |
|
222 | + while (self::isalnumat($this->dataStr, $q)) { |
|
223 | 223 | $q++; |
224 | 224 | } |
225 | 225 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
226 | 226 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
227 | 227 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
228 | - if($dif < 0) { |
|
228 | + if ($dif < 0) { |
|
229 | 229 | break; |
230 | 230 | } else { |
231 | 231 | $p = $q; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $run = $p; |
239 | 239 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
240 | 240 | |
241 | - if($ret < 0) |
|
241 | + if ($ret < 0) |
|
242 | 242 | return -1; |
243 | 243 | |
244 | 244 | return $run; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | { |
250 | 250 | while (strlen($this->dataStr) > 0) |
251 | 251 | { |
252 | - if($this->dataStr == '') |
|
252 | + if ($this->dataStr == '') |
|
253 | 253 | return 0; |
254 | 254 | |
255 | 255 | $mode = $this->identifyMode(0); |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | |
267 | 267 | } |
268 | 268 | |
269 | - if($length == 0) return 0; |
|
270 | - if($length < 0) return -1; |
|
269 | + if ($length == 0) return 0; |
|
270 | + if ($length < 0) return -1; |
|
271 | 271 | |
272 | 272 | $this->dataStr = substr($this->dataStr, $length); |
273 | 273 | } |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | $stringLen = strlen($this->dataStr); |
280 | 280 | $p = 0; |
281 | 281 | |
282 | - while ($p<$stringLen) { |
|
282 | + while ($p < $stringLen) { |
|
283 | 283 | $mode = self::identifyMode(substr($this->dataStr, $p)); |
284 | - if($mode == QR_MODE_KANJI) { |
|
284 | + if ($mode == QR_MODE_KANJI) { |
|
285 | 285 | $p += 2; |
286 | 286 | } else { |
287 | 287 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { |
@@ -297,13 +297,13 @@ discard block |
||
297 | 297 | //---------------------------------------------------------------------- |
298 | 298 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
299 | 299 | { |
300 | - if(is_null($string) || $string == '\0' || $string == '') { |
|
300 | + if (is_null($string) || $string == '\0' || $string == '') { |
|
301 | 301 | throw new Exception('empty string!!!'); |
302 | 302 | } |
303 | 303 | |
304 | 304 | $split = new QRsplit($string, $input, $modeHint); |
305 | 305 | |
306 | - if(!$casesensitive) |
|
306 | + if (!$casesensitive) |
|
307 | 307 | $split->toUpper(); |
308 | 308 | |
309 | 309 | return $split->splitString(); |
@@ -47,8 +47,9 @@ discard block |
||
47 | 47 | //---------------------------------------------------------------------- |
48 | 48 | public static function isdigitat($str, $pos) |
49 | 49 | { |
50 | - if ($pos >= strlen($str)) |
|
51 | - return false; |
|
50 | + if ($pos >= strlen($str)) { |
|
51 | + return false; |
|
52 | + } |
|
52 | 53 | |
53 | 54 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
54 | 55 | } |
@@ -56,8 +57,9 @@ discard block |
||
56 | 57 | //---------------------------------------------------------------------- |
57 | 58 | public static function isalnumat($str, $pos) |
58 | 59 | { |
59 | - if ($pos >= strlen($str)) |
|
60 | - return false; |
|
60 | + if ($pos >= strlen($str)) { |
|
61 | + return false; |
|
62 | + } |
|
61 | 63 | |
62 | 64 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
63 | 65 | } |
@@ -65,8 +67,9 @@ discard block |
||
65 | 67 | //---------------------------------------------------------------------- |
66 | 68 | public function identifyMode($pos) |
67 | 69 | { |
68 | - if ($pos >= strlen($this->dataStr)) |
|
69 | - return QR_MODE_NUL; |
|
70 | + if ($pos >= strlen($this->dataStr)) { |
|
71 | + return QR_MODE_NUL; |
|
72 | + } |
|
70 | 73 | |
71 | 74 | $c = $this->dataStr[$pos]; |
72 | 75 | |
@@ -120,8 +123,9 @@ discard block |
||
120 | 123 | } |
121 | 124 | |
122 | 125 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
123 | - if($ret < 0) |
|
124 | - return -1; |
|
126 | + if($ret < 0) { |
|
127 | + return -1; |
|
128 | + } |
|
125 | 129 | |
126 | 130 | return $run; |
127 | 131 | } |
@@ -167,8 +171,9 @@ discard block |
||
167 | 171 | } |
168 | 172 | |
169 | 173 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
170 | - if($ret < 0) |
|
171 | - return -1; |
|
174 | + if($ret < 0) { |
|
175 | + return -1; |
|
176 | + } |
|
172 | 177 | |
173 | 178 | return $run; |
174 | 179 | } |
@@ -183,8 +188,9 @@ discard block |
||
183 | 188 | } |
184 | 189 | |
185 | 190 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
186 | - if($ret < 0) |
|
187 | - return -1; |
|
191 | + if($ret < 0) { |
|
192 | + return -1; |
|
193 | + } |
|
188 | 194 | |
189 | 195 | return $ret; |
190 | 196 | } |
@@ -238,8 +244,9 @@ discard block |
||
238 | 244 | $run = $p; |
239 | 245 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
240 | 246 | |
241 | - if($ret < 0) |
|
242 | - return -1; |
|
247 | + if($ret < 0) { |
|
248 | + return -1; |
|
249 | + } |
|
243 | 250 | |
244 | 251 | return $run; |
245 | 252 | } |
@@ -249,8 +256,9 @@ discard block |
||
249 | 256 | { |
250 | 257 | while (strlen($this->dataStr) > 0) |
251 | 258 | { |
252 | - if($this->dataStr == '') |
|
253 | - return 0; |
|
259 | + if($this->dataStr == '') { |
|
260 | + return 0; |
|
261 | + } |
|
254 | 262 | |
255 | 263 | $mode = $this->identifyMode(0); |
256 | 264 | |
@@ -258,16 +266,22 @@ discard block |
||
258 | 266 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
259 | 267 | case QR_MODE_AN: $length = $this->eatAn(); break; |
260 | 268 | case QR_MODE_KANJI: |
261 | - if ($this->modeHint == QR_MODE_KANJI) |
|
262 | - $length = $this->eatKanji(); |
|
263 | - else $length = $this->eat8(); |
|
269 | + if ($this->modeHint == QR_MODE_KANJI) { |
|
270 | + $length = $this->eatKanji(); |
|
271 | + } else { |
|
272 | + $length = $this->eat8(); |
|
273 | + } |
|
264 | 274 | break; |
265 | 275 | default: $length = $this->eat8(); break; |
266 | 276 | |
267 | 277 | } |
268 | 278 | |
269 | - if($length == 0) return 0; |
|
270 | - if($length < 0) return -1; |
|
279 | + if($length == 0) { |
|
280 | + return 0; |
|
281 | + } |
|
282 | + if($length < 0) { |
|
283 | + return -1; |
|
284 | + } |
|
271 | 285 | |
272 | 286 | $this->dataStr = substr($this->dataStr, $length); |
273 | 287 | } |
@@ -303,8 +317,9 @@ discard block |
||
303 | 317 | |
304 | 318 | $split = new QRsplit($string, $input, $modeHint); |
305 | 319 | |
306 | - if(!$casesensitive) |
|
307 | - $split->toUpper(); |
|
320 | + if(!$casesensitive) { |
|
321 | + $split->toUpper(); |
|
322 | + } |
|
308 | 323 | |
309 | 324 | return $split->splitString(); |
310 | 325 | } |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | $version = 1; |
202 | 202 | |
203 | 203 | switch($this->mode) { |
204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
208 | - case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
209 | - default: |
|
210 | - return 0; |
|
204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
208 | + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
209 | + default: |
|
210 | + return 0; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | $l = QRspec::lengthIndicator($this->mode, $version); |
@@ -247,14 +247,14 @@ discard block |
||
247 | 247 | $ret = 0; |
248 | 248 | |
249 | 249 | switch($this->mode) { |
250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
255 | 255 | |
256 | - default: |
|
257 | - break; |
|
256 | + default: |
|
257 | + break; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | if($ret < 0) |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | $bits = $w * 10; |
405 | 405 | |
406 | 406 | switch($size - $w * 3) { |
407 | - case 1: |
|
408 | - $bits += 4; |
|
409 | - break; |
|
410 | - case 2: |
|
411 | - $bits += 7; |
|
412 | - break; |
|
413 | - default: |
|
414 | - break; |
|
407 | + case 1: |
|
408 | + $bits += 4; |
|
409 | + break; |
|
410 | + case 2: |
|
411 | + $bits += 7; |
|
412 | + break; |
|
413 | + default: |
|
414 | + break; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | return $bits; |
@@ -500,14 +500,14 @@ discard block |
||
500 | 500 | return false; |
501 | 501 | |
502 | 502 | switch($mode) { |
503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
505 | - case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
506 | - case QR_MODE_8: return true; break; |
|
507 | - case QR_MODE_STRUCTURE: return true; break; |
|
503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
505 | + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
506 | + case QR_MODE_8: return true; break; |
|
507 | + case QR_MODE_STRUCTURE: return true; break; |
|
508 | 508 | |
509 | - default: |
|
510 | - break; |
|
509 | + default: |
|
510 | + break; |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return false; |
@@ -548,35 +548,35 @@ discard block |
||
548 | 548 | { |
549 | 549 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
550 | 550 | switch($mode) { |
551 | - case QR_MODE_NUM: |
|
552 | - $chunks = (int)($payload / 10); |
|
553 | - $remain = $payload - $chunks * 10; |
|
554 | - $size = $chunks * 3; |
|
555 | - if($remain >= 7) { |
|
556 | - $size += 2; |
|
557 | - } else if($remain >= 4) { |
|
558 | - $size += 1; |
|
559 | - } |
|
560 | - break; |
|
561 | - case QR_MODE_AN: |
|
562 | - $chunks = (int)($payload / 11); |
|
563 | - $remain = $payload - $chunks * 11; |
|
564 | - $size = $chunks * 2; |
|
565 | - if($remain >= 6) |
|
566 | - $size++; |
|
567 | - break; |
|
568 | - case QR_MODE_8: |
|
569 | - $size = (int)($payload / 8); |
|
570 | - break; |
|
571 | - case QR_MODE_KANJI: |
|
572 | - $size = (int)(($payload / 13) * 2); |
|
573 | - break; |
|
574 | - case QR_MODE_STRUCTURE: |
|
575 | - $size = (int)($payload / 8); |
|
576 | - break; |
|
577 | - default: |
|
578 | - $size = 0; |
|
579 | - break; |
|
551 | + case QR_MODE_NUM: |
|
552 | + $chunks = (int)($payload / 10); |
|
553 | + $remain = $payload - $chunks * 10; |
|
554 | + $size = $chunks * 3; |
|
555 | + if($remain >= 7) { |
|
556 | + $size += 2; |
|
557 | + } else if($remain >= 4) { |
|
558 | + $size += 1; |
|
559 | + } |
|
560 | + break; |
|
561 | + case QR_MODE_AN: |
|
562 | + $chunks = (int)($payload / 11); |
|
563 | + $remain = $payload - $chunks * 11; |
|
564 | + $size = $chunks * 2; |
|
565 | + if($remain >= 6) |
|
566 | + $size++; |
|
567 | + break; |
|
568 | + case QR_MODE_8: |
|
569 | + $size = (int)($payload / 8); |
|
570 | + break; |
|
571 | + case QR_MODE_KANJI: |
|
572 | + $size = (int)(($payload / 13) * 2); |
|
573 | + break; |
|
574 | + case QR_MODE_STRUCTURE: |
|
575 | + $size = (int)($payload / 8); |
|
576 | + break; |
|
577 | + default: |
|
578 | + $size = 0; |
|
579 | + break; |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | $maxsize = QRspec::maximumWords($mode, $version); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
26 | 26 | */ |
27 | 27 | |
28 | - define('STRUCTURE_HEADER_BITS', 20); |
|
28 | + define('STRUCTURE_HEADER_BITS', 20); |
|
29 | 29 | define('MAX_STRUCTURED_SYMBOLS', 16); |
30 | 30 | |
31 | 31 | class QRinputItem { |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | $setData = array_slice($data, 0, $size); |
41 | 41 | |
42 | 42 | if (count($setData) < $size) { |
43 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
43 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if(!QRinput::check($mode, $size, $setData)) { |
|
47 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); |
|
46 | + if (!QRinput::check($mode, $size, $setData)) { |
|
47 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData)); |
|
48 | 48 | return null; |
49 | 49 | } |
50 | 50 | |
@@ -59,26 +59,26 @@ discard block |
||
59 | 59 | { |
60 | 60 | try { |
61 | 61 | |
62 | - $words = (int)($this->size / 3); |
|
62 | + $words = (int) ($this->size / 3); |
|
63 | 63 | $bs = new QRbitstream(); |
64 | 64 | |
65 | 65 | $val = 0x1; |
66 | 66 | $bs->appendNum(4, $val); |
67 | 67 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
68 | 68 | |
69 | - for($i=0; $i<$words; $i++) { |
|
70 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; |
|
71 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; |
|
72 | - $val += (ord($this->data[$i*3+2]) - ord('0')); |
|
69 | + for ($i = 0; $i < $words; $i++) { |
|
70 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100; |
|
71 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10; |
|
72 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0')); |
|
73 | 73 | $bs->appendNum(10, $val); |
74 | 74 | } |
75 | 75 | |
76 | - if($this->size - $words * 3 == 1) { |
|
77 | - $val = ord($this->data[$words*3]) - ord('0'); |
|
76 | + if ($this->size - $words * 3 == 1) { |
|
77 | + $val = ord($this->data[$words * 3]) - ord('0'); |
|
78 | 78 | $bs->appendNum(4, $val); |
79 | - } else if($this->size - $words * 3 == 2) { |
|
80 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; |
|
81 | - $val += (ord($this->data[$words*3+1]) - ord('0')); |
|
79 | + } else if ($this->size - $words * 3 == 2) { |
|
80 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10; |
|
81 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0')); |
|
82 | 82 | $bs->appendNum(7, $val); |
83 | 83 | } |
84 | 84 | |
@@ -94,20 +94,20 @@ discard block |
||
94 | 94 | public function encodeModeAn($version) |
95 | 95 | { |
96 | 96 | try { |
97 | - $words = (int)($this->size / 2); |
|
97 | + $words = (int) ($this->size / 2); |
|
98 | 98 | $bs = new QRbitstream(); |
99 | 99 | |
100 | 100 | $bs->appendNum(4, 0x02); |
101 | 101 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
102 | 102 | |
103 | - for($i=0; $i<$words; $i++) { |
|
104 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
105 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
103 | + for ($i = 0; $i < $words; $i++) { |
|
104 | + $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
105 | + $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
106 | 106 | |
107 | 107 | $bs->appendNum(11, $val); |
108 | 108 | } |
109 | 109 | |
110 | - if($this->size & 1) { |
|
110 | + if ($this->size & 1) { |
|
111 | 111 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
112 | 112 | $bs->appendNum(6, $val); |
113 | 113 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $bs->appendNum(4, 0x4); |
130 | 130 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
131 | 131 | |
132 | - for($i=0; $i<$this->size; $i++) { |
|
132 | + for ($i = 0; $i < $this->size; $i++) { |
|
133 | 133 | $bs->appendNum(8, ord($this->data[$i])); |
134 | 134 | } |
135 | 135 | |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | $bs = new QRbitrtream(); |
150 | 150 | |
151 | 151 | $bs->appendNum(4, 0x8); |
152 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
152 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2)); |
|
153 | 153 | |
154 | - for($i=0; $i<$this->size; $i+=2) { |
|
155 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
156 | - if($val <= 0x9ffc) { |
|
154 | + for ($i = 0; $i < $this->size; $i += 2) { |
|
155 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
156 | + if ($val <= 0x9ffc) { |
|
157 | 157 | $val -= 0x8140; |
158 | 158 | } else { |
159 | 159 | $val -= 0xc140; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | public function encodeModeStructure() |
178 | 178 | { |
179 | 179 | try { |
180 | - $bs = new QRbitstream(); |
|
180 | + $bs = new QRbitstream(); |
|
181 | 181 | |
182 | 182 | $bs->appendNum(4, 0x03); |
183 | 183 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | { |
198 | 198 | $bits = 0; |
199 | 199 | |
200 | - if($version == 0) |
|
200 | + if ($version == 0) |
|
201 | 201 | $version = 1; |
202 | 202 | |
203 | - switch($this->mode) { |
|
204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
203 | + switch ($this->mode) { |
|
204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
208 | 208 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
209 | 209 | default: |
210 | 210 | return 0; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $l = QRspec::lengthIndicator($this->mode, $version); |
214 | 214 | $m = 1 << $l; |
215 | - $num = (int)(($this->size + $m - 1) / $m); |
|
215 | + $num = (int) (($this->size + $m - 1) / $m); |
|
216 | 216 | |
217 | 217 | $bits += $num * (4 + $l); |
218 | 218 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | unset($this->bstream); |
228 | 228 | $words = QRspec::maximumWords($this->mode, $version); |
229 | 229 | |
230 | - if($this->size > $words) { |
|
230 | + if ($this->size > $words) { |
|
231 | 231 | |
232 | 232 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
233 | 233 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -246,18 +246,18 @@ discard block |
||
246 | 246 | |
247 | 247 | $ret = 0; |
248 | 248 | |
249 | - switch($this->mode) { |
|
250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
249 | + switch ($this->mode) { |
|
250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
255 | 255 | |
256 | 256 | default: |
257 | 257 | break; |
258 | 258 | } |
259 | 259 | |
260 | - if($ret < 0) |
|
260 | + if ($ret < 0) |
|
261 | 261 | return -1; |
262 | 262 | } |
263 | 263 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | //---------------------------------------------------------------------- |
300 | 300 | public function setVersion($version) |
301 | 301 | { |
302 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
302 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) { |
|
303 | 303 | throw new Exception('Invalid version no'); |
304 | 304 | return -1; |
305 | 305 | } |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | //---------------------------------------------------------------------- |
319 | 319 | public function setErrorCorrectionLevel($level) |
320 | 320 | { |
321 | - if($level > QR_ECLEVEL_H) { |
|
321 | + if ($level > QR_ECLEVEL_H) { |
|
322 | 322 | throw new Exception('Invalid ECLEVEL'); |
323 | 323 | return -1; |
324 | 324 | } |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | |
351 | 351 | public function insertStructuredAppendHeader($size, $index, $parity) |
352 | 352 | { |
353 | - if( $size > MAX_STRUCTURED_SYMBOLS ) { |
|
353 | + if ($size > MAX_STRUCTURED_SYMBOLS) { |
|
354 | 354 | throw new Exception('insertStructuredAppendHeader wrong size'); |
355 | 355 | } |
356 | 356 | |
357 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { |
|
357 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) { |
|
358 | 358 | throw new Exception('insertStructuredAppendHeader wrong index'); |
359 | 359 | } |
360 | 360 | |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | { |
375 | 375 | $parity = 0; |
376 | 376 | |
377 | - foreach($this->items as $item) { |
|
378 | - if($item->mode != QR_MODE_STRUCTURE) { |
|
379 | - for($i=$item->size-1; $i>=0; $i--) { |
|
377 | + foreach ($this->items as $item) { |
|
378 | + if ($item->mode != QR_MODE_STRUCTURE) { |
|
379 | + for ($i = $item->size - 1; $i >= 0; $i--) { |
|
380 | 380 | $parity ^= $item->data[$i]; |
381 | 381 | } |
382 | 382 | } |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | //---------------------------------------------------------------------- |
389 | 389 | public static function checkModeNum($size, $data) |
390 | 390 | { |
391 | - for($i=0; $i<$size; $i++) { |
|
392 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ |
|
391 | + for ($i = 0; $i < $size; $i++) { |
|
392 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) { |
|
393 | 393 | return false; |
394 | 394 | } |
395 | 395 | } |
@@ -400,10 +400,10 @@ discard block |
||
400 | 400 | //---------------------------------------------------------------------- |
401 | 401 | public static function estimateBitsModeNum($size) |
402 | 402 | { |
403 | - $w = (int)$size / 3; |
|
403 | + $w = (int) $size / 3; |
|
404 | 404 | $bits = $w * 10; |
405 | 405 | |
406 | - switch($size - $w * 3) { |
|
406 | + switch ($size - $w * 3) { |
|
407 | 407 | case 1: |
408 | 408 | $bits += 4; |
409 | 409 | break; |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
423 | 423 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
424 | 424 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
425 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
425 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
426 | 426 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
427 | 427 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
428 | 428 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | //---------------------------------------------------------------------- |
433 | 433 | public static function lookAnTable($c) |
434 | 434 | { |
435 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
435 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | //---------------------------------------------------------------------- |
439 | 439 | public static function checkModeAn($size, $data) |
440 | 440 | { |
441 | - for($i=0; $i<$size; $i++) { |
|
441 | + for ($i = 0; $i < $size; $i++) { |
|
442 | 442 | if (self::lookAnTable(ord($data[$i])) == -1) { |
443 | 443 | return false; |
444 | 444 | } |
@@ -450,10 +450,10 @@ discard block |
||
450 | 450 | //---------------------------------------------------------------------- |
451 | 451 | public static function estimateBitsModeAn($size) |
452 | 452 | { |
453 | - $w = (int)($size / 2); |
|
453 | + $w = (int) ($size / 2); |
|
454 | 454 | $bits = $w * 11; |
455 | 455 | |
456 | - if($size & 1) { |
|
456 | + if ($size & 1) { |
|
457 | 457 | $bits += 6; |
458 | 458 | } |
459 | 459 | |
@@ -469,18 +469,18 @@ discard block |
||
469 | 469 | //---------------------------------------------------------------------- |
470 | 470 | public function estimateBitsModeKanji($size) |
471 | 471 | { |
472 | - return (int)(($size / 2) * 13); |
|
472 | + return (int) (($size / 2) * 13); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | //---------------------------------------------------------------------- |
476 | 476 | public static function checkModeKanji($size, $data) |
477 | 477 | { |
478 | - if($size & 1) |
|
478 | + if ($size & 1) |
|
479 | 479 | return false; |
480 | 480 | |
481 | - for($i=0; $i<$size; $i+=2) { |
|
482 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
483 | - if( $val < 0x8140 |
|
481 | + for ($i = 0; $i < $size; $i += 2) { |
|
482 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
483 | + if ($val < 0x8140 |
|
484 | 484 | || ($val > 0x9ffc && $val < 0xe040) |
485 | 485 | || $val > 0xebbf) { |
486 | 486 | return false; |
@@ -496,12 +496,12 @@ discard block |
||
496 | 496 | |
497 | 497 | public static function check($mode, $size, $data) |
498 | 498 | { |
499 | - if($size <= 0) |
|
499 | + if ($size <= 0) |
|
500 | 500 | return false; |
501 | 501 | |
502 | - switch($mode) { |
|
503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
502 | + switch ($mode) { |
|
503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
505 | 505 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
506 | 506 | case QR_MODE_8: return true; break; |
507 | 507 | case QR_MODE_STRUCTURE: return true; break; |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | { |
520 | 520 | $bits = 0; |
521 | 521 | |
522 | - foreach($this->items as $item) { |
|
522 | + foreach ($this->items as $item) { |
|
523 | 523 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
524 | 524 | } |
525 | 525 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | do { |
535 | 535 | $prev = $version; |
536 | 536 | $bits = $this->estimateBitStreamSize($prev); |
537 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
537 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
538 | 538 | if ($version < 0) { |
539 | 539 | return -1; |
540 | 540 | } |
@@ -547,32 +547,32 @@ discard block |
||
547 | 547 | public static function lengthOfCode($mode, $version, $bits) |
548 | 548 | { |
549 | 549 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
550 | - switch($mode) { |
|
550 | + switch ($mode) { |
|
551 | 551 | case QR_MODE_NUM: |
552 | - $chunks = (int)($payload / 10); |
|
552 | + $chunks = (int) ($payload / 10); |
|
553 | 553 | $remain = $payload - $chunks * 10; |
554 | 554 | $size = $chunks * 3; |
555 | - if($remain >= 7) { |
|
555 | + if ($remain >= 7) { |
|
556 | 556 | $size += 2; |
557 | - } else if($remain >= 4) { |
|
557 | + } else if ($remain >= 4) { |
|
558 | 558 | $size += 1; |
559 | 559 | } |
560 | 560 | break; |
561 | 561 | case QR_MODE_AN: |
562 | - $chunks = (int)($payload / 11); |
|
562 | + $chunks = (int) ($payload / 11); |
|
563 | 563 | $remain = $payload - $chunks * 11; |
564 | 564 | $size = $chunks * 2; |
565 | - if($remain >= 6) |
|
565 | + if ($remain >= 6) |
|
566 | 566 | $size++; |
567 | 567 | break; |
568 | 568 | case QR_MODE_8: |
569 | - $size = (int)($payload / 8); |
|
569 | + $size = (int) ($payload / 8); |
|
570 | 570 | break; |
571 | 571 | case QR_MODE_KANJI: |
572 | - $size = (int)(($payload / 13) * 2); |
|
572 | + $size = (int) (($payload / 13) * 2); |
|
573 | 573 | break; |
574 | 574 | case QR_MODE_STRUCTURE: |
575 | - $size = (int)($payload / 8); |
|
575 | + $size = (int) ($payload / 8); |
|
576 | 576 | break; |
577 | 577 | default: |
578 | 578 | $size = 0; |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | } |
581 | 581 | |
582 | 582 | $maxsize = QRspec::maximumWords($mode, $version); |
583 | - if($size < 0) $size = 0; |
|
584 | - if($size > $maxsize) $size = $maxsize; |
|
583 | + if ($size < 0) $size = 0; |
|
584 | + if ($size > $maxsize) $size = $maxsize; |
|
585 | 585 | |
586 | 586 | return $size; |
587 | 587 | } |
@@ -591,10 +591,10 @@ discard block |
||
591 | 591 | { |
592 | 592 | $total = 0; |
593 | 593 | |
594 | - foreach($this->items as $item) { |
|
594 | + foreach ($this->items as $item) { |
|
595 | 595 | $bits = $item->encodeBitStream($this->version); |
596 | 596 | |
597 | - if($bits < 0) |
|
597 | + if ($bits < 0) |
|
598 | 598 | return -1; |
599 | 599 | |
600 | 600 | $total += $bits; |
@@ -607,21 +607,21 @@ discard block |
||
607 | 607 | public function convertData() |
608 | 608 | { |
609 | 609 | $ver = $this->estimateVersion(); |
610 | - if($ver > $this->getVersion()) { |
|
610 | + if ($ver > $this->getVersion()) { |
|
611 | 611 | $this->setVersion($ver); |
612 | 612 | } |
613 | 613 | |
614 | - for(;;) { |
|
614 | + for (;;) { |
|
615 | 615 | $bits = $this->createBitStream(); |
616 | 616 | |
617 | - if($bits < 0) |
|
617 | + if ($bits < 0) |
|
618 | 618 | return -1; |
619 | 619 | |
620 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
621 | - if($ver < 0) { |
|
620 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
621 | + if ($ver < 0) { |
|
622 | 622 | throw new Exception('WRONG VERSION'); |
623 | 623 | return -1; |
624 | - } else if($ver > $this->getVersion()) { |
|
624 | + } else if ($ver > $this->getVersion()) { |
|
625 | 625 | $this->setVersion($ver); |
626 | 626 | } else { |
627 | 627 | break; |
@@ -647,26 +647,26 @@ discard block |
||
647 | 647 | } |
648 | 648 | |
649 | 649 | $bits += 4; |
650 | - $words = (int)(($bits + 7) / 8); |
|
650 | + $words = (int) (($bits + 7) / 8); |
|
651 | 651 | |
652 | 652 | $padding = new QRbitstream(); |
653 | 653 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
654 | 654 | |
655 | - if($ret < 0) |
|
655 | + if ($ret < 0) |
|
656 | 656 | return $ret; |
657 | 657 | |
658 | 658 | $padlen = $maxwords - $words; |
659 | 659 | |
660 | - if($padlen > 0) { |
|
660 | + if ($padlen > 0) { |
|
661 | 661 | |
662 | 662 | $padbuf = array(); |
663 | - for($i=0; $i<$padlen; $i++) { |
|
664 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
663 | + for ($i = 0; $i < $padlen; $i++) { |
|
664 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | $ret = $padding->appendBytes($padlen, $padbuf); |
668 | 668 | |
669 | - if($ret < 0) |
|
669 | + if ($ret < 0) |
|
670 | 670 | return $ret; |
671 | 671 | |
672 | 672 | } |
@@ -679,15 +679,15 @@ discard block |
||
679 | 679 | //---------------------------------------------------------------------- |
680 | 680 | public function mergeBitStream() |
681 | 681 | { |
682 | - if($this->convertData() < 0) { |
|
682 | + if ($this->convertData() < 0) { |
|
683 | 683 | return null; |
684 | 684 | } |
685 | 685 | |
686 | 686 | $bstream = new QRbitstream(); |
687 | 687 | |
688 | - foreach($this->items as $item) { |
|
688 | + foreach ($this->items as $item) { |
|
689 | 689 | $ret = $bstream->append($item->bstream); |
690 | - if($ret < 0) { |
|
690 | + if ($ret < 0) { |
|
691 | 691 | return null; |
692 | 692 | } |
693 | 693 | } |
@@ -701,12 +701,12 @@ discard block |
||
701 | 701 | |
702 | 702 | $bstream = $this->mergeBitStream(); |
703 | 703 | |
704 | - if($bstream == null) { |
|
704 | + if ($bstream == null) { |
|
705 | 705 | return null; |
706 | 706 | } |
707 | 707 | |
708 | 708 | $ret = $this->appendPaddingBit($bstream); |
709 | - if($ret < 0) { |
|
709 | + if ($ret < 0) { |
|
710 | 710 | return null; |
711 | 711 | } |
712 | 712 | |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | public function getByteStream() |
718 | 718 | { |
719 | 719 | $bstream = $this->getBitStream(); |
720 | - if($bstream == null) { |
|
720 | + if ($bstream == null) { |
|
721 | 721 | return null; |
722 | 722 | } |
723 | 723 |
@@ -197,8 +197,9 @@ discard block |
||
197 | 197 | { |
198 | 198 | $bits = 0; |
199 | 199 | |
200 | - if($version == 0) |
|
201 | - $version = 1; |
|
200 | + if($version == 0) { |
|
201 | + $version = 1; |
|
202 | + } |
|
202 | 203 | |
203 | 204 | switch($this->mode) { |
204 | 205 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -257,8 +258,9 @@ discard block |
||
257 | 258 | break; |
258 | 259 | } |
259 | 260 | |
260 | - if($ret < 0) |
|
261 | - return -1; |
|
261 | + if($ret < 0) { |
|
262 | + return -1; |
|
263 | + } |
|
262 | 264 | } |
263 | 265 | |
264 | 266 | return $this->bstream->size(); |
@@ -475,8 +477,9 @@ discard block |
||
475 | 477 | //---------------------------------------------------------------------- |
476 | 478 | public static function checkModeKanji($size, $data) |
477 | 479 | { |
478 | - if($size & 1) |
|
479 | - return false; |
|
480 | + if($size & 1) { |
|
481 | + return false; |
|
482 | + } |
|
480 | 483 | |
481 | 484 | for($i=0; $i<$size; $i+=2) { |
482 | 485 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -496,8 +499,9 @@ discard block |
||
496 | 499 | |
497 | 500 | public static function check($mode, $size, $data) |
498 | 501 | { |
499 | - if($size <= 0) |
|
500 | - return false; |
|
502 | + if($size <= 0) { |
|
503 | + return false; |
|
504 | + } |
|
501 | 505 | |
502 | 506 | switch($mode) { |
503 | 507 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -562,8 +566,9 @@ discard block |
||
562 | 566 | $chunks = (int)($payload / 11); |
563 | 567 | $remain = $payload - $chunks * 11; |
564 | 568 | $size = $chunks * 2; |
565 | - if($remain >= 6) |
|
566 | - $size++; |
|
569 | + if($remain >= 6) { |
|
570 | + $size++; |
|
571 | + } |
|
567 | 572 | break; |
568 | 573 | case QR_MODE_8: |
569 | 574 | $size = (int)($payload / 8); |
@@ -580,8 +585,12 @@ discard block |
||
580 | 585 | } |
581 | 586 | |
582 | 587 | $maxsize = QRspec::maximumWords($mode, $version); |
583 | - if($size < 0) $size = 0; |
|
584 | - if($size > $maxsize) $size = $maxsize; |
|
588 | + if($size < 0) { |
|
589 | + $size = 0; |
|
590 | + } |
|
591 | + if($size > $maxsize) { |
|
592 | + $size = $maxsize; |
|
593 | + } |
|
585 | 594 | |
586 | 595 | return $size; |
587 | 596 | } |
@@ -594,8 +603,9 @@ discard block |
||
594 | 603 | foreach($this->items as $item) { |
595 | 604 | $bits = $item->encodeBitStream($this->version); |
596 | 605 | |
597 | - if($bits < 0) |
|
598 | - return -1; |
|
606 | + if($bits < 0) { |
|
607 | + return -1; |
|
608 | + } |
|
599 | 609 | |
600 | 610 | $total += $bits; |
601 | 611 | } |
@@ -614,8 +624,9 @@ discard block |
||
614 | 624 | for(;;) { |
615 | 625 | $bits = $this->createBitStream(); |
616 | 626 | |
617 | - if($bits < 0) |
|
618 | - return -1; |
|
627 | + if($bits < 0) { |
|
628 | + return -1; |
|
629 | + } |
|
619 | 630 | |
620 | 631 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
621 | 632 | if($ver < 0) { |
@@ -652,8 +663,9 @@ discard block |
||
652 | 663 | $padding = new QRbitstream(); |
653 | 664 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
654 | 665 | |
655 | - if($ret < 0) |
|
656 | - return $ret; |
|
666 | + if($ret < 0) { |
|
667 | + return $ret; |
|
668 | + } |
|
657 | 669 | |
658 | 670 | $padlen = $maxwords - $words; |
659 | 671 | |
@@ -666,8 +678,9 @@ discard block |
||
666 | 678 | |
667 | 679 | $ret = $padding->appendBytes($padlen, $padbuf); |
668 | 680 | |
669 | - if($ret < 0) |
|
670 | - return $ret; |
|
681 | + if($ret < 0) { |
|
682 | + return $ret; |
|
683 | + } |
|
671 | 684 | |
672 | 685 | } |
673 | 686 |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | /** |
181 | 181 | * Matrix index to get width from $capacity array. |
182 | 182 | */ |
183 | - define('QRCAP_WIDTH', 0); |
|
183 | + define('QRCAP_WIDTH', 0); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Matrix index to get number of words from $capacity array. |
187 | 187 | */ |
188 | - define('QRCAP_WORDS', 1); |
|
188 | + define('QRCAP_WORDS', 1); |
|
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Matrix index to get remainder from $capacity array. |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * Matrix index to get error correction level from $capacity array. |
197 | 197 | */ |
198 | - define('QRCAP_EC', 3); |
|
198 | + define('QRCAP_EC', 3); |
|
199 | 199 | |
200 | 200 | // ----------------------------------------------------- |
201 | 201 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * Number of header bits for structured mode |
206 | 206 | */ |
207 | - define('STRUCTURE_HEADER_BITS', 20); |
|
207 | + define('STRUCTURE_HEADER_BITS', 20); |
|
208 | 208 | |
209 | 209 | /** |
210 | 210 | * Max number of symbols for structured mode |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | /** |
219 | 219 | * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column) |
220 | 220 | */ |
221 | - define('N1', 3); |
|
221 | + define('N1', 3); |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Down point base value for case 2 mask pattern (module block of same color) |
225 | 225 | */ |
226 | - define('N2', 3); |
|
226 | + define('N2', 3); |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column) |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param int $split_length Maximum length of the chunk. |
271 | 271 | * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element. |
272 | 272 | */ |
273 | - function str_split($string, $split_length=1) { |
|
273 | + function str_split($string, $split_length = 1) { |
|
274 | 274 | if ((strlen($string) > $split_length) OR (!$split_length)) { |
275 | 275 | do { |
276 | 276 | $c = strlen($string); |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']); |
1665 | 1665 | $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']); |
1666 | 1666 | } else { |
1667 | - switch($inputitem['mode']) { |
|
1667 | + switch ($inputitem['mode']) { |
|
1668 | 1668 | case QR_MODE_NM: { |
1669 | 1669 | $inputitem = $this->encodeModeNum($inputitem, $version); |
1670 | 1670 | break; |
@@ -1771,9 +1771,9 @@ discard block |
||
1771 | 1771 | * @return int number of bits |
1772 | 1772 | */ |
1773 | 1773 | protected function estimateBitsModeNum($size) { |
1774 | - $w = (int)$size / 3; |
|
1774 | + $w = (int) $size / 3; |
|
1775 | 1775 | $bits = $w * 10; |
1776 | - switch($size - $w * 3) { |
|
1776 | + switch ($size - $w * 3) { |
|
1777 | 1777 | case 1: { |
1778 | 1778 | $bits += 4; |
1779 | 1779 | break; |
@@ -1875,7 +1875,7 @@ discard block |
||
1875 | 1875 | if ($size <= 0) { |
1876 | 1876 | return false; |
1877 | 1877 | } |
1878 | - switch($mode) { |
|
1878 | + switch ($mode) { |
|
1879 | 1879 | case QR_MODE_NM: { |
1880 | 1880 | return $this->checkModeNum($size, $data); |
1881 | 1881 | } |
@@ -1910,7 +1910,7 @@ discard block |
||
1910 | 1910 | $version = 1; |
1911 | 1911 | } |
1912 | 1912 | foreach ($items as $item) { |
1913 | - switch($item['mode']) { |
|
1913 | + switch ($item['mode']) { |
|
1914 | 1914 | case QR_MODE_NM: { |
1915 | 1915 | $bits = $this->estimateBitsModeNum($item['size']); |
1916 | 1916 | break; |
@@ -1970,9 +1970,9 @@ discard block |
||
1970 | 1970 | */ |
1971 | 1971 | protected function lengthOfCode($mode, $version, $bits) { |
1972 | 1972 | $payload = $bits - 4 - $this->lengthIndicator($mode, $version); |
1973 | - switch($mode) { |
|
1973 | + switch ($mode) { |
|
1974 | 1974 | case QR_MODE_NM: { |
1975 | - $chunks = (int)($payload / 10); |
|
1975 | + $chunks = (int) ($payload / 10); |
|
1976 | 1976 | $remain = $payload - $chunks * 10; |
1977 | 1977 | $size = $chunks * 3; |
1978 | 1978 | if ($remain >= 7) { |
@@ -1983,7 +1983,7 @@ discard block |
||
1983 | 1983 | break; |
1984 | 1984 | } |
1985 | 1985 | case QR_MODE_AN: { |
1986 | - $chunks = (int)($payload / 11); |
|
1986 | + $chunks = (int) ($payload / 11); |
|
1987 | 1987 | $remain = $payload - $chunks * 11; |
1988 | 1988 | $size = $chunks * 2; |
1989 | 1989 | if ($remain >= 6) { |
@@ -1992,15 +1992,15 @@ discard block |
||
1992 | 1992 | break; |
1993 | 1993 | } |
1994 | 1994 | case QR_MODE_8B: { |
1995 | - $size = (int)($payload / 8); |
|
1995 | + $size = (int) ($payload / 8); |
|
1996 | 1996 | break; |
1997 | 1997 | } |
1998 | 1998 | case QR_MODE_KJ: { |
1999 | - $size = (int)(($payload / 13) * 2); |
|
1999 | + $size = (int) (($payload / 13) * 2); |
|
2000 | 2000 | break; |
2001 | 2001 | } |
2002 | 2002 | case QR_MODE_ST: { |
2003 | - $size = (int)($payload / 8); |
|
2003 | + $size = (int) ($payload / 8); |
|
2004 | 2004 | break; |
2005 | 2005 | } |
2006 | 2006 | default: { |