@@ -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,162 +128,162 @@ 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 | |
| 147 | 147 | /* get original and translations tables */ |
| 148 | 148 | if (!is_array($this->table_originals)) { |
| 149 | - $this->STREAM->seekto($this->originals); |
|
| 150 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
| 149 | + $this->STREAM->seekto($this->originals); |
|
| 150 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
| 151 | 151 | } |
| 152 | 152 | if (!is_array($this->table_translations)) { |
| 153 | - $this->STREAM->seekto($this->translations); |
|
| 154 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
| 153 | + $this->STREAM->seekto($this->translations); |
|
| 154 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($this->enable_cache) { |
| 158 | - $this->cache_translations = array(); |
|
| 159 | - /* read all strings in the cache */ |
|
| 160 | - for ($i = 0; $i < $this->total; $i++) { |
|
| 158 | + $this->cache_translations = array(); |
|
| 159 | + /* read all strings in the cache */ |
|
| 160 | + for ($i = 0; $i < $this->total; $i++) { |
|
| 161 | 161 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
| 162 | 162 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
| 163 | 163 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
| 164 | 164 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
| 165 | 165 | $this->cache_translations[$original] = $translation; |
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns a string from the "originals" table |
|
| 172 | - * |
|
| 173 | - * @access private |
|
| 174 | - * @param int num Offset number of original string |
|
| 175 | - * @return string Requested string if found, otherwise '' |
|
| 176 | - */ |
|
| 177 | - function get_original_string($num) { |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns a string from the "originals" table |
|
| 172 | + * |
|
| 173 | + * @access private |
|
| 174 | + * @param int num Offset number of original string |
|
| 175 | + * @return string Requested string if found, otherwise '' |
|
| 176 | + */ |
|
| 177 | + function get_original_string($num) { |
|
| 178 | 178 | $length = $this->table_originals[$num * 2 + 1]; |
| 179 | 179 | $offset = $this->table_originals[$num * 2 + 2]; |
| 180 | 180 | if (! $length) { |
| 181 | - return ''; |
|
| 181 | + return ''; |
|
| 182 | 182 | } |
| 183 | 183 | $this->STREAM->seekto($offset); |
| 184 | 184 | $data = $this->STREAM->read($length); |
| 185 | 185 | return (string)$data; |
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns a string from the "translations" table |
|
| 190 | - * |
|
| 191 | - * @access private |
|
| 192 | - * @param int num Offset number of original string |
|
| 193 | - * @return string Requested string if found, otherwise '' |
|
| 194 | - */ |
|
| 195 | - function get_translation_string($num) { |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns a string from the "translations" table |
|
| 190 | + * |
|
| 191 | + * @access private |
|
| 192 | + * @param int num Offset number of original string |
|
| 193 | + * @return string Requested string if found, otherwise '' |
|
| 194 | + */ |
|
| 195 | + function get_translation_string($num) { |
|
| 196 | 196 | $length = $this->table_translations[$num * 2 + 1]; |
| 197 | 197 | $offset = $this->table_translations[$num * 2 + 2]; |
| 198 | 198 | if (! $length) { |
| 199 | - return ''; |
|
| 199 | + return ''; |
|
| 200 | 200 | } |
| 201 | 201 | $this->STREAM->seekto($offset); |
| 202 | 202 | $data = $this->STREAM->read($length); |
| 203 | 203 | return (string)$data; |
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Binary search for string |
|
| 208 | - * |
|
| 209 | - * @access private |
|
| 210 | - * @param string string |
|
| 211 | - * @param int start (internally used in recursive function) |
|
| 212 | - * @param int end (internally used in recursive function) |
|
| 213 | - * @return int string number (offset in originals table) |
|
| 214 | - */ |
|
| 215 | - function find_string($string, $start = -1, $end = -1) { |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Binary search for string |
|
| 208 | + * |
|
| 209 | + * @access private |
|
| 210 | + * @param string string |
|
| 211 | + * @param int start (internally used in recursive function) |
|
| 212 | + * @param int end (internally used in recursive function) |
|
| 213 | + * @return int string number (offset in originals table) |
|
| 214 | + */ |
|
| 215 | + function find_string($string, $start = -1, $end = -1) { |
|
| 216 | 216 | if (($start == -1) or ($end == -1)) { |
| 217 | - // find_string is called with only one parameter, set start end end |
|
| 218 | - $start = 0; |
|
| 219 | - $end = $this->total; |
|
| 217 | + // find_string is called with only one parameter, set start end end |
|
| 218 | + $start = 0; |
|
| 219 | + $end = $this->total; |
|
| 220 | 220 | } |
| 221 | 221 | if (abs($start - $end) <= 1) { |
| 222 | - // We're done, now we either found the string, or it doesn't exist |
|
| 223 | - $txt = $this->get_original_string($start); |
|
| 224 | - if ($string == $txt) { |
|
| 225 | - return $start; |
|
| 226 | - } else { |
|
| 227 | - return -1; |
|
| 228 | - } |
|
| 222 | + // We're done, now we either found the string, or it doesn't exist |
|
| 223 | + $txt = $this->get_original_string($start); |
|
| 224 | + if ($string == $txt) { |
|
| 225 | + return $start; |
|
| 226 | + } else { |
|
| 227 | + return -1; |
|
| 228 | + } |
|
| 229 | 229 | } else if ($start > $end) { |
| 230 | - // start > end -> turn around and start over |
|
| 231 | - return $this->find_string($string, $end, $start); |
|
| 230 | + // start > end -> turn around and start over |
|
| 231 | + return $this->find_string($string, $end, $start); |
|
| 232 | 232 | } else { |
| 233 | - // Divide table in two parts |
|
| 234 | - $half = (int) (($start + $end) / 2); |
|
| 235 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 236 | - if ($cmp == 0) { |
|
| 237 | - // string is exactly in the middle => return it |
|
| 233 | + // Divide table in two parts |
|
| 234 | + $half = (int) (($start + $end) / 2); |
|
| 235 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 236 | + if ($cmp == 0) { |
|
| 237 | + // string is exactly in the middle => return it |
|
| 238 | 238 | return $half; |
| 239 | - } else if ($cmp < 0) { |
|
| 240 | - // The string is in the upper half |
|
| 239 | + } else if ($cmp < 0) { |
|
| 240 | + // The string is in the upper half |
|
| 241 | 241 | return $this->find_string($string, $start, $half); |
| 242 | - } else { |
|
| 243 | - // The string is in the lower half |
|
| 242 | + } else { |
|
| 243 | + // The string is in the lower half |
|
| 244 | 244 | return $this->find_string($string, $half, $end); |
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Translates a string |
|
| 251 | - * |
|
| 252 | - * @access public |
|
| 253 | - * @param string string to be translated |
|
| 254 | - * @return string translated string (or original, if not found) |
|
| 255 | - */ |
|
| 256 | - function translate($string) { |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Translates a string |
|
| 251 | + * |
|
| 252 | + * @access public |
|
| 253 | + * @param string string to be translated |
|
| 254 | + * @return string translated string (or original, if not found) |
|
| 255 | + */ |
|
| 256 | + function translate($string) { |
|
| 257 | 257 | if ($this->short_circuit) { |
| 258 | - return $string; |
|
| 258 | + return $string; |
|
| 259 | 259 | } |
| 260 | 260 | $this->load_tables(); |
| 261 | 261 | |
| 262 | 262 | if ($this->enable_cache) { |
| 263 | - // Caching enabled, get translated string from cache |
|
| 264 | - if (array_key_exists($string, $this->cache_translations)) { |
|
| 265 | - return $this->cache_translations[$string]; |
|
| 266 | - } else { |
|
| 267 | - return $string; |
|
| 268 | - } |
|
| 263 | + // Caching enabled, get translated string from cache |
|
| 264 | + if (array_key_exists($string, $this->cache_translations)) { |
|
| 265 | + return $this->cache_translations[$string]; |
|
| 266 | + } else { |
|
| 267 | + return $string; |
|
| 268 | + } |
|
| 269 | 269 | } else { |
| 270 | - // Caching not enabled, try to find string |
|
| 271 | - $num = $this->find_string($string); |
|
| 272 | - if ($num == -1) { |
|
| 273 | - return $string; |
|
| 274 | - } else { |
|
| 275 | - return $this->get_translation_string($num); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Sanitize plural form expression for use in PHP eval call. |
|
| 282 | - * |
|
| 283 | - * @access private |
|
| 284 | - * @return string sanitized plural form expression |
|
| 285 | - */ |
|
| 286 | - function sanitize_plural_expression($expr) { |
|
| 270 | + // Caching not enabled, try to find string |
|
| 271 | + $num = $this->find_string($string); |
|
| 272 | + if ($num == -1) { |
|
| 273 | + return $string; |
|
| 274 | + } else { |
|
| 275 | + return $this->get_translation_string($num); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Sanitize plural form expression for use in PHP eval call. |
|
| 282 | + * |
|
| 283 | + * @access private |
|
| 284 | + * @return string sanitized plural form expression |
|
| 285 | + */ |
|
| 286 | + function sanitize_plural_expression($expr) { |
|
| 287 | 287 | // Get rid of disallowed characters. |
| 288 | 288 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
| 289 | 289 | |
@@ -292,75 +292,75 @@ discard block |
||
| 292 | 292 | $res = ''; |
| 293 | 293 | $p = 0; |
| 294 | 294 | for ($i = 0; $i < strlen($expr); $i++) { |
| 295 | - $ch = $expr[$i]; |
|
| 296 | - switch ($ch) { |
|
| 297 | - case '?': |
|
| 295 | + $ch = $expr[$i]; |
|
| 296 | + switch ($ch) { |
|
| 297 | + case '?': |
|
| 298 | 298 | $res .= ' ? ('; |
| 299 | 299 | $p++; |
| 300 | 300 | break; |
| 301 | - case ':': |
|
| 301 | + case ':': |
|
| 302 | 302 | $res .= ') : ('; |
| 303 | 303 | break; |
| 304 | - case ';': |
|
| 304 | + case ';': |
|
| 305 | 305 | $res .= str_repeat(')', $p).';'; |
| 306 | 306 | $p = 0; |
| 307 | 307 | break; |
| 308 | - default: |
|
| 308 | + default: |
|
| 309 | 309 | $res .= $ch; |
| 310 | - } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | return $res; |
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Parse full PO header and extract only plural forms line. |
|
| 317 | - * |
|
| 318 | - * @access private |
|
| 319 | - * @return string verbatim plural form header field |
|
| 320 | - */ |
|
| 321 | - function extract_plural_forms_header_from_po_header($header) { |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Parse full PO header and extract only plural forms line. |
|
| 317 | + * |
|
| 318 | + * @access private |
|
| 319 | + * @return string verbatim plural form header field |
|
| 320 | + */ |
|
| 321 | + function extract_plural_forms_header_from_po_header($header) { |
|
| 322 | 322 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) { |
| 323 | - $expr = $regs[2]; |
|
| 323 | + $expr = $regs[2]; |
|
| 324 | 324 | } else { |
| 325 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 325 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 326 | 326 | } |
| 327 | 327 | return $expr; |
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get possible plural forms from MO header |
|
| 332 | - * |
|
| 333 | - * @access private |
|
| 334 | - * @return string plural form header |
|
| 335 | - */ |
|
| 336 | - function get_plural_forms() { |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get possible plural forms from MO header |
|
| 332 | + * |
|
| 333 | + * @access private |
|
| 334 | + * @return string plural form header |
|
| 335 | + */ |
|
| 336 | + function get_plural_forms() { |
|
| 337 | 337 | // lets assume message number 0 is header |
| 338 | 338 | // this is true, right? |
| 339 | 339 | $this->load_tables(); |
| 340 | 340 | |
| 341 | 341 | // cache header field for plural forms |
| 342 | 342 | if (!is_string($this->pluralheader)) { |
| 343 | - if ($this->enable_cache) { |
|
| 343 | + if ($this->enable_cache) { |
|
| 344 | 344 | $header = $this->cache_translations[""]; |
| 345 | - } else { |
|
| 345 | + } else { |
|
| 346 | 346 | $header = $this->get_translation_string(0); |
| 347 | - } |
|
| 348 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 349 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 347 | + } |
|
| 348 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 349 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 350 | 350 | } |
| 351 | 351 | return $this->pluralheader; |
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Detects which plural form to take |
|
| 356 | - * |
|
| 357 | - * @access private |
|
| 358 | - * @param n count |
|
| 359 | - * @return int array index of the right plural form |
|
| 360 | - */ |
|
| 361 | - function select_string($n) { |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Detects which plural form to take |
|
| 356 | + * |
|
| 357 | + * @access private |
|
| 358 | + * @param n count |
|
| 359 | + * @return int array index of the right plural form |
|
| 360 | + */ |
|
| 361 | + function select_string($n) { |
|
| 362 | 362 | if (!is_int($n)) { |
| 363 | - throw new InvalidArgumentException( |
|
| 363 | + throw new InvalidArgumentException( |
|
| 364 | 364 | "Select_string only accepts integers: ".$n); |
| 365 | 365 | } |
| 366 | 366 | $string = $this->get_plural_forms(); |
@@ -376,24 +376,24 @@ discard block |
||
| 376 | 376 | $plural = $total - 1; |
| 377 | 377 | } |
| 378 | 378 | return $plural; |
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Plural version of gettext |
|
| 383 | - * |
|
| 384 | - * @access public |
|
| 385 | - * @param string single |
|
| 386 | - * @param string plural |
|
| 387 | - * @param string number |
|
| 388 | - * @return translated plural form |
|
| 389 | - */ |
|
| 390 | - function ngettext($single, $plural, $number) { |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Plural version of gettext |
|
| 383 | + * |
|
| 384 | + * @access public |
|
| 385 | + * @param string single |
|
| 386 | + * @param string plural |
|
| 387 | + * @param string number |
|
| 388 | + * @return translated plural form |
|
| 389 | + */ |
|
| 390 | + function ngettext($single, $plural, $number) { |
|
| 391 | 391 | if ($this->short_circuit) { |
| 392 | - if ($number != 1) { |
|
| 393 | - return $plural; |
|
| 394 | - } else { |
|
| 395 | - return $single; |
|
| 396 | - } |
|
| 392 | + if ($number != 1) { |
|
| 393 | + return $plural; |
|
| 394 | + } else { |
|
| 395 | + return $single; |
|
| 396 | + } |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // find out the appropriate form |
@@ -404,45 +404,45 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | if ($this->enable_cache) { |
| 407 | - if (!array_key_exists($key, $this->cache_translations)) { |
|
| 407 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
| 408 | 408 | return ($number != 1) ? $plural : $single; |
| 409 | - } else { |
|
| 409 | + } else { |
|
| 410 | 410 | $result = $this->cache_translations[$key]; |
| 411 | 411 | $list = explode(chr(0), $result); |
| 412 | 412 | return $list[$select]; |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | } else { |
| 415 | - $num = $this->find_string($key); |
|
| 416 | - if ($num == -1) { |
|
| 415 | + $num = $this->find_string($key); |
|
| 416 | + if ($num == -1) { |
|
| 417 | 417 | return ($number != 1) ? $plural : $single; |
| 418 | - } else { |
|
| 418 | + } else { |
|
| 419 | 419 | $result = $this->get_translation_string($num); |
| 420 | 420 | $list = explode(chr(0), $result); |
| 421 | 421 | return $list[$select]; |
| 422 | - } |
|
| 422 | + } |
|
| 423 | + } |
|
| 423 | 424 | } |
| 424 | - } |
|
| 425 | 425 | |
| 426 | - function pgettext($context, $msgid) { |
|
| 426 | + function pgettext($context, $msgid) { |
|
| 427 | 427 | $key = $context.chr(4).$msgid; |
| 428 | 428 | $ret = $this->translate($key); |
| 429 | 429 | if (strpos($ret, "\004") !== false) { |
| 430 | - return $msgid; |
|
| 430 | + return $msgid; |
|
| 431 | 431 | } else { |
| 432 | - return $ret; |
|
| 432 | + return $ret; |
|
| 433 | + } |
|
| 433 | 434 | } |
| 434 | - } |
|
| 435 | 435 | |
| 436 | - function npgettext($context, $singular, $plural, $number) { |
|
| 436 | + function npgettext($context, $singular, $plural, $number) { |
|
| 437 | 437 | $key = $context.chr(4).$singular; |
| 438 | 438 | $ret = $this->ngettext($key, $plural, $number); |
| 439 | 439 | if (strpos($ret, "\004") !== false) { |
| 440 | - return $singular; |
|
| 440 | + return $singular; |
|
| 441 | 441 | } else { |
| 442 | - return $ret; |
|
| 442 | + return $ret; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | ?> |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | function get_original_string($num) { |
| 178 | 178 | $length = $this->table_originals[$num * 2 + 1]; |
| 179 | 179 | $offset = $this->table_originals[$num * 2 + 2]; |
| 180 | - if (! $length) { |
|
| 180 | + if (!$length) { |
|
| 181 | 181 | return ''; |
| 182 | 182 | } |
| 183 | 183 | $this->STREAM->seekto($offset); |
| 184 | 184 | $data = $this->STREAM->read($length); |
| 185 | - return (string)$data; |
|
| 185 | + return (string) $data; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | function get_translation_string($num) { |
| 196 | 196 | $length = $this->table_translations[$num * 2 + 1]; |
| 197 | 197 | $offset = $this->table_translations[$num * 2 + 2]; |
| 198 | - if (! $length) { |
|
| 198 | + if (!$length) { |
|
| 199 | 199 | return ''; |
| 200 | 200 | } |
| 201 | 201 | $this->STREAM->seekto($offset); |
| 202 | 202 | $data = $this->STREAM->read($length); |
| 203 | - return (string)$data; |
|
| 203 | + return (string) $data; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -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,63 +64,63 @@ 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)) { |
|
| 82 | - |
|
| 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 | - } |
|
| 95 | - |
|
| 96 | - if ($modifier) { |
|
| 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 | + |
|
| 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 | + } |
|
| 95 | + |
|
| 96 | + if ($modifier) { |
|
| 97 | 97 | if ($country) { |
| 98 | - if ($charset) { |
|
| 99 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 100 | - } |
|
| 101 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 98 | + if ($charset) { |
|
| 99 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 100 | + } |
|
| 101 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 102 | 102 | } elseif ($charset) { |
| 103 | 103 | array_push($locale_names, "${lang}.$charset@$modifier"); |
| 104 | 104 | } |
| 105 | 105 | array_push($locale_names, "$lang@$modifier"); |
| 106 | - } |
|
| 107 | - if ($country) { |
|
| 106 | + } |
|
| 107 | + if ($country) { |
|
| 108 | 108 | if ($charset) { |
| 109 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
| 109 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
| 110 | 110 | } |
| 111 | 111 | array_push($locale_names, "${lang}_$country"); |
| 112 | - } elseif ($charset) { |
|
| 112 | + } elseif ($charset) { |
|
| 113 | 113 | array_push($locale_names, "${lang}.$charset"); |
| 114 | - } |
|
| 115 | - array_push($locale_names, $lang); |
|
| 114 | + } |
|
| 115 | + array_push($locale_names, $lang); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // If the locale name doesn't match POSIX style, just include it as-is. |
| 119 | 119 | if (!in_array($locale, $locale_names)) { |
| 120 | - array_push($locale_names, $locale); |
|
| 120 | + array_push($locale_names, $locale); |
|
| 121 | 121 | } |
| 122 | - } |
|
| 123 | - return $locale_names; |
|
| 122 | + } |
|
| 123 | + return $locale_names; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | $locale_names = get_list_of_locales($locale); |
| 142 | 142 | $input = null; |
| 143 | 143 | foreach ($locale_names as $locale) { |
| 144 | - $full_path = $bound_path.$locale."/".$subpath; |
|
| 145 | - if (file_exists($full_path)) { |
|
| 144 | + $full_path = $bound_path.$locale."/".$subpath; |
|
| 145 | + if (file_exists($full_path)) { |
|
| 146 | 146 | $input = new FileReader($full_path); |
| 147 | 147 | break; |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (!array_key_exists($domain, $text_domains)) { |
| 152 | - // Initialize an empty domain object. |
|
| 153 | - $text_domains[$domain] = new domain(); |
|
| 152 | + // Initialize an empty domain object. |
|
| 153 | + $text_domains[$domain] = new domain(); |
|
| 154 | 154 | } |
| 155 | 155 | $text_domains[$domain]->l10n = new gettext_reader($input, |
| 156 | - $enable_cache); |
|
| 156 | + $enable_cache); |
|
| 157 | 157 | } |
| 158 | 158 | return $text_domains[$domain]->l10n; |
| 159 | 159 | } |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | * Convert the given string to the encoding set by bind_textdomain_codeset. |
| 191 | 191 | */ |
| 192 | 192 | function _encode($text) { |
| 193 | - $target_encoding = _get_codeset(); |
|
| 194 | - if (function_exists("mb_detect_encoding")) { |
|
| 193 | + $target_encoding = _get_codeset(); |
|
| 194 | + if (function_exists("mb_detect_encoding")) { |
|
| 195 | 195 | $source_encoding = mb_detect_encoding($text); |
| 196 | 196 | if ($source_encoding != $target_encoding) { |
| 197 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 197 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 198 | + } |
|
| 198 | 199 | } |
| 199 | - } |
|
| 200 | - return $text; |
|
| 200 | + return $text; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
| 208 | 208 | */ |
| 209 | 209 | function _get_default_locale($locale) { |
| 210 | - if ($locale == '') { |
|
| 211 | - // emulate variable support |
|
| 210 | + if ($locale == '') { |
|
| 211 | + // emulate variable support |
|
| 212 | 212 | return getenv('LANG'); |
| 213 | - } else { |
|
| 214 | - return $locale; |
|
| 215 | - } |
|
| 216 | - } |
|
| 213 | + } else { |
|
| 214 | + return $locale; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | 219 | * Sets a requested locale, if needed emulates it. |
@@ -230,20 +230,20 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | } else { |
| 232 | 232 | if (function_exists('setlocale')) { |
| 233 | - $ret = setlocale($category, $locale); |
|
| 234 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
| 233 | + $ret = setlocale($category, $locale); |
|
| 234 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
| 235 | 235 | ($locale != '' and $ret != $locale)) { // failed setting it |
| 236 | 236 | // Failed setting it according to environment. |
| 237 | 237 | $CURRENTLOCALE = _get_default_locale($locale); |
| 238 | 238 | $EMULATEGETTEXT = 1; |
| 239 | - } else { |
|
| 239 | + } else { |
|
| 240 | 240 | $CURRENTLOCALE = $ret; |
| 241 | 241 | $EMULATEGETTEXT = 0; |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | } else { |
| 244 | - // No function setlocale(), emulate it all. |
|
| 245 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 246 | - $EMULATEGETTEXT = 1; |
|
| 244 | + // No function setlocale(), emulate it all. |
|
| 245 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 246 | + $EMULATEGETTEXT = 1; |
|
| 247 | 247 | } |
| 248 | 248 | // Allow locale to be changed on the go for one translation domain. |
| 249 | 249 | global $text_domains, $default_domain; |
@@ -261,15 +261,15 @@ discard block |
||
| 261 | 261 | global $text_domains; |
| 262 | 262 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
| 263 | 263 | if (substr(php_uname(), 0, 7) == "Windows") { |
| 264 | - if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
| 264 | + if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
| 265 | 265 | $path .= '\\'; |
| 266 | 266 | } else { |
| 267 | - if ($path[strlen($path) - 1] != '/') |
|
| 267 | + if ($path[strlen($path) - 1] != '/') |
|
| 268 | 268 | $path .= '/'; |
| 269 | 269 | } |
| 270 | 270 | if (!array_key_exists($domain, $text_domains)) { |
| 271 | - // Initialize an empty domain object. |
|
| 272 | - $text_domains[$domain] = new domain(); |
|
| 271 | + // Initialize an empty domain object. |
|
| 272 | + $text_domains[$domain] = new domain(); |
|
| 273 | 273 | } |
| 274 | 274 | $text_domains[$domain]->path = $path; |
| 275 | 275 | } |
@@ -468,35 +468,35 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
| 470 | 470 | if (_check_locale_and_function()) { |
| 471 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 471 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 472 | 472 | } else { |
| 473 | 473 | return _dcngettext($domain, $singular, $plural, $number, $category); |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | function T_pgettext($context, $msgid) { |
| 478 | - if (_check_locale_and_function('pgettext')) { |
|
| 478 | + if (_check_locale_and_function('pgettext')) { |
|
| 479 | 479 | return pgettext($context, $msgid); |
| 480 | - } else { |
|
| 480 | + } else { |
|
| 481 | 481 | return _pgettext($context, $msgid); |
| 482 | - } |
|
| 483 | - } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | 485 | function T_dpgettext($domain, $context, $msgid) { |
| 486 | - if (_check_locale_and_function('dpgettext')) { |
|
| 486 | + if (_check_locale_and_function('dpgettext')) { |
|
| 487 | 487 | return dpgettext($domain, $context, $msgid); |
| 488 | - } else { |
|
| 488 | + } else { |
|
| 489 | 489 | return _dpgettext($domain, $context, $msgid); |
| 490 | - } |
|
| 491 | - } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | 493 | function T_dcpgettext($domain, $context, $msgid, $category) { |
| 494 | - if (_check_locale_and_function('dcpgettext')) { |
|
| 494 | + if (_check_locale_and_function('dcpgettext')) { |
|
| 495 | 495 | return dcpgettext($domain, $context, $msgid, $category); |
| 496 | - } else { |
|
| 496 | + } else { |
|
| 497 | 497 | return _dcpgettext($domain, $context, $msgid, $category); |
| 498 | - } |
|
| 499 | - } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | function T_npgettext($context, $singular, $plural, $number) { |
| 502 | 502 | if (_check_locale_and_function('npgettext')) { |
@@ -507,18 +507,18 @@ discard block |
||
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
| 510 | - if (_check_locale_and_function('dnpgettext')) { |
|
| 510 | + if (_check_locale_and_function('dnpgettext')) { |
|
| 511 | 511 | return dnpgettext($domain, $context, $singular, $plural, $number); |
| 512 | - } else { |
|
| 512 | + } else { |
|
| 513 | 513 | return _dnpgettext($domain, $context, $singular, $plural, $number); |
| 514 | - } |
|
| 515 | - } |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | function T_dcnpgettext($domain, $context, $singular, $plural, |
| 518 | - $number, $category) { |
|
| 518 | + $number, $category) { |
|
| 519 | 519 | if (_check_locale_and_function('dcnpgettext')) { |
| 520 | 520 | return dcnpgettext($domain, $context, $singular, |
| 521 | - $plural, $number, $category); |
|
| 521 | + $plural, $number, $category); |
|
| 522 | 522 | } else { |
| 523 | 523 | return _dcnpgettext($domain, $context, $singular, |
| 524 | 524 | $plural, $number, $category); |
@@ -576,9 +576,9 @@ discard block |
||
| 576 | 576 | return _dcpgettext($domain, $context, $msgid, $category); |
| 577 | 577 | } |
| 578 | 578 | function dcnpgettext($domain, $context, $singular, $plural, |
| 579 | - $number, $category) { |
|
| 580 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 581 | - $number, $category); |
|
| 579 | + $number, $category) { |
|
| 580 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 581 | + $number, $category); |
|
| 582 | 582 | } |
| 583 | 583 | } |
| 584 | 584 | |
@@ -182,7 +182,9 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | function _get_codeset($domain = null) { |
| 184 | 184 | global $text_domains, $default_domain, $LC_CATEGORIES; |
| 185 | - if (!isset($domain)) $domain = $default_domain; |
|
| 185 | + if (!isset($domain)) { |
|
| 186 | + $domain = $default_domain; |
|
| 187 | + } |
|
| 186 | 188 | return (isset($text_domains[$domain]->codeset)) ? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
| 187 | 189 | } |
| 188 | 190 | |
@@ -261,11 +263,13 @@ discard block |
||
| 261 | 263 | global $text_domains; |
| 262 | 264 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
| 263 | 265 | if (substr(php_uname(), 0, 7) == "Windows") { |
| 264 | - if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
| 265 | - $path .= '\\'; |
|
| 266 | + if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') { |
|
| 267 | + $path .= '\\'; |
|
| 268 | + } |
|
| 266 | 269 | } else { |
| 267 | - if ($path[strlen($path) - 1] != '/') |
|
| 268 | - $path .= '/'; |
|
| 270 | + if ($path[strlen($path) - 1] != '/') { |
|
| 271 | + $path .= '/'; |
|
| 272 | + } |
|
| 269 | 273 | } |
| 270 | 274 | if (!array_key_exists($domain, $text_domains)) { |
| 271 | 275 | // Initialize an empty domain object. |
@@ -35,11 +35,11 @@ |
||
| 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 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | //---------------------------------------------------------------------- |
| 80 | 80 | public static function buildCache() |
| 81 | 81 | {
|
| 82 | - QRtools::markTime('before_build_cache');
|
|
| 82 | + QRtools::markTime('before_build_cache');
|
|
| 83 | 83 | |
| 84 | - $mask = new QRmask(); |
|
| 84 | + $mask = new QRmask(); |
|
| 85 | 85 | for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
| 86 | 86 | $frame = QRspec::newFrame($a); |
| 87 | 87 | if (QR_IMAGE) {
|
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $width = count($frame); |
|
| 93 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 94 | - for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 95 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 92 | + $width = count($frame); |
|
| 93 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 94 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 95 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - QRtools::markTime('after_build_cache');
|
|
| 98 | + QRtools::markTime('after_build_cache');
|
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | //---------------------------------------------------------------------- |
@@ -62,8 +62,9 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | foreach ($qrTab as $line) {
|
| 64 | 64 | $arrAdd = array(); |
| 65 | - foreach (str_split($line) as $char) |
|
| 66 | - $arrAdd[] = ($char == '1') ? 1 : 0; |
|
| 65 | + foreach (str_split($line) as $char) { |
|
| 66 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
| 67 | + } |
|
| 67 | 68 | $barcode_array['bcode'][] = $arrAdd; |
| 68 | 69 | } |
| 69 | 70 | |
@@ -91,8 +92,9 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | $width = count($frame); |
| 93 | 94 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 94 | - for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 95 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 95 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) { |
|
| 96 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 97 | + } |
|
| 96 | 98 | } |
| 97 | 99 | |
| 98 | 100 | QRtools::markTime('after_build_cache');
|
@@ -26,29 +26,29 @@ |
||
| 26 | 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | - // Encoding modes |
|
| 29 | + // Encoding modes |
|
| 30 | 30 | |
| 31 | - define('QR_MODE_NUL', -1);
|
|
| 32 | - define('QR_MODE_NUM', 0);
|
|
| 33 | - define('QR_MODE_AN', 1);
|
|
| 34 | - define('QR_MODE_8', 2);
|
|
| 35 | - define('QR_MODE_KANJI', 3);
|
|
| 36 | - define('QR_MODE_STRUCTURE', 4);
|
|
| 31 | + define('QR_MODE_NUL', -1);
|
|
| 32 | + define('QR_MODE_NUM', 0);
|
|
| 33 | + define('QR_MODE_AN', 1);
|
|
| 34 | + define('QR_MODE_8', 2);
|
|
| 35 | + define('QR_MODE_KANJI', 3);
|
|
| 36 | + define('QR_MODE_STRUCTURE', 4);
|
|
| 37 | 37 | |
| 38 | - // Levels of error correction. |
|
| 38 | + // Levels of error correction. |
|
| 39 | 39 | |
| 40 | - define('QR_ECLEVEL_L', 0);
|
|
| 41 | - define('QR_ECLEVEL_M', 1);
|
|
| 42 | - define('QR_ECLEVEL_Q', 2);
|
|
| 43 | - define('QR_ECLEVEL_H', 3);
|
|
| 40 | + define('QR_ECLEVEL_L', 0);
|
|
| 41 | + define('QR_ECLEVEL_M', 1);
|
|
| 42 | + define('QR_ECLEVEL_Q', 2);
|
|
| 43 | + define('QR_ECLEVEL_H', 3);
|
|
| 44 | 44 | |
| 45 | - // Supported output formats |
|
| 45 | + // Supported output formats |
|
| 46 | 46 | |
| 47 | - define('QR_FORMAT_TEXT', 0);
|
|
| 48 | - define('QR_FORMAT_PNG', 1);
|
|
| 47 | + define('QR_FORMAT_TEXT', 0);
|
|
| 48 | + define('QR_FORMAT_PNG', 1);
|
|
| 49 | 49 | |
| 50 | - class qrstr {
|
|
| 51 | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 52 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | 50 | \ No newline at end of file |
| 51 | + class qrstr {
|
|
| 52 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 53 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | \ No newline at end of file |
@@ -43,19 +43,22 @@ discard block |
||
| 43 | 43 | //processing form input |
| 44 | 44 | //remember to sanitize user input in real-life solution !!! |
| 45 | 45 | $errorCorrectionLevel = 'L'; |
| 46 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L', 'M', 'Q', 'H')))
|
|
| 47 | - $errorCorrectionLevel = $_REQUEST['level']; |
|
| 46 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L', 'M', 'Q', 'H'))) { |
|
| 47 | + $errorCorrectionLevel = $_REQUEST['level']; |
|
| 48 | + } |
|
| 48 | 49 | |
| 49 | 50 | $matrixPointSize = 4; |
| 50 | - if (isset($_REQUEST['size'])) |
|
| 51 | - $matrixPointSize = min(max((int) $_REQUEST['size'], 1), 10); |
|
| 51 | + if (isset($_REQUEST['size'])) { |
|
| 52 | + $matrixPointSize = min(max((int) $_REQUEST['size'], 1), 10); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | |
| 54 | 56 | if (isset($_REQUEST['data'])) {
|
| 55 | 57 | |
| 56 | 58 | //it's very important! |
| 57 | - if (trim($_REQUEST['data']) == '') |
|
| 58 | - die('data cannot be empty! <a href="?">back</a>');
|
|
| 59 | + if (trim($_REQUEST['data']) == '') { |
|
| 60 | + die('data cannot be empty! <a href="?">back</a>'); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | // user data |
| 61 | 64 | $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
@@ -83,8 +86,9 @@ discard block |
||
| 83 | 86 | </select> |
| 84 | 87 | Size: <select name="size">'; |
| 85 | 88 | |
| 86 | - for ($i = 1; $i <= 10; $i++) |
|
| 87 | - echo '<option value="'.$i.'"'.(($matrixPointSize == $i) ? ' selected' : '').'>'.$i.'</option>'; |
|
| 89 | + for ($i = 1; $i <= 10; $i++) { |
|
| 90 | + echo '<option value="'.$i.'"'.(($matrixPointSize == $i) ? ' selected' : '').'>'.$i.'</option>'; |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | echo '</select> |
| 90 | 94 | <input type="submit" value="GENERATE"></form><hr/>'; |
@@ -108,13 +108,15 @@ discard block |
||
| 108 | 108 | //---------------------------------------------------------------------- |
| 109 | 109 | public function appendNum($bits, $num) |
| 110 | 110 | {
|
| 111 | - if ($bits == 0) |
|
| 112 | - return 0; |
|
| 111 | + if ($bits == 0) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 113 | 114 | |
| 114 | 115 | $b = QRbitstream::newFromNum($bits, $num); |
| 115 | 116 | |
| 116 | - if (is_null($b)) |
|
| 117 | - return -1; |
|
| 117 | + if (is_null($b)) { |
|
| 118 | + return -1; |
|
| 119 | + } |
|
| 118 | 120 | |
| 119 | 121 | $ret = $this->append($b); |
| 120 | 122 | unset($b); |
@@ -125,13 +127,15 @@ discard block |
||
| 125 | 127 | //---------------------------------------------------------------------- |
| 126 | 128 | public function appendBytes($size, $data) |
| 127 | 129 | {
|
| 128 | - if ($size == 0) |
|
| 129 | - return 0; |
|
| 130 | + if ($size == 0) { |
|
| 131 | + return 0; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | $b = QRbitstream::newFromBytes($size, $data); |
| 132 | 135 | |
| 133 | - if (is_null($b)) |
|
| 134 | - return -1; |
|
| 136 | + if (is_null($b)) { |
|
| 137 | + return -1; |
|
| 138 | + } |
|
| 135 | 139 | |
| 136 | 140 | $ret = $this->append($b); |
| 137 | 141 | unset($b); |
@@ -14,4 +14,4 @@ |
||
| 14 | 14 | define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
| 15 | 15 | |
| 16 | 16 | define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
| 17 | - |
|
| 18 | 17 | \ No newline at end of file |
| 18 | + |
|
| 19 | 19 | \ No newline at end of file |
@@ -422,7 +422,7 @@ |
||
| 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, |
@@ -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); |
@@ -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 | |